contestId
int64 0
1.01k
| name
stringlengths 2
58
| tags
sequencelengths 0
11
| title
stringclasses 523
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| test_cases
listlengths 0
402
| timeConsumedMillis
int64 0
8k
| memoryConsumedBytes
int64 0
537M
| score
float64 -1
3.99
| __index_level_0__
int64 0
621k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
828 | Black Square | [
"implementation"
] | null | null | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | [
"5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"1 2\nBB\n",
"3 3\nWWW\nWWW\nWWW\n"
] | [
"5\n",
"-1\n",
"1\n"
] | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW",
"output": "5"
},
{
"input": "1 2\nBB",
"output": "-1"
},
{
"input": "3 3\nWWW\nWWW\nWWW",
"output": "1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB",
"output": "-1"
},
{
"input": "1 1\nW",
"output": "1"
},
{
"input": "2 4\nWWWW\nWBWW",
"output": "0"
},
{
"input": "4 5\nWWWWW\nBBWWW\nBBWWW\nWWWWW",
"output": "0"
},
{
"input": "5 4\nWWWW\nWWWW\nWWWB\nWWWW\nWWWW",
"output": "0"
},
{
"input": "10 5\nWWWWB\nWWWWW\nWWWBB\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW",
"output": "12"
},
{
"input": "5 10\nWWWWWWWWWW\nWWWWBWBBWW\nWWWWWWWWWW\nWWWWBWWWWW\nWWWWWWBWWW",
"output": "11"
},
{
"input": "20 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWBBWBWWWW\nWWBWWBWWWW\nWWWWBWWWWW\nWWWWBWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW",
"output": "9"
},
{
"input": "10 20\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWBW\nWWWWWWWWWWWWWWWWWBWW\nWWWWWWWWWWWWWWWWWWWW",
"output": "2"
},
{
"input": "1 1\nW",
"output": "1"
},
{
"input": "1 1\nB",
"output": "0"
},
{
"input": "2 2\nWW\nWW",
"output": "1"
},
{
"input": "2 2\nWW\nWB",
"output": "0"
},
{
"input": "2 2\nWW\nBW",
"output": "0"
},
{
"input": "2 2\nWW\nBB",
"output": "2"
},
{
"input": "2 2\nWB\nWW",
"output": "0"
},
{
"input": "2 2\nWB\nWB",
"output": "2"
},
{
"input": "2 2\nWB\nBW",
"output": "2"
},
{
"input": "2 2\nWB\nBB",
"output": "1"
},
{
"input": "2 2\nBW\nWW",
"output": "0"
},
{
"input": "2 2\nBW\nWB",
"output": "2"
},
{
"input": "2 2\nBW\nBW",
"output": "2"
},
{
"input": "2 2\nBW\nBB",
"output": "1"
},
{
"input": "2 2\nBB\nWW",
"output": "2"
},
{
"input": "2 2\nBB\nWB",
"output": "1"
},
{
"input": "2 2\nBB\nBW",
"output": "1"
},
{
"input": "2 2\nBB\nBB",
"output": "0"
},
{
"input": "1 2\nWW",
"output": "1"
},
{
"input": "1 2\nWB",
"output": "0"
},
{
"input": "1 2\nBW",
"output": "0"
},
{
"input": "2 1\nW\nW",
"output": "1"
},
{
"input": "2 1\nW\nB",
"output": "0"
},
{
"input": "2 1\nB\nW",
"output": "0"
},
{
"input": "2 1\nB\nB",
"output": "-1"
},
{
"input": "20 10\nWWBWWWBBWW\nWWWWWBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWBBBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWBWWWWWBWW\nWBWWBWWWBW\nWWBWBWWWWW\nWWWBWWBBWW\nWWBBWBWBWW\nBBWWWWWBWW\nWWBWWBBBWW\nWWWBWBBWWW\nWWWBBWBWWW\nWWWWWWWWWW\nWWWBWWWWWW\nWWWWWWWWWW",
"output": "-1"
},
{
"input": "10 20\nWWWWWWWBWWWWWWWBWWWB\nWWWBWWWBWWWWWWWWWWWW\nBWWWWWWWWWWWWWWWWWBB\nWWWWWWBWWBWWBWWWBWWW\nWWWWWWWWBWWBWWWBWWWW\nWBWWWWWWWBWWWWWWWWWW\nWWWBWBWWBWWWWWBBWWWB\nWWBBWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWBWWWWBW\nWWWWWWWWWWWWBWWBWWWB",
"output": "-1"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB",
"output": "0"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "-1"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB",
"output": "-1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n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\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW",
"output": "-1"
},
{
"input": "1 5\nWBBWW",
"output": "-1"
},
{
"input": "20 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nB\nB",
"output": "-1"
},
{
"input": "3 3\nWBW\nWBB\nWWW",
"output": "1"
},
{
"input": "4 6\nWWWWWW\nWWWBWW\nWWWWWB\nWWWWWW",
"output": "7"
},
{
"input": "5 5\nWBWBW\nWWWWW\nWWWWW\nWWWWW\nWWWWW",
"output": "7"
},
{
"input": "3 3\nBBB\nBBB\nBBB",
"output": "0"
},
{
"input": "5 5\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW",
"output": "23"
},
{
"input": "5 4\nWWBW\nBWWB\nWWWW\nWWWW\nWWWW",
"output": "13"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWWW\nWBBW",
"output": "12"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWBWW",
"output": "34"
},
{
"input": "3 3\nBBW\nWWW\nBWW",
"output": "6"
},
{
"input": "3 3\nBWB\nWWW\nBWW",
"output": "6"
},
{
"input": "6 6\nWBWWWW\nBWWWBW\nWWWWWW\nWWBWWW\nWWWWWW\nWWWWWW",
"output": "21"
},
{
"input": "3 3\nWWW\nWBW\nWWW",
"output": "0"
},
{
"input": "3 3\nBBB\nWWW\nWWW",
"output": "6"
},
{
"input": "5 5\nWWBWW\nWWBWW\nWBBBW\nWWBWW\nWWBWW",
"output": "18"
},
{
"input": "5 2\nWB\nWB\nWB\nWW\nWW",
"output": "-1"
},
{
"input": "4 7\nBBBBBWW\nWWWWWWW\nWWWWWWW\nWWWWWWW",
"output": "-1"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWW\nWWBB\nWWWW",
"output": "6"
},
{
"input": "4 4\nWWWW\nWBWW\nWWWW\nWWWW",
"output": "0"
},
{
"input": "2 5\nWWWWW\nBBBWW",
"output": "-1"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWBW\nWWWWWW\nWWWWWW\nWWBWWW",
"output": "33"
},
{
"input": "3 3\nWBW\nWBW\nWBW",
"output": "6"
},
{
"input": "3 5\nWWBBB\nBWBBB\nWWBBB",
"output": "-1"
},
{
"input": "5 5\nWWWWB\nBWWWW\nWWWWB\nWWWWW\nWWWWW",
"output": "22"
},
{
"input": "5 5\nBWWWB\nWWWWW\nWWWWW\nWWWWW\nBWWWW",
"output": "22"
},
{
"input": "4 5\nWWWWW\nBWWWW\nBBBWW\nWWWWW",
"output": "5"
},
{
"input": "4 4\nBBBB\nWWWW\nWWWW\nWWWW",
"output": "12"
},
{
"input": "4 6\nWWWWWW\nBWWWWW\nBWWWWW\nBBBBBB",
"output": "-1"
},
{
"input": "3 6\nWWWWWW\nBBBWWW\nWWWWWW",
"output": "6"
},
{
"input": "5 2\nWW\nBW\nBW\nBB\nWW",
"output": "-1"
},
{
"input": "5 5\nWWWWW\nWWWWW\nBBBBB\nWWWWW\nWWWWW",
"output": "20"
},
{
"input": "5 5\nWWWWW\nWWWWW\nWWWWB\nWBWWW\nWWWWW",
"output": "14"
},
{
"input": "1 5\nWWBWW",
"output": "0"
},
{
"input": "1 3\nBBB",
"output": "-1"
},
{
"input": "2 4\nWWBW\nBWBW",
"output": "-1"
},
{
"input": "6 6\nBBBBBB\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW",
"output": "30"
},
{
"input": "4 4\nWWWW\nWWWW\nWWWW\nWWWW",
"output": "1"
},
{
"input": "3 3\nWWW\nWWW\nWWB",
"output": "0"
},
{
"input": "5 1\nB\nB\nW\nW\nW",
"output": "-1"
},
{
"input": "2 3\nWBW\nWBW",
"output": "2"
},
{
"input": "5 2\nWW\nWB\nWB\nWB\nWW",
"output": "-1"
},
{
"input": "5 5\nWWWWW\nBWWWW\nWWWWB\nWWWWW\nWWWWW",
"output": "23"
}
] | 62 | 0 | 0 | 4,864 |
|
797 | Odd sum | [
"dp",
"greedy",
"implementation"
] | null | null | 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. | [
"4\n-2 2 -3 1\n",
"3\n2 -5 -3\n"
] | [
"3\n",
"-1\n"
] | In the first example sum of the second and the fourth elements is 3. | [
{
"input": "4\n-2 2 -3 1",
"output": "3"
},
{
"input": "3\n2 -5 -3",
"output": "-1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046",
"output": "53507"
},
{
"input": "2\n-5439 -6705",
"output": "-5439"
},
{
"input": "2\n2850 6843",
"output": "9693"
},
{
"input": "2\n144 9001",
"output": "9145"
},
{
"input": "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757",
"output": "38951"
},
{
"input": "10\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197",
"output": "18005"
},
{
"input": "10\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097",
"output": "28605"
},
{
"input": "10\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504",
"output": "8463"
},
{
"input": "10\n1184 5136 1654 3254 6576 6900 6468 327 179 7114",
"output": "38613"
},
{
"input": "10\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812",
"output": "-787"
},
{
"input": "3\n1 1 1",
"output": "3"
},
{
"input": "5\n5 5 5 3 -1",
"output": "17"
},
{
"input": "5\n-1 -2 5 3 0",
"output": "7"
},
{
"input": "5\n-3 -2 5 -1 3",
"output": "7"
},
{
"input": "3\n-2 2 -1",
"output": "1"
},
{
"input": "5\n5 0 7 -2 3",
"output": "15"
},
{
"input": "2\n-2 -5",
"output": "-5"
},
{
"input": "3\n-1 -3 0",
"output": "-1"
},
{
"input": "5\n2 -1 0 -3 -2",
"output": "1"
},
{
"input": "4\n2 3 0 5",
"output": "7"
},
{
"input": "5\n-5 3 -2 2 5",
"output": "7"
},
{
"input": "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",
"output": "129433"
},
{
"input": "17\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565",
"output": "43749"
},
{
"input": "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",
"output": "60757"
},
{
"input": "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",
"output": "73781"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n-2 1",
"output": "1"
},
{
"input": "2\n3 2",
"output": "5"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "2\n-1 1",
"output": "1"
},
{
"input": "2\n0 -1",
"output": "-1"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "2\n3 0",
"output": "3"
},
{
"input": "2\n0 -1",
"output": "-1"
},
{
"input": "3\n-3 1 -1",
"output": "1"
},
{
"input": "3\n3 -1 1",
"output": "3"
},
{
"input": "3\n1 3 1",
"output": "5"
},
{
"input": "3\n-1 0 1",
"output": "1"
},
{
"input": "3\n-3 -3 -2",
"output": "-3"
},
{
"input": "3\n3 -1 1",
"output": "3"
},
{
"input": "3\n3 -1 1",
"output": "3"
},
{
"input": "3\n-2 -2 1",
"output": "1"
},
{
"input": "4\n0 -1 -3 -4",
"output": "-1"
},
{
"input": "4\n5 3 2 1",
"output": "11"
},
{
"input": "4\n-1 -2 4 -2",
"output": "3"
},
{
"input": "4\n-1 -3 0 -3",
"output": "-1"
},
{
"input": "4\n1 -4 -3 -4",
"output": "1"
},
{
"input": "4\n5 3 3 4",
"output": "15"
},
{
"input": "4\n-1 -3 -1 2",
"output": "1"
},
{
"input": "4\n3 2 -1 -4",
"output": "5"
},
{
"input": "5\n-5 -4 -3 -5 2",
"output": "-1"
},
{
"input": "5\n5 5 1 2 -2",
"output": "13"
},
{
"input": "5\n-2 -1 -5 -1 4",
"output": "3"
},
{
"input": "5\n-5 -5 -4 4 0",
"output": "-1"
},
{
"input": "5\n2 -3 -1 -4 -5",
"output": "1"
},
{
"input": "5\n4 3 4 2 3",
"output": "13"
},
{
"input": "5\n0 -2 -5 3 3",
"output": "3"
},
{
"input": "5\n4 -2 -2 -3 0",
"output": "1"
},
{
"input": "6\n6 7 -1 1 5 -1",
"output": "19"
},
{
"input": "6\n-1 7 2 -3 -4 -5",
"output": "9"
},
{
"input": "6\n0 -1 -3 -5 2 -6",
"output": "1"
},
{
"input": "6\n4 -1 0 3 6 1",
"output": "13"
},
{
"input": "6\n5 3 3 4 4 -3",
"output": "19"
},
{
"input": "6\n0 -3 5 -4 5 -4",
"output": "7"
},
{
"input": "6\n-5 -3 1 -1 -5 -3",
"output": "1"
},
{
"input": "6\n-2 1 3 -2 7 4",
"output": "15"
},
{
"input": "7\n0 7 6 2 7 0 6",
"output": "21"
},
{
"input": "7\n6 -6 -1 -5 7 1 7",
"output": "21"
},
{
"input": "7\n2 3 -5 0 -4 0 -4",
"output": "5"
},
{
"input": "7\n-6 3 -3 -1 -6 -6 -5",
"output": "3"
},
{
"input": "7\n7 6 3 2 4 2 0",
"output": "21"
},
{
"input": "7\n-2 3 -3 4 4 0 -1",
"output": "11"
},
{
"input": "7\n-5 -7 4 0 5 -3 -5",
"output": "9"
},
{
"input": "7\n-3 -5 -4 1 3 -4 -7",
"output": "3"
},
{
"input": "8\n5 2 4 5 7 -2 7 3",
"output": "33"
},
{
"input": "8\n-8 -3 -1 3 -8 -4 -4 4",
"output": "7"
},
{
"input": "8\n-6 -7 -7 -5 -4 -9 -2 -7",
"output": "-5"
},
{
"input": "8\n8 7 6 8 3 4 8 -2",
"output": "41"
},
{
"input": "8\n6 7 0 -6 6 5 4 7",
"output": "35"
},
{
"input": "8\n0 -7 -5 -5 5 -1 -8 -7",
"output": "5"
},
{
"input": "8\n1 -6 -5 7 -3 -4 2 -2",
"output": "9"
},
{
"input": "8\n1 -8 -6 -6 -6 -7 -5 -1",
"output": "1"
},
{
"input": "9\n-3 -1 4 4 8 -8 -5 9 -2",
"output": "25"
},
{
"input": "9\n-9 -1 3 -2 -7 2 -9 -1 -4",
"output": "5"
},
{
"input": "9\n-6 -9 -3 -8 -5 2 -6 0 -5",
"output": "-1"
},
{
"input": "9\n5 4 3 3 6 7 8 5 9",
"output": "47"
},
{
"input": "9\n5 3 9 1 5 2 -3 7 0",
"output": "31"
},
{
"input": "9\n-3 -9 -1 -7 5 6 -4 -6 -6",
"output": "11"
},
{
"input": "9\n-6 -5 6 -5 -2 0 1 2 -9",
"output": "9"
},
{
"input": "9\n8 3 6 1 -3 5 2 9 1",
"output": "35"
},
{
"input": "10\n-6 -4 -7 -1 -9 -10 -10 1 0 -3",
"output": "1"
},
{
"input": "10\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8",
"output": "-3"
},
{
"input": "10\n8 5 9 2 3 3 -6 1 -1 8",
"output": "39"
},
{
"input": "10\n2 10 -7 6 -1 -1 7 -9 -4 -6",
"output": "25"
},
{
"input": "10\n-10 -2 -2 -1 -10 -7 1 0 -4 -5",
"output": "1"
},
{
"input": "10\n4 3 10 -2 -1 0 10 6 7 0",
"output": "39"
},
{
"input": "10\n-2 6 6 5 0 10 6 7 -1 1",
"output": "41"
},
{
"input": "10\n-10 2 8 -6 -1 -5 1 -10 -10 -1",
"output": "11"
}
] | 124 | 409,600 | 0 | 4,870 |
|
134 | Average Numbers | [
"brute force",
"implementation"
] | null | null | You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). | The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers. | Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*.
If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line. | [
"5\n1 2 3 4 5\n",
"4\n50 50 50 50\n"
] | [
"1\n3 ",
"4\n1 2 3 4 "
] | none | [
{
"input": "5\n1 2 3 4 5",
"output": "1\n3 "
},
{
"input": "4\n50 50 50 50",
"output": "4\n1 2 3 4 "
},
{
"input": "3\n2 3 1",
"output": "1\n1 "
},
{
"input": "2\n4 2",
"output": "0"
},
{
"input": "2\n1 1",
"output": "2\n1 2 "
},
{
"input": "10\n3 3 3 3 3 4 3 3 3 2",
"output": "8\n1 2 3 4 5 7 8 9 "
},
{
"input": "10\n15 7 10 7 7 7 4 4 7 2",
"output": "5\n2 4 5 6 9 "
},
{
"input": "6\n2 2 2 2 2 2",
"output": "6\n1 2 3 4 5 6 "
},
{
"input": "6\n3 3 3 3 3 3",
"output": "6\n1 2 3 4 5 6 "
},
{
"input": "4\n6 6 6 7",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "3\n3 3 4",
"output": "0"
},
{
"input": "5\n7 6 6 6 6",
"output": "0"
},
{
"input": "4\n3 5 5 9",
"output": "0"
},
{
"input": "3\n99 100 99",
"output": "0"
},
{
"input": "4\n5 6 5 5",
"output": "0"
},
{
"input": "6\n1 1 2 1 1 1",
"output": "0"
},
{
"input": "2\n4 5",
"output": "0"
},
{
"input": "4\n1 1 1 2",
"output": "0"
},
{
"input": "3\n1 2 4",
"output": "0"
},
{
"input": "6\n1 1 2 3 3 3",
"output": "0"
},
{
"input": "4\n4 5 5 4",
"output": "0"
},
{
"input": "3\n2 3 5",
"output": "0"
},
{
"input": "3\n2 1 1",
"output": "0"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "4\n1 2 3 4",
"output": "0"
},
{
"input": "5\n1 2 3 4 6",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "4\n3 4 5 1",
"output": "0"
},
{
"input": "3\n2 3 2",
"output": "0"
},
{
"input": "3\n3 4 4",
"output": "0"
},
{
"input": "3\n10 5 7",
"output": "0"
},
{
"input": "3\n5 6 5",
"output": "0"
},
{
"input": "4\n1 2 3 7",
"output": "0"
},
{
"input": "5\n2 2 3 3 3",
"output": "0"
},
{
"input": "3\n4 3 6",
"output": "0"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 "
}
] | 186 | 20,275,200 | 3 | 4,877 |
|
417 | Crash | [
"implementation"
] | null | null | During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer *k*, and each sent solution *A* is characterized by two numbers: *x* — the number of different solutions that are sent before the first solution identical to *A*, and *k* — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same *x*.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with number *x* (*x*<=><=0) of the participant with number *k*, then the testing system has a solution with number *x*<=-<=1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of solutions. Each of the following *n* lines contains two integers separated by space *x* and *k* (0<=≤<=*x*<=≤<=105; 1<=≤<=*k*<=≤<=105) — the number of previous unique solutions and the identifier of the participant. | A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise. | [
"2\n0 1\n1 1\n",
"4\n0 1\n1 2\n1 1\n0 2\n",
"4\n0 1\n1 1\n0 1\n0 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | [
{
"input": "2\n0 1\n1 1",
"output": "YES"
},
{
"input": "4\n0 1\n1 2\n1 1\n0 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 1\n0 1\n0 2",
"output": "YES"
},
{
"input": "4\n7 1\n4 2\n8 2\n1 8",
"output": "NO"
},
{
"input": "2\n0 8\n0 5",
"output": "YES"
},
{
"input": "3\n7 9\n5 8\n8 2",
"output": "NO"
},
{
"input": "1\n0 8",
"output": "YES"
},
{
"input": "5\n8 10\n7 9\n5 6\n5 2\n10 7",
"output": "NO"
},
{
"input": "7\n0 2\n0 3\n0 2\n0 1\n0 10\n1 10\n0 5",
"output": "YES"
},
{
"input": "6\n0 1\n1 1\n2 1\n1 1\n2 1\n4 1",
"output": "NO"
},
{
"input": "4\n0 1\n1 1\n0 1\n2 1",
"output": "YES"
},
{
"input": "6\n0 1\n1 1\n2 1\n3 1\n4 1\n2 1",
"output": "YES"
},
{
"input": "3\n0 1\n0 1\n2 1",
"output": "NO"
},
{
"input": "1\n1 100000",
"output": "NO"
},
{
"input": "2\n99 1\n99 1",
"output": "NO"
},
{
"input": "4\n0 1\n0 2\n1 1\n1 2",
"output": "YES"
},
{
"input": "4\n0 1\n0 2\n1 1\n2 1",
"output": "YES"
},
{
"input": "5\n0 1\n1 1\n2 1\n1 1\n3 1",
"output": "YES"
},
{
"input": "4\n0 1\n1 100000\n1 1\n0 100000",
"output": "NO"
},
{
"input": "5\n0 1\n1 1\n2 1\n3 1\n1 1",
"output": "YES"
},
{
"input": "3\n0 1\n0 2\n1 1",
"output": "YES"
},
{
"input": "5\n0 1\n1 1\n2 1\n0 1\n4 1",
"output": "NO"
},
{
"input": "1\n2 1",
"output": "NO"
},
{
"input": "6\n0 1\n1 1\n2 1\n0 1\n3 1\n4 1",
"output": "YES"
}
] | 46 | 0 | 0 | 4,891 |
|
44 | Anfisa the Monkey | [
"dp"
] | E. Anfisa the Monkey | 2 | 256 | Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble human speech more. Help Anfisa. | The first line contains three integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=200, 1<=≤<=*a*<=≤<=*b*<=≤<=200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols. | Print *k* lines, each of which contains no less than *a* and no more than *b* symbols — Anfisa's text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print "No solution" (without quotes). | [
"3 2 5\nabrakadabra\n",
"4 1 2\nabrakadabra\n"
] | [
"ab\nrakad\nabra\n",
"No solution\n"
] | none | [
{
"input": "3 2 5\nabrakadabra",
"output": "abra\nkada\nbra"
},
{
"input": "4 1 2\nabrakadabra",
"output": "No solution"
},
{
"input": "3 1 2\nvgnfpo",
"output": "vg\nnf\npo"
},
{
"input": "5 3 4\nvrrdnhazvexzjfv",
"output": "vrr\ndnh\nazv\nexz\njfv"
},
{
"input": "10 12 15\nctxgddcfdtllmpuxsjkubuqpldznulsilueakbwwlzgeyudyrjachmitfdcgyzszoejphrubpxzpdtgexaqpxgnoxwfjoikljudnoucirussumyhetfwgaoxfbugfiyjmp",
"output": "ctxgddcfdtllm\npuxsjkubuqpld\nznulsilueakbw\nwlzgeyudyrjac\nhmitfdcgyzszo\nejphrubpxzpdt\ngexaqpxgnoxwf\njoikljudnouci\nrussumyhetfwg\naoxfbugfiyjmp"
},
{
"input": "10 20 30\nbvdqvlxiyogiyimdlwdyxsummjgqxaxsucfeuegleetybsylpnepkqzbutibtlgqrbjbwqnvkysxftmsjqkczoploxoqfuwyrufzwwsxpcqfuckjainpphpbvvtllgkljnnoibsvwnxvaksxjrffakpoxwkhjjjemqatbfkmmlmjhhroetlqvfaumctbicqkuxaabpsh",
"output": "bvdqvlxiyogiyimdlwdy\nxsummjgqxaxsucfeuegl\neetybsylpnepkqzbutib\ntlgqrbjbwqnvkysxftms\njqkczoploxoqfuwyrufz\nwwsxpcqfuckjainpphpb\nvvtllgkljnnoibsvwnxv\naksxjrffakpoxwkhjjje\nmqatbfkmmlmjhhroetlq\nvfaumctbicqkuxaabpsh"
},
{
"input": "10 1 200\nolahgjusovchbowjxtwzvjakrktyjqcgkqmcxknjchzxcvbnkbakwnxdouebomyhjsrfsicmzsgdweabbuipbzrhuqfpynybaohzquqbbsqpoaskccszzsmnfleevtasmjuwqgcqtvysohvyutqipnvuhjumwwyytkeuebbncxsnpavwdkoxyycqrhcidf",
"output": "olahgjusovchbowjxtw\nzvjakrktyjqcgkqmcxk\nnjchzxcvbnkbakwnxdo\nuebomyhjsrfsicmzsgd\nweabbuipbzrhuqfpyny\nbaohzquqbbsqpoaskcc\nszzsmnfleevtasmjuwq\ngcqtvysohvyutqipnvu\nhjumwwyytkeuebbncxs\nnpavwdkoxyycqrhcidf"
},
{
"input": "30 3 6\nebdgacrmhfldirwrcfadurngearrfyjiqkmfqmgzpnzcpprkjyeuuppzvmibzzwyouhxclcgqtjhjmucypqnhdaqke",
"output": "ebd\ngac\nrmh\nfld\nirw\nrcf\nadu\nrng\near\nrfy\njiq\nkmf\nqmg\nzpn\nzcp\nprk\njye\nuup\npzv\nmib\nzzw\nyou\nhxc\nlcg\nqtj\nhjm\nucy\npqn\nhda\nqke"
},
{
"input": "200 1 200\nlycjpjrpkgxrkfvutlcwglghxadttpihmlpphwfttegfpimjxintjdxgqfhzrmxfcfojnxruhyfynlzgpxjeobjyxarsfxaqeogxfzvdlwsimupkwujudtfenryulzvsiazneyibqtweeuxpzrbumqqswjasliyjnnzfzuvthhzcsgfljikkajqkpjftztrzpjneaxqg",
"output": "l\ny\nc\nj\np\nj\nr\np\nk\ng\nx\nr\nk\nf\nv\nu\nt\nl\nc\nw\ng\nl\ng\nh\nx\na\nd\nt\nt\np\ni\nh\nm\nl\np\np\nh\nw\nf\nt\nt\ne\ng\nf\np\ni\nm\nj\nx\ni\nn\nt\nj\nd\nx\ng\nq\nf\nh\nz\nr\nm\nx\nf\nc\nf\no\nj\nn\nx\nr\nu\nh\ny\nf\ny\nn\nl\nz\ng\np\nx\nj\ne\no\nb\nj\ny\nx\na\nr\ns\nf\nx\na\nq\ne\no\ng\nx\nf\nz\nv\nd\nl\nw\ns\ni\nm\nu\np\nk\nw\nu\nj\nu\nd\nt\nf\ne\nn\nr\ny\nu\nl\nz\nv\ns\ni\na\nz\nn\ne\ny\ni\nb\nq\nt\nw\ne\ne\nu\nx\np\nz\nr\nb\nu\nm\nq\nq\ns\nw\nj\na\ns\nl\ni\ny\nj\nn\nn\nz\nf\nz\nu\nv\nt\nh\nh\nz..."
},
{
"input": "15 3 4\naronayjutjdhjcelgexgalnyiruevjelvcvzaihgbwwrc",
"output": "aro\nnay\njut\njdh\njce\nlge\nxga\nlny\niru\nevj\nelv\ncvz\naih\ngbw\nwrc"
},
{
"input": "7 3 4\nweoghhroclwslkfcsszplh",
"output": "weog\nhhr\nocl\nwsl\nkfc\nssz\nplh"
},
{
"input": "12 2 5\nozgscnrddhejkhllokmafxcuorxryhvqnkikauclhfbddfoxl",
"output": "ozgsc\nnrdd\nhejk\nhllo\nkmaf\nxcuo\nrxry\nhvqn\nkika\nuclh\nfbdd\nfoxl"
},
{
"input": "3 1 2\nfpos",
"output": "fp\no\ns"
},
{
"input": "5 3 4\nvrrdnhazvexzjfvs",
"output": "vrrd\nnha\nzve\nxzj\nfvs"
},
{
"input": "10 12 15\nllmpuxsjkubuqpldznulsilueakbwwlzgeyudyrjachmitfdcgyzszoejphrubpxzpdtgexaqpxgnoxwfjoikljudnoucirussumyhetfwgaoxfbugfiyjmpm",
"output": "llmpuxsjkubuq\npldznulsilue\nakbwwlzgeyud\nyrjachmitfdc\ngyzszoejphru\nbpxzpdtgexaq\npxgnoxwfjoik\nljudnoucirus\nsumyhetfwgao\nxfbugfiyjmpm"
},
{
"input": "10 20 30\nvdqvlxiyogiyimdlwdyxsummjgqxaxsucfeuegleetybsylpnepkqzbutibtlgqrbjbwqnvkysxftmsjqkczoploxoqfuwyrufzwwsxpcqfuckjainpphpbvvtllgkljnnoibsvwnxvaksxjrffakpoxwkhjjjemqatbfkmmlmjhhroetlqvfaumctbicqkuxaabpshu",
"output": "vdqvlxiyogiyimdlwdyx\nsummjgqxaxsucfeuegle\netybsylpnepkqzbutibt\nlgqrbjbwqnvkysxftmsj\nqkczoploxoqfuwyrufzw\nwsxpcqfuckjainpphpbv\nvtllgkljnnoibsvwnxva\nksxjrffakpoxwkhjjjem\nqatbfkmmlmjhhroetlqv\nfaumctbicqkuxaabpshu"
},
{
"input": "10 1 200\nolahgjusovchbowjxtwzvjakrktyjqcgkqmcxknjchzxcvbnkbakwnxdouebomyhjsrfsicmzsgdweabbuipbzrhuqfpynybaohzquqbbsqpoaskccszzsmnfleevtasmjuwqgcqtvysohvyutqipnvuhjumwwyytkeuebbncxsnpavwdkoxyycqrhcidfd",
"output": "olahgjusovchbowjxtwz\nvjakrktyjqcgkqmcxkn\njchzxcvbnkbakwnxdou\nebomyhjsrfsicmzsgdw\neabbuipbzrhuqfpynyb\naohzquqbbsqpoaskccs\nzzsmnfleevtasmjuwqg\ncqtvysohvyutqipnvuh\njumwwyytkeuebbncxsn\npavwdkoxyycqrhcidfd"
},
{
"input": "30 3 6\nhstvoyuksbbsbgatemzmvbhbjdmnzpluefgzlcqgfsmkdydadsonaryzskleebdgacrmhfldirwrcfadurngearrfyjiqkmfqmgzpnzcpprkjyeuuppzvmibzzwyouhxclcgqtjhjmucypqnhdaqkea",
"output": "hstvoy\nuksbb\nsbgat\nemzmv\nbhbjd\nmnzpl\nuefgz\nlcqgf\nsmkdy\ndadso\nnaryz\nsklee\nbdgac\nrmhfl\ndirwr\ncfadu\nrngea\nrrfyj\niqkmf\nqmgzp\nnzcpp\nrkjye\nuuppz\nvmibz\nzwyou\nhxclc\ngqtjh\njmucy\npqnhd\naqkea"
},
{
"input": "200 1 200\nycjpjrpkgxrkfvutlcwglghxadttpihmlpphwfttegfpimjxintjdxgqfhzrmxfcfojnxruhyfynlzgpxjeobjyxarsfxaqeogxfzvdlwsimupkwujudtfenryulzvsiazneyibqtweeuxpzrbumqqswjasliyjnnzfzuvthhzcsgfljikkajqkpjftztrzpjneaxqgn",
"output": "y\nc\nj\np\nj\nr\np\nk\ng\nx\nr\nk\nf\nv\nu\nt\nl\nc\nw\ng\nl\ng\nh\nx\na\nd\nt\nt\np\ni\nh\nm\nl\np\np\nh\nw\nf\nt\nt\ne\ng\nf\np\ni\nm\nj\nx\ni\nn\nt\nj\nd\nx\ng\nq\nf\nh\nz\nr\nm\nx\nf\nc\nf\no\nj\nn\nx\nr\nu\nh\ny\nf\ny\nn\nl\nz\ng\np\nx\nj\ne\no\nb\nj\ny\nx\na\nr\ns\nf\nx\na\nq\ne\no\ng\nx\nf\nz\nv\nd\nl\nw\ns\ni\nm\nu\np\nk\nw\nu\nj\nu\nd\nt\nf\ne\nn\nr\ny\nu\nl\nz\nv\ns\ni\na\nz\nn\ne\ny\ni\nb\nq\nt\nw\ne\ne\nu\nx\np\nz\nr\nb\nu\nm\nq\nq\ns\nw\nj\na\ns\nl\ni\ny\nj\nn\nn\nz\nf\nz\nu\nv\nt\nh\nh\nz\nc..."
},
{
"input": "15 3 4\naronayjutjdhjcelgexgalnyiruevjelvcvzaihgbwwrcq",
"output": "aron\nayj\nutj\ndhj\ncel\ngex\ngal\nnyi\nrue\nvje\nlvc\nvza\nihg\nbww\nrcq"
},
{
"input": "200 1 10\njtlykeyfekfrzbpzrhvrxagzywzlsktyzoriwiyatoetikfnhyhlrhuogyhjrxdmlqvpfsmqiqkivtodligzerymdtnqahuprhbfefbjwuavmpkurtfzmwediq",
"output": "No solution"
},
{
"input": "15 2 3\ndplkzxpsxodehcj",
"output": "No solution"
},
{
"input": "100 100 200\nximcxraplfjygtrpxrgjhqagrojixizlogaqfvwvqjaiqvcimelxtmtcsqluvcrdzhihgmwhywfgxmzmikdqdytfrlpzqmvhaexrtflwacsuxhkuzbukgvbdcmwpcvxwznupsmmryxwexlevjlonpipuxjgagxtcgqjdczrnmktgcaagmiumnbcxuafmysisahaqnngc",
"output": "No solution"
},
{
"input": "7 2 3\nggzkinj",
"output": "No solution"
},
{
"input": "17 2 4\npgyujupquzenuldnt",
"output": "No solution"
},
{
"input": "100 1 1\nratfdjnvjmaqgcttjtenixeocyxrtuwhpmejhpxjcqhzjsujqolgcccmvnpoomkrforsdtvhgrcpakibozhgqotcrctzozhggrufk",
"output": "No solution"
},
{
"input": "50 2 3\nizlszyucwjarrrgxzbfzyoxapozmunxuygfjynslcjnxitimjjklucjowtkccbnfsuwtyroxirhxzosbyhvnrroaxryhcvvcjvwfcpvnpdaqwzaiuzycyrtvkgkjfbdqnzrmritaonptpvncdifushrquywzykybhjdplbmsrgibpknxkxkqqywmkeljpxrrmufpkubv",
"output": "No solution"
},
{
"input": "15 2 5\nkddainaviqrjsesrhhdnbuisennbgcxseeyxqtmautpoobtpfigcpgagcixmyzsntmgzwmiczsfp",
"output": "No solution"
},
{
"input": "3 1 50\nhcdonseimahtfmtejvxebwctfkjsrcqjrunpcofrapijvwmmbbbrohkskjomeknlwkdxscybxkintcaynwyjfaghwcofpsbwruzqqqkhyndbxbdpgqokjqitznnnrfuaciriqmyuvktpdxewkrycjefkmjwglhoggpgvztvqndbhiajryxqlrqdb",
"output": "No solution"
},
{
"input": "5 1 30\nxmuatgstrlkerxzezenrauupxiskpfugncncatcgtffhuwzojuapgrevnwzfkpyzbzljbzwvfoeuqhinyravsfqrjmgidjoszvkkhxrdstmydvbertvzltpipmcuakzqflldztzdjqlicvadgpicqio",
"output": "No solution"
},
{
"input": "5 2 3\nabacababb",
"output": "No solution"
},
{
"input": "5 6 6\nabacabadabacabaabacabadabacab",
"output": "No solution"
}
] | 216 | 0 | 3.946 | 4,915 |
660 | Hard Process | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"output": "1\n0 1 0 0 0 1 0"
},
{
"input": "7 2\n1 0 1 1 0 0 0",
"output": "5\n1 1 1 1 1 0 0"
},
{
"input": "7 3\n1 0 0 0 0 1 0",
"output": "4\n1 1 1 1 0 1 0"
},
{
"input": "3 0\n1 1 1",
"output": "3\n1 1 1"
},
{
"input": "1 0\n1",
"output": "1\n1"
},
{
"input": "2 0\n0 1",
"output": "1\n0 1"
},
{
"input": "1 1\n0",
"output": "1\n1"
},
{
"input": "3 1\n0 0 1",
"output": "2\n0 1 1"
},
{
"input": "2 0\n0 0",
"output": "0\n0 0"
},
{
"input": "3 1\n0 0 0",
"output": "1\n1 0 0"
},
{
"input": "7 7\n1 0 1 0 0 0 0",
"output": "7\n1 1 1 1 1 1 1"
},
{
"input": "1 1\n1",
"output": "1\n1"
},
{
"input": "3 0\n0 0 0",
"output": "0\n0 0 0"
},
{
"input": "7 3\n1 1 1 1 1 1 1",
"output": "7\n1 1 1 1 1 1 1"
},
{
"input": "10 3\n0 0 1 0 0 1 0 0 1 1",
"output": "6\n0 0 1 0 1 1 1 1 1 1"
},
{
"input": "2 1\n0 0",
"output": "1\n1 0"
},
{
"input": "2 2\n1 0",
"output": "2\n1 1"
}
] | 467 | 9,830,400 | 3 | 4,919 |
|
329 | Biridian Forest | [
"dfs and similar",
"shortest paths"
] | null | null | You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid consisting of *r* rows and *c* columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.
The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example):
Moves
Breeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions:
- Do nothing. - Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees. - If you are located on the exit cell, you may leave the forest. Only you can perform this move — all other mikemon breeders will never leave the forest by using this type of movement.
After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).
Mikemon battle
If you and *t* (*t*<=><=0) mikemon breeders are located on the same cell, exactly *t* mikemon battles will ensue that time (since you will be battling each of those *t* breeders once). After the battle, all of those *t* breeders will leave the forest to heal their respective mikemons.
Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders — there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).
Your goal
You would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.
Goal of other breeders
Because you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.
Your task
Print the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make. | The first line consists of two integers: *r* and *c* (1<=≤<=*r*,<=*c*<=≤<=1000), denoting the number of rows and the number of columns in Biridian Forest. The next *r* rows will each depict a row of the map, where each character represents the content of a single cell:
- 'T': A cell occupied by a tree. - 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map. - 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map. - A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder).
It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves. | A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number. | [
"5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000\n",
"1 4\nSE23\n"
] | [
"3\n",
"2\n"
] | The following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog:
The three breeders on the left side of the map will be able to battle you — the lone breeder can simply stay in his place until you come while the other two breeders can move to where the lone breeder is and stay there until you come. The three breeders on the right does not have a way to battle you, so they will stay in their place.
For the second example, you should post this sequence in your Blog:
Here's what happens. First, you move one cell to the right.
Then, the two breeders directly to the right of the exit will simultaneously move to the left. The other three breeder cannot battle you so they will do nothing.
You end up in the same cell with 2 breeders, so 2 mikemon battles are conducted. After those battles, all of your opponents leave the forest.
Finally, you make another move by leaving the forest. | [
{
"input": "5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000",
"output": "3"
},
{
"input": "1 4\nSE23",
"output": "2"
},
{
"input": "3 3\n000\nS0E\n000",
"output": "0"
},
{
"input": "5 5\nS9999\nTTTT9\n99999\n9TTTT\n9999E",
"output": "135"
},
{
"input": "1 10\n9T9TSET9T9",
"output": "0"
},
{
"input": "10 1\nS\n9\n9\n9\n9\nE\n9\n9\n9\n9",
"output": "72"
},
{
"input": "4 3\nS01\n234\n567\n89E",
"output": "45"
},
{
"input": "2 2\nE9\nS4",
"output": "9"
},
{
"input": "3 3\n920\n752\nE8S",
"output": "29"
},
{
"input": "5 1\n9\nT\nE\n6\nS",
"output": "6"
},
{
"input": "1 5\n78S6E",
"output": "6"
},
{
"input": "9 8\n38030772\n697T83S2\n8T626740\n86T02062\n05402864\nT7504180\n3T368E08\n90637446\n12709560",
"output": "194"
},
{
"input": "3 5\n00000\nS0E01\n00000",
"output": "1"
}
] | 92 | 102,400 | -1 | 4,930 |
|
0 | none | [
"none"
] | null | null | Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*.
Spring is starting and the Winter sleep is over for bears. Limak has just woken up and logged in. All his friends still sleep and thus none of them is online. Some (maybe all) of them will appear online in the next hours, one at a time.
The system displays friends who are online. On the screen there is space to display at most *k* friends. If there are more than *k* friends online then the system displays only *k* best of them — those with biggest *t**i*.
Your task is to handle queries of two types:
- "1 id" — Friend *id* becomes online. It's guaranteed that he wasn't online before. - "2 id" — Check whether friend *id* is displayed by the system. Print "YES" or "NO" in a separate line.
Are you able to help Limak and answer all queries of the second type? | The first line contains three integers *n*, *k* and *q* (1<=≤<=*n*,<=*q*<=≤<=150<=000,<=1<=≤<=*k*<=≤<=*min*(6,<=*n*)) — the number of friends, the maximum number of displayed online friends and the number of queries, respectively.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=109) where *t**i* describes how good is Limak's relation with the *i*-th friend.
The *i*-th of the following *q* lines contains two integers *type**i* and *id**i* (1<=≤<=*type**i*<=≤<=2,<=1<=≤<=*id**i*<=≤<=*n*) — the *i*-th query. If *type**i*<==<=1 then a friend *id**i* becomes online. If *type**i*<==<=2 then you should check whether a friend *id**i* is displayed.
It's guaranteed that no two queries of the first type will have the same *id**i* becuase one friend can't become online twice. Also, it's guaranteed that at least one query will be of the second type (*type**i*<==<=2) so the output won't be empty. | For each query of the second type print one line with the answer — "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise. | [
"4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n",
"6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n"
] | [
"NO\nYES\nNO\nYES\nYES\n",
"NO\nYES\nNO\nYES\n"
] | In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries:
1. "1 3" — Friend 3 becomes online. 1. "2 4" — We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3" — We should check if friend 3 is displayed. Right now he is the only friend online and the system displays him. We should print "YES". 1. "1 1" — Friend 1 becomes online. The system now displays both friend 1 and friend 3. 1. "1 2" — Friend 2 becomes online. There are 3 friends online now but we were given *k* = 2 so only two friends can be displayed. Limak has worse relation with friend 1 than with other two online friends (*t*<sub class="lower-index">1</sub> < *t*<sub class="lower-index">2</sub>, *t*<sub class="lower-index">3</sub>) so friend 1 won't be displayed 1. "2 1" — Print "NO". 1. "2 2" — Print "YES". 1. "2 3" — Print "YES". | [
{
"input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3",
"output": "NO\nYES\nNO\nYES\nYES"
},
{
"input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3",
"output": "NO\nYES\nNO\nYES"
},
{
"input": "6 3 10\n62417580 78150524 410053501 582708235 630200761 760672946\n2 2\n1 5\n1 2\n1 4\n2 4\n2 1\n2 1\n1 6\n2 5\n2 6",
"output": "NO\nYES\nNO\nNO\nYES\nYES"
},
{
"input": "20 2 15\n12698951 55128070 116962690 156763505 188535242 194018601 269939893 428710623 442819431 483000923 516768937 552903993 633087286 656092270 671535141 714291344 717660646 846508634 879748146 937368929\n2 7\n1 2\n2 4\n1 19\n1 12\n1 5\n2 18\n2 11\n1 16\n2 1\n2 3\n2 19\n1 17\n2 9\n2 6",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO"
},
{
"input": "1 1 1\n1000000000\n2 1",
"output": "NO"
}
] | 186 | 23,142,400 | 0 | 4,936 |
|
0 | none | [
"none"
] | null | null | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, the line of performers can be represented by a sequence *a*1,<=*a*2,<=...,<=*a**n*.
Little Tommy is among them. He would like to choose an interval [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), then reverse *a**l*,<=*a**l*<=+<=1,<=...,<=*a**r* so that the length of the longest non-decreasing subsequence of the new sequence is maximum.
A non-decreasing subsequence is a sequence of indices *p*1,<=*p*2,<=...,<=*p**k*, such that *p*1<=<<=*p*2<=<<=...<=<<=*p**k* and *a**p*1<=≤<=*a**p*2<=≤<=...<=≤<=*a**p**k*. The length of the subsequence is *k*. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence.
The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*). | Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. | [
"4\n1 2 1 2\n",
"10\n1 1 2 2 2 1 1 2 2 1\n"
] | [
"4\n",
"9\n"
] | In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4.
In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. | [
{
"input": "4\n1 2 1 2",
"output": "4"
},
{
"input": "10\n1 1 2 2 2 1 1 2 2 1",
"output": "9"
},
{
"input": "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 2 1 2 2 1 1 1 2 2 2 2 1 2 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 2 2 2 1 2 1 2 1 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 1 1 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 1 2 1 2 2 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 2 2",
"output": "116"
},
{
"input": "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",
"output": "200"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "2\n2 1",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "3"
},
{
"input": "3\n1 2 1",
"output": "3"
},
{
"input": "100\n1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 2 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "89"
},
{
"input": "100\n1 2 1 2 2 2 1 1 2 2 2 1 2 2 2 1 1 1 1 2 2 2 1 1 1 1 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 2 2 1 2 2 1 1 1 1 2 2 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 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 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 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "191"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 1",
"output": "10"
},
{
"input": "6\n2 2 2 1 1 1",
"output": "6"
}
] | 155 | 12,390,400 | -1 | 4,939 |
|
90 | African Crossword | [
"implementation",
"strings"
] | B. African Crossword | 2 | 256 | An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a letter should only be crossed out if and only if the corresponding column or row contains at least one more letter that is exactly the same. Besides, all such letters are crossed out simultaneously.
When all repeated letters have been crossed out, we should write the remaining letters in a string. The letters that occupy a higher position follow before the letters that occupy a lower position. If the letters are located in one row, then the letter to the left goes first. The resulting word is the answer to the problem.
You are suggested to solve an African crossword and print the word encrypted there. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid. | Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. | [
"3 3\ncba\nbcd\ncbc\n",
"5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n"
] | [
"abcd",
"codeforces"
] | none | [
{
"input": "3 3\ncba\nbcd\ncbc",
"output": "abcd"
},
{
"input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf",
"output": "codeforces"
},
{
"input": "4 4\nusah\nusha\nhasu\nsuha",
"output": "ahhasusu"
},
{
"input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz",
"output": "bcdeghjlmnprsuvwz"
},
{
"input": "10 10\naaaaaaaaaa\nbccceeeeee\ncdfffffffe\ncdfiiiiile\ncdfjjjjile\ndddddddile\nedfkkkkile\nedddddddde\ngggggggggg\nhhhhhhhhhe",
"output": "b"
},
{
"input": "15 3\njhg\njkn\njui\nfth\noij\nyuf\nyfb\nugd\nhgd\noih\nhvc\nugg\nyvv\ntdg\nhgf",
"output": "hkniftjfbctd"
},
{
"input": "17 19\nbmzbmweyydiadtlcoue\ngmdbyfwurpwbpuvhifn\nuapwyndmhtqvkgkbhty\ntszotwflegsjzzszfwt\nzfpnscguemwrczqxyci\nvdqnkypnxnnpmuduhzn\noaquudhavrncwfwujpc\nmiggjmcmkkbnjfeodxk\ngjgwxtrxingiqquhuwq\nhdswxxrxuzzfhkplwun\nfagppcoildagktgdarv\neusjuqfistulgbglwmf\ngzrnyxryetwzhlnfewc\nzmnoozlqatugmdjwgzc\nfabbkoxyjxkatjmpprs\nwkdkobdagwdwxsufees\nrvncbszcepigpbzuzoo",
"output": "lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs"
},
{
"input": "1 1\na",
"output": "a"
},
{
"input": "2 2\nzx\nxz",
"output": "zxxz"
},
{
"input": "1 2\nfg",
"output": "fg"
},
{
"input": "2 1\nh\nj",
"output": "hj"
},
{
"input": "1 3\niji",
"output": "j"
},
{
"input": "3 1\nk\np\nk",
"output": "p"
},
{
"input": "2 3\nmhw\nbfq",
"output": "mhwbfq"
},
{
"input": "3 2\nxe\ner\nwb",
"output": "xeerwb"
},
{
"input": "3 7\nnutuvjg\ntgqutfn\nyfjeiot",
"output": "ntvjggqfnyfjeiot"
},
{
"input": "5 4\nuzvs\namfz\nwypl\nxizp\nfhmf",
"output": "uzvsamfzwyplxizphm"
},
{
"input": "8 9\ntjqrtgrem\nrwjcfuoey\nywrjgpzca\nwabzggojv\najqmmcclh\nozilebskd\nqmgnbmtcq\nwakptzkjr",
"output": "mrjcfuyyrjpzabzvalhozilebskdgnbtpzr"
},
{
"input": "9 3\njel\njws\ntab\nvyo\nkgm\npls\nabq\nbjx\nljt",
"output": "elwtabvyokgmplabqbxlt"
},
{
"input": "7 6\neklgxi\nxmpzgf\nxvwcmr\nrqssed\nouiqpt\ndueiok\nbbuorv",
"output": "eklgximpzgfvwcmrrqedoiqptdeiokuorv"
},
{
"input": "14 27\npzoshpvvjdpmwfoeojapmkxjrnk\nitoojpcorxjdxrwyewtmmlhjxhx\ndoyopbwusgsmephixzcilxpskxh\nygpvepeuxjbnezdrnjfwdhjwjka\nrfjlbypoalbtjwrpjxzenmeipfg\nkhjhrtktcnajrnbefhpavxxfnlx\nvwlwumqpfegjgvoezevqsolaqhh\npdrvrtzqsoujqfeitkqgtxwckrl\nxtepjflcxcrfomhqimhimnzfxzg\nwhkfkfvvjwkmwhfgeovwowshyhw\nolchgmhiehumivswgtfyhqfagbp\ntdudrkttpkryvaiepsijuejqvmq\nmuratfqqdbfpefmhjzercortroh\nwxkebkzchupxumfizftgqvuwgau",
"output": "zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva"
},
{
"input": "1 100\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu",
"output": "g"
},
{
"input": "2 100\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg",
"output": "rbe"
},
{
"input": "3 100\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo",
"output": "blkck"
},
{
"input": "100 1\na\nm\nn\nh\na\nx\nt\na\no\np\nj\nz\nr\nk\nq\nl\nb\nr\no\ni\ny\ni\np\ni\nt\nn\nd\nc\nz\np\nu\nn\nw\ny\ng\ns\nt\nm\nz\ne\nv\ng\ny\nj\nd\nz\ny\na\nn\nx\nk\nd\nq\nn\nv\ng\nk\ni\nk\nf\na\nb\nw\no\nu\nw\nk\nk\nb\nz\nu\ni\nu\nv\ng\nv\nx\ng\np\ni\nz\ns\nv\nq\ns\nb\nw\ne\np\nk\nt\np\nd\nr\ng\nd\nk\nm\nf\nd",
"output": "hlc"
},
{
"input": "100 2\nhd\ngx\nmz\nbq\nof\nst\nzc\ndg\nth\nba\new\nbw\noc\now\nvh\nqp\nin\neh\npj\nat\nnn\nbr\nij\nco\nlv\nsa\ntb\nbl\nsr\nxa\nbz\nrp\nsz\noi\nec\npw\nhf\njm\nwu\nhq\nra\npv\ntc\ngv\nik\nux\ntz\nbf\nty\ndk\nwo\nor\nza\nkv\nqt\nfa\njy\nbk\nuv\ngk\ncz\nds\nie\noq\nmf\nxn\nql\nxs\nfb\niv\ncj\nkn\nns\nlg\nji\nha\naj\ndg\nfj\nut\nsg\nju\noc\nov\nhe\nnw\nbl\nlp\nbx\nnm\nyq\ncw\nov\nxk\npg\noh\npl\nuo\ngf\nul",
"output": "dvy"
},
{
"input": "100 3\nruy\nmye\njgp\nscn\nktq\nalx\nmvk\nlpm\nkry\norb\nmpu\nzcv\nlge\nkft\ndzp\ntfb\nhqz\nuur\nhry\nzjx\ncuo\nqqc\ntih\nenj\nvnp\nbwi\nzzh\nhkc\nwdr\nldh\nvel\nizj\nfhb\nqrn\nqpp\nvzs\nlhg\nkee\nlbq\nzhy\nwcl\nyaa\nton\nfly\nkyw\nept\ngwq\ncoe\nopd\neez\nnmx\nnjg\nwhy\nvel\nafq\nnbq\nulx\noxs\nbbo\nyhx\nfmz\nnrg\nnfm\njek\nbeu\ntya\nxgs\nsgg\nnkq\nbbv\nwkd\ntns\nfdt\neox\nobc\neab\nkkj\noub\ngji\nrht\nozv\nysk\nsbt\nflf\npbu\nlxb\npzs\nrzh\ncea\nkmi\nuea\nncc\nzng\nvkn\njhn\njqw\nlqc\nmbt\nlov\ngam",
"output": "tvdiixs"
}
] | 122 | 2,867,200 | -1 | 4,952 |
43 | Letter | [
"implementation",
"strings"
] | B. Letter | 2 | 256 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help him; find out if he will manage to compose the needed text. | The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces out of the heading. | If Vasya can write the given anonymous letter, print YES, otherwise print NO | [
"Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n",
"Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"abcdefg hijk\nk j i h g f e d c b a\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | none | [
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog",
"output": "NO"
},
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "YES"
},
{
"input": "Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "NO"
},
{
"input": "abcdefg hijk\nk j i h g f e d c b a",
"output": "YES"
},
{
"input": "HpOKgo\neAtAVB",
"output": "NO"
},
{
"input": "GRZGc\nLPzD",
"output": "NO"
},
{
"input": "GtPXu\nd",
"output": "NO"
},
{
"input": "FVF\nr ",
"output": "NO"
},
{
"input": "HpOKgo\nogK",
"output": "YES"
},
{
"input": "GRZGc\nZG",
"output": "YES"
},
{
"input": "HpOKgoueAtAVBdGffvQheJDejNDHhhwyKJisugiRAH OseK yUwqPPNuThUxTfthqIUeb wS jChGOdFDarNrKRT MlwKecxWNoKEeD BbiHAruE XMlvKYVsJGPP\nAHN XvoaNwV AVBKwKjr u U K wKE D K Jy KiHsR h d W Js IHyMPK Br iSqe E fDA g H",
"output": "YES"
},
{
"input": "GRZGcsLPzDrCSXhhNTaibJqVphhjbcPoZhCDUlzAbDnRWjHvxLKtpGiFWiGbfeDxBwCrdJmJGCGv GebAOinUsFrlqKTILOmxrFjSpEoVGoTdSSstJWVgMLKMPettxHASaQZNdOIObcTxtF qTHWBdNIKwj\nWqrxze Ji x q aT GllLrRV jMpGiMDTwwS JDsPGpAZKACmsFCOS CD Sj bCDgKF jJxa RddtLFAi VGLHH SecObzG q hPF ",
"output": "YES"
},
{
"input": "GtPXuwdAxNhODQbjRslDDKciOALJrCifTjDQurQEBeFUUSZWwCZQPdYwZkYbrduMijFjgodAOrKIuUKwSXageZuOWMIhAMexyLRzFuzuXqBDTEaWMzVdbzhxDGSJC SsIYuYILwpiwwcObEHWpFvHeBkWYNitqYrxqgHReHcKnHbtjcWZuaxPBVPb\nTQIKyqFaewOkY lZUOOuxEw EwuKcArxRQGFYkvVWIAe SuanPeHuDjquurJu aSxwgOSw jYMwjxItNUUArQjO BIujAhSwttLWp",
"output": "YES"
},
{
"input": "FVFSr unvtXbpKWF vPaAgNaoTqklzVqiGYcUcBIcattzBrRuNSnKUtmdGKbjcE\nUzrU K an GFGR Wc zt iBa P c T K v p V In b B c",
"output": "YES"
},
{
"input": "lSwjnYLYtDNIZjxHiTawdh ntSzggZogcIZTuiTMWVgwyloMtEhqkrOxgIcFvwvsboXUPILPIymFAEXnhApewJXJNtFyZ\nAoxe jWZ u yImg o AZ FNI w lpj tNhT g y ZYcb rc J w Dlv",
"output": "YES"
},
{
"input": "kvlekcdJqODUKdsJlXkRaileTmdGwUHWWgvgUokQxRzzbpFnswvNKiDnjfOFGvFcnaaiRnBGQmqoPxDHepgYasLhzjDgmvaFfVNEcSPVQCJKAbSyTGpXsAjIHr\nGjzUllNaGGKXUdYmDFpqFAKIwvTpjmqnyswWRTnxlBnavAGvavxJemrjvRJc",
"output": "YES"
},
{
"input": "kWbvhgvvoYOhwXmgTwOSCDXrtFHhqwvMlCvsuuAUXMmWaYXiqHplFZZemhgkTuvsUtIaUxtyYauBIpjdbyYxjZ ZkaBPzwqPfqF kCqGRmXvWuabnQognnkvdNDtRUsSUvSzgBuxCMBWJifbxWegsknp\nBsH bWHJD n Ca T xq PRCv tatn Wjy sm I q s WCjFqdWe t W XUs Do eb Pfh ii hTbF O Fll",
"output": "YES"
},
{
"input": "OTmLdkMhmDEOMQMiW ZpzEIjyElHFrNCfFQDp SZyoZaEIUIpyCHfwOUqiSkKtFHggrTBGkqfOxkChPztmPrsHoxVwAdrxbZLKxPXHlMnrkgMgiaHFopiFFiUEtKwCjpJtwdwkbJCgA bxeDIscFdmHQJLAMNhWlrZisQrHQpvbALWTwpf jnx\nDbZwrQbydCdkJMCrftiwtPFfpMiwwrfIrKidEChKECxQUBVUEfFirbGWiLkFQkdJiFtkrtkbIAEXCEDkwLpK",
"output": "YES"
},
{
"input": "NwcGaIeSkOva\naIa",
"output": "YES"
},
{
"input": "gSrAcVYgAdbdayzbKGhIzLDjyznLRIJH KyvilAaEddmgkBPCNzpmPNeGEbmmpAyHvUSoPvnaORrPUuafpReEGoDOQsAYnUHYfBqhdcopQfxJuGXgKnbdVMQNhJYkyjiJDKlShqBTtnnDQQzEijOMcYRGMgPGVhfIReYennKBLwDTVvcHMIHMgVpJkvzTrezxqS\nHJerIVvRyfrPgAQMTI AqGNO mQDfDwQHKgeeYmuRmozKHILvehMPOJNMRtPTAfvKvsoGKi xHEeKqDAYmQJPUXRJbIbHrgVOMGMTdvYiLui",
"output": "YES"
},
{
"input": "ReB hksbHqQXxUgpvoNK bFqmNVCEiOyKdKcAJQRkpeohpfuqZabvrLfmpZOMcfyFBJGZwVMxiUPP pbZZtJjxhEwvrAba\nJTCpQnIViIGIdQtLnmkVzmcbBZR CoxAdTtWSYpbOglDFifqIVQ vfGKGtLpxpJHiHSWCMeRcrVOXBGBhoEnVhNTPWGTOErNtSvokcGdgZXbgTEtISUyTwaXUEIlJMmutsdCbiyrPZPJyRdOjnSuAGttLy",
"output": "NO"
},
{
"input": "hrLzRegCuDGxTrhDgVvM KowwyYuXGzIpcXdSMgeQVfVOtJZdkhNYSegwFWWoPqcZoeapbQnyCtojgkcyezUNHGGIZrhzsKrvvcrtokIdcnqXXkCNKjrOjrnEAKBNxyDdiMVeyLvXxUYMZQRFdlcdlcxzKTeYzBlmpNiwWbNAAhWkMoGpRxkCuyqkzXdKWwGH\nJESKDOfnFdxPvUOCkrgSBEPQHJtJHzuNGstRbTCcchRWJvCcveSEAtwtOmZZiW",
"output": "NO"
},
{
"input": "yDBxCtUygQwWqONxQCcuAvVCkMGlqgC zvkfEkwqbhMCQxnkwQIUhucCbVUyOBUcXvTNEGriTBwMDMfdsPZgWRgIUDqM\neptVnORTTyixxmWIBpSTEwOXqGZllBgSxPenYCDlFwckJlWsoVwWLAIbPOmFqcKcTcoQqahetl KLfVSyaLVebzsGwPSVbtQAeUdZAaJtfxlCEvvaRhLlVvRJhKat IaB awdqcDlrrhTbRxjEbzGwcdmdavkhcjHjzmwbxAgw",
"output": "NO"
},
{
"input": "jlMwnnotSdlQMluKWkJwAeCetcqbIEnKeNyLWoKCGONDRBQOjbkGpUvDlmSFUJ bWhohqmmIUWTlDsvelUArAcZJBipMDwUvRfBsYzMdQnPDPAuBaeJmAxVKwUMJrwMDxNtlrtAowVWqWiwFGtmquZAcrpFsLHCrvMSMMlvQUqypAihQWrFMNoaqfs IBg\nNzeWQ bafrmDsYlpNHSGTBBgPl WIcuNhyNaNOEFvL",
"output": "NO"
},
{
"input": "zyWvXBcUZqGqjHwZHQryBtFliLYnweXAoMKNpLaunaOlzaauWmLtywsEvWPiwxJapocAFRMjrqWJXYqfKEbBKnzLO\npsbi bsXpSeJaCkIuPWfSRADXdIClxcDCowwJzGCDTyAl",
"output": "NO"
},
{
"input": "kKhuIwRPLCwPFfcnsyCfBdnsraGeOCcLTfXuGjqFSGPSAeDZJSS bXKFanNqWjpFnvRpWxHJspvisDlADJBioxXNbVoXeUedoPcNEpUyEeYxdJXhGzFAmpAiHotSVwbZQsuWjIVhVaEGgqbZHIoDpiEmjTtFylCwCkWWzUOoUfOHxEZvDwNpXhBWamHn\nK VpJjGhNbwCRhcfmNGVjewBFpEmPlIKeTuWiukDtEWpjgqciqglkyNfWrBLbGAKvlNWxaUelJmSlSoakSpRzePvJsshOsTYrMPXdxKpaShjyVIXGhRIAdtiGpNwtiRmGTBZhkJqIMdxMHX RMxCMYcWjcjhtCHyFnCvjjezGbkRDRiVxkbh",
"output": "NO"
},
{
"input": "AXssNpFKyQmJcBdBdfkhhMUzfqJVgcLBddkwtnFSzSRUCjiDcdtmkzIGkCKSxWUEGhmHmciktJyGMkgCductyHx\nI nYhmJfPnvoKUiXYUBIPIcxNYTtvwPUoXERZvY ahlDpQFNMmVZqEBiYqYlHNqcpSCmhFczBlOAhsYFeqMGfqL EJsDNOgwoJfBzqijKOFcYQ",
"output": "NO"
},
{
"input": "lkhrzDZmkdbjzYKPNMRkiwCFoZsMzBQMnxxdKKVJezSBjnLjPpUYtabcPTIaDJeDEobbWHdKOdVfMQwDXzDDcSrwVenDEYpMqfiOQ xSsqApWnAMoyhQXCKFzHvvzvUvkWwmwZrvZz\nsUzGspYpRFsHRbRgTQuCBgnFgPkisTUfFNwyEEWWRiweWWgjRkVQxgTwxOzdsOwfrGIH O gCXpzvHzfItuEHaihmugEyymSJIogYwX qAwcwIItidfnzZDhZgQHi eRjMAeVkJHceDZuJkmxGowOsmcGYYvk Ajtgi TxwihvjLViNZjvscTWvsaQUelTSivLShhEl",
"output": "NO"
},
{
"input": "BRsVjyNhrqRHVwrJzuzRigEhdpbDmaACSPfed\nlWqKTjlrqOCUbgBBZdZDGCeQJDXawPnnDkQdZDgwrEQk",
"output": "NO"
},
{
"input": "KRmINuyBYPwiTsdlyiNVuylToysJKmOpcLovAtwGPqrgFJQNAYvuAiyQRkeFMECVZvkDEmTauXlyjAaYRnTJXORMZRnTakBaUzSelMilejySDIZjQjzcOIrwXdvDvpeRIkoBgreyFXIyyIZutjiEBtwrmzQtPVUhvvdEtDMbXjBpoPVjGdM EXTAK JbCnw\nXZZqlJvzKKtvdNlzFPDTYxidqlsgufVzyEmO FZuLQ vVQsJESNviUCovCK NwwlbxsmPtOJNmAonCqrOZ bZ LVKAsQGmoLnYjeekvEIECFk",
"output": "NO"
}
] | 124 | 0 | 0 | 4,953 |
982 | Cut 'em all! | [
"dfs and similar",
"dp",
"graphs",
"greedy",
"trees"
] | null | null | You're given a tree with $n$ vertices.
Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size. | The first line contains an integer $n$ ($1 \le n \le 10^5$) denoting the size of the tree.
The next $n - 1$ lines contain two integers $u$, $v$ ($1 \le u, v \le n$) each, describing the vertices connected by the $i$-th edge.
It's guaranteed that the given edges form a tree. | Output a single integer $k$ — the maximum number of edges that can be removed to leave all connected components with even size, or $-1$ if it is impossible to remove edges in order to satisfy this property. | [
"4\n2 4\n4 1\n3 1\n",
"3\n1 2\n1 3\n",
"10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5\n",
"2\n1 2\n"
] | [
"1",
"-1",
"4",
"0"
] | In the first example you can remove the edge between vertices $1$ and $4$. The graph after that will have two connected components with two vertices in each.
In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $-1$. | [
{
"input": "4\n2 4\n4 1\n3 1",
"output": "1"
},
{
"input": "3\n1 2\n1 3",
"output": "-1"
},
{
"input": "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5",
"output": "4"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4\n1 2\n1 3\n1 4",
"output": "0"
}
] | 61 | 2,764,800 | -1 | 4,967 |
|
662 | Gambling Nim | [
"bitmasks",
"math",
"matrices",
"probabilities"
] | null | null | As you know, the game of "Nim" is played with *n* piles of stones, where the *i*-th pile initially contains *a**i* stones. Two players alternate the turns. During a turn a player picks any non-empty pile and removes any positive number of stones from it. The one who is not able to make a move loses the game.
Petya and Vasya are tired of playing Nim, so they invented their own version of the game and named it the "Gambling Nim". They have *n* two-sided cards, one side of the *i*-th card has number *a**i* written on it, while the other side has number *b**i*. At the beginning of the game the players put all the cards on the table, each card only one of its sides up, and this side is chosen independently and uniformly. Thus they obtain a sequence *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is equal to *a**i* or *b**i*. Then they take *n* piles of stones, with *i*-th pile containing exactly *c**i* stones and play Nim. Petya takes the first turn.
Given that both players play optimally, find the probability of Petya's victory. Output the answer as an irreducible fraction. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=500<=000) — the number of cards in the deck.
Each of the following *n* lines contains the description of one card, consisting of two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1018). | Output the answer as an irreducible fraction *p*<=/<=*q*. If the probability of Petya's victory is 0, print 0/1. | [
"2\n1 1\n1 1\n",
"2\n1 2\n1 2\n",
"3\n0 4\n1 5\n2 3\n"
] | [
"0/1\n",
"1/2\n",
"1/1\n"
] | none | [
{
"input": "2\n1 1\n1 1",
"output": "0/1"
},
{
"input": "2\n1 2\n1 2",
"output": "1/2"
},
{
"input": "3\n0 4\n1 5\n2 3",
"output": "1/1"
},
{
"input": "1\n0 0",
"output": "0/1"
},
{
"input": "1\n8 10",
"output": "1/1"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0/1"
},
{
"input": "3\n3 6\n1 4\n4 5",
"output": "1/1"
},
{
"input": "10\n6 3\n9 3\n4 5\n4 8\n9 1\n2 10\n9 0\n8 2\n4 9\n10 5",
"output": "15/16"
},
{
"input": "10\n40 61\n67 7\n90 42\n86 68\n41 73\n97 35\n8 71\n68 12\n67 40\n35 74",
"output": "127/128"
},
{
"input": "10\n955 199\n618 994\n485 602\n335 433\n116 562\n500 553\n301 990\n668 720\n753 271\n549 124",
"output": "1/1"
}
] | 46 | 0 | -1 | 4,970 |
|
0 | none | [
"none"
] | null | null | Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are *n* piles of cows, with the *i*-th pile containing *a**i* cows. During each player's turn, that player calls upon the power of Sunlight, and uses it to either:
1. Remove a single cow from a chosen non-empty pile. 1. Choose a pile of cows with even size 2·*x* (*x*<=><=0), and replace it with *k* piles of *x* cows each.
The player who removes the last cow wins. Given *n*, *k*, and a sequence *a*1,<=*a*2,<=...,<=*a**n*, help Kevin and Nicky find the winner, given that both sides play in optimal way. | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=109).
The second line contains *n* integers, *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=109) describing the initial state of the game. | Output the name of the winning player, either "Kevin" or "Nicky" (without quotes). | [
"2 1\n3 4\n",
"1 2\n3\n"
] | [
"Kevin\n",
"Nicky\n"
] | In the second sample, Nicky can win in the following way: Kevin moves first and is forced to remove a cow, so the pile contains two cows after his move. Next, Nicky replaces this pile of size 2 with two piles of size 1. So the game state is now two piles of size 1. Kevin then removes one of the remaining cows and Nicky wins by removing the other. | [
{
"input": "2 1\n3 4",
"output": "Kevin"
},
{
"input": "1 2\n3",
"output": "Nicky"
},
{
"input": "4 5\n20 21 22 25",
"output": "Kevin"
},
{
"input": "5 1\n1 7 7 6 6",
"output": "Kevin"
},
{
"input": "7 1\n8 6 10 10 1 5 8",
"output": "Kevin"
},
{
"input": "10 1\n2 3 5 2 7 4 7 7 4 2",
"output": "Kevin"
},
{
"input": "10 1\n5 6 3 10 6 6 1 1 5 3",
"output": "Kevin"
},
{
"input": "6 1\n1 4 4 4 2 2",
"output": "Kevin"
},
{
"input": "10 2\n3 10 10 8 6 10 9 9 5 7",
"output": "Kevin"
},
{
"input": "6 2\n5 3 5 6 2 2",
"output": "Kevin"
},
{
"input": "9 2\n8 2 9 4 7 5 2 4 9",
"output": "Kevin"
},
{
"input": "9 2\n2 8 4 2 5 7 1 8 10",
"output": "Kevin"
},
{
"input": "7 2\n9 1 7 6 10 3 5",
"output": "Kevin"
},
{
"input": "2 2\n1 2",
"output": "Kevin"
},
{
"input": "2 2\n2 2",
"output": "Nicky"
},
{
"input": "4 100\n2 1 2 2",
"output": "Kevin"
},
{
"input": "2 2\n2 3",
"output": "Kevin"
},
{
"input": "2 2\n2 4",
"output": "Kevin"
},
{
"input": "2 2\n2 5",
"output": "Kevin"
},
{
"input": "2 2\n2 6",
"output": "Kevin"
},
{
"input": "2 1\n24 1",
"output": "Kevin"
},
{
"input": "1 1\n1000000000",
"output": "Kevin"
},
{
"input": "1 1\n1",
"output": "Kevin"
},
{
"input": "2 3\n12345678 23456789",
"output": "Kevin"
},
{
"input": "2 1\n160 150",
"output": "Nicky"
},
{
"input": "2 3\n1000000000 1000000000",
"output": "Nicky"
},
{
"input": "2 3\n7 7",
"output": "Nicky"
},
{
"input": "1 1\n111111112",
"output": "Kevin"
},
{
"input": "3 2\n1 1 1",
"output": "Kevin"
},
{
"input": "1 2\n1",
"output": "Kevin"
}
] | 78 | 10,035,200 | 0 | 4,976 |
|
979 | Treasure Hunt | [
"greedy"
] | null | null | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $7$ because its subribbon a appears $7$ times, and the ribbon abcdabc has the beauty of $2$ because its subribbon abc appears twice.
The rules are simple. The game will have $n$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $n$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally? | The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors. | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | [
"3\nKuroo\nShiro\nKatie\n",
"7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"1\nabcabc\ncbabac\nababca\n",
"15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n"
] | [
"Kuro\n",
"Shiro\n",
"Katie\n",
"Draw\n"
] | In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $9$ and the number of turn is $15$, everyone can change their ribbons in some way to reach the maximal beauty of $9$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw. | [
{
"input": "3\nKuroo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces",
"output": "Shiro"
},
{
"input": "1\nabcabc\ncbabac\nababca",
"output": "Katie"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE",
"output": "Draw"
},
{
"input": "1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbbzzbb",
"output": "Shiro"
},
{
"input": "60\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ",
"output": "Draw"
},
{
"input": "9174\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd",
"output": "Draw"
},
{
"input": "727\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef",
"output": "Draw"
},
{
"input": "61\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub",
"output": "Katie"
},
{
"input": "30\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr",
"output": "Draw"
},
{
"input": "3\nabcabcabcabcdddabc\nzxytzytxxtytxyzxyt\nfgffghfghffgghghhh",
"output": "Katie"
},
{
"input": "3\naaaaa\naaaaa\naaaab",
"output": "Draw"
},
{
"input": "3\naaaaaaa\naaaabcd\nabcdefg",
"output": "Draw"
},
{
"input": "3\naaaaaaa\naaabcde\nabcdefg",
"output": "Kuro"
},
{
"input": "3\naaaaaaa\naaaabbb\nabcdefg",
"output": "Draw"
},
{
"input": "3\naaa\nbbb\nabc",
"output": "Draw"
},
{
"input": "3\naaaaa\nabcde\nabcde",
"output": "Kuro"
},
{
"input": "3\naaaaa\nqwert\nlkjhg",
"output": "Kuro"
},
{
"input": "3\naaaaa\nbbbbb\naabcd",
"output": "Draw"
},
{
"input": "3\nabcde\nfghij\nkkkkk",
"output": "Katie"
},
{
"input": "4\naaaabcd\naaaabcd\naaaaaaa",
"output": "Draw"
},
{
"input": "3\naaaabb\naabcde\nabcdef",
"output": "Kuro"
},
{
"input": "2\naaab\nabcd\naaaa",
"output": "Draw"
},
{
"input": "3\naaaaaa\naaaaaa\nabcdef",
"output": "Draw"
},
{
"input": "1\nAAAAA\nBBBBB\nABCDE",
"output": "Draw"
},
{
"input": "1\nabcde\naaaaa\naaaaa",
"output": "Draw"
},
{
"input": "4\naaabbb\nabfcde\nabfcde",
"output": "Kuro"
},
{
"input": "0\naaa\naab\nccd",
"output": "Kuro"
},
{
"input": "3\naaaaa\naaaaa\naabbb",
"output": "Draw"
},
{
"input": "3\nxxxxxx\nxxxooo\nabcdef",
"output": "Draw"
},
{
"input": "2\noooo\naaac\nabcd",
"output": "Draw"
},
{
"input": "1\naaaaaaa\naaabcde\nabcdefg",
"output": "Kuro"
},
{
"input": "3\nooooo\naaabb\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaa\nqwert\nqwery",
"output": "Kuro"
},
{
"input": "2\naaaaaa\nbbbbbb\naaaaab",
"output": "Draw"
},
{
"input": "3\naabb\naabb\naabc",
"output": "Draw"
},
{
"input": "2\naaa\naab\naab",
"output": "Draw"
},
{
"input": "3\nbbbbcc\nbbbbbb\nsadfgh",
"output": "Draw"
},
{
"input": "3\naaaaaacc\nxxxxkkkk\nxxxxkkkk",
"output": "Kuro"
},
{
"input": "2\naaaac\nbbbbc\nccccc",
"output": "Draw"
},
{
"input": "3\naaaaaaaaa\naaabbbbbb\nabcdewert",
"output": "Draw"
},
{
"input": "3\naaabc\naaaab\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaaaaa\naaaaaaab\naaaabbbb",
"output": "Draw"
},
{
"input": "2\nabcdefg\nabccccc\nacccccc",
"output": "Draw"
},
{
"input": "3\naaaaa\naabcd\nabcde",
"output": "Draw"
},
{
"input": "4\naaabbb\nabcdef\nabcdef",
"output": "Kuro"
},
{
"input": "4\naaabbb\naabdef\nabcdef",
"output": "Draw"
},
{
"input": "3\nabba\nbbbb\naaaa",
"output": "Draw"
},
{
"input": "3\naaaaa\nbbaaa\nabcde",
"output": "Draw"
},
{
"input": "2\naaa\naaa\nabc",
"output": "Draw"
},
{
"input": "3\naaaaa\nabcda\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaa\nabcde\nbcdef",
"output": "Kuro"
},
{
"input": "3\naaabb\naabbc\nqwert",
"output": "Draw"
},
{
"input": "3\naaaaaa\naabbcc\naabbcc",
"output": "Kuro"
},
{
"input": "3\nAAAAAA\nAAAAAB\nABCDEF",
"output": "Draw"
},
{
"input": "3\nabc\naac\nbbb",
"output": "Draw"
},
{
"input": "2\naaaab\naabbc\naabbc",
"output": "Kuro"
},
{
"input": "2\naaaaaab\naaaaabb\nabcdefg",
"output": "Draw"
},
{
"input": "3\naaaaaaaaaaa\nbbbbbbbbaaa\nqwertyuiasd",
"output": "Draw"
},
{
"input": "3\naaaa\nbbbb\naabb",
"output": "Draw"
},
{
"input": "3\naaaabb\naaabcd\nabcdef",
"output": "Draw"
},
{
"input": "3\naaa\nabc\nbbb",
"output": "Draw"
},
{
"input": "1\naa\nab\nbb",
"output": "Shiro"
},
{
"input": "1\naacb\nabcd\naaaa",
"output": "Draw"
},
{
"input": "3\naaaabb\naaabbb\nabcdef",
"output": "Draw"
},
{
"input": "3\naaaa\naaaa\nabcd",
"output": "Draw"
},
{
"input": "2\nabcd\nabcd\naaad",
"output": "Katie"
},
{
"input": "3\naaa\nbbb\naab",
"output": "Draw"
},
{
"input": "3\naaaaaa\naaaaab\naaaaaa",
"output": "Draw"
},
{
"input": "2\naaab\nabcd\nabcd",
"output": "Kuro"
},
{
"input": "3\nooooo\nShiro\nKatie",
"output": "Kuro"
},
{
"input": "3\naaabb\naabcd\nabcde",
"output": "Draw"
},
{
"input": "4\nabcd\nabcd\naaaa",
"output": "Draw"
},
{
"input": "4\naaa\nbbb\naab",
"output": "Draw"
},
{
"input": "2\nxxxx\nyyyx\nabcd",
"output": "Draw"
},
{
"input": "3\nAAAAA\nAAAAB\nABCDE",
"output": "Draw"
},
{
"input": "3\naaaacdc\naaaaabc\naaaaabc",
"output": "Draw"
},
{
"input": "3\naaaaaa\naabcde\naabcde",
"output": "Kuro"
},
{
"input": "3\naaabb\naaabb\naaaaa",
"output": "Draw"
},
{
"input": "5\nabbbbb\ncbbbbb\nabcdef",
"output": "Draw"
},
{
"input": "3\naaaaaaaaa\naaaaabbbb\naaaaabbbb",
"output": "Kuro"
},
{
"input": "4\naaaaaab\naaabbbb\naaabbbb",
"output": "Draw"
},
{
"input": "3\naaaabb\naaaabb\naaabbb",
"output": "Draw"
},
{
"input": "2\naaaabb\naaaaab\nabcdef",
"output": "Draw"
},
{
"input": "2\naaaaa\naaaae\nabcde",
"output": "Draw"
},
{
"input": "3\naaaaaa\nbbbcde\nabcdef",
"output": "Draw"
},
{
"input": "4\naaaabbb\naabcdef\naabcdef",
"output": "Kuro"
},
{
"input": "2\naaaaa\naaaab\nabcde",
"output": "Draw"
},
{
"input": "3\naabbbbb\naaabbbb\nabcdefg",
"output": "Draw"
},
{
"input": "3\nabcde\naabcd\naaaaa",
"output": "Draw"
},
{
"input": "5\naaabbcc\nabcdefg\nabcdefg",
"output": "Kuro"
},
{
"input": "3\naabbb\nabcde\nabcde",
"output": "Kuro"
},
{
"input": "0\nbbb\nabb\nqer",
"output": "Kuro"
},
{
"input": "5\naabbbbb\naaaaaaa\nabcdefg",
"output": "Draw"
},
{
"input": "2\naaaab\naaaab\naaabb",
"output": "Draw"
},
{
"input": "2\naaaaaab\naaaabbb\naaaaccc",
"output": "Kuro"
},
{
"input": "3\naaaaaaaaaaaa\naaaaaaaaaaab\naaaaaabbbbbb",
"output": "Draw"
},
{
"input": "3\naaabb\nabcde\naaaaa",
"output": "Draw"
},
{
"input": "3\naaaaaac\naaaaebc\naaaaaac",
"output": "Draw"
},
{
"input": "3\naaaaaa\naaabbb\nqwerty",
"output": "Draw"
},
{
"input": "3\ncccca\nabcde\nabcde",
"output": "Kuro"
},
{
"input": "100005\nAA\nBC\nCC",
"output": "Draw"
},
{
"input": "3\naaaa\nbbbb\nccca",
"output": "Draw"
},
{
"input": "3\naaaaa\nbcdef\nbcdef",
"output": "Kuro"
},
{
"input": "2\naaab\naabb\nqwer",
"output": "Draw"
},
{
"input": "3\nabcddd\nabcdef\nbbaaaa",
"output": "Draw"
},
{
"input": "2\naaaa\naaaa\naabc",
"output": "Draw"
},
{
"input": "3\naaaa\naaaa\naaab",
"output": "Draw"
},
{
"input": "3\nabcddd\nabcdef\naaaaaa",
"output": "Draw"
},
{
"input": "1\naaaa\nabcd\naaab",
"output": "Katie"
}
] | 77 | 409,600 | 0 | 4,977 |
|
31 | Chocolate | [
"dfs and similar",
"implementation"
] | D. Chocolate | 2 | 256 | Bob has a rectangular chocolate bar of the size *W*<=×<=*H*. He introduced a cartesian coordinate system so that the point (0,<=0) corresponds to the lower-left corner of the bar, and the point (*W*,<=*H*) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parallel to one of the coordinate axes, which connects the edges of the bar. More formally, each break goes along the line *x*<==<=*x**c* or *y*<==<=*y**c*, where *x**c* and *y**c* are integers. It should divide one part of the bar into two non-empty parts. After Bob breaks some part into two parts, he breaks the resulting parts separately and independently from each other. Also he doesn't move the parts of the bar. Bob made *n* breaks and wrote them down in his notebook in arbitrary order. At the end he got *n*<=+<=1 parts. Now he wants to calculate their areas. Bob is lazy, so he asks you to do this task. | The first line contains 3 integers *W*, *H* and *n* (1<=≤<=*W*,<=*H*,<=*n*<=≤<=100) — width of the bar, height of the bar and amount of breaks. Each of the following *n* lines contains four integers *x**i*,<=1,<=*y**i*,<=1,<=*x**i*,<=2,<=*y**i*,<=2 — coordinates of the endpoints of the *i*-th break (0<=≤<=*x**i*,<=1<=≤<=*x**i*,<=2<=≤<=*W*,<=0<=≤<=*y**i*,<=1<=≤<=*y**i*,<=2<=≤<=*H*, or *x**i*,<=1<==<=*x**i*,<=2, or *y**i*,<=1<==<=*y**i*,<=2). Breaks are given in arbitrary order.
It is guaranteed that the set of breaks is correct, i.e. there is some order of the given breaks that each next break divides exactly one part of the bar into two non-empty parts. | Output *n*<=+<=1 numbers — areas of the resulting parts in the increasing order. | [
"2 2 2\n1 0 1 2\n0 1 1 1\n",
"2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1\n",
"2 4 2\n0 1 2 1\n0 3 2 3\n"
] | [
"1 1 2 ",
"1 1 1 1 ",
"2 2 4 "
] | none | [
{
"input": "2 2 2\n1 0 1 2\n0 1 1 1",
"output": "1 1 2 "
},
{
"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1",
"output": "1 1 1 1 "
},
{
"input": "2 4 2\n0 1 2 1\n0 3 2 3",
"output": "2 2 4 "
},
{
"input": "5 5 3\n2 1 2 5\n0 1 5 1\n4 0 4 1",
"output": "1 4 8 12 "
},
{
"input": "10 10 4\n9 0 9 10\n4 0 4 10\n1 0 1 10\n1 4 4 4",
"output": "10 10 12 18 50 "
},
{
"input": "9 8 5\n4 3 4 4\n0 4 9 4\n5 4 5 8\n0 3 9 3\n1 4 1 8",
"output": "4 4 5 16 16 27 "
},
{
"input": "100 100 1\n0 14 100 14",
"output": "1400 8600 "
}
] | 92 | 0 | 0 | 4,979 |
776 | Sherlock and his girlfriend | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.
Help Sherlock complete this trivial task. | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
If there are multiple ways to color the pieces using *k* colors, you can output any of them. | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 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[
"dp",
"sortings"
] | C. Sequence | 1 | 64 | Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of *N* integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is to make the sequence non-decreasing with the smallest number of steps. Petya is not good at math, so he asks for your help.
The sequence *a* is called non-decreasing if *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**N* holds, where *N* is the length of the sequence. | The first line of the input contains single integer *N* (1<=≤<=*N*<=≤<=5000) — the length of the initial sequence. The following *N* lines contain one integer each — elements of the sequence. These numbers do not exceed 109 by absolute value. | Output one integer — minimum number of steps required to achieve the goal. | [
"5\n3 2 -1 2 11\n",
"5\n2 1 1 1 1\n"
] | [
"4\n",
"1\n"
] | none | [
{
"input": "5\n3 2 -1 2 11",
"output": "4"
},
{
"input": "5\n2 1 1 1 1",
"output": "1"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "1\n11",
"output": "0"
},
{
"input": "2\n10 2",
"output": "8"
},
{
"input": "6\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000",
"output": "6000000000"
},
{
"input": "7\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "6000000000"
},
{
"input": "10\n3 0 5 10 10 9 10 8 8 1",
"output": "16"
},
{
"input": "20\n5 5 6 5 10 9 4 0 0 0 7 7 7 5 6 7 5 6 5 6",
"output": "33"
},
{
"input": "20\n10 6 1 9 10 10 7 0 10 5 9 1 5 7 4 9 3 9 7 2",
"output": "55"
},
{
"input": "20\n0 0 0 1 5 10 7 7 8 7 66 64 62 65 39 38 72 69 71 72",
"output": "63"
},
{
"input": "5\n1 2 3 1 1",
"output": "3"
}
] | 218 | 0 | 0 | 5,012 |
663 | Rebus | [
"constructive algorithms",
"expression parsing",
"greedy",
"math"
] | null | null | You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer *n*. The goal is to replace each question mark with some positive integer from 1 to *n*, such that equality holds. | The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer *n* is positive and doesn't exceed 1<=000<=000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks. | The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise.
If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to *n*. Follow the format given in the samples. | [
"? + ? - ? + ? + ? = 42\n",
"? - ? = 1\n",
"? = 1000000\n"
] | [
"Possible\n9 + 13 - 39 + 28 + 31 = 42\n",
"Impossible\n",
"Possible\n1000000 = 1000000\n"
] | none | [
{
"input": "? + ? - ? + ? + ? = 42",
"output": "Possible\n1 + 1 - 1 + 1 + 40 = 42"
},
{
"input": "? - ? = 1",
"output": "Impossible"
},
{
"input": "? = 1000000",
"output": "Possible\n1000000 = 1000000"
},
{
"input": "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 9",
"output": "Impossible"
},
{
"input": "? - ? + ? + ? + ? + ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? + ? + ? + ? - ? + ? + ? + ? - ? + ? + ? - ? + ? - ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? + ? + ? - ? - ? - ? - ? + ? - ? - ? + ? + ? - ? + ? + ? - ? - ? - ? + ? + ? - ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? + ? - ? + ? - ? + ? + ? + ? - ? + ? + ? - ? - ? + ? = 123456",
"output": "Possible\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 + 2 - 1 - 1 + 123456 = 123456"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 93",
"output": "Impossible"
},
{
"input": "? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 57",
"output": "Possible\n18 - 1 + 57 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 57"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 32",
"output": "Possible\n32 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 32 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 32 - 1 - 1 - 1 - 1 + 32 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 32"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 31",
"output": "Impossible"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? + ? + ? - ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? + ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? + ? - ? - ? = 4",
"output": "Impossible"
},
{
"input": "? + ? - ? - ? - ? + ? + ? - ? + ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? = 5",
"output": "Possible\n1 + 1 - 1 - 1 - 1 + 1 + 2 - 1 + 5 + 5 - 1 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 + 5 - 1 + 5 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 5"
},
{
"input": "? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? + ? + ? + ? + ? - ? - ? + ? + ? - ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? - ? + ? + ? + ? + ? - ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? = 3",
"output": "Impossible"
},
{
"input": "? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? - ? + ? + ? - ? - ? + ? + ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? + ? + ? - ? + ? + ? - ? - ? + ? - ? + ? + ? + ? = 4",
"output": "Possible\n1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 - 4 - 4 + 1 + 1 - 4 - 4 + 1 + 1 + 1 - 4 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 - 4 + 1 + 1 + 1 - 4 + 1 + 1 - 4 - 4 + 1 - 4 + 1 + 1 + 1 = 4"
},
{
"input": "? + ? - ? + ? + ? - ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? - ? + ? + ? = 4",
"output": "Possible\n1 + 1 - 1 + 1 + 1 - 3 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 - 4 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 - 4 + 1 - 4 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 - 4 - 4 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 - 4 - 4 + 1 + 1 = 4"
},
{
"input": "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 100",
"output": "Possible\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"
},
{
"input": "? + ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? + ? - ? - ? - ? + ? - ? - ? + ? - ? - ? + ? - ? + ? + ? - ? + ? - ? - ? + ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? + ? - ? - ? + ? - ? - ? - ? - ? + ? + ? - ? + ? + ? - ? + ? - ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? = 837454",
"output": "Possible\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 + 28 - 1 - 1 - 1 - 1 - 1 + 837454 - 1 = 837454"
},
{
"input": "? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? - ? + ? - ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? - ? + ? + ? - ? + ? - ? + ? - ? - ? + ? - ? - ? + ? - ? - ? - ? + ? - ? - ? + ? - ? + ? + ? - ? - ? + ? - ? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? - ? - ? + ? - ? - ? - ? + ? = 254253",
"output": "Possible\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 + 2 - 1 - 1 - 1 + 254253 = 254253"
},
{
"input": "? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? - ? - ? + ? - ? + ? + ? + ? + ? - ? - ? + ? + ? - ? - ? + ? = 1000000",
"output": "Possible\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 + 999963 = 1000000"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 43386",
"output": "Impossible"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? = 999999",
"output": "Possible\n98 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 999999 - 1 - 1 = 999999"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 37",
"output": "Possible\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 + 20 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 37 - 1 - 1 - 1 + 37 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 37 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 37"
},
{
"input": "? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 19",
"output": "Possible\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 + 11 - 1 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 19"
},
{
"input": "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 15",
"output": "Possible\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 - 14 + 1 + 1 - 15 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 15 + 1 - 15 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 15 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 15"
},
{
"input": "? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 33",
"output": "Possible\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 - 33 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 33"
},
{
"input": "? + ? + ? + ? + ? - ? = 3",
"output": "Possible\n1 + 1 + 1 + 1 + 1 - 2 = 3"
},
{
"input": "? + ? + ? + ? - ? = 2",
"output": "Possible\n1 + 1 + 1 + 1 - 2 = 2"
},
{
"input": "? + ? - ? + ? + ? = 2",
"output": "Possible\n1 + 1 - 2 + 1 + 1 = 2"
},
{
"input": "? + ? + ? + ? + ? - ? - ? = 2",
"output": "Possible\n1 + 1 + 1 + 1 + 1 - 1 - 2 = 2"
},
{
"input": "? + ? - ? = 1",
"output": "Possible\n1 + 1 - 1 = 1"
},
{
"input": "? - ? + ? - ? + ? + ? + ? + ? = 2",
"output": "Possible\n1 - 2 + 1 - 2 + 1 + 1 + 1 + 1 = 2"
},
{
"input": "? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? = 5",
"output": "Possible\n1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 5 = 5"
}
] | 124 | 307,200 | 3 | 5,015 |
|
495 | Modular Equations | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation.
Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations.
Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has. | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "0 0",
"output": "infinity"
},
{
"input": "121 0",
"output": "3"
},
{
"input": "772930485 686893955",
"output": "0"
},
{
"input": "257424 24",
"output": "127"
},
{
"input": "295138437 589952171",
"output": "0"
},
{
"input": "223093836 966",
"output": "399"
},
{
"input": "233758336 10665466",
"output": "13"
},
{
"input": "223092887 17",
"output": "500"
},
{
"input": "223094728 1858",
"output": "371"
},
{
"input": "223092899 29",
"output": "495"
},
{
"input": "997920 0",
"output": "240"
},
{
"input": "887043 3",
"output": "213"
},
{
"input": "124 24",
"output": "3"
},
{
"input": "982901 101",
"output": "193"
},
{
"input": "357987 35",
"output": "45"
},
{
"input": "954374 1030",
"output": "32"
},
{
"input": "49106 46",
"output": "15"
},
{
"input": "325508499 119510657",
"output": "1"
},
{
"input": "89768760 885778845",
"output": "0"
},
{
"input": "944387968 700818251",
"output": "0"
},
{
"input": "12 3",
"output": "1"
},
{
"input": "1000000000 1",
"output": "19"
},
{
"input": "923456789 3",
"output": "14"
},
{
"input": "1000000000 6",
"output": "6"
},
{
"input": "1000000000 333333300",
"output": "2"
},
{
"input": "5 2",
"output": "1"
},
{
"input": "1 10",
"output": "0"
},
{
"input": "15 3",
"output": "3"
},
{
"input": "2 0",
"output": "2"
},
{
"input": "77 75",
"output": "0"
},
{
"input": "1000000000 1000000000",
"output": "infinity"
}
] | 140 | 1,228,800 | 3 | 5,019 |
|
916 | Jamie and Binary Sequence (changed after round) | [
"bitmasks",
"greedy",
"math"
] | null | null | Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find *k* integers such that the sum of two to the power of each number equals to the number *n* and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.
To be more clear, consider all integer sequence with length *k* (*a*1,<=*a*2,<=...,<=*a**k*) with . Give a value to each sequence. Among all sequence(s) that have the minimum *y* value, output the one that is the lexicographically largest.
For definitions of powers and lexicographical order see notes. | The first line consists of two integers *n* and *k* (1<=≤<=*n*<=≤<=1018,<=1<=≤<=*k*<=≤<=105) — the required sum and the length of the sequence. | Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and *k* numbers separated by space in the second line — the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [<=-<=1018,<=1018]. | [
"23 5\n",
"13 2\n",
"1 2\n"
] | [
"Yes\n3 3 2 1 0 \n",
"No\n",
"Yes\n-1 -1 \n"
] | Sample 1:
2<sup class="upper-index">3</sup> + 2<sup class="upper-index">3</sup> + 2<sup class="upper-index">2</sup> + 2<sup class="upper-index">1</sup> + 2<sup class="upper-index">0</sup> = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1, 1, 0) do not have the minimum *y* value.
Sample 2:
It can be shown there does not exist a sequence with length 2.
Sample 3:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a8539b2d27aefc8d2fab6dfd8296d11c36dcaa40.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Powers of 2:
If *x* > 0, then 2<sup class="upper-index">*x*</sup> = 2·2·2·...·2 (*x* times).
If *x* = 0, then 2<sup class="upper-index">*x*</sup> = 1.
If *x* < 0, then <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/766628f1c7814795eac1a0afaa1ff062c40ef29e.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Lexicographical order:
Given two different sequences of the same length, (*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ... , *a*<sub class="lower-index">*k*</sub>) and (*b*<sub class="lower-index">1</sub>, *b*<sub class="lower-index">2</sub>, ... , *b*<sub class="lower-index">*k*</sub>), the first one is smaller than the second one for the lexicographical order, if and only if *a*<sub class="lower-index">*i*</sub> < *b*<sub class="lower-index">*i*</sub>, for the first *i* where *a*<sub class="lower-index">*i*</sub> and *b*<sub class="lower-index">*i*</sub> differ. | [
{
"input": "23 5",
"output": "Yes\n3 3 2 1 0 "
},
{
"input": "13 2",
"output": "No"
},
{
"input": "1 2",
"output": "Yes\n-1 -1 "
},
{
"input": "1 1",
"output": "Yes\n0 "
},
{
"input": "1000000000000000000 100000",
"output": "Yes\n44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44..."
},
{
"input": "7 2",
"output": "No"
},
{
"input": "7 3",
"output": "Yes\n2 1 0 "
},
{
"input": "7 4",
"output": "Yes\n1 1 1 0 "
},
{
"input": "521325125150442808 10",
"output": "No"
},
{
"input": "498518679725149504 1000",
"output": "Yes\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49..."
},
{
"input": "464823731286228582 100000",
"output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..."
},
{
"input": "1 4",
"output": "Yes\n-2 -2 -2 -2 "
},
{
"input": "9 4",
"output": "Yes\n2 2 -1 -1 "
},
{
"input": "3 4",
"output": "Yes\n0 0 -1 -1 "
},
{
"input": "144 4",
"output": "Yes\n6 6 3 3 "
},
{
"input": "59 4",
"output": "No"
},
{
"input": "78 4",
"output": "Yes\n6 3 2 1 "
},
{
"input": "192 4",
"output": "Yes\n6 6 5 5 "
},
{
"input": "107 4",
"output": "No"
},
{
"input": "552 5",
"output": "Yes\n8 8 5 2 2 "
},
{
"input": "680 5",
"output": "Yes\n8 8 7 5 3 "
},
{
"input": "808 5",
"output": "Yes\n8 8 8 5 3 "
},
{
"input": "1528 5",
"output": "No"
},
{
"input": "1656 5",
"output": "No"
},
{
"input": "26972 8",
"output": "Yes\n14 13 11 8 6 4 3 2 "
},
{
"input": "23100 8",
"output": "Yes\n14 12 11 9 5 4 3 2 "
},
{
"input": "19228 8",
"output": "Yes\n13 13 11 9 8 4 3 2 "
},
{
"input": "22652 8",
"output": "Yes\n14 12 11 6 5 4 3 2 "
},
{
"input": "26076 8",
"output": "No"
},
{
"input": "329438 10",
"output": "Yes\n18 16 10 9 7 6 4 3 2 1 "
},
{
"input": "12862 10",
"output": "Yes\n12 12 12 9 5 4 3 2 0 0 "
},
{
"input": "96286 10",
"output": "Yes\n15 15 14 13 12 11 4 3 2 1 "
},
{
"input": "12414 10",
"output": "Yes\n12 12 12 6 5 4 3 2 0 0 "
},
{
"input": "95838 10",
"output": "No"
},
{
"input": "1728568411 16",
"output": "No"
},
{
"input": "611684539 16",
"output": "Yes\n28 28 26 22 21 20 18 16 15 12 7 5 4 3 1 0 "
},
{
"input": "84735259 16",
"output": "Yes\n25 25 24 19 18 15 14 13 12 10 8 4 3 1 -1 -1 "
},
{
"input": "6967851387 16",
"output": "No"
},
{
"input": "2145934811 16",
"output": "No"
},
{
"input": "6795804571172 20",
"output": "Yes\n41 41 41 37 35 34 33 30 26 24 23 18 14 13 12 10 9 5 1 1 "
},
{
"input": "1038982654596 20",
"output": "Yes\n38 38 38 37 36 32 31 30 29 27 21 20 16 13 11 9 7 1 0 0 "
},
{
"input": "11277865770724 20",
"output": "No"
},
{
"input": "5525338821444 20",
"output": "No"
},
{
"input": "15764221937572 20",
"output": "No"
},
{
"input": "922239521698513045 30",
"output": "Yes\n58 58 58 55 54 51 50 46 45 44 41 40 39 38 37 36 34 32 30 29 28 23 21 19 17 15 7 4 2 0 "
},
{
"input": "923065764876596469 30",
"output": "No"
},
{
"input": "923892008054679893 30",
"output": "No"
},
{
"input": "924718251232763317 30",
"output": "Yes\n58 58 58 55 54 52 50 48 46 41 38 36 35 32 31 29 25 19 18 15 12 11 10 8 7 5 4 2 -1 -1 "
},
{
"input": "925544490115879445 30",
"output": "Yes\n59 58 55 54 52 51 45 44 40 39 38 35 34 33 32 30 28 27 26 24 21 19 18 16 14 12 9 4 2 0 "
},
{
"input": "926370733293962869 30",
"output": "Yes\n57 57 57 57 57 57 55 54 52 51 49 48 45 40 38 34 33 28 27 22 19 18 17 10 9 6 5 4 2 0 "
},
{
"input": "927196976472046293 30",
"output": "No"
},
{
"input": "928023215355162421 30",
"output": "Yes\n58 58 58 55 54 53 48 37 36 33 31 27 26 25 23 19 18 17 16 14 13 11 10 9 8 5 4 2 -1 -1 "
},
{
"input": "928849458533245845 30",
"output": "No"
},
{
"input": "855969764271400156 30",
"output": "No"
},
{
"input": "856796007449483580 30",
"output": "No"
},
{
"input": "857622246332599708 30",
"output": "Yes\n58 58 57 56 55 54 53 50 49 47 46 45 41 39 38 37 33 32 31 29 21 15 11 10 8 7 4 3 1 1 "
},
{
"input": "858448489510683132 30",
"output": "No"
},
{
"input": "859274728393799260 30",
"output": "Yes\n59 57 56 55 54 53 51 50 47 46 40 39 38 36 28 26 25 22 21 16 15 14 13 12 10 9 6 4 3 2 "
},
{
"input": "860100975866849980 30",
"output": "No"
},
{
"input": "860927214749966108 30",
"output": "No"
},
{
"input": "861753457928049532 30",
"output": "Yes\n58 58 57 56 55 54 53 52 50 48 47 44 37 36 34 30 26 25 24 23 22 18 12 9 8 6 5 4 3 2 "
},
{
"input": "862579701106132957 30",
"output": "No"
},
{
"input": "863405944284216381 30",
"output": "No"
},
{
"input": "374585535361966567 30",
"output": "No"
},
{
"input": "4 1",
"output": "Yes\n2 "
},
{
"input": "4 9",
"output": "Yes\n-1 -1 -1 -1 -1 -1 -1 -2 -2 "
},
{
"input": "4 3",
"output": "Yes\n1 0 0 "
},
{
"input": "4 144",
"output": "Yes\n-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 -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 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -21 "
},
{
"input": "4 59",
"output": "Yes\n-3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -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 -30 "
},
{
"input": "4 78",
"output": "Yes\n-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 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 "
},
{
"input": "4 192",
"output": "Yes\n-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 -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 -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 -..."
},
{
"input": "4 107",
"output": "Yes\n-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 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -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 -47 "
},
{
"input": "5 552",
"output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 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-8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8 -8..."
},
{
"input": "8 26972",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 23100",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 19228",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 22652",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "8 26076",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 19354",
"output": "Yes\n-9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9..."
},
{
"input": "23 35482",
"output": "Yes\n-10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -1..."
},
{
"input": "23 18906",
"output": "Yes\n-9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9..."
},
{
"input": "23 2330",
"output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..."
},
{
"input": "23 85754",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 1882",
"output": "Yes\n-6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 -6..."
},
{
"input": "23 85306",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 68730",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 84859",
"output": "Yes\n-11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -11 -1..."
},
{
"input": "23 45148",
"output": "Yes\n-10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -10 -1..."
},
{
"input": "281474976710656 5",
"output": "Yes\n46 46 46 45 45 "
},
{
"input": "288230376151973890 5",
"output": "Yes\n57 57 18 0 0 "
},
{
"input": "36029346774812736 5",
"output": "Yes\n55 39 15 11 6 "
},
{
"input": "901283150305558530 5",
"output": "No"
},
{
"input": "288318372649779720 50",
"output": "Yes\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 46 44 35 30 27 17 14 9 2 1 0 -1 -2 -3 -4 -5 -6 -6 "
},
{
"input": "513703875844698663 50",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 53 48 43 41 39 38 37 36 34 27 26 25 24 22 21 20 18 17 15 14 13 12 9 5 2 1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -9 "
},
{
"input": "287632104387196918 50",
"output": "Yes\n57 56 55 54 53 52 51 50 48 47 46 44 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 13 12 10 9 8 7 6 5 4 2 1 "
},
{
"input": "864690028406636543 58",
"output": "Yes\n58 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 39 38 37 36 35 34 33 32 31 30 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "
},
{
"input": "576460752303423487 60",
"output": "Yes\n57 57 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "
},
{
"input": "141012366262272 1",
"output": "No"
},
{
"input": "1100585377792 4",
"output": "Yes\n39 39 30 13 "
},
{
"input": "18598239186190594 9",
"output": "Yes\n54 49 44 41 40 21 18 8 1 "
},
{
"input": "18647719372456016 19",
"output": "Yes\n51 51 51 51 51 51 51 51 49 46 31 24 20 16 6 3 2 1 1 "
},
{
"input": "9297478914673158 29",
"output": "Yes\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 48 43 33 18 11 9 2 0 -1 -2 -3 -4 -4 "
},
{
"input": "668507368948226 39",
"output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 32 22 16 15 9 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -13 "
},
{
"input": "1143595340402690 49",
"output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 36 35 27 25 19 12 0 -1 -2 -3 -4 -5 -6 -7 -8 -8 "
},
{
"input": "35527987183872 59",
"output": "Yes\n40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 38 36 24 19 18 17 14 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 "
},
{
"input": "324634416758413825 9",
"output": "No"
},
{
"input": "577030480059438572 19",
"output": "Yes\n59 49 42 41 37 35 33 28 26 23 18 12 10 8 7 6 5 3 2 "
},
{
"input": "185505960265024385 29",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 52 49 48 43 42 39 37 36 29 24 22 20 15 9 8 7 -1 -2 -2 "
},
{
"input": "57421517433081233 39",
"output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 51 50 39 36 31 30 28 27 26 24 20 11 10 8 7 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -10 "
},
{
"input": "90131572647657641 49",
"output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 45 44 42 41 37 36 28 25 23 21 20 18 17 7 5 3 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -12 "
},
{
"input": "732268459757413905 59",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 53 51 48 47 43 41 38 35 31 30 28 20 13 10 9 4 -1 -2 -2 "
},
{
"input": "226111453445787190 9",
"output": "No"
},
{
"input": "478818723873062027 19",
"output": "No"
},
{
"input": "337790572680259391 29",
"output": "Yes\n58 55 53 52 44 41 39 37 36 35 34 30 29 28 26 24 20 18 16 13 10 9 8 5 4 3 2 1 0 "
},
{
"input": "168057637182978458 39",
"output": "Yes\n54 54 54 54 54 54 54 54 54 52 50 48 43 42 41 40 39 34 33 32 31 30 28 26 25 20 18 16 13 12 11 8 7 4 3 0 -1 -2 -2 "
},
{
"input": "401486559567818547 49",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 52 49 46 44 43 42 40 39 38 37 34 33 28 26 24 21 17 13 11 10 9 8 5 4 1 -1 -1 "
},
{
"input": "828935109688089201 59",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 47 46 45 44 43 36 34 33 32 29 25 23 22 19 18 17 15 14 12 11 9 6 5 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 "
},
{
"input": "954687629161163764 9",
"output": "No"
},
{
"input": "287025268967992526 19",
"output": "No"
},
{
"input": "844118423640988373 29",
"output": "No"
},
{
"input": "128233154575908599 39",
"output": "Yes\n56 55 54 50 49 48 47 44 41 40 38 36 35 34 33 32 31 30 29 27 25 23 22 21 19 18 15 13 12 11 10 9 7 6 5 4 2 1 0 "
},
{
"input": "792058388714085231 49",
"output": "Yes\n56 56 56 56 56 56 56 56 56 56 55 54 53 52 51 50 48 47 46 45 44 42 39 38 37 35 30 29 28 26 23 21 19 17 16 15 14 12 11 9 8 6 5 3 2 1 -1 -2 -2 "
},
{
"input": "827183623566145225 59",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 54 53 52 51 49 47 45 44 43 42 41 40 36 35 34 33 32 30 29 28 27 26 25 23 21 19 18 17 13 12 10 9 7 6 3 -1 -1 "
},
{
"input": "846113779983498737 9",
"output": "No"
},
{
"input": "780248358343081983 19",
"output": "No"
},
{
"input": "576460580458522095 29",
"output": "No"
},
{
"input": "540145805193625598 39",
"output": "No"
},
{
"input": "576388182371377103 49",
"output": "Yes\n58 57 56 55 54 53 52 51 50 49 48 47 45 44 43 42 40 39 38 37 36 35 34 33 32 30 29 28 27 26 25 23 22 21 20 19 17 15 12 11 10 9 8 7 6 3 2 1 0 "
},
{
"input": "567448991726268409 59",
"output": "Yes\n56 56 56 56 56 56 56 55 54 52 51 50 49 48 47 46 45 44 43 41 40 39 38 36 35 32 31 30 29 28 27 25 24 23 22 21 20 19 18 17 16 14 13 11 10 9 8 7 6 5 4 3 -1 -2 -3 -4 -5 -6 -6 "
},
{
"input": "576460752303423487 9",
"output": "No"
},
{
"input": "576460752303423487 19",
"output": "No"
},
{
"input": "864691128455135231 29",
"output": "No"
},
{
"input": "864691128455135231 39",
"output": "No"
},
{
"input": "576460752303423487 49",
"output": "No"
},
{
"input": "864691128455135231 59",
"output": "Yes\n59 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "
},
{
"input": "628839188486443015 2412",
"output": "Yes\n48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48..."
},
{
"input": "558445254282313727 89558",
"output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..."
},
{
"input": "576460752303423487 100000",
"output": "Yes\n43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43..."
},
{
"input": "1 100000",
"output": "Yes\n-16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -16 -1..."
},
{
"input": "99997 100000",
"output": "Yes\n0 0 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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..."
},
{
"input": "1 4",
"output": "Yes\n-2 -2 -2 -2 "
},
{
"input": "2 64",
"output": "Yes\n-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 "
},
{
"input": "2 8",
"output": "Yes\n-2 -2 -2 -2 -2 -2 -2 -2 "
},
{
"input": "1 5",
"output": "Yes\n-2 -2 -2 -3 -3 "
},
{
"input": "1 7",
"output": "Yes\n-2 -2 -2 -3 -4 -5 -5 "
},
{
"input": "19 5",
"output": "Yes\n3 3 1 -1 -1 "
},
{
"input": "1 30",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 "
}
] | 62 | 19,865,600 | 0 | 5,024 |
|
55 | Flea travel | [
"implementation",
"math"
] | A. Flea travel | 1 | 256 | A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that flea has infinitely much time for this jumping. | The only line contains single integer: 1<=≤<=*n*<=≤<=1000 — number of hassocks. | Output "YES" if all the hassocks will be visited and "NO" otherwise. | [
"1\n",
"3\n"
] | [
"YES\n",
"NO\n"
] | none | [
{
"input": "1",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "YES"
},
{
"input": "4",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "8",
"output": "YES"
},
{
"input": "9",
"output": "NO"
},
{
"input": "10",
"output": "NO"
},
{
"input": "11",
"output": "NO"
},
{
"input": "12",
"output": "NO"
},
{
"input": "13",
"output": "NO"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "16",
"output": "YES"
},
{
"input": "17",
"output": "NO"
},
{
"input": "18",
"output": "NO"
},
{
"input": "19",
"output": "NO"
},
{
"input": "20",
"output": "NO"
},
{
"input": "21",
"output": "NO"
},
{
"input": "22",
"output": "NO"
},
{
"input": "23",
"output": "NO"
},
{
"input": "24",
"output": "NO"
},
{
"input": "25",
"output": "NO"
},
{
"input": "26",
"output": "NO"
},
{
"input": "27",
"output": "NO"
},
{
"input": "28",
"output": "NO"
},
{
"input": "29",
"output": "NO"
},
{
"input": "30",
"output": "NO"
},
{
"input": "31",
"output": "NO"
},
{
"input": "32",
"output": "YES"
},
{
"input": "33",
"output": "NO"
},
{
"input": "34",
"output": "NO"
},
{
"input": "35",
"output": "NO"
},
{
"input": "36",
"output": "NO"
},
{
"input": "37",
"output": "NO"
},
{
"input": "38",
"output": "NO"
},
{
"input": "39",
"output": "NO"
},
{
"input": "40",
"output": "NO"
},
{
"input": "41",
"output": "NO"
},
{
"input": "42",
"output": "NO"
},
{
"input": "43",
"output": "NO"
},
{
"input": "44",
"output": "NO"
},
{
"input": "45",
"output": "NO"
},
{
"input": "46",
"output": "NO"
},
{
"input": "47",
"output": "NO"
},
{
"input": "48",
"output": "NO"
},
{
"input": "49",
"output": "NO"
},
{
"input": "50",
"output": "NO"
},
{
"input": "64",
"output": "YES"
},
{
"input": "289",
"output": "NO"
},
{
"input": "170",
"output": "NO"
},
{
"input": "639",
"output": "NO"
},
{
"input": "700",
"output": "NO"
},
{
"input": "95",
"output": "NO"
},
{
"input": "240",
"output": "NO"
},
{
"input": "1000",
"output": "NO"
},
{
"input": "200",
"output": "NO"
},
{
"input": "57",
"output": "NO"
},
{
"input": "871",
"output": "NO"
},
{
"input": "840",
"output": "NO"
},
{
"input": "705",
"output": "NO"
},
{
"input": "685",
"output": "NO"
},
{
"input": "213",
"output": "NO"
},
{
"input": "665",
"output": "NO"
},
{
"input": "868",
"output": "NO"
},
{
"input": "897",
"output": "NO"
},
{
"input": "61",
"output": "NO"
},
{
"input": "817",
"output": "NO"
},
{
"input": "688",
"output": "NO"
},
{
"input": "580",
"output": "NO"
},
{
"input": "373",
"output": "NO"
},
{
"input": "613",
"output": "NO"
},
{
"input": "685",
"output": "NO"
},
{
"input": "116",
"output": "NO"
},
{
"input": "518",
"output": "NO"
},
{
"input": "383",
"output": "NO"
},
{
"input": "260",
"output": "NO"
},
{
"input": "728",
"output": "NO"
},
{
"input": "1000",
"output": "NO"
},
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "YES"
}
] | 46 | 4,608,000 | 0 | 5,026 |
459 | Pashmak and Buses | [
"combinatorics",
"constructive algorithms",
"math"
] | null | null | Recently Pashmak has been employed in a transportation company. The company has *k* buses and has a contract with a school which has *n* students. The school planned to take the students to *d* different places for *d* days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all *d* days.
Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity. | The first line of input contains three space-separated integers *n*,<=*k*,<=*d* (1<=≤<=*n*,<=*d*<=≤<=1000; 1<=≤<=*k*<=≤<=109). | If there is no valid arrangement just print -1. Otherwise print *d* lines, in each of them print *n* integers. The *j*-th integer of the *i*-th line shows which bus the *j*-th student has to take on the *i*-th day. You can assume that the buses are numbered from 1 to *k*. | [
"3 2 2\n",
"3 2 1\n"
] | [
"1 1 2 \n1 2 1 \n",
"-1\n"
] | Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day. | [
{
"input": "3 2 2",
"output": "1 1 2 \n1 2 1 "
},
{
"input": "3 2 1",
"output": "-1"
},
{
"input": "7 2 3",
"output": "1 1 1 1 2 2 2 \n1 1 2 2 1 1 2 \n1 2 1 2 1 2 1 "
},
{
"input": "9 2 3",
"output": "-1"
},
{
"input": "2 1 1000",
"output": "-1"
},
{
"input": "512 2 9",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "1000 1000000000 511",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "1000 1000 1",
"output": "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..."
},
{
"input": "1000 3 1000",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1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 1 1 1 1 1 1 1 1 1 1 1 1 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 \n1 1 1 1 1 1 1 1 1 1 1 1..."
},
{
"input": "244 3 5",
"output": "-1"
},
{
"input": "999 999 1",
"output": "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..."
},
{
"input": "1000 999 1",
"output": "-1"
},
{
"input": "343 7 3",
"output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 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1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3..."
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "1 1 2",
"output": "1 \n1 "
},
{
"input": "2 1 1",
"output": "-1"
},
{
"input": "1 2 1",
"output": "1 "
},
{
"input": "5 3 2",
"output": "1 1 1 2 2 \n1 2 3 1 2 "
},
{
"input": "1 1000000000 1",
"output": "1 "
},
{
"input": "1000 1000000000 1",
"output": "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..."
},
{
"input": "27 3 3",
"output": "1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 \n1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 \n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 "
},
{
"input": "1 1 10",
"output": "1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 \n1 "
}
] | 639 | 17,408,000 | 3 | 5,028 |
|
484 | Maximum Value | [
"binary search",
"math",
"sortings",
"two pointers"
] | null | null | You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*. | The first line contains integer *n* — the length of the sequence (1<=≤<=*n*<=≤<=2·105).
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=106). | Print the answer to the problem. | [
"3\n3 4 5\n"
] | [
"2\n"
] | none | [
{
"input": "3\n3 4 5",
"output": "2"
},
{
"input": "3\n1 2 4",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "2\n1000000 999999",
"output": "1"
},
{
"input": "12\n4 4 10 13 28 30 41 43 58 61 70 88",
"output": "30"
},
{
"input": "7\n2 13 22 32 72 91 96",
"output": "27"
},
{
"input": "5\n5 11 12 109 110",
"output": "10"
}
] | 1,000 | 11,264,000 | 0 | 5,038 |
|
178 | Educational Game | [
"greedy"
] | null | null | The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of *n* non-negative integers *a**i* numbered from 1 to *n*. The goal of the game is to make numbers *a*1,<=*a*2,<=...,<=*a**k* (i.e. some prefix of the sequence) equal to zero for some fixed *k* (*k*<=<<=*n*), and this should be done in the smallest possible number of moves.
One move is choosing an integer *i* (1<=≤<=*i*<=≤<=*n*) such that *a**i*<=><=0 and an integer *t* (*t*<=≥<=0) such that *i*<=+<=2*t*<=≤<=*n*. After the values of *i* and *t* have been selected, the value of *a**i* is decreased by 1, and the value of *a**i*<=+<=2*t* is increased by 1. For example, let *n*<==<=4 and *a*<==<=(1,<=0,<=1,<=2), then it is possible to make move *i*<==<=3, *t*<==<=0 and get *a*<==<=(1,<=0,<=0,<=3) or to make move *i*<==<=1, *t*<==<=1 and get *a*<==<=(0,<=0,<=2,<=2) (the only possible other move is *i*<==<=1, *t*<==<=0).
You are given *n* and the initial sequence *a**i*. The task is to calculate the minimum number of moves needed to make the first *k* elements of the original sequence equal to zero for each possible *k* (1<=≤<=*k*<=<<=*n*). | The first input line contains a single integer *n*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=104), separated by single spaces.
The input limitations for getting 20 points are:
- 1<=≤<=*n*<=≤<=300
The input limitations for getting 50 points are:
- 1<=≤<=*n*<=≤<=2000
The input limitations for getting 100 points are:
- 1<=≤<=*n*<=≤<=105 | Print exactly *n*<=-<=1 lines: the *k*-th output line must contain the minimum number of moves needed to make the first *k* elements of the original sequence *a**i* equal to zero.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier. | [
"4\n1 0 1 2\n",
"8\n1 2 3 4 5 6 7 8\n"
] | [
"1\n1\n3\n",
"1\n3\n6\n10\n16\n24\n40\n"
] | none | [
{
"input": "4\n1 0 1 2",
"output": "1\n1\n3"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1\n3\n6\n10\n16\n24\n40"
},
{
"input": "5\n4 1 4 7 6",
"output": "4\n5\n9\n17"
},
{
"input": "9\n13 13 7 11 3 9 3 5 5",
"output": "13\n26\n33\n44\n47\n69\n79\n117"
},
{
"input": "30\n8 17 20 15 18 15 20 10 5 13 5 4 15 9 11 14 18 15 7 16 18 9 17 7 10 9 5 13 17 16",
"output": "8\n25\n45\n60\n78\n93\n113\n123\n128\n141\n146\n150\n165\n174\n185\n199\n225\n257\n284\n315\n351\n375\n423\n454\n495\n549\n634\n713\n907"
},
{
"input": "80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 20 36 70 66 75 12 54 96",
"output": "72\n138\n220\n266\n310\n332\n395\n487\n558\n623\n628\n658\n703\n787\n816\n889\n898\n988\n1013\n1032\n1058\n1073\n1085\n1114\n1147\n1166\n1251\n1343\n1434\n1500\n1583\n1622\n1722\n1775\n1795\n1894\n1905\n1986\n2012\n2053\n2089\n2140\n2161\n2233\n2261\n2361\n2395\n2398\n2431\n2579\n2615\n2719\n2818\n2851\n2867\n2941\n3064\n3182\n3309\n3486\n3603\n3740\n3881\n3969\n4250\n4549\n4775\n5037\n5231\n5465\n5627\n5929\n6460\n7029\n7478\n8085\n9075\n10211\n12070"
},
{
"input": "120\n242 524 420 973 816 432 247 666 134 849 145 366 608 930 613 315 863 628 97 109 65 704 741 314 736 17 872 971 559 648 223 771 171 327 782 837 303 393 292 339 730 834 794 868 540 251 789 893 23 305 116 220 699 863 580 992 861 393 98 253 544 171 336 207 348 496 316 285 286 727 613 616 304 811 592 916 91 554 962 950 475 473 806 510 986 254 290 351 143 710 573 949 256 216 235 246 533 177 12 764 543 689 490 386 849 694 386 693 134 416 293 589 171 76 527 324 782 661 943 134",
"output": "242\n766\n1186\n2159\n2975\n3407\n3654\n4320\n4454\n5303\n5448\n5814\n6422\n7352\n7965\n8280\n9143\n9771\n9868\n9977\n10042\n10746\n11487\n11801\n12537\n12554\n13426\n14397\n14956\n15604\n15827\n16598\n16769\n17096\n17878\n18715\n19018\n19411\n19703\n20042\n20772\n21606\n22400\n23268\n23808\n24059\n24848\n25741\n25764\n26069\n26185\n26405\n27104\n27967\n28547\n29539\n30400\n30793\n30891\n31144\n31688\n31859\n32195\n32402\n32992\n34012\n34748\n36006\n37108\n38267\n39127\n40409\n40847\n42507\n43244\n44526\n4..."
}
] | 1,840 | 6,451,200 | 3 | 5,044 |
|
216 | Tiling with Hexagons | [
"implementation",
"math"
] | null | null | Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.
The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has *a*, *b*, *c*, *a*, *b* and *c* adjacent tiles, correspondingly.
To better visualize the situation, look at the picture showing a similar hexagon for *a*<==<=2, *b*<==<=3 and *c*<==<=4.
According to the legend, as the King of Berland obtained the values *a*, *b* and *c*, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same? | The first line contains three integers: *a*, *b* and *c* (2<=≤<=*a*,<=*b*,<=*c*<=≤<=1000). | Print a single number — the total number of tiles on the hall floor. | [
"2 3 4\n"
] | [
"18"
] | none | [
{
"input": "2 3 4",
"output": "18"
},
{
"input": "2 2 2",
"output": "7"
},
{
"input": "7 8 13",
"output": "224"
},
{
"input": "14 7 75",
"output": "1578"
},
{
"input": "201 108 304",
"output": "115032"
},
{
"input": "999 998 996",
"output": "2983022"
},
{
"input": "2 2 3",
"output": "10"
},
{
"input": "2 3 2",
"output": "10"
},
{
"input": "3 2 2",
"output": "10"
},
{
"input": "2 3 3",
"output": "14"
},
{
"input": "3 2 3",
"output": "14"
},
{
"input": "3 3 2",
"output": "14"
},
{
"input": "3 3 3",
"output": "19"
},
{
"input": "4 5 3",
"output": "36"
},
{
"input": "2 2 856",
"output": "2569"
},
{
"input": "2 986 2",
"output": "2959"
},
{
"input": "985 2 2",
"output": "2956"
},
{
"input": "2 958 983",
"output": "943654"
},
{
"input": "992 2 912",
"output": "906607"
},
{
"input": "789 894 2",
"output": "707048"
},
{
"input": "1000 1000 1000",
"output": "2997001"
},
{
"input": "384 458 284",
"output": "413875"
},
{
"input": "709 14 290",
"output": "218584"
},
{
"input": "485 117 521",
"output": "369265"
},
{
"input": "849 333 102",
"output": "401998"
},
{
"input": "998 999 1000",
"output": "2991006"
},
{
"input": "2 2 1000",
"output": "3001"
},
{
"input": "2 1000 2",
"output": "3001"
},
{
"input": "1000 2 2",
"output": "3001"
},
{
"input": "1000 2 1000",
"output": "1001999"
},
{
"input": "865 291 383",
"output": "692925"
},
{
"input": "41 49 28",
"output": "4412"
},
{
"input": "34 86 90",
"output": "13515"
},
{
"input": "39 23 56",
"output": "4252"
},
{
"input": "14 99 81",
"output": "10346"
},
{
"input": "48 38 193",
"output": "18144"
},
{
"input": "395 85 22",
"output": "43634"
},
{
"input": "38 291 89",
"output": "39922"
},
{
"input": "7 23 595",
"output": "17387"
},
{
"input": "948 48 3",
"output": "47494"
}
] | 154 | 0 | 0 | 5,047 |
|
230 | Dragons | [
"greedy",
"sortings"
] | null | null | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals *s*.
If Kirito starts duelling with the *i*-th (1<=≤<=*i*<=≤<=*n*) dragon and Kirito's strength is not greater than the dragon's strength *x**i*, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by *y**i*.
Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss. | The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | [
"2 2\n1 99\n100 0\n",
"10 1\n100 100\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength is too small to defeat the only dragon and win. | [
{
"input": "2 2\n1 99\n100 0",
"output": "YES"
},
{
"input": "10 1\n100 100",
"output": "NO"
},
{
"input": "123 2\n78 10\n130 0",
"output": "YES"
},
{
"input": "999 2\n1010 10\n67 89",
"output": "YES"
},
{
"input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1",
"output": "YES"
},
{
"input": "2 2\n3 5\n1 2",
"output": "YES"
},
{
"input": "1 2\n1 0\n1 0",
"output": "NO"
},
{
"input": "5 10\n20 1\n4 3\n5 1\n100 1\n4 2\n101 1\n10 0\n10 2\n17 3\n12 84",
"output": "YES"
},
{
"input": "2 2\n1 98\n100 0",
"output": "NO"
},
{
"input": "2 2\n1 2\n3 5",
"output": "YES"
},
{
"input": "5 3\n13 20\n3 10\n15 5",
"output": "YES"
},
{
"input": "2 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n4 0",
"output": "YES"
},
{
"input": "10 4\n20 1\n3 5\n2 4\n1 3",
"output": "YES"
},
{
"input": "10 1\n1 1",
"output": "YES"
},
{
"input": "4 1\n100 1000",
"output": "NO"
},
{
"input": "5 1\n6 7",
"output": "NO"
},
{
"input": "10 1\n10 10",
"output": "NO"
},
{
"input": "6 2\n496 0\n28 8128",
"output": "NO"
},
{
"input": "4 2\n2 1\n10 3",
"output": "NO"
},
{
"input": "11 2\n22 0\n33 0",
"output": "NO"
},
{
"input": "1 2\n100 1\n100 1",
"output": "NO"
},
{
"input": "10 3\n12 0\n13 0\n14 0",
"output": "NO"
},
{
"input": "50 3\n39 0\n38 0\n37 0",
"output": "YES"
},
{
"input": "14 3\n1 5\n1 6\n1 7",
"output": "YES"
},
{
"input": "1 3\n1 10\n1 11\n1 9",
"output": "NO"
},
{
"input": "10 10\n2 10\n3 10\n4 10\n2 20\n3 20\n3 20\n100 50\n100 30\n150 30\n200 10",
"output": "NO"
},
{
"input": "9983 34\n6626 5976\n4448 3568\n2794 2309\n3741 8806\n4754 129\n2780 9275\n5785 9243\n3915 6159\n2609 4331\n238 6756\n6987 3887\n3384 5711\n4349 5563\n1135 4483\n9151 1584\n1500 766\n1608 4440\n7768 5005\n7205 2360\n9088 2933\n3923 7814\n7538 9372\n7504 165\n5277 1636\n2061 4384\n7668 1422\n9582 2121\n5483 7967\n487 2944\n7432 5794\n8208 8970\n5747 3800\n4322 3920\n8261 9319",
"output": "YES"
},
{
"input": "1 10\n8 8\n54 3\n1 8\n26 3\n16 1\n29 9\n38 10\n57 8\n48 6\n17 9",
"output": "NO"
},
{
"input": "5 10\n7 0\n7 0\n10 0\n10 0\n7 2\n4 2\n9 0\n6 1\n7 0\n7 0",
"output": "NO"
},
{
"input": "2 3\n1 1\n1 10\n17 2",
"output": "NO"
},
{
"input": "100 5\n99 100\n199 1\n199 1\n199 1\n202 1",
"output": "YES"
},
{
"input": "1 1\n10000 1",
"output": "NO"
}
] | 92 | 0 | 0 | 5,049 |
|
714 | Filya and Homework | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than once), subtract *x* from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer *x* and change some elements of the array using this *x* in order to make all elements equal. | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"output": "YES"
},
{
"input": "4\n1 2 3 4",
"output": "NO"
},
{
"input": "10\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "2\n4 2",
"output": "YES"
},
{
"input": "4\n1 1 4 7",
"output": "YES"
},
{
"input": "3\n99999999 1 50000000",
"output": "YES"
},
{
"input": "1\n0",
"output": "YES"
},
{
"input": "5\n0 0 0 0 0",
"output": "YES"
},
{
"input": "4\n4 2 2 1",
"output": "NO"
},
{
"input": "3\n1 4 2",
"output": "NO"
},
{
"input": "3\n1 4 100",
"output": "NO"
},
{
"input": "3\n2 5 11",
"output": "NO"
},
{
"input": "3\n1 4 6",
"output": "NO"
},
{
"input": "3\n1 2 4",
"output": "NO"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "5\n1 1 1 4 5",
"output": "NO"
},
{
"input": "2\n100000001 100000003",
"output": "YES"
},
{
"input": "3\n7 4 5",
"output": "NO"
},
{
"input": "3\n2 3 5",
"output": "NO"
},
{
"input": "3\n1 2 5",
"output": "NO"
},
{
"input": "2\n2 3",
"output": "YES"
},
{
"input": "3\n2 100 29",
"output": "NO"
},
{
"input": "3\n0 1 5",
"output": "NO"
},
{
"input": "3\n1 3 6",
"output": "NO"
},
{
"input": "3\n2 1 3",
"output": "YES"
},
{
"input": "3\n1 5 100",
"output": "NO"
},
{
"input": "3\n1 4 8",
"output": "NO"
},
{
"input": "3\n1 7 10",
"output": "NO"
},
{
"input": "3\n5 4 1",
"output": "NO"
},
{
"input": "3\n1 6 10",
"output": "NO"
},
{
"input": "4\n1 3 4 5",
"output": "NO"
},
{
"input": "3\n1 5 4",
"output": "NO"
},
{
"input": "5\n1 2 3 3 5",
"output": "NO"
},
{
"input": "3\n2 3 1",
"output": "YES"
},
{
"input": "3\n2 3 8",
"output": "NO"
},
{
"input": "3\n0 3 5",
"output": "NO"
},
{
"input": "3\n1 5 10",
"output": "NO"
},
{
"input": "3\n1 7 2",
"output": "NO"
},
{
"input": "3\n1 3 9",
"output": "NO"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "7\n1 1 1 1 1 2 4",
"output": "NO"
},
{
"input": "5\n1 4 4 4 6",
"output": "NO"
},
{
"input": "5\n1 2 2 4 4",
"output": "NO"
},
{
"input": "3\n1 9 10",
"output": "NO"
},
{
"input": "8\n1 1 1 1 1 1 2 3",
"output": "YES"
},
{
"input": "3\n1 2 100",
"output": "NO"
},
{
"input": "3\n1 3 4",
"output": "NO"
},
{
"input": "3\n1 15 14",
"output": "NO"
},
{
"input": "3\n1 3 8",
"output": "NO"
},
{
"input": "3\n1 2 10",
"output": "NO"
},
{
"input": "4\n2 2 4 5",
"output": "NO"
},
{
"input": "3\n1 3 5",
"output": "YES"
},
{
"input": "5\n3 6 7 8 9",
"output": "NO"
},
{
"input": "3\n7 6 8",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 2 2 3",
"output": "YES"
},
{
"input": "3\n4 6 7",
"output": "NO"
},
{
"input": "3\n2 0 4",
"output": "YES"
},
{
"input": "4\n10 20 21 30",
"output": "NO"
},
{
"input": "4\n0 2 3 4",
"output": "NO"
},
{
"input": "3\n3 6 12",
"output": "NO"
},
{
"input": "5\n0 0 1 3 5",
"output": "NO"
},
{
"input": "3\n3 5 8",
"output": "NO"
},
{
"input": "3\n1 4 4",
"output": "YES"
},
{
"input": "4\n2 4 5 6",
"output": "NO"
}
] | 171 | 13,312,000 | 3 | 5,054 |
|
286 | Lucky Permutation | [
"constructive algorithms",
"math"
] | null | null | A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=≤<=*p**i*<=≤<=*n*).
A lucky permutation is such permutation *p*, that any integer *i* (1<=≤<=*i*<=≤<=*n*) meets this condition *p**p**i*<==<=*n*<=-<=*i*<=+<=1.
You have integer *n*. Find some lucky permutation *p* of size *n*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the required permutation size. | Print "-1" (without the quotes) if the lucky permutation *p* of size *n* doesn't exist.
Otherwise, print *n* distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) after a space — the required permutation.
If there are multiple answers, you can print any of them. | [
"1\n",
"2\n",
"4\n",
"5\n"
] | [
"1 \n",
"-1\n",
"2 4 1 3 \n",
"2 5 3 1 4 \n"
] | none | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "-1"
},
{
"input": "4",
"output": "2 4 1 3 "
},
{
"input": "5",
"output": "2 5 3 1 4 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "100000",
"output": "2 100000 4 99998 6 99996 8 99994 10 99992 12 99990 14 99988 16 99986 18 99984 20 99982 22 99980 24 99978 26 99976 28 99974 30 99972 32 99970 34 99968 36 99966 38 99964 40 99962 42 99960 44 99958 46 99956 48 99954 50 99952 52 99950 54 99948 56 99946 58 99944 60 99942 62 99940 64 99938 66 99936 68 99934 70 99932 72 99930 74 99928 76 99926 78 99924 80 99922 82 99920 84 99918 86 99916 88 99914 90 99912 92 99910 94 99908 96 99906 98 99904 100 99902 102 99900 104 99898 106 99896 108 99894 110 99892 112 99890 114..."
},
{
"input": "6",
"output": "-1"
},
{
"input": "7",
"output": "-1"
},
{
"input": "8",
"output": "2 8 4 6 3 5 1 7 "
},
{
"input": "9",
"output": "2 9 4 7 5 3 6 1 8 "
},
{
"input": "99997",
"output": "2 99997 4 99995 6 99993 8 99991 10 99989 12 99987 14 99985 16 99983 18 99981 20 99979 22 99977 24 99975 26 99973 28 99971 30 99969 32 99967 34 99965 36 99963 38 99961 40 99959 42 99957 44 99955 46 99953 48 99951 50 99949 52 99947 54 99945 56 99943 58 99941 60 99939 62 99937 64 99935 66 99933 68 99931 70 99929 72 99927 74 99925 76 99923 78 99921 80 99919 82 99917 84 99915 86 99913 88 99911 90 99909 92 99907 94 99905 96 99903 98 99901 100 99899 102 99897 104 99895 106 99893 108 99891 110 99889 112 99887 114 ..."
},
{
"input": "10000",
"output": "2 10000 4 9998 6 9996 8 9994 10 9992 12 9990 14 9988 16 9986 18 9984 20 9982 22 9980 24 9978 26 9976 28 9974 30 9972 32 9970 34 9968 36 9966 38 9964 40 9962 42 9960 44 9958 46 9956 48 9954 50 9952 52 9950 54 9948 56 9946 58 9944 60 9942 62 9940 64 9938 66 9936 68 9934 70 9932 72 9930 74 9928 76 9926 78 9924 80 9922 82 9920 84 9918 86 9916 88 9914 90 9912 92 9910 94 9908 96 9906 98 9904 100 9902 102 9900 104 9898 106 9896 108 9894 110 9892 112 9890 114 9888 116 9886 118 9884 120 9882 122 9880 124 9878 126 9..."
},
{
"input": "10001",
"output": "2 10001 4 9999 6 9997 8 9995 10 9993 12 9991 14 9989 16 9987 18 9985 20 9983 22 9981 24 9979 26 9977 28 9975 30 9973 32 9971 34 9969 36 9967 38 9965 40 9963 42 9961 44 9959 46 9957 48 9955 50 9953 52 9951 54 9949 56 9947 58 9945 60 9943 62 9941 64 9939 66 9937 68 9935 70 9933 72 9931 74 9929 76 9927 78 9925 80 9923 82 9921 84 9919 86 9917 88 9915 90 9913 92 9911 94 9909 96 9907 98 9905 100 9903 102 9901 104 9899 106 9897 108 9895 110 9893 112 9891 114 9889 116 9887 118 9885 120 9883 122 9881 124 9879 126 9..."
},
{
"input": "10002",
"output": "-1"
},
{
"input": "10003",
"output": "-1"
},
{
"input": "10004",
"output": "2 10004 4 10002 6 10000 8 9998 10 9996 12 9994 14 9992 16 9990 18 9988 20 9986 22 9984 24 9982 26 9980 28 9978 30 9976 32 9974 34 9972 36 9970 38 9968 40 9966 42 9964 44 9962 46 9960 48 9958 50 9956 52 9954 54 9952 56 9950 58 9948 60 9946 62 9944 64 9942 66 9940 68 9938 70 9936 72 9934 74 9932 76 9930 78 9928 80 9926 82 9924 84 9922 86 9920 88 9918 90 9916 92 9914 94 9912 96 9910 98 9908 100 9906 102 9904 104 9902 106 9900 108 9898 110 9896 112 9894 114 9892 116 9890 118 9888 120 9886 122 9884 124 9882 126..."
},
{
"input": "25",
"output": "2 25 4 23 6 21 8 19 10 17 12 15 13 11 14 9 16 7 18 5 20 3 22 1 24 "
},
{
"input": "29",
"output": "2 29 4 27 6 25 8 23 10 21 12 19 14 17 15 13 16 11 18 9 20 7 22 5 24 3 26 1 28 "
},
{
"input": "33",
"output": "2 33 4 31 6 29 8 27 10 25 12 23 14 21 16 19 17 15 18 13 20 11 22 9 24 7 26 5 28 3 30 1 32 "
},
{
"input": "9",
"output": "2 9 4 7 5 3 6 1 8 "
},
{
"input": "13",
"output": "2 13 4 11 6 9 7 5 8 3 10 1 12 "
},
{
"input": "17",
"output": "2 17 4 15 6 13 8 11 9 7 10 5 12 3 14 1 16 "
},
{
"input": "50001",
"output": "2 50001 4 49999 6 49997 8 49995 10 49993 12 49991 14 49989 16 49987 18 49985 20 49983 22 49981 24 49979 26 49977 28 49975 30 49973 32 49971 34 49969 36 49967 38 49965 40 49963 42 49961 44 49959 46 49957 48 49955 50 49953 52 49951 54 49949 56 49947 58 49945 60 49943 62 49941 64 49939 66 49937 68 49935 70 49933 72 49931 74 49929 76 49927 78 49925 80 49923 82 49921 84 49919 86 49917 88 49915 90 49913 92 49911 94 49909 96 49907 98 49905 100 49903 102 49901 104 49899 106 49897 108 49895 110 49893 112 49891 114 ..."
},
{
"input": "20001",
"output": "2 20001 4 19999 6 19997 8 19995 10 19993 12 19991 14 19989 16 19987 18 19985 20 19983 22 19981 24 19979 26 19977 28 19975 30 19973 32 19971 34 19969 36 19967 38 19965 40 19963 42 19961 44 19959 46 19957 48 19955 50 19953 52 19951 54 19949 56 19947 58 19945 60 19943 62 19941 64 19939 66 19937 68 19935 70 19933 72 19931 74 19929 76 19927 78 19925 80 19923 82 19921 84 19919 86 19917 88 19915 90 19913 92 19911 94 19909 96 19907 98 19905 100 19903 102 19901 104 19899 106 19897 108 19895 110 19893 112 19891 114 ..."
},
{
"input": "30001",
"output": "2 30001 4 29999 6 29997 8 29995 10 29993 12 29991 14 29989 16 29987 18 29985 20 29983 22 29981 24 29979 26 29977 28 29975 30 29973 32 29971 34 29969 36 29967 38 29965 40 29963 42 29961 44 29959 46 29957 48 29955 50 29953 52 29951 54 29949 56 29947 58 29945 60 29943 62 29941 64 29939 66 29937 68 29935 70 29933 72 29931 74 29929 76 29927 78 29925 80 29923 82 29921 84 29919 86 29917 88 29915 90 29913 92 29911 94 29909 96 29907 98 29905 100 29903 102 29901 104 29899 106 29897 108 29895 110 29893 112 29891 114 ..."
},
{
"input": "99996",
"output": "2 99996 4 99994 6 99992 8 99990 10 99988 12 99986 14 99984 16 99982 18 99980 20 99978 22 99976 24 99974 26 99972 28 99970 30 99968 32 99966 34 99964 36 99962 38 99960 40 99958 42 99956 44 99954 46 99952 48 99950 50 99948 52 99946 54 99944 56 99942 58 99940 60 99938 62 99936 64 99934 66 99932 68 99930 70 99928 72 99926 74 99924 76 99922 78 99920 80 99918 82 99916 84 99914 86 99912 88 99910 90 99908 92 99906 94 99904 96 99902 98 99900 100 99898 102 99896 104 99894 106 99892 108 99890 110 99888 112 99886 114 ..."
},
{
"input": "99999",
"output": "-1"
},
{
"input": "101",
"output": "2 101 4 99 6 97 8 95 10 93 12 91 14 89 16 87 18 85 20 83 22 81 24 79 26 77 28 75 30 73 32 71 34 69 36 67 38 65 40 63 42 61 44 59 46 57 48 55 50 53 51 49 52 47 54 45 56 43 58 41 60 39 62 37 64 35 66 33 68 31 70 29 72 27 74 25 76 23 78 21 80 19 82 17 84 15 86 13 88 11 90 9 92 7 94 5 96 3 98 1 100 "
},
{
"input": "505",
"output": "2 505 4 503 6 501 8 499 10 497 12 495 14 493 16 491 18 489 20 487 22 485 24 483 26 481 28 479 30 477 32 475 34 473 36 471 38 469 40 467 42 465 44 463 46 461 48 459 50 457 52 455 54 453 56 451 58 449 60 447 62 445 64 443 66 441 68 439 70 437 72 435 74 433 76 431 78 429 80 427 82 425 84 423 86 421 88 419 90 417 92 415 94 413 96 411 98 409 100 407 102 405 104 403 106 401 108 399 110 397 112 395 114 393 116 391 118 389 120 387 122 385 124 383 126 381 128 379 130 377 132 375 134 373 136 371 138 369 140 367 142 ..."
},
{
"input": "565",
"output": "2 565 4 563 6 561 8 559 10 557 12 555 14 553 16 551 18 549 20 547 22 545 24 543 26 541 28 539 30 537 32 535 34 533 36 531 38 529 40 527 42 525 44 523 46 521 48 519 50 517 52 515 54 513 56 511 58 509 60 507 62 505 64 503 66 501 68 499 70 497 72 495 74 493 76 491 78 489 80 487 82 485 84 483 86 481 88 479 90 477 92 475 94 473 96 471 98 469 100 467 102 465 104 463 106 461 108 459 110 457 112 455 114 453 116 451 118 449 120 447 122 445 124 443 126 441 128 439 130 437 132 435 134 433 136 431 138 429 140 427 142 ..."
}
] | 312 | 409,600 | 0 | 5,078 |
|
749 | Parallelogram is Back | [
"brute force",
"constructive algorithms",
"geometry"
] | null | null | Long time ago Alex created an interesting problem about parallelogram. The input data for this problem contained four integer points on the Cartesian plane, that defined the set of vertices of some non-degenerate (positive area) parallelogram. Points not necessary were given in the order of clockwise or counterclockwise traversal.
Alex had very nice test for this problem, but is somehow happened that the last line of the input was lost and now he has only three out of four points of the original parallelogram. He remembers that test was so good that he asks you to restore it given only these three points. | The input consists of three lines, each containing a pair of integer coordinates *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000). It's guaranteed that these three points do not lie on the same line and no two of them coincide. | First print integer *k* — the number of ways to add one new integer point such that the obtained set defines some parallelogram of positive area. There is no requirement for the points to be arranged in any special order (like traversal), they just define the set of vertices.
Then print *k* lines, each containing a pair of integer — possible coordinates of the fourth point. | [
"0 0\n1 0\n0 1\n"
] | [
"3\n1 -1\n-1 1\n1 1\n"
] | If you need clarification of what parallelogram is, please check Wikipedia page:
https://en.wikipedia.org/wiki/Parallelogram | [
{
"input": "0 0\n1 0\n0 1",
"output": "3\n1 -1\n-1 1\n1 1"
},
{
"input": "0 -1\n-1 0\n1 1",
"output": "3\n-2 -2\n2 0\n0 2"
},
{
"input": "-1 -1\n0 1\n1 1",
"output": "3\n-2 -1\n0 -1\n2 3"
},
{
"input": "1000 1000\n-1000 -1000\n-1000 1000",
"output": "3\n1000 -1000\n1000 3000\n-3000 -1000"
},
{
"input": "-1000 1000\n1000 -1000\n-1000 -1000",
"output": "3\n1000 1000\n-3000 1000\n1000 -3000"
},
{
"input": "-4 -5\n7 10\n3 -10",
"output": "3\n0 15\n-8 -25\n14 5"
},
{
"input": "-86 25\n-55 18\n58 24",
"output": "3\n-199 19\n27 31\n89 17"
},
{
"input": "-301 -397\n192 317\n-98 729",
"output": "3\n-11 -809\n-591 15\n395 1443"
},
{
"input": "1000 1000\n999 1000\n-1000 -1000",
"output": "3\n2999 3000\n-999 -1000\n-1001 -1000"
},
{
"input": "-1000 0\n999 0\n1000 1",
"output": "3\n-1001 -1\n-999 1\n2999 1"
},
{
"input": "-1000 1000\n1000 -1000\n0 1",
"output": "3\n0 -1\n-2000 2001\n2000 -1999"
},
{
"input": "1000 -1000\n1000 1000\n-1000 0",
"output": "3\n3000 0\n-1000 -2000\n-1000 2000"
},
{
"input": "-1000 -1000\n-1 -1000\n-1000 -2",
"output": "3\n-1 -1998\n-1999 -2\n-1 -2"
},
{
"input": "0 -1000\n0 1000\n-1 -1000",
"output": "3\n1 1000\n-1 -3000\n-1 1000"
},
{
"input": "0 -1000\n0 1000\n1 -1000",
"output": "3\n-1 1000\n1 -3000\n1 1000"
},
{
"input": "9 5\n-6 6\n8 -8",
"output": "3\n-5 19\n23 -9\n-7 -7"
},
{
"input": "5 0\n-7 -7\n-3 3",
"output": "3\n1 -10\n9 10\n-15 -4"
},
{
"input": "1 -1\n1 7\n2 9",
"output": "3\n0 -3\n2 1\n2 17"
},
{
"input": "-7 -9\n1 -10\n4 8",
"output": "3\n-10 -27\n-4 9\n12 7"
},
{
"input": "10 3\n4 -9\n-8 -2",
"output": "3\n22 -4\n-2 10\n-14 -14"
},
{
"input": "6 -5\n4 -4\n-6 5",
"output": "3\n16 -14\n-4 4\n-8 6"
},
{
"input": "2 7\n8 9\n-5 4",
"output": "3\n15 12\n-11 2\n1 6"
},
{
"input": "-6 2\n-10 -7\n9 -6",
"output": "3\n-25 1\n13 3\n5 -15"
},
{
"input": "-6 -23\n-68 -8\n-63 71",
"output": "3\n-11 -102\n-1 56\n-125 86"
},
{
"input": "-11 -61\n56 9\n-57 46",
"output": "3\n102 -98\n-124 -24\n10 116"
},
{
"input": "-17 0\n-95 26\n-25 -54",
"output": "3\n-87 80\n53 -80\n-103 -28"
},
{
"input": "-22 -38\n-70 -58\n-19 21",
"output": "3\n-73 -117\n29 41\n-67 1"
},
{
"input": "73 -2\n79 -16\n13 -4",
"output": "3\n139 -14\n7 10\n19 -18"
},
{
"input": "-33 60\n3 0\n-57 97",
"output": "3\n27 -37\n-93 157\n-21 37"
},
{
"input": "-38 22\n53 -83\n-50 -28",
"output": "3\n65 -33\n-141 77\n41 -133"
},
{
"input": "57 83\n-24 -66\n-19 -53",
"output": "3\n52 70\n62 96\n-100 -202"
},
{
"input": "21 185\n966 -167\n-291 -804",
"output": "3\n1278 822\n-1236 -452\n654 -1156"
},
{
"input": "-917 -272\n-285 -579\n318 -437",
"output": "3\n-1520 -414\n-314 -130\n950 -744"
},
{
"input": "-969 -199\n766 -179\n626 -372",
"output": "3\n-829 -6\n-1109 -392\n2361 -352"
},
{
"input": "980 -656\n-485 -591\n-766 880",
"output": "3\n1261 -2127\n699 815\n-2231 945"
},
{
"input": "928 1\n-319 111\n428 -754",
"output": "3\n181 866\n1675 -864\n-819 -644"
},
{
"input": "-10 658\n732 -301\n735 197",
"output": "3\n-13 160\n-7 1156\n1477 -762"
},
{
"input": "-948 201\n-519 -713\n459 564",
"output": "3\n-1926 -1076\n30 1478\n888 -350"
},
{
"input": "-114 -28\n532 573\n766 931",
"output": "3\n-348 -386\n120 330\n1412 1532"
}
] | 0 | 0 | -1 | 5,082 |
|
487 | Prefix Product Sequence | [
"constructive algorithms",
"math",
"number theory"
] | null | null | Consider a sequence [*a*1,<=*a*2,<=... ,<=*a**n*]. Define its prefix product sequence .
Now given *n*, find a permutation of [1,<=2,<=...,<=*n*], such that its prefix product sequence is a permutation of [0,<=1,<=...,<=*n*<=-<=1]. | The only input line contains an integer *n* (1<=≤<=*n*<=≤<=105). | In the first output line, print "YES" if such sequence exists, or print "NO" if no such sequence exists.
If any solution exists, you should output *n* more lines. *i*-th line contains only an integer *a**i*. The elements of the sequence should be different positive integers no larger than *n*.
If there are multiple solutions, you are allowed to print any of them. | [
"7\n",
"6\n"
] | [
"YES\n1\n4\n3\n6\n5\n2\n7\n",
"NO\n"
] | For the second sample, there are no valid sequences. | [
{
"input": "7",
"output": "YES\n1\n2\n5\n6\n3\n4\n7"
},
{
"input": "6",
"output": "NO"
},
{
"input": "7137",
"output": "NO"
},
{
"input": "10529",
"output": "YES\n1\n2\n5266\n3511\n7898\n2107\n1756\n9026\n9214\n1171\n1054\n4787\n6143\n811\n9778\n703\n9872\n8672\n586\n3326\n5792\n6519\n2394\n6410\n3072\n2528\n406\n391\n10154\n5084\n352\n5775\n10201\n5106\n9601\n1806\n5558\n1993\n6928\n271\n8161\n9246\n3260\n8816\n6462\n235\n8470\n10306\n6801\n8811\n6529\n6401\n5468\n597\n196\n3064\n10342\n4619\n7807\n4284\n5441\n4834\n2888\n9193\n5101\n163\n7818\n3144\n4801\n5647\n6168\n4005\n8044\n4328\n997\n4353\n8729\n3693\n136\n8131\n4081\n131\n9888\n889\n6895\n3841\n9673\n5..."
},
{
"input": "34211",
"output": "YES\n1\n2\n17107\n11405\n8554\n27370\n5703\n14663\n21383\n15206\n30791\n31102\n2852\n21054\n7332\n9124\n10692\n24150\n24709\n21608\n15396\n16292\n32657\n23800\n18532\n12317\n27633\n16473\n20772\n15337\n21668\n13244\n22452\n10368\n29181\n23460\n12355\n7398\n27910\n29826\n24804\n10014\n25252\n30234\n16329\n3042\n29006\n13831\n26372\n26532\n6159\n30858\n13817\n1292\n8237\n33590\n27492\n18607\n7669\n26674\n27940\n30847\n23728\n16835\n28332\n17896\n22290\n25021\n14591\n7934\n28836\n6265\n6178\n27651\n20805\n155..."
},
{
"input": "1941",
"output": "NO"
},
{
"input": "55004",
"output": "NO"
},
{
"input": "21341",
"output": "YES\n1\n2\n10672\n7115\n16007\n17074\n3558\n12196\n8004\n9486\n19208\n19402\n12450\n13134\n16769\n5692\n14673\n17576\n15414\n15726\n20275\n4066\n20372\n7424\n16896\n11952\n17238\n17390\n8385\n7360\n13517\n13081\n7337\n6468\n19459\n2440\n18378\n8076\n18534\n18606\n10138\n20301\n12704\n16379\n20857\n1898\n14383\n14077\n19119\n13938\n16647\n12973\n19290\n1209\n19366\n20954\n4193\n19470\n14351\n2533\n6759\n11896\n6541\n1356\n3669\n11164\n13905\n14016\n9730\n9589\n11891\n13527\n19860\n10233\n14709\n18212\n19938..."
},
{
"input": "61333",
"output": "YES\n1\n2\n30668\n40890\n46001\n36801\n51112\n8763\n23001\n34075\n18401\n22304\n56223\n4719\n4382\n32712\n11501\n21648\n17038\n58106\n9201\n23366\n41819\n8001\n28112\n7361\n2360\n11359\n32858\n31725\n47023\n3958\n5751\n48324\n41491\n14020\n39186\n33154\n59720\n22018\n4601\n20944\n42350\n28528\n20910\n31349\n4001\n31320\n44723\n45062\n3681\n27661\n31847\n25460\n5680\n53528\n47096\n60258\n15863\n36385\n23512\n37203\n32646\n48678\n2876\n50011\n54829\n50349\n20746\n23112\n37677\n11231\n50260\n23526\n47244\n433..."
},
{
"input": "77617",
"output": "YES\n1\n2\n38810\n51746\n58214\n31048\n64682\n66530\n67916\n68994\n54333\n70562\n71150\n65677\n72074\n10350\n72767\n31961\n73306\n36767\n27167\n73922\n74090\n10125\n74384\n68304\n32839\n48871\n74846\n53530\n43984\n22535\n36384\n75266\n15981\n59877\n75462\n69227\n18384\n21893\n13584\n18932\n75770\n37907\n75854\n29323\n5063\n11561\n76001\n76034\n72961\n62399\n16420\n52722\n24436\n45160\n76232\n64001\n65574\n46045\n60801\n49625\n11268\n76386\n57001\n44183\n76442\n62558\n7991\n29248\n29939\n5467\n76540\n4254\n..."
},
{
"input": "44633",
"output": "YES\n1\n2\n22318\n14879\n33476\n26781\n7440\n38258\n39055\n19838\n13391\n36519\n26037\n10301\n41446\n38683\n19528\n5252\n32236\n21143\n6696\n27631\n18260\n13585\n13019\n5357\n5151\n21491\n43040\n21548\n19342\n12959\n32081\n41929\n24943\n16579\n38435\n12064\n10572\n18312\n25665\n19596\n13816\n1039\n31447\n12895\n6793\n34188\n6510\n37347\n2679\n16629\n2576\n12633\n10746\n43011\n43837\n21926\n33091\n1514\n31988\n32927\n6480\n9211\n16041\n2061\n20965\n3998\n12472\n4529\n8290\n25775\n19218\n10395\n28349\n16664\n..."
},
{
"input": "18047",
"output": "YES\n1\n2\n9025\n6017\n4513\n7220\n3009\n15470\n2257\n8022\n12634\n4923\n1505\n5554\n16759\n8423\n1129\n5309\n13035\n12349\n15341\n11173\n2462\n2355\n753\n12273\n11801\n14706\n8380\n9958\n4212\n3494\n565\n13673\n2655\n13923\n6518\n16097\n6175\n1852\n7671\n15407\n5587\n4198\n10255\n8824\n1178\n385\n377\n4789\n6137\n7786\n5901\n17367\n16377\n15423\n13214\n4117\n14003\n5201\n11130\n10060\n10771\n3725\n283\n4721\n6837\n14277\n1328\n12817\n6962\n15252\n12283\n10137\n8049\n16123\n3088\n16173\n9950\n2057\n3836\n1..."
},
{
"input": "78137",
"output": "YES\n1\n2\n39070\n26047\n58604\n31256\n13024\n22326\n68371\n8683\n54697\n56828\n45581\n66117\n50232\n36465\n34186\n45964\n4342\n8226\n27349\n59534\n67483\n64549\n22791\n6252\n33059\n2895\n64185\n56583\n18233\n50412\n56162\n44989\n62051\n4466\n41240\n33790\n43182\n74131\n13675\n60986\n68836\n12721\n33742\n64247\n32275\n3326\n11396\n47840\n42195\n15322\n16530\n10321\n1448\n73876\n32093\n54834\n28292\n18542\n9117\n58924\n64275\n45891\n67150\n44479\n22495\n67642\n31026\n21517\n41302\n25313\n59689\n28901\n55964..."
},
{
"input": "2647",
"output": "YES\n1\n2\n1325\n1766\n663\n1060\n2207\n2270\n332\n2354\n1854\n723\n1104\n1630\n2459\n354\n1490\n1091\n2501\n419\n2251\n2522\n362\n1267\n1876\n1801\n2139\n2550\n1230\n1644\n1501\n1538\n2069\n1124\n546\n2043\n1251\n1718\n210\n544\n1126\n1034\n2585\n2094\n1505\n1001\n634\n1409\n2262\n2594\n901\n2129\n1070\n900\n2599\n2263\n1939\n1905\n2146\n1661\n751\n1433\n2093\n2606\n1035\n1915\n1886\n2569\n1597\n423\n1022\n1455\n626\n835\n2183\n601\n1429\n2373\n1596\n2581\n1887\n1733\n1841\n1181\n1293\n219\n2371\n1431\n75..."
},
{
"input": "6577",
"output": "YES\n1\n2\n3290\n4386\n4934\n2632\n5482\n4699\n5756\n3655\n4605\n599\n6030\n507\n2350\n878\n6167\n3483\n1828\n2078\n2303\n1567\n300\n287\n6304\n3158\n254\n1219\n4464\n1135\n3728\n1274\n3084\n4585\n1742\n2256\n4203\n5867\n4328\n2362\n1152\n1926\n784\n3366\n3439\n4678\n144\n2240\n6441\n5370\n4868\n3354\n3416\n2607\n610\n1436\n5521\n5078\n568\n4460\n5153\n5392\n3926\n523\n4831\n2733\n2293\n590\n4160\n4481\n4417\n3799\n2102\n4686\n2934\n5438\n5453\n1026\n4470\n6245\n3865\n407\n4252\n2299\n3681\n5959\n4972\n379..."
},
{
"input": "87511",
"output": "YES\n1\n2\n43757\n58342\n21879\n70010\n72927\n62509\n10940\n19448\n78761\n71601\n36464\n53854\n31255\n81678\n49226\n36035\n53480\n59877\n39381\n20837\n35801\n22830\n61988\n31505\n70683\n64824\n15628\n24142\n84595\n45168\n68369\n53038\n18018\n47507\n70496\n14192\n29939\n17952\n19691\n25614\n10419\n14247\n17901\n56397\n55171\n29792\n74750\n58937\n15753\n70353\n35342\n54489\n76168\n14321\n51570\n49130\n55827\n31149\n42298\n40170\n66340\n65287\n34185\n45776\n70275\n67920\n52765\n36781\n23754\n24652\n79004\n383..."
},
{
"input": "87299",
"output": "YES\n1\n2\n43651\n29101\n21826\n17461\n14551\n37415\n54563\n9701\n8731\n55555\n7276\n20147\n18708\n5821\n27282\n20542\n4851\n73516\n4366\n41572\n27778\n68322\n47288\n3493\n10074\n32334\n53004\n48166\n2911\n28162\n57291\n18519\n53921\n77323\n2426\n70784\n80408\n35816\n45833\n8518\n64436\n38575\n57539\n1941\n77811\n13003\n67294\n55231\n1747\n6848\n48687\n54357\n59817\n80951\n70152\n24506\n67733\n66585\n1456\n54384\n57731\n13858\n28646\n21490\n9260\n44302\n26961\n80974\n38662\n67627\n44863\n77733\n79042\n1165..."
},
{
"input": "49069",
"output": "YES\n1\n2\n24536\n32714\n36803\n9815\n40892\n7011\n18402\n43618\n4908\n26766\n44981\n41521\n3506\n35985\n33736\n34638\n46344\n30992\n26989\n18694\n37918\n34136\n22491\n41219\n20761\n14540\n26288\n47378\n17993\n12664\n41403\n25279\n41854\n1403\n47707\n27851\n40031\n13841\n13495\n43086\n33882\n7989\n43494\n28352\n41603\n48026\n11246\n22032\n20610\n27903\n10381\n5556\n31805\n5354\n37679\n43044\n48224\n23288\n8997\n31373\n30867\n6232\n20702\n8305\n12640\n5860\n45462\n44092\n702\n42850\n23854\n18822\n13926\n464..."
},
{
"input": "16553",
"output": "YES\n1\n2\n8278\n5519\n12416\n9933\n2760\n9460\n14485\n7358\n4967\n9030\n9657\n3821\n13007\n14347\n7243\n6817\n11956\n12198\n2484\n3154\n12792\n7198\n4829\n5298\n1911\n7971\n6504\n2855\n7174\n535\n3622\n14046\n3409\n8514\n14255\n12975\n14376\n6792\n9519\n6057\n9854\n8470\n14673\n4783\n11876\n9158\n2415\n3717\n10926\n2273\n956\n8746\n3986\n8428\n11529\n15102\n1428\n7015\n11864\n9770\n268\n1052\n10088\n765\n15300\n12354\n1705\n2400\n12534\n1633\n7128\n15647\n6488\n12802\n15465\n8385\n11673\n9849\n4760\n13693..."
},
{
"input": "19333",
"output": "YES\n1\n2\n9668\n12890\n14501\n11601\n16112\n2763\n7251\n17186\n5801\n15819\n17723\n8924\n1382\n10312\n3626\n4550\n18260\n17299\n2901\n7366\n7910\n5885\n8862\n2321\n14129\n18618\n10358\n2001\n14823\n10603\n11480\n11718\n11942\n4420\n18797\n18289\n8650\n15864\n1451\n6131\n13350\n17086\n13622\n3438\n2943\n18100\n14098\n11443\n1161\n14406\n7065\n11309\n18976\n18631\n14846\n5767\n1001\n9176\n7412\n14580\n5302\n2456\n15407\n17252\n15526\n10966\n15638\n14851\n11877\n7353\n9399\n17745\n9145\n13663\n13992\n16070\n..."
},
{
"input": "8677",
"output": "YES\n1\n2\n4340\n5786\n6509\n3472\n7232\n6199\n3255\n7714\n6075\n4734\n7955\n1336\n3100\n1158\n1628\n6126\n8196\n7308\n3038\n2067\n6706\n7169\n3978\n4166\n5007\n2572\n5889\n7182\n4918\n5879\n5153\n4471\n7402\n2976\n8437\n8209\n7993\n446\n5858\n2329\n1034\n4844\n7692\n3279\n3585\n6278\n6328\n2126\n6422\n4935\n2504\n7532\n5625\n2683\n2945\n5329\n7930\n6472\n6798\n570\n2940\n3582\n2577\n268\n2236\n8419\n8040\n8175\n5827\n6356\n4219\n2616\n4105\n7174\n3997\n6875\n4562\n8019\n7268\n858\n1165\n6169\n4856\n1226\n..."
},
{
"input": "83203",
"output": "YES\n1\n2\n41603\n55470\n20802\n49923\n69337\n71318\n52003\n46225\n24962\n7565\n34669\n25602\n77261\n44376\n26002\n48944\n23113\n39413\n54083\n79242\n3783\n75969\n17335\n26626\n54403\n15409\n38631\n40168\n63790\n2685\n54603\n57991\n66074\n30905\n11557\n58468\n19707\n36269\n27042\n77116\n81223\n42570\n1892\n42527\n37985\n31866\n8668\n81506\n54915\n71784\n27202\n59656\n7705\n34795\n19316\n68607\n61686\n12693\n73497\n1365\n1343\n54149\n27302\n55043\n28996\n75753\n74639\n53058\n15453\n9376\n5779\n49011\n70836\n..."
},
{
"input": "31513",
"output": "YES\n1\n2\n15758\n21010\n23636\n18909\n26262\n4503\n27575\n7004\n9455\n17190\n28888\n29090\n2252\n16808\n13788\n12977\n19259\n19904\n4728\n12006\n24352\n20553\n30201\n28993\n30302\n23344\n16883\n3261\n24161\n20332\n22651\n16235\n6489\n7204\n9630\n22997\n25709\n30706\n18121\n13836\n21760\n26384\n27933\n26612\n10277\n1342\n15101\n5146\n14497\n25335\n30908\n24379\n27429\n16044\n8442\n27644\n1631\n22434\n12081\n14466\n25923\n14507\n11326\n18424\n8118\n15052\n3245\n17356\n19359\n5771\n20572\n23312\n11499\n9665\n..."
},
{
"input": "60811",
"output": "YES\n1\n2\n30407\n40542\n15204\n48650\n50677\n26063\n38008\n33785\n54731\n38699\n25339\n42101\n13032\n56758\n49410\n28618\n16893\n38408\n27366\n49229\n19350\n2645\n12670\n21893\n21051\n51803\n36922\n31455\n58785\n33349\n55111\n53441\n44715\n41700\n8447\n39446\n49610\n54575\n44089\n7417\n24615\n26871\n40081\n18920\n1323\n34935\n36741\n29786\n10947\n9540\n10526\n51633\n25902\n32065\n48867\n53344\n15728\n23707\n29393\n50843\n16675\n56951\n27556\n8421\n26721\n53551\n22358\n41423\n51256\n1714\n4224\n29990\n5012..."
},
{
"input": "71821",
"output": "YES\n1\n2\n35912\n47882\n53867\n57458\n59852\n61562\n26934\n63842\n64640\n32647\n65837\n55248\n66692\n67034\n49378\n54923\n67832\n68042\n68231\n68402\n16324\n9369\n32919\n54585\n63535\n69162\n69257\n42103\n69428\n60238\n60600\n10883\n27462\n69770\n69827\n17471\n69932\n42357\n34116\n26277\n70112\n65141\n44073\n70226\n4685\n42788\n16460\n49836\n27293\n66189\n31768\n59626\n70492\n63987\n34629\n70562\n21052\n43824\n70625\n38855\n66030\n70682\n66211\n54143\n5442\n48239\n49642\n27064\n70796\n55637\n34914\n19678\n..."
},
{
"input": "1",
"output": "YES\n1"
},
{
"input": "2",
"output": "YES\n1\n2"
},
{
"input": "3",
"output": "YES\n1\n2\n3"
},
{
"input": "4",
"output": "YES\n1\n3\n2\n4"
},
{
"input": "5",
"output": "YES\n1\n2\n4\n3\n5"
},
{
"input": "99989",
"output": "YES\n1\n2\n49996\n33331\n74993\n19999\n16666\n85706\n37497\n11111\n10000\n9091\n58328\n15384\n92848\n6667\n18749\n41173\n5556\n63152\n54995\n61899\n4546\n86948\n79159\n63994\n57687\n37034\n96419\n34480\n3334\n35481\n9375\n3031\n20587\n17142\n52773\n86478\n81571\n71788\n27498\n90235\n30950\n6977\n52268\n2223\n93469\n14893\n39580\n55097\n81992\n13725\n28844\n77351\n68512\n1819\n48210\n54381\n67235\n81348\n51662\n9836\n17741\n87293\n4688\n63071\n1516\n11940\n10294\n62313\n58566\n38025\n26387\n9589\n93234\n213..."
}
] | 842 | 102,400 | 3 | 5,103 |
|
99 | Help Chef Gerasim | [
"implementation",
"sortings"
] | B. Help Chef Gerasim | 0 | 256 | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.
To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. | The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. | If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). | [
"5\n270\n250\n250\n230\n250\n",
"5\n250\n250\n250\n250\n250\n",
"5\n270\n250\n249\n230\n250\n"
] | [
"20 ml. from cup #4 to cup #1.\n",
"Exemplary pages.\n",
"Unrecoverable configuration.\n"
] | none | [
{
"input": "5\n270\n250\n250\n230\n250",
"output": "20 ml. from cup #4 to cup #1."
},
{
"input": "5\n250\n250\n250\n250\n250",
"output": "Exemplary pages."
},
{
"input": "5\n270\n250\n249\n230\n250",
"output": "Unrecoverable configuration."
},
{
"input": "4\n200\n190\n210\n200",
"output": "10 ml. from cup #2 to cup #3."
},
{
"input": "4\n1\n2\n3\n4",
"output": "Unrecoverable configuration."
},
{
"input": "1\n0",
"output": "Exemplary pages."
},
{
"input": "2\n0\n0",
"output": "Exemplary pages."
},
{
"input": "2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "2\n0\n2",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "2\n1\n1",
"output": "Exemplary pages."
},
{
"input": "2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "2\n2\n0",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "3\n0\n0\n0",
"output": "Exemplary pages."
},
{
"input": "3\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n2",
"output": "1 ml. from cup #1 to cup #3."
},
{
"input": "3\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n2\n1",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "3\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n2",
"output": "1 ml. from cup #2 to cup #3."
},
{
"input": "3\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n1\n1",
"output": "Exemplary pages."
},
{
"input": "3\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n2\n0",
"output": "1 ml. from cup #3 to cup #2."
},
{
"input": "3\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n0\n1",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "3\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n1\n0",
"output": "1 ml. from cup #3 to cup #1."
},
{
"input": "3\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "4\n0\n0\n0\n0",
"output": "Exemplary pages."
},
{
"input": "4\n0\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n2",
"output": "1 ml. from cup #1 to cup #4."
},
{
"input": "4\n0\n1\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n2\n1",
"output": "1 ml. from cup #1 to cup #3."
},
{
"input": "4\n0\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n1\n1",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "4\n0\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n2",
"output": "1 ml. from cup #2 to cup #4."
},
{
"input": "4\n1\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n2\n1",
"output": "1 ml. from cup #2 to cup #3."
},
{
"input": "4\n1\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n2",
"output": "1 ml. from cup #3 to cup #4."
},
{
"input": "4\n1\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n1\n1",
"output": "Exemplary pages."
},
{
"input": "4\n1\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n2\n0",
"output": "1 ml. from cup #4 to cup #3."
},
{
"input": "4\n1\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n0\n1",
"output": "1 ml. from cup #3 to cup #2."
},
{
"input": "4\n1\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n1\n0",
"output": "1 ml. from cup #4 to cup #2."
},
{
"input": "4\n1\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n1\n1",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "4\n2\n0\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n0\n1",
"output": "1 ml. from cup #3 to cup #1."
},
{
"input": "4\n2\n1\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n1\n0",
"output": "1 ml. from cup #4 to cup #1."
},
{
"input": "4\n2\n1\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "27\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n2626\n5599\n5599\n5599\n5599\n5599\n8572\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599",
"output": "2973 ml. from cup #11 to cup #17."
},
{
"input": "98\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n1204\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n197\n702\n702\n702\n702\n702\n702\n702\n702\n702",
"output": "Unrecoverable configuration."
},
{
"input": "54\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6859\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n5389\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124",
"output": "735 ml. from cup #37 to cup #29."
},
{
"input": "50\n9636\n9678\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9596\n9636\n9636\n9636\n9636\n9636\n9636",
"output": "Unrecoverable configuration."
},
{
"input": "19\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n82\n5001\n9919\n5001\n5001",
"output": "Unrecoverable configuration."
},
{
"input": "74\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n3918\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n6742\n5330\n5330",
"output": "1412 ml. from cup #36 to cup #72."
}
] | 93 | 0 | 0 | 5,109 |
0 | none | [
"none"
] | null | null | Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.
After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in lexicographical order in normal sense. But it was always true that after some modification of the order of letters in alphabet, the order of authors becomes lexicographical!
She wants to know, if there exists an order of letters in Latin alphabet such that the names on the paper she is submitting are following in the lexicographical order. If so, you should find out any such order.
Lexicographical order is defined in following way. When we compare *s* and *t*, first we find the leftmost position with differing characters: *s**i*<=≠<=*t**i*. If there is no such position (i. e. *s* is a prefix of *t* or vice versa) the shortest string is less. Otherwise, we compare characters *s**i* and *t**i* according to their order in alphabet. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100): number of names.
Each of the following *n* lines contain one string *name**i* (1<=≤<=|*name**i*|<=≤<=100), the *i*-th name. Each name contains only lowercase Latin letters. All names are different. | If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'–'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on).
Otherwise output a single word "Impossible" (without quotes). | [
"3\nrivest\nshamir\nadleman\n",
"10\ntourist\npetr\nwjmzbmr\nyeputons\nvepifanov\nscottwu\noooooooooooooooo\nsubscriber\nrowdark\ntankengineer\n",
"10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever\n",
"7\ncar\ncare\ncareful\ncarefully\nbecarefuldontforgetsomething\notherwiseyouwillbehacked\ngoodluck\n"
] | [
"bcdefghijklmnopqrsatuvwxyz\n",
"Impossible\n",
"aghjlnopefikdmbcqrstuvwxyz\n",
"acbdefhijklmnogpqrstuvwxyz\n"
] | none | [
{
"input": "3\nrivest\nshamir\nadleman",
"output": "bcdefghijklmnopqrsatuvwxyz"
},
{
"input": "10\ntourist\npetr\nwjmzbmr\nyeputons\nvepifanov\nscottwu\noooooooooooooooo\nsubscriber\nrowdark\ntankengineer",
"output": "Impossible"
},
{
"input": "10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever",
"output": "aghjlnopefikdmbcqrstuvwxyz"
},
{
"input": "7\ncar\ncare\ncareful\ncarefully\nbecarefuldontforgetsomething\notherwiseyouwillbehacked\ngoodluck",
"output": "acbdefhijklmnogpqrstuvwxyz"
},
{
"input": "2\na\naa",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "6\nax\nay\nby\nbz\ncz\ncx",
"output": "Impossible"
},
{
"input": "4\nax\nay\nby\nbx",
"output": "Impossible"
},
{
"input": "4\nax\nay\nby\nbz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "1\na",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "2\naa\na",
"output": "Impossible"
},
{
"input": "5\naaaaa\naaaa\naaa\naa\na",
"output": "Impossible"
},
{
"input": "2\nanud\nanu",
"output": "Impossible"
},
{
"input": "8\nwa\nwb\nxc\nxd\nyb\nyc\nzd\nza",
"output": "Impossible"
}
] | 62 | 5,529,600 | -1 | 5,118 |
|
354 | Vasya and Beautiful Arrays | [
"brute force",
"dp",
"number theory"
] | null | null | Vasya's got a birthday coming up and his mom decided to give him an array of positive integers *a* of length *n*.
Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array *a* left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by *k* for each number).
The seller can obtain array *b* from array *a* if the following conditions hold: *b**i*<=><=0; 0<=≤<=*a**i*<=-<=*b**i*<=≤<=*k* for all 1<=≤<=*i*<=≤<=*n*.
Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105;<=1<=≤<=*k*<=≤<=106). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — array *a*. | In the single line print a single number — the maximum possible beauty of the resulting array. | [
"6 1\n3 6 10 12 13 16\n",
"5 3\n8 21 52 15 77\n"
] | [
"3\n",
"7\n"
] | In the first sample we can obtain the array:
3 6 9 12 12 15
In the second sample we can obtain the next array:
7 21 49 14 77 | [
{
"input": "6 1\n3 6 10 12 13 16",
"output": "3"
},
{
"input": "5 3\n8 21 52 15 77",
"output": "7"
},
{
"input": "13 11\n55 16 26 40 84 80 48 52 25 43 75 21 58",
"output": "16"
},
{
"input": "18 9\n85 29 29 15 17 71 46 69 48 80 44 73 40 55 61 57 22 68",
"output": "13"
},
{
"input": "25 7\n67 18 36 85 64 22 32 66 17 64 66 65 82 36 16 52 19 70 38 51 17 32 85 16 64",
"output": "16"
},
{
"input": "7 1\n12 84 21 60 33 21 45",
"output": "4"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 10\n40141 53368 66538 64507 78114 34253 73242 42141 37430 6",
"output": "6"
},
{
"input": "10 7\n869 1293 12421 1 90901 120214 12403 6543 591870 124",
"output": "1"
},
{
"input": "2 84794\n1000000 1000000",
"output": "1000000"
}
] | 358 | 21,606,400 | 3 | 5,121 |
|
835 | The number on the board | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ. | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n1000000010000000000000000000010000000000000001000001000000000000000000000000000000000000000000000000",
"output": "22"
},
{
"input": "500\n1899337170458531693764539600958943248270674811247191310452938511077656066239840703432499357537079035",
"output": "6"
},
{
"input": "700\n9307216756404590162143344901558545760612901767837570518638460182990196397856220673189163417019781185",
"output": "32"
},
{
"input": "900\n7570423817272967027553082464863962024635217372307919506594193055572300657732661146354209508997483330",
"output": "91"
},
{
"input": "18\n900",
"output": "1"
},
{
"input": "23\n12138",
"output": "1"
},
{
"input": "16\n333",
"output": "2"
},
{
"input": "3\n12",
"output": "0"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "17\n89",
"output": "0"
},
{
"input": "18\n99",
"output": "0"
},
{
"input": "42\n97779",
"output": "2"
},
{
"input": "2\n11",
"output": "0"
},
{
"input": "6\n33",
"output": "0"
},
{
"input": "45\n23456",
"output": "5"
},
{
"input": "3\n21",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "108\n199999899899",
"output": "3"
},
{
"input": "6\n222",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "9\n9",
"output": "0"
},
{
"input": "5\n5",
"output": "0"
},
{
"input": "27\n888",
"output": "3"
}
] | 155 | 1,945,600 | 3 | 5,128 |
|
620 | Pearls in a Row | [
"greedy"
] | null | null | There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of pearls in a row.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) – the type of the *i*-th pearl. | On the first line print integer *k* — the maximal number of segments in a partition of the row.
Each of the next *k* lines should contain two integers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the number of the leftmost and the rightmost pearls in the *j*-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1". | [
"5\n1 2 3 4 1\n",
"5\n1 2 3 4 5\n",
"7\n1 2 1 3 1 2 1\n"
] | [
"1\n1 5\n",
"-1\n",
"2\n1 3\n4 7\n"
] | none | [
{
"input": "5\n1 2 3 4 1",
"output": "1\n1 5"
},
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "7\n1 2 1 3 1 2 1",
"output": "2\n1 3\n4 7"
},
{
"input": "9\n1 2 1 2 1 2 1 2 1",
"output": "3\n1 3\n4 6\n7 9"
},
{
"input": "11\n1 1 2 1 2 1 2 1 2 1 1",
"output": "4\n1 2\n3 5\n6 8\n9 11"
},
{
"input": "1\n576560149",
"output": "-1"
},
{
"input": "10\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451",
"output": "5\n1 2\n3 4\n5 6\n7 8\n9 10"
},
{
"input": "10\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 80672280 80672280 933677171",
"output": "4\n1 3\n4 5\n6 7\n8 10"
},
{
"input": "10\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597",
"output": "2\n1 3\n4 10"
},
{
"input": "7\n13 9 19 13 3 13 12",
"output": "1\n1 7"
},
{
"input": "3\n1 1 1",
"output": "1\n1 3"
},
{
"input": "5\n1 2 2 2 3",
"output": "1\n1 5"
},
{
"input": "5\n1 2 2 2 1",
"output": "1\n1 5"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "6\n1 2\n3 4\n5 6\n7 8\n9 10\n11 13"
},
{
"input": "4\n1 2 1 2",
"output": "1\n1 4"
}
] | 1,169 | 23,961,600 | 3 | 5,129 |
|
558 | Lala Land and Apple Trees | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect? | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0. | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "300000"
},
{
"input": "1\n-1 1",
"output": "1"
},
{
"input": "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463",
"output": "1036452"
},
{
"input": "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532",
"output": "632240"
},
{
"input": "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044",
"output": "891593"
},
{
"input": "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422",
"output": "1109655"
},
{
"input": "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834",
"output": "847241"
},
{
"input": "3\n-94146 4473\n28707 99079\n-4153 8857",
"output": "112409"
},
{
"input": "3\n-3 3\n-2 2\n-1 1",
"output": "1"
},
{
"input": "2\n100000 3\n-100000 9",
"output": "12"
},
{
"input": "2\n-100000 100000\n100000 99999",
"output": "199999"
}
] | 77 | 7,065,600 | 0 | 5,143 |
|
407 | Triangle | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices. | The first line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=1000), separated by a single space. | In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value. | [
"1 1\n",
"5 5\n",
"5 10\n"
] | [
"NO\n",
"YES\n2 1\n5 5\n-2 4\n",
"YES\n-10 4\n-2 -2\n1 2\n"
] | none | [
{
"input": "1 1",
"output": "NO"
},
{
"input": "5 5",
"output": "YES\n2 1\n5 5\n-2 4"
},
{
"input": "5 10",
"output": "YES\n-10 4\n-2 -2\n1 2"
},
{
"input": "2 2",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "10 15",
"output": "YES\n0 0\n6 8\n-12 9"
},
{
"input": "935 938",
"output": "NO"
},
{
"input": "999 1000",
"output": "NO"
},
{
"input": "1000 1000",
"output": "YES\n0 0\n280 960\n-960 280"
},
{
"input": "15 20",
"output": "YES\n0 0\n12 9\n-12 16"
},
{
"input": "20 15",
"output": "YES\n0 0\n12 16\n-12 9"
},
{
"input": "629 865",
"output": "NO"
},
{
"input": "45 872",
"output": "NO"
},
{
"input": "757 582",
"output": "NO"
},
{
"input": "173 588",
"output": "NO"
},
{
"input": "533 298",
"output": "NO"
},
{
"input": "949 360",
"output": "NO"
},
{
"input": "661 175",
"output": "NO"
},
{
"input": "728 299",
"output": "YES\n0 0\n280 672\n-276 115"
},
{
"input": "575 85",
"output": "YES\n0 0\n345 460\n-68 51"
},
{
"input": "385 505",
"output": "YES\n0 0\n231 308\n-404 303"
},
{
"input": "755 865",
"output": "YES\n0 0\n453 604\n-692 519"
},
{
"input": "395 55",
"output": "YES\n0 0\n237 316\n-44 33"
},
{
"input": "600 175",
"output": "YES\n0 0\n168 576\n-168 49"
},
{
"input": "280 210",
"output": "YES\n0 0\n168 224\n-168 126"
},
{
"input": "180 135",
"output": "YES\n0 0\n108 144\n-108 81"
},
{
"input": "140 105",
"output": "YES\n0 0\n84 112\n-84 63"
},
{
"input": "440 330",
"output": "YES\n0 0\n264 352\n-264 198"
},
{
"input": "130 312",
"output": "YES\n0 0\n120 50\n-120 288"
},
{
"input": "65 156",
"output": "YES\n0 0\n60 25\n-60 144"
},
{
"input": "105 140",
"output": "YES\n0 0\n84 63\n-84 112"
},
{
"input": "408 765",
"output": "YES\n0 0\n360 192\n-360 675"
},
{
"input": "195 468",
"output": "YES\n0 0\n180 75\n-180 432"
},
{
"input": "305 949",
"output": "NO"
},
{
"input": "80 60",
"output": "YES\n0 0\n48 64\n-48 36"
},
{
"input": "15 15",
"output": "YES\n0 0\n9 12\n-12 9"
},
{
"input": "120 90",
"output": "YES\n0 0\n72 96\n-72 54"
},
{
"input": "60 80",
"output": "YES\n0 0\n48 36\n-48 64"
},
{
"input": "5 25",
"output": "YES\n0 0\n3 4\n-20 15"
},
{
"input": "5 1000",
"output": "YES\n0 0\n3 4\n-800 600"
},
{
"input": "25 35",
"output": "YES\n0 0\n15 20\n-28 21"
},
{
"input": "25 5",
"output": "YES\n0 0\n15 20\n-4 3"
},
{
"input": "30 40",
"output": "YES\n0 0\n24 18\n-24 32"
},
{
"input": "65 156",
"output": "YES\n0 0\n60 25\n-60 144"
},
{
"input": "455 470",
"output": "YES\n0 0\n273 364\n-376 282"
},
{
"input": "90 120",
"output": "YES\n0 0\n72 54\n-72 96"
},
{
"input": "5 205",
"output": "YES\n0 0\n3 4\n-164 123"
},
{
"input": "111 111",
"output": "YES\n0 0\n36 105\n-105 36"
},
{
"input": "17 17",
"output": "YES\n0 0\n8 15\n-15 8"
},
{
"input": "1000 5",
"output": "YES\n0 0\n600 800\n-4 3"
}
] | 46 | 0 | -1 | 5,147 |
|
764 | Timofey and cubes | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1.
After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4]. | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n21968 5686",
"output": "5686 21968"
},
{
"input": "5\n241218936 -825949895 -84926813 491336344 -872198236",
"output": "-872198236 -825949895 -84926813 491336344 241218936"
},
{
"input": "42\n-557774624 828320986 -345782722 -62979938 -681259411 -945983652 -139095040 832293378 -82572118 432027535 88438103 568183540 961782904 73543295 615958219 -5050584 322982437 -146046730 759453379 129267920 -819827396 -348156048 805080102 390723009 -771277251 -79011872 -592313207 528489973 656201270 -127795621 17284747 145139617 -565641608 83452176 -223074608 545811186 -657981923 -204657836 154779765 -476867246 180386291 202782486",
"output": "202782486 828320986 -476867246 -62979938 -204657836 -945983652 545811186 832293378 83452176 432027535 145139617 568183540 -127795621 73543295 528489973 -5050584 -79011872 -146046730 390723009 129267920 -348156048 -819827396 805080102 759453379 -771277251 322982437 -592313207 615958219 656201270 961782904 17284747 88438103 -565641608 -82572118 -223074608 -139095040 -657981923 -681259411 154779765 -345782722 180386291 -557774624"
},
{
"input": "2\n1 2",
"output": "2 1"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "6 2 4 3 5 1"
},
{
"input": "4\n0 1 2 3",
"output": "3 1 2 0"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10 2 8 4 6 5 7 3 9 1"
},
{
"input": "2\n4 5",
"output": "5 4"
},
{
"input": "2\n1 5",
"output": "5 1"
},
{
"input": "2\n2 5",
"output": "5 2"
},
{
"input": "2\n3 4",
"output": "4 3"
},
{
"input": "2\n10 0",
"output": "0 10"
},
{
"input": "66\n8229 5299 5562 1259 2258 1126 5026 8796 3497 7111 6680 1180 1426 4821 3322 3502 400 2951 4187 417 5234 1266 7525 7648 417 9297 174 670 1790 4121 9737 938 4616 3402 2009 2461 474 3728 327 3353 9773 6818 8781 874 2209 1260 1647 6126 9287 9638 5049 1256 4459 863 1835 4822 6809 348 5053 7784 6927 2140 9173 7817 5095 4184",
"output": "4184 5299 7817 1259 2140 1126 7784 8796 348 7111 4822 1180 863 4821 1256 3502 9638 2951 6126 417 1260 1266 874 7648 6818 9297 3353 670 3728 4121 2461 938 3402 4616 2009 9737 474 1790 327 174 9773 417 8781 7525 2209 5234 1647 4187 9287 400 5049 3322 4459 1426 1835 6680 6809 3497 5053 5026 6927 2258 9173 5562 5095 8229"
}
] | 452 | 22,323,200 | 3 | 5,149 |
|
358 | Dima and Hares | [
"dp",
"greedy"
] | null | null | Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her *n* hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to *n* from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?
Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and *n* don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.
Help Inna maximize the total joy the hares radiate. :) | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=3000) — the number of hares. Then three lines follow, each line has *n* integers. The first line contains integers *a*1 *a*2 ... *a**n*. The second line contains *b*1,<=*b*2,<=...,<=*b**n*. The third line contains *c*1,<=*c*2,<=...,<=*c**n*. The following limits are fulfilled: 0<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=105.
Number *a**i* in the first line shows the joy that hare number *i* gets if his adjacent hares are both hungry. Number *b**i* in the second line shows the joy that hare number *i* radiates if he has exactly one full adjacent hare. Number *с**i* in the third line shows the joy that hare number *i* radiates if both his adjacent hares are full. | In a single line, print the maximum possible total joy of the hares Inna can get by feeding them. | [
"4\n1 2 3 4\n4 3 2 1\n0 1 1 0\n",
"7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3\n",
"3\n1 1 1\n1 2 1\n1 1 1\n"
] | [
"13\n",
"44\n",
"4\n"
] | none | [
{
"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0",
"output": "13"
},
{
"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3",
"output": "44"
},
{
"input": "3\n1 1 1\n1 2 1\n1 1 1",
"output": "4"
},
{
"input": "7\n1 3 8 9 3 4 4\n6 0 6 6 1 8 4\n9 6 3 7 8 8 2",
"output": "42"
},
{
"input": "2\n3 5\n9 8\n4 0",
"output": "14"
},
{
"input": "7\n3 6 1 5 4 2 0\n9 7 3 7 2 6 0\n1 6 5 7 5 4 1",
"output": "37"
},
{
"input": "1\n0\n1\n4",
"output": "0"
},
{
"input": "1\n7\n1\n7",
"output": "7"
},
{
"input": "8\n7 3 3 5 9 9 8 1\n8 2 6 6 0 3 8 0\n1 2 5 0 9 4 7 8",
"output": "49"
},
{
"input": "6\n1 2 0 1 6 4\n0 6 1 8 9 8\n4 1 4 3 9 8",
"output": "33"
},
{
"input": "1\n0\n0\n0",
"output": "0"
},
{
"input": "1\n100000\n100000\n100000",
"output": "100000"
}
] | 109 | 614,400 | 3 | 5,155 |
|
491 | Deciphering | [
"flows",
"graph matchings"
] | null | null | One day Maria Ivanovna found a Sasha's piece of paper with a message dedicated to Olya. Maria Ivanovna wants to know what is there in a message, but unfortunately the message is ciphered. Maria Ivanovna knows that her students usually cipher their messages by replacing each letter of an original message by some another letter. Replacement works in such way that same letters are always replaced with some fixed letter, and different letters are always replaced by different letters.
Maria Ivanovna supposed that the message contains answers to the final exam (since its length is equal to the number of final exam questions). On the other hand she knows that Sasha's answer are not necessary correct. There are *K* possible answers for each questions. Of course, Maria Ivanovna knows correct answers.
Maria Ivanovna decided to decipher message in such way that the number of Sasha's correct answers is maximum possible. She is very busy now, so your task is to help her. | First line contains length of both strings *N* (1<=≤<=*N*<=≤<=2<=000<=000) and an integer *K* — number of possible answers for each of the questions (1<=≤<=*K*<=≤<=52). Answers to the questions are denoted as Latin letters abcde...xyzABCDE...XYZ in the order. For example for *K*<==<=6, possible answers are abcdef and for *K*<==<=30 possible answers are abcde...xyzABCD.
Second line contains a ciphered message string consisting of Latin letters.
Third line contains a correct answers string consisting of Latin letters. | In the first line output maximum possible number of correct Sasha's answers.
In the second line output cipher rule as the string of length *K* where for each letter from the students' cipher (starting from 'a' as mentioned above) there is specified which answer does it correspond to.
If there are several ways to produce maximum answer, output any of them. | [
"10 2\naaabbbaaab\nbbbbabbbbb\n",
"10 2\naaaaaaabbb\nbbbbaaabbb\n",
"9 4\ndacbdacbd\nacbdacbda\n"
] | [
"7\nba\n",
"6\nab\n",
"9\ncdba\n"
] | none | [] | 30 | 0 | 0 | 5,168 |
|
934 | A Prosperous Lot | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.
He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist.
A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms. | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output": "6"
},
{
"input": "7",
"output": "8886"
},
{
"input": "8",
"output": "8888"
},
{
"input": "9",
"output": "88886"
},
{
"input": "10",
"output": "88888"
},
{
"input": "11",
"output": "888886"
},
{
"input": "12",
"output": "888888"
},
{
"input": "13",
"output": "8888886"
},
{
"input": "14",
"output": "8888888"
},
{
"input": "15",
"output": "88888886"
},
{
"input": "16",
"output": "88888888"
},
{
"input": "17",
"output": "888888886"
},
{
"input": "18",
"output": "888888888"
},
{
"input": "19",
"output": "8888888886"
},
{
"input": "20",
"output": "8888888888"
},
{
"input": "21",
"output": "88888888886"
},
{
"input": "22",
"output": "88888888888"
},
{
"input": "23",
"output": "888888888886"
},
{
"input": "24",
"output": "888888888888"
},
{
"input": "25",
"output": "8888888888886"
},
{
"input": "26",
"output": "8888888888888"
},
{
"input": "27",
"output": "88888888888886"
},
{
"input": "28",
"output": "88888888888888"
},
{
"input": "29",
"output": "888888888888886"
},
{
"input": "30",
"output": "888888888888888"
},
{
"input": "31",
"output": "8888888888888886"
},
{
"input": "32",
"output": "8888888888888888"
},
{
"input": "33",
"output": "88888888888888886"
},
{
"input": "34",
"output": "88888888888888888"
},
{
"input": "35",
"output": "888888888888888886"
},
{
"input": "36",
"output": "888888888888888888"
},
{
"input": "37",
"output": "-1"
},
{
"input": "38",
"output": "-1"
},
{
"input": "39",
"output": "-1"
},
{
"input": "40",
"output": "-1"
},
{
"input": "462",
"output": "-1"
},
{
"input": "1317",
"output": "-1"
},
{
"input": "88",
"output": "-1"
},
{
"input": "87",
"output": "-1"
}
] | 1,000 | 614,400 | 0 | 5,178 |
|
906 | Shockers | [
"implementation",
"strings"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and *w* is the word that Valentin said. 1. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and *w* is the word that Valentin said. 1. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and *s* is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter. | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin pronounces the word *cd* and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is *e* or *o*. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is *e*, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks. | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"output": "0"
},
{
"input": "1\n? q",
"output": "0"
},
{
"input": "15\n. r\n? e\n. s\n. rw\n? y\n. fj\n. zftyd\n? r\n! wq\n? w\n? p\n. ours\n. dto\n. lbyfru\n? q",
"output": "2"
},
{
"input": "3\n. abcdefghijklmnopqrstuvwxy\n? a\n? z",
"output": "1"
},
{
"input": "3\n. abcdefghijklmnopqrstuvwxy\n! z\n? z",
"output": "1"
}
] | 77 | 5,939,200 | 0 | 5,191 |
|
411 | Multi-core Processor | [
"implementation"
] | null | null | The research center Q has developed a new multi-core processor. The processor consists of *n* cores and has *k* cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within *m* cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the *m* cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100). Then follow *n* lines describing instructions. The *i*-th line contains *m* integers: *x**i*1,<=*x**i*2,<=...,<=*x**im* (0<=≤<=*x**ij*<=≤<=*k*), where *x**ij* is the instruction that must be executed by the *i*-th core at the *j*-th cycle. If *x**ij* equals 0, then the corresponding instruction is «do nothing». But if *x**ij* is a number from 1 to *k*, then the corresponding instruction is «write information to the memory cell number *x**ij*».
We assume that the cores are numbered from 1 to *n*, the work cycles are numbered from 1 to *m* and the memory cells are numbered from 1 to *k*. | Print *n* lines. In the *i*-th line print integer *t**i*. This number should be equal to 0 if the *i*-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked. | [
"4 3 5\n1 0 0\n1 0 2\n2 3 1\n3 2 0\n",
"3 2 2\n1 2\n1 2\n2 2\n",
"1 1 1\n0\n"
] | [
"1\n1\n3\n0\n",
"1\n1\n0\n",
"0\n"
] | none | [
{
"input": "4 3 5\n1 0 0\n1 0 2\n2 3 1\n3 2 0",
"output": "1\n1\n3\n0"
},
{
"input": "3 2 2\n1 2\n1 2\n2 2",
"output": "1\n1\n0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 1\n1\n1",
"output": "1\n1"
},
{
"input": "2 1 1\n1\n0",
"output": "0\n0"
},
{
"input": "2 1 1\n0\n1",
"output": "0\n0"
},
{
"input": "2 1 1\n0\n0",
"output": "0\n0"
},
{
"input": "2 1 2\n1\n2",
"output": "0\n0"
},
{
"input": "2 1 1\n1\n1",
"output": "1\n1"
},
{
"input": "2 2 2\n2 1\n0 2",
"output": "0\n0"
},
{
"input": "1 100 100\n32 97 28 73 22 27 27 21 25 26 21 95 45 60 47 64 44 88 24 10 82 55 84 69 86 70 99 99 34 59 71 83 53 90 29 100 98 68 24 82 5 67 49 70 23 85 5 90 57 0 99 26 32 11 81 92 6 45 32 72 54 32 20 37 40 33 55 55 33 61 13 31 67 51 74 96 67 13 28 3 23 99 26 6 91 95 67 29 46 78 85 17 47 83 26 51 88 31 37 15",
"output": "0"
},
{
"input": "100 1 100\n59\n37\n53\n72\n37\n15\n8\n93\n92\n74\n11\n11\n68\n16\n92\n40\n76\n20\n10\n86\n76\n5\n9\n95\n5\n81\n44\n57\n10\n24\n22\n2\n57\n6\n26\n67\n48\n95\n34\n97\n55\n33\n70\n66\n51\n70\n74\n65\n35\n85\n37\n9\n27\n43\n65\n6\n5\n57\n54\n27\n22\n41\n8\n29\n10\n50\n9\n68\n78\n9\n92\n30\n88\n62\n30\n5\n80\n58\n19\n39\n22\n88\n81\n34\n36\n18\n28\n93\n64\n27\n47\n89\n30\n21\n24\n42\n34\n100\n27\n46",
"output": "0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n0\n0\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n0\n1\n0\n1\n0\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n0\n0\n0\n0\n1\n1\n1\n1\n0\n0\n0\n1\n0\n1\n0\n0\n1\n0\n1\n0\n1\n0\n1\n0"
},
{
"input": "1 100 10\n7 2 8 3 0 10 0 3 0 5 3 6 4 1 2 2 5 1 7 10 7 9 10 6 2 8 6 10 0 10 4 4 4 9 7 0 0 8 6 2 2 4 10 10 5 9 4 6 1 1 9 7 2 7 4 7 2 2 3 3 10 3 8 1 0 4 3 10 9 8 6 2 10 7 5 10 0 3 6 2 3 6 6 2 5 9 10 0 10 4 10 3 4 2 2 10 4 5 7 8",
"output": "0"
},
{
"input": "100 1 10\n10\n6\n8\n2\n4\n3\n3\n2\n0\n2\n10\n5\n10\n4\n10\n2\n6\n9\n1\n1\n1\n3\n7\n3\n9\n10\n6\n1\n4\n1\n4\n1\n4\n4\n5\n1\n9\n4\n10\n3\n3\n2\n8\n10\n1\n2\n10\n4\n8\n8\n4\n8\n6\n3\n8\n6\n8\n1\n2\n3\n2\n2\n9\n4\n1\n10\n10\n7\n8\n10\n8\n8\n10\n9\n2\n0\n5\n0\n9\n0\n2\n6\n7\n4\n5\n4\n2\n3\n1\n9\n7\n0\n10\n7\n2\n1\n1\n9\n6\n7",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n0\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\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\n1\n1\n1\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "7 2 98\n0 72\n71 26\n87 23\n26 37\n65 97\n81 30\n19 83",
"output": "0\n0\n0\n0\n0\n0\n0"
}
] | 62 | 0 | 0 | 5,199 |
|
156 | Cipher | [
"combinatorics",
"dp"
] | null | null | Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of something. Let's say there is a word *s*, consisting of |*s*| lowercase Latin letters. Then for one operation you can choose a certain position *p* (1<=≤<=*p*<=<<=|*s*|) and perform one of the following actions:
- either replace letter *s**p* with the one that alphabetically follows it and replace letter *s**p*<=+<=1 with the one that alphabetically precedes it; - or replace letter *s**p* with the one that alphabetically precedes it and replace letter *s**p*<=+<=1 with the one that alphabetically follows it.
Let us note that letter "z" doesn't have a defined following letter and letter "a" doesn't have a defined preceding letter. That's why the corresponding changes are not acceptable. If the operation requires performing at least one unacceptable change, then such operation cannot be performed.
Two words coincide in their meaning iff one of them can be transformed into the other one as a result of zero or more operations.
Sherlock Holmes needs to learn to quickly determine the following for each word: how many words can exist that coincide in their meaning with the given word, but differs from the given word in at least one character? Count this number for him modulo 1000000007 (109<=+<=7). | The input data contains several tests. The first line contains the only integer *t* (1<=≤<=*t*<=≤<=104) — the number of tests.
Next *t* lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ. | For each word you should print the number of different other words that coincide with it in their meaning — not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109<=+<=7). | [
"1\nab\n",
"1\naaaaaaaaaaa\n",
"2\nya\nklmbfxzb\n"
] | [
"1\n",
"0\n",
"24\n320092793\n"
] | Some explanations about the operation:
- Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y". - Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "a" precedes letter "b". - Note that the operation never changes a word's length.
In the first sample you can obtain the only other word "ba". In the second sample you cannot obtain any other word, so the correct answer is 0.
Consider the third sample. One operation can transform word "klmbfxzb" into word "klmcexzb": we should choose *p* = 4, and replace the fourth letter with the following one ("b" → "c"), and the fifth one — with the preceding one ("f" → "e"). Also, we can obtain many other words from this one. An operation can transform word "ya" only into one other word "xb".
Word "ya" coincides in its meaning with words "xb", "wc", "vd", ..., "ay" (overall there are 24 other words). The word "klmbfxzb has many more variants — there are 3320092814 other words that coincide with in the meaning. So the answer for the first word equals 24 and for the second one equals 320092793 — the number 3320092814 modulo 10<sup class="upper-index">9</sup> + 7 | [
{
"input": "1\nab",
"output": "1"
},
{
"input": "1\naaaaaaaaaaa",
"output": "0"
},
{
"input": "2\nya\nklmbfxzb",
"output": "24\n320092793"
},
{
"input": "1\na",
"output": "0"
},
{
"input": "1\nz",
"output": "0"
},
{
"input": "1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "1\nmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmnmn",
"output": "39086755"
},
{
"input": "15\nejkf\nkc\nu\nznmjnznzn\nbjkcg\nwou\nywy\nqoojqlr\nnbkip\nsgmgjg\ndjjdd\nh\nkgbkri\nt\npvzbvkij",
"output": "4454\n12\n0\n667098198\n35884\n209\n20\n142184034\n186649\n4212829\n31439\n0\n3167654\n0\n474922754"
},
{
"input": "15\nieqqe\nwwbnobrb\ngyftfg\nclrn\nzwtviipwww\nmsmsiih\nofqsusmsmm\nyjomiiq\naedoeun\nz\nmwwmimiwiu\ngtdsifgg\nvmmmren\nzlgzousxzp\ngcpodkxebk",
"output": "195974\n543885418\n5715485\n10619\n87838649\n154292634\n869212338\n155736014\n55669004\n0\n792902040\n590044032\n155736014\n991368939\n271743066"
},
{
"input": "17\nwfvfmnmr\nkyururk\nnei\nmeb\nwldtalawww\njeobzb\nuuww\nwfkgzxmr\nrvvpxrihha\nqz\ngpodf\niatnevlia\njjnaunradf\nwoi\ny\nmewdykdldp\nnckg",
"output": "662991818\n51681734\n350\n170\n598684361\n3582684\n968\n541474246\n55368153\n9\n148439\n157054204\n91519085\n464\n0\n838428119\n5759"
},
{
"input": "17\nku\njf\nygbkcbf\ngmp\nnuaxjssqv\nawxxcxw\nyccccvc\na\nu\nnod\nmfgtj\nekkjbkzr\njtisatba\nxtkxlk\nt\nxkxzuizs\nnvvvqarn",
"output": "20\n14\n25664534\n486\n516112667\n64053170\n44165015\n0\n0\n450\n222299\n145570718\n897496632\n3582684\n0\n190441484\n326269025"
},
{
"input": "19\nqhovyphr\nttymgy\nqbed\nidxitl\nusbrx\nqevvydqdb\nltyjljj\ncgv\nsruvudcu\naqjbqjybyq\nrhtwwtthhh\nh\nksktyyst\npmwmnzswlw\nm\nuwaup\nxhvk\nj\nvii",
"output": "434174305\n2030279\n2924\n6460404\n177169\n583243193\n154292634\n434\n434174305\n191795714\n792902040\n0\n573191111\n676498805\n0\n195974\n9239\n0\n506"
},
{
"input": "10\njrojjyqqjtrfjf\nvuwzvmwjyfvifdfddymwfuzmvvummwdfzjzdvzuvfvjiuvyzymviyyumvziyimfzfiji\nwxzwojjzqzyqlojjbrjlbqrrwqw\nqfwppnuvbgegbqgbmeqpbguwmmqhunnquepepeewubbmnenvmwhnvhunnmsqmmgfepevupewvenmwpmgspnebv\nrxqzorkizznsiirciokscrrjqqqzkfijrrkkfrqjjifczcjcnqoisorszkjxcxvqzcfczqfcrvfrsckvvfjxnxzqjivqv\nnvimavvhfskwkhgvaowsficdmv\nqvrdgohdmgawrqo\npulanukntfhrthkxkprprhrhcouxxnkhoroptcxkfktotkokonoxptcocnfartlucnlncalnknhlpachofclannctpklackcc\ntqezktgzhipiaootfpqpzjgtqitagthef\nqaeigcacoqoc",
"output": "520219051\n945235283\n691128313\n324077859\n417775814\n827035318\n275780270\n145635612\n155578699\n486064325"
},
{
"input": "10\nnnclytzybytthncihlnnbclzcbhinhyzbhnbiyccltnnchylynhznycniiztzcthiyyhccybc\ngbcccdnjbgntyzayntwdf\ndzkxapreirktspflaudtlexeffifxxzxrjaxqfkcncxf\nnilfxfsyliingzbgsxbzxxmqqxnngsfqqqbqinglmbxgysbi\nsjquzchhssjrrzbuc\nhdhvdnjvhreiiekeinvdddneejkrdkjvikj\nanyamaosolahmhnmsmmmmhhofsaalfmomoshy\nnqvzznlicebqsviwivvhhiiciblbelvlelhisclecb\nlbtihlhulugddgtfwjiftfltijwitcgmgvjfcfcdwbliijqhidghdwibpgjqdumdijmhlbdfvcpcqqptcc\nkfjcmfzxhhkhfikihymhmhxuzeykfkmezcmieyxxshjckfxsx",
"output": "860385290\n566220124\n563237657\n25482967\n365565922\n211740598\n627945017\n550126162\n997587067\n505019519"
}
] | 654 | 3,276,800 | 0 | 5,203 |
|
893 | Beautiful Divisors | [
"brute force",
"implementation"
] | null | null | Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of *k*<=+<=1 consecutive ones, and then *k* consecutive zeroes.
Some examples of beautiful numbers:
- 12 (110); - 1102 (610); - 11110002 (12010); - 1111100002 (49610).
More formally, the number is beautiful iff there exists some positive integer *k* such that the number is equal to (2*k*<=-<=1)<=*<=(2*k*<=-<=1).
Luba has got an integer number *n*, and she wants to find its greatest beautiful divisor. Help her to find it! | The only line of input contains one number *n* (1<=≤<=*n*<=≤<=105) — the number Luba has got. | Output one number — the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists. | [
"3\n",
"992\n"
] | [
"1\n",
"496\n"
] | none | [
{
"input": "3",
"output": "1"
},
{
"input": "992",
"output": "496"
},
{
"input": "81142",
"output": "1"
},
{
"input": "76920",
"output": "120"
},
{
"input": "2016",
"output": "2016"
},
{
"input": "1",
"output": "1"
},
{
"input": "6",
"output": "6"
},
{
"input": "32640",
"output": "32640"
},
{
"input": "12096",
"output": "2016"
},
{
"input": "55948",
"output": "1"
},
{
"input": "47262",
"output": "6"
},
{
"input": "22876",
"output": "28"
},
{
"input": "96120",
"output": "120"
},
{
"input": "42160",
"output": "496"
},
{
"input": "38304",
"output": "2016"
},
{
"input": "89408",
"output": "8128"
},
{
"input": "97920",
"output": "32640"
},
{
"input": "55493",
"output": "1"
},
{
"input": "38021",
"output": "1"
},
{
"input": "21445",
"output": "1"
},
{
"input": "100000",
"output": "1"
},
{
"input": "497",
"output": "1"
},
{
"input": "240",
"output": "120"
},
{
"input": "21204",
"output": "6"
},
{
"input": "65536",
"output": "1"
},
{
"input": "364",
"output": "28"
},
{
"input": "1024",
"output": "1"
},
{
"input": "36",
"output": "6"
},
{
"input": "28",
"output": "28"
},
{
"input": "14400",
"output": "120"
},
{
"input": "10080",
"output": "2016"
},
{
"input": "9",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "42",
"output": "6"
},
{
"input": "83160",
"output": "120"
},
{
"input": "65534",
"output": "1"
},
{
"input": "1026",
"output": "6"
},
{
"input": "1025",
"output": "1"
},
{
"input": "1027",
"output": "1"
},
{
"input": "2018",
"output": "1"
},
{
"input": "2020",
"output": "1"
},
{
"input": "123",
"output": "1"
},
{
"input": "150",
"output": "6"
},
{
"input": "5",
"output": "1"
},
{
"input": "66",
"output": "6"
},
{
"input": "12768",
"output": "28"
},
{
"input": "156",
"output": "6"
},
{
"input": "99990",
"output": "6"
},
{
"input": "248",
"output": "1"
}
] | 124 | 20,172,800 | 3 | 5,204 |
|
1,010 | Fly | [
"binary search",
"math"
] | null | null | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists of two phases: take-off from planet $x$ and landing to planet $y$. This way, the overall itinerary of the trip will be: the $1$-st planet $\to$ take-off from the $1$-st planet $\to$ landing to the $2$-nd planet $\to$ $2$-nd planet $\to$ take-off from the $2$-nd planet $\to$ $\ldots$ $\to$ landing to the $n$-th planet $\to$ the $n$-th planet $\to$ take-off from the $n$-th planet $\to$ landing to the $1$-st planet $\to$ the $1$-st planet.
The mass of the rocket together with all the useful cargo (but without fuel) is $m$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $1$ ton of fuel can lift off $a_i$ tons of rocket from the $i$-th planet or to land $b_i$ tons of rocket onto the $i$-th planet.
For example, if the weight of rocket is $9$ tons, weight of fuel is $3$ tons and take-off coefficient is $8$ ($a_i = 8$), then $1.5$ tons of fuel will be burnt (since $1.5 \cdot 8 = 9 + 3$). The new weight of fuel after take-off will be $1.5$ tons.
Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.
Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly. | The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted off by one ton of fuel.
The fourth line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($1 \le b_i \le 1000$), where $b_i$ is the number of tons, which can be landed by one ton of fuel.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel. | If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Formally, let your answer be $p$, and the jury's answer be $q$. Your answer is considered correct if $\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$. | [
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] | [
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] | Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fuel can land $5$ tons of cargo, so for landing $20$ tons you will need to burn $4$ tons of fuel. There will be $16$ tons of the rocket with fuel remaining.- While taking off from Mars, one ton of fuel can raise $8$ tons of cargo, so to lift off $16$ tons you will need to burn $2$ tons of fuel. There will be $14$ tons of rocket with fuel after that.- During landing on Earth, one ton of fuel can land $7$ tons of cargo, so for landing $14$ tons you will need to burn $2$ tons of fuel. Remaining weight is $12$ tons, that is, a rocket without any fuel.
In the second case, the rocket will not be able even to take off from Earth. | [
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2 3 4 3",
"output": "284.0000000000"
},
{
"input": "5\n2\n1 2 2 1 2\n4 5 1 4 1",
"output": "-1"
},
{
"input": "7\n7\n3 2 6 2 2 2 5\n4 7 5 6 2 2 2",
"output": "4697.0000000000"
},
{
"input": "2\n1000\n12 34\n56 78",
"output": "159.2650775220"
},
{
"input": "8\n4\n1 1 4 1 3 1 8 1\n1 1 1 1 1 3 1 2",
"output": "-1"
},
{
"input": "9\n2\n8 7 1 1 3 7 1 2 4\n4 1 1 8 7 7 1 1 5",
"output": "-1"
},
{
"input": "10\n10\n9 8 8 7 2 10 2 9 2 4\n3 10 6 2 6 6 5 9 4 5",
"output": "3075.7142857143"
},
{
"input": "20\n12\n3 9 12 13 16 18 9 9 19 7 2 5 17 14 7 7 15 16 5 7\n16 9 13 5 14 10 4 3 16 16 12 20 17 11 4 5 5 14 6 15",
"output": "4670.8944493007"
},
{
"input": "30\n5\n25 1 28 1 27 25 24 1 28 1 12 1 29 16 1 1 1 1 27 1 24 1 1 1 1 1 1 1 30 3\n1 22 1 1 24 2 13 1 16 21 1 27 14 16 1 1 7 1 1 18 1 23 10 1 15 16 16 15 10 1",
"output": "-1"
},
{
"input": "40\n13\n1 1 1 23 21 1 1 1 1 1 40 32 1 21 1 8 1 1 36 15 33 1 30 1 1 37 22 1 4 39 7 1 9 37 1 1 1 28 1 1\n1 34 17 1 38 20 8 14 1 18 29 3 21 21 18 14 1 11 1 1 23 1 25 1 14 1 7 31 9 20 25 1 1 1 1 8 26 12 1 1",
"output": "-1"
},
{
"input": "50\n19\n17 7 13 42 19 25 10 25 2 36 17 40 30 48 34 43 34 20 5 15 8 7 43 35 21 40 40 19 30 11 49 7 24 23 43 30 38 49 10 8 30 11 28 50 48 25 25 20 48 24\n49 35 10 22 24 50 50 7 6 13 16 35 12 43 50 44 35 33 38 49 26 18 23 37 7 38 23 20 28 48 41 16 6 32 32 34 11 39 38 9 38 23 16 31 37 47 33 20 46 30",
"output": "7832.1821424977"
},
{
"input": "60\n21\n11 35 1 28 39 13 19 56 13 13 21 25 1 1 23 1 52 26 53 1 1 1 30 39 1 7 1 1 3 1 1 10 1 1 37 1 1 25 1 1 1 53 1 3 48 1 6 5 4 15 1 14 25 53 25 38 27 1 1 1\n1 1 1 35 40 58 10 22 1 56 1 59 1 6 33 1 1 1 1 18 14 1 1 40 25 47 1 34 1 1 53 1 1 25 1 45 1 1 25 34 3 1 1 1 53 27 11 58 1 1 1 10 12 1 1 1 31 52 1 1",
"output": "-1"
},
{
"input": "70\n69\n70 66 57 58 24 60 39 2 48 61 65 22 10 26 68 62 48 25 12 14 45 57 6 30 48 15 46 33 42 28 69 42 64 25 24 8 62 12 68 53 55 20 32 70 3 5 41 49 16 26 2 34 34 20 39 65 18 47 62 31 39 28 61 67 7 14 31 31 53 54\n40 33 24 20 68 20 22 39 53 56 48 38 59 45 47 46 7 69 11 58 61 40 35 38 62 66 18 36 44 48 67 24 14 27 67 63 68 30 50 6 58 7 6 35 20 58 6 12 12 23 14 2 63 27 29 22 49 16 55 40 70 27 27 70 42 38 66 55 69 47",
"output": "217989.4794743629"
},
{
"input": "80\n21\n65 4 26 25 1 1 1 1 1 1 60 1 29 43 48 6 48 13 29 1 1 62 1 1 1 1 1 1 1 26 9 1 22 1 35 13 66 36 1 1 1 38 55 21 70 1 58 70 1 1 38 1 1 20 1 1 51 1 1 28 1 23 11 1 39 47 1 52 41 1 63 1 1 52 1 45 11 10 80 1\n1 1 25 30 1 1 55 54 1 48 10 37 22 1 74 1 78 13 1 65 32 1 1 1 1 69 5 59 1 1 65 1 40 1 31 1 1 75 54 1 60 1 1 1 1 1 1 1 11 29 36 1 72 71 52 1 1 1 37 1 1 75 43 9 53 1 62 1 29 1 40 27 59 74 41 53 19 30 1 73",
"output": "-1"
},
{
"input": "90\n35\n1 68 16 30 24 1 1 1 35 1 1 67 1 1 1 1 33 16 37 77 83 1 77 26 1 1 68 67 70 62 1 47 1 1 1 84 1 65 1 32 83 1 1 1 28 1 71 76 84 1 1 5 1 74 10 1 1 1 38 87 13 1 7 66 81 49 1 9 1 11 1 25 1 1 1 1 7 1 1 36 61 47 51 1 1 69 40 1 37 1\n40 1 21 1 19 51 37 52 64 1 86 1 5 24 1 1 1 19 36 1 1 77 24 4 1 18 89 1 1 1 1 1 29 22 1 80 32 36 6 1 63 1 30 1 1 1 86 79 73 52 9 1 1 11 7 1 25 20 1 20 1 49 1 37 1 41 1 1 1 1 54 55 1 10 1 1 1 1 1 1 66 1 68 1 1 1 1 53 1 1",
"output": "-1"
},
{
"input": "2\n1\n1 1\n1 1",
"output": "-1"
},
{
"input": "2\n1\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n1\n2 2\n1 1",
"output": "-1"
},
{
"input": "2\n1\n2 2\n2 2",
"output": "15.0000000000"
},
{
"input": "2\n2\n1 1\n1 1",
"output": "-1"
},
{
"input": "2\n2\n1 1\n2 2",
"output": "-1"
},
{
"input": "2\n2\n2 2\n1 1",
"output": "-1"
},
{
"input": "2\n2\n2 2\n2 2",
"output": "30.0000000000"
},
{
"input": "40\n55\n1 382 1 1 1 629 111 689 396 614 1 1 995 148 7 820 913 1 1 169 157 1 702 1 159 1 1 226 1 253 1 319 1 130 1 1 1 466 1 756\n1 23 555 1 412 1 1 373 316 234 888 1 112 818 33 443 313 1 235 1 1 610 110 535 1 445 1 386 1 1 758 1 292 1 862 1 244 428 530 1",
"output": "-1"
},
{
"input": "49\n1\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\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "695580114.6380882263"
},
{
"input": "2\n12\n11 8\n1 1",
"output": "-1"
},
{
"input": "3\n3\n7 11 17\n19 31 33",
"output": "1.6012429470"
}
] | 217 | 2,355,200 | -1 | 5,205 |
|
600 | Edge coloring of bipartite graph | [
"graphs"
] | null | null | You are given an undirected bipartite graph without multiple edges. You should paint the edges of graph to minimal number of colours, so that no two adjacent edges have the same colour. | The first line contains three integers *a*,<=*b*,<=*m* (1<=≤<=*a*,<=*b*<=≤<=1000, 0<=≤<=*m*<=≤<=105), *a* is the size of the first part, *b* is the size of the second part, *m* is the number of edges in the graph.
Each of the next *m* lines contains two integers *x*,<=*y* (1<=≤<=*x*<=≤<=*a*,<=1<=≤<=*y*<=≤<=*b*), where *x* is the number of the vertex in the first part and *y* is the number of the vertex in the second part. It is guaranteed that there are no multiple edges. | In the first line print integer *c* — the minimal number of colours. The second line should contain *m* integers from 1 to *c* — the colours of the edges (in the order they appear in the input).
If there are several solutions, you can print any one of them. | [
"4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3\n"
] | [
"3\n1 2 3 1 2\n"
] | none | [
{
"input": "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3",
"output": "3\n1 2 3 1 2"
},
{
"input": "4 3 5\n1 2\n2 2\n3 2\n4 1\n4 3",
"output": "3\n1 2 3 1 2"
},
{
"input": "4 3 0",
"output": "0"
},
{
"input": "10 10 67\n1 1\n1 2\n1 3\n1 7\n1 9\n1 10\n2 1\n2 2\n2 3\n2 6\n2 8\n2 10\n3 2\n3 3\n3 6\n3 8\n3 9\n3 10\n4 1\n4 4\n4 5\n4 6\n4 7\n4 8\n5 2\n5 4\n5 7\n5 8\n5 9\n5 10\n6 1\n6 2\n6 3\n6 4\n6 6\n6 8\n6 9\n6 10\n7 2\n7 4\n7 6\n7 9\n7 10\n8 3\n8 4\n8 5\n8 6\n8 7\n8 8\n8 9\n8 10\n9 1\n9 2\n9 3\n9 5\n9 6\n9 7\n9 8\n9 9\n9 10\n10 1\n10 3\n10 4\n10 5\n10 8\n10 9\n10 10",
"output": "9\n3 2 1 4 5 6 2 6 4 3 5 1 1 2 4 3 6 5 1 3 4 5 6 2 3 5 1 6 4 2 4 5 3 2 6 1 7 8 4 8 2 3 7 5 4 6 7 2 8 1 3 5 7 6 1 8 3 4 2 9 6 7 1 2 9 8 4"
},
{
"input": "10 10 27\n1 10\n2 1\n2 3\n2 6\n2 8\n3 2\n3 4\n3 5\n4 1\n4 3\n4 5\n5 2\n5 5\n5 6\n6 1\n6 6\n7 8\n7 9\n8 1\n8 3\n8 6\n8 8\n9 1\n9 10\n10 2\n10 4\n10 5",
"output": "5\n1 1 2 3 4 1 2 3 2 1 4 2 1 4 3 2 1 2 4 3 1 2 5 2 3 1 2"
},
{
"input": "10 10 10\n1 7\n1 10\n2 3\n3 3\n4 5\n4 6\n4 7\n5 5\n8 10\n10 9",
"output": "3\n1 2 1 2 1 2 3 2 1 1"
},
{
"input": "100 100 50\n6 1\n6 89\n12 34\n14 4\n16 12\n20 45\n22 41\n22 87\n25 81\n30 92\n30 98\n31 16\n31 89\n32 84\n33 45\n33 94\n34 97\n36 94\n37 81\n39 23\n40 55\n40 60\n42 82\n44 80\n46 57\n46 86\n50 48\n55 33\n56 59\n56 76\n64 27\n64 60\n65 24\n71 95\n72 28\n74 23\n76 11\n80 34\n80 46\n81 22\n81 46\n85 2\n87 9\n91 97\n92 35\n95 22\n97 87\n98 29\n98 74\n100 7",
"output": "2\n1 2 1 1 1 1 1 2 1 1 2 2 1 1 2 1 1 2 2 1 1 2 1 1 1 2 1 1 1 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 1 2 1 1 2 1"
},
{
"input": "100 100 50\n3 71\n3 97\n5 65\n7 49\n9 85\n10 92\n12 60\n16 52\n17 13\n18 22\n22 85\n24 16\n27 47\n29 18\n31 83\n36 10\n37 68\n37 75\n38 1\n41 48\n43 99\n45 65\n45 96\n46 33\n50 39\n51 43\n53 55\n59 4\n63 1\n64 58\n64 92\n65 95\n70 49\n74 52\n75 51\n76 29\n76 43\n80 92\n84 51\n85 25\n85 37\n86 24\n86 81\n87 51\n91 7\n93 33\n97 50\n100 39\n100 59\n100 66",
"output": "3\n1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 2 1 2 1 2 2 1 1 2 3 2 1 2 1 2 3 1 2 1 2 1 3"
},
{
"input": "100 100 50\n4 76\n7 17\n8 6\n8 58\n11 56\n12 79\n14 38\n19 39\n22 50\n24 33\n27 41\n29 5\n29 35\n30 20\n31 37\n31 80\n32 50\n38 39\n42 49\n42 59\n48 1\n48 80\n49 36\n49 70\n50 95\n51 3\n51 33\n57 28\n59 71\n59 94\n59 95\n61 70\n63 5\n63 98\n64 73\n66 65\n74 85\n77 13\n77 59\n78 61\n79 4\n80 39\n82 91\n85 82\n85 92\n86 45\n88 32\n89 7\n93 21\n96 36",
"output": "3\n1 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 2 2 1 2 2 1 1 2 1 1 2 1 1 2 3 1 2 1 1 1 1 1 3 1 1 3 1 1 2 1 1 1 1 2"
},
{
"input": "15 15 54\n1 1\n1 3\n1 5\n1 10\n1 14\n1 15\n2 3\n2 5\n2 14\n3 4\n3 10\n4 2\n4 13\n4 15\n5 4\n5 8\n5 10\n6 4\n6 6\n6 7\n6 8\n6 15\n7 3\n7 6\n7 7\n7 10\n8 1\n8 4\n8 6\n8 13\n9 2\n9 3\n10 2\n10 7\n10 15\n11 3\n11 6\n11 7\n11 10\n11 11\n12 5\n12 9\n12 10\n13 11\n14 2\n14 8\n14 12\n14 14\n14 15\n15 4\n15 5\n15 6\n15 10\n15 15",
"output": "7\n1 2 3 4 5 6 1 2 3 1 2 1 2 3 2 1 3 3 1 2 4 5 3 2 1 5 2 4 3 1 2 4 3 4 1 5 4 3 1 2 4 2 6 1 4 3 1 6 2 5 1 6 7 4"
},
{
"input": "15 15 49\n1 4\n1 7\n1 9\n1 11\n1 13\n2 1\n2 2\n2 4\n2 6\n2 8\n2 12\n2 13\n3 1\n3 2\n3 5\n3 9\n3 10\n4 2\n4 5\n4 6\n5 1\n5 8\n5 12\n6 1\n6 6\n6 15\n7 14\n8 2\n8 5\n8 6\n8 15\n9 1\n9 6\n9 13\n10 9\n10 11\n11 1\n11 2\n12 3\n12 7\n12 14\n13 5\n13 9\n13 14\n14 2\n14 3\n14 13\n15 10\n15 15",
"output": "7\n1 2 3 4 5 1 2 3 4 5 6 7 2 1 3 4 5 3 1 2 3 1 2 4 1 2 1 4 2 3 1 5 6 1 1 2 6 5 1 3 2 4 2 3 6 2 3 1 3"
},
{
"input": "15 15 49\n1 4\n1 7\n1 9\n1 11\n1 13\n2 1\n2 2\n2 4\n2 6\n2 8\n2 12\n2 13\n3 1\n3 2\n3 5\n3 9\n3 10\n4 2\n4 5\n4 6\n5 1\n5 8\n5 12\n6 1\n6 6\n6 15\n7 14\n8 2\n8 5\n8 6\n8 15\n9 1\n9 6\n9 13\n10 9\n10 11\n11 1\n11 2\n12 3\n12 7\n12 14\n13 5\n13 9\n13 14\n14 2\n14 3\n14 13\n15 10\n15 15",
"output": "7\n1 2 3 4 5 1 2 3 4 5 6 7 2 1 3 4 5 3 1 2 3 1 2 4 1 2 1 4 2 3 1 5 6 1 1 2 6 5 1 3 2 4 2 3 6 2 3 1 3"
},
{
"input": "15 15 53\n1 6\n2 4\n2 10\n3 3\n3 4\n3 11\n3 13\n3 14\n4 2\n4 12\n5 7\n5 8\n5 10\n6 1\n6 9\n7 10\n7 15\n8 7\n8 8\n9 4\n9 5\n9 6\n9 8\n9 11\n9 15\n10 1\n10 11\n10 15\n11 5\n11 7\n11 10\n11 12\n11 13\n12 1\n12 2\n12 4\n12 8\n12 10\n13 6\n13 7\n13 9\n13 13\n13 14\n14 9\n14 10\n14 15\n15 5\n15 8\n15 10\n15 11\n15 12\n15 14\n15 15",
"output": "7\n1 1 2 1 2 3 4 5 1 2 1 2 3 1 2 1 2 2 1 3 1 2 4 5 6 2 1 3 2 3 4 1 5 3 2 4 5 6 3 4 1 2 6 3 5 1 3 6 7 2 4 1 5"
},
{
"input": "139 1000 0",
"output": "0"
},
{
"input": "139 1000 1\n75 791",
"output": "1\n1"
}
] | 108 | 2,252,800 | -1 | 5,209 |
|
140 | New Year Table | [
"geometry",
"math"
] | null | null | Gerald is setting the New Year table. The table has the form of a circle; its radius equals *R*. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal *r*. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for *n* plates. | The first line contains three integers *n*, *R* and *r* (1<=≤<=*n*<=≤<=100, 1<=≤<=*r*,<=*R*<=≤<=1000) — the number of plates, the radius of the table and the plates' radius. | Print "YES" (without the quotes) if it is possible to place *n* plates on the table by the rules given above. If it is impossible, print "NO".
Remember, that each plate must touch the edge of the table. | [
"4 10 4\n",
"5 10 4\n",
"1 10 10\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | The possible arrangement of the plates for the first sample is: | [
{
"input": "4 10 4",
"output": "YES"
},
{
"input": "5 10 4",
"output": "NO"
},
{
"input": "1 10 10",
"output": "YES"
},
{
"input": "3 10 20",
"output": "NO"
},
{
"input": "2 20 11",
"output": "NO"
},
{
"input": "6 9 3",
"output": "YES"
},
{
"input": "1 999 1000",
"output": "NO"
},
{
"input": "1 1000 999",
"output": "YES"
},
{
"input": "2 1000 500",
"output": "YES"
},
{
"input": "2 1000 499",
"output": "YES"
},
{
"input": "10 1000 236",
"output": "YES"
},
{
"input": "10 1000 237",
"output": "NO"
},
{
"input": "6 999 334",
"output": "NO"
},
{
"input": "100 1000 1",
"output": "YES"
},
{
"input": "100 1000 50",
"output": "NO"
},
{
"input": "13 927 179",
"output": "YES"
},
{
"input": "13 145 28",
"output": "NO"
},
{
"input": "37 307 24",
"output": "YES"
},
{
"input": "37 857 67",
"output": "NO"
},
{
"input": "100 821 25",
"output": "YES"
},
{
"input": "100 197 6",
"output": "NO"
},
{
"input": "93 704 23",
"output": "YES"
},
{
"input": "93 857 28",
"output": "NO"
},
{
"input": "85 870 31",
"output": "YES"
},
{
"input": "85 449 16",
"output": "NO"
},
{
"input": "29 10 1",
"output": "NO"
},
{
"input": "3 10 5",
"output": "NO"
},
{
"input": "2 4 2",
"output": "YES"
},
{
"input": "2 10 5",
"output": "YES"
},
{
"input": "4 2 1",
"output": "NO"
},
{
"input": "3 2 1",
"output": "NO"
},
{
"input": "59 486 43",
"output": "NO"
},
{
"input": "4 997 413",
"output": "NO"
},
{
"input": "100 100 5",
"output": "NO"
},
{
"input": "2 100 50",
"output": "YES"
},
{
"input": "2 2 1",
"output": "YES"
},
{
"input": "1 100 45",
"output": "YES"
},
{
"input": "2 20 10",
"output": "YES"
},
{
"input": "36 474 38",
"output": "NO"
},
{
"input": "6 996 333",
"output": "NO"
},
{
"input": "23 100 12",
"output": "NO"
},
{
"input": "100 886 27",
"output": "NO"
},
{
"input": "7 997 332",
"output": "NO"
},
{
"input": "10 72 17",
"output": "NO"
},
{
"input": "85 449 16",
"output": "NO"
},
{
"input": "2 10 10",
"output": "NO"
}
] | 404 | 1,024,000 | -1 | 5,228 |
|
154 | Colliders | [
"math",
"number theory"
] | null | null | By 2312 there were *n* Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to *n*. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated.
In 2312 there was a startling discovery: a collider's activity is safe if and only if all numbers of activated colliders are pairwise relatively prime to each other (two numbers are relatively prime if their greatest common divisor equals 1)! If two colliders with relatively nonprime numbers are activated, it will cause a global collapse.
Upon learning this, physicists rushed to turn the colliders on and off and carry out all sorts of experiments. To make sure than the scientists' quickness doesn't end with big trouble, the Large Hadron Colliders' Large Remote Control was created. You are commissioned to write the software for the remote (well, you do not expect anybody to operate it manually, do you?).
Initially, all colliders are deactivated. Your program receives multiple requests of the form "activate/deactivate the *i*-th collider". The program should handle requests in the order of receiving them. The program should print the processed results in the format described below.
To the request of "+ i" (that is, to activate the *i*-th collider), the program should print exactly one of the following responses:
- "Success" if the activation was successful. - "Already on", if the *i*-th collider was already activated before the request. - "Conflict with j", if there is a conflict with the *j*-th collider (that is, the *j*-th collider is on, and numbers *i* and *j* are not relatively prime). In this case, the *i*-th collider shouldn't be activated. If a conflict occurs with several colliders simultaneously, you should print the number of any of them.
The request of "- i" (that is, to deactivate the *i*-th collider), should receive one of the following responses from the program:
- "Success", if the deactivation was successful. - "Already off", if the *i*-th collider was already deactivated before the request.
You don't need to print quotes in the output of the responses to the requests. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of colliders and the number of requests, correspondingly.
Next *m* lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the *i*-th collider, or "- i" (without the quotes) — deactivate the *i*-th collider (1<=≤<=*i*<=≤<=*n*). | Print *m* lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes. | [
"10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3\n"
] | [
"Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on\n"
] | Note that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3". | [
{
"input": "10 10\n+ 6\n+ 10\n+ 5\n- 10\n- 5\n- 6\n+ 10\n+ 3\n+ 6\n+ 3",
"output": "Success\nConflict with 6\nSuccess\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 10\nAlready on"
},
{
"input": "7 5\n+ 7\n+ 6\n+ 4\n+ 3\n- 7",
"output": "Success\nSuccess\nConflict with 6\nConflict with 6\nSuccess"
},
{
"input": "10 5\n+ 2\n- 8\n- 4\n- 10\n+ 1",
"output": "Success\nAlready off\nAlready off\nAlready off\nSuccess"
},
{
"input": "10 10\n+ 1\n+ 10\n- 1\n- 10\n+ 1\n- 1\n+ 7\n+ 8\n+ 6\n- 7",
"output": "Success\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 8\nSuccess"
},
{
"input": "15 15\n+ 12\n+ 6\n+ 13\n- 13\n+ 7\n+ 14\n+ 8\n+ 13\n- 13\n+ 15\n+ 4\n+ 10\n+ 11\n+ 2\n- 14",
"output": "Success\nConflict with 12\nSuccess\nSuccess\nSuccess\nConflict with 12\nConflict with 12\nSuccess\nSuccess\nConflict with 12\nConflict with 12\nConflict with 12\nSuccess\nConflict with 12\nAlready off"
},
{
"input": "2 20\n+ 1\n+ 2\n- 2\n+ 2\n- 1\n- 2\n+ 2\n- 2\n+ 2\n+ 1\n- 1\n+ 1\n- 1\n- 2\n+ 1\n- 1\n+ 1\n- 1\n+ 2\n+ 1",
"output": "Success\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess"
},
{
"input": "2 20\n- 1\n- 2\n- 1\n- 2\n+ 2\n+ 1\n- 1\n+ 1\n+ 1\n+ 2\n- 2\n+ 1\n- 2\n+ 2\n+ 1\n+ 1\n+ 1\n- 1\n- 1\n- 2",
"output": "Already off\nAlready off\nAlready off\nAlready off\nSuccess\nSuccess\nSuccess\nSuccess\nAlready on\nAlready on\nSuccess\nAlready on\nAlready off\nSuccess\nAlready on\nAlready on\nAlready on\nSuccess\nAlready off\nSuccess"
},
{
"input": "25 20\n+ 7\n+ 14\n- 7\n+ 11\n+ 15\n+ 10\n+ 20\n- 15\n+ 13\n- 14\n+ 4\n- 11\n- 20\n+ 15\n+ 16\n+ 3\n+ 11\n+ 22\n- 16\n- 22",
"output": "Success\nConflict with 7\nSuccess\nSuccess\nSuccess\nConflict with 15\nConflict with 15\nSuccess\nSuccess\nAlready off\nSuccess\nSuccess\nAlready off\nSuccess\nConflict with 4\nConflict with 15\nSuccess\nConflict with 4\nAlready off\nAlready off"
},
{
"input": "50 30\n- 39\n- 2\n+ 37\n- 10\n+ 27\n- 25\n+ 41\n+ 23\n- 36\n+ 49\n+ 5\n- 28\n+ 22\n+ 45\n+ 1\n+ 23\n+ 36\n+ 35\n- 4\n- 28\n- 10\n- 36\n- 38\n- 2\n- 38\n- 38\n- 37\n+ 8\n- 27\n- 28",
"output": "Already off\nAlready off\nSuccess\nAlready off\nSuccess\nAlready off\nSuccess\nSuccess\nAlready off\nSuccess\nSuccess\nAlready off\nSuccess\nConflict with 27\nSuccess\nAlready on\nConflict with 22\nConflict with 5\nAlready off\nAlready off\nAlready off\nAlready off\nAlready off\nAlready off\nAlready off\nAlready off\nSuccess\nConflict with 22\nSuccess\nAlready off"
},
{
"input": "50 50\n+ 14\n+ 4\n+ 20\n+ 37\n+ 50\n+ 46\n+ 19\n- 20\n+ 25\n+ 47\n+ 10\n+ 6\n+ 34\n+ 12\n+ 41\n- 47\n+ 9\n+ 22\n+ 28\n- 41\n- 34\n+ 47\n+ 40\n- 12\n+ 42\n- 9\n- 4\n+ 15\n- 15\n+ 27\n+ 8\n+ 38\n+ 9\n+ 4\n+ 17\n- 8\n+ 13\n- 47\n+ 7\n- 9\n- 38\n+ 30\n+ 48\n- 50\n- 7\n+ 41\n+ 34\n+ 23\n+ 11\n+ 16",
"output": "Success\nConflict with 14\nConflict with 14\nSuccess\nConflict with 14\nConflict with 14\nSuccess\nAlready off\nSuccess\nSuccess\nConflict with 14\nConflict with 14\nConflict with 14\nConflict with 14\nSuccess\nSuccess\nSuccess\nConflict with 14\nConflict with 14\nSuccess\nAlready off\nSuccess\nConflict with 14\nAlready off\nConflict with 14\nSuccess\nAlready off\nConflict with 25\nAlready off\nSuccess\nConflict with 14\nConflict with 14\nConflict with 27\nConflict with 14\nSuccess\nAlready off\nSuccess\nS..."
},
{
"input": "100 1\n+ 51",
"output": "Success"
},
{
"input": "1 100\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1\n+ 1\n- 1",
"output": "Success\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess..."
},
{
"input": "100 50\n+ 2\n+ 3\n+ 5\n+ 7\n+ 11\n+ 13\n+ 17\n+ 19\n+ 23\n+ 29\n+ 31\n+ 37\n+ 41\n+ 43\n+ 47\n+ 53\n+ 59\n+ 61\n+ 67\n+ 71\n+ 73\n+ 79\n+ 83\n+ 89\n+ 97\n+ 52\n+ 96\n+ 54\n+ 56\n+ 88\n+ 69\n+ 65\n+ 84\n+ 10\n+ 85\n- 37\n+ 80\n- 53\n+ 25\n- 5\n+ 45\n+ 90\n+ 95\n+ 33\n+ 81\n+ 6\n+ 20\n- 10\n+ 94\n- 61",
"output": "Success\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nSuccess\nConflict with 2\nConflict with 2\nConflict with 2\nConflict with 2\nConflict with 2\nConflict with 3\nConflict with 5\nConflict with 2\nConflict with 2\nConflict with 5\nSuccess\nConflict with 2\nSuccess\nConflict with 5\nSuccess\nConflict with 3\nConflict with 2\nConflict with 19\nCon..."
},
{
"input": "100000 1\n+ 12345",
"output": "Success"
},
{
"input": "4 2\n+ 2\n+ 4",
"output": "Success\nConflict with 2"
},
{
"input": "100000 2\n+ 57314\n+ 85971",
"output": "Success\nConflict with 57314"
},
{
"input": "100000 4\n+ 81799\n+ 81799\n- 81799\n+ 81799",
"output": "Success\nAlready on\nSuccess\nSuccess"
}
] | 2,000 | 0 | 0 | 5,234 |
|
0 | none | [
"none"
] | null | null | Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times:
- A BC - B AC - C AB - AAA empty string
Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source. | The first line contains a string *S* (1<=≤<=|*S*|<=≤<=105). The second line contains a string *T* (1<=≤<=|*T*|<=≤<=105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'.
The third line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105).
The following *Q* lines describe queries. The *i*-th of these lines contains four space separated integers *a**i*, *b**i*, *c**i*, *d**i*. These represent the *i*-th query: is it possible to create *T*[*c**i*..*d**i*] from *S*[*a**i*..*b**i*] by applying the above transitions finite amount of times?
Here, *U*[*x*..*y*] is a substring of *U* that begins at index *x* (indexed from 1) and ends at index *y*. In particular, *U*[1..|*U*|] is the whole string *U*.
It is guaranteed that 1<=≤<=*a*<=≤<=*b*<=≤<=|*S*| and 1<=≤<=*c*<=≤<=*d*<=≤<=|*T*|. | Print a string of *Q* characters, where the *i*-th character is '1' if the answer to the *i*-th query is positive, and '0' otherwise. | [
"AABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3\n"
] | [
"10011\n"
] | In the first query we can achieve the result, for instance, by using transitions <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/2c164f8b6e335aa51b97bbd019ca0d7326927314.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'. | [] | 124 | 0 | 0 | 5,235 |
|
87 | Trains | [
"implementation",
"math"
] | A. Trains | 2 | 256 | Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence.
When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample).
We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously.
Help Vasya count to which girlfriend he will go more often. | The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). | Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. | [
"3 7\n",
"5 3\n",
"2 3\n"
] | [
"Dasha\n",
"Masha\n",
"Equal\n"
] | Let's take a look at the third sample. Let the trains start to go at the zero moment of time. It is clear that the moments of the trains' arrival will be periodic with period 6. That's why it is enough to show that if Vasya descends to the subway at a moment of time inside the interval (0, 6], he will go to both girls equally often.
If he descends to the subway at a moment of time from 0 to 2, he leaves for Dasha on the train that arrives by the second minute.
If he descends to the subway at a moment of time from 2 to 3, he leaves for Masha on the train that arrives by the third minute.
If he descends to the subway at a moment of time from 3 to 4, he leaves for Dasha on the train that arrives by the fourth minute.
If he descends to the subway at a moment of time from 4 to 6, he waits for both trains to arrive by the sixth minute and goes to Masha as trains go less often in Masha's direction.
In sum Masha and Dasha get equal time — three minutes for each one, thus, Vasya will go to both girlfriends equally often. | [
{
"input": "3 7",
"output": "Dasha"
},
{
"input": "5 3",
"output": "Masha"
},
{
"input": "2 3",
"output": "Equal"
},
{
"input": "31 88",
"output": "Dasha"
},
{
"input": "8 75",
"output": "Dasha"
},
{
"input": "32 99",
"output": "Dasha"
},
{
"input": "77 4",
"output": "Masha"
},
{
"input": "27 1",
"output": "Masha"
},
{
"input": "84 11",
"output": "Masha"
},
{
"input": "4 6",
"output": "Equal"
},
{
"input": "52 53",
"output": "Equal"
},
{
"input": "397 568",
"output": "Dasha"
},
{
"input": "22 332",
"output": "Dasha"
},
{
"input": "419 430",
"output": "Dasha"
},
{
"input": "638 619",
"output": "Masha"
},
{
"input": "393 325",
"output": "Masha"
},
{
"input": "876 218",
"output": "Masha"
},
{
"input": "552 551",
"output": "Equal"
},
{
"input": "906 912",
"output": "Equal"
},
{
"input": "999 996",
"output": "Equal"
},
{
"input": "652 653",
"output": "Equal"
},
{
"input": "3647 7698",
"output": "Dasha"
},
{
"input": "2661 8975",
"output": "Dasha"
},
{
"input": "251 9731",
"output": "Dasha"
},
{
"input": "9886 8671",
"output": "Masha"
},
{
"input": "8545 7312",
"output": "Masha"
},
{
"input": "4982 2927",
"output": "Masha"
},
{
"input": "7660 7658",
"output": "Equal"
},
{
"input": "9846 9844",
"output": "Equal"
},
{
"input": "9632 9640",
"output": "Equal"
},
{
"input": "5036 5037",
"output": "Equal"
},
{
"input": "64854 77725",
"output": "Dasha"
},
{
"input": "4965 85708",
"output": "Dasha"
},
{
"input": "20393 86640",
"output": "Dasha"
},
{
"input": "99207 30728",
"output": "Masha"
},
{
"input": "77545 13842",
"output": "Masha"
},
{
"input": "30362 10712",
"output": "Masha"
},
{
"input": "51291 51292",
"output": "Equal"
},
{
"input": "55381 55382",
"output": "Equal"
},
{
"input": "91560 91550",
"output": "Equal"
},
{
"input": "99087 99090",
"output": "Equal"
},
{
"input": "983794 986389",
"output": "Dasha"
},
{
"input": "779183 786727",
"output": "Dasha"
},
{
"input": "450766 610961",
"output": "Dasha"
},
{
"input": "664690 630787",
"output": "Masha"
},
{
"input": "461363 256765",
"output": "Masha"
},
{
"input": "638067 409048",
"output": "Masha"
},
{
"input": "929061 929052",
"output": "Equal"
},
{
"input": "996219 996216",
"output": "Equal"
},
{
"input": "716249 716248",
"output": "Equal"
},
{
"input": "782250 782252",
"output": "Equal"
},
{
"input": "1 2",
"output": "Equal"
},
{
"input": "2 1",
"output": "Equal"
},
{
"input": "999999 1000000",
"output": "Equal"
},
{
"input": "999997 1000000",
"output": "Dasha"
},
{
"input": "1000000 999993",
"output": "Masha"
},
{
"input": "999983 999979",
"output": "Masha"
}
] | 156 | 0 | 3.961 | 5,249 |
946 | String Transformation | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number of moves (not necessary minimal) to get string abcdefghijklmnopqrstuvwxyz (english alphabet) as a subsequence. Subsequence of the string is the string that is obtained by deleting characters at some positions. You need to print the string that will be obtained from the given string and will be contain english alphabet as a subsequence or say that it is impossible. | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaendlpbfuylqgxtndhmhqgbsknsy",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdefghijklmnopqrstuvwxxx",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxya",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "cdaaaaaaaaabcdjklmnopqrstuvwxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "cdabcdefghijklmnopqrstuvwxyzxyzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "zazaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zazbcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abbbefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaa"
},
{
"input": "abcdefghijklmaopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvwxyx",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaz"
},
{
"input": "zaaaazaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zabcdzefghijklmnopqrstuvwxyzaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaa"
},
{
"input": "aaaaaafghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyzz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaz"
},
{
"input": "abcdefghijklmnopqrstuvwaxy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaa"
},
{
"input": "abcdefghijklmnapqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdefghijklmnopqrstuvnxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaa"
},
{
"input": "abcdefghijklmnopqrstuvwxyzzzz",
"output": "abcdefghijklmnopqrstuvwxyzzzz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aacceeggiikkmmooqqssuuwwya",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aacdefghijklmnopqrstuvwxyyy",
"output": "abcdefghijklmnopqrstuvwxyzy"
},
{
"input": "abcaefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zaaacaaaaaaaaaaaaaaaaaaaayy",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "abcdedccdcdccdcdcdcdcdcddccdcdcdc",
"output": "abcdefghijklmnopqrstuvwxyzcdcdcdc"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "abcdecdcdcddcdcdcdcdcdcdcd",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "a",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaa"
},
{
"input": "aaadefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaa"
},
{
"input": "abbbbbbbbbbbbbbbbbbbbbbbbz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aacceeggiikkmmaacceeggiikkmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy",
"output": "abcdefghijklmnopqrstuvwxyzmmooaacceeggiikkmmaacceeggiikkmmooqqssuuwwzy"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "phqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxf",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaap",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zabcdefghijklmnopqrstuvwxyz",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzabcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "rveviaomdienfygifatviahordebxazoxflfgzslhyzowhxbhqzpsgellkoimnwkvhpbijorhpggwfjexivpqbcbmqjyghkbq",
"output": "rveviaomdienfygifbtvichordefxgzoxhlijzslkyzowlxmnqzpsopqrstuvwxyzhpbijorhpggwfjexivpqbcbmqjyghkbq"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "xtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknly",
"output": "xtlsgypsfadpooefxzbcoejuvpvdeoygpofylgphnpljvrvipyjmyklwqnqrqpmxunopqrvstwuxwvwxyzbxcoksfzkvatxdknly"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxsa",
"output": "jqcfvsavebixhiocdefphgmsmhijkylwsmpynoypqrxstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqh",
"output": "wlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldcefsdrefynghiyjkxxplmornopqrstuvwxyzopkmcoqh"
},
{
"input": "abadefghijklmnopqrstuvwxyz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "zazsazcbbbbbbbbbbbbbbbbbbbbbbb",
"output": "zazsbzcdefghijklmnopqrstuvwxyz"
},
{
"input": "zazsazcbbbbbbbbbbbbbbbbbbbbbyb",
"output": "zazsbzcdefghijklmnopqrstuvwxyz"
},
{
"input": "bbcdefghijklmnopqrstuvwxyzzz",
"output": "-1"
},
{
"input": "zaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zabcdefghijklmnopqrstuvwxyz"
},
{
"input": "zzzzzaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "zzzzzabcdefghijklmnopqrstuvwxyza"
},
{
"input": "kkimnfjbbgggicykcciwtoazomcvisigagkjwhyrmojmoebnqoadpmockfjxibdtvrbedrsdoundbcpkfdqdidqdmxdltink",
"output": "kkimnfjbbgggicykcciwtoazomcvisigbgkjwhyrmojmoecnqodepmofkgjxihitvrjklrsmounopqrstuvwxyzdmxdltink"
},
{
"input": "cawgathqceccscakbazmhwbefvygjbcfyihcbgga",
"output": "-1"
},
{
"input": "acrsbyszsbfslzbqzzamcmrypictkcheddehvxdipaxaannjodzyfxgtfnwababzjraapqbqbfzhbiewlzz",
"output": "acrsbyszscfslzdqzzemfmrypigtkhijklmnvxopqrxstuvwxyzyfxgtfnwababzjraapqbqbfzhbiewlzz"
},
{
"input": "ggcebbheeblbioxdvtlrtkxeuilonazpebcbqpzz",
"output": "-1"
},
{
"input": "zzzzabcdefghijklmnopqrstuvwxy",
"output": "-1"
},
{
"input": "zabcdefghijklmnopqrstuvwxy",
"output": "-1"
},
{
"input": "babcdefghijklmnopqrstuvwxyz",
"output": "babcdefghijklmnopqrstuvwxyz"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "abcdefghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
] | 139 | 0 | 0 | 5,261 |
|
780 | Andryusha and Colored Balloons | [
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them.
The park consists of *n* squares connected with (*n*<=-<=1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored balloon at each of the squares. The baloons' colors are described by positive integers, starting from 1. In order to make the park varicolored, Andryusha wants to choose the colors in a special way. More precisely, he wants to use such colors that if *a*, *b* and *c* are distinct squares that *a* and *b* have a direct path between them, and *b* and *c* have a direct path between them, then balloon colors on these three squares are distinct.
Andryusha wants to use as little different colors as possible. Help him to choose the colors! | The first line contains single integer *n* (3<=≤<=*n*<=≤<=2·105) — the number of squares in the park.
Each of the next (*n*<=-<=1) lines contains two integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*) — the indices of two squares directly connected by a path.
It is guaranteed that any square is reachable from any other using the paths. | In the first line print single integer *k* — the minimum number of colors Andryusha has to use.
In the second line print *n* integers, the *i*-th of them should be equal to the balloon color on the *i*-th square. Each of these numbers should be within range from 1 to *k*. | [
"3\n2 3\n1 3\n",
"5\n2 3\n5 3\n4 3\n1 3\n",
"5\n2 1\n3 2\n4 3\n5 4\n"
] | [
"3\n1 3 2 ",
"5\n1 3 2 5 4 ",
"3\n1 2 3 1 2 "
] | In the first sample the park consists of three squares: 1 → 3 → 2. Thus, the balloon colors have to be distinct.
In the second example there are following triples of consequently connected squares:
- 1 → 3 → 2 - 1 → 3 → 4 - 1 → 3 → 5 - 2 → 3 → 4 - 2 → 3 → 5 - 4 → 3 → 5
In the third example there are following triples:
- 1 → 2 → 3 - 2 → 3 → 4 - 3 → 4 → 5 | [
{
"input": "3\n2 3\n1 3",
"output": "3\n1 3 2 "
},
{
"input": "5\n2 3\n5 3\n4 3\n1 3",
"output": "5\n1 3 2 5 4 "
},
{
"input": "5\n2 1\n3 2\n4 3\n5 4",
"output": "3\n1 2 3 1 2 "
},
{
"input": "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2",
"output": "5\n1 2 1 3 2 1 2 3 4 5 "
},
{
"input": "3\n2 1\n3 2",
"output": "3\n1 2 3 "
},
{
"input": "10\n2 7\n8 2\n9 8\n1 9\n4 1\n3 4\n6 3\n10 6\n5 10",
"output": "3\n1 1 2 3 2 1 2 3 2 3 "
},
{
"input": "5\n4 2\n3 1\n3 4\n3 5",
"output": "4\n1 1 2 3 4 "
},
{
"input": "7\n3 6\n3 1\n3 2\n3 5\n3 4\n3 7",
"output": "7\n1 4 2 6 5 3 7 "
},
{
"input": "10\n8 6\n10 5\n8 4\n2 7\n3 8\n10 3\n3 9\n2 1\n3 2",
"output": "5\n1 2 4 3 1 2 3 1 5 3 "
},
{
"input": "50\n45 2\n4 48\n16 4\n17 29\n29 33\n31 2\n47 41\n41 33\n22 6\n44 40\n32 24\n12 40\n28 16\n18 30\n20 41\n25 45\n35 29\n10 32\n1 48\n15 50\n6 9\n43 2\n33 2\n38 33\n8 2\n36 7\n26 48\n50 8\n34 31\n48 33\n13 45\n37 33\n7 6\n40 32\n3 6\n30 49\n49 33\n11 40\n19 40\n24 2\n14 50\n5 50\n42 16\n23 2\n9 45\n39 6\n46 48\n27 13\n21 2",
"output": "9\n1 4 4 3 4 2 3 6 5 2 5 4 3 3 2 1 2 2 6 2 9 1 8 7 2 4 2 2 1 1 2 1 5 1 3 1 7 6 6 3 3 4 3 2 1 6 1 2 8 1 "
},
{
"input": "50\n8 37\n40 8\n38 40\n10 38\n29 10\n33 29\n17 33\n25 17\n19 25\n3 19\n13 3\n24 13\n12 24\n5 12\n41 5\n11 41\n27 11\n45 27\n6 45\n35 6\n9 35\n50 9\n32 50\n21 32\n22 21\n1 22\n31 1\n28 31\n4 28\n30 4\n7 30\n48 7\n46 48\n16 46\n49 16\n39 49\n18 39\n14 18\n34 14\n23 34\n20 23\n15 20\n44 15\n42 44\n2 42\n36 2\n43 36\n26 43\n47 26",
"output": "3\n1 3 2 1 1 2 2 2 3 2 2 2 1 1 3 2 2 2 3 1 3 2 2 3 1 3 1 2 1 3 3 1 3 3 1 2 3 3 3 1 3 1 1 2 3 3 2 1 1 2 "
},
{
"input": "50\n7 5\n6 40\n49 43\n48 2\n44 11\n10 3\n46 49\n22 18\n17 33\n4 29\n48 4\n47 41\n24 19\n48 8\n1 21\n2 17\n17 34\n16 10\n17 20\n1 22\n44 32\n6 28\n7 1\n47 26\n28 44\n23 50\n21 15\n1 30\n7 27\n28 25\n17 23\n14 42\n6 46\n5 24\n44 9\n25 39\n46 47\n21 35\n7 16\n34 12\n45 14\n35 36\n28 13\n6 48\n46 37\n39 45\n40 7\n2 31\n30 38",
"output": "6\n1 2 2 3 2 1 4 5 5 1 1 2 5 3 3 5 1 2 3 5 2 3 6 1 4 2 3 2 1 5 3 4 3 4 4 1 5 2 1 6 1 1 1 3 2 3 4 4 2 2 "
}
] | 1,263 | 19,353,600 | -1 | 5,266 |
|
399 | Red and Blue Balls | [] | null | null | User ainta has a stack of *n* red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack.
- While the top ball inside the stack is red, pop the ball from the top of the stack. - Then replace the blue ball on the top with a red ball. - And finally push some blue balls to the stack until the stack has total of *n* balls inside.
If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of balls inside the stack.
The second line contains a string *s* (|*s*|<==<=*n*) describing the initial state of the stack. The *i*-th character of the string *s* denotes the color of the *i*-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue. | Print the maximum number of operations ainta can repeatedly apply.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\nRBR\n",
"4\nRBBR\n",
"5\nRBBRR\n"
] | [
"2\n",
"6\n",
"6\n"
] | The first example is depicted below.
The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball.
The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red.
From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2.
The second example is depicted below. The blue arrow denotes a single operation. | [
{
"input": "3\nRBR",
"output": "2"
},
{
"input": "4\nRBBR",
"output": "6"
},
{
"input": "5\nRBBRR",
"output": "6"
},
{
"input": "5\nRBRBR",
"output": "10"
},
{
"input": "10\nRRBRRBBRRR",
"output": "100"
},
{
"input": "10\nBRBRRRRRRR",
"output": "5"
},
{
"input": "10\nBRRRRRRRRR",
"output": "1"
},
{
"input": "20\nBRBRRRRRRRRRRRRRRRRR",
"output": "5"
},
{
"input": "30\nRRBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1073741820"
},
{
"input": "50\nBRRRBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1125899906842609"
},
{
"input": "20\nRRRBRBBBBBRRRRRRRRRR",
"output": "1000"
},
{
"input": "20\nRRBRBBBBBRRRRRRRRRRR",
"output": "500"
},
{
"input": "1\nR",
"output": "0"
},
{
"input": "1\nB",
"output": "1"
},
{
"input": "2\nRR",
"output": "0"
},
{
"input": "2\nBR",
"output": "1"
},
{
"input": "50\nRRRRRRRRRRBBBBBBRRBBRRRBRRBBBRRRRRRRRRRRRRRRRRRRRR",
"output": "479001600"
},
{
"input": "50\nRBRRRRRBRBRRBBBBBBRRRBRRRRRBBBRRBRRRRRBBBRRRRRRRRR",
"output": "1929382195842"
},
{
"input": "48\nRBRBRRRRBRBRRBRRRRRRRBBBRRBRBRRRBBRRRRRRRRRRRRRR",
"output": "13235135754"
},
{
"input": "30\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "0"
},
{
"input": "50\nRRBBBBBBBBBBBBBBBBRBRRBBBRBBRBBBRRBRBBBBBRBBRBBRBR",
"output": "402373705727996"
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1125899906842623"
},
{
"input": "19\nRRRRRBRRBRRRRBRBBBB",
"output": "500000"
},
{
"input": "32\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBR",
"output": "2147483647"
},
{
"input": "3\nBBB",
"output": "7"
},
{
"input": "3\nBBR",
"output": "3"
},
{
"input": "3\nBRB",
"output": "5"
},
{
"input": "3\nBRR",
"output": "1"
},
{
"input": "3\nRBB",
"output": "6"
},
{
"input": "3\nRBR",
"output": "2"
},
{
"input": "3\nRRB",
"output": "4"
},
{
"input": "3\nRRR",
"output": "0"
},
{
"input": "2\nRB",
"output": "2"
},
{
"input": "2\nBB",
"output": "3"
}
] | 46 | 0 | 0 | 5,267 |
|
435 | Cardiogram | [
"implementation"
] | null | null | In this problem, your task is to use ASCII graphics to paint a cardiogram.
A cardiogram is a polyline with the following corners:
That is, a cardiogram is fully defined by a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*.
Your task is to paint a cardiogram by given sequence *a**i*. | The first line contains integer *n* (2<=≤<=*n*<=≤<=1000). The next line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). It is guaranteed that the sum of all *a**i* doesn't exceed 1000. | Print *max* |*y**i*<=-<=*y**j*| lines (where *y**k* is the *y* coordinate of the *k*-th point of the polyline), in each line print characters. Each character must equal either «<=/<=» (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram.
Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty. | [
"5\n3 1 2 5 1\n",
"3\n1 5 1\n"
] | [
"/ \\ \n / \\ / \\ \n / \\ \n / \\ \n \\ / \n",
"/ \\ \n \\ \n \\ \n \\ \n \\ / \n"
] | Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below.
http://assets.codeforces.com/rounds/435/1.txt
http://assets.codeforces.com/rounds/435/2.txt | [
{
"input": "5\n3 1 2 5 1",
"output": " /\\ \n /\\/ \\ \n / \\ \n/ \\ \n \\/"
},
{
"input": "3\n1 5 1",
"output": "/\\ \n \\ \n \\ \n \\ \n \\/"
},
{
"input": "2\n1 1",
"output": "/\\"
},
{
"input": "2\n2 1",
"output": " /\\\n/ "
},
{
"input": "2\n1 2",
"output": "/\\ \n \\"
},
{
"input": "2\n2 2",
"output": " /\\ \n/ \\"
},
{
"input": "3\n1 1 1",
"output": "/\\/"
},
{
"input": "100\n14 6 10 12 11 12 6 19 12 7 10 17 8 10 10 5 9 6 9 14 15 5 9 11 8 12 14 15 9 9 9 11 13 15 11 10 4 10 8 7 13 11 17 10 14 14 15 8 10 7 12 8 7 15 13 8 7 13 5 11 12 8 9 8 7 16 11 10 10 15 9 11 2 12 12 9 9 13 7 6 9 7 8 7 4 6 15 6 8 11 7 10 11 9 17 8 8 5 9 9",
"output": " /\\ ..."
},
{
"input": "2\n478 522",
"output": " /\\ ..."
},
{
"input": "3\n328 341 331",
"output": " /\\ ..."
},
{
"input": "4\n253 250 261 236",
"output": " ..."
},
{
"input": "5\n198 213 195 189 205",
"output": " /\\ ..."
},
{
"input": "6\n163 170 175 168 172 152",
"output": " ..."
},
{
"input": "7\n154 157 138 129 136 148 138",
"output": " /\\ ..."
},
{
"input": "8\n117 140 141 105 129 127 122 118",
"output": " ..."
},
{
"input": "9\n96 114 117 124 114 107 126 95 105",
"output": " ..."
},
{
"input": "4\n1 1 1 1",
"output": "/\\/\\"
},
{
"input": "4\n1 1 2 1",
"output": " /\\\n/\\/ "
},
{
"input": "4\n1 1 2 2",
"output": " /\\ \n/\\/ \\"
},
{
"input": "4\n1 2 2 2",
"output": "/\\ /\\ \n \\/ \\"
},
{
"input": "4\n2 2 2 2",
"output": " /\\ /\\ \n/ \\/ \\"
},
{
"input": "5\n1 1 1 1 1",
"output": "/\\/\\/"
},
{
"input": "5\n1 2 1 1 1",
"output": "/\\ \n \\/\\/"
},
{
"input": "5\n2 1 1 2 1",
"output": " /\\/\\ \n/ \\/"
},
{
"input": "5\n2 1 1 1 3",
"output": " /\n / \n /\\/\\/ \n/ "
},
{
"input": "5\n2 2 1 2 2",
"output": " /\\ \n/ \\/\\ /\n \\/ "
},
{
"input": "5\n2 1 2 3 2",
"output": " /\\ \n /\\/ \\ /\n/ \\/ "
},
{
"input": "2\n500 500",
"output": " /\\ ..."
},
{
"input": "3\n1 499 500",
"output": " ..."
},
{
"input": "6\n1 200 1 200 1 200",
"output": "/\\ ..."
},
{
"input": "6\n200 1 200 1 200 1",
"output": " ..."
},
{
"input": "123\n2 5 7 7 3 7 8 7 6 6 7 10 7 8 7 4 6 6 7 6 6 6 5 8 9 6 3 3 5 5 6 7 7 8 8 6 4 1 3 8 9 9 3 4 5 6 6 7 9 9 4 7 7 6 3 9 7 7 6 3 6 5 3 7 7 1 6 5 10 4 5 6 3 7 7 7 4 7 7 8 6 10 9 5 5 6 5 4 5 7 3 6 7 8 3 5 6 5 4 5 5 9 5 4 9 6 3 4 7 5 7 2 3 10 5 8 5 5 5 9 3 6 7",
"output": " /\\ ..."
},
{
"input": "23\n33 42 55 36 37 42 36 39 35 27 38 38 31 33 26 40 20 32 45 32 31 35 36",
"output": " /\\ ..."
},
{
"input": "3\n2 1 1",
"output": " /\\/\n/ "
},
{
"input": "3\n1 1 2",
"output": " /\n/\\/ "
},
{
"input": "3\n1 2 1",
"output": "/\\ \n \\/"
},
{
"input": "3\n1 2 2",
"output": "/\\ /\n \\/ "
},
{
"input": "3\n2 2 1",
"output": " /\\ \n/ \\/"
},
{
"input": "3\n2 1 2",
"output": " /\n /\\/ \n/ "
},
{
"input": "3\n2 2 2",
"output": " /\\ /\n/ \\/ "
},
{
"input": "2\n999 1",
"output": " ..."
},
{
"input": "2\n1 999",
"output": "/\\ ..."
},
{
"input": "3\n10 1 10",
"output": " /\n / \n / \n / \n / \n / \n / \n / \n / \n /\\/ \n / \n / \n / \n / \n / \n / \n / \n / \n/ "
}
] | 171 | 4,403,200 | 3 | 5,302 |
|
681 | Economy Game | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that he have bought only some houses (for 1<=234<=567 game-coins each), cars (for 123<=456 game-coins each) and computers (for 1<=234 game-coins each).
Kolya is now interested, whether he could have spent all of his initial *n* game-coins buying only houses, cars and computers or there is a bug in the game. Formally, is there a triple of non-negative integers *a*, *b* and *c* such that *a*<=×<=1<=234<=567<=+<=*b*<=×<=123<=456<=+<=*c*<=×<=1<=234<==<=*n*?
Please help Kolya answer this question. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES"
},
{
"input": "999999987",
"output": "YES"
},
{
"input": "27406117",
"output": "NO"
},
{
"input": "27404883",
"output": "NO"
},
{
"input": "27403649",
"output": "NO"
},
{
"input": "27402415",
"output": "NO"
},
{
"input": "27401181",
"output": "NO"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999244",
"output": "YES"
},
{
"input": "999129999",
"output": "YES"
},
{
"input": "17159199",
"output": "NO"
},
{
"input": "13606913",
"output": "NO"
},
{
"input": "14841529",
"output": "NO"
},
{
"input": "915968473",
"output": "YES"
},
{
"input": "980698615",
"output": "YES"
},
{
"input": "912331505",
"output": "YES"
},
{
"input": "917261049",
"output": "YES"
},
{
"input": "999999997",
"output": "YES"
},
{
"input": "12345",
"output": "NO"
},
{
"input": "1234",
"output": "YES"
},
{
"input": "124690",
"output": "YES"
},
{
"input": "1359257",
"output": "YES"
},
{
"input": "1358023",
"output": "YES"
},
{
"input": "1234",
"output": "YES"
},
{
"input": "1234567",
"output": "YES"
},
{
"input": "124690",
"output": "YES"
},
{
"input": "1358023",
"output": "YES"
},
{
"input": "123456",
"output": "YES"
},
{
"input": "2592590",
"output": "YES"
},
{
"input": "999999998",
"output": "YES"
},
{
"input": "1356789",
"output": "NO"
},
{
"input": "12345670",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "1480800",
"output": "YES"
},
{
"input": "908000000",
"output": "YES"
},
{
"input": "3000",
"output": "NO"
},
{
"input": "1235801",
"output": "YES"
},
{
"input": "991919191",
"output": "YES"
},
{
"input": "25613715",
"output": "YES"
},
{
"input": "13580237",
"output": "YES"
},
{
"input": "14814804",
"output": "YES"
},
{
"input": "11403961",
"output": "YES"
},
{
"input": "999999989",
"output": "YES"
},
{
"input": "1237035",
"output": "YES"
},
{
"input": "81134231",
"output": "YES"
},
{
"input": "1236",
"output": "NO"
},
{
"input": "1359250",
"output": "YES"
},
{
"input": "100",
"output": "NO"
},
{
"input": "987654321",
"output": "YES"
},
{
"input": "122222",
"output": "NO"
},
{
"input": "123458",
"output": "NO"
},
{
"input": "20987639",
"output": "YES"
},
{
"input": "999973333",
"output": "YES"
},
{
"input": "253082",
"output": "YES"
},
{
"input": "1235",
"output": "NO"
},
{
"input": "803219200",
"output": "YES"
},
{
"input": "100000000",
"output": "YES"
},
{
"input": "1485181",
"output": "YES"
}
] | 77 | 0 | 0 | 5,303 |
|
222 | Decoding Genome | [
"dp",
"matrices"
] | null | null | Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is *k*.
The needs of gene research required information about the quantity of correct *n*-long chains of the Martian DNA. Your task is to write a program that will calculate this value. | The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*m*<=≤<=52, 0<=≤<=*k*<=≤<=*m*2).
Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide.
The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z").
It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than *m*. Note that order is important in nucleotide pairs.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print a single integer — the sought number modulo 1000000007 (109<=+<=7). | [
"3 3 2\nab\nba\n",
"3 3 0\n",
"2 1 1\naa\n"
] | [
"17\n",
"27\n",
"0\n"
] | In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs.
In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively. | [
{
"input": "3 3 2\nab\nba",
"output": "17"
},
{
"input": "3 3 0",
"output": "27"
},
{
"input": "2 1 1\naa",
"output": "0"
},
{
"input": "3 5 4\ncd\nce\ned\nee",
"output": "89"
},
{
"input": "100 5 4\ncd\nce\ned\nee",
"output": "537303881"
},
{
"input": "1 2 4\naa\nbb\nab\nba",
"output": "2"
},
{
"input": "2 2 4\naa\nbb\nab\nba",
"output": "0"
},
{
"input": "3 3 6\naa\nab\nac\nbb\nbc\ncc",
"output": "1"
},
{
"input": "4 4 13\naa\nbc\nad\nac\nbb\nba\nda\ndb\ndd\ncc\nca\ncb\ncd",
"output": "1"
},
{
"input": "2 3 7\naa\nac\nba\nbb\ncc\nca\ncb",
"output": "2"
},
{
"input": "3 3 7\naa\nac\nba\nbb\ncc\nca\ncb",
"output": "1"
},
{
"input": "4 3 7\naa\nac\nba\nbb\ncc\nca\ncb",
"output": "0"
},
{
"input": "1 52 2\naA\nAa",
"output": "52"
},
{
"input": "100000 52 0",
"output": "378241178"
},
{
"input": "10000 52 10\nEN\nYJ\nKH\nGa\nQA\njY\nYf\nSt\nap\nDT",
"output": "671474539"
},
{
"input": "1000000000000 2 0",
"output": "959366170"
},
{
"input": "100 3 6\naa\nab\nac\nbb\nbc\ncc",
"output": "0"
},
{
"input": "1000 10 20\naa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nab\nbc\ncd\nde\nef\nfg\ngh\nhi\nij\nja",
"output": "207125595"
},
{
"input": "5000 3 0",
"output": "22443616"
},
{
"input": "5000 4 7\naa\nab\nac\nad\nba\nca\nda",
"output": "22443616"
},
{
"input": "5000 4 6\nab\nac\nad\nba\nca\nda",
"output": "22443617"
},
{
"input": "10000 5 4\nce\nee\ncd\ned",
"output": "386438816"
},
{
"input": "50000 52 10\nAa\naA\nBy\ntS\nzA\nZu\nyy\nUU\nen\neq",
"output": "447275409"
},
{
"input": "1000000000000 3 5\naa\nab\nac\nba\nca",
"output": "959366170"
},
{
"input": "1000000000000 3 3\naa\nab\nac",
"output": "439049248"
},
{
"input": "1000000000000 3 4\nab\nac\nba\nca",
"output": "959366171"
},
{
"input": "1000000000000 4 9\naa\nab\nac\nad\nbb\nbc\nbd\ncc\ncd",
"output": "8"
},
{
"input": "1000000000000000 52 0",
"output": "588668785"
},
{
"input": "1000000000000000 52 26\naa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nkk\nll\nmm\nnn\noo\npp\nqq\nrr\nss\ntt\nuu\nvv\nww\nxx\nyy\nzz",
"output": "271910099"
},
{
"input": "298470512649 26 20\nav\nsf\nqq\nyt\ncz\nkl\nqw\nwe\ner\nrt\nty\nfg\nin\nxy\nbt\nmm\njm\ndp\nno\nuy",
"output": "399097981"
},
{
"input": "10000000000 20 15\nhs\npm\ncd\ner\nht\nmk\nce\nad\nfe\nmj\npf\nlm\nmo\nkd\nde",
"output": "768931983"
},
{
"input": "1000000000000000 26 2\nfj\nho",
"output": "688841650"
},
{
"input": "1000000000000000 10 0",
"output": "478484352"
},
{
"input": "1000000000000000 10 1\ncd",
"output": "82984398"
},
{
"input": "1000000000000000 12 3\nce\ndg\nfb",
"output": "792123851"
},
{
"input": "853332331434235 35 77\nBy\nhs\nzB\njs\nIr\nEa\nHG\nxb\nxG\nFp\nAC\nDt\nwo\nFB\nzh\nim\ntx\nyi\ngC\nkp\njz\ndc\nwE\naa\nsG\nng\ncr\npB\nCg\ncv\nxs\nDn\ndg\nyj\nCd\naC\nIi\ngH\nml\nww\nAD\nir\nti\nEr\nCj\nHt\nAe\nsn\naH\nHv\nan\nDf\nGn\nfC\nay\ngB\nlh\nup\nda\nzs\nbh\nHB\nHd\nmg\nzy\nGi\nzm\nHq\nac\nCB\niE\ncc\nfi\ngm\nHf\neD\nqA",
"output": "351800015"
}
] | 2,000 | 1,536,000 | 0 | 5,304 |
|
659 | Bicycle Race | [
"geometry",
"implementation",
"math"
] | null | null | Maria participates in a bicycle race.
The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west.
Let's introduce a system of coordinates, directing the *Ox* axis from west to east, and the *Oy* axis from south to north. As a starting position of the race the southernmost point of the track is selected (and if there are several such points, the most western among them). The participants start the race, moving to the north. At all straight sections of the track, the participants travel in one of the four directions (north, south, east or west) and change the direction of movement only in bends between the straight sections. The participants, of course, never turn back, that is, they do not change the direction of movement from north to south or from east to west (or vice versa).
Maria is still young, so she does not feel confident at some turns. Namely, Maria feels insecure if at a failed or untimely turn, she gets into the water. In other words, Maria considers the turn dangerous if she immediately gets into the water if it is ignored.
Help Maria get ready for the competition — determine the number of dangerous turns on the track. | The first line of the input contains an integer *n* (4<=≤<=*n*<=≤<=1000) — the number of straight sections of the track.
The following (*n*<=+<=1)-th line contains pairs of integers (*x**i*,<=*y**i*) (<=-<=10<=000<=≤<=*x**i*,<=*y**i*<=≤<=10<=000). The first of these points is the starting position. The *i*-th straight section of the track begins at the point (*x**i*,<=*y**i*) and ends at the point (*x**i*<=+<=1,<=*y**i*<=+<=1).
It is guaranteed that:
- the first straight section is directed to the north; - the southernmost (and if there are several, then the most western of among them) point of the track is the first point; - the last point coincides with the first one (i.e., the start position); - any pair of straight sections of the track has no shared points (except for the neighboring ones, they share exactly one point); - no pair of points (except for the first and last one) is the same; - no two adjacent straight sections are directed in the same direction or in opposite directions. | Print a single integer — the number of dangerous turns on the track. | [
"6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0\n",
"16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1\n"
] | [
"1\n",
"6\n"
] | The first sample corresponds to the picture:
The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1. | [
{
"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0",
"output": "1"
},
{
"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1",
"output": "6"
},
{
"input": "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000",
"output": "0"
},
{
"input": "4\n6 8\n6 9\n7 9\n7 8\n6 8",
"output": "0"
},
{
"input": "8\n-10000 -10000\n-10000 5000\n0 5000\n0 10000\n10000 10000\n10000 0\n0 0\n0 -10000\n-10000 -10000",
"output": "2"
},
{
"input": "20\n-4286 -10000\n-4286 -7778\n-7143 -7778\n-7143 -3334\n-10000 -3334\n-10000 1110\n-4286 1110\n-4286 -3334\n4285 -3334\n4285 -1112\n7142 -1112\n7142 3332\n4285 3332\n4285 9998\n9999 9998\n9999 -3334\n7142 -3334\n7142 -5556\n-1429 -5556\n-1429 -10000\n-4286 -10000",
"output": "8"
},
{
"input": "24\n-10000 -10000\n-10000 9998\n9998 9998\n9998 -10000\n-6364 -10000\n-6364 6362\n6362 6362\n6362 -6364\n-2728 -6364\n-2728 2726\n2726 2726\n2726 -910\n908 -910\n908 908\n-910 908\n-910 -4546\n4544 -4546\n4544 4544\n-4546 4544\n-4546 -8182\n8180 -8182\n8180 8180\n-8182 8180\n-8182 -10000\n-10000 -10000",
"output": "10"
},
{
"input": "12\n-10000 -10000\n-10000 10000\n10000 10000\n10000 6000\n-6000 6000\n-6000 2000\n10000 2000\n10000 -2000\n-6000 -2000\n-6000 -6000\n10000 -6000\n10000 -10000\n-10000 -10000",
"output": "4"
},
{
"input": "12\n-10000 -10000\n-10000 10000\n10000 10000\n10000 6000\n-9800 6000\n-9800 2000\n10000 2000\n10000 -2000\n-9800 -2000\n-9800 -6000\n10000 -6000\n10000 -10000\n-10000 -10000",
"output": "4"
},
{
"input": "4\n0 0\n0 10000\n10000 10000\n10000 0\n0 0",
"output": "0"
},
{
"input": "4\n-10000 -10000\n-10000 10000\n10000 10000\n10000 -10000\n-10000 -10000",
"output": "0"
}
] | 77 | 1,638,400 | 3 | 5,307 |
|
975 | Hag's Khashba | [
"geometry"
] | null | null | Hag is a very talented person. He has always had an artist inside him but his father forced him to study mechanical engineering.
Yesterday he spent all of his time cutting a giant piece of wood trying to make it look like a goose. Anyway, his dad found out that he was doing arts rather than studying mechanics and other boring subjects. He confronted Hag with the fact that he is a spoiled son that does not care about his future, and if he continues to do arts he will cut his 25 Lira monthly allowance.
Hag is trying to prove to his dad that the wooden piece is a project for mechanics subject. He also told his dad that the wooden piece is a strictly convex polygon with $n$ vertices.
Hag brought two pins and pinned the polygon with them in the $1$-st and $2$-nd vertices to the wall. His dad has $q$ queries to Hag of two types.
- $1$ $f$ $t$: pull a pin from the vertex $f$, wait for the wooden polygon to rotate under the gravity force (if it will rotate) and stabilize. And then put the pin in vertex $t$. - $2$ $v$: answer what are the coordinates of the vertex $v$.
Please help Hag to answer his father's queries.
You can assume that the wood that forms the polygon has uniform density and the polygon has a positive thickness, same in all points. After every query of the 1-st type Hag's dad tries to move the polygon a bit and watches it stabilize again. | The first line contains two integers $n$ and $q$ ($3\leq n \leq 10\,000$, $1 \leq q \leq 200000$) — the number of vertices in the polygon and the number of queries.
The next $n$ lines describe the wooden polygon, the $i$-th line contains two integers $x_i$ and $y_i$ ($|x_i|, |y_i|\leq 10^8$) — the coordinates of the $i$-th vertex of the polygon. It is guaranteed that polygon is strictly convex and the vertices are given in the counter-clockwise order and all vertices are distinct.
The next $q$ lines describe the queries, one per line. Each query starts with its type $1$ or $2$. Each query of the first type continues with two integers $f$ and $t$ ($1 \le f, t \le n$) — the vertex the pin is taken from, and the vertex the pin is put to and the polygon finishes rotating. It is guaranteed that the vertex $f$ contains a pin. Each query of the second type continues with a single integer $v$ ($1 \le v \le n$) — the vertex the coordinates of which Hag should tell his father.
It is guaranteed that there is at least one query of the second type. | The output should contain the answer to each query of second type — two numbers in a separate line. Your answer is considered correct, if its absolute or relative error does not exceed $10^{-4}$.
Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}$ | [
"3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3\n",
"3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1\n"
] | [
"3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624\n",
"1.0000000000 -1.0000000000\n"
] | In the first test note the initial and the final state of the wooden polygon.
Red Triangle is the initial state and the green one is the triangle after rotation around $(2,0)$.
In the second sample note that the polygon rotates $180$ degrees counter-clockwise or clockwise direction (it does not matter), because Hag's father makes sure that the polygon is stable and his son does not trick him. | [
{
"input": "3 4\n0 0\n2 0\n2 2\n1 1 2\n2 1\n2 2\n2 3",
"output": "3.4142135624 -1.4142135624\n2.0000000000 0.0000000000\n0.5857864376 -1.4142135624"
},
{
"input": "3 2\n-1 1\n0 0\n1 1\n1 1 2\n2 1",
"output": "1.0000000000 -1.0000000000"
},
{
"input": "10 10\n0 -100000000\n1 -100000000\n1566 -99999999\n2088 -99999997\n2610 -99999994\n3132 -99999990\n3654 -99999985\n4176 -99999979\n4698 -99999972\n5220 -99999964\n1 2 5\n2 1\n1 1 7\n2 5\n1 5 4\n1 4 2\n2 8\n1 7 9\n2 1\n1 2 10",
"output": "0.0000000000 -100000000.0000000000\n-7.3726558373 -100002609.9964835122\n-129.8654413032 -100003125.4302210321\n-114.4079442212 -100007299.4544525659"
},
{
"input": "4 10\n0 0\n2 0\n2 2\n0 2\n2 3\n2 1\n2 1\n1 1 1\n2 3\n1 2 4\n1 4 4\n2 4\n1 1 3\n2 3",
"output": "2.0000000000 2.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.5857864376 -1.4142135624\n4.8284271247 -2.8284271247\n6.2426406871 -4.2426406871"
},
{
"input": "3 2\n0 0\n1 0\n1566 1\n1 2 1\n2 3",
"output": "0.0006381620 -1566.0003192846"
}
] | 93 | 7,065,600 | 0 | 5,311 |
|
452 | 4-point polyline | [
"brute force",
"constructive algorithms",
"geometry",
"trees"
] | null | null | You are given a rectangular grid of lattice points from (0,<=0) to (*n*,<=*m*) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points *p*1,<=*p*2,<=*p*3,<=*p*4 consists of the line segments *p*1<=*p*2,<=*p*2<=*p*3,<=*p*3<=*p*4, and its length is the sum of the lengths of the individual line segments. | The only line of the input contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1000). It is guaranteed that grid contains at least 4 different points. | Print 4 lines with two integers per line separated by space — coordinates of points *p*1,<=*p*2,<=*p*3,<=*p*4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10<=-<=6 precision. | [
"1 1\n",
"0 10\n"
] | [
"1 1\n0 0\n1 0\n0 1\n",
"0 1\n0 10\n0 0\n0 9\n"
] | none | [
{
"input": "1 1",
"output": "0 0\n1 1\n0 1\n1 0"
},
{
"input": "0 10",
"output": "0 1\n0 10\n0 0\n0 9"
},
{
"input": "10 10",
"output": "10 9\n0 0\n10 10\n1 0"
},
{
"input": "100 100",
"output": "0 1\n100 100\n0 0\n99 100"
},
{
"input": "10 100",
"output": "9 100\n0 0\n10 100\n1 0"
},
{
"input": "20 1000",
"output": "19 1000\n0 0\n20 1000\n1 0"
},
{
"input": "1000 20",
"output": "1000 19\n0 0\n1000 20\n0 1"
},
{
"input": "100 10",
"output": "100 9\n0 0\n100 10\n0 1"
},
{
"input": "2 2",
"output": "0 0\n2 2\n0 2\n2 0"
},
{
"input": "3 3",
"output": "3 3\n0 0\n3 0\n0 3"
},
{
"input": "2 15",
"output": "2 15\n0 0\n0 15\n2 0"
},
{
"input": "15 2",
"output": "15 2\n0 0\n15 0\n0 2"
},
{
"input": "1000 1000",
"output": "0 1\n1000 1000\n0 0\n999 1000"
},
{
"input": "1000 999",
"output": "1000 998\n0 0\n1000 999\n0 1"
},
{
"input": "999 1000",
"output": "998 1000\n0 0\n999 1000\n1 0"
},
{
"input": "987 567",
"output": "0 1\n987 567\n0 0\n987 566"
},
{
"input": "555 555",
"output": "0 1\n555 555\n0 0\n554 555"
},
{
"input": "555 1",
"output": "555 1\n0 0\n555 0\n0 1"
},
{
"input": "1 4",
"output": "0 0\n1 4\n1 0\n0 4"
},
{
"input": "955 956",
"output": "1 0\n955 956\n0 0\n954 956"
},
{
"input": "4 0",
"output": "1 0\n4 0\n0 0\n3 0"
},
{
"input": "0 3",
"output": "0 1\n0 3\n0 0\n0 2"
},
{
"input": "3 0",
"output": "1 0\n3 0\n0 0\n2 0"
},
{
"input": "2 3",
"output": "0 0\n2 3\n2 0\n0 3"
},
{
"input": "3 2",
"output": "0 0\n3 2\n0 2\n3 0"
},
{
"input": "3 4",
"output": "0 0\n3 4\n3 0\n0 4"
},
{
"input": "4 3",
"output": "0 0\n4 3\n0 3\n4 0"
},
{
"input": "3 5",
"output": "0 0\n3 5\n3 0\n0 5"
},
{
"input": "5 3",
"output": "0 0\n5 3\n0 3\n5 0"
},
{
"input": "3 6",
"output": "0 0\n3 6\n3 0\n0 6"
},
{
"input": "6 3",
"output": "0 0\n6 3\n0 3\n6 0"
},
{
"input": "4 4",
"output": "4 3\n0 0\n4 4\n1 0"
},
{
"input": "4 5",
"output": "1 0\n4 5\n0 0\n3 5"
},
{
"input": "5 4",
"output": "0 1\n5 4\n0 0\n5 3"
},
{
"input": "4 6",
"output": "1 0\n4 6\n0 0\n3 6"
},
{
"input": "6 4",
"output": "0 1\n6 4\n0 0\n6 3"
},
{
"input": "4 7",
"output": "1 0\n4 7\n0 0\n3 7"
},
{
"input": "7 4",
"output": "0 1\n7 4\n0 0\n7 3"
},
{
"input": "3 100",
"output": "0 0\n3 100\n3 0\n0 100"
},
{
"input": "100 3",
"output": "0 0\n100 3\n0 3\n100 0"
},
{
"input": "4 100",
"output": "1 0\n4 100\n0 0\n3 100"
},
{
"input": "100 4",
"output": "0 1\n100 4\n0 0\n100 3"
},
{
"input": "30 1000",
"output": "1 0\n30 1000\n0 0\n29 1000"
},
{
"input": "1000 30",
"output": "0 1\n1000 30\n0 0\n1000 29"
},
{
"input": "1000 40",
"output": "0 1\n1000 40\n0 0\n1000 39"
},
{
"input": "40 1000",
"output": "1 0\n40 1000\n0 0\n39 1000"
},
{
"input": "2 10",
"output": "2 10\n0 0\n0 10\n2 0"
},
{
"input": "9 3",
"output": "0 0\n9 3\n0 3\n9 0"
},
{
"input": "2 1000",
"output": "2 1000\n0 0\n0 1000\n2 0"
},
{
"input": "100 2",
"output": "0 0\n100 2\n0 2\n100 0"
},
{
"input": "3 1",
"output": "3 1\n0 0\n3 0\n0 1"
},
{
"input": "2 100",
"output": "0 0\n2 100\n2 0\n0 100"
},
{
"input": "3 7",
"output": "0 0\n3 7\n3 0\n0 7"
},
{
"input": "2 50",
"output": "0 0\n2 50\n2 0\n0 50"
},
{
"input": "1 5",
"output": "1 5\n0 0\n0 5\n1 0"
},
{
"input": "3 1000",
"output": "0 0\n3 1000\n3 0\n0 1000"
},
{
"input": "5 2",
"output": "5 2\n0 0\n5 0\n0 2"
},
{
"input": "10 0",
"output": "1 0\n10 0\n0 0\n9 0"
},
{
"input": "20 0",
"output": "1 0\n20 0\n0 0\n19 0"
},
{
"input": "1000 3",
"output": "0 0\n1000 3\n0 3\n1000 0"
},
{
"input": "1000 500",
"output": "0 1\n1000 500\n0 0\n1000 499"
},
{
"input": "2 5",
"output": "2 5\n0 0\n0 5\n2 0"
},
{
"input": "2 1",
"output": "0 0\n2 1\n0 1\n2 0"
},
{
"input": "1000 2",
"output": "1000 2\n0 0\n1000 0\n0 2"
},
{
"input": "6 5",
"output": "0 1\n6 5\n0 0\n6 4"
},
{
"input": "2 4",
"output": "0 0\n2 4\n2 0\n0 4"
},
{
"input": "20 10",
"output": "20 9\n0 0\n20 10\n0 1"
},
{
"input": "10 1",
"output": "10 1\n0 0\n10 0\n0 1"
}
] | 61 | 0 | 0 | 5,368 |
|
911 | Stack Sorting | [
"constructive algorithms",
"data structures",
"greedy",
"implementation"
] | null | null | Let's suppose you have an array *a*, a stack *s* (initially empty) and an array *b* (also initially empty).
You may perform the following operations until both *a* and *s* are empty:
- Take the first element of *a*, push it into *s* and remove it from *a* (if *a* is not empty); - Take the top element from *s*, append it to the end of array *b* and remove it from *s* (if *s* is not empty).
You can perform these operations in arbitrary order.
If there exists a way to perform the operations such that array *b* is sorted in non-descending order in the end, then array *a* is called stack-sortable.
For example, [3,<=1,<=2] is stack-sortable, because *b* will be sorted if we perform the following operations:
1. Remove 3 from *a* and push it into *s*; 1. Remove 1 from *a* and push it into *s*; 1. Remove 1 from *s* and append it to the end of *b*; 1. Remove 2 from *a* and push it into *s*; 1. Remove 2 from *s* and append it to the end of *b*; 1. Remove 3 from *s* and append it to the end of *b*.
After all these operations *b*<==<=[1,<=2,<=3], so [3,<=1,<=2] is stack-sortable. [2,<=3,<=1] is not stack-sortable.
You are given *k* first elements of some permutation *p* of size *n* (recall that a permutation of size *n* is an array of size *n* where each integer from 1 to *n* occurs exactly once). You have to restore the remaining *n*<=-<=*k* elements of this permutation so it is stack-sortable. If there are multiple answers, choose the answer such that *p* is lexicographically maximal (an array *q* is lexicographically greater than an array *p* iff there exists some integer *k* such that for every *i*<=<<=*k* *q**i*<==<=*p**i*, and *q**k*<=><=*p**k*). You may not swap or change any of first *k* elements of the permutation.
Print the lexicographically maximal permutation *p* you can obtain.
If there exists no answer then output -1. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200000, 1<=≤<=*k*<=<<=*n*) — the size of a desired permutation, and the number of elements you are given, respectively.
The second line contains *k* integers *p*1, *p*2, ..., *p**k* (1<=≤<=*p**i*<=≤<=*n*) — the first *k* elements of *p*. These integers are pairwise distinct. | If it is possible to restore a stack-sortable permutation *p* of size *n* such that the first *k* elements of *p* are equal to elements given in the input, print lexicographically maximal such permutation.
Otherwise print -1. | [
"5 3\n3 2 1\n",
"5 3\n2 3 1\n",
"5 1\n3\n",
"5 2\n3 4\n"
] | [
"3 2 1 5 4 ",
"-1\n",
"3 2 1 5 4 ",
"-1\n"
] | none | [
{
"input": "5 3\n3 2 1",
"output": "3 2 1 5 4 "
},
{
"input": "5 3\n2 3 1",
"output": "-1"
},
{
"input": "5 1\n3",
"output": "3 2 1 5 4 "
},
{
"input": "5 2\n3 4",
"output": "-1"
},
{
"input": "100000 1\n98419",
"output": "98419 98418 98417 98416 98415 98414 98413 98412 98411 98410 98409 98408 98407 98406 98405 98404 98403 98402 98401 98400 98399 98398 98397 98396 98395 98394 98393 98392 98391 98390 98389 98388 98387 98386 98385 98384 98383 98382 98381 98380 98379 98378 98377 98376 98375 98374 98373 98372 98371 98370 98369 98368 98367 98366 98365 98364 98363 98362 98361 98360 98359 98358 98357 98356 98355 98354 98353 98352 98351 98350 98349 98348 98347 98346 98345 98344 98343 98342 98341 98340 98339 98338 98337 98336 98335 9..."
},
{
"input": "20 19\n2 18 19 11 9 20 15 1 8 14 4 6 5 12 17 16 7 13 3",
"output": "-1"
},
{
"input": "10 1\n6",
"output": "6 5 4 3 2 1 10 9 8 7 "
},
{
"input": "100000 2\n64398 63673",
"output": "64398 63673 63672 63671 63670 63669 63668 63667 63666 63665 63664 63663 63662 63661 63660 63659 63658 63657 63656 63655 63654 63653 63652 63651 63650 63649 63648 63647 63646 63645 63644 63643 63642 63641 63640 63639 63638 63637 63636 63635 63634 63633 63632 63631 63630 63629 63628 63627 63626 63625 63624 63623 63622 63621 63620 63619 63618 63617 63616 63615 63614 63613 63612 63611 63610 63609 63608 63607 63606 63605 63604 63603 63602 63601 63600 63599 63598 63597 63596 63595 63594 63593 63592 63591 63590 6..."
},
{
"input": "20 18\n8 14 18 10 1 3 7 15 2 12 17 19 5 4 11 13 20 16",
"output": "-1"
},
{
"input": "10 2\n3 7",
"output": "-1"
},
{
"input": "100000 3\n43791 91790 34124",
"output": "-1"
},
{
"input": "20 17\n9 11 19 4 8 16 13 3 1 6 18 2 20 10 17 7 5",
"output": "-1"
},
{
"input": "10 3\n2 10 3",
"output": "-1"
},
{
"input": "100000 4\n8269 53984 47865 42245",
"output": "-1"
},
{
"input": "20 16\n8 1 5 11 15 14 7 20 16 9 12 13 18 4 6 10",
"output": "-1"
},
{
"input": "10 4\n2 4 1 10",
"output": "-1"
},
{
"input": "100000 5\n82211 48488 99853 11566 42120",
"output": "-1"
},
{
"input": "20 15\n6 7 14 13 8 4 15 2 11 9 12 16 5 1 20",
"output": "-1"
},
{
"input": "10 5\n2 10 5 8 4",
"output": "-1"
},
{
"input": "100000 6\n98217 55264 24242 71840 2627 67839",
"output": "-1"
},
{
"input": "20 14\n10 15 4 3 1 5 11 12 13 14 6 2 19 20",
"output": "-1"
},
{
"input": "10 6\n4 5 2 1 6 3",
"output": "-1"
},
{
"input": "100000 7\n44943 51099 61988 40497 85738 74092 2771",
"output": "-1"
},
{
"input": "20 13\n6 16 5 19 8 1 4 18 2 20 10 11 13",
"output": "-1"
},
{
"input": "10 7\n10 4 3 8 2 5 6",
"output": "-1"
},
{
"input": "100000 8\n88153 88461 80211 24770 13872 57414 32941 63030",
"output": "-1"
},
{
"input": "20 12\n20 11 14 7 16 13 9 1 4 18 6 12",
"output": "-1"
},
{
"input": "10 8\n7 9 3 6 2 4 1 8",
"output": "-1"
},
{
"input": "200000 1\n177300",
"output": "177300 177299 177298 177297 177296 177295 177294 177293 177292 177291 177290 177289 177288 177287 177286 177285 177284 177283 177282 177281 177280 177279 177278 177277 177276 177275 177274 177273 177272 177271 177270 177269 177268 177267 177266 177265 177264 177263 177262 177261 177260 177259 177258 177257 177256 177255 177254 177253 177252 177251 177250 177249 177248 177247 177246 177245 177244 177243 177242 177241 177240 177239 177238 177237 177236 177235 177234 177233 177232 177231 177230 177229 177228 ..."
},
{
"input": "40 39\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12",
"output": "-1"
},
{
"input": "20 1\n20",
"output": "20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 "
},
{
"input": "200000 2\n102991 8046",
"output": "102991 8046 8045 8044 8043 8042 8041 8040 8039 8038 8037 8036 8035 8034 8033 8032 8031 8030 8029 8028 8027 8026 8025 8024 8023 8022 8021 8020 8019 8018 8017 8016 8015 8014 8013 8012 8011 8010 8009 8008 8007 8006 8005 8004 8003 8002 8001 8000 7999 7998 7997 7996 7995 7994 7993 7992 7991 7990 7989 7988 7987 7986 7985 7984 7983 7982 7981 7980 7979 7978 7977 7976 7975 7974 7973 7972 7971 7970 7969 7968 7967 7966 7965 7964 7963 7962 7961 7960 7959 7958 7957 7956 7955 7954 7953 7952 7951 7950 7949 7948 7947 7946..."
},
{
"input": "40 38\n32 35 36 4 22 6 15 21 40 13 33 17 5 24 28 9 1 23 25 14 26 3 8 11 37 30 18 16 19 20 27 12 39 2 10 38 29 31",
"output": "-1"
},
{
"input": "20 2\n1 13",
"output": "1 13 12 11 10 9 8 7 6 5 4 3 2 20 19 18 17 16 15 14 "
},
{
"input": "200000 3\n60323 163214 48453",
"output": "-1"
},
{
"input": "40 37\n26 16 40 10 9 30 8 33 39 19 4 11 2 3 38 21 22 12 1 27 20 37 24 17 23 14 13 29 7 28 34 31 25 35 6 32 5",
"output": "-1"
},
{
"input": "20 3\n16 6 14",
"output": "-1"
},
{
"input": "200000 4\n194118 175603 110154 129526",
"output": "-1"
},
{
"input": "40 36\n27 33 34 40 16 39 1 10 9 12 8 37 17 7 24 30 2 31 13 23 20 18 29 21 4 28 25 35 6 22 36 15 3 11 5 26",
"output": "-1"
},
{
"input": "20 4\n2 10 4 9",
"output": "-1"
},
{
"input": "200000 5\n53765 19781 63409 69811 120021",
"output": "-1"
},
{
"input": "40 35\n2 1 5 3 11 32 13 16 37 26 6 10 8 35 25 24 7 38 21 17 40 14 9 34 33 20 29 12 22 28 36 31 30 19 27",
"output": "-1"
},
{
"input": "20 5\n11 19 6 2 12",
"output": "-1"
},
{
"input": "200000 6\n33936 11771 42964 153325 684 8678",
"output": "-1"
},
{
"input": "40 34\n35 31 38 25 29 9 32 23 24 16 3 26 39 2 17 28 14 1 30 34 5 36 33 7 22 13 21 12 27 19 40 10 18 15",
"output": "-1"
},
{
"input": "20 6\n3 6 9 13 20 14",
"output": "-1"
},
{
"input": "200000 7\n175932 99083 128533 75304 164663 7578 174396",
"output": "-1"
},
{
"input": "40 33\n11 15 22 26 21 6 8 5 32 39 28 29 30 13 2 40 33 27 17 31 7 36 9 19 3 38 37 12 10 16 1 23 35",
"output": "-1"
},
{
"input": "20 7\n7 5 6 13 16 3 17",
"output": "-1"
},
{
"input": "200000 8\n197281 11492 67218 100058 179300 182264 17781 192818",
"output": "-1"
},
{
"input": "40 32\n22 7 35 31 14 28 9 20 10 3 38 6 15 36 33 16 37 2 11 13 26 23 30 12 40 5 21 1 34 19 27 24",
"output": "-1"
},
{
"input": "20 8\n1 16 14 11 7 9 2 12",
"output": "-1"
},
{
"input": "30 3\n17 5 3",
"output": "17 5 3 2 1 4 16 15 14 13 12 11 10 9 8 7 6 30 29 28 27 26 25 24 23 22 21 20 19 18 "
},
{
"input": "30 3\n29 25 21",
"output": "29 25 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 24 23 22 28 27 26 30 "
},
{
"input": "10 6\n2 1 4 3 6 5",
"output": "2 1 4 3 6 5 10 9 8 7 "
},
{
"input": "4 3\n2 1 3",
"output": "2 1 3 4 "
},
{
"input": "6 4\n5 4 3 1",
"output": "5 4 3 1 2 6 "
},
{
"input": "4 3\n1 2 3",
"output": "1 2 3 4 "
},
{
"input": "6 4\n1 3 2 6",
"output": "1 3 2 6 5 4 "
},
{
"input": "5 4\n3 2 1 5",
"output": "3 2 1 5 4 "
},
{
"input": "10 4\n6 4 1 3",
"output": "6 4 1 3 2 5 10 9 8 7 "
},
{
"input": "4 3\n3 4 2",
"output": "-1"
},
{
"input": "4 3\n3 1 4",
"output": "-1"
},
{
"input": "3 2\n2 3",
"output": "-1"
},
{
"input": "4 3\n1 4 2",
"output": "1 4 2 3 "
},
{
"input": "4 3\n3 1 2",
"output": "3 1 2 4 "
},
{
"input": "2 1\n1",
"output": "1 2 "
},
{
"input": "3 2\n3 2",
"output": "3 2 1 "
},
{
"input": "4 3\n4 1 2",
"output": "4 1 2 3 "
},
{
"input": "3 2\n3 1",
"output": "3 1 2 "
},
{
"input": "4 3\n2 1 4",
"output": "2 1 4 3 "
},
{
"input": "8 5\n3 1 4 2 7",
"output": "-1"
},
{
"input": "6 4\n2 5 1 4",
"output": "-1"
},
{
"input": "10 5\n10 1 8 5 6",
"output": "-1"
},
{
"input": "10 3\n6 4 3",
"output": "6 4 3 2 1 5 10 9 8 7 "
},
{
"input": "10 3\n2 1 6",
"output": "2 1 6 5 4 3 10 9 8 7 "
},
{
"input": "10 3\n8 1 7",
"output": "8 1 7 6 5 4 3 2 10 9 "
},
{
"input": "10 2\n5 4",
"output": "5 4 3 2 1 10 9 8 7 6 "
},
{
"input": "10 3\n1 2 10",
"output": "1 2 10 9 8 7 6 5 4 3 "
},
{
"input": "10 4\n4 1 6 3",
"output": "-1"
},
{
"input": "10 3\n8 1 5",
"output": "8 1 5 4 3 2 7 6 10 9 "
},
{
"input": "10 4\n1 4 9 8",
"output": "-1"
},
{
"input": "10 3\n3 1 6",
"output": "-1"
},
{
"input": "10 6\n1 2 5 4 3 6",
"output": "1 2 5 4 3 6 10 9 8 7 "
},
{
"input": "10 9\n9 8 7 5 4 3 2 1 6",
"output": "9 8 7 5 4 3 2 1 6 10 "
},
{
"input": "10 4\n4 7 5 10",
"output": "-1"
},
{
"input": "10 5\n8 6 2 1 5",
"output": "8 6 2 1 5 4 3 7 10 9 "
},
{
"input": "10 7\n7 5 2 1 4 3 6",
"output": "7 5 2 1 4 3 6 10 9 8 "
},
{
"input": "10 4\n1 2 10 6",
"output": "1 2 10 6 5 4 3 9 8 7 "
},
{
"input": "10 6\n1 10 9 5 4 3",
"output": "1 10 9 5 4 3 2 8 7 6 "
},
{
"input": "10 8\n6 10 4 7 9 8 5 3",
"output": "-1"
},
{
"input": "10 4\n6 1 10 3",
"output": "-1"
},
{
"input": "10 9\n9 6 1 4 2 3 5 10 7",
"output": "-1"
},
{
"input": "10 9\n10 1 9 3 2 4 5 8 6",
"output": "10 1 9 3 2 4 5 8 6 7 "
},
{
"input": "10 4\n10 8 1 7",
"output": "10 8 1 7 6 5 4 3 2 9 "
},
{
"input": "10 4\n2 1 3 6",
"output": "2 1 3 6 5 4 10 9 8 7 "
},
{
"input": "10 3\n2 1 4",
"output": "2 1 4 3 10 9 8 7 6 5 "
},
{
"input": "10 3\n4 1 5",
"output": "-1"
},
{
"input": "10 5\n9 8 1 2 10",
"output": "-1"
},
{
"input": "10 3\n9 8 3",
"output": "9 8 3 2 1 7 6 5 4 10 "
},
{
"input": "10 4\n8 2 1 5",
"output": "8 2 1 5 4 3 7 6 10 9 "
},
{
"input": "10 6\n6 5 3 1 2 4",
"output": "6 5 3 1 2 4 10 9 8 7 "
},
{
"input": "10 2\n1 2",
"output": "1 2 10 9 8 7 6 5 4 3 "
},
{
"input": "10 6\n9 6 5 2 1 4",
"output": "9 6 5 2 1 4 3 8 7 10 "
},
{
"input": "10 4\n2 1 7 3",
"output": "2 1 7 3 6 5 4 10 9 8 "
},
{
"input": "10 2\n6 5",
"output": "6 5 4 3 2 1 10 9 8 7 "
},
{
"input": "10 3\n2 1 5",
"output": "2 1 5 4 3 10 9 8 7 6 "
},
{
"input": "10 4\n3 1 2 4",
"output": "3 1 2 4 10 9 8 7 6 5 "
},
{
"input": "10 3\n8 5 4",
"output": "8 5 4 3 2 1 7 6 10 9 "
},
{
"input": "10 4\n2 1 8 4",
"output": "2 1 8 4 3 7 6 5 10 9 "
},
{
"input": "10 3\n8 3 2",
"output": "8 3 2 1 7 6 5 4 10 9 "
},
{
"input": "10 3\n5 4 2",
"output": "5 4 2 1 3 10 9 8 7 6 "
},
{
"input": "10 9\n10 8 7 5 6 2 1 9 4",
"output": "-1"
},
{
"input": "10 4\n2 1 6 4",
"output": "2 1 6 4 3 5 10 9 8 7 "
},
{
"input": "10 4\n2 1 3 9",
"output": "2 1 3 9 8 7 6 5 4 10 "
},
{
"input": "10 3\n1 4 3",
"output": "1 4 3 2 10 9 8 7 6 5 "
},
{
"input": "10 7\n3 2 1 9 8 6 5",
"output": "3 2 1 9 8 6 5 4 7 10 "
},
{
"input": "10 4\n10 7 1 5",
"output": "10 7 1 5 4 3 2 6 9 8 "
},
{
"input": "10 4\n8 7 1 2",
"output": "8 7 1 2 6 5 4 3 10 9 "
},
{
"input": "10 4\n1 5 4 2",
"output": "1 5 4 2 3 10 9 8 7 6 "
},
{
"input": "10 5\n2 1 9 3 7",
"output": "2 1 9 3 7 6 5 4 8 10 "
},
{
"input": "10 4\n2 1 5 3",
"output": "2 1 5 3 4 10 9 8 7 6 "
},
{
"input": "10 5\n9 6 1 8 2",
"output": "-1"
},
{
"input": "20 13\n3 2 1 7 4 5 6 11 10 9 8 13 12",
"output": "3 2 1 7 4 5 6 11 10 9 8 13 12 20 19 18 17 16 15 14 "
},
{
"input": "20 14\n3 2 1 7 4 5 6 14 11 10 9 8 13 12",
"output": "3 2 1 7 4 5 6 14 11 10 9 8 13 12 20 19 18 17 16 15 "
},
{
"input": "10 5\n9 4 2 1 5",
"output": "-1"
},
{
"input": "10 5\n1 5 2 10 3",
"output": "-1"
},
{
"input": "10 8\n6 5 3 1 2 4 9 8",
"output": "6 5 3 1 2 4 9 8 7 10 "
},
{
"input": "10 4\n10 9 3 7",
"output": "-1"
},
{
"input": "10 7\n10 8 5 1 2 7 3",
"output": "-1"
},
{
"input": "10 3\n3 1 5",
"output": "-1"
},
{
"input": "10 5\n1 9 8 4 3",
"output": "1 9 8 4 3 2 7 6 5 10 "
},
{
"input": "10 3\n1 8 4",
"output": "1 8 4 3 2 7 6 5 10 9 "
},
{
"input": "10 4\n6 2 1 4",
"output": "6 2 1 4 3 5 10 9 8 7 "
},
{
"input": "10 3\n1 6 4",
"output": "1 6 4 3 2 5 10 9 8 7 "
},
{
"input": "10 3\n10 9 3",
"output": "10 9 3 2 1 8 7 6 5 4 "
},
{
"input": "10 9\n8 10 4 1 3 2 9 7 5",
"output": "-1"
},
{
"input": "10 3\n7 10 6",
"output": "-1"
},
{
"input": "10 3\n9 10 8",
"output": "-1"
},
{
"input": "10 6\n10 8 1 6 2 7",
"output": "-1"
},
{
"input": "10 6\n6 5 1 2 9 3",
"output": "-1"
},
{
"input": "10 3\n10 1 8",
"output": "10 1 8 7 6 5 4 3 2 9 "
},
{
"input": "10 9\n1 9 7 10 5 8 4 6 3",
"output": "-1"
},
{
"input": "10 5\n1 9 3 2 5",
"output": "1 9 3 2 5 4 8 7 6 10 "
},
{
"input": "10 4\n10 1 9 7",
"output": "10 1 9 7 6 5 4 3 2 8 "
},
{
"input": "10 8\n1 10 3 2 9 4 8 5",
"output": "1 10 3 2 9 4 8 5 7 6 "
},
{
"input": "10 1\n1",
"output": "1 10 9 8 7 6 5 4 3 2 "
},
{
"input": "10 7\n9 7 1 6 5 4 2",
"output": "9 7 1 6 5 4 2 3 8 10 "
},
{
"input": "10 9\n10 2 1 7 8 3 5 6 9",
"output": "-1"
},
{
"input": "10 4\n2 1 3 10",
"output": "2 1 3 10 9 8 7 6 5 4 "
},
{
"input": "10 9\n5 1 4 6 3 9 8 10 7",
"output": "-1"
},
{
"input": "10 6\n8 2 1 7 6 5",
"output": "8 2 1 7 6 5 4 3 10 9 "
},
{
"input": "10 5\n2 9 8 6 1",
"output": "-1"
},
{
"input": "10 4\n9 2 1 6",
"output": "9 2 1 6 5 4 3 8 7 10 "
},
{
"input": "10 3\n2 1 7",
"output": "2 1 7 6 5 4 3 10 9 8 "
},
{
"input": "10 7\n4 1 2 10 9 6 3",
"output": "-1"
},
{
"input": "10 6\n10 2 1 3 9 4",
"output": "10 2 1 3 9 4 8 7 6 5 "
},
{
"input": "10 4\n9 2 1 4",
"output": "9 2 1 4 3 8 7 6 5 10 "
},
{
"input": "10 3\n5 1 4",
"output": "5 1 4 3 2 10 9 8 7 6 "
},
{
"input": "10 4\n4 1 2 10",
"output": "-1"
},
{
"input": "8 6\n5 4 3 2 1 8",
"output": "5 4 3 2 1 8 7 6 "
},
{
"input": "10 4\n1 6 5 4",
"output": "1 6 5 4 3 2 10 9 8 7 "
},
{
"input": "10 2\n10 2",
"output": "10 2 1 9 8 7 6 5 4 3 "
},
{
"input": "10 5\n1 6 2 10 5",
"output": "-1"
},
{
"input": "10 9\n6 1 2 10 9 5 3 4 8",
"output": "-1"
},
{
"input": "10 5\n4 1 7 2 3",
"output": "-1"
},
{
"input": "10 4\n2 1 3 4",
"output": "2 1 3 4 10 9 8 7 6 5 "
},
{
"input": "11 2\n3 2",
"output": "3 2 1 11 10 9 8 7 6 5 4 "
},
{
"input": "6 5\n3 2 1 4 5",
"output": "3 2 1 4 5 6 "
},
{
"input": "5 4\n2 1 3 5",
"output": "2 1 3 5 4 "
},
{
"input": "10 6\n3 2 1 5 4 6",
"output": "3 2 1 5 4 6 10 9 8 7 "
},
{
"input": "11 5\n1 8 7 6 5",
"output": "1 8 7 6 5 4 3 2 11 10 9 "
},
{
"input": "10 3\n2 1 3",
"output": "2 1 3 10 9 8 7 6 5 4 "
},
{
"input": "10 4\n2 1 7 6",
"output": "2 1 7 6 5 4 3 10 9 8 "
},
{
"input": "10 4\n5 4 1 8",
"output": "-1"
},
{
"input": "10 4\n9 1 5 4",
"output": "9 1 5 4 3 2 8 7 6 10 "
},
{
"input": "10 3\n6 1 4",
"output": "6 1 4 3 2 5 10 9 8 7 "
},
{
"input": "10 6\n1 9 3 2 4 6",
"output": "1 9 3 2 4 6 5 8 7 10 "
},
{
"input": "10 3\n10 1 9",
"output": "10 1 9 8 7 6 5 4 3 2 "
},
{
"input": "10 3\n1 9 7",
"output": "1 9 7 6 5 4 3 2 8 10 "
},
{
"input": "10 2\n2 10",
"output": "-1"
},
{
"input": "10 5\n9 2 1 4 3",
"output": "9 2 1 4 3 8 7 6 5 10 "
},
{
"input": "10 6\n1 2 3 6 5 4",
"output": "1 2 3 6 5 4 10 9 8 7 "
},
{
"input": "10 5\n7 6 5 1 4",
"output": "7 6 5 1 4 3 2 10 9 8 "
},
{
"input": "10 9\n8 1 3 4 10 5 9 7 2",
"output": "-1"
}
] | 0 | 0 | -1 | 5,377 |
|
417 | Square Table | [
"constructive algorithms",
"math",
"probabilities"
] | null | null | 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. | [
"1 1\n",
"1 2\n"
] | [
"1",
"3 4"
] | none | [
{
"input": "1 1",
"output": "1 "
},
{
"input": "1 2",
"output": "3 4 "
},
{
"input": "4 1",
"output": "1 \n1 \n1 \n1 "
},
{
"input": "1 4",
"output": "1 1 1 1 "
},
{
"input": "2 1",
"output": "3 \n4 "
},
{
"input": "2 4",
"output": "3 3 3 3 \n4 4 4 4 "
},
{
"input": "48 2",
"output": "3 4 \n3 4 \n3 4 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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..."
}
] | 61 | 0 | -1 | 5,398 |
|
407 | Curious Array | [
"brute force",
"combinatorics",
"implementation",
"math"
] | null | null | You've got an array consisting of *n* integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*]. Moreover, there are *m* queries, each query can be described by three integers *l**i*,<=*r**i*,<=*k**i*. Query *l**i*,<=*r**i*,<=*k**i* means that we should add to each element *a*[*j*], where *l**i*<=≤<=*j*<=≤<=*r**i*.
Record means the binomial coefficient, or the number of combinations from *y* elements into groups of *x* elements.
You need to fulfil consecutively all queries and then print the final array. | The first line contains integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The second line contains *n* integers *a*[1],<=*a*[2],<=...,<=*a*[*n*] (0<=≤<=*a**i*<=≤<=109) — the initial array.
Next *m* lines contain queries in the format *l**i*,<=*r**i*,<=*k**i* — to all elements of the segment *l**i*... *r**i* add number (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*; 0<=≤<=*k*<=≤<=100). | Print *n* integers: the *i*-th number is the value of element *a*[*i*] after all the queries. As the values can be rather large, print them modulo 1000000007 (109<=+<=7). | [
"5 1\n0 0 0 0 0\n1 5 0\n",
"10 2\n1 2 3 4 5 0 0 0 0 0\n1 6 1\n6 10 2\n"
] | [
"1 1 1 1 1\n",
"2 4 6 8 10 7 3 6 10 15\n"
] | none | [
{
"input": "5 1\n0 0 0 0 0\n1 5 0",
"output": "1 1 1 1 1"
},
{
"input": "10 2\n1 2 3 4 5 0 0 0 0 0\n1 6 1\n6 10 2",
"output": "2 4 6 8 10 7 3 6 10 15"
},
{
"input": "5 3\n0 0 0 0 0\n1 5 0\n1 5 1\n1 5 2",
"output": "3 6 10 15 21"
},
{
"input": "10 2\n0 0 0 0 0 0 0 0 0 0\n7 9 4\n2 4 1",
"output": "0 1 2 3 0 0 1 5 15 0"
},
{
"input": "5 5\n1 2 8 6 3\n5 5 4\n1 5 5\n1 1 4\n5 5 0\n2 3 0",
"output": "3 9 30 62 131"
},
{
"input": "10 2\n0 0 0 0 0 0 0 0 0 0\n8 10 3\n5 9 6",
"output": "0 0 0 0 1 7 28 85 214 10"
},
{
"input": "10 50\n15 209 149 994 266 845 236 114 228 968\n3 6 9\n8 10 14\n5 7 17\n5 5 0\n10 10 9\n8 10 13\n6 10 19\n6 9 14\n10 10 7\n6 9 3\n4 7 23\n3 3 10\n3 5 2\n4 7 13\n6 7 23\n6 10 10\n7 7 9\n4 7 17\n9 9 13\n9 9 0\n4 4 12\n3 6 2\n9 10 20\n10 10 16\n10 10 25\n6 10 14\n2 2 21\n3 4 3\n10 10 14\n4 10 15\n3 7 0\n9 10 16\n9 10 13\n1 2 8\n6 10 10\n10 10 2\n7 10 25\n3 8 0\n5 10 0\n10 10 0\n4 10 11\n5 6 21\n6 6 23\n8 9 7\n8 10 24\n8 8 0\n9 10 14\n6 9 23\n9 9 2\n5 10 24",
"output": "16 219 156 1022 424 1942 6341 9205 47088 204181"
},
{
"input": "32 16\n75454244 591508245 780919327 242504555 10328304 976613741 643845730 775054920 304114699 157548484 187864536 479076425 730938598 269393345 867303813 827252520 445388306 572924267 371919467 266567274 722374029 991613490 895119771 605883929 58242943 469913370 914902088 264594507 541825276 891949494 767100156 465664861\n21 23 64\n20 32 37\n30 31 33\n5 16 62\n23 27 69\n31 31 98\n16 26 65\n10 12 16\n25 26 75\n12 23 28\n31 31 8\n18 21 83\n12 20 37\n3 17 74\n7 16 45\n11 31 97",
"output": "75454244 591508245 780919328 242504630 10331155 976686954 645274172 797636161 605336700 644440008 938999679 253648426 215172119 77111091 235540349 736135108 511694665 823709810 235878127 379861943 231742811 721935729 833146404 107601756 54917798 329009798 27304007 557864981 417846432 692087830 701419388 729399053"
}
] | 77 | 1,331,200 | 0 | 5,401 |
|
607 | Zuma | [
"dp"
] | null | null | Genos recently installed the game Zuma on his phone. In Zuma there exists a line of *n* gemstones, the *i*-th of which has color *c**i*. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is able to choose exactly one continuous substring of colored gemstones that is a palindrome and remove it from the line. After the substring is removed, the remaining gemstones shift to form a solid line again. What is the minimum number of seconds needed to destroy the entire line?
Let us remind, that the string (or substring) is called palindrome, if it reads same backwards or forward. In our case this means the color of the first gemstone is equal to the color of the last one, the color of the second gemstone is equal to the color of the next to last and so on. | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=500) — the number of gemstones.
The second line contains *n* space-separated integers, the *i*-th of which is *c**i* (1<=≤<=*c**i*<=≤<=*n*) — the color of the *i*-th gemstone in a line. | Print a single integer — the minimum number of seconds needed to destroy the entire line. | [
"3\n1 2 1\n",
"3\n1 2 3\n",
"7\n1 4 4 2 3 2 1\n"
] | [
"1\n",
"3\n",
"2\n"
] | In the first sample, Genos can destroy the entire line in one second.
In the second sample, Genos can only destroy one gemstone at a time, so destroying three gemstones takes three seconds.
In the third sample, to achieve the optimal time of two seconds, destroy palindrome 4 4 first and then destroy palindrome 1 2 3 2 1. | [
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "7\n1 4 4 2 3 2 1",
"output": "2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "8\n1 2 1 3 4 1 2 1",
"output": "2"
},
{
"input": "50\n5 7 5 10 7 9 1 9 10 2 8 3 5 7 3 10 2 3 7 6 2 7 1 2 2 2 4 7 3 5 8 3 4 4 1 6 7 10 5 4 8 1 9 5 5 3 4 4 8 3",
"output": "21"
},
{
"input": "50\n13 17 20 5 14 19 4 17 9 13 10 19 16 13 17 2 18 3 1 9 19 4 19 10 17 12 16 20 10 11 15 10 3 19 8 6 2 8 9 15 13 7 8 8 5 8 15 18 9 4",
"output": "28"
},
{
"input": "50\n22 19 14 22 20 11 16 28 23 15 3 23 6 16 30 15 15 10 24 28 19 19 22 30 28 1 27 12 12 14 17 30 17 26 21 26 27 1 11 23 9 30 18 19 17 29 11 20 29 24",
"output": "25"
},
{
"input": "50\n30 17 31 15 10 3 39 36 5 29 16 11 31 2 38 1 32 40 7 15 39 34 24 11 4 23 9 35 39 32 4 5 14 37 10 34 11 33 30 14 4 34 23 10 34 34 26 34 26 16",
"output": "36"
},
{
"input": "50\n19 25 46 17 1 41 50 19 7 1 43 8 19 38 42 32 38 22 8 5 5 31 29 35 43 12 23 48 40 29 30 9 46 3 39 24 36 36 32 22 21 29 43 33 36 49 48 22 47 37",
"output": "36"
},
{
"input": "6\n1 2 1 1 3 1",
"output": "2"
}
] | 2,000 | 10,444,800 | 0 | 5,410 |
|
825 | Multi-judge Solving | [
"greedy",
"implementation"
] | null | null | 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. | [
"3 3\n2 1 9\n",
"4 20\n10 3 6 3\n"
] | [
"1\n",
"0\n"
] | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second example he can solve every problem right from the start. | [
{
"input": "3 3\n2 1 9",
"output": "1"
},
{
"input": "4 20\n10 3 6 3",
"output": "0"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1\n3",
"output": "1"
},
{
"input": "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",
"output": "0"
},
{
"input": "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",
"output": "1"
},
{
"input": "2 1\n1 1000000000",
"output": "29"
},
{
"input": "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",
"output": "27"
},
{
"input": "1 1\n1000000000",
"output": "29"
},
{
"input": "7 6\n4 20 16 14 3 17 4",
"output": "1"
},
{
"input": "2 1\n3 6",
"output": "1"
},
{
"input": "1 1\n20",
"output": "4"
},
{
"input": "5 2\n86 81 53 25 18",
"output": "4"
},
{
"input": "4 1\n88 55 14 39",
"output": "4"
},
{
"input": "3 1\n2 3 6",
"output": "0"
},
{
"input": "3 2\n4 9 18",
"output": "1"
},
{
"input": "5 3\n6 6 6 13 27",
"output": "2"
},
{
"input": "5 1\n23 8 83 26 18",
"output": "4"
},
{
"input": "3 1\n4 5 6",
"output": "1"
},
{
"input": "3 1\n1 3 6",
"output": "1"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "3 2\n4 5 6",
"output": "0"
},
{
"input": "5 1\n100 200 400 1000 2000",
"output": "7"
},
{
"input": "2 1\n1 4",
"output": "1"
},
{
"input": "4 1\n2 4 8 32",
"output": "1"
},
{
"input": "2 10\n21 42",
"output": "1"
},
{
"input": "3 3\n1 7 13",
"output": "1"
},
{
"input": "3 1\n1 4 6",
"output": "1"
},
{
"input": "2 2\n2 8",
"output": "1"
},
{
"input": "1 1\n4",
"output": "1"
},
{
"input": "2 2\n8 16",
"output": "1"
},
{
"input": "3 1\n4 8 16",
"output": "1"
},
{
"input": "3 1\n3 6 9",
"output": "1"
},
{
"input": "2 1\n4 8",
"output": "1"
},
{
"input": "2 2\n7 14",
"output": "1"
},
{
"input": "1 4\n9",
"output": "1"
},
{
"input": "5 3\n1024 4096 16384 65536 536870913",
"output": "24"
},
{
"input": "2 5\n10 11",
"output": "0"
},
{
"input": "2 2\n3 6",
"output": "0"
},
{
"input": "2 2\n8 11",
"output": "1"
},
{
"input": "3 19905705\n263637263 417905394 108361057",
"output": "3"
},
{
"input": "4 25\n100 11 1 13",
"output": "1"
},
{
"input": "10 295206008\n67980321 440051990 883040288 135744260 96431758 242465794 576630162 972797687 356406646 547451696",
"output": "0"
},
{
"input": "4 2\n45 44 35 38",
"output": "4"
},
{
"input": "1 2\n9",
"output": "2"
},
{
"input": "3 6\n13 26 52",
"output": "1"
},
{
"input": "9 30111088\n824713578 11195876 458715185 731769293 680826358 189542586 550198537 860586039 101083021",
"output": "2"
},
{
"input": "3 72014068\n430005292 807436976 828082746",
"output": "2"
},
{
"input": "3 165219745\n737649884 652879952 506420386",
"output": "1"
},
{
"input": "2 60669400\n95037700 337255240",
"output": "1"
},
{
"input": "4 28\n34 1 86 90",
"output": "1"
},
{
"input": "2 1\n5 10",
"output": "2"
},
{
"input": "2 1\n4 1000000000",
"output": "28"
},
{
"input": "2 1\n2 3",
"output": "0"
},
{
"input": "2 1\n3 5",
"output": "1"
},
{
"input": "3 3\n1 5 20",
"output": "1"
},
{
"input": "9 1\n1 2 4 9 15 32 64 128 1024",
"output": "4"
}
] | 62 | 5,632,000 | 0 | 5,415 |
|
106 | Treasure Island | [
"brute force",
"implementation"
] | D. Treasure Island | 2 | 256 | Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.
The treasure map can be represented as a rectangle *n*<=×<=*m* in size. Each cell stands for an islands' square (the square's side length equals to a mile). Some cells stand for the sea and they are impenetrable. All other cells are penetrable (i.e. available) and some of them contain local sights. For example, the large tree on the hills or the cave in the rocks.
Besides, the map also has a set of *k* instructions. Each instruction is in the following form:
"Walk *n* miles in the *y* direction"
The possible directions are: north, south, east, and west. If you follow these instructions carefully (you should fulfill all of them, one by one) then you should reach exactly the place where treasures are buried.
Unfortunately the captain doesn't know the place where to start fulfilling the instructions — as that very piece of the map was lost. But the captain very well remembers that the place contained some local sight. Besides, the captain knows that the whole way goes through the island's penetrable squares.
The captain wants to know which sights are worth checking. He asks you to help him with that. | The first line contains two integers *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=1000).
Then follow *n* lines containing *m* integers each — the island map's description. "#" stands for the sea. It is guaranteed that all cells along the rectangle's perimeter are the sea. "." stands for a penetrable square without any sights and the sights are marked with uppercase Latin letters from "A" to "Z". Not all alphabet letters can be used. However, it is guaranteed that at least one of them is present on the map. All local sights are marked by different letters.
The next line contains number *k* (1<=≤<=*k*<=≤<=105), after which *k* lines follow. Each line describes an instruction. Each instruction possesses the form "*dir* *len*", where *dir* stands for the direction and *len* stands for the length of the way to walk. *dir* can take values "N", "S", "W" and "E" for North, South, West and East correspondingly. At that, north is to the top, South is to the bottom, west is to the left and east is to the right. *len* is an integer from 1 to 1000. | Print all local sights that satisfy to the instructions as a string without any separators in the alphabetical order. If no sight fits, print "no solution" without the quotes. | [
"6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2\n",
"3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n"
] | [
"AD",
"no solution"
] | none | [
{
"input": "6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n4\nN 2\nS 1\nE 1\nW 2",
"output": "AD"
},
{
"input": "3 4\n####\n#.A#\n####\n2\nW 1\nN 2",
"output": "no solution"
},
{
"input": "10 10\n##########\n#K#..##..#\n##...ZB..#\n##.......#\n#D..#....#\n##...Y..##\n#...N...J#\n#.G...#.##\n#.S.I....#\n##########\n4\nE 2\nW 4\nS 3\nN 4",
"output": "YZ"
},
{
"input": "17 19\n###################\n#K..##..##.#.Z.#.##\n#..#....#.......#Y#\n###.####..##...#.##\n###.##.S.I..#.J...#\n#...###.#.#...#.#.#\n###.....##.##.#.B.#\n###...#.....#.#...#\n#.#.#.##.#.##.#.#.#\n#...#...#...###.###\n##.###.#.#.##...#.#\n##..#...#G...##N#.#\n###..####.#.##.#..#\n#..#.#.....###.#.##\n#.#.#.#.#..##...#.#\n#...D.#..#..##..###\n###################\n10\nN 1\nN 1\nE 1\nS 3\nN 2\nW 5\nN 4\nS 2\nW 3\nN 3",
"output": "no solution"
},
{
"input": "10 19\n###################\n#######QR..H#######\n#M##O...G....U#####\n#.##AK#Z.......##I#\n#L.#######Y.J.V##.#\n##..W######..#.#..#\n##.D.....N#..#..P##\n####.E.#...B..X####\n#T##F#####S...###C#\n###################\n14\nN 1\nE 3\nS 1\nE 4\nN 1\nS 5\nW 3\nN 1\nW 4\nS 1\nE 1\nN 1\nW 2\nN 1",
"output": "AK"
},
{
"input": "6 6\n######\n#UPWT#\n#KJSL#\n#VCMA#\n#QOGB#\n######\n5\nN 1\nW 1\nS 1\nE 1\nN 1",
"output": "ABCGJLMOS"
},
{
"input": "3 3\n###\n#A#\n###\n1\nN 1",
"output": "no solution"
},
{
"input": "7 8\n########\n#..#O.##\n##U#YTI#\n##.#####\n##R.E.P#\n###W#Q##\n########\n2\nN 1\nW 1",
"output": "QTUW"
},
{
"input": "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nE 3",
"output": "C"
},
{
"input": "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nW 3",
"output": "F"
},
{
"input": "4 9\n#########\n#AB#CDEF#\n#.......#\n#########\n1\nS 1",
"output": "ABCDEF"
},
{
"input": "9 4\n####\n#AB#\n#C.#\n##.#\n#D.#\n#E.#\n#F.#\n#G.#\n####\n1\nN 3",
"output": "G"
},
{
"input": "9 4\n####\n#AB#\n#C.#\n##.#\n#D.#\n#E.#\n#F.#\n#G.#\n####\n1\nS 3",
"output": "BD"
},
{
"input": "10 11\n###########\n#.F.#.P.###\n#..#.#....#\n#Y#.U....##\n##....#...#\n##.OV.NK#.#\n#H####.#EA#\n#R.#....###\n##..#MS.D##\n###########\n3\nW 2\nE 1\nN 1",
"output": "DNV"
},
{
"input": "17 16\n################\n######..#..##.##\n#A#U..##..###.##\n#.#.##.######.##\n#TZ#K.#G.#.###.#\n#..L##.#.#.D...#\n##J##..W###.#..#\n####.#.N.###.###\n#..###..##.#..##\n#.O.#.#.#S..#.##\n####.#.####.##.#\n#.B#####X..#####\n#..####.##.#..##\n#.#...M##.#.#..#\n##E####RV####..#\n##....#.##...#Q#\n################\n5\nE 1\nW 1\nE 2\nW 1\nW 1",
"output": "DSUX"
},
{
"input": "20 20\n####################\n#.#.#.####.#.###.###\n##.###...#..##.###.#\n##.##.##..####..####\n#.....######...#####\n##.##.#..###.#.#####\n#####..##.##.X.....#\n#####.....#T....##.#\n##.##.#....###...#.#\n##.#W....###.##.#.##\n####.#FA....##..#.##\n##...##.#.#...######\n###M........#.##.###\n#...##...##.#..###.#\n#.H....#..V....###.#\n#######Y......###..#\n##.#####.###..###..#\n##.#####.###.#######\n#.###.###..U....####\n####################\n5\nE 1\nE 3\nW 3\nN 3\nE 1",
"output": "AFHMTUVWXY"
},
{
"input": "20 20\n####################\n############.####.##\n#######..####..#####\n######............##\n######.....#...###.#\n#####E..........##.#\n#.##.#.........#####\n##NR....KO.....#####\n##B........#...#####\n#Y.W...H.......#####\n#####Z.....#...#####\n######...#.#...#####\n#A.......#.#...#####\n######.....#...#####\n####.#...#.#.#####.#\n######.#.#.#.#######\n######.###.#########\n######.###.#########\n#..###.#############\n####################\n10\nE 5\nS 1\nS 5\nN 2\nN 4\nN 5\nS 1\nE 3\nW 1\nW 3",
"output": "ABHKNORWYZ"
}
] | 2,000 | 18,432,000 | 0 | 5,416 |
44 | Toys | [
"brute force",
"combinatorics"
] | I. Toys | 5 | 256 | Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her *n* toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Having seen it, Masha got very upset and started crying. Sasha still can't calm Masha down and mom is going to come home soon and punish Sasha for having made Masha crying. That's why he decides to restore the piles' arrangement. However, he doesn't remember at all the way the toys used to lie. Of course, Masha remembers it, but she can't talk yet and can only help Sasha by shouting happily when he arranges the toys in the way they used to lie. That means that Sasha will have to arrange the toys in every possible way until Masha recognizes the needed arrangement. The relative position of the piles and toys in every pile is irrelevant, that's why the two ways of arranging the toys are considered different if can be found two such toys that when arranged in the first way lie in one and the same pile and do not if arranged in the second way. Sasha is looking for the fastest way of trying all the ways because mom will come soon. With every action Sasha can take a toy from any pile and move it to any other pile (as a result a new pile may appear or the old one may disappear). Sasha wants to find the sequence of actions as a result of which all the pile arrangement variants will be tried exactly one time each. Help Sasha. As we remember, initially all the toys are located in one pile. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=10) — the number of toys. | In the first line print the number of different variants of arrangement of toys into piles. Then print all the ways of arranging toys into piles in the order in which Sasha should try them (i.e. every next way must result from the previous one through the operation described in the statement). Every way should be printed in the following format. In every pile the toys should be arranged in ascending order of the numbers. Then the piles should be sorted in ascending order of the numbers of the first toys there. Output every way on a single line. Cf. the example to specify the output data format. If the solution is not unique, output any of them. | [
"3\n"
] | [
"5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}"
] | none | [
{
"input": "3",
"output": "5\n{1,2,3}\n{1,2},{3}\n{1},{2,3}\n{1},{2},{3}\n{1,3},{2}"
},
{
"input": "1",
"output": "1\n{1}"
},
{
"input": "2",
"output": "2\n{1,2}\n{1},{2}"
},
{
"input": "4",
"output": "15\n{1,2,3,4}\n{1,2,3},{4}\n{1,2},{3,4}\n{1,2},{3},{4}\n{1,2,4},{3}\n{1,4},{2,3}\n{1},{2,3},{4}\n{1},{2,3,4}\n{1},{2,4},{3}\n{1},{2},{3,4}\n{1},{2},{3},{4}\n{1,4},{2},{3}\n{1,3,4},{2}\n{1,3},{2},{4}\n{1,3},{2,4}"
},
{
"input": "5",
"output": "52\n{1,2,3,4,5}\n{1,2,3,4},{5}\n{1,2,3},{4,5}\n{1,2,3},{4},{5}\n{1,2,3,5},{4}\n{1,2,5},{3,4}\n{1,2},{3,4},{5}\n{1,2},{3,4,5}\n{1,2},{3,5},{4}\n{1,2},{3},{4,5}\n{1,2},{3},{4},{5}\n{1,2,5},{3},{4}\n{1,2,4,5},{3}\n{1,2,4},{3},{5}\n{1,2,4},{3,5}\n{1,4},{2,3,5}\n{1,4},{2,3},{5}\n{1,4,5},{2,3}\n{1,5},{2,3},{4}\n{1},{2,3},{4},{5}\n{1},{2,3},{4,5}\n{1},{2,3,5},{4}\n{1},{2,3,4,5}\n{1},{2,3,4},{5}\n{1,5},{2,3,4}\n{1,5},{2,4},{3}\n{1},{2,4},{3},{5}\n{1},{2,4},{3,5}\n{1},{2,4,5},{3}\n{1},{2,5},{3,4}\n{1},{2},{3,4,5}\n..."
},
{
"input": "6",
"output": "203\n{1,2,3,4,5,6}\n{1,2,3,4,5},{6}\n{1,2,3,4},{5,6}\n{1,2,3,4},{5},{6}\n{1,2,3,4,6},{5}\n{1,2,3,6},{4,5}\n{1,2,3},{4,5},{6}\n{1,2,3},{4,5,6}\n{1,2,3},{4,6},{5}\n{1,2,3},{4},{5,6}\n{1,2,3},{4},{5},{6}\n{1,2,3,6},{4},{5}\n{1,2,3,5,6},{4}\n{1,2,3,5},{4},{6}\n{1,2,3,5},{4,6}\n{1,2,5},{3,4,6}\n{1,2,5},{3,4},{6}\n{1,2,5,6},{3,4}\n{1,2,6},{3,4},{5}\n{1,2},{3,4},{5},{6}\n{1,2},{3,4},{5,6}\n{1,2},{3,4,6},{5}\n{1,2},{3,4,5,6}\n{1,2},{3,4,5},{6}\n{1,2,6},{3,4,5}\n{1,2,6},{3,5},{4}\n{1,2},{3,5},{4},{6}\n{1,2},{3,5},{..."
},
{
"input": "7",
"output": "877\n{1,2,3,4,5,6,7}\n{1,2,3,4,5,6},{7}\n{1,2,3,4,5},{6,7}\n{1,2,3,4,5},{6},{7}\n{1,2,3,4,5,7},{6}\n{1,2,3,4,7},{5,6}\n{1,2,3,4},{5,6},{7}\n{1,2,3,4},{5,6,7}\n{1,2,3,4},{5,7},{6}\n{1,2,3,4},{5},{6,7}\n{1,2,3,4},{5},{6},{7}\n{1,2,3,4,7},{5},{6}\n{1,2,3,4,6,7},{5}\n{1,2,3,4,6},{5},{7}\n{1,2,3,4,6},{5,7}\n{1,2,3,6},{4,5,7}\n{1,2,3,6},{4,5},{7}\n{1,2,3,6,7},{4,5}\n{1,2,3,7},{4,5},{6}\n{1,2,3},{4,5},{6},{7}\n{1,2,3},{4,5},{6,7}\n{1,2,3},{4,5,7},{6}\n{1,2,3},{4,5,6,7}\n{1,2,3},{4,5,6},{7}\n{1,2,3,7},{4,5,6}\n{1,..."
},
{
"input": "8",
"output": "4140\n{1,2,3,4,5,6,7,8}\n{1,2,3,4,5,6,7},{8}\n{1,2,3,4,5,6},{7,8}\n{1,2,3,4,5,6},{7},{8}\n{1,2,3,4,5,6,8},{7}\n{1,2,3,4,5,8},{6,7}\n{1,2,3,4,5},{6,7},{8}\n{1,2,3,4,5},{6,7,8}\n{1,2,3,4,5},{6,8},{7}\n{1,2,3,4,5},{6},{7,8}\n{1,2,3,4,5},{6},{7},{8}\n{1,2,3,4,5,8},{6},{7}\n{1,2,3,4,5,7,8},{6}\n{1,2,3,4,5,7},{6},{8}\n{1,2,3,4,5,7},{6,8}\n{1,2,3,4,7},{5,6,8}\n{1,2,3,4,7},{5,6},{8}\n{1,2,3,4,7,8},{5,6}\n{1,2,3,4,8},{5,6},{7}\n{1,2,3,4},{5,6},{7},{8}\n{1,2,3,4},{5,6},{7,8}\n{1,2,3,4},{5,6,8},{7}\n{1,2,3,4},{5,6,7,..."
},
{
"input": "9",
"output": "21147\n{1,2,3,4,5,6,7,8,9}\n{1,2,3,4,5,6,7,8},{9}\n{1,2,3,4,5,6,7},{8,9}\n{1,2,3,4,5,6,7},{8},{9}\n{1,2,3,4,5,6,7,9},{8}\n{1,2,3,4,5,6,9},{7,8}\n{1,2,3,4,5,6},{7,8},{9}\n{1,2,3,4,5,6},{7,8,9}\n{1,2,3,4,5,6},{7,9},{8}\n{1,2,3,4,5,6},{7},{8,9}\n{1,2,3,4,5,6},{7},{8},{9}\n{1,2,3,4,5,6,9},{7},{8}\n{1,2,3,4,5,6,8,9},{7}\n{1,2,3,4,5,6,8},{7},{9}\n{1,2,3,4,5,6,8},{7,9}\n{1,2,3,4,5,8},{6,7,9}\n{1,2,3,4,5,8},{6,7},{9}\n{1,2,3,4,5,8,9},{6,7}\n{1,2,3,4,5,9},{6,7},{8}\n{1,2,3,4,5},{6,7},{8},{9}\n{1,2,3,4,5},{6,7},{8,9..."
},
{
"input": "10",
"output": "115975\n{1,2,3,4,5,6,7,8,9,10}\n{1,2,3,4,5,6,7,8,9},{10}\n{1,2,3,4,5,6,7,8},{9,10}\n{1,2,3,4,5,6,7,8},{9},{10}\n{1,2,3,4,5,6,7,8,10},{9}\n{1,2,3,4,5,6,7,10},{8,9}\n{1,2,3,4,5,6,7},{8,9},{10}\n{1,2,3,4,5,6,7},{8,9,10}\n{1,2,3,4,5,6,7},{8,10},{9}\n{1,2,3,4,5,6,7},{8},{9,10}\n{1,2,3,4,5,6,7},{8},{9},{10}\n{1,2,3,4,5,6,7,10},{8},{9}\n{1,2,3,4,5,6,7,9,10},{8}\n{1,2,3,4,5,6,7,9},{8},{10}\n{1,2,3,4,5,6,7,9},{8,10}\n{1,2,3,4,5,6,9},{7,8,10}\n{1,2,3,4,5,6,9},{7,8},{10}\n{1,2,3,4,5,6,9,10},{7,8}\n{1,2,3,4,5,6,10},{7..."
}
] | 62 | 0 | 0 | 5,426 |
739 | Gosha is hunting | [
"brute force",
"data structures",
"dp",
"flows",
"math",
"probabilities",
"sortings"
] | null | null | 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. | [
"3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500\n",
"4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400\n",
"3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443\n"
] | [
"2.75\n",
"2.16\n",
"1.011"
] | none | [
{
"input": "3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500",
"output": "2.75"
},
{
"input": "4 1 3\n0.100 0.500 0.500 0.600\n0.100 0.500 0.900 0.400",
"output": "2.1600000000000001421"
},
{
"input": "3 2 0\n0.412 0.198 0.599\n0.612 0.987 0.443",
"output": "1.0109999999999998987"
},
{
"input": "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",
"output": "3.4660000000000001918"
},
{
"input": "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",
"output": "4.4030560000000003029"
},
{
"input": "2 0 0\n0.860 0.363\n0.730 0.668",
"output": "0"
},
{
"input": "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",
"output": "8.2298779999999993606"
},
{
"input": "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",
"output": "5.726613999999999649"
},
{
"input": "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",
"output": "21.622652999999999679"
},
{
"input": "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",
"output": "23.385518999999998613"
},
{
"input": "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",
"output": "4.6398159999999997183"
},
{
"input": "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",
"output": "22.63200000000000145"
},
{
"input": "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",
"output": "8.1265070000000001471"
},
{
"input": "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",
"output": "10.145936999999999983"
},
{
"input": "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",
"output": "20.728999999999999204"
},
{
"input": "4 4 3\n0.372 0.969 0.901 0.479\n0.856 0.858 0.630 0.701",
"output": "3.6861589999999999634"
},
{
"input": "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",
"output": "23.92238100000000145"
},
{
"input": "3 2 2\n0.025 0.950 0.035\n0.745 0.123 0.426",
"output": "2.1410900000000001597"
},
{
"input": "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",
"output": "23.350999999999999091"
},
{
"input": "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",
"output": "17.541436999999998392"
}
] | 3,634 | 11,161,600 | 3 | 5,432 |
|
150 | Win or Freeze | [
"games",
"math",
"number theory"
] | null | null | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer *q*. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.
The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move. | The first line contains the only integer *q* (1<=≤<=*q*<=≤<=1013).
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer — his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them. | [
"6\n",
"30\n",
"1\n"
] | [
"2\n",
"1\n6\n",
"1\n0\n"
] | Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory. | [
{
"input": "6",
"output": "2"
},
{
"input": "30",
"output": "1\n6"
},
{
"input": "1",
"output": "1\n0"
},
{
"input": "2",
"output": "1\n0"
},
{
"input": "3",
"output": "1\n0"
},
{
"input": "5",
"output": "1\n0"
},
{
"input": "445538663413",
"output": "1\n0"
},
{
"input": "5138168457911",
"output": "2"
},
{
"input": "472670214391",
"output": "1\n23020027"
},
{
"input": "1468526771489",
"output": "1\n613783"
},
{
"input": "1307514188557",
"output": "1\n39283"
},
{
"input": "8110708459517",
"output": "2"
},
{
"input": "7938986881993",
"output": "1\n378028993"
},
{
"input": "34280152201",
"output": "2"
},
{
"input": "8587340257",
"output": "1\n9409"
},
{
"input": "1245373417369",
"output": "1\n908209"
},
{
"input": "48855707",
"output": "1\n18769"
},
{
"input": "614125",
"output": "1\n25"
},
{
"input": "1716443237161",
"output": "1\n5329"
},
{
"input": "49380563",
"output": "1\n289"
},
{
"input": "2975",
"output": "1\n25"
},
{
"input": "5839252225",
"output": "1\n25"
},
{
"input": "266418",
"output": "1\n9"
},
{
"input": "319757451841",
"output": "1\n289"
},
{
"input": "3047527844089",
"output": "2"
},
{
"input": "1408514752349",
"output": "1\n72361"
},
{
"input": "9999925100701",
"output": "1\n0"
},
{
"input": "9999926826034",
"output": "2"
},
{
"input": "6599669076000",
"output": "1\n4"
},
{
"input": "324",
"output": "1\n4"
},
{
"input": "99",
"output": "1\n9"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "1\n4"
},
{
"input": "1000000000000",
"output": "1\n4"
},
{
"input": "9",
"output": "2"
},
{
"input": "50",
"output": "1\n25"
},
{
"input": "16",
"output": "1\n4"
},
{
"input": "25",
"output": "2"
},
{
"input": "44",
"output": "1\n4"
},
{
"input": "388",
"output": "1\n4"
},
{
"input": "2000000014",
"output": "2"
},
{
"input": "128",
"output": "1\n4"
},
{
"input": "27",
"output": "1\n9"
},
{
"input": "274875809788",
"output": "1\n4"
},
{
"input": "64",
"output": "1\n4"
},
{
"input": "802241960524",
"output": "1\n4"
},
{
"input": "401120980262",
"output": "2"
},
{
"input": "236",
"output": "1\n4"
},
{
"input": "7420738134810",
"output": "1\n6"
},
{
"input": "12",
"output": "1\n4"
},
{
"input": "57461344602",
"output": "1\n6"
},
{
"input": "81",
"output": "1\n9"
},
{
"input": "30971726",
"output": "2"
}
] | 62 | 0 | 0 | 5,455 |
|
697 | Barnicle | [
"brute force",
"implementation",
"math",
"strings"
] | null | null | Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.
Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number *x* is the notation of form *AeB*, where *A* is a real number and *B* is an integer and *x*<==<=*A*<=×<=10*B* is true. In our case *A* is between 0 and 9 and *B* is non-negative.
Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding. | The first and only line of input contains a single string of form *a*.*deb* where *a*, *d* and *b* are integers and *e* is usual character 'e' (0<=≤<=*a*<=≤<=9,<=0<=≤<=*d*<=<<=10100,<=0<=≤<=*b*<=≤<=100) — the scientific notation of the desired distance value.
*a* and *b* contain no leading zeros and *d* contains no trailing zeros (but may be equal to 0). Also, *b* can not be non-zero if *a* is zero. | Print the only real number *x* (the desired distance value) in the only line in its decimal notation.
Thus if *x* is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.
Otherwise print *x* in a form of *p*.*q* such that *p* is an integer that have no leading zeroes (but may be equal to zero), and *q* is an integer that have no trailing zeroes (and may not be equal to zero). | [
"8.549e2\n",
"8.549e3\n",
"0.33e0\n"
] | [
"854.9\n",
"8549\n",
"0.33\n"
] | none | [
{
"input": "8.549e2",
"output": "854.9"
},
{
"input": "8.549e3",
"output": "8549"
},
{
"input": "0.33e0",
"output": "0.33"
},
{
"input": "1.31e1",
"output": "13.1"
},
{
"input": "1.038e0",
"output": "1.038"
},
{
"input": "8.25983e5",
"output": "825983"
},
{
"input": "8.77056e6",
"output": "8770560"
},
{
"input": "4.28522890224373996236468418851564462623381500262405e30",
"output": "4285228902243739962364684188515.64462623381500262405"
},
{
"input": "4.09336275522154223604344399571355118601483591618747e85",
"output": "40933627552215422360434439957135511860148359161874700000000000000000000000000000000000"
},
{
"input": "2.0629094807595491132306264747042243928486303384791951220362096240931158821630792563855724946791054152e85",
"output": "20629094807595491132306264747042243928486303384791951220362096240931158821630792563855.724946791054152"
},
{
"input": "0.7e0",
"output": "0.7"
},
{
"input": "0.75e0",
"output": "0.75"
},
{
"input": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451e0",
"output": "0.3299209894804593859495773277850971828150469972132991597085582244596065712639531451"
},
{
"input": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197e0",
"output": "0.1438410315232821898580886049593487999249997483354329425897344341660326482795266134253882860655873197"
},
{
"input": "1.7282220592677586155528202123627915992640276211396528871e0",
"output": "1.7282220592677586155528202123627915992640276211396528871"
},
{
"input": "1.91641639840522198229453882518758458881136053577016034847369545687354908120008812644841021662133251e89",
"output": "191641639840522198229453882518758458881136053577016034847369545687354908120008812644841021.662133251"
},
{
"input": "7.0e100",
"output": "70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1.7390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051e100",
"output": "17390193766535948887334396973270576641602486903095355363287177932797263236084900516267835886881779051"
},
{
"input": "4.6329496401734172195e50",
"output": "463294964017341721950000000000000000000000000000000"
},
{
"input": "2.806303180541991592302230754797823269634e39",
"output": "2806303180541991592302230754797823269634"
},
{
"input": "5.8743505652112692964508303637002e64",
"output": "58743505652112692964508303637002000000000000000000000000000000000"
},
{
"input": "6.8778661934058405217475274375560252344373481358834598914724956711e31",
"output": "68778661934058405217475274375560.252344373481358834598914724956711"
},
{
"input": "9.4e100",
"output": "94000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "3.2371070627618799335840070613481911588919091676203766004638236894609230433739617153911544972468224113e50",
"output": "323710706276187993358400706134819115889190916762037.66004638236894609230433739617153911544972468224113"
},
{
"input": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929e0",
"output": "4.8133196117786711780806656271869913331127534865038175322117213586960112955982462632332925275690064929"
},
{
"input": "7.7060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625e1",
"output": "77.060200967648284035308242369118752594772564843152902469146249303976625961451358536989314351204406625"
},
{
"input": "8.1089882894234341219420177467603732503076124872188628349726911362800974096687340341040683238197289136e31",
"output": "81089882894234341219420177467603.732503076124872188628349726911362800974096687340341040683238197289136"
},
{
"input": "9.6576660076120385279859051742522204516365367878315639937449558670629833997839913220859648564428655877e99",
"output": "9657666007612038527985905174252220451636536787831563993744955867062983399783991322085964856442865587.7"
},
{
"input": "0.0e0",
"output": "0"
},
{
"input": "1.0e0",
"output": "1"
},
{
"input": "8.0e0",
"output": "8"
},
{
"input": "3.0e0",
"output": "3"
},
{
"input": "4.0e0",
"output": "4"
},
{
"input": "2.0e0",
"output": "2"
},
{
"input": "9.0e0",
"output": "9"
},
{
"input": "0.888888e0",
"output": "0.888888"
},
{
"input": "9.99999999999999999999999999999999999999999999999999999999999999999999999999999999e100",
"output": "99999999999999999999999999999999999999999999999999999999999999999999999999999999900000000000000000000"
},
{
"input": "5.0e0",
"output": "5"
},
{
"input": "1.0e10",
"output": "10000000000"
},
{
"input": "1.0e5",
"output": "100000"
},
{
"input": "6.0e0",
"output": "6"
},
{
"input": "1.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e1",
"output": "11.111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
}
] | 108 | 0 | 0 | 5,469 |
|
354 | Vasya and Robot | [
"brute force",
"greedy",
"math"
] | null | null | Vasya has *n* items lying in a line. The items are consecutively numbered by numbers from 1 to *n* in such a way that the leftmost item has number 1, the rightmost item has number *n*. Each item has a weight, the *i*-th item weights *w**i* kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
1. Take the leftmost item with the left hand and spend *w**i*<=·<=*l* energy units (*w**i* is a weight of the leftmost item, *l* is some parameter). If the previous action was the same (left-hand), then the robot spends extra *Q**l* energy units; 1. Take the rightmost item with the right hand and spend *w**j*<=·<=*r* energy units (*w**j* is a weight of the rightmost item, *r* is some parameter). If the previous action was the same (right-hand), then the robot spends extra *Q**r* energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items. | The first line contains five integers *n*,<=*l*,<=*r*,<=*Q**l*,<=*Q**r* (1<=≤<=*n*<=≤<=105;<=1<=≤<=*l*,<=*r*<=≤<=100;<=1<=≤<=*Q**l*,<=*Q**r*<=≤<=104).
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=100). | In the single line print a single number — the answer to the problem. | [
"3 4 4 19 1\n42 3 99\n",
"4 7 2 3 9\n1 2 3 4\n"
] | [
"576\n",
"34\n"
] | Consider the first sample. As *l* = *r*, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units. | [
{
"input": "3 4 4 19 1\n42 3 99",
"output": "576"
},
{
"input": "4 7 2 3 9\n1 2 3 4",
"output": "34"
},
{
"input": "2 100 100 10000 10000\n100 100",
"output": "20000"
},
{
"input": "2 3 4 5 6\n1 2",
"output": "11"
},
{
"input": "1 78 94 369 10000\n93",
"output": "7254"
},
{
"input": "1 94 78 369 10000\n93",
"output": "7254"
},
{
"input": "5 1 100 1 10000\n1 2 3 4 5",
"output": "19"
},
{
"input": "5 100 1 10000 1\n1 2 3 4 5",
"output": "19"
},
{
"input": "5 1 100 10000 1\n1 2 3 4 5",
"output": "906"
},
{
"input": "5 100 1 1 10000\n1 2 3 4 5",
"output": "312"
},
{
"input": "6 32 47 965 897\n7 4 1 3 5 4",
"output": "948"
},
{
"input": "7 3 13 30 978\n1 2 3 4 5 1 7",
"output": "199"
},
{
"input": "7 13 3 978 30\n7 1 5 4 3 2 1",
"output": "199"
}
] | 46 | 268,390,400 | 0 | 5,470 |
|
676 | Pyramid of Glasses | [
"implementation",
"math",
"math"
] | null | null | Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is *n*. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of *n* glasses.
Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid.
Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in *t* seconds.
Pictures below illustrate the pyramid consisting of three levels. | The only line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=10,<=0<=≤<=*t*<=≤<=10<=000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle. | Print the single integer — the number of completely full glasses after *t* seconds. | [
"3 5\n",
"4 8\n"
] | [
"4\n",
"6\n"
] | In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty. | [
{
"input": "3 5",
"output": "4"
},
{
"input": "4 8",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "10 10000",
"output": "55"
},
{
"input": "1 10000",
"output": "1"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "10 0",
"output": "0"
},
{
"input": "10 1022",
"output": "53"
},
{
"input": "10 1023",
"output": "55"
},
{
"input": "10 1024",
"output": "55"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 200",
"output": "1"
},
{
"input": "7 128",
"output": "28"
},
{
"input": "8 198",
"output": "34"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "2 4",
"output": "3"
},
{
"input": "2 100",
"output": "3"
},
{
"input": "2 10000",
"output": "3"
},
{
"input": "3 7",
"output": "6"
},
{
"input": "3 6",
"output": "4"
},
{
"input": "3 8",
"output": "6"
},
{
"input": "3 12",
"output": "6"
},
{
"input": "3 1",
"output": "1"
},
{
"input": "4 15",
"output": "10"
},
{
"input": "4 14",
"output": "8"
},
{
"input": "4 10",
"output": "8"
},
{
"input": "4 16",
"output": "10"
},
{
"input": "4 999",
"output": "10"
},
{
"input": "4 9",
"output": "8"
},
{
"input": "5 31",
"output": "15"
},
{
"input": "5 30",
"output": "13"
},
{
"input": "5 28",
"output": "13"
},
{
"input": "5 25",
"output": "13"
},
{
"input": "5 15",
"output": "13"
},
{
"input": "5 32",
"output": "15"
},
{
"input": "5 9999",
"output": "15"
},
{
"input": "5 4",
"output": "3"
},
{
"input": "5 9",
"output": "8"
},
{
"input": "5 14",
"output": "11"
},
{
"input": "6 63",
"output": "21"
},
{
"input": "6 62",
"output": "19"
},
{
"input": "6 61",
"output": "19"
},
{
"input": "6 52",
"output": "19"
},
{
"input": "6 31",
"output": "19"
},
{
"input": "6 32",
"output": "19"
},
{
"input": "6 39",
"output": "19"
},
{
"input": "6 15",
"output": "13"
},
{
"input": "6 14",
"output": "11"
},
{
"input": "6 10",
"output": "8"
},
{
"input": "6 4",
"output": "3"
},
{
"input": "6 7653",
"output": "21"
},
{
"input": "7 127",
"output": "28"
},
{
"input": "6 64",
"output": "21"
},
{
"input": "7 126",
"output": "26"
},
{
"input": "7 125",
"output": "26"
},
{
"input": "7 120",
"output": "26"
},
{
"input": "7 98",
"output": "26"
},
{
"input": "7 110",
"output": "26"
},
{
"input": "7 65",
"output": "26"
},
{
"input": "7 63",
"output": "26"
},
{
"input": "7 15",
"output": "13"
},
{
"input": "7 3",
"output": "3"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 83",
"output": "26"
},
{
"input": "7 214",
"output": "28"
},
{
"input": "8 2555",
"output": "36"
},
{
"input": "8 257",
"output": "36"
},
{
"input": "8 256",
"output": "36"
},
{
"input": "8 255",
"output": "36"
},
{
"input": "8 254",
"output": "34"
},
{
"input": "8 253",
"output": "34"
},
{
"input": "8 251",
"output": "34"
},
{
"input": "8 240",
"output": "34"
},
{
"input": "8 128",
"output": "34"
},
{
"input": "8 127",
"output": "34"
},
{
"input": "8 100",
"output": "32"
},
{
"input": "8 1",
"output": "1"
},
{
"input": "8 0",
"output": "0"
},
{
"input": "8 10000",
"output": "36"
},
{
"input": "8 94",
"output": "32"
},
{
"input": "8 33",
"output": "26"
},
{
"input": "9 10000",
"output": "45"
},
{
"input": "9 513",
"output": "45"
},
{
"input": "9 512",
"output": "45"
},
{
"input": "9 511",
"output": "45"
},
{
"input": "9 510",
"output": "43"
},
{
"input": "9 255",
"output": "43"
},
{
"input": "9 256",
"output": "43"
},
{
"input": "9 254",
"output": "41"
},
{
"input": "9 253",
"output": "41"
},
{
"input": "9 200",
"output": "41"
},
{
"input": "9 100",
"output": "37"
},
{
"input": "9 150",
"output": "41"
},
{
"input": "10 9999",
"output": "55"
},
{
"input": "10 1025",
"output": "55"
},
{
"input": "10 1021",
"output": "53"
},
{
"input": "10 512",
"output": "53"
},
{
"input": "10 689",
"output": "53"
},
{
"input": "10 754",
"output": "53"
},
{
"input": "10 985",
"output": "53"
},
{
"input": "10 255",
"output": "51"
},
{
"input": "10 256",
"output": "51"
},
{
"input": "10 254",
"output": "49"
},
{
"input": "10 153",
"output": "47"
},
{
"input": "10 2",
"output": "1"
},
{
"input": "10 3",
"output": "3"
},
{
"input": "10 5",
"output": "4"
},
{
"input": "10 63",
"output": "41"
},
{
"input": "10 64",
"output": "41"
},
{
"input": "10 126",
"output": "45"
},
{
"input": "10 127",
"output": "47"
},
{
"input": "10 128",
"output": "47"
},
{
"input": "10 55",
"output": "37"
},
{
"input": "10 9",
"output": "8"
},
{
"input": "10 37",
"output": "33"
},
{
"input": "10 68",
"output": "41"
},
{
"input": "3 4",
"output": "3"
},
{
"input": "7 23",
"output": "20"
},
{
"input": "1 3",
"output": "1"
}
] | 155 | 0 | 0 | 5,488 |
|
508 | Tanya and Password | [
"dfs and similar",
"graphs"
] | null | null | While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of *n*<=+<=2 characters. She has written all the possible *n* three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password out. Each three-letter substring was written the number of times it occurred in the password. Thus, Tanya ended up with *n* pieces of paper.
Then Tanya realized that dad will be upset to learn about her game and decided to restore the password or at least any string corresponding to the final set of three-letter strings. You have to help her in this difficult task. We know that dad's password consisted of lowercase and uppercase letters of the Latin alphabet and digits. Uppercase and lowercase letters of the Latin alphabet are considered distinct. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105), the number of three-letter substrings Tanya got.
Next *n* lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit. | If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO".
If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option. | [
"5\naca\naba\naba\ncab\nbac\n",
"4\nabc\nbCb\ncb1\nb13\n",
"7\naaa\naaa\naaa\naaa\naaa\naaa\naaa\n"
] | [
"YES\nabacaba\n",
"NO\n",
"YES\naaaaaaaaa\n"
] | none | [
{
"input": "5\naca\naba\naba\ncab\nbac",
"output": "YES\nabacaba"
},
{
"input": "4\nabc\nbCb\ncb1\nb13",
"output": "NO"
},
{
"input": "7\naaa\naaa\naaa\naaa\naaa\naaa\naaa",
"output": "YES\naaaaaaaaa"
},
{
"input": "1\nabc",
"output": "YES\nabc"
},
{
"input": "2\nbba\nabb",
"output": "YES\nabba"
},
{
"input": "3\naaa\naaa\naab",
"output": "YES\naaaab"
},
{
"input": "2\naba\nbab",
"output": "YES\nbaba"
},
{
"input": "2\nabc\nbga",
"output": "NO"
},
{
"input": "4\naba\nbab\ncdc\ndcd",
"output": "NO"
},
{
"input": "4\nbaa\ncaa\naax\naay",
"output": "NO"
},
{
"input": "2\naba\naba",
"output": "NO"
},
{
"input": "5\n123\n234\n345\n456\n567",
"output": "YES\n1234567"
},
{
"input": "3\n42y\n2ya\nya6",
"output": "YES\n42ya6"
},
{
"input": "8\nzHW\ncwx\nxmo\nWcw\nox1\nwxm\nmox\nHWc",
"output": "YES\nzHWcwxmox1"
},
{
"input": "98\nuOK\nI0I\n7Ql\nqT6\nYux\nnGb\nXuh\nNZ4\nzrV\ntlm\nRMm\nWyO\nOCX\nq2q\nTpY\nukr\nRuO\njr7\nRjv\nxBW\nBWy\n1nG\n7Tp\n4NQ\nrI0\nepN\nZfB\nUzz\n6PR\nzFC\nIKN\nlR1\nQiq\nD2U\nV1h\niZf\nr7T\nuOt\nyOC\nNTe\njaN\nlmN\n2Uz\nZ4N\nuxB\nvuk\nAu1\nVQG\nT6P\nNQi\nfBy\nnr7\npYu\n0IK\nCXu\nZja\nhZj\nKNn\nu1n\neoj\nQGR\nmvu\njv3\npNi\nv3i\nmNT\nMmv\nr7Q\nFCu\n2qT\nkrI\nCuO\nKbR\nOtl\nR1z\nBxA\nGbV\n1zr\nojr\nPRu\nhD2\n3iZ\nNnr\niq2\nbRM\nOKb\n1hD\nNiB\nzzF\nuhZ\nbV1\nrVQ\niBx\nQlR\nxAu\nTeo\nGRj\naNZ",
"output": "YES\nepNiBxAu1nGbV1hD2UzzFCuOKbRMmvukrI0IKNnr7TpYuxBWyOCXuhZjaNZ4NQiq2qT6PRuOtlmNTeojr7QlR1zrVQGRjv3iZfBy"
},
{
"input": "100\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa\naaa",
"output": "YES\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
},
{
"input": "98\n229\nB2p\npBp\np9T\np9B\nB9T\nB9p\nB2T\n22T\nTBB\np2B\n29B\n9B9\nBTT\n929\n9pB\nT92\nppB\nB92\nBpT\nB9p\n29B\nT9B\n9B2\nTB9\np99\nT2T\n9TT\n9B2\nTp9\n2pB\npTB\nBp9\n92p\nBTB\n9Tp\nTBB\nTTp\n9B9\nTp2\nTBT\n9BT\n9BT\npT9\npBp\npB2\np9B\npBB\nBpB\n9pB\nBTB\n992\n2T9\n2TT\nT9p\nBTp\nBTB\n9pT\nT29\nTT9\n2B2\n2BT\nTT2\nTTT\n922\nB2B\np22\n9pT\nB2p\npBp\nB9B\nBTp\npT2\n9B9\nBBp\n2p2\nBpT\nTB2\n92B\nBB2\nTp9\n2BT\nB9B\nBB9\n2BT\n292\nTp9\np9p\nTpp\n292\nB2T\n2Tp\n2p9\nB2B\n2TB\n929\npT9\nBB9",
"output": "YES\nBB9B9BTB2BTp9pT2922TBTBB9pT9pBB2Tp9BTB92p9B9pB2p229B2BTTT2TT9B2T929B9Tp2B2pBpBpTBBp9TTp99292BTppBpT9"
},
{
"input": "99\naaJ\nJx9\naLL\nrCx\nllJ\naja\nxxr\nLal\nv9C\njrL\nLvL\nJLl\nxlJ\nLja\nLLC\njvL\n9CJ\nvrJ\nlJJ\nlCC\nlxC\njxl\nLaJ\nLxJ\nrjr\nxvv\n9jC\nLxL\nvvr\nCCa\nJJr\nxJL\nxCj\nvv9\nLJJ\nx9J\nxx9\nrCx\nJLa\nrLv\nJrC\nvLx\njCv\nr9J\n9Cj\nv9C\naJL\nJrC\nCJx\nJJv\nJxx\nLCr\nLlx\nrJL\nx9L\naJx\nJxv\nxvv\nLLr\nLrC\nCv9\nCja\nxjv\n9Jj\nCjL\njvL\nC9j\nJLx\njaa\nxLJ\nlxv\n9LL\nJlC\nCxx\nJLa\njaj\nWRX\njJl\nljv\n9Jx\nall\nLlj\njaL\naJl\nvlx\nCr9\nCaJ\nCxj\nrC9\nJlJ\nlJL\njLl\nlJr\nvLj\njvl\nvjx\nJjv\nxrj\nJvj",
"output": "NO"
},
{
"input": "5\ndip\nBQd\nipB\npBQ\nQdi",
"output": "YES\nQdipBQd"
}
] | 483 | 9,011,200 | -1 | 5,498 |
|
171 | Mysterious numbers - 1 | [
"*special",
"constructive algorithms"
] | null | null | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space.
Output a single integer. | The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. | Output a single integer. | [
"3 14\n",
"27 12\n",
"100 200\n"
] | [
"44\n",
"48\n",
"102\n"
] | none | [
{
"input": "3 14",
"output": "44"
},
{
"input": "27 12",
"output": "48"
},
{
"input": "100 200",
"output": "102"
},
{
"input": "0 0",
"output": "0"
},
{
"input": "31415 92653",
"output": "67044"
},
{
"input": "1000000000 0",
"output": "1000000000"
},
{
"input": "0 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000",
"output": "1000000001"
},
{
"input": "804289383 846930886",
"output": "1492329031"
},
{
"input": "681692777 714636915",
"output": "1201329194"
},
{
"input": "957747793 424238335",
"output": "1491580217"
},
{
"input": "719885386 649760492",
"output": "1013953332"
},
{
"input": "596516649 189641421",
"output": "720663630"
},
{
"input": "25202362 350490027",
"output": "745296415"
},
{
"input": "783368690 102520059",
"output": "1733393891"
},
{
"input": "44897763 967513926",
"output": "674213532"
},
{
"input": "365180540 540383426",
"output": "989563585"
},
{
"input": "304089172 303455736",
"output": "941643475"
},
{
"input": "35005211 521595368",
"output": "898600336"
},
{
"input": "294702567 726956429",
"output": "1219362194"
},
{
"input": "336465782 861021530",
"output": "371585950"
},
{
"input": "278722862 233665123",
"output": "600289194"
},
{
"input": "145174067 468703135",
"output": "676481931"
},
{
"input": "101513929 801979802",
"output": "310493037"
},
{
"input": "315634022 635723058",
"output": "1165961558"
},
{
"input": "369133069 125898167",
"output": "1131031590"
},
{
"input": "59961393 89018456",
"output": "125442491"
},
{
"input": "628175011 656478042",
"output": "869049667"
},
{
"input": "131176229 653377373",
"output": "504949585"
},
{
"input": "859484421 914544919",
"output": "1778929840"
},
{
"input": "608413784 756898537",
"output": "1344312441"
},
{
"input": "734575198 973594324",
"output": "1158070577"
},
{
"input": "149798315 38664370",
"output": "157144998"
},
{
"input": "129566413 184803526",
"output": "754874894"
},
{
"input": "412776091 424268980",
"output": "502638515"
},
{
"input": "911759956 749241873",
"output": "1289902903"
},
{
"input": "137806862 42999170",
"output": "145006786"
},
{
"input": "982906996 135497281",
"output": "1165701527"
},
{
"input": "511702305 84420925",
"output": "564604753"
},
{
"input": "937477084 827336327",
"output": "1661110812"
},
{
"input": "1000000000 999999999",
"output": "1999999999"
}
] | 92 | 0 | 3 | 5,512 |
|
65 | Harry Potter and Three Spells | [
"implementation",
"math"
] | A. Harry Potter and Three Spells | 2 | 256 | A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a* grams of sand into *b* grams of lead, the second one allows you to convert *c* grams of lead into *d* grams of gold and third one allows you to convert *e* grams of gold into *f* grams of sand. When Harry told his friends about these spells, Ron Weasley was amazed. After all, if they succeed in turning sand into lead, lead into gold, and then turning part of the gold into sand again and so on, then it will be possible to start with a small amount of sand and get huge amounts of gold! Even an infinite amount of gold! Hermione Granger, by contrast, was skeptical about that idea. She argues that according to the law of conservation of matter getting an infinite amount of matter, even using magic, is impossible. On the contrary, the amount of matter may even decrease during transformation, being converted to magical energy. Though Hermione's theory seems convincing, Ron won't believe her. As far as Ron is concerned, Hermione made up her law of conservation of matter to stop Harry and Ron wasting their time with this nonsense, and to make them go and do homework instead. That's why Ron has already collected a certain amount of sand for the experiments. A quarrel between the friends seems unavoidable...
Help Harry to determine which one of his friends is right, and avoid the quarrel after all. To do this you have to figure out whether it is possible to get the amount of gold greater than any preassigned number from some finite amount of sand. | The first line contains 6 integers *a*, *b*, *c*, *d*, *e*, *f* (0<=≤<=*a*,<=*b*,<=*c*,<=*d*,<=*e*,<=*f*<=≤<=1000). | Print "Ron", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print "Hermione". | [
"100 200 250 150 200 250\n",
"100 50 50 200 200 100\n",
"100 10 200 20 300 30\n",
"0 0 0 0 0 0\n",
"1 1 0 1 1 1\n",
"1 0 1 2 1 2\n",
"100 1 100 1 0 1\n"
] | [
"Ron\n",
"Hermione\n",
"Hermione\n",
"Hermione\n",
"Ron\n",
"Hermione\n",
"Ron\n"
] | Consider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 grams of gold. If we apply the same operations to 500 grams of sand again, we can get extra 200 grams of gold every time. Thus, you can get 200, 400, 600 etc. grams of gold, i.e., starting with a finite amount of sand (500 grams), you can get the amount of gold which is greater than any preassigned number.
In the forth sample it is impossible to get sand, or lead, or gold, applying the spells.
In the fifth sample an infinitely large amount of gold can be obtained by using only the second spell, which allows you to receive 1 gram of gold out of nothing. Note that if such a second spell is available, then the first and the third one do not affect the answer at all.
The seventh sample is more interesting. We can also start with a zero amount of sand there. With the aid of the third spell you can get sand out of nothing. We get 10000 grams of sand in this manner. Let's get 100 grams of lead using the first spell 100 times. Then make 1 gram of gold from them. We managed to receive 1 gram of gold, starting with a zero amount of sand! Clearly, in this manner you can get an infinitely large amount of gold. | [
{
"input": "100 200 250 150 200 250",
"output": "Ron"
},
{
"input": "100 50 50 200 200 100",
"output": "Hermione"
},
{
"input": "100 10 200 20 300 30",
"output": "Hermione"
},
{
"input": "0 0 0 0 0 0",
"output": "Hermione"
},
{
"input": "1 1 0 1 1 1",
"output": "Ron"
},
{
"input": "1 0 1 2 1 2",
"output": "Hermione"
},
{
"input": "100 1 100 1 0 1",
"output": "Ron"
},
{
"input": "1 1 2 2 1 1",
"output": "Hermione"
},
{
"input": "4 4 1 3 1 4",
"output": "Ron"
},
{
"input": "3 3 2 1 4 4",
"output": "Hermione"
},
{
"input": "5 1 2 9 1 10",
"output": "Ron"
},
{
"input": "63 65 21 41 95 23",
"output": "Hermione"
},
{
"input": "913 0 0 0 0 0",
"output": "Hermione"
},
{
"input": "0 333 0 0 0 0",
"output": "Hermione"
},
{
"input": "842 538 0 0 0 0",
"output": "Hermione"
},
{
"input": "0 0 536 0 0 0",
"output": "Hermione"
},
{
"input": "324 0 495 0 0 0",
"output": "Hermione"
},
{
"input": "0 407 227 0 0 0",
"output": "Hermione"
},
{
"input": "635 63 924 0 0 0",
"output": "Hermione"
},
{
"input": "0 0 0 493 0 0",
"output": "Ron"
},
{
"input": "414 0 0 564 0 0",
"output": "Ron"
},
{
"input": "0 143 0 895 0 0",
"output": "Ron"
},
{
"input": "276 264 0 875 0 0",
"output": "Ron"
},
{
"input": "0 0 532 186 0 0",
"output": "Hermione"
},
{
"input": "510 0 692 825 0 0",
"output": "Hermione"
},
{
"input": "0 777 910 46 0 0",
"output": "Ron"
},
{
"input": "754 329 959 618 0 0",
"output": "Hermione"
},
{
"input": "0 0 0 0 416 0",
"output": "Hermione"
},
{
"input": "320 0 0 0 526 0",
"output": "Hermione"
},
{
"input": "0 149 0 0 6 0",
"output": "Hermione"
},
{
"input": "996 13 0 0 111 0",
"output": "Hermione"
},
{
"input": "0 0 531 0 688 0",
"output": "Hermione"
},
{
"input": "544 0 837 0 498 0",
"output": "Hermione"
},
{
"input": "0 54 680 0 988 0",
"output": "Hermione"
},
{
"input": "684 986 930 0 555 0",
"output": "Hermione"
},
{
"input": "0 0 0 511 534 0",
"output": "Ron"
},
{
"input": "594 0 0 819 304 0",
"output": "Ron"
},
{
"input": "0 55 0 977 230 0",
"output": "Ron"
},
{
"input": "189 291 0 845 97 0",
"output": "Ron"
},
{
"input": "0 0 77 302 95 0",
"output": "Hermione"
},
{
"input": "247 0 272 232 96 0",
"output": "Hermione"
},
{
"input": "0 883 219 748 77 0",
"output": "Ron"
},
{
"input": "865 643 599 98 322 0",
"output": "Hermione"
},
{
"input": "0 0 0 0 0 699",
"output": "Hermione"
},
{
"input": "907 0 0 0 0 99",
"output": "Hermione"
},
{
"input": "0 891 0 0 0 529",
"output": "Hermione"
},
{
"input": "640 125 0 0 0 849",
"output": "Hermione"
},
{
"input": "0 0 698 0 0 702",
"output": "Hermione"
},
{
"input": "58 0 483 0 0 470",
"output": "Hermione"
},
{
"input": "0 945 924 0 0 355",
"output": "Hermione"
},
{
"input": "998 185 209 0 0 554",
"output": "Hermione"
},
{
"input": "0 0 0 914 0 428",
"output": "Ron"
},
{
"input": "412 0 0 287 0 575",
"output": "Ron"
},
{
"input": "0 850 0 509 0 76",
"output": "Ron"
},
{
"input": "877 318 0 478 0 782",
"output": "Ron"
},
{
"input": "0 0 823 740 0 806",
"output": "Hermione"
},
{
"input": "126 0 620 51 0 835",
"output": "Hermione"
},
{
"input": "0 17 946 633 0 792",
"output": "Ron"
},
{
"input": "296 546 493 22 0 893",
"output": "Ron"
},
{
"input": "0 0 0 0 766 813",
"output": "Hermione"
},
{
"input": "319 0 0 0 891 271",
"output": "Hermione"
},
{
"input": "0 252 0 0 261 576",
"output": "Hermione"
},
{
"input": "876 440 0 0 65 362",
"output": "Hermione"
},
{
"input": "0 0 580 0 245 808",
"output": "Hermione"
},
{
"input": "835 0 116 0 9 552",
"output": "Hermione"
},
{
"input": "0 106 748 0 773 840",
"output": "Hermione"
},
{
"input": "935 388 453 0 797 235",
"output": "Hermione"
},
{
"input": "0 0 0 893 293 289",
"output": "Ron"
},
{
"input": "938 0 0 682 55 725",
"output": "Ron"
},
{
"input": "0 710 0 532 389 511",
"output": "Ron"
},
{
"input": "617 861 0 247 920 902",
"output": "Ron"
},
{
"input": "0 0 732 202 68 389",
"output": "Hermione"
},
{
"input": "279 0 254 964 449 143",
"output": "Hermione"
},
{
"input": "0 746 400 968 853 85",
"output": "Ron"
},
{
"input": "565 846 658 828 767 734",
"output": "Ron"
},
{
"input": "6 6 1 6 1 6",
"output": "Ron"
},
{
"input": "3 6 1 6 3 3",
"output": "Ron"
},
{
"input": "6 3 1 3 2 3",
"output": "Ron"
},
{
"input": "3 6 2 2 6 3",
"output": "Hermione"
},
{
"input": "3 2 2 1 3 3",
"output": "Hermione"
},
{
"input": "1 1 1 6 1 1",
"output": "Ron"
},
{
"input": "1 3 1 3 3 2",
"output": "Ron"
},
{
"input": "6 2 6 6 2 3",
"output": "Hermione"
},
{
"input": "2 6 2 1 2 1",
"output": "Hermione"
},
{
"input": "2 3 2 1 6 6",
"output": "Hermione"
},
{
"input": "2 1 2 1 6 2",
"output": "Hermione"
},
{
"input": "6 1 3 1 3 3",
"output": "Hermione"
},
{
"input": "1 2 2 3 2 2",
"output": "Ron"
},
{
"input": "3 3 2 6 3 6",
"output": "Ron"
},
{
"input": "2 1 6 1 2 6",
"output": "Hermione"
},
{
"input": "2 3 1 3 1 6",
"output": "Ron"
},
{
"input": "6 6 2 3 1 3",
"output": "Ron"
},
{
"input": "6 2 6 2 3 1",
"output": "Hermione"
},
{
"input": "1 6 6 2 3 2",
"output": "Ron"
},
{
"input": "6 3 6 2 6 6",
"output": "Hermione"
},
{
"input": "1 3 1 6 6 1",
"output": "Ron"
},
{
"input": "1 1 1 1 6 6",
"output": "Hermione"
},
{
"input": "2 6 2 2 2 3",
"output": "Ron"
},
{
"input": "1 6 1 6 6 3",
"output": "Ron"
},
{
"input": "6 6 3 1 3 3",
"output": "Hermione"
},
{
"input": "2 6 6 1 2 6",
"output": "Ron"
},
{
"input": "3 2 6 6 1 6",
"output": "Ron"
},
{
"input": "1 2 3 2 2 3",
"output": "Ron"
},
{
"input": "2 6 1 1 1 6",
"output": "Ron"
},
{
"input": "1 6 3 6 6 3",
"output": "Ron"
},
{
"input": "3 3 3 2 6 2",
"output": "Hermione"
},
{
"input": "6 2 3 6 2 2",
"output": "Hermione"
},
{
"input": "2 1 2 3 3 2",
"output": "Hermione"
},
{
"input": "6 2 1 1 3 6",
"output": "Hermione"
},
{
"input": "6 6 6 6 3 2",
"output": "Hermione"
},
{
"input": "6 1 1 6 2 3",
"output": "Ron"
},
{
"input": "6 1 3 6 1 2",
"output": "Hermione"
},
{
"input": "2 1 2 6 6 1",
"output": "Hermione"
},
{
"input": "1 2 2 3 2 1",
"output": "Ron"
},
{
"input": "2 2 6 6 6 6",
"output": "Hermione"
},
{
"input": "31 75 12 62 94 137",
"output": "Ron"
},
{
"input": "236 9 184 68 345 332",
"output": "Hermione"
},
{
"input": "362 142 107 565 329 608",
"output": "Ron"
},
{
"input": "731 859 197 474 370 465",
"output": "Ron"
},
{
"input": "452 577 639 31 60 673",
"output": "Hermione"
},
{
"input": "821 294 730 941 101 530",
"output": "Ron"
},
{
"input": "542 11 820 850 791 738",
"output": "Hermione"
},
{
"input": "911 728 910 407 833 594",
"output": "Hermione"
},
{
"input": "632 446 352 317 522 451",
"output": "Hermione"
}
] | 124 | 31,744,000 | -1 | 5,513 |
818 | Permutation Game | [
"implementation"
] | null | null | *n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it.
The game consists of *m* steps. On each step the current leader with index *i* counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader becomes the new leader.
You are given numbers *l*1,<=*l*2,<=...,<=*l**m* — indices of leaders in the beginning of each step. Child with number *l*1 is the first leader in the game.
Write a program which will restore a possible permutation *a*1,<=*a*2,<=...,<=*a**n*. If there are multiple solutions then print any of them. If there is no solution then print -1. | The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step. | Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them.
If there is no permutation which satisfies all described conditions print -1. | [
"4 5\n2 3 1 4 4\n",
"3 3\n3 1 2\n"
] | [
"3 1 2 4 \n",
"-1\n"
] | Let's follow leadership in the first example:
- Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lower-index">1</sub> = 4. - Leadership goes from 4 to 4 + *a*<sub class="lower-index">4</sub> = 8. Thus in circle it still remains at 4. | [
{
"input": "4 5\n2 3 1 4 4",
"output": "3 1 2 4 "
},
{
"input": "3 3\n3 1 2",
"output": "-1"
},
{
"input": "1 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",
"output": "1 "
},
{
"input": "6 8\n2 5 4 2 5 4 2 5",
"output": "1 3 2 4 5 6 "
},
{
"input": "100 1\n6",
"output": "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 "
},
{
"input": "10 5\n7 7 9 9 3",
"output": "-1"
},
{
"input": "10 20\n10 1 5 7 1 2 5 3 6 3 9 4 3 4 9 6 8 4 9 6",
"output": "-1"
},
{
"input": "20 15\n11 19 1 8 17 12 3 1 8 17 12 3 1 8 17",
"output": "7 1 18 3 4 5 6 9 10 12 8 11 13 14 16 17 15 19 2 20 "
},
{
"input": "100 100\n96 73 23 74 35 44 75 13 62 50 76 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63 29 45 24 63",
"output": "1 2 3 4 5 6 7 8 10 11 12 13 49 14 15 17 18 19 20 21 22 23 51 39 24 25 27 28 16 29 30 32 33 34 9 35 36 37 40 41 42 43 44 31 79 45 46 47 48 26 52 53 54 55 56 57 58 59 60 62 63 88 66 64 65 67 68 69 70 71 72 73 50 61 38 87 74 75 76 78 80 81 82 83 84 85 86 89 90 91 92 93 94 95 96 77 97 98 99 100 "
},
{
"input": "100 100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91",
"output": "-1"
},
{
"input": "20 20\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11",
"output": "19 17 15 13 11 9 7 5 3 1 20 18 16 14 12 10 8 6 4 2 "
},
{
"input": "20 5\n1 20 2 19 3",
"output": "19 17 1 3 5 6 7 8 9 10 11 12 13 14 15 16 18 20 4 2 "
},
{
"input": "19 19\n1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10",
"output": "-1"
},
{
"input": "100 100\n1 99 2 98 3 97 4 96 5 95 6 94 7 93 8 92 9 91 10 90 11 89 12 88 13 87 14 86 15 85 16 84 17 83 18 82 19 81 20 80 21 79 22 78 23 77 24 76 25 75 26 74 27 73 28 72 29 71 30 70 31 69 32 68 33 67 34 66 35 65 36 64 37 63 38 62 39 61 40 60 41 59 42 58 43 57 44 56 45 55 46 54 47 53 48 52 49 51 50 50",
"output": "98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 100 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 "
},
{
"input": "51 18\n8 32 24 19 1 29 49 24 39 33 5 37 37 26 17 28 2 19",
"output": "-1"
},
{
"input": "5 5\n1 2 5 2 4",
"output": "-1"
},
{
"input": "6 6\n1 2 1 1 3 6",
"output": "-1"
},
{
"input": "4 4\n4 3 4 2",
"output": "-1"
},
{
"input": "3 3\n2 2 3",
"output": "-1"
},
{
"input": "4 6\n1 1 2 4 4 4",
"output": "-1"
},
{
"input": "9 4\n8 2 8 3",
"output": "-1"
},
{
"input": "4 6\n2 3 1 4 4 1",
"output": "-1"
},
{
"input": "2 3\n1 1 2",
"output": "-1"
},
{
"input": "5 7\n4 3 4 3 3 4 5",
"output": "-1"
},
{
"input": "2 9\n1 1 1 1 2 1 1 1 1",
"output": "-1"
},
{
"input": "4 4\n2 4 4 4",
"output": "1 2 3 4 "
},
{
"input": "3 3\n1 1 3",
"output": "-1"
},
{
"input": "2 5\n1 2 2 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 3",
"output": "-1"
},
{
"input": "3 4\n1 3 1 1",
"output": "-1"
},
{
"input": "4 4\n1 4 1 1",
"output": "-1"
},
{
"input": "66 67\n19 9 60 40 19 48 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5 58 5",
"output": "-1"
},
{
"input": "3 3\n3 3 2",
"output": "-1"
},
{
"input": "27 28\n8 18 27 24 20 8 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23",
"output": "-1"
},
{
"input": "4 3\n1 1 2",
"output": "-1"
},
{
"input": "4 4\n2 4 2 3",
"output": "-1"
},
{
"input": "2 3\n2 2 1",
"output": "-1"
},
{
"input": "2 2\n2 2",
"output": "1 2 "
},
{
"input": "3 4\n2 3 3 1",
"output": "-1"
},
{
"input": "5 6\n1 4 4 2 1 4",
"output": "-1"
},
{
"input": "4 3\n2 3 4",
"output": "-1"
},
{
"input": "2 3\n1 2 1",
"output": "-1"
},
{
"input": "10 4\n5 6 5 7",
"output": "-1"
},
{
"input": "3 3\n1 1 2",
"output": "-1"
},
{
"input": "4 5\n1 4 1 3 2",
"output": "-1"
},
{
"input": "6 5\n1 2 4 1 3",
"output": "-1"
}
] | 31 | 4,608,000 | 0 | 5,514 |
|
893 | Chess For Three | [
"implementation"
] | null | null | Alex, Bob and Carl will soon participate in a team chess tournament. Since they are all in the same team, they have decided to practise really hard before the tournament. But it's a bit difficult for them because chess is a game for two players, not three.
So they play with each other according to following rules:
- Alex and Bob play the first game, and Carl is spectating; - When the game ends, the one who lost the game becomes the spectator in the next game, and the one who was spectating plays against the winner.
Alex, Bob and Carl play in such a way that there are no draws.
Today they have played *n* games, and for each of these games they remember who was the winner. They decided to make up a log of games describing who won each game. But now they doubt if the information in the log is correct, and they want to know if the situation described in the log they made up was possible (that is, no game is won by someone who is spectating if Alex, Bob and Carl play according to the rules). Help them to check it! | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of games Alex, Bob and Carl played.
Then *n* lines follow, describing the game log. *i*-th line contains one integer *a**i* (1<=≤<=*a**i*<=≤<=3) which is equal to 1 if Alex won *i*-th game, to 2 if Bob won *i*-th game and 3 if Carl won *i*-th game. | Print YES if the situation described in the log was possible. Otherwise print NO. | [
"3\n1\n1\n2\n",
"2\n1\n2\n"
] | [
"YES\n",
"NO\n"
] | In the first example the possible situation is:
1. Alex wins, Carl starts playing instead of Bob; 1. Alex wins, Bob replaces Carl; 1. Bob wins.
The situation in the second example is impossible because Bob loses the first game, so he cannot win the second one. | [
{
"input": "3\n1\n1\n2",
"output": "YES"
},
{
"input": "2\n1\n2",
"output": "NO"
},
{
"input": "100\n2\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n3\n3\n3\n3\n3\n3\n1\n2\n2\n2\n3\n1\n1\n3\n3\n3\n3\n3\n3\n3\n3\n1\n2\n3\n3\n3\n1\n1\n1\n1\n3\n3\n3\n3\n1\n2\n3\n1\n2\n2\n2\n3\n3\n2\n1\n3\n3\n1\n2\n3\n1\n1\n1\n2\n2\n2\n3\n1\n1\n1\n1\n1\n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1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "1\n3",
"output": "NO"
},
{
"input": "1\n2",
"output": "YES"
},
{
"input": "42\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\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "4\n2\n3\n3\n3",
"output": "YES"
},
{
"input": "3\n1\n2\n3",
"output": "NO"
},
{
"input": "5\n1\n1\n1\n1\n3",
"output": "NO"
},
{
"input": "5\n2\n3\n3\n3\n3",
"output": "YES"
},
{
"input": "2\n3\n3",
"output": "NO"
},
{
"input": "4\n1\n2\n2\n1",
"output": "NO"
},
{
"input": "3\n2\n2\n3",
"output": "NO"
},
{
"input": "5\n2\n3\n3\n1\n1",
"output": "NO"
},
{
"input": "3\n3\n1\n3",
"output": "NO"
},
{
"input": "3\n3\n3\n1",
"output": "NO"
},
{
"input": "2\n2\n1",
"output": "NO"
},
{
"input": "3\n1\n1\n3",
"output": "NO"
},
{
"input": "6\n2\n2\n2\n3\n1\n3",
"output": "NO"
},
{
"input": "2\n3\n1",
"output": "NO"
},
{
"input": "2\n3\n2",
"output": "NO"
},
{
"input": "2\n1\n3",
"output": "YES"
},
{
"input": "3\n1\n3\n1",
"output": "NO"
},
{
"input": "5\n1\n1\n2\n2\n3",
"output": "NO"
},
{
"input": "3\n2\n1\n1",
"output": "NO"
},
{
"input": "2\n2\n2",
"output": "YES"
},
{
"input": "3\n2\n2\n1",
"output": "YES"
},
{
"input": "5\n2\n2\n2\n2\n2",
"output": "YES"
},
{
"input": "8\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "YES"
},
{
"input": "3\n3\n2\n2",
"output": "NO"
},
{
"input": "3\n3\n2\n3",
"output": "NO"
},
{
"input": "7\n2\n2\n2\n2\n2\n2\n2",
"output": "YES"
},
{
"input": "3\n2\n2\n2",
"output": "YES"
}
] | 46 | 0 | 3 | 5,521 |
|
812 | Sagheer and Nubian Market | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<=*x**k*, then the cost of item *x**j* is *a**x**j*<=+<=*x**j*·*k* for 1<=≤<=*j*<=≤<=*k*. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor *k*.
Sagheer wants to buy as many souvenirs as possible without paying more than *S* Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task? | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"output": "3 27"
},
{
"input": "86 96\n89 48 14 55 5 35 7 79 49 70 74 18 64 63 35 93 63 97 90 77 33 11 100 75 60 99 54 38 3 6 55 1 7 64 56 90 21 76 35 16 61 78 38 78 93 21 89 1 58 53 34 77 56 37 46 59 30 5 85 1 52 87 84 99 97 9 15 66 29 60 17 16 59 23 88 93 32 2 98 89 63 42 9 86 70 80",
"output": "3 71"
},
{
"input": "9 2727\n73 41 68 90 51 7 20 48 69",
"output": "9 872"
},
{
"input": "35 792600\n61 11 82 29 3 50 65 60 62 86 83 78 15 82 7 77 38 87 100 12 93 86 96 79 14 58 60 47 94 39 36 23 69 93 18",
"output": "35 24043"
},
{
"input": "63 47677090\n53 4 59 68 6 12 47 63 28 93 9 53 61 63 53 70 77 63 49 76 70 23 4 40 4 34 24 70 42 83 84 95 11 46 38 83 26 85 34 29 67 96 3 62 97 7 42 65 49 45 50 54 81 74 83 59 10 87 95 87 89 27 3",
"output": "63 130272"
},
{
"input": "88 631662736\n93 75 25 7 6 55 92 23 22 32 4 48 61 29 91 79 16 18 18 9 66 9 57 62 3 81 48 16 21 90 93 58 30 8 31 47 44 70 34 85 52 71 58 42 99 53 43 54 96 26 6 13 38 4 13 60 1 48 32 100 52 8 27 99 66 34 98 45 19 50 37 59 31 56 58 70 61 14 100 66 74 85 64 57 92 89 7 92",
"output": "88 348883"
},
{
"input": "12 12\n1232 1848 2048 4694 5121 3735 9968 4687 2040 6033 5839 2507",
"output": "0 0"
},
{
"input": "37 5271\n368 6194 4856 8534 944 4953 2085 5350 788 7772 9786 1321 4310 4453 7078 9912 5799 4066 5471 5079 5161 9773 1300 5474 1202 1353 9499 9694 9020 6332 595 7619 1271 7430 1199 3127 8867",
"output": "5 4252"
},
{
"input": "65 958484\n9597 1867 5346 637 6115 5833 3318 6059 4430 9169 8155 7895 3534 7962 9900 9495 5694 3461 5370 1945 1724 9264 3475 618 3421 551 8359 6889 1843 6716 9216 2356 1592 6265 2945 6496 4947 2840 9057 6141 887 4823 4004 8027 1993 1391 796 7059 5500 4369 4012 4983 6495 8990 3633 5439 421 1129 6970 8796 7826 1200 8741 6555 5037",
"output": "65 468998"
},
{
"input": "90 61394040\n2480 6212 4506 829 8191 797 5336 6722 3178 1007 5849 3061 3588 6684 5983 5452 7654 5321 660 2569 2809 2179 679 4858 6887 2580 6880 6120 4159 5542 4999 8703 2386 8221 7046 1229 1662 4542 7089 3548 4298 1973 1854 2473 5507 241 359 5248 7907 5201 9624 4596 1723 2622 4800 4716 693 961 7402 9004 7994 8048 6590 5866 7502 3304 4331 5218 6906 1016 5342 6644 2205 5823 8525 4839 1914 2651 3940 7751 3489 4178 7234 6640 7602 9765 8559 7819 5827 163",
"output": "90 795634"
},
{
"input": "14 891190480\n1424 3077 9632 6506 4568 9650 5534 1085 6934 9340 2867 367 7075 618",
"output": "14 70147"
},
{
"input": "39 43\n22166 81842 15513 80979 39645 60168 96994 13493 12904 79871 49910 45356 93691 51829 18226 34288 11525 41944 40433 67295 30123 1081 55623 22279 75814 82316 2963 39329 38223 8445 43202 61912 15122 86367 37200 68113 57194 38541 49641",
"output": "0 0"
},
{
"input": "67 8824\n75515 67590 86373 34191 3446 27408 31581 24727 40005 23718 39738 30960 4786 51040 32590 80454 14335 47173 20079 41204 67289 58347 88969 88396 37681 43963 13886 85690 12259 14732 42036 62620 15011 41890 20150 59469 62104 30136 47163 19790 25699 27453 36151 52914 52684 20503 78622 81082 94500 55756 94030 54764 72763 37830 13210 64559 53600 87998 80472 19001 83769 79700 88794 10161 99980 95184 74439",
"output": "2 8268"
},
{
"input": "16 56532535\n84567 85265 99012 62115 58908 10120 27355 90226 17191 35588 43807 6327 89157 71156 16253 22387",
"output": "16 821610"
},
{
"input": "42 818723640\n57019 99450 43192 25131 80678 41786 52490 34454 51620 56132 41773 94622 23949 11597 96944 51420 44164 85727 72959 26622 1838 36302 99335 35572 92734 10651 22293 97601 38634 24066 81870 10904 5825 71968 2377 61198 3104 4191 97851 99920 65295 1385",
"output": "42 2094569"
}
] | 124 | 0 | 0 | 5,523 |
|
990 | Commentary Boxes | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "5000000000020"
},
{
"input": "1000000000000 750000000001 100 10",
"output": "2499999999990"
},
{
"input": "42 1 1 1",
"output": "0"
},
{
"input": "1 1000000000000 1 100",
"output": "100"
},
{
"input": "7 2 3 7",
"output": "3"
},
{
"input": "999999999 2 1 1",
"output": "1"
},
{
"input": "999999999999 10000000007 100 100",
"output": "70100"
},
{
"input": "10000000001 2 1 1",
"output": "1"
},
{
"input": "29 6 1 2",
"output": "1"
},
{
"input": "99999999999 6 100 100",
"output": "300"
},
{
"input": "1000000000000 7 3 8",
"output": "8"
},
{
"input": "99999999999 2 1 1",
"output": "1"
},
{
"input": "1 2 1 1",
"output": "1"
},
{
"input": "999999999999 2 1 1",
"output": "1"
},
{
"input": "9 2 1 1",
"output": "1"
},
{
"input": "17 4 5 5",
"output": "5"
},
{
"input": "100000000000 3 1 1",
"output": "1"
},
{
"input": "100 7 1 1",
"output": "2"
},
{
"input": "1000000000000 3 100 100",
"output": "100"
},
{
"input": "70 3 10 10",
"output": "10"
},
{
"input": "1 2 5 1",
"output": "1"
},
{
"input": "1000000000000 3 1 1",
"output": "1"
},
{
"input": "804289377 846930887 78 16",
"output": "3326037780"
},
{
"input": "1000000000000 9 55 55",
"output": "55"
},
{
"input": "957747787 424238336 87 93",
"output": "10162213695"
},
{
"input": "25 6 1 2",
"output": "2"
},
{
"input": "22 7 3 8",
"output": "8"
},
{
"input": "10000000000 1 1 1",
"output": "0"
},
{
"input": "999999999999 2 10 10",
"output": "10"
},
{
"input": "999999999999 2 100 100",
"output": "100"
},
{
"input": "100 3 3 8",
"output": "6"
},
{
"input": "99999 2 1 1",
"output": "1"
},
{
"input": "100 3 2 5",
"output": "4"
},
{
"input": "1000000000000 13 10 17",
"output": "17"
},
{
"input": "7 2 1 2",
"output": "1"
},
{
"input": "10 3 1 2",
"output": "2"
},
{
"input": "5 2 2 2",
"output": "2"
},
{
"input": "100 3 5 2",
"output": "2"
},
{
"input": "7 2 1 1",
"output": "1"
},
{
"input": "70 4 1 1",
"output": "2"
},
{
"input": "10 4 1 1",
"output": "2"
},
{
"input": "6 7 41 42",
"output": "41"
},
{
"input": "10 3 10 1",
"output": "1"
},
{
"input": "5 5 2 3",
"output": "0"
},
{
"input": "1000000000000 3 99 99",
"output": "99"
},
{
"input": "7 3 100 1",
"output": "1"
},
{
"input": "7 2 100 5",
"output": "5"
},
{
"input": "1000000000000 1 23 33",
"output": "0"
},
{
"input": "30 7 1 1",
"output": "2"
},
{
"input": "100 3 1 1",
"output": "1"
},
{
"input": "90001 300 100 1",
"output": "1"
},
{
"input": "13 4 1 2",
"output": "2"
},
{
"input": "1000000000000 6 1 3",
"output": "2"
},
{
"input": "50 4 5 100",
"output": "10"
},
{
"input": "999 2 1 1",
"output": "1"
},
{
"input": "5 2 5 5",
"output": "5"
},
{
"input": "20 3 3 3",
"output": "3"
},
{
"input": "3982258181 1589052704 87 20",
"output": "16083055460"
},
{
"input": "100 3 1 3",
"output": "2"
},
{
"input": "7 3 1 1",
"output": "1"
},
{
"input": "19 10 100 100",
"output": "100"
},
{
"input": "23 3 100 1",
"output": "2"
},
{
"input": "25 7 100 1",
"output": "4"
},
{
"input": "100 9 1 2",
"output": "2"
},
{
"input": "9999999999 2 1 100",
"output": "1"
},
{
"input": "1000000000000 2 1 1",
"output": "0"
},
{
"input": "10000 3 1 1",
"output": "1"
},
{
"input": "22 7 1 6",
"output": "6"
},
{
"input": "100000000000 1 1 1",
"output": "0"
},
{
"input": "18 7 100 1",
"output": "4"
},
{
"input": "10003 4 1 100",
"output": "1"
},
{
"input": "3205261341 718648876 58 11",
"output": "3637324207"
},
{
"input": "8 3 100 1",
"output": "2"
},
{
"input": "15 7 1 1",
"output": "1"
},
{
"input": "1000000000000 1 20 20",
"output": "0"
},
{
"input": "16 7 3 2",
"output": "4"
},
{
"input": "1000000000000 1 1 1",
"output": "0"
},
{
"input": "7 3 1 100",
"output": "2"
},
{
"input": "16 3 1 100",
"output": "2"
},
{
"input": "13 4 1 10",
"output": "3"
},
{
"input": "10 4 5 5",
"output": "10"
},
{
"input": "14 3 1 100",
"output": "1"
},
{
"input": "100 33 100 1",
"output": "1"
},
{
"input": "22 7 1 8",
"output": "6"
},
{
"input": "10 4 2 1",
"output": "2"
},
{
"input": "6 4 2 2",
"output": "4"
},
{
"input": "17 4 2 1",
"output": "1"
},
{
"input": "7 3 100 10",
"output": "10"
},
{
"input": "702 7 3 2",
"output": "4"
},
{
"input": "8 3 1 5",
"output": "1"
},
{
"input": "3 2 5 2",
"output": "2"
},
{
"input": "99 19 1 7",
"output": "15"
},
{
"input": "16 3 100 1",
"output": "1"
},
{
"input": "100 34 1 100",
"output": "2"
},
{
"input": "100 33 1 1",
"output": "1"
},
{
"input": "2 3 4 3",
"output": "4"
},
{
"input": "15 4 4 10",
"output": "4"
},
{
"input": "1144108931 470211273 45 79",
"output": "11993619960"
},
{
"input": "2 3 3 4",
"output": "3"
},
{
"input": "29 5 4 9",
"output": "4"
},
{
"input": "15 7 1 5",
"output": "5"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "1 1 3 4",
"output": "0"
},
{
"input": "10 12 2 1",
"output": "4"
},
{
"input": "1 2 3 4",
"output": "3"
}
] | 124 | 0 | 0 | 5,528 |
|
287 | Pipeline | [
"binary search",
"math"
] | null | null | Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.
A splitter is a construction that consists of one input (it can be connected to a water pipe) and *x* output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe.
Vova has one splitter of each kind: with 2, 3, 4, ..., *k* outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.
Vova needs the pipeline to have exactly *n* pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters. | The first line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1. | [
"4 3\n",
"5 5\n",
"8 4\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | [
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "1000000000000000000 1000000000",
"output": "-1"
},
{
"input": "499999998500000001 1000000000",
"output": "999955279"
},
{
"input": "499999998500000000 1000000000",
"output": "999955279"
},
{
"input": "499999999500000000 1000000000",
"output": "999999998"
},
{
"input": "499999999500000001 1000000000",
"output": "999999999"
},
{
"input": "525 34",
"output": "25"
},
{
"input": "223265034477 726990",
"output": "440662"
},
{
"input": "15597035789572051 185473109",
"output": "128849771"
},
{
"input": "499999999500000002 1000000000",
"output": "-1"
},
{
"input": "1 1000000000",
"output": "0"
},
{
"input": "1000000000 2",
"output": "-1"
},
{
"input": "462498979 204468265",
"output": "3"
},
{
"input": "2107921 542531",
"output": "4"
},
{
"input": "131 49",
"output": "3"
},
{
"input": "20171878992939541 200857557",
"output": "200853401"
},
{
"input": "399812655947 894219",
"output": "893030"
},
{
"input": "93 17",
"output": "8"
},
{
"input": "1000000000 999999999",
"output": "2"
},
{
"input": "100000000000000000 1000000000",
"output": "105572810"
}
] | 31 | 0 | 0 | 5,539 |
|
476 | Dreamoon and Stairs | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 3",
"output": "5001"
},
{
"input": "10000 10",
"output": "5000"
},
{
"input": "9999 3",
"output": "5001"
},
{
"input": "9999 2",
"output": "5000"
},
{
"input": "9999 10",
"output": "5000"
},
{
"input": "9999 9",
"output": "5004"
},
{
"input": "18 10",
"output": "10"
},
{
"input": "19 10",
"output": "10"
},
{
"input": "20 10",
"output": "10"
},
{
"input": "21 10",
"output": "20"
},
{
"input": "7688 5",
"output": "3845"
},
{
"input": "4608 5",
"output": "2305"
},
{
"input": "3979 2",
"output": "1990"
},
{
"input": "9985 6",
"output": "4998"
},
{
"input": "3230 8",
"output": "1616"
},
{
"input": "24 9",
"output": "18"
},
{
"input": "3275 8",
"output": "1640"
},
{
"input": "6240 7",
"output": "3122"
},
{
"input": "5227 4",
"output": "2616"
},
{
"input": "3832 6",
"output": "1920"
},
{
"input": "4 2",
"output": "2"
},
{
"input": "6 3",
"output": "3"
},
{
"input": "10 5",
"output": "5"
},
{
"input": "3 2",
"output": "2"
},
{
"input": "6 4",
"output": "4"
},
{
"input": "5 2",
"output": "4"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "9 9",
"output": "9"
},
{
"input": "4 5",
"output": "-1"
}
] | 93 | 0 | 3 | 5,552 |
|
840 | Destiny | [
"data structures",
"probabilities"
] | null | null | Once, Leha found in the left pocket an array consisting of *n* integers, and in the right pocket *q* queries of the form *l* *r* *k*. If there are queries, then they must be answered. Answer for the query is minimal *x* such that *x* occurs in the interval *l* *r* strictly more than times or <=-<=1 if there is no such number. Help Leha with such a difficult task. | First line of input data contains two integers *n* and *q* (1<=≤<=*n*,<=*q*<=≤<=3·105) — number of elements in the array and number of queries respectively.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — Leha's array.
Each of next *q* lines contains three integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*,<=2<=≤<=*k*<=≤<=5) — description of the queries. | Output answer for each query in new line. | [
"4 2\n1 1 2 2\n1 3 2\n1 4 2\n",
"5 3\n1 2 1 3 2\n2 5 3\n1 2 3\n5 5 2\n"
] | [
"1\n-1\n",
"2\n1\n2\n"
] | none | [] | 30 | 0 | 0 | 5,558 |
|
495 | Digital Counter | [
"implementation"
] | null | null | Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each digit.
One day when Malek wanted to go from floor 88 to floor 0 using the elevator he noticed that the counter shows number 89 instead of 88. Then when the elevator started moving the number on the counter changed to 87. After a little thinking Malek came to the conclusion that there is only one explanation for this: One of the sticks of the counter was broken. Later that day Malek was thinking about the broken stick and suddenly he came up with the following problem.
Suppose the digital counter is showing number *n*. Malek calls an integer *x* (0<=≤<=*x*<=≤<=99) good if it's possible that the digital counter was supposed to show *x* but because of some(possibly none) broken sticks it's showing *n* instead. Malek wants to know number of good integers for a specific *n*. So you must write a program that calculates this number. Please note that the counter always shows two digits. | The only line of input contains exactly two digits representing number *n* (0<=≤<=*n*<=≤<=99). Note that *n* may have a leading zero. | In the only line of the output print the number of good integers. | [
"89\n",
"00\n",
"73\n"
] | [
"2\n",
"4\n",
"15\n"
] | In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | [
{
"input": "89",
"output": "2"
},
{
"input": "00",
"output": "4"
},
{
"input": "73",
"output": "15"
},
{
"input": "08",
"output": "2"
},
{
"input": "26",
"output": "4"
},
{
"input": "49",
"output": "6"
},
{
"input": "88",
"output": "1"
},
{
"input": "04",
"output": "6"
},
{
"input": "60",
"output": "4"
},
{
"input": "11",
"output": "49"
},
{
"input": "22",
"output": "4"
},
{
"input": "33",
"output": "9"
},
{
"input": "44",
"output": "9"
},
{
"input": "55",
"output": "16"
},
{
"input": "66",
"output": "4"
},
{
"input": "77",
"output": "25"
},
{
"input": "88",
"output": "1"
},
{
"input": "99",
"output": "4"
},
{
"input": "80",
"output": "2"
},
{
"input": "78",
"output": "5"
},
{
"input": "67",
"output": "10"
},
{
"input": "89",
"output": "2"
},
{
"input": "46",
"output": "6"
},
{
"input": "90",
"output": "4"
},
{
"input": "92",
"output": "4"
},
{
"input": "35",
"output": "12"
},
{
"input": "05",
"output": "8"
},
{
"input": "57",
"output": "20"
},
{
"input": "20",
"output": "4"
}
] | 62 | 0 | 0 | 5,561 |
|
195 | Let's Watch Football | [
"binary search",
"brute force",
"math"
] | null | null | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is *c* seconds and Valeric and Valerko wait *t* seconds before the watching. Then for any moment of time *t*0, *t*<=≤<=*t*0<=≤<=*c*<=+<=*t*, the following condition must fulfill: the size of data received in *t*0 seconds is not less than the size of data needed to watch *t*0<=-<=*t* seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses. | The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (*c*) denotes the video's length in seconds. | Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses. | [
"4 1 1\n",
"10 3 2\n",
"13 12 1\n"
] | [
"3\n",
"5\n",
"1\n"
] | In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.
In the second sample guys need 2 · 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary. | [
{
"input": "4 1 1",
"output": "3"
},
{
"input": "10 3 2",
"output": "5"
},
{
"input": "13 12 1",
"output": "1"
},
{
"input": "2 1 3",
"output": "3"
},
{
"input": "6 2 4",
"output": "8"
},
{
"input": "5 2 1",
"output": "2"
},
{
"input": "2 1 1",
"output": "1"
},
{
"input": "2 1 4",
"output": "4"
},
{
"input": "5 1 5",
"output": "20"
},
{
"input": "2 1 2",
"output": "2"
},
{
"input": "60 16 1",
"output": "3"
},
{
"input": "64 12 8",
"output": "35"
},
{
"input": "66 38 4",
"output": "3"
},
{
"input": "70 32 1",
"output": "2"
},
{
"input": "24 12 12",
"output": "12"
},
{
"input": "24 19 9",
"output": "3"
},
{
"input": "244 87 4",
"output": "8"
},
{
"input": "305 203 421",
"output": "212"
},
{
"input": "888 777 1",
"output": "1"
},
{
"input": "888 777 1000",
"output": "143"
},
{
"input": "888 777 888",
"output": "127"
},
{
"input": "5 4 10",
"output": "3"
},
{
"input": "1000 1 1",
"output": "999"
},
{
"input": "1000 1 1000",
"output": "999000"
},
{
"input": "1000 999 1",
"output": "1"
},
{
"input": "1000 999 1000",
"output": "2"
},
{
"input": "945 812 917",
"output": "151"
},
{
"input": "993 992 991",
"output": "1"
},
{
"input": "17 7 10",
"output": "15"
},
{
"input": "17 10 7",
"output": "5"
},
{
"input": "500 300 300",
"output": "200"
},
{
"input": "196 169 144",
"output": "24"
},
{
"input": "7 3 200",
"output": "267"
},
{
"input": "9 3 300",
"output": "600"
},
{
"input": "561 31 917",
"output": "15678"
},
{
"input": "100 10 1",
"output": "9"
},
{
"input": "1000 100 10",
"output": "90"
},
{
"input": "18 14 10",
"output": "3"
},
{
"input": "93 74 831",
"output": "214"
},
{
"input": "960 935 994",
"output": "27"
},
{
"input": "894 1 999",
"output": "892107"
},
{
"input": "767 2 514",
"output": "196605"
},
{
"input": "765 123 45",
"output": "235"
},
{
"input": "1000 1 1000",
"output": "999000"
},
{
"input": "765 123 899",
"output": "4693"
},
{
"input": "759 10 258",
"output": "19325"
},
{
"input": "100 1 10",
"output": "990"
},
{
"input": "99 8 99",
"output": "1127"
},
{
"input": "27 26 1",
"output": "1"
}
] | 218 | 0 | 3 | 5,566 |
|
525 | Ilya and Sticks | [
"greedy",
"math",
"sortings"
] | null | null | In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maximizes their total area. Each stick is used in making at most one rectangle, it is possible that some of sticks remain unused. Bending sticks is not allowed.
Sticks with lengths *a*1, *a*2, *a*3 and *a*4 can make a rectangle if the following properties are observed:
- *a*1<=≤<=*a*2<=≤<=*a*3<=≤<=*a*4 - *a*1<==<=*a*2 - *a*3<==<=*a*4
A rectangle can be made of sticks with lengths of, for example, 3 3 3 3 or 2 2 4 4. A rectangle cannot be made of, for example, sticks 5 5 5 7.
Ilya also has an instrument which can reduce the length of the sticks. The sticks are made of a special material, so the length of each stick can be reduced by at most one. For example, a stick with length 5 can either stay at this length or be transformed into a stick of length 4.
You have to answer the question — what maximum total area of the rectangles can Ilya get with a file if makes rectangles from the available sticks? | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks.
The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks. | The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks. | [
"4\n2 4 4 2\n",
"4\n2 2 3 5\n",
"4\n100003 100004 100005 100006\n"
] | [
"8\n",
"0\n",
"10000800015\n"
] | none | [
{
"input": "4\n2 4 4 2",
"output": "8"
},
{
"input": "4\n2 2 3 5",
"output": "0"
},
{
"input": "4\n100003 100004 100005 100006",
"output": "10000800015"
},
{
"input": "8\n5 3 3 3 3 4 4 4",
"output": "25"
},
{
"input": "10\n123 124 123 124 2 2 2 2 9 9",
"output": "15270"
},
{
"input": "8\n10 10 10 10 11 10 11 10",
"output": "210"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "10\n10519 10519 10520 10520 10520 10521 10521 10521 10522 10523",
"output": "221372362"
},
{
"input": "100\n4116 4116 4117 4117 4117 4117 4118 4119 4119 4119 4119 4120 4120 4120 4120 4121 4122 4123 4123 4123 4123 4124 4124 4124 4124 4125 4126 4126 4126 4126 4127 4127 4127 4127 4128 4128 4128 4128 4129 4129 4130 4130 4131 4132 4133 4133 4134 4134 4135 4135 4136 4137 4137 4137 4138 4139 4140 4140 4141 4141 4142 4143 4143 4143 4144 4144 4144 4144 4145 4145 4145 4146 4146 4146 4147 4147 4147 4147 4148 4148 4148 4149 4149 4149 4150 4151 4151 4151 4152 4152 4153 4153 4154 4154 4155 4155 4155 4155 4156 4156",
"output": "427591742"
},
{
"input": "10\n402840 873316 567766 493234 711262 291654 683001 496971 64909 190173",
"output": "0"
},
{
"input": "45\n1800 4967 1094 551 871 3505 846 960 4868 4304 2112 496 2293 2128 2430 2119 4497 2159 774 4520 3535 1013 452 1458 1895 1191 958 1133 416 2613 4172 3926 1665 4237 539 101 2448 1212 2631 4530 3026 412 1006 2515 1922",
"output": "0"
},
{
"input": "69\n2367 2018 3511 1047 1789 2332 1082 4678 2036 4108 2357 339 536 2272 3638 2588 754 3795 375 506 3243 1033 4531 1216 4266 2547 3540 4642 1256 2248 4705 14 629 876 2304 1673 4186 2356 3172 2664 3896 552 4293 1507 3307 2661 3143 4565 58 1298 4380 2738 917 2054 2676 4464 1314 3752 3378 1823 4219 3142 4258 1833 886 4286 4040 1070 2206",
"output": "7402552"
},
{
"input": "93\n13 2633 3005 1516 2681 3262 1318 1935 665 2450 2601 1644 214 929 4873 955 1983 3945 3488 2927 1516 1026 2150 974 150 2442 2610 1664 636 3369 266 2536 3132 2515 2582 1169 4462 4961 200 2848 4793 2795 4657 474 2640 2488 378 544 1805 1390 1548 2683 1474 4027 1724 2078 183 3717 1727 1780 552 2905 4260 1444 2906 3779 400 1491 1467 4480 3680 2539 4681 2875 4021 2711 106 853 3094 4531 4066 372 2129 2577 3996 2350 943 4478 3058 3333 4592 232 2780",
"output": "4403980"
},
{
"input": "21\n580 3221 3987 2012 35 629 1554 654 756 2254 4307 2948 3457 4612 4620 4320 1777 556 3088 348 1250",
"output": "0"
},
{
"input": "45\n4685 272 3481 3942 952 3020 329 4371 2923 2057 4526 2791 1674 3269 829 2713 3006 2166 1228 2795 983 1065 3875 4028 3429 3720 697 734 4393 1176 2820 1173 4598 2281 2549 4341 1504 172 4230 1193 3022 3742 1232 3433 1871",
"output": "0"
},
{
"input": "69\n3766 2348 4437 4438 3305 386 2026 1629 1552 400 4770 4069 4916 1926 2037 1079 2801 854 803 216 2152 4622 1494 3786 775 3615 4766 2781 235 836 1892 2234 3563 1843 4314 3836 320 2776 4796 1378 380 2421 3057 964 4717 1122 620 530 3455 1639 1618 3109 3120 564 2382 1995 1173 4510 286 1088 218 734 2779 3738 456 1668 4476 2780 3555",
"output": "12334860"
},
{
"input": "4\n2 2 2 4",
"output": "0"
},
{
"input": "8\n10 10 10 11 14 14 14 16",
"output": "140"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "3\n2 3 5",
"output": "0"
},
{
"input": "8\n2 1000000 2 1000000 2 1000000 2 1000000",
"output": "1000000000004"
},
{
"input": "4\n2 4 6 8",
"output": "0"
},
{
"input": "4\n2 3 6 8",
"output": "0"
},
{
"input": "5\n2 2 3 4 5",
"output": "8"
},
{
"input": "5\n1000000 999999 999999 999999 999999",
"output": "999998000001"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "4"
},
{
"input": "4\n2 4 5 5",
"output": "0"
},
{
"input": "20\n4 4 8 4 5 6 7 4 5 4 6 4 4 5 7 6 5 8 8 4",
"output": "149"
},
{
"input": "10\n8 4 6 6 8 5 7 7 6 8",
"output": "92"
},
{
"input": "11\n4 4 9 9 3 8 8 8 6 4 3",
"output": "84"
},
{
"input": "8\n2 3 3 4 4 5 5 5",
"output": "26"
},
{
"input": "4\n3 3 3 2",
"output": "6"
},
{
"input": "5\n3 3 10 100 100",
"output": "300"
},
{
"input": "8\n9 9 9 8 8 7 7 6",
"output": "114"
},
{
"input": "4\n5 6 6 7",
"output": "30"
},
{
"input": "5\n9 9 5 2 2",
"output": "18"
},
{
"input": "6\n3 4 100 200 1001 1002",
"output": "3003"
},
{
"input": "6\n3 4 5 100 101 102",
"output": "404"
},
{
"input": "5\n2 2 4 6 6",
"output": "12"
},
{
"input": "6\n2 3 8 10 13 14",
"output": "26"
},
{
"input": "7\n2 2 2 2 2 2 2",
"output": "4"
},
{
"input": "5\n5 2 2 2 2",
"output": "4"
},
{
"input": "6\n3 4 100 200 1000 1001",
"output": "3000"
},
{
"input": "5\n5 5 7 9 9",
"output": "45"
},
{
"input": "5\n8 8 7 4 4",
"output": "32"
},
{
"input": "5\n2 2 5 8 9",
"output": "16"
},
{
"input": "5\n4 4 4 2 2",
"output": "8"
},
{
"input": "5\n3 10 100 1000 10000",
"output": "0"
},
{
"input": "6\n10 10 7 4 2 2",
"output": "20"
},
{
"input": "6\n5 5 7 9 10 10",
"output": "50"
},
{
"input": "7\n10 10 7 5 3 2 2",
"output": "20"
},
{
"input": "7\n10 9 9 9 9 2 2",
"output": "81"
}
] | 2,000 | 7,680,000 | 0 | 5,569 |
|
644 | Parliament of Berland | [
"*special",
"constructive algorithms"
] | null | null | There are *n* parliamentarians in Berland. They are numbered with integers from 1 to *n*. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall is a rectangle consisting of *a*<=×<=*b* chairs — *a* rows of *b* chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hall
We know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.
Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats. | The first line of the input contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=10<=000, 1<=≤<=*a*,<=*b*<=≤<=100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively. | If there is no way to assigns seats to parliamentarians in a proper way print -1.
Otherwise print the solution in *a* lines, each containing *b* integers. The *j*-th integer of the *i*-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them. | [
"3 2 2\n",
"8 4 3\n",
"10 2 2\n"
] | [
"0 3\n1 2\n",
"7 8 3\n0 1 4\n6 0 5\n0 2 0\n",
"-1\n"
] | In the first sample there are many other possible solutions. For example,
and
The following assignment
is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats. | [
{
"input": "3 2 2",
"output": "1 2 \n0 3 "
},
{
"input": "8 4 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 "
},
{
"input": "10 2 2",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "8 3 3",
"output": "1 2 3 \n4 5 6 \n7 8 0 "
},
{
"input": "1 1 100",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "
},
{
"input": "1 100 1",
"output": "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 \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 \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 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 \n0 "
},
{
"input": "12 4 3",
"output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 "
},
{
"input": "64 8 9",
"output": "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 0 0 0 0 0 0 0 0 "
},
{
"input": "13 2 6",
"output": "-1"
},
{
"input": "41 6 7",
"output": "1 2 3 4 5 6 7 \n8 9 10 11 12 13 14 \n15 16 17 18 19 20 21 \n22 23 24 25 26 27 28 \n29 30 31 32 33 34 35 \n36 37 38 39 40 41 0 "
},
{
"input": "9999 100 100",
"output": "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 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "10000 100 100",
"output": "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 \n102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "2099 70 30",
"output": "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 \n32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 \n61 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 \n92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 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 \n152 151 1..."
},
{
"input": "2098 30 70",
"output": "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 \n72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 \n141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "10000 1 1",
"output": "-1"
},
{
"input": "1583 49 36",
"output": "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 \n38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 \n73 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 \n110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153..."
},
{
"input": "4825 77 88",
"output": "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 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "26 1 33",
"output": "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 0 0 0 0 0 0 0 "
},
{
"input": "274 25 77",
"output": "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 \n78 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 \n..."
},
{
"input": "694 49 22",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152..."
},
{
"input": "3585 77 62",
"output": "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 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 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..."
},
{
"input": "3 1 6",
"output": "1 2 3 0 0 0 "
},
{
"input": "352 25 59",
"output": "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 \n60 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 \n119 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..."
},
{
"input": "150 53 3",
"output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 110 111 \n112 113 114 \n115 116 117 \n118 119 120 \n121 122 123 \n124 125 126 \n127 128 129 \n130 131 132 \n133..."
},
{
"input": "4227 91 80",
"output": "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 \n82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "378 19 25",
"output": "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 \n26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \n51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 \n76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 \n101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 \n126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 \n151 152..."
},
{
"input": "2357 43 65",
"output": "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 \n66 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 \n131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "232 71 9",
"output": "1 2 3 4 5 6 7 8 9 \n10 11 12 13 14 15 16 17 18 \n19 20 21 22 23 24 25 26 27 \n28 29 30 31 32 33 34 35 36 \n37 38 39 40 41 42 43 44 45 \n46 47 48 49 50 51 52 53 54 \n55 56 57 58 59 60 61 62 63 \n64 65 66 67 68 69 70 71 72 \n73 74 75 76 77 78 79 80 81 \n82 83 84 85 86 87 88 89 90 \n91 92 93 94 95 96 97 98 99 \n100 101 102 103 104 105 106 107 108 \n109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 \n127 128 129 130 131 132 133 134 135 \n136 137 138 139 140 141 142 143 144 \n145 146 147..."
},
{
"input": "2362 91 62",
"output": "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 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 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..."
},
{
"input": "4601 59 78",
"output": "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 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "4439 74 60",
"output": "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 \n62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 \n121 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..."
},
{
"input": "3733 89 42",
"output": "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 \n44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 \n85 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 \n128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 1..."
},
{
"input": "335 12 28",
"output": "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 \n30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 \n57 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 \n86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 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 \n142 141 144 143 146 145 148 147 150 149 152 151 1..."
},
{
"input": "440 26 17",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 \n18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 \n35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \n52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 \n69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 \n86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 \n103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 \n120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151..."
},
{
"input": "109 37 3",
"output": "1 2 3 \n4 5 6 \n7 8 9 \n10 11 12 \n13 14 15 \n16 17 18 \n19 20 21 \n22 23 24 \n25 26 27 \n28 29 30 \n31 32 33 \n34 35 36 \n37 38 39 \n40 41 42 \n43 44 45 \n46 47 48 \n49 50 51 \n52 53 54 \n55 56 57 \n58 59 60 \n61 62 63 \n64 65 66 \n67 68 69 \n70 71 72 \n73 74 75 \n76 77 78 \n79 80 81 \n82 83 84 \n85 86 87 \n88 89 90 \n91 92 93 \n94 95 96 \n97 98 99 \n100 101 102 \n103 104 105 \n106 107 108 \n109 0 0 "
},
{
"input": "4416 52 85",
"output": "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 \n86 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 1..."
},
{
"input": "5025 75 67",
"output": "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 \n68 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 \n135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "4983 89 56",
"output": "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 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 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..."
},
{
"input": "950 17 56",
"output": "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 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 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..."
},
{
"input": "1637 40 41",
"output": "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 \n42 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 \n83 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 \n124 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 1..."
},
{
"input": "1142 52 22",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 \n24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 \n45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 \n68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 \n89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 \n112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152..."
},
{
"input": "907 70 13",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 \n14 15 16 17 18 19 20 21 22 23 24 25 26 \n27 28 29 30 31 32 33 34 35 36 37 38 39 \n40 41 42 43 44 45 46 47 48 49 50 51 52 \n53 54 55 56 57 58 59 60 61 62 63 64 65 \n66 67 68 69 70 71 72 73 74 75 76 77 78 \n79 80 81 82 83 84 85 86 87 88 89 90 91 \n92 93 94 95 96 97 98 99 100 101 102 103 104 \n105 106 107 108 109 110 111 112 113 114 115 116 117 \n118 119 120 121 122 123 124 125 126 127 128 129 130 \n131 132 133 134 135 136 137 138 139 140 141 142 143 \n144 145 146 147 148 149 1..."
},
{
"input": "7279 80 91",
"output": "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 \n92 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 1..."
},
{
"input": "1653 87 19",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \n20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 \n39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 \n58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 \n77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 \n96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 \n115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 \n134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 1..."
},
{
"input": "15 2 8",
"output": "1 2 3 4 5 6 7 8 \n10 9 12 11 14 13 0 15 "
},
{
"input": "1459 17 86",
"output": "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 \n88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "3035 40 76",
"output": "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 \n78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 \n153 154..."
},
{
"input": "3095 50 62",
"output": "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 \n64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 \n125 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..."
},
{
"input": "3055 65 47",
"output": "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 \n48 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 \n95 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 \n142 143 144 145 146 147 148 149 150 151 152 153 1..."
},
{
"input": "2638 80 33",
"output": "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 \n34 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 \n67 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 \n100 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 \n133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153..."
},
{
"input": "29 3 11",
"output": "1 2 3 4 5 6 7 8 9 10 11 \n12 13 14 15 16 17 18 19 20 21 22 \n23 24 25 26 27 28 29 0 0 0 0 "
},
{
"input": "16 18 1",
"output": "1 \n2 \n3 \n4 \n5 \n6 \n7 \n8 \n9 \n10 \n11 \n12 \n13 \n14 \n15 \n16 \n0 \n0 "
},
{
"input": "2240 27 83",
"output": "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 \n84 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 1..."
},
{
"input": "1264 55 23",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 \n24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 \n47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 \n70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 \n93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 \n116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 \n139 140 141 142 143 144 145 146 147 148 149 150 151 152..."
},
{
"input": "5400 75 72",
"output": "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 \n74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 \n145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "46 3 16",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 \n33 34 35 36 37 38 39 40 41 42 43 44 45 46 0 0 "
},
{
"input": "1512 27 56",
"output": "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 \n58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 \n113 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..."
},
{
"input": "4206 86 12",
"output": "-1"
},
{
"input": "2358 14 56",
"output": "-1"
},
{
"input": "5420 35 96",
"output": "-1"
},
{
"input": "7758 63 41",
"output": "-1"
},
{
"input": "9806 87 93",
"output": "-1"
},
{
"input": "99 1 97",
"output": "-1"
},
{
"input": "1053 25 42",
"output": "-1"
},
{
"input": "4217 49 86",
"output": "-1"
},
{
"input": "2312 77 30",
"output": "-1"
},
{
"input": "74 1 71",
"output": "-1"
},
{
"input": "1 99 100",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "1 57 99",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..."
},
{
"input": "4785 55 87",
"output": "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 \n88 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 1..."
},
{
"input": "4611 53 87",
"output": "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 \n88 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 1..."
},
{
"input": "9801 99 99",
"output": "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 \n100 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 1..."
},
{
"input": "8096 92 88",
"output": "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 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "5916 68 87",
"output": "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 \n88 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 1..."
},
{
"input": "8928 93 96",
"output": "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 \n98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "7743 89 87",
"output": "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 \n88 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 1..."
},
{
"input": "3128 46 68",
"output": "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 \n70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 \n137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154..."
},
{
"input": "3800 40 95",
"output": "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 \n96 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 1..."
},
{
"input": "5368 61 88",
"output": "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 \n90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "2583 41 63",
"output": "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 \n64 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 \n127 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..."
},
{
"input": "4056 52 78",
"output": "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 \n80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "3822 42 91",
"output": "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 \n92 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 1..."
},
{
"input": "5358 57 94",
"output": "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 \n96 95 98 97 100 99 102 101 104 103 106 105 108 107 110 109 112 111 114 113 116 115 118 117 120 119 122 121 124 123 126 125 128 127 130 129 132 131 134 133 136 135 138 137 140 139 142 141 144 143 146 145 148 147 150 149 152 151 154 153 1..."
},
{
"input": "2961 47 63",
"output": "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 \n64 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 \n127 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..."
}
] | 124 | 2,867,200 | 3 | 5,581 |
|
1,006 | Xor-Paths | [
"bitmasks",
"brute force",
"dp",
"meet-in-the-middle"
] | null | null | There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints:
- You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. - The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal).
Find the number of such paths in the given grid. | The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) — the height and the width of the grid, and the number $k$.
The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$). | Print one integer — the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$. | [
"3 3 11\n2 1 5\n7 10 0\n12 6 4\n",
"3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1\n",
"3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1\n"
] | [
"3\n",
"5\n",
"0\n"
] | All the paths from the first example:
- $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; - $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$.
All the paths from the second example:
- $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; - $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; - $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; - $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; - $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$. | [
{
"input": "3 3 11\n2 1 5\n7 10 0\n12 6 4",
"output": "3"
},
{
"input": "3 4 2\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "5"
},
{
"input": "3 4 1000000000000000000\n1 3 3 3\n0 3 3 2\n3 0 1 1",
"output": "0"
},
{
"input": "1 1 1000000000000000000\n1000000000000000000",
"output": "1"
},
{
"input": "1 1 1000000000000000000\n999999999999999999",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "1"
},
{
"input": "1 2 3\n1 2",
"output": "1"
},
{
"input": "1 10 1023\n1 2 4 8 16 32 64 128 256 512",
"output": "1"
},
{
"input": "1 20 1048575\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288",
"output": "1"
},
{
"input": "2 1 3\n1\n2",
"output": "1"
},
{
"input": "2 2 7\n1 2\n2 4",
"output": "2"
},
{
"input": "2 10 2047\n1 2 4 8 16 32 64 128 256 512\n2 4 8 16 32 64 128 256 512 1024",
"output": "10"
},
{
"input": "2 20 2097151\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288\n2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576",
"output": "20"
},
{
"input": "10 1 1023\n1\n2\n4\n8\n16\n32\n64\n128\n256\n512",
"output": "1"
},
{
"input": "10 2 2047\n1 2\n2 4\n4 8\n8 16\n16 32\n32 64\n64 128\n128 256\n256 512\n512 1024",
"output": "10"
},
{
"input": "10 10 524287\n1 2 4 8 16 32 64 128 256 512\n2 4 8 16 32 64 128 256 512 1024\n4 8 16 32 64 128 256 512 1024 2048\n8 16 32 64 128 256 512 1024 2048 4096\n16 32 64 128 256 512 1024 2048 4096 8192\n32 64 128 256 512 1024 2048 4096 8192 16384\n64 128 256 512 1024 2048 4096 8192 16384 32768\n128 256 512 1024 2048 4096 8192 16384 32768 65536\n256 512 1024 2048 4096 8192 16384 32768 65536 131072\n512 1024 2048 4096 8192 16384 32768 65536 131072 262144",
"output": "48620"
},
{
"input": "20 1 1048575\n1\n2\n4\n8\n16\n32\n64\n128\n256\n512\n1024\n2048\n4096\n8192\n16384\n32768\n65536\n131072\n262144\n524288",
"output": "1"
},
{
"input": "20 2 2097151\n1 2\n2 4\n4 8\n8 16\n16 32\n32 64\n64 128\n128 256\n256 512\n512 1024\n1024 2048\n2048 4096\n4096 8192\n8192 16384\n16384 32768\n32768 65536\n65536 131072\n131072 262144\n262144 524288\n524288 1048576",
"output": "20"
},
{
"input": "1 1 982347923479\n1",
"output": "0"
},
{
"input": "1 2 1\n1 1",
"output": "0"
}
] | 233 | 34,918,400 | 0 | 5,586 |
|
630 | Divisibility | [
"math",
"number theory"
] | null | null | IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus.
A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that *n* people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. | The only line of the input contains one integer *n* (1<=≤<=*n*<=≤<=1018) — the prediction on the number of people who will buy the game. | Output one integer showing how many numbers from 1 to *n* are divisible by all numbers from 2 to 10. | [
"3000\n"
] | [
"1"
] | none | [
{
"input": "3000",
"output": "1"
},
{
"input": "2520",
"output": "1"
},
{
"input": "2519",
"output": "0"
},
{
"input": "2521",
"output": "1"
},
{
"input": "1",
"output": "0"
},
{
"input": "314159265",
"output": "124666"
},
{
"input": "718281828459045235",
"output": "285032471610732"
},
{
"input": "1000000000000000000",
"output": "396825396825396"
},
{
"input": "987654321234567890",
"output": "391926317950225"
},
{
"input": "3628800",
"output": "1440"
},
{
"input": "504000000000000000",
"output": "200000000000000"
}
] | 500 | 1,331,200 | 0 | 5,593 |
|
444 | DZY Loves Colors | [
"data structures"
] | null | null | DZY loves colors, and he enjoys painting.
On a colorful day, DZY gets a colorful ribbon, which consists of *n* units (they are numbered from 1 to *n* from left to right). The color of the *i*-th unit of the ribbon is *i* at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first.
DZY loves painting, we know. He takes up a paintbrush with color *x* and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit *i* currently is *y*. When it is painted by this paintbrush, the color of the unit becomes *x*, and the colorfulness of the unit increases by |*x*<=-<=*y*|.
DZY wants to perform *m* operations, each operation can be one of the following:
1. Paint all the units with numbers between *l* and *r* (both inclusive) with color *x*. 1. Ask the sum of colorfulness of the units between *l* and *r* (both inclusive).
Can you help DZY? | The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105).
Each of the next *m* lines begins with a integer *type* (1<=≤<=*type*<=≤<=2), which represents the type of this operation.
If *type*<==<=1, there will be 3 more integers *l*,<=*r*,<=*x* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*x*<=≤<=108) in this line, describing an operation 1.
If *type*<==<=2, there will be 2 more integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) in this line, describing an operation 2. | For each operation 2, print a line containing the answer — sum of colorfulness. | [
"3 3\n1 1 2 4\n1 2 3 5\n2 1 3\n",
"3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3\n",
"10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10\n"
] | [
"8\n",
"3\n2\n1\n",
"129\n"
] | In the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0].
After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0].
After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2].
So the answer to the only operation of type 2 is 8. | [
{
"input": "3 3\n1 1 2 4\n1 2 3 5\n2 1 3",
"output": "8"
},
{
"input": "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3",
"output": "3\n2\n1"
},
{
"input": "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10",
"output": "129"
},
{
"input": "3 3\n1 2 2 31844623\n1 1 2 37662529\n2 2 3",
"output": "37662527"
},
{
"input": "3 3\n2 2 3\n1 1 3 72971211\n2 2 3",
"output": "0\n145942417"
},
{
"input": "10 10\n1 5 9 60144710\n2 3 3\n2 3 4\n2 6 10\n1 8 9 11764737\n1 1 9 38454635\n1 3 10 58013969\n1 2 3 49601991\n1 1 3 73003418\n2 4 6",
"output": "0\n0\n240578810\n260802192"
}
] | 46 | 0 | 0 | 5,617 |
|
0 | none | [
"none"
] | null | null | A positive integer is called a 2-3-integer, if it is equal to 2*x*·3*y* for some non-negative integers *x* and *y*. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 120 are not.
Print the number of 2-3-integers on the given segment [*l*,<=*r*], i. e. the number of sich 2-3-integers *t* that *l*<=≤<=*t*<=≤<=*r*. | The only line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=2·109). | Print a single integer the number of 2-3-integers on the segment [*l*,<=*r*]. | [
"1 10\n",
"100 200\n",
"1 2000000000\n"
] | [
"7\n",
"5\n",
"326\n"
] | In the first example the 2-3-integers are 1, 2, 3, 4, 6, 8 and 9.
In the second example the 2-3-integers are 108, 128, 144, 162 and 192. | [
{
"input": "1 10",
"output": "7"
},
{
"input": "100 200",
"output": "5"
},
{
"input": "1 2000000000",
"output": "326"
},
{
"input": "1088391168 1934917632",
"output": "17"
},
{
"input": "1088391167 1934917632",
"output": "17"
},
{
"input": "1088391169 1934917632",
"output": "16"
},
{
"input": "1088391168 1934917631",
"output": "16"
},
{
"input": "1088391168 1934917633",
"output": "17"
},
{
"input": "4 134217728",
"output": "250"
},
{
"input": "209952 43046722",
"output": "112"
},
{
"input": "25165825 43046719",
"output": "13"
},
{
"input": "5183 25165825",
"output": "153"
},
{
"input": "388645 455910",
"output": "3"
},
{
"input": "472069 972050",
"output": "14"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "12 1999999931",
"output": "319"
},
{
"input": "1999999999 1999999999",
"output": "0"
},
{
"input": "2000000000 2000000000",
"output": "0"
},
{
"input": "1934917632 1934917632",
"output": "1"
},
{
"input": "1836660096 1836660096",
"output": "1"
},
{
"input": "1811939328 1811939328",
"output": "1"
},
{
"input": "1719926784 1719926784",
"output": "1"
},
{
"input": "1632586752 1632586752",
"output": "1"
},
{
"input": "1610612736 1610612736",
"output": "1"
},
{
"input": "1207959552 1207959552",
"output": "1"
},
{
"input": "129140163 129140163",
"output": "1"
},
{
"input": "12345 54321",
"output": "21"
},
{
"input": "1889569 25165826",
"output": "56"
},
{
"input": "73 7077888",
"output": "165"
},
{
"input": "7077888 45349631",
"output": "43"
},
{
"input": "6144 7077886",
"output": "122"
},
{
"input": "3779135 4194302",
"output": "2"
},
{
"input": "214 161243134",
"output": "232"
},
{
"input": "214 18874369",
"output": "180"
},
{
"input": "28 863",
"output": "26"
},
{
"input": "1417174 172186886",
"output": "112"
},
{
"input": "27 102036671",
"output": "234"
},
{
"input": "147458 102036672",
"output": "138"
},
{
"input": "33554431 102036671",
"output": "28"
},
{
"input": "1572863 33554433",
"output": "68"
},
{
"input": "33554434 181398528",
"output": "43"
},
{
"input": "373247 17915905",
"output": "81"
},
{
"input": "4251526 68024450",
"output": "65"
},
{
"input": "553599 555493",
"output": "0"
},
{
"input": "69739 671621",
"output": "40"
},
{
"input": "618583 755045",
"output": "4"
},
{
"input": "838469 943236",
"output": "2"
},
{
"input": "509607936 1836660096",
"output": "38"
},
{
"input": "509607935 1836660096",
"output": "38"
},
{
"input": "509607937 1836660096",
"output": "37"
},
{
"input": "509607936 1836660095",
"output": "37"
},
{
"input": "509607936 1836660097",
"output": "38"
}
] | 124 | 307,200 | 3 | 5,639 |
|
0 | none | [
"none"
] | null | null | 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. | [
"5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n",
"5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n"
] | [
"2\n1 3 ",
"4\n1 2 4 5 "
] | In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.
In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5, - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last. | [
{
"input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2",
"output": "2\n1 3 "
},
{
"input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9",
"output": "4\n1 2 4 5 "
},
{
"input": "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",
"output": "3\n1 2 5 "
},
{
"input": "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",
"output": "6\n1 2 3 4 5 7 "
},
{
"input": "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",
"output": "8\n1 2 3 4 5 7 8 10 "
},
{
"input": "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",
"output": "5\n1 2 3 5 8 "
},
{
"input": "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",
"output": "5\n1 2 5 6 8 "
},
{
"input": "4\n2 10 1\n1 2 2\n2 1 1\n5 5 1",
"output": "3\n1 2 4 "
},
{
"input": "1\n1 1 1",
"output": "1\n1 "
},
{
"input": "2\n5 1 1\n1 1 5",
"output": "2\n1 2 "
},
{
"input": "2\n5 1 1\n1 1 4",
"output": "1\n1 "
},
{
"input": "2\n5 1 1\n1 1 6",
"output": "2\n1 2 "
},
{
"input": "3\n5 1 1\n1 1 4\n1 1 4",
"output": "1\n1 "
},
{
"input": "3\n5 1 1\n1 1 4\n1 1 5",
"output": "2\n1 3 "
},
{
"input": "3\n5 1 1\n1 1 5\n1 1 3",
"output": "2\n1 2 "
},
{
"input": "3\n5 1 1\n10 1 5\n1000 1000 14",
"output": "3\n1 2 3 "
},
{
"input": "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",
"output": "10\n1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "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",
"output": "1\n1 "
}
] | 61 | 0 | 0 | 5,652 |
|
264 | Good Sequences | [
"dp",
"number theory"
] | null | null | Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions:
- The sequence is strictly increasing, i.e. *x**i*<=<<=*x**i*<=+<=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1). - No two adjacent elements are coprime, i.e. *gcd*(*x**i*,<=*x**i*<=+<=1)<=><=1 for each *i* (1<=≤<=*i*<=≤<=*k*<=-<=1) (where *gcd*(*p*,<=*q*) denotes the greatest common divisor of the integers *p* and *q*). - All elements of the sequence are good integers.
Find the length of the longest good sequence. | The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=<<=*a**i*<=+<=1). | Print a single integer — the length of the longest good sequence. | [
"5\n2 3 4 6 9\n",
"9\n1 2 3 5 6 7 8 9 10\n"
] | [
"4\n",
"4\n"
] | In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4. | [
{
"input": "5\n2 3 4 6 9",
"output": "4"
},
{
"input": "9\n1 2 3 5 6 7 8 9 10",
"output": "4"
},
{
"input": "4\n1 2 4 6",
"output": "3"
},
{
"input": "7\n1 2 3 4 7 9 10",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "8\n3 4 5 6 7 8 9 10",
"output": "4"
},
{
"input": "5\n2 3 7 9 10",
"output": "2"
},
{
"input": "3\n1 4 7",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "9\n1 2 3 4 5 6 7 9 10",
"output": "4"
},
{
"input": "49\n10 34 58 72 126 166 176 180 198 200 208 228 238 248 302 332 340 344 350 354 380 406 418 428 438 442 482 532 536 544 546 554 596 626 642 682 684 704 714 792 804 820 862 880 906 946 954 966 970",
"output": "49"
},
{
"input": "44\n1 5 37 97 107 147 185 187 195 241 249 295 311 323 341 345 363 391 425 431 473 525 539 541 555 577 595 611 647 695 757 759 775 779 869 877 927 935 963 965 967 969 973 975",
"output": "15"
},
{
"input": "3\n21 67 243",
"output": "2"
},
{
"input": "3\n150 358 382",
"output": "3"
},
{
"input": "10\n13 2187 2197 4567 5200 29873 67866 98798 99999 100000",
"output": "6"
},
{
"input": "10\n1 2 4 8 16 32 33 64 128 256",
"output": "8"
},
{
"input": "10\n2 4 8 67 128 324 789 1296 39877 98383",
"output": "7"
},
{
"input": "10\n2 3 4 5 6 8 9 10 17 92",
"output": "6"
},
{
"input": "10\n2 3 10 40 478 3877 28787 88888 99999 100000",
"output": "6"
},
{
"input": "10\n2 3 45 67 89 101 234 567 890 1234",
"output": "5"
},
{
"input": "10\n2 3 4 5 6 7 8 9 10 11",
"output": "5"
},
{
"input": "2\n5101 10202",
"output": "2"
},
{
"input": "1\n99991",
"output": "1"
},
{
"input": "2\n1009 2018",
"output": "2"
},
{
"input": "2\n601 1202",
"output": "2"
},
{
"input": "3\n3 14 22",
"output": "2"
}
] | 684 | 31,027,200 | 3 | 5,660 |
|
514 | Han Solo and Lazer Gun | [
"brute force",
"data structures",
"geometry",
"implementation",
"math"
] | null | null | There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot it can can destroy all the stormtroopers, situated on some line that crosses point (*x*0,<=*y*0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location. | The first line contains three integers *n*, *x*0 и *y*0 (1<=≤<=*n*<=≤<=1000, <=-<=104<=≤<=*x*0,<=*y*0<=≤<=104) — the number of stormtroopers on the battle field and the coordinates of your gun.
Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=≤<=*x**i*,<=*y**i*<=≤<=104) — the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point. | Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers. | [
"4 0 0\n1 1\n2 2\n2 0\n-1 -1\n",
"2 1 2\n1 1\n1 0\n"
] | [
"2\n",
"1\n"
] | Explanation to the first and second samples from the statement, respectively: | [
{
"input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1",
"output": "2"
},
{
"input": "2 1 2\n1 1\n1 0",
"output": "1"
},
{
"input": "1 1 1\n0 0",
"output": "1"
},
{
"input": "2 0 0\n10000 -10000\n-10000 10000",
"output": "1"
},
{
"input": "2 0 0\n10000 -10000\n10000 10000",
"output": "2"
},
{
"input": "10 -4 -4\n2 -4\n2 0\n-4 2\n5 -4\n-3 -5\n1 4\n-4 2\n-3 5\n0 -3\n2 4",
"output": "8"
},
{
"input": "10 5 -3\n1 1\n2 -1\n2 2\n1 -2\n4 -5\n1 4\n0 1\n1 -4\n-2 0\n-4 -5",
"output": "10"
},
{
"input": "10 -3 3\n3 -5\n4 3\n0 -2\n0 0\n3 -3\n3 5\n4 1\n5 5\n4 -5\n4 -4",
"output": "8"
},
{
"input": "2 -10000 -10000\n10000 10000\n10000 9999",
"output": "2"
},
{
"input": "2 -10000 -10000\n9998 9999\n9999 10000",
"output": "2"
},
{
"input": "2 0 0\n0 1337\n3 9000",
"output": "2"
},
{
"input": "2 0 -1\n0 1\n1 10000",
"output": "2"
},
{
"input": "2 0 0\n0 10\n1 2000",
"output": "2"
},
{
"input": "2 0 0\n0 2\n1 90",
"output": "2"
},
{
"input": "2 0 0\n1001 0\n1001 1",
"output": "2"
}
] | 46 | 102,400 | 3 | 5,677 |
|
288 | Polo the Penguin and Strings | [
"greedy"
] | null | null | Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbouring letters of a string coincide; that is, if we represent a string as *s*<==<=*s*1*s*2... *s**n*, then the following inequality holds, *s**i*<=≠<=*s**i*<=+<=1(1<=≤<=*i*<=<<=*n*). 1. Among all strings that meet points 1 and 2, the required string is lexicographically smallest.
Help him find such string or state that such string doesn't exist.
String *x*<==<=*x*1*x*2... *x**p* is lexicographically less than string *y*<==<=*y*1*y*2... *y**q*, if either *p*<=<<=*q* and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**p*<==<=*y**p*, or there is such number *r* (*r*<=<<=*p*,<=*r*<=<<=*q*), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=<<=*y**r*<=+<=1. The characters of the strings are compared by their ASCII codes. | A single line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=26) — the string's length and the number of distinct letters. | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | [
"7 4\n",
"4 7\n"
] | [
"ababacd\n",
"-1\n"
] | none | [
{
"input": "7 4",
"output": "ababacd"
},
{
"input": "4 7",
"output": "-1"
},
{
"input": "10 5",
"output": "abababacde"
},
{
"input": "47 2",
"output": "abababababababababababababababababababababababa"
},
{
"input": "10 7",
"output": "ababacdefg"
},
{
"input": "20 7",
"output": "abababababababacdefg"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "47 1",
"output": "-1"
},
{
"input": "128 26",
"output": "ababababababababababababababababababababababababababababababababababababababababababababababababababababcdefghijklmnopqrstuvwxyz"
},
{
"input": "999 7",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "4585 1",
"output": "-1"
},
{
"input": "6875 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "7642 3",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "100000 7",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "68754 25",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "1000000 1",
"output": "-1"
},
{
"input": "999999 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "1000000 26",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "100000 20",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "579466 17",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "679854 9",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "978458 16",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "6791 21",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababa..."
},
{
"input": "6795 1",
"output": "-1"
},
{
"input": "12 17",
"output": "-1"
},
{
"input": "1 1",
"output": "a"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "1 26",
"output": "-1"
},
{
"input": "26 2",
"output": "ababababababababababababab"
},
{
"input": "123 21",
"output": "ababababababababababababababababababababababababababababababababababababababababababababababababababababcdefghijklmnopqrstu"
},
{
"input": "3 3",
"output": "abc"
}
] | 218 | 2,048,000 | 0 | 5,680 |
|
830 | Cards Sorting | [
"data structures",
"implementation",
"sortings"
] | null | null | Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number on it equals the minimum number written on the cards in the deck, then he places the card away. Otherwise, he puts it under the deck and takes the next card from the top, and so on. The process ends as soon as there are no cards in the deck. You can assume that Vasily always knows the minimum number written on some card in the remaining deck, but doesn't know where this card (or these cards) is.
You are to determine the total number of times Vasily takes the top card from the deck. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cards in the deck.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), where *a**i* is the number written on the *i*-th from top card in the deck. | Print the total number of times Vasily takes the top card from the deck. | [
"4\n6 3 1 2\n",
"1\n1000\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"7\n",
"1\n",
"7\n"
] | In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards from top to bottom are [2, 6, 3]. Then Vasily looks at the top card with number 2 and puts it away. After that the cards from top to bottom are [6, 3]. Then Vasily looks at card 6, puts it under the deck, then at card 3 and puts it away. Then there is only one card with number 6 on it, and Vasily looks at it and puts it away. Thus, in total Vasily looks at 7 cards. | [
{
"input": "4\n6 3 1 2",
"output": "7"
},
{
"input": "1\n1000",
"output": "1"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "7"
},
{
"input": "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256 404 852 496 373 322 716 202 689 857 936 806 556 153 137 863 1047 678 564 474 282 135 610 176 855 360 814 144 77 112 354 154",
"output": "1042"
},
{
"input": "87\n12 2 2 10 12 1 5 9 15 2 4 7 7 14 8 10 1 6 7 6 13 15 10 6 2 11 13 1 15 14 8 8 4 7 11 12 3 15 9 2 13 1 7 11 2 1 13 11 8 14 2 2 12 7 13 4 13 3 13 3 11 1 7 13 15 8 12 4 12 4 1 4 9 3 13 12 10 15 14 10 7 7 7 2 7 6 10",
"output": "580"
},
{
"input": "10\n4 3 4 3 3 3 4 4 4 3",
"output": "15"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "20"
},
{
"input": "30\n6283 14661 69188 39640 41261 48019 86266 70517 4592 69008 20602 33339 29980 96844 76008 96294 27120 22671 5243 742 33692 18068 29056 48033 1223 82728 99765 38350 36425 10671",
"output": "235"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14",
"output": "1805"
}
] | 1,000 | 7,270,400 | 0 | 5,687 |
|
814 | An impassioned circulation of affection | [
"brute force",
"dp",
"strings",
"two pointers"
] | null | null | Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it!
Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has *n* pieces numbered from 1 to *n* from left to right, and the *i*-th piece has a colour *s**i*, denoted by a lowercase English letter. Nadeko will repaint at most *m* of the pieces to give each of them an arbitrary new colour (still denoted by a lowercase English letter). After this work, she finds out all subsegments of the garland containing pieces of only colour *c* — Brother Koyomi's favourite one, and takes the length of the longest among them to be the Koyomity of the garland.
For instance, let's say the garland is represented by "kooomo", and Brother Koyomi's favourite colour is "o". Among all subsegments containing pieces of "o" only, "ooo" is the longest, with a length of 3. Thus the Koyomity of this garland equals 3.
But problem arises as Nadeko is unsure about Brother Koyomi's favourite colour, and has swaying ideas on the amount of work to do. She has *q* plans on this, each of which can be expressed as a pair of an integer *m**i* and a lowercase letter *c**i*, meanings of which are explained above. You are to find out the maximum Koyomity achievable after repainting the garland according to each plan. | The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=500) — the length of the garland.
The second line contains *n* lowercase English letters *s*1*s*2... *s**n* as a string — the initial colours of paper pieces on the garland.
The third line contains a positive integer *q* (1<=≤<=*q*<=≤<=200<=000) — the number of plans Nadeko has.
The next *q* lines describe one plan each: the *i*-th among them contains an integer *m**i* (1<=≤<=*m**i*<=≤<=*n*) — the maximum amount of pieces to repaint, followed by a space, then by a lowercase English letter *c**i* — Koyomi's possible favourite colour. | Output *q* lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it. | [
"6\nkoyomi\n3\n1 o\n4 o\n4 m\n",
"15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n",
"10\naaaaaaaaaa\n2\n10 b\n10 z\n"
] | [
"3\n6\n5\n",
"3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n",
"10\n10\n"
] | In the first sample, there are three plans:
- In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; - In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; - In the third plan, at most 4 pieces can be repainted, and "mmmmmi" and "kmmmmm" both result in a Koyomity of 5. | [
{
"input": "6\nkoyomi\n3\n1 o\n4 o\n4 m",
"output": "3\n6\n5"
},
{
"input": "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b",
"output": "3\n4\n5\n7\n8\n1\n2\n3\n4\n5"
},
{
"input": "10\naaaaaaaaaa\n2\n10 b\n10 z",
"output": "10\n10"
},
{
"input": "1\nc\n4\n1 x\n1 a\n1 e\n1 t",
"output": "1\n1\n1\n1"
},
{
"input": "20\naaaaaaaaaaaaaaaaaaaa\n1\n11 a",
"output": "20"
},
{
"input": "4\ncbcc\n12\n4 b\n4 c\n1 b\n2 a\n3 b\n2 c\n4 a\n1 a\n2 b\n3 a\n1 c\n3 c",
"output": "4\n4\n2\n2\n4\n4\n4\n1\n3\n3\n4\n4"
},
{
"input": "4\nddbb\n16\n3 c\n3 b\n1 a\n1 b\n4 d\n4 a\n3 d\n2 a\n2 d\n4 c\n3 a\n2 c\n4 b\n1 c\n2 b\n1 d",
"output": "3\n4\n1\n3\n4\n4\n4\n2\n4\n4\n3\n2\n4\n1\n4\n3"
},
{
"input": "4\nabcc\n24\n1 c\n4 d\n3 c\n1 d\n1 c\n1 b\n3 b\n2 c\n3 d\n3 d\n4 c\n2 a\n4 d\n1 a\n1 b\n4 a\n4 d\n3 b\n4 b\n3 c\n3 a\n2 d\n1 a\n2 b",
"output": "3\n4\n4\n1\n3\n2\n4\n4\n3\n3\n4\n3\n4\n2\n2\n4\n4\n4\n4\n4\n4\n2\n2\n3"
},
{
"input": "40\ncbbcbcccccacccccbbacbaabccbbabbaaaaacccc\n10\n40 a\n28 c\n25 c\n21 a\n18 c\n27 a\n9 c\n37 c\n15 a\n18 b",
"output": "40\n40\n40\n31\n35\n37\n23\n40\n24\n27"
},
{
"input": "100\ndddddccccdddddaaaaabbbbbbbbbbbbbaaacdcabbacccacccccbdbbadddbbddddbdaaccacdddbbbaddddbbbbdcbbbdddddda\n50\n54 b\n48 d\n45 b\n52 c\n52 a\n48 a\n54 b\n45 a\n47 d\n50 d\n53 a\n34 a\n51 b\n48 d\n47 d\n47 a\n48 d\n53 b\n52 d\n54 d\n46 a\n38 a\n52 b\n49 a\n49 b\n46 c\n54 a\n45 b\n35 c\n55 c\n51 c\n46 d\n54 d\n50 a\n33 c\n46 a\n50 b\n50 a\n54 a\n32 b\n55 b\n49 c\n53 d\n49 a\n46 b\n48 c\n47 b\n47 b\n47 a\n46 b",
"output": "85\n72\n76\n69\n68\n63\n85\n60\n71\n74\n69\n46\n82\n72\n71\n62\n72\n84\n76\n78\n61\n50\n83\n64\n80\n60\n70\n76\n49\n72\n68\n70\n78\n66\n47\n61\n81\n66\n70\n53\n86\n63\n77\n64\n77\n62\n78\n78\n62\n77"
},
{
"input": "200\nddeecdbbbeeeeebbbbbaaaaaaaaaaaaaaaaaaaaaaabbcaacccbeeeeddddddddddddccccccdffeeeeecccccbbbbaaaaedfffffaadeeeeeeeedddddaaaaaaaaaaaaaabbbbbcaadddeefffbbbbcccccccccccbbbbbbeeeeeeeffffffdffffffffffffaaaaab\n10\n43 f\n118 d\n165 f\n72 f\n48 f\n2 a\n61 e\n94 d\n109 f\n16 a",
"output": "64\n144\n193\n98\n69\n25\n79\n117\n137\n41"
},
{
"input": "5\naaaaa\n1\n1 b",
"output": "1"
}
] | 46 | 5,529,600 | -1 | 5,688 |
|
682 | Alyona and Numbers | [
"constructive algorithms",
"math",
"number theory"
] | null | null | 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. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case. | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
"output": "30"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 1000000",
"output": "200000"
},
{
"input": "1000000 1",
"output": "200000"
},
{
"input": "1000000 1000000",
"output": "200000000000"
},
{
"input": "944 844",
"output": "159348"
},
{
"input": "368 984",
"output": "72423"
},
{
"input": "792 828",
"output": "131155"
},
{
"input": "920 969",
"output": "178296"
},
{
"input": "640 325",
"output": "41600"
},
{
"input": "768 170",
"output": "26112"
},
{
"input": "896 310",
"output": "55552"
},
{
"input": "320 154",
"output": "9856"
},
{
"input": "744 999",
"output": "148652"
},
{
"input": "630 843",
"output": "106218"
},
{
"input": "54 688",
"output": "7431"
},
{
"input": "478 828",
"output": "79157"
},
{
"input": "902 184",
"output": "33194"
},
{
"input": "31 29",
"output": "180"
},
{
"input": "751 169",
"output": "25384"
},
{
"input": "879 14",
"output": "2462"
},
{
"input": "7 858",
"output": "1201"
},
{
"input": "431 702",
"output": "60512"
},
{
"input": "855 355",
"output": "60705"
},
{
"input": "553 29",
"output": "3208"
},
{
"input": "721767 525996",
"output": "75929310986"
},
{
"input": "805191 74841",
"output": "12052259926"
},
{
"input": "888615 590981",
"output": "105030916263"
},
{
"input": "4743 139826",
"output": "132638943"
},
{
"input": "88167 721374",
"output": "12720276292"
},
{
"input": "171591 13322",
"output": "457187060"
},
{
"input": "287719 562167",
"output": "32349225415"
},
{
"input": "371143 78307",
"output": "5812618980"
},
{
"input": "487271 627151",
"output": "61118498984"
},
{
"input": "261436 930642",
"output": "48660664382"
},
{
"input": "377564 446782",
"output": "33737759810"
},
{
"input": "460988 28330",
"output": "2611958008"
},
{
"input": "544412 352983",
"output": "38433636199"
},
{
"input": "660540 869123",
"output": "114818101284"
},
{
"input": "743964 417967",
"output": "62190480238"
},
{
"input": "827388 966812",
"output": "159985729411"
},
{
"input": "910812 515656",
"output": "93933134534"
},
{
"input": "26940 64501",
"output": "347531388"
},
{
"input": "110364 356449",
"output": "7867827488"
},
{
"input": "636358 355531",
"output": "45248999219"
},
{
"input": "752486 871672",
"output": "131184195318"
},
{
"input": "803206 420516",
"output": "67552194859"
},
{
"input": "919334 969361",
"output": "178233305115"
},
{
"input": "35462 261309",
"output": "1853307952"
},
{
"input": "118887 842857",
"output": "20040948031"
},
{
"input": "202311 358998",
"output": "14525848875"
},
{
"input": "285735 907842",
"output": "51880446774"
},
{
"input": "401863 456686",
"output": "36705041203"
},
{
"input": "452583 972827",
"output": "88056992428"
},
{
"input": "235473 715013",
"output": "33673251230"
},
{
"input": "318897 263858",
"output": "16828704925"
},
{
"input": "402321 812702",
"output": "65393416268"
},
{
"input": "518449 361546",
"output": "37488632431"
},
{
"input": "634577 910391",
"output": "115542637921"
},
{
"input": "685297 235043",
"output": "32214852554"
},
{
"input": "801425 751183",
"output": "120403367155"
},
{
"input": "884849 300028",
"output": "53095895155"
},
{
"input": "977 848872",
"output": "165869588"
},
{
"input": "51697 397716",
"output": "4112144810"
},
{
"input": "834588 107199",
"output": "17893399803"
},
{
"input": "918012 688747",
"output": "126455602192"
},
{
"input": "1436 237592",
"output": "68236422"
},
{
"input": "117564 753732",
"output": "17722349770"
},
{
"input": "200988 302576",
"output": "12162829017"
},
{
"input": "284412 818717",
"output": "46570587880"
},
{
"input": "400540 176073",
"output": "14104855884"
},
{
"input": "483964 724917",
"output": "70166746198"
},
{
"input": "567388 241058",
"output": "27354683301"
},
{
"input": "650812 789902",
"output": "102815540084"
},
{
"input": "400999 756281",
"output": "60653584944"
},
{
"input": "100 101",
"output": "2020"
},
{
"input": "100 102",
"output": "2040"
},
{
"input": "103 100",
"output": "2060"
},
{
"input": "100 104",
"output": "2080"
},
{
"input": "3 4",
"output": "3"
},
{
"input": "11 23",
"output": "50"
},
{
"input": "8 14",
"output": "23"
},
{
"input": "23423 34234",
"output": "160372597"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "999999 999999",
"output": "199999600001"
},
{
"input": "82 99",
"output": "1624"
},
{
"input": "21 18",
"output": "75"
},
{
"input": "234 234",
"output": "10952"
},
{
"input": "4 4",
"output": "4"
},
{
"input": "6 13",
"output": "15"
},
{
"input": "3 9",
"output": "6"
},
{
"input": "99999 99999",
"output": "1999960001"
},
{
"input": "34 33",
"output": "225"
},
{
"input": "2 2",
"output": "0"
},
{
"input": "333 1",
"output": "66"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "8 2",
"output": "3"
},
{
"input": "2179 2218",
"output": "966605"
},
{
"input": "1000000 999999",
"output": "199999800000"
},
{
"input": "873828 774207",
"output": "135304750879"
},
{
"input": "13 19",
"output": "50"
},
{
"input": "1648 576469",
"output": "190004183"
},
{
"input": "11 13",
"output": "28"
},
{
"input": "5 8",
"output": "8"
},
{
"input": "650074 943659",
"output": "122689636154"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "54 43",
"output": "465"
},
{
"input": "14 9",
"output": "26"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "543 534",
"output": "57993"
},
{
"input": "321 123",
"output": "7896"
},
{
"input": "21 3",
"output": "12"
},
{
"input": "2 1",
"output": "0"
},
{
"input": "4 3",
"output": "3"
},
{
"input": "47474 74747",
"output": "709707816"
},
{
"input": "4 9",
"output": "8"
},
{
"input": "7 4",
"output": "6"
},
{
"input": "9 4",
"output": "8"
},
{
"input": "12414 4214",
"output": "10462520"
},
{
"input": "2 9",
"output": "4"
},
{
"input": "253 821",
"output": "41542"
},
{
"input": "2 4",
"output": "2"
}
] | 608 | 0 | 3 | 5,697 |
|
887 | Solution for Cube | [
"brute force",
"implementation"
] | null | null | During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube | In first line given a sequence of 24 integers *a**i* (1<=≤<=*a**i*<=≤<=6), where *a**i* denotes color of *i*-th square. There are exactly 4 occurrences of all colors in this sequence. | Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise. | [
"2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4\n",
"5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3\n"
] | [
"NO",
"YES"
] | In first test case cube looks like this:
In second test case cube looks like this:
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | [
{
"input": "2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4",
"output": "NO"
},
{
"input": "5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3",
"output": "YES"
},
{
"input": "2 6 3 3 5 5 2 6 1 1 6 4 4 4 2 4 6 5 3 1 2 5 3 1",
"output": "NO"
},
{
"input": "3 4 2 3 5 5 6 6 4 5 4 6 5 1 1 1 6 2 1 3 3 2 4 2",
"output": "NO"
},
{
"input": "5 5 2 5 3 3 2 6 6 4 2 4 6 1 4 3 1 6 2 1 3 4 5 1",
"output": "NO"
},
{
"input": "6 6 1 2 6 1 1 3 5 4 3 4 3 5 5 2 4 4 6 2 1 5 3 2",
"output": "NO"
},
{
"input": "2 2 1 1 5 5 5 5 3 3 4 4 1 4 1 4 2 3 2 3 6 6 6 6",
"output": "YES"
},
{
"input": "1 1 1 1 5 5 3 3 4 4 4 4 3 3 2 2 6 6 5 5 2 2 6 6",
"output": "YES"
},
{
"input": "1 1 1 1 3 3 3 3 5 5 5 5 2 2 2 2 4 4 4 4 6 6 6 6",
"output": "NO"
},
{
"input": "5 4 5 4 4 6 4 6 6 3 6 3 1 1 1 1 2 2 2 2 5 3 5 3",
"output": "YES"
},
{
"input": "3 3 5 5 2 2 2 2 6 6 4 4 6 3 6 3 4 5 4 5 1 1 1 1",
"output": "YES"
},
{
"input": "6 6 6 6 2 2 5 5 1 1 1 1 4 4 2 2 5 5 3 3 3 3 4 4",
"output": "YES"
},
{
"input": "4 6 4 6 6 1 6 1 1 3 1 3 2 2 2 2 5 5 5 5 4 3 4 3",
"output": "YES"
},
{
"input": "6 6 2 2 3 3 3 3 4 4 5 5 4 6 4 6 5 2 5 2 1 1 1 1",
"output": "YES"
},
{
"input": "3 3 3 3 4 4 5 5 1 1 1 1 2 2 4 4 5 5 6 6 6 6 2 2",
"output": "YES"
},
{
"input": "2 5 2 5 4 2 4 2 1 4 1 4 6 6 6 6 3 3 3 3 1 5 1 5",
"output": "YES"
},
{
"input": "4 4 3 3 5 5 5 5 1 1 6 6 3 6 3 6 4 1 4 1 2 2 2 2",
"output": "YES"
},
{
"input": "5 5 5 5 6 6 2 2 3 3 3 3 2 2 1 1 4 4 6 6 1 1 4 4",
"output": "YES"
},
{
"input": "1 4 3 4 2 6 5 2 1 5 1 6 3 4 3 6 5 5 1 3 2 6 4 2",
"output": "NO"
},
{
"input": "4 4 2 5 3 2 4 2 5 3 6 4 6 5 1 3 1 5 6 3 1 1 6 2",
"output": "NO"
},
{
"input": "4 5 3 4 5 5 6 3 2 5 1 6 2 1 6 3 1 4 2 3 2 6 1 4",
"output": "NO"
},
{
"input": "3 3 2 3 6 4 4 4 1 2 1 3 2 5 6 6 1 2 6 5 4 5 1 5",
"output": "NO"
},
{
"input": "5 6 1 1 4 5 6 5 4 6 2 1 4 2 6 5 3 2 3 2 3 1 3 4",
"output": "NO"
},
{
"input": "4 4 4 5 2 3 4 1 3 3 1 5 6 5 6 6 1 3 6 2 5 2 1 2",
"output": "NO"
},
{
"input": "3 2 5 6 1 4 3 4 6 5 4 3 2 3 2 2 1 4 1 1 6 5 6 5",
"output": "NO"
},
{
"input": "5 4 6 2 5 6 4 1 6 3 3 1 3 2 4 1 1 6 2 3 5 2 4 5",
"output": "NO"
},
{
"input": "6 6 3 1 5 6 5 3 2 5 3 1 2 4 1 6 4 5 2 2 4 1 3 4",
"output": "NO"
},
{
"input": "6 5 4 1 6 5 2 3 3 5 3 6 4 2 6 5 4 2 1 1 4 1 3 2",
"output": "NO"
},
{
"input": "1 3 5 6 4 4 4 3 5 2 2 2 3 1 5 6 3 4 6 5 1 2 1 6",
"output": "NO"
},
{
"input": "3 6 5 4 4 6 1 4 3 2 5 2 1 2 6 2 5 4 1 3 1 6 5 3",
"output": "NO"
},
{
"input": "5 2 6 1 5 3 5 3 1 1 3 6 6 2 4 2 5 4 4 2 1 3 4 6",
"output": "NO"
},
{
"input": "2 5 6 2 3 6 5 6 2 3 1 3 6 4 5 4 1 1 1 5 3 4 4 2",
"output": "NO"
},
{
"input": "4 5 4 4 3 3 1 2 3 1 1 5 2 2 5 6 6 4 3 2 6 5 1 6",
"output": "NO"
},
{
"input": "5 2 5 2 3 5 3 5 4 3 4 3 6 6 6 6 1 1 1 1 4 2 4 2",
"output": "YES"
},
{
"input": "2 4 2 4 4 5 4 5 5 1 5 1 3 3 3 3 6 6 6 6 2 1 2 1",
"output": "YES"
},
{
"input": "3 5 3 5 5 1 5 1 1 4 1 4 6 6 6 6 2 2 2 2 3 4 3 4",
"output": "YES"
},
{
"input": "2 1 2 1 4 2 4 2 6 4 6 4 5 5 5 5 3 3 3 3 6 1 6 1",
"output": "YES"
},
{
"input": "4 4 2 2 1 1 1 1 5 5 6 6 2 6 2 6 4 5 4 5 3 3 3 3",
"output": "YES"
},
{
"input": "1 1 2 2 4 4 4 4 5 5 6 6 5 1 5 1 6 2 6 2 3 3 3 3",
"output": "YES"
},
{
"input": "2 2 6 6 4 4 4 4 1 1 5 5 1 2 1 2 5 6 5 6 3 3 3 3",
"output": "YES"
},
{
"input": "2 2 3 3 6 6 6 6 4 4 1 1 3 1 3 1 2 4 2 4 5 5 5 5",
"output": "YES"
},
{
"input": "6 6 6 6 4 4 3 3 5 5 5 5 3 3 1 1 2 2 4 4 1 1 2 2",
"output": "YES"
},
{
"input": "2 2 2 2 4 4 5 5 3 3 3 3 6 6 4 4 5 5 1 1 1 1 6 6",
"output": "YES"
},
{
"input": "1 1 1 1 5 5 6 6 3 3 3 3 4 4 5 5 6 6 2 2 2 2 4 4",
"output": "YES"
},
{
"input": "4 4 4 4 2 2 3 3 1 1 1 1 3 3 6 6 5 5 2 2 6 6 5 5",
"output": "YES"
},
{
"input": "1 1 1 1 2 2 3 3 6 6 6 6 5 5 4 4 3 3 2 2 4 4 5 5",
"output": "NO"
},
{
"input": "1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5 6 6 6 6",
"output": "NO"
},
{
"input": "5 5 5 5 1 1 2 2 6 6 6 6 4 4 3 3 3 3 4 4 2 2 1 1",
"output": "NO"
}
] | 61 | 0 | 0 | 5,702 |
|
120 | Put Knight! | [
"games",
"math"
] | null | null | Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (*r*,<=*c*) can threat squares (*r*<=-<=1,<=*c*<=+<=2), (*r*<=-<=1,<=*c*<=-<=2), (*r*<=+<=1,<=*c*<=+<=2), (*r*<=+<=1,<=*c*<=-<=2), (*r*<=-<=2,<=*c*<=+<=1), (*r*<=-<=2,<=*c*<=-<=1), (*r*<=+<=2,<=*c*<=+<=1) and (*r*<=+<=2,<=*c*<=-<=1) (some of the squares may be located outside the chessboard). The player who can't put a new knight during his move loses. Determine which player wins considering that both players play optimally well and Petya starts. | The first line contains integer *T* (1<=≤<=*T*<=≤<=100) — the number of boards, for which you should determine the winning player. Next *T* lines contain *T* integers *n**i* (1<=≤<=*n**i*<=≤<=10000) — the sizes of the chessboards. | For each *n**i*<=×<=*n**i* board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1". | [
"2\n2\n1\n"
] | [
"1\n0\n"
] | none | [
{
"input": "2\n2\n1",
"output": "1\n0"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "0\n1\n0\n1\n0\n1\n0\n1\n0\n1"
},
{
"input": "15\n10\n4\n7\n8\n9\n6\n2\n1\n3\n1\n5\n2\n3\n4\n5",
"output": "1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0"
},
{
"input": "6\n10\n7\n10\n8\n5\n1",
"output": "1\n0\n1\n1\n0\n0"
},
{
"input": "100\n5\n6\n8\n7\n5\n7\n10\n2\n8\n3\n10\n3\n7\n3\n2\n7\n10\n3\n7\n3\n9\n5\n1\n1\n1\n5\n7\n5\n4\n8\n7\n3\n2\n10\n5\n10\n1\n10\n5\n2\n10\n6\n4\n10\n7\n6\n10\n8\n8\n5\n5\n7\n5\n7\n8\n6\n7\n8\n5\n8\n7\n9\n1\n1\n1\n5\n10\n6\n3\n3\n2\n7\n5\n2\n4\n4\n10\n1\n5\n2\n9\n1\n9\n9\n8\n2\n6\n9\n8\n2\n6\n2\n1\n10\n10\n8\n9\n7\n8\n8",
"output": "0\n1\n1\n0\n0\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n0\n0\n1\n1"
},
{
"input": "100\n59\n95\n11\n67\n65\n90\n93\n53\n29\n63\n74\n47\n5\n67\n70\n67\n56\n66\n10\n33\n81\n63\n41\n77\n62\n58\n19\n95\n68\n2\n99\n85\n85\n94\n52\n87\n20\n85\n74\n58\n74\n85\n76\n95\n46\n1\n28\n89\n100\n75\n94\n46\n29\n21\n89\n42\n95\n72\n18\n65\n73\n99\n98\n59\n59\n74\n80\n47\n68\n58\n94\n1\n63\n90\n74\n77\n36\n9\n13\n100\n64\n55\n63\n70\n97\n50\n48\n7\n81\n25\n31\n64\n57\n12\n42\n61\n95\n83\n79\n84",
"output": "0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n0\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n0\n0\n0\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1"
},
{
"input": "100\n62\n25\n86\n34\n47\n37\n38\n18\n42\n48\n39\n59\n74\n41\n58\n96\n50\n19\n40\n42\n43\n80\n100\n64\n54\n2\n36\n56\n80\n77\n29\n21\n87\n58\n87\n92\n30\n73\n87\n8\n30\n98\n52\n47\n67\n95\n12\n87\n98\n18\n16\n52\n36\n1\n100\n23\n49\n60\n89\n14\n100\n6\n34\n27\n30\n81\n33\n10\n59\n64\n74\n33\n28\n19\n78\n79\n87\n98\n30\n78\n42\n77\n80\n87\n34\n72\n19\n86\n36\n19\n15\n94\n61\n11\n32\n91\n44\n33\n32\n48",
"output": "1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n0\n0\n1\n0\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n1\n1\n0\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1"
},
{
"input": "100\n17\n6\n14\n53\n81\n33\n31\n31\n4\n34\n4\n70\n94\n64\n46\n25\n92\n19\n70\n4\n57\n45\n59\n51\n47\n45\n2\n69\n91\n3\n10\n4\n89\n71\n21\n46\n87\n60\n100\n59\n37\n12\n75\n98\n88\n89\n49\n38\n44\n14\n39\n57\n95\n82\n11\n56\n51\n97\n9\n14\n27\n14\n17\n43\n2\n88\n37\n21\n98\n70\n55\n66\n93\n47\n30\n30\n87\n86\n46\n56\n67\n99\n98\n3\n23\n42\n90\n18\n91\n14\n46\n73\n65\n10\n70\n72\n45\n31\n84\n59",
"output": "0\n1\n1\n0\n0\n0\n0\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n0\n0\n0\n1\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n0"
},
{
"input": "100\n20\n36\n41\n21\n15\n80\n24\n44\n18\n20\n17\n82\n63\n38\n34\n53\n85\n20\n48\n13\n19\n11\n18\n86\n39\n89\n20\n30\n3\n30\n39\n40\n91\n35\n56\n52\n97\n48\n12\n9\n93\n25\n50\n50\n9\n32\n85\n89\n42\n9\n14\n15\n54\n14\n70\n37\n5\n86\n80\n63\n6\n74\n1\n11\n22\n96\n89\n85\n37\n76\n83\n47\n58\n28\n83\n32\n38\n75\n63\n33\n45\n70\n16\n20\n59\n63\n62\n97\n46\n56\n30\n52\n17\n60\n61\n54\n94\n29\n37\n71",
"output": "1\n1\n0\n0\n0\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0"
},
{
"input": "100\n24\n18\n68\n40\n49\n27\n17\n9\n31\n6\n81\n93\n31\n12\n22\n82\n27\n20\n78\n23\n33\n76\n78\n73\n83\n32\n37\n91\n15\n4\n20\n75\n93\n48\n91\n58\n7\n36\n25\n59\n1\n38\n73\n1\n31\n26\n69\n40\n40\n53\n36\n21\n12\n95\n81\n17\n6\n23\n52\n11\n33\n81\n84\n80\n94\n3\n42\n48\n76\n81\n64\n79\n23\n56\n87\n82\n89\n63\n80\n11\n71\n92\n33\n37\n48\n33\n33\n77\n1\n50\n13\n82\n21\n59\n51\n83\n96\n27\n89\n83",
"output": "1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n0\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0"
},
{
"input": "100\n27\n47\n95\n7\n82\n22\n9\n21\n45\n40\n46\n5\n52\n34\n10\n11\n21\n73\n8\n85\n95\n41\n37\n8\n75\n24\n3\n52\n26\n31\n49\n11\n95\n12\n25\n12\n17\n71\n37\n10\n56\n51\n97\n100\n52\n20\n5\n91\n86\n48\n59\n26\n19\n27\n92\n50\n8\n60\n23\n11\n12\n89\n68\n96\n66\n58\n94\n59\n15\n39\n92\n12\n36\n85\n39\n84\n41\n52\n97\n89\n48\n14\n51\n53\n85\n54\n4\n9\n56\n44\n45\n61\n25\n58\n41\n65\n45\n25\n42\n94",
"output": "0\n0\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n1\n1\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0\n0\n0\n1\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n0\n1\n0\n0\n1\n1\n1\n1\n0\n0\n1\n0\n1\n1\n1\n1\n1\n0\n0\n0\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1"
},
{
"input": "100\n30\n29\n70\n26\n16\n70\n2\n34\n59\n26\n11\n16\n20\n8\n98\n39\n14\n73\n38\n94\n9\n6\n96\n95\n67\n68\n21\n13\n38\n57\n30\n95\n97\n25\n60\n17\n75\n59\n98\n60\n64\n64\n72\n52\n73\n15\n42\n41\n84\n91\n34\n32\n78\n7\n51\n31\n62\n49\n43\n60\n40\n49\n51\n64\n38\n66\n46\n23\n6\n45\n73\n92\n1\n65\n91\n86\n92\n40\n14\n19\n74\n36\n68\n70\n22\n76\n75\n88\n11\n86\n28\n39\n29\n9\n31\n47\n46\n23\n94\n6",
"output": "1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n1\n1\n0\n0\n1\n0\n0\n1\n0\n1\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n0\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n0\n1\n0\n1\n1"
},
{
"input": "100\n34\n58\n97\n93\n50\n17\n95\n47\n72\n11\n76\n28\n89\n82\n86\n68\n56\n74\n68\n4\n72\n24\n3\n82\n60\n11\n39\n74\n50\n32\n59\n30\n99\n89\n94\n71\n84\n46\n10\n10\n19\n30\n95\n3\n94\n57\n26\n40\n82\n87\n56\n38\n37\n40\n62\n64\n64\n86\n14\n8\n19\n57\n87\n80\n58\n73\n99\n86\n45\n51\n53\n25\n66\n94\n95\n36\n43\n29\n31\n97\n52\n58\n86\n87\n10\n45\n46\n68\n66\n80\n60\n70\n33\n8\n22\n28\n96\n21\n47\n18",
"output": "1\n1\n0\n0\n1\n0\n0\n0\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n0\n0\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n0\n0\n1\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n0\n1"
},
{
"input": "100\n37\n88\n24\n60\n84\n12\n40\n12\n86\n97\n88\n39\n9\n4\n74\n97\n50\n75\n46\n65\n86\n89\n62\n17\n52\n55\n4\n88\n61\n58\n88\n66\n1\n2\n29\n77\n94\n34\n23\n9\n27\n43\n71\n55\n67\n52\n62\n91\n80\n82\n79\n95\n95\n20\n73\n45\n18\n23\n85\n9\n46\n64\n70\n48\n30\n80\n51\n97\n84\n57\n82\n57\n31\n22\n47\n39\n95\n17\n96\n74\n30\n81\n4\n3\n47\n67\n17\n99\n21\n74\n43\n49\n37\n6\n12\n58\n97\n20\n51\n30",
"output": "0\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n0\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n1\n1\n0\n0\n0\n0\n0\n0\n0\n1\n1\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n1\n1\n1\n1\n0\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n0\n1\n1\n1\n0\n1\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n1\n1\n1\n0\n1\n0\n1"
},
{
"input": "100\n91\n83\n93\n95\n65\n56\n2\n7\n85\n42\n28\n26\n84\n62\n65\n23\n78\n49\n15\n100\n72\n86\n71\n19\n5\n71\n49\n100\n29\n59\n92\n82\n41\n53\n50\n57\n98\n80\n5\n65\n58\n68\n58\n72\n8\n64\n67\n44\n5\n79\n3\n59\n19\n22\n33\n85\n63\n23\n62\n50\n67\n52\n9\n14\n29\n31\n46\n3\n60\n82\n60\n12\n89\n87\n95\n51\n87\n54\n16\n36\n67\n90\n72\n77\n10\n14\n9\n76\n92\n82\n85\n59\n87\n75\n52\n76\n79\n24\n33\n76",
"output": "0\n0\n0\n0\n0\n1\n1\n0\n0\n1\n1\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n0\n0\n0\n0\n0\n1\n0\n0\n1\n1\n0\n0\n1\n0\n1\n1\n0\n0\n1\n1\n1\n1\n1\n1\n0\n1\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n0\n0\n0\n0\n0\n1\n1\n1\n0\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n0\n0\n0\n1\n1\n0\n1\n0\n1"
}
] | 154 | 2,764,800 | -1 | 5,736 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.