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 |
---|---|---|---|---|---|---|---|---|---|
bed62bfd6378b367e3fe0617a419b84a | Save the problem! | Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph.
People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?
As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below.
Input will consist of a single integer *A* (1<=β€<=*A*<=β€<=105), the desired number of ways.
In the first line print integers *N* and *M* (1<=β€<=*N*<=β€<=106,<=1<=β€<=*M*<=β€<=10), the amount of change to be made, and the number of denominations, respectively.
Then print *M* integers *D*1,<=*D*2,<=...,<=*D**M* (1<=β€<=*D**i*<=β€<=106), the denominations of the coins. All denominations must be distinct: for any *i*<=β <=*j* we must have *D**i*<=β <=*D**j*.
If there are multiple tests, print any of them. You can print denominations in atbitrary order.
Sample Input
18
3
314
Sample Output
30 4
1 5 10 25
20 2
5 2
183 4
6 5 2 139
| {"inputs": ["18", "3", "314", "1023", "100000", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "239", "4063", "65536", "65535", "65537", "99991", "99990", "99992", "99971", "99990", "2", "99991"], "outputs": ["30 4\n1 5 10 25", "20 2\n5 2", "183 4\n6 5 2 139", "2045 2\n1 2", "199999 2\n1 2", "1 2\n1 2", "3 2\n1 2", "20 2\n5 2", "7 2\n1 2", "9 2\n1 2", "11 2\n1 2", "13 2\n1 2", "15 2\n1 2", "17 2\n1 2", "19 2\n1 2", "21 2\n1 2", "23 2\n1 2", "25 2\n1 2", "27 2\n1 2", "29 2\n1 2", "31 2\n1 2", "33 2\n1 2", "30 4\n1 5 10 25", "37 2\n1 2", "39 2\n1 2", "477 2\n1 2", "8125 2\n1 2", "131071 2\n1 2", "131069 2\n1 2", "131073 2\n1 2", "199981 2\n1 2", "199979 2\n1 2", "199983 2\n1 2", "199941 2\n1 2", "199979 2\n1 2", "3 2\n1 2", "199981 2\n1 2"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 43 | codeforces |
|
beda8b32b0ec9b99868f00941d309d79 | Tyndex.Brome | Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome!
The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installed (the Tyndex.Bar automatically fills the glass with the finest 1664 cognac after you buy Tyndex.Bottles and insert in into a USB port). It is highly popular due to the well-thought interaction with the user.
Let us take, for example, the system of automatic address correction. Have you entered codehorses instead of codeforces? The gloomy Zoozle Chrome will sadly say that the address does not exist. Tyndex.Brome at the same time will automatically find the closest address and sent you there. That's brilliant!
How does this splendid function work? That's simple! For each potential address a function of the *F* error is calculated by the following rules:
- for every letter *c**i* from the potential address *c* the closest position *j* of the letter *c**i* in the address (*s*) entered by the user is found. The absolute difference |*i*<=-<=*j*| of these positions is added to *F*. So for every *i* (1<=β€<=*i*<=β€<=|*c*|) the position *j* is chosen such, that *c**i*<==<=*s**j*, and |*i*<=-<=*j*| is minimal possible. - if no such letter *c**i* exists in the address entered by the user, then the length of the potential address |*c*| is added to *F*.
After the values of the error function have been calculated for all the potential addresses the most suitable one is found.
To understand the special features of the above described method better, it is recommended to realize the algorithm of calculating the *F* function for an address given by the user and some set of potential addresses. Good luck!
The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=105,<=1<=β€<=*k*<=β€<=105). They are the number of potential addresses and the length of the address entered by the user. The next line contains *k* lowercase Latin letters. They are the address entered by the user (*s*). Each next *i*-th (1<=β€<=*i*<=β€<=*n*) line contains a non-empty sequence of lowercase Latin letters. They are the potential address. It is guaranteed that the total length of all the lines does not exceed 2Β·105.
On each *n* line of the output file print a single number: the value of the error function when the current potential address is chosen.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
Sample Input
2 10
codeforces
codeforces
codehorses
9 9
vkontakte
vcontacte
vkontrakte
vkollapse
vkrokodile
vtopke
vkapuste
vpechke
vk
vcodeforcese
Sample Output
0
12
18
14
36
47
14
29
30
0
84
| {"inputs": ["2 10\ncodeforces\ncodeforces\ncodehorses", "9 9\nvkontakte\nvcontacte\nvkontrakte\nvkollapse\nvkrokodile\nvtopke\nvkapuste\nvpechke\nvk\nvcodeforcese", "3 3\nbyg\ndwg\nl\nx", "4 4\nlocw\na\nr\nba\nxuv", "5 5\nvpjjx\njj\ne\nnor\nuthm\nbf", "10 10\nczuanvzpiq\nc\ng\ni\nx\na\ny\nz\nk\nf\nx", "15 15\ndtpbfpabizlkgan\nnpybkhyu\njqyhismeyf\nnab\nkobmcjvqgfmij\nfh\ndmontj\nlggmbfcwecn\nwrwguzebezdqe\nnmmnozy\ntzrcodnu\nvbekfhdkxkultgs\ndnenm\nhbpe\nczfdmvwtqdj\ngftkkevg", "10 20\nowopujiohbocynvpllmk\nyyprqugbejvhi\nagrdbmotaastc\nzesafjoocdjnxgse\nr\nenlfylphtqjnrbo\njphnoumpdrebxtgbch\nfapki\nhbfptfbjhio\nsugzpa\nqojcadybsjedi", "20 10\niwbiucrjoj\nqvjewvdrgwgc\newwqyhtdzakryafqaacimthycyasyb\ncuoscayekvbsqokyfdmjnojkjennf\nhkuv\njtdgbespjdtbc\ngeujitsrlqihoulvwuobnfospq\nzqhnlqxacchxhyeehnpfwdjnwvj\nxicsaoyfgtdbwqfrdgaiyn\natgshewfkuxaipizcdev\nvp\nyblkfmqsj\nyevxolvycyrrooosberqzrabefdckg\nrytykrlgttc\nafphunqbtydppxotf\nnkfoatpikdg\njwskqdsnymehilufkjzcjbwlixy\nwswr\nwsuhgjvzgppyeoxqrftpvmdlxqotl\nyivyjfuqxstysxgmmqutmd\nbymvqulyuzibelpuuwsoiuktv"], "outputs": ["0\n12", "18\n14\n36\n47\n14\n29\n30\n0\n84", "6\n1\n1", "1\n1\n4\n9", "3\n1\n9\n16\n4", "0\n1\n8\n1\n3\n1\n1\n1\n1\n1", "54\n89\n20\n128\n6\n32\n92\n127\n57\n54\n125\n34\n10\n94\n52", "96\n137\n171\n1\n139\n172\n29\n57\n28\n108", "107\n771\n630\n14\n130\n461\n646\n382\n341\n4\n65\n655\n100\n249\n108\n579\n9\n705\n416\n457"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
bee568ff74ad54cec8202b1f59786496 | Physics Practical | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher had made his friend Petya redo the experiment because the largest and the smallest results differed by more than two times. Vasya is lazy, and he does not want to redo the experiment. He wants to do the task and go home play computer games. So he decided to cheat: before Vasya shows the measurements to the teacher, he will erase some of them, so as to make the largest and the smallest results of the remaining measurements differ in no more than two times. In other words, if the remaining measurements have the smallest result *x*, and the largest result *y*, then the inequality *y*<=β€<=2Β·*x* must fulfill. Of course, to avoid the teacher's suspicion, Vasya wants to remove as few measurement results as possible from his notes.
Help Vasya, find what minimum number of measurement results he will have to erase from his notes so that the largest and the smallest of the remaining results of the measurements differed in no more than two times.
The first line contains integer *n* (2<=β€<=*n*<=β€<=105) β the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=5000) β the results of the measurements. The numbers on the second line are separated by single spaces.
Print a single integer β the minimum number of results Vasya will have to remove.
Sample Input
6
4 5 3 8 3 7
4
4 3 2 4
Sample Output
2
0
| {"inputs": ["6\n4 5 3 8 3 7", "4\n4 3 2 4", "6\n5 6 4 9 4 8", "4\n5 4 1 5", "2\n3 2", "10\n39 9 18 13 6 16 47 15 1 24", "20\n43 49 46 46 40 41 49 49 48 30 35 36 33 34 42 38 40 46 50 45", "30\n6 1 26 13 16 30 16 23 9 1 5 14 7 2 17 22 21 23 16 3 5 17 22 10 1 24 4 30 8 18", "50\n3 61 16 13 13 12 3 8 14 16 1 32 8 23 29 7 28 13 8 5 9 2 3 2 29 13 1 2 18 29 28 4 13 3 14 9 20 26 1 19 13 7 8 22 7 5 13 14 10 23", "10\n135 188 160 167 179 192 195 192 193 191", "15\n2 19 19 22 15 24 6 36 20 3 18 27 20 1 10", "25\n8 1 2 1 2 5 3 4 2 6 3 3 4 1 6 1 6 1 4 5 2 9 1 2 1", "40\n4784 4824 4707 4343 4376 4585 4917 4848 3748 4554 3390 4944 4845 3922 4617 4606 4815 4698 4595 4942 4327 4983 4833 4507 3721 4863 4633 4553 4991 4922 4733 4396 4747 4724 4886 4226 4025 4928 4990 4792", "60\n1219 19 647 1321 21 242 677 901 10 165 434 978 448 163 919 517 1085 10 516 920 653 1363 62 98 629 928 998 1335 1448 85 357 432 1298 561 663 182 2095 801 59 208 765 1653 642 645 1378 221 911 749 347 849 43 1804 62 73 613 143 860 297 278 148", "100\n4204 4719 4688 3104 4012 4927 4696 4614 4826 4792 3891 4672 4914 4740 4968 3879 4424 4755 3856 3837 4965 4939 4030 4941 4504 4668 4908 4608 3660 4822 4846 3945 4539 4819 4895 3746 4324 4233 4135 4956 4983 4546 4673 4617 3533 4851 4868 4838 4998 4769 4899 4578 3841 4974 4627 4990 4524 4939 4469 4233 4434 4339 4446 4979 4354 4912 4558 4609 4436 3883 4379 4927 4824 4819 4984 4660 4874 3732 4853 4268 4761 4402 4642 4577 4635 4564 4113 4896 4943 4122 4413 4597 3768 4731 4669 4958 4548 4263 4657 3651", "100\n1354 1797 588 3046 1290 745 217 907 113 381 523 935 791 415 92 1597 1739 1774 240 27 1262 2498 52 1339 1031 1355 2036 230 489 7 69 877 530 2664 1230 940 2712 2651 3410 480 332 699 957 2257 1877 1940 452 1652 1216 3144 236 165 1109 888 1649 346 24 183 1061 1226 2694 3225 2021 1145 907 1671 1599 3395 942 1959 555 1281 675 1125 1386 732 1081 326 256 26 1009 1772 2687 1173 491 709 390 992 519 203 1029 1381 846 1515 705 2859 282 147 1824 299", "100\n2794 2201 4935 564 2876 4472 4196 2571 2260 1479 1451 3497 245 2805 4834 3872 4294 1299 937 2983 1458 3278 1098 2990 4447 4337 4388 947 3708 3382 3694 4562 3827 2312 3760 1181 2830 1256 1054 1583 2094 931 86 2526 998 3420 2248 3461 3662 1715 5 4123 1051 545 3704 1084 1916 695 794 121 1000 1611 3674 1910 4795 2805 825 2392 3551 1148 3738 4650 791 288 1064 2011 2991 2116 2179 3333 1303 498 1610 3092 1935 3450 3524 2624 1596 2801 2290 2297 2327 1602 4779 3135 1231 4203 3283 3580", "2\n1 5"], "outputs": ["2", "0", "1", "1", "0", "5", "0", "15", "29", "0", "6", "13", "0", "37", "0", "63", "51", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 71 | codeforces |
|
beedede080fa2c18f6b59e2bbe40ce40 | Malek Dance Club | As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2*n* members and coincidentally Natalia Fan Club also has 2*n* members. Each member of MDC is assigned a unique id *i* from 0 to 2*n*<=-<=1. The same holds for each member of NFC.
One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (*a*,<=*b*) such that member *a* from MDC dances with member *b* from NFC.
The complexity of a pairs' assignment is the number of pairs of dancing pairs (*a*,<=*b*) and (*c*,<=*d*) such that *a*<=<<=*c* and *b*<=><=*d*.
You are given a binary number of length *n* named *x*. We know that member *i* from MDC dances with member from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109<=+<=7).
Expression denotes applying Β«XORΒ» to numbers *x* and *y*. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as Β«^Β», in Pascal β Β«xorΒ».
The first line of input contains a binary number *x* of lenght *n*, (1<=β€<=*n*<=β€<=100).
This number may contain leading zeros.
Print the complexity of the given dance assignent modulo 1000000007 (109<=+<=7).
Sample Input
11
01
1
Sample Output
6
2
1
| {"inputs": ["11", "01", "1", "1111111111111111111111111111111111", "0000000000000000000000000000000000000", "11111111111111111111111111111111111000000000000000000000000000", "00000000000000000000111111111111111111111111111111111111111111", "10100101000010011110101011011110001", "01010100001010111111001111001000101010010101000111011011111000", "10001010011010010101101010111001001001011110110101011000010100110", "00001100100101000111111100110010001101001000011110110000", "01100010011001101100001000000101001000101101000110011100101101111101010100000011101011100", "100111100", "11110111000110101111100100111110000011", "1000101010000101111110100110011110000011000110001111001001000110110011110110111110100", "0110011110111000001101001010101000011011101001001101000000111101010101111101010011101001111010111001", "0111001111110010000001111100110100111110001100100001111111110000010010111010010010010111000110001111", "1000000001101010101011111001001101011100011000010000100101001111001000110100100001110001100001000001", "1101010110001010100110011011101011010100010001110100010011011100011011000101110001010101110001101011", "1000001010111011110011111110011001011111011001110011100101111110100110111001100001110000011101011011", "10", "01", "00", "11", "0", "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "10110", "1100110010110011001011001100101100110010110011001111001100101100110010110011001011001100101100100010"], "outputs": ["6", "2", "1", "68817500", "0", "774857564", "738177230", "374541417", "629793317", "276731670", "526794740", "67141264", "80896", "448062885", "532893377", "416862683", "777947548", "759144998", "383088952", "928069440", "4", "2", "0", "6", "0", "0", "261536897", "352", "499547155"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 22 | codeforces |
|
bf3e927823c777d2ef7bd32bc83e59eb | Easter Eggs | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
The only line contains an integer *n* β the amount of eggs (7<=β€<=*n*<=β€<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Sample Input
8
13
Sample Output
ROYGRBIV
ROYGBIVGBIVYG
| {"inputs": ["8", "13", "7", "10", "14", "50", "9", "11", "12", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "28", "29", "34", "43", "61", "79", "81", "92", "95", "96", "97", "98", "99", "100"], "outputs": ["ROYGBIVG", "ROYGBIVOYGBIV", "ROYGBIV", "ROYGBIVYGB", "ROYGBIVROYGBIV", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG", "ROYGBIVGB", "ROYGBIVYGBI", "ROYGBIVOYGBI", "ROYGBIVROYGBIVG", "ROYGBIVROYGBIVGB", "ROYGBIVROYGBIVYGB", "ROYGBIVROYGBIVYGBI", "ROYGBIVROYGBIVOYGBI", "ROYGBIVROYGBIVOYGBIV", "ROYGBIVROYGBIVROYGBIV", "ROYGBIVROYGBIVROYGBIVG", "ROYGBIVROYGBIVROYGBIVGB", "ROYGBIVROYGBIVROYGBIVYGB", "ROYGBIVROYGBIVROYGBIVYGBI", "ROYGBIVROYGBIVROYGBIVROYGBIV", "ROYGBIVROYGBIVROYGBIVROYGBIVG", "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG", "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 274 | codeforces |
|
bf4dd0423ecea20ddef0b68b094f200c | Holiday Of Equality | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland).
You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
The first line contains the integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=β€<=*a**i*<=β€<=106)Β β the welfare of the *i*-th citizen.
In the only line print the integer *S*Β β the minimum number of burles which are had to spend.
Sample Input
5
0 1 2 3 4
5
1 1 0 1 1
3
1 3 1
1
12
Sample Output
10140 | {"inputs": ["5\n0 1 2 3 4", "5\n1 1 0 1 1", "3\n1 3 1", "1\n12", "3\n1 2 3", "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353", "3\n1 3 2", "3\n2 1 3", "3\n2 3 1", "3\n3 1 2", "3\n3 2 1", "1\n228503", "2\n32576 550340", "3\n910648 542843 537125", "4\n751720 572344 569387 893618", "6\n433864 631347 597596 794426 713555 231193", "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107", "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025", "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763", "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351", "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642", "1\n0", "1\n1000000", "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 0 0 0", "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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\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 1000000", "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 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "3\n0 0 0", "50\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", "3\n5 0 0", "5\n2 10 0 0 0"], "outputs": ["10", "1", "4", "0", "3", "5464380", "9535765", "3", "3", "3", "3", "3", "0", "517764", "741328", "787403", "1364575", "4647430", "13488674", "21993384", "26984185", "32816391", "0", "0", "0", "99000000", "99000000", "99000000", "0", "0", "10", "38"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1,122 | codeforces |
|
bf66bc37c82f2c30ec50a774ce6d0932 | Coat of Anticubism | As some of you know, cubism is a trend in art, where the problem of constructing volumetrical shape on a plane with a combination of three-dimensional geometric shapes comes to the fore.
A famous sculptor Cicasso, whose self-portrait you can contemplate, hates cubism. He is more impressed by the idea to transmit two-dimensional objects through three-dimensional objects by using his magnificent sculptures. And his new project is connected with this. Cicasso wants to make a coat for the haters of anticubism. To do this, he wants to create a sculpture depicting a well-known geometric primitive β convex polygon.
Cicasso prepared for this a few blanks, which are rods with integer lengths, and now he wants to bring them together. The *i*-th rod is a segment of length *l**i*.
The sculptor plans to make a convex polygon with a nonzero area, using all rods he has as its sides. Each rod should be used as a side to its full length. It is forbidden to cut, break or bend rods. However, two sides may form a straight angle .
Cicasso knows that it is impossible to make a convex polygon with a nonzero area out of the rods with the lengths which he had chosen. Cicasso does not want to leave the unused rods, so the sculptor decides to make another rod-blank with an integer length so that his problem is solvable. Of course, he wants to make it as short as possible, because the materials are expensive, and it is improper deed to spend money for nothing.
Help sculptor!
The first line contains an integer *n* (3<=β€<=*n*<=β€<=105) β a number of rod-blanks.
The second line contains *n* integers *l**i* (1<=β€<=*l**i*<=β€<=109) β lengths of rods, which Cicasso already has. It is guaranteed that it is impossible to make a polygon with *n* vertices and nonzero area using the rods Cicasso already has.
Print the only integer *z* β the minimum length of the rod, so that after adding it it can be possible to construct convex polygon with (*n*<=+<=1) vertices and nonzero area from all of the rods.
Sample Input
3
1 2 1
5
20 4 3 2 1
Sample Output
1
11
| {"inputs": ["3\n1 2 1", "5\n20 4 3 2 1", "7\n77486105 317474713 89523018 332007362 7897847 949616701 54820086", "14\n245638694 2941428 4673577 12468 991349408 44735727 14046308 60637707 81525 104620306 88059371 53742651 8489205 3528194", "19\n479740 7703374 196076708 180202968 579604 17429 16916 11989886 30832424 6384983 8937497 431 62955 48167457 898566333 29534955 1485775 848444 372839845", "35\n306260 278 43508628 54350745 222255 842526 39010821 10627 14916465 3059978 61449 503809 2820 1609513 196062 65695 270869 15079297 2885093 189306 4682268 422616382 1642346 82340 6 2 975464673 1388191 70110665 272855 253160079 1849635 7837751 274070 10394", "53\n1014364 40727 75774 243769 314 406417 5272684 14138 10640282 64955 2763 5667043 2121887 204672692 567643 60183 5183 11361359 2792918 199155 174809 16182540 21 392221 19434423 9140891 159733 15438 67903 3816799 616 429181 30392293 413992581 10847741 20771 16366654 1163 414283 156163 55907108 310278 95949614 185865 976650886 197610 87 61264 4586815 107764 26390852 331828 541", "3\n1 1 1000000000", "10\n1 2 3 4 5 6 7 8 9 1000000000", "5\n100000000 100000000 100000000 100000000 500000000", "3\n300000000 300000000 600000000", "5\n10 4 3 2 1", "3\n800000000 1 1", "3\n1000000000 1 1"], "outputs": ["1", "11", "70407571", "360142248", "2404943", "34445194", "25390787", "999999999", "999999956", "100000001", "1", "1", "799999999", "999999999"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 147 | codeforces |
|
bf68fad205ecadb130b7e87b5aac8a68 | Chris and Road | And while Mishka is enjoying her trip...
Chris is a little brown bear. No one knows, where and when he met Mishka, but for a long time they are together (excluding her current trip). However, best friends are important too. John is Chris' best friend.
Once walking with his friend, John gave Chris the following problem:
At the infinite horizontal road of width *w*, bounded by lines *y*<==<=0 and *y*<==<=*w*, there is a bus moving, presented as a convex polygon of *n* vertices. The bus moves continuously with a constant speed of *v* in a straight *Ox* line in direction of decreasing *x* coordinates, thus in time only *x* coordinates of its points are changing. Formally, after time *t* each of *x* coordinates of its points will be decreased by *vt*.
There is a pedestrian in the point (0,<=0), who can move only by a vertical pedestrian crossing, presented as a segment connecting points (0,<=0) and (0,<=*w*) with any speed not exceeding *u*. Thus the pedestrian can move only in a straight line *Oy* in any direction with any speed not exceeding *u* and not leaving the road borders. The pedestrian can instantly change his speed, thus, for example, he can stop instantly.
Please look at the sample note picture for better understanding.
We consider the pedestrian is hit by the bus, if at any moment the point he is located in lies strictly inside the bus polygon (this means that if the point lies on the polygon vertex or on its edge, the pedestrian is not hit by the bus).
You are given the bus position at the moment 0. Please help Chris determine minimum amount of time the pedestrian needs to cross the road and reach the point (0,<=*w*) and not to be hit by the bus.
The first line of the input contains four integers *n*, *w*, *v*, *u* (3<=β€<=*n*<=β€<=10<=000, 1<=β€<=*w*<=β€<=109, 1<=β€<=*v*,<=<=*u*<=β€<=1000)Β β the number of the bus polygon vertices, road width, bus speed and pedestrian speed respectively.
The next *n* lines describes polygon vertices in counter-clockwise order. *i*-th of them contains pair of integers *x**i* and *y**i* (<=-<=109<=β€<=*x**i*<=β€<=109, 0<=β€<=*y**i*<=β€<=*w*)Β β coordinates of *i*-th polygon point. It is guaranteed that the polygon is non-degenerate.
Print the single real *t*Β β the time the pedestrian needs to croos the road and not to be hit by the bus. The answer is considered correct if its relative or absolute error doesn't exceed 10<=-<=6.
Sample Input
5 5 1 2
1 2
3 1
4 3
3 4
1 4
Sample Output
5.0000000000 | {"inputs": ["5 5 1 2\n1 2\n3 1\n4 3\n3 4\n1 4", "3 3 5 2\n3 1\n4 0\n5 1", "3 3 2 4\n0 1\n2 1\n1 2", "3 3 1 1\n0 0\n1 1\n0 2", "9 10 5 2\n22 5\n25 0\n29 0\n31 2\n32 5\n31 8\n29 10\n25 10\n23 8", "10 10 2 4\n-4 5\n-3 2\n-1 0\n3 0\n5 2\n6 5\n5 8\n3 10\n-1 10\n-2 9", "10 10 1 4\n-1 5\n0 2\n2 0\n5 0\n7 1\n9 5\n8 8\n6 10\n2 10\n0 8", "10 10 1 1\n5 5\n7 1\n8 0\n12 0\n14 2\n15 5\n14 8\n12 10\n8 10\n6 8", "10 1000 4 5\n-175 23\n-52 1\n129 24\n412 255\n399 767\n218 938\n110 982\n62 993\n-168 979\n-501 650", "10 1000 8 4\n1015 375\n1399 10\n1605 11\n1863 157\n1934 747\n1798 901\n1790 907\n1609 988\n1404 991\n1177 883", "10 1000 2 8\n-75 224\n-56 197\n0 135\n84 72\n264 6\n643 899\n572 944\n282 996\n110 943\n1 866", "10 1000 6 2\n1901 411\n1933 304\n2203 38\n2230 27\n2250 21\n2396 0\n2814 230\n2705 891\n2445 997\n2081 891", "10 1000 4 7\n-253 81\n67 2\n341 117\n488 324\n489 673\n380 847\n62 998\n20 1000\n-85 989\n-378 803", "10 1000 4 1\n2659 245\n2715 168\n2972 14\n3229 20\n3232 21\n3479 187\n3496 210\n3370 914\n3035 997\n2938 977", "10 1000 2 2\n60 123\n404 0\n619 56\n715 121\n740 144\n614 947\n566 968\n448 997\n300 992\n270 986", "10 1000 10 4\n554 284\n720 89\n788 50\n820 35\n924 7\n1324 115\n1309 897\n1063 997\n592 782\n584 770", "10 1000 4 8\n-261 776\n-94 67\n-45 42\n23 18\n175 0\n415 72\n258 989\n183 999\n114 998\n-217 833", "10 1000 10 2\n2731 286\n3154 1\n3590 210\n3674 406\n3667 625\n3546 844\n3275 991\n3154 999\n2771 783\n2754 757", "10 1000 59 381\n131 195\n303 53\n528 0\n546 0\n726 41\n792 76\n917 187\n755 945\n220 895\n124 796", "10 1000 519 882\n-407 135\n-222 25\n-211 22\n-168 11\n-90 1\n43 12\n312 828\n175 939\n-174 988\n-329 925", "10 1000 787 576\n-126 73\n-20 24\n216 7\n314 34\n312 967\n288 976\n99 999\n-138 920\n-220 853\n-308 734", "10 1000 35 722\n320 31\n528 1\n676 34\n979 378\n990 563\n916 768\n613 986\n197 902\n164 876\n34 696", "10 1000 791 415\n613 191\n618 185\n999 0\n1023 0\n1084 6\n1162 25\n1306 100\n1351 138\n713 905\n559 724", "10 1000 763 109\n-449 324\n-398 224\n-357 170\n45 1\n328 107\n406 183\n428 212\n65 998\n-160 967\n-262 914", "10 1000 12 255\n120 71\n847 668\n814 741\n705 877\n698 883\n622 935\n473 991\n176 958\n131 936\n41 871", "10 1000 471 348\n-161 383\n339 0\n398 5\n462 19\n606 86\n770 728\n765 737\n747 768\n546 949\n529 956", "10 1000 35 450\n259 41\n383 6\n506 2\n552 9\n852 193\n943 383\n908 716\n770 890\n536 994\n28 757", "10 1000 750 426\n1037 589\n1215 111\n1545 0\n1616 8\n1729 42\n2026 445\n1964 747\n1904 831\n1763 942\n1757 945", "10 1000 505 223\n1564 401\n1689 158\n2078 1\n2428 168\n2477 767\n2424 836\n1929 984\n1906 978\n1764 907\n1723 875", "10 1000 774 517\n-252 138\n150 3\n501 211\n543 282\n575 367\n534 736\n382 908\n84 1000\n-78 970\n-344 743", "10 1000 22 255\n70 266\n272 61\n328 35\n740 55\n850 868\n550 999\n448 996\n371 980\n302 954\n62 718", "10 1000 482 756\n114 363\n190 207\n1016 230\n1039 270\n912 887\n629 999\n514 993\n439 975\n292 898\n266 877", "10 1000 750 154\n-154 43\n-134 35\n-41 8\n127 6\n387 868\n179 983\n77 999\n26 999\n-51 990\n-239 909", "10 1000 998 596\n1681 18\n2048 59\n2110 98\n2201 185\n2282 327\n2250 743\n2122 893\n1844 999\n1618 960\n1564 934", "10 1000 458 393\n826 363\n1241 4\n1402 9\n1441 18\n1800 417\n1804 555\n1248 997\n1207 990\n1116 962\n1029 916", "10 1000 430 983\n-206 338\n-86 146\n221 2\n766 532\n531 925\n507 939\n430 973\n369 989\n29 940\n-170 743", "5 5 100 2\n1 2\n3 1\n4 3\n3 4\n1 4", "3 10 3 2\n1 5\n2 2\n2 8"], "outputs": ["5.0000000000", "1.5000000000", "1.5000000000", "3.0000000000", "5.0000000000", "4.5000000000", "10.2500000000", "22.0000000000", "252.0000000000", "447.8750000000", "334.1250000000", "899.3333333333", "218.5714285714", "1787.2500000000", "798.0000000000", "353.6500000000", "219.7500000000", "814.9000000000", "2.6246719160", "1.2030330437", "2.0760668149", "1.3850415512", "3.8197492879", "9.2241153342", "3.9215686275", "3.9130609854", "28.3139682540", "2.3474178404", "8.5946721130", "2.1733990074", "3.9215686275", "3.1264023359", "6.6238787879", "1.6778523490", "5.6450159450", "2.2574889399", "2.5000000000", "5.0000000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
bf78b5d20ae69dfbd2374b041a0e3b55 | Valera and Tubes | Valera has got a rectangle table consisting of *n* rows and *m* columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row *x* and column *y* by a pair of integers (*x*,<=*y*).
Valera wants to place exactly *k* tubes on his rectangle table. A tube is such sequence of table cells (*x*1,<=*y*1), (*x*2,<=*y*2), ..., (*x**r*,<=*y**r*), that:
- *r*<=β₯<=2; - for any integer *i* (1<=β€<=*i*<=β€<=*r*<=-<=1) the following equation |*x**i*<=-<=*x**i*<=+<=1|<=+<=|*y**i*<=-<=*y**i*<=+<=1|<==<=1 holds; - each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
- no pair of tubes has common cells; - each cell of the table belongs to some tube.
Help Valera to arrange *k* tubes on his rectangle table in a fancy manner.
The first line contains three space-separated integers *n*,<=*m*,<=*k* (2<=β€<=*n*,<=*m*<=β€<=300; 2<=β€<=2*k*<=β€<=*n*Β·*m*) β the number of rows, the number of columns and the number of tubes, correspondingly.
Print *k* lines. In the *i*-th line print the description of the *i*-th tube: first print integer *r**i* (the number of tube cells), then print 2*r**i* integers *x**i*1,<=*y**i*1,<=*x**i*2,<=*y**i*2,<=...,<=*x**ir**i*,<=*y**ir**i* (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Sample Input
3 3 3
2 3 1
Sample Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
6 1 1 1 2 1 3 2 3 2 2 2 1
| {"inputs": ["3 3 3", "2 3 1", "2 3 1", "300 300 2", "300 300 150", "300 299 299", "300 300 45000", "300 299 44850", "2 2 2", "2 3 3", "3 3 4", "5 5 12", "7 5 17", "135 91 4352", "32 27 153", "74 83 2667", "296 218 5275", "89 82 2330", "15 68 212", "95 4 177", "60 136 8", "91 183 7827", "2 15 3", "139 275 10770", "114 298 7143", "260 182 9496", "42 297 3703", "236 156 9535", "201 226 1495", "299 299 100", "299 298 100", "298 299 100", "299 299 2", "299 299 1", "298 299 1", "299 298 11", "298 300 12", "298 2 1", "2 298 1", "300 300 500", "300 300 501", "300 300 44999", "5 5 3", "2 4 3"], "outputs": ["3 1 1 1 2 1 3\n3 2 1 2 2 2 3\n3 3 1 3 2 3 3", "6 1 1 1 2 1 3 2 3 2 2 2 1", "6 1 1 1 2 1 3 2 3 2 2 2 1", "2 1 1 1 2\n89998 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 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 10...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 2 2 2 1", "2 1 1 1 2\n2 1 3 2 3\n2 2 2 2 1", "2 1 1 1 2\n2 1 3 2 3\n2 2 2 2 1\n3 3 1 3 2 3 3", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 2 5\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 3 5 4 5\n2 4 4 4 3\n2 4 2 4 1\n2 5 1 5 2\n3 5 3 5 4 5 5", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 2 5\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 3 5 4 5\n2 4 4 4 3\n2 4 2 4 1\n2 5 1 5 2\n2 5 3 5 4\n2 5 5 6 5\n2 6 4 6 3\n2 6 2 6 1\n2 7 1 7 2\n3 7 3 7 4 7 5", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 2 27\n2 2 26 2 25\n2 2 24 2 23\n2 2 22 2 21\n2 2 20 2 19\n2 2 18 2 17\n2 2 16 2 15\n2 2 14 2 13\n2 2 12 2 11\n2 2 10 2 9\n2 2 8 2 7\n2 2 6 2 5\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 3 5 3 6\n2 3 7 3 8\n2 3 9 3 10\n2 3 11 3 12\n2 3 13 3 14\n2 3 15 3 16\n2 3 17 3 18\n2 3 19 3 20\n2 3 21 3 22\n2 3 23 3 24\n2 3 25 3 26\n2 3 27 4 27\n2 4 2...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 2 68 2 67\n2 2 66 2 65\n2 2 64 2 63\n2 2 62 2 61\n2 2 60 2 59\n2 2 58 2 57\n...", "2 1 1 1 2\n2 1 3 1 4\n2 2 4 2 3\n2 2 2 2 1\n2 3 1 3 2\n2 3 3 3 4\n2 4 4 4 3\n2 4 2 4 1\n2 5 1 5 2\n2 5 3 5 4\n2 6 4 6 3\n2 6 2 6 1\n2 7 1 7 2\n2 7 3 7 4\n2 8 4 8 3\n2 8 2 8 1\n2 9 1 9 2\n2 9 3 9 4\n2 10 4 10 3\n2 10 2 10 1\n2 11 1 11 2\n2 11 3 11 4\n2 12 4 12 3\n2 12 2 12 1\n2 13 1 13 2\n2 13 3 13 4\n2 14 4 14 3\n2 14 2 14 1\n2 15 1 15 2\n2 15 3 15 4\n2 16 4 16 3\n2 16 2 16 1\n2 17 1 17 2\n2 17 3 17 4\n2 18 4 18 3\n2 18 2 18 1\n2 19 1 19 2\n2 19 3 19 4\n2 20 4 20 3\n2 20 2 20 1\n2 21 1 21 2\n2 21 3 21 4\n2...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n8146 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n26 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 2 15 2 14 2 13 2 12 2 11 2 10 2 9 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n89399 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 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 10...", "89401 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 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 102 1...", "89102 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 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 102 1...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n89082 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n89378 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1...", "596 1 1 1 2 2 2 2 1 3 1 3 2 4 2 4 1 5 1 5 2 6 2 6 1 7 1 7 2 8 2 8 1 9 1 9 2 10 2 10 1 11 1 11 2 12 2 12 1 13 1 13 2 14 2 14 1 15 1 15 2 16 2 16 1 17 1 17 2 18 2 18 1 19 1 19 2 20 2 20 1 21 1 21 2 22 2 22 1 23 1 23 2 24 2 24 1 25 1 25 2 26 2 26 1 27 1 27 2 28 2 28 1 29 1 29 2 30 2 30 1 31 1 31 2 32 2 32 1 33 1 33 2 34 2 34 1 35 1 35 2 36 2 36 1 37 1 37 2 38 2 38 1 39 1 39 2 40 2 40 1 41 1 41 2 42 2 42 1 43 1 43 2 44 2 44 1 45 1 45 2 46 2 46 1 47 1 47 2 48 2 48 1 49 1 49 2 50 2 50 1 51 1 51 2 52 2 52 1 53 1 ...", "596 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 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1 62 1 63 1 64 1 65 1 66 1 67 1 68 1 69 1 70 1 71 1 72 1 73 1 74 1 75 1 76 1 77 1 78 1 79 1 80 1 81 1 82 1 83 1 84 1 85 1 86 1 87 1 88 1 89 1 90 1 91 1 92 1 93 1 94 1 95 1 96 1 97 1 98 1 99 1 100 1 101 1 102 1 1...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n2 1 5 1 6\n2 1 7 1 8\n2 1 9 1 10\n2 1 11 1 12\n2 1 13 1 14\n2 1 15 1 16\n2 1 17 1 18\n2 1 19 1 20\n2 1 21 1 22\n2 1 23 1 24\n2 1 25 1 26\n2 1 27 1 28\n2 1 29 1 30\n2 1 31 1 32\n2 1 33 1 34\n2 1 35 1 36\n2 1 37 1 38\n2 1 39 1 40\n2 1 41 1 42\n2 1 43 1 44\n2 1 45 1 46\n2 1 47 1 48\n2 1 49 1 50\n2 1 51 1 52\n2 1 53 1 54\n2 1 55 1 56\n2 1 57 1 58\n2 1 59 1 60\n2 1 61 1 62\n2 1 63 1 64\n2 1 65 1 66\n2 1 67 1 68\n2 1 69 1 70\n2 1 71 1 72\n2 1 73 1 74\n2 1 75 1 76\n2 1 77 1 78\n2 1 79 1 80\n...", "2 1 1 1 2\n2 1 3 1 4\n21 1 5 2 5 2 4 2 3 2 2 2 1 3 1 3 2 3 3 3 4 3 5 4 5 4 4 4 3 4 2 4 1 5 1 5 2 5 3 5 4 5 5", "2 1 1 1 2\n2 1 3 1 4\n4 2 4 2 3 2 2 2 1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 91 | codeforces |
|
bf841357522a9a2799b0b9ada43e47dd | Ksusha and Array | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=β€<=*n*<=β€<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the array elements.
Print a single integer β the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them.
Sample Input
3
2 2 4
5
2 1 3 1 6
3
2 3 5
Sample Output
2
1
-1
| {"inputs": ["3\n2 2 4", "5\n2 1 3 1 6", "3\n2 3 5", "1\n331358794", "5\n506904227 214303304 136194869 838256937 183952885", "2\n500000000 1000000000", "2\n4 6", "5\n10 8 6 4 2", "2\n6 10", "1\n1000000000", "2\n6 8", "5\n2 2 2 2 1000000000", "2\n6 4"], "outputs": ["2", "1", "-1", "331358794", "-1", "500000000", "-1", "2", "-1", "1000000000", "-1", "2", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 187 | codeforces |
|
c008ffb743cb2d9e14ef24a4fd1394ae | Mages and Monsters | Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.
Vova's character can learn new spells during the game. Every spell is characterized by two values *x**i* and *y**i* β damage per second and mana cost per second, respectively. Vova doesn't have to use a spell for an integer amount of seconds. More formally, if he uses a spell with damage *x* and mana cost *y* for *z* seconds, then he will deal *x*Β·*z* damage and spend *y*Β·*z* mana (no rounding). If there is no mana left (mana amount is set in the start of the game and it remains the same at the beginning of every fight), then character won't be able to use any spells. It is prohibited to use multiple spells simultaneously.
Also Vova can fight monsters. Every monster is characterized by two values *t**j* and *h**j* β monster kills Vova's character in *t**j* seconds and has *h**j* health points. Mana refills after every fight (or Vova's character revives with full mana reserve), so previous fights have no influence on further ones.
Vova's character kills a monster, if he deals *h**j* damage to it in no more than *t**j* seconds using his spells (it is allowed to use more than one spell in a fight) and spending no more mana than he had at the beginning of the fight. If monster's health becomes zero exactly in *t**j* seconds (it means that the monster and Vova's character kill each other at the same time), then Vova wins the fight.
You have to write a program which can answer two types of queries:
- 1 *x* *y* β Vova's character learns new spell which deals *x* damage per second and costs *y* mana per second. - 2 *t* *h* β Vova fights the monster which kills his character in *t* seconds and has *h* health points.
Note that queries are given in a different form. Also remember that Vova's character knows no spells at the beginning of the game.
For every query of second type you have to determine if Vova is able to win the fight with corresponding monster.
The first line contains two integer numbers *q* and *m* (2<=β€<=*q*<=β€<=105,<=1<=β€<=*m*<=β€<=1012) β the number of queries and the amount of mana at the beginning of every fight.
*i*-th of each next *q* lines contains three numbers *k**i*, *a**i* and *b**i* (1<=β€<=*k**i*<=β€<=2,<=1<=β€<=*a**i*,<=*b**i*<=β€<=106).
Using them you can restore queries this way: let *j* be the index of the last query of second type with positive answer (*j*<==<=0 if there were none of these).
- If *k**i*<==<=1, then character learns spell with *x*<==<=(*a**i*<=+<=*j*) *mod* 106<=+<=1, *y*<==<=(*b**i*<=+<=*j*) *mod* 106<=+<=1. - If *k**i*<==<=2, then you have to determine if Vova is able to win the fight against monster with *t*<==<=(*a**i*<=+<=*j*) *mod* 106<=+<=1, *h*<==<=(*b**i*<=+<=*j*) *mod* 106<=+<=1.
For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise.
Sample Input
3 100
1 4 9
2 19 49
2 19 49
Sample Output
YES
NO
| {"inputs": ["3 100\n1 4 9\n2 19 49\n2 19 49", "10 442006988299\n2 10 47\n1 9 83\n1 15 24\n2 19 47\n2 75 99\n2 85 23\n2 8 33\n2 9 82\n1 86 49\n2 71 49", "2 424978864039\n2 7 3\n2 10 8", "3 10\n1 1 1\n2 1 1\n2 999999 999999", "12 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n2 999991 11\n2 999991 10", "15 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n1 2 999992\n2 6 256\n2 7 256\n1 2 999988\n2 2 252", "3 12\n1 99 9\n1 49 1\n2 1 149"], "outputs": ["YES\nNO", "NO\nYES\nYES\nYES\nYES\nYES\nYES", "NO\nNO", "YES\nYES", "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES", "NO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nYES", "YES"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c01e2b377cf5803a3db4c18e169a42d5 | Tennis Game | Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores *t* points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of *s* sets, he wins the match and the match is over. Here *s* and *t* are some positive integer numbers.
To spice it up, Petya and Gena choose new numbers *s* and *t* before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores *t* points and the match is over as soon as one of the players wins *s* sets.
Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers *s* and *t* for the given match are also lost. The players now wonder what values of *s* and *t* might be. Can you determine all the possible options?
The first line contains a single integer *n*Β β the length of the sequence of games (1<=β€<=*n*<=β€<=105).
The second line contains *n* space-separated integers *a**i*. If *a**i*<==<=1, then the *i*-th serve was won by Petya, if *a**i*<==<=2, then the *i*-th serve was won by Gena.
It is not guaranteed that at least one option for numbers *s* and *t* corresponds to the given record.
In the first line print a single number *k*Β β the number of options for numbers *s* and *t*.
In each of the following *k* lines print two integers *s**i* and *t**i*Β β the option for numbers *s* and *t*. Print the options in the order of increasing *s**i*, and for equal *s**i*Β β in the order of increasing *t**i*.
Sample Input
5
1 2 1 2 1
4
1 1 1 1
4
1 2 1 2
8
2 1 2 1 1 1 1 1
Sample Output
2
1 3
3 1
3
1 4
2 2
4 1
0
3
1 6
2 3
6 1
| {"inputs": ["5\n1 2 1 2 1", "4\n1 1 1 1", "4\n1 2 1 2", "8\n2 1 2 1 1 1 1 1", "14\n2 1 2 1 1 1 1 2 1 1 2 1 2 1", "10\n1 1 2 2 1 1 2 2 1 1", "20\n1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 1", "186\n2 1 2 1 1 1 1 1 2 1 1 2 2 2 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 2 1 1 1 2 2 2 2 2 2 2 1 2 1 2 1 1 2 1 2 2 1 1 1 1 1 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 1 1 2 1 1 2 2 2 2 2 2 1 1 1 1 1 2 1 1 2 2 1 2 2 1 1 1 1 1 2 2 1 1 2 2 1 2 2 2 1 2 1 2 1 1 2 1 2 2 2 2 1 2 1 2 2 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 2 1 2 2 1 1 2 1 1 1 1 2 1 1", "82\n1 1 1 2 2 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2", "83\n1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 2 2 2 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 2 2 2 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 1 1", "1\n1", "1\n2"], "outputs": ["2\n1 3\n3 1", "3\n1 4\n2 2\n4 1", "0", "3\n1 6\n2 3\n6 1", "3\n1 9\n3 3\n9 1", "4\n1 6\n2 3\n3 2\n6 1", "0", "8\n1 100\n2 50\n6 11\n8 8\n19 4\n25 3\n40 2\n100 1", "0", "5\n1 45\n3 10\n3 15\n4 7\n45 1", "1\n1 1", "1\n1 1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c0315ec500973071a258e2b530a085a5 | Maxim Buys an Apartment | Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has *n* apartments that are numbered from 1 to *n* and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.
Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly *k* already inhabited apartments, but he doesn't know their indices yet.
Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.
The only line of the input contains two integers: *n* and *k* (1<=β€<=*n*<=β€<=109, 0<=β€<=*k*<=β€<=*n*).
Print the minimum possible and the maximum possible number of apartments good for Maxim.
Sample Input
6 3
Sample Output
1 3
| {"inputs": ["6 3", "10 1", "10 9", "8 0", "8 8", "966871928 890926970", "20 2", "1 0", "1 1", "2 0", "2 1", "2 2", "7 2", "8 3", "9 4", "10 3", "10 4", "10 5", "1000 1000", "1000 333", "1000 334", "999 333", "999 334", "998 332", "998 333", "89 4", "66 50", "88 15", "95 43", "900 344", "777 113", "964 42", "982 867", "1000000000 0", "1000000000 1000000000", "1000000000 333333333", "1000000000 333333334", "999999999 333333333", "999999999 333333334", "999999998 333333332", "999999998 333333333", "78602604 42160832", "35679021 9137902", "41949373 13173511", "77855558 49163875", "87187123 2851901", "66849627 25004217", "873046672 517064947", "639857373 1393427", "637563683 69636269", "911669737 141068293", "547575919 313272818", "955020006 297895809", "10 4", "11 3", "10 3", "4 1", "9 3", "7 2", "7 3", "12 5", "8 3", "1000 8"], "outputs": ["1 3", "1 2", "1 1", "0 0", "0 0", "1 75944958", "1 4", "0 0", "0 0", "0 0", "1 1", "0 0", "1 4", "1 5", "1 5", "1 6", "1 6", "1 5", "0 0", "1 666", "1 666", "1 666", "1 665", "1 664", "1 665", "1 8", "1 16", "1 30", "1 52", "1 556", "1 226", "1 84", "1 115", "0 0", "0 0", "1 666666666", "1 666666666", "1 666666666", "1 666666665", "1 666666664", "1 666666665", "1 36441772", "1 18275804", "1 26347022", "1 28691683", "1 5703802", "1 41845410", "1 355981725", "1 2786854", "1 139272538", "1 282136586", "1 234303101", "1 595791618", "1 6", "1 6", "1 6", "1 2", "1 6", "1 4", "1 4", "1 7", "1 5", "1 16"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 82 | codeforces |
|
c0519a7dc6f0c45ebc244c6c22cec56d | Max History | You are given an array *a* of length *n*. We define *f**a* the following way:
- Initially *f**a*<==<=0, *M*<==<=1; - for every 2<=β€<=*i*<=β€<=*n* if *a**M*<=<<=*a**i* then we set *f**a*<==<=*f**a*<=+<=*a**M* and then set *M*<==<=*i*.
Calculate the sum of *f**a* over all *n*! permutations of the array *a* modulo 109<=+<=7.
Note: two elements are considered different if their indices differ, so for every array *a* there are exactly *n*! permutations.
The first line contains integer *n* (1<=β€<=*n*<=β€<=<=1 000 000) β the size of array *a*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=<=*a**i*<=β€<=<=109).
Print the only integer, the sum of *f**a* over all *n*! permutations of the array *a* modulo 109<=+<=7.
Sample Input
2
1 3
3
1 1 2
Sample Output
14 | {"inputs": ["2\n1 3", "3\n1 1 2", "6\n1 4 5 2 3 3", "8\n8 7 5 4 6 6 6 6", "8\n1 2 3 9 100 100 100 100", "1\n364489807", "1\n194945396", "9\n25401015 88843847 702650194 306965770 57623156 571088345 835502151 56113403 116176210", "3\n855856619 518546431 920370158", "7\n686312223 948248999 138090108 566544521 711825575 414057105 925454439", "5\n516767827 377951584 355810087 196333905 38926793", "9\n347223417 807654168 573530036 826123287 366028010 257025851 15406743 784063803 132844347", "7\n177679021 237356752 791250000 455912656 693129227 678510224 60382864", "7\n8134640 667059306 8969950 85702040 20230430 99994612 105359016", "1\n911130621", "4\n1 1 8 10"], "outputs": ["1", "4", "2928", "351360", "109296", "0", "0", "168126961", "604662698", "75238511", "733758401", "932879531", "14393405", "264207095", "0", "108"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 3 | codeforces |
|
c05fc5f9b4c21dc89887cfb96b7400ea | Colored Balls | There are *n* boxes with colored balls on the table. Colors are numbered from 1 to *n*. *i*-th box contains *a**i* balls, all of which have color *i*. You have to write a program that will divide all balls into sets such that:
- each ball belongs to exactly one of the sets, - there are no empty sets, - there is no set containing two (or more) balls of different colors (each set contains only balls of one color), - there are no two sets such that the difference between their sizes is greater than 1.
Print the minimum possible number of sets.
The first line contains one integer number *n* (1<=β€<=*n*<=β€<=500).
The second line contains *n* integer numbers *a*1,<=*a*2,<=... ,<=*a**n* (1<=β€<=*a**i*<=β€<=109).
Print one integer number β the minimum possible number of sets.
Sample Input
3
4 7 8
2
2 7
Sample Output
5
4
| {"inputs": ["3\n4 7 8", "2\n2 7", "1\n1", "1\n1000000000", "2\n1000000000 1", "2\n9 6", "2\n948507270 461613425", "5\n8 7 4 8 3", "5\n11703 91351 99 16279 50449", "20\n3 2 1 1 1 2 2 2 3 3 1 1 3 2 3 3 2 3 3 2", "20\n895 8894 6182 5852 9830 7562 8854 4004 5909 4979 6863 2987 3586 1319 513 5496 9543 9561 6590 5063", "200\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "200\n1 1 1 2 1 1 2 1 2 2 2 1 2 2 1 2 1 2 2 1 2 1 1 1 1 2 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 2 1 1 2 1 2 2 1 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 1 2 1 2 1 2 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 1 2 2 2 2 1 1 2 2 1 2 1 1 2 1 1 1 1 1 2 1", "200\n1 2 4 10 5 8 1 10 9 10 1 9 5 5 3 10 4 7 7 1 5 10 1 6 7 3 9 3 5 8 8 9 7 3 1 5 6 7 3 3 1 4 9 2 8 7 2 10 2 1 10 9 6 1 9 5 3 5 9 3 3 2 4 9 5 9 4 8 5 6 10 1 3 10 8 6 10 10 4 6 8 4 10 7 5 2 6 6 8 8 8 10 3 2 4 5 10 2 2 10 4 5 3 1 8 10 8 5 6 4 9 10 8 10 8 6 3 1 6 4 7 4 10 10 6 7 1 1 2 5 2 6 9 10 1 5 8 3 10 8 4 4 2 6 4 3 6 10 3 1 2 9 3 8 7 5 4 10 9 7 8 3 3 1 1 5 2 7 9 7 1 10 4 3 4 2 8 8 6 5 1 10 3 10 6 9 4 2 6 3 7 5 9 10 10 1 2 4 10 6", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "2\n1000000000 999999999", "2\n999999999 1000000000", "2\n500000000 999999998", "10\n1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000"], "outputs": ["5", "4", "1", "1", "500000001", "5", "2789", "8", "1701", "28", "2670", "200", "200", "610", "10", "2", "2", "3", "4500000001"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 5 | codeforces |
|
c086d2e71d8091df7b4eef2dd781beec | Valera and Number | Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given below:
Now Valera wonders: given the values *x*, *k* and *p*, what is the expected value of the resulting number *s*?
The first line of the input contains three integers *x*,<=*k*,<=*p* (1<=β€<=*x*<=β€<=109;Β 1<=β€<=*k*<=β€<=200;Β 0<=β€<=*p*<=β€<=100).
Print the required expected value. Your answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
Sample Input
1 1 50
5 3 0
5 3 25
Sample Output
1.0000000000000
3.0000000000000
1.9218750000000
| {"inputs": ["1 1 50", "5 3 0", "5 3 25", "1132123 200 0", "1213112 200 100", "490879136 12 75", "114566801 2 55", "331870050 6 98", "252615193 9 45", "224314221 19 51", "510823354 20 18", "573292218 200 77", "465672965 100 95", "853095531 50 72", "254290166 200 95", "206910020 200 4", "680841078 112 48", "92021679 54 25", "244974370 130 30", "870669648 101 37", "647275659 22 54", "366067081 15 70", "31708573 22 99", "38299352 98 68", "106105555 25 2", "536870912 200 50", "536870912 100 100", "536870912 100 0", "536870912 1 50", "536870912 1 100", "536870912 1 0", "536870912 200 100", "1000000000 200 50", "1000000000 200 100", "1000000000 200 0", "1000000000 100 50", "1000000000 24 20", "1000000000 12 4", "31 1 0", "536870911 200 50", "536870911 100 25", "536870911 100 75", "536870911 100 77", "536870911 100 11", "536870911 100 1", "536870912 200 1", "536870912 200 99"], "outputs": ["1.0000000000000", "3.0000000000000", "1.9218750000000", "0.0000000000000", "203.0000000000000", "3.3114133477211", "1.1000000000000", "6.4818567047040", "1.4355493665625", "1.5899951568248", "1.1217824259945", "3.5871884160548", "18.9376296087060", "2.8672052767888", "19.0494861521300", "1.0210764588937", "1.5078321592645", "1.1664654573827", "1.2150385000681", "1.3005166437271", "1.6854437311768", "2.6410955937423", "19.6485751296919", "2.4672029415358", "1.6204473866840", "1.5604085205096", "129.0000000000000", "2.0000000000000", "15.0000000000000", "30.0000000000000", "0.0000000000000", "229.0000000000000", "1.5604085205096", "209.0000000000000", "3.0000000000000", "1.5604085205095", "1.1262594299198", "1.5927927717949", "5.0000000000000", "1.5604085205096", "1.1664988130957", "3.2617068081606", "3.5871884160953", "1.0616588070835", "0.6327462477115", "1.2702354621557", "89.6300701436891"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c08a7770e7aaa6e439fb7923a9c9b201 | Two Melodies | Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time!
Alice has a sheet with *n* notes written on it. She wants to take two such non-empty non-intersecting subsequences that both of them form a melody and sum of their lengths is maximal.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Subsequence forms a melody when each two adjacent notes either differs by 1 or are congruent modulo 7.
You should write a program which will calculate maximum sum of lengths of such two non-empty non-intersecting subsequences that both of them form a melody.
The first line contains one integer number *n* (2<=β€<=*n*<=β€<=5000).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105) β notes written on a sheet.
Print maximum sum of lengths of such two non-empty non-intersecting subsequences that both of them form a melody.
Sample Input
4
1 2 4 5
6
62 22 60 61 48 49
Sample Output
4
5
| {"inputs": ["4\n1 2 4 5", "6\n62 22 60 61 48 49", "2\n1 4", "2\n5 4", "10\n9 6 8 5 5 2 8 9 2 2", "10\n7776 32915 1030 71664 7542 72359 65387 75222 95899 40333", "10\n1 1 1 1 1 1 1 1 1 1", "4\n15 11 28 17", "3\n1 36 6", "6\n3 12 4 12 5 6", "6\n7 20 21 22 23 28"], "outputs": ["4", "5", "2", "2", "9", "6", "10", "2", "3", "6", "6"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c0a0039fbe76bdb7d48cb9d1f504232e | System Administrator | Bob got a job as a system administrator in X corporation. His first task was to connect *n* servers with the help of *m* two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index *v* fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.
The first input line contains 3 space-separated integer numbers *n*, *m*, *v* (3<=β€<=*n*<=β€<=105,<=0<=β€<=*m*<=β€<=105,<=1<=β€<=*v*<=β€<=*n*), *n* β amount of servers, *m* β amount of direct connections, *v* β index of the server that fails and leads to the failure of the whole system.
If it is impossible to connect the servers in the required way, output -1. Otherwise output *m* lines with 2 numbers each β description of all the direct connections in the system. Each direct connection is described by two numbers β indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.
Sample Input
5 6 3
6 100 1
Sample Output
1 2
2 3
3 4
4 5
1 3
3 5
-1
| {"inputs": ["5 6 3", "6 100 1", "10 26 1", "20 155 1", "30 393 29", "50 535 8", "100 4283 65", "1000 51277 488", "10000 57971 8854", "100000 99999 41895", "99999 100000 66180", "99997 99997 72727", "100000 100000 100000", "100000 100000 1", "100000 99999 100000", "100000 99999 1", "100000 99998 100000", "100000 99998 1", "100000 0 100000", "100000 0 1", "10000 100000 10000", "10000 100000 1", "123 13527 42", "100 96943 65", "10 39377 1", "200 34305 75", "300 44552 1", "300 44552 300", "300 44553 1", "300 44553 300"], "outputs": ["1 3\n2 3\n4 3\n5 3\n1 2\n1 4", "-1", "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n4 5\n4 6\n4 7\n4 8", "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\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\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\n3 17\n3 18\n3 19\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\n4 18\n4 19\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\n5 19\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n6 13\n6 14\n6 15\n6 16...", "1 29\n2 29\n3 29\n4 29\n5 29\n6 29\n7 29\n8 29\n9 29\n10 29\n11 29\n12 29\n13 29\n14 29\n15 29\n16 29\n17 29\n18 29\n19 29\n20 29\n21 29\n22 29\n23 29\n24 29\n25 29\n26 29\n27 29\n28 29\n30 29\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\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\n3 4\n3 5\n3 6\n...", "1 8\n2 8\n3 8\n4 8\n5 8\n6 8\n7 8\n9 8\n10 8\n11 8\n12 8\n13 8\n14 8\n15 8\n16 8\n17 8\n18 8\n19 8\n20 8\n21 8\n22 8\n23 8\n24 8\n25 8\n26 8\n27 8\n28 8\n29 8\n30 8\n31 8\n32 8\n33 8\n34 8\n35 8\n36 8\n37 8\n38 8\n39 8\n40 8\n41 8\n42 8\n43 8\n44 8\n45 8\n46 8\n47 8\n48 8\n49 8\n50 8\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\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...", "1 65\n2 65\n3 65\n4 65\n5 65\n6 65\n7 65\n8 65\n9 65\n10 65\n11 65\n12 65\n13 65\n14 65\n15 65\n16 65\n17 65\n18 65\n19 65\n20 65\n21 65\n22 65\n23 65\n24 65\n25 65\n26 65\n27 65\n28 65\n29 65\n30 65\n31 65\n32 65\n33 65\n34 65\n35 65\n36 65\n37 65\n38 65\n39 65\n40 65\n41 65\n42 65\n43 65\n44 65\n45 65\n46 65\n47 65\n48 65\n49 65\n50 65\n51 65\n52 65\n53 65\n54 65\n55 65\n56 65\n57 65\n58 65\n59 65\n60 65\n61 65\n62 65\n63 65\n64 65\n66 65\n67 65\n68 65\n69 65\n70 65\n71 65\n72 65\n73 65\n74 65\n75 65\n76...", "1 488\n2 488\n3 488\n4 488\n5 488\n6 488\n7 488\n8 488\n9 488\n10 488\n11 488\n12 488\n13 488\n14 488\n15 488\n16 488\n17 488\n18 488\n19 488\n20 488\n21 488\n22 488\n23 488\n24 488\n25 488\n26 488\n27 488\n28 488\n29 488\n30 488\n31 488\n32 488\n33 488\n34 488\n35 488\n36 488\n37 488\n38 488\n39 488\n40 488\n41 488\n42 488\n43 488\n44 488\n45 488\n46 488\n47 488\n48 488\n49 488\n50 488\n51 488\n52 488\n53 488\n54 488\n55 488\n56 488\n57 488\n58 488\n59 488\n60 488\n61 488\n62 488\n63 488\n64 488\n65 488\n...", "1 8854\n2 8854\n3 8854\n4 8854\n5 8854\n6 8854\n7 8854\n8 8854\n9 8854\n10 8854\n11 8854\n12 8854\n13 8854\n14 8854\n15 8854\n16 8854\n17 8854\n18 8854\n19 8854\n20 8854\n21 8854\n22 8854\n23 8854\n24 8854\n25 8854\n26 8854\n27 8854\n28 8854\n29 8854\n30 8854\n31 8854\n32 8854\n33 8854\n34 8854\n35 8854\n36 8854\n37 8854\n38 8854\n39 8854\n40 8854\n41 8854\n42 8854\n43 8854\n44 8854\n45 8854\n46 8854\n47 8854\n48 8854\n49 8854\n50 8854\n51 8854\n52 8854\n53 8854\n54 8854\n55 8854\n56 8854\n57 8854\n58 8854...", "1 41895\n2 41895\n3 41895\n4 41895\n5 41895\n6 41895\n7 41895\n8 41895\n9 41895\n10 41895\n11 41895\n12 41895\n13 41895\n14 41895\n15 41895\n16 41895\n17 41895\n18 41895\n19 41895\n20 41895\n21 41895\n22 41895\n23 41895\n24 41895\n25 41895\n26 41895\n27 41895\n28 41895\n29 41895\n30 41895\n31 41895\n32 41895\n33 41895\n34 41895\n35 41895\n36 41895\n37 41895\n38 41895\n39 41895\n40 41895\n41 41895\n42 41895\n43 41895\n44 41895\n45 41895\n46 41895\n47 41895\n48 41895\n49 41895\n50 41895\n51 41895\n52 41895\n...", "1 66180\n2 66180\n3 66180\n4 66180\n5 66180\n6 66180\n7 66180\n8 66180\n9 66180\n10 66180\n11 66180\n12 66180\n13 66180\n14 66180\n15 66180\n16 66180\n17 66180\n18 66180\n19 66180\n20 66180\n21 66180\n22 66180\n23 66180\n24 66180\n25 66180\n26 66180\n27 66180\n28 66180\n29 66180\n30 66180\n31 66180\n32 66180\n33 66180\n34 66180\n35 66180\n36 66180\n37 66180\n38 66180\n39 66180\n40 66180\n41 66180\n42 66180\n43 66180\n44 66180\n45 66180\n46 66180\n47 66180\n48 66180\n49 66180\n50 66180\n51 66180\n52 66180\n...", "1 72727\n2 72727\n3 72727\n4 72727\n5 72727\n6 72727\n7 72727\n8 72727\n9 72727\n10 72727\n11 72727\n12 72727\n13 72727\n14 72727\n15 72727\n16 72727\n17 72727\n18 72727\n19 72727\n20 72727\n21 72727\n22 72727\n23 72727\n24 72727\n25 72727\n26 72727\n27 72727\n28 72727\n29 72727\n30 72727\n31 72727\n32 72727\n33 72727\n34 72727\n35 72727\n36 72727\n37 72727\n38 72727\n39 72727\n40 72727\n41 72727\n42 72727\n43 72727\n44 72727\n45 72727\n46 72727\n47 72727\n48 72727\n49 72727\n50 72727\n51 72727\n52 72727\n...", "1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000\n21 100000\n22 100000\n23 100000\n24 100000\n25 100000\n26 100000\n27 100000\n28 100000\n29 100000\n30 100000\n31 100000\n32 100000\n33 100000\n34 100000\n35 100000\n36 100000\n37 100000\n38 100000\n39 100000\n40 100000\n41 100000\n42 100000\n43 100000\n44 100000\n45 100000\n46 100000\n47 100000\n48 ...", "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ...", "1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000\n7 100000\n8 100000\n9 100000\n10 100000\n11 100000\n12 100000\n13 100000\n14 100000\n15 100000\n16 100000\n17 100000\n18 100000\n19 100000\n20 100000\n21 100000\n22 100000\n23 100000\n24 100000\n25 100000\n26 100000\n27 100000\n28 100000\n29 100000\n30 100000\n31 100000\n32 100000\n33 100000\n34 100000\n35 100000\n36 100000\n37 100000\n38 100000\n39 100000\n40 100000\n41 100000\n42 100000\n43 100000\n44 100000\n45 100000\n46 100000\n47 100000\n48 ...", "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ...", "-1", "-1", "-1", "-1", "1 10000\n2 10000\n3 10000\n4 10000\n5 10000\n6 10000\n7 10000\n8 10000\n9 10000\n10 10000\n11 10000\n12 10000\n13 10000\n14 10000\n15 10000\n16 10000\n17 10000\n18 10000\n19 10000\n20 10000\n21 10000\n22 10000\n23 10000\n24 10000\n25 10000\n26 10000\n27 10000\n28 10000\n29 10000\n30 10000\n31 10000\n32 10000\n33 10000\n34 10000\n35 10000\n36 10000\n37 10000\n38 10000\n39 10000\n40 10000\n41 10000\n42 10000\n43 10000\n44 10000\n45 10000\n46 10000\n47 10000\n48 10000\n49 10000\n50 10000\n51 10000\n52 10000\n...", "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ...", "-1", "-1", "-1", "-1", "2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n41 1\n42 1\n43 1\n44 1\n45 1\n46 1\n47 1\n48 1\n49 1\n50 1\n51 1\n52 1\n53 1\n54 1\n55 1\n56 1\n57 1\n58 1\n59 1\n60 1\n61 1\n62 1\n63 1\n64 1\n65 1\n66 1\n67 1\n68 1\n69 1\n70 1\n71 1\n72 1\n73 1\n74 1\n75 1\n76 1\n77 1\n78 1\n79 1\n80 1\n81 1\n82 1\n83 1\n84 1\n85 1\n86 1\n87 1\n88 ...", "1 300\n2 300\n3 300\n4 300\n5 300\n6 300\n7 300\n8 300\n9 300\n10 300\n11 300\n12 300\n13 300\n14 300\n15 300\n16 300\n17 300\n18 300\n19 300\n20 300\n21 300\n22 300\n23 300\n24 300\n25 300\n26 300\n27 300\n28 300\n29 300\n30 300\n31 300\n32 300\n33 300\n34 300\n35 300\n36 300\n37 300\n38 300\n39 300\n40 300\n41 300\n42 300\n43 300\n44 300\n45 300\n46 300\n47 300\n48 300\n49 300\n50 300\n51 300\n52 300\n53 300\n54 300\n55 300\n56 300\n57 300\n58 300\n59 300\n60 300\n61 300\n62 300\n63 300\n64 300\n65 300\n...", "-1", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 12 | codeforces |
|
c0c1479e7ce5028f5eaa529aedd3e85c | Bars | Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that $k$ is strictly greater than $1$.
Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible.
Consider that Polycarp eats a bar in the minute $x$ and the next bar in the minute $y$ ($x < y$). Then the break time is equal to $y - x - 1$ minutes. It is not necessary for Polycarp to eat all bars he has.
The first line contains two integers $n$ and $k$ ($2 \le n \le 200\,000$, $2 \le k \le n$) β the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length $n$ consisting of zeros and ones. If the $i$-th symbol in the string equals to zero, Polycarp has no important things to do in the minute $i$ and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute $i$ and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes.
Print the minimum possible break in minutes between eating chocolate bars.
Sample Input
3 3
010
8 3
01010110
Sample Output
1
3
| {"inputs": ["3 3\n010", "8 3\n01010110", "9 5\n001100110", "2 2\n00", "3 2\n010", "3 2\n000", "3 3\n000", "4 2\n0000", "4 2\n0100", "4 2\n0010", "4 2\n0110", "4 3\n0000", "4 3\n0010", "4 3\n0100", "4 3\n0110", "4 4\n0000", "4 4\n0100", "4 4\n0010", "4 4\n0110", "10 3\n0111011010", "100 19\n0011011110011111111010111101101100101111111111011011111111110111101111101111111101111011111011101110", "10 3\n0111011010", "100 19\n0011011110011111111010111101101100101111111111011011111111110111101111101111111101111011111011101110", "10 6\n0000000000", "10 4\n0000001000", "10 6\n0000000000", "100 21\n0110111011000010010101011101110101110111000111101011110100011011100011111101001010001111001111111000", "10 9\n0111011010", "100 89\n0011011110011111111010111101101100101111111111011011111111110111101111101111111101111011111011101110", "10 6\n0000000000", "100 81\n0110111011000010010101011101110101110111000111101011110100011011100011111101001010001111001111111000"], "outputs": ["1", "3", "2", "0", "1", "1", "0", "2", "2", "2", "2", "1", "1", "1", "2", "0", "1", "1", "2", "4", "10", "4", "10", "1", "3", "1", "7", "3", "10", "1", "7"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 7 | codeforces |
|
c0c31df16741dd7d0059f2a9ec8f3864 | Super Agent | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=Γ<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.
Input contains the matrix of three rows of three symbols each. Symbol Β«XΒ» means that the corresponding button was pressed, and Β«.Β» means that is was not pressed. The matrix may contain no Β«XΒ», also it may contain no Β«.Β».
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
Sample Input
XX.
...
.XX
X.X
X..
...
Sample Output
YES
NO
| {"inputs": ["XX.\n...\n.XX", ".X.\n.X.\n.X.", "XXX\nXXX\nXXX", "XXX\nX.X\nXXX", "X..\n.X.\n..X", "...\nX.X\nX..", ".X.\nX.X\n.X.", "X.X\n.X.\nX.X", "...\n...\n..X", "XXX\n...\nXXX", "..X\nX..\n..X", ".X.\n...\nX.X", "X.X\nX.X\nX.X", ".X.\nX.X\nXX.", "...\nXXX\nXXX", "XXX\n..X\nXXX", "X..\nX.X\n.X.", "...\n..X\nXXX", "..X\nX.X\nX..", "..X\n..X\nXXX", "X..\nX..\nX..", "XXX\n.X.\nXXX", "..X\n...\nX..", "...\n...\nX..", "...\n...\n.X.", "...\n...\n..X", "...\n.X.\nX.."], "outputs": ["YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 320 | codeforces |
|
c0f901607f527b8e6f3e00116e7c7ab4 | Petya and Square | Little Petya loves playing with squares. Mum bought him a square 2*n*<=Γ<=2*n* in size. Petya marked a cell inside the square and now he is solving the following task.
The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not have any common points with the marked cell and the resulting two parts should be equal up to rotation.
Petya wants to determine whether it is possible to cut the square in the required manner given the sizes of the square side and the coordinates of the marked cell. Help him.
The first line contains three space-separated integers 2*n*, *x* and *y* (2<=β€<=2*n*<=β€<=100,<=1<=β€<=*x*,<=*y*<=β€<=2*n*), representing the length of a square's side and the coordinates of the marked cell. It is guaranteed that 2*n* is even.
The coordinates of the marked cell are represented by a pair of numbers *x* *y*, where *x* represents the number of the row and *y* represents the number of the column. The rows and columns are numbered by consecutive integers from 1 to 2*n*. The rows are numbered from top to bottom and the columns are numbered from the left to the right.
If the square is possible to cut, print "YES", otherwise print "NO" (without the quotes).
Sample Input
4 1 1
2 2 2
Sample Output
YES
NO
| {"inputs": ["4 1 1", "2 2 2", "8 2 5", "6 1 6", "2 1 1", "2 1 2", "2 2 1", "4 2 2", "4 2 3", "4 2 4", "60 30 30", "60 34 30", "60 31 29", "100 61 30", "100 52 50", "100 51 51", "100 1 2", "100 1 8", "100 19 99", "100 18 82", "100 100 50", "100 51 100", "100 100 100", "6 3 3", "6 4 4", "6 3 1", "6 3 5", "8 4 4", "6 3 2", "4 3 3", "20 10 1", "8 4 1", "100 50 50"], "outputs": ["YES", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "YES", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c1099b4137bcb0dc819f8df0ea6630c3 | Multi-judge Solving | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty β a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge).
Makes has chosen *n* problems to solve on Decoforces with difficulties *a*1,<=*a*2,<=...,<=*a**n*. He can solve these problems in arbitrary order. Though he can solve problem *i* with difficulty *a**i* only if he had already solved some problem with difficulty (no matter on what online judge was it).
Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty *k*.
With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.
For every positive integer *y* there exist some problem with difficulty *y* on at least one judge besides Decoforces.
Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.
Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.
The first line contains two integer numbers *n*, *k* (1<=β€<=*n*<=β€<=103, 1<=β€<=*k*<=β€<=109).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109).
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.
Sample Input
3 3
2 1 9
4 20
10 3 6 3
Sample Output
1
0
| {"inputs": ["3 3\n2 1 9", "4 20\n10 3 6 3", "1 1000000000\n1", "1 1\n3", "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34 79 61 72 13 31 44 75 7 3 63 46 18 16 44 89 62 25 32 12 38 55 75 56 61 82", "100 10\n246 286 693 607 87 612 909 312 621 37 801 558 504 914 416 762 187 974 976 123 635 488 416 659 988 998 93 662 92 749 889 78 214 786 735 625 921 372 713 617 975 119 402 411 878 138 548 905 802 762 940 336 529 373 745 835 805 880 816 94 166 114 475 699 974 462 61 337 555 805 968 815 392 746 591 558 740 380 668 29 881 151 387 986 174 923 541 520 998 947 535 651 103 584 664 854 180 852 726 93", "2 1\n1 1000000000", "29 2\n1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 1048575 2097151 4194303 8388607 16777215 33554431 67108863 134217727 268435455 536870911", "1 1\n1000000000", "7 6\n4 20 16 14 3 17 4", "2 1\n3 6", "1 1\n20", "5 2\n86 81 53 25 18", "4 1\n88 55 14 39", "3 1\n2 3 6", "3 2\n4 9 18", "5 3\n6 6 6 13 27", "5 1\n23 8 83 26 18", "3 1\n4 5 6", "3 1\n1 3 6", "1 1\n2", "3 2\n4 5 6", "5 1\n100 200 400 1000 2000", "2 1\n1 4", "4 1\n2 4 8 32", "2 10\n21 42", "3 3\n1 7 13", "3 1\n1 4 6", "2 2\n2 8", "1 1\n4", "2 2\n8 16", "3 1\n4 8 16", "3 1\n3 6 9", "2 1\n4 8", "2 2\n7 14", "1 4\n9", "5 3\n1024 4096 16384 65536 536870913", "2 5\n10 11", "2 2\n3 6", "2 2\n8 11", "3 19905705\n263637263 417905394 108361057", "4 25\n100 11 1 13", "10 295206008\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696", "4 2\n45 44 35 38", "1 2\n9", "3 6\n13 26 52", "9 30111088\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021", "3 72014068\n430005292 807436976 828082746", "3 165219745\n737649884 652879952 506420386", "2 60669400\n95037700 337255240", "4 28\n34 1 86 90", "2 1\n5 10", "2 1\n4 1000000000", "2 1\n2 3", "2 1\n3 5", "3 3\n1 5 20", "9 1\n1 2 4 9 15 32 64 128 1024"], "outputs": ["1", "0", "0", "1", "0", "1", "29", "27", "29", "1", "1", "4", "4", "4", "0", "1", "2", "4", "1", "1", "0", "0", "7", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "24", "0", "0", "1", "3", "1", "0", "4", "2", "1", "2", "2", "1", "1", "1", "2", "28", "0", "1", "1", "4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 61 | codeforces |
|
c11ed3f7cf93b87239cbf0e5d6a42e5b | Alyona and Numbers | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integersΒ β the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (*x*,<=*y*) such that 1<=β€<=*x*<=β€<=*n*, 1<=β€<=*y*<=β€<=*m* and equals 0.
As usual, Alyona has some troubles and asks you to help.
The only line of the input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1<=000<=000).
Print the only integerΒ β the number of pairs of integers (*x*,<=*y*) such that 1<=β€<=*x*<=β€<=*n*, 1<=β€<=*y*<=β€<=*m* and (*x*<=+<=*y*) is divisible by 5.
Sample Input
6 12
11 14
1 5
3 8
5 7
21 21
Sample Output
14
31
1
5
7
88
| {"inputs": ["6 12", "11 14", "1 5", "3 8", "5 7", "21 21", "10 15", "1 1", "1 1000000", "1000000 1", "1000000 1000000", "944 844", "368 984", "792 828", "920 969", "640 325", "768 170", "896 310", "320 154", "744 999", "630 843", "54 688", "478 828", "902 184", "31 29", "751 169", "879 14", "7 858", "431 702", "855 355", "553 29", "721767 525996", "805191 74841", "888615 590981", "4743 139826", "88167 721374", "171591 13322", "287719 562167", "371143 78307", "487271 627151", "261436 930642", "377564 446782", "460988 28330", "544412 352983", "660540 869123", "743964 417967", "827388 966812", "910812 515656", "26940 64501", "110364 356449", "636358 355531", "752486 871672", "803206 420516", "919334 969361", "35462 261309", "118887 842857", "202311 358998", "285735 907842", "401863 456686", "452583 972827", "235473 715013", "318897 263858", "402321 812702", "518449 361546", "634577 910391", "685297 235043", "801425 751183", "884849 300028", "977 848872", "51697 397716", "834588 107199", "918012 688747", "1436 237592", "117564 753732", "200988 302576", "284412 818717", "400540 176073", "483964 724917", "567388 241058", "650812 789902", "400999 756281", "100 101", "100 102", "103 100", "100 104", "3 4", "11 23", "8 14", "23423 34234", "1 4", "999999 999999", "82 99", "21 18", "234 234", "4 4", "6 13", "3 9", "99999 99999", "34 33", "2 2", "333 1", "3 3", "8 2", "2179 2218", "1000000 999999", "873828 774207", "13 19", "1648 576469", "11 13", "5 8", "650074 943659", "1 3", "54 43", "14 9", "2 3", "543 534", "321 123", "21 3", "2 1", "4 3", "47474 74747", "4 9", "7 4", "9 4", "12414 4214", "2 9", "253 821", "2 4"], "outputs": ["14", "31", "1", "5", "7", "88", "30", "0", "200000", "200000", "200000000000", "159348", "72423", "131155", "178296", "41600", "26112", "55552", "9856", "148652", "106218", "7431", "79157", "33194", "180", "25384", "2462", "1201", "60512", "60705", "3208", "75929310986", "12052259926", "105030916263", "132638943", "12720276292", "457187060", "32349225415", "5812618980", "61118498984", "48660664382", "33737759810", "2611958008", "38433636199", "114818101284", "62190480238", "159985729411", "93933134534", "347531388", "7867827488", "45248999219", "131184195318", "67552194859", "178233305115", "1853307952", "20040948031", "14525848875", "51880446774", "36705041203", "88056992428", "33673251230", "16828704925", "65393416268", "37488632431", "115542637921", "32214852554", "120403367155", "53095895155", "165869588", "4112144810", "17893399803", "126455602192", "68236422", "17722349770", "12162829017", "46570587880", "14104855884", "70166746198", "27354683301", "102815540084", "60653584944", "2020", "2040", "2060", "2080", "3", "50", "23", "160372597", "1", "199999600001", "1624", "75", "10952", "4", "15", "6", "1999960001", "225", "0", "66", "2", "3", "966605", "199999800000", "135304750879", "50", "190004183", "28", "8", "122689636154", "0", "465", "26", "1", "57993", "7896", "12", "0", "3", "709707816", "8", "6", "8", "10462520", "4", "41542", "2"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 371 | codeforces |
|
c12241ccb6ccd236b53aeca845120461 | Ciel and Duel | Fox Ciel is playing a card game with her friend Jiro.
Jiro has *n* cards, each one has two attributes: *position* (Attack or Defense) and *strength*. Fox Ciel has *m* cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the following operation many times:
1. Choose one of her cards *X*. This card mustn't be chosen before. 1. If Jiro has no alive cards at that moment, he gets the damage equal to (*X*'s strength). Otherwise, Ciel needs to choose one Jiro's alive card *Y*, then: If *Y*'s position is Attack, then (*X*'s strength) <=β₯<= (*Y*'s strength) must hold. After this attack, card *Y* dies, and Jiro gets the damage equal to (*X*'s strength) - (*Y*'s strength). 1. If *Y*'s position is Defense, then (*X*'s strength) <=><= (*Y*'s strength) must hold. After this attack, card *Y* dies, but Jiro gets no damage.
Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.
The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the number of cards Jiro and Ciel have.
Each of the next *n* lines contains a string *position* and an integer *strength* (0<=β€<=*strength*<=β€<=8000) β the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense.
Each of the next *m* lines contains an integer *strength* (0<=β€<=*strength*<=β€<=8000) β the strength of Ciel's current card.
Output an integer: the maximal damage Jiro can get.
Sample Input
2 3
ATK 2000
DEF 1700
2500
2500
2500
3 4
ATK 10
ATK 100
ATK 1000
1
11
101
1001
2 4
DEF 0
ATK 0
0
0
1
1
Sample Output
3000
992
1
| {"inputs": ["2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500", "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001", "2 4\nDEF 0\nATK 0\n0\n0\n1\n1", "1 1\nATK 100\n99", "4 8\nDEF 100\nDEF 200\nDEF 300\nATK 100\n100\n101\n201\n301\n1\n1\n1\n1", "3 4\nDEF 100\nATK 200\nDEF 300\n101\n201\n301\n1", "4 4\nDEF 0\nDEF 0\nDEF 0\nATK 100\n100\n100\n100\n100", "10 7\nATK 1\nATK 2\nATK 3\nATK 4\nATK 5\nATK 6\nATK 7\nDEF 8\nDEF 9\nDEF 10\n1\n2\n3\n4\n5\n6\n7", "5 6\nDEF 0\nDEF 0\nDEF 0\nDEF 0\nDEF 0\n1\n1\n1\n1\n1\n1", "17 42\nDEF 4824\nDEF 4258\nDEF 4496\nATK 3932\nDEF 6130\nDEF 4005\nATK 5807\nDEF 4434\nDEF 5122\nATK 3904\nDEF 4617\nDEF 5329\nDEF 6169\nATK 4046\nATK 3612\nATK 5689\nDEF 5226\n735\n1278\n38\n1556\n312\n271\n850\n1511\n1196\n811\n1192\n387\n1470\n1441\n1330\n797\n477\n207\n1119\n1311\n527\n97\n1153\n1197\n1558\n1394\n82\n619\n494\n777\n765\n487\n1236\n581\n1403\n1012\n144\n1537\n1282\n973\n1507\n928", "5 25\nDEF 1568\nDEF 5006\nATK 4756\nDEF 1289\nDEF 1747\n3547\n1688\n1816\n3028\n1786\n3186\n3631\n3422\n1413\n2527\n2487\n3099\n2074\n2059\n1590\n1321\n3666\n2017\n1452\n2943\n1996\n2475\n1071\n1677\n2163", "21 35\nDEF 5009\nATK 2263\nATK 1391\nATK 1458\nATK 1576\nATK 2211\nATK 1761\nATK 1234\nATK 2737\nATK 2624\nATK 1140\nATK 1815\nATK 1756\nATK 1597\nATK 2192\nATK 960\nATK 2024\nATK 1954\nATK 2286\nATK 1390\nDEF 5139\n923\n1310\n1111\n820\n1658\n1158\n1902\n1715\n915\n826\n1858\n968\n982\n914\n1830\n1315\n972\n1061\n1774\n1097\n1333\n1743\n1715\n1375\n1801\n1772\n1879\n1311\n785\n1739\n1240\n971\n1259\n1603\n1808", "13 14\nATK 2896\nATK 2919\nATK 2117\nATK 2423\nATK 2636\nATK 2003\nATK 2614\nATK 2857\nATK 2326\nATK 2958\nATK 2768\nATK 3017\nATK 2788\n3245\n3274\n3035\n3113\n2982\n3312\n3129\n2934\n3427\n3316\n3232\n3368\n3314\n3040", "25 28\nATK 1267\nDEF 1944\nATK 1244\nATK 1164\nATK 1131\nDEF 1589\nDEF 1116\nDEF 1903\nATK 1162\nATK 1058\nDEF 1291\nDEF 1199\nDEF 754\nDEF 1726\nDEF 1621\nATK 1210\nDEF 939\nDEF 919\nDEF 978\nDEF 1967\nATK 1179\nDEF 1981\nATK 1088\nDEF 404\nATK 1250\n2149\n1969\n2161\n1930\n2022\n1901\n1982\n2098\n1993\n1977\n2021\n2038\n1999\n1963\n1889\n1992\n2062\n2025\n2081\n1995\n1908\n2097\n2034\n1993\n2145\n2083\n2133\n2143", "34 9\nDEF 7295\nDEF 7017\nDEF 7483\nDEF 7509\nDEF 7458\nDEF 7434\nDEF 6981\nDEF 7090\nDEF 7298\nDEF 7134\nATK 737\nDEF 7320\nDEF 7228\nDEF 7323\nATK 786\nDEF 6895\nDEF 7259\nDEF 6921\nDEF 7373\nDEF 7505\nDEF 7421\nDEF 6930\nDEF 6890\nDEF 7507\nDEF 6964\nDEF 7418\nDEF 7098\nDEF 6867\nDEF 7229\nDEF 7162\nDEF 6987\nDEF 7043\nDEF 7230\nDEF 7330\n3629\n4161\n2611\n4518\n2357\n2777\n1923\n1909\n1738", "10 25\nATK 3519\nATK 2186\nATK 3219\nATK 3116\nATK 2170\nATK 3236\nATK 3013\nDEF 1188\nATK 1914\nATK 2838\n1335\n725\n752\n1254\n414\n1653\n439\n784\n649\n477\n759\n1666\n417\n1316\n392\n799\n534\n1402\n515\n1334\n1435\n898\n1214\n1427\n1820", "26 36\nATK 657\nATK 1366\nDEF 226\nATK 1170\nATK 969\nATK 1633\nATK 610\nATK 1386\nATK 740\nDEF 496\nATK 450\nATK 1480\nATK 1094\nATK 875\nATK 845\nATK 1012\nATK 1635\nATK 657\nATK 1534\nATK 1602\nATK 1581\nDEF 211\nATK 946\nATK 1281\nATK 843\nATK 1442\n6364\n7403\n2344\n426\n1895\n863\n6965\n5025\n1159\n1873\n6792\n3331\n2171\n529\n1862\n6415\n4427\n7408\n4164\n917\n5892\n5595\n4841\n5311\n5141\n1154\n6415\n4059\n3850\n1681\n6068\n5081\n2325\n5122\n6942\n3247", "2 12\nATK 3626\nATK 2802\n1160\n4985\n2267\n673\n2085\n3288\n1391\n2846\n4602\n2088\n3058\n3223", "14 18\nDEF 102\nATK 519\nATK 219\nATK 671\nATK 1016\nATK 674\nATK 590\nATK 1005\nATK 514\nATK 851\nATK 273\nATK 928\nATK 1023\nATK 209\n2204\n2239\n2193\n2221\n2203\n2211\n2224\n2221\n2218\n2186\n2204\n2195\n2202\n2203\n2217\n2201\n2213\n2192", "30 28\nDEF 5209\nATK 82\nDEF 4211\nDEF 2850\nATK 79\nATK 79\nDEF 4092\nDEF 5021\nATK 80\nDEF 5554\nDEF 2737\nDEF 4188\nATK 83\nATK 80\nDEF 4756\nATK 76\nDEF 3928\nDEF 5290\nATK 82\nATK 77\nDEF 3921\nDEF 3352\nDEF 2653\nATK 74\nDEF 4489\nDEF 5143\nDEF 3212\nATK 79\nDEF 4177\nATK 75\n195\n504\n551\n660\n351\n252\n389\n676\n225\n757\n404\n734\n203\n532\n382\n272\n621\n537\n311\n588\n609\n774\n669\n399\n382\n308\n230\n648", "6 45\nATK 2374\nATK 2298\nATK 2591\nATK 2383\nATK 2523\nATK 2587\n2899\n3569\n3034\n3728\n3331\n3323\n3901\n3905\n2655\n2959\n3438\n3477\n4190\n3024\n3952\n3413\n3970\n3079\n3306\n3005\n4148\n4267\n4129\n4112\n4388\n3392\n3344\n2602\n4300\n3464\n4142\n3469\n4367\n4530\n3032\n3290\n3009\n3049\n4467\n4256\n3423\n2917\n3627\n2759\n4287", "39 22\nDEF 5748\nDEF 5028\nDEF 1873\nDEF 6817\nDEF 5727\nDEF 4386\nDEF 4549\nDEF 5498\nDEF 1506\nDEF 2805\nATK 3186\nDEF 6202\nDEF 2129\nDEF 1646\nDEF 5367\nDEF 5754\nDEF 6195\nDEF 2109\nDEF 1837\nDEF 6575\nDEF 2842\nDEF 2970\nDEF 4494\nATK 3300\nDEF 4290\nDEF 6751\nDEF 3802\nDEF 5067\nDEF 1463\nDEF 3643\nDEF 6442\nDEF 4856\nDEF 4226\nDEF 3835\nDEF 1790\nDEF 5415\nDEF 6668\nDEF 5320\nDEF 1787\n252\n237\n304\n525\n99\n322\n280\n341\n215\n132\n303\n436\n80\n283\n400\n192\n425\n513\n138\n427\n514\n470", "6 42\nDEF 88\nDEF 92\nDEF 108\nDEF 94\nDEF 96\nDEF 78\n437\n1623\n2354\n2090\n802\n2500\n1512\n2691\n1521\n1087\n1415\n2081\n670\n1955\n3107\n2991\n1865\n2727\n1422\n2345\n2754\n1226\n3153\n3025\n1094\n2943\n2516\n1770\n1401\n590\n3292\n979\n840\n746\n1767\n696\n620\n2533\n2364\n2550\n916\n625", "18 48\nATK 5377\nATK 5244\nATK 5213\nATK 5410\nATK 5094\nATK 5755\nDEF 5425\nATK 5215\nATK 5126\nDEF 5080\nDEF 5491\nATK 5671\nDEF 5409\nATK 5564\nDEF 5518\nDEF 5374\nATK 5182\nATK 5764\n1620\n1321\n1639\n837\n1705\n1076\n1106\n1395\n1008\n1610\n1047\n1414\n1944\n926\n1681\n904\n813\n1880\n1175\n1988\n976\n1679\n1051\n1800\n1714\n934\n951\n1282\n1224\n977\n759\n901\n1581\n1567\n1411\n1563\n1917\n751\n723\n1793\n1637\n1949\n1395\n1752\n1326\n1259\n1535\n1127", "34 10\nDEF 1740\nDEF 2236\nATK 3210\nATK 3468\nATK 4789\nDEF 1392\nATK 3639\nATK 1789\nDEF 2107\nDEF 1301\nDEF 2047\nDEF 1892\nATK 4845\nATK 4182\nATK 4504\nDEF 1557\nDEF 1537\nDEF 910\nATK 1548\nATK 3045\nATK 2660\nDEF 2097\nATK 2157\nDEF 2299\nDEF 2282\nATK 1956\nDEF 1812\nATK 3347\nDEF 1714\nATK 5446\nDEF 1326\nATK 3275\nDEF 907\nATK 3655\n1316\n1332\n1283\n1176\n939\n1175\n944\n1433\n1435\n1165", "10 27\nATK 7277\nATK 6269\nATK 7618\nDEF 4805\nDEF 4837\nDEF 4798\nDEF 4012\nATK 6353\nATK 7690\nATK 7653\n4788\n4860\n4837\n4528\n4826\n4820\n4921\n4678\n4924\n5070\n4961\n5007\n4495\n4581\n4748\n4480\n5176\n4589\n4998\n4660\n4575\n5090\n4540\n4750\n5136\n5118\n4667", "22 37\nDEF 3258\nDEF 3379\nATK 883\nATK 3945\nATK 4382\nATK 554\nDEF 3374\nDEF 3051\nDEF 2943\nATK 462\nATK 5098\nDEF 2986\nDEF 2957\nATK 1267\nATK 1296\nATK 4178\nDEF 2805\nDEF 3388\nATK 957\nDEF 3102\nDEF 3121\nATK 2875\n1366\n665\n561\n2503\n1329\n2353\n2529\n2932\n940\n2044\n2483\n575\n1980\n2930\n926\n2894\n1395\n577\n2813\n529\n327\n2911\n455\n948\n1076\n1741\n2668\n536\n481\n980\n1208\n2680\n2036\n1618\n2718\n2280\n711", "2 13\nDEF 4509\nDEF 4646\n4842\n4315\n5359\n3477\n5876\n5601\n3134\n5939\n6653\n5673\n4473\n2956\n4127", "14 23\nDEF 2361\nDEF 2253\nDEF 2442\nATK 2530\nDEF 2608\nDEF 2717\nDEF 2274\nDEF 2308\nATK 1200\nDEF 2244\nDEF 2678\nDEF 2338\nDEF 2383\nDEF 2563\n2640\n6118\n2613\n3441\n3607\n5502\n4425\n4368\n4059\n4264\n3979\n5098\n2413\n3564\n6118\n6075\n6049\n2524\n5245\n5004\n5560\n2877\n3450", "23 49\nATK 3263\nATK 2712\nATK 3221\nATK 4441\nATK 4225\nATK 2120\nATK 3062\nATK 2246\nATK 4263\nATK 2850\nATK 3491\nATK 4248\nATK 3650\nATK 4444\nATK 3509\nATK 3254\nATK 4073\nATK 4263\nATK 4278\nATK 4747\nATK 2581\nATK 3355\nATK 4180\n516\n469\n494\n521\n536\n586\n482\n571\n502\n515\n537\n513\n503\n482\n512\n615\n607\n574\n561\n561\n514\n511\n617\n491\n511\n616\n578\n464\n459\n591\n518\n586\n596\n612\n540\n599\n558\n539\n514\n524\n463\n609\n532\n616\n620\n615\n538\n539\n553", "39 11\nDEF 5456\nATK 801\nDEF 4013\nATK 798\nATK 1119\nDEF 2283\nDEF 2400\nDEF 3847\nDEF 5386\nDEF 2839\nDEF 3577\nDEF 4050\nDEF 5623\nATK 1061\nDEF 4331\nDEF 4036\nDEF 5138\nDEF 4552\nATK 929\nDEF 3221\nDEF 3645\nDEF 3523\nATK 1147\nDEF 3490\nATK 1030\nDEF 2689\nATK 1265\nDEF 2533\nDEF 3181\nDEF 5582\nATK 790\nDEF 5623\nATK 1254\nATK 1145\nDEF 2873\nDEF 4117\nDEF 2589\nDEF 5471\nDEF 2977\n2454\n5681\n6267\n2680\n5560\n5394\n5419\n4350\n3803\n6003\n5502", "15 35\nATK 5598\nATK 6155\nDEF 511\nDEF 534\nATK 5999\nATK 5659\nATK 6185\nATK 6269\nATK 5959\nATK 6176\nDEF 520\nATK 5602\nDEF 517\nATK 6422\nATK 6185\n2108\n2446\n2176\n1828\n2460\n2800\n1842\n2936\n1918\n2980\n2271\n2436\n2993\n2462\n2571\n2907\n2136\n1810\n2079\n2863\n2094\n1887\n2194\n2727\n2589\n2843\n2141\n2552\n1824\n3038\n2113\n2198\n2075\n2012\n2708", "20 20\nDEF 6409\nDEF 6327\nATK 2541\nDEF 6395\nDEF 6301\nATK 3144\nATK 3419\nDEF 6386\nATK 2477\nDEF 6337\nDEF 6448\nATK 3157\nATK 1951\nDEF 6345\nDEF 6368\nDEF 6352\nDEF 6348\nDEF 6430\nDEF 6456\nDEF 6380\n3825\n3407\n3071\n1158\n2193\n385\n1657\n86\n493\n2168\n3457\n1679\n3928\n3006\n1122\n190\n135\n3597\n2907\n2394", "36 30\nATK 116\nATK 120\nATK 122\nATK 120\nATK 116\nATK 118\nATK 123\nDEF 2564\nATK 123\nDEF 1810\nATK 124\nATK 120\nDEF 2598\nATK 119\nDEF 2103\nATK 123\nATK 118\nATK 118\nATK 123\nDEF 1988\nATK 122\nATK 120\nDEF 2494\nATK 122\nATK 124\nATK 117\nATK 121\nATK 118\nATK 117\nATK 122\nATK 119\nATK 122\nDEF 2484\nATK 118\nATK 117\nATK 120\n1012\n946\n1137\n1212\n1138\n1028\n1181\n981\n1039\n1007\n900\n947\n894\n979\n1021\n1096\n1200\n937\n957\n1211\n1031\n881\n1122\n967\n1024\n972\n1193\n1092\n1177\n1101"], "outputs": ["3000", "992", "1", "0", "201", "101", "0", "12", "1", "0", "0", "3878", "10399", "15496", "7156", "0", "117431", "25238", "29069", "6878", "146172", "0", "71957", "0", "0", "0", "11779", "52224", "55832", "0", "41774", "0", "4944", "27020"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 5 | codeforces |
|
c15f635616d643c4688b14322dc81920 | Amr and Music | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.
The first line contains two numbers *n*, *k* (1<=β€<=*n*<=β€<=100, 0<=β€<=*k*<=β€<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=100), representing number of days required to learn the *i*-th instrument.
In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use all days for studying.
Sample Input
4 10
4 3 1 2
5 6
4 3 1 1 2
1 3
4
Sample Output
4
1 2 3 43
1 3 40
| {"inputs": ["4 10\n4 3 1 2", "5 6\n4 3 1 1 2", "1 3\n4", "2 100\n100 100", "3 150\n50 50 50", "4 0\n100 100 100 100", "100 7567\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", "68 3250\n95 84 67 7 82 75 100 39 31 45 69 100 8 97 13 58 74 40 88 69 35 91 94 28 62 85 51 97 37 15 87 51 24 96 89 49 53 54 35 17 23 54 51 91 94 18 26 92 79 63 23 37 98 43 16 44 82 25 100 59 97 3 60 92 76 58 56 50", "100 10000\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", "25 1293\n96 13 7 2 81 72 39 45 5 88 47 23 60 81 54 46 63 52 41 57 2 87 90 28 93", "98 7454\n71 57 94 76 52 90 76 81 67 60 99 88 98 61 73 61 80 91 88 93 53 55 88 64 71 55 81 76 52 63 87 99 84 66 65 52 83 99 92 62 95 81 90 67 64 57 80 80 67 75 77 58 71 85 97 50 97 55 52 59 55 96 57 53 85 100 95 95 74 51 78 88 66 98 97 86 94 81 56 64 61 57 67 95 85 82 85 60 76 95 69 95 76 91 74 100 69 76", "5 249\n96 13 7 2 81", "61 3331\n12 63 99 56 57 70 53 21 41 82 97 63 42 91 18 84 99 78 85 89 6 63 76 28 33 78 100 46 78 78 32 13 11 12 73 50 34 60 12 73 9 19 88 100 28 51 50 45 51 10 78 38 25 22 8 40 71 55 56 83 44", "99 10000\n42 88 21 63 59 38 23 100 86 37 57 86 11 22 19 89 6 19 15 64 18 77 83 29 14 26 80 73 8 51 14 19 9 98 81 96 47 77 22 19 86 71 91 61 84 8 80 28 6 25 33 95 96 21 57 92 96 57 31 88 38 32 70 19 25 67 29 78 18 90 37 50 62 33 49 16 47 39 9 33 88 69 69 29 14 66 75 76 41 98 40 52 65 25 33 47 39 24 80", "89 4910\n44 9 31 70 85 72 55 9 85 84 63 43 92 85 10 34 83 28 73 45 62 7 34 52 89 58 24 10 28 6 72 45 57 36 71 34 26 24 38 59 5 15 48 82 58 99 8 77 49 84 14 58 29 46 88 50 13 7 58 23 40 63 96 23 46 31 17 8 59 93 12 76 69 20 43 44 91 78 68 94 37 27 100 65 40 25 52 30 97", "40 2110\n91 18 52 22 26 67 59 10 55 43 97 78 20 81 99 36 33 12 86 32 82 87 70 63 48 48 45 94 78 23 77 15 68 17 71 54 44 98 54 8", "27 1480\n38 95 9 36 21 70 19 89 35 46 7 31 88 25 10 72 81 32 65 83 68 57 50 20 73 42 12", "57 2937\n84 73 23 62 93 64 23 17 53 100 47 67 52 53 90 58 19 84 33 69 46 47 50 28 73 74 40 42 92 70 32 29 57 52 23 82 42 32 46 83 45 87 40 58 50 51 48 37 57 52 78 26 21 54 16 66 93", "6 41\n6 8 9 8 9 8", "9 95\n9 11 12 11 12 11 8 11 10", "89 6512\n80 87 61 91 85 51 58 69 79 57 81 67 74 55 88 70 77 61 55 81 56 76 79 67 92 52 54 73 67 72 81 54 72 81 65 88 83 57 83 92 62 66 63 58 61 66 92 77 73 66 71 85 92 73 82 65 76 64 58 62 64 51 90 59 79 70 86 89 86 51 72 61 60 71 52 74 58 72 77 91 91 60 76 56 64 55 61 81 52", "5 29\n6 3 7 2 1", "5 49\n16 13 7 2 1", "6 84\n16 21 25 6 17 16", "4 9\n7 4 2 1", "50 2500\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", "100 10000\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 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", "96 514\n6 3 7 2 1 2 9 5 5 8 7 3 10 1 4 6 3 2 1 7 2 7 10 8 3 8 10 4 8 8 2 5 3 2 1 4 4 8 4 3 3 7 4 4 2 7 8 3 9 2 2 6 3 4 8 6 7 5 4 3 10 7 6 5 10 1 7 10 7 7 8 2 1 2 3 10 9 8 8 2 7 1 2 7 10 1 2 2 3 8 6 2 9 6 9 6", "47 350\n6 1 9 12 8 8 11 4 4 8 8 3 3 2 12 7 7 7 12 2 9 1 5 10 6 1 5 2 6 3 9 13 8 3 10 10 10 10 6 9 10 10 8 5 12 11 3", "100 200\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", "2 10000\n1 1", "1 2\n1", "1 3\n2", "34 4964\n37 27 90 83 36 59 80 7 28 41 97 72 64 8 40 30 76 4 92 51 52 44 42 13 38 64 60 66 47 93 30 35 71 71", "2 2\n1 10", "2 5\n1 1", "1 4\n3", "4 384\n1 2 3 4"], "outputs": ["4\n1 2 3 4", "3\n3 4 5", "0", "1\n1", "3\n1 2 3", "0", "75\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", "60\n1 2 3 4 5 6 8 9 10 11 13 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 54 55 56 57 58 60 62 63 64 65 66 67 68", "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", "25\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", "98\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", "5\n1 2 3 4 5", "61\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", "99\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", "89\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", "39\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 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", "27\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", "55\n1 2 3 4 5 6 7 8 9 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", "5\n1 2 3 4 6", "9\n1 2 3 4 5 6 7 8 9", "89\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", "5\n1 2 3 4 5", "5\n1 2 3 4 5", "5\n1 2 4 5 6", "3\n2 3 4", "50\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", "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", "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", "96\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", "47\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", "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", "2\n1 2", "1\n1", "1\n1", "34\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", "1\n1", "2\n1 2", "1\n1", "4\n1 2 3 4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 192 | codeforces |
|
c1728962a6cce0de630f0372867289aa | Game Shopping | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.
When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop.
Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.
For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 > a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$.
Your task is to get the number of games Maxim will buy.
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) β the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet.
Print a single integer β the number of games Maxim will buy.
Sample Input
5 4
2 4 5 2 4
5 3 4 6
5 2
20 40 50 20 40
19 20
6 4
4 8 15 16 23 42
1000 1000 1000 1000
Sample Output
3
0
4
| {"inputs": ["5 4\n2 4 5 2 4\n5 3 4 6", "5 2\n20 40 50 20 40\n19 20", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "5 1\n1 1 1 1 1\n5", "5 1\n10 1 1 1 1\n1000", "5 1\n100 100 100 100 100\n100", "2 1\n2 1\n1", "2 3\n3 1\n2 4 2", "1 5\n4\n1 4 3 3 2", "5 3\n4 2 3 1 1\n2 1 3", "3 5\n5 2 5\n1 4 1 4 2", "7 3\n9 7 10 2 1 1 1\n8 9 6", "5 3\n2 5 3 3 2\n2 5 3"], "outputs": ["3", "0", "4", "1", "1", "1", "1", "1", "0", "3", "0", "3", "3"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 321 | codeforces |
|
c1a730423f27fa14659fb6ff4387706b | Looking for Order | Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready for the University and noticed that the room was in a mess β all the objects from her handbag were thrown about the room. Of course, she wanted to put them back into her handbag. The problem is that the girl cannot carry more than two objects at a time, and cannot move the handbag. Also, if he has taken an object, she cannot put it anywhere except her handbag β her inherent sense of order does not let her do so.
You are given the coordinates of the handbag and the coordinates of the objects in some Π‘artesian coordinate system. It is known that the girl covers the distance between any two objects in the time equal to the squared length of the segment between the points of the objects. It is also known that initially the coordinates of the girl and the handbag are the same. You are asked to find such an order of actions, that the girl can put all the objects back into her handbag in a minimum time period.
The first line of the input file contains the handbag's coordinates *x**s*,<=*y**s*. The second line contains number *n* (1<=β€<=*n*<=β€<=24) β the amount of objects the girl has. The following *n* lines contain the objects' coordinates. All the coordinates do not exceed 100 in absolute value. All the given positions are different. All the numbers are integer.
In the first line output the only number β the minimum time the girl needs to put the objects into her handbag.
In the second line output the possible optimum way for Lena. Each object in the input is described by its index number (from 1 to *n*), the handbag's point is described by number 0. The path should start and end in the handbag's point. If there are several optimal paths, print any of them.
Sample Input
0 0
2
1 1
-1 1
1 1
3
4 3
3 4
0 0
Sample Output
8
0 1 2 0
32
0 1 2 0 3 0
| {"inputs": ["0 0\n2\n1 1\n-1 1", "1 1\n3\n4 3\n3 4\n0 0", "-3 4\n1\n2 2", "7 -7\n2\n3 1\n-3 8", "3 -9\n3\n0 -9\n-10 -3\n-12 -2", "4 -1\n4\n14 -3\n-11 10\n-3 -5\n-8 1", "7 -11\n5\n-1 7\n-7 -11\n12 -4\n8 -6\n-18 -8", "11 3\n6\n-17 -17\n-4 -9\n15 19\n7 4\n13 1\n5 -6", "-6 4\n7\n-10 -11\n-11 -3\n13 27\n12 -22\n19 -17\n21 -21\n-5 4", "27 -5\n8\n-13 -19\n-20 -8\n11 2\n-23 21\n-28 1\n11 -12\n6 29\n22 -15", "31 9\n9\n8 -26\n26 4\n3 2\n24 21\n14 34\n-3 26\n35 -25\n5 20\n-1 8", "-44 47\n24\n96 -18\n-50 86\n84 68\n-25 80\n-11 -15\n-62 0\n-42 50\n-57 11\n-5 27\n-44 67\n-77 -3\n-27 -46\n32 63\n86 13\n-21 -51\n-25 -62\n-14 -2\n-21 86\n-92 -94\n-44 -34\n-74 55\n91 -35\n-10 55\n-34 16", "5 4\n11\n-26 2\n20 35\n-41 39\n31 -15\n-2 -44\n16 -28\n17 -6\n0 7\n-29 -35\n-17 12\n42 29", "-44 22\n12\n-28 24\n41 -19\n-39 -36\n12 -18\n-31 -24\n-7 29\n45 0\n12 -2\n42 31\n28 -37\n-34 -38\n6 24", "40 -36\n13\n3 -31\n28 -43\n45 11\n47 -37\n47 -28\n-30 24\n-46 -33\n-31 46\n-2 -38\n-43 -4\n39 11\n45 -1\n50 38", "-54 2\n14\n-21 -2\n-5 34\n48 -55\n-32 -23\n22 -10\n-33 54\n-16 32\n-53 -17\n10 31\n-47 21\n-52 49\n34 42\n-42 -25\n-32 31", "-19 -31\n15\n-31 -59\n60 -34\n-22 -59\n5 44\n26 39\n-39 -23\n-60 -7\n1 2\n-5 -19\n-41 -26\n46 -8\n51 -2\n60 4\n-12 44\n14 49", "-34 19\n16\n-44 24\n30 -42\n46 5\n13 -32\n40 53\n35 49\n-30 7\n-60 -50\n37 46\n-18 -57\n37 -44\n-61 58\n13 -55\n28 22\n-50 -3\n5 52", "-64 -6\n17\n-3 -18\n66 -58\n55 34\n-4 -40\n-1 -50\n13 -9\n56 55\n3 42\n-54 -52\n51 -56\n21 -27\n62 -17\n54 -5\n-28 -24\n12 68\n43 -22\n8 -6", "7 -35\n18\n24 -3\n25 -42\n-56 0\n63 -30\n18 -63\n-30 -20\n-53 -47\n-11 -17\n-22 -54\n7 -41\n-32 -3\n-29 15\n-30 -25\n68 15\n-18 70\n-28 19\n-12 69\n44 29", "-8 47\n19\n47 51\n43 -57\n-76 -26\n-23 51\n19 74\n-36 65\n50 4\n48 8\n14 -67\n23 44\n5 59\n7 -45\n-52 -6\n-2 -33\n34 -72\n-51 -47\n-42 4\n-41 55\n22 9", "44 75\n20\n-19 -33\n-25 -42\n-30 -61\n-21 44\n7 4\n-38 -78\n-14 9\n65 40\n-27 25\n65 -1\n-71 -38\n-52 57\n-41 -50\n-52 40\n40 44\n-19 51\n42 -43\n-79 -69\n26 -69\n-56 44", "42 -34\n21\n4 62\n43 73\n29 -26\n68 83\n0 52\n-72 34\n-48 44\n64 41\n83 -12\n-25 52\n42 59\n1 38\n12 -79\n-56 -62\n-8 67\n84 -83\n22 -63\n-11 -56\n71 44\n7 55\n-62 65", "-44 42\n22\n-67 -15\n74 -14\n67 76\n-57 58\n-64 78\n29 33\n-27 27\n-20 -52\n-54 -2\n-29 22\n31 -65\n-76 -76\n-29 -51\n-5 -79\n-55 36\n72 36\n-80 -26\n5 60\n-26 69\n78 42\n-47 -84\n8 83", "52 92\n23\n-67 -82\n31 82\n-31 -14\n-1 35\n-31 -49\n-75 -14\n78 -51\n-35 -24\n28 -84\n44 -51\n-37 -9\n-38 -91\n41 57\n-19 35\n14 -88\n-60 -60\n-13 -91\n65 -8\n-30 -46\n72 -44\n74 -5\n-79 31\n-3 84", "-21 -47\n24\n-37 1\n-65 8\n-74 74\n58 -7\n81 -31\n-77 90\n-51 10\n-42 -37\n-14 -17\n-26 -71\n62 45\n56 43\n-75 -73\n-33 68\n39 10\n-65 -93\n61 -93\n30 69\n-28 -53\n5 24\n93 38\n-45 -14\n3 -86\n63 -80", "31 16\n21\n-9 24\n-59 9\n-25 51\n62 52\n39 15\n83 -24\n45 -81\n42 -62\n57 -56\n-7 -3\n54 47\n-14 -54\n-14 -34\n-19 -60\n-38 58\n68 -63\n-1 -49\n6 75\n-27 22\n-58 -77\n-10 56", "20 -1\n22\n-51 -31\n-41 24\n-19 46\n70 -54\n60 5\n-41 35\n73 -6\n-31 0\n-29 23\n85 9\n-7 -86\n8 65\n-86 66\n-35 14\n11 19\n-66 -34\n-36 61\n84 -10\n-58 -74\n-11 -67\n79 74\n3 -67", "-49 4\n23\n-18 -53\n-42 31\n18 -84\n-20 -70\n-12 74\n-72 81\n12 26\n3 9\n-70 -27\n34 -32\n74 -47\n-19 -35\n-46 -8\n-77 90\n7 -42\n81 25\n84 81\n-53 -49\n20 81\n-39 0\n-70 -44\n-63 77\n-67 -73", "-81 35\n24\n58 27\n92 -93\n-82 63\n-55 80\n20 67\n33 93\n-29 46\n-71 -51\n-19 8\n58 -71\n13 60\n0 -48\n-2 -68\n-56 53\n62 52\n64 32\n-12 -63\n-82 -22\n9 -43\n55 12\n77 -21\n26 -25\n-91 -32\n-66 57", "45 79\n24\n-66 22\n10 77\n74 88\n59 1\n-51 -86\n-60 91\n1 -51\n-23 85\n3 96\n38 -4\n-55 43\n9 -68\n-4 83\n75 -13\n64 -74\n28 27\n92 -57\n-20 -64\n30 -44\n-95 67\n13 55\n67 -4\n42 77\n61 87", "-61 34\n24\n-57 -46\n-37 -24\n-87 -54\n51 -89\n-90 2\n95 -63\n-24 -84\n-85 38\n-52 -62\n96 4\n89 -22\n-16 -3\n-2 -14\n71 -62\n-51 68\n-83 -24\n15 77\n-61 45\n17 -32\n-68 -87\n-93 -28\n-85 24\n-84 -34\n-4 1", "70 90\n24\n-64 -96\n-87 -82\n10 -65\n94 22\n95 60\n-13 54\n-83 -92\n95 -50\n-65 -91\n96 -88\n80 -56\n-31 85\n58 86\n-28 22\n-22 45\n-24 -12\n-62 70\n-2 -77\n-31 -72\n61 37\n67 43\n-5 -30\n-84 -59\n-91 51", "72 -37\n24\n56 -47\n-37 -20\n76 -46\n-14 11\n-63 -46\n52 74\n-60 -23\n27 8\n-78 -26\n15 -23\n74 -90\n39 -64\n86 53\n77 11\n-47 -44\n-1 -14\n90 56\n76 -88\n-27 51\n-67 -8\n-27 4\n83 -91\n54 68\n56 26", "9 -5\n10\n-22 23\n22 -26\n10 -32\n18 -34\n7 -27\n2 -38\n-5 -24\n-38 -15\n21 -32\n-17 37"], "outputs": ["8\n0 1 2 0 ", "32\n0 1 2 0 3 0 ", "58\n0 1 0 ", "490\n0 1 2 0 ", "502\n0 1 0 2 3 0 ", "922\n0 1 0 2 4 0 3 0 ", "1764\n0 1 3 0 2 5 0 4 0 ", "2584\n0 1 2 0 3 0 4 6 0 5 0 ", "6178\n0 1 4 0 2 0 3 7 0 5 6 0 ", "14062\n0 1 2 0 3 7 0 4 5 0 6 8 0 ", "9384\n0 1 7 0 2 0 3 9 0 4 5 0 6 8 0 ", "191534\n0 1 22 0 2 10 0 3 14 0 4 18 0 5 20 0 6 11 0 7 0 8 24 0 9 17 0 12 15 0 13 23 0 16 19 0 21 0 ", "19400\n0 1 3 0 2 11 0 4 6 0 5 9 0 7 0 8 10 0 ", "59712\n0 1 5 0 2 10 0 3 11 0 4 8 0 6 12 0 7 9 0 ", "52988\n0 1 9 0 2 0 3 13 0 4 5 0 6 8 0 7 10 0 11 12 0 ", "55146\n0 1 4 0 2 7 0 3 5 0 6 11 0 8 13 0 9 12 0 10 14 0 ", "60546\n0 1 3 0 2 11 0 4 14 0 5 15 0 6 0 7 10 0 8 9 0 12 13 0 ", "81108\n0 1 12 0 2 11 0 3 14 0 4 13 0 5 9 0 6 16 0 7 15 0 8 10 0 ", "171198\n0 1 14 0 2 10 0 3 7 0 4 5 0 6 17 0 8 15 0 9 0 11 16 0 12 13 0 ", "70504\n0 1 4 0 2 5 0 3 11 0 6 13 0 7 9 0 8 0 10 0 12 16 0 14 18 0 15 17 0 ", "112710\n0 1 10 0 2 15 0 3 16 0 4 0 5 11 0 6 18 0 7 8 0 9 12 0 13 17 0 14 19 0 ", "288596\n0 1 19 0 2 13 0 3 6 0 4 16 0 5 7 0 8 15 0 9 14 0 10 17 0 11 18 0 12 20 0 ", "196482\n0 1 15 0 2 4 0 3 0 5 12 0 6 21 0 7 10 0 8 19 0 9 16 0 11 20 0 13 17 0 14 18 0 ", "181122\n0 1 17 0 2 16 0 3 20 0 4 5 0 6 18 0 7 10 0 8 13 0 9 15 0 11 14 0 12 21 0 19 22 0 ", "492344\n0 1 12 0 2 23 0 3 11 0 4 14 0 5 16 0 6 22 0 7 20 0 8 19 0 9 10 0 13 0 15 17 0 18 21 0 ", "204138\n0 1 22 0 2 7 0 3 6 0 4 5 0 8 19 0 9 20 0 10 23 0 11 21 0 12 15 0 13 16 0 14 18 0 17 24 0 ", "121890\n0 1 10 0 2 19 0 3 15 0 4 11 0 5 0 6 16 0 7 9 0 8 17 0 12 13 0 14 20 0 18 21 0 ", "135950\n0 1 16 0 2 6 0 3 12 0 4 18 0 5 7 0 8 14 0 9 15 0 10 21 0 11 22 0 13 17 0 19 20 0 ", "169524\n0 1 4 0 2 22 0 3 15 0 5 19 0 6 14 0 7 8 0 9 21 0 10 11 0 12 13 0 16 17 0 18 23 0 20 0 ", "337256\n0 1 16 0 2 10 0 3 24 0 4 14 0 5 11 0 6 15 0 7 9 0 8 17 0 12 13 0 18 23 0 19 22 0 20 21 0 ", "277576\n0 1 11 0 2 9 0 3 24 0 4 16 0 5 18 0 6 20 0 7 12 0 8 13 0 10 19 0 14 22 0 15 17 0 21 23 0 ", "262400\n0 1 9 0 2 12 0 3 23 0 4 19 0 5 22 0 6 14 0 7 20 0 8 18 0 10 11 0 13 24 0 15 17 0 16 21 0 ", "585696\n0 1 7 0 2 23 0 3 18 0 4 8 0 5 0 6 12 0 9 19 0 10 11 0 13 0 14 15 0 16 22 0 17 24 0 20 21 0 ", "224008\n0 1 3 0 2 7 0 4 19 0 5 15 0 6 23 0 8 10 0 9 20 0 11 12 0 13 17 0 14 24 0 16 21 0 18 22 0 ", "13454\n0 1 10 0 2 9 0 3 4 0 5 6 0 7 8 0 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 6 | codeforces |
|
c1e7da4ca3f099a03821e7eefe9f889b | Ilya and Escalator | Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.
Let's assume that *n* people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability *p*, or the first person in the queue doesn't move with probability (1<=-<=*p*), paralyzed by his fear of escalators and making the whole queue wait behind him.
Formally speaking, the *i*-th person in the queue cannot enter the escalator until people with indices from 1 to *i*<=-<=1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after *t* seconds.
Your task is to help him solve this complicated task.
The first line of the input contains three numbers *n*,<=*p*,<=*t* (1<=β€<=*n*,<=*t*<=β€<=2000, 0<=β€<=*p*<=β€<=1). Numbers *n* and *t* are integers, number *p* is real, given with exactly two digits after the decimal point.
Print a single real number β the expected number of people who will be standing on the escalator after *t* seconds. The absolute or relative error mustn't exceed 10<=-<=6.
Sample Input
1 0.50 1
1 0.50 4
4 0.20 2
Sample Output
0.5
0.9375
0.4
| {"inputs": ["1 0.50 1", "1 0.50 4", "4 0.20 2", "2000 0.61 2000", "100 1.00 200", "417 0.57 742", "100 0.01 53", "300 0.05 55", "1400 0.02 200", "2000 0.01 234", "1 0.01 2000", "300 0.99 1000", "400 0.96 1754", "2000 0.93 100", "1000 0.90 1733", "1 1.00 1", "2000 1.00 2000", "2000 0.00 2000", "2000 0.01 2000", "2000 0.99 2000", "654 0.67 999", "132 0.34 241", "984 0.19 1565", "439 0.83 790", "559 0.92 1006", "887 0.69 1596", "211 0.78 379", "539 0.54 970", "659 0.97 1186", "87 0.95 156", "415 0.72 747", "639 0.81 1150", "818 0.99 1472", "246 0.98 442", "470 0.74 846"], "outputs": ["0.500000000000000", "0.937500000000000", "0.400000000000000", "1219.999999999999545", "100.000000000000000", "414.074442142061741", "0.530000000000000", "2.750000000000001", "3.999999999999999", "2.340000000000000", "0.999999998136245", "299.999999999999886", "400.000000000000171", "93.000000000000014", "999.999999999999545", "1.000000000000000", "2000.000000000000000", "0.000000000000000", "20.000000000000004", "1980.000000000000000", "652.821925126205883", "81.939999999977616", "297.350000000000023", "439.000000000000000", "558.999999999999773", "886.999999999999545", "211.000000000000000", "522.459296616033384", "659.000000000000455", "87.000000000000014", "415.000000000000000", "638.999999999999659", "818.000000000000000", "245.999999999999972", "470.000000000000114"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 25 | codeforces |
|
c20295e447351fec89195b82e112921a | Preparing Olympiad | You have *n* problems. You have estimated the difficulty of the *i*-th one as integer *c**i*. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least *l* and at most *r*. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least *x*.
Find the number of ways to choose a problemset for the contest.
The first line contains four integers *n*, *l*, *r*, *x* (1<=β€<=*n*<=β€<=15, 1<=β€<=*l*<=β€<=*r*<=β€<=109, 1<=β€<=*x*<=β€<=106) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=106) β the difficulty of each problem.
Print the number of ways to choose a suitable problemset for the contest.
Sample Input
3 5 6 1
1 2 3
4 40 50 10
10 20 30 25
5 25 35 10
10 10 20 10 20
Sample Output
2
2
6
| {"inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20", "4 15 60 10\n10 20 30 25", "1 10 20 1\n15", "10 626451 11471247 246428\n369649 684428 303821 287098 422756 301599 720377 177567 515216 750602", "15 1415849 15540979 356865\n8352 960238 276753 259695 712845 945369 60023 920446 181269 392011 318488 857649 30681 740872 115749", "7 1000 2000 1\n10 20 30 40 50 60 70", "4 10 20 1\n4 6 4 6", "4 10 20 1\n5 15 13 7", "2 10 20 5\n5 10", "5 1098816 3969849 167639\n85627 615007 794045 530104 7091", "13 700147 8713522 390093\n996812 94040 954140 545670 369698 423872 365802 784830 700267 960664 949252 84637 257447", "15 4531977 20754263 137419\n637830 85299 755530 64382 896833 879525 331501 148182 741013 192101 112217 52165 702790 988594 587499", "15 2572491 5084070 823435\n570344 78552 775918 501843 844935 71141 331498 636557 435494 715447 992666 831188 28969 171046 989614", "15 4789415 23152928 233992\n502422 273992 449428 947379 700461 681985 857134 243310 478052 77769 936151 642380 464695 281772 964693", "3 390224 390224 1\n264237 125987 288891", "7 1652707 1652707 1\n492387 684636 235422 332532 924898 499872 192988", "10 501107 501107 1\n843967 30518 196518 619138 204862 690754 274071 550121 173607 359971", "15 6627289 6627289 1\n683844 183950 184972 764255 211665 842336 790234 815301 914823 513046 93547 713159 554415 200951 388028", "15 5083470 5083470 1\n978510 643688 591921 723137 573784 346171 920030 352119 528857 365128 627302 308557 716247 263519 654230", "15 6558665 6558665 1\n572491 435494 916457 775918 823435 78552 501843 331498 71141 844935 636557 992666 570344 831188 715447", "10 159699 10967276 3542\n998862 999751 995306 992648 992661 991407 997503 998809 999740 997669", "5 2815840 8479687 4082\n991137 992161 997887 998891 994990", "15 2898377 6694755 721\n992733 999159 990076 996808 990975 993338 993234 994757 997873 993303 994409 993801 998027 990495 999287", "6 20 70 1\n10 10 20 20 30 30", "6 20 70 1\n10 10 10 10 10 10", "15 1 1000000000 1\n10 20 30 40 50 60 70 80 90 100 110 120 130 140 150", "6 30 40 1\n19 20 21 14 15 16", "4 5 234 2\n10 9 12 11"], "outputs": ["2", "2", "6", "6", "0", "914", "31485", "0", "9", "4", "1", "15", "8026", "6759", "15078", "10875", "1", "1", "1", "1", "1", "1", "942", "14", "9819", "35", "0", "32752", "13", "8"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 67 | codeforces |
|
c238239f5c75f82bf35be066d8493e38 | Sonya and Queries | Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a**i*Β β add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i*Β β delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s*Β β count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.
For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
The first line of the input contains an integer *t* (1<=β€<=*t*<=β€<=100<=000)Β β the number of operation Sonya has to perform.
Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i*Β β the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=β€<=*a**i*<=<<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.
It's guaranteed that there will be at least one query of type '?'.
It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
Sample Input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
4
+ 200
+ 200
- 200
? 0
Sample Output
2
1
2
1
1
1
| {"inputs": ["12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "4\n+ 200\n+ 200\n- 200\n? 0", "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00", "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\n? 11\n- 50\n? 10\n? 1\n- 9\n? 1\n? 11\n- 79\n? 11", "10\n+ 870566619432760298\n+ 869797178280285214\n+ 609920823721618090\n+ 221159591436767023\n+ 730599542279836538\n? 101001100111001011\n? 001111010101010011\n? 100010100011101110\n? 100110010110001100\n? 110000011101110011", "10\n+ 96135\n? 10111\n+ 63322\n? 10111\n+ 44490\n? 10111\n+ 69312\n? 10111\n? 01100\n+ 59396", "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011", "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\n- 70424\n? 00011\n+ 29\n? 00001\n+ 6632\n+ 3319\n? 00001\n+ 3172\n? 01111\n- 29"], "outputs": ["2\n1\n2\n1\n1", "1", "3\n2\n3\n4\n4\n2\n2", "0\n1\n0\n2\n1\n0\n1\n0\n1\n0", "0\n0\n0\n0\n0", "1\n1\n1\n1\n1", "1\n1", "1\n1\n1\n1\n1\n1\n1\n1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 30 | codeforces |
|
c24a81f69a8987d5a513e4987cd9b6b9 | Arpaβs obvious problem and Mehrdadβs terrible solution | There are some beautiful girls in Arpaβs land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=β€<=*i*<=<<=*j*<=β€<=*n*) such that , where is bitwise xor operation (see notes for explanation).
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
First line contains two integers *n* and *x* (1<=β€<=*n*<=β€<=105,<=0<=β€<=*x*<=β€<=105)Β β the number of elements in the array and the integer *x*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105)Β β the elements of the array.
Print a single integer: the answer to the problem.
Sample Input
2 3
1 2
6 1
5 1 2 3 4 1
Sample Output
12 | {"inputs": ["2 3\n1 2", "6 1\n5 1 2 3 4 1", "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423", "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 135 519 174 147 201 564 182 359 41 465 162 125 378 342 144 549 363 309", "27 41\n156 148 86 161 113 80 185 15 204 185 205 95 147 146 133 187 114 8 11 120 117 167 100 171 140 102 174", "10 208\n399 912 747 631 510 622 234 707 483 496", "64 43\n78 90 211 205 198 4 172 43 163 21 58 145 28 66 210 68 79 90 155 123 9 119 188 151 180 157 44 163 20 71 28 120 163 141 170 206 31 34 21 195 72 194 83 163 140 40 182 208 127 128 110 72 184 157 128 189 146 35 51 206 62 8 117 61", "69 25\n68 26 8 121 96 101 106 87 103 14 86 26 76 85 70 50 4 4 97 89 44 98 33 65 76 64 98 95 30 5 93 121 97 85 47 50 66 2 46 79 46 22 68 59 75 94 104 105 91 97 121 6 32 94 101 125 32 91 76 57 110 31 27 97 91 49 45 37 92", "64 118\n361 547 410 294 448 377 482 490 13 116 346 50 251 330 443 128 543 580 370 489 337 509 414 291 228 71 245 308 319 314 154 39 317 288 145 248 547 152 262 278 89 108 522 238 128 575 112 469 86 230 310 492 127 270 475 25 179 72 345 444 17 332 544 338", "52 231\n229 492 1005 498 786 274 773 573 316 774 977 110 709 49 131 81 1146 1028 451 451 776 470 996 363 581 484 1023 858 1115 273 1105 4 445 509 428 125 432 131 360 404 280 808 649 4 499 1097 831 512 208 996 430 1010", "4 0\n1 2 3 4", "3 0\n2 2 2", "5 0\n1 1 1 1 1", "3 0\n1 1 1", "4 0\n2 2 2 2", "3 0\n10 10 10", "3 0\n3 3 3", "4 0\n1 1 1 1", "3 0\n4 4 4", "2 0\n2 2", "2 0\n2 3", "2 0\n1 2", "5 0\n5 5 5 5 5", "6 0\n1 1 1 1 1 1", "2 0\n1 1", "4 0\n1 1 3 3", "2 0\n10 10", "4 0\n3 3 3 3", "5 0\n1 1 1 2 2", "5 0\n1 1 2 2 3", "10 0\n1 1 1 1 1 1 1 1 1 1", "2 0\n3 3"], "outputs": ["1", "2", "0", "1", "1", "0", "8", "21", "3", "0", "0", "3", "10", "3", "6", "3", "3", "6", "3", "1", "0", "0", "10", "15", "1", "2", "1", "6", "4", "2", "45", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 16 | codeforces |
|
c25593723134889d759fd6786d906c97 | none | Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.
While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one β by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged.
If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*.
All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.
Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.
The first line of the input contains a positive integer *n* (1<=β€<=*n*<=β€<=4000) β the number of kids in the line.
Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=β€<=*v**i*,<=*d**i*,<=*p**i*<=β€<=106) β the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child.
In the first line print number *k* β the number of children whose teeth Gennady will cure.
In the second line print *k* integers β the numbers of the children who will make it to the end of the line in the increasing order.
Sample Input
5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2
5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9
Sample Output
2
1 3 4
1 2 4 5 | {"inputs": ["5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2", "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9", "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24", "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5", "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 30\n8 7 38\n6 5 5\n6 9 37", "10\n10 3 3\n8 6 17\n9 5 26\n10 7 17\n3 10 29\n3 1 27\n3 3 7\n8 10 28\n1 3 23\n3 4 6", "10\n5 6 1\n9 2 6\n4 1 5\n4 10 5\n1 8 23\n9 4 21\n3 9 6\n7 8 34\n7 4 24\n8 9 21", "4\n2 10 1\n1 2 2\n2 1 1\n5 5 1", "1\n1 1 1", "2\n5 1 1\n1 1 5", "2\n5 1 1\n1 1 4", "2\n5 1 1\n1 1 6", "3\n5 1 1\n1 1 4\n1 1 4", "3\n5 1 1\n1 1 4\n1 1 5", "3\n5 1 1\n1 1 5\n1 1 3", "3\n5 1 1\n10 1 5\n1000 1000 14", "10\n9 8 8\n2 9 33\n10 7 42\n7 2 18\n3 5 82\n9 9 25\n3 2 86\n3 5 49\n5 3 72\n4 4 71", "10\n9 8 8\n2 9 8\n10 7 16\n7 2 9\n3 5 23\n9 9 25\n3 2 35\n3 5 36\n5 3 40\n4 4 42"], "outputs": ["2\n1 3 ", "4\n1 2 4 5 ", "3\n1 2 5 ", "6\n1 2 3 4 5 7 ", "8\n1 2 3 4 5 7 8 10 ", "5\n1 2 3 5 8 ", "5\n1 2 5 6 8 ", "3\n1 2 4 ", "1\n1 ", "2\n1 2 ", "1\n1 ", "2\n1 2 ", "1\n1 ", "2\n1 3 ", "2\n1 2 ", "3\n1 2 3 ", "10\n1 2 3 4 5 6 7 8 9 10 ", "1\n1 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 10 | codeforces |
|
c25b6da41baeb504d209ee704414dbfc | Area of a Star | It was decided in IT City to distinguish successes of local IT companies by awards in the form of stars covered with gold from one side. To order the stars it is necessary to estimate order cost that depends on the area of gold-plating. Write a program that can calculate the area of a star.
A "star" figure having *n*<=β₯<=5 corners where *n* is a prime number is constructed the following way. On the circle of radius *r* *n* points are selected so that the distances between the adjacent ones are equal. Then every point is connected by a segment with two maximally distant points. All areas bounded by the segments parts are the figure parts.
The only line of the input contains two integers *n* (5<=β€<=*n*<=<<=109, *n* is prime) and *r* (1<=β€<=*r*<=β€<=109) β the number of the star corners and the radius of the circumcircle correspondingly.
Output one number β the star area. The relative error of your answer should not be greater than 10<=-<=7.
Sample Input
7 10
Sample Output
108.395919545675 | {"inputs": ["7 10", "5 1", "7 1000", "11 1000000000", "999999937 1", "999999929 2", "999999929 1000000000", "603530531 585244", "7369339 31415926", "2341 5001"], "outputs": ["108.395919545675", "1.122569941449", "1083959.195456745256", "1061689977712182980.125000000000", "1.047197551197", "4.188790204786", "1047197551196597556.500000000000", "358676198261.124618709087", "1033542520749354.968872070312", "26190419.663812126875"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
c261497be852ac543fbe17bd9a243b60 | Vulnerable Kerbals | You are given an integer *m*, and a list of *n* distinct integers between 0 and *m*<=-<=1.
You would like to construct a sequence satisfying the properties:
- Each element is an integer between 0 and *m*<=-<=1, inclusive. - All prefix products of the sequence modulo *m* are distinct. - No prefix product modulo *m* appears as an element of the input list. - The length of the sequence is maximized.
Construct any sequence satisfying the properties above.
The first line of input contains two integers *n* and *m* (0<=β€<=*n*<=<<=*m*<=β€<=200<=000)Β β the number of forbidden prefix products and the modulus.
If *n* is non-zero, the next line of input contains *n* distinct integers between 0 and *m*<=-<=1, the forbidden prefix products. If *n* is zero, this line doesn't exist.
On the first line, print the number *k*, denoting the length of your sequence.
On the second line, print *k* space separated integers, denoting your sequence.
Sample Input
0 5
3 10
2 9 1
Sample Output
5
1 2 4 3 0
6
3 9 2 9 8 0
| {"inputs": ["0 5", "3 10\n2 9 1", "0 1", "0 720", "0 9997", "0 200000", "10 200000\n7853 79004 71155 23846 63333 31964 47634 15792 39758 55551", "3 19997\n4524 13719 9073", "3 19997\n2024 4058 6143", "3 19997\n6068 18563 12338"], "outputs": ["5\n1 2 4 3 0", "6\n3 9 2 9 8 0", "1\n0", "397\n1 7 413 263 389 467 77 283 299 187 293 563 269 47 677 463 599 367 173 143 149 347 557 643 179 547 53 443 29 647 437 103 479 7 653 23 629 227 317 283 59 187 533 323 509 527 197 463 359 367 413 623 389 107 77 643 659 547 293 203 269 407 677 103 239 7 173 503 149 707 557 283 539 187 53 83 29 287 437 463 119 367 653 383 629 587 317 643 419 547 533 683 509 167 197 103 719 7 413 263 389 467 77 283 299 187 293 563 269 47 677 463 599 367 173 143 149 347 557 643 179 547 53 443 29 647 437 103 479 7 653 23 629 2...", "9985\n1 2 5000 6666 7499 4000 8332 8570 3750 5555 6999 5454 8332 9284 1334 6874 9410 2778 3158 3500 9522 7726 1305 4583 3600 8517 9641 3793 5666 646 8436 5151 9704 7713 6388 5675 3158 6749 1464 9760 466 8862 7110 653 7871 2292 9794 3400 9606 1510 4259 3091 4821 7718 1897 5762 7832 5737 5322 6507 8436 2576 6417 9851 3768 3857 9294 8193 7533 2838 2267 8288 1559 1393 3375 6172 5731 8914 9879 7881 5232 1265 9430 5168 7110 327 216 3936 8630 6145 1650 9896 5050 6699 5049 9900 3301 5904 5754 9344 2130 9356 1546 8...", "160625\n1 3 66669 114287 177779 18183 92309 164707 63159 104763 104349 125927 124139 167743 78789 145947 148719 195123 111629 12767 44899 54903 18869 154387 40679 95083 136509 38807 84059 143663 120549 174027 43039 108643 146989 108047 105619 178023 111829 28867 179799 19803 31069 164487 93579 181983 40709 182907 194959 92563 196749 192127 151939 59543 75189 140147 152519 70923 172029 14967 104699 194703 103269 44587 36479 178883 4909 97007 95859 51463 132949 80227 150839 120443 63389 142247 189419 173823 ...", "160616\n1 3 66669 114287 177779 18183 92309 164707 63159 104763 104349 125927 124139 167743 78789 145947 148719 195123 111629 12767 44899 54903 18869 154387 40679 95083 136509 38807 84059 143663 120549 174027 43039 108643 146989 108047 105619 178023 111829 28867 179799 19803 31069 164487 93579 181983 40709 182907 194959 92563 196749 192127 151939 59543 75189 140147 152519 70923 172029 14967 104699 194703 103269 44587 36479 178883 4909 97007 95859 51463 132949 80227 150839 120443 63389 142247 189419 173823 ...", "19994\n1 2 10000 6667 14999 8000 3334 11428 7500 2223 13999 1819 11666 6154 15713 9333 13749 11764 1112 2106 7000 3810 910 13912 15832 13599 13076 14073 7857 6207 4667 9677 6875 607 15881 18284 10555 7027 11052 2052 13499 7317 11904 9767 10454 16443 16955 13616 17915 15917 6800 3922 16537 16225 7037 4364 3929 14034 3104 5085 2334 16392 4839 14602 3438 5231 304 16118 7941 4638 19141 15210 5278 12054 3514 17865 15525 17401 11025 17973 6750 18023 3659 3374 15951 6353 4884 15401 15226 7865 8222 880 8478 9892 1...", "19994\n1 2 10000 6667 14999 8000 3334 11428 7500 2223 13999 1819 11666 6154 15713 9333 13749 11764 1112 2106 7000 3810 910 13912 15832 13599 13076 14073 7857 6207 4667 9677 6875 607 15881 18284 10555 7027 11052 2052 13499 7317 11904 9767 10454 16443 16955 13616 17915 15917 6800 3922 16537 16225 7037 4364 3929 14034 3104 5085 2334 16392 4839 14602 3438 5231 304 16118 7941 4638 19141 15210 5278 12054 3514 17865 15525 17401 11025 17973 6750 18023 3659 3374 15951 6353 4884 15401 15226 7865 8222 880 8478 9892 1...", "19994\n1 2 10000 6667 14999 8000 3334 11428 7500 2223 13999 1819 11666 6154 15713 9333 13749 11764 1112 2106 7000 3810 910 13912 15832 13599 13076 14073 7857 6207 4667 9677 6875 607 15881 18284 10555 7027 11052 2052 13499 7317 11904 9767 10454 16443 16955 13616 17915 15917 6800 3922 16537 16225 7037 4364 3929 14034 3104 5085 2334 16392 4839 14602 3438 5231 304 16118 7941 4638 19141 15210 5278 12054 3514 17865 15525 17401 11025 17973 6750 18023 3659 3374 15951 6353 4884 15401 15226 7865 8222 880 8478 9892 1..."]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
c27368c56a4d9ea1647917157aef81aa | Check the string | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.
You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Print "YES" or "NO", according to the condition.
Sample Input
aaabccc
bbacc
aabc
Sample Output
YES
NO
YES
| {"inputs": ["aaabccc", "bbacc", "aabc", "aabbcc", "aaacccbb", "abc", "acba", "bbabbc", "bbbabacca", "aabcbcaca", "aaaaabbbbbb", "c", "cc", "bbb", "bc", "ccbcc", "aaa", "aaccaa", "a", "b", "abca", "aabbcccc", "abac", "abcc", "abcb", "aacc", "aabbaacccc", "aabb", "ac", "abbacc", "abacc", "ababc", "aa", "aabaccc", "bbcc", "aaabcbc", "acbbc", "babc", "bbbcc", "bbc", "abababccc", "ccbbaa"], "outputs": ["YES", "NO", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 120 | codeforces |
|
c28cf0add33a4e63ce6077ddf93bd7e9 | Devu, the Dumb Guy | Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial per chapter learning power of a subject is *x* hours. In other words he can learn a chapter of a particular subject in *x* hours.
Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.
You can teach him the *n* subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.
Please be careful that answer might not fit in 32 bit data type.
The first line will contain two space separated integers *n*, *x* (1<=β€<=*n*,<=*x*<=β€<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=β€<=*c**i*<=β€<=105).
Output a single integer representing the answer to the problem.
Sample Input
2 3
4 1
4 2
5 1 2 1
3 3
1 1 1
Sample Output
11
10
6
| {"inputs": ["2 3\n4 1", "4 2\n5 1 2 1", "3 3\n1 1 1", "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3", "1 1\n9273", "1 1\n1", "1 2\n1", "1 2\n2", "2 1\n1 2"], "outputs": ["11", "10", "6", "65", "196", "9273", "1", "2", "4", "3"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 299 | codeforces |
|
c2a566fe43974d07b567fd3c0e438366 | Byteland, Berland and Disputed Cities | The cities of Byteland and Berland are located on the axis $Ox$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $Ox$ there are three types of cities:
- the cities of Byteland, - the cities of Berland, - disputed cities.
Recently, the project BNET has been launched β a computer network of a new generation. Now the task of the both countries is to connect the cities so that the network of this country is connected.
The countries agreed to connect the pairs of cities with BNET cables in such a way that:
- If you look at the only cities of Byteland and the disputed cities, then in the resulting set of cities, any city should be reachable from any other one by one or more cables, - If you look at the only cities of Berland and the disputed cities, then in the resulting set of cities, any city should be reachable from any other one by one or more cables.
Thus, it is necessary to choose a set of pairs of cities to connect by cables in such a way that both conditions are satisfied simultaneously. Cables allow bi-directional data transfer. Each cable connects exactly two distinct cities.
The cost of laying a cable from one city to another is equal to the distance between them. Find the minimum total cost of laying a set of cables so that two subsets of cities (Byteland and disputed cities, Berland and disputed cities) are connected.
Each city is a point on the line $Ox$. It is technically possible to connect the cities $a$ and $b$ with a cable so that the city $c$ ($a < c < b$) is not connected to this cable, where $a$, $b$ and $c$ are simultaneously coordinates of the cities $a$, $b$ and $c$.
The first line contains a single integer $n$ ($2 \le n \le 2 \cdot 10^{5}$) β the number of cities.
The following $n$ lines contains an integer $x_i$ and the letter $c_i$ ($-10^{9} \le x_i \le 10^{9}$) β the coordinate of the city and its type. If the city belongs to Byteland, $c_i$ equals to 'B'. If the city belongs to Berland, $c_i$ equals to Β«RΒ». If the city is disputed, $c_i$ equals to 'P'.
All cities have distinct coordinates. Guaranteed, that the cities are given in the increasing order of their coordinates.
Print the minimal total length of such set of cables, that if we delete all Berland cities ($c_i$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($c_i$='B'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables.
Sample Input
4
-5 R
0 P
3 P
7 B
5
10 R
14 B
16 B
21 R
32 R
Sample Output
12
24
| {"inputs": ["4\n-5 R\n0 P\n3 P\n7 B", "5\n10 R\n14 B\n16 B\n21 R\n32 R", "10\n66 R\n67 R\n72 R\n73 R\n76 R\n78 B\n79 B\n83 B\n84 B\n85 P", "10\n61 R\n64 R\n68 R\n71 R\n72 R\n73 R\n74 P\n86 P\n87 B\n90 B", "15\n-9518 R\n-6858 P\n-6726 B\n-6486 R\n-4496 P\n-4191 P\n-772 B\n-258 R\n-194 P\n1035 R\n2297 P\n4816 B\n5779 R\n9342 B\n9713 B", "6\n-8401 R\n-5558 P\n-3457 P\n-2361 R\n6966 P\n8140 B", "2\n1 R\n2 R", "2\n-1000000000 B\n1000000000 R", "2\n-1000000000 P\n1000000000 P", "2\n-1000000000 B\n1000000000 P", "9\n-105 R\n-81 B\n-47 P\n-25 R\n-23 B\n55 P\n57 R\n67 B\n76 P", "6\n-13 R\n-10 P\n-6 R\n-1 P\n4 R\n10 P", "8\n-839 P\n-820 P\n-488 P\n-334 R\n-83 B\n187 R\n380 B\n804 P", "8\n-12 P\n-9 B\n-2 R\n-1 R\n2 B\n8 B\n9 R\n15 P", "6\n0 B\n3 P\n7 B\n9 B\n11 P\n13 B"], "outputs": ["12", "24", "26", "29", "25088", "17637", "1", "0", "2000000000", "2000000000", "272", "32", "2935", "54", "17"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 6 | codeforces |
|
c2d5c5716d620d4c3e6264bef5bdc57b | Wizards and Trolleybuses | In some country live wizards. They love to ride trolleybuses.
A city in this country has a trolleybus depot with *n* trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of *d* meters from the depot. We know for the *i*-th trolleybus that it leaves at the moment of time *t**i* seconds, can go at a speed of no greater than *v**i* meters per second, and accelerate with an acceleration no greater than *a* meters per second squared. A trolleybus can decelerate as quickly as you want (magic!). It can change its acceleration as fast as you want, as well. Note that the maximum acceleration is the same for all trolleys.
Despite the magic the trolleys are still powered by an electric circuit and cannot overtake each other (the wires are to blame, of course). If a trolleybus catches up with another one, they go together one right after the other until they arrive at the final station. Also, the drivers are driving so as to arrive at the final station as quickly as possible.
You, as head of the trolleybuses' fans' club, are to determine for each trolley the minimum time by which it can reach the final station. At the time of arrival at the destination station the trolleybus does not necessarily have zero speed. When a trolley is leaving the depot, its speed is considered equal to zero. From the point of view of physics, the trolleybuses can be considered as material points, and also we should ignore the impact on the speed of a trolley bus by everything, except for the acceleration and deceleration provided by the engine.
The first input line contains three space-separated integers *n*, *a*, *d* (1<=β€<=*n*<=β€<=105, 1<=β€<=*a*,<=*d*<=β€<=106) β the number of trolleybuses, their maximum acceleration and the distance from the depot to the final station, correspondingly.
Next *n* lines contain pairs of integers *t**i* *v**i* (0<=β€<=*t*1<=<<=*t*2...<=<<=*t**n*<=-<=1<=<<=*t**n*<=β€<=106, 1<=β€<=*v**i*<=β€<=106) β the time when the *i*-th trolleybus leaves the depot and its maximum speed, correspondingly. The numbers in the lines are separated by spaces.
For each trolleybus print a single line the time it arrives to the final station. Print the times for the trolleybuses in the order in which the trolleybuses are given in the input. The answer will be accepted if the absolute or relative error doesn't exceed 10<=-<=4.
Sample Input
3 10 10000
0 10
5 11
1000 1
1 2 26
28 29
Sample Output
1000.5000000000
1000.5000000000
11000.0500000000
33.0990195136
| {"inputs": ["3 10 10000\n0 10\n5 11\n1000 1", "1 2 26\n28 29", "7 8 3\n1 3\n5 26\n7 3\n10 15\n18 7\n21 17\n23 21", "3 6 6\n2 10\n14 19\n18 14", "10 7 8\n2 4\n3 13\n4 7\n5 1\n9 16\n10 9\n12 18\n16 4\n17 16\n20 6", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12", "1 2 7\n20 13", "3 3 3\n13 1\n18 12\n19 2", "8 7 21\n2 11\n3 4\n4 3\n9 23\n15 9\n16 5\n22 17\n24 10", "3 6 19\n12 3\n20 24\n30 2", "4 5 14\n11 1\n16 20\n17 15\n21 7", "1 1 722397\n556297 454495", "1 100000 363166\n560443 753304", "1 124232 477338\n899117 898233", "1 1000000 1000000\n0 1000000", "1 1 1\n0 1000000"], "outputs": ["1000.5000000000\n1000.5000000000\n11000.0500000000", "33.0990195136", "2.1875000000\n5.8660254038\n8.1875000000\n10.8660254038\n18.8660254038\n21.8660254038\n23.8660254038", "3.4142135624\n15.4142135624\n19.4142135624", "4.2857142857\n4.5118578920\n5.6428571429\n13.0714285714\n13.0714285714\n13.0714285714\n13.5118578920\n18.2857142857\n18.5118578920\n21.7619047619", "2.5495097568\n8.5495097568\n12.5495097568\n14.2250000000\n14.5495097568\n22.5495097568\n23.6250000000\n24.5495097568", "22.6457513111", "16.1666666667\n19.4142135624\n20.8333333333", "4.6948051948\n8.5357142857\n11.2142857143\n11.4494897428\n17.9761904762\n20.5571428571\n24.4495798319\n26.8142857143", "18.5833333333\n22.5166114784\n39.6666666667", "25.1000000000\n25.1000000000\n25.1000000000\n25.1000000000", "557498.9958402590", "560445.6950547304", "899119.7721151346", "1.5000000000", "1.4142135624"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 13 | codeforces |
|
c2fb46bcb0c07141a390386eb43d17e6 | Success Rate | You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x*<=/<=*y*.
Your favorite rational number in the [0;1] range is *p*<=/<=*q*. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be *p*<=/<=*q*?
The first line contains a single integer *t* (1<=β€<=*t*<=β€<=1000)Β β the number of test cases.
Each of the next *t* lines contains four integers *x*, *y*, *p* and *q* (0<=β€<=*x*<=β€<=*y*<=β€<=109; 0<=β€<=*p*<=β€<=*q*<=β€<=109; *y*<=><=0; *q*<=><=0).
It is guaranteed that *p*<=/<=*q* is an irreducible fraction.
Hacks. For hacks, an additional constraint of *t*<=β€<=5 must be met.
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
Sample Input
4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1
Sample Output
4
10
0
-1
| {"inputs": ["4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1", "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1", "5\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2", "5\n999999999 1000000000 1 1000000000\n999999999 1000000000 1 1000000000\n999999999 1000000000 1 1000000000\n999999999 1000000000 1 1000000000\n999999999 1000000000 1 1000000000", "5\n0 1000000000 999999999 1000000000\n0 1000000000 999999999 1000000000\n0 1000000000 999999999 1000000000\n0 1000000000 999999999 1000000000\n0 1000000000 999999999 1000000000", "1\n999999999 1000000000 1 2", "1\n50 50 1 1", "1\n100000000 100000000 1 2", "1\n3 999999990 1 1000000000", "5\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1\n1 1 1 1", "5\n9999999 10000000 1 1000000000\n9999999 10000000 1 1000000000\n9999999 10000000 1 1000000000\n9999999 10000000 1 1000000000\n9999999 10000000 1 1000000000", "1\n0 1000000000 999999999 1000000000", "5\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000", "5\n1 1000000000 999999999 1000000000\n2 1000000000 999999999 1000000000\n3 1000000000 999999999 1000000000\n4 1000000000 999999999 1000000000\n5 1000000000 999999999 1000000000", "1\n1 1 1 1", "5\n999999997 999999998 2 999999999\n999999997 999999998 2 999999999\n999999997 999999998 2 999999999\n999999997 999999998 2 999999999\n999999997 999999998 2 999999999", "5\n1000000000 1000000000 1 1000000000\n1000000000 1000000000 1 1000000000\n1000000000 1000000000 1 1000000000\n1000000000 1000000000 1 1000000000\n1000000000 1000000000 1 1000000000", "5\n99999997 999999998 999999998 999999999\n99999996 999999997 999999997 999999999\n99999997 999999998 999999998 999999999\n99999996 999999997 999999997 999999999\n99999997 999999998 999999998 999999999", "1\n1000000000 1000000000 1 1000000000", "1\n7 7 1 1", "5\n1000000000 1000000000 1 2\n1000000000 1000000000 1 2\n1000000000 1000000000 1 2\n1000000000 1000000000 1 2\n1000000000 1000000000 1 2", "1\n1000000000 1000000000 1 1", "1\n1 1000000000 999999999 1000000000", "4\n1 1000000000 999999999 1000000000\n999999999 1000000000 1 1000000000\n1 2 0 1\n0 1 0 1", "1\n1 1000000000 1 2", "5\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2\n1 982449707 1 2", "5\n13 900000007 900000007 900000009\n13 900000007 900000007 900000009\n13 900000007 900000007 900000009\n13 900000007 900000007 900000009\n13 900000007 900000007 900000009", "1\n5 10 0 1", "1\n2 2 1 1", "5\n0 999999999 999999999 1000000000\n0 999999999 999999999 1000000000\n0 999999999 999999999 1000000000\n0 999999999 999999999 1000000000\n0 999999999 999999999 1000000000", "1\n0 5 0 1", "5\n999999999 1000000000 1 9999\n999999999 1000000000 1 9999\n999999999 1000000000 1 9999\n999999999 1000000000 1 9999\n999999999 1000000000 1 9999", "5\n999999997 1000000000 3 1000000000\n999999997 1000000000 3 1000000000\n999999997 1000000000 3 1000000000\n999999997 1000000000 3 1000000000\n999999997 1000000000 3 1000000000", "5\n1000000000 1000000000 1 1000000000\n1000000000 1000000000 1 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000", "5\n1000000000 1000000000 1 1000000000\n1000000000 1000000000 1 1000000000\n1000000000 1000000000 1 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000", "1\n999999998 999999999 1 10", "5\n1 1 1 1\n2 2 1 1\n100 100 1 1\n1000000000 1000000000 1 1\n1000000000 1000000000 1 1", "4\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000\n1 1000000000 999999999 1000000000"], "outputs": ["4\n10\n0\n-1", "0\n2\n-1\n-1\n-1\n-1\n3\n0", "999999998\n999999998\n999999998\n999999998\n999999998", "999999998000000000\n999999998000000000\n999999998000000000\n999999998000000000\n999999998000000000", "999999999000000000\n999999999000000000\n999999999000000000\n999999999000000000\n999999999000000000", "999999998", "0", "100000000", "2000000010", "4\n10\n0\n-1\n0", "9999998990000000\n9999998990000000\n9999998990000000\n9999998990000000\n9999998990000000", "999999999000000000", "999999998000000000\n999999998000000000\n999999998000000000\n999999998000000000\n999999998000000000", "999999998000000000\n999999997000000000\n999999996000000000\n999999995000000000\n999999994000000000", "0", "499999997500000003\n499999997500000003\n499999997500000003\n499999997500000003\n499999997500000003", "999999999000000000\n999999999000000000\n999999999000000000\n999999999000000000\n999999999000000000", "899999999100000001\n449999999550000002\n899999999100000001\n449999999550000002\n899999999100000001", "999999999000000000", "0", "1000000000\n1000000000\n1000000000\n1000000000\n1000000000", "0", "999999998000000000", "999999998000000000\n999999998000000000\n-1\n0", "999999998", "982449705\n982449705\n982449705\n982449705\n982449705", "405000000449999966\n405000000449999966\n405000000449999966\n405000000449999966\n405000000449999966", "-1", "0", "999999998000000001\n999999998000000001\n999999998000000001\n999999998000000001\n999999998000000001", "0", "9997999990001\n9997999990001\n9997999990001\n9997999990001\n9997999990001", "333333332000000000\n333333332000000000\n333333332000000000\n333333332000000000\n333333332000000000", "999999999000000000\n999999999000000000\n999999998000000000\n999999998000000000\n999999998000000000", "999999999000000000\n999999999000000000\n999999999000000000\n999999998000000000\n999999998000000000", "8999999981", "0\n0\n0\n0\n0", "999999998000000000\n999999998000000000\n999999998000000000\n999999998000000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 55 | codeforces |
|
c305e3530a54f2ea0d43187252188974 | Game of Stones | Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:
- The game starts with *n* piles of stones indexed from 1 to *n*. The *i*-th pile contains *s**i* stones.- The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0 stones does not count as a move.- The player who is unable to make a move loses.
Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.
In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.
Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.
First line consists of a single integer *n* (1<=β€<=*n*<=β€<=106) β the number of piles.
Each of next *n* lines contains an integer *s**i* (1<=β€<=*s**i*<=β€<=60) β the number of stones in *i*-th pile.
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
Sample Input
1
5
2
1
2
Sample Output
NOYES | {"inputs": ["1\n5", "2\n1\n2", "3\n34\n44\n21", "6\n34\n44\n21\n55\n1\n36", "14\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32", "10\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59", "12\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40", "118\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43\n48\n16\n5\n35\n20\n21\n36\n15\n2\n11\n56\n58\n2\n40\n47\n29\n21\n4\n21\n1\n25\n51\n55\n17\n40\n56\n35\n51\n1\n34\n18\n54\n44\n1\n43\n16\n28\n21\n14\n57\n53\n29\n44\n59\n54\n47\n21\n43\n41\n11\n37\n30\n4\n39\n47\n40\n50\n52\n9\n32\n1\n19\n30\n20\n6\n25\n42\n34\n38\n42\n46\n35\n28\n20\n47\n60\n46\n35\n59\n24\n11\n25\n27\n9\n51\n39\n35\n22\n24\n10\n48\n6\n30\n10\n33\n51\n45\n38\n8\n51\n8\n7\n46", "124\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43\n48\n16\n5\n35\n20\n21\n36\n15\n2\n11\n56\n58\n2\n40\n47\n29\n21\n4\n21\n1\n25\n51\n55\n17\n40\n56\n35\n51\n1\n34\n18\n54\n44\n1\n43\n16\n28\n21\n14\n57\n53\n29\n44\n59\n54\n47\n21\n43\n41\n11\n37\n30\n4\n39\n47\n40\n50\n52\n9\n32\n1\n19\n30\n20\n6\n25\n42\n34\n38\n42\n46\n35\n28\n20\n47\n60\n46\n35\n59\n24\n11\n25\n27\n9\n51\n39\n35\n22\n24\n10\n48\n6\n30\n10\n33\n51\n45\n38\n8\n51\n8\n7\n46\n49\n27\n16\n13\n4\n54", "15\n34\n44\n21\n55\n1\n36\n53\n31\n58\n59\n11\n40\n20\n32\n43", "2\n34\n44"], "outputs": ["NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c32aecaf273108e539a4710735fff11f | Gosha is hunting | Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has *a* Poke Balls and *b* Ultra Balls. There are *n* Pokemons. They are numbered 1 through *n*. Gosha knows that if he throws a Poke Ball at the *i*-th Pokemon he catches it with probability *p**i*. If he throws an Ultra Ball at the *i*-th Pokemon he catches it with probability *u**i*. He can throw at most one Ball of each type at any Pokemon.
The hunting proceeds as follows: at first, Gosha chooses no more than *a* Pokemons at which he will throw Poke Balls and no more than *b* Pokemons at which he will throw Ultra Balls. After that, he throws the chosen Balls at the chosen Pokemons. If he throws both Ultra Ball and Poke Ball at some Pokemon, he is caught if and only if he is caught by any of these Balls. The outcome of a throw doesn't depend on the other throws.
Gosha would like to know what is the expected number of the Pokemons he catches if he acts in an optimal way. In other words, he would like to know the maximum possible expected number of Pokemons can catch.
The first line contains three integers *n*, *a* and *b* (2<=β€<=*n*<=β€<=2000, 0<=β€<=*a*,<=*b*<=β€<=*n*)Β β the number of Pokemons, the number of Poke Balls and the number of Ultra Balls.
The second line contains *n* real values *p*1,<=*p*2,<=...,<=*p**n* (0<=β€<=*p**i*<=β€<=1), where *p**i* is the probability of catching the *i*-th Pokemon if Gosha throws a Poke Ball to it.
The third line contains *n* real values *u*1,<=*u*2,<=...,<=*u**n* (0<=β€<=*u**i*<=β€<=1), where *u**i* is the probability of catching the *i*-th Pokemon if Gosha throws an Ultra Ball to it.
All the probabilities are given with exactly three digits after the decimal separator.
Print the maximum possible expected number of Pokemons Gosha can catch. The answer is considered correct if it's absolute or relative error doesn't exceed 10<=-<=4.
Sample Input
3 2 2
1.000 0.000 0.500
0.000 1.000 0.500
4 1 3
0.100 0.500 0.500 0.600
0.100 0.500 0.900 0.400
3 2 0
0.412 0.198 0.599
0.612 0.987 0.443
Sample Output
2.75
2.16
1.011 | {"inputs": ["3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500", "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400", "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443", "8 4 1\n0.425 0.709 0.507 0.932 0.085 0.389 0.215 0.508\n0.471 0.825 0.240 0.981 0.184 0.241 0.810 0.711", "7 4 4\n0.642 0.036 0.552 0.936 0.866 0.905 0.409\n0.100 0.247 0.172 0.859 0.036 0.672 0.255", "2 0 0\n0.860 0.363\n0.730 0.668", "10 8 8\n0.078 0.690 0.642 0.945 0.429 0.939 0.797 0.913 0.379 0.691\n0.360 0.090 0.036 0.614 0.741 0.533 0.144 0.809 0.975 0.841", "9 7 3\n0.295 0.017 0.687 0.949 0.210 0.456 0.991 0.381 0.016\n0.990 0.511 0.968 0.492 0.594 0.964 0.589 0.842 0.271", "29 21 14\n0.466 0.740 0.535 0.531 0.988 0.986 0.832 0.548 0.685 0.695 0.746 0.256 0.264 0.367 0.964 0.372 0.622 0.930 0.463 0.870 0.346 0.881 0.778 0.951 0.612 0.584 0.940 0.211 0.090\n0.209 0.603 0.629 0.775 0.641 0.655 0.407 0.192 0.060 0.986 0.317 0.695 0.800 0.272 0.780 0.606 0.153 0.111 0.566 0.294 0.714 0.359 0.029 0.451 0.155 0.254 0.846 0.251 0.165", "31 26 23\n0.119 0.721 0.670 0.544 0.333 0.537 0.414 0.953 0.595 0.741 0.376 0.347 0.328 0.002 0.577 0.319 0.014 0.239 0.388 0.768 0.768 0.479 0.898 0.469 0.571 0.297 0.504 0.462 0.127 0.134 0.335\n0.098 0.868 0.425 0.408 0.198 0.947 0.741 0.290 0.947 0.210 0.537 0.830 0.471 0.338 0.893 0.461 0.446 0.943 0.185 0.462 0.590 0.029 0.390 0.961 0.990 0.924 0.313 0.377 0.765 0.993 0.863", "6 4 4\n0.956 0.032 0.951 0.094 0.958 0.424\n0.678 0.753 0.293 0.318 0.113 0.434", "41 8 22\n0.173 0.359 0.996 0.098 0.739 0.941 0.489 0.622 0.314 0.932 0.950 0.080 0.383 0.346 0.729 0.456 0.590 0.455 0.159 0.900 0.700 0.128 0.675 0.954 0.703 0.646 0.757 0.197 0.474 0.957 0.225 0.426 0.652 0.616 0.677 0.707 0.645 0.854 0.102 0.908 0.924\n0.307 0.174 0.225 0.196 0.965 0.865 0.044 0.976 0.874 0.089 0.783 0.527 0.840 0.165 0.914 0.095 0.702 0.657 0.246 0.773 0.806 0.011 0.810 0.302 0.033 0.779 0.036 0.767 0.428 0.585 0.420 0.412 0.763 0.180 0.119 0.108 0.587 0.254 0.162 0.210 0.588", "12 6 8\n0.609 0.013 0.086 0.106 0.302 0.974 0.877 0.559 0.588 0.296 0.370 0.474\n0.567 0.017 0.089 0.952 0.670 0.726 0.934 0.041 0.465 0.572 0.930 0.617", "14 11 12\n0.262 0.995 0.220 0.119 0.646 0.524 0.459 0.964 0.497 0.342 0.000 0.565 0.157 0.736\n0.456 0.282 0.885 0.585 0.228 0.019 0.267 0.139 0.353 0.795 0.150 0.752 0.624 0.941", "33 10 20\n0.937 0.314 0.811 0.471 0.081 0.086 0.293 0.414 0.883 0.945 0.060 0.848 0.222 0.911 0.172 0.313 0.354 0.257 0.029 0.498 0.841 0.043 0.473 0.871 0.181 0.326 0.819 0.972 0.619 0.070 0.370 0.520 0.846\n0.596 0.015 0.766 0.946 0.480 0.127 0.217 0.093 0.134 0.953 0.542 0.384 0.635 0.415 0.905 0.925 0.728 0.145 0.677 0.490 0.220 0.475 0.587 0.540 0.767 0.134 0.793 0.519 0.673 0.346 0.636 0.238 0.590", "4 4 3\n0.372 0.969 0.901 0.479\n0.856 0.858 0.630 0.701", "35 21 17\n0.590 0.296 0.946 0.483 0.425 0.636 0.875 0.819 0.792 0.991 0.690 0.938 0.286 0.545 0.785 0.259 0.746 0.566 0.954 0.396 0.263 0.641 0.593 0.389 0.140 0.039 0.384 0.223 0.656 0.319 0.896 0.388 0.685 0.599 0.827\n0.485 0.280 0.562 0.579 0.037 0.419 0.551 0.191 0.021 0.177 0.762 0.518 0.306 0.481 0.018 0.779 0.021 0.978 0.296 0.658 0.096 0.144 0.948 0.050 0.602 0.805 0.260 0.645 0.273 0.226 0.332 0.150 0.802 0.227 0.516", "3 2 2\n0.025 0.950 0.035\n0.745 0.123 0.426", "38 21 14\n0.243 0.277 0.080 0.496 0.769 0.186 0.457 0.224 0.702 0.037 0.320 0.029 0.350 0.180 0.398 0.206 0.138 0.875 0.879 0.293 0.685 0.239 0.712 0.907 0.100 0.752 0.948 0.475 0.692 0.567 0.422 0.256 0.525 0.139 0.355 0.261 0.511 0.912\n0.375 0.544 0.358 0.212 0.595 0.711 0.885 0.288 0.908 0.401 0.982 0.653 0.976 0.546 0.131 0.634 0.314 0.810 0.915 0.826 0.971 0.814 0.309 0.559 0.438 0.475 0.727 0.772 0.873 0.106 0.028 0.061 0.015 0.189 0.966 0.971 0.350 0.984", "24 18 15\n0.959 0.760 0.149 0.151 0.727 0.189 0.885 0.001 0.707 0.444 0.186 0.591 0.886 0.067 0.767 0.221 0.966 0.661 0.271 0.246 0.599 0.499 0.059 0.284\n0.407 0.626 0.014 0.589 0.111 0.735 0.538 0.419 0.780 0.600 0.703 0.944 0.113 0.821 0.877 0.142 0.092 0.017 0.393 0.702 0.061 0.118 0.999 0.552"], "outputs": ["2.75", "2.1600000000000001421", "1.0109999999999998987", "3.4660000000000001918", "4.4030560000000003029", "0", "8.2298779999999993606", "5.726613999999999649", "21.622652999999999679", "23.385518999999998613", "4.6398159999999997183", "22.63200000000000145", "8.1265070000000001471", "10.145936999999999983", "20.728999999999999204", "3.6861589999999999634", "23.92238100000000145", "2.1410900000000001597", "23.350999999999999091", "17.541436999999998392"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c33a7c4403551ca5163e14847cc720c9 | Bus of Characters | In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:
- an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it; - an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it.
You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β the number of rows in the bus.
The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct.
The third line contains a string of length $2n$, consisting of digits '0' and '1' β the description of the order the passengers enter the bus. If the $j$-th character is '0', then the passenger that enters the bus on the $j$-th stop is an introvert. If the $j$-th character is '1', the the passenger that enters the bus on the $j$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i.Β e. both numbers equal $n$), and for each extrovert there always is a suitable row.
Print $2n$ integers β the rows the passengers will take. The order of passengers should be the same as in input.
Sample Input
2
3 1
0011
6
10 8 9 11 13 5
010010011101
Sample Output
2 1 1 2
6 6 2 3 3 1 4 4 1 2 5 5
| {"inputs": ["2\n3 1\n0011", "6\n10 8 9 11 13 5\n010010011101", "1\n1\n01", "1\n1000000\n01", "2\n1 1000000\n0011", "2\n1000000000 1\n0101", "2\n1000000000 999999999\n0011", "10\n24 53 10 99 83 9 15 62 33 47\n00100000000111111111"], "outputs": ["2 1 1 2 ", "6 6 2 3 3 1 4 4 1 2 5 5 ", "1 1 ", "1 1 ", "1 2 2 1 ", "2 2 1 1 ", "2 1 1 2 ", "6 3 3 7 1 9 10 2 8 5 4 4 5 8 2 10 9 1 7 6 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 68 | codeforces |
|
c33ee1ebed2d67a1fc93b05bf3e8b65a | Eugeny and Play List | Eugeny loves listening to music. He has *n* songs in his play list. We know that song number *i* has the duration of *t**i* minutes. Eugeny listens to each song, perhaps more than once. He listens to song number *i* *c**i* times. Eugeny's play list is organized as follows: first song number 1 plays *c*1 times, then song number 2 plays *c*2 times, ..., in the end the song number *n* plays *c**n* times.
Eugeny took a piece of paper and wrote out *m* moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment *x* means that Eugeny wants to know which song was playing during the *x*-th minute of his listening to the play list.
Help Eugeny and calculate the required numbers of songs.
The first line contains two integers *n*, *m* (1<=β€<=*n*,<=*m*<=β€<=105). The next *n* lines contain pairs of integers. The *i*-th line contains integers *c**i*,<=*t**i* (1<=β€<=*c**i*,<=*t**i*<=β€<=109) β the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 .
The next line contains *m* positive integers *v*1,<=*v*2,<=...,<=*v**m*, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time *v**i*, when the music doesn't play any longer. It is guaranteed that *v**i*<=<<=*v**i*<=+<=1 (*i*<=<<=*m*).
The moment of time *v**i* means that Eugeny wants to know which song was playing during the *v**i*-th munite from the start of listening to the playlist.
Print *m* integers β the *i*-th number must equal the number of the song that was playing during the *v**i*-th minute after Eugeny started listening to the play list.
Sample Input
1 2
2 8
1 16
4 9
1 2
2 1
1 1
2 2
1 2 3 4 5 6 7 8 9
Sample Output
1
1
1
1
2
2
3
4
4
4
4
| {"inputs": ["1 2\n2 8\n1 16", "4 9\n1 2\n2 1\n1 1\n2 2\n1 2 3 4 5 6 7 8 9", "3 3\n2 8\n5 1\n10 5\n13 16 62", "4 4\n2 8\n2 2\n6 3\n8 7\n13 23 29 85", "5 5\n9 6\n8 7\n2 9\n10 3\n8 10\n69 95 146 162 177", "6 6\n4 9\n8 5\n3 8\n8 10\n4 2\n10 9\n15 45 97 197 231 265", "7 7\n1 10\n1 1\n7 2\n4 9\n10 4\n5 5\n7 1\n48 71 86 87 110 113 127", "8 8\n4 6\n10 9\n5 1\n8 7\n4 7\n2 6\n5 3\n1 10\n21 91 93 142 145 157 181 206", "9 9\n2 5\n7 1\n8 2\n8 8\n8 8\n4 4\n6 10\n10 9\n2 9\n1 10 36 48 76 151 229 276 310", "10 10\n3 1\n2 7\n5 1\n7 2\n9 10\n9 5\n2 5\n4 10\n9 9\n1 9\n26 34 37 141 146 201 239 245 296 299", "2 3\n1 500000000\n1 500000000\n499999999 500000000 500000001", "2 3\n500000000 1\n1 500000000\n499999999 500000000 500000001", "2 3\n500000000 1\n500000000 1\n499999999 500000000 500000001", "3 1\n2 50\n1 50\n1 50\n160"], "outputs": ["1\n1", "1\n1\n2\n2\n3\n4\n4\n4\n4", "1\n1\n3", "1\n3\n3\n4", "2\n2\n4\n5\n5", "1\n2\n3\n6\n6\n6", "4\n5\n5\n5\n6\n6\n7", "1\n2\n2\n4\n4\n4\n5\n6", "1\n1\n4\n4\n4\n5\n7\n8\n8", "4\n4\n5\n6\n6\n8\n9\n9\n9\n9", "1\n1\n2", "1\n1\n2", "1\n1\n2", "3"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 100 | codeforces |
|
c34576ad4cc651a3744cc85ae9b0a608 | Replace To Make Regular Bracket Sequence | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a regular bracket sequence is well-known, so you can be familiar with it.
Let's define a regular bracket sequence (RBS). Empty string is RBS. Let *s*1 and *s*2 be a RBS then the strings <*s*1>*s*2, {*s*1}*s*2, [*s*1]*s*2, (*s*1)*s*2 are also RBS.
For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.
Determine the least number of replaces to make the string *s* RBS.
The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106.
If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*.
Sample Input
[<}){}
{()}[]
]]
Sample Output
20Impossible | {"inputs": ["[<}){}", "{()}[]", "]]", ">", "{}", "{}", "{]", "{]", "{]", "[]{[]({)([", "(([{>}{[{[)]]>>]", "((<>)[]<]><]", "[[([[(>]>)))[<)>", "({)[}<)](}", "(}{)[<][)(]}", ">}({>]{[}<{<{{)[]]{)]>]]]<(][{)<<<{<<)>)()[>{<]]{}<>}}}}(>}<})(][>{((<{<)]}>)))][>[}[])<]){]]][<[)([", "<<[<{{<([({<<[)<>(]]){})>[](])[)))[[}>]<)>[[>{>>>[<]}<>>)[>]<{)<[><(<]][>(>]>][(<][{]}(()<[()[>><<])<]})]<]}{)", "[<<{{((}[}<<)<)>})(][{>}})((>)<[)[>}[})[)>()[()[((}<<(>)<>](<>(}[>})[[[{)<}<<(}{>>}[<([[])<><)]<{>}[>>>{({>)}]})>)", "(<[([(<({>(}{]>[(})])}])()<<}{]{[>]>(>>[(>>}[){(}<[{(()]{{<(<{][[{<><{<{)<>>]}}}{)(}{})}[<))>>}((({>){({}{{]}]>>}})>))", "{(]}<([]<]{>]<{<({{{<>))}[({(}{)[}({>]}}<<)}<]))(<>(>{>{{{)<}({<]<>{)(>[)>{({}<([<[[)]><>{]}}(>]{}<)[})]}]]}]}>}", "<(([)]<[}>{)>][[(<()({{{>>((]<}<{{<>}><<[)}[[)([[)[)}<]<{(<>){([)><{[([[][({])})<][(}]}>>[){)[({>){(}[}})>}>]>)]}))})>}]", ")(", "[[[[[[[["], "outputs": ["2", "0", "Impossible", "Impossible", "0", "0", "1", "1", "1", "Impossible", "7", "3", "6", "5", "6", "Impossible", "45", "42", "43", "40", "45", "Impossible", "Impossible"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 73 | codeforces |
|
c35efd66426b5bd961aa720f0ee29dcb | Guilty --- to the kitchen! | It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills.
According to the borscht recipe it consists of *n* ingredients that have to be mixed in proportion litres (thus, there should be *a*1<=Β·*x*,<=...,<=*a**n*<=Β·*x* litres of corresponding ingredients mixed for some non-negative *x*). In the kitchen Volodya found out that he has *b*1,<=...,<=*b**n* litres of these ingredients at his disposal correspondingly. In order to correct his algebra mistakes he ought to cook as much soup as possible in a *V* litres volume pan (which means the amount of soup cooked can be between 0 and *V* litres). What is the volume of borscht Volodya will cook ultimately?
The first line of the input contains two space-separated integers *n* and *V* (1<=β€<=*n*<=β€<=20,<=1<=β€<=*V*<=β€<=10000). The next line contains *n* space-separated integers *a**i* (1<=β€<=*a**i*<=β€<=100). Finally, the last line contains *n* space-separated integers *b**i* (0<=β€<=*b**i*<=β€<=100).
Your program should output just one real number β the volume of soup that Volodya will cook. Your answer must have a relative or absolute error less than 10<=-<=4.
Sample Input
1 100
1
40
2 100
1 1
25 30
2 100
1 1
60 60
Sample Output
40.0
50.0
100.0
| {"inputs": ["1 100\n1\n40", "2 100\n1 1\n25 30", "2 100\n1 1\n60 60", "2 100\n1 1\n50 50", "2 100\n1 2\n33 66", "3 10000\n1 1 1\n100 0 100", "7 5100\n21 93 52 80 5 46 20\n79 37 74 54 22 15 90", "10 2707\n80 91 41 99 99 48 81 25 80 17\n88 79 64 78 4 54 38 92 77 61", "19 8111\n44 75 80 69 90 64 58 8 93 50 44 39 7 25 14 52 32 26 26\n38 57 38 23 73 24 4 49 0 34 96 93 14 26 29 89 54 12 24", "5 1121\n14 37 91 35 71\n17 87 48 91 13", "4 6054\n72 21 14 49\n43 53 42 55", "6 8692\n20 61 56 4 78 76\n73 83 97 45 16 7", "9 5583\n73 31 18 36 38 99 34 50 69\n48 24 75 78 75 69 13 74 3", "1 5215\n24\n85", "15 9559\n55 13 69 16 15 34 89 30 56 64 74 100 72 71 20\n40 73 29 12 31 5 59 5 90 13 32 75 99 7 44", "13 2530\n83 59 19 69 8 81 99 74 14 75 61 13 36\n26 36 77 44 10 8 8 16 81 61 29 81 50", "4 7672\n42 34 57 72\n56 7 24 24", "17 6030\n100 77 5 87 28 50 51 64 45 79 60 80 49 20 25 91 64\n12 13 58 55 3 59 8 62 69 38 69 27 50 39 5 41 30", "18 4842\n73 20 36 89 89 74 88 46 21 55 40 99 86 2 53 92 36 6\n24 97 23 27 31 63 29 2 23 84 86 44 68 8 63 0 50 16", "8 2342\n7 91 9 17 86 22 49 53\n20 76 25 24 54 78 33 90", "1 8987\n16\n38", "10 9501\n39 67 33 71 89 69 5 90 7 48\n89 91 8 68 7 54 61 66 53 51", "1 1966\n85\n99", "9 7611\n58 46 28 18 29 70 62 22 55\n53 43 51 72 52 99 18 61 91", "5 6739\n29 48 36 80 74\n22 37 36 54 88", "9 35\n27 71 41 3 9 74 16 29 95\n95 69 20 41 41 22 10 92 58", "13 5115\n13 51 17 24 52 4 33 4 94 17 54 82 77\n40 34 90 29 81 24 38 74 28 81 14 40 24", "13 9049\n58 13 53 62 41 80 38 14 6 96 23 29 41\n42 24 20 12 63 82 33 93 3 31 68 10 24", "2 775\n13 39\n76 35", "7 8690\n73 93 32 47 80 82 97\n49 49 90 43 89 43 67", "11 9698\n62 53 97 20 84 9 50 100 81 35 14\n18 19 39 30 26 56 41 43 24 32 28", "6 1090\n1 1 44 63 35 64\n29 53 64 11 32 66", "8 9291\n93 68 34 81 53 96 7 26\n23 64 15 47 94 66 90 92", "16 1718\n42 68 96 52 47 31 89 5 87 70 25 69 35 86 86 11\n35 37 51 15 33 94 18 48 91 2 4 89 73 93 47 26", "4 575\n24 23 16 64\n85 100 14 13", "9 423\n28 88 41 71 99 24 35 68 90\n7 76 44 27 64 52 92 81 98", "2 1437\n66 58\n44 8", "18 4733\n78 53 33 72 38 76 43 51 94 18 22 21 65 60 5 71 88 40\n5 78 50 43 81 44 10 18 23 51 52 31 10 55 63 46 82 92", "16 7170\n17 1 48 51 28 16 41 14 59 93 25 76 46 69 74 41\n54 53 41 25 50 42 37 20 11 35 90 96 78 3 20 38", "14 7455\n96 38 61 34 68 91 45 49 81 87 46 60 83 16\n38 4 99 16 99 40 68 84 18 56 16 81 21 21", "1 9291\n97\n96", "14 3615\n81 79 13 94 54 69 92 5 47 98 40 64 44 88\n52 73 7 12 29 40 46 47 60 66 63 68 71 4", "18 6283\n50 78 16 38 44 9 23 54 58 82 59 12 69 1 10 6 77 61\n70 59 12 11 98 55 52 12 69 40 100 47 42 21 48 18 14 22", "9 3269\n79 88 15 74 92 33 68 64 45\n55 84 75 50 68 32 41 82 42", "6 1007\n93 23 35 15 25 6\n58 24 11 99 23 47", "11 710\n2 49 56 33 79 69 64 62 64 9 87\n94 34 90 3 13 67 76 80 69 19 41", "18 9292\n15 97 47 88 15 7 15 86 52 40 16 97 2 80 64 37 88 15\n39 47 94 12 34 17 45 39 98 99 19 8 94 50 87 68 31 6", "11 3753\n78 75 17 65 97 36 79 56 97 62 43\n18 41 17 47 14 40 7 57 58 24 98", "13 1407\n21 67 79 68 44 52 18 40 68 56 69 66 25\n26 39 78 93 1 57 58 5 67 49 96 15 16", "20 1479\n69 30 15 62 81 24 5 16 25 65 47 23 62 51 87 50 6 44 88 61\n57 47 76 68 7 57 44 98 24 44 1 79 67 31 72 83 36 65 83 42", "17 3856\n50 59 100 50 80 77 58 86 95 87 30 41 11 99 33 27 75\n47 47 39 62 58 91 55 18 65 47 8 97 31 80 61 87 66", "9 2382\n84 51 95 66 34 77 96 9 57\n3 94 56 22 61 50 23 83 45", "14 1751\n33 82 63 35 67 78 47 27 43 96 58 95 39 29\n42 7 15 83 95 91 60 3 85 39 7 56 39 4", "6 8371\n34 11 24 95 62 32\n98 50 58 46 49 93", "2 5181\n4 1\n6 33", "9 632\n51 64 25 25 60 71 56 3 31\n70 28 76 84 86 33 77 11 69", "3 2102\n76 15 85\n25 95 80", "5 5005\n5 53 65 52 99\n21 49 9 3 66", "17 8971\n54 62 7 47 48 70 78 96 91 34 84 23 72 75 72 60 21\n4 26 6 41 28 45 70 61 6 75 74 46 17 46 34 27 10", "15 5527\n22 49 56 95 86 23 15 74 38 65 52 92 88 49 54\n33 61 71 95 69 31 30 0 1 93 66 48 65 92 11", "20 3696\n87 22 21 83 95 31 28 96 71 25 56 40 70 79 46 87 19 19 34 25\n70 44 34 11 2 1 59 22 46 28 3 53 52 71 34 47 65 71 76 30", "8 5540\n5 9 88 1 74 52 32 79\n17 48 99 33 68 28 2 58", "15 303\n33 15 28 14 97 33 77 69 41 76 54 97 11 1 1\n83 70 63 11 71 10 48 65 5 5 82 2 6 79 19", "10 9401\n4 53 39 66 52 42 65 39 1 76\n9 34 16 56 78 14 43 49 95 42", "2 9083\n77 33\n22 22", "16 8826\n29 21 40 93 48 49 43 96 60 68 66 5 96 49 84 44\n94 1 79 12 76 65 99 53 37 39 3 76 15 81 51 91", "4 9426\n95 48 98 92\n65 40 43 90", "13 175\n46 77 14 16 84 80 81 36 71 13 87 69 8\n54 46 69 59 30 72 83 97 83 96 43 94 84", "13 5023\n11 30 92 40 26 77 33 94 71 2 70 97 50\n32 46 51 14 63 76 34 19 13 34 40 91 23", "18 9978\n26 3 87 84 97 53 70 97 37 57 78 23 34 40 81 62 21 92\n56 73 0 79 93 14 17 80 0 20 3 81 22 71 7 82 71 81", "14 8481\n64 2 90 76 49 30 88 32 98 64 20 85 40 35\n55 84 75 43 36 13 67 75 100 19 22 7 5 58", "2 1674\n77 23\n23 25", "10 2112\n45 11 32 14 82 30 34 11 42 56\n18 9 84 99 82 43 61 84 14 70", "6 2006\n62 4 3 71 61 10\n37 45 61 84 24 15", "8 3954\n80 77 64 1 50 21 89 26\n30 82 17 20 67 21 31 99", "18 7253\n64 77 92 9 32 66 23 34 10 71 8 7 83 9 52 97 29 65\n46 90 65 43 44 63 7 38 38 20 62 9 53 39 17 13 5 90", "4 4384\n42 41 85 79\n29 67 52 55", "7 529\n77 18 67 64 43 51 30\n35 87 17 52 1 97 84", "16 2915\n39 39 81 44 23 47 43 56 7 38 10 100 5 34 87 14\n10 96 34 20 62 88 46 38 29 35 2 43 26 55 31 63", "14 6488\n53 41 36 28 17 15 63 33 75 40 85 88 90 100\n7 35 83 2 48 76 93 2 69 56 59 7 25 24"], "outputs": ["40.0", "50.0", "100.0", "100.0", "99.0", "0.0", "103.3695652173913", "26.70707070707071", "0.0", "45.40845070422535", "93.16666666666666", "27.171052631578945", "19.478260869565215", "85.0", "76.70422535211266", "55.83838383838385", "42.205882352941174", "104.46428571428571", "0.0", "209.72093023255815", "38.0", "40.74157303370786", "99.0", "112.64516129032259", "180.22500000000002", "35.0", "135.33333333333334", "107.2258064516129", "46.66666666666667", "264.2926829268293", "175.6451612903226", "36.317460317460316", "113.26881720430106", "25.685714285714283", "25.796875", "136.0", "17.10344827586207", "59.48717948717948", "30.391304347826086", "89.99999999999999", "96.0", "39.45454545454545", "135.8181818181818", "336.44117647058823", "61.91428571428571", "52.18181818181819", "71.01030927835052", "62.46835443037974", "15.295454545454545", "19.382978723404253", "221.4418604651163", "20.32142857142857", "67.60975609756098", "124.92631578947369", "7.5", "168.875", "57.89473684210526", "15.807692307692308", "65.53846153846153", "0.0", "21.768421052631577", "21.25", "13.340206185567009", "145.66666666666666", "31.42857142857143", "40.5", "146.1122448979592", "175.0", "126.88732394366197", "0.0", "63.65882352941177", "29.87012987012987", "119.0", "83.01639344262294", "108.375", "110.96907216494844", "151.1058823529412", "8.139534883720929", "133.4", "46.30303030303031"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 43 | codeforces |
|
c3b0f25282825914e3165f036647ca3b | Wrath | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *j*<=β₯<=*i*<=-<=*L**i*.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings.
The first line contains one integer *n* (1<=β€<=*n*<=β€<=106) β the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=β€<=*L**i*<=β€<=109), where *L**i* is the length of the *i*-th person's claw.
Print one integer β the total number of alive people after the bell rings.
Sample Input
4
0 1 0 10
2
0 0
10
1 1 3 0 0 0 2 1 0 3
Sample Output
1
2
3
| {"inputs": ["4\n0 1 0 10", "2\n0 0", "10\n1 1 3 0 0 0 2 1 0 3", "10\n0 0 2 0 0 3 3 2 2 0", "1\n0", "5\n0 0 0 1 0", "6\n3 1 1 0 3 3", "8\n0 0 0 1 0 0 1 2", "1\n1000000000", "2\n1 3", "2\n1000000000 1000000000", "11\n1 0 0 1 1 3 2 0 0 2 3", "1\n1"], "outputs": ["1", "2", "3", "2", "1", "4", "1", "5", "1", "1", "1", "4", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 206 | codeforces |
|
c3caabd20656dfea798193d9f8828c62 | bHTML Tables Analisys | In this problem is used an extremely simplified version of HTML table markup. Please use the statement as a formal document and read it carefully.
A string is a bHTML table, if it satisfies the grammar:
Blanks in the grammar are only for purposes of illustration, in the given data there will be no spaces. The bHTML table is very similar to a simple regular HTML table in which meet only the following tags : "table", "tr", "td", all the tags are paired and the table contains at least one row and at least one cell in each row. Have a look at the sample tests as examples of tables.
As can be seen, the tables may be nested. You are given a table (which may contain other(s)). You need to write a program that analyzes all the tables and finds the number of cells in each of them. The tables are not required to be rectangular.
For convenience, input data can be separated into non-empty lines in an arbitrary manner. The input data consist of no more than 10 lines. Combine (concatenate) all the input lines into one, to get a text representation *s* of the specified table. String *s* corresponds to the given grammar (the root element of grammar is TABLE), its length does not exceed 5000. Only lower case letters are used to write tags. There are no spaces in the given string *s*.
Print the sizes of all the tables in the non-decreasing order.
Sample Input
<table><tr><td></td></tr></table>
<table>
<tr>
<td>
<table><tr><td></td></tr><tr><td></
td
></tr><tr
><td></td></tr><tr><td></td></tr></table>
</td>
</tr>
</table>
<table><tr><td>
<table><tr><td>
<table><tr><td>
<table><tr><td></td><td></td>
</tr><tr><td></td></tr></table>
</td></tr></table>
</td></tr></table>
</td></tr></table>
Sample Output
1 1 4 1 1 1 3 | {"inputs": ["<table><tr><td></td></tr></table>", "<table>\n<tr>\n<td>\n<table><tr><td></td></tr><tr><td></\ntd\n></tr><tr\n><td></td></tr><tr><td></td></tr></table>\n</td>\n</tr>\n</table>", "<table><tr><td>\n<table><tr><td>\n<table><tr><td>\n<table><tr><td></td><td></td>\n</tr><tr><td></td></tr></table>\n</td></tr></table>\n</td></tr></table>\n</td></tr></table>", "<\nt\na\nble><tr><td></td>\n</\ntr>\n</\nt\nab\nle>", "<table><tr><td><table><tr><td></td></tr></table></td></tr></table>", "<table><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table>", "<table><tr><td><table><tr><td></td></tr></table></td></tr></table>", "<table><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table>", "<table><tr><td><table><tr><td></td><td></td></tr></table></td><td><table><tr><td></td></tr></table></td></tr></table>", "<table><tr><td><table><tr><td></td><td></td></tr></table></td><td><table><tr><td></td></tr></table></td></tr></table>", "<table><tr><td><table><tr><td></td></tr></table></td></tr><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table>", "<table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td><table><tr><td></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table>"], "outputs": ["1 ", "1 4 ", "1 1 1 3 ", "1 ", "1 1 ", "1 1 1 ", "1 1 ", "1 1 1 ", "1 2 2 ", "1 2 2 ", "1 1 1 2 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 7 | codeforces |
|
c3d790805eede963d52bb39905c572fe | Queries about less or equal elements | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=β€<=*n*,<=*m*<=β€<=2Β·105) β the sizes of arrays *a* and *b*.
The second line contains *n* integers β the elements of array *a* (<=-<=109<=β€<=*a**i*<=β€<=109).
The third line contains *m* integers β the elements of array *b* (<=-<=109<=β€<=*b**j*<=β€<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
Sample Input
5 4
1 3 5 7 9
6 4 2 8
5 5
1 2 1 2 5
3 1 4 1 5
Sample Output
3 2 1 4
4 2 4 2 5
| {"inputs": ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5", "1 1\n-1\n-2", "1 1\n-80890826\n686519510", "11 11\n237468511 -779187544 -174606592 193890085 404563196 -71722998 -617934776 170102710 -442808289 109833389 953091341\n994454001 322957429 216874735 -606986750 -455806318 -663190696 3793295 41395397 -929612742 -787653860 -684738874", "20 22\n858276994 -568758442 -918490847 -983345984 -172435358 389604931 200224783 486556113 413281867 -258259500 -627945379 -584563643 444685477 -602481243 -370745158 965672503 630955806 -626138773 -997221880 633102929\n-61330638 -977252080 -212144219 385501731 669589742 954357160 563935906 584468977 -895883477 405774444 853372186 186056475 -964575261 -952431965 632332084 -388829939 -23011650 310957048 -770695392 977376693 321435214 199223897", "5 9\n1 3 5 7 9\n1 2 3 4 5 6 7 8 9", "22 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22\n1", "5 1\n1 3 3 3 5\n3", "4 5\n1 1 1 4\n1 5 5 4 3", "5 4\n0 5 5 5 6\n5 1 6 3", "1 3\n0\n-1 0 1", "96 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\n1", "7 1\n1 2 3 4 5 6 7\n1", "13 13\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000", "9 5\n1 2 3 4 5 6 7 8 9\n1 2 3 4 5", "3 8\n1 1 1\n1 1 1 1 1 1 1 1", "1 1\n-11111\n-5938", "1 1\n1\n400000009", "1 1\n1\n300000009", "1 1\n1\n200000009", "1 1\n1\n200000003"], "outputs": ["3 2 1 4", "4 2 4 2 5", "0", "1", "11 9 8 2 2 1 5 5 0 0 1", "11 2 10 12 18 19 16 16 3 13 18 11 2 2 17 8 11 12 3 20 12 11", "1 1 2 2 3 3 4 4 5", "1", "4", "3 4 4 4 3", "4 1 5 1", "0 1 1", "96", "1", "7 13 7 13 7 13 7 13 7 13 7 13 7", "1 2 3 4 5", "3 3 3 3 3 3 3 3", "1", "1", "1", "1", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 241 | codeforces |
|
c3f6f1b2d8283ce5173cfcc44bb75b45 | Intersection | You are given two set of points. The first set is determined by the equation *A*1*x*<=+<=*B*1*y*<=+<=*C*1<==<=0, and the second one is determined by the equation *A*2*x*<=+<=*B*2*y*<=+<=*C*2<==<=0.
Write the program which finds the number of points in the intersection of two given sets.
The first line of the input contains three integer numbers *A*1,<=*B*1,<=*C*1 separated by space. The second line contains three integer numbers *A*2,<=*B*2,<=*C*2 separated by space. All the numbers are between -100 and 100, inclusive.
Print the number of points in the intersection or -1 if there are infinite number of points.
Sample Input
1 1 0
2 2 0
1 1 0
2 -2 0
Sample Output
-1
1
| {"inputs": ["1 1 0\n2 2 0", "1 1 0\n2 -2 0", "0 0 0\n0 0 0", "1 1 1\n1 1 1", "8 3 -4\n-5 2 7", "-1 -1 0\n0 -1 -1", "-1 -1 0\n1 1 -1", "-1 -1 1\n0 -1 0", "0 0 0\n1 -1 -1", "0 0 1\n-1 1 -1", "0 1 -1\n-1 1 -1", "1 0 -1\n0 0 -1", "0 1 1\n1 0 0", "1 0 0\n0 0 1", "1 -1 -1\n1 -1 0", "1 0 0\n0 1 1", "1 -1 1\n-1 -1 1", "1 0 0\n0 1 1", "-1 -1 1\n-1 -1 -1", "-1 -1 0\n1 1 -1", "0 0 0\n0 1 -1", "0 1 1\n0 1 -1", "0 1 0\n1 1 0", "1 0 1\n-1 0 -1", "1 1 0\n1 0 -1", "0 -1 -1\n-1 0 0", "1 0 0\n1 0 0", "1 1 1\n-1 -1 0", "-1 -1 -1\n0 -1 1", "0 -1 0\n0 0 1", "0 1 1\n-1 -1 1", "0 -1 0\n0 -1 1", "0 1 1\n0 1 1", "1 -1 0\n-1 -1 1", "0 1 1\n0 1 -1", "1 0 1\n1 0 0", "1 1 1\n0 0 0", "1 0 1\n-1 -1 -1", "1 -1 1\n0 0 0", "0 1 1\n-1 -1 0", "-1 0 1\n1 0 0", "0 1 -1\n0 0 1", "0 -1 0\n1 1 1", "1 0 1\n0 1 1", "0 0 0\n1 1 -1", "1 -1 1\n1 1 1", "1 0 -1\n-1 0 1", "1 0 1\n1 -1 1", "1 -1 -1\n-1 -1 -1", "0 -1 1\n0 0 -1", "0 0 -1\n1 -1 -1", "1 1 0\n-1 0 0", "1 0 -1\n0 -1 0", "1 -1 0\n-1 1 0", "1 -1 1\n1 -1 0", "-1 -1 -1\n-1 1 0", "-1 0 1\n1 -1 1", "1 -1 0\n0 -1 -1", "-1 1 0\n-1 0 -1", "-1 -1 -1\n1 -1 1", "-1 -1 0\n1 1 1", "0 1 -1\n-1 0 0", "0 0 0\n0 0 0", "0 1 1\n1 0 -1", "0 1 -1\n0 0 0", "1 -1 0\n-1 1 0", "0 0 0\n0 1 0", "0 -1 1\n1 -1 1", "1 0 0\n0 1 0", "-1 1 0\n0 -1 1", "-1 0 -1\n1 1 0", "0 -1 0\n1 1 -1", "-1 -1 1\n-1 0 1", "0 1 0\n1 0 1", "1 0 0\n-1 0 -1", "-1 -1 0\n1 -1 1", "1 1 1\n-1 -1 -1", "1 -1 0\n-1 1 0", "-1 -1 1\n-1 1 0", "0 0 1\n1 0 -1", "0 -1 -2\n0 1 0", "0 -1 0\n2 -2 2", "1 -1 2\n-1 0 0", "-2 0 2\n0 0 2", "-1 0 -1\n1 -1 -1", "-1 2 0\n-2 1 -2", "0 2 0\n0 1 2", "2 2 2\n0 -2 0", "-2 0 -2\n2 -2 -2", "2 2 -1\n-2 1 1", "-2 -1 1\n0 -1 0", "-2 1 1\n0 0 -2", "-1 2 -2\n0 2 1", "1 2 -2\n-1 2 0", "0 0 2\n0 -1 -1", "2 1 1\n1 2 1", "-2 -1 2\n1 1 1", "0 -1 -1\n-2 -2 -1", "-1 0 -1\n0 -2 1", "1 1 2\n0 1 0", "-2 1 1\n2 1 -1", "-1 -2 1\n-1 -2 2", "0 -2 1\n-2 2 2", "0 -1 2\n-1 -1 0", "1 -1 -2\n1 2 -2", "-2 -1 0\n-2 2 2", "-1 1 0\n0 -1 0", "-1 -2 2\n-1 0 -2", "0 1 -1\n1 0 -2", "-1 -2 -2\n-2 1 0", "1 -1 2\n0 0 -2", "2 -1 2\n0 -2 1", "1 0 -1\n2 0 1", "-2 -1 0\n-2 0 -1", "-1 1 1\n0 1 1", "1 1 1\n1 1 -2", "1 2 1\n1 -1 1", "-2 -2 0\n0 -2 -1", "-1 -1 0\n-1 -2 -1", "-2 -2 -2\n1 1 -1", "0 0 0\n0 0 1", "0 0 -87\n0 0 0", "0 0 1\n0 0 1", "100 100 100\n-100 100 -100", "12 -32 89\n0 67 -23", "0 0 1\n0 0 2", "0 5 0\n0 0 5", "0 1 1\n0 -1 -1", "1 1 0\n2 2 1", "0 0 5\n0 0 5", "0 5 0\n0 5 1", "0 1 1\n0 1 2", "0 1 1\n0 2 3", "2 2 -3\n2 2 -2", "3 3 3\n3 3 4", "0 1 2\n0 2 3", "0 0 1\n1 1 1", "5 0 1\n7 0 2", "4 6 1\n2 3 1", "0 0 0\n0 1 2"], "outputs": ["-1", "1", "-1", "-1", "1", "1", "0", "1", "-1", "0", "1", "0", "1", "0", "0", "1", "1", "1", "0", "0", "-1", "0", "1", "-1", "1", "1", "-1", "0", "1", "0", "1", "0", "-1", "1", "0", "0", "-1", "1", "-1", "1", "0", "0", "1", "1", "-1", "1", "-1", "1", "1", "0", "0", "1", "1", "-1", "0", "1", "1", "1", "1", "1", "0", "1", "-1", "1", "-1", "-1", "-1", "1", "1", "1", "1", "1", "1", "1", "0", "1", "-1", "-1", "1", "0", "0", "1", "1", "0", "1", "1", "0", "1", "1", "1", "1", "0", "1", "1", "0", "1", "1", "1", "1", "1", "1", "0", "1", "1", "1", "1", "1", "1", "1", "1", "0", "1", "0", "1", "1", "0", "1", "1", "1", "0", "0", "0", "0", "1", "1", "0", "0", "-1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 15 | codeforces |
|
c3fb39355574a7e1da59bd733c53c45c | Parallelepiped | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers β the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number β the sum of all edges of the parallelepiped.
Sample Input
1 1 1
4 6 6
Sample Output
12
28
| {"inputs": ["1 1 1", "4 6 6", "20 10 50", "9 4 36", "324 9 36", "1333 93 129", "1022 584 112", "66 174 319", "912 276 1748", "65 156 60", "1 10000 10000", "1485 55 27", "152 108 4104", "1656 6900 1350", "12 14 42", "615 18 1230", "680 60 408", "644 966 6", "1 432 432", "2239 2239 1", "4106 8212 2", "10000 10000 10000", "3623 3623 1", "9801 9801 9801", "10000 1 10000", "9 9 9", "9801 9702 9702"], "outputs": ["12", "28", "68", "56", "184", "308", "380", "184", "444", "120", "40008", "332", "528", "740", "60", "856", "336", "1308", "1736", "8964", "16436", "1200", "14500", "1188", "40008", "36", "1184"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 622 | codeforces |
|
c405d7dde8cef7bb4e1c964e697aa3e5 | T-Shirt Hunt | Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.
Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place *p*.
Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let *s* be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed:
Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator.
As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of *s*.
You're in the lead of the elimination round of 8VC Venture Cup 2017, having *x* points. You believe that having at least *y* points in the current round will be enough for victory.
To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.
You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?
The only line contains three integers *p*, *x* and *y* (26<=β€<=*p*<=β€<=500; 1<=β€<=*y*<=β€<=*x*<=β€<=20000)Β β your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.
Output a single integerΒ β the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt.
It's guaranteed that your goal is achievable for any valid input data.
Sample Input
239 10880 9889
26 7258 6123
493 8000 8000
101 6800 6500
329 19913 19900
Sample Output
0
2
24
0
8
| {"inputs": ["239 10880 9889", "26 7258 6123", "493 8000 8000", "101 6800 6500", "329 19913 19900", "264 19252 10888", "176 9670 9174", "42 11 6", "412 17647 15917", "91 4883 4302", "200 16031 15842", "186 18666 18329", "486 9748 9598", "180 4213 4207", "329 19989 1", "390 11676 2570", "173 7017 4512", "38 6404 5034", "364 17243 16625", "57 11066 9738", "419 9142 8622", "31 12956 10515", "412 5027 4975", "94 1231 986", "173 7783 7674", "338 8291 8008", "424 10906 10346", "168 2953 2292", "406 16527 16314", "368 1597 1506", "111 14627 14479", "400 15224 15212", "427 19269 19231", "26 10232 10220", "500 7030 7023", "26 13819 13682", "500 18737 18069", "26 20000 20000", "26 1 1", "26 20000 1", "68 51 1", "198 6550 6549", "68 50 49", "239 10927 10880", "239 10830 9889", "329 2150 1900", "164 49 48", "329 2150 2101"], "outputs": ["0", "2", "24", "0", "8", "0", "6", "27", "8", "12", "24", "23", "25", "27", "0", "0", "0", "0", "0", "1", "1", "2", "2", "3", "3", "7", "13", "17", "22", "26", "26", "27", "27", "27", "27", "0", "0", "7", "6", "0", "0", "5", "5", "11", "1", "0", "1", "6"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 31 | codeforces |
|
c40e9d6ff14b79d32f1975a0c3702047 | Dima and Staircase | Dima's got a staircase that consists of *n* stairs. The first stair is at height *a*1, the second one is at *a*2, the last one is at *a**n* (1<=β€<=*a*1<=β€<=*a*2<=β€<=...<=β€<=*a**n*).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The *i*-th box has width *w**i* and height *h**i*. Dima throws each box vertically down on the first *w**i* stairs of the staircase, that is, the box covers stairs with numbers 1,<=2,<=...,<=*w**i*. Each thrown box flies vertically down until at least one of the two following events happen:
- the bottom of the box touches the top of a stair; - the bottom of the box touches the top of a box, thrown earlier.
We only consider touching of the horizontal sides of stairs and boxes, at that touching with the corners isn't taken into consideration. Specifically, that implies that a box with width *w**i* cannot touch the stair number *w**i*<=+<=1.
You are given the description of the staircase and the sequence in which Dima threw the boxes at it. For each box, determine how high the bottom of the box after landing will be. Consider a box to fall after the previous one lands.
The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of stairs in the staircase. The second line contains a non-decreasing sequence, consisting of *n* integers, *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109;Β *a**i*<=β€<=*a**i*<=+<=1).
The next line contains integer *m* (1<=β€<=*m*<=β€<=105) β the number of boxes. Each of the following *m* lines contains a pair of integers *w**i*,<=*h**i* (1<=β€<=*w**i*<=β€<=*n*;Β 1<=β€<=*h**i*<=β€<=109) β the size of the *i*-th thrown box.
The numbers in the lines are separated by spaces.
Print *m* integers β for each box the height, where the bottom of the box will be after landing. Print the answers for the boxes in the order, in which the boxes are given in the input.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Sample Input
5
1 2 3 6 6
4
1 1
3 1
1 1
4 3
3
1 2 3
2
1 1
3 1
1
1
5
1 2
1 10
1 10
1 10
1 10
Sample Output
1
3
4
6
1
3
1
3
13
23
33
| {"inputs": ["5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3", "3\n1 2 3\n2\n1 1\n3 1", "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10", "8\n6 10 18 23 30 31 31 33\n1\n5 3", "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2", "5\n4 7 10 12 12\n9\n3 9\n2 1\n3 5\n4 7\n1 1\n5 1\n1 7\n2 4\n4 10", "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6", "3\n2 10 15\n1\n1 830", "2\n1 6\n5\n2 6\n1 2\n1 1\n1 2\n1 7", "1\n9\n8\n1 4\n1 10\n1 9\n1 9\n1 7\n1 1\n1 9\n1 2", "1\n8\n1\n1 42", "1\n1\n1\n1 1", "5\n1 2 3 6 6\n25\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000", "1\n1000000000\n6\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000"], "outputs": ["1\n3\n4\n6", "1\n3", "1\n3\n13\n23\n33", "30", "25\n30\n35", "10\n19\n20\n25\n32\n33\n34\n41\n45", "8\n12\n21\n24\n26", "2", "6\n12\n14\n15\n17", "9\n13\n23\n32\n41\n48\n49\n58", "8", "1", "1\n1000000001\n2000000001\n3000000001\n4000000001\n5000000001\n6000000001\n7000000001\n8000000001\n9000000001\n10000000001\n11000000001\n12000000001\n13000000001\n14000000001\n15000000001\n16000000001\n17000000001\n18000000001\n19000000001\n20000000001\n21000000001\n22000000001\n23000000001\n24000000001", "1000000000\n2000000000\n3000000000\n4000000000\n5000000000\n6000000000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 38 | codeforces |
|
c428cb3795453c6365d8f87de077feb5 | Mike and palindrome | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
The first and single line contains string *s* (1<=β€<=|*s*|<=β€<=15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Sample Input
abccaa
abbcca
abcda
Sample Output
YES
NO
YES
| {"inputs": ["abccaa", "abbcca", "abcda", "kyw", "fccf", "mnlm", "gqrk", "glxlg", "czhfc", "broon", "rmggmr", "wvxxzw", "ukvciu", "vrnwnrv", "vlkjkav", "guayhmg", "lkvhhvkl", "ffdsslff", "galjjtyw", "uosgwgsou", "qjwmjmljq", "ustrvrodf", "a", "qjfyjjyfjq", "ysxibbixsq", "howfslfwmh", "ekhajrjahke", "ucnolsloncw", "jrzsfrrkrtj", "typayzzyapyt", "uwdhkzokhdwu", "xokxpyyuafij", "eusneioiensue", "fuxpuajabpxuf", "guvggtfhlgruy", "cojhkhxxhkhjoc", "mhifbmmmmbmihm", "kxfqqncnebpami", "scfwrjevejrwfcs", "thdaonpepdoadht", "jsfzcbnhsccuqsj", "nn", "nm", "jdj", "bbcaa", "abcde", "abcdf", "aa", "abecd", "abccacb", "aabc", "anpqb", "c", "abcdefg", "aanbb", "aabbb", "aaabbab", "ab", "aabbc", "ecabd", "abcdrty", "abcdmnp", "bbbbbb", "abcxuio", "abcdabcde", "abcxpoi", "aba", "aacbb", "abcedca", "abcdd", "abbcs", "aaabccc", "paxkxbq", "z", "b", "abcdefghi", "abcqr", "abcdc", "abcb", "aabcd", "abbba", "aaabbb", "bb", "aaacbbb", "abbzcca", "abxab", "bbb", "abcrtyu", "cbacb", "acbb", "ww", "aaaaaa", "jizzz", "aaakcba", "acbak", "bddeffd", "aaa", "afghqwe", "abcdfga"], "outputs": ["YES", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 163 | codeforces |
|
c471ea63a38a1fc6ba0d6161cb75b220 | Bertown Subway | The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown Transport Law:
1. For each station *i* there exists exactly one train that goes from this station. Its destination station is *p**i*, possibly *p**i*<==<=*i*; 1. For each station *i* there exists exactly one station *j* such that *p**j*<==<=*i*.
The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (*x*,<=*y*) such that person can start at station *x* and, after taking some subway trains (possibly zero), arrive at station *y* (1<=β€<=*x*,<=*y*<=β€<=*n*).
The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of *p**i* for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes.
The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get!
The first line contains one integer number *n* (1<=β€<=*n*<=β€<=100000) β the number of stations.
The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=β€<=*p**i*<=β€<=*n*) β the current structure of the subway. All these numbers are distinct.
Print one number β the maximum possible value of convenience.
Sample Input
3
2 1 3
5
1 5 4 3 2
Sample Output
9
17
| {"inputs": ["3\n2 1 3", "5\n1 5 4 3 2", "1\n1", "2\n1 2", "2\n2 1", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "5\n1 4 2 3 5", "6\n5 3 6 1 4 2", "10\n5 1 6 2 8 3 4 10 9 7", "20\n1 6 15 9 18 17 7 8 3 19 2 13 11 12 14 4 5 20 16 10", "3\n1 2 3"], "outputs": ["9", "17", "1", "4", "4", "5416", "17", "36", "82", "326", "5"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 48 | codeforces |
|
c481daf3fd61e80e4acb7dd5b3b0ad8b | EKG | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native tradition in Russia, dating back to the Soviet period. Queues can resemble crowds rather than lines. Not to get lost in such a queue, a person should follow a strict survival technique: you approach the queue and ask who the last person is, somebody answers and you join the crowd. Now you're the last person in the queue till somebody else shows up. You keep an eye on the one who was last before you as he is your only chance to get to your destination) I'm sure many people have had the problem when a stranger asks who the last person in the queue is and even dares to hint that he will be the last in the queue and then bolts away to some unknown destination. These are the representatives of the modern world, in which the ratio of lack of time is so great that they do not even watch foreign top-rated TV series. Such people often create problems in queues, because the newcomer does not see the last person in the queue and takes a place after the "virtual" link in this chain, wondering where this legendary figure has left.
The Smart Beaver has been ill and he's made an appointment with a therapist. The doctor told the Beaver the sad news in a nutshell: it is necessary to do an electrocardiogram. The next day the Smart Beaver got up early, put on the famous TV series on download (three hours till the download's complete), clenched his teeth and bravely went to join a queue to the electrocardiogram room, which is notorious for the biggest queues at the clinic.
Having stood for about three hours in the queue, the Smart Beaver realized that many beavers had not seen who was supposed to stand in the queue before them and there was a huge mess. He came up to each beaver in the ECG room queue and asked who should be in front of him in the queue. If the beaver did not know his correct position in the queue, then it might be his turn to go get an ECG, or maybe he should wait for a long, long time...
As you've guessed, the Smart Beaver was in a hurry home, so he gave you all the necessary information for you to help him to determine what his number in the queue can be.
The first line contains two integers *n* (1<=β€<=*n*<=β€<=103) and *x* (1<=β€<=*x*<=β€<=*n*) β the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to *n*.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=*n*) β the number of the beaver followed by the *i*-th beaver. If *a**i*<==<=0, then the *i*-th beaver doesn't know who is should be in front of him. It is guaranteed that values *a**i* are correct. That is there is no cycles in the dependencies. And any beaver is followed by at most one beaver in the queue.
The input limits for scoring 30 points are (subproblem B1):
- It is guaranteed that the number of zero elements *a**i* doesn't exceed 20.
The input limits for scoring 100 points are (subproblems B1+B2):
- The number of zero elements *a**i* is arbitrary.
Print all possible positions of the Smart Beaver in the line in the increasing order.
Sample Input
6 1
2 0 4 0 6 0
6 2
2 3 0 5 6 0
4 1
0 0 0 0
6 2
0 0 1 0 4 5
Sample Output
2
4
6
2
5
1
2
3
4
1
3
4
6
| {"inputs": ["6 1\n2 0 4 0 6 0", "6 2\n2 3 0 5 6 0", "4 1\n0 0 0 0", "6 2\n0 0 1 0 4 5", "10 7\n10 8 6 5 0 0 0 4 3 9", "10 1\n8 7 0 2 0 10 0 0 3 5", "10 4\n0 1 4 2 7 0 10 0 5 8", "10 2\n0 7 0 10 8 0 4 2 3 0", "10 2\n10 0 9 0 0 4 2 6 8 0", "10 7\n7 9 2 10 0 0 0 3 5 1", "20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"], "outputs": ["2\n4\n6", "2\n5", "1\n2\n3\n4", "1\n3\n4\n6", "1\n5\n6\n10", "2\n4\n5\n7\n8\n10", "3\n4\n8\n9", "4\n5\n6\n7\n8", "1\n2\n3\n4\n6\n7\n8\n9", "1\n2\n6\n7", "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 7 | codeforces |
|
c490d53ce60b1d95c8f1965c603a15cd | Challenge Pennants | Because of budget cuts one IT company established new non-financial reward system instead of bonuses.
Two kinds of actions are rewarded: fixing critical bugs and suggesting new interesting features. A man who fixed a critical bug gets "I fixed a critical bug" pennant on his table. A man who suggested a new interesting feature gets "I suggested a new feature" pennant on his table.
Because of the limited budget of the new reward system only 5 "I fixed a critical bug" pennants and 3 "I suggested a new feature" pennants were bought.
In order to use these pennants for a long time they were made challenge ones. When a man fixes a new critical bug one of the earlier awarded "I fixed a critical bug" pennants is passed on to his table. When a man suggests a new interesting feature one of the earlier awarded "I suggested a new feature" pennants is passed on to his table.
One man can have several pennants of one type and of course he can have pennants of both types on his table. There are *n* tables in the IT company. Find the number of ways to place the pennants on these tables given that each pennant is situated on one of the tables and each table is big enough to contain any number of pennants.
The only line of the input contains one integer *n* (1<=β€<=*n*<=β€<=500) β the number of tables in the IT company.
Output one integer β the amount of ways to place the pennants on *n* tables.
Sample Input
2
Sample Output
24 | {"inputs": ["2", "1", "3", "4", "5", "6", "7", "12", "28", "43", "139", "321", "100", "498", "500"], "outputs": ["24", "1", "210", "1120", "4410", "14112", "38808", "1589952", "817586560", "21766594410", "212332162372330", "163013183025830865", "15789964684000", "5392730685240975000", "5567867859752100000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 7 | codeforces |
|
c4925395433ef9f0418e15736bd8532f | Squares | Vasya has found a piece of paper with a coordinate system written on it. There are *n* distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to *n*. It turned out that points with coordinates (0,<=0) and (*a**i*,<=*a**i*) are the opposite corners of the *i*-th square.
Vasya wants to find such integer point (with integer coordinates) of the plane, that belongs to exactly *k* drawn squares. We'll say that a point belongs to a square, if the point is located either inside the square, or on its boundary.
Help Vasya find a point that would meet the described limits.
The first line contains two space-separated integers *n*, *k* (1<=β€<=*n*,<=*k*<=β€<=50). The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109).
It is guaranteed that all given squares are distinct.
In a single line print two space-separated integers *x* and *y* (0<=β€<=*x*,<=*y*<=β€<=109) β the coordinates of the point that belongs to exactly *k* squares. If there are multiple answers, you are allowed to print any of them.
If there is no answer, print "-1" (without the quotes).
Sample Input
4 3
5 1 3 4
3 1
2 4 1
4 50
5 1 10 2
Sample Output
2 1
4 0
-1
| {"inputs": ["4 3\n5 1 3 4", "3 1\n2 4 1", "4 50\n5 1 10 2", "3 4\n5 1 4", "1 1\n2", "1 2\n10", "10 5\n68 78 70 3 77 2 24 17 96 63", "5 2\n10 9 19 12 14", "2 2\n7 2", "2 1\n8 20", "2 40\n33 29", "5 10\n7 5 9 10 8", "9 8\n83 6 90 96 42 71 11 82 51", "40 30\n115644639 84968781 502201719 185562964 985439338 904909761 987469310 392279024 34042735 634622221 839483595 370724480 578485357 293110515 426715668 623544321 361578399 344575100 906293095 989519195 455225 952837951 263384814 771897504 859893161 171980440 959878829 233550924 365529816 203041523 562264000 739766404 289946473 250809088 370936224 210349657 657189623 5710590 638043996 944609028", "50 50\n873312389 604039796 470980211 604092901 317645830 865841782 30190128 90700018 361113641 948274316 775347907 312933768 745800411 976357881 652424427 420068005 77994941 746874884 912886330 875358567 675008609 780785718 874337107 541592914 532566154 316033689 257781802 361740423 72046192 816493561 290190407 245507086 581576441 739752998 801377026 469634060 850496001 558296112 702877640 836956173 304850066 276508329 703262292 394254651 789172012 655966182 103434486 635267748 872287742 750895678", "50 1\n282174632 865088564 656352811 984648256 521352785 57911680 996749451 85805091 790762915 281422127 195283931 253923622 554865826 31466324 214732274 790749112 441328969 537583501 612245057 877161587 763349710 784532543 192804116 844363612 235045603 185195996 13097680 541100831 561866993 317797406 403001652 484887637 16410460 587211083 582483610 461878975 571808452 827167600 562613044 787964041 370263360 15717800 907380817 301112202 488431522 827024725 622035351 983160960 309839543 725826915", "50 2\n611819205 916034844 226292837 817298502 176794540 727900268 460009451 154197232 671291076 641633528 316549457 84943963 581078373 360295861 299532522 279193498 61088105 776327911 952977833 796036148 193827182 248414821 822409059 451009120 316494610 702170585 194014479 567762248 201775925 186588924 630333192 849644874 978885690 826471389 136002889 659371057 392112709 74463003 491124655 336372608 480423293 428908070 423023163 749932199 880227915 227662209 304705869 82537803 424363417 744202499", "50 49\n88725980 83881995 59295833 19992230 98694184 93275377 61249454 52781239 92644863 72826940 50546968 49705218 12163764 2370616 74789070 66649536 44427957 38263003 29482181 32784244 68697287 58653702 72057831 71170858 7965262 28000704 62154588 20020410 74475651 17112704 51168707 67055363 94596285 74161506 20821879 13196082 72415147 47307630 29342412 42369019 97867158 37513173 21502544 32181980 10790305 28119093 11323148 54617694 24131594 56797138", "50 40\n96796700 70298164 77962801 85411997 38782814 34003824 38719796 99639116 67985686 99451905 61978628 21844407 12207253 79918 49399043 20719647 39110240 7094466 69163751 33236841 22249070 77179977 59576055 65178969 85705829 95074132 34273099 39626456 4907488 86213552 61097999 82889263 50311083 51771059 1255360 54093385 26718724 93604207 70082669 67044340 47726300 29504508 9910007 22933280 6155028 44655282 92452176 72975646 64485568 28849515", "50 25\n1498786 501094 6396443 1167317 719496 636212 1912961 3111395 9572144 6277130 9288513 7311574 4038261 7897312 6769622 3412399 9996933 4060756 9948079 1769012 7600286 9897826 2087275 5962282 4953810 9654443 5333662 433180 3588803 4130095 9598090 5151122 9842663 2514194 1676006 1626458 6001092 8600794 1723930 8161219 1356724 4329774 8289408 3197404 7978402 1561752 3254820 3668793 6778571 7700292", "40 11\n60208 236973 84548 315924 250944 161962 297861 210884 314453 279066 6713 301121 238667 162406 271727 215696 44559 217356 265375 162107 289254 27492 179940 37333 304851 292475 216268 324087 57771 193073 309245 77531 58743 46448 125774 80238 70527 80833 24488 206156", "44 38\n1462767 3166364 2098867 3314373 272988 1780023 2892344 3453931 131181 2304994 1855709 770970 3125250 2260136 1472897 2688663 2516513 1842215 187194 725629 1982324 3030991 3106666 2504895 211807 3306495 3315809 2391117 1748124 110461 1156562 1210236 190189 504062 371439 3202405 503823 2844645 568415 3139160 1616378 3185067 3099571 2832834", "37 15\n438778 549860 49173 79840 234277 898394 923784 647192 886153 382676 312989 525192 837433 210204 822734 218858 732642 336426 241548 478143 133580 508509 279685 393941 361559 59454 924509 236866 531648 567554 476854 399527 678235 527942 854506 697967 609944", "48 42\n140920201 439599146 631470789 326348765 777305542 246501797 98842561 66698125 328893187 320920834 442056583 300823217 102856871 894833295 183971312 540000242 77621006 301282781 633518310 368397657 266701251 254744062 276445863 624102545 317896643 457301959 840650755 37020968 787211200 835830799 696187545 77377229 666128476 254311406 706645277 592561555 487913577 799871742 248143253 499058221 533238063 603652509 401508758 545626159 728850086 173008168 373273227 772142675", "30 7\n483242884 141465390 673274235 374698924 293895324 745776711 38293296 624522417 759055572 343124219 260836408 738391263 503711346 394651562 297415680 772345540 864523609 288584413 650320686 449000886 409412162 15908489 635266274 210759446 839533571 807852364 888754168 98417552 843606733 776397228", "20 50\n366890701 326770801 264406917 201841167 245146846 423010984 902787383 250242526 915591714 753137694 212804025 728751237 707187607 713393006 915812218 208754076 88791411 661347329 647317959 484135977", "49 50\n237449581 667894738 947395330 631153874 73096515 526873659 442758248 458113553 593707922 871777170 341397492 276382904 953470766 481575900 456794298 949850484 901479039 641744893 906465923 889863668 865607102 676085245 15087113 733126439 805674805 419604807 578669881 662288768 867202435 312642277 690318191 928184117 255005653 221548485 89241021 776806523 716418093 628174070 549089059 180504011 699093407 914610155 999333080 522769440 884252814 601964726 433999999 961290550 79463155", "32 50\n7 5 50 2 42 36 28 8 44 3 40 15 33 18 1 6 25 20 39 24 45 35 14 27 17 47 19 49 13 34 22 26", "20 17\n407 2799 2032 2154 8119 9404 6718 7914 916 4720 1267 9403 5497 4518 9072 7828 8364 8230 3057 7770", "17 27\n22 8 17 12 24 28 25 20 7 9 4 15 6 33 19 5 10", "1 1\n1", "2 1\n2 1", "2 1\n1 2", "5 2\n1 2 5 4 3", "2 1\n2 3", "1 1\n1000000000", "5 1\n1 2 3 4 5", "5 4\n1 2 3 4 5", "4 1\n1 2 999999991 999999999", "3 2\n1 2 3", "4 3\n1 1000000000 100000000 10000000", "4 4\n1 2 3 4", "2 2\n10000000 1000000", "3 1\n1 2 3", "2 2\n100000000 1000000000"], "outputs": ["2 1", "4 0", "-1", "-1", "2 1", "-1", "68 68", "14 14", "2 1", "20 20", "-1", "-1", "11 11", "250809088 250809088", "2 1", "996749451 996749451", "952977833 952977833", "7965262 7965262", "22933280 22933280", "4953810 4953810", "271727 271727", "371439 371439", "531648 531648", "140920201 140920201", "772345540 772345540", "-1", "-1", "-1", "2032 2032", "-1", "1 1", "2 1", "2 1", "4 0", "3 3", "2 1", "5 5", "2 1", "999999999 999999999", "2 1", "2 1", "1 1", "2 1", "3 3", "2 1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
c49fbe44ec18bf074af51a7b17df7ae3 | Maze | Pavel loves grid mazes. A grid maze is an *n*<=Γ<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly *k* empty cells into walls so that all the remaining cells still formed a connected area. Help him.
The first line contains three integers *n*, *m*, *k* (1<=β€<=*n*,<=*m*<=β€<=500, 0<=β€<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines contains *m* characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.
Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
Sample Input
3 4 2
#..#
..#.
#...
5 4 5
#...
#.#.
.#..
...#
.#.#
Sample Output
#.X#
X.#.
#...
#XXX
#X#.
X#..
...#
.#.#
| {"inputs": ["5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "3 3 2\n#.#\n...\n#.#", "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#", "1 1 0\n.", "2 3 1\n..#\n#..", "2 3 1\n#..\n..#", "3 3 1\n...\n.#.\n..#", "3 3 1\n...\n.#.\n#..", "5 4 4\n#..#\n....\n.##.\n....\n#..#", "5 5 2\n.#..#\n..#.#\n#....\n##.#.\n###..", "4 6 3\n#.....\n#.#.#.\n.#...#\n...#.#", "7 5 4\n.....\n.#.#.\n#...#\n.#.#.\n.#...\n..#..\n....#", "16 14 19\n##############\n..############\n#.############\n#..###########\n....##########\n..############\n.#############\n.#.###########\n....##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###....#......\n#...#...##.###", "10 17 32\n######.##########\n####.#.##########\n...#....#########\n.........########\n##.......########\n........#########\n#.....###########\n#################\n#################\n#################", "16 10 38\n##########\n##########\n##########\n..########\n...#######\n...#######\n...#######\n....######\n.....####.\n......###.\n......##..\n.......#..\n.........#\n.........#\n.........#\n.........#", "15 16 19\n########.....###\n########.....###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n.....#####.#..##\n................\n.#...........###\n###.########.###\n###.########.###", "12 19 42\n.........##########\n...................\n.##.##############.\n..################.\n..#################\n..#################\n..#################\n..#################\n..#################\n..#################\n..##########.######\n.............######", "3 5 1\n#...#\n..#..\n..#..", "4 5 10\n.....\n.....\n..#..\n..#..", "3 5 3\n.....\n..#..\n..#..", "3 5 1\n#....\n..#..\n..###", "4 5 1\n.....\n.##..\n..#..\n..###", "3 5 2\n..#..\n..#..\n....#", "10 10 1\n##########\n##......##\n#..#..#..#\n#..####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########", "10 10 3\n..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######..\n.#######..\n.####..###\n.......###", "5 7 10\n..#....\n..#.#..\n.##.#..\n..#.#..\n....#..", "5 7 10\n..#....\n..#.##.\n.##.##.\n..#.#..\n....#..", "10 10 1\n##########\n##..##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########", "4 5 1\n.....\n.###.\n..#..\n..#..", "2 5 2\n###..\n###..", "2 5 3\n.....\n..#..", "12 12 3\n############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######..#\n#.#######..#\n#.####..####\n#.......####\n############", "5 5 1\n.....\n.##..\n..###\n..###\n#####", "4 4 1\n....\n.#..\n..##\n..##", "5 5 1\n....#\n.##..\n.##..\n...##\n...##", "5 5 1\n.....\n.##..\n..###\n..###\n..###", "4 5 1\n#....\n#.#..\n..###\n..###", "4 4 3\n....\n.#..\n..##\n..##", "4 7 6\n.......\n....#..\n.##.#..\n....#..", "8 8 7\n........\n.##.....\n.#######\n..######\n..######\n..######\n..######\n..######"], "outputs": ["#XXX\n#X#.\nX#..\n...#\n.#.#", "#X#\nX..\n#.#", "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#...\nX#...#.\nX.#.#..\n#.....#", ".", "X.#\n#..", "#.X\n..#", "...\n.#X\n..#", "...\nX#.\n#..", "#XX#\nXX..\n.##.\n....\n#..#", "X#..#\nX.#.#\n#....\n##.#.\n###..", "#.....\n#X#.#X\nX#...#\n...#.#", "X...X\nX#.#X\n#...#\n.#.#.\n.#...\n..#..\n....#", "##############\nXX############\n#X############\n#XX###########\nXXXX##########\nXX############\nX#############\nX#.###########\nX...##########\n###..#########\n##...#########\n###....#######\n###.##.......#\n###..###.#..#.\n###...X#......\n#X..#XXX##.###", "######X##########\n####X#X##########\nXXX#XXXX#########\nXXXXXXXXX########\n##XXX.XXX########\nXXXX...X#########\n#XX...###########\n#################\n#################\n#################", "##########\n##########\n##########\nXX########\nXXX#######\nXXX#######\nXXX#######\nXXXX######\nXXXXX####.\nXXXXX.###.\nXXXX..##..\nXXX....#..\nXXX......#\nXX.......#\nX........#\n.........#", "########XXXXX###\n########XXXXX###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\n############.###\nXXXX.#####.#..##\nXXX.............\nX#...........###\n###.########.###\n###X########.###", "XXXXXXXXX##########\nXXXXXXXXXXXXXXXXXXX\nX##X##############X\nXX################X\nXX#################\nXX#################\nXX#################\nX.#################\nX.#################\n..#################\n..##########.######\n.............######", "#...#\n..#..\nX.#..", "XXX..\nXXX..\nXX#..\nXX#..", ".....\nX.#..\nXX#..", "#....\n..#.X\n..###", ".....\n.##..\n..#.X\n..###", "X.#..\nX.#..\n....#", "##########\n##......##\n#..#..#..#\n#X.####..#\n#######.##\n#######.##\n#..####..#\n#..#..#..#\n##......##\n##########", "..........\n.########.\n.########.\n.########.\n.########.\n.########.\n.#######X.\n.#######XX\n.####..###\n.......###", "XX#....\nXX#.#..\nX##.#..\nXX#.#..\nXXX.#..", "XX#....\nXX#.##.\nX##.##.\nXX#.#..\nXXX.#..", "##########\n##.X##..##\n#...##...#\n#.######.#\n#..####..#\n#..####..#\n#.######.#\n#........#\n##..##..##\n##########", ".....\n.###.\n..#..\n.X#..", "###X.\n###X.", "X....\nXX#..", "############\n#..........#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.########.#\n#.#######X.#\n#.#######XX#\n#.####..####\n#.......####\n############", ".....\n.##.X\n..###\n..###\n#####", "....\n.#.X\n..##\n..##", "....#\n.##..\n.##.X\n...##\n...##", ".....\n.##.X\n..###\n..###\n..###", "#....\n#.#.X\n..###\n..###", "...X\n.#XX\n..##\n..##", "X......\nX...#..\nX##.#..\nXXX.#..", ".....XXX\n.##.XXXX\n.#######\n..######\n..######\n..######\n..######\n..######"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 97 | codeforces |
|
c4a1a34f497ee40fd471d8de5b3c962b | Lightsabers (medium) | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of the lightsabers of the Jedi who will go on that mission.
Heidi has *n* Jedi Knights standing in front of her, each one with a lightsaber of one of *m* possible colors. She knows that for the mission to be the most effective, she needs to select some contiguous interval of knights such that there are exactly *k*1 knights with lightsabers of the first color, *k*2 knights with lightsabers of the second color, ..., *k**m* knights with lightsabers of the *m*-th color.
However, since the last time, she has learned that it is not always possible to select such an interval. Therefore, she decided to ask some Jedi Knights to go on an indefinite unpaid vacation leave near certain pits on Tatooine, if you know what I mean. Help Heidi decide what is the minimum number of Jedi Knights that need to be let go before she is able to select the desired interval from the subsequence of remaining knights.
The first line of the input contains *n* (1<=β€<=*n*<=β€<=2Β·105) and *m* (1<=β€<=*m*<=β€<=*n*). The second line contains *n* integers in the range {1,<=2,<=...,<=*m*} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains *m* integers *k*1,<=*k*2,<=...,<=*k**m* (with ) β the desired counts of Jedi Knights with lightsabers of each color from 1 to *m*.
Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output <=-<=1.
Sample Input
8 3
3 3 1 2 2 1 1 3
3 1 1
Sample Output
1
| {"inputs": ["8 3\n3 3 1 2 2 1 1 3\n3 1 1", "6 5\n1 2 4 2 4 3\n0 0 1 0 0", "1 1\n1\n1", "2 1\n1 1\n1", "2 1\n1 1\n2", "2 2\n1 2\n1 1", "2 2\n2 2\n1 1", "3 3\n3 3 2\n0 0 1", "4 4\n4 4 4 4\n0 1 1 1", "2 2\n1 1\n1 0", "3 3\n3 3 3\n0 0 1", "4 4\n2 4 4 3\n0 1 0 0", "2 2\n2 1\n0 1", "3 3\n3 1 1\n1 1 1", "4 4\n1 3 1 4\n1 0 0 1", "2 2\n2 1\n1 0", "3 3\n3 1 1\n2 0 0", "4 4\n4 4 2 2\n1 1 1 1", "2 2\n1 2\n0 2", "3 3\n3 2 3\n0 2 1", "4 4\n1 2 4 2\n0 0 1 0", "4 4\n4 2 1 2\n1 2 0 1", "5 5\n4 4 2 4 2\n0 2 0 3 0", "6 6\n4 3 5 4 5 2\n0 1 0 1 2 0", "4 4\n4 3 3 2\n0 0 2 0", "5 5\n3 4 5 1 4\n1 0 1 1 1", "6 6\n1 1 3 2 2 2\n1 0 0 0 0 0", "4 4\n4 1 1 3\n2 0 0 1", "5 5\n3 4 1 1 5\n2 0 1 1 0", "6 6\n4 3 5 6 5 5\n0 0 1 1 0 0", "4 4\n1 3 4 2\n1 0 0 0", "5 5\n4 1 3 3 3\n0 0 0 1 0", "6 6\n6 2 6 2 5 4\n0 1 0 0 0 1", "4 4\n3 2 1 3\n0 1 0 0", "5 5\n3 4 1 4 2\n1 0 0 1 0", "6 6\n4 1 6 6 3 5\n1 0 1 1 1 2"], "outputs": ["1", "0", "0", "0", "0", "0", "-1", "0", "-1", "0", "0", "0", "0", "-1", "0", "0", "0", "-1", "-1", "-1", "-1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 7 | codeforces |
|
c4ad62bddbc94c55cc70b08762937167 | Bombs | You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains *n* bombs, the *i*-th bomb is at point with coordinates (*x**i*,<=*y**i*). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0,<=0). Initially, the robot is at point with coordinates (0,<=0). Also, let's mark the robot's current position as (*x*,<=*y*). In order to destroy all the bombs, the robot can perform three types of operations:
1. Operation has format "1 k dir". To perform the operation robot have to move in direction *dir* *k* (*k*<=β₯<=1) times. There are only 4 directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1), (*x*,<=*y*<=-<=1) (corresponding to directions). It is forbidden to move from point (*x*,<=*y*), if at least one point on the path (besides the destination point) contains a bomb. 1. Operation has format "2". To perform the operation robot have to pick a bomb at point (*x*,<=*y*) and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point (*x*,<=*y*) has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container. 1. Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point (0,<=0). It is forbidden to perform the operation if the container has no bomb.
Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane.
The first line contains a single integer *n* (1<=β€<=*n*<=β€<=105) β the number of bombs on the coordinate plane. Next *n* lines contain two integers each. The *i*-th line contains numbers (*x**i*,<=*y**i*) (<=-<=109<=β€<=*x**i*,<=*y**i*<=β€<=109) β the coordinates of the *i*-th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point (0,<=0).
In a single line print a single integer *k* β the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these *k* operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where *k*<=β€<=106.
Sample Input
2
1 1
-1 -1
3
5 0
0 5
1 0
Sample Output
12
1 1 R
1 1 U
2
1 1 L
1 1 D
3
1 1 L
1 1 D
2
1 1 R
1 1 U
3
12
1 1 R
2
1 1 L
3
1 5 R
2
1 5 L
3
1 5 U
2
1 5 D
3
| {"inputs": ["2\n1 1\n-1 -1", "3\n5 0\n0 5\n1 0", "1\n-277226476 314722425", "2\n-404192496 -968658337\n556071553 -256244640", "24\n-2 -2\n-1 1\n0 1\n1 1\n0 2\n1 -1\n2 -2\n1 -2\n-1 0\n0 -2\n0 -1\n-2 0\n-2 -1\n2 -1\n2 2\n-1 -2\n-2 1\n2 0\n-1 2\n1 2\n-1 -1\n1 0\n2 1\n-2 2"], "outputs": ["12\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3", "12\n1 1 R\n2\n1 1 L\n3\n1 5 R\n2\n1 5 L\n3\n1 5 U\n2\n1 5 D\n3", "6\n1 277226476 L\n1 314722425 U\n2\n1 277226476 R\n1 314722425 D\n3", "12\n1 556071553 R\n1 256244640 D\n2\n1 556071553 L\n1 256244640 U\n3\n1 404192496 L\n1 968658337 D\n2\n1 404192496 R\n1 968658337 U\n3", "128\n1 1 U\n2\n1 1 D\n3\n1 1 R\n2\n1 1 L\n3\n1 1 L\n2\n1 1 R\n3\n1 1 D\n2\n1 1 U\n3\n1 1 L\n1 1 U\n2\n1 1 R\n1 1 D\n3\n1 1 R\n1 1 U\n2\n1 1 L\n1 1 D\n3\n1 2 U\n2\n1 2 D\n3\n1 1 R\n1 1 D\n2\n1 1 L\n1 1 U\n3\n1 2 D\n2\n1 2 U\n3\n1 2 L\n2\n1 2 R\n3\n1 1 L\n1 1 D\n2\n1 1 R\n1 1 U\n3\n1 2 R\n2\n1 2 L\n3\n1 2 L\n1 1 D\n2\n1 2 R\n1 1 U\n3\n1 2 R\n1 1 U\n2\n1 2 L\n1 1 D\n3\n1 1 R\n1 2 U\n2\n1 1 L\n1 2 D\n3\n1 1 L\n1 2 U\n2\n1 1 R\n1 2 D\n3\n1 2 L\n1 1 U\n2\n1 2 R\n1 1 D\n3\n1 1 L\n1 2 D\n2\n1 1 R\n1 2 U\n3\n1 2 R\n..."]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 11 | codeforces |
|
c4b0d56e3f40a886b55753344382562d | Minimization | You've got array *A*, consisting of *n* integers and a positive integer *k*. Array *A* is indexed by integers from 1 to *n*.
You need to permute the array elements so that value
The first line contains two integers *n*,<=*k* (2<=β€<=*n*<=β€<=3Β·105, 1<=β€<=*k*<=β€<=*min*(5000,<=*n*<=-<=1)).
The second line contains *n* integers *A*[1],<=*A*[2],<=...,<=*A*[*n*] (<=-<=109<=β€<=*A*[*i*]<=β€<=109), separate by spaces β elements of the array *A*.
Print the minimum possible value of the sum described in the statement.
Sample Input
3 2
1 2 4
5 2
3 -5 3 -5 3
6 3
4 3 4 3 2 5
Sample Output
1
0
3
| {"inputs": ["3 2\n1 2 4", "5 2\n3 -5 3 -5 3", "6 3\n4 3 4 3 2 5", "2 1\n1 100", "4 3\n1 2 4 8", "5 2\n1 2 8 8 16", "10 3\n-999999914 -999999976 -999999966 -999999952 29 54 -999999963 -999999959 -999999974 48", "30 2\n-999999924 -499999902 500000091 -999999998 500000030 -999999934 500000086 -499999918 -499999998 67 -999999964 -499999975 -499999947 -499999925 3 -499999985 14 500000015 500000022 88 25 -499999909 500000051 -499999984 -999999964 -499999905 -499999968 86 43 -999999980", "40 4\n600000080 -199999981 -599999907 -199999935 -199999904 -599999919 200000022 600000032 600000046 -999999980 -199999917 600000027 200000075 -999999949 -599999911 -999999969 600000017 -199999999 -999999923 -599999924 600000091 -599999973 -599999936 600000011 -199999951 600000030 -199999900 -599999906 200000099 -199999967 -199999940 200000063 -199999944 -599999948 200000071 -599999976 -599999922 600000014 200000030 -199999969", "5 2\n1 2 4 8 16", "15 2\n-333333258 333333394 -333333272 -999999901 -333333281 333333394 333333386 -999999965 333333407 -333333288 333333384 -333333289 333333339 -999999924 -333333329", "15 5\n70 -999999913 -999999976 55 -999999925 -999999989 -999999934 4 61 53 -999999960 -999999921 89 89 87", "20 7\n-999999935 -555555531 -333333247 -333333331 555555563 777777781 -777777774 111111179 777777870 111111119 555555647 -333333265 -555555466 111111161 -111111070 -555555503 111111183 333333402 333333407 -111111104"], "outputs": ["1", "0", "3", "99", "1", "9", "83", "1500000085", "1600000040", "11", "1333333358", "1000000025", "888888939"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
c4dd3e1e06a63ef2153e3968b846c4ce | Really Big Numbers | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
The first (and the only) line contains two integers *n* and *s* (1<=β€<=*n*,<=*s*<=β€<=1018).
Print one integer β the quantity of really big numbers that are not greater than *n*.
Sample Input
12 1
25 20
10 9
Sample Output
3
0
1
| {"inputs": ["12 1", "25 20", "10 9", "300 1000", "500 1000", "1000 2000", "10000 1000", "1000000000000000000 1000000000000000000", "1000000000000000000 100000000000000000", "1000000000000000000 10000000000000000", "1000000000000000000 1000000000000000", "1000000000000000000 100000000000000", "1000000000000000000 200000000000000000", "10 5", "20 5", "20 9", "100 9", "1 1", "130 118", "190 181", "1999 1971", "100 99", "6909094398 719694282", "260 258", "35 19", "100 87", "91 89", "109 89", "109 91", "20331 11580", "405487470 255750281", "17382 12863", "19725 14457", "24848 15384", "25727 15982", "109 90", "1000000000000000000 999999999999999999", "1000000000000000000 999999999999999998", "1009 980", "999999999999999999 999999999999999838", "1000000000000000000 99999999999999800", "8785369357 3377262261", "110 109", "999 777", "327170000015578 77230000029054", "12515000022229 1791000022317", "9999999999999 9999999999882", "213 196", "92 82", "148 136", "8 9", "309 299", "9999 9963", "82 81", "9999999 9999936", "171 155", "999 972", "999999999999 999999999891", "9 9", "6900 6885", "96 57", "5 4", "17386 5814", "493679757404593 316259583979965", "18474 9478", "270091571496186 250931112649966", "565751690089037 381448507916936", "19 10"], "outputs": ["3", "0", "1", "0", "0", "0", "8991", "0", "899999999999999991", "989999999999999991", "998999999999999991", "999899999999999991", "799999999999999991", "1", "11", "11", "91", "0", "1", "0", "10", "1", "6189400069", "0", "6", "1", "0", "10", "10", "8732", "149737161", "4493", "5246", "9449", "9728", "10", "1", "1", "10", "0", "900000000000000061", "5408107058", "0", "200", "249939999986479", "10723999999880", "10", "14", "0", "0", "0", "0", "10", "0", "10", "2", "10", "10", "0", "1", "27", "0", "11557", "177420173424564", "8975", "19160458846177", "184303182172038", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 89 | codeforces |
|
c4ed979e1e7dc2e04476df656d461770 | Square Table | While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size *n*<=Γ<=*m*, consisting of positive integers such that the sum of the squares of numbers for each row and each column was also a square.
Since checking the correctness of the table manually is difficult, Misha asks you to make each number in the table to not exceed 108.
The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100) Β β the size of the table.
Print the table that meets the condition: *n* lines containing *m* integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer.
Sample Input
1 1
1 2
Sample Output
13 4 | {"inputs": ["1 1", "1 2", "4 1", "1 4", "2 1", "2 4", "48 2", "3 75", "33 1", "4 23", "58 2", "2 11", "7 14", "48 24", "77 93", "77 20", "30 31", "100 100"], "outputs": ["1 ", "3 4 ", "1 \n1 \n1 \n1 ", "1 1 1 1 ", "3 \n4 ", "3 3 3 3 \n4 4 4 4 ", "3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n69 92 ", "4 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 76 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 38 \n4 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 76 ", "2 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n17 ", "2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 ", "3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n3 4 \n84 112 ", "6 3 3 3 3 3 3 3 3 3 18 \n8 4 4 4 4 4 4 4 4 4 24 ", "2 2 2 2 2 2 2 2 2 2 2 2 2 12 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n1 1 1 1 1 1 1 1 1 1 1 1 1 6 \n4 4 4 4 4 4 4 4 4 4 4 4 4 24 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 \n1...", "4 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 94 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 47 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...", "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 18 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 \n1 1 1 ...", "2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 \n2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 49 \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 49 \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..."]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 3 | codeforces |
|
c4f24bad678c0dc44f16444d1931b0f5 | Currency System in Geraldion | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum?
The first line contains number *n* (1<=β€<=*n*<=β€<=1000) β the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=106) β the values of the banknotes.
Print a single line β the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1.
Sample Input
5
1 2 3 4 5
Sample Output
-1
| {"inputs": ["5\n1 2 3 4 5", "1\n2", "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837", "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264", "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97866 124255 950067 697612 244256 782385 789882 37608 82153 399889 598867 416717 377988 535636 511221 792568 683271 131077 290194 496712 330720 587436 563481 645817 942562 654093 980561 382937 48293 582608 116156", "50\n474421 421097 217233 156339 27075 733996 281778 863492 184707 956857 288561 70997 393786 337382 663642 131184 637 273801 799870 295017 392338 842567 161819 297705 102013 930684 375703 838048 154915 138503 629056 256591 893619 19263 787927 684541 320265 841090 421423 490879 394582 493952 619247 633202 612928 50907 276653 407819 489945 153173", "1\n1", "1\n1000000", "2\n3 2", "2\n2 3"], "outputs": ["-1", "1", "-1", "1", "-1", "1", "-1", "1", "1", "1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 304 | codeforces |
|
c50b1b965f540f3178cb912f00fd25cf | Spyke Talks | Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.
One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.
Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.
Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β that is, one call connects exactly two people.
The first line contains integer *n* (1<=β€<=*n*<=β€<=103) β the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=β€<=*id**i*<=β€<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise.
Consider the secretaries indexed from 1 to *n* in some way.
Print a single integer β the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.
Sample Input
6
0 1 7 1 7 10
3
1 1 1
1
0
Sample Output
2
-1
0
| {"inputs": ["6\n0 1 7 1 7 10", "3\n1 1 1", "1\n0", "5\n2 2 1 1 3", "1\n1", "10\n4 21 3 21 21 1 1 2 2 3", "2\n1 2", "5\n0 0 0 0 0", "6\n6 6 0 8 0 0", "10\n0 0 0 0 0 1 0 1 0 1", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 0 3 0 0 3 0 0 0 0 0 0 3 0 0 3 0 0 0 0 0 0 0 3 0 0 0 0 0", "1\n1000000000", "2\n1 0", "2\n1000000000 1000000000", "5\n1 0 0 0 1", "15\n380515742 842209759 945171461 664384656 945171461 474872104 0 0 131648973 131648973 474872104 842209759 664384656 0 380515742", "123\n0 6361 8903 10428 0 258 0 10422 0 0 2642 1958 0 0 0 0 0 8249 1958 0 0 2642 0 0 0 11566 4709 1847 3998 0 1331 0 0 10289 2739 6135 3450 0 0 10994 6069 4337 5854 1331 5854 0 630 630 11244 5928 2706 0 683 214 0 9080 0 0 0 10422 683 11566 10994 0 0 3450 11244 11542 3998 1847 2708 9871 2739 2001 0 12216 6069 0 5928 0 10289 1307 0 1307 8903 0 6361 6135 6632 10428 0 0 632 258 9080 12216 4709 4967 2706 0 11542 2001 6632 0 8249 214 0 10301 4967 10301 7296 7296 10914 2708 4337 0 0 632 0 10914 0 9871 0", "10\n0 3 2 3 2 0 1 3 3 0", "20\n0 1 2 0 0 0 0 5 3 4 0 0 1 1 3 0 4 0 1 0", "47\n1 6 0 6 1 1 6 4 3 6 5 3 6 3 2 2 5 1 4 7 3 5 6 1 6 7 4 5 6 3 3 3 7 4 1 6 1 1 7 1 3 1 5 5 1 3 6", "74\n0 0 0 0 0 37 0 0 0 0 0 0 0 8 0 0 9 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 9 0 7 0 0 0 0 0 0 19 19 0 0 0 0 0 0 0 0 0 0 0 0 17 0 30 0 0 0 0 0 0 30 0 0 0 0 0 0 0 37 0", "3\n1 1 1", "2\n2 3", "2\n2 2", "5\n10000 10000 1 1 10000"], "outputs": ["2", "-1", "0", "2", "0", "-1", "0", "0", "1", "-1", "-1", "0", "0", "1", "1", "6", "40", "-1", "-1", "-1", "5", "-1", "0", "1", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 61 | codeforces |
|
c544dbf38e7f9a8e6286d2e4f208c1e3 | Puzzles | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces).
The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on.
Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=β€<=*n*<=β€<=*m*<=β€<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=β€<=*f**i*<=β€<=1000) β the quantities of pieces in the puzzles sold in the shop.
Print a single integer β the least possible difference the teacher can obtain.
Sample Input
4 6
10 12 10 7 5 22
Sample Output
5
| {"inputs": ["4 6\n10 12 10 7 5 22", "2 2\n4 4", "2 10\n4 5 6 7 8 9 10 11 12 12", "4 5\n818 136 713 59 946", "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "2 2\n1000 4", "2 3\n4 502 1000", "3 3\n4 1000 4"], "outputs": ["5", "0", "0", "759", "13", "3", "31", "0", "412", "938", "937", "0", "12", "0", "31", "996", "498", "996"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 385 | codeforces |
|
c58eac4bb58780bf424ac77f4fb18275 | Physical Education and Buns | The Physical education teacher at SESC is a sort of mathematician too. His most favorite topic in mathematics is progressions. That is why the teacher wants the students lined up in non-decreasing height form an arithmetic progression.
To achieve the goal, the gym teacher ordered a lot of magical buns from the dining room. The magic buns come in two types: when a student eats one magic bun of the first type, his height increases by one, when the student eats one magical bun of the second type, his height decreases by one. The physical education teacher, as expected, cares about the health of his students, so he does not want them to eat a lot of buns. More precisely, he wants the maximum number of buns eaten by some student to be minimum.
Help the teacher, get the maximum number of buns that some pupils will have to eat to achieve the goal of the teacher. Also, get one of the possible ways for achieving the objective, namely, the height of the lowest student in the end and the step of the resulting progression.
The single line contains integer *n* (2<=β€<=*n*<=β€<=103) β the number of students. The second line contains *n* space-separated integers β the heights of all students. The height of one student is an integer which absolute value doesn't exceed 104.
In the first line print the maximum number of buns eaten by some student to achieve the teacher's aim. In the second line, print two space-separated integers β the height of the lowest student in the end and the step of the progression. Please, pay attention that the step should be non-negative.
If there are multiple possible answers, you can print any of them.
Sample Input
5
-3 -4 -2 -3 3
5
2 -3 -1 -4 3
Sample Output
2
-3 1
1
-4 2
| {"inputs": ["5\n-3 -4 -2 -3 3", "5\n2 -3 -1 -4 3", "6\n94 65 -33 -43 60 -24", "3\n-10000 10000 -10000", "2\n0 0", "7\n-1 -2 -4 -10 6 6 5", "10\n-10 3 -16 -15 14 -16 13 -6 -8 18", "50\n-67 -84 -89 80 40 42 -38 30 74 -12 -66 27 1 11 -45 -44 2 -70 -59 -70 -59 -59 62 100 -5 1 91 79 47 -64 -51 -88 -5 37 82 87 79 46 76 47 60 57 59 -24 47 -49 -63 24 -84 -54", "100\n246 485 -940 -186 -841 -98 711 429 -154 164 -244 -111 886 -447 22 480 224 -132 927 812 -243 -152 -843 403 -320 -346 -407 827 645 -903 -172 540 -359 498 270 284 374 -52 -983 -164 -707 -242 -159 -825 -889 661 -629 212 849 -891 -622 810 957 897 -96 -293 -257 822 690 369 -914 212 -338 -928 -862 525 -537 782 727 665 964 -559 -675 -835 -800 254 -522 -504 239 909 638 -589 -700 907 127 -77 -748 999 152 -253 -505 889 -967 -481 -312 161 28 258 118 -870", "2\n-9116 9298", "2\n-10000 10000"], "outputs": ["2\n-3 1", "1\n-4 2", "25\n-67 34", "5000\n-15000 10000", "0\n0 0", "3\n-9 3", "6\n-20 4", "15\n-97 4", "83\n-1065 21", "0\n-9116 18414", "0\n-10000 20000"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
c597f61ed8d5dea2daccb09176049488 | Watchmen | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula .
The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=β€<=*i*<=<<=*j*<=β€<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs.
The first line of the input contains the single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=β€<=109).
Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
Sample Input
3
1 1
7 5
1 5
6
0 0
0 1
0 2
-1 1
0 1
1 1
Sample Output
2
11
| {"inputs": ["3\n1 1\n7 5\n1 5", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "1\n-5 -90", "2\n315 845\n-669 -762", "3\n8911 7861\n-6888 7861\n8911 7861", "2\n-1 1000000000\n0 -1", "2\n1000000000 0\n-7 1", "2\n1 4\n2 1", "2\n1 0\n0 2333333", "2\n2 1\n1 2", "2\n1 1000000000\n2 -1000000000", "2\n0 1000000000\n1 -7", "2\n1 0\n0 19990213"], "outputs": ["2", "11", "33", "0", "0", "3", "0", "0", "0", "0", "0", "0", "0", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 194 | codeforces |
|
c59ca7de6700cc5a4c83078af6170202 | The Monster and the Squirrel | Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other vertex. The ray stops when it reaches a vertex or intersects with another ray drawn before. Ari repeats this process for vertex 2,<=3,<=...,<=*n* (in this particular order). And then she puts a walnut in each region inside the polygon.
Ada the squirrel wants to collect all the walnuts, but she is not allowed to step on the lines drawn by Ari. That means Ada have to perform a small jump if she wants to go from one region to another. Ada can jump from one region P to another region Q if and only if P and Q share a side or a corner.
Assuming that Ada starts from outside of the picture, what is the minimum number of jumps she has to perform in order to collect all the walnuts?
The first and only line of the input contains a single integer *n* (3<=β€<=*n*<=β€<=54321) - the number of vertices of the regular polygon drawn by Ari.
Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after.
Sample Input
5
3
Sample Output
9
1
| {"inputs": ["5", "3", "54321", "4", "6", "7", "8", "9", "10", "54320", "54319", "54318", "54317", "54316", "54315", "54314", "8153", "51689", "16659", "47389", "314", "23481", "20380", "1994"], "outputs": ["9", "1", "2950553761", "4", "16", "25", "36", "49", "64", "2950445124", "2950336489", "2950227856", "2950119225", "2950010596", "2949901969", "2949793344", "66438801", "2671545969", "277455649", "2245527769", "97344", "551263441", "415262884", "3968064"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 113 | codeforces |
|
c5ae15dcd5da50929da25698093ceacc | Second Order Statistics | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
The first input line contains integer *n* (1<=β€<=*n*<=β€<=100) β amount of numbers in the sequence. The second line contains *n* space-separated integer numbers β elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Sample Input
4
1 2 2 -4
5
1 2 3 1 1
Sample Output
1
2
| {"inputs": ["4\n1 2 2 -4", "5\n1 2 3 1 1", "1\n28", "2\n-28 12", "3\n-83 40 -80", "8\n93 77 -92 26 21 -48 53 91", "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49", "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94", "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46", "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89", "2\n-1 -1", "3\n-2 -2 -2", "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 0 0 0", "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 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\n40 71 -85 -85 40 -85 -85 64 -85 47", "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90", "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93", "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83", "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43", "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92", "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12", "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100", "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92", "3\n1 2 3", "3\n1 3 2", "3\n2 1 3", "3\n2 3 1", "3\n3 1 2", "3\n3 2 1", "9\n99 99 99 99 100 100 100 100 100", "5\n-100 -100 -100 -100 -100"], "outputs": ["1", "2", "NO", "12", "-80", "-48", "-86", "-98", "-91", "-98", "NO", "NO", "NO", "100", "40", "-64", "-93", "-86", "-95", "-92", "-98", "-98", "-98", "2", "2", "2", "2", "2", "2", "100", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 442 | codeforces |
|
c5c5681c6f810bdbc9e8ce105d24d625 | Round Subset | Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible.
The first line contains two integer numbers *n* and *k* (1<=β€<=*n*<=β€<=200,<=1<=β€<=*k*<=β€<=*n*).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1018).
Print maximal roundness of product of the chosen subset of length *k*.
Sample Input
3 2
50 4 20
5 3
15 16 3 25 9
3 3
9 77 13
Sample Output
3
3
0
| {"inputs": ["3 2\n50 4 20", "5 3\n15 16 3 25 9", "3 3\n9 77 13", "1 1\n200000000", "1 1\n3", "3 1\n1000000000000000000 800000000000000000 625", "20 13\n93050001 1 750000001 950000001 160250001 482000001 145875001 900000001 500000001 513300001 313620001 724750001 205800001 400000001 800000001 175000001 875000001 852686005 868880001 342500001", "5 3\n1360922189858001 5513375057164001 4060879738933651 3260997351273601 5540397778584001", "5 3\n670206146698567481 75620705254979501 828058059097865201 67124386759325201 946737848872942801", "5 4\n539134530963895499 265657472022483040 798956216114326361 930406714691011229 562844921643925634", "200 10\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "200 50\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "200 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "200 200\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "5 2\n625 5 100 16 10", "5 2\n64 32 16 8 3125", "2 2\n2199023255552 11920928955078125", "1 1\n500", "3 1\n125 10 8", "7 5\n50 312500 10000 1250 2000000 250 1250000", "4 2\n3125 1000 1000 32", "3 1\n4 10 25", "3 1\n16 10 75", "3 2\n100 5120 19531250", "4 2\n16 200 500 625", "7 4\n5000 1250 100 200 10 5000 640", "2 1\n125 10", "3 2\n16 625 10", "4 2\n10 4 25 5", "2 1\n10 25", "3 1\n10 16 625", "4 2\n10 200 625 16", "3 1\n1000 16 625", "3 2\n6250 100 160", "3 2\n1250 100 80", "3 2\n1024 1000 9765625", "5 2\n125 10 10 3 3", "4 2\n31250 200 500 320", "3 1\n16 10 125", "5 3\n125 8 1000 100 100", "3 2\n25 4 10", "3 2\n125 8 10", "6 2\n125 125 100 100 8 8", "3 1\n32 3125 10", "5 3\n4 5 125 16 1", "7 4\n5 125 2 5 2 5 20", "200 200\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 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 2", "2 1\n200 250", "5 3\n500 10 250 20 8", "4 2\n2 2 25 1", "2 2\n16 25"], "outputs": ["3", "3", "0", "8", "0", "18", "0", "0", "0", "1", "0", "0", "0", "0", "4", "5", "23", "2", "1", "18", "6", "1", "1", "11", "5", "13", "1", "4", "2", "1", "1", "4", "3", "6", "5", "10", "2", "7", "1", "7", "2", "3", "4", "1", "4", "4", "100", "2", "6", "1", "2"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
c5ca3ab2eac89426a9d116a1fd9ce067 | Little Girl and Maximum Sum | The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive.
The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) β the number of elements in the array and the number of queries, correspondingly.
The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) β the array elements.
Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) β the $i$-th query.
In a single line print, a single integer β the maximum sum of query replies after the array elements are reordered.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Sample Input
3 3
5 3 2
1 2
2 3
1 3
5 3
5 2 4 1 3
1 5
2 3
2 3
Sample Output
25
33
| {"inputs": ["3 3\n5 3 2\n1 2\n2 3\n1 3", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "3 2\n1 2 3\n2 3\n1 2"], "outputs": ["25", "33", "9382", "2838", "17471", "2202", "9"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 92 | codeforces |
|
c5ea6b1be53adf0faf640c2b06b4178e | Seating On Bus | Consider 2*n* rows of the seats in a bus. *n* rows of the seats on the left and *n* rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4*n*.
Consider that *m* (*m*<=β€<=4*n*) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to *m* (in the order of their entering the bus). The pattern of the seat occupation is as below:
1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , *n*-th row left window seat, *n*-th row right window seat.
After occupying all the window seats (for *m*<=><=2*n*) the non-window seats are occupied:
1-st row left non-window seat, 1-st row right non-window seat, ... , *n*-th row left non-window seat, *n*-th row right non-window seat.
All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.
1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , *n*-th row left non-window seat, *n*-th row left window seat, *n*-th row right non-window seat, *n*-th row right window seat.
You are given the values *n* and *m*. Output *m* numbers from 1 to *m*, the order in which the passengers will get off the bus.
The only line contains two integers, *n* and *m* (1<=β€<=*n*<=β€<=100,<=1<=β€<=*m*<=β€<=4*n*) β the number of pairs of rows and the number of passengers.
Print *m* distinct integers from 1 to *m* β the order in which the passengers will get off the bus.
Sample Input
2 7
9 36
Sample Output
5 1 6 2 7 3 4
19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18
| {"inputs": ["2 7", "9 36", "1 1", "1 4", "10 1", "10 10", "10 40", "10 39", "77 1", "77 13", "77 53", "77 280", "100 1", "100 13", "100 77", "100 103", "100 200", "100 199", "100 201", "100 300", "100 399", "100 400", "3 9"], "outputs": ["5 1 6 2 7 3 4", "19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18", "1", "3 1 4 2", "1", "1 2 3 4 5 6 7 8 9 10", "21 1 22 2 23 3 24 4 25 5 26 6 27 7 28 8 29 9 30 10 31 11 32 12 33 13 34 14 35 15 36 16 37 17 38 18 39 19 40 20", "21 1 22 2 23 3 24 4 25 5 26 6 27 7 28 8 29 9 30 10 31 11 32 12 33 13 34 14 35 15 36 16 37 17 38 18 39 19 20", "1", "1 2 3 4 5 6 7 8 9 10 11 12 13", "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", "155 1 156 2 157 3 158 4 159 5 160 6 161 7 162 8 163 9 164 10 165 11 166 12 167 13 168 14 169 15 170 16 171 17 172 18 173 19 174 20 175 21 176 22 177 23 178 24 179 25 180 26 181 27 182 28 183 29 184 30 185 31 186 32 187 33 188 34 189 35 190 36 191 37 192 38 193 39 194 40 195 41 196 42 197 43 198 44 199 45 200 46 201 47 202 48 203 49 204 50 205 51 206 52 207 53 208 54 209 55 210 56 211 57 212 58 213 59 214 60 215 61 216 62 217 63 218 64 219 65 220 66 221 67 222 68 223 69 224 70 225 71 226 72 227 73 228 74 22...", "1", "1 2 3 4 5 6 7 8 9 10 11 12 13", "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", "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", "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 154 155...", "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 154 155...", "201 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 154...", "201 1 202 2 203 3 204 4 205 5 206 6 207 7 208 8 209 9 210 10 211 11 212 12 213 13 214 14 215 15 216 16 217 17 218 18 219 19 220 20 221 21 222 22 223 23 224 24 225 25 226 26 227 27 228 28 229 29 230 30 231 31 232 32 233 33 234 34 235 35 236 36 237 37 238 38 239 39 240 40 241 41 242 42 243 43 244 44 245 45 246 46 247 47 248 48 249 49 250 50 251 51 252 52 253 53 254 54 255 55 256 56 257 57 258 58 259 59 260 60 261 61 262 62 263 63 264 64 265 65 266 66 267 67 268 68 269 69 270 70 271 71 272 72 273 73 274 74 27...", "201 1 202 2 203 3 204 4 205 5 206 6 207 7 208 8 209 9 210 10 211 11 212 12 213 13 214 14 215 15 216 16 217 17 218 18 219 19 220 20 221 21 222 22 223 23 224 24 225 25 226 26 227 27 228 28 229 29 230 30 231 31 232 32 233 33 234 34 235 35 236 36 237 37 238 38 239 39 240 40 241 41 242 42 243 43 244 44 245 45 246 46 247 47 248 48 249 49 250 50 251 51 252 52 253 53 254 54 255 55 256 56 257 57 258 58 259 59 260 60 261 61 262 62 263 63 264 64 265 65 266 66 267 67 268 68 269 69 270 70 271 71 272 72 273 73 274 74 27...", "201 1 202 2 203 3 204 4 205 5 206 6 207 7 208 8 209 9 210 10 211 11 212 12 213 13 214 14 215 15 216 16 217 17 218 18 219 19 220 20 221 21 222 22 223 23 224 24 225 25 226 26 227 27 228 28 229 29 230 30 231 31 232 32 233 33 234 34 235 35 236 36 237 37 238 38 239 39 240 40 241 41 242 42 243 43 244 44 245 45 246 46 247 47 248 48 249 49 250 50 251 51 252 52 253 53 254 54 255 55 256 56 257 57 258 58 259 59 260 60 261 61 262 62 263 63 264 64 265 65 266 66 267 67 268 68 269 69 270 70 271 71 272 72 273 73 274 74 27...", "7 1 8 2 9 3 4 5 6"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 88 | codeforces |
|
c5f46d86f67634da80c5333c585ae150 | Phone Numbers | And where the are the phone numbers?
You are given a string *s* consisting of lowercase English letters and an integer *k*. Find the lexicographically smallest string *t* of length *k*, such that its set of letters is a subset of the set of letters of *s* and *s* is lexicographically smaller than *t*.
It's guaranteed that the answer exists.
Note that the set of letters is a set, not a multiset. For example, the set of letters of abadaba is {*a*,<=*b*,<=*d*}.
String *p* is lexicographically smaller than string *q*, if *p* is a prefix of *q*, is not equal to *q* or there exists *i*, such that *p**i*<=<<=*q**i* and for all *j*<=<<=*i* it is satisfied that *p**j*<==<=*q**j*. For example, abc is lexicographically smaller than abcd , abd is lexicographically smaller than abec, afa is not lexicographically smaller than ab and a is not lexicographically smaller than a.
The first line of input contains two space separated integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100<=000)Β β the length of *s* and the required length of *t*.
The second line of input contains the string *s* consisting of *n* lowercase English letters.
Output the string *t* conforming to the requirements above.
It's guaranteed that the answer exists.
Sample Input
3 3
abc
3 2
abc
3 3
ayy
2 3
ba
Sample Output
aca
ac
yaa
baa
| {"inputs": ["3 3\nabc", "3 2\nabc", "3 3\nayy", "2 3\nba", "1 3\nf", "3 1\nazz", "3 3\nzbf", "2 3\ngi", "3 2\nyzy", "5 10\nkekff", "10 5\nhqqqqcdddb", "10 10\nmrfkcsxcuj", "10 3\nggjnohlepu", "8 9\npppppppp", "10 7\nffffffffyf", "10 2\nkmiejhcimj", "10 1\ngiwekrmngf", "8 8\nlolololo", "10 9\nbcegikmyyy", "7 5000\nqqqqqqq", "3 99948\nttt"], "outputs": ["aca", "ac", "yaa", "baa", "fff", "z", "zbz", "gig", "zy", "kekffeeeee", "qbbbb", "mrfkcsxcuk", "ggl", "ppppppppp", "ffffffy", "mc", "i", "lololool", "bcegikybb", "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...", "ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt..."]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 57 | codeforces |
|
c60017dd2b08478f814800ebfa6f9f27 | Guess Your Way Out! II | Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the nodes of the tree such that
- The root is number 1 - Each internal node *i* (*i*<=β€<=2*h*<=-<=1<=-<=1) will have a left child with index = 2*i* and a right child with index = 2*i*<=+<=1
The level of a node is defined as 1 for a root, or 1 + level of parent of the node otherwise. The vertices of the level *h* are called leaves. The exit to the maze is located at some leaf node *n*, the player doesn't know where the exit is so he has to guess his way out!
In the new version of the game the player is allowed to ask questions on the format "Does the *ancestor*(*exit*,<=*i*) node number belong to the range [*L*,<=*R*]?". Here *ancestor*(*v*,<=*i*) is the ancestor of a node *v* that located in the level *i*. The game will answer with "Yes" or "No" only. The game is designed such that it doesn't always answer correctly, and sometimes it cheats to confuse the player!.
Amr asked a lot of questions and got confused by all these answers, so he asked you to help him. Given the questions and its answers, can you identify whether the game is telling contradictory information or not? If the information is not contradictory and the exit node can be determined uniquely, output its number. If the information is not contradictory, but the exit node isn't defined uniquely, output that the number of questions is not sufficient. Otherwise output that the information is contradictory.
The first line contains two integers *h*,<=*q* (1<=β€<=*h*<=β€<=50, 0<=β€<=*q*<=β€<=105), the height of the tree and the number of questions respectively.
The next *q* lines will contain four integers each *i*,<=*L*,<=*R*,<=*ans* (1<=β€<=*i*<=β€<=*h*, 2*i*<=-<=1<=β€<=*L*<=β€<=*R*<=β€<=2*i*<=-<=1, ), representing a question as described in the statement with its answer (*ans*<==<=1 if the answer is "Yes" and *ans*<==<=0 if the answer is "No").
If the information provided by the game is contradictory output "Game cheated!" without the quotes.
Else if you can uniquely identify the exit to the maze output its index.
Otherwise output "Data not sufficient!" without the quotes.
Sample Input
3 1
3 4 6 0
4 3
4 10 14 1
3 6 6 0
2 3 3 1
4 2
3 4 6 1
4 12 15 1
4 2
3 4 5 1
2 3 3 1
Sample Output
714Data not sufficient!Game cheated! | {"inputs": ["3 1\n3 4 6 0", "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "4 2\n3 4 6 1\n4 12 15 1", "4 2\n3 4 5 1\n2 3 3 1", "1 0", "1 1\n1 1 1 0"], "outputs": ["7", "14", "Data not sufficient!", "Game cheated!", "1", "Game cheated!"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
c64702b7496904c374deec17f72e5c05 | Odd sum | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
You should write a program which finds sum of the best subsequence.
The first line contains integer number *n* (1<=β€<=*n*<=β€<=105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=β€<=*a**i*<=β€<=104). The sequence contains at least one subsequence with odd sum.
Print sum of resulting subseqeuence.
Sample Input
4
-2 2 -3 1
3
2 -5 -3
Sample Output
3
-1
| {"inputs": ["4\n-2 2 -3 1", "3\n2 -5 -3", "1\n1", "1\n-1", "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046", "2\n-5439 -6705", "2\n2850 6843", "2\n144 9001", "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757", "10\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197", "10\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097", "10\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504", "10\n1184 5136 1654 3254 6576 6900 6468 327 179 7114", "10\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812", "3\n1 1 1", "5\n5 5 5 3 -1", "5\n-1 -2 5 3 0", "5\n-3 -2 5 -1 3", "3\n-2 2 -1", "5\n5 0 7 -2 3", "2\n-2 -5", "3\n-1 -3 0", "5\n2 -1 0 -3 -2", "4\n2 3 0 5", "5\n-5 3 -2 2 5", "59\n8593 5929 3016 -859 4366 -6842 8435 -3910 -2458 -8503 -3612 -9793 -5360 -9791 -362 -7180 727 -6245 -8869 -7316 8214 -7944 7098 3788 -5436 -6626 -1131 -2410 -5647 -7981 263 -5879 8786 709 6489 5316 -4039 4909 -4340 7979 -89 9844 -906 172 -7674 -3371 -6828 9505 3284 5895 3646 6680 -1255 3635 -9547 -5104 -1435 -7222 2244", "17\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565", "26\n-8668 9705 1798 -1766 9644 3688 8654 -3077 -5462 2274 6739 2732 3635 -4745 -9144 -9175 -7488 -2010 1637 1118 8987 1597 -2873 -5153 -8062 146", "51\n8237 -7239 -3545 -6059 -5110 4066 -4148 -7641 -5797 -994 963 1144 -2785 -8765 -1216 5410 1508 -6312 -6313 -680 -7657 4579 -6898 7379 2015 -5087 -5417 -6092 3819 -9101 989 -8380 9161 -7519 -9314 -3838 7160 5180 567 -1606 -3842 -9665 -2266 1296 -8417 -3976 7436 -2075 -441 -4565 3313", "1\n-1", "1\n1", "1\n-1", "1\n1", "1\n1", "1\n-1", "1\n-1", "1\n1", "2\n-2 1", "2\n3 2", "2\n1 2", "2\n-1 1", "2\n0 -1", "2\n2 1", "2\n3 0", "2\n0 -1", "3\n-3 1 -1", "3\n3 -1 1", "3\n1 3 1", "3\n-1 0 1", "3\n-3 -3 -2", "3\n3 -1 1", "3\n3 -1 1", "3\n-2 -2 1", "4\n0 -1 -3 -4", "4\n5 3 2 1", "4\n-1 -2 4 -2", "4\n-1 -3 0 -3", "4\n1 -4 -3 -4", "4\n5 3 3 4", "4\n-1 -3 -1 2", "4\n3 2 -1 -4", "5\n-5 -4 -3 -5 2", "5\n5 5 1 2 -2", "5\n-2 -1 -5 -1 4", "5\n-5 -5 -4 4 0", "5\n2 -3 -1 -4 -5", "5\n4 3 4 2 3", "5\n0 -2 -5 3 3", "5\n4 -2 -2 -3 0", "6\n6 7 -1 1 5 -1", "6\n-1 7 2 -3 -4 -5", "6\n0 -1 -3 -5 2 -6", "6\n4 -1 0 3 6 1", "6\n5 3 3 4 4 -3", "6\n0 -3 5 -4 5 -4", "6\n-5 -3 1 -1 -5 -3", "6\n-2 1 3 -2 7 4", "7\n0 7 6 2 7 0 6", "7\n6 -6 -1 -5 7 1 7", "7\n2 3 -5 0 -4 0 -4", "7\n-6 3 -3 -1 -6 -6 -5", "7\n7 6 3 2 4 2 0", "7\n-2 3 -3 4 4 0 -1", "7\n-5 -7 4 0 5 -3 -5", "7\n-3 -5 -4 1 3 -4 -7", "8\n5 2 4 5 7 -2 7 3", "8\n-8 -3 -1 3 -8 -4 -4 4", "8\n-6 -7 -7 -5 -4 -9 -2 -7", "8\n8 7 6 8 3 4 8 -2", "8\n6 7 0 -6 6 5 4 7", "8\n0 -7 -5 -5 5 -1 -8 -7", "8\n1 -6 -5 7 -3 -4 2 -2", "8\n1 -8 -6 -6 -6 -7 -5 -1", "9\n-3 -1 4 4 8 -8 -5 9 -2", "9\n-9 -1 3 -2 -7 2 -9 -1 -4", "9\n-6 -9 -3 -8 -5 2 -6 0 -5", "9\n5 4 3 3 6 7 8 5 9", "9\n5 3 9 1 5 2 -3 7 0", "9\n-3 -9 -1 -7 5 6 -4 -6 -6", "9\n-6 -5 6 -5 -2 0 1 2 -9", "9\n8 3 6 1 -3 5 2 9 1", "10\n-6 -4 -7 -1 -9 -10 -10 1 0 -3", "10\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8", "10\n8 5 9 2 3 3 -6 1 -1 8", "10\n2 10 -7 6 -1 -1 7 -9 -4 -6", "10\n-10 -2 -2 -1 -10 -7 1 0 -4 -5", "10\n4 3 10 -2 -1 0 10 6 7 0", "10\n-2 6 6 5 0 10 6 7 -1 1", "10\n-10 2 8 -6 -1 -5 1 -10 -10 -1"], "outputs": ["3", "-1", "1", "-1", "53507", "-5439", "9693", "9145", "38951", "18005", "28605", "8463", "38613", "-787", "3", "17", "7", "7", "1", "15", "-5", "-1", "1", "7", "7", "129433", "43749", "60757", "73781", "-1", "1", "-1", "1", "1", "-1", "-1", "1", "1", "5", "3", "1", "-1", "3", "3", "-1", "1", "3", "5", "1", "-3", "3", "3", "1", "-1", "11", "3", "-1", "1", "15", "1", "5", "-1", "13", "3", "-1", "1", "13", "3", "1", "19", "9", "1", "13", "19", "7", "1", "15", "21", "21", "5", "3", "21", "11", "9", "3", "33", "7", "-5", "41", "35", "5", "9", "1", "25", "5", "-1", "47", "31", "11", "9", "35", "1", "-3", "39", "25", "1", "39", "41", "11"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 102 | codeforces |
|
c6729c66bbbfd7bb2760347f9870b5b0 | Sum of Remainders | Calculate the value of the sum: *n* mod 1 + *n* mod 2 + *n* mod 3 + ... + *n* mod *m*. As the result can be very large, you should print the value modulo 109<=+<=7 (the remainder when divided by 109<=+<=7).
The modulo operator *a* mod *b* stands for the remainder after dividing *a* by *b*. For example 10 mod 3 = 1.
The only line contains two integers *n*,<=*m* (1<=β€<=*n*,<=*m*<=β€<=1013) β the parameters of the sum.
Print integer *s* β the value of the required sum modulo 109<=+<=7.
Sample Input
3 4
4 4
1 1
Sample Output
4
1
0
| {"inputs": ["3 4", "4 4", "1 1", "20000000 10000000", "10000000000000 10000000000000", "1 10000000000000", "10000000000000 1", "100 100", "1000 1000", "500 1000", "1010 435", "997167959139 7344481199252", "7244641009859 6300054748096", "3483524125987 5259923264237", "9726702209411 4215496813081", "5965585325539 3175365329221", "2213058376259 2126643910770", "8451941492387 3119072235422", "4690824608515 2078940751563", "1666199186071 28985049", "9999999999989 9999998979371", "9999999999999 9999999999957", "56598 56"], "outputs": ["4", "1", "0", "176305083", "869957328", "999930006", "0", "1701", "176919", "294117", "48431", "695194729", "955368330", "953462184", "517714807", "286054680", "971336268", "394884104", "858876367", "729884985", "915094997", "344038473", "755"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
c6cb6358e37594008f8beb2f16fd86b0 | Kindergarten | In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particular, if the group consists of one child, its sociability equals a zero).
The teacher wants to divide the children into some number of groups in such way that the total sociability of the groups is maximum. Help him find this value.
The first line contains integer *n*Β β the number of children in the line (1<=β€<=*n*<=β€<=106).
The second line contains *n* integers *a**i*Β β the charisma of the *i*-th child (<=-<=109<=β€<=*a**i*<=β€<=109).
Print the maximum possible total sociability of all groups.
Sample Input
5
1 2 3 1 2
3
3 3 3
Sample Output
3
0
| {"inputs": ["5\n1 2 3 1 2", "3\n3 3 3", "1\n0", "2\n-1000000000 1000000000", "4\n1 4 2 3", "4\n23 5 7 1", "4\n23 7 5 1", "8\n23 2 7 5 15 8 4 10", "8\n4 5 3 6 2 7 1 8"], "outputs": ["3", "0", "0", "2000000000", "4", "24", "22", "37", "16"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
c6e9fbfb051ff01b6a80e52bde08d396 | LCM Challenge | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers?
The first line contains an integer *n* (1<=β€<=*n*<=β€<=106) β the *n* mentioned in the statement.
Print a single integer β the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*.
Sample Input
9
7
Sample Output
504
210
| {"inputs": ["9", "7", "1", "5", "6", "33", "21", "2", "41", "29", "117", "149", "733", "925", "509", "829", "117", "605", "245", "925", "213", "53", "341", "21", "605", "149", "733", "117", "53", "245", "829", "924", "508", "700", "636", "20", "604", "796", "732", "412", "700", "244", "828", "508", "796", "636", "924", "245", "828", "21", "605", "636", "924", "116", "700", "732", "20", "508", "148", "828", "763116", "756604", "447244", "372636", "546924", "540412", "714700", "520731", "695019", "688507", "862795", "668827", "810411", "836603", "978187", "816923", "958507", "984699", "642635", "296604", "1000000", "8", "3", "4", "30", "18", "12"], "outputs": ["504", "210", "1", "60", "60", "32736", "7980", "2", "63960", "21924", "1560780", "3241644", "392222436", "788888100", "131096004", "567662724", "1560780", "220348260", "14526540", "788888100", "9527916", "140556", "39303660", "7980", "220348260", "3241644", "392222436", "1560780", "140556", "14526540", "567662724", "783776526", "130065780", "341042100", "254839470", "6460", "218891412", "501826260", "389016270", "69256788", "341042100", "14289372", "563559150", "130065780", "501826260", "254839470", "783776526", "14526540", "563559150", "7980", "220348260", "254839470", "783776526", "1507420", "341042100", "389016270", "6460", "130065780", "3154620", "563559150", "444394078546562430", "433115377058855412", "89460162932862372", "51742503205363470", "163597318076822526", "157823524476316788", "365063922340784100", "141201007712496270", "335728459024850814", "326379736779169710", "642275489615199390", "299184742915995150", "532248411551110590", "585540171302562606", "935975171582120670", "545182335484592526", "880611813728059710", "954792870629291694", "265393998349453470", "26092892528622606", "999996000003000000", "280", "6", "12", "21924", "4080", "990"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 122 | codeforces |
|
c6fc6efb4116f26068ba51942a03faac | Mahmoud and Ehab and the xor | Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to find a set of *n* distinct non-negative integers such the bitwise-xor sum of the integers in it is exactly *x*. Dr. Evil doesn't like big numbers, so any number in the set shouldn't be greater than 106.
The only line contains two integers *n* and *x* (1<=β€<=*n*<=β€<=105, 0<=β€<=*x*<=β€<=105)Β β the number of elements in the set and the desired bitwise-xor, respectively.
If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them.
Sample Input
5 5
3 6
Sample Output
YES
1 2 4 5 7YES
1 2 5 | {"inputs": ["5 5", "3 6", "3 0", "1 0", "3 3", "100000 41243", "100000 100000", "32 32", "32 31", "1 1", "2 0", "3 1", "3 2", "3 5", "3 4", "3 10203", "3 10100", "5 0", "5 1", "5 2", "5 3", "5 4", "5 6", "5 7", "5 8", "5 9", "100000 1", "100000 0", "100000 21323", "100000 65536", "100000 65537", "100000 65535", "4 2", "10 2", "1 2", "1 3", "2 1", "2 2", "2 3", "4 0", "4 1", "4 3", "6 0", "7 1"], "outputs": ["YES\n1 2 131072 131078 0 ", "YES\n131072 131078 0 ", "YES\n393216 131072 262144", "YES\n0", "YES\n131072 131075 0 ", "YES\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 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...", "YES\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 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...", "YES\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 131072 131105 0 ", "YES\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 131072 131102 0 ", "YES\n1", "NO", "YES\n131072 131073 0 ", "YES\n131072 131074 0 ", "YES\n131072 131077 0 ", "YES\n131072 131076 0 ", "YES\n131072 141275 0 ", "YES\n131072 141172 0 ", "YES\n1 2 131072 131075 0 ", "YES\n1 2 131072 131074 0 ", "YES\n1 2 131072 131073 0 ", "YES\n1 2 393216 131072 262144", "YES\n1 2 131072 131079 0 ", "YES\n1 2 131072 131077 0 ", "YES\n1 2 131072 131076 0 ", "YES\n1 2 131072 131083 0 ", "YES\n1 2 131072 131082 0 ", "YES\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 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...", "YES\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 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...", "YES\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 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...", "YES\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 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...", "YES\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 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...", "YES\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 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...", "YES\n1 131072 131075 0 ", "YES\n1 2 3 4 5 6 7 131072 131074 0 ", "YES\n2", "YES\n3", "YES\n0 1", "YES\n0 2", "YES\n0 3", "YES\n1 131072 131073 0 ", "YES\n1 393216 131072 262144", "YES\n1 131072 131074 0 ", "YES\n1 2 3 393216 131072 262144", "YES\n1 2 3 4 131072 131077 0 "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 9 | codeforces |
|
c71255b01a479ab3650e790fad56511a | Fire Again | After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation.
The burning began in *K* points simultaneously, which means that initially *K* trees started to burn. Every minute the fire gets from the burning trees to the ones that arenβt burning and that the distance from them to the nearest burning tree equals to 1.
Find the tree that will be the last to start burning. If there are several such trees, output any.
The first input line contains two integers *N*,<=*M* (1<=β€<=*N*,<=*M*<=β€<=2000) β the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=β€<=*x*<=β€<=*N*,<=1<=β€<=*y*<=β€<=*M*) type, *x* and *y* are integers.
The second line contains an integer *K* (1<=β€<=*K*<=β€<=10) β amount of trees, burning in the beginning.
The third line contains *K* pairs of integers: *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k* (1<=β€<=*x**i*<=β€<=*N*,<=1<=β€<=*y**i*<=β€<=*M*) β coordinates of the points from which the fire started. It is guaranteed that no two points coincide.
Output a line with two space-separated integers *x* and *y* β coordinates of the tree that will be the last one to start burning. If there are several such trees, output any.
Sample Input
3 3
1
2 2
3 3
1
1 1
3 3
2
1 1 3 3
Sample Output
1 1
3 3
2 2 | {"inputs": ["3 3\n1\n2 2", "3 3\n1\n1 1", "3 3\n2\n1 1 3 3", "1 1\n1\n1 1", "2 2\n1\n2 2", "2 2\n2\n1 1 2 1", "2 2\n3\n1 2 2 1 1 1", "2 2\n4\n2 1 2 2 1 1 1 2", "10 10\n1\n5 5", "10 10\n2\n7 8 1 9", "10 10\n3\n3 9 6 3 3 5", "10 10\n4\n5 3 4 7 7 5 8 5", "10 10\n5\n2 7 10 6 5 3 9 5 2 9", "10 10\n6\n5 1 4 6 3 9 9 9 5 7 7 2", "10 10\n7\n5 8 4 6 4 1 6 2 1 10 3 2 7 10", "10 10\n8\n9 4 9 10 5 8 6 5 1 3 2 5 10 6 2 1", "10 10\n9\n10 1 10 4 8 4 6 6 1 9 10 10 7 7 6 5 7 10", "10 10\n10\n7 2 1 9 5 8 6 10 9 4 10 8 6 8 8 7 4 1 9 5", "100 100\n1\n44 3", "100 100\n2\n79 84 76 63", "100 100\n3\n89 93 99 32 32 82", "100 100\n4\n72 12 1 66 57 67 25 67", "100 100\n5\n22 41 82 16 6 3 20 6 69 78", "100 100\n6\n92 32 90 80 32 40 24 19 36 37 39 13", "100 100\n7\n30 32 29 63 86 78 88 2 86 50 41 60 54 28", "100 100\n8\n40 43 96 8 17 63 61 59 16 69 4 95 30 62 12 91", "100 100\n9\n18 16 41 71 25 1 43 38 78 92 77 70 99 8 33 54 76 78", "100 100\n10\n58 98 33 62 75 13 94 86 81 42 14 53 12 66 7 14 3 63 87 37", "2000 2000\n1\n407 594", "2000 2000\n2\n1884 43 1235 1111", "2000 2000\n3\n1740 1797 1279 1552 329 756", "2000 2000\n4\n1844 1342 171 1810 1558 1141 1917 1999", "2000 2000\n5\n1846 327 1911 1534 134 1615 1664 682 1982 1112", "2000 2000\n6\n1744 1102 852 723 409 179 89 1085 997 1433 1082 1680", "2000 2000\n7\n1890 22 288 1729 383 831 1192 1206 721 1376 969 492 510 1699", "2000 2000\n8\n286 381 572 1849 1703 1574 622 1047 1507 941 871 663 1930 120 1084 1830", "2000 2000\n9\n226 531 56 138 722 405 1082 608 1355 1426 83 544 275 1268 683 412 1880 1049", "2000 2000\n10\n763 851 1182 571 1758 389 247 1907 730 881 531 1970 1430 667 169 765 1729 120 129 967", "2000 2000\n10\n655 95 1640 1656 1344 79 666 1677 968 1180 522 1394 1850 1568 336 130 412 920 29 1664", "10 1\n10\n4 1 6 1 10 1 9 1 1 1 7 1 5 1 2 1 8 1 3 1", "1 10\n10\n1 10 1 4 1 3 1 7 1 6 1 1 1 8 1 2 1 9 1 5", "1 100\n10\n1 68 1 18 1 43 1 12 1 64 1 34 1 23 1 70 1 46 1 33", "100 1\n10\n62 1 63 1 57 1 76 1 35 1 69 1 73 1 95 1 96 1 21 1", "1 2000\n10\n1 1730 1 1374 1 831 1 1076 1 580 1 914 1 123 1 668 1 1288 1 160", "2000 1\n10\n1058 1 1779 1 1995 1 1398 1 96 1 1599 1 1496 1 1659 1 385 1 1485 1", "5 5\n1\n1 1", "2 5\n10\n1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5", "1 10\n9\n1 1 1 2 1 3 1 4 1 6 1 7 1 8 1 9 1 10", "3 3\n5\n1 1 1 3 2 2 3 1 3 3", "999 999\n4\n1 499 499 1 499 999 999 499"], "outputs": ["1 1", "3 3", "1 3", "1 1", "1 1", "1 2", "2 2", "1 1", "10 10", "3 1", "10 7", "10 10", "1 1", "1 3", "10 5", "1 10", "1 1", "1 3", "100 100", "1 1", "1 1", "100 100", "1 100", "1 100", "1 100", "100 100", "1 100", "40 1", "2000 2000", "1 2000", "2000 1", "530 1", "346 1", "2000 1", "2000 2000", "1 1423", "1701 1", "2000 1793", "2000 570", "1 1", "1 1", "1 100", "1 1", "1 2000", "721 1", "5 5", "1 1", "1 5", "1 2", "500 500"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
c73011b7f575e990667e991cae603566 | Oath of the Night's Watch | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." β The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
First line consists of a single integer *n* (1<=β€<=*n*<=β€<=105) β the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=109) representing the values assigned to the stewards.
Output a single integer representing the number of stewards which Jon will feed.
Sample Input
2
1 5
3
1 2 5
Sample Output
01 | {"inputs": ["2\n1 5", "3\n1 2 5", "4\n1 2 3 4", "8\n7 8 9 4 5 6 1 2", "1\n1", "1\n100", "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1", "4\n1000000000 99999999 1000000000 1000000000", "3\n2 2 2", "5\n1 1 1 1 1", "3\n1 1 1", "6\n1 1 3 3 2 2", "7\n1 1 1 1 1 1 1", "4\n1 1 2 5", "3\n0 0 0", "5\n0 0 0 0 0", "5\n1 1 1 1 5", "5\n1 1 2 3 3", "3\n1 1 3", "3\n2 2 3", "1\n6", "5\n1 5 3 5 1", "7\n1 2 2 2 2 2 3", "4\n2 2 2 2", "9\n2 2 2 3 4 5 6 6 6", "10\n1 1 1 2 3 3 3 3 3 3", "6\n1 1 1 1 1 1", "3\n0 0 1", "9\n1 1 1 2 2 2 3 3 3", "3\n1 2 2", "6\n2 2 2 2 2 2", "5\n2 2 2 2 2", "5\n5 5 5 5 5", "1\n0", "6\n1 2 5 5 5 5", "5\n1 2 3 3 3", "3\n1 1 2", "6\n1 1 1 1 1 2", "5\n1 1 2 4 4", "3\n999999 5999999 9999999", "4\n1 1 5 5", "9\n1 1 1 2 2 2 4 4 4", "5\n1 3 4 5 1", "5\n3 3 3 3 3", "5\n1 1 2 2 2", "5\n2 1 1 1 3", "5\n0 0 0 1 2", "4\n2 2 2 3", "7\n1 1 1 1 5 5 5", "5\n1 2 3 4 4", "2\n5 4", "4\n5 5 5 5", "5\n1 1 1 5 5", "2\n1 1", "1\n3", "3\n2 1 2", "4\n1 2 2 2", "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998", "5\n1 1 3 4 4", "6\n1 1 2 2 3 3", "4\n1 1 1 1", "9\n1 2 3 4 1 5 6 7 8", "8\n5 4 4 6 6 4 4 3", "8\n4 3 3 3 3 3 3 3", "7\n4 3 3 3 3 3 3", "6\n4 3 3 3 3 3", "5\n4 3 3 3 3"], "outputs": ["0", "1", "2", "6", "0", "0", "174", "0", "0", "0", "0", "2", "0", "1", "0", "0", "0", "1", "0", "0", "0", "1", "5", "0", "3", "1", "0", "0", "3", "0", "0", "0", "0", "0", "1", "1", "0", "0", "1", "1", "0", "3", "2", "0", "0", "1", "1", "0", "0", "2", "0", "0", "0", "0", "0", "0", "0", "3", "1", "2", "0", "6", "5", "0", "0", "0", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 198 | codeforces |
|
c7341b7a840763c95143df19e11cfce1 | Oranges and Apples | In 2*N*<=-<=1 boxes there are apples and oranges. Your task is to choose *N* boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
The first input line contains one number *T* β amount of tests. The description of each test starts with a natural number *N* β amount of boxes. Each of the following 2*N*<=-<=1 lines contains numbers *a**i* and *o**i* β amount of apples and oranges in the *i*-th box (0<=β€<=*a**i*,<=*o**i*<=β€<=109). The sum of *N* in all the tests in the input doesn't exceed 105. All the input numbers are integer.
For each test output two lines. In the first line output YES, if it's possible to choose *N* boxes, or NO otherwise. If the answer is positive output in the second line *N* numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Sample Input
2
2
10 15
5 7
20 18
1
0 0
Sample Output
YES
1 3
YES
1
| {"inputs": ["2\n2\n10 15\n5 7\n20 18\n1\n0 0"], "outputs": ["YES\n3 1\nYES\n1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 5 | codeforces |
|
c74fe8f7ab7e5d953a678609275967cc | Inna and New Matrix of Candies | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=Γ<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The game lasts for several moves. During each move the player should choose all lines of the matrix where dwarf is not on the cell with candy and shout "Let's go!". After that, all the dwarves from the chosen lines start to simultaneously move to the right. During each second, each dwarf goes to the adjacent cell that is located to the right of its current cell. The movement continues until one of the following events occurs:
- some dwarf in one of the chosen lines is located in the rightmost cell of his row; - some dwarf in the chosen lines is located in the cell with the candy.
The point of the game is to transport all the dwarves to the candy cells.
Inna is fabulous, as she came up with such an interesting game. But what about you? Your task is to play this game optimally well. Specifically, you should say by the given game field what minimum number of moves the player needs to reach the goal of the game.
The first line of the input contains two integers *n* and *m* (1<=β€<=*n*<=β€<=1000;Β 2<=β€<=*m*<=β€<=1000).
Next *n* lines each contain *m* characters β the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a candy. The matrix doesn't contain other characters. It is guaranteed that each line contains exactly one character "G" and one character "S".
In a single line print a single integer β either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field.
Sample Input
3 4
*G*S
G**S
*G*S
1 3
S*G
Sample Output
2
-1
| {"inputs": ["3 4\n*G*S\nG**S\n*G*S", "1 3\nS*G", "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S", "5 10\nG***S*****\nG****S****\n***GS*****\nG*S*******\nG***S*****", "4 8\nG*S*****\n****G*S*\nG*****S*\n**G***S*", "4 10\n***G****S*\n*****GS***\nG****S****\nG*******S*", "1 2\nSG", "1 2\nGS", "1 4\nSG**"], "outputs": ["2", "-1", "9", "4", "3", "3", "-1", "1", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 101 | codeforces |
|
c7a543879506cdc6eb620e614597cc1f | Compartments | A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of *n* compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they get bored, and if one compartment contain three or four students, then the compartment has fun throughout the entire trip.
The students want to swap with other people, so that no compartment with students had bored students. To swap places with another person, you need to convince him that it is really necessary. The students can not independently find the necessary arguments, so they asked a sympathetic conductor for help. The conductor can use her life experience to persuade any passenger to switch places with some student.
However, the conductor does not want to waste time persuading the wrong people, so she wants to know what is the minimum number of people necessary to persuade her to change places with the students. Your task is to find the number.
After all the swaps each compartment should either have no student left, or have a company of three or four students.
The first line contains integer *n* (1<=β€<=*n*<=β€<=106) β the number of compartments in the carriage. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* showing how many students ride in each compartment (0<=β€<=*a**i*<=β€<=4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
Sample Input
5
1 2 2 4 3
3
4 1 1
4
0 3 0 4
Sample Output
2
2
0
| {"inputs": ["5\n1 2 2 4 3", "3\n4 1 1", "4\n0 3 0 4", "5\n4 4 3 3 1", "5\n4 3 4 2 4", "10\n2 1 2 3 4 1 3 4 4 4", "10\n2 3 3 1 3 1 3 2 2 4", "120\n1 1 1 1 1 1 1 4 4 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 4 1 1 4 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 2 4 1 1 3 1 1 1 2 1 0 3 1 1 1 2 1 4 1 1 1 1 1 1 1 1 1 1", "10\n2 4 1 3 1 2 2 2 2 2", "10\n3 4 2 2 1 1 3 1 1 2", "20\n4 1 4 4 2 1 4 3 2 3 1 1 2 2 2 4 4 2 4 2", "20\n4 3 4 2 1 1 3 1 4 2 1 4 3 3 4 3 1 1 1 3", "20\n4 1 1 1 4 2 3 3 2 1 1 4 4 3 1 1 2 4 2 3", "20\n4 4 2 4 3 2 3 1 4 1 1 4 1 4 3 4 4 3 3 3", "20\n4 2 3 3 1 3 2 3 1 4 4 4 2 1 4 2 1 3 4 4", "23\n2 3 1 1 1 1 4 3 2 2 3 3 4 1 4 2 4 1 4 2 3 1 1", "27\n0 2 4 1 4 2 1 2 3 4 2 4 1 2 3 2 3 2 2 1 0 4 3 0 3 0 1", "28\n2 0 4 2 3 4 1 1 4 3 0 3 0 3 2 3 2 4 1 2 4 3 3 3 0 1 0 1", "24\n4 2 4 3 1 3 4 1 3 4 2 4 0 2 3 4 1 1 4 3 1 2 2 4", "19\n2 4 4 2 0 0 1 4 1 0 2 2 4 2 0 1 1 1 4", "16\n3 3 3 1 3 0 1 4 4 4 1 4 3 1 1 4", "17\n3 3 1 0 1 3 1 1 1 3 0 2 2 2 3 2 2", "12\n2 2 2 1 1 0 2 0 1 1 2 1", "15\n4 0 1 0 0 4 1 1 0 4 1 4 4 1 0", "20\n0 4 4 0 0 0 2 3 3 3 2 0 3 2 3 2 4 4 2 4", "23\n1 1 3 2 0 3 1 2 2 2 1 3 3 4 1 0 0 3 1 2 2 0 3", "15\n0 2 4 2 0 4 4 2 4 4 1 2 4 2 2", "17\n0 4 3 0 2 2 4 2 4 4 2 4 2 1 0 0 0", "21\n0 3 2 3 0 2 3 4 3 0 1 3 2 2 3 3 3 0 2 2 0", "21\n1 1 3 1 0 3 3 3 3 0 1 3 0 3 1 1 1 3 2 0 0", "13\n1 1 1 2 1 1 4 1 3 1 1 1 0", "14\n4 2 4 4 0 4 4 0 1 0 0 4 3 4", "13\n2 1 2 2 3 4 0 2 2 2 2 2 2", "10\n2 2 2 0 0 0 0 0 2 2", "11\n2 2 2 2 0 2 2 2 2 2 2", "11\n1 1 1 1 1 1 1 1 1 1 1", "16\n0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1", "17\n1 1 4 1 1 0 1 1 1 1 0 1 0 1 0 0 1", "14\n1 0 0 1 1 1 0 1 1 1 1 1 3 0", "9\n1 1 1 2 1 1 1 1 1", "13\n2 2 0 4 2 2 2 2 2 1 2 2 2", "19\n2 2 3 2 0 0 1 1 2 0 0 2 1 2 2 2 0 2 2", "29\n3 1 3 3 0 2 2 3 3 2 0 3 3 2 3 0 3 3 0 2 2 2 3 2 0 3 2 2 3", "27\n0 1 2 2 3 3 2 0 2 3 2 0 2 3 2 2 2 2 3 3 1 3 2 3 1 2 2", "29\n3 3 2 0 1 1 1 2 2 2 1 3 2 0 2 3 3 2 2 3 2 2 2 2 1 2 2 2 4", "13\n4 1 1 4 1 1 1 1 1 1 1 1 1", "30\n1 1 1 3 3 4 0 1 1 1 1 1 1 3 0 0 0 1 1 1 1 3 1 1 1 1 3 1 1 1", "32\n1 4 4 3 1 4 4 4 1 1 1 1 1 4 1 1 1 4 1 1 1 1 2 1 1 4 4 1 1 1 1 4", "48\n1 3 1 1 1 1 1 1 2 1 1 2 1 1 4 1 1 1 2 2 2 1 3 1 1 1 1 2 1 2 2 1 1 1 1 1 3 0 2 3 1 1 3 1 0 1 2 1", "49\n2 2 1 2 2 2 2 2 2 2 2 2 1 2 1 3 4 2 2 2 2 4 1 1 2 1 2 2 2 2 2 4 0 0 2 0 1 1 2 1 2 2 2 2 4 4 2 2 1", "165\n1 1 1 1 1 1 1 1 0 2 2 2 1 1 1 1 1 4 4 1 1 2 2 1 2 1 2 2 2 1 2 2 3 1 1 2 1 1 2 2 4 1 2 2 2 4 1 1 1 4 2 2 1 1 1 1 1 2 1 1 1 2 1 1 1 1 4 2 2 1 1 1 1 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 1 2 2 1 1 1 2 1 4 2 2 2 1 1 1 1 2 3 2 1 2 1 1 2 1 1 1 1 1 2 1 2 1 1 0 1 2 1 1 1 1 1 3 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 3 4 1 1 1", "197\n1 4 4 4 1 4 1 1 0 1 4 4 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 4 1 1 1 1 1 4 1 1 1 2 1 1 4 4 4 4 4 4 1 1 1 4 1 4 4 4 4 4 1 1 1 1 1 4 4 1 4 0 4 1 4 4 1 4 4 4 2 1 1 4 4 2 1 1 1 4 1 4 1 4 4 4 1 1 4 4 4 1 1 0 1 4 1 4 0 4 3 1 1 1 4 1 4 4 4 1 4 1 4 3 1 4 4 4 1 1 4 0 4 1 1 4 1 4 4 1 4 1 1 1 4 1 4 1 1 3 4 1 4 4 1 1 1 1 4 1 1 3 4 1 1 0 1 4 4 1 4 4 1 4 4 1 1 0 2 1 4 1 4 1 1 1 1 1 4 4 1 1 0 4 2 4 1 4 1 4 4", "177\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 4 2 2 2 2 4 2 0 2 2 2 2 2 3 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 1 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 0 2 4 2 2 2 2 2 2 4 2 2 2 2 2 3 2 1 2 2 2 2 2 2 4 4 2 2 2 4 2 2 2 2 2 2 2 2 4 2 4 2 2 4 2 2 2 2 2 2 2 2 0 2 3 2 2 2 2 2 2 2 0 2 2 4 2 2 2 2 3 2 2", "166\n2 3 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 4 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 3 2 0 2 0 3 2 2 2 0 2 0 2 2 2 2 2 2 3 0 2 2 2 2 2 3 3 2 2 2 3 2 2 2 3 3 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 2 2 2 2 2 2 2 2 2 0 2 2 2 2 3 2 2 2 2", "172\n2 2 2 0 1 3 2 1 0 3 3 1 0 1 2 3 4 2 2 4 2 1 4 0 3 2 2 3 3 3 0 0 3 1 1 0 1 2 2 0 1 4 4 0 3 3 2 0 1 4 4 1 4 2 2 3 0 1 2 2 1 1 4 4 4 4 0 1 0 2 4 0 2 0 0 2 2 1 4 2 2 2 2 2 0 2 3 0 2 1 0 2 1 0 2 2 0 2 2 0 2 2 2 1 1 0 2 1 2 1 0 2 2 0 2 2 3 2 4 2 4 3 2 3 1 2 2 4 0 2 0 2 2 1 0 1 2 1 4 1 0 3 2 2 1 0 0 2 0 4 2 2 0 0 4 1 3 2 1 1 0 2 3 2 0 2 2 2 2 2 3 0", "141\n2 1 1 1 1 1 4 2 3 1 1 1 1 1 1 4 1 1 1 1 1 1 1 4 4 1 1 1 1 2 1 4 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 2 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 3 1 1 1 1 1 4 4 1 3 4 1 1 1 1 1 1 1 1 1 4 2 1 0 1 1 4 1 1 1 1 2 1 0 1 1 2 1 1 1 1 4 4 1 2 4 4 1 1 3 1 1 1 3 1 1 4 4 1 1 1 4 1 1 1 1 1 1 2 0 1 0 0 1 0 4", "108\n2 2 1 4 2 2 1 2 2 2 2 2 2 4 2 2 4 2 4 2 2 2 2 4 2 4 2 2 2 1 2 1 2 2 2 4 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 4 2 2 2 2 4 2 2 2 1 2 2 2 2 2 4 1 2 2", "138\n3 1 3 1 3 3 3 1 1 1 1 1 1 3 3 1 1 1 3 3 1 1 3 1 1 1 1 1 1 1 3 3 3 1 3 1 1 1 1 1 3 1 1 3 1 3 1 3 1 1 1 1 3 1 3 1 1 3 1 1 1 3 1 1 1 1 1 1 1 1 3 1 1 1 1 3 1 3 1 3 3 3 3 3 3 1 1 1 3 1 1 3 1 1 1 1 1 1 1 1 3 1 1 3 3 1 3 3 1 3 1 1 1 3 1 1 1 1 1 1 3 1 1 1 1 3 1 1 1 3 1 1 3 1 1 3 1 1", "81\n2 2 2 3 2 3 2 2 2 2 2 3 2 2 2 2 2 2 0 2 4 2 3 4 2 3 2 3 2 0 2 2 0 2 2 3 2 2 4 3 3 2 2 2 2 2 2 2 3 2 2 2 2 2 2 3 3 2 2 3 2 0 2 0 2 2 2 2 2 2 4 0 2 3 2 4 2 2 2 2 2", "115\n2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 4 2 4 2 4 2 2 2 2 2 2 2 2 2 2 2 4 4 3 2 2 2 2 2 2 2 4 2 2 2 3 2 2 2 2 2 2 4 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 3 2 2 2 2 2 4 4 4 2 2", "146\n1 1 1 1 1 4 1 1 0 1 4 4 1 4 1 1 1 1 1 4 1 1 1 1 1 1 1 4 1 1 1 1 4 1 4 1 1 1 0 1 4 1 4 1 4 4 1 1 1 1 1 1 1 1 1 4 4 1 1 4 1 4 4 4 1 1 4 4 1 4 1 1 1 1 0 1 1 1 1 1 1 4 1 4 1 1 4 1 1 4 4 4 1 1 4 1 1 1 1 1 1 1 4 1 1 1 4 1 4 1 1 1 1 1 1 1 4 1 1 4 4 4 1 1 1 1 1 1 1 4 1 1 1 1 4 1 4 1 1 1 4 4 4 4 1 1", "198\n1 2 1 2 2 1 2 1 1 1 3 2 1 1 2 1 2 2 1 1 1 4 1 1 1 1 0 1 1 1 1 4 1 1 3 1 2 1 1 1 2 1 2 0 1 1 1 1 1 1 1 1 1 2 4 4 1 0 1 1 1 1 1 1 1 1 2 1 1 1 4 0 1 2 1 2 1 1 2 2 1 1 1 1 3 2 2 2 1 1 4 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 1 3 1 3 1 1 0 1 4 1 2 2 1 1 1 2 2 1 1 1 1 3 2 1 2 1 1 2 1 2 1 2 1 0 4 1 2 1 1 1 1 3 1 1 2 0 1 1 1 1 1 3 2 1 2 1 1 0 1 1 3 1 1 2 1 1 1 1 1 1 4 4 1 1 0 1 1 1 2 1 1 1 3 0 2 1 2 1 1 1 1 1", "200\n4 1 1 4 3 1 1 3 1 1 1 4 3 3 3 2 3 3 1 3 3 4 4 2 2 2 3 1 2 2 2 3 1 1 3 2 2 4 1 3 4 3 2 4 2 2 4 2 2 3 4 2 3 2 2 1 2 4 4 2 4 4 2 3 2 4 1 4 2 1 3 4 1 3 1 1 2 1 4 1 3 3 3 4 1 4 4 1 4 4 2 3 1 3 3 2 2 1 4 2 4 4 3 3 3 1 3 4 3 1 1 1 1 4 2 1 2 3 2 2 2 3 2 1 2 1 1 1 2 4 1 3 3 3 2 3 3 2 3 4 4 3 3 4 3 2 1 4 1 4 2 1 3 2 4 4 1 4 1 1 1 3 2 3 4 2 2 4 1 4 4 4 4 3 1 3 1 4 3 2 1 2 1 1 2 4 1 3 3 4 4 2 2 4 4 3 2 1 2 4", "200\n2 1 1 2 2 2 2 1 1 2 2 2 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 2 1 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 2 2 1 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 1 1 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 1 2 2 1 1 2 2 2 1 2 2 0 1 2 1 1 2 2 2 1 2 2 1 1 1 2 2 2 1 2 1 2 1 2 1 1 2 2 1 1 1 1 1 2 2 1 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2 2 1 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 1 1 1 2 1 1 2 2 1 1 2 1 0", "6\n1 1 1 2 2 1", "10\n3 3 1 1 2 1 1 1 2 2", "10\n1 1 1 2 1 2 2 1 2 1", "15\n1 2 2 1 2 3 2 1 2 1 1 1 2 1 1", "13\n2 1 2 2 1 0 1 2 1 1 1 1 2", "3\n4 4 1", "5\n4 4 4 4 1", "1\n1", "4\n1 1 3 4", "7\n1 1 1 3 3 3 3", "6\n2 2 2 4 4 4", "3\n2 3 3", "9\n1 1 1 1 3 3 3 3 3", "3\n1 4 4", "3\n3 3 2", "5\n1 1 1 1 1", "2\n1 1", "3\n1 1 3", "4\n2 2 2 2", "6\n2 2 2 2 2 4", "3\n2 2 4", "2\n2 3", "2\n1 4", "4\n1 1 3 3", "4\n3 3 3 2", "1\n4"], "outputs": ["2", "2", "0", "1", "1", "2", "3", "69", "5", "4", "6", "6", "6", "4", "4", "7", "7", "5", "5", "5", "4", "5", "5", "4", "4", "6", "5", "4", "5", "5", "7", "1", "7", "4", "8", "8", "8", "8", "6", "6", "7", "9", "7", "11", "12", "8", "14", "14", "24", "24", "84", "69", "103", "93", "53", "69", "61", "62", "38", "65", "68", "97", "50", "100", "4", "5", "6", "8", "7", "2", "2", "-1", "2", "2", "2", "2", "3", "2", "2", "-1", "-1", "-1", "4", "4", "2", "-1", "-1", "2", "2", "0"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 1 | codeforces |
|
c7bebd7fa695c6aa741ee0b47480fe3f | Number Busters | Arthur and Alexander are number busters. Today they've got a competition.
Arthur took a group of four integers *a*,<=*b*,<=*w*,<=*x* (0<=β€<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*) and Alexander took integer *Ρ*. Arthur and Alexander use distinct approaches to number bustings. Alexander is just a regular guy. Each second, he subtracts one from his number. In other words, he performs the assignment: *c*<==<=*c*<=-<=1. Arthur is a sophisticated guy. Each second Arthur performs a complex operation, described as follows: if *b*<=β₯<=*x*, perform the assignment *b*<==<=*b*<=-<=*x*, if *b*<=<<=*x*, then perform two consecutive assignments *a*<==<=*a*<=-<=1;Β *b*<==<=*w*<=-<=(*x*<=-<=*b*).
You've got numbers *a*,<=*b*,<=*w*,<=*x*,<=*c*. Determine when Alexander gets ahead of Arthur if both guys start performing the operations at the same time. Assume that Alexander got ahead of Arthur if *c*<=β€<=*a*.
The first line contains integers *a*,<=*b*,<=*w*,<=*x*,<=*c* (1<=β€<=*a*<=β€<=2Β·109,<=1<=β€<=*w*<=β€<=1000,<=0<=β€<=*b*<=<<=*w*,<=0<=<<=*x*<=<<=*w*,<=1<=β€<=*c*<=β€<=2Β·109).
Print a single integer β the minimum time in seconds Alexander needs to get ahead of Arthur. You can prove that the described situation always occurs within the problem's limits.
Sample Input
4 2 3 1 6
4 2 3 1 7
1 2 3 2 6
1 1 2 1 1
Sample Output
2
4
13
0
| {"inputs": ["4 2 3 1 6", "4 2 3 1 7", "1 2 3 2 6", "1 1 2 1 1", "1 0 1000 999 2000000000", "10 1 6 4 20", "10 3 6 5 30", "10 3 5 1 30", "10 32 312 72 1000", "1 102 123 27 2321", "2000000000 159 1000 870 2000000000", "200000000 794 1000 117 2000000000", "20000000 280 1000 25 2000000000", "1999999999 47 1000 527 2000000000", "19999 346 1000 141 2000000000", "1 142 1000 673 2000000000", "1 851 999 721 2000000000", "1 504 998 900 2000000000", "1 250 997 55 2000000000", "1 2 3 2 2000000000", "1 0 2 1 1232132", "1 999 1000 1 2000000000", "1 999 1000 2 2000000000"], "outputs": ["2", "4", "13", "0", "1999999999000", "30", "117", "25", "1287", "2972", "0", "2038505096", "2030769231", "3", "2328265426", "6116207948", "7187050354", "20367346924", "2116772823", "5999999995", "2464262", "2002002001", "2004008015"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 6 | codeforces |
|
c7e27805e59dc67395e03bd861fc9692 | Playing with Permutations | Little Petya likes permutations a lot. Recently his mom has presented him permutation *q*1,<=*q*2,<=...,<=*q**n* of length *n*.
A permutation *a* of length *n* is a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*n*), all integers there are distinct.
There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length *n*. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:
- Before the beginning of the game Petya writes permutation 1,<=2,<=...,<=*n* on the blackboard. After that Petya makes exactly *k* moves, which are described below. - During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2. Let's assume that the board contains permutation *p*1,<=*p*2,<=...,<=*p**n* at the given moment. Then Petya removes the written permutation *p* from the board and writes another one instead: *p**q*1,<=*p**q*2,<=...,<=*p**q**n*. In other words, Petya applies permutation *q* (which he has got from his mother) to permutation *p*. - All actions are similar to point 1, except that Petya writes permutation *t* on the board, such that: *t**q**i*<==<=*p**i* for all *i* from 1 to *n*. In other words, Petya applies a permutation that is inverse to *q* to permutation *p*.
We know that after the *k*-th move the board contained Masha's permutation *s*1,<=*s*2,<=...,<=*s**n*. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the *k*-th move. Note that the game has exactly *k* moves, that is, throughout the game the coin was tossed exactly *k* times.
Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.
The first line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100). The second line contains *n* space-separated integers *q*1,<=*q*2,<=...,<=*q**n* (1<=β€<=*q**i*<=β€<=*n*) β the permutation that Petya's got as a present. The third line contains Masha's permutation *s*, in the similar format.
It is guaranteed that the given sequences *q* and *s* are correct permutations.
If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).
Sample Input
4 1
2 3 4 1
1 2 3 4
4 1
4 3 1 2
3 4 2 1
4 3
4 3 1 2
3 4 2 1
4 2
4 3 1 2
2 1 4 3
4 1
4 3 1 2
2 1 4 3
Sample Output
NO
YES
YES
YES
NO
| {"inputs": ["4 1\n2 3 4 1\n1 2 3 4", "4 1\n4 3 1 2\n3 4 2 1", "4 3\n4 3 1 2\n3 4 2 1", "4 2\n4 3 1 2\n2 1 4 3", "4 1\n4 3 1 2\n2 1 4 3", "4 3\n4 3 1 2\n2 1 4 3", "4 3\n2 1 4 3\n4 3 1 2", "4 1\n2 1 4 3\n2 1 4 3", "4 2\n2 1 4 3\n2 1 4 3", "4 2\n2 3 4 1\n1 2 3 4", "5 3\n2 1 4 3 5\n2 1 4 3 5", "9 10\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9", "8 10\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8", "8 9\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8", "10 10\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "10 9\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "10 100\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "10 99\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9", "9 100\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9", "5 99\n2 1 4 3 5\n2 1 4 3 5", "5 1\n2 1 4 3 5\n2 1 4 3 5", "55 30\n51 43 20 22 50 48 35 6 49 7 52 29 34 45 9 55 47 36 41 54 1 4 39 46 25 26 12 28 14 3 33 23 11 2 53 8 40 32 13 37 19 16 18 42 27 31 17 44 30 24 15 38 10 21 5\n30 31 51 22 43 32 10 38 54 53 44 12 24 14 20 34 47 11 41 15 49 4 5 36 25 26 27 28 29 1 6 55 48 46 7 52 40 16 50 37 19 13 33 39 45 8 17 23 21 18 3 42 35 9 2", "55 30\n32 37 9 26 13 6 44 1 2 38 11 12 36 49 10 46 5 21 43 24 28 31 15 51 55 27 29 18 41 17 20 8 45 16 52 30 39 53 3 35 19 33 50 54 47 34 48 14 4 42 22 40 23 25 7\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", "55 28\n25 13 15 37 5 7 42 9 50 8 14 21 3 30 29 38 1 51 52 20 16 27 6 41 48 4 49 32 2 44 55 10 33 34 54 23 40 26 12 31 39 28 43 46 53 19 22 35 36 47 24 17 11 45 18\n17 29 13 26 5 23 6 10 8 32 53 39 2 11 3 21 52 55 46 20 12 47 36 51 1 38 22 42 15 14 40 28 33 34 48 49 4 16 41 37 24 7 43 30 54 44 50 25 27 9 18 19 45 35 31", "55 28\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26", "55 28\n35 33 46 8 11 13 14 26 42 38 1 7 34 5 2 21 17 45 54 43 4 18 27 50 25 10 29 48 6 16 22 28 55 53 49 41 39 23 40 47 51 37 36 19 9 32 52 12 24 3 20 15 30 44 31\n5 52 24 16 7 27 48 21 18 8 14 28 29 12 47 53 17 31 54 41 30 55 10 35 25 4 38 46 23 34 33 3 15 6 11 20 9 26 42 37 43 45 51 19 22 50 39 32 1 49 36 40 13 44 2", "1 1\n1\n1", "1 2\n1\n1", "2 3\n2 1\n2 1", "3 100\n2 3 1\n2 3 1", "6 3\n2 3 4 5 6 1\n2 3 4 5 6 1", "13 2\n2 3 4 5 6 7 8 9 10 11 12 13 1\n3 4 5 6 7 8 9 10 11 12 13 1 2", "2 99\n2 1\n2 1", "4 3\n2 1 4 3\n2 1 4 3", "4 50\n2 3 4 1\n3 4 1 2", "3 99\n2 3 1\n2 3 1", "2 2\n2 1\n1 2", "10 29\n2 1 4 5 3 7 8 9 10 6\n2 1 5 3 4 8 9 10 6 7", "4 11\n2 3 4 1\n2 3 4 1", "9 3\n2 3 4 5 6 7 8 9 1\n3 4 5 6 7 8 9 1 2"], "outputs": ["NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "NO", "YES", "NO", "YES", "NO", "NO", "YES", "NO", "NO", "YES", "YES", "YES", "NO", "NO", "NO", "YES", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "YES", "YES", "NO"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
c7e518f6e36784b468c9c07c49fe35b5 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba".
If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible.
Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
Sample Input
2
aa
4
koko
5
murat
Sample Output
1
2
0
| {"inputs": ["2\naa", "4\nkoko", "5\nmurat", "6\nacbead", "7\ncdaadad", "25\npeoaicnbisdocqofsqdpgobpn", "25\ntcqpchnqskqjacruoaqilgebu", "13\naebaecedabbee", "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "10\nbababbdaee", "11\ndbadcdbdbca", "12\nacceaabddaaa", "13\nabddfbfaeecfa", "14\neeceecacdbcbbb", "15\ndcbceaaggabaheb", "16\nhgiegfbadgcicbhd", "17\nabhfibbdddfghgfdi", "26\nbbbbbabbaababaaabaaababbaa", "26\nahnxdnbfbcrirerssyzydihuee", "26\nhwqeqhkpxwulbsiwmnlfyhgknc", "26\nrvxmulriorilidecqwmfaemifj", "26\naowpmreooavnmamogdoopuisge", "26\ninimevtuefhvuefirdehmmfudh", "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "27\nqdcfjtblgglnilgassirrjekcjt", "27\nabcdefghijklmnopqrstuvwxyza", "26\nqwertyuiopasdfghjklzxcvbnm", "5\nzzzzz", "27\naaaaaaaaaaaaaaaaabaaaaaaaaa", "1\nq", "27\nqwertyuioplkjhgfdsazxcvbnmm", "9\nxxxyyyzzz", "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk", "27\nqwertyuiopasdfghjklzxcvbnmm", "26\nabcdefghijklmnopqrstuvwxyz", "26\nabcdefghijklmnopqrstuvwxya", "27\nabcdefghijklmnopqrstuvwxyzz", "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "26\nqwertyuioplkjhgfdsazxcvbnm", "10\nzzzzzzzzzz", "1\na", "30\nabcdefghtyabcdefghtyabcdefghty"], "outputs": ["1", "2", "0", "1", "4", "12", "7", "8", "-1", "6", "7", "7", "7", "9", "8", "7", "10", "24", "11", "8", "10", "12", "15", "25", "-1", "-1", "0", "4", "-1", "0", "-1", "6", "-1", "-1", "0", "1", "-1", "25", "0", "9", "0", "-1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 244 | codeforces |
|
c7e74819c84278ce098eec5e10bf0950 | Harry Potter and the History of Magic | The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
The first input line contains an integer *n* (1<=β€<=*n*<=β€<=1000). It represents the number of dates in Harry's notes. Next *n* lines contain the actual dates *y*1, *y*2, ..., *y**n*, each line contains a date. Each date is a four-digit integer (1000<=β€<=*y**i*<=β€<=9999).
Print *n* numbers *z*1, *z*2, ..., *z**n* (1000<=β€<=*z**i*<=β€<=2011). They are Ron's resulting dates. Print each number on a single line. Numbers *z**i* must form the non-decreasing sequence. Each number *z**i* should differ from the corresponding date *y**i* in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
Sample Input
3
1875
1936
1721
4
9999
2000
3000
3011
3
1999
5055
2000
Sample Output
1835
1836
1921
1999
2000
2000
2011
No solution
| {"inputs": ["3\n1875\n1936\n1721", "4\n9999\n2000\n3000\n3011", "3\n1999\n5055\n2000", "2\n2037\n2025", "1\n1234", "1\n9876", "2\n9988\n8899", "3\n1095\n1094\n1095", "5\n5555\n4444\n3333\n2222\n1111", "3\n2010\n2011\n2012", "5\n1901\n1166\n1308\n1037\n1808", "5\n1612\n7835\n8183\n3368\n1685", "10\n1501\n1617\n1368\n1737\n1800\n1272\n1019\n1545\n1035\n1302", "10\n7577\n1411\n1864\n1604\n1589\n1343\n6832\n1648\n1222\n1832", "10\n1110\n1278\n1283\n7758\n1183\n1214\n2970\n1398\n7515\n1005", "15\n2003\n1991\n1741\n1348\n1258\n1964\n1411\n1431\n1780\n1701\n1787\n1094\n1108\n1074\n1942", "20\n1749\n1792\n1703\n1011\n1289\n1066\n1947\n1354\n1693\n1806\n1645\n1292\n1718\n1981\n1197\n1471\n1603\n1325\n1057\n1552", "20\n1639\n1437\n1054\n1010\n1872\n1942\n1315\n1437\n1226\n1893\n1712\n1024\n1410\n1691\n1188\n1056\n1642\n1100\n1893\n1192", "20\n1025\n1000\n1026\n1085\n1354\n1783\n3490\n1512\n1553\n1682\n1695\n1654\n1679\n1304\n1574\n1814\n1854\n1804\n1928\n1949", "20\n1011\n1157\n2181\n6218\n1766\n8319\n1364\n6428\n1476\n4417\n6618\n1629\n1747\n1786\n1787\n2830\n7671\n1953\n1275\n1099", "50\n1230\n6040\n1035\n1973\n9096\n5133\n1146\n1164\n9195\n5211\n6212\n1313\n1953\n1560\n1382\n2324\n1343\n1481\n1555\n1363\n1487\n1414\n1525\n1564\n1561\n9585\n7590\n1663\n5625\n1630\n1630\n3644\n1164\n1665\n7678\n1282\n1626\n1798\n9755\n7801\n8809\n1762\n1867\n1861\n1826\n1809\n8902\n1033\n1774\n9978", "10\n1014\n1140\n1692\n1644\n3647\n1716\n4821\n9839\n2882\n1664", "10\n1075\n1133\n1393\n1350\n1369\n1403\n2643\n1653\n1756\n7811", "10\n6025\n1522\n1835\n2142\n1414\n9547\n1456\n6784\n4984\n3992", "10\n1074\n1547\n1554\n1581\n1170\n8683\n1434\n4750\n1866\n1051", "10\n2008\n3007\n4066\n1017\n1920\n1113\n1317\n4746\n1972\n1598", "10\n1171\n1275\n1680\n7300\n4742\n2517\n7980\n1852\n1993\n5004", "2\n1999\n1000", "2\n2004\n1000", "2\n2099\n1000", "12\n1000\n1002\n1021\n1006\n1001\n1036\n1038\n1039\n1098\n1097\n1029\n1053", "2\n1011\n1000", "3\n1012\n1101\n1000", "3\n2000\n3999\n6011"], "outputs": ["1075\n1136\n1221", "1999\n2000\n2000\n2011", "No solution", "1037\n2005", "1034", "1876", "No solution", "1005\n1014\n1015", "No solution", "1010\n1011\n1012", "1001\n1066\n1108\n1137\n1208", "No solution", "1001\n1017\n1068\n1137\n1200\n1202\n1219\n1245\n1335\n1342", "1577\n1611\n1664\n1664\n1689\n1743\n1832\n1848\n1922\n1932", "No solution", "1003\n1091\n1141\n1148\n1158\n1164\n1211\n1231\n1280\n1301\n1387\n1394\n1408\n1474\n1542", "1049\n1092\n1103\n1111\n1189\n1266\n1347\n1350\n1393\n1406\n1445\n1492\n1518\n1581\n1597\n1671\n1673\n1725\n1757\n1852", "No solution", "1005\n1005\n1006\n1015\n1054\n1083\n1490\n1502\n1503\n1582\n1595\n1604\n1609\n1704\n1774\n1804\n1804\n1804\n1828\n1849", "No solution", "1030\n1040\n1045\n1073\n1096\n1133\n1136\n1144\n1195\n1211\n1212\n1213\n1253\n1260\n1282\n1324\n1333\n1381\n1455\n1463\n1467\n1474\n1505\n1514\n1521\n1585\n1590\n1603\n1625\n1630\n1630\n1644\n1664\n1664\n1678\n1682\n1686\n1698\n1755\n1801\n1809\n1862\n1862\n1862\n1866\n1869\n1902\n1933\n1974\n1978", "1004\n1040\n1092\n1144\n1647\n1706\n1821\n1839\n1882\n1964", "1005\n1033\n1093\n1150\n1169\n1203\n1643\n1643\n1656\n1811", "1025\n1122\n1135\n1142\n1214\n1547\n1556\n1784\n1984\n1992", "1004\n1047\n1054\n1081\n1100\n1683\n1734\n1750\n1766\n1851", "No solution", "No solution", "1099\n1100", "1004\n1004", "1099\n1100", "1000\n1000\n1001\n1001\n1001\n1006\n1008\n1009\n1018\n1027\n1027\n1033", "1001\n1001", "1002\n1100\n1100", "1000\n1999\n2011"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
c81d5e4a49895d98aa46236e26ffe463 | Ladder | You've got an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Also, you've got *m* queries, the *i*-th query is described by two integers *l**i*,<=*r**i*. Numbers *l**i*,<=*r**i* define a subsegment of the original array, that is, the sequence of numbers *a**l**i*,<=*a**l**i*<=+<=1,<=*a**l**i*<=+<=2,<=...,<=*a**r**i*. For each query you should check whether the corresponding segment is a ladder.
A ladder is a sequence of integers *b*1,<=*b*2,<=...,<=*b**k*, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer *x* (1<=β€<=*x*<=β€<=*k*), that the following inequation fulfills: *b*1<=β€<=*b*2<=β€<=...<=β€<=*b**x*<=β₯<=*b**x*<=+<=1<=β₯<=*b**x*<=+<=2...<=β₯<=*b**k*. Note that the non-decreasing and the non-increasing sequences are also considered ladders.
The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=105) β the number of array elements and the number of queries. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109), where number *a**i* stands for the *i*-th array element.
The following *m* lines contain the description of the queries. The *i*-th line contains the description of the *i*-th query, consisting of two integers *l**i*, *r**i* (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*) β the boundaries of the subsegment of the initial array.
The numbers in the lines are separated by single spaces.
Print *m* lines, in the *i*-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the *i*-th query is the ladder, or word "No" (without the quotes) otherwise.
Sample Input
8 6
1 2 1 3 3 5 2 1
1 3
2 3
2 4
8 8
1 4
5 8
Sample Output
Yes
Yes
No
Yes
No
Yes
| {"inputs": ["8 6\n1 2 1 3 3 5 2 1\n1 3\n2 3\n2 4\n8 8\n1 4\n5 8", "1 1\n6\n1 1", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2", "10 10\n4 7 2 6 4 8 1 2 1 9\n6 10\n1 9\n9 9\n2 8\n9 9\n1 1\n8 8\n4 8\n8 8\n7 7", "7 5\n13 13 16 12 16 3 19\n2 7\n3 4\n7 7\n1 2\n4 7", "13 6\n2 6 1 3 5 2 2 1 6 4 2 5 2\n10 13\n4 10\n4 11\n3 5\n9 13\n3 13", "20 20\n17 11 7 4 1 17 7 20 12 12 15 14 7 12 5 13 9 16 7 19\n9 16\n11 11\n18 19\n1 10\n14 19\n6 13\n5 16\n1 17\n5 15\n5 5\n1 13\n20 20\n20 20\n3 18\n16 20\n16 18\n17 18\n14 20\n13 14\n14 15", "100 10\n53 72 2 58 6 29 65 7 43 9 77 10 58 25 49 95 88 11 7 36 51 25 78 20 15 2 69 76 1 66 17 4 91 66 50 66 69 94 74 31 19 96 35 84 83 15 33 73 39 73 29 53 9 47 3 19 4 16 85 6 49 6 57 70 96 19 66 63 86 61 27 21 33 82 13 98 59 48 85 1 13 65 28 34 93 16 88 32 60 50 33 37 36 57 97 28 18 23 30 70\n25 43\n20 70\n13 51\n64 66\n1 60\n17 86\n100 100\n94 98\n51 66\n18 92"], "outputs": ["Yes\nYes\nNo\nYes\nNo\nYes", "Yes", "Yes\nYes\nYes\nYes\nYes", "No\nNo\nYes\nNo\nYes\nYes\nYes\nNo\nYes\nYes", "No\nYes\nYes\nYes\nNo", "No\nNo\nNo\nYes\nNo\nNo", "No\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nYes\nNo\nYes\nYes\nNo\nNo\nNo\nYes\nNo\nYes\nYes", "No\nNo\nNo\nYes\nNo\nNo\nYes\nNo\nNo\nNo"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 5 | codeforces |
|
c8591ab3dbd3135c5318ccccc83231f2 | Yaroslav and Algorithm | Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as *a*. 1. The algorithm consists of some number of command. Π‘ommand number *i* looks either as *s**i* >> *w**i*, or as *s**i* <> *w**i*, where *s**i* and *w**i* are some possibly empty strings of length at most 7, consisting of digits and characters "?". 1. At each iteration, the algorithm looks for a command with the minimum index *i*, such that *s**i* occurs in *a* as a substring. If this command is not found the algorithm terminates. 1. Let's denote the number of the found command as *k*. In string *a* the first occurrence of the string *s**k* is replaced by string *w**k*. If the found command at that had form *s**k* >> *w**k*, then the algorithm continues its execution and proceeds to the next iteration. Otherwise, the algorithm terminates. 1. The value of string *a* after algorithm termination is considered to be the output of the algorithm.
Yaroslav has a set of *n* positive integers, he needs to come up with his favorite algorithm that will increase each of the given numbers by one. More formally, if we consider each number as a string representing the decimal representation of the number, then being run on each of these strings separately, the algorithm should receive the output string that is a recording of the corresponding number increased by one.
Help Yaroslav.
The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in the set. The next *n* lines contains one positive integer each. All the given numbers are less than 1025.
Print the algorithm which can individually increase each number of the set. In the *i*-th line print the command number *i* without spaces.
Your algorithm will be launched for each of these numbers. The answer will be considered correct if: Β
- Each line will a correct algorithm command (see the description in the problem statement). - The number of commands should not exceed 50. - The algorithm will increase each of the given numbers by one. - To get a respond, the algorithm will perform no more than 200 iterations for each number.
Sample Input
2
10
79
Sample Output
10<>11
79<>80
| {"inputs": ["2\n10\n79", "5\n9\n99\n999\n9999\n99999", "5\n99999\n9999\n999\n99\n9", "10\n392\n605\n903\n154\n293\n383\n422\n717\n719\n896", "10\n448\n727\n772\n539\n870\n913\n668\n300\n36\n895", "10\n704\n812\n323\n334\n674\n665\n142\n712\n254\n869", "10\n548\n645\n663\n758\n38\n860\n724\n742\n530\n779", "10\n317\n36\n191\n843\n289\n107\n41\n943\n265\n649", "10\n447\n806\n891\n730\n371\n351\n7\n102\n394\n549", "10\n630\n624\n85\n955\n757\n841\n967\n377\n932\n309", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "1\n9999999999999999999999999"], "outputs": ["10<>11\n79<>80", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 2 | codeforces |
|
c88414bf76eef58c9a7872fa666c98b0 | Little Pigs and Wolves | Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size *n*<=Γ<=*m*. Each cell in this grid was either empty, containing one little pig, or containing one wolf.
A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid of wolves, so there will be at most one wolf adjacent to each little pig. But each wolf may be adjacent to any number of little pigs.
They have been living peacefully for several years. But today the wolves got hungry. One by one, each wolf will choose one of the little pigs adjacent to it (if any), and eats the poor little pig. This process is not repeated. That is, each wolf will get to eat at most one little pig. Once a little pig gets eaten, it disappears and cannot be eaten by any other wolf.
What is the maximum number of little pigs that may be eaten by the wolves?
The first line contains integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=10) which denotes the number of rows and columns in our two-dimensional grid, respectively. Then follow *n* lines containing *m* characters each β that is the grid description. "." means that this cell is empty. "P" means that this cell contains a little pig. "W" means that this cell contains a wolf.
It is guaranteed that there will be at most one wolf adjacent to any little pig.
Print a single number β the maximal number of little pigs that may be eaten by the wolves.
Sample Input
2 3
PPW
W.P
3 3
P.W
.P.
W.P
Sample Output
2
0
| {"inputs": ["2 3\nPPW\nW.P", "3 3\nP.W\n.P.\nW.P", "1 1\nP", "2 6\nWW..WW\n.PPPP.", "6 2\n.W\n.W\n.P\nWP\n.P\nPW", "2 10\nW..WWP.P.P\nW..PP.WWP.", "10 2\nP.\n.W\nPW\n..\nW.\nW.\n..\nP.\nWP\nPP", "3 4\nWPPW\n.P..\nPWW.", "4 3\n.WW\n..P\nP.P\nPWW", "3 10\nWPPP...PP.\n.P...WW..W\n.WWP.PP.PW", "10 3\n...\nPWW\n..P\n..P\nP.P\nWP.\nPPW\n..W\nW..\nWPP", "4 8\n..PW..WW\nWWPP.PP.\nP...PW.P\nP.WW...P", "8 4\nP.WW\nW..P\nP..P\nP.WW\n..P.\nW.P.\nWP.W\nP..P", "1 1\nW", "4 10\n..P.PW.P.P\nP.WP.W..WP\nW..P.P..WP\nW.PWW.P.P.", "10 4\nWPPP\nP.PW\n...W\nW..P\n..W.\n.PP.\nW..P\nW.PW\n..P.\nPPW.", "5 1\n.\nP\n.\n.\nW", "5 10\nP.PPWWP.PP\n.W....P.PP\nPWPP..WW..\n...W..P.P.\nWP.W...PWW", "10 5\n..PWW\nWWP.P\n.PP..\nP..WW\nPW...\n.W..P\n..P.W\nP.PP.\nW..WP\nWPPP.", "6 5\n..WP.\nWP..W\nW.PP.\n.PWW.\nP.PPP\nWP..W", "5 6\nP...PW\n.WWP.W\n.P...P\nWP..W.\nWPPPWP", "6 10\nPPP.WW..PW\n.W.....WP.\n.W.PP..WP.\n.PP..WPP.P\nW.PW.P.PWW\nWP.P..P.P.", "10 6\n.WW.PW\n......\nWP..W.\nPPWP.P\n.PW.PW\nPP.P.W\nP.PWPP\nW..W.P\nWPP..W\n.PWP.W", "7 3\nWPP\nW.P\n...\nPWP\nPW.\n..P\n..W", "3 7\nWP...PW\n.PW.P..\nPPW.PW.", "7 10\nW..W.PWW.P\nW.P.P.PP.W\nP...W.....\nPWPPW..WW.\n....PPP..P\nWP.WPP.P.P\nPP..PWP.WW", "10 7\n.PW..WP\nW...PW.\n..PW...\nPW..PP.\n.W.P.WW\n.P.P...\nP.PPW..\n.PW...P\nW.P.PPP\nW.PPWPP", "8 8\nWP.W...P\nW.P..WW.\nP.W.P.P.\nPPPPPPPP\nWW..WP.W\nP.P.PP..\n..WW..W.\nPP....W.", "8 10\nPWW..P..W.\nPP.PP...W.\nWP..PWW.P.\nP.P.....P.\nPPW.P.P.WW\nPPP.WW.PP.\nW.P....P.P\n..WWPPW..W", "10 8\n.PPW.PWW\nW.PWP.P.\nWP..PP..\n..WP.PPP\n..PP.WW.\n.WP...P.\n..PWW..W\nW.P..PPW\n...P...P\nPWP.WWP.", "9 8\nPP..W..W\n.PP.W..W\n..W...PP\nWP.P.WW.\nW..W.P..\nP.PP..P.\n...PW.PP\n.WPPW..W\nPWP.PPPP", "8 9\nPWWPPW..W\nP.P..WP.P\nW..WPP.PP\nP.PP....W\n.....WWP.\nP.WWP.P..\nW......WW\nPP.PWPP.P", "10 10\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP", "9 10\nW.PPWW..P.\nW.P.....WP\nP..W......\n..P.PP.W.P\n.PW.P..W..\n..P...PPPP\nPPP.W..PPP\nWW.PW...PP\n.PPP..WW.P", "10 9\nWWP.P.WPP\n..PWP.P.W\n....PWP..\nWW...P.WP\n.P.WP..W.\nPP...W.P.\nP.W..WP.W\n.PWPP..P.\n.PPPPPWW.\nPW..W..PP", "10 1\n.\nW\nW\nP\nP\n.\n.\n.\nW\nP", "1 10\nP.PW.PW..W", "10 10\nPWPP...PPW\n.P.W...W..\nW.P.PW....\nP.P.PW..WP\nPP.W.PP.P.\n.P.P..WP.W\n.WW.PPP..P\n..P...PPP.\nP.P..WW..W\n.WWP...PPW", "10 10\n.PW...P.PW\n....W..PPW\nWWP.W..P.P\n.P..PP.P..\n...W...WW.\nPWP..W....\nPW...W..PW\n.P..P.PP.P\nPPPPWP..W.\nPPPPP.W.PP", "10 10\nPP..PPWPPW\nPPPPPPPP..\n.PPPPPPP.P\nPPPPPPPPPP\nPWP.PPP.PP\nPW.PP.PPPP\nPPPPPP.PPW\n..PPWPPP.P\nWPPPPPPPPP\nWP.WPPPWPP", "10 10\nPPPPPPPPPP\nPPPPPPPWPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP", "10 10\nPPPPPPPPWP\nPPPWPPPPPP\nPPPPPPPPPP\nPWWPPWPPPP\nPPPPPPPPPP\nPPPPWPPPPP\nPPPPPPPPPP\nPPPPPPWPPW\nPPPPPPPPPP\nPPWPPPPPWP", "10 10\n.PWWP..W..\n.....W...W\nWP........\nW...WP....\nP.W..P..WW\n..W...WP.P\nW...W.....\n....WP..P.\n.W....W..W\n.W....W..W", "10 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW", "10 10\nW..W..W...\nW..P..W...\n..W.....WW\n....WW....\nWW.....W..\n.........W\n..WW......\n.......WW.\nW.........\nW..WW....W", "10 10\n..P..WWP.W\nPP.WPPPPPP\nWWPP.PPWPP\nPPPPW..PPW\nPP.PW.P.PW\nWW..PPWWP.\n..PW...PP.\n.PPPP.PPPW\nPP.PWP..P.\nPWPPP..WWP", "10 10\n......W...\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n........P.", "10 10\n.P.PPPP..W\nPWW.PPWPPW\n...PPP.P..\nW..P...WP.\n.PPWPP.W..\n...PPWPPPP\nWP..PW..W.\nPPW.....P.\nP.P...PP.W\nWPPWW.PPPW", "10 10\nW...W.....\n..W...WW..\n.........W\n...WW....W\nWW.....W..\n.....W....\n..W.....W.\nW...W.....\nW.....W..W\n..WW..W..W", "10 10\nWW..W...WW\n....W.....\n......WW..\n.W.....P..\n.W...W..WW\n...W......\nW..W......\nW....WW..P\nP.........\n...WW...WW", "10 10\nP.PPP.PP.P\nPPP.PPP.P.\nP.PPPP..PW\nP.PPP.PP.P\nPPPPPP.P.P\nPPPP.PP.P.\n.PPWPPPPP.\nPPP...PPPP\nPPP.PPPP.P\n.WPPPP.P.P", "1 4\nW..P", "10 10\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W\nP.W.P.W.P.\n.W.P.W.P.W", "10 10\nWPPPWPPPWP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nWPPPWPPPWP\nPPPPPPPPPP\nPPPPPPPPPP\nPPPPPPPPPP\nWPPPWPPPWP\nPPPPPPPPPP", "10 10\nPPPPPPPPPP\nWWWWWWWWWW\nWWWWWWWWWW\nPPPPPPPPPP\nPPPPPPPPPP\nWWWWWWWWWW\nWWWWWWWWWW\nPPPPPPPPPP\nPPPPPPPPPP\nWWWWWWWWWW", "4 1\n.\nW\nP\n.", "1 10\nP..W.PPWW.", "10 1\nP\nP\nW\nW\n.\nP\n.\n.\n.\nW", "1 1\n.", "10 10\nPPPWPPPWPP\nPWPPPWPPPP\nPPPPPPPPPP\nWPPWPPWPPW\nPPPPPPPPPP\nPWPPWPPWPP\nPPPPPPPPPP\nPPWPPWPPWP\nPPPPPPPPPP\nWPPWPPWPPW", "10 10\nWPPPPWPPWP\nPPPWPPPPPP\nPWPPPPWPPP\nPPPPWPPPWP\nWPPPPPPPPP\nPPPWPPWPPP\nPWPPPPPPWP\nPPPPWPPPPP\nWPPPPPWPPP\nPPPWPPPPWP", "4 4\n.P..\n.W..\n.P..\n..W.", "4 1\n.\n.\nW\nP", "10 10\nWPPPPWPPWP\nPPPWPPPPPP\nPWPPPPWPPP\nPPPPWPPPWP\nWPPPPPPPPP\nPPPWPPWPPP\nPWPPPPPPWP\nPPPPWPPPPP\nWPPPPPWPPP\nPPPWPPPPWP", "3 3\nPWP\n...\nW..", "2 3\nWWP\nPPP"], "outputs": ["2", "0", "0", "2", "3", "3", "2", "3", "3", "6", "5", "5", "6", "0", "7", "6", "0", "7", "8", "6", "7", "10", "11", "4", "5", "11", "10", "9", "12", "12", "12", "13", "0", "8", "15", "2", "2", "16", "11", "10", "1", "10", "8", "0", "1", "20", "0", "14", "0", "2", "3", "0", "0", "9", "50", "1", "1", "1", "0", "18", "18", "1", "1", "18", "1", "2"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 8 | codeforces |
|
c8a6479bca3e0c6689745a18c57e353e | Tic-tac-toe | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=Γ<=3 grid (one player always draws crosses, the other β noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.
You are given a 3<=Γ<=3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:
- illegal β if the given board layout can't appear during a valid game; - the first player won β if in the given board layout the first player has just won; - the second player won β if in the given board layout the second player has just won; - draw β if the given board layout has just let to a draw.
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
Sample Input
X0X
.0.
.X.
Sample Output
second
| {"inputs": ["X0X\n.0.\n.X.", "0.X\nXX.\n000", "XXX\n.0.\n000", "XXX\n...\n000", "X.X\nX..\n00.", "X.X\nX.0\n0.0", "XXX\nX00\nX00", "000\nX.X\nX.X", "XXX\n0.0\n0..", "X0X\n0X0\nX0X", "XX.\nX0X\nX..", "X0X\n0X0\nX..", "XX0\n0..\n000", "XXX\n0..\n.0.", "XXX\nX..\n.00", "X00\n0.0\nXX0", "0.0\n0XX\n..0", ".00\nX.X\n0..", "..0\n.00\n.0X", "..0\n0..\n00X", "..0\n.XX\nX..", "0.X\n0X0\n.00", "..X\n0X0\n0X.", "0X0\nX..\nX.0", ".0.\nX.X\n0..", "0X0\n00X\n.00", ".0.\n.X0\nX..", "00X\n0.X\n00X", "00X\n0XX\n0X.", "X00\n..0\nX.X", "X00\nX00\n.X0", "X0X\n.X0\n0..", "..0\nXXX\n000", "XXX\n...\n.0.", "0..\n000\nX0X", ".00\n0X.\n0.0", "X..\nX00\n0.0", ".X0\nXX0\nX.X", "X.X\n0.0\nX..", "00X\n.00\n..0", "..0\n0.X\n00.", "0.X\nX0X\n.X0", "0X.\n.X.\n0X0", "00.\nX0.\n..X", "..X\n.00\nXX.", ".00\n.0.\n.X.", "XX0\nX.0\nXX0", "00.\n00.\nX.X", "X00\nX.0\nX.0", "0X.\n0XX\n000", "00.\n00.\n.X.", "X0X\n00.\n0.X", "XX0\nXXX\n0X0", "XX0\n..X\nXX0", "0X.\n..X\nX..", "...\nX0.\nXX0", "..X\n.0.\n0..", "00X\nXX.\n00X", "..0\nXX0\n..X", ".0.\n.00\nX00", "X00\n.XX\n00.", ".00\n0.X\n000", "X0.\n..0\nX.0", "X0X\n.XX\n00.", "0X.\n00.\n.X.", ".0.\n...\n0.0", "..X\nX00\n0.0", "0XX\n...\nX0.", "X.X\n0X.\n.0X", "XX0\nX.X\n00.", ".0X\n.00\n00.", ".XX\nXXX\n0..", "XX0\n.X0\n.0.", "X00\n0.X\nX..", "X..\n.X0\nX0.", ".0X\nX..\nXXX", "X0X\nXXX\nX.X", ".00\nX0.\n00X", "0XX\n.X0\n0.0", "00X\nXXX\n..0", "X0X\n...\n.X.", ".X0\n...\n0X.", "X..\n0X0\nX.0", "..0\n.00\nX.0", ".XX\n.0.\nX0X", "00.\n0XX\n..0", ".0.\n00.\n00.", "00.\n000\nX.X", "0X0\n.X0\n.X.", "00X\n0..\n0..", ".X.\n.X0\nX.0", ".0.\n0X0\nX0X", "...\nX.0\n0..", "..0\nXX.\n00X", "0.X\n.0X\nX00", "..X\n0X.\n.0.", "..X\nX.0\n.0X", "X0.\n.0X\nX0X", "...\n.0.\n.X0", ".X0\nXX0\n0..", "0X.\n...\nX..", ".0.\n0.0\n0.X", "XX.\n.X0\n.0X", ".0.\nX0X\nX00", "0X.\n.X0\nX..", "..0\n0X.\n000", "0.0\nX.X\nXX.", ".X.\n.XX\nX0.", "X.X\n.XX\n0X.", "X.0\n0XX\n..0", "X.0\n0XX\n.X0", "X00\n0XX\n.X0", "X00\n0XX\nXX0", "X00\n0XX\n0X0", "XXX\nXXX\nXXX", "000\n000\n000", "XX0\n00X\nXX0", "X00\n00X\nXX0", "X.0\n00.\nXXX", "X..\nX0.\nX0.", ".XX\n000\nXX0", "X0.\nX.X\nX00", "00X\nX00\nXXX", "XXX\n.00\nX0.", "XX0\n000\nXX.", ".X0\n0.0\nXXX", "0XX\nX00\n0XX", "0XX\nX0X\n00X", "XX0\n0XX\n0X0", "0X0\nX0X\nX0X", "X0X\n0XX\n00X", "0XX\nX0.\nX00", "X.0\n0X0\nXX0", "X0X\nX0X\n0X0", "X.0\n00X\n0XX", "00X\nX0X\n.X0", "X0X\n.00\nX0X", "0XX\nX00\nX0X", "000\nX0X\n.XX", "0.0\n0.X\nXXX", "X.0\nX0.\n0X.", "X0X\n0X0\n..X", "0X0\nXX0\n.X.", "X0.\n.X.\n0.X", "0XX\nX00\n.X0", "0.0\nXXX\n0.X", ".0X\n.X.\nX.0", "XXX\nX.0\n0.0", "XX0\nX..\nX00", "XXX\n00X\n00X", "X00\n00X\nXXX", "0X0\nX0X\n0X.", "XX0\nX00\n0X.", "..X\n0X0\nX..", "X0.\n00.\nXXX", "0.X\nX00\nXX0", "X0.\n0X.\n..X", "00X\nX0.\nXX0", "XX.\n000\n0XX", "..X\n0.X\n.0X", "X00\n.0X\n0XX", "00X\n0X.\nXX.", "X00\nXX.\n0.X", "XXX\n00X\n0X0", "X00\nXX0\n0XX", "0X0\nX00\nXXX", "XX0\nX00\n.X0"], "outputs": ["second", "illegal", "illegal", "illegal", "second", "first", "the first player won", "illegal", "illegal", "the first player won", "illegal", "the first player won", "illegal", "the first player won", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "first", "first", "first", "illegal", "first", "illegal", "the second player won", "first", "illegal", "first", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "second", "illegal", "illegal", "illegal", "illegal", "illegal", "second", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "second", "illegal", "first", "second", "illegal", "illegal", "illegal", "illegal", "second", "illegal", "illegal", "illegal", "second", "illegal", "second", "illegal", "illegal", "first", "first", "second", "illegal", "illegal", "illegal", "illegal", "the first player won", "illegal", "first", "first", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "illegal", "second", "illegal", "illegal", "first", "illegal", "first", "second", "illegal", "illegal", "first", "second", "illegal", "illegal", "illegal", "second", "illegal", "illegal", "illegal", "illegal", "first", "second", "first", "draw", "illegal", "illegal", "illegal", "draw", "illegal", "the first player won", "the first player won", "the second player won", "the first player won", "the first player won", "the first player won", "the second player won", "the first player won", "draw", "the first player won", "the first player won", "draw", "the first player won", "the second player won", "the second player won", "draw", "the second player won", "the second player won", "the second player won", "draw", "the second player won", "the first player won", "the second player won", "the first player won", "the first player won", "the first player won", "the second player won", "the first player won", "the first player won", "the first player won", "the first player won", "the first player won", "the first player won", "the second player won", "the second player won", "the first player won", "the first player won", "the second player won", "the first player won", "the second player won", "the second player won", "the first player won", "the second player won", "the first player won", "the first player won", "the first player won", "the first player won", "the first player won", "the second player won"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 36 | codeforces |
|
c8b59efdcaa0c4ce3da4b4d5ef8753c8 | Death Stars (medium) | The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the solar system that contains the Death Star. However, this time the Empire has hidden the Death Star very well, and Heidi needs to find a place that appears on both maps in order to detect the Death Star.
The first map is an *N*<=Γ<=*M* grid, each cell of which shows some type of cosmic object that is present in the corresponding quadrant of space. The second map is an *M*<=Γ<=*N* grid. Heidi needs to align those two maps in such a way that they overlap over some *M*<=Γ<=*M* section in which all cosmic objects are identical. Help Heidi by identifying where such an *M*<=Γ<=*M* section lies within both maps.
The first line of the input contains two space-separated integers *N* and *M* (1<=β€<=*N*<=β€<=2000, 1<=β€<=*M*<=β€<=200, *M*<=β€<=*N*). The next *N* lines each contain *M* lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next *M* lines each contain *N* characters, describing the second map in the same format.
The only line of the output should contain two space-separated integers *i* and *j*, denoting that the section of size *M*<=Γ<=*M* in the first map that starts at the *i*-th row is equal to the section of the second map that starts at the *j*-th column. Rows and columns are numbered starting from 1.
If there are several possible ways to align the maps, Heidi will be satisfied with any of those. It is guaranteed that a solution exists.
Sample Input
10 5
somer
andom
noise
mayth
eforc
ebewi
thyou
hctwo
again
noise
somermayth
andomeforc
noiseebewi
againthyou
noisehctwo
Sample Output
4 6
| {"inputs": ["10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo", "1 1\ng\ng"], "outputs": ["4 6", "1 1"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 4 | codeforces |
|
c8c6dafa16661bd281ebc6cc95d78b44 | Calendar | BerOilGasDiamondBank has branches in *n* cities, at that *n* is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly *n*<=/<=2 lines of strictly equal length, each of which contains exactly two names and exactly one separator character between them. The name of every city should be used in the calendar exactly once. For historical reasons the symbol *d* is used as the separator of words in the calendar.
The BerOilGasDiamondBank management wants to show that all its branches are equally important to it, that's why the order of their appearance in the calendar should be following: if we "glue"(concatinate) all the *n*<=/<=2 calendar lines (from top to bottom) to make a single line, then the lexicographically minimal line is obtained. No separator character will be used to separate calendar lines. For example, if the lines are "bertown!berville", "newberville!bera", then the resulting line is "bertown!bervillenewberville!bera". In some sense one has to find the lexicographically minimal calendar, where the comparison of calendars happens line by line.
Help BerOilGasDiamondBank and construct the required calendar.
The first line contains an integer *n* (1<=β€<=*n*<=β€<=104, *n* is even) which is the number of branches. Then follow *n* lines which are the names of the cities. All the names consist of lowercase Latin letters; their lengths are no less than 1 and no more than 10 symbols. The next line contains a single symbol *d* (*d* has an ASCII-code from 33 to 126 inclusively, excluding lowercase Latin letters) which is the separator between words in the calendar lines. It is guaranteed that the calendar is possible to be constructed and all the names are different.
Print *n*<=/<=2 lines of similar length which are the required calendar. Every line should contain exactly two words and exactly one separator between them. If there are several solutions, print the lexicographically minimal one. The lexicographical comparison of lines is realized by the "<" operator in the modern programming languages.
Sample Input
4
b
aa
hg
c
.
2
aa
a
!
2
aa
a
|
Sample Output
aa.b
c.hg
a!aa
aa|a
| {"inputs": ["4\nb\naa\nhg\nc\n.", "2\naa\na\n!", "2\naa\na\n|", "4\nqhcivbxotj\nirgxzzxvw\npxdmcyszvk\nyyaevcdal\n~", "8\nbad\nrnnpg\njvcjsxfob\nad\nairnnpg\nqury\njvcjsxfo\nquryai\n6", "6\neh\nehkhdp\ngque\nkhdptvgque\ntvgque\nehkhdptv\n}", "10\ndoecgzo\ntjptpqp\noitegxzwlp\nmwsrwmeyeg\nsmapaqanak\nsmapaqa\nqghrydm\nnakqghrydm\nmedoraus\nnyvgozjdf\n|", "30\nd\nahx\nr\nyd\np\nnhy\na\ntqt\nctp\ntp\nho\nry\nm\ng\ns\nn\nct\nsc\nqr\nrry\ny\nhxm\nqrr\nsct\ncwu\nq\ndk\nrf\nhyd\nnh\n$", "14\neskrrgzq\nxbmynhxfg\nwwffafny\nfaxcnrqkkb\nfaxcnrqk\nkbwwffafny\nmnborvqeae\nranfahuebj\neskrrgzqk\nfaxcnrqkk\ncznaycxe\nrnkgfgyq\nkxbmynhxfg\nbwwffafny\n}", "34\nobseknnnqk\ncvyvvbcgb\nxvmhfzfl\ngrtp\nhbcbhj\nknnnqk\ncyud\nkuaeui\naeui\nlhpdobsekn\ncxmigej\ncvyvvbcgbs\nuwuu\nnnqk\npzcftfrrqp\nnwsyrgqa\nxvmhfzflku\nndcis\nxhaznwqsgk\ncftfrrqp\nkakdggegew\njjzvokhh\nlhpdobse\nxjjzvokhh\nlhpd\nsuwuu\ntuatbwof\nvpsuday\nndcisx\nfggxici\nbfnipz\nknzjio\noirksxb\nbfni\n~", "58\nesgdfmf\nxfkluadj\nqhvh\njwhuyhm\nmgi\nysgc\nvhhenku\npb\ntr\nu\njyrpjnpd\nkluadjo\nopb\ncopb\ngcyhceo\nr\ndjo\nxfklu\neo\nadjo\nfkluadjo\nybe\nwljwh\nqhvhh\nrhgotp\nyhceo\nuyhm\nvdd\nyhm\nysgcyhc\nvddrhg\nril\nwljwhu\nx\nqh\nhceo\ntfcopb\nmgitfc\nvddrh\nmgitfco\nxf\nmgitf\ncyoybe\notp\no\nljwhuyhm\nysgcy\nhhenku\nwl\ngotp\nqhv\nw\nhenku\nenku\nys\nrilcyo\nxfklua\nqhvhhenk\n|", "76\nsd\nwhx\nk\nce\nthm\nbyfi\npju\nbn\ndz\non\nizr\niswh\nl\nwig\ns\nju\nsr\nie\nx\nbth\nzvi\nlxth\ndmzz\nbnqq\nan\ny\ng\nvlj\nc\nhdu\nlx\nwkyd\ndb\nrmr\nrv\nis\ngv\nu\nbyf\nm\nqqb\nwe\nb\ne\nnioo\niek\no\nymk\nifpw\nisw\nammm\ncgk\ncq\nhhv\nq\nat\nd\ney\nn\nrhq\ncecg\nqsh\nak\nhx\nrve\nlaly\ni\nbnsa\nioou\nsk\nkg\nqshs\nwzmn\nupt\nvwvr\nyjj\nN", "10\npo\negf\ne\ngfuzaqsi\nsi\nhpo\nuldiig\negfuzaq\nuldiigh\nuzaqsi\n{", "4\na\nf\nz\nh\n!"], "outputs": ["aa.b\nc.hg", "a!aa", "aa|a", "irgxzzxvw~pxdmcyszvk\nqhcivbxotj~yyaevcdal", "ad6jvcjsxfob\nairnnpg6qury\nbad6jvcjsxfo\nquryai6rnnpg", "ehkhdptv}gque\nehkhdp}tvgque\neh}khdptvgque", "doecgzo|mwsrwmeyeg\nmedoraus|nyvgozjdf\nnakqghrydm|qghrydm\noitegxzwlp|smapaqa\nsmapaqanak|tjptpqp", "a$ahx\nct$dk\nctp$d\ncwu$g\nho$nh\nhxm$m\nhyd$n\nnhy$p\nq$qrr\nqr$rf\nr$rry\nry$sc\ns$sct\ntp$yd\ntqt$y", "bwwffafny}eskrrgzqk\ncznaycxe}faxcnrqkkb\neskrrgzq}kbwwffafny\nfaxcnrqkk}xbmynhxfg\nfaxcnrqk}kxbmynhxfg\nmnborvqeae}rnkgfgyq\nranfahuebj}wwffafny", "aeui~cvyvvbcgbs\nbfnipz~cftfrrqp\nbfni~kakdggegew\ncvyvvbcgb~ndcis\ncxmigej~fggxici\ncyud~lhpdobsekn\ngrtp~obseknnnqk\nhbcbhj~jjzvokhh\nknnnqk~lhpdobse\nknzjio~nwsyrgqa\nkuaeui~tuatbwof\nlhpd~pzcftfrrqp\nndcisx~xvmhfzfl\nnnqk~xhaznwqsgk\noirksxb~vpsuday\nsuwuu~xjjzvokhh\nuwuu~xvmhfzflku", "adjo|henku\ncopb|mgitf\ncyoybe|djo\nenku|qhvhh\neo|esgdfmf\nfkluadjo|o\ngcyhceo|pb\ngotp|vddrh\nhceo|wljwh\nhhenku|mgi\njwhuyhm|qh\njyrpjnpd|r\nkluadjo|tr\nljwhuyhm|u\nmgitfco|wl\nmgitfc|opb\notp|rhgotp\nqhvhhenk|w\nqhvh|xfklu\nqhv|rilcyo\nril|tfcopb\nuyhm|yhceo\nvddrhg|vdd\nvhhenku|xf\nwljwhu|ybe\nxfkluadj|x\nxfklua|yhm\nysgcyhc|ys\nysgcy|ysgc", "akNbth\nammmNb\nanNbyf\natNcgk\nbnNhdu\nbnqqNc\nbnsaNd\nbyfiNe\nceNhhv\ncecgNg\ncqNiek\ndbNisw\ndmzzNi\ndzNizr\neyNpju\ngvNqqb\nhxNqsh\nieNrhq\nifpwNk\nioouNl\nisNrmr\niswhNm\njuNrve\nkgNthm\nlalyNn\nlxNupt\nlxthNo\nniooNq\nonNvlj\nqshsNs\nrvNwhx\nsdNwig\nskNyjj\nsrNymk\nuNvwvr\nweNzvi\nwkydNx\nwzmnNy", "egfuzaq{po\negf{uldiig\ne{gfuzaqsi\nhpo{uzaqsi\nsi{uldiigh", "a!f\nh!z"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 3 | codeforces |
|
c8c6e9cfbda391ccbc4fdded3cf790eb | Laurenty and Shop | A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each row. Laurenty lives in the very last house of the second row. The only shop in town is placed in the first house of the first row.
The first and second rows are separated with the main avenue of the city. The adjacent houses of one row are separated by streets.
Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and cross the street. Different traffic lights can have different waiting time.
The traffic light on the crosswalk from the *j*-th house of the *i*-th row to the (*j*<=+<=1)-th house of the same row has waiting time equal to *a**ij* (1<=β€<=*i*<=β€<=2,<=1<=β€<=*j*<=β€<=*n*<=-<=1). For the traffic light on the crossing from the *j*-th house of one row to the *j*-th house of another row the waiting time equals *b**j* (1<=β€<=*j*<=β€<=*n*). The city doesn't have any other crossings.
The boy wants to get to the store, buy the products and go back. The main avenue of the city is wide enough, so the boy wants to cross it exactly once on the way to the store and exactly once on the way back home. The boy would get bored if he had to walk the same way again, so he wants the way home to be different from the way to the store in at least one crossing.
Help Laurenty determine the minimum total time he needs to wait at the crossroads.
The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=50) β the number of houses in each row.
Each of the next two lines contains *n*<=-<=1 space-separated integer β values *a**ij* (1<=β€<=*a**ij*<=β€<=100).
The last line contains *n* space-separated integers *b**j* (1<=β€<=*b**j*<=β€<=100).
Print a single integer β the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home.
Sample Input
4
1 2 3
3 2 1
3 2 2 3
3
1 2
3 3
2 1 3
2
1
1
1 1
Sample Output
12
11
4
| {"inputs": ["4\n1 2 3\n3 2 1\n3 2 2 3", "3\n1 2\n3 3\n2 1 3", "2\n1\n1\n1 1", "2\n1\n1\n2 1", "3\n1 100\n1 1\n100 100 100", "4\n5 6 7\n8 9 10\n1 8 8 1", "4\n1 2 3\n2 2 3\n2 3 4 3", "48\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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", "48\n2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 1 1 2 1 2 1 2 2 2 2 1 1 2 2 1 1 2 2 1 1 1 2 2 2 2 1 2 1 1 1 1 1\n1 1 1 1 1 1 2 1 2 1 1 2 2 1 2 2 2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2 2 1 1 2 2\n2 1 1 2 1 2 2 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 1 1 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1", "48\n7 3 1 5 3 8 5 6 4 6 8 7 7 6 9 6 4 1 10 3 2 7 6 9 4 9 1 10 6 10 9 1 5 7 8 8 1 1 3 2 2 10 3 7 8 4 7\n4 9 9 4 2 6 2 4 3 9 2 9 7 3 10 1 5 2 2 10 2 1 6 2 10 5 4 6 10 2 5 10 3 1 8 1 2 6 5 2 3 5 8 1 1 8 4\n4 6 4 3 10 4 8 9 1 10 4 2 2 10 4 7 4 5 4 1 10 6 10 8 4 9 4 10 8 5 3 2 10 10 1 10 10 10 6 10 1 7 6 10 5 8 6 4", "48\n47 3 47 2 29 33 39 16 27 34 31 9 2 40 16 28 15 8 37 9 25 36 14 5 24 48 49 26 43 47 46 23 31 27 30 44 34 12 41 21 2 9 27 49 42 27 9\n6 46 24 12 19 6 39 50 37 30 39 44 14 9 39 47 13 13 1 28 36 22 15 28 43 22 2 19 36 48 34 45 44 9 24 28 41 20 39 8 19 23 25 36 37 16 21\n1 35 9 12 25 39 4 27 26 20 15 4 28 30 21 46 34 30 39 22 6 2 31 2 27 44 3 16 47 12 8 32 37 37 47 8 40 2 2 4 33 38 20 25 3 43 45 45", "48\n25 48 43 29 32 6 22 4 33 17 25 2 50 19 39 45 38 8 5 3 23 14 24 31 35 11 20 37 10 13 14 43 18 6 42 44 14 37 29 28 2 20 12 3 30 11 24\n46 14 32 22 21 37 6 42 26 20 10 45 18 20 2 36 41 44 17 17 10 21 45 23 26 41 6 45 16 4 16 48 2 6 26 8 15 1 48 30 20 27 39 24 49 27 36\n10 29 17 21 21 13 27 43 27 3 33 20 22 39 37 21 9 41 7 23 30 17 31 4 45 49 9 43 41 42 38 30 5 49 45 30 43 3 2 43 29 35 11 47 12 12 15 43", "48\n3 42 46 11 44 25 1 42 38 49 14 42 44 10 4 12 2 20 27 44 14 50 33 10 42 27 41 48 26 42 40 18 9 42 1 2 47 8 20 39 45 42 47 8 19 41 32\n36 32 45 48 26 26 38 38 10 7 31 50 23 23 15 17 18 25 24 44 29 12 29 30 16 14 18 20 50 10 3 1 10 7 32 35 43 36 20 40 16 26 12 8 20 38 5\n19 15 33 18 13 29 50 17 28 48 2 36 13 2 12 43 47 6 17 40 8 28 27 15 14 9 10 37 47 25 10 19 11 11 32 3 45 9 11 33 18 35 43 14 13 27 31 34", "48\n26 55 85 65 66 16 31 85 42 78 14 83 42 52 22 32 73 68 30 92 82 18 43 40 43 36 87 77 64 61 46 79 88 86 92 16 28 47 89 34 58 47 76 24 100 27 80\n78 15 79 90 84 28 98 65 60 65 5 65 89 9 72 9 52 52 85 77 66 9 78 76 4 76 3 26 77 91 58 76 76 17 50 83 64 83 40 1 6 61 37 20 55 7 82\n61 19 9 30 98 19 6 4 36 32 54 99 18 46 28 24 12 1 21 15 38 23 39 82 66 92 95 88 65 97 98 4 22 62 96 79 1 8 85 82 38 71 50 82 4 81 58 57", "48\n54 99 43 46 23 80 6 77 2 60 54 26 32 93 45 41 92 23 49 33 31 100 52 19 4 61 4 38 89 27 72 58 79 22 5 20 58 14 30 49 55 69 65 79 97 15 92\n22 41 46 100 36 13 14 61 94 56 26 12 93 12 77 48 34 83 38 66 86 100 16 25 90 91 15 2 12 48 45 25 84 68 98 14 88 22 16 65 53 11 56 54 68 10 39\n74 17 18 74 36 43 75 82 41 15 73 65 17 9 45 95 88 66 93 78 70 88 88 39 35 60 100 70 63 27 75 10 78 78 90 2 57 14 97 29 88 72 45 99 55 46 24 6", "48\n82 39 88 16 77 57 94 61 57 42 93 70 26 26 60 58 14 85 67 85 83 78 57 3 61 69 25 91 97 97 94 24 66 55 10 24 88 85 68 60 52 80 46 33 85 98 3\n58 59 5 18 92 6 46 57 36 47 51 67 5 24 94 83 7 15 3 42 13 98 50 78 76 6 19 77 42 8 28 78 88 22 54 40 12 56 76 37 95 53 74 92 88 22 100\n83 8 34 25 78 60 48 57 42 10 91 35 8 72 69 71 75 31 65 28 2 45 30 87 91 16 1 55 64 56 55 99 46 93 89 24 6 15 97 72 39 73 24 24 14 15 86 47", "48\n2 92 42 94 30 34 65 53 13 24 37 14 17 63 83 79 37 31 93 26 28 60 67 74 22 77 42 52 17 67 20 95 54 91 15 36 18 60 6 62 45 94 31 92 78 82 15\n2 73 72 31 32 92 67 49 75 30 72 22 13 31 3 22 89 50 69 27 33 89 84 26 59 33 34 48 72 64 15 35 4 65 10 70 36 91 48 4 46 2 93 26 1 29 69\n92 2 42 76 12 84 29 19 43 93 10 97 3 31 86 42 51 96 29 87 26 10 79 40 64 79 7 49 66 90 27 93 7 5 83 38 50 21 6 11 85 77 14 41 69 83 52 95", "48\n30 36 96 71 92 99 48 41 72 3 77 61 7 97 98 96 51 93 11 67 76 45 84 57 79 85 63 13 34 38 39 77 53 23 27 32 39 35 43 81 42 13 16 46 75 66 22\n46 91 30 49 88 81 95 45 9 13 93 69 17 42 20 57 79 73 34 16 57 88 18 83 57 44 46 24 2 20 2 80 12 20 66 97 59 34 12 68 92 56 16 64 17 32 34\n97 100 50 24 58 100 99 93 45 88 24 66 93 98 10 17 38 72 98 46 50 83 21 100 32 35 4 34 60 20 7 95 59 12 73 60 2 27 10 55 35 74 9 58 32 48 18 36", "49\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\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\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", "49\n1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 1 2 1 2 1 1 1 1 1 2 2 2 1 2 1 2 2 2 2 2 2 1 2\n2 2 2 1 1 2 1 1 2 2 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 1 1 1 2 1 1 2 2 2 2 2 2 2 2 2 2 2 1 1\n2 2 1 2 2 1 1 1 2 2 1 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 2 2 2 1 2 2 1 1 1 2 1 2 2 2 1 2 2 1 1 1", "49\n5 1 1 2 6 1 10 9 5 5 1 3 6 7 2 3 4 5 7 10 6 7 1 1 5 10 7 5 5 8 6 3 6 5 8 10 4 8 2 1 6 7 3 3 2 6 1 9\n9 7 2 1 10 9 9 4 10 5 9 8 1 7 7 4 6 5 6 4 3 3 3 10 7 8 9 3 6 6 1 8 8 6 7 7 2 5 4 9 5 10 8 5 8 8 4 2\n9 10 9 9 7 3 10 5 7 8 2 6 3 1 7 3 1 3 6 4 4 5 10 2 7 9 7 10 1 2 6 2 2 8 9 9 10 10 8 10 9 7 8 9 3 8 8 3 7", "49\n9 3 7 10 7 8 5 1 10 7 10 2 2 8 7 2 7 9 6 9 7 1 10 2 2 7 8 6 1 8 2 6 3 8 3 6 3 9 4 2 9 1 4 10 1 3 5 9\n7 6 9 7 3 8 5 8 7 6 8 2 2 10 6 2 3 10 1 2 4 7 8 7 2 9 8 7 8 3 6 6 9 8 8 1 5 2 3 2 4 9 6 7 9 3 1 3\n8 1 1 3 10 7 1 2 4 10 10 9 8 1 6 8 3 4 8 7 4 2 10 2 2 4 1 10 3 6 8 3 4 10 1 4 3 4 8 7 1 4 9 3 3 6 2 4 2", "49\n37 26 4 44 25 50 32 7 34 46 49 12 7 41 26 30 17 1 27 50 35 48 42 29 30 21 17 26 16 36 13 22 49 17 38 21 11 9 5 36 44 47 17 36 13 28 29 15\n29 42 5 42 1 43 22 15 34 35 42 13 41 40 2 35 35 35 30 4 35 6 13 19 10 25 4 8 50 14 36 33 45 43 7 1 42 44 10 30 12 48 30 4 28 33 31 43\n27 36 12 11 35 41 36 14 5 39 30 39 46 3 46 10 46 47 2 21 12 43 1 2 26 14 24 19 8 29 16 45 7 19 2 50 49 46 20 45 39 2 35 43 46 4 41 20 20", "49\n11 20 15 26 29 19 7 45 43 28 39 9 47 24 49 1 32 13 45 49 38 26 5 12 41 37 38 33 32 3 39 4 36 3 35 29 45 30 42 43 49 11 10 49 1 16 45 1\n47 9 19 36 32 18 14 49 25 10 47 26 45 49 41 13 9 50 15 31 34 32 7 9 25 37 29 46 2 1 39 48 50 49 33 25 23 12 24 30 11 16 10 20 35 48 40 42\n43 37 4 35 12 8 37 9 19 5 28 2 21 25 26 24 6 6 34 36 12 50 19 8 32 41 18 49 34 26 22 11 5 37 4 2 15 43 13 42 22 23 40 8 16 49 48 31 29", "49\n35 14 11 50 36 42 45 37 49 10 28 49 45 4 14 10 4 13 17 44 28 12 15 41 48 49 5 44 49 23 7 21 36 35 48 30 21 5 26 50 42 30 37 3 2 49 2 45\n19 18 36 37 30 42 10 34 16 27 2 34 6 16 27 45 44 15 50 5 25 20 6 41 48 2 50 30 8 38 46 2 50 5 17 48 16 30 45 23 11 35 44 29 39 13 49 28\n1 39 4 2 36 32 38 42 42 25 19 11 37 50 9 35 28 10 7 47 3 6 42 26 29 27 16 29 11 24 37 26 42 9 11 11 16 36 9 39 17 44 49 26 32 47 1 29 37", "49\n75 32 47 38 45 100 90 67 82 21 4 16 61 69 49 86 95 13 79 70 92 98 92 48 64 1 95 47 90 31 41 12 89 98 22 95 62 54 94 57 43 1 72 8 12 71 98 41\n40 31 71 13 20 32 48 81 17 13 68 6 48 50 44 17 37 8 76 100 57 65 91 15 51 33 83 64 44 66 22 20 44 69 18 32 50 91 43 25 95 42 28 20 16 68 69 70\n52 51 67 93 7 99 59 90 53 66 35 25 8 89 80 64 49 80 87 76 3 38 71 86 88 18 41 91 55 27 12 84 44 81 14 51 35 82 33 93 1 50 62 30 65 60 41 12 85", "49\n99 77 96 11 98 68 62 59 38 4 44 64 51 6 60 3 10 71 97 18 44 75 9 28 25 9 16 4 7 9 63 90 84 31 35 91 96 29 31 60 32 16 57 66 8 55 6 77\n54 98 89 57 9 52 40 15 99 34 23 10 52 59 79 99 72 66 56 24 56 99 48 2 66 45 58 95 1 53 75 36 94 22 45 60 85 63 14 71 41 72 65 37 20 33 82 65\n60 98 13 18 76 61 60 85 63 28 34 84 32 64 60 29 21 39 15 37 53 94 40 41 94 3 39 21 35 17 77 92 42 7 58 53 39 30 79 93 96 68 25 94 31 9 48 26 35", "49\n27 21 50 89 60 45 49 47 1 82 88 11 49 43 87 20 32 26 19 63 93 61 14 11 82 22 33 61 23 76 81 61 79 67 36 99 30 4 69 70 37 38 34 21 1 38 21 21\n72 57 11 8 2 81 44 49 90 55 70 18 63 72 18 73 3 27 41 47 47 33 93 88 85 49 29 29 61 44 32 44 53 78 75 84 24 23 86 18 91 91 3 53 31 2 91 59\n68 49 48 34 49 40 57 76 82 90 32 43 49 31 48 89 89 93 43 9 94 55 97 1 99 89 45 54 7 7 33 15 37 22 10 59 48 73 25 90 87 85 76 63 1 57 55 25 94", "49\n51 65 96 71 14 18 24 31 56 68 27 51 40 81 98 29 55 84 41 4 41 43 28 90 39 38 55 22 35 46 8 31 66 95 48 3 55 79 6 85 30 49 19 75 90 22 29 65\n90 23 25 64 88 1 40 96 77 76 25 22 66 81 53 54 27 92 26 67 46 71 41 74 100 60 5 55 21 31 77 60 95 38 5 8 59 99 50 65 40 10 29 66 38 63 9 53\n84 100 94 58 22 14 58 63 4 60 19 2 73 7 23 58 61 52 67 74 48 3 65 65 1 82 38 84 95 13 1 27 27 44 58 64 48 8 80 86 77 10 35 28 59 98 62 36 53", "49\n75 14 49 48 71 87 8 23 20 50 75 95 30 14 25 50 77 38 59 57 82 21 45 69 100 46 80 83 56 16 34 9 57 32 57 7 89 50 44 96 31 71 12 34 86 10 40 1\n4 82 38 4 73 33 32 30 68 1 80 35 77 98 89 28 62 54 7 95 37 5 94 61 24 76 80 89 65 18 30 64 50 90 40 27 94 59 22 11 94 28 67 82 49 28 14 47\n92 48 28 74 4 88 59 58 23 21 18 73 90 78 7 23 26 14 3 31 90 56 22 20 98 68 36 18 71 3 57 35 21 66 2 70 56 51 18 99 60 27 98 97 29 51 69 38 12", "50\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\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\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", "50\n19 43 43 6 20 8 25 17 19 22 27 30 50 1 16 18 6 48 28 26 15 12 38 6 11 13 4 9 24 47 38 11 27 15 3 7 17 40 32 25 38 21 7 20 23 19 44 13 25\n40 21 42 10 13 34 13 8 39 13 29 43 7 4 22 47 50 45 10 1 43 5 44 11 46 40 24 44 27 9 26 18 24 34 25 49 19 39 24 36 32 6 2 25 33 35 44 6 41\n37 48 32 4 4 41 5 5 30 15 48 11 6 29 5 45 40 13 16 34 19 10 44 24 42 27 3 11 29 8 13 12 25 43 14 36 2 1 48 4 24 42 5 4 22 19 25 21 8 41", "50\n47 38 39 30 32 23 9 5 28 4 17 20 36 31 35 39 29 6 46 20 14 40 47 35 18 21 13 23 40 18 14 32 18 1 16 12 43 11 19 40 31 32 38 16 12 48 9 7 39\n3 35 43 7 33 30 43 49 14 19 37 46 13 39 4 32 16 30 30 42 27 4 39 34 7 7 9 4 10 12 34 15 34 14 49 38 45 3 21 36 47 44 15 29 48 44 35 15 42\n29 14 5 20 5 28 19 21 17 24 14 29 40 40 15 4 26 28 15 37 38 15 38 10 36 11 29 1 43 23 11 27 23 49 23 29 49 47 39 22 33 11 17 45 33 34 34 41 36 32", "50\n30 98 29 67 86 51 9 45 25 85 75 2 91 37 7 29 14 92 46 14 8 4 98 40 62 90 10 41 77 95 16 74 11 4 86 64 66 21 33 99 74 1 29 31 66 20 91 14 15\n28 41 39 21 17 86 46 45 41 52 62 9 93 44 26 18 97 81 57 97 68 65 2 58 30 54 96 68 20 18 78 56 84 43 92 33 66 60 25 97 8 71 55 79 58 33 47 59 63\n90 82 54 3 42 44 43 71 16 93 91 64 43 51 30 3 87 22 60 83 13 24 64 3 9 73 64 24 29 60 63 49 61 63 9 34 85 83 23 80 17 63 53 100 70 20 19 92 66 63", "50\n55 51 83 45 43 16 84 33 80 71 23 46 82 74 34 46 28 43 68 59 60 90 8 23 19 99 32 98 85 61 42 56 6 40 95 72 100 92 71 18 67 24 6 89 55 8 3 50 41\n90 59 91 11 45 78 81 35 58 7 70 12 98 79 8 53 54 66 80 88 6 17 88 73 45 29 26 24 7 71 82 2 44 74 16 76 38 28 72 43 34 5 72 90 23 43 41 76 14\n24 94 31 77 43 27 62 25 7 52 8 39 26 16 94 58 11 83 9 39 77 92 62 96 3 3 36 22 94 71 53 71 13 69 18 77 32 80 14 1 76 23 19 45 77 23 73 66 44 58", "50\n83 91 33 26 97 92 67 25 36 49 62 89 72 7 45 56 54 5 86 100 1 68 17 6 80 11 53 55 9 28 60 26 1 72 7 68 22 67 9 24 68 34 99 44 52 91 14 94 55\n53 81 43 92 66 74 19 18 79 58 83 23 15 14 90 85 16 50 4 87 32 66 74 88 57 96 60 84 94 16 98 53 92 4 36 11 10 96 18 96 57 43 84 94 84 52 35 84 62\n66 14 4 51 44 22 80 94 2 15 32 6 6 81 66 21 43 43 55 88 46 47 63 82 8 36 24 20 54 87 48 94 53 75 18 16 70 77 9 22 31 92 85 93 80 30 32 36 23 45", "50\n3 35 86 4 51 65 51 9 95 31 6 29 66 36 68 77 73 59 4 49 49 50 34 86 37 27 74 16 22 98 91 93 93 9 8 80 52 38 46 35 60 49 84 2 40 79 26 38 74\n16 99 87 89 98 66 53 5 100 9 87 27 24 53 63 8 81 31 28 86 66 15 61 3 69 76 90 32 77 69 6 7 44 30 60 46 70 68 61 46 76 81 5 5 45 61 29 92 9\n4 31 74 17 49 5 95 56 100 82 49 82 89 46 38 79 67 4 4 40 7 11 65 67 2 66 100 14 10 3 46 8 5 81 30 55 24 81 96 39 90 61 47 42 91 36 87 6 6 44", "50\n31 80 40 85 12 38 30 97 51 18 45 81 56 82 91 94 95 13 26 93 98 35 44 69 98 39 83 77 38 68 13 71 80 41 21 80 81 17 88 46 61 67 65 49 29 55 37 74 88\n71 8 42 74 14 70 100 96 25 56 95 38 41 88 45 43 46 16 55 77 100 68 51 30 73 51 25 88 64 26 22 50 4 57 88 85 45 32 11 96 94 19 9 12 10 66 24 8 60\n46 55 55 95 50 96 13 26 91 41 74 53 65 10 11 30 99 77 46 93 71 67 70 44 100 96 73 8 74 14 32 30 62 87 31 3 71 78 82 60 41 26 17 87 98 39 45 80 84 39", "50\n55 24 86 55 70 15 9 89 6 96 85 20 47 11 6 11 18 75 44 34 50 13 53 40 59 48 4 30 54 34 31 46 75 73 26 85 15 92 21 56 58 81 54 3 26 42 53 18 6\n37 22 90 56 39 67 34 83 46 11 7 49 58 27 23 74 100 1 83 76 38 17 41 45 84 26 51 48 47 75 26 4 60 87 7 20 13 3 58 45 13 57 22 23 79 75 18 17 7\n80 71 24 69 51 91 35 92 90 100 90 28 52 71 67 89 31 42 92 53 40 26 75 38 98 30 53 6 34 30 31 52 6 92 43 46 17 75 73 74 4 95 79 35 5 46 4 58 63 26"], "outputs": ["12", "11", "4", "5", "204", "47", "18", "96", "143", "435", "2404", "2243", "2202", "4754", "4262", "4664", "4018", "4492", "98", "136", "476", "523", "2472", "2542", "2612", "4518", "4427", "4541", "4447", "4688", "100", "2189", "2553", "4675", "4620", "4859", "4472", "4804", "3834"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 78 | codeforces |
|
c8ce6e123182a0581d1c615039667841 | Reachability from the Capital | There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.
What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?
New roads will also be one-way.
The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) β the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$.
The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$).
Print one integer β the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0.
Sample Input
9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1
5 4 5
1 2
2 3
3 4
4 1
Sample Output
3
1
| {"inputs": ["9 9 1\n1 2\n1 3\n2 3\n1 5\n5 6\n6 1\n1 8\n9 8\n7 1", "5 4 5\n1 2\n2 3\n3 4\n4 1", "5000 0 2956", "2 0 2", "2 1 1\n1 2", "2 1 2\n1 2", "2 2 2\n1 2\n2 1", "5000 2 238\n3212 238\n238 3212", "5000 2 3810\n3225 1137\n1137 3225", "100 1 30\n69 81", "500 1 209\n183 107", "1000 1 712\n542 916", "39 40 38\n4 8\n24 28\n16 17\n7 25\n4 29\n34 35\n16 24\n21 10\n23 36\n36 14\n28 16\n34 19\n15 21\n22 38\n22 37\n37 27\n28 33\n3 29\n32 22\n12 30\n9 15\n5 19\n23 27\n19 17\n25 17\n24 11\n39 10\n6 20\n16 6\n3 18\n34 21\n15 38\n11 19\n11 3\n32 4\n15 13\n16 11\n11 7\n33 7\n3 33", "8 8 1\n3 2\n3 4\n4 5\n5 3\n6 4\n6 7\n7 8\n8 6", "7 7 1\n2 3\n4 2\n7 4\n5 7\n4 5\n4 6\n6 4", "2333 1 1\n1 2", "7 4 2\n1 2\n3 4\n5 6\n7 1", "1 0 1", "9 9 1\n2 3\n3 4\n4 5\n6 2\n7 6\n8 7\n6 8\n5 9\n9 2", "30 30 29\n29 9\n1 3\n15 5\n14 24\n7 18\n17 12\n5 9\n22 7\n26 20\n7 29\n8 2\n10 12\n17 18\n17 24\n8 12\n23 28\n10 15\n18 2\n29 13\n25 29\n9 2\n7 13\n11 5\n19 26\n10 5\n25 5\n20 10\n5 26\n24 23\n22 8", "30 30 28\n16 28\n5 30\n7 17\n6 1\n12 28\n15 28\n14 30\n25 11\n25 10\n25 8\n12 30\n27 5\n30 10\n22 14\n30 13\n20 27\n15 25\n24 20\n20 15\n1 30\n3 10\n3 4\n3 18\n15 14\n18 22\n20 26\n10 3\n15 27\n23 29\n10 24"], "outputs": ["3", "1", "4999", "1", "0", "1", "0", "4998", "4998", "98", "498", "998", "12", "1", "1", "2331", "3", "0", "1", "13", "9"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 15 | codeforces |
|
c8d0de1d9d6b8ab910755fb08a28ec2a | Bargaining Table | Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room *n*<=Γ<=*m* meters. Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.
The first line contains 2 space-separated numbers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=25) β the office room dimensions. Then there follow *n* lines with *m* characters 0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.
Output one number β the maximum possible perimeter of a bargaining table for Bob's office room.
Sample Input
3 3
000
010
000
5 4
1100
0000
0000
0000
0000
Sample Output
8
16
| {"inputs": ["3 3\n000\n010\n000", "5 4\n1100\n0000\n0000\n0000\n0000", "3 3\n000\n110\n000", "4 2\n00\n10\n11\n00", "3 5\n00001\n00000\n10100", "1 1\n0", "10 11\n11111111101\n01111111111\n11101111111\n01111110111\n11111111111\n11111111111\n11111111111\n11110111111\n11111111111\n11111111111", "7 7\n1110111\n1111111\n1111101\n1111101\n1111111\n1100111\n1011111", "10 10\n0110001011\n0101010111\n0010110100\n1010000110\n0111100011\n1010100100\n1010010000\n1011100011\n1110011000\n0010100101", "20 20\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000\n00000000000000000000", "25 1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n0\n1\n1\n1\n1", "25 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "1 25\n1111111111111111011010110", "1 25\n0000000000000000000000000", "3 4\n1111\n1101\n1011"], "outputs": ["8", "16", "8", "6", "12", "4", "4", "6", "16", "80", "4", "52", "4", "52", "4"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 30 | codeforces |
|
c8d20c0015d8c8ad5f2d84cc1c0da6db | Comments | A rare article in the Internet is posted without a possibility to comment it. On a Polycarp's website each article has comments feed.
Each comment on Polycarp's website is a non-empty string consisting of uppercase and lowercase letters of English alphabet. Comments have tree-like structure, that means each comment except root comments (comments of the highest level) has exactly one parent comment.
When Polycarp wants to save comments to his hard drive he uses the following format. Each comment he writes in the following format:
- at first, the text of the comment is written; - after that the number of comments is written, for which this comment is a parent comment (i.Β e. the number of the replies to this comments); - after that the comments for which this comment is a parent comment are written (the writing of these comments uses the same algorithm).
For example, if the comments look like:
then the first comment is written as "hello,2,ok,0,bye,0", the second is written as "test,0", the third comment is written as "one,1,two,2,a,0,b,0". The whole comments feed is written as: "hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0". For a given comments feed in the format specified above print the comments in a different format:
- at first, print a integer *d*Β β the maximum depth of nesting comments; - after that print *d* lines, the *i*-th of them corresponds to nesting level *i*; - for the *i*-th row print comments of nesting level *i* in the order of their appearance in the Policarp's comments feed, separated by space.
The first line contains non-empty comments feed in the described format. It consists of uppercase and lowercase letters of English alphabet, digits and commas.
It is guaranteed that each comment is a non-empty string consisting of uppercase and lowercase English characters. Each of the number of comments is integer (consisting of at least one digit), and either equals 0 or does not contain leading zeros.
The length of the whole string does not exceed 106. It is guaranteed that given structure of comments is valid.
Print comments in a format that is given in the statement. For each level of nesting, comments should be printed in the order they are given in the input.
Sample Input
hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0
a,5,A,0,a,0,A,0,a,0,A,0
A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0
Sample Output
3
hello test one
ok bye two
a b
2
a
A a A a A
4
A K M
B F H L N O
C D G I P
E J
| {"inputs": ["hello,2,ok,0,bye,0,test,0,one,1,two,2,a,0,b,0", "a,5,A,0,a,0,A,0,a,0,A,0", "A,3,B,2,C,0,D,1,E,0,F,1,G,0,H,1,I,1,J,0,K,1,L,0,M,2,N,0,O,1,P,0", "BA,0", "Tu,1,dU,1,zncD,0", "nwEwA,2,C,1,aG,0,xgv,0", "aa,0", "ab,0,ba,0", "aa,0,ab,1,a,0", "a,0,bb,1,a,1,bb,0", "a,2,b,0,bb,1,a,1,a,0", "bb,0,b,1,a,1,b,1,a,0,b,0", "b,2,b,0,b,0,b,1,b,0,ba,1,b,0", "bb,0,bb,0,b,1,ab,0,b,0,a,2,ab,0,bb,0", "ba,0,aa,1,a,0,bb,1,a,0,a,0,a,0,a,1,a,0", "a,3,aa,0,b,0,b,0,b,0,a,0,b,2,aa,1,a,0,ab,0"], "outputs": ["3\nhello test one \nok bye two \na b ", "2\na \nA a A a A ", "4\nA K M \nB F H L N O \nC D G I P \nE J ", "1\nBA ", "3\nTu \ndU \nzncD ", "3\nnwEwA \nC xgv \naG ", "1\naa ", "1\nab ba ", "2\naa ab \na ", "3\na bb \na \nbb ", "4\na \nb bb \na \na ", "4\nbb b b \na \nb \na ", "2\nb b ba \nb b b b ", "2\nbb bb b b a \nab ab bb ", "2\nba aa bb a a a \na a a ", "3\na b a b \naa b b aa ab \na "]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 23 | codeforces |
|
c9003a393c88d23eebbb3bcb8db3ab73 | BerOS file system | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/'Β β the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
Sample Input
//usr///local//nginx/sbin
Sample Output
/usr/local/nginx/sbin
| {"inputs": ["//usr///local//nginx/sbin", "////a//b/////g", "/a/b/c", "/", "////", "/a//aa/a//", "/aa//b/aa", "////////////////////////////////////////////////////////////////////////////////////////////////////", "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/", "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//", "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/", "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt", "///a//a////a/a//a//a//a/////", "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/", "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "///////////////////////////////////////////////////////////////////////////////////////////////////z", "/z//////////////////////////////////////////////////////////////////////////////////////////////////"], "outputs": ["/usr/local/nginx/sbin", "/a/b/g", "/a/b/c", "/", "/", "/a/aa/a", "/aa/b/aa", "/", "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb", "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game", "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game", "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test", "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt", "/a/a/a/a/a/a/a", "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "/z", "/z"]} | UNKNOWN | [
"PYTHON3"
] | CODEFORCES | 107 | codeforces |
Subsets and Splits