[
 {
  "id": "APPS-3820",
  "question": "You are given two strings $s$ and $t$. The string $s$ consists of lowercase Latin letters and at most one wildcard character '*', the string $t$ consists only of lowercase Latin letters. The length of the string $s$ equals $n$, the length of the string $t$ equals $m$.\n\nThe wildcard character '*' in the string $s$ (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase Latin letters. No other character of $s$ can be replaced with anything. If it is possible to replace a wildcard character '*' in $s$ to obtain a string $t$, then the string $t$ matches the pattern $s$.\n\nFor example, if $s=$\"aba*aba\" then the following strings match it \"abaaba\", \"abacaba\" and \"abazzzaba\", but the following strings do not match: \"ababa\", \"abcaaba\", \"codeforces\", \"aba1aba\", \"aba?aba\".\n\nIf the given string $t$ matches the given string $s$, print \"YES\", otherwise print \"NO\".\n\n\n-----Input-----\n\nThe first line contains two integers $n$ and $m$ ($1 \\le n, m \\le 2 \\cdot 10^5$) — the length of the string $s$ and the length of the string $t$, respectively.\n\nThe second line contains string $s$ of length $n$, which consists of lowercase Latin letters and at most one wildcard character '*'.\n\nThe third line contains string $t$ of length $m$, which consists only of lowercase Latin letters.\n\n\n-----Output-----\n\nPrint \"YES\" (without quotes), if you can obtain the string $t$ from the string $s$. Otherwise print \"NO\" (without quotes).\n\n\n-----Examples-----\nInput\n6 10\ncode*s\ncodeforces\n\nOutput\nYES\n\nInput\n6 5\nvk*cup\nvkcup\n\nOutput\nYES\n\nInput\n1 1\nv\nk\n\nOutput\nNO\n\nInput\n9 6\ngfgf*gfgf\ngfgfgf\n\nOutput\nNO\n\n\n\n-----Note-----\n\nIn the first example a wildcard character '*' can be replaced with a string \"force\". So the string $s$ after this replacement is \"codeforces\" and the answer is \"YES\".\n\nIn the second example a wildcard character '*' can be replaced with an empty string. So the string $s$ after this replacement is \"vkcup\" and the answer is \"YES\".\n\nThere is no wildcard character '*' in the third example and the strings \"v\" and \"k\" are different so the answer is \"NO\".\n\nIn the fourth example there is no such replacement of a wildcard character '*' that you can obtain the string $t$ so the answer is \"NO\".",
  "inputs": [
   "6 10\ncode*s\ncodeforces\n",
   "6 5\nvk*cup\nvkcup\n",
   "1 1\nv\nk\n",
   "9 6\ngfgf*gfgf\ngfgfgf\n",
   "5 102\neyw*y\neywsnxcwslfyiqbbeoaawtmioksfdndptxxcwzfmrpcixjbzvicijofjrbcvzaedglifuoczgjlqylddnsvsjfmfsccxbdveqguyfk\n",
   "1 17\n*\nthisisabadproblem\n",
   "3 2\nr*p\nrp\n",
   "5 2\ns*pjd\nsd\n",
   "4 2\nlq*e\nle\n",
   "6 2\nmv*mqs\nms\n",
   "4 4\na*ba\nayba\n",
   "3 4\na*o\naqro\n",
   "2 4\n*a\nbkga\n",
   "5 4\nzem*o\nzemo\n",
   "7 4\nec*aqro\naqro\n",
   "4 4\nb*af\nbkga\n",
   "1 1\n*\na\n",
   "1 1\na\na\n",
   "1 1\nb\na\n",
   "2 1\n*z\nz\n",
   "6 4\ntes*st\ntest\n",
   "3 3\naaa\naaa\n",
   "3 5\naaa\naaaaa\n",
   "7 7\nabacaba\nabacaba\n",
   "2 3\naa\naaa\n"
  ],
  "outputs": [
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "NO\n"
  ]
 },
 {
  "id": "APPS-3974",
  "question": "Polycarpus just has been out of luck lately! As soon as he found a job in the \"Binary Cat\" cafe, the club got burgled. All ice-cream was stolen.\n\nOn the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character \"+\" in his notes. Similarly, each time a visitor left the club, Polycarpus put character \"-\" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended.\n\nRight now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times.\n\n\n-----Input-----\n\nThe only line of the input contains a sequence of characters \"+\" and \"-\", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.\n\n\n-----Output-----\n\nPrint the sought minimum number of people\n\n\n-----Examples-----\nInput\n+-+-+\n\nOutput\n1\n\nInput\n---\nOutput\n3",
  "inputs": [
   "+-+-+\n",
   "---\n",
   "-\n",
   "--\n",
   "---\n",
   "----\n",
   "---+\n",
   "--+-\n",
   "--++\n",
   "-+--\n",
   "-++\n",
   "-++-\n",
   "+\n",
   "+-\n",
   "+--\n",
   "+--+\n",
   "++--\n",
   "-+++--+-++--+-+--+-+\n",
   "++-++--+++++-+++++---+++-++-++-\n",
   "----+-+--++---++---++-+-----+--\n",
   "-+++---+++++++++++++-++-++++++-++-+-+++-\n"
  ],
  "outputs": [
   "1\n",
   "3\n",
   "1\n",
   "2\n",
   "3\n",
   "4\n",
   "3\n",
   "2\n",
   "2\n",
   "2\n",
   "2\n",
   "2\n",
   "1\n",
   "1\n",
   "2\n",
   "2\n",
   "2\n",
   "3\n",
   "12\n",
   "11\n",
   "22\n"
  ]
 },
 {
  "id": "APPS-3775",
  "question": "Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.\n\nBoth participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers.\n\nDetermine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not.\n\n\n-----Input-----\n\nThe first line contains two integers $n$ and $m$ ($1 \\le n, m \\le 12$) — the number of pairs the first participant communicated to the second and vice versa.\n\nThe second line contains $n$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from first participant to the second.\n\nThe third line contains $m$ pairs of integers, each between $1$ and $9$, — pairs of numbers communicated from the second participant to the first.\n\nAll pairs within each set are distinct (in particular, if there is a pair $(1,2)$, there will be no pair $(2,1)$ within the same set), and no pair contains the same number twice.\n\nIt is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number.\n\n\n-----Output-----\n\nIf you can deduce the shared number with certainty, print that number.\n\nIf you can with certainty deduce that both participants know the shared number, but you do not know it, print $0$.\n\nOtherwise print $-1$.\n\n\n-----Examples-----\nInput\n2 2\n1 2 3 4\n1 5 3 4\n\nOutput\n1\n\nInput\n2 2\n1 2 3 4\n1 5 6 4\n\nOutput\n0\n\nInput\n2 3\n1 2 4 5\n1 2 1 3 2 3\n\nOutput\n-1\n\n\n\n-----Note-----\n\nIn the first example the first participant communicated pairs $(1,2)$ and $(3,4)$, and the second communicated $(1,5)$, $(3,4)$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $(3,4)$. Thus, the first participant has $(1,2)$ and the second has $(1,5)$, and at this point you already know the shared number is $1$.\n\nIn the second example either the first participant has $(1,2)$ and the second has $(1,5)$, or the first has $(3,4)$ and the second has $(6,4)$. In the first case both of them know the shared number is $1$, in the second case both of them know the shared number is $4$. You don't have enough information to tell $1$ and $4$ apart.\n\nIn the third case if the first participant was given $(1,2)$, they don't know what the shared number is, since from their perspective the second participant might have been given either $(1,3)$, in which case the shared number is $1$, or $(2,3)$, in which case the shared number is $2$. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is $-1$.",
  "inputs": [
   "2 2\n1 2 3 4\n1 5 3 4\n",
   "2 2\n1 2 3 4\n1 5 6 4\n",
   "2 3\n1 2 4 5\n1 2 1 3 2 3\n",
   "2 1\n1 2 1 3\n1 2\n",
   "4 4\n1 2 3 4 5 6 7 8\n2 3 4 5 6 7 8 1\n",
   "3 3\n1 2 5 6 7 8\n2 3 4 5 8 9\n",
   "4 3\n1 2 4 5 6 7 8 9\n1 2 8 9 3 1\n",
   "3 4\n2 1 8 9 3 1\n1 2 4 5 6 7 8 9\n",
   "3 8\n8 9 8 5 9 2\n8 4 8 3 2 6 4 2 4 3 3 7 3 6 1 6\n",
   "9 1\n3 4 3 2 3 7 3 5 9 4 1 9 6 4 5 2 7 6\n8 3\n",
   "5 6\n4 7 7 3 4 3 9 4 3 9\n7 5 7 8 1 7 7 2 6 2 1 2\n",
   "7 3\n2 6 6 7 6 4 6 1 9 6 7 4 1 9\n6 5 3 6 6 8\n",
   "9 2\n9 6 1 6 2 5 7 3 8 1 7 2 9 1 2 8 3 8\n6 4 4 5\n",
   "5 6\n1 7 5 6 6 9 3 6 1 9\n2 7 2 5 8 5 4 8 4 2 8 2\n",
   "3 9\n9 7 9 2 7 2\n9 8 1 9 3 9 6 3 8 6 4 6 1 3 5 4 5 3\n",
   "9 4\n2 8 8 9 8 1 9 2 5 9 3 5 3 2 5 2 9 1\n8 4 8 7 6 8 4 7\n",
   "1 12\n6 8\n8 4 8 2 5 8 9 8 8 3 8 7 8 1 1 3 1 9 4 3 7 3 5 7\n",
   "12 12\n7 6 3 8 8 4 4 7 1 9 9 5 7 5 4 9 8 6 2 7 7 3 3 6\n9 1 2 4 9 8 5 3 6 7 3 8 2 7 5 9 6 4 3 1 2 6 1 4\n",
   "12 12\n1 6 2 6 8 3 6 4 4 8 7 2 7 5 9 4 2 4 9 5 8 5 3 6\n2 8 6 9 2 6 7 4 6 5 6 3 5 8 7 8 7 1 1 9 9 7 7 3\n",
   "12 12\n6 7 5 4 7 8 2 9 8 5 3 5 1 6 7 3 7 9 5 7 1 8 6 8\n6 4 2 1 7 8 1 6 8 5 9 8 1 5 7 2 5 9 6 3 9 2 9 4\n",
   "1 10\n3 9\n3 2 3 4 5 3 5 7 8 6 2 5 7 8 2 4 1 7 5 1\n",
   "3 10\n6 1 4 1 4 6\n7 1 8 1 8 5 3 2 9 7 9 3 5 9 5 3 5 7 7 2\n",
   "2 7\n2 7 2 5\n7 1 9 7 8 9 4 9 8 1 3 9 3 8\n",
   "12 1\n6 2 6 4 8 6 6 9 5 6 6 1 9 1 1 3 3 9 2 4 5 2 8 1\n6 7\n",
   "2 11\n6 1 3 6\n1 7 1 2 1 5 1 4 5 3 3 2 9 8 4 2 7 5 4 9 2 9\n"
  ],
  "outputs": [
   "1\n",
   "0\n",
   "-1\n",
   "1\n",
   "-1\n",
   "0\n",
   "1\n",
   "1\n",
   "0\n",
   "3\n",
   "7\n",
   "6\n",
   "0\n",
   "0\n",
   "9\n",
   "8\n",
   "8\n",
   "-1\n",
   "-1\n",
   "-1\n",
   "3\n",
   "1\n",
   "7\n",
   "6\n",
   "0\n"
  ]
 },
 {
  "id": "APPS-3933",
  "question": "Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral.\n\nVasya believes that if the average temperatures over the last n days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (n + 1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (n + 1)-th day will be equal to the temperature of the n-th day.\n\nYour task is to help Vasya predict the average temperature for tomorrow, i. e. for the (n + 1)-th day.\n\n\n-----Input-----\n\nThe first line contains a single integer n (2 ≤ n ≤ 100) — the number of days for which the average air temperature is known.\n\nThe second line contains a sequence of integers t_1, t_2, ..., t_{n} ( - 1000 ≤ t_{i} ≤ 1000) — where t_{i} is the average temperature in the i-th day.\n\n\n-----Output-----\n\nPrint the average air temperature in the (n + 1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000.\n\n\n-----Examples-----\nInput\n5\n10 5 0 -5 -10\n\nOutput\n-15\n\nInput\n4\n1 1 1 1\n\nOutput\n1\n\nInput\n3\n5 1 -5\n\nOutput\n-5\n\nInput\n2\n900 1000\n\nOutput\n1100\n\n\n\n-----Note-----\n\nIn the first example the sequence of the average temperatures is an arithmetic progression where the first term is 10 and each following terms decreases by 5. So the predicted average temperature for the sixth day is  - 10 - 5 =  - 15.\n\nIn the second example the sequence of the average temperatures is an arithmetic progression where the first term is 1 and each following terms equals to the previous one. So the predicted average temperature in the fifth day is 1.\n\nIn the third example the average temperatures do not form an arithmetic progression, so the average temperature of the fourth day equals to the temperature of the third day and equals to  - 5.\n\nIn the fourth example the sequence of the average temperatures is an arithmetic progression where the first term is 900 and each the following terms increase by 100. So predicted average temperature in the third day is 1000 + 100 = 1100.",
  "inputs": [
   "5\n10 5 0 -5 -10\n",
   "4\n1 1 1 1\n",
   "3\n5 1 -5\n",
   "2\n900 1000\n",
   "2\n1 2\n",
   "3\n2 5 8\n",
   "4\n4 1 -2 -5\n",
   "10\n-1000 -995 -990 -985 -980 -975 -970 -965 -960 -955\n",
   "11\n-1000 -800 -600 -400 -200 0 200 400 600 800 1000\n",
   "31\n1000 978 956 934 912 890 868 846 824 802 780 758 736 714 692 670 648 626 604 582 560 538 516 494 472 450 428 406 384 362 340\n",
   "5\n1000 544 88 -368 -824\n",
   "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
   "33\n456 411 366 321 276 231 186 141 96 51 6 -39 -84 -129 -174 -219 -264 -309 -354 -399 -444 -489 -534 -579 -624 -669 -714 -759 -804 -849 -894 -939 -984\n",
   "77\n-765 -742 -719 -696 -673 -650 -627 -604 -581 -558 -535 -512 -489 -466 -443 -420 -397 -374 -351 -328 -305 -282 -259 -236 -213 -190 -167 -144 -121 -98 -75 -52 -29 -6 17 40 63 86 109 132 155 178 201 224 247 270 293 316 339 362 385 408 431 454 477 500 523 546 569 592 615 638 661 684 707 730 753 776 799 822 845 868 891 914 937 960 983\n",
   "3\n2 4 8\n",
   "4\n4 1 -3 -5\n",
   "10\n-1000 -995 -990 -984 -980 -975 -970 -965 -960 -955\n",
   "11\n-999 -800 -600 -400 -200 0 200 400 600 800 1000\n",
   "51\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990\n",
   "100\n10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198 200 202 204 206 207\n",
   "2\n1000 1000\n",
   "2\n-1000 1000\n",
   "2\n1000 -1000\n",
   "2\n-1000 -1000\n",
   "100\n-85 -80 -76 -72 -68 -64 -60 -56 -52 -48 -44 -40 -36 -32 -28 -24 -20 -16 -12 -8 -4 0 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120 124 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196 200 204 208 212 216 220 224 228 232 236 240 244 248 252 256 260 264 268 272 276 280 284 288 292 296 300 304 308 312\n"
  ],
  "outputs": [
   "-15\n",
   "1\n",
   "-5\n",
   "1100\n",
   "3\n",
   "11\n",
   "-8\n",
   "-950\n",
   "1200\n",
   "318\n",
   "-1280\n",
   "0\n",
   "-1029\n",
   "1006\n",
   "8\n",
   "-5\n",
   "-955\n",
   "1000\n",
   "990\n",
   "207\n",
   "1000\n",
   "3000\n",
   "-3000\n",
   "-1000\n",
   "312\n"
  ]
 },
 {
  "id": "APPS-3991",
  "question": "Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to n computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis.\n\nLet's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from 1 to n. So the i-th hacked computer is located at the point x_{i}. Moreover the coordinates of all computers are distinct. \n\nLeha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task.\n\nLeha should calculate a sum of F(a) for all a, where a is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote A the set of all integers from 1 to n. Noora asks the hacker to find value of the expression $\\sum_{a \\subseteq A, a \\neq \\varnothing} F(a)$. Here F(a) is calculated as the maximum among the distances between all pairs of computers from the set a. Formally, $F(a) = \\operatorname{max}_{i, j \\in a}|x_{i} - x_{j}|$. Since the required sum can be quite large Noora asks to find it modulo 10^9 + 7.\n\nThough, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.\n\n\n-----Input-----\n\nThe first line contains one integer n (1 ≤ n ≤ 3·10^5) denoting the number of hacked computers.\n\nThe second line contains n integers x_1, x_2, ..., x_{n} (1 ≤ x_{i} ≤ 10^9) denoting the coordinates of hacked computers. It is guaranteed that all x_{i} are distinct.\n\n\n-----Output-----\n\nPrint a single integer — the required sum modulo 10^9 + 7.\n\n\n-----Examples-----\nInput\n2\n4 7\n\nOutput\n3\n\nInput\n3\n4 3 1\n\nOutput\n9\n\n\n\n-----Note-----\n\nThere are three non-empty subsets in the first sample test:$\\{4 \\}$, $\\{7 \\}$ and $\\{4,7 \\}$. The first and the second subset increase the sum by 0 and the third subset increases the sum by 7 - 4 = 3. In total the answer is 0 + 0 + 3 = 3.\n\nThere are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: $\\{4,3 \\}$, $\\{4,1 \\}$, $\\{3,1 \\}$, $\\{4,3,1 \\}$. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.",
  "inputs": [
   "2\n4 7\n",
   "3\n4 3 1\n",
   "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95\n",
   "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73\n",
   "20\n2 6 8 9 20 23 27 36 43 49 63 65 70 71 85 87 89 91 94 97\n",
   "1\n78091781\n",
   "2\n1000000000 1\n",
   "3\n999999998 999999999 999999992\n",
   "3\n465343471 465343474 465343473\n",
   "10\n10 3 6 2 1 9 8 4 5 7\n",
   "10\n756734546 756734524 756734550 756734529 756734553 756734538 756734541 756734536 756734579 756734537\n",
   "10\n877105545 939360757 849826701 845946140 803128820 926787996 967305000 904694971 921301848 971203310\n",
   "5\n4 7 13 17 18\n",
   "5\n20 17 13 7 2\n",
   "5\n3 17 2 5 4\n",
   "5\n999999980 999999985 999999986 999999990 999999992\n",
   "5\n1000000000 999999988 999999982 999999981 999999980\n",
   "5\n999999984 999999997 999999994 999999991 999999982\n",
   "1\n2\n",
   "5\n9 10 7 4 5\n"
  ],
  "outputs": [
   "3\n",
   "9\n",
   "83396599\n",
   "68059140\n",
   "92743989\n",
   "0\n",
   "999999999\n",
   "21\n",
   "9\n",
   "7181\n",
   "36489\n",
   "861364152\n",
   "270\n",
   "330\n",
   "237\n",
   "210\n",
   "342\n",
   "285\n",
   "0\n",
   "114\n"
  ]
 },
 {
  "id": "APPS-3693",
  "question": "You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.\n\nThe interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.\n\n\n-----Input-----\n\nThe input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.\n\nThe first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees.\n\nAll the values are integer and between $-100$ and $100$.\n\n\n-----Output-----\n\nPrint \"Yes\" if squares intersect, otherwise print \"No\".\n\nYou can print each letter in any case (upper or lower).\n\n\n-----Examples-----\nInput\n0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n\nOutput\nYES\n\nInput\n0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n\nOutput\nNO\n\nInput\n6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n\nOutput\nYES\n\n\n\n-----Note-----\n\nIn the first example the second square lies entirely within the first square, so they do intersect.\n\nIn the second sample squares do not have any points in common.\n\nHere are images corresponding to the samples: [Image]  [Image]  [Image]",
  "inputs": [
   "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n",
   "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n",
   "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n",
   "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8\n",
   "2 2 4 2 4 4 2 4\n0 3 3 6 6 3 3 0\n",
   "-5 -5 5 -5 5 5 -5 5\n-5 7 0 2 5 7 0 12\n",
   "-5 -5 5 -5 5 5 -5 5\n-5 12 0 7 5 12 0 17\n",
   "-5 -5 5 -5 5 5 -5 5\n6 0 0 6 -6 0 0 -6\n",
   "-100 -100 100 -100 100 100 -100 100\n-100 0 0 -100 100 0 0 100\n",
   "92 1 92 98 -5 98 -5 1\n44 60 56 48 44 36 32 48\n",
   "-12 -54 -12 33 -99 33 -99 -54\n-77 -40 -86 -31 -77 -22 -68 -31\n",
   "3 45 19 45 19 61 3 61\n-29 45 -13 29 3 45 -13 61\n",
   "79 -19 79 15 45 15 45 -19\n-1 24 -29 52 -1 80 27 52\n",
   "75 -57 75 -21 39 -21 39 -57\n10 -42 -32 0 10 42 52 0\n",
   "-11 53 9 53 9 73 -11 73\n-10 9 -43 42 -10 75 23 42\n",
   "-10 -36 -10 27 -73 27 -73 -36\n44 -28 71 -55 44 -82 17 -55\n",
   "-63 -15 6 -15 6 54 -63 54\n15 -13 -8 10 15 33 38 10\n",
   "47 15 51 15 51 19 47 19\n19 0 -27 46 19 92 65 46\n",
   "87 -5 87 79 3 79 3 -5\n36 36 78 -6 36 -48 -6 -6\n",
   "-4 56 10 56 10 70 -4 70\n-11 47 -35 71 -11 95 13 71\n",
   "-41 6 -41 8 -43 8 -43 6\n-7 27 43 -23 -7 -73 -57 -23\n",
   "44 -58 44 7 -21 7 -21 -58\n22 19 47 -6 22 -31 -3 -6\n",
   "-37 -63 49 -63 49 23 -37 23\n-52 68 -21 37 -52 6 -83 37\n",
   "93 20 93 55 58 55 58 20\n61 -17 39 5 61 27 83 5\n",
   "-7 4 -7 58 -61 58 -61 4\n-28 45 -17 34 -28 23 -39 34\n"
  ],
  "outputs": [
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n"
  ]
 },
 {
  "id": "APPS-3752",
  "question": "Julia is going to cook a chicken in the kitchen of her dormitory. To save energy, the stove in the kitchen automatically turns off after k minutes after turning on.\n\nDuring cooking, Julia goes to the kitchen every d minutes and turns on the stove if it is turned off. While the cooker is turned off, it stays warm. The stove switches on and off instantly.\n\nIt is known that the chicken needs t minutes to be cooked on the stove, if it is turned on, and 2t minutes, if it is turned off. You need to find out, how much time will Julia have to cook the chicken, if it is considered that the chicken is cooked evenly, with constant speed when the stove is turned on and at a constant speed when it is turned off.\n\n\n-----Input-----\n\nThe single line contains three integers k, d and t (1 ≤ k, d, t ≤ 10^18).\n\n\n-----Output-----\n\nPrint a single number, the total time of cooking in minutes. The relative or absolute error must not exceed 10^{ - 9}.\n\nNamely, let's assume that your answer is x and the answer of the jury is y. The checker program will consider your answer correct if $\\frac{|x - y|}{\\operatorname{max}(1, y)} \\leq 10^{-9}$.\n\n\n-----Examples-----\nInput\n3 2 6\n\nOutput\n6.5\n\nInput\n4 2 20\n\nOutput\n20.0\n\n\n\n-----Note-----\n\nIn the first example, the chicken will be cooked for 3 minutes on the turned on stove, after this it will be cooked for $\\frac{3}{6}$. Then the chicken will be cooked for one minute on a turned off stove, it will be cooked for $\\frac{1}{12}$. Thus, after four minutes the chicken will be cooked for $\\frac{3}{6} + \\frac{1}{12} = \\frac{7}{12}$. Before the fifth minute Julia will turn on the stove and after 2.5 minutes the chicken will be ready $\\frac{7}{12} + \\frac{2.5}{6} = 1$.\n\nIn the second example, when the stove is turned off, Julia will immediately turn it on, so the stove will always be turned on and the chicken will be cooked in 20 minutes.",
  "inputs": [
   "3 2 6\n",
   "4 2 20\n",
   "8 10 9\n",
   "43 50 140\n",
   "251 79 76\n",
   "892 67 1000\n",
   "1000 1000 1000\n",
   "87 4 1000\n",
   "1 629 384378949109878497\n",
   "2124 6621 12695\n",
   "27548 68747 111\n",
   "74974 46016 1000000000\n",
   "223 844 704\n",
   "1 558 743\n",
   "43 387 402\n",
   "972 2 763\n",
   "330 167 15\n",
   "387 43 650\n",
   "1 314 824\n",
   "2 4 18\n",
   "3 5 127\n",
   "3260 4439 6837\n",
   "3950 7386 195\n",
   "18036 47899 1000000000\n",
   "29 46 1000000000\n"
  ],
  "outputs": [
   "6.5\n",
   "20.0\n",
   "10.0\n",
   "150.5\n",
   "76.0\n",
   "1023.0\n",
   "1000.0\n",
   "1005.5\n",
   "767537647587662141\n",
   "19018\n",
   "111.0\n",
   "1102134775.0\n",
   "1014.5\n",
   "1483\n",
   "718\n",
   "763.0\n",
   "15.0\n",
   "650.0\n",
   "1642\n",
   "24.0\n",
   "158.0\n",
   "7426.5\n",
   "195.0\n",
   "1452914012\n",
   "1226666661.0\n"
  ]
 },
 {
  "id": "APPS-3863",
  "question": "Takahashi and Aoki are going to together construct a sequence of integers.\nFirst, Takahashi will provide a sequence of integers a, satisfying all of the following conditions:\n - The length of a is N.\n - Each element in a is an integer between 1 and K, inclusive.\n - a is a palindrome, that is, reversing the order of elements in a will result in the same sequence as the original.\nThen, Aoki will perform the following operation an arbitrary number of times:\n - Move the first element in a to the end of a.\nHow many sequences a can be obtained after this procedure, modulo 10^9+7?\n\n-----Constraints-----\n - 1≤N≤10^9\n - 1≤K≤10^9\n\n-----Input-----\nThe input is given from Standard Input in the following format:\nN K\n\n-----Output-----\nPrint the number of the sequences a that can be obtained after the procedure, modulo 10^9+7.\n\n-----Sample Input-----\n4 2\n\n-----Sample Output-----\n6\n\nThe following six sequences can be obtained:\n - (1, 1, 1, 1)\n - (1, 1, 2, 2)\n - (1, 2, 2, 1)\n - (2, 2, 1, 1)\n - (2, 1, 1, 2)\n - (2, 2, 2, 2)",
  "inputs": [
   "4 2\n",
   "1 10\n",
   "6 3\n",
   "1000000000 1000000000\n",
   "1 1\n",
   "1 1000000000\n",
   "1000000000 1\n",
   "1 660938501\n",
   "2 61108425\n",
   "3 563031691\n",
   "4 989494029\n",
   "1000000000 146388030\n",
   "1000000000 121963892\n",
   "1000000000 33979032\n",
   "1000000000 153662193\n",
   "999950884 4763832\n",
   "999950884 439471894\n",
   "999950884 562114809\n",
   "999950884 829327194\n",
   "735134400 809627511\n",
   "735134400 684047352\n",
   "735134400 40516377\n",
   "735134400 789009986\n",
   "698377680 872551324\n",
   "698377680 370909028\n"
  ],
  "outputs": [
   "6\n",
   "10\n",
   "75\n",
   "875699961\n",
   "1\n",
   "1000000000\n",
   "1\n",
   "660938501\n",
   "61108425\n",
   "427796732\n",
   "156433689\n",
   "329875629\n",
   "419967204\n",
   "563046250\n",
   "749048454\n",
   "121031764\n",
   "463969172\n",
   "881550795\n",
   "369714198\n",
   "64879363\n",
   "332341683\n",
   "580070139\n",
   "122155644\n",
   "815976601\n",
   "315179999\n"
  ]
 },
 {
  "id": "APPS-3954",
  "question": "As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:\n\n$f(a, l, r) = \\sum_{i = l}^{r} a [ i ] ; m(a) = \\operatorname{max}_{1 \\leq l \\leq r \\leq n} f(a, l, r)$\n\nA swap operation is the following sequence of actions:\n\n  choose two indexes i, j (i ≠ j);  perform assignments tmp = a[i], a[i] = a[j], a[j] = tmp. \n\nWhat maximum value of function m(a) can Sereja get if he is allowed to perform at most k swap operations?\n\n\n-----Input-----\n\nThe first line contains two integers n and k (1 ≤ n ≤ 200; 1 ≤ k ≤ 10). The next line contains n integers a[1], a[2], ..., a[n] ( - 1000 ≤ a[i] ≤ 1000).\n\n\n-----Output-----\n\nIn a single line print the maximum value of m(a) that Sereja can get if he is allowed to perform at most k swap operations.\n\n\n-----Examples-----\nInput\n10 2\n10 -1 2 2 2 2 2 2 -1 10\n\nOutput\n32\n\nInput\n5 10\n-1 -1 -1 -1 -1\n\nOutput\n-1",
  "inputs": [
   "10 2\n10 -1 2 2 2 2 2 2 -1 10\n",
   "5 10\n-1 -1 -1 -1 -1\n",
   "18 1\n166 788 276 -103 -491 195 -960 389 376 369 630 285 3 575 315 -987 820 466\n",
   "29 6\n-21 486 -630 -433 -123 -387 618 110 -203 55 -123 524 -168 662 432 378 -155 -136 -162 811 457 -157 -215 861 -565 -506 557 348 -7\n",
   "9 9\n-767 148 -323 -818 41 -228 615 885 -260\n",
   "35 5\n151 -160 -292 -31 -131 174 359 42 438 413 164 91 118 393 76 435 371 -76 145 605 292 578 623 405 664 330 455 329 66 168 179 -76 996 163 531\n",
   "47 10\n-175 246 -903 681 748 -338 333 0 666 245 370 402 -38 682 144 658 -10 313 295 351 -95 149 111 -210 645 -173 -276 690 593 697 259 698 421 584 -229 445 -215 -203 49 642 386 649 469 4 340 484 279\n",
   "11 7\n877 -188 10 -175 217 -254 841 380 552 -607 228\n",
   "38 1\n173 587 -788 163 83 -768 461 -527 350 3 -898 634 -217 -528 317 -238 545 93 -964 283 -798 -596 77 222 -370 -209 61 846 -831 -419 -366 -509 -356 -649 916 -391 981 -596\n",
   "6 9\n-669 45 -220 544 106 680\n",
   "32 9\n-650 -208 506 812 -540 -275 -272 -236 -96 197 425 475 81 570 281 633 449 396 401 -362 -379 667 717 875 658 114 294 100 286 112 -928 -373\n",
   "36 5\n-286 762 -5 -230 -483 -140 -143 -82 -127 449 435 85 -262 567 454 -163 942 -679 -609 854 -533 717 -101 92 -767 795 -804 -953 -754 -251 -100 884 809 -358 469 -112\n",
   "24 5\n-751 889 721 -900 903 -900 -693 895 828 314 836 -493 549 -74 264 662 229 517 -223 367 141 -99 -390 283\n",
   "82 8\n-483 465 435 -789 80 -412 672 512 -755 981 784 -281 -634 -270 806 887 -495 -46 -244 609 42 -821 100 -40 -299 -6 560 941 523 758 -730 -930 91 -138 -299 0 533 -208 -416 869 967 -871 573 165 -279 298 934 -236 70 800 550 433 139 147 139 -212 137 -933 -863 876 -622 193 -121 -944 983 -592 -40 -712 891 985 16 580 -845 -903 -986 952 -95 -613 -2 -45 -86 -206\n",
   "116 10\n477 -765 -756 376 -48 -75 768 -658 263 -207 362 -535 96 -960 630 -686 609 -830 889 57 -239 346 -298 -18 -107 853 -607 -443 -517 371 657 105 479 498 -47 432 503 -917 -656 610 -466 216 -747 -587 -163 -174 493 -882 853 -582 -774 -477 -386 610 -58 557 968 196 69 610 -38 366 -79 574 170 317 332 189 158 -194 136 -151 500 309 624 316 543 472 132 -15 -78 166 360 -71 12 247 678 263 573 -198 1 101 155 -65 597 -93 60 3 -496 985 -586 -761 -532 506 578 -13 569 845 -341 870 -900 891 724 408 229 -210\n",
   "110 4\n-813 -73 334 667 602 -155 432 -133 689 397 461 499 630 40 69 299 697 449 -130 210 -146 415 292 123 12 -105 444 338 509 497 142 688 603 107 -108 160 211 -215 219 -144 637 -173 615 -210 521 545 377 -6 -187 354 647 309 139 309 155 -242 546 -231 -267 405 411 -271 -149 264 -169 -447 -749 -218 273 -798 -135 839 54 -764 279 -578 -641 -152 -881 241 174 31 525 621 -855 656 482 -197 -402 995 785 338 -733 293 606 294 -645 262 909 325 -246 -952 408 646 2 -567 -484 661 -390 -488\n",
   "94 2\n432 255 304 757 -438 52 461 55 837 -564 304 713 -968 -539 -593 835 -824 -532 38 -880 -772 480 -755 -387 -830 286 -38 -202 -273 423 272 471 -224 306 490 532 -210 -245 -20 680 -236 404 -5 -188 387 582 -30 -800 276 -811 240 -4 214 -708 200 -785 -466 61 16 -742 647 -371 -851 -295 -552 480 38 924 403 704 -705 -972 677 569 450 446 816 396 -179 281 -564 -27 -272 -640 809 29 28 -209 -925 997 -268 133 265 161\n",
   "78 8\n-230 -757 673 -284 381 -324 -96 975 249 971 -355 186 -526 804 147 -553 655 263 -247 775 108 -246 -107 25 -786 -372 -24 -619 265 -192 269 392 210 449 335 -207 371 562 307 141 668 78 13 251 623 -238 60 543 618 201 73 -35 -663 620 485 444 330 362 -33 484 685 257 542 375 -952 48 -604 -288 -19 -718 -798 946 -533 -666 -686 -278 368 -294\n",
   "1 10\n-1\n",
   "1 1\n-1\n",
   "1 1\n1\n",
   "1 10\n1\n",
   "10 1\n-1 1 1 1 1 1 1 1 1 1\n"
  ],
  "outputs": [
   "32\n",
   "-1\n",
   "5016\n",
   "6299\n",
   "1689\n",
   "9754\n",
   "14728\n",
   "3105\n",
   "2743\n",
   "1375\n",
   "9049\n",
   "8222\n",
   "8398\n",
   "18704\n",
   "24624\n",
   "20286\n",
   "7839\n",
   "17941\n",
   "-1\n",
   "-1\n",
   "1\n",
   "1\n",
   "9\n"
  ]
 },
 {
  "id": "APPS-3996",
  "question": "As we all know Barney's job is \"PLEASE\" and he has not much to do at work. That's why he started playing \"cups and key\". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. [Image] \n\nThen at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start.\n\nAfter n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right.\n\nNumber n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a_1, a_2, ..., a_{k} such that  $n = \\prod_{i = 1}^{k} a_{i}$ \n\nin other words, n is multiplication of all elements of the given array.\n\nBecause of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that $\\operatorname{gcd}(p, q) = 1$, where $gcd$ is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 10^9 + 7.\n\nPlease note that we want $gcd$ of p and q to be 1, not $gcd$ of their remainders after dividing by 10^9 + 7.\n\n\n-----Input-----\n\nThe first line of input contains a single integer k (1 ≤ k ≤ 10^5) — the number of elements in array Barney gave you.\n\nThe second line contains k integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ 10^18) — the elements of the array.\n\n\n-----Output-----\n\nIn the only line of output print a single string x / y where x is the remainder of dividing p by 10^9 + 7 and y is the remainder of dividing q by 10^9 + 7.\n\n\n-----Examples-----\nInput\n1\n2\n\nOutput\n1/2\n\nInput\n3\n1 1 1\n\nOutput\n0/1",
  "inputs": [
   "1\n2\n",
   "3\n1 1 1\n",
   "1\n983155795040951739\n",
   "2\n467131402341701583 956277077729692725\n",
   "10\n217673221404542171 806579927281665969 500754531396239406 214319484250163112 328494187336342674 427465830578952934 951554014286436941 664022909283791499 653206814724654845 66704816231807388\n",
   "8\n137264686188377169 524477139880847337 939966121107073137 244138018261712937 158070587508987781 35608416591331673 378899027510195451 81986819972451999\n",
   "9\n174496219779575399 193634487267697117 972518022554199573 695317701399937273 464007855398119159 881020180696239657 296973121744507377 544232692627163469 751214074246742731\n",
   "12\n254904759290707697 475737283258450340 533306428548398547 442127134828578937 779740159015946254 272877594683860919 93000149670491971 349640818793278778 498293278222136720 551099726729989816 149940343283925029 989425634209891686\n",
   "1\n1\n",
   "1\n1000000000000000000\n",
   "1\n3\n",
   "1\n1000000006\n",
   "2\n500000004 1000000006\n",
   "1\n500000004\n",
   "2\n500000004 500000004\n",
   "1\n500000003\n",
   "2\n500000003 500000004\n",
   "2\n500000003 500000003\n",
   "1\n1000000005\n",
   "2\n1000000005 500000004\n"
  ],
  "outputs": [
   "1/2\n",
   "0/1\n",
   "145599903/436799710\n",
   "63467752/190403257\n",
   "896298678/688896019\n",
   "993002178/979006521\n",
   "149736910/449210731\n",
   "674872752/24618241\n",
   "0/1\n",
   "453246046/359738130\n",
   "1/4\n",
   "500000004/500000004\n",
   "500000004/500000004\n",
   "666666672/1\n",
   "666666672/1\n",
   "833333339/500000004\n",
   "500000004/500000004\n",
   "833333339/500000004\n",
   "750000005/250000002\n",
   "416666670/250000002\n"
  ]
 },
 {
  "id": "APPS-3716",
  "question": "Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.\n\nBut I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than n. Can you help me to find the maximum possible least common multiple of these three integers?\n\n\n-----Input-----\n\nThe first line contains an integer n (1 ≤ n ≤ 10^6) — the n mentioned in the statement.\n\n\n-----Output-----\n\nPrint a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than n.\n\n\n-----Examples-----\nInput\n9\n\nOutput\n504\n\nInput\n7\n\nOutput\n210\n\n\n\n-----Note-----\n\nThe least common multiple of some positive integers is the least positive integer which is multiple for each of them.\n\nThe result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.\n\nFor the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get.",
  "inputs": [
   "9\n",
   "7\n",
   "1\n",
   "5\n",
   "6\n",
   "33\n",
   "21\n",
   "2\n",
   "41\n",
   "29\n",
   "117\n",
   "149\n",
   "733\n",
   "925\n",
   "509\n",
   "829\n",
   "117\n",
   "605\n",
   "245\n",
   "925\n",
   "213\n",
   "53\n",
   "341\n",
   "21\n",
   "605\n"
  ],
  "outputs": [
   "504\n",
   "210\n",
   "1\n",
   "60\n",
   "60\n",
   "32736\n",
   "7980\n",
   "2\n",
   "63960\n",
   "21924\n",
   "1560780\n",
   "3241644\n",
   "392222436\n",
   "788888100\n",
   "131096004\n",
   "567662724\n",
   "1560780\n",
   "220348260\n",
   "14526540\n",
   "788888100\n",
   "9527916\n",
   "140556\n",
   "39303660\n",
   "7980\n",
   "220348260\n"
  ]
 },
 {
  "id": "APPS-3838",
  "question": "Little Petya likes permutations a lot. Recently his mom has presented him permutation q_1, q_2, ..., q_{n} of length n.\n\nA permutation a of length n is a sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n), all integers there are distinct. \n\nThere is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length n. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:  Before the beginning of the game Petya writes permutation 1, 2, ..., n on the blackboard. After that Petya makes exactly k moves, which are described below.  During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2.  Let's assume that the board contains permutation p_1, p_2, ..., p_{n} at the given moment. Then Petya removes the written permutation p from the board and writes another one instead: p_{q}_1, p_{q}_2, ..., p_{q}_{n}. In other words, Petya applies permutation q (which he has got from his mother) to permutation p.  All actions are similar to point 1, except that Petya writes permutation t on the board, such that: t_{q}_{i} = p_{i} for all i from 1 to n. In other words, Petya applies a permutation that is inverse to q to permutation p. \n\nWe know that after the k-th move the board contained Masha's permutation s_1, s_2, ..., s_{n}. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the k-th move. Note that the game has exactly k moves, that is, throughout the game the coin was tossed exactly k times.\n\nYour task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.\n\n\n-----Input-----\n\nThe first line contains two integers n and k (1 ≤ n, k ≤ 100). The second line contains n space-separated integers q_1, q_2, ..., q_{n} (1 ≤ q_{i} ≤ n) — the permutation that Petya's got as a present. The third line contains Masha's permutation s, in the similar format.\n\nIt is guaranteed that the given sequences q and s are correct permutations.\n\n\n-----Output-----\n\nIf the situation that is described in the statement is possible, print \"YES\" (without the quotes), otherwise print \"NO\" (without the quotes).\n\n\n-----Examples-----\nInput\n4 1\n2 3 4 1\n1 2 3 4\n\nOutput\nNO\n\nInput\n4 1\n4 3 1 2\n3 4 2 1\n\nOutput\nYES\n\nInput\n4 3\n4 3 1 2\n3 4 2 1\n\nOutput\nYES\n\nInput\n4 2\n4 3 1 2\n2 1 4 3\n\nOutput\nYES\n\nInput\n4 1\n4 3 1 2\n2 1 4 3\n\nOutput\nNO\n\n\n\n-----Note-----\n\nIn the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before k moves were performed.\n\nIn the second sample the described situation is possible, in case if after we toss a coin, we get tails.\n\nIn the third sample the possible coin tossing sequence is: heads-tails-tails.\n\nIn the fourth sample the possible coin tossing sequence is: heads-heads.",
  "inputs": [
   "4 1\n2 3 4 1\n1 2 3 4\n",
   "4 1\n4 3 1 2\n3 4 2 1\n",
   "4 3\n4 3 1 2\n3 4 2 1\n",
   "4 2\n4 3 1 2\n2 1 4 3\n",
   "4 1\n4 3 1 2\n2 1 4 3\n",
   "4 3\n4 3 1 2\n2 1 4 3\n",
   "4 3\n2 1 4 3\n4 3 1 2\n",
   "4 1\n2 1 4 3\n2 1 4 3\n",
   "4 2\n2 1 4 3\n2 1 4 3\n",
   "4 2\n2 3 4 1\n1 2 3 4\n",
   "5 3\n2 1 4 3 5\n2 1 4 3 5\n",
   "9 10\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9\n",
   "8 10\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8\n",
   "8 9\n2 3 1 5 6 7 8 4\n2 3 1 4 5 6 7 8\n",
   "10 10\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9\n",
   "10 9\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9\n",
   "10 100\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9\n",
   "10 99\n2 3 1 5 6 7 8 4 10 9\n2 3 1 4 5 6 7 8 10 9\n",
   "9 100\n2 3 1 5 6 7 8 9 4\n2 3 1 4 5 6 7 8 9\n",
   "5 99\n2 1 4 3 5\n2 1 4 3 5\n",
   "5 1\n2 1 4 3 5\n2 1 4 3 5\n",
   "55 30\n51 43 20 22 50 48 35 6 49 7 52 29 34 45 9 55 47 36 41 54 1 4 39 46 25 26 12 28 14 3 33 23 11 2 53 8 40 32 13 37 19 16 18 42 27 31 17 44 30 24 15 38 10 21 5\n30 31 51 22 43 32 10 38 54 53 44 12 24 14 20 34 47 11 41 15 49 4 5 36 25 26 27 28 29 1 6 55 48 46 7 52 40 16 50 37 19 13 33 39 45 8 17 23 21 18 3 42 35 9 2\n",
   "55 30\n32 37 9 26 13 6 44 1 2 38 11 12 36 49 10 46 5 21 43 24 28 31 15 51 55 27 29 18 41 17 20 8 45 16 52 30 39 53 3 35 19 33 50 54 47 34 48 14 4 42 22 40 23 25 7\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55\n",
   "55 28\n25 13 15 37 5 7 42 9 50 8 14 21 3 30 29 38 1 51 52 20 16 27 6 41 48 4 49 32 2 44 55 10 33 34 54 23 40 26 12 31 39 28 43 46 53 19 22 35 36 47 24 17 11 45 18\n17 29 13 26 5 23 6 10 8 32 53 39 2 11 3 21 52 55 46 20 12 47 36 51 1 38 22 42 15 14 40 28 33 34 48 49 4 16 41 37 24 7 43 30 54 44 50 25 27 9 18 19 45 35 31\n",
   "55 28\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26\n34 11 18 6 16 43 12 25 48 27 35 17 19 14 33 30 7 53 52 2 15 10 44 1 37 28 22 49 46 8 45 39 21 47 40 20 41 51 13 24 42 55 23 4 36 38 50 31 3 9 54 32 5 29 26\n"
  ],
  "outputs": [
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n"
  ]
 },
 {
  "id": "APPS-3848",
  "question": "Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more.\n\nPaul has found a tolerable string s of length n. Help him find the lexicographically next tolerable string of the same length or else state that such string does not exist.\n\n\n-----Input-----\n\nThe first line contains two space-separated integers: n and p (1 ≤ n ≤ 1000; 1 ≤ p ≤ 26). The second line contains string s, consisting of n small English letters. It is guaranteed that the string is tolerable (according to the above definition).\n\n\n-----Output-----\n\nIf the lexicographically next tolerable string of the same length exists, print it. Otherwise, print \"NO\" (without the quotes).\n\n\n-----Examples-----\nInput\n3 3\ncba\n\nOutput\nNO\n\nInput\n3 4\ncba\n\nOutput\ncbd\n\nInput\n4 4\nabcd\n\nOutput\nabda\n\n\n\n-----Note-----\n\nString s is lexicographically larger (or simply larger) than string t with the same length, if there is number i, such that s_1 = t_1, ..., s_{i} = t_{i}, s_{i} + 1 > t_{i} + 1.\n\nThe lexicographically next tolerable string is the lexicographically minimum tolerable string which is larger than the given one.\n\nA palindrome is a string that reads the same forward or reversed.",
  "inputs": [
   "3 3\ncba\n",
   "3 4\ncba\n",
   "4 4\nabcd\n",
   "2 2\nab\n",
   "2 2\nba\n",
   "1 2\na\n",
   "1 2\nb\n",
   "1 1\na\n",
   "3 4\ncdb\n",
   "7 26\nzyxzyxz\n",
   "10 5\nabcabcabca\n",
   "10 10\nfajegfaicb\n",
   "1 26\no\n",
   "1 2\nb\n",
   "1 26\nz\n",
   "3 3\ncab\n",
   "3 26\nyzx\n",
   "5 5\naceba\n",
   "10 3\ncbacbacbac\n",
   "11 3\nabcabcabcab\n",
   "12 10\nabcabcabcabc\n",
   "13 7\ngfegfegfegfeg\n",
   "15 11\ncgjkbadjfbdaikj\n",
   "17 4\ndabcadcbdcadbcdbc\n",
   "26 26\nahnxdnbfcriersyzdihuecojdi\n"
  ],
  "outputs": [
   "NO\n",
   "cbd\n",
   "abda\n",
   "ba\n",
   "NO\n",
   "b\n",
   "NO\n",
   "NO\n",
   "dab\n",
   "NO\n",
   "abcabcabcd\n",
   "fajegfaicd\n",
   "p\n",
   "NO\n",
   "NO\n",
   "cba\n",
   "zab\n",
   "acebc\n",
   "NO\n",
   "acbacbacbac\n",
   "abcabcabcabd\n",
   "NO\n",
   "cgjkbadjfbdajba\n",
   "dabcadcbdcadcabca\n",
   "ahnxdnbfcriersyzdihuecojdk\n"
  ]
 },
 {
  "id": "APPS-3929",
  "question": "Snuke has decided to play with N cards and a deque (that is, a double-ended queue).\nEach card shows an integer from 1 through N, and the deque is initially empty.\nSnuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N.\nThen, he will perform the following action N times: take out the card from the beginning or the end of the deque and eat it.\nAfterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the K-th element is 1. Print the answer modulo 10^{9} + 7.\n\n-----Constraints-----\n - 1 ≦ K ≦ N ≦ 2{,}000\n\n-----Input-----\nThe input is given from Standard Input in the following format:\nN K\n\n-----Output-----\nPrint the answer modulo 10^{9} + 7.\n\n-----Sample Input-----\n2 1\n\n-----Sample Output-----\n1\n\nThere is one sequence satisfying the condition: 1,2. One possible way to obtain this sequence is the following:\n - Insert both cards, 1 and 2, at the end of the deque.\n - Eat the card at the beginning of the deque twice.",
  "inputs": [
   "2 1\n",
   "17 2\n",
   "2000 1000\n",
   "12 4\n",
   "1058 839\n",
   "36 36\n",
   "177 115\n",
   "1 1\n",
   "4 1\n",
   "18 7\n",
   "44 24\n",
   "1899 1672\n",
   "11 5\n",
   "13 13\n",
   "1862 1782\n",
   "151 51\n",
   "1981 668\n",
   "536 485\n",
   "1999 686\n",
   "2000 546\n",
   "1999 1223\n",
   "2000 1073\n",
   "1999 464\n",
   "1 1\n",
   "2000 2000\n"
  ],
  "outputs": [
   "1\n",
   "262144\n",
   "674286644\n",
   "34944\n",
   "176907232\n",
   "93302951\n",
   "912372337\n",
   "1\n",
   "4\n",
   "68913152\n",
   "228560302\n",
   "28208936\n",
   "20384\n",
   "208012\n",
   "833498751\n",
   "929507120\n",
   "523694290\n",
   "419105982\n",
   "569569444\n",
   "403479603\n",
   "472460308\n",
   "303581106\n",
   "419882148\n",
   "1\n",
   "319838403\n"
  ]
 },
 {
  "id": "APPS-3984",
  "question": "Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $s$ and a number $k$ ($0 \\le k < |s|$).\n\nAt the beginning of the game, players are given a substring of $s$ with left border $l$ and right border $r$, both equal to $k$ (i.e. initially $l=r=k$). Then players start to make moves one by one, according to the following rules: A player chooses $l^{\\prime}$ and $r^{\\prime}$ so that $l^{\\prime} \\le l$, $r^{\\prime} \\ge r$ and $s[l^{\\prime}, r^{\\prime}]$ is lexicographically less than $s[l, r]$. Then the player changes $l$ and $r$ in this way: $l := l^{\\prime}$, $r := r^{\\prime}$. Ann moves first. The player, that can't make a move loses.\n\nRecall that a substring $s[l, r]$ ($l \\le r$) of a string $s$ is a continuous segment of letters from s that starts at position $l$ and ends at position $r$. For example, \"ehn\" is a substring ($s[3, 5]$) of \"aaaehnsvz\" and \"ahz\" is not.\n\nMike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $s$ and $k$.\n\nUnfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $s$ and determines the winner for all possible $k$.\n\n\n-----Input-----\n\nThe first line of the input contains a single string $s$ ($1 \\leq |s| \\leq 5 \\cdot 10^5$) consisting of lowercase English letters.\n\n\n-----Output-----\n\nPrint $|s|$ lines.\n\nIn the line $i$ write the name of the winner (print Mike or Ann) in the game with string $s$ and $k = i$, if both play optimally\n\n\n-----Examples-----\nInput\nabba\n\nOutput\nMike\nAnn\nAnn\nMike\n\nInput\ncba\n\nOutput\nMike\nMike\nMike",
  "inputs": [
   "abba\n",
   "cba\n",
   "abacaba\n",
   "a\n",
   "abacabadabacabaeabacabadabacaba\n",
   "abcdefghijklmnopqrstuvwxyz\n",
   "dequudpveoozswafkmdadrxtnmagtpcdqzhxkitrbqytichoswltzzasfoeqktomxlypvhjyjnjymvlrvglvyursfm\n",
   "bt\n",
   "ctjfjfilqa\n",
   "ww\n",
   "nsfsgfs\n",
   "igiggr\n",
   "aabdbddcaabbcccabcbadadbbcddcbbdbbaadcbcdabdccbadbacdbbdcdbbccacca\n",
   "lbkgircdbr\n",
   "zhh\n",
   "qrwrere\n",
   "aaab\n",
   "dyqyq\n",
   "okdudu\n",
   "aaaa\n"
  ],
  "outputs": [
   "Mike\nAnn\nAnn\nMike\n",
   "Mike\nMike\nMike\n",
   "Mike\nAnn\nMike\nAnn\nMike\nAnn\nMike\n",
   "Mike\n",
   "Mike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\nAnn\nMike\n",
   "Mike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\n",
   "Mike\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\n",
   "Mike\nAnn\n",
   "Mike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\n",
   "Mike\nMike\n",
   "Mike\nAnn\nMike\nAnn\nAnn\nMike\nAnn\n",
   "Mike\nMike\nAnn\nMike\nMike\nAnn\n",
   "Mike\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nMike\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\nAnn\nMike\n",
   "Mike\nMike\nAnn\nAnn\nAnn\nAnn\nAnn\nAnn\nMike\nAnn\n",
   "Mike\nMike\nMike\n",
   "Mike\nAnn\nAnn\nAnn\nMike\nAnn\nMike\n",
   "Mike\nMike\nMike\nAnn\n",
   "Mike\nAnn\nAnn\nAnn\nAnn\n",
   "Mike\nMike\nMike\nAnn\nMike\nAnn\n",
   "Mike\nMike\nMike\nMike\n"
  ]
 },
 {
  "id": "APPS-3707",
  "question": "In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take d minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.\n\nDetermine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get n cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.\n\n\n-----Input-----\n\nThe only line contains four integers n, t, k, d (1 ≤ n, t, k, d ≤ 1 000) — the number of cakes needed, the time needed for one oven to bake k cakes, the number of cakes baked at the same time, the time needed to build the second oven. \n\n\n-----Output-----\n\nIf it is reasonable to build the second oven, print \"YES\". Otherwise print \"NO\".\n\n\n-----Examples-----\nInput\n8 6 4 5\n\nOutput\nYES\n\nInput\n8 6 4 6\n\nOutput\nNO\n\nInput\n10 3 11 4\n\nOutput\nNO\n\nInput\n4 2 1 4\n\nOutput\nYES\n\n\n\n-----Note-----\n\nIn the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. \n\nIn the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.\n\nIn the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.",
  "inputs": [
   "8 6 4 5\n",
   "8 6 4 6\n",
   "10 3 11 4\n",
   "4 2 1 4\n",
   "28 17 16 26\n",
   "60 69 9 438\n",
   "599 97 54 992\n",
   "11 22 18 17\n",
   "1 13 22 11\n",
   "1 1 1 1\n",
   "3 1 1 1\n",
   "1000 1000 1000 1000\n",
   "1000 1000 1 1\n",
   "1000 1000 1 400\n",
   "1000 1000 1 1000\n",
   "1000 1000 1 999\n",
   "53 11 3 166\n",
   "313 2 3 385\n",
   "214 9 9 412\n",
   "349 9 5 268\n",
   "611 16 8 153\n",
   "877 13 3 191\n",
   "340 9 9 10\n",
   "31 8 2 205\n",
   "519 3 2 148\n"
  ],
  "outputs": [
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "YES\n"
  ]
 },
 {
  "id": "APPS-3736",
  "question": "Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?\n\nThe market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.\n\nThere are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.\n\n\n-----Input-----\n\nThe first line contains a non-empty name that needs to be checked. The name contains at most 10^5 large English letters. The name will be written with the next sans serif font: $\\text{ABCDEFGHI JKLMNOPQRSTUVWXYZ}$\n\n\n-----Output-----\n\nPrint 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).\n\n\n-----Examples-----\nInput\nAHA\n\nOutput\nYES\n\nInput\nZ\n\nOutput\nNO\n\nInput\nXO\n\nOutput\nNO",
  "inputs": [
   "AHA\n",
   "Z\n",
   "XO\n",
   "AAA\n",
   "AHHA\n",
   "BAB\n",
   "OMMMAAMMMO\n",
   "YYHUIUGYI\n",
   "TT\n",
   "UUU\n",
   "WYYW\n",
   "MITIM\n",
   "VO\n",
   "WWS\n",
   "VIYMAXXAVM\n",
   "OVWIHIWVYXMVAAAATOXWOIUUHYXHIHHVUIOOXWHOXTUUMUUVHVWWYUTIAUAITAOMHXWMTTOIVMIVOTHOVOIOHYHAOXWAUVWAVIVM\n",
   "CC\n",
   "QOQ\n",
   "AEEA\n",
   "OQQQO\n",
   "HNCMEEMCNH\n",
   "QDPINBMCRFWXPDBFGOZVVOCEMJRUCTOADEWEGTVBVBFWWRPGYEEYGPRWWFBVBVTGEWEDAOTCURJMECOVVZOGFBDPXWFRCMBNIPDQ\n",
   "A\n",
   "B\n",
   "C\n"
  ],
  "outputs": [
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n"
  ]
 },
 {
  "id": "APPS-3977",
  "question": "Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.\n\nThe world can be modeled as an undirected graph with n nodes and m edges. k of the nodes are home to the governments of the k countries that make up the world.\n\nThere is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.\n\nHongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.\n\n\n-----Input-----\n\nThe first line of input will contain three integers n, m and k (1 ≤ n ≤ 1 000, 0 ≤ m ≤ 100 000, 1 ≤ k ≤ n) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government. \n\nThe next line of input will contain k integers c_1, c_2, ..., c_{k} (1 ≤ c_{i} ≤ n). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.\n\nThe following m lines of input will contain two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n). This denotes an undirected edge between nodes u_{i} and v_{i}.\n\nIt is guaranteed that the graph described by the input is stable.\n\n\n-----Output-----\n\nOutput a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.\n\n\n-----Examples-----\nInput\n4 1 2\n1 3\n1 2\n\nOutput\n2\n\nInput\n3 3 1\n2\n1 2\n1 3\n2 3\n\nOutput\n0\n\n\n\n-----Note-----\n\nFor the first sample test, the graph looks like this:  [Image]  Vertices 1 and 3 are special. The optimal solution is to connect vertex 4 to vertices 1 and 2. This adds a total of 2 edges. We cannot add any more edges, since vertices 1 and 3 cannot have any path between them.\n\nFor the second sample test, the graph looks like this:  $\\infty$  We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.",
  "inputs": [
   "4 1 2\n1 3\n1 2\n",
   "3 3 1\n2\n1 2\n1 3\n2 3\n",
   "10 3 2\n1 10\n1 2\n1 3\n4 5\n",
   "1 0 1\n1\n",
   "1000 0 1\n72\n",
   "24 38 2\n4 13\n7 1\n24 1\n2 8\n17 2\n2 18\n22 2\n23 3\n5 9\n21 5\n6 7\n6 19\n6 20\n11 7\n7 20\n13 8\n16 8\n9 10\n14 9\n21 9\n12 10\n10 22\n23 10\n17 11\n11 24\n20 12\n13 16\n13 23\n15 14\n17 14\n14 20\n19 16\n17 20\n17 23\n18 22\n18 23\n22 19\n21 20\n23 24\n",
   "10 30 1\n4\n1 2\n3 1\n4 1\n1 6\n1 8\n10 1\n2 4\n2 7\n3 4\n3 5\n7 3\n3 9\n10 3\n5 4\n6 4\n7 4\n9 4\n10 4\n6 5\n5 8\n9 5\n10 5\n6 7\n9 6\n10 6\n7 8\n9 7\n10 7\n9 8\n10 8\n",
   "10 13 2\n5 10\n2 1\n1 4\n2 3\n2 8\n3 4\n7 3\n4 6\n8 4\n4 9\n6 7\n6 9\n10 6\n7 8\n",
   "10 10 3\n2 5 6\n1 3\n4 1\n4 3\n5 3\n3 9\n8 4\n9 4\n5 10\n8 7\n10 8\n",
   "10 5 3\n1 5 9\n1 3\n1 8\n2 3\n8 4\n5 7\n",
   "6 4 2\n1 4\n1 2\n2 3\n4 5\n5 6\n",
   "7 8 2\n1 4\n1 2\n2 3\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7\n",
   "5 2 3\n1 3 4\n1 5\n2 4\n",
   "5 3 2\n1 2\n2 3\n2 4\n1 5\n",
   "9 5 2\n1 5\n1 2\n2 3\n3 4\n5 6\n6 7\n",
   "6 4 1\n1\n2 3\n3 4\n4 5\n5 6\n",
   "6 4 2\n1 5\n1 2\n2 3\n3 4\n5 6\n",
   "7 3 3\n1 5 6\n1 2\n1 3\n6 7\n",
   "5 2 2\n1 2\n1 3\n2 4\n",
   "11 7 2\n1 4\n1 2\n1 3\n4 5\n4 6\n5 6\n9 10\n1 11\n",
   "20 4 5\n1 3 9 10 20\n5 6\n1 2\n7 9\n4 10\n"
  ],
  "outputs": [
   "2\n",
   "0\n",
   "33\n",
   "0\n",
   "499500\n",
   "215\n",
   "15\n",
   "23\n",
   "18\n",
   "17\n",
   "2\n",
   "1\n",
   "0\n",
   "1\n",
   "13\n",
   "11\n",
   "3\n",
   "4\n",
   "2\n",
   "24\n",
   "89\n"
  ]
 },
 {
  "id": "APPS-3826",
  "question": "You are given an array $a_{1}, a_{2}, \\ldots, a_{n}$. You can remove at most one subsegment from it. The remaining elements should be pairwise distinct.\n\nIn other words, at most one time you can choose two integers $l$ and $r$ ($1 \\leq l \\leq r \\leq n$) and delete integers $a_l, a_{l+1}, \\ldots, a_r$ from the array. Remaining elements should be pairwise distinct. \n\nFind the minimum size of the subsegment you need to remove to make all remaining elements distinct.\n\n\n-----Input-----\n\nThe first line of the input contains a single integer $n$ ($1 \\le n \\le 2000$) — the number of elements in the given array.\n\nThe next line contains $n$ spaced integers $a_{1}, a_{2}, \\ldots, a_{n}$ ($1 \\le a_{i} \\le 10^{9}$) — the elements of the array. \n\n\n-----Output-----\n\nPrint a single integer — the minimum size of the subsegment you need to remove to make all elements of the array pairwise distinct. If no subsegment needs to be removed, print $0$.\n\n\n-----Examples-----\nInput\n3\n1 2 3\n\nOutput\n0\n\nInput\n4\n1 1 2 2\n\nOutput\n2\n\nInput\n5\n1 4 1 4 9\n\nOutput\n2\n\n\n\n-----Note-----\n\nIn the first example all the elements are already distinct, therefore no subsegment needs to be removed.\n\nIn the second example you can remove the subsegment from index $2$ to $3$.\n\nIn the third example you can remove the subsegments from index $1$ to $2$, or from index $2$ to $3$, or from index $3$ to $4$.",
  "inputs": [
   "3\n1 2 3\n",
   "4\n1 1 2 2\n",
   "5\n1 4 1 4 9\n",
   "10\n7 6 5 4 3 2 1 7 7 7\n",
   "1\n192901559\n",
   "2\n2 1\n",
   "8\n8 8 8 1 2 3 5 8\n",
   "12\n10 11 12 12 10 11 12 1 2 3 4 5\n",
   "10\n10 10 10 7 5 3 1 6 4 2\n",
   "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5\n",
   "23\n377591893 573551113 588143484 403344050 978839121 978839121 978839121 978839121 978839121 978839121 258460444 47026996 557747855 106846019 321206691 771678331 110479483 434020046 631317448 873248488 951781959 592552557 869237945\n",
   "10\n15 13 14 14 13 11 11 13 14 11\n",
   "10\n15 14 10 20 18 11 14 10 16 18\n",
   "87\n65 97 97 99 57 78 92 55 68 89 63 94 71 54 74 63 94 60 97 75 96 82 87 90 62 72 83 100 76 67 95 69 61 53 55 79 73 99 77 85 79 84 51 58 66 96 97 89 69 84 87 72 53 67 90 63 92 65 73 57 82 69 96 77 73 53 85 96 84 86 61 54 84 52 52 68 100 94 80 60 61 83 89 91 74 92 55\n",
   "9\n3 10 9 3 1 8 5 9 6\n",
   "9\n7 8 2 9 5 10 8 4 2\n",
   "12\n1 2 6 3 8 4 1 4 7 6 5 4\n",
   "8\n1 2 3 4 1 5 6 4\n",
   "12\n1 2 3 4 5 10 1 6 7 8 9 10\n",
   "8\n5 1 2 1 3 4 1 6\n",
   "10\n10 1 2 3 4 5 6 1 2 11\n",
   "10\n1 2 3 4 5 1 8 7 6 5\n",
   "13\n5 1 2 1 3 4 1 6 7 8 9 10 11\n",
   "8\n1 2 3 4 1 6 5 4\n",
   "10\n1 2 3 4 7 2 5 6 7 8\n"
  ],
  "outputs": [
   "0\n",
   "2\n",
   "2\n",
   "3\n",
   "0\n",
   "0\n",
   "3\n",
   "4\n",
   "2\n",
   "10\n",
   "5\n",
   "6\n",
   "4\n",
   "72\n",
   "2\n",
   "2\n",
   "5\n",
   "2\n",
   "2\n",
   "3\n",
   "2\n",
   "2\n",
   "3\n",
   "2\n",
   "2\n"
  ]
 },
 {
  "id": "APPS-3737",
  "question": "\"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come.\" — The Night's Watch oath.\n\nWith that begins the watch of Jon Snow. He is assigned the task to support the stewards.\n\nThis time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.\n\nCan you find how many stewards will Jon support?\n\n\n-----Input-----\n\nFirst line consists of a single integer n (1 ≤ n ≤ 10^5) — the number of stewards with Jon Snow.\n\nSecond line consists of n space separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) representing the values assigned to the stewards.\n\n\n-----Output-----\n\nOutput a single integer representing the number of stewards which Jon will feed.\n\n\n-----Examples-----\nInput\n2\n1 5\n\nOutput\n0\nInput\n3\n1 2 5\n\nOutput\n1\n\n\n-----Note-----\n\nIn the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.\n\nIn the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.",
  "inputs": [
   "2\n1 5\n",
   "3\n1 2 5\n",
   "4\n1 2 3 4\n",
   "8\n7 8 9 4 5 6 1 2\n",
   "1\n1\n",
   "1\n100\n",
   "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1\n",
   "4\n1000000000 99999999 1000000000 1000000000\n",
   "3\n2 2 2\n",
   "5\n1 1 1 1 1\n",
   "3\n1 1 1\n",
   "6\n1 1 3 3 2 2\n",
   "7\n1 1 1 1 1 1 1\n",
   "4\n1 1 2 5\n",
   "3\n0 0 0\n",
   "5\n0 0 0 0 0\n",
   "5\n1 1 1 1 5\n",
   "5\n1 1 2 3 3\n",
   "3\n1 1 3\n",
   "3\n2 2 3\n",
   "1\n6\n",
   "5\n1 5 3 5 1\n",
   "7\n1 2 2 2 2 2 3\n",
   "4\n2 2 2 2\n",
   "9\n2 2 2 3 4 5 6 6 6\n"
  ],
  "outputs": [
   "0",
   "1",
   "2",
   "6",
   "0",
   "0",
   "174",
   "0",
   "0",
   "0",
   "0",
   "2",
   "0",
   "1",
   "0",
   "0",
   "0",
   "1",
   "0",
   "0",
   "0",
   "1",
   "5",
   "0",
   "3"
  ]
 },
 {
  "id": "APPS-3766",
  "question": "Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game.\n\nOverall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has).\n\nThe aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. \n\nA color hint goes like that: a player names some color and points at all the cards of this color. \n\nSimilarly goes the value hint. A player names some value and points at all the cards that contain the value.\n\nDetermine what minimum number of hints the other players should make for Borya to be certain about each card's color and value.\n\n\n-----Input-----\n\nThe first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in.\n\n\n-----Output-----\n\nPrint a single integer — the minimum number of hints that the other players should make.\n\n\n-----Examples-----\nInput\n2\nG3 G3\n\nOutput\n0\n\nInput\n4\nG4 R4 R3 B3\n\nOutput\n2\n\nInput\n5\nB1 Y1 W1 G1 R1\n\nOutput\n4\n\n\n\n-----Note-----\n\nIn the first sample Borya already knows for each card that it is a green three.\n\nIn the second sample we can show all fours and all red cards.\n\nIn the third sample you need to make hints about any four colors.",
  "inputs": [
   "2\nG3 G3\n",
   "4\nG4 R4 R3 B3\n",
   "5\nB1 Y1 W1 G1 R1\n",
   "10\nY4 B1 R3 G5 R5 W3 W5 W2 R1 Y1\n",
   "3\nG4 G3 B4\n",
   "2\nW3 Y5\n",
   "2\nW5 Y5\n",
   "100\nW4 Y1 W5 R4 W3 Y1 R4 W2 G3 G1 B5 Y5 Y2 Y3 G4 B5 W1 G5 Y5 Y3 G2 Y5 Y5 G5 R2 B3 B1 W5 Y1 W5 B4 W4 R4 B1 R1 W3 R5 R4 G2 W3 W3 R2 W5 Y2 B2 R3 R3 Y1 G5 G2 Y1 R4 Y5 W5 G5 B3 W2 R1 B2 W2 W2 Y5 W3 G1 B1 G2 Y3 W3 G1 W5 W1 G5 G2 Y1 W5 B5 W4 Y5 G2 R3 B4 R5 B1 R1 B4 Y4 Y4 Y3 R5 Y3 B3 W5 R5 Y5 G2 G5 W5 B4 G4 W5\n",
   "100\nB5 G3 Y2 W3 W1 G1 Y4 G3 G4 B5 W4 B5 Y3 R5 B4 G4 G4 B1 G1 R5 G4 B4 G1 G2 W1 Y4 R5 Y3 W5 W4 Y5 W1 B4 G3 R2 R3 W1 B4 Y4 G2 G2 R1 Y5 W1 Y3 B3 G5 Y3 G3 W2 W5 Y4 B2 Y5 R4 B2 Y3 W4 G2 G3 R2 W1 B4 B2 B1 Y2 Y2 Y3 W3 Y5 W1 R1 R1 R4 R4 R4 Y1 Y3 B2 Y3 Y1 R3 G4 G4 Y5 B5 W2 G1 G5 B3 G1 Y1 R2 G5 R2 Y5 R5 Y4 R4 W2\n",
   "100\nY3 Y3 Y5 Y2 Y4 Y1 Y2 Y3 Y1 Y5 Y3 Y1 Y4 Y5 Y5 Y3 Y1 Y5 Y2 Y3 Y1 Y4 Y4 Y1 Y2 Y2 Y4 Y2 Y4 Y5 Y5 Y2 Y3 Y1 Y3 Y5 Y3 Y1 Y5 Y3 Y3 Y2 Y5 Y1 Y5 Y5 Y4 Y2 Y2 Y1 Y2 Y4 Y3 Y2 Y5 Y3 Y4 Y3 Y1 Y4 Y2 Y4 Y4 Y3 Y3 Y1 Y1 Y4 Y2 Y5 Y3 Y4 Y4 Y4 Y3 Y2 Y2 Y2 Y3 Y4 Y4 Y2 Y1 Y2 Y2 Y4 Y3 Y5 Y4 Y2 Y5 Y3 Y1 Y5 Y2 Y5 Y4 Y1 Y2 Y1\n",
   "100\nG3 B3 G3 Y3 R3 G3 R3 G3 W3 B3 B3 B3 R3 Y3 Y3 W3 R3 B3 G3 W3 G3 W3 Y3 R3 Y3 W3 W3 G3 W3 G3 W3 Y3 G3 R3 Y3 W3 W3 Y3 Y3 Y3 R3 W3 R3 G3 W3 W3 G3 Y3 B3 W3 B3 Y3 G3 Y3 B3 Y3 W3 Y3 R3 Y3 R3 W3 W3 W3 G3 Y3 G3 R3 B3 R3 Y3 R3 Y3 R3 Y3 R3 Y3 R3 W3 Y3 R3 W3 W3 W3 G3 G3 Y3 B3 Y3 R3 G3 G3 B3 B3 Y3 R3 G3 R3 W3 G3\n",
   "100\nW5 Y5 Y3 W3 Y5 Y5 W5 W5 Y3 W5 Y5 Y3 W5 Y5 W5 W3 Y3 Y5 W3 W5 Y5 W3 Y5 Y3 W3 W3 Y3 Y5 W3 W3 Y3 Y5 W3 Y5 Y5 Y5 W5 Y5 W5 Y5 W5 W5 W3 W5 W3 Y3 W5 W3 W3 W5 Y3 Y5 W5 W5 W3 W5 W5 Y5 W5 W3 W3 W3 Y3 Y5 Y5 Y3 Y5 W5 W5 Y5 W3 W3 W5 Y5 Y5 Y3 W5 W5 W3 Y5 W3 W5 Y3 Y5 W5 Y3 Y3 W3 Y3 Y5 Y3 Y3 W5 Y5 Y3 Y5 Y3 W3 Y3 W5\n",
   "100\nY5 Y5 Y3 Y5 Y3 Y5 Y5 Y5 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y5 Y5 Y3 Y3 Y5 Y3 Y5 Y3 Y3 Y3 Y5 Y3 Y3 Y3 Y3 Y3 Y3 Y3 Y5 Y5 Y5 Y5 Y3 Y5 Y5 Y5 Y5 Y3 Y3 Y3 Y5 Y5 Y3 Y3 Y3 Y5 Y3 Y3 Y5 Y3 Y3 Y3 Y5 Y3 Y5 Y5 Y5 Y5 Y3 Y3 Y5 Y5 Y5 Y5 Y5 Y5 Y5 Y5 Y3 Y5 Y5 Y5 Y5 Y5 Y5 Y3 Y5 Y3 Y5 Y5 Y5 Y5 Y5 Y5 Y3 Y3 Y3 Y5 Y5\n",
   "100\nY3 Y3 Y3 W3 W3 Y3 Y3 W3 Y3 Y3 W3 Y3 Y3 Y3 W3 Y3 Y3 W3 Y3 Y3 Y3 W3 Y3 W3 W3 W3 W3 W3 Y3 Y3 W3 Y3 Y3 W3 W3 Y3 Y3 W3 Y3 Y3 W3 W3 W3 W3 W3 Y3 Y3 Y3 Y3 W3 Y3 Y3 W3 W3 W3 Y3 W3 W3 W3 Y3 Y3 Y3 Y3 W3 W3 W3 W3 W3 Y3 Y3 W3 Y3 W3 Y3 Y3 Y3 Y3 Y3 Y3 Y3 W3 W3 W3 W3 Y3 W3 Y3 Y3 Y3 Y3 Y3 Y3 Y3 Y3 W3 Y3 Y3 W3 W3 Y3\n",
   "10\nW1 Y4 Y3 W3 Y2 W2 W1 Y2 Y3 W3\n",
   "10\nW2 R2 B5 W5 W2 B3 B2 R5 Y5 R2\n",
   "5\nW3 Y5 W2 G3 Y3\n",
   "5\nW5 G5 W2 Y5 G2\n",
   "5\nW5 W3 Y3 Y5 W2\n",
   "5\nY5 W3 W2 G5 W3\n",
   "5\nG5 G3 G5 G5 W2\n",
   "5\nW2 Y2 G3 G3 G3\n",
   "5\nG3 Y5 Y2 Y5 W3\n",
   "5\nW3 W5 Y3 W2 G5\n",
   "5\nY3 Y2 Y3 Y5 Y5\n"
  ],
  "outputs": [
   "0\n",
   "2\n",
   "4\n",
   "6\n",
   "2\n",
   "1\n",
   "1\n",
   "8\n",
   "8\n",
   "4\n",
   "4\n",
   "2\n",
   "1\n",
   "1\n",
   "3\n",
   "5\n",
   "3\n",
   "3\n",
   "3\n",
   "3\n",
   "2\n",
   "2\n",
   "3\n",
   "3\n",
   "2\n"
  ]
 },
 {
  "id": "APPS-3788",
  "question": "Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!\n\nRecently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and sees his creation demolished, he'll get extremely upset. \n\nTo not let that happen, Dima has to recover the binary search tree. Luckily, he noticed that any two vertices connected by a direct edge had their greatest common divisor value exceed $1$.\n\nHelp Dima construct such a binary search tree or determine that it's impossible. The definition and properties of a binary search tree can be found here.\n\n\n-----Input-----\n\nThe first line contains the number of vertices $n$ ($2 \\le n \\le 700$).\n\nThe second line features $n$ distinct integers $a_i$ ($2 \\le a_i \\le 10^9$) — the values of vertices in ascending order.\n\n\n-----Output-----\n\nIf it is possible to reassemble the binary search tree, such that the greatest common divisor of any two vertices connected by the edge is greater than $1$, print \"Yes\" (quotes for clarity).\n\nOtherwise, print \"No\" (quotes for clarity).\n\n\n-----Examples-----\nInput\n6\n3 6 9 18 36 108\n\nOutput\nYes\n\nInput\n2\n7 17\n\nOutput\nNo\n\nInput\n9\n4 8 10 12 15 18 33 44 81\n\nOutput\nYes\n\n\n\n-----Note-----\n\nThe picture below illustrates one of the possible trees for the first example. [Image] \n\nThe picture below illustrates one of the possible trees for the third example. [Image]",
  "inputs": [
   "6\n3 6 9 18 36 108\n",
   "2\n7 17\n",
   "9\n4 8 10 12 15 18 33 44 81\n",
   "22\n2 4 8 16 32 96 288 576 1728 3456 10368 20736 62208 186624 559872 1119744 3359232 10077696 30233088 90699264 181398528 544195584\n",
   "14\n122501 245002 367503 735006 1225010 4287535 8575070 21437675 42875350 85750700 171501400 343002800 531654340 823206720\n",
   "21\n2 1637 8185 16370 32740 49110 98220 106405 532025 671170 1225010 5267543 10535086 21070172 42140344 63210516 94815774 189631548 379263096 568894644 632105160\n",
   "23\n5 10 149 298 397 794 1588 3176 6352 12704 20644 30966 61932 103220 118306 208600 312900 625800 1225010 13107607 249044533 498089066 917532490\n",
   "29\n2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912\n",
   "21\n2 6 18 54 216 432 1296 5184 10368 31104 124416 248832 746496 1492992 2985984 5971968 17915904 53747712 107495424 214990848 644972544\n",
   "13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n",
   "27\n17 34 68 85 170 340 510 1020 1105 22621 45242 90484 113105 226210 452420 565525 2284721 11423605 15993047 47979141 79965235 114236050 124981025 199969640 299954460 599908920 999848200\n",
   "27\n13 26 52 104 208 221 442 884 1105 4211 12633 25266 63165 126330 130541 261082 522164 1044328 1305410 1697033 12426661 37279983 111839949 223679898 298239864 385226491 721239025\n",
   "24\n13 26 52 104 130 260 520 728 1105 238529 477058 954116 1908232 3816464 4293522 6440283 12880566 20274965 40549930 60824895 121649790 243299580 263574545 527149090\n",
   "27\n5 10 29 58 116 174 2297 4594 9188 18376 36752 43643 415757 831514 1663028 2494542 6236355 12472710 22450878 44901756 47396298 68344938 114906990 229813980 306418640 612837280 919255920\n",
   "30\n5 10 14 28 42 3709 7418 11127 14836 29672 44508 55635 74180 148360 222540 445080 778890 1557780 2039646 5778997 11557994 23115988 46231976 92463952 138695928 208043892 312065838 624131676 832175568 928038930\n",
   "25\n2 4 8 10 25 50 100 107903 215806 431612 863224 1726448 3452896 4316120 8632240 17264480 21580600 32370900 64741800 86322400 172644800 193362176 302128400 604256800 841824100\n",
   "30\n3 5 15 30 55 77 154 231 462 770 1540 2310 4569 13707 41121 123363 246726 424917 662505 1987515 5962545 7950060 15900120 23850180 35775270 71550540 132501000 265002000 397503000 795006000\n",
   "36\n3 41 82 123 174 216 432 864 1080 1228 2149 4298 8596 11052 22104 33156 35919 71838 179595 359190 431028 862056 994680 1315440 1753920 3507840 7015680 10523520 21047040 26500200 53000400 106000800 132501000 176668000 353336000 530004000\n",
   "29\n2 4 8 16 24 449 898 1796 3592 5388 16613 33226 66452 132904 199356 398712 689664 1375736 2751472 3439340 6878680 13757360 27514720 52277968 86671368 132501000 265002000 530004000 795006000\n",
   "4\n2 3 5 30\n",
   "9\n2 3 5 7 9 11 13 17 9699690\n",
   "2\n2 4\n",
   "4\n23 247 299 703\n",
   "4\n3 4 9 12\n",
   "5\n2 6 9 10 81\n"
  ],
  "outputs": [
   "Yes\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "No\n",
   "No\n",
   "Yes\n",
   "No\n",
   "No\n",
   "No\n"
  ]
 },
 {
  "id": "APPS-3776",
  "question": "You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.\n\nYou are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.\n\nFor example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.\n\n\n-----Input-----\n\nThe first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.\n\nThe second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.\n\n\n-----Output-----\n\nThe only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.\n\n\n-----Examples-----\nInput\n24\n17:30\n\nOutput\n17:30\n\nInput\n12\n17:30\n\nOutput\n07:30\n\nInput\n24\n99:99\n\nOutput\n09:09",
  "inputs": [
   "24\n17:30\n",
   "12\n17:30\n",
   "24\n99:99\n",
   "12\n05:54\n",
   "12\n00:05\n",
   "24\n23:80\n",
   "24\n73:16\n",
   "12\n03:77\n",
   "12\n47:83\n",
   "24\n23:88\n",
   "24\n51:67\n",
   "12\n10:33\n",
   "12\n00:01\n",
   "12\n07:74\n",
   "12\n00:60\n",
   "24\n08:32\n",
   "24\n42:59\n",
   "24\n19:87\n",
   "24\n26:98\n",
   "12\n12:91\n",
   "12\n11:30\n",
   "12\n90:32\n",
   "12\n03:69\n",
   "12\n33:83\n",
   "24\n10:45\n"
  ],
  "outputs": [
   "17:30\n",
   "07:30\n",
   "09:09\n",
   "05:54\n",
   "01:05\n",
   "23:00\n",
   "03:16\n",
   "03:07\n",
   "07:03\n",
   "23:08\n",
   "01:07\n",
   "10:33\n",
   "01:01\n",
   "07:04\n",
   "01:00\n",
   "08:32\n",
   "02:59\n",
   "19:07\n",
   "06:08\n",
   "12:01\n",
   "11:30\n",
   "10:32\n",
   "03:09\n",
   "03:03\n",
   "10:45\n"
  ]
 },
 {
  "id": "APPS-3932",
  "question": "Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. \n\nIahub asks Iahubina: can you build a rooted tree, such that\n\n  each internal node (a node with at least one son) has at least two sons;  node i has c_{i} nodes in its subtree? \n\nIahubina has to guess the tree. Being a smart girl, she realized that it's possible no tree can follow Iahub's restrictions. In this way, Iahub will eat all the food. You need to help Iahubina: determine if there's at least one tree following Iahub's restrictions. The required tree must contain n nodes.\n\n\n-----Input-----\n\nThe first line of the input contains integer n (1 ≤ n ≤ 24). Next line contains n positive integers: the i-th number represents c_{i} (1 ≤ c_{i} ≤ n).\n\n\n-----Output-----\n\nOutput on the first line \"YES\" (without quotes) if there exist at least one tree following Iahub's restrictions, otherwise output \"NO\" (without quotes). \n\n\n-----Examples-----\nInput\n4\n1 1 1 4\n\nOutput\nYES\nInput\n5\n1 1 5 2 1\n\nOutput\nNO",
  "inputs": [
   "4\n1 1 1 4\n",
   "5\n1 1 5 2 1\n",
   "13\n1 1 1 1 1 1 1 1 1 4 4 4 13\n",
   "4\n1 1 1 3\n",
   "24\n1 1 1 1 1 1 1 1 1 1 1 1 24 1 1 1 1 1 1 1 1 1 1 1\n",
   "24\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24\n",
   "10\n1 1 1 1 7 1 1 1 4 10\n",
   "24\n1 1 3 1 1 10 2 9 13 1 8 1 4 1 3 24 1 1 1 1 4 1 3 1\n",
   "24\n2 3 20 1 4 9 1 3 1 2 1 3 1 2 1 1 1 2 1 2 4 24 2 1\n",
   "24\n8 5 3 1 1 5 10 1 1 1 1 5 1 2 7 3 4 1 1 24 1 1 2 8\n",
   "24\n1 1 1 3 4 1 24 1 1 3 1 1 1 5 14 2 17 1 2 2 5 1 1 6\n",
   "1\n1\n",
   "17\n6 1 1 1 3 1 1 17 6 1 4 1 1 1 3 1 1\n",
   "23\n1 1 1 1 3 7 3 1 1 1 3 7 1 3 1 15 1 3 7 3 23 1 1\n",
   "24\n1 24 1 1 1 3 8 1 1 3 1 1 6 1 1 1 1 3 5 1 3 7 13 1\n",
   "16\n1 1 1 1 1 1 1 1 1 1 1 1 16 1 1 1\n",
   "21\n1 1 1 6 1 1 13 21 1 1 3 1 8 1 19 3 3 1 1 1 1\n",
   "22\n1 1 1 6 1 1 13 21 1 1 2 1 8 1 19 3 3 1 1 1 1 2\n",
   "19\n9 7 1 8 1 1 1 13 1 1 3 3 19 1 1 1 1 1 1\n",
   "18\n6 1 1 3 1 1 1 1 1 1 4 1 8 1 1 18 1 5\n",
   "14\n4 1 1 1 3 1 1 1 1 14 1 5 1 3\n",
   "2\n1 2\n",
   "24\n3 3 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24\n",
   "20\n20 9 4 4 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
   "12\n12 7 4 3 3 1 1 1 1 1 1 1\n"
  ],
  "outputs": [
   "YES",
   "NO",
   "YES",
   "NO",
   "YES",
   "NO",
   "YES",
   "NO",
   "NO",
   "NO",
   "NO",
   "YES",
   "YES",
   "YES",
   "YES",
   "YES",
   "YES",
   "NO",
   "NO",
   "YES",
   "YES",
   "NO",
   "NO",
   "YES",
   "YES"
  ]
 },
 {
  "id": "APPS-3959",
  "question": "It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has g_{i} Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving. \n\nFormally, an evolution plan is a permutation f of {1, 2, ..., m}, such that f(x) = y means that a Pokemon of type x evolves into a Pokemon of type y.\n\nThe gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol.\n\nTwo evolution plans f_1 and f_2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an i such that f_1(i) ≠ f_2(i).\n\nYour task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 10^9 + 7.\n\n\n-----Input-----\n\nThe first line contains two integers n and m (1 ≤ n ≤ 10^5, 1 ≤ m ≤ 10^6) — the number of gyms and the number of Pokemon types.\n\nThe next n lines contain the description of Pokemons in the gyms. The i-th of these lines begins with the integer g_{i} (1 ≤ g_{i} ≤ 10^5) — the number of Pokemon in the i-th gym. After that g_{i} integers follow, denoting types of the Pokemons in the i-th gym. Each of these integers is between 1 and m.\n\nThe total number of Pokemons (the sum of all g_{i}) does not exceed 5·10^5.\n\n\n-----Output-----\n\nOutput the number of valid evolution plans modulo 10^9 + 7.\n\n\n-----Examples-----\nInput\n2 3\n2 1 2\n2 2 3\n\nOutput\n1\n\nInput\n1 3\n3 1 2 3\n\nOutput\n6\n\nInput\n2 4\n2 1 2\n3 2 3 4\n\nOutput\n2\n\nInput\n2 2\n3 2 2 1\n2 1 2\n\nOutput\n1\n\nInput\n3 7\n2 1 2\n2 3 4\n3 5 6 7\n\nOutput\n24\n\n\n\n-----Note-----\n\nIn the first case, the only possible evolution plan is: $1 \\rightarrow 1,2 \\rightarrow 2,3 \\rightarrow 3$\n\nIn the second case, any permutation of (1,  2,  3) is valid.\n\nIn the third case, there are two possible plans: $1 \\rightarrow 1,2 \\rightarrow 2,3 \\rightarrow 4,4 \\rightarrow 3$ $1 \\rightarrow 1,2 \\rightarrow 2,3 \\rightarrow 3,4 \\rightarrow 4$\n\nIn the fourth case, the only possible evolution plan is: $1 \\rightarrow 1,2 \\rightarrow 2$",
  "inputs": [
   "2 3\n2 1 2\n2 2 3\n",
   "1 3\n3 1 2 3\n",
   "2 4\n2 1 2\n3 2 3 4\n",
   "2 2\n3 2 2 1\n2 1 2\n",
   "3 7\n2 1 2\n2 3 4\n3 5 6 7\n",
   "10 100\n16 25 7 48 43 16 23 66 3 17 31 64 27 7 17 11 60\n62 76 82 99 77 19 26 66 46 9 54 77 8 34 76 70 48 53 35 69 29 84 22 16 53 36 27 24 81 2 86 67 45 22 54 96 37 8 3 22 9 30 63 61 86 19 16 47 3 72 39 36 1 50 1 18 7 44 52 66 90 3 63\n3 22 61 39\n9 28 69 91 62 98 23 45 9 10\n2 42 20\n3 90 46 55\n2 71 9\n1 7\n1 44\n1 94\n",
   "10 100\n26 69 60 30 8 89 7 54 66 100 75 4 17 48 40 20 78 56 94 23 48 55 40 9 23 55 30\n3 94 78 64\n50 57 81 62 43 95 4 22 29 9 67 17 82 13 69 13 30 85 3 44 5 85 70 4 50 9 30 85 67 64 7 59 98 78 68 61 63 35 35 94 87 37 18 12 83 26 77 48 67 72 82\n7 59 52 92 41 37 11 17\n1 65\n2 75 82\n4 28 66 33 70\n1 81\n2 4 31\n1 12\n",
   "10 100\n53 9 10 7 62 66 82 38 22 82 14 48 7 77 51 37 5 10 12 68 88 36 49 80 80 71 48 72 6 49 87 21 48 17 75 43 25 75 55 36 10 82 2 28 14 53 25 66 7 70 58 53 74 86\n32 84 95 55 32 79 75 12 94 80 13 29 49 87 26 69 51 73 52 30 87 17 75 60 1 82 15 34 26 83 95 60 13\n8 61 39 91 78 19 32 91 26\n1 22\n1 87\n1 55\n1 87\n1 39\n1 70\n1 40\n",
   "10 100\n46 62 64 81 19 35 65 30 81 64 54 95 98 18 78 54 19 68 34 16 37 22 55 63 41 87 65 33 22 15 5 99 35 49 79 47 54 50 97 54 3 100 86 91 3 24 36\n36 25 29 71 1 64 18 92 22 86 76 91 87 79 29 33 61 36 87 22 10 25 7 96 56 67 38 66 43 35 55 54 90 65 83 56 11\n4 36 73 34 11\n2 28 94\n2 97 100\n5 52 69 13 11 78\n1 78\n2 71 8\n1 33\n1 11\n",
   "10 100\n73 10 13 55 73 7 41 18 37 47 97 43 96 52 97 75 42 23 52 61 89 100 64 43 98 95 86 86 39 85 31 74 30 82 84 51 84 21 35 61 3 15 71 45 99 12 48 54 39 96 85 57 45 35 92 57 65 97 42 91 86 47 64 35 67 52 11 34 24 41 45 42 87 50\n9 77 91 42 99 98 20 43 82 35\n10 96 48 77 64 81 66 3 38 58 9\n1 61\n2 47 35\n1 7\n1 61\n1 70\n1 88\n1 83\n",
   "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
   "100 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 2\n",
   "2 1000000\n1 1\n1 2\n",
   "5 262143\n1 1\n1 2\n1 3\n1 4\n1 5\n",
   "65 3\n1 1\n1 1\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n2 1 2\n1 1\n1 1\n1 1\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n1 1\n2 1 2\n",
   "1 1000000\n1 1\n",
   "20 3\n4 1 3 3 3\n6 1 3 3 3 3 3\n1 1\n2 1 3\n2 1 2\n1 1\n8 1 2 2 2 2 2 2 2\n3 1 3 3\n3 1 3 3\n5 1 2 2 2 2\n10 1 3 3 3 3 3 3 3 3 3\n15 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n10 1 2 2 2 2 2 2 2 2 2\n3 1 2 2\n1 1\n1 1\n7 1 3 3 3 3 3 3\n1 1\n1 1\n1 1\n",
   "20 3\n1 1\n5 1 2 2 2 2\n6 1 3 3 3 3 3\n2 1 2\n3 1 3 3\n3 1 3 3\n4 1 3 3 3\n2 1 3\n3 1 3 3\n5 1 2 2 2 2\n3 1 3 3\n7 1 2 2 2 2 2 2\n3 1 2 2\n6 1 3 3 3 3 3\n3 1 3 3\n2 1 2\n3 1 3 3\n2 1 2\n1 1\n1 1\n",
   "65 3\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1\n1 1\n2 1 2\n1 1\n2 1 2\n",
   "20 3\n2 1 2\n8 1 3 3 3 3 3 3 3\n4 1 3 3 3\n2 1 2\n3 1 2 2\n9 1 3 3 3 3 3 3 3 3\n2 1 2\n3 1 2 2\n2 1 2\n3 1 3 3\n9 1 3 3 3 3 3 3 3 3\n2 1 2\n15 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n2 1 3\n4 1 3 3 3\n2 1 2\n1 1\n1 1\n1 1\n1 1\n",
   "20 3\n2 1 3\n3 1 2 2\n5 1 3 3 3 3\n3 1 2 2\n1 1\n5 1 3 3 3 3\n4 1 3 3 3\n5 1 3 3 3 3\n4 1 3 3 3\n3 1 2 2\n2 1 3\n5 1 3 3 3 3\n5 1 2 2 2 2\n6 1 2 2 2 2 2\n3 1 2 2\n5 1 3 3 3 3\n5 1 2 2 2 2\n3 1 3 3\n4 1 2 2 2\n2 1 2\n",
   "3 3\n6 1 1 1 1 1 1\n6 2 2 2 2 2 2\n2 1 1\n"
  ],
  "outputs": [
   "1\n",
   "6\n",
   "2\n",
   "1\n",
   "24\n",
   "732842622\n",
   "510562296\n",
   "51603121\n",
   "166939681\n",
   "8656282\n",
   "1\n",
   "1\n",
   "44455173\n",
   "943283753\n",
   "1\n",
   "128233642\n",
   "1\n",
   "1\n",
   "1\n",
   "1\n",
   "1\n",
   "1\n"
  ]
 },
 {
  "id": "APPS-3698",
  "question": "The Travelling Salesman spends a lot of time travelling so he tends to get bored. To pass time, he likes to perform operations on numbers. One such operation is to take a positive integer x and reduce it to the number of bits set to 1 in the binary representation of x. For example for number 13 it's true that 13_10 = 1101_2, so it has 3 bits set and 13 will be reduced to 3 in one operation.\n\nHe calls a number special if the minimum number of operations to reduce it to 1 is k.\n\nHe wants to find out how many special numbers exist which are not greater than n. Please help the Travelling Salesman, as he is about to reach his destination!\n\nSince the answer can be large, output it modulo 10^9 + 7.\n\n\n-----Input-----\n\nThe first line contains integer n (1 ≤ n < 2^1000).\n\nThe second line contains integer k (0 ≤ k ≤ 1000).\n\nNote that n is given in its binary representation without any leading zeros.\n\n\n-----Output-----\n\nOutput a single integer — the number of special numbers not greater than n, modulo 10^9 + 7.\n\n\n-----Examples-----\nInput\n110\n2\n\nOutput\n3\n\nInput\n111111011\n2\n\nOutput\n169\n\n\n\n-----Note-----\n\nIn the first sample, the three special numbers are 3, 5 and 6. They get reduced to 2 in one operation (since there are two set bits in each of 3, 5 and 6) and then to 1 in one more operation (since there is only one set bit in 2).",
  "inputs": [
   "110\n2\n",
   "111111011\n2\n",
   "100011110011110110100\n7\n",
   "110100110\n0\n",
   "10000000000000000000000000000000000000000000\n2\n",
   "100000000000000000000100000000000010100100001001000010011101010\n3\n",
   "101010110000\n3\n",
   "11010110000\n3\n",
   "100\n6\n",
   "100100100100\n5\n",
   "10000000000\n4\n",
   "10\n868\n",
   "1\n0\n",
   "1\n1\n",
   "10\n0\n",
   "101110011101100100010010101001010111001\n8\n",
   "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n10\n",
   "10000000000000000000000000000\n1\n",
   "111111111111111111111111111111111111\n2\n",
   "10010110001111110001100000110111010011010110100111100010001011000011000011000100011010000000000110110010111111\n2\n",
   "11111100010011110101100110100010001011100111001011001111101111110111001111011011110101100101001000111001000100000011011110110010001000111101001101001010100011\n1\n",
   "10011101000010110111001\n1\n",
   "10000110011100011111100010011010111110111110100011110101110010000001111100110000001000101011001000111110111100110111010011011100000000111101001010110\n1\n",
   "11101011101101101111101100001101110010011011101101010101101111100011101111010111011\n1\n",
   "11101111100100100110010100010100101111\n4\n"
  ],
  "outputs": [
   "3\n",
   "169\n",
   "0\n",
   "1\n",
   "79284496\n",
   "35190061\n",
   "1563\n",
   "1001\n",
   "0\n",
   "0\n",
   "120\n",
   "0\n",
   "1\n",
   "0\n",
   "1\n",
   "0\n",
   "0\n",
   "28\n",
   "338250841\n",
   "678359035\n",
   "157\n",
   "22\n",
   "148\n",
   "82\n",
   "839492816\n"
  ]
 },
 {
  "id": "APPS-3909",
  "question": "Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen.\n\nOne day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?\n\nThe formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of n marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least n marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want.\n\n\n-----Input-----\n\nThe single line contains a single integer n (1 ≤ n ≤ 10^17).\n\nPlease, 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.\n\n\n-----Output-----\n\nIn a single line print an integer: the maximum number of coins the unlucky buyer could have paid with.\n\n\n-----Examples-----\nInput\n1\n\nOutput\n1\n\nInput\n4\n\nOutput\n2\n\n\n\n-----Note-----\n\nIn the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.\n\nIn the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins. The buyer cannot give three coins as he wants to minimize the number of coins that he gives.",
  "inputs": [
   "1\n",
   "4\n",
   "3\n",
   "8\n",
   "10\n",
   "100000000000000000\n",
   "99999999999999999\n",
   "50031545098999707\n",
   "16677181699666569\n",
   "72900000000000\n",
   "99999999999999997\n",
   "58061299250691018\n",
   "49664023559436051\n",
   "66708726798666276\n",
   "29442431889534807\n",
   "70414767176369958\n",
   "93886356235159944\n",
   "97626528902553453\n",
   "52013157885656046\n",
   "37586570003500923\n",
   "34391854792828422\n",
   "205891132094649\n",
   "243\n",
   "5559060566555523\n",
   "81\n"
  ],
  "outputs": [
   "1\n",
   "2\n",
   "1\n",
   "3\n",
   "4\n",
   "33333333333333334\n",
   "3703703703703704\n",
   "1\n",
   "1\n",
   "33333333334\n",
   "33333333333333333\n",
   "32\n",
   "128191526\n",
   "2\n",
   "48\n",
   "13\n",
   "51\n",
   "551104613133\n",
   "880847395988\n",
   "548\n",
   "582429080812\n",
   "1\n",
   "1\n",
   "1\n",
   "1\n"
  ]
 },
 {
  "id": "APPS-3853",
  "question": "Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.\n\nFrom the top view each magical box looks like a square with side length equal to 2^{k} (k is an integer, k ≥ 0) units. A magical box v can be put inside a magical box u, if side length of v is strictly less than the side length of u. In particular, Emuskald can put 4 boxes of side length 2^{k} - 1 into one box of side length 2^{k}, or as in the following figure:\n\n [Image] \n\nEmuskald is about to go on tour performing around the world, and needs to pack his magical boxes for the trip. He has decided that the best way to pack them would be inside another magical box, but magical boxes are quite expensive to make. Help him find the smallest magical box that can fit all his boxes.\n\n\n-----Input-----\n\nThe first line of input contains an integer n (1 ≤ n ≤ 10^5), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers k_{i} and a_{i} (0 ≤ k_{i} ≤ 10^9, 1 ≤ a_{i} ≤ 10^9), which means that Emuskald has a_{i} boxes with side length 2^{k}_{i}. It is guaranteed that all of k_{i} are distinct.\n\n\n-----Output-----\n\nOutput a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2^{p}.\n\n\n-----Examples-----\nInput\n2\n0 3\n1 5\n\nOutput\n3\n\nInput\n1\n0 4\n\nOutput\n1\n\nInput\n2\n1 10\n2 2\n\nOutput\n3\n\n\n\n-----Note-----\n\nPicture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.\n\nIn the second test case, we can put all four small boxes into a box with side length 2.",
  "inputs": [
   "2\n0 3\n1 5\n",
   "1\n0 4\n",
   "2\n1 10\n2 2\n",
   "1\n0 1\n",
   "1\n1000000000 1000000000\n",
   "1\n0 16\n",
   "1\n0 17\n",
   "2\n0 16\n1 4\n",
   "3\n0 20\n1 18\n2 4\n",
   "3\n0 64\n1 16\n2 4\n",
   "5\n1 1000000\n100 100\n101 9\n102 4\n103 8\n",
   "10\n11 69\n7 56\n8 48\n2 56\n12 6\n9 84\n1 81\n4 80\n3 9\n5 18\n",
   "15\n0 268435456\n1 67108864\n2 16777216\n3 4194304\n4 1048576\n5 262144\n6 65536\n7 16384\n8 4096\n9 1024\n10 256\n11 64\n12 16\n13 4\n14 1\n",
   "14\n0 268435456\n1 67108864\n2 16777216\n3 4194304\n4 1048576\n5 262144\n6 65536\n7 16384\n8 4096\n9 1024\n10 256\n11 64\n12 16\n13 4\n",
   "14\n0 268435456\n1 67108864\n2 16777216\n3 4194305\n4 1048576\n5 262144\n6 65536\n7 16384\n8 4096\n9 1024\n10 256\n11 64\n12 16\n13 4\n",
   "14\n0 268435457\n1 67108865\n2 16777217\n3 4194305\n4 1048577\n5 262145\n6 65537\n7 16383\n8 4097\n9 1025\n10 257\n11 65\n12 17\n13 4\n",
   "16\n1296 2\n1568 1\n7435 2\n3660 1\n6863 2\n886 2\n2596 1\n7239 1\n6146 1\n5634 1\n3119 2\n1166 2\n7610 2\n5992 1\n630 2\n8491 2\n",
   "17\n8028 11\n4011 32\n8609 52\n1440 25\n6752 42\n536 47\n761 15\n2749 60\n5363 62\n7170 23\n9734 10\n8487 28\n6147 20\n5257 54\n821 49\n7219 19\n6150 43\n",
   "15\n999999986 268435456\n999999987 67108864\n999999988 16777216\n999999989 4194304\n999999990 1048576\n999999991 262144\n999999992 65536\n999999993 16384\n999999994 4096\n999999995 1024\n999999996 256\n999999997 64\n999999998 16\n999999999 4\n1000000000 1\n",
   "3\n1 4\n0 17\n2 4\n",
   "2\n0 13\n1 1\n",
   "2\n0 2\n1 4\n",
   "2\n100 52\n101 4\n",
   "10\n1 1\n10 1\n100 1\n1000 1\n10000 1\n100000 1\n1000000 1\n10000000 1\n100000000 1\n1000000000 1\n",
   "1\n0 268435456\n"
  ],
  "outputs": [
   "3\n",
   "1\n",
   "3\n",
   "1\n",
   "1000000015\n",
   "2\n",
   "3\n",
   "2\n",
   "4\n",
   "3\n",
   "105\n",
   "15\n",
   "15\n",
   "14\n",
   "15\n",
   "15\n",
   "8492\n",
   "9736\n",
   "1000000001\n",
   "3\n",
   "2\n",
   "2\n",
   "103\n",
   "1000000001\n",
   "14\n"
  ]
 },
 {
  "id": "APPS-3738",
  "question": "Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all:  'U': go up, (x, y)  →  (x, y+1);  'D': go down, (x, y)  →  (x, y-1);  'L': go left, (x, y)  →  (x-1, y);  'R': go right, (x, y)  →  (x+1, y). \n\nThe robot will do the operations in s from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (a, b).\n\n\n-----Input-----\n\nThe first line contains two integers a and b, ( - 10^9 ≤ a, b ≤ 10^9). The second line contains a string s (1 ≤ |s| ≤ 100, s only contains characters 'U', 'D', 'L', 'R') — the command.\n\n\n-----Output-----\n\nPrint \"Yes\" if the robot will be located at (a, b), and \"No\" otherwise.\n\n\n-----Examples-----\nInput\n2 2\nRU\n\nOutput\nYes\n\nInput\n1 2\nRU\n\nOutput\nNo\n\nInput\n-1 1000000000\nLRRLU\n\nOutput\nYes\n\nInput\n0 0\nD\n\nOutput\nYes\n\n\n\n-----Note-----\n\nIn the first and second test case, command string is \"RU\", so the robot will go right, then go up, then right, and then up and so on.\n\nThe locations of its moves are (0, 0)  →  (1, 0)  →  (1, 1)  →  (2, 1)  →  (2, 2)  →  ...\n\nSo it can reach (2, 2) but not (1, 2).",
  "inputs": [
   "2 2\nRU\n",
   "1 2\nRU\n",
   "-1 1000000000\nLRRLU\n",
   "0 0\nD\n",
   "0 0\nUURRDL\n",
   "987654321 987654321\nUURRDL\n",
   "4 2\nUURRDL\n",
   "4 3\nUURRDL\n",
   "4 4\nUURRDL\n",
   "4 6\nUURRDL\n",
   "4 7\nUURRDL\n",
   "1000000000 1000000000\nUURRDL\n",
   "-1 -1\nUR\n",
   "1 1\nUURRDDLL\n",
   "987654321 2\nUURDD\n",
   "0 123456789\nRRULL\n",
   "4 4\nUUUURRRRDDDDLLLL\n",
   "-491226083 -49122610\nUDRLDURLDLLLDUDURLRDUUDDUUULUDRDRDUULURDRLLDDDLUDUURLUUDLLDULLLLDDLDDUU\n",
   "-261597957 418556728\nLLLDLUDUULLRDDULLRRUDRDLULRLRLLRRUUDRRLRUDLRRLUDRDLLUUDUULRURLDLULUUULDDUURLRUDURRL\n",
   "-771928144 -3\nRUDULULDRDLLLULDDUDDDDUDULRULRUULDDDURUDLUURULLLDLLDDRDDRLRURUULRUURRUDLDLDDRLLULRRDRRLLUULUDRUUDRRD\n",
   "397346346 1\nDDURRUURLDLRRLULD\n",
   "-528551525 0\nUDRLRRLDLDLURRRRULDLRLRLURUUDDLRLLDRRULLUDLURDLUUULLLRUUUDRRURLDUDULDDRDDDRDL\n",
   "311692421 -129871846\nLLLDURULDDDDUDDURRLUUDRLDDRDURDDRUDUURLUDUDLDRUDDDUUURDRRUDRDRDURLLDURUUDRLDLDURRRRRRDULURDRU\n",
   "485940814 728911221\nURURU\n",
   "-843450986 632588242\nLURLULULRUDUDULRDDLUL\n"
  ],
  "outputs": [
   "Yes\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "No\n",
   "Yes\n",
   "No\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n"
  ]
 },
 {
  "id": "APPS-3757",
  "question": "For each string s consisting of characters '0' and '1' one can define four integers a_00, a_01, a_10 and a_11, where a_{xy} is the number of subsequences of length 2 of the string s equal to the sequence {x, y}. \n\nIn these problem you are given four integers a_00, a_01, a_10, a_11 and have to find any non-empty string s that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than 1 000 000.\n\n\n-----Input-----\n\nThe only line of the input contains four non-negative integers a_00, a_01, a_10 and a_11. Each of them doesn't exceed 10^9.\n\n\n-----Output-----\n\nIf there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print \"Impossible\". The length of your answer must not exceed 1 000 000.\n\n\n-----Examples-----\nInput\n1 2 3 4\n\nOutput\nImpossible\n\nInput\n1 2 2 1\n\nOutput\n0110",
  "inputs": [
   "1 2 3 4\n",
   "1 2 2 1\n",
   "10 7 28 21\n",
   "0 0 0 0\n",
   "49995000 11667 4308334 93096\n",
   "499928010 601314341 398636540 499991253\n",
   "0 2548 1752 650\n",
   "0 0 0 45\n",
   "105 2 598 780\n",
   "1 0 0 0\n",
   "0 0 0 1\n",
   "0 0 1 0\n",
   "0 1 0 0\n",
   "487577 9219238 1758432 61721604\n",
   "1000000000 0 0 0\n",
   "0 1000000000 0 0\n",
   "0 0 1000000000 0\n",
   "0 0 0 1000000000\n",
   "0 1 1 1\n",
   "1 1 1 0\n",
   "1 20000 20001 200010000\n",
   "1 1 1 3\n",
   "1000000000 1000000000 1000000000 1000000000\n",
   "321451234 456748672 987936461 785645414\n",
   "123456789 987654321 123456789 1\n"
  ],
  "outputs": [
   "Impossible\n",
   "0110\n",
   "011111110000\n",
   "0\n",
   "Impossible\n",
   "Impossible\n",
   "Impossible\n",
   "1111111111\n",
   "1111111111111111111111111111111111111101100000000000000\n",
   "00\n",
   "11\n",
   "10\n",
   "01\n",
   "Impossible\n",
   "Impossible\n",
   "Impossible\n",
   "Impossible\n",
   "Impossible\n",
   "101\n",
   "010\n",
   "Impossible\n",
   "Impossible\n",
   "Impossible\n",
   "Impossible\n",
   "Impossible\n"
  ]
 },
 {
  "id": "APPS-3834",
  "question": "Sereja has an n × m rectangular table a, each cell of the table contains a zero or a number one. Sereja wants his table to meet the following requirement: each connected component of the same values forms a rectangle with sides parallel to the sides of the table. Rectangles should be filled with cells, that is, if a component form a rectangle of size h × w, then the component must contain exactly hw cells.\n\nA connected component of the same values is a set of cells of the table that meet the following conditions:  every two cells of the set have the same value;  the cells of the set form a connected region on the table (two cells are connected if they are adjacent in some row or some column of the table);  it is impossible to add any cell to the set unless we violate the two previous conditions. \n\nCan Sereja change the values of at most k cells of the table so that the table met the described requirement? What minimum number of table cells should he change in this case?\n\n\n-----Input-----\n\nThe first line contains integers n, m and k (1 ≤ n, m ≤ 100; 1 ≤ k ≤ 10). Next n lines describe the table a: the i-th of them contains m integers a_{i}1, a_{i}2, ..., a_{im} (0 ≤ a_{i}, j ≤ 1) — the values in the cells of the i-th row.\n\n\n-----Output-----\n\nPrint -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed.\n\n\n-----Examples-----\nInput\n5 5 2\n1 1 1 1 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1\n1 1 1 1 1\n\nOutput\n1\n\nInput\n3 4 1\n1 0 0 0\n0 1 1 1\n1 1 1 0\n\nOutput\n-1\n\nInput\n3 4 1\n1 0 0 1\n0 1 1 0\n1 0 0 1\n\nOutput\n0",
  "inputs": [
   "5 5 2\n1 1 1 1 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1\n1 1 1 1 1\n",
   "3 4 1\n1 0 0 0\n0 1 1 1\n1 1 1 0\n",
   "3 4 1\n1 0 0 1\n0 1 1 0\n1 0 0 1\n",
   "8 1 4\n0\n0\n0\n1\n0\n1\n1\n0\n",
   "3 10 7\n0 1 0 0 1 0 1 0 0 0\n0 0 1 1 0 0 0 1 0 1\n1 0 1 1 1 0 1 1 0 0\n",
   "4 9 7\n0 0 0 1 0 1 1 0 0\n1 1 1 0 0 0 0 1 1\n1 1 0 0 1 1 0 1 0\n0 0 0 1 0 1 0 0 0\n",
   "9 2 5\n0 1\n0 1\n1 1\n0 1\n0 1\n1 0\n1 1\n1 0\n1 1\n",
   "10 7 8\n1 0 1 0 1 1 0\n0 1 0 1 0 0 1\n1 0 1 0 1 1 0\n0 1 0 1 0 0 1\n1 0 1 0 1 1 0\n1 0 1 0 1 1 0\n1 0 1 0 1 1 0\n1 0 1 0 1 1 0\n0 1 0 1 0 0 1\n0 1 0 1 0 0 1\n",
   "9 2 10\n1 0\n0 1\n1 0\n1 1\n0 1\n1 0\n1 0\n1 1\n0 1\n",
   "4 6 3\n1 0 0 1 0 0\n0 1 1 0 1 1\n1 0 0 1 0 0\n0 1 1 0 1 1\n",
   "4 4 5\n1 0 1 0\n0 1 0 1\n0 1 0 1\n0 1 0 0\n",
   "6 4 10\n0 1 0 0\n1 1 1 0\n0 1 1 0\n0 1 0 0\n0 1 0 0\n0 0 0 0\n",
   "1 9 2\n1 0 1 0 0 0 0 1 0\n",
   "3 63 4\n0 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 0 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 0 1 0 0 0 1 0 1 1 1 1 1\n1 1 0 1 1 0 1 1 0 1 0 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0 1 0 0 1 1 0 1 1 1 1 1 0 1 1 0 0\n1 1 1 1 1 0 1 1 0 1 0 0 1 1 0 0 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 0 0 1 1 1 1 1 0 0 1 0 1 0 1 0 0 0 1 0 1 1 1 0 1 0 1 0 0 0\n",
   "1 40 4\n1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 0 1 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0\n",
   "1 12 7\n0 0 0 1 0 0 1 1 1 1 0 1\n",
   "4 35 6\n1 1 0 1 1 0 1 1 1 0 0 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0\n0 0 1 0 0 1 0 0 0 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1\n1 0 0 1 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 1 0 0 1 0 1 1 0 1 0 0 0 0 0 0\n0 0 1 0 0 1 0 0 0 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 1 1 1\n",
   "5 38 9\n0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 1 0 0 0\n0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1 0 1 0 0 1 0 0 0\n1 0 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0 1 0 0 0 1 1 1 0 1 0 1 1 0 1 1 1\n1 0 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 1 1 0 1 1 1\n1 0 1 1 0 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 1 1 0 1 1 1\n",
   "2 75 7\n0 0 1 0 0 0 1 1 0 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 1 1 1 1\n1 1 0 1 1 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 0 0 1 1 0 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 0 0 1\n",
   "21 10 8\n1 1 1 0 0 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n0 0 1 1 1 0 0 0 0 0\n0 0 0 1 1 0 0 0 0 0\n1 1 1 0 0 1 1 1 1 1\n0 0 0 1 1 0 0 0 0 0\n1 1 1 0 0 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n0 0 0 1 1 0 0 0 0 0\n1 0 1 0 0 1 1 1 1 1\n0 1 0 1 1 0 0 0 0 0\n0 0 0 1 1 0 0 0 0 0\n0 0 0 1 1 0 0 0 0 0\n0 0 0 1 1 0 0 0 0 0\n1 1 1 0 1 1 1 1 1 1\n0 0 0 0 1 0 0 0 0 0\n1 1 1 0 1 1 1 1 1 1\n1 1 1 0 0 1 1 1 1 1\n",
   "11 9 9\n0 0 0 0 0 0 1 1 0\n0 0 0 0 0 0 1 1 0\n0 0 0 0 0 0 1 0 0\n1 1 1 1 1 1 0 0 1\n1 1 1 1 1 1 0 0 1\n1 1 1 1 1 1 0 0 1\n0 0 0 0 0 0 1 1 0\n0 0 0 0 0 0 1 1 0\n0 0 0 0 0 0 1 1 0\n1 1 1 1 1 1 0 0 1\n0 0 0 0 0 0 1 1 0\n",
   "37 4 7\n1 0 0 1\n0 1 0 1\n0 1 1 1\n1 0 0 0\n0 1 1 1\n0 1 1 1\n1 0 1 0\n1 0 0 0\n1 0 0 0\n1 0 0 0\n0 1 1 1\n0 1 1 1\n1 0 0 0\n0 1 1 0\n0 1 1 1\n0 1 1 1\n0 1 1 0\n1 0 0 0\n1 0 0 0\n0 1 1 1\n0 1 1 1\n1 0 0 0\n1 1 1 1\n1 1 1 1\n1 1 0 0\n0 1 1 1\n0 1 0 1\n0 1 1 1\n0 1 1 1\n1 1 0 0\n1 0 0 0\n0 0 1 1\n0 1 1 1\n1 0 0 0\n1 0 0 0\n1 0 0 0\n0 0 0 0\n",
   "1 1 1\n1\n",
   "2 2 1\n1 1\n1 0\n",
   "3 3 1\n1 1 1\n1 0 1\n1 1 0\n"
  ],
  "outputs": [
   "1\n",
   "-1\n",
   "0\n",
   "0\n",
   "6\n",
   "5\n",
   "3\n",
   "0\n",
   "2\n",
   "0\n",
   "1\n",
   "4\n",
   "0\n",
   "-1\n",
   "0\n",
   "0\n",
   "5\n",
   "2\n",
   "4\n",
   "6\n",
   "1\n",
   "-1\n",
   "0\n",
   "1\n",
   "-1\n"
  ]
 },
 {
  "id": "APPS-3921",
  "question": "Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a_1, a_2, ..., a_{n} are good.\n\nNow 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. \n\nFind the length of the longest good sequence.\n\n\n-----Input-----\n\nThe input consists of two lines. The first line contains a single integer n (1 ≤ n ≤ 10^5) — 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} ≤ 10^5; a_{i} < a_{i} + 1).\n\n\n-----Output-----\n\nPrint a single integer — the length of the longest good sequence.\n\n\n-----Examples-----\nInput\n5\n2 3 4 6 9\n\nOutput\n4\n\nInput\n9\n1 2 3 5 6 7 8 9 10\n\nOutput\n4\n\n\n\n-----Note-----\n\nIn 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.",
  "inputs": [
   "5\n2 3 4 6 9\n",
   "9\n1 2 3 5 6 7 8 9 10\n",
   "4\n1 2 4 6\n",
   "7\n1 2 3 4 7 9 10\n",
   "1\n1\n",
   "8\n3 4 5 6 7 8 9 10\n",
   "5\n2 3 7 9 10\n",
   "3\n1 4 7\n",
   "1\n4\n",
   "9\n1 2 3 4 5 6 7 9 10\n",
   "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\n",
   "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\n",
   "3\n21 67 243\n",
   "3\n150 358 382\n",
   "10\n13 2187 2197 4567 5200 29873 67866 98798 99999 100000\n",
   "10\n1 2 4 8 16 32 33 64 128 256\n",
   "10\n2 4 8 67 128 324 789 1296 39877 98383\n",
   "10\n2 3 4 5 6 8 9 10 17 92\n",
   "10\n2 3 10 40 478 3877 28787 88888 99999 100000\n",
   "10\n2 3 45 67 89 101 234 567 890 1234\n",
   "10\n2 3 4 5 6 7 8 9 10 11\n",
   "2\n5101 10202\n",
   "1\n99991\n",
   "2\n1009 2018\n",
   "2\n601 1202\n"
  ],
  "outputs": [
   "4\n",
   "4\n",
   "3\n",
   "3\n",
   "1\n",
   "4\n",
   "2\n",
   "1\n",
   "1\n",
   "4\n",
   "49\n",
   "15\n",
   "2\n",
   "3\n",
   "6\n",
   "8\n",
   "7\n",
   "6\n",
   "6\n",
   "5\n",
   "5\n",
   "2\n",
   "1\n",
   "2\n",
   "2\n"
  ]
 },
 {
  "id": "APPS-3938",
  "question": "There is a square grid of size $n \\times n$. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs $\\min(h, w)$ to color a rectangle of size $h \\times w$. You are to make all cells white for minimum total cost.\n\nThe square is large, so we give it to you in a compressed way. The set of black cells is the union of $m$ rectangles.\n\n\n-----Input-----\n\nThe first line contains two integers $n$ and $m$ ($1 \\le n \\le 10^{9}$, $0 \\le m \\le 50$) — the size of the square grid and the number of black rectangles.\n\nEach of the next $m$ lines contains 4 integers $x_{i1}$ $y_{i1}$ $x_{i2}$ $y_{i2}$ ($1 \\le x_{i1} \\le x_{i2} \\le n$, $1 \\le y_{i1} \\le y_{i2} \\le n$) — the coordinates of the bottom-left and the top-right corner cells of the $i$-th black rectangle.\n\nThe rectangles may intersect.\n\n\n-----Output-----\n\nPrint a single integer — the minimum total cost of painting the whole square in white.\n\n\n-----Examples-----\nInput\n10 2\n4 1 5 10\n1 4 10 5\n\nOutput\n4\n\nInput\n7 6\n2 1 2 1\n4 2 4 3\n2 5 2 5\n2 3 5 3\n1 2 1 2\n3 2 5 3\n\nOutput\n3\n\n\n\n-----Note-----\n\nThe examples and some of optimal solutions are shown on the pictures below.\n\n [Image]",
  "inputs": [
   "10 2\n4 1 5 10\n1 4 10 5\n",
   "7 6\n2 1 2 1\n4 2 4 3\n2 5 2 5\n2 3 5 3\n1 2 1 2\n3 2 5 3\n",
   "1 0\n",
   "200 13\n84 113 191 187\n52 68 74 83\n63 46 158 68\n38 15 170 81\n38 81 164 183\n109 52 141 156\n117 151 126 155\n21 25 128 197\n111 30 163 59\n138 62 154 73\n83 161 143 189\n26 56 77 196\n19 56 66 150\n",
   "10 3\n4 8 6 9\n2 3 4 4\n6 5 6 6\n",
   "10 5\n3 2 10 5\n8 2 10 2\n5 4 5 6\n5 1 8 7\n10 4 10 10\n",
   "10 9\n6 1 9 9\n5 1 8 8\n4 7 6 8\n3 9 10 9\n1 2 3 4\n8 6 9 7\n5 1 5 8\n3 7 3 10\n2 6 4 9\n",
   "50 3\n17 33 19 45\n1 13 47 50\n2 38 31 49\n",
   "50 5\n2 16 39 20\n32 29 36 42\n14 4 23 9\n17 16 28 45\n1 33 46 39\n",
   "50 9\n15 28 32 38\n7 34 45 49\n14 7 25 49\n22 4 28 48\n1 34 41 36\n27 12 29 36\n4 6 30 18\n1 40 40 41\n9 22 45 32\n",
   "200 3\n171 77 191 120\n1 177 46 182\n42 15 162 50\n",
   "200 5\n9 10 59 49\n32 6 83 156\n78 133 125 170\n28 92 177 175\n37 23 168 25\n",
   "200 9\n98 2 172 82\n46 122 98 161\n31 28 98 65\n40 109 189 195\n27 20 73 73\n183 46 198 77\n42 29 103 132\n115 34 160 68\n50 20 93 182\n",
   "200 18\n16 4 162 109\n7 98 30 184\n30 85 61 186\n48 160 177 178\n25 27 76 185\n39 2 119 119\n50 126 151 127\n49 21 165 49\n67 9 190 105\n2 10 112 86\n9 39 158 158\n89 105 125 137\n153 67 196 157\n104 97 130 163\n2 109 75 194\n43 97 96 97\n1 98 168 168\n111 30 129 73\n",
   "200 24\n26 9 43 17\n20 27 44 190\n78 27 117 96\n6 43 55 192\n8 120 166 133\n91 44 114 47\n52 185 149 185\n145 42 169 161\n2 132 93 136\n11 127 156 133\n72 143 161 148\n9 31 52 50\n73 20 79 184\n132 3 161 73\n129 11 192 44\n85 188 150 195\n158 159 174 176\n81 60 192 167\n51 47 119 54\n18 165 37 197\n13 27 169 34\n28 120 45 176\n10 79 178 112\n122 22 173 150\n",
   "1000 3\n296 494 507 910\n101 154 570 609\n48 579 101 812\n",
   "1000 5\n334 123 582 438\n183 433 852 934\n435 626 529 996\n143 78 824 386\n21 363 955 978\n",
   "1000 9\n221 596 897 600\n346 990 822 993\n697 63 874 749\n533 77 955 224\n12 263 860 834\n184 70 395 175\n290 481 363 942\n130 135 364 276\n24 81 783 437\n",
   "1000 13\n127 536 917 639\n595 533 881 744\n695 484 985 618\n717 308 888 531\n389 430 908 589\n50 140 388 210\n130 92 254 933\n730 319 936 859\n455 184 890 754\n371 254 609 479\n92 9 311 534\n110 444 942 951\n633 148 807 799\n",
   "1000 18\n741 34 804 58\n629 658 751 844\n502 335 936 923\n105 35 332 652\n362 176 827 591\n627 573 814 986\n851 608 980 867\n58 406 376 603\n282 28 541 534\n235 19 271 371\n166 495 377 886\n309 152 861 240\n507 265 990 701\n216 27 454 934\n169 208 789 536\n324 92 642 840\n189 341 805 359\n695 765 790 901\n",
   "1000 24\n190 39 552 958\n539 146 763 587\n31 526 423 673\n208 432 953 442\n263 69 719 635\n162 428 623 797\n49 126 94 963\n749 623 979 919\n190 461 367 855\n211 240 939 914\n169 80 336 203\n684 546 829 582\n80 218 324 327\n560 452 656 637\n316 534 982 642\n521 634 758 686\n514 324 753 437\n342 395 384 995\n479 246 723 400\n217 344 886 381\n52 50 686 432\n636 245 699 643\n205 9 278 62\n446 460 479 660\n",
   "1000000000 3\n759015278 311645863 977199104 413261371\n17450998 375349221 428269906 902340672\n310207450 432866707 841374960 756699437\n",
   "1000000000 5\n175991137 463805003 423173142 846453004\n316647784 561571055 533177891 759404250\n367497836 223465366 484781581 257304521\n854838912 188836931 920765503 912199365\n129732287 492353023 208065087 527794268\n",
   "1000000000 9\n755312705 208314772 979816776 413350061\n504975947 580545612 742993862 822481605\n71081030 302221415 777045906 760955957\n59005620 71441769 579437611 173761068\n108290992 135681316 130173981 423327924\n730854196 342245706 987367869 746156573\n549592180 299075961 851728078 759898613\n767765094 416880160 988884730 602444576\n132601847 887575854 837539482 977191979\n"
  ],
  "outputs": [
   "4\n",
   "3\n",
   "0\n",
   "173\n",
   "5\n",
   "8\n",
   "10\n",
   "38\n",
   "32\n",
   "45\n",
   "63\n",
   "162\n",
   "172\n",
   "193\n",
   "191\n",
   "523\n",
   "919\n",
   "850\n",
   "936\n",
   "933\n",
   "952\n",
   "590694810\n",
   "458554593\n",
   "827985250\n"
  ]
 },
 {
  "id": "APPS-3710",
  "question": "Today Pari and Arya are playing a game called Remainders.\n\nPari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value $x \\text{mod} k$. There are n ancient numbers c_1, c_2, ..., c_{n} and Pari has to tell Arya $x \\operatorname{mod} c_{i}$ if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value $x \\text{mod} k$ for any positive integer x?\n\nNote, that $x \\text{mod} y$ means the remainder of x after dividing it by y.\n\n\n-----Input-----\n\nThe first line of the input contains two integers n and k (1 ≤ n,  k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari.\n\nThe second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 1 000 000).\n\n\n-----Output-----\n\nPrint \"Yes\" (without quotes) if Arya has a winning strategy independent of value of x, or \"No\" (without quotes) otherwise.\n\n\n-----Examples-----\nInput\n4 5\n2 3 5 12\n\nOutput\nYes\n\nInput\n2 7\n2 3\n\nOutput\nNo\n\n\n\n-----Note-----\n\nIn the first sample, Arya can understand $x \\operatorname{mod} 5$ because 5 is one of the ancient numbers.\n\nIn the second sample, Arya can't be sure what $x \\text{mod} 7$ is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.",
  "inputs": [
   "4 5\n2 3 5 12\n",
   "2 7\n2 3\n",
   "1 6\n8\n",
   "2 3\n9 4\n",
   "4 16\n19 16 13 9\n",
   "5 10\n5 16 19 9 17\n",
   "11 95\n31 49 8 139 169 121 71 17 43 29 125\n",
   "17 71\n173 43 139 73 169 199 49 81 11 89 131 107 23 29 125 152 17\n",
   "13 86\n41 64 17 31 13 97 19 25 81 47 61 37 71\n",
   "15 91\n49 121 83 67 128 125 27 113 41 169 149 19 37 29 71\n",
   "2 4\n2 2\n",
   "14 87\n1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619 1619\n",
   "12 100\n1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766 1766\n",
   "1 994619\n216000\n",
   "1 651040\n911250\n",
   "1 620622\n60060\n",
   "1 1\n559872\n",
   "88 935089\n967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967 967\n",
   "93 181476\n426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426 426\n",
   "91 4900\n630 630 70 630 910 630 630 630 770 70 770 630 630 770 70 630 70 630 70 630 70 630 630 70 910 630 630 630 770 630 630 630 70 910 70 630 70 630 770 630 630 70 630 770 70 630 70 70 630 630 70 70 70 70 630 70 70 770 910 630 70 630 770 70 910 70 630 910 630 70 770 70 70 630 770 630 70 630 70 70 630 70 630 770 630 70 630 630 70 910 630\n",
   "61 531012\n698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 963349 698043 698043 698043 698043 966694 698043 698043 698043 698043 698043 698043 636247 698043 963349 698043 698043 698043 698043 697838 698043 963349 698043 698043 966694 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 698043 963349 698043 698043 698043 698043 963349 698043\n",
   "1 216000\n648000\n",
   "2 8\n4 4\n",
   "3 8\n4 4 4\n",
   "2 8\n2 4\n"
  ],
  "outputs": [
   "Yes\n",
   "No\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "No\n",
   "No\n",
   "No\n",
   "Yes\n",
   "No\n",
   "No\n",
   "No\n",
   "No\n",
   "No\n",
   "No\n",
   "Yes\n",
   "No\n",
   "No\n",
   "No\n",
   "No\n",
   "Yes\n",
   "No\n",
   "No\n",
   "No\n"
  ]
 },
 {
  "id": "APPS-3925",
  "question": "Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. \n\nInspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now wants to select several consequent (contiguous) pieces of alternating colors to create a zebra. Let's call the number of selected pieces the length of the zebra.\n\nBefore assembling the zebra Grisha can make the following operation $0$ or more times. He splits the sequence in some place into two parts, then reverses each of them and sticks them together again. For example, if Grisha has pieces in the order \"bwbbw\" (here 'b' denotes a black strip, and 'w' denotes a white strip), then he can split the sequence as bw|bbw (here the vertical bar represents the cut), reverse both parts and obtain \"wbwbb\".\n\nDetermine the maximum possible length of the zebra that Grisha can produce.\n\n\n-----Input-----\n\nThe only line contains a string $s$ ($1 \\le |s| \\le 10^5$, where $|s|$ denotes the length of the string $s$) comprised of lowercase English letters 'b' and 'w' only, where 'w' denotes a white piece and 'b' denotes a black piece.\n\n\n-----Output-----\n\nPrint a single integer — the maximum possible zebra length.\n\n\n-----Examples-----\nInput\nbwwwbwwbw\n\nOutput\n5\n\nInput\nbwwbwwb\n\nOutput\n3\n\n\n\n-----Note-----\n\nIn the first example one of the possible sequence of operations is bwwwbww|bw $\\to$ w|wbwwwbwb $\\to$ wbwbwwwbw, that gives the answer equal to $5$.\n\nIn the second example no operation can increase the answer.",
  "inputs": [
   "bwwwbwwbw\n",
   "bwwbwwb\n",
   "bwb\n",
   "bbbbwbwwbbwwwwwbbbwb\n",
   "bbwwwbwwbwwbbwwwwwbbbbbbwbwwwwbbwwbbwbbwbwwwbwwwwbwwbbwwwbbwbbwwbbwbwwwwwwwbbwwbbwwbbwwbbbwbwbbbwbbbwwwbbbwwwwbbwbwbbwwbwbbbwbwwbbwbbwbbwbwwwwbbbbbwwb\n",
   "wwwbbwbbbwbwbwwbwwbbbwbwbwwbbbwbwwwbwwbwbbbbwwbwwwwwbwwwwwwwwbbwwwwbbbbbwbwbbwwbbbbbwbwbbwbwwwbbwwbbbwwwbbwwbwwbbbbwwbwbbwbwwbbwbwbwbbwwbwwwbwbwbbbwwwwwwbwwbbbwwbwwbwbwwwbbwwwwwwwwwbwwbwbbbwbwwwwbwwbbwbbwbwwbwwbwwbbwbbwwwwbwwwbwwwbwbwwwbbwwbbwwbwbwwwwwwbwbwwwwbbwwwbwbwwwbbwwwwwbwwbwbbbbbwbwwbbbbbbbwbbwbbwwwwwbbbbbbwbbwwwwwwbwwwwbbbbwbwbbbbbbbbwwbbwwwwwwbbbbwbwbbwwbwwwbwbwbbbwwbbbbbwbbbbbbwbwwbwbbbwbbwbbwbwwwbwwwbwwwwbbwwbwwwwbbbwwbbbbwwwwwbwwwwwwbwbwwwwbwwwbwwwbwwbwbbwbbwbbwwbbbbbbbbwbwbbbwwwwwb\n",
   "bw\n",
   "b\n",
   "w\n",
   "bbbbbbwbwb\n",
   "wbwb\n",
   "bwbw\n",
   "wbwbwbwbwbwb\n",
   "wbwbwbwbwb\n",
   "bwbwbw\n",
   "bww\n",
   "wbwbwb\n",
   "www\n",
   "bwbwbwbwbwbw\n",
   "bwbwbwbwbwbwbwbwbwbwbwbwbwbwbwbwbwbwbwbwbw\n",
   "bwwwwwbbbbbw\n",
   "wwwwb\n",
   "bwbwwwwwwwwbwb\n",
   "bwbwbbbbwb\n",
   "wbbwbw\n"
  ],
  "outputs": [
   "5\n",
   "3\n",
   "3\n",
   "4\n",
   "5\n",
   "7\n",
   "2\n",
   "1\n",
   "1\n",
   "5\n",
   "4\n",
   "4\n",
   "12\n",
   "10\n",
   "6\n",
   "3\n",
   "6\n",
   "1\n",
   "12\n",
   "42\n",
   "4\n",
   "3\n",
   "4\n",
   "5\n",
   "4\n"
  ]
 },
 {
  "id": "APPS-3800",
  "question": "You have a string of decimal digits s. Let's define b_{ij} = s_{i}·s_{j}. Find in matrix b the number of such rectangles that the sum b_{ij} for all cells (i, j) that are the elements of the rectangle equals a in each rectangle.\n\nA rectangle in a matrix is a group of four integers (x, y, z, t) (x ≤ y, z ≤ t). The elements of the rectangle are all cells (i, j) such that x ≤ i ≤ y, z ≤ j ≤ t.\n\n\n-----Input-----\n\nThe first line contains integer a (0 ≤ a ≤ 10^9), the second line contains a string of decimal integers s (1 ≤ |s| ≤ 4000).\n\n\n-----Output-----\n\nPrint a single integer — the answer to a problem.\n\nPlease, 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.\n\n\n-----Examples-----\nInput\n10\n12345\n\nOutput\n6\n\nInput\n16\n439873893693495623498263984765\n\nOutput\n40",
  "inputs": [
   "10\n12345\n",
   "16\n439873893693495623498263984765\n",
   "0\n1230\n",
   "8398\n67950927224842887617892831243606761170908507858527\n",
   "2\n11\n",
   "4\n111\n",
   "0\n0\n",
   "1\n0\n",
   "0\n1\n",
   "0\n0000\n",
   "1\n00\n",
   "1\n000\n",
   "1\n11111\n",
   "700\n100101011011001100111101100101000100000000011001111000111110001011011100010110000000000100100000001100000011110011101110011101101110111011011100001001101011000100000000000110001000101001100011111110011010101011010100010100001011011111001011000101001101000111010100110000100100110011111100010111100010000101001110111101110011111000111011011110111\n",
   "1000000000\n769416574772919262229125278908144478541501489034872535880758612234526208997051461441045410435259231256676917086438172075984271711722261161236033705315696117638300191007208614272746181036958213963736353682247646595587613148679926094811\n",
   "10000\n011111011000110010011010001011101100110111000100111110011100010001111010010010\n",
   "5\n1010100010101000010101001010102020201010100101020\n",
   "0\n0001001001011001100101100001111111001010011111000100000000011000001010110111100100000000001110110101010010001010100110011100001010001\n",
   "0\n11002201122211202102\n",
   "0\n3123232011321302332331322102332011002122123113023032320333332330233131131123012232200000120323200110\n",
   "2\n21111102201122101122\n",
   "3\n0130301201202102033203302203131122023031112010202333033033021210331110110022230021013231130200102022\n",
   "0\n5054451336060064631662402176557747457153065525132775141002773502671221320017407134475306346213334141573052346075726400141731757473641\n",
   "1\n14230330640346634338\n",
   "2\n5101140593483723176811719219208813520975285810392000077455984289096240663245004460322003001554026756\n"
  ],
  "outputs": [
   "6\n",
   "40\n",
   "19\n",
   "0\n",
   "4\n",
   "4\n",
   "1\n",
   "0\n",
   "0\n",
   "100\n",
   "0\n",
   "0\n",
   "25\n",
   "3390908\n",
   "0\n",
   "0\n",
   "14288\n",
   "3559240\n",
   "2484\n",
   "322176\n",
   "532\n",
   "7980\n",
   "373821\n",
   "1\n",
   "800\n"
  ]
 },
 {
  "id": "APPS-3751",
  "question": "Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.\n\nTo obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.\n\nYou are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.\n\n\n-----Input-----\n\nIn the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.\n\n\n-----Output-----\n\nIf this program can be a result of Kostya's obfuscation, print \"YES\" (without quotes), otherwise print \"NO\".\n\n\n-----Examples-----\nInput\nabacaba\n\nOutput\nYES\n\nInput\njinotega\n\nOutput\nNO\n\n\n\n-----Note-----\n\nIn the first sample case, one possible list of identifiers would be \"number string number character number string number\". Here how Kostya would obfuscate the program:\n\n\n\n replace all occurences of number with a, the result would be \"a string a character a string a\",\n\n replace all occurences of string with b, the result would be \"a b a character a b a\",\n\n replace all occurences of character with c, the result would be \"a b a c a b a\",\n\n all identifiers have been replaced, thus the obfuscation is finished.",
  "inputs": [
   "abacaba\n",
   "jinotega\n",
   "aaaaaaaaaaa\n",
   "aba\n",
   "bab\n",
   "a\n",
   "abcdefghijklmnopqrstuvwxyz\n",
   "fihyxmbnzq\n",
   "aamlaswqzotaanasdhcvjoaiwdhctezzawagkdgfffeqkyrvbcrfqgkdsvximsnvmkmjyofswmtjdoxgwamsaatngenqvsvrvwlbzuoeaolfcnmdacrmdleafbsmerwmxzyylfhemnkoayuhtpbikm\n",
   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
   "darbbbcwynbbbbaacbkvbakavabbbabzajlbajryaabbbccxraakgniagbtsswcfbkubdmcasccepybkaefcfsbzdddxgcjadybcfjtmqbspflqrdghgfwnccfveogdmifkociqscahdejctacwzbkhihajfilrgcjiofwfklifobozikcmvcfeqlidrgsgdfxffaaebzjxngsjxiclyolhjokqpdbfffooticxsezpgqkhhzmbmqgskkqvefzyijrwhpftcmbedmaflapmeljaudllojfpgfkpvgylaglrhrslxlprbhgknrctilngqccbddvpamhifsbmyowohczizjcbleehfrecjbqtxertnpfmalejmbxkhkkbyopuwlhkxuqellsybgcndvniyyxfoufalstdsdfjoxlnmigkqwmgojsppaannfstxytelluvvkdcezlqfsperwyjsdsmkvgjdbksswamhmoukcawiigkggztr\n",
   "bbbbbb\n",
   "aabbbd\n",
   "abdefghijklmnopqrstuvwxyz\n",
   "abcdeghijklmnopqrstuvwxyz\n",
   "abcdefghijklmnopqrsuvwxyz\n",
   "abcdefghijklmnopqrstuvwxy\n",
   "abcdefghijklmnopqrsutvwxyz\n",
   "acdef\n",
   "z\n",
   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaababaaababaabababccbabdbcbadccacdbdedabbeecbcabbdcaecdabbedddafeffaccgeacefbcahabfiiegecdbebabhhbdgfeghhbfahgagefbgghdbhadeicbdfgdchhefhigfcgdhcihecacfhadfgfejccibcjkfhbigbealjjkfldiecfdcafbamgfkbjlbifldghmiifkkglaflmjfmkfdjlbliijkgfdelklfnadbifgbmklfbqkhirhcadoadhmjrghlmelmjfpakqkdfcgqdkaeqpbcdoeqglqrarkipncckpfmajrqsfffldegbmahsfcqdfdqtrgrouqajgsojmmukptgerpanpcbejmergqtavwsvtveufdseuemwrhfmjqinxjodddnpcgqullrhmogflsxgsbapoghortiwcovejtinncozk\n",
   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbabbbabbaaabbaaaaabaabbaa\n",
   "aababbabbaabbbbbaabababaabbbaaaaabbabbabbaabbbbabaabbaaababbaaacbbabbbbbbcbcababbccaaacbaccaccaababbccaacccaabaaccaaabacacbaabacbaacbaaabcbbbcbbaacaabcbcbccbacabbcbabcaccaaaaaabcbacabcbabbbbbabccbbcacbaaabbccbbaaaaaaaaaaaadbbbabdacabdaddddbaabbddbdabbdacbacbacaaaabbacadbcddddadaddabbdccaddbaaacbceebbceadbeaadecddbbbcaaecbdeaebaddbbdebbcbaabcacbdcdc\n",
   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbaabaabaababbbabbacacbbbacbbaaaabbccacbaabaaccbbbbbcbbbacabbccaaabbaaacabcbacbcabbbbecbecadcbacbaadeeadabeacdebccdbbcaecdbeeebbebcaaaeacdcbdeccdbbdcdebdcbdacebcecbacddeeaebcedffedfggbeedceacaecagdfedfabcfchffceachgcbicbcffeeebgcgiefcafhibhceiedgbfebbccegbehhibhhfedbaeedbghggffehggaeaidifhdhaggdjcfjhiaieaichjacedchejg\n"
  ],
  "outputs": [
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n",
   "YES\n",
   "YES\n",
   "NO\n"
  ]
 },
 {
  "id": "APPS-3993",
  "question": "Recently, Tokitsukaze found an interesting game. Tokitsukaze had $n$ items at the beginning of this game. However, she thought there were too many items, so now she wants to discard $m$ ($1 \\le m \\le n$) special items of them.\n\nThese $n$ items are marked with indices from $1$ to $n$. In the beginning, the item with index $i$ is placed on the $i$-th position. Items are divided into several pages orderly, such that each page contains exactly $k$ positions and the last positions on the last page may be left empty.\n\nTokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.\n\n [Image] Consider the first example from the statement: $n=10$, $m=4$, $k=5$, $p=[3, 5, 7, 10]$. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices $3$ and $5$. After, the first page remains to be special. It contains $[1, 2, 4, 6, 7]$, Tokitsukaze discards the special item with index $7$. After, the second page is special (since it is the first page containing a special item). It contains $[9, 10]$, Tokitsukaze discards the special item with index $10$. \n\nTokitsukaze wants to know the number of operations she would do in total.\n\n\n-----Input-----\n\nThe first line contains three integers $n$, $m$ and $k$ ($1 \\le n \\le 10^{18}$, $1 \\le m \\le 10^5$, $1 \\le m, k \\le n$) — the number of items, the number of special items to be discarded and the number of positions in each page.\n\nThe second line contains $m$ distinct integers $p_1, p_2, \\ldots, p_m$ ($1 \\le p_1 < p_2 < \\ldots < p_m \\le n$) — the indices of special items which should be discarded.\n\n\n-----Output-----\n\nPrint a single integer — the number of operations that Tokitsukaze would do in total.\n\n\n-----Examples-----\nInput\n10 4 5\n3 5 7 10\n\nOutput\n3\n\nInput\n13 4 5\n7 8 9 10\n\nOutput\n1\n\n\n\n-----Note-----\n\nFor the first example:\n\n  In the first operation, Tokitsukaze would focus on the first page $[1, 2, 3, 4, 5]$ and discard items with indices $3$ and $5$;  In the second operation, Tokitsukaze would focus on the first page $[1, 2, 4, 6, 7]$ and discard item with index $7$;  In the third operation, Tokitsukaze would focus on the second page $[9, 10]$ and discard item with index $10$. \n\nFor the second example, Tokitsukaze would focus on the second page $[6, 7, 8, 9, 10]$ and discard all special items at once.",
  "inputs": [
   "10 4 5\n3 5 7 10\n",
   "13 4 5\n7 8 9 10\n",
   "1 1 1\n1\n",
   "11 7 3\n2 3 4 5 6 7 11\n",
   "13 9 4\n1 2 3 6 7 8 11 12 13\n",
   "16 7 5\n2 3 4 5 6 15 16\n",
   "10 5 5\n2 3 4 5 6\n",
   "1000000000 2 1000000000\n1 1000000000\n",
   "1000000000000000000 2 1\n1 1000000000000000000\n",
   "3 2 1\n1 2\n",
   "15 15 15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n",
   "21 21 20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21\n",
   "35 35 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35\n",
   "33 32 1\n1 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33\n",
   "45 43 2\n1 2 3 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n",
   "101 55 10\n1 3 5 7 8 9 10 16 18 21 22 23 24 25 27 30 32 35 36 37 38 39 40 43 45 47 49 50 51 52 54 57 59 61 64 66 67 68 69 70 71 72 73 80 83 86 87 88 89 90 91 92 96 97 98\n",
   "107 20 13\n5 9 20 25 26 30 37 45 51 58 62 73 82 87 89 90 99 101 104 106\n",
   "1000000000000000000 10 68\n9818112234872670 233245257111863071 266483628625876079 375103213040049805 431982380866113633 489732004669478331 501030096787260719 541800997319766183 551892546260532408 696178619227890200\n",
   "1000000000000000000 20 365\n31881893160049984 103938857870698567 103962228223609431 140762820261865064 175962215264653912 239086305245565642 354522451098745823 383839975876242372 443471287955807705 478923027151493682 511195154588214957 619570919279066139 677571312513476877 705864797651447277 789633853044745934 867300890280086078 883297431113041450 891736036124527038 937306858250803630 990892290394455512\n",
   "1000000000000000000 2 1000000000\n102306300054748096 267367244641009859\n"
  ],
  "outputs": [
   "3\n",
   "1\n",
   "1\n",
   "4\n",
   "4\n",
   "4\n",
   "2\n",
   "1\n",
   "2\n",
   "2\n",
   "1\n",
   "2\n",
   "35\n",
   "32\n",
   "35\n",
   "15\n",
   "9\n",
   "10\n",
   "20\n",
   "2\n"
  ]
 },
 {
  "id": "APPS-3835",
  "question": "Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table $M$ with $n$ rows and $n$ columns such that $M_{ij}=a_i \\cdot a_j$ where $a_1, \\dots, a_n$ is some sequence of positive integers.\n\nOf course, the girl decided to take it to school with her. But while she was having lunch, hooligan Grisha erased numbers on the main diagonal and threw away the array $a_1, \\dots, a_n$. Help Sasha restore the array!\n\n\n-----Input-----\n\nThe first line contains a single integer $n$ ($3 \\leqslant n \\leqslant 10^3$), the size of the table. \n\nThe next $n$ lines contain $n$ integers each. The $j$-th number of the $i$-th line contains the number $M_{ij}$ ($1 \\leq M_{ij} \\leq 10^9$). The table has zeroes on the main diagonal, that is, $M_{ii}=0$.\n\n\n-----Output-----\n\nIn a single line print $n$ integers, the original array $a_1, \\dots, a_n$ ($1 \\leq a_i \\leq 10^9$). It is guaranteed that an answer exists. If there are multiple answers, print any.\n\n\n-----Examples-----\nInput\n5\n0 4 6 2 4\n4 0 6 2 4\n6 6 0 3 6\n2 2 3 0 2\n4 4 6 2 0\n\nOutput\n2 2 3 1 2 \nInput\n3\n0 99990000 99970002\n99990000 0 99980000\n99970002 99980000 0\n\nOutput\n9999 10000 9998",
  "inputs": [
   "5\n0 4 6 2 4\n4 0 6 2 4\n6 6 0 3 6\n2 2 3 0 2\n4 4 6 2 0\n",
   "3\n0 99990000 99970002\n99990000 0 99980000\n99970002 99980000 0\n",
   "3\n0 42 54\n42 0 63\n54 63 0\n",
   "6\n0 4 1 1 8 2\n4 0 4 4 32 8\n1 4 0 1 8 2\n1 4 1 0 8 2\n8 32 8 8 0 16\n2 8 2 2 16 0\n",
   "9\n0 2268 1701 5292 3969 4158 945 1008 4788\n2268 0 972 3024 2268 2376 540 576 2736\n1701 972 0 2268 1701 1782 405 432 2052\n5292 3024 2268 0 5292 5544 1260 1344 6384\n3969 2268 1701 5292 0 4158 945 1008 4788\n4158 2376 1782 5544 4158 0 990 1056 5016\n945 540 405 1260 945 990 0 240 1140\n1008 576 432 1344 1008 1056 240 0 1216\n4788 2736 2052 6384 4788 5016 1140 1216 0\n",
   "5\n0 418770 480249 81081 710127\n418770 0 253330 42770 374590\n480249 253330 0 49049 429583\n81081 42770 49049 0 72527\n710127 374590 429583 72527 0\n",
   "5\n0 32659800 17106978 20710818 51743259\n32659800 0 17620400 21332400 53296200\n17106978 17620400 0 11173764 27916182\n20710818 21332400 11173764 0 33797142\n51743259 53296200 27916182 33797142 0\n",
   "3\n0 2 4\n2 0 8\n4 8 0\n",
   "3\n0 4 4\n4 0 4\n4 4 0\n",
   "4\n0 8 16 32\n8 0 32 64\n16 32 0 128\n32 64 128 0\n",
   "4\n0 1 1 1000000000\n1 0 1 1000000000\n1 1 0 1000000000\n1000000000 1000000000 1000000000 0\n",
   "3\n0 1 1000000000\n1 0 1000000000\n1000000000 1000000000 0\n",
   "3\n0 100000000 100000000\n100000000 0 100000000\n100000000 100000000 0\n",
   "3\n0 36 72\n36 0 8\n72 8 0\n",
   "3\n0 30000 30000\n30000 0 900000000\n30000 900000000 0\n",
   "3\n0 16 24\n16 0 96\n24 96 0\n",
   "3\n0 6 6\n6 0 4\n6 4 0\n",
   "3\n0 24 24\n24 0 144\n24 144 0\n",
   "3\n0 1000000000 1000000000\n1000000000 0 1\n1000000000 1 0\n",
   "3\n0 999950884 999950884\n999950884 0 999950884\n999950884 999950884 0\n",
   "4\n0 540 756 1188\n540 0 1260 1980\n756 1260 0 2772\n1188 1980 2772 0\n",
   "4\n0 4 4 4\n4 0 4 4\n4 4 0 4\n4 4 4 0\n",
   "3\n0 24 36\n24 0 54\n36 54 0\n",
   "3\n0 10 5\n10 0 50\n5 50 0\n",
   "3\n0 8 20\n8 0 40\n20 40 0\n"
  ],
  "outputs": [
   "2 2 3 1 2 ",
   "9999 10000 9998 ",
   "6 7 9 ",
   "1 4 1 1 8 2 ",
   "63 36 27 84 63 66 15 16 76 ",
   "891 470 539 91 797 ",
   "5631 5800 3038 3678 9189 ",
   "1 2 4 ",
   "2 2 2 ",
   "2 4 8 16 ",
   "1 1 1 1000000000 ",
   "1 1 1000000000 ",
   "10000 10000 10000 ",
   "18 2 4 ",
   "1 30000 30000 ",
   "2 8 12 ",
   "3 2 2 ",
   "2 12 12 ",
   "1000000000 1 1 ",
   "31622 31622 31622 ",
   "18 30 42 66 ",
   "2 2 2 2 ",
   "4 6 9 ",
   "1 10 5 ",
   "2 4 10 "
  ]
 },
 {
  "id": "APPS-3795",
  "question": "Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $n$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $d$ rubles, and one euro costs $e$ rubles.\n\nRecall that there exist the following dollar bills: $1$, $2$, $5$, $10$, $20$, $50$, $100$, and the following euro bills — $5$, $10$, $20$, $50$, $100$, $200$ (note that, in this problem we do not consider the $500$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.\n\nHelp him — write a program that given integers $n$, $e$ and $d$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.\n\n\n-----Input-----\n\nThe first line of the input contains one integer $n$ ($1 \\leq n \\leq 10^8$) — the initial sum in rubles Andrew has. \n\nThe second line of the input contains one integer $d$ ($30 \\leq d \\leq 100$) — the price of one dollar in rubles. \n\nThe third line of the input contains integer $e$ ($30 \\leq e \\leq 100$) — the price of one euro in rubles.\n\n\n-----Output-----\n\nOutput one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.\n\n\n-----Examples-----\nInput\n100\n60\n70\n\nOutput\n40\n\nInput\n410\n55\n70\n\nOutput\n5\n\nInput\n600\n60\n70\n\nOutput\n0\n\n\n\n-----Note-----\n\nIn the first example, we can buy just $1$ dollar because there is no $1$ euro bill.\n\nIn the second example, optimal exchange is to buy $5$ euro and $1$ dollar.\n\nIn the third example, optimal exchange is to buy $10$ dollars in one bill.",
  "inputs": [
   "100\n60\n70\n",
   "410\n55\n70\n",
   "600\n60\n70\n",
   "50\n60\n70\n",
   "420\n70\n65\n",
   "1750\n45\n50\n",
   "100000000\n31\n33\n",
   "99\n100\n100\n",
   "99999998\n60\n75\n",
   "90\n80\n89\n",
   "999\n66\n74\n",
   "420\n65\n70\n",
   "1000\n63\n70\n",
   "1000\n60\n80\n",
   "8642\n70\n90\n",
   "10000\n68\n78\n",
   "11750\n49\n50\n",
   "54321\n63\n70\n",
   "99998\n68\n78\n",
   "99999\n70\n75\n",
   "100005\n60\n70\n",
   "9876543\n66\n88\n",
   "99750\n50\n51\n",
   "12149750\n45\n50\n",
   "23456789\n66\n100\n"
  ],
  "outputs": [
   "40\n",
   "5\n",
   "0\n",
   "50\n",
   "0\n",
   "0\n",
   "0\n",
   "99\n",
   "8\n",
   "10\n",
   "9\n",
   "5\n",
   "20\n",
   "0\n",
   "2\n",
   "2\n",
   "0\n",
   "1\n",
   "0\n",
   "4\n",
   "5\n",
   "17\n",
   "0\n",
   "0\n",
   "1\n"
  ]
 },
 {
  "id": "APPS-3733",
  "question": "One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of $n$ non-negative integers.\n\nIf there are exactly $K$ distinct values in the array, then we need $k = \\lceil \\log_{2} K \\rceil$ bits to store each value. It then takes $nk$ bits to store the whole file.\n\nTo reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers $l \\le r$, and after that all intensity values are changed in the following way: if the intensity value is within the range $[l;r]$, we don't change it. If it is less than $l$, we change it to $l$; if it is greater than $r$, we change it to $r$. You can see that we lose some low and some high intensities.\n\nYour task is to apply this compression in such a way that the file fits onto a disk of size $I$ bytes, and the number of changed elements in the array is minimal possible.\n\nWe remind you that $1$ byte contains $8$ bits.\n\n$k = \\lceil log_{2} K \\rceil$ is the smallest integer such that $K \\le 2^{k}$. In particular, if $K = 1$, then $k = 0$.\n\n\n-----Input-----\n\nThe first line contains two integers $n$ and $I$ ($1 \\le n \\le 4 \\cdot 10^{5}$, $1 \\le I \\le 10^{8}$) — the length of the array and the size of the disk in bytes, respectively.\n\nThe next line contains $n$ integers $a_{i}$ ($0 \\le a_{i} \\le 10^{9}$) — the array denoting the sound file.\n\n\n-----Output-----\n\nPrint a single integer — the minimal possible number of changed elements.\n\n\n-----Examples-----\nInput\n6 1\n2 1 2 3 4 3\n\nOutput\n2\n\nInput\n6 2\n2 1 2 3 4 3\n\nOutput\n0\n\nInput\n6 1\n1 1 2 2 3 3\n\nOutput\n2\n\n\n\n-----Note-----\n\nIn the first example we can choose $l=2, r=3$. The array becomes 2 2 2 3 3 3, the number of distinct elements is $K=2$, and the sound file fits onto the disk. Only two values are changed.\n\nIn the second example the disk is larger, so the initial file fits it and no changes are required.\n\nIn the third example we have to change both 1s or both 3s.",
  "inputs": [
   "6 1\n2 1 2 3 4 3\n",
   "6 2\n2 1 2 3 4 3\n",
   "6 1\n1 1 2 2 3 3\n",
   "10 1\n589934963 440265648 161048053 196789927 951616256 63404428 660569162 779938975 237139603 31052281\n",
   "40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 50110079 72399009 347194050 322418543 594963355 407238845 847251668 210179965 293944170 300817194 842872332 82882809 446438478 304657690 343250734 567326942 47727237 662711343 59995716 812214268 994315801 193163726 656281454 249432773 772706196 977253852 342331261 182317828 550599535 3939813\n",
   "50 20\n592183311 362557946 154127088 616872926 395353745 675069471 509655682 79915471 356656666 937992998 304422065 724106263 472338455 792258113 796069631 663370025 201799298 566151622 722278085 508905399 703159587 690854023 925377265 11010958 69791159 990158269 535460930 167415727 999216963 237203826 693974848 530462137 555061429 744123832 887168514 479773974 575345653 282142246 899762676 446274594 338501746 168668673 408947684 226311538 645441958 258972430 216333311 338561078 123733185 539429791\n",
   "1 1\n1\n",
   "2 1\n1 3\n",
   "100 1000\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\n",
   "81 800\n2 8 5 1 10 5 9 9 3 5 6 6 2 8 2 2 6 3 8 7 2 5 3 4 3 3 2 7 9 6 8 7 2 9 10 3 8 10 6 5 4 2 3 4 4 5 2 2 4 9 8 5 3 8 8 10 4 2 10 9 7 6 1 3 9 7 1 3 5 9 7 6 1 10 1 1 7 2 4 9 10\n",
   "8 33\n1 2 3 4 5 6 7 8\n",
   "8 64\n1 2 3 4 5 6 7 8\n",
   "8 65\n1 2 3 4 5 6 7 8\n",
   "8 31\n2 8 5 1 10 5 9 9\n",
   "3 11\n1 2 3\n",
   "5 100000\n1 2 3 4 5\n",
   "2 100000000\n1 2\n",
   "5 100000000\n1 2 3 4 5\n",
   "100 1000\n1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10\n",
   "100 800\n1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10\n",
   "8 10000000\n1 2 3 4 5 6 7 8\n",
   "1 4\n1\n",
   "5 1234567\n1 2 3 4 5\n",
   "20 8\n1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2\n",
   "9 1\n1 2 1 2 1 2 1 2 1000000000\n"
  ],
  "outputs": [
   "2\n",
   "0\n",
   "2\n",
   "9\n",
   "39\n",
   "42\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "0\n",
   "5\n"
  ]
 },
 {
  "id": "APPS-3877",
  "question": "Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility. \n\nInitially Sam has a list with a single element n. Then he has to perform certain operations on this list. In each operation Sam must remove any element x, such that x > 1, from the list and insert at the same position $\\lfloor \\frac{x}{2} \\rfloor$, $x \\operatorname{mod} 2$, $\\lfloor \\frac{x}{2} \\rfloor$ sequentially. He must continue with these operations until all the elements in the list are either 0 or 1.\n\nNow the masters want the total number of 1s in the range l to r (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?\n\n\n-----Input-----\n\nThe first line contains three integers n, l, r (0 ≤ n < 2^50, 0 ≤ r - l ≤ 10^5, r ≥ 1, l ≥ 1) – initial element and the range l to r.\n\nIt is guaranteed that r is not greater than the length of the final list.\n\n\n-----Output-----\n\nOutput the total number of 1s in the range l to r in the final sequence.\n\n\n-----Examples-----\nInput\n7 2 5\n\nOutput\n4\n\nInput\n10 3 10\n\nOutput\n5\n\n\n\n-----Note-----\n\nConsider first example:\n\n$[ 7 ] \\rightarrow [ 3,1,3 ] \\rightarrow [ 1,1,1,1,3 ] \\rightarrow [ 1,1,1,1,1,1,1 ] \\rightarrow [ 1,1,1,1,1,1,1 ]$\n\nElements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.\n\nFor the second example:\n\n$[ 10 ] \\rightarrow [ 1,0,1,1,1,0,1,0,1,0,1,1,1,0,1 ]$\n\nElements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5.",
  "inputs": [
   "7 2 5\n",
   "10 3 10\n",
   "56 18 40\n",
   "203 40 124\n",
   "903316762502 354723010040 354723105411\n",
   "33534354842198 32529564319236 32529564342569\n",
   "62518534961045 50734311240112 50734311287877\n",
   "95173251245550 106288351347530 106288351372022\n",
   "542 321 956\n",
   "3621 237 2637\n",
   "9056 336 896\n",
   "36007 368 24490\n",
   "244269 149154 244246\n",
   "880234 669493 757150\n",
   "3740160 1031384 1104236\n",
   "11586121 15337246 15397874\n",
   "38658997 35923164 35985664\n",
   "192308932 207804787 207866400\n",
   "950099012 175922161 176000556\n",
   "2787326787 3799676481 3799680514\n",
   "14417262581 8527979363 8528075536\n",
   "39889373539 7747197212 7747278363\n",
   "251772781087 70597428577 70597479816\n",
   "0 1 1\n",
   "1 1 1\n"
  ],
  "outputs": [
   "4\n",
   "5\n",
   "20\n",
   "67\n",
   "78355\n",
   "22239\n",
   "42439\n",
   "16565\n",
   "336\n",
   "2124\n",
   "311\n",
   "13253\n",
   "88609\n",
   "73585\n",
   "64965\n",
   "41868\n",
   "36004\n",
   "44142\n",
   "69369\n",
   "2618\n",
   "80707\n",
   "47105\n",
   "46933\n",
   "0\n",
   "1\n"
  ]
 },
 {
  "id": "APPS-3727",
  "question": "An integer sequence is called beautiful if the difference between any two consecutive numbers is equal to $1$. More formally, a sequence $s_1, s_2, \\ldots, s_{n}$ is beautiful if $|s_i - s_{i+1}| = 1$ for all $1 \\leq i \\leq n - 1$.\n\nTrans has $a$ numbers $0$, $b$ numbers $1$, $c$ numbers $2$ and $d$ numbers $3$. He wants to construct a beautiful sequence using all of these $a + b + c + d$ numbers.\n\nHowever, it turns out to be a non-trivial task, and Trans was not able to do it. Could you please help Trans?\n\n\n-----Input-----\n\nThe only input line contains four non-negative integers $a$, $b$, $c$ and $d$ ($0 < a+b+c+d \\leq 10^5$).\n\n\n-----Output-----\n\nIf it is impossible to construct a beautiful sequence satisfying the above constraints, print \"NO\" (without quotes) in one line.\n\nOtherwise, print \"YES\" (without quotes) in the first line. Then in the second line print $a + b + c + d$ integers, separated by spaces — a beautiful sequence. There should be $a$ numbers equal to $0$, $b$ numbers equal to $1$, $c$ numbers equal to $2$ and $d$ numbers equal to $3$.\n\nIf there are multiple answers, you can print any of them.\n\n\n-----Examples-----\nInput\n2 2 2 1\n\nOutput\nYES\n0 1 0 1 2 3 2\n\nInput\n1 2 3 4\n\nOutput\nNO\n\nInput\n2 2 2 3\n\nOutput\nNO\n\n\n\n-----Note-----\n\nIn the first test, it is easy to see, that the sequence is beautiful because the difference between any two consecutive numbers is equal to $1$. Also, there are exactly two numbers, equal to $0$, $1$, $2$ and exactly one number, equal to $3$.\n\nIt can be proved, that it is impossible to construct beautiful sequences in the second and third tests.",
  "inputs": [
   "2 2 2 1\n",
   "1 2 3 4\n",
   "2 2 2 3\n",
   "3436 3436 46563 46564\n",
   "15039 15038 34961 34961\n",
   "26 25 24 26\n",
   "67 66 33 34\n",
   "145 145 105 107\n",
   "211 209 91 91\n",
   "119 146 31 2\n",
   "197 280 249 164\n",
   "1 0 0 1\n",
   "0 0 1 2\n",
   "1 0 0 0\n",
   "104 182 94 18\n",
   "119 333 231 19\n",
   "0 1 1 1\n",
   "1 1 0 0\n",
   "0 1 1 0\n",
   "0 0 1 1\n",
   "1 1 1 0\n",
   "1 0 1 1\n",
   "1 1 0 1\n",
   "1 1 1 1\n",
   "2 0 0 0\n"
  ],
  "outputs": [
   "YES\n0 1 0 1 2 3 2\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "NO\n",
   "YES\n3 2 3\n",
   "YES\n0\n",
   "NO\n",
   "NO\n",
   "YES\n1 2 3\n",
   "YES\n0 1\n",
   "YES\n1 2\n",
   "YES\n2 3\n",
   "YES\n0 1 2\n",
   "NO\n",
   "NO\n",
   "YES\n0 1 2 3\n",
   "NO\n"
  ]
 },
 {
  "id": "APPS-3790",
  "question": "You are given an array of positive integers a_1, a_2, ..., a_{n} × T of length n × T. We know that for any i > n it is true that a_{i} = a_{i} - n. Find the length of the longest non-decreasing sequence of the given array.\n\n\n-----Input-----\n\nThe first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 10^7). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 300).\n\n\n-----Output-----\n\nPrint a single number — the length of a sought sequence.\n\n\n-----Examples-----\nInput\n4 3\n3 1 4 2\n\nOutput\n5\n\n\n\n-----Note-----\n\nThe array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.",
  "inputs": [
   "4 3\n3 1 4 2\n",
   "1 1000\n42\n",
   "31 3767\n16 192 152 78 224 202 186 52 118 19 13 38 199 196 35 295 100 64 205 37 166 124 169 214 66 243 134 192 253 270 92\n",
   "15 12226\n18 125 213 221 124 147 154 182 134 184 51 49 267 88 251\n",
   "81 10683\n3 52 265 294 213 242 185 151 27 165 128 237 124 14 43 147 104 162 124 103 233 156 288 57 289 195 129 77 97 138 153 289 203 126 34 5 97 35 224 120 200 203 222 94 171 294 293 108 145 193 227 206 34 295 1 233 258 7 246 34 60 232 58 169 77 150 272 279 171 228 168 84 114 229 149 97 66 246 212 236 151\n",
   "29 7954\n1 257 8 47 4 26 49 228 120 53 138 101 101 35 293 232 299 195 219 45 195 174 96 157 168 138 288 114 291\n",
   "39 1057\n1 120 247 206 260 117 152 24 162 266 202 152 278 199 63 188 271 62 62 177 213 77 229 197 263 178 211 102 255 257 163 134 14 66 11 113 216 288 225\n",
   "2 766\n147 282\n",
   "2 13101\n180 199\n",
   "29 1918\n8 81 38 146 195 199 31 153 267 139 48 202 38 259 139 71 253 3 289 44 210 81 78 259 236 189 219 102 133\n",
   "46 13793\n1 239 20 83 33 183 122 208 46 141 11 264 196 266 104 130 116 117 31 213 235 207 219 206 206 46 89 112 260 191 245 234 87 255 186 4 251 177 130 59 81 54 227 116 105 284\n",
   "2 8698\n71 225\n",
   "68 2450\n107 297 185 215 224 128 8 65 101 202 19 145 255 233 138 223 144 132 32 122 153 85 31 160 219 125 167 220 138 255 219 119 165 249 47 124 20 37 160 24 156 154 163 226 270 88 74 192 204 300 194 184 235 93 267 160 12 216 91 191 267 241 152 9 111 76 201 295\n",
   "100 10000000\n98 99 96 97 94 95 92 93 90 91 88 89 86 87 84 85 82 83 80 81 78 79 76 77 74 75 72 73 70 71 68 69 66 67 64 65 62 63 60 61 58 59 56 57 54 55 52 53 50 51 48 49 46 47 44 45 42 43 40 41 38 39 36 37 34 35 32 33 30 31 28 29 26 27 24 25 22 23 20 21 18 19 16 17 14 15 12 13 10 11 8 9 6 7 4 5 2 3 1 100\n",
   "99 10000000\n97 98 95 96 93 94 91 92 89 90 87 88 85 86 83 84 81 82 79 80 77 78 75 76 73 74 71 72 69 70 67 68 65 66 63 64 61 62 59 60 57 58 55 56 53 54 51 52 49 50 47 48 45 46 43 44 41 42 39 40 37 38 35 36 33 34 31 32 29 30 27 28 25 26 23 24 21 22 19 20 17 18 15 16 13 14 11 12 9 10 7 8 5 6 3 4 1 2 99\n",
   "99 10000000\n96 97 98 93 94 95 90 91 92 87 88 89 84 85 86 81 82 83 78 79 80 75 76 77 72 73 74 69 70 71 66 67 68 63 64 65 60 61 62 57 58 59 54 55 56 51 52 53 48 49 50 45 46 47 42 43 44 39 40 41 36 37 38 33 34 35 30 31 32 27 28 29 24 25 26 21 22 23 18 19 20 15 16 17 12 13 14 9 10 11 6 7 8 3 4 5 2 1 99\n",
   "100 10000000\n97 98 99 94 95 96 91 92 93 88 89 90 85 86 87 82 83 84 79 80 81 76 77 78 73 74 75 70 71 72 67 68 69 64 65 66 61 62 63 58 59 60 55 56 57 52 53 54 49 50 51 46 47 48 43 44 45 40 41 42 37 38 39 34 35 36 31 32 33 28 29 30 25 26 27 22 23 24 19 20 21 16 17 18 13 14 15 10 11 12 7 8 9 4 5 6 1 2 3 100\n",
   "98 10000000\n95 96 97 92 93 94 89 90 91 86 87 88 83 84 85 80 81 82 77 78 79 74 75 76 71 72 73 68 69 70 65 66 67 62 63 64 59 60 61 56 57 58 53 54 55 50 51 52 47 48 49 44 45 46 41 42 43 38 39 40 35 36 37 32 33 34 29 30 31 26 27 28 23 24 25 20 21 22 17 18 19 14 15 16 11 12 13 8 9 10 5 6 7 2 3 4 97 98\n",
   "95 10000000\n92 93 94 89 90 91 86 87 88 83 84 85 80 81 82 77 78 79 74 75 76 71 72 73 68 69 70 65 66 67 62 63 64 59 60 61 56 57 58 53 54 55 50 51 52 47 48 49 44 45 46 41 42 43 38 39 40 35 36 37 32 33 34 29 30 31 26 27 28 23 24 25 20 21 22 17 18 19 14 15 16 11 12 13 8 9 10 5 6 7 2 3 4 94 95\n",
   "98 10000000\n195 196 197 192 193 194 189 190 191 186 187 188 183 184 185 180 181 182 177 178 179 174 175 176 171 172 173 168 169 170 165 166 167 162 163 164 159 160 161 156 157 158 153 154 155 150 151 152 147 148 149 144 145 146 141 142 143 138 139 140 135 136 137 132 133 134 129 130 131 126 127 128 123 124 125 120 121 122 117 118 119 114 115 116 111 112 113 108 109 110 105 106 107 102 103 104 1 2\n",
   "95 10000000\n192 193 194 189 190 191 186 187 188 183 184 185 180 181 182 177 178 179 174 175 176 171 172 173 168 169 170 165 166 167 162 163 164 159 160 161 156 157 158 153 154 155 150 151 152 147 148 149 144 145 146 141 142 143 138 139 140 135 136 137 132 133 134 129 130 131 126 127 128 123 124 125 120 121 122 117 118 119 114 115 116 111 112 113 108 109 110 105 106 107 102 103 104 1 2\n",
   "98 10000000\n1 2 195 196 197 192 193 194 189 190 191 186 187 188 183 184 185 180 181 182 177 178 179 174 175 176 171 172 173 168 169 170 165 166 167 162 163 164 159 160 161 156 157 158 153 154 155 150 151 152 147 148 149 144 145 146 141 142 143 138 139 140 135 136 137 132 133 134 129 130 131 126 127 128 123 124 125 120 121 122 117 118 119 114 115 116 111 112 113 108 109 110 105 106 107 102 103 104\n",
   "98 10000000\n1 2 5 4 3 8 7 6 11 10 9 14 13 12 17 16 15 20 19 18 23 22 21 26 25 24 29 28 27 32 31 30 35 34 33 38 37 36 41 40 39 44 43 42 47 46 45 50 49 48 53 52 51 56 55 54 59 58 57 62 61 60 65 64 63 68 67 66 71 70 69 74 73 72 77 76 75 80 79 78 83 82 81 86 85 84 89 88 87 92 91 90 95 94 93 98 97 96\n",
   "98 10000000\n1 1 5 4 3 8 7 6 11 10 9 14 13 12 17 16 15 20 19 18 23 22 21 26 25 24 29 28 27 32 31 30 35 34 33 38 37 36 41 40 39 44 43 42 47 46 45 50 49 48 53 52 51 56 55 54 59 58 57 62 61 60 65 64 63 68 67 66 71 70 69 74 73 72 77 76 75 80 79 78 83 82 81 86 85 84 89 88 87 92 91 90 95 94 93 98 97 96\n",
   "98 10000000\n1 2 95 96 97 92 93 94 89 90 91 86 87 88 83 84 85 80 81 82 77 78 79 74 75 76 71 72 73 68 69 70 65 66 67 62 63 64 59 60 61 56 57 58 53 54 55 50 51 52 47 48 49 44 45 46 41 42 43 38 39 40 35 36 37 32 33 34 29 30 31 26 27 28 23 24 25 20 21 22 17 18 19 14 15 16 11 12 13 8 9 10 5 6 7 2 3 4\n"
  ],
  "outputs": [
   "5\n",
   "1000\n",
   "7546\n",
   "12234\n",
   "32070\n",
   "15919\n",
   "2128\n",
   "767\n",
   "13102\n",
   "3845\n",
   "27600\n",
   "8699\n",
   "7366\n",
   "10000050\n",
   "10000050\n",
   "10000065\n",
   "10000067\n",
   "20000034\n",
   "20000033\n",
   "10000065\n",
   "10000063\n",
   "10000066\n",
   "10000033\n",
   "20000032\n",
   "20000034\n"
  ]
 },
 {
  "id": "APPS-3871",
  "question": "A popular reality show is recruiting a new cast for the third season! $n$ candidates numbered from $1$ to $n$ have been interviewed. The candidate $i$ has aggressiveness level $l_i$, and recruiting this candidate will cost the show $s_i$ roubles.\n\nThe show host reviewes applications of all candidates from $i=1$ to $i=n$ by increasing of their indices, and for each of them she decides whether to recruit this candidate or not. If aggressiveness level of the candidate $i$ is strictly higher than that of any already accepted candidates, then the candidate $i$ will definitely be rejected. Otherwise the host may accept or reject this candidate at her own discretion. The host wants to choose the cast so that to maximize the total profit.\n\nThe show makes revenue as follows. For each aggressiveness level $v$ a corresponding profitability value $c_v$ is specified, which can be positive as well as negative. All recruited participants enter the stage one by one by increasing of their indices. When the participant $i$ enters the stage, events proceed as follows:\n\n  The show makes $c_{l_i}$ roubles, where $l_i$ is initial aggressiveness level of the participant $i$.  If there are two participants with the same aggressiveness level on stage, they immediately start a fight. The outcome of this is:\n\n  the defeated participant is hospitalized and leaves the show.  aggressiveness level of the victorious participant is increased by one, and the show makes $c_t$ roubles, where $t$ is the new aggressiveness level. \n\n The fights continue until all participants on stage have distinct aggressiveness levels. \n\nIt is allowed to select an empty set of participants (to choose neither of the candidates).\n\nThe host wants to recruit the cast so that the total profit is maximized. The profit is calculated as the total revenue from the events on stage, less the total expenses to recruit all accepted participants (that is, their total $s_i$). Help the host to make the show as profitable as possible.\n\n\n-----Input-----\n\nThe first line contains two integers $n$ and $m$ ($1 \\le n, m \\le 2000$) — the number of candidates and an upper bound for initial aggressiveness levels.\n\nThe second line contains $n$ integers $l_i$ ($1 \\le l_i \\le m$) — initial aggressiveness levels of all candidates.\n\nThe third line contains $n$ integers $s_i$ ($0 \\le s_i \\le 5000$) — the costs (in roubles) to recruit each of the candidates.\n\nThe fourth line contains $n + m$ integers $c_i$ ($|c_i| \\le 5000$) — profitability for each aggrressiveness level.\n\nIt is guaranteed that aggressiveness level of any participant can never exceed $n + m$ under given conditions.\n\n\n-----Output-----\n\nPrint a single integer — the largest profit of the show.\n\n\n-----Examples-----\nInput\n5 4\n4 3 1 2 1\n1 2 1 2 1\n1 2 3 4 5 6 7 8 9\n\nOutput\n6\n\nInput\n2 2\n1 2\n0 0\n2 1 -100 -100\n\nOutput\n2\n\nInput\n5 4\n4 3 2 1 1\n0 2 6 7 4\n12 12 12 6 -3 -5 3 10 -4\n\nOutput\n62\n\n\n\n-----Note-----\n\nIn the first sample case it is optimal to recruit candidates $1, 2, 3, 5$. Then the show will pay $1 + 2 + 1 + 1 = 5$ roubles for recruitment. The events on stage will proceed as follows:\n\n  a participant with aggressiveness level $4$ enters the stage, the show makes $4$ roubles;  a participant with aggressiveness level $3$ enters the stage, the show makes $3$ roubles;  a participant with aggressiveness level $1$ enters the stage, the show makes $1$ rouble;  a participant with aggressiveness level $1$ enters the stage, the show makes $1$ roubles, a fight starts. One of the participants leaves, the other one increases his aggressiveness level to $2$. The show will make extra $2$ roubles for this. \n\nTotal revenue of the show will be $4 + 3 + 1 + 1 + 2=11$ roubles, and the profit is $11 - 5 = 6$ roubles.\n\nIn the second sample case it is impossible to recruit both candidates since the second one has higher aggressiveness, thus it is better to recruit the candidate $1$.",
  "inputs": [
   "5 4\n4 3 1 2 1\n1 2 1 2 1\n1 2 3 4 5 6 7 8 9\n",
   "2 2\n1 2\n0 0\n2 1 -100 -100\n",
   "5 4\n4 3 2 1 1\n0 2 6 7 4\n12 12 12 6 -3 -5 3 10 -4\n",
   "7 5\n4 3 2 3 2 1 1\n6 8 9 1 2 0 5\n14 6 0 14 -12 -2 -13 10 -14 -3 10 -9\n",
   "7 4\n1 4 3 2 1 3 1\n8 2 2 1 4 3 2\n-6 14 8 13 -8 -6 -23 1 -17 9 -13\n",
   "7 4\n2 4 4 3 2 1 1\n1 5 4 0 2 2 6\n-2 9 12 8 -14 -19 -21 2 -4 -2 -2\n",
   "5 5\n5 4 3 2 2\n1 0 7 2 2\n0 10 -1 10 11 -2 3 8 3 3\n",
   "5 4\n4 3 2 1 1\n2 2 2 1 4\n2 3 3 4 -4 3 -5 -1 3\n",
   "15 15\n14 13 12 11 10 9 8 7 6 5 4 3 2 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30\n",
   "10 10\n10 10 7 9 8 3 3 10 7 3\n830 44 523 854 2814 3713 4060 4459 2969 1610\n-4686 -3632 -3799 3290 -3703 -2728 -1734 3011 -4878 -2210 -4851 -3660 -2476 -2847 -2173 -4398 -2895 2446 3298 -86\n",
   "11 10\n10 10 3 7 1 3 7 1 8 4 10\n4760 2257 1313 2152 2236 3005 1453 1879 4098 582 3719\n4696 1160 -1319 -4357 -3259 645 3495 3771 3591 -3196 4916 -2392 -2958 4242 -1219 -1239 4080 -4643 -1982 3780 2659\n",
   "15 15\n5 8 12 12 9 15 10 2 3 15 1 14 4 5 9\n2812 2979 2208 3179 339 3951 923 313 1223 1688 4429 52 1340 4222 152\n-4371 462 -1975 4253 2289 30 -1722 -1356 -251 -1141 4081 -4048 -1448 -842 -4770 -3795 3790 624 -1575 1012 328 732 -4716 3180 -4174 870 4771 616 -1424 -2726\n",
   "15 15\n4 3 11 11 1 14 14 15 13 4 5 9 7 1 13\n2454 2857 3172 2380 1574 3888 368 4036 541 3490 2223 4670 3422 1351 4669\n130 -3065 -4713 2646 -4470 -2753 -2444 -4997 3539 -2556 -4903 -239 3103 1893 -4313 3072 4228 -4430 60 720 -3131 3120 211 -4092 4564 -3658 -2648 -4914 -3123 -3085\n",
   "15 15\n3 5 1 5 14 7 8 13 8 5 9 3 2 4 12\n570 1841 1556 3107 388 3826 4815 2758 1385 3343 2437 2761 4873 1324 2659\n4632 -2684 -3542 -1119 3088 4465 -3167 3521 -2673 -61 -1321 -338 3338 -3216 -2105 -2219 -4927 -3392 1288 21 3411 -177 3388 2952 1143 1408 2092 3466 1270 4806\n",
   "15 15\n1 14 14 11 7 14 12 11 4 7 14 12 12 8 9\n4582 3245 995 3834 1623 1183 3366 586 2229 144 1125 4327 1954 1929 1281\n-1275 1632 -4529 -4883 2395 3433 -1731 -2278 3275 276 1854 3471 -3863 -481 2261 4648 -2330 -2354 4674 1886 -48 -3882 -1686 -3914 -2278 -1368 -3169 -2064 -4338 -3395\n",
   "15 15\n1 9 13 4 5 13 7 9 13 11 3 13 6 5 15\n2698 3754 4380 4561 1331 1121 2811 2783 2443 1946 3919 2418 984 4954 4272\n3226 -145 4892 1353 -2206 650 -2453 -4168 4907 1019 3277 -4878 -1470 2253 2717 -2801 266 842 -4099 1187 -1350 664 3241 973 -1383 3698 -588 2407 -352 -3754\n",
   "15 15\n14 4 3 11 4 6 10 7 9 12 7 8 3 9 12\n814 3633 1869 3762 1671 1059 2257 1505 3287 273 659 510 2435 4928 3788\n-2274 -3672 -3938 -254 -4649 -381 -3175 34 853 1356 -1391 -2820 923 -2855 4925 3660 2863 1880 -713 3053 3034 -4791 -3584 4108 -4804 -1237 -4098 -965 4041 4137\n",
   "15 5\n5 5 5 3 3 3 1 1 1 4 4 4 2 2 2\n1644 534 4138 987 4613 1026 949 3899 2283 2741 2410 2403 4397 1914 2642\n150 -3027 2817 -2011 1025 868 3251 2072 1029 2552 -3131 -1843 -4546 -1218 3069 -2903 -396 3225 1837 -1914\n",
   "15 5\n2 2 2 1 1 1 4 4 4 3 3 3 5 5 5\n3194 3057 1570 1665 1987 2261 1604 2627 4570 909 4255 4162 1264 4430 4233\n4739 -1245 4499 -1692 2441 3449 -2427 -1040 493 4550 -3594 459 421 -3844 -2431 3164 775 -540 -2764 -4697\n",
   "15 5\n2 2 2 5 5 5 1 1 1 4 4 4 3 3 3\n3218 4685 2478 2973 3467 4126 2259 4831 3805 1026 2626 920 2501 4367 3244\n-674 130 -3820 378 3856 4280 -263 1941 2115 -1701 259 2761 1478 -4719 3822 -364 1947 -2147 -3457 4272\n",
   "15 5\n1 1 1 2 2 2 4 4 4 3 3 3 5 5 5\n822 1311 4281 176 3421 3834 3809 2033 4566 4194 4472 2680 4369 3408 1360\n-4335 1912 20 697 -2978 -3139 1901 -2922 1579 4206 1954 -3187 -1399 91 -1678 17 960 4090 1943 1489\n",
   "15 5\n5 5 5 2 2 2 1 1 1 4 4 4 3 3 3\n846 359 1713 1484 794 698 4464 762 1853 836 3473 4439 606 3344 1002\n2411 1130 3860 608 -1563 1601 2315 58 3201 -3797 1491 -885 1410 -783 4574 4333 380 2483 -2658 -1701\n",
   "1 15\n11\n65\n576 -4348 3988 -4968 2212 -3005 4588 -4712 -415 -1088 -4887 -4884 -3043 -1838 4248 -3582\n",
   "1 1\n1\n499\n-4955 898\n",
   "2 2\n1 2\n1007 1736\n-4987 3535 -2296 29\n"
  ],
  "outputs": [
   "6\n",
   "2\n",
   "62\n",
   "46\n",
   "39\n",
   "36\n",
   "46\n",
   "11\n",
   "225\n",
   "197\n",
   "9973\n",
   "2913\n",
   "4087\n",
   "5693\n",
   "4753\n",
   "5269\n",
   "0\n",
   "2570\n",
   "8743\n",
   "11965\n",
   "1736\n",
   "12079\n",
   "0\n",
   "0\n",
   "1799\n"
  ]
 },
 {
  "id": "APPS-3824",
  "question": "Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:\n\n  start the race from some point of a field,  go around the flag,  close cycle returning back to the starting point. \n\nPolycarp knows the coordinates of the starting point (x_1, y_1) and the coordinates of the point where the flag is situated (x_2, y_2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (x, y) to any of four points: (x - 1, y), (x + 1, y), (x, y - 1) or (x, y + 1).\n\nThus the quadcopter path is a closed cycle starting and finishing in (x_1, y_1) and containing the point (x_2, y_2) strictly inside.\n\n [Image] The picture corresponds to the first example: the starting (and finishing) point is in (1, 5) and the flag is in (5, 2). \n\nWhat is the minimal length of the quadcopter path?\n\n\n-----Input-----\n\nThe first line contains two integer numbers x_1 and y_1 ( - 100 ≤ x_1, y_1 ≤ 100) — coordinates of the quadcopter starting (and finishing) point.\n\nThe second line contains two integer numbers x_2 and y_2 ( - 100 ≤ x_2, y_2 ≤ 100) — coordinates of the flag.\n\nIt is guaranteed that the quadcopter starting point and the flag do not coincide.\n\n\n-----Output-----\n\nPrint the length of minimal path of the quadcopter to surround the flag and return back.\n\n\n-----Examples-----\nInput\n1 5\n5 2\n\nOutput\n18\n\nInput\n0 1\n0 0\n\nOutput\n8",
  "inputs": [
   "1 5\n5 2\n",
   "0 1\n0 0\n",
   "-100 -100\n100 100\n",
   "-100 -100\n-100 100\n",
   "-100 -100\n100 -100\n",
   "100 -100\n-100 -100\n",
   "100 -100\n-100 100\n",
   "100 -100\n100 100\n",
   "-100 100\n-100 -100\n",
   "-100 100\n100 -100\n",
   "-100 100\n100 100\n",
   "100 100\n-100 -100\n",
   "100 100\n-100 100\n",
   "100 100\n100 -100\n",
   "45 -43\n45 -44\n",
   "76 76\n75 75\n",
   "-34 -56\n-35 -56\n",
   "56 -7\n55 -6\n",
   "43 -11\n43 -10\n",
   "1 -3\n2 -2\n",
   "-27 -25\n-28 68\n",
   "25 76\n24 76\n",
   "-53 63\n-53 62\n",
   "63 41\n62 40\n",
   "0 0\n0 1\n"
  ],
  "outputs": [
   "18\n",
   "8\n",
   "804\n",
   "406\n",
   "406\n",
   "406\n",
   "804\n",
   "406\n",
   "406\n",
   "804\n",
   "406\n",
   "804\n",
   "406\n",
   "406\n",
   "8\n",
   "8\n",
   "8\n",
   "8\n",
   "8\n",
   "8\n",
   "192\n",
   "8\n",
   "8\n",
   "8\n",
   "8\n"
  ]
 },
 {
  "id": "APPS-3868",
  "question": "Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process.\n\nThere are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for all jury members. For each city from 1 to n there is exactly one jury member living there. Olympiad preparation is a long and demanding process that requires k days of work. For all of these k days each of the n jury members should be present in Metropolis to be able to work on problems.\n\nYou know the flight schedule in the country (jury members consider themselves important enough to only use flights for transportation). All flights in Metropolia are either going to Metropolis or out of Metropolis. There are no night flights in Metropolia, or in the other words, plane always takes off at the same day it arrives. On his arrival day and departure day jury member is not able to discuss the olympiad. All flights in Megapolia depart and arrive at the same day.\n\nGather everybody for k days in the capital is a hard objective, doing that while spending the minimum possible money is even harder. Nevertheless, your task is to arrange the cheapest way to bring all of the jury members to Metrpolis, so that they can work together for k days and then send them back to their home cities. Cost of the arrangement is defined as a total cost of tickets for all used flights. It is allowed for jury member to stay in Metropolis for more than k days.\n\n\n-----Input-----\n\nThe first line of input contains three integers n, m and k (1 ≤ n ≤ 10^5, 0 ≤ m ≤ 10^5, 1 ≤ k ≤ 10^6). \n\nThe i-th of the following m lines contains the description of the i-th flight defined by four integers d_{i}, f_{i}, t_{i} and c_{i} (1 ≤ d_{i} ≤ 10^6, 0 ≤ f_{i} ≤ n, 0 ≤ t_{i} ≤ n, 1 ≤ c_{i} ≤ 10^6, exactly one of f_{i} and t_{i} equals zero), the day of departure (and arrival), the departure city, the arrival city and the ticket cost.\n\n\n-----Output-----\n\nOutput the only integer that is the minimum cost of gathering all jury members in city 0 for k days and then sending them back to their home cities.\n\nIf it is impossible to gather everybody in Metropolis for k days and then send them back to their home cities, output \"-1\" (without the quotes).\n\n\n-----Examples-----\nInput\n2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n\nOutput\n24500\n\nInput\n2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n\nOutput\n-1\n\n\n\n-----Note-----\n\nThe optimal way to gather everybody in Metropolis in the first sample test is to use flights that take place on days 1, 2, 8 and 9. The only alternative option is to send jury member from second city back home on day 15, that would cost 2500 more.\n\nIn the second sample it is impossible to send jury member from city 2 back home from Metropolis.",
  "inputs": [
   "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n",
   "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n",
   "2 5 5\n1 1 0 1\n2 2 0 100\n3 2 0 10\n9 0 1 1000\n10 0 2 10000\n",
   "2 4 5\n1 1 0 1\n2 2 0 10\n8 0 1 100\n9 0 2 1000\n",
   "1 2 1\n10 1 0 16\n20 0 1 7\n",
   "1 2 10\n20 0 1 36\n10 1 0 28\n",
   "1 2 9\n20 0 1 97\n10 1 0 47\n",
   "2 4 1\n20 0 1 72\n21 0 2 94\n9 2 0 43\n10 1 0 91\n",
   "2 4 10\n20 0 1 7\n9 2 0 32\n10 1 0 27\n21 0 2 19\n",
   "2 4 9\n10 1 0 22\n21 0 2 92\n9 2 0 29\n20 0 1 37\n",
   "3 6 1\n10 1 0 62\n8 3 0 83\n20 0 1 28\n22 0 3 61\n21 0 2 61\n9 2 0 75\n",
   "3 6 10\n22 0 3 71\n20 0 1 57\n8 3 0 42\n10 1 0 26\n9 2 0 35\n21 0 2 84\n",
   "3 6 9\n10 1 0 93\n20 0 1 26\n8 3 0 51\n22 0 3 90\n21 0 2 78\n9 2 0 65\n",
   "4 8 1\n9 2 0 3\n22 0 3 100\n20 0 1 40\n10 1 0 37\n23 0 4 49\n7 4 0 53\n21 0 2 94\n8 3 0 97\n",
   "4 8 10\n8 3 0 65\n21 0 2 75\n7 4 0 7\n23 0 4 38\n20 0 1 27\n10 1 0 33\n22 0 3 91\n9 2 0 27\n",
   "4 8 9\n8 3 0 61\n9 2 0 94\n23 0 4 18\n21 0 2 19\n20 0 1 52\n10 1 0 68\n22 0 3 5\n7 4 0 59\n",
   "5 10 1\n24 0 5 61\n22 0 3 36\n8 3 0 7\n21 0 2 20\n6 5 0 23\n20 0 1 28\n23 0 4 18\n9 2 0 40\n7 4 0 87\n10 1 0 8\n",
   "5 10 10\n24 0 5 64\n23 0 4 17\n20 0 1 91\n9 2 0 35\n21 0 2 4\n22 0 3 51\n6 5 0 69\n7 4 0 46\n8 3 0 92\n10 1 0 36\n",
   "5 10 9\n22 0 3 13\n9 2 0 30\n24 0 5 42\n21 0 2 33\n23 0 4 36\n20 0 1 57\n10 1 0 39\n8 3 0 68\n7 4 0 85\n6 5 0 35\n",
   "1 10 1\n278 1 0 4\n208 1 0 4\n102 0 1 9\n499 0 1 7\n159 0 1 8\n218 1 0 6\n655 0 1 5\n532 1 0 6\n318 0 1 6\n304 1 0 7\n",
   "2 10 1\n5 0 2 5\n52 2 0 9\n627 0 2 6\n75 0 1 6\n642 0 1 8\n543 0 2 7\n273 1 0 2\n737 2 0 4\n576 0 1 7\n959 0 2 5\n",
   "3 10 1\n48 2 0 9\n98 0 2 5\n43 0 1 8\n267 0 1 7\n394 3 0 7\n612 0 3 9\n502 2 0 6\n36 0 2 9\n602 0 1 3\n112 1 0 6\n",
   "4 10 1\n988 0 1 1\n507 1 0 9\n798 1 0 9\n246 0 3 7\n242 1 0 8\n574 4 0 7\n458 0 4 9\n330 0 2 9\n303 2 0 8\n293 0 3 9\n",
   "5 10 1\n132 0 4 7\n803 0 2 8\n280 3 0 5\n175 4 0 6\n196 1 0 7\n801 0 4 6\n320 0 5 7\n221 0 4 6\n446 4 0 8\n699 0 5 9\n",
   "6 10 1\n845 0 4 9\n47 0 4 8\n762 0 2 8\n212 6 0 6\n416 0 5 9\n112 5 0 9\n897 0 6 9\n541 0 4 5\n799 0 6 7\n252 2 0 9\n"
  ],
  "outputs": [
   "24500\n",
   "-1\n",
   "11011\n",
   "1111\n",
   "23\n",
   "-1\n",
   "144\n",
   "300\n",
   "-1\n",
   "180\n",
   "370\n",
   "-1\n",
   "403\n",
   "473\n",
   "-1\n",
   "376\n",
   "328\n",
   "-1\n",
   "438\n",
   "9\n",
   "23\n",
   "-1\n",
   "-1\n",
   "-1\n",
   "-1\n"
  ]
 },
 {
  "id": "APPS-3896",
  "question": "As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2^{n} members and coincidentally Natalia Fan Club also has 2^{n} members. Each member of MDC is assigned a unique id i from 0 to 2^{n} - 1. The same holds for each member of NFC.\n\nOne of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.\n\nThe complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.\n\nYou are given a binary number of length n named x. We know that member i from MDC dances with member $i \\oplus x$ from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (10^9 + 7).\n\nExpression $x \\oplus y$ denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor».\n\n\n-----Input-----\n\nThe first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100).\n\nThis number may contain leading zeros.\n\n\n-----Output-----\n\nPrint the complexity of the given dance assignent modulo 1000000007 (10^9 + 7).\n\n\n-----Examples-----\nInput\n11\n\nOutput\n6\n\nInput\n01\n\nOutput\n2\n\nInput\n1\n\nOutput\n1",
  "inputs": [
   "11\n",
   "01\n",
   "1\n",
   "1111111111111111111111111111111111\n",
   "0000000000000000000000000000000000000\n",
   "11111111111111111111111111111111111000000000000000000000000000\n",
   "00000000000000000000111111111111111111111111111111111111111111\n",
   "10100101000010011110101011011110001\n",
   "01010100001010111111001111001000101010010101000111011011111000\n",
   "10001010011010010101101010111001001001011110110101011000010100110\n",
   "00001100100101000111111100110010001101001000011110110000\n",
   "01100010011001101100001000000101001000101101000110011100101101111101010100000011101011100\n",
   "100111100\n",
   "11110111000110101111100100111110000011\n",
   "1000101010000101111110100110011110000011000110001111001001000110110011110110111110100\n",
   "0110011110111000001101001010101000011011101001001101000000111101010101111101010011101001111010111001\n",
   "0111001111110010000001111100110100111110001100100001111111110000010010111010010010010111000110001111\n",
   "1000000001101010101011111001001101011100011000010000100101001111001000110100100001110001100001000001\n",
   "1101010110001010100110011011101011010100010001110100010011011100011011000101110001010101110001101011\n",
   "1000001010111011110011111110011001011111011001110011100101111110100110111001100001110000011101011011\n",
   "10\n",
   "01\n",
   "00\n",
   "11\n",
   "0\n"
  ],
  "outputs": [
   "6\n",
   "2\n",
   "1\n",
   "68817500\n",
   "0\n",
   "774857564\n",
   "738177230\n",
   "374541417\n",
   "629793317\n",
   "276731670\n",
   "526794740\n",
   "67141264\n",
   "80896\n",
   "448062885\n",
   "532893377\n",
   "416862683\n",
   "777947548\n",
   "759144998\n",
   "383088952\n",
   "928069440\n",
   "4\n",
   "2\n",
   "0\n",
   "6\n",
   "0\n"
  ]
 },
 {
  "id": "APPS-3885",
  "question": "A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.\n\nThere are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j costs $(i + j) \\operatorname{mod}(n + 1)$ and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.\n\n\n-----Input-----\n\nThe first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of schools.\n\n\n-----Output-----\n\nPrint single integer: the minimum cost of tickets needed to visit all schools.\n\n\n-----Examples-----\nInput\n2\n\nOutput\n0\n\nInput\n10\n\nOutput\n4\n\n\n\n-----Note-----\n\nIn the first example we can buy a ticket between the schools that costs $(1 + 2) \\operatorname{mod}(2 + 1) = 0$.",
  "inputs": [
   "2\n",
   "10\n",
   "43670\n",
   "4217\n",
   "17879\n",
   "31809\n",
   "40873\n",
   "77859\n",
   "53022\n",
   "79227\n",
   "100000\n",
   "82801\n",
   "5188\n",
   "86539\n",
   "12802\n",
   "20289\n",
   "32866\n",
   "33377\n",
   "31775\n",
   "60397\n",
   "100000\n",
   "99999\n",
   "99998\n",
   "99997\n",
   "99996\n"
  ],
  "outputs": [
   "0\n",
   "4\n",
   "21834\n",
   "2108\n",
   "8939\n",
   "15904\n",
   "20436\n",
   "38929\n",
   "26510\n",
   "39613\n",
   "49999\n",
   "41400\n",
   "2593\n",
   "43269\n",
   "6400\n",
   "10144\n",
   "16432\n",
   "16688\n",
   "15887\n",
   "30198\n",
   "49999\n",
   "49999\n",
   "49998\n",
   "49998\n",
   "49997\n"
  ]
 },
 {
  "id": "APPS-3972",
  "question": "How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions?\n - The n-th and subsequent elements are all equal. That is, if n \\leq i,j, a_i = a_j.\n - For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\\leq i+a_i, a_j = a_k.\nFind the count modulo 10^9+7.\n\n-----Constraints-----\n - 1 \\leq n \\leq 10^6\n\n-----Input-----\nInput is given from Standard Input in the following format:\nn\n\n-----Output-----\nPrint how many sequences satisfy the conditions, modulo 10^9+7.\n\n-----Sample Input-----\n2\n\n-----Sample Output-----\n4\n\nThe four sequences that satisfy the conditions are:\n - 1, 1, 1, ...\n - 1, 2, 2, ...\n - 2, 1, 1, ...\n - 2, 2, 2, ...",
  "inputs": [
   "2\n",
   "654321\n",
   "1000000\n",
   "999745\n",
   "999880\n",
   "999999\n",
   "1\n",
   "14\n",
   "22\n",
   "25002\n",
   "2956\n",
   "3\n",
   "380467\n",
   "407774\n",
   "52228\n",
   "68\n",
   "804783\n",
   "85984\n",
   "894324\n",
   "93\n",
   "963981\n",
   "968416\n"
  ],
  "outputs": [
   "4\n",
   "968545283\n",
   "267909856\n",
   "371558098\n",
   "488039603\n",
   "373070711\n",
   "1\n",
   "156521\n",
   "35072458\n",
   "261919868\n",
   "531167668\n",
   "15\n",
   "858853071\n",
   "308265835\n",
   "418193562\n",
   "594239438\n",
   "464390031\n",
   "375905327\n",
   "774623738\n",
   "182981174\n",
   "52682151\n",
   "20240856\n"
  ]
 },
 {
  "id": "APPS-3910",
  "question": "Note that girls in Arpa’s land are really attractive.\n\nArpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the a_{i}-th chair, and his girlfriend, sitting on the b_{i}-th chair. The chairs were numbered 1 through 2n in clockwise direction. There was exactly one person sitting on each chair.\n\n [Image] \n\nThere were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that:   Each person had exactly one type of food,  No boy had the same type of food as his girlfriend,  Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2n and 1 are considered consecutive. \n\nFind the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions.\n\n\n-----Input-----\n\nThe first line contains an integer n (1  ≤  n  ≤  10^5) — the number of pairs of guests.\n\nThe i-th of the next n lines contains a pair of integers a_{i} and b_{i} (1  ≤ a_{i}, b_{i} ≤  2n) — the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair. \n\n\n-----Output-----\n\nIf there is no solution, print -1.\n\nOtherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2.\n\nIf there are multiple solutions, print any of them.\n\n\n-----Example-----\nInput\n3\n1 4\n2 5\n3 6\n\nOutput\n1 2\n2 1\n1 2",
  "inputs": [
   "3\n1 4\n2 5\n3 6\n",
   "6\n3 2\n5 11\n7 12\n6 9\n8 4\n1 10\n",
   "19\n30 27\n6 38\n10 28\n20 5\n14 18\n32 2\n36 29\n12 1\n31 24\n15 4\n35 11\n3 7\n21 17\n25 19\n16 8\n23 22\n37 33\n13 9\n34 26\n",
   "4\n4 2\n6 8\n5 1\n3 7\n",
   "17\n11 12\n17 22\n34 7\n3 1\n5 24\n18 20\n27 30\n16 33\n23 21\n19 4\n2 15\n29 28\n9 8\n13 25\n6 10\n32 26\n31 14\n",
   "19\n10 7\n9 17\n21 30\n36 8\n14 11\n25 24\n1 23\n38 33\n4 20\n3 37\n27 5\n28 19\n22 2\n6 34\n12 15\n31 32\n35 13\n16 29\n18 26\n",
   "17\n17 31\n11 23\n34 22\n24 8\n4 1\n7 14\n20 27\n3 19\n12 26\n32 25\n28 18\n16 29\n21 9\n6 2\n33 30\n5 13\n10 15\n",
   "6\n2 7\n5 9\n12 8\n1 4\n3 6\n10 11\n",
   "8\n10 3\n2 16\n14 13\n5 15\n1 7\n11 8\n6 4\n12 9\n",
   "4\n2 8\n3 5\n4 7\n1 6\n",
   "2\n2 3\n1 4\n",
   "15\n16 22\n4 17\n27 3\n23 24\n18 20\n15 21\n9 7\n2 28\n29 19\n8 30\n14 10\n6 26\n25 11\n12 1\n13 5\n",
   "10\n19 6\n8 2\n15 18\n17 14\n16 7\n20 10\n5 1\n13 3\n9 12\n11 4\n",
   "9\n12 7\n10 15\n16 14\n2 4\n1 17\n6 9\n8 3\n13 5\n11 18\n",
   "7\n3 14\n7 4\n13 10\n11 8\n6 1\n5 9\n2 12\n",
   "6\n2 11\n7 1\n12 8\n4 10\n3 9\n5 6\n",
   "8\n13 6\n10 5\n1 12\n11 15\n7 16\n4 14\n9 2\n8 3\n",
   "8\n16 5\n10 15\n8 11\n2 14\n6 4\n7 3\n1 13\n9 12\n",
   "7\n10 14\n4 6\n1 11\n7 2\n9 8\n5 13\n3 12\n",
   "5\n2 5\n10 9\n1 6\n3 8\n4 7\n",
   "8\n14 2\n7 9\n15 6\n13 11\n12 16\n10 5\n8 1\n3 4\n",
   "5\n4 6\n5 1\n2 3\n7 8\n9 10\n",
   "23\n46 21\n17 3\n27 38\n34 43\n7 6\n8 37\n22 4\n16 42\n36 32\n12 9\n10 45\n26 2\n13 24\n23 29\n18 15\n33 30\n31 5\n11 25\n1 14\n44 39\n19 20\n35 28\n41 40\n",
   "26\n8 10\n52 21\n2 33\n18 34\n30 51\n5 19\n22 32\n36 28\n42 16\n13 49\n11 17\n31 39\n43 37\n50 15\n29 20\n35 46\n47 23\n3 1\n44 7\n9 27\n6 48\n40 24\n26 14\n45 4\n12 25\n41 38\n",
   "20\n34 12\n9 6\n5 3\n13 26\n18 15\n16 22\n7 14\n17 37\n38 40\n4 2\n11 23\n21 8\n10 36\n30 33\n28 19\n29 31\n39 20\n35 24\n25 32\n1 27\n"
  ],
  "outputs": [
   "1 2\n2 1\n1 2\n",
   "1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n",
   "1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n",
   "1 2\n1 2\n2 1\n2 1\n",
   "1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n",
   "1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n",
   "1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n",
   "2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n",
   "1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n",
   "2 1\n2 1\n1 2\n1 2\n",
   "2 1\n1 2\n",
   "2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n",
   "2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n",
   "1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n",
   "2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n",
   "2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n",
   "1 2\n2 1\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n",
   "1 2\n1 2\n1 2\n2 1\n1 2\n2 1\n1 2\n2 1\n",
   "2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n",
   "2 1\n2 1\n1 2\n1 2\n2 1\n",
   "1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n",
   "2 1\n2 1\n2 1\n1 2\n1 2\n",
   "2 1\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n",
   "2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n",
   "1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n"
  ]
 },
 {
  "id": "APPS-3917",
  "question": "Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be the one qualified, he tells Iahub the following task.\n\nYou're given an (1-based) array a with n elements. Let's define function f(i, j) (1 ≤ i, j ≤ n) as (i - j)^2 + g(i, j)^2. Function g is calculated by the following pseudo-code:\n\n\n\nint g(int i, int j) {\n\n    int sum = 0;\n\n    for (int k = min(i, j) + 1; k <= max(i, j); k = k + 1)\n\n        sum = sum + a[k];\n\n    return sum;\n\n}\n\n\n\nFind a value min_{i} ≠ j  f(i, j).\n\nProbably by now Iahub already figured out the solution to this problem. Can you?\n\n\n-----Input-----\n\nThe first line of input contains a single integer n (2 ≤ n ≤ 100000). Next line contains n integers a[1], a[2], ..., a[n] ( - 10^4 ≤ a[i] ≤ 10^4). \n\n\n-----Output-----\n\nOutput a single integer — the value of min_{i} ≠ j  f(i, j).\n\n\n-----Examples-----\nInput\n4\n1 0 0 -1\n\nOutput\n1\n\nInput\n2\n1 -1\n\nOutput\n2",
  "inputs": [
   "4\n1 0 0 -1\n",
   "2\n1 -1\n",
   "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -74 -36 4 -75 -55 92 3 -22 43 -30 48 -27 88 -58 41 36 8 -40 -30 -18 16 22 -66 -91 -46 48 -60 -45 -89 37 -76 52 81 81 15 1 -43 -45 -19 9 -75 -75 -63 41 29\n",
   "100\n-1 -3 -3 0 -1 -1 -1 1 2 1 0 -1 -2 0 -2 -2 3 -2 -1 -2 2 -2 -2 3 0 2 3 -1 2 -1 -2 2 -3 2 1 0 -1 1 3 -1 0 2 -3 -2 2 2 3 -2 2 3 0 -3 -2 1 -1 0 3 0 2 0 1 1 0 -3 1 -3 3 0 -1 -3 3 3 1 -2 2 -2 -3 -1 -2 2 -1 0 2 1 2 -1 2 3 -2 -1 0 -3 0 -1 3 2 -2 2 3 0\n",
   "4\n200 100 -200 100\n",
   "2\n3 -9\n",
   "3\n0 -10 10\n",
   "2\n10000 10000\n",
   "2\n5 5\n",
   "3\n10 10 -10\n",
   "6\n10000 10000 10000 10000 10000 6904\n",
   "3\n0 10000 -10000\n",
   "3\n0 2 3\n",
   "2\n0 1\n",
   "5\n5865 6072 -4563 5913 -7926\n",
   "2\n1 10000\n",
   "5\n10 11 12 13 -40\n",
   "21\n10 10 10 10 10 10 10 10 10 10 -95 10 10 10 10 10 10 10 10 10 10\n",
   "5\n0 4 10 -5 -5\n",
   "2\n0 10000\n",
   "4\n0 100 100 -200\n",
   "4\n0 10 -5 -5\n",
   "4\n10 10 -10 -10\n",
   "3\n1 10 10\n",
   "3\n1000 1000 -800\n"
  ],
  "outputs": [
   "1\n",
   "2\n",
   "2\n",
   "1\n",
   "9\n",
   "82\n",
   "4\n",
   "100000001\n",
   "26\n",
   "4\n",
   "47665217\n",
   "4\n",
   "5\n",
   "2\n",
   "254032\n",
   "100000001\n",
   "32\n",
   "101\n",
   "9\n",
   "100000001\n",
   "9\n",
   "9\n",
   "4\n",
   "101\n",
   "40004\n"
  ]
 },
 {
  "id": "APPS-3726",
  "question": "There are infinitely many cards, numbered 1, 2, 3, ...\nInitially, Cards x_1, x_2, ..., x_N are face up, and the others are face down.\nSnuke can perform the following operation repeatedly:\n - Select a prime p greater than or equal to 3. Then, select p consecutive cards and flip all of them.\nSnuke's objective is to have all the cards face down.\nFind the minimum number of operations required to achieve the objective.\n\n-----Constraints-----\n - 1 ≤ N ≤ 100\n - 1 ≤ x_1 < x_2 < ... < x_N ≤ 10^7\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN\nx_1 x_2 ... x_N\n\n-----Output-----\nPrint the minimum number of operations required to achieve the objective.\n\n-----Sample Input-----\n2\n4 5\n\n-----Sample Output-----\n2\n\nBelow is one way to achieve the objective in two operations:\n - Select p = 5 and flip Cards 1, 2, 3, 4 and 5.\n - Select p = 3 and flip Cards 1, 2 and 3.",
  "inputs": [
   "2\n4 5\n",
   "9\n1 2 3 4 5 6 7 8 9\n",
   "2\n1 10000000\n",
   "1\n1\n",
   "2\n1 2\n",
   "2\n2 3\n",
   "100\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199\n",
   "100\n1 2 5 6 9 10 13 14 17 18 21 22 25 26 29 30 33 34 37 38 41 42 45 46 49 50 53 54 57 58 61 62 65 66 69 70 73 74 77 78 81 82 85 86 89 90 93 94 97 98 101 102 105 106 109 110 113 114 117 118 121 122 125 126 129 130 133 134 137 138 141 142 145 146 149 150 153 154 157 158 161 162 165 166 169 170 173 174 177 178 181 182 185 186 189 190 193 194 197 198\n",
   "100\n2 3 6 7 10 11 14 15 18 19 22 23 26 27 30 31 34 35 38 39 42 43 46 47 50 51 54 55 58 59 62 63 66 67 70 71 74 75 78 79 82 83 86 87 90 91 94 95 98 99 102 103 106 107 110 111 114 115 118 119 122 123 126 127 130 131 134 135 138 139 142 143 146 147 150 151 154 155 158 159 162 163 166 167 170 171 174 175 178 179 182 183 186 187 190 191 194 195 198 199\n",
   "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
   "100\n1 100001 200001 300001 400001 500001 600001 700001 800001 900001 1000001 1100001 1200001 1300001 1400001 1500001 1600001 1700001 1800001 1900001 2000001 2100001 2200001 2300001 2400001 2500001 2600001 2700001 2800001 2900001 3000001 3100001 3200001 3300001 3400001 3500001 3600001 3700001 3800001 3900001 4000001 4100001 4200001 4300001 4400001 4500001 4600001 4700001 4800001 4900001 5000001 5100001 5200001 5300001 5400001 5500001 5600001 5700001 5800001 5900001 6000001 6100001 6200001 6300001 6400001 6500001 6600001 6700001 6800001 6900001 7000001 7100001 7200001 7300001 7400001 7500001 7600001 7700001 7800001 7900001 8000001 8100001 8200001 8300001 8400001 8500001 8600001 8700001 8800001 8900001 9000001 9100001 9200001 9300001 9400001 9500001 9600001 9700001 9800001 9900001\n",
   "99\n84857 128630 178392 196188 248799 265823 308749 343912 467570 735401 931886 996228 1075678 1080045 1148539 1626815 1657658 1679491 1712891 1853509 1927737 1950898 2183640 2452596 2533482 2582826 2664949 2687670 2706444 2773668 2800406 2860522 2945465 2964235 2967617 3191866 3230127 3332766 3526988 3529499 3583899 3647868 3922022 4026391 4688668 4850943 5138160 5173897 5194836 5278204 5439340 5476622 5588614 5658530 5938234 6126089 6203746 6239035 6379226 6393460 6450852 6520967 6603883 6741246 6761388 6808466 6898376 6904424 6971232 6980313 7046859 7185214 7255109 7363753 7576298 7635536 7637998 7647645 7776942 7851348 7884088 7905585 8146845 8278553 8433138 8812871 8858711 8981036 9058384 9125206 9209714 9316781 9462442 9474557 9608821 9624899 9743127 9940134 9963727\n",
   "100\n9987 16407 16408 50966 136331 136332 162843 249358 462837 645738 645739 872795 872796 1017799 1372696 1380485 1391249 1612352 1677779 1841926 1960482 2023995 2039022 2052842 2052843 2066199 2120566 2139751 2294509 2294510 2641572 2815598 2828167 2831439 2931802 3092718 3092719 3163293 3481265 3489462 3490290 3625357 3730488 3764799 3857446 4017643 4166652 4376649 4464711 4718896 4718897 4829428 4875888 4899456 4937632 5308228 5619931 5625760 5668126 5701586 5772800 6064143 6069708 6216447 6510656 6650634 6667048 6907438 6992845 6996996 7056967 7081046 7081047 7089312 7233611 7233612 7560518 7885312 7885313 7906992 8053937 8085723 8089899 8408982 8529821 8620702 8960552 9012115 9204893 9206918 9206919 9323923 9323924 9606900 9630227 9695605 9781657 9826604 9839270 9931918\n",
   "99\n293881 545149 781661 789654 869529 986060 1004897 1520459 1654321 1799996 1799997 1968728 1968729 2106521 2236889 2236890 2404823 2404824 2404825 2404826 2404827 2404828 2464391 2529689 2585704 2666147 3022287 3247538 3484581 3515340 3554345 3580475 3693245 3767800 3767801 3769482 3788671 3788672 4497806 4588135 4588136 4657311 4675819 4684142 4979142 5077619 5116787 5667182 5667183 5701042 5827164 5937344 5951937 5958389 5987731 6144043 6225267 6285434 6311608 6311609 6339434 6485656 6565265 6605479 6713663 6944931 6996340 7010287 7212406 7212407 7328470 7560411 8151848 8187931 8291935 8408125 8409858 8821644 8835095 8858311 8986382 8986383 9100089 9212537 9212538 9212539 9212540 9349141 9447445 9447446 9584877 9601607 9643061 9643062 9793638 9808093 9848097 9883576 9883577\n",
   "99\n76370 575676 946909 946910 946911 1025036 1025358 1089741 1172618 1183311 1204317 1204318 1309065 1979020 1979021 2480907 2487305 2520728 2793653 2922261 2922262 2922263 3367988 3367989 3367990 3750411 3764041 3773665 3869930 3985987 4001398 4088237 4098857 4098858 4106274 4240085 4278189 4278190 4351184 4351185 4620597 4904340 4927038 4990871 5096415 5098830 5111299 5111300 5186774 5186775 5186776 5186777 5186778 5186779 5186780 5186781 5556601 5556602 5690190 5734263 5767666 5767667 6006487 6651776 6651777 6726505 6726506 6856929 6862499 6862500 6875452 6924647 6924648 7127645 7127646 7145172 7714074 7741404 7741405 7741406 7741407 8520521 8556928 8556929 8868092 8876047 8876048 8876049 8876050 9157033 9157034 9409798 9574798 9574799 9574800 9793568 9813154 9813155 9813156\n",
   "97\n118610 118611 155844 282651 336278 372467 527008 527009 697662 923708 923709 1037824 1051891 1218531 1261836 1512689 1573635 1573636 1573637 1922643 2845385 2845386 2910939 2910940 3209870 3209871 3472528 3472529 3759344 3937542 4023843 4087599 4173304 4196596 4196597 4310352 4310353 4649702 4649703 5192968 5521515 5521516 5521517 5597193 5597194 5707726 5707727 5707728 5707729 5719570 5776712 5856476 6047192 6047193 6156339 6156340 6156341 6156342 6156343 6156344 6373115 6373116 6458941 6458942 6458943 6518470 6518471 6518472 6519393 7052460 7096109 7096110 7424647 7424648 7951364 7951365 8116338 8116339 8116340 8188887 8307826 8524783 8524784 8681771 8718619 8755619 8755620 8760181 8760182 8760183 8760184 8760185 8810990 9216675 9216676 9470393 9495525\n",
   "100\n170430 639435 639436 639437 1173857 1190655 1190656 1190851 1225523 1225524 1245679 1700369 1700370 1728171 1956926 1956927 1956928 1956929 1956930 1998791 1998792 1998793 2047259 2047260 2048720 2048721 2048722 2449330 2449331 2449332 2449333 2449334 2645893 2645894 2754931 2754932 2810315 3332407 3529697 3639739 3639740 3812028 3861158 3861159 3861160 3861161 3861162 3861163 3959766 4227625 4227626 4227627 4227628 4247609 4247610 4378794 4452012 4452013 4726181 4726182 4726183 4899124 5023785 5157952 5157953 5157954 5157955 5157956 5529081 5725149 5754754 5784898 5882841 5882842 5912993 5912994 5912995 6061123 6061124 6061125 6061126 6153093 6223461 6416951 6416952 6416953 6461404 6461405 6461406 6534279 7982805 8315437 8516484 8737127 8861703 9248607 9461556 9556717 9556718 9556719\n",
   "99\n71101 71102 71103 71617 71618 71619 83214 397309 397310 397311 600242 600243 600244 744221 975919 975920 995981 995982 995983 1026400 1176230 1176231 1914652 1914653 3024649 3024650 3024651 3024652 3024653 3024654 3226788 3372563 3372564 3372565 3463639 3463640 3472595 3736826 3778396 3822749 4107941 4531469 4531470 4597225 4597226 4597227 4597228 4597229 4597230 5274349 5274350 5398591 5398592 5398593 5398594 5398595 5858270 5858271 5858272 5858273 5858274 5858275 6599363 6892479 7072013 7072014 8014418 8225266 8225267 8451635 8451636 8451637 8607490 8607491 8607492 8607493 8607494 8607495 8607496 8607497 8607498 8607499 8607500 8607501 8607502 8607503 8607504 8607505 8607506 8607507 8607508 8607509 9222151 9222152 9519126 9519127 9660807 9956884 9956885\n",
   "100\n1193226 1193227 1193228 1321766 2059359 2059360 2059361 2059362 3026992 3026993 3251387 3464481 3464482 3464483 3464484 3464485 3464486 3464487 3464488 3464489 3464490 3846512 3846513 3849100 3849101 3849102 3911410 3911411 3911412 4750647 5162888 5162889 5162890 5162891 5162892 5162893 5162894 5162895 5162896 5162897 5212761 5212762 5262065 5262066 5262067 5262068 5262069 5262070 5262071 5331878 5331879 5331880 5331881 5331882 5331883 5331884 5331885 5405567 5574023 5706087 5706088 5706089 5706090 5706091 5768951 5775420 6679650 6680043 6680044 6680045 6680046 6680047 6680048 6680049 6680050 6680051 6789381 7591872 7778194 8541480 8541481 8541482 8541483 8956466 8956467 9088992 9088993 9119781 9119782 9119783 9119784 9119785 9119786 9119787 9119788 9518325 9518326 9518327 9865200 9865201\n",
   "100\n31607 662038 728274 778822 778823 778824 778825 778826 1045851 1045852 1697322 1697323 1697324 1697325 1697326 1697327 1828794 1828795 1931101 1990458 1990459 1990460 1990461 1990462 2540202 2540203 2540204 2540205 2594729 2594730 2630828 2970405 2970406 3005629 3005630 3005631 3005632 3005633 3005634 3005635 3148889 3148890 3181008 3515432 3515433 3752458 3752459 3752460 3752461 3992559 3992560 3992561 3992562 3992563 3992564 3992565 4044409 4044410 4044411 4749877 5062527 5212411 5425221 6047775 6047776 6173366 6173367 6173368 6173369 6866253 6866254 6866255 6866256 6866257 6866258 7141092 7230680 7230681 7230682 7508624 7508625 7508626 7508627 7849903 7941604 7990939 8134200 8250943 8976017 8976674 8993155 8993156 8993157 8993158 9225910 9225911 9627143 9627144 9770615 9770616\n",
   "100\n141819 141820 141821 141822 141823 141824 141825 141826 141827 148176 656244 656245 656246 656247 656248 845475 1252360 1252361 1252362 1252363 1252364 1423091 1423092 2477571 2477572 2477573 2745562 2745563 2745564 2745565 2745566 2745567 3060531 3060532 3060533 3253574 3905522 4164975 4164976 4667429 4909240 5701504 5809150 5809151 5809152 5809153 5809154 5809155 5851676 5851677 5851678 5851679 5851680 5851681 5851682 5851683 5851684 5851685 6097923 6097924 6097925 6267186 6267187 6267188 6267189 6267190 6267191 6267192 6267193 6502967 6502968 6502969 6843203 6851106 6851107 6851108 6851109 7032992 7032993 7032994 7032995 7435714 7435715 7518771 7815820 7815821 7815822 7932407 8832777 8832778 8832779 8832780 8832781 8832782 8832783 8832784 8832785 8832786 8832787 8855144\n",
   "99\n416987 416988 1061068 1061069 1061070 1061071 1061072 1061073 1061074 1061075 1061076 1061077 1107974 1107975 1107976 1107977 2299308 2299309 2299310 2299311 2299312 2299313 2449773 2449774 2449775 2449776 2793965 2793966 2793967 2793968 2793969 2793970 2793971 2793972 2793973 2793974 2793975 2793976 4245404 4245405 4548899 4548900 4565981 4565982 4565983 4565984 4565985 4565986 4565987 4613398 4613399 4642080 4642081 4642082 4792281 4792282 4792283 4792284 4792285 4792286 5785238 5986482 5986483 5986484 5986485 5986486 5986487 6978811 6978812 6980512 7889540 7889541 7889542 7889543 7889544 7889545 7889546 7889547 9074398 9074399 9074400 9074401 9074402 9074403 9074404 9074405 9074406 9074407 9144549 9261848 9622835 9622836 9622837 9622838 9622839 9622840 9907535 9907536 9907537\n",
   "99\n237698 237699 237700 237701 593700 593701 593702 1041103 1041104 1041105 1041106 1041107 1581017 1581018 1581019 1581020 1581021 1581022 1581023 1581024 1581025 1581026 1987312 1987313 1987314 1987315 1987316 1987317 1987318 2839548 2839549 2839550 2839551 2839552 2839553 2839554 2839555 2839556 3386893 3386894 3386895 3386896 5143396 5863750 5863751 5863752 5863753 5863754 5863755 5863756 5863757 5863758 5863759 5863760 6119956 6119957 6119958 6119959 6119960 6586201 6818419 6818420 7004928 7004929 7004930 7004931 7004932 7686034 7686035 8290975 8290976 8290977 8290978 8587147 8587148 8587149 8587150 8587151 8587152 8587153 8587154 8587155 8609377 8609378 8609379 8609380 8609381 8609382 8609383 8609384 8609385 8805066 8805067 8805068 8805069 9273322 9273323 9613278 9613279\n",
   "99\n416582 735546 1421964 1421965 1421966 1421967 1421968 1421969 1421970 1421971 1421972 1421973 1421974 1440462 1440463 1954196 1954197 1954198 1954199 1954200 1954201 4636943 4636944 4636945 4636946 4636947 4636948 4636949 4636950 4636951 4636952 4636953 4636954 4636955 4636956 4636957 4636958 4636959 4636960 4636961 4636962 4636963 4636964 4636965 4636966 4636967 4885443 4885444 5081117 5081118 5837706 5837707 5837708 5837709 5837710 5837711 5837712 5837713 5837714 5890287 5890288 6043638 6043639 6535118 6535119 6609092 6829676 6829677 6954726 6954727 6954728 6954729 6954730 6960796 8524922 8524923 8747707 8747708 8747709 8946488 9234494 9234495 9234496 9234497 9234498 9234499 9234500 9234501 9234502 9234503 9234504 9234505 9514613 9514614 9574510 9574511 9574512 9574513 9574514\n",
   "100\n272906 272907 272908 272909 272910 272911 272912 522828 522829 629837 630182 630183 630184 630185 630186 630187 630188 630189 2581061 2581062 2581063 2581064 2581065 2581066 2581067 2581068 2581069 2581070 2581071 3314603 3314604 3314605 3314606 3314607 3314608 3314609 3314610 3507609 3507610 3507611 3507612 3507613 3507614 4238339 4262473 4262474 4262475 4262476 4262477 4262478 4262479 4262480 4262481 4262482 4262483 4262484 4262485 4262486 4262487 4262488 5296494 5296495 5583605 5583606 5583607 7638201 7638202 7638203 7638204 7638205 7638206 7697509 7697510 7697511 7697512 7697513 7697514 7697515 7697516 7697517 7697518 7697519 7697520 7697521 7697522 9301906 9301907 9868615 9868616 9868617 9868618 9868619 9868620 9868621 9868622 9868623 9868624 9868625 9868626 9868627\n"
  ],
  "outputs": [
   "2\n",
   "3\n",
   "4\n",
   "3\n",
   "2\n",
   "2\n",
   "100\n",
   "100\n",
   "100\n",
   "2\n",
   "100\n",
   "99\n",
   "88\n",
   "79\n",
   "65\n",
   "57\n",
   "60\n",
   "39\n",
   "34\n",
   "42\n",
   "34\n",
   "25\n",
   "23\n",
   "27\n",
   "18\n"
  ]
 },
 {
  "id": "APPS-3831",
  "question": "Mayor of city S just hates trees and lawns. They take so much space and there could be a road on the place they occupy!\n\nThe Mayor thinks that one of the main city streets could be considerably widened on account of lawn nobody needs anyway. Moreover, that might help reduce the car jams which happen from time to time on the street.\n\nThe street is split into n equal length parts from left to right, the i-th part is characterized by two integers: width of road s_{i} and width of lawn g_{i}. [Image] \n\nFor each of n parts the Mayor should decide the size of lawn to demolish. For the i-th part he can reduce lawn width by integer x_{i} (0 ≤ x_{i} ≤ g_{i}). After it new road width of the i-th part will be equal to s'_{i} = s_{i} + x_{i} and new lawn width will be equal to g'_{i} = g_{i} - x_{i}.\n\nOn the one hand, the Mayor wants to demolish as much lawn as possible (and replace it with road). On the other hand, he does not want to create a rapid widening or narrowing of the road, which would lead to car accidents. To avoid that, the Mayor decided that width of the road for consecutive parts should differ by at most 1, i.e. for each i (1 ≤ i < n) the inequation |s'_{i} + 1 - s'_{i}| ≤ 1 should hold. Initially this condition might not be true.\n\nYou need to find the the total width of lawns the Mayor will destroy according to his plan.\n\n\n-----Input-----\n\nThe first line contains integer n (1 ≤ n ≤ 2·10^5) — number of parts of the street.\n\nEach of the following n lines contains two integers s_{i}, g_{i} (1 ≤ s_{i} ≤ 10^6, 0 ≤ g_{i} ≤ 10^6) — current width of road and width of the lawn on the i-th part of the street.\n\n\n-----Output-----\n\nIn the first line print the total width of lawns which will be removed.\n\nIn the second line print n integers s'_1, s'_2, ..., s'_{n} (s_{i} ≤ s'_{i} ≤ s_{i} + g_{i}) — new widths of the road starting from the first part and to the last.\n\nIf there is no solution, print the only integer -1 in the first line.\n\n\n-----Examples-----\nInput\n3\n4 5\n4 5\n4 10\n\nOutput\n16\n9 9 10 \n\nInput\n4\n1 100\n100 1\n1 100\n100 1\n\nOutput\n202\n101 101 101 101 \n\nInput\n3\n1 1\n100 100\n1 1\n\nOutput\n-1",
  "inputs": [
   "3\n4 5\n4 5\n4 10\n",
   "4\n1 100\n100 1\n1 100\n100 1\n",
   "3\n1 1\n100 100\n1 1\n",
   "10\n21005 10850\n27020 13372\n28183 3724\n22874 13564\n27446 11493\n22522 10012\n24819 11529\n24166 11084\n24539 9211\n24152 9235\n",
   "1\n1 0\n",
   "1\n1 1000000\n",
   "1\n1000000 1000000\n",
   "1\n1 0\n",
   "1\n1 0\n",
   "1\n1 1\n",
   "2\n2 2\n1 1\n",
   "2\n2 0\n1 0\n",
   "2\n2 1\n2 2\n",
   "3\n1 3\n2 1\n3 0\n",
   "3\n1 3\n1 3\n2 1\n",
   "3\n3 3\n2 0\n1 2\n",
   "4\n1 3\n2 3\n3 1\n1 0\n",
   "4\n1 2\n4 2\n4 2\n4 2\n",
   "4\n1 3\n1 4\n2 0\n4 1\n",
   "5\n3 5\n4 5\n1 0\n2 3\n1 1\n",
   "5\n2 0\n3 0\n3 0\n3 5\n2 4\n",
   "5\n1 0\n4 2\n1 5\n1 5\n1 4\n",
   "6\n1 1\n3 4\n3 5\n2 5\n6 3\n2 3\n",
   "6\n5 3\n4 4\n5 5\n1 2\n6 3\n6 4\n",
   "6\n1 5\n6 2\n2 1\n1 2\n3 6\n1 1\n"
  ],
  "outputs": [
   "16\n9 9 10 \n",
   "202\n101 101 101 101 \n",
   "-1\n",
   "71869\n31855 31856 31857 31858 31859 31860 31861 31862 31863 31864 \n",
   "0\n1 \n",
   "1000000\n1000001 \n",
   "1000000\n2000000 \n",
   "0\n1 \n",
   "0\n1 \n",
   "1\n2 \n",
   "2\n3 2 \n",
   "0\n2 1 \n",
   "3\n3 4 \n",
   "4\n4 3 3 \n",
   "7\n4 4 3 \n",
   "2\n3 2 3 \n",
   "-1\n",
   "5\n3 4 5 6 \n",
   "-1\n",
   "-1\n",
   "4\n2 3 3 4 5 \n",
   "-1\n",
   "8\n2 3 4 5 6 5 \n",
   "-1\n",
   "-1\n"
  ]
 },
 {
  "id": "APPS-3720",
  "question": "Vasya and Petya wrote down all integers from 1 to n to play the \"powers\" game (n can be quite large; however, Vasya and Petya are not confused by this fact).\n\nPlayers choose numbers in turn (Vasya chooses first). If some number x is chosen at the current turn, it is forbidden to choose x or all of its other positive integer powers (that is, x^2, x^3, ...) at the next turns. For instance, if the number 9 is chosen at the first turn, one cannot choose 9 or 81 later, while it is still allowed to choose 3 or 27. The one who cannot make a move loses.\n\nWho wins if both Vasya and Petya play optimally?\n\n\n-----Input-----\n\nInput contains single integer n (1 ≤ n ≤ 10^9).\n\n\n-----Output-----\n\nPrint the name of the winner — \"Vasya\" or \"Petya\" (without quotes).\n\n\n-----Examples-----\nInput\n1\n\nOutput\nVasya\n\nInput\n2\n\nOutput\nPetya\n\nInput\n8\n\nOutput\nPetya\n\n\n\n-----Note-----\n\nIn the first sample Vasya will choose 1 and win immediately.\n\nIn the second sample no matter which number Vasya chooses during his first turn, Petya can choose the remaining number and win.",
  "inputs": [
   "1\n",
   "2\n",
   "8\n",
   "52\n",
   "53\n",
   "3\n",
   "4\n",
   "5\n",
   "6\n",
   "7\n",
   "9\n",
   "10\n",
   "11\n",
   "12\n",
   "13\n",
   "14\n",
   "15\n",
   "16\n",
   "17\n",
   "18\n",
   "19\n",
   "20\n",
   "21\n",
   "22\n",
   "23\n"
  ],
  "outputs": [
   "Vasya\n",
   "Petya\n",
   "Petya\n",
   "Petya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n",
   "Vasya\n"
  ]
 },
 {
  "id": "APPS-3971",
  "question": "Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.\n\nGiven a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it a_{k}) and delete it, at that all elements equal to a_{k} + 1 and a_{k} - 1 also must be deleted from the sequence. That step brings a_{k} points to the player. \n\nAlex is a perfectionist, so he decided to get as many points as possible. Help him.\n\n\n-----Input-----\n\nThe first line contains integer n (1 ≤ n ≤ 10^5) that shows how many numbers are in Alex's sequence. \n\nThe second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5).\n\n\n-----Output-----\n\nPrint a single integer — the maximum number of points that Alex can earn.\n\n\n-----Examples-----\nInput\n2\n1 2\n\nOutput\n2\n\nInput\n3\n1 2 3\n\nOutput\n4\n\nInput\n9\n1 2 1 3 2 2 2 2 3\n\nOutput\n10\n\n\n\n-----Note-----\n\nConsider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.",
  "inputs": [
   "2\n1 2\n",
   "3\n1 2 3\n",
   "9\n1 2 1 3 2 2 2 2 3\n",
   "5\n3 3 4 5 4\n",
   "5\n5 3 5 3 4\n",
   "5\n4 2 3 2 5\n",
   "10\n10 5 8 9 5 6 8 7 2 8\n",
   "10\n1 1 1 1 1 1 2 3 4 4\n",
   "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4\n",
   "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2\n",
   "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9\n",
   "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5\n",
   "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2\n",
   "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8\n",
   "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8\n",
   "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2\n",
   "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9\n",
   "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9\n",
   "10\n7 4 5 3 9 1 10 3 4 5\n",
   "10\n8 9 6 5 6 4 10 9 1 4\n",
   "10\n1 7 1 4 9 10 8 2 9 9\n",
   "1\n100000\n"
  ],
  "outputs": [
   "2\n",
   "4\n",
   "10\n",
   "11\n",
   "16\n",
   "9\n",
   "46\n",
   "14\n",
   "296\n",
   "313\n",
   "298\n",
   "312\n",
   "287\n",
   "380\n",
   "380\n",
   "265\n",
   "328\n",
   "324\n",
   "34\n",
   "39\n",
   "40\n",
   "100000\n"
  ]
 },
 {
  "id": "APPS-3839",
  "question": "Ivan places knights on infinite chessboard. Initially there are $n$ knights. If there is free cell which is under attack of at least $4$ knights then he places new knight in this cell. Ivan repeats this until there are no such free cells. One can prove that this process is finite. One can also prove that position in the end does not depend on the order in which new knights are placed.\n\nIvan asked you to find initial placement of exactly $n$ knights such that in the end there will be at least $\\lfloor \\frac{n^{2}}{10} \\rfloor$ knights.\n\n\n-----Input-----\n\nThe only line of input contains one integer $n$ ($1 \\le n \\le 10^{3}$) — number of knights in the initial placement.\n\n\n-----Output-----\n\nPrint $n$ lines. Each line should contain $2$ numbers $x_{i}$ and $y_{i}$ ($-10^{9} \\le x_{i}, \\,\\, y_{i} \\le 10^{9}$) — coordinates of $i$-th knight. For all $i \\ne j$, $(x_{i}, \\,\\, y_{i}) \\ne (x_{j}, \\,\\, y_{j})$ should hold. In other words, all knights should be in different cells.\n\nIt is guaranteed that the solution exists.\n\n\n-----Examples-----\nInput\n4\n\nOutput\n1 1\n3 1\n1 5\n4 4\n\nInput\n7\n\nOutput\n2 1\n1 2\n4 1\n5 2\n2 6\n5 7\n6 6\n\n\n\n-----Note-----\n\nLet's look at second example:\n\n$\\left. \\begin{array}{|l|l|l|l|l|l|l|l|l|} \\hline 7 & {} & {} & {} & {} & {0} & {} & {} \\\\ \\hline 6 & {} & {0} & {} & {} & {} & {0} & {} \\\\ \\hline 5 & {} & {} & {} & {2} & {} & {} & {} \\\\ \\hline 4 & {} & {} & {} & {} & {} & {} & {} \\\\ \\hline 3 & {} & {} & {1} & {} & {} & {} & {} \\\\ \\hline 2 & {0} & {} & {} & {} & {0} & {} & {} \\\\ \\hline 1 & {} & {0} & {} & {0} & {} & {} & {} \\\\ \\hline & {1} & {2} & {3} & {4} & {5} & {6} & {7} \\\\ \\hline \\end{array} \\right.$\n\nGreen zeroes are initial knights. Cell $(3, \\,\\, 3)$ is under attack of $4$ knights in cells $(1, \\,\\, 2)$, $(2, \\,\\, 1)$, $(4, \\,\\, 1)$ and $(5, \\,\\, 2)$, therefore Ivan will place a knight in this cell. Cell $(4, \\,\\, 5)$ is initially attacked by only $3$ knights in cells $(2, \\,\\, 6)$, $(5, \\,\\, 7)$ and $(6, \\,\\, 6)$. But new knight in cell $(3, \\,\\, 3)$ also attacks cell $(4, \\,\\, 5)$, now it is attacked by $4$ knights and Ivan will place another knight in this cell. There are no more free cells which are attacked by $4$ or more knights, so the process stops. There are $9$ knights in the end, which is not less than $\\lfloor \\frac{7^{2}}{10} \\rfloor = 4$.",
  "inputs": [
   "4\n",
   "7\n",
   "11\n",
   "12\n",
   "20\n",
   "22\n",
   "25\n",
   "27\n",
   "13\n",
   "14\n",
   "15\n",
   "16\n",
   "17\n",
   "18\n",
   "19\n",
   "8\n",
   "10\n",
   "21\n",
   "1\n",
   "30\n",
   "40\n",
   "79\n",
   "66\n",
   "34\n",
   "37\n"
  ],
  "outputs": [
   "0 0\n1 0\n1 3\n2 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n17 0\n17 3\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n",
   "0 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n17 0\n17 3\n18 0\n19 0\n19 3\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n17 0\n17 3\n18 0\n19 0\n19 3\n20 0\n21 0\n21 3\n22 0\n23 0\n23 3\n24 0\n25 0\n25 3\n26 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n17 0\n17 3\n18 0\n19 0\n19 3\n20 0\n21 0\n21 3\n22 0\n23 0\n23 3\n24 0\n25 0\n25 3\n26 0\n27 0\n27 3\n28 0\n29 0\n29 3\n30 0\n31 0\n31 3\n32 0\n33 0\n33 3\n34 0\n35 0\n35 3\n36 0\n37 0\n37 3\n38 0\n39 0\n39 3\n40 0\n41 0\n41 3\n42 0\n43 0\n43 3\n44 0\n45 0\n45 3\n46 0\n47 0\n47 3\n48 0\n49 0\n49 3\n50 0\n51 0\n51 3\n52 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n17 0\n17 3\n18 0\n19 0\n19 3\n20 0\n21 0\n21 3\n22 0\n23 0\n23 3\n24 0\n25 0\n25 3\n26 0\n27 0\n27 3\n28 0\n29 0\n29 3\n30 0\n31 0\n31 3\n32 0\n33 0\n33 3\n34 0\n35 0\n35 3\n36 0\n37 0\n37 3\n38 0\n39 0\n39 3\n40 0\n41 0\n41 3\n42 0\n43 0\n43 3\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n17 0\n17 3\n18 0\n19 0\n19 3\n20 0\n21 0\n21 3\n22 0\n",
   "0 0\n1 0\n1 3\n2 0\n3 0\n3 3\n4 0\n5 0\n5 3\n6 0\n7 0\n7 3\n8 0\n9 0\n9 3\n10 0\n11 0\n11 3\n12 0\n13 0\n13 3\n14 0\n15 0\n15 3\n16 0\n17 0\n17 3\n18 0\n19 0\n19 3\n20 0\n21 0\n21 3\n22 0\n23 0\n23 3\n24 0\n"
  ]
 },
 {
  "id": "APPS-3697",
  "question": "The elections to Berland parliament are happening today. Voting is in full swing!\n\nTotally there are n candidates, they are numbered from 1 to n. Based on election results k (1 ≤ k ≤ n) top candidates will take seats in the parliament.\n\nAfter the end of the voting the number of votes for each candidate is calculated. In the resulting table the candidates are ordered by the number of votes. In case of tie (equal number of votes) they are ordered by the time of the last vote given. The candidate with ealier last vote stands higher in the resulting table.\n\nSo in the resulting table candidates are sorted by the number of votes (more votes stand for the higher place) and if two candidates have equal number of votes they are sorted by the time of last vote (earlier last vote stands for the higher place).\n\nThere is no way for a candidate with zero votes to take a seat in the parliament. So it is possible that less than k candidates will take a seat in the parliament.\n\nIn Berland there are m citizens who can vote. Each of them will vote for some candidate. Each citizen will give a vote to exactly one of n candidates. There is no option \"against everyone\" on the elections. It is not accepted to spoil bulletins or not to go to elections. So each of m citizens will vote for exactly one of n candidates.\n\nAt the moment a citizens have voted already (1 ≤ a ≤ m). This is an open election, so for each citizen it is known the candidate for which the citizen has voted. Formally, the j-th citizen voted for the candidate g_{j}. The citizens who already voted are numbered in chronological order; i.e. the (j + 1)-th citizen voted after the j-th.\n\nThe remaining m - a citizens will vote before the end of elections, each of them will vote for one of n candidates.\n\nYour task is to determine for each of n candidates one of the three possible outcomes:\n\n  a candidate will be elected to the parliament regardless of votes of the remaining m - a citizens;  a candidate has chance to be elected to the parliament after all n citizens have voted;  a candidate has no chances to be elected to the parliament regardless of votes of the remaining m - a citizens. \n\n\n-----Input-----\n\nThe first line contains four integers n, k, m and a (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100, 1 ≤ a ≤ m) — the number of candidates, the number of seats in the parliament, the number of Berland citizens and the number of citizens who already have voted.\n\nThe second line contains a sequence of a integers g_1, g_2, ..., g_{a} (1 ≤ g_{j} ≤ n), where g_{j} is the candidate for which the j-th citizen has voted. Citizens who already voted are numbered in increasing order of voting times.\n\n\n-----Output-----\n\nPrint the sequence consisting of n integers r_1, r_2, ..., r_{n} where:\n\n  r_{i} = 1 means that the i-th candidate is guaranteed to take seat in the parliament regardless of votes of the remaining m - a citizens;  r_{i} = 2 means that the i-th candidate has a chance to take a seat in the parliament, i.e. the remaining m - a citizens can vote in such a way that the candidate will take a seat in the parliament;  r_{i} = 3 means that the i-th candidate will not take a seat in the parliament regardless of votes of the remaining m - a citizens. \n\n\n-----Examples-----\nInput\n3 1 5 4\n1 2 1 3\n\nOutput\n1 3 3 \nInput\n3 1 5 3\n1 3 1\n\nOutput\n2 3 2 \nInput\n3 2 5 3\n1 3 1\n\nOutput\n1 2 2",
  "inputs": [
   "3 1 5 4\n1 2 1 3\n",
   "3 1 5 3\n1 3 1\n",
   "3 2 5 3\n1 3 1\n",
   "1 1 1 1\n1\n",
   "1 1 1 1\n1\n",
   "1 1 2 2\n1 1\n",
   "1 1 2 1\n1\n",
   "1 1 1 1\n1\n",
   "1 1 3 3\n1 1 1\n",
   "1 1 1 1\n1\n",
   "1 1 3 3\n1 1 1\n",
   "1 1 5 4\n1 1 1 1\n",
   "1 1 4 2\n1 1\n",
   "1 1 1 1\n1\n",
   "1 1 3 3\n1 1 1\n",
   "2 1 1 1\n2\n",
   "2 2 1 1\n1\n",
   "1 1 2 1\n1\n",
   "1 1 2 1\n1\n",
   "2 1 1 1\n1\n",
   "2 1 1 1\n1\n",
   "1 1 3 1\n1\n",
   "1 1 4 4\n1 1 1 1\n",
   "2 2 3 1\n1\n",
   "2 1 1 1\n1\n"
  ],
  "outputs": [
   "1 3 3 ",
   "2 3 2 ",
   "1 2 2 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "1 ",
   "3 1 ",
   "1 3 ",
   "1 ",
   "1 ",
   "1 3 ",
   "1 3 ",
   "1 ",
   "1 ",
   "1 2 ",
   "1 3 "
  ]
 },
 {
  "id": "APPS-3789",
  "question": "We have N gemstones labeled 1 through N.\nYou can perform the following operation any number of times (possibly zero).\n - Select a positive integer x, and smash all the gems labeled with multiples of x.\nThen, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan).\nHowever, a_i may be negative, in which case you will be charged money.\nBy optimally performing the operation, how much yen can you earn?\n\n-----Constraints-----\n - All input values are integers.\n - 1 \\leq N \\leq 100\n - |a_i| \\leq 10^9\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN\na_1 a_2 ... a_N\n\n-----Output-----\nPrint the maximum amount of money that can be earned.\n\n-----Sample Input-----\n6\n1 2 -6 4 5 3\n\n-----Sample Output-----\n12\n\nIt is optimal to smash Gem 3 and 6.",
  "inputs": [
   "6\n1 2 -6 4 5 3\n",
   "6\n100 -100 -100 -100 100 -100\n",
   "5\n-1 -2 -3 -4 -5\n",
   "2\n-1000 100000\n",
   "98\n-732082503 484310639 410514008 709792355 513377678 -643565830 -558057755 673249507 -879378244 595054694 886176495 197608768 127996665 169589649 -210521660 98709367 -47020110 536605652 -136787827 -182892932 -888829303 -901014895 677846910 -190813377 -671953311 731321705 -974264455 -866044167 396491508 539073495 -754869657 575975333 453688989 681855145 -399761109 -386950225 -816040302 -202359086 915081824 241112350 983080677 19109453 124297220 792149360 -675138311 369322621 -741920995 -730315755 -61806783 -929304962 -11041147 -306944960 -831325318 577854177 -166790083 -612869698 -912842168 -77723620 -154118760 171010456 81157346 -944847943 221125914 -93996263 733731784 -3770343 -717580505 -160645288 -897600312 -815089273 106416539 265982095 321873832 333934673 438264906 -770570932 560539451 682769573 -910555069 -300928360 623197765 597899472 -716112873 -189037966 41058203 -730570899 852023432 668889800 -240064056 308504995 -856589035 -958731159 -683108502 254779243 311356691 206150940 -121876641 209576340\n",
   "59\n160830807 -416156479 199560179 -853012066 710795756 59706390 -126534735 -533380565 -436461607 -606769791 964941203 973944412 209040160 -440141890 272284977 -24455080 541065674 -608858491 -552221031 -325674848 -869049719 112273618 -44909036 709917809 -889888478 828350586 -756306236 897950232 747965143 980236164 -256537312 675719397 -316188281 81239673 984686385 706814364 436878374 501259205 996793252 753853376 -578171523 109290638 -947689607 474161031 846030019 -839480662 -747435765 920826722 620400742 445643214 240284696 -689463601 -213600174 -904115584 819049613 -525205881 657681989 663819315 629999402\n",
   "96\n-125532817 37532357 -789927612 -704294197 689073833 665051963 186409982 -102118908 461285711 -635446845 481299943 325948583 -986950485 83194911 -767331704 590762631 -109617820 267545937 -352813770 -828962357 -670002432 -496185743 519391446 171046017 -441814387 -231094607 716209134 -36839600 -543185999 -979699262 -380837479 432099171 737069321 -716778206 568696245 -58628109 -557821450 780061711 -763498678 819814668 -288794348 -110689860 -861558297 560065595 994313123 -183937522 -288316924 -942909186 -898740553 859197551 402924494 -32549764 -665747627 -153846077 336421648 925274904 805917527 970139960 -792501734 681406413 -401588536 100676385 553663720 418240936 734639473 453750827 190820351 -312555869 -813548198 -256293424 970718342 839480836 -935150371 -86116783 324764491 769835264 -959112682 180615239 -20887804 -42594936 618787192 195125831 170718143 254236202 618071475 -156358502 197646448 426430008 -6644319 470387581 402827160 -992311672 803059296 -27036132 964867342 -935387335\n",
   "50\n246805875 -890461718 666044295 -626442309 97497884 -184675091 -762138672 -321558599 -416699058 258579029 993785257 -514270374 -812670604 480060224 -120578051 -511401973 -455830277 -432567866 716410610 500422920 169329321 669262133 -16476259 -744517869 943553514 -366003077 -214874285 -589153263 -865453392 853498992 3925995 -463210266 437007593 874150636 777084847 909645665 -191720668 767437115 976555827 -264656754 -258627265 -174566812 -875127007 363522806 510578276 280369871 855704690 836408139 -205939340 -102690517\n",
   "95\n379870403 -961763837 42910244 -909222793 995367621 436418760 143131163 928259357 -516551023 338055173 18694983 -89037336 -508381437 377697496 -628121940 247187583 776580124 829270523 -521450211 -251568842 335203333 -452203116 -500576159 -850783378 617658109 -731136251 105321372 494506438 -79814582 913172054 167662120 -884079322 -119042204 584277758 -397960114 353729691 598719245 -185076926 68918562 143126602 579169992 -546941916 -441627910 -850274852 -428742924 844012003 987233526 -614902014 -72666468 729587094 -468345645 -85152489 -417330667 -134665352 34208577 -867280179 349484064 166843194 -819998290 -780904952 858428594 594072779 617645809 266543726 -819088234 -760280439 74314214 943134516 396209456 -357285086 -898239037 631493714 525234956 -122531321 -103139961 -216303704 84084762 -108176666 234462195 397627658 279697902 935544356 679667639 -563112231 714356409 673229492 -528848239 -464681496 290989491 974266738 -927741544 -250179681 471853662 483749708 -151262858\n",
   "51\n480315750 858482337 -45774653 281944274 -280152130 585669201 -738732698 -628982278 -169864664 -424218811 -849581207 -230045639 463944177 -914595406 -562533330 -564382761 972264712 928265005 710343531 -699777060 -851828755 -642490917 -550664793 824964298 -550053516 -415911087 -493702405 -795825378 -134020607 -699376318 -813724709 176664518 499291516 -840732220 -847053965 621835242 953787985 471108829 -880905678 88215262 85299776 -732996284 33758567 -786868529 -142779984 -220330641 603564484 288966874 730585874 883607376 272152033\n",
   "98\n864509457 -865667143 -886261580 -906439231 143111756 -980626347 -81738602 495262733 156079208 911382813 991721980 542411093 745404340 -664655680 231941221 -535898320 -701946950 -611619580 -909197605 322691804 442898355 -594969532 847937328 -939012937 471152061 719359747 107915672 -110277207 389557198 445191925 460291207 -323036967 188829560 -927970321 -267222513 388292640 219563260 -963082961 537875404 324224103 578442556 780434286 457811747 -953034782 -178651092 -124679751 -297000479 507110571 -757765504 645754959 96957387 -413706382 442942396 130563952 -784664626 -810041815 -801195006 771191684 804585431 -306639848 -183578191 170712754 -115480571 -76236283 396879494 -151558419 -660771977 482601947 -296095580 -132574152 -121356251 -81032394 684271014 317027007 81614768 87563162 923853985 908570672 727747112 -502559509 637622887 -244780440 -117166396 -435453385 -811705957 278947396 912911676 -661834437 -658133387 868106518 -647476607 452660654 -296808139 -117996035 724222205 153874063 -247148691 728646746\n",
   "27\n732695891 680410489 698012296 933753931 506278944 767298893 -652488891 -319537137 61539280 209341308 587606483 229720512 756910003 854459007 329423170 773026083 -544891835 342790984 490901272 -392496837 395867895 597349389 -795807628 381476384 210218680 931785597 -680297525\n",
   "97\n266955458 943345734 -368895265 -821575631 493340861 -557381300 223852518 -158715469 961913291 -26966071 708161916 -863565426 -747488907 -141220751 679205890 902087900 -11765114 -802811813 -711992611 998353560 95296747 -522435914 373377231 776340798 60625172 -62083616 -839282751 -602280926 303089612 597572349 -77235043 -330704988 -948342353 508941399 -995404544 -892882712 -538077944 659926472 -709078649 213908090 -941483600 496512788 -406664762 781269048 755295157 309036406 235118129 187927850 -959113887 -358179928 -617713509 -966993697 255507727 -321681141 -409032350 606149311 -211004080 -380492498 916795820 333506838 -781226804 -793321806 624794727 688933040 631293506 -485878318 457284766 -434715206 -12676036 719149950 311453281 -979486022 -964079468 484360290 896836168 643795678 -915360894 -18990215 -828086409 -436947094 -602060681 330664120 -405984409 -755245378 -356215565 -157911862 -36794425 -607213323 109188258 639295476 158371123 826277775 884277238 769826349 355878849 183968214 -143822300\n",
   "46\n-190457044 -386076312 867933504 11131516 816681300 135008719 426518229 -255668756 285920005 891606236 86320956 -927572449 -91481267 -118274749 -461555544 166514979 84825257 66228766 -239444966 -502824988 563288795 -22552317 -478178013 570542783 -329204 -265925299 948224776 -222560036 226559414 -56725357 -869534313 137213291 -907574962 -566846367 -299072227 -246968011 995964774 -261264584 896149746 315922116 760769464 515688497 665640044 314805338 -160330611 -624625837\n",
   "98\n314509832 -617908018 518835922 -520341982 -120849880 -259878728 720752128 -467728565 -259256252 209652650 -294022391 70379346 -723962834 688810355 -540028557 195945993 837076825 86528478 -802607782 -57437535 361796229 -816765080 -272104241 636363854 409709595 29600120 -222509941 336847911 -516635879 -904668431 215611421 -427252306 169728767 15122637 415678958 592224164 -5393790 -653502389 -595445642 748611707 -708154741 -539289114 -193320465 -475901158 -158967647 -112013766 -970489833 688374530 -718372532 646361685 -323678949 928235159 520526676 142749649 463832478 -138012514 871484950 -146850485 277472093 -541398022 -20788647 465370961 -563861849 597848135 912060991 406131724 584171422 -124460085 -485384609 -115374373 -89406174 58099841 -927845868 947646258 -359005015 -292953157 -967679666 50860410 421071629 138615473 588547875 297547628 -902978447 636804238 -771564936 436027697 -183338093 -749648274 -561756683 644354135 -753132740 150974314 -592927662 180099702 686001679 -881338966 192545352 956323425\n",
   "86\n488580610 -497425866 -192024423 284936045 -412383268 974832727 -330601927 -851553834 945353583 711274105 642731184 427360265 88501157 896554836 689880151 -393602901 -104957875 413216385 352921664 239388619 288611383 -344918331 -684332637 961891736 -143989754 -251267048 448841745 -581347834 697167422 -38073517 -394957923 81150620 584817005 521904748 771887345 48145977 440264578 -715956153 53230283 648887132 -258402118 643232439 -438786208 200475543 564903925 -569094538 205672813 357235966 -4680697 497995752 -857565002 -721617382 -908934613 -852829247 677631477 626089627 -800971196 -157755467 892809094 438618129 453983861 740294594 708180678 -971538727 -13635113 -344037022 -187874095 647862153 463378802 892856683 13726928 -788808233 -400509240 410236506 827613930 343281124 254857162 -636944818 -848565032 74832540 -244324247 507273135 50293586 -247010455 -978150445 -784624751\n",
   "99\n122741031 -204980087 525357399 -35985856 -416421742 611495756 -929791499 -703341024 312660354 -8716403 -885125673 332761853 -601694152 -453492700 658205998 -888173729 58182557 620328675 -664005151 -864927032 645923185 675352889 -954440570 -792010737 -826546996 -44381354 332330747 -64136214 -790678352 -296084579 -244480980 -772375042 -425964702 -391276054 650734738 -377554590 -587415545 269978067 -292899235 105542408 514213110 -457527895 173475988 957868052 -560581924 -765594268 225395776 -996553584 458639494 640334468 592400411 913819872 -298917769 -485204315 637563767 399937856 -575532654 907299440 602288683 737463293 -101036208 -60716929 756434898 601256927 -342869091 834072903 -758076503 759751058 395812687 -943465113 -674028993 601518484 738953364 -569932247 -306363003 -37074221 -425095741 980607802 247313935 -86656058 -375846061 -736270307 -227767888 77835169 -39882120 991458743 -776275267 -456420406 924101784 820760583 -557509270 463841633 198578913 147673940 462655750 -955146078 324821275 -760593951 -107711424\n",
   "67\n342498977 -366090854 -277280076 804780980 -224444831 607221718 -99921030 -860283192 625877891 -674276160 695529897 -682285164 -142344727 71263543 163727641 581966829 -867749381 -120898288 -816632129 -478523751 771040439 -534643322 116833879 -40878830 603539005 830905221 558365923 651269803 -468147105 -10068232 346050673 -358816512 -931285173 -387109823 -275325947 293773379 -703566929 514862278 -28167837 588061879 115830657 -732391476 173783075 985171772 -311268655 -581757322 -758271648 -93012186 5595808 -14254920 -218133808 -862837048 -927938908 -880566692 849867654 -604371527 -345548440 498179960 543874212 185639625 22570680 160105014 59778731 180612946 58114182 -955482341 994510417\n",
   "95\n71414002 -147723385 50948068 -775502757 -137568826 555431680 42570426 -945052553 -499631715 -117214185 -80847 578863316 25466340 -758835099 -928408888 -2408023 -278478316 -839716014 -689402028 770073616 -241873504 633128169 -950746719 -226411928 961008705 356819394 818343184 915205110 28328359 -471148542 605843550 -69752047 408584316 166260340 156203986 -93975437 -26822166 -360797731 27651569 -315993536 137546346 -275947646 -650246639 154807545 184311682 243444775 60489058 912929095 431016448 681033061 -297295914 937659071 547497381 590511438 795957351 982184983 693894401 -153542659 498698969 -630587927 193503539 -563175681 -26015952 -643587006 100466489 -475146275 534832090 -327768108 902729468 -480734188 503227304 607141030 743448864 159599758 -709691291 -580611767 645361290 -890941025 487193768 -273778437 929703840 -15863917 -37669984 954211907 464882182 -66088848 100261391 -787316859 114672606 -100229553 998629742 472353547 161912569 -441782994 490951729\n",
   "89\n-59446479 957713271 -995213793 116546072 875731920 -178376990 783740488 212943574 896072331 690578728 149596012 -318744368 476525701 4634463 886285477 90211618 583158725 330646781 -717606550 -779967199 405552694 -623816607 702132046 -374184914 -674270511 120192677 -932457305 -137471102 -36015306 984260773 -756942290 -250194852 -438610568 -759551508 76473981 945512434 -284762122 -721875557 -844507530 -190803213 491118173 -774911995 -742669592 -645404115 807078076 -544288854 696946845 -400136383 966778799 146693851 -372054874 347279000 -380442932 603011793 778437201 -425685605 242678782 -9475641 816735290 -607304258 -889487951 619420873 697216606 338304377 408267586 -338158725 -771484962 724119879 -602597299 503717758 778686029 797111079 -725151817 -600566818 835154910 708360416 -291846733 -68043935 280813604 524458205 -231843425 -208680981 289846757 -949237985 -459196069 540574357 793191350 707579029 -824034429\n",
   "96\n536252133 560095389 51624819 638692416 384898188 723906213 11286724 938589049 741727514 -533325694 -230954564 101287676 676839501 -116465067 70747948 163789916 -129815932 -252532751 698541747 -741227795 579294077 -824709620 414429198 984134249 629361582 17745148 -462543541 -930314545 322636347 -145626292 -21429923 269031919 -945250139 -409039822 -486472515 -746953780 844995942 423183949 -54902024 692434524 442612736 231676102 778939737 -528390730 -378658398 -705397493 225625547 -420773822 577363142 -783802841 180530008 314898111 440520844 224339077 990261065 -376925931 305116694 -253435791 8476558 310985383 -43149598 -451919515 625543863 -789553934 734175179 -568973480 -273158476 -338978917 -468357246 235567336 -486053677 -117931027 -969218546 513712843 -263321495 648700382 -146893717 -554254229 684058474 -456352294 45474064 -877949272 -42058811 377974785 937504548 -321876954 507665853 298295446 562573742 -97817208 -74208617 -13648477 804869685 -241695485 230943175 95136740\n",
   "50\n-516476141 -643850367 968065390 937396345 -761786007 -387965609 -63294517 36897326 800500310 436072643 -171177011 -782838023 566692579 945690941 -212555829 -8799649 538580080 541281969 959647002 837370408 -106641964 70462741 477099032 -256211652 -88503411 -704498174 -762923496 351832998 -576712900 356326024 -540153009 763681142 377032866 -566356926 448718879 -199618835 -98882617 926047279 60033962 70403916 -283413439 -799930664 908610895 463244748 -564113295 -619460047 394626605 -926149894 -704969227 -962657222\n",
   "97\n-866011270 -917234705 46225231 -509043433 645849764 -486233863 912206705 -798200099 -56481209 846739685 -738676628 904344898 220968101 319281878 576497705 985914210 920490132 897254367 -84796627 265627267 771417380 344709850 -81893660 -251247492 -867094276 200057674 -763845920 391841934 340028921 116971140 -239563698 -585621812 -295664368 84410676 127036329 -95255036 -264216587 -65050888 435450429 536350801 -78768936 -578908259 -767718621 -152984455 982795745 305576562 989161194 562260928 -276662582 483572077 -686776387 -271241742 -327282462 -436742223 998073577 -302723261 296724179 170705359 327889244 972172520 65533928 -733827403 -875343303 -364709609 809275054 226701025 -531609947 93576678 -700007301 298286047 -108861602 -948765169 -389273918 210462246 70607869 933350662 -668826433 -953598937 541368131 -978149857 762506644 470145083 891184811 667297181 973079049 -984421672 -432888504 -114852393 231697107 136943246 -154946596 -951595080 -617303660 -767064285 -680052597 -300422138 910500145\n",
   "47\n158097562 547471580 681607780 -327720661 -738774270 817966740 779335774 68831534 -905123318 806340490 -73947501 -14634055 712267052 306842586 -83754249 984298031 -886051694 135552236 296727010 649265885 -359773630 -973151416 507691833 -845521344 308354994 593809122 -52197128 215168449 806088124 25693960 230065116 220276992 -743023182 479686091 812631728 -745495925 801138392 546602342 -763204866 -938301859 929683736 89325865 614619840 -53392535 527532890 447471756 633444055\n",
   "99\n865119910 -324217861 -564353406 -240821790 743729091 384978515 -76078266 105515720 724933537 -394973711 -846571917 551537423 -351513921 715380710 -853026592 584788726 30389517 -591459991 -237802902 792139217 434680109 -796964420 791195253 314024121 -344535785 807595929 187653875 153735851 697991369 -813923436 643467065 -999824834 554786062 -542866446 989401862 -659389432 -895678011 231147416 -661393731 -515925525 244636714 -847767157 781478170 -770147787 30558785 532742020 921576435 -807456170 -44919908 109344550 -754924546 447817774 431370509 -755721586 -288861275 -450857919 945148758 -58705720 467065198 -94137279 120473589 470612250 -285624562 376317980 -9535739 375300940 741152946 232628527 -249584239 476090052 -861950442 561594333 -506620495 -641323423 788922818 -706966814 -24538368 -534013102 820089685 985511598 863497022 -155552867 -750526919 -333267348 -364634064 -782587001 -619632341 -731165252 801304095 -612813108 -843846426 -564355135 -186458758 -573119122 542219434 -961083745 849034211 -61075718 127616533\n"
  ],
  "outputs": [
   "12\n",
   "200\n",
   "0\n",
   "99000\n",
   "14212229586\n",
   "14454694082\n",
   "16230896865\n",
   "8155615671\n",
   "18589417528\n",
   "8073032967\n",
   "17619918807\n",
   "10498840463\n",
   "16243369628\n",
   "8798483161\n",
   "13503826973\n",
   "18989211043\n",
   "13283659437\n",
   "9543415807\n",
   "17397506017\n",
   "18175439844\n",
   "21030194446\n",
   "10470410950\n",
   "18004724438\n",
   "13409603572\n",
   "19485538294\n"
  ]
 },
 {
  "id": "APPS-3889",
  "question": "Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.\n\nThe committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.\n\nUnfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color $x$ such that there are currently at least two puppies of color $x$ and recolor all puppies of the color $x$ into some arbitrary color $y$. Luckily, this operation can be applied multiple times (including zero).\n\nFor example, if the number of puppies is $7$ and their colors are represented as the string \"abababc\", then in one operation Slava can get the results \"zbzbzbc\", \"bbbbbbc\", \"aaaaaac\", \"acacacc\" and others. However, if the current color sequence is \"abababc\", then he can't choose $x$='c' right now, because currently only one puppy has the color 'c'.\n\nHelp Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.\n\n\n-----Input-----\n\nThe first line contains a single integer $n$ ($1 \\le n \\le 10^5$) — the number of puppies.\n\nThe second line contains a string $s$ of length $n$ consisting of lowercase Latin letters, where the $i$-th symbol denotes the $i$-th puppy's color.\n\n\n-----Output-----\n\nIf it's possible to recolor all puppies into one color, print \"Yes\".\n\nOtherwise print \"No\".\n\nOutput the answer without quotation signs.\n\n\n-----Examples-----\nInput\n6\naabddc\n\nOutput\nYes\n\nInput\n3\nabc\n\nOutput\nNo\n\nInput\n3\njjj\n\nOutput\nYes\n\n\n\n-----Note-----\n\nIn the first example Slava can perform the following steps:   take all puppies of color 'a' (a total of two) and recolor them into 'b';  take all puppies of color 'd' (a total of two) and recolor them into 'c';  take all puppies of color 'b' (three puppies for now) and recolor them into 'c'. \n\nIn the second example it's impossible to recolor any of the puppies.\n\nIn the third example all the puppies' colors are the same; thus there's no need to recolor anything.",
  "inputs": [
   "6\naabddc\n",
   "3\nabc\n",
   "3\njjj\n",
   "1\nd\n",
   "26\nadtopxgnculmhfkezrwsvqbiyj\n",
   "2\naz\n",
   "5\nfnfvn\n",
   "7\nkssssss\n",
   "10\nuyouuzyyrb\n",
   "3\ngcw\n",
   "15\nnrnuugruronnsur\n",
   "27\nmnpsweykjdvaxyiqtgcuzhbfrlo\n",
   "2\naa\n",
   "2\nba\n",
   "3\naba\n",
   "2\nzz\n",
   "1\ne\n",
   "4\nabab\n",
   "4\nabcc\n",
   "6\naabcde\n",
   "3\nzza\n",
   "27\nabcdefghijklmnopqrstuvwxyza\n",
   "5\naabcd\n",
   "3\naaa\n",
   "9\nabcdefghh\n"
  ],
  "outputs": [
   "Yes\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "No\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "No\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n",
   "Yes\n"
  ]
 }
]