problem_id
stringlengths
32
32
name
stringlengths
2
54
problem
stringlengths
204
5.28k
solutions
sequencelengths
1
5.17k
test_cases
stringlengths
38
86.7k
difficulty
stringclasses
1 value
language
stringclasses
1 value
source
stringclasses
1 value
num_solutions
int64
1
5.17k
starter_code
stringclasses
1 value
19d770e2c74d695b37b93d822093c5aa
Marathon
Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0,<=0) and the length of the side equals *a* meters. The sides of the square are parallel to coordinate axes. As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each *d* meters of the path. We know that Valera starts at the point with coordinates (0,<=0) and runs counter-clockwise. That is, when Valera covers *a* meters, he reaches the point with coordinates (*a*,<=0). We also know that the length of the marathon race equals *nd*<=+<=0.5 meters. Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers *d*,<=2·*d*,<=...,<=*n*·*d* meters. The first line contains two space-separated real numbers *a* and *d* (1<=≤<=*a*,<=*d*<=≤<=105), given with precision till 4 decimal digits after the decimal point. Number *a* denotes the length of the square's side that describes the stadium. Number *d* shows that after each *d* meters Valera gets an extra drink. The second line contains integer *n* (1<=≤<=*n*<=≤<=105) showing that Valera needs an extra drink *n* times. Print *n* lines, each line should contain two real numbers *x**i* and *y**i*, separated by a space. Numbers *x**i* and *y**i* in the *i*-th line mean that Valera is at point with coordinates (*x**i*,<=*y**i*) after he covers *i*·*d* meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10<=-<=4. Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem. Sample Input 2 5 2 4.147 2.8819 6 Sample Output 1.0000000000 2.0000000000 2.0000000000 0.0000000000 2.8819000000 0.0000000000 4.1470000000 1.6168000000 3.7953000000 4.1470000000 0.9134000000 4.1470000000 0.0000000000 2.1785000000 0.7034000000 0.0000000000
[ "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\na,d = map(float, input().split())\r\nN = int(input())\r\nperi = a*4\r\n\r\npos = [(0,0),(a,0),(a,a),(0,a)]\r\ndirs = [(1,0),(0,1),(-1,0),(0,-1)]\r\nfor i in range(1,N+1):\r\n t = (d*i)%peri\r\n j = int(t//a)\r\n \r\n x,y = pos[j]\r\n x+=dirs[j][0]*(t%a)\r\n y+=dirs[j][1]*(t%a)\r\n \r\n print(x,y)\r\n", "# import sys\n# input = sys.stdin.readline\n\nimport math\n\n\ndef solve():\n a, d = list(map(float, input().split(\" \")))\n n = int(input())\n\n currentCorner = 0\n cornerDistance = 0\n corners, rem = int(d // a), d % a\n for i in range(1, n + 1):\n currentCorner += corners\n cornerDistance += rem\n excessCorner, excessRem = int(cornerDistance // a), cornerDistance % a\n currentCorner += excessCorner\n cornerDistance = excessRem\n currentCorner %= 4\n coordsAll = [\n [cornerDistance, 0],\n [a, cornerDistance],\n [a - cornerDistance, a],\n [0, a - cornerDistance],\n ]\n x, y = coordsAll[currentCorner]\n print(f\"{x:.10f} {y:.10f}\")\n\n\nt = 1\nif False:\n t = int(input())\nfor _ in range(t):\n solve()\n", "a, d = map(float, input().strip().split())\r\nn = int(input())\r\n\r\nfor i in range(n):\r\n # Calculate the remaining distance for this step\r\n remaining = d * (i + 1)\r\n\r\n # Determine which side of the square Valera is on\r\n side = int(remaining // a) % 4\r\n remainder = remaining % a\r\n\r\n # Calculate the coordinates based on the side and the remaining distance\r\n if side == 0:\r\n x, y = remainder, 0\r\n elif side == 1:\r\n x, y = a, remainder\r\n elif side == 2:\r\n x, y = a - remainder, a\r\n else: # side == 3\r\n x, y = 0, a - remainder\r\n\r\n print(\"{:.10f} {:.10f}\".format(x, y))\r\n", "a,b = [float(x) for x in input().split()]\r\nn = int(input())\r\nfor i in range(1,n+1):\r\n rem = (i*b)%(4*a)\r\n print(*[(rem,0),(a,rem-a),(3*a-rem,a),(0,4*a-rem)][int(rem//a)])", "import sys\r\ninput = sys.stdin.readline\r\n\r\na, d = list(map(float, input().split()))\r\nn = int(input())\r\nx = d%(a*4)\r\nc = 0\r\nu, v = 0, 0\r\nfor i in range(n):\r\n b = x\r\n while b:\r\n if c == 0:\r\n d = a-u\r\n if d > b:\r\n u += b\r\n b = 0\r\n else:\r\n u = a\r\n c += 1\r\n b -= d\r\n elif c == 1:\r\n d = a-v\r\n if d > b:\r\n v += b\r\n b = 0\r\n else:\r\n v = a\r\n c += 1\r\n b -= d\r\n elif c == 2:\r\n if u > b:\r\n u -= b\r\n b = 0\r\n else:\r\n b -= u\r\n u = 0\r\n c += 1\r\n else:\r\n if v > b:\r\n v -= b\r\n b = 0\r\n else:\r\n b -= v\r\n v = 0\r\n c = 0\r\n\r\n print(u, v)", "a, d = map(float, input().split())\r\nn = int(input())\r\n\r\ndef calc(l : float) :\r\n global a\r\n l %= 4 * a\r\n\r\n if l < a :\r\n return l, 0\r\n if l < 2 * a :\r\n return a, l - a\r\n if l < 3 * a :\r\n return 3 * a - l, a\r\n\r\n return 0, 4 * a - l\r\n\r\nfor i in range(n) :\r\n x, y = calc((i + 1) * d)\r\n print(x, y)\r\n\r\n\r\n" ]
{"inputs": ["2 5\n2", "4.147 2.8819\n6", "16904.8597 21646.2846\n10", "40356.3702 72886.7142\n100", "70092.4982 95833.7741\n1000", "39712.7105 19285.2846\n10000", "97591.0354 49021.4126\n100000", "1 100000\n100000", "1 1\n1", "99999.9999 99999.9998\n100000", "1.0001 9999.9999\n100000", "100000 1\n100000", "100000 100000\n100000", "100000 100000\n100000", "1.6055 15170.3125\n100000", "2.5828 24165.5413\n100000", "2.9320 33160.7701\n100000", "71601.9916 1.6928\n100000", "15145.9844 2.4240\n100000", "58689.9772 5.1934\n100000", "26244.1561 49410.8330\n100000", "26253.1158 32456.3935\n100000", "26262.0740 15501.9524\n100000", "22635.8777 74922.1758\n10", "5681.4396 74931.1355\n10", "52372.0072 97869.2372\n100", "35417.5676 97878.1954\n100", "21992.2179 21320.7493\n1000", "5037.7799 21329.7059\n1000", "79870.5443 51056.8773\n10000", "62916.1032 51065.8339\n10000", "79870.5443 51056.8773\n10000", "62916.1032 51065.8339\n10000", "3 99999.1\n100000", "3 99999.2\n100000", "3 99999.0001\n100000", "3 99999.0002\n100000", "100000 99999.0002\n100000", "99999.9998 99999.9999\n100000", "1 9999.9999\n100000", "1.0001 9996.9996\n100000", "1.0001 99999.9999\n100000", "1.0001 100000\n100000", "1.1 99999.9\n100000", "1.0001 99997\n100000", "1.1101 100000\n100000"], "outputs": ["1.0000000000 2.0000000000\n2.0000000000 0.0000000000", "2.8819000000 0.0000000000\n4.1470000000 1.6168000000\n3.7953000000 4.1470000000\n0.9134000000 4.1470000000\n0.0000000000 2.1785000000\n0.7034000000 0.0000000000", "16904.8597000000 4741.4249000000\n7422.0099000000 16904.8597000000\n0.0000000000 2680.5850000000\n16904.8597000000 2060.8399000000\n10102.5949000000 16904.8597000000\n0.0000000000 5361.1700000000\n16285.1146000000 0.0000000000\n12783.1799000000 16904.8597000000\n0.0000000000 8041.7550000000\n13604.5296000000 0.0000000000", "40356.3702000000 32530.3440000000\n0.0000000000 15652.0524000000\n40356.3702000000 16878.2916000000\n0.0000000000 31304.1048000000\n40356.3702000000 1226.2392000000\n6599.7870000000 40356.3702000000\n25930.5570000000 0.0000000000\n22251.8394000000 40356.3702000000\n10278.5046000000 0.0000000000\n37903.8918000000 40356.3702000000\n0.0000000000 5373.5478000000\n40356.3702000000 27156.7962000000\n0.0000000000 21025.6002000000\n40356.3702000000 11504.7438000000\n0.0000000000 36677.6526000000\n36209.0616000000 ...", "70092.4982000000 25741.2759000000\n18609.9464000000 70092.4982000000\n7131.3295000000 0.0000000000\n70092.4982000000 32872.6054000000\n11478.6169000000 70092.4982000000\n14262.6590000000 0.0000000000\n70092.4982000000 40003.9349000000\n4347.2874000000 70092.4982000000\n21393.9885000000 0.0000000000\n70092.4982000000 47135.2644000000\n0.0000000000 67308.4561000000\n28525.3180000000 0.0000000000\n70092.4982000000 54266.5939000000\n0.0000000000 60177.1266000000\n35656.6475000000 0.0000000000\n70092.4982000000...", "19285.2846000000 0.0000000000\n38570.5692000000 0.0000000000\n39712.7105000000 18143.1433000000\n39712.7105000000 37428.4279000000\n22711.7085000000 39712.7105000000\n3426.4239000000 39712.7105000000\n0.0000000000 23853.8498000000\n0.0000000000 4568.5652000000\n14716.7194000000 0.0000000000\n34002.0040000000 0.0000000000\n39712.7105000000 13574.5781000000\n39712.7105000000 32859.8627000000\n27280.2737000000 39712.7105000000\n7994.9891000000 39712.7105000000\n0.0000000000 28422.4150000000\n0.0000000000 9137...", "49021.4126000000 0.0000000000\n97591.0354000000 451.7898000000\n97591.0354000000 49473.2024000000\n96687.4558000000 97591.0354000000\n47666.0432000000 97591.0354000000\n0.0000000000 96235.6660000000\n0.0000000000 47214.2534000000\n1807.1592000000 0.0000000000\n50828.5718000000 0.0000000000\n97591.0354000000 2258.9490000000\n97591.0354000000 51280.3616000000\n94880.2966000000 97591.0354000000\n45858.8840000000 97591.0354000000\n0.0000000000 94428.5068000000\n0.0000000000 45407.0942000000\n3614.3184000000 0....", "0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000...", "1.0000000000 0.0000000000", "99999.9998000000 0.0000000000\n99999.9999000000 99999.9997000000\n0.0003000000 99999.9999000000\n0.0000000000 0.0004000000\n99999.9994000000 0.0000000000\n99999.9999000000 99999.9993000000\n0.0007000000 99999.9999000000\n0.0000000000 0.0008000000\n99999.9990000000 0.0000000000\n99999.9999000000 99999.9989000000\n0.0011000000 99999.9999000000\n0.0000000000 0.0012000000\n99999.9986000000 0.0000000000\n99999.9999000000 99999.9985000000\n0.0015000000 99999.9999000000\n0.0000000000 0.0016000000\n99999.998200000...", "-0.0000000000 1.0001000000\n1.0001000000 1.0001000000\n1.0001000000 0.0000000000\n-0.0000000000 0.0000000000\n0.0000000000 1.0001000000\n1.0001000000 1.0001000000\n1.0001000000 0.0000000000\n-0.0000000000 0.0000000000\n0.0000000000 1.0001000000\n1.0001000000 1.0001000000\n1.0001000000 0.0000000000\n-0.0000000000 0.0000000000\n0.0000000000 1.0001000000\n1.0001000000 1.0001000000\n1.0001000000 0.0000000000\n-0.0000000000 0.0000000000\n0.0000000000 1.0001000000\n1.0001000000 1.0001000000\n1.0001000000 0.00000...", "1.0000000000 0.0000000000\n2.0000000000 0.0000000000\n3.0000000000 0.0000000000\n4.0000000000 0.0000000000\n5.0000000000 0.0000000000\n6.0000000000 0.0000000000\n7.0000000000 0.0000000000\n8.0000000000 0.0000000000\n9.0000000000 0.0000000000\n10.0000000000 0.0000000000\n11.0000000000 0.0000000000\n12.0000000000 0.0000000000\n13.0000000000 0.0000000000\n14.0000000000 0.0000000000\n15.0000000000 0.0000000000\n16.0000000000 0.0000000000\n17.0000000000 0.0000000000\n18.0000000000 0.0000000000\n19.0000000000 0....", "100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n...", "100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n100000.0000000000 0.0000000000\n100000.0000000000 100000.0000000000\n0.0000000000 100000.0000000000\n0.0000000000 0.0000000000\n...", "1.5485000000 0.0000000000\n1.6055000000 1.4915000000\n0.1710000000 1.6055000000\n0.0000000000 0.2280000000\n1.3205000000 0.0000000000\n1.6055000000 1.2635000000\n0.3990000000 1.6055000000\n0.0000000000 0.4560000000\n1.0925000000 0.0000000000\n1.6055000000 1.0355000000\n0.6270000000 1.6055000000\n0.0000000000 0.6840000000\n0.8645000000 0.0000000000\n1.6055000000 0.8075000000\n0.8550000000 1.6055000000\n0.0000000000 0.9120000000\n0.6365000000 0.0000000000\n1.6055000000 0.5795000000\n1.0830000000 1.6055000000...", "0.8645000000 0.0000000000\n1.7290000000 0.0000000000\n2.5828000000 0.0107000000\n2.5828000000 0.8752000000\n2.5828000000 1.7397000000\n2.5614000000 2.5828000000\n1.6969000000 2.5828000000\n0.8324000000 2.5828000000\n0.0000000000 2.5507000000\n0.0000000000 1.6862000000\n0.0000000000 0.8217000000\n0.0428000000 0.0000000000\n0.9073000000 0.0000000000\n1.7718000000 0.0000000000\n2.5828000000 0.0535000000\n2.5828000000 0.9180000000\n2.5828000000 1.7825000000\n2.5186000000 2.5828000000\n1.6541000000 2.5828000000...", "2.9320000000 2.7821000000\n0.0000000000 0.2998000000\n2.9320000000 2.4823000000\n0.0000000000 0.5996000000\n2.9320000000 2.1825000000\n0.0000000000 0.8994000000\n2.9320000000 1.8827000000\n0.0000000000 1.1992000000\n2.9320000000 1.5829000000\n0.0000000000 1.4990000000\n2.9320000000 1.2831000000\n0.0000000000 1.7988000000\n2.9320000000 0.9833000000\n0.0000000000 2.0986000000\n2.9320000000 0.6835000000\n0.0000000000 2.3984000000\n2.9320000000 0.3837000000\n0.0000000000 2.6982000000\n2.9320000000 0.0839000000...", "1.6928000000 0.0000000000\n3.3856000000 0.0000000000\n5.0784000000 0.0000000000\n6.7712000000 0.0000000000\n8.4640000000 0.0000000000\n10.1568000000 0.0000000000\n11.8496000000 0.0000000000\n13.5424000000 0.0000000000\n15.2352000000 0.0000000000\n16.9280000000 0.0000000000\n18.6208000000 0.0000000000\n20.3136000000 0.0000000000\n22.0064000000 0.0000000000\n23.6992000000 0.0000000000\n25.3920000000 0.0000000000\n27.0848000000 0.0000000000\n28.7776000000 0.0000000000\n30.4704000000 0.0000000000\n32.163200000...", "2.4240000000 0.0000000000\n4.8480000000 0.0000000000\n7.2720000000 0.0000000000\n9.6960000000 0.0000000000\n12.1200000000 0.0000000000\n14.5440000000 0.0000000000\n16.9680000000 0.0000000000\n19.3920000000 0.0000000000\n21.8160000000 0.0000000000\n24.2400000000 0.0000000000\n26.6640000000 0.0000000000\n29.0880000000 0.0000000000\n31.5120000000 0.0000000000\n33.9360000000 0.0000000000\n36.3600000000 0.0000000000\n38.7840000000 0.0000000000\n41.2080000000 0.0000000000\n43.6320000000 0.0000000000\n46.05600000...", "5.1934000000 0.0000000000\n10.3868000000 0.0000000000\n15.5802000000 0.0000000000\n20.7736000000 0.0000000000\n25.9670000000 0.0000000000\n31.1604000000 0.0000000000\n36.3538000000 0.0000000000\n41.5472000000 0.0000000000\n46.7406000000 0.0000000000\n51.9340000000 0.0000000000\n57.1274000000 0.0000000000\n62.3208000000 0.0000000000\n67.5142000000 0.0000000000\n72.7076000000 0.0000000000\n77.9010000000 0.0000000000\n83.0944000000 0.0000000000\n88.2878000000 0.0000000000\n93.4812000000 0.0000000000\n98.67460...", "26244.1561000000 23166.6769000000\n0.0000000000 6154.9584000000\n26244.1561000000 17011.7185000000\n0.0000000000 12309.9168000000\n26244.1561000000 10856.7601000000\n0.0000000000 18464.8752000000\n26244.1561000000 4701.8017000000\n0.0000000000 24619.8336000000\n24790.9994000000 0.0000000000\n4530.6359000000 26244.1561000000\n18636.0410000000 0.0000000000\n10685.5943000000 26244.1561000000\n12481.0826000000 0.0000000000\n16840.5527000000 26244.1561000000\n6326.1242000000 0.0000000000\n22995.5111000000 26244...", "26253.1158000000 6203.2777000000\n13846.5604000000 26253.1158000000\n0.0000000000 7643.2827000000\n24813.1108000000 0.0000000000\n21489.8431000000 26253.1158000000\n0.0000000000 15286.5654000000\n17169.8281000000 0.0000000000\n26253.1158000000 23373.1058000000\n0.0000000000 22929.8481000000\n9526.5454000000 0.0000000000\n26253.1158000000 15729.8231000000\n4320.0150000000 26253.1158000000\n1883.2627000000 0.0000000000\n26253.1158000000 8086.5404000000\n11963.2977000000 26253.1158000000\n0.0000000000 5760.02...", "15501.9524000000 0.0000000000\n26262.0740000000 4741.8308000000\n26262.0740000000 20243.7832000000\n16778.4124000000 26262.0740000000\n1276.4600000000 26262.0740000000\n0.0000000000 12036.5816000000\n3465.3708000000 0.0000000000\n18967.3232000000 0.0000000000\n26262.0740000000 8207.2016000000\n26262.0740000000 23709.1540000000\n13313.0416000000 26262.0740000000\n0.0000000000 24073.1632000000\n0.0000000000 8571.2108000000\n6930.7416000000 0.0000000000\n22432.6940000000 0.0000000000\n26262.0740000000 11672.5...", "0.0000000000 15621.3350000000\n8606.7923000000 22635.8777000000\n22635.8777000000 21043.6281000000\n22635.8777000000 5422.2931000000\n12436.8358000000 0.0000000000\n0.0000000000 3184.4992000000\n0.0000000000 18805.8342000000\n11791.2915000000 22635.8777000000\n22635.8777000000 17859.1289000000\n22635.8777000000 2237.7939000000", "5681.4396000000 1072.4207000000\n3536.5982000000 5681.4396000000\n0.0000000000 2464.1775000000\n4289.6828000000 0.0000000000\n5681.4396000000 5362.1035000000\n0.0000000000 4928.3550000000\n1825.5053000000 0.0000000000\n5681.4396000000 2897.9260000000\n1711.0929000000 5681.4396000000\n0.0000000000 638.6722000000", "52372.0072000000 45497.2300000000\n0.0000000000 13749.5544000000\n52372.0072000000 31747.6756000000\n0.0000000000 27499.1088000000\n52372.0072000000 17998.1212000000\n0.0000000000 41248.6632000000\n52372.0072000000 4248.5668000000\n2626.2104000000 52372.0072000000\n42871.0196000000 0.0000000000\n16375.7648000000 52372.0072000000\n29121.4652000000 0.0000000000\n30125.3192000000 52372.0072000000\n15371.9108000000 0.0000000000\n43874.8736000000 52372.0072000000\n1622.3564000000 0.0000000000\n52372.0072000000 ...", "8374.5074000000 35417.5676000000\n35417.5676000000 18668.5528000000\n10294.0454000000 0.0000000000\n0.0000000000 33498.0296000000\n35417.5676000000 28962.5982000000\n20588.0908000000 0.0000000000\n0.0000000000 23203.9842000000\n31578.4916000000 35417.5676000000\n30882.1362000000 0.0000000000\n0.0000000000 12909.9388000000\n21284.4462000000 35417.5676000000\n35417.5676000000 5758.6140000000\n0.0000000000 2615.8934000000\n10990.4008000000 35417.5676000000\n35417.5676000000 16052.6594000000\n7678.1520000000 0...", "21320.7493000000 0.0000000000\n21992.2179000000 20649.2807000000\n2014.4058000000 21992.2179000000\n0.0000000000 2685.8744000000\n18634.8749000000 0.0000000000\n21992.2179000000 17963.4063000000\n4700.2802000000 21992.2179000000\n0.0000000000 5371.7488000000\n15949.0005000000 0.0000000000\n21992.2179000000 15277.5319000000\n7386.1546000000 21992.2179000000\n0.0000000000 8057.6232000000\n13263.1261000000 0.0000000000\n21992.2179000000 12591.6575000000\n10072.0290000000 21992.2179000000\n0.0000000000 10743.4...", "1178.5863000000 0.0000000000\n2357.1726000000 0.0000000000\n3535.7589000000 0.0000000000\n4714.3452000000 0.0000000000\n5037.7799000000 855.1516000000\n5037.7799000000 2033.7379000000\n5037.7799000000 3212.3242000000\n5037.7799000000 4390.9105000000\n4506.0630000000 5037.7799000000\n3327.4767000000 5037.7799000000\n2148.8904000000 5037.7799000000\n970.3041000000 5037.7799000000\n0.0000000000 4829.4977000000\n0.0000000000 3650.9114000000\n0.0000000000 2472.3251000000\n0.0000000000 1293.7388000000\n0.0000000...", "51056.8773000000 0.0000000000\n79870.5443000000 22243.2103000000\n79870.5443000000 73300.0876000000\n35384.1237000000 79870.5443000000\n0.0000000000 64197.7907000000\n0.0000000000 13140.9134000000\n37915.9639000000 0.0000000000\n79870.5443000000 9102.2969000000\n79870.5443000000 60159.1742000000\n48525.0371000000 79870.5443000000\n0.0000000000 77338.7041000000\n0.0000000000 26281.8268000000\n24775.0505000000 0.0000000000\n75831.9278000000 0.0000000000\n79870.5443000000 47018.2608000000\n61665.9505000000 79...", "51065.8339000000 0.0000000000\n62916.1032000000 39215.5646000000\n35550.8079000000 62916.1032000000\n0.0000000000 47401.0772000000\n3664.7567000000 0.0000000000\n54730.5906000000 0.0000000000\n62916.1032000000 42880.3213000000\n31886.0512000000 62916.1032000000\n0.0000000000 43736.3205000000\n7329.5134000000 0.0000000000\n58395.3473000000 0.0000000000\n62916.1032000000 46545.0780000000\n28221.2945000000 62916.1032000000\n0.0000000000 40071.5638000000\n10994.2701000000 0.0000000000\n62060.1040000000 0.00000...", "51056.8773000000 0.0000000000\n79870.5443000000 22243.2103000000\n79870.5443000000 73300.0876000000\n35384.1237000000 79870.5443000000\n0.0000000000 64197.7907000000\n0.0000000000 13140.9134000000\n37915.9639000000 0.0000000000\n79870.5443000000 9102.2969000000\n79870.5443000000 60159.1742000000\n48525.0371000000 79870.5443000000\n0.0000000000 77338.7041000000\n0.0000000000 26281.8268000000\n24775.0505000000 0.0000000000\n75831.9278000000 0.0000000000\n79870.5443000000 47018.2608000000\n61665.9505000000 79...", "51065.8339000000 0.0000000000\n62916.1032000000 39215.5646000000\n35550.8079000000 62916.1032000000\n0.0000000000 47401.0772000000\n3664.7567000000 0.0000000000\n54730.5906000000 0.0000000000\n62916.1032000000 42880.3213000000\n31886.0512000000 62916.1032000000\n0.0000000000 43736.3205000000\n7329.5134000000 0.0000000000\n58395.3473000000 0.0000000000\n62916.1032000000 46545.0780000000\n28221.2945000000 62916.1032000000\n0.0000000000 40071.5638000000\n10994.2701000000 0.0000000000\n62060.1040000000 0.00000...", "3.0000000000 0.1000000000\n2.8000000000 3.0000000000\n0.0000000000 2.7000000000\n0.4000000000 0.0000000000\n3.0000000000 0.5000000000\n2.4000000000 3.0000000000\n0.0000000000 2.3000000000\n0.8000000000 0.0000000000\n3.0000000000 0.9000000000\n2.0000000000 3.0000000000\n0.0000000000 1.9000000000\n1.2000000000 0.0000000000\n3.0000000000 1.3000000000\n1.6000000000 3.0000000000\n0.0000000000 1.5000000000\n1.6000000000 0.0000000000\n3.0000000000 1.7000000000\n1.2000000000 3.0000000000\n0.0000000000 1.1000000000...", "3.0000000000 0.2000000000\n2.6000000000 3.0000000000\n0.0000000000 2.4000000000\n0.8000000000 0.0000000000\n3.0000000000 1.0000000000\n1.8000000000 3.0000000000\n0.0000000000 1.6000000000\n1.6000000000 0.0000000000\n3.0000000000 1.8000000000\n1.0000000000 3.0000000000\n0.0000000000 0.8000000000\n2.4000000000 0.0000000000\n3.0000000000 2.6000000000\n0.2000000000 3.0000000000\n0.0000000000 0.0000000000\n3.0000000000 0.2000000000\n2.6000000000 3.0000000000\n0.0000000000 2.4000000000\n0.8000000000 0.0000000000...", "3.0000000000 0.0001000000\n2.9998000000 3.0000000000\n0.0000000000 2.9997000000\n0.0004000000 0.0000000000\n3.0000000000 0.0005000000\n2.9994000000 3.0000000000\n0.0000000000 2.9993000000\n0.0008000000 0.0000000000\n3.0000000000 0.0009000000\n2.9990000000 3.0000000000\n0.0000000000 2.9989000000\n0.0012000000 0.0000000000\n3.0000000000 0.0013000000\n2.9986000000 3.0000000000\n0.0000000000 2.9985000000\n0.0016000000 0.0000000000\n3.0000000000 0.0017000000\n2.9982000000 3.0000000000\n0.0000000000 2.9981000000...", "3.0000000000 0.0002000000\n2.9996000000 3.0000000000\n0.0000000000 2.9994000000\n0.0008000000 0.0000000000\n3.0000000000 0.0010000000\n2.9988000000 3.0000000000\n0.0000000000 2.9986000000\n0.0016000000 0.0000000000\n3.0000000000 0.0018000000\n2.9980000000 3.0000000000\n0.0000000000 2.9978000000\n0.0024000000 0.0000000000\n3.0000000000 0.0026000000\n2.9972000000 3.0000000000\n0.0000000000 2.9970000000\n0.0032000000 0.0000000000\n3.0000000000 0.0034000000\n2.9964000000 3.0000000000\n0.0000000000 2.9962000000...", "99999.0002000000 0.0000000000\n100000.0000000000 99998.0004000000\n2.9994000000 100000.0000000000\n0.0000000000 3.9992000000\n99995.0010000000 0.0000000000\n100000.0000000000 99994.0012000000\n6.9986000000 100000.0000000000\n0.0000000000 7.9984000000\n99991.0018000000 0.0000000000\n100000.0000000000 99990.0020000000\n10.9978000000 100000.0000000000\n0.0000000000 11.9976000000\n99987.0026000000 0.0000000000\n100000.0000000000 99986.0028000000\n14.9970000000 100000.0000000000\n0.0000000000 15.9968000000\n999...", "99999.9998000000 0.0001000000\n99999.9996000000 99999.9998000000\n0.0000000000 99999.9995000000\n0.0004000000 0.0000000000\n99999.9998000000 0.0005000000\n99999.9992000000 99999.9998000000\n0.0000000000 99999.9991000000\n0.0008000000 0.0000000000\n99999.9998000000 0.0009000000\n99999.9988000000 99999.9998000000\n0.0000000000 99999.9987000000\n0.0012000000 0.0000000000\n99999.9998000000 0.0013000000\n99999.9984000000 99999.9998000000\n0.0000000000 99999.9983000000\n0.0016000000 0.0000000000\n99999.999800000...", "0.0000000000 0.0001000000\n0.0000000000 0.0002000000\n0.0000000000 0.0003000000\n0.0000000000 0.0004000000\n0.0000000000 0.0005000000\n0.0000000000 0.0006000000\n0.0000000000 0.0007000000\n0.0000000000 0.0008000000\n0.0000000000 0.0009000000\n0.0000000000 0.0010000000\n0.0000000000 0.0011000000\n0.0000000000 0.0012000000\n0.0000000000 0.0013000000\n0.0000000000 0.0014000000\n0.0000000000 0.0015000000\n0.0000000000 0.0016000000\n0.0000000000 0.0017000000\n0.0000000000 0.0018000000\n0.0000000000 0.0019000000...", "0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000\n0.0000000000 0.0000000000...", "0.9992000000 1.0001000000\n0.0018000000 0.0000000000\n0.9974000000 1.0001000000\n0.0036000000 0.0000000000\n0.9956000000 1.0001000000\n0.0054000000 0.0000000000\n0.9938000000 1.0001000000\n0.0072000000 0.0000000000\n0.9920000000 1.0001000000\n0.0090000000 0.0000000000\n0.9902000000 1.0001000000\n0.0108000000 0.0000000000\n0.9884000000 1.0001000000\n0.0126000000 0.0000000000\n0.9866000000 1.0001000000\n0.0144000000 0.0000000000\n0.9848000000 1.0001000000\n0.0162000000 0.0000000000\n0.9830000000 1.0001000000...", "0.9991000000 1.0001000000\n0.0020000000 0.0000000000\n0.9971000000 1.0001000000\n0.0040000000 0.0000000000\n0.9951000000 1.0001000000\n0.0060000000 0.0000000000\n0.9931000000 1.0001000000\n0.0080000000 0.0000000000\n0.9911000000 1.0001000000\n0.0100000000 0.0000000000\n0.9891000000 1.0001000000\n0.0120000000 0.0000000000\n0.9871000000 1.0001000000\n0.0140000000 0.0000000000\n0.9851000000 1.0001000000\n0.0160000000 0.0000000000\n0.9831000000 1.0001000000\n0.0180000000 0.0000000000\n0.9811000000 1.0001000000...", "1.1000000000 0.0000000000\n1.1000000000 1.1000000000\n0.0000000000 1.1000000000\n-0.0000000000 0.0000000000\n1.1000000000 0.0000000000\n1.1000000000 1.1000000000\n0.0000000000 1.1000000000\n-0.0000000000 0.0000000000\n1.1000000000 0.0000000000\n1.1000000000 1.1000000000\n0.0000000000 1.1000000000\n-0.0000000000 0.0000000000\n1.1000000000 0.0000000000\n1.1000000000 1.1000000000\n0.0000000000 1.1000000000\n-0.0000000000 0.0000000000\n1.1000000000 0.0000000000\n1.1000000000 1.1000000000\n0.0000000000 1.100000...", "0.0000000000 0.9988000000\n0.9975000000 1.0001000000\n1.0001000000 0.0039000000\n0.0052000000 0.0000000000\n0.0000000000 0.9936000000\n0.9923000000 1.0001000000\n1.0001000000 0.0091000000\n0.0104000000 0.0000000000\n0.0000000000 0.9884000000\n0.9871000000 1.0001000000\n1.0001000000 0.0143000000\n0.0156000000 0.0000000000\n0.0000000000 0.9832000000\n0.9819000000 1.0001000000\n1.0001000000 0.0195000000\n0.0208000000 0.0000000000\n0.0000000000 0.9780000000\n0.9767000000 1.0001000000\n1.0001000000 0.0247000000...", "1.1101000000 1.0819000000\n0.0000000000 0.0564000000\n1.1101000000 1.0255000000\n0.0000000000 0.1128000000\n1.1101000000 0.9691000000\n0.0000000000 0.1692000000\n1.1101000000 0.9127000000\n0.0000000000 0.2256000000\n1.1101000000 0.8563000000\n0.0000000000 0.2820000000\n1.1101000000 0.7999000000\n0.0000000000 0.3384000000\n1.1101000000 0.7435000000\n0.0000000000 0.3948000000\n1.1101000000 0.6871000000\n0.0000000000 0.4512000000\n1.1101000000 0.6307000000\n0.0000000000 0.5076000000\n1.1101000000 0.5743000000..."]}
UNKNOWN
PYTHON3
CODEFORCES
6
19dae5f00909e7d63f427950e41e714c
Game with Coins
Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer *x* (2·*x*<=+<=1<=≤<=*n*) and take a coin from each chest with numbers *x*, 2·*x*, 2·*x*<=+<=1. It may turn out that some chest has no coins, in this case the player doesn't take a coin from this chest. The game finishes when all chests get emptied. Polycarpus isn't a greedy scrooge. Polycarpys is a lazy slob. So he wonders in what minimum number of moves the game can finish. Help Polycarpus, determine the minimum number of moves in which the game can finish. Note that Polycarpus counts not only his moves, he also counts Vasily's moves. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of chests with coins. The second line contains a sequence of space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the number of coins in the chest number *i* at the beginning of the game. Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1. Sample Input 1 1 3 1 2 3 Sample Output -1 3
[ "n = int(input())\r\nif n == 1 or n & 1 == 0: print(-1)\r\nelse:\r\n t = list(map(int, input().split()))\r\n s, k = 0, n // 2 - 1\r\n for i in range(n - 1, 1, -2):\r\n p = max(t[i], t[i - 1])\r\n t[k] = max(0, t[k] - p)\r\n s += p\r\n k -= 1\r\n print(s + t[0])", "def solve(A):\r\n res = 0\r\n for i in range(n, 0, -1):\r\n if A[i] <= 0:\r\n continue\r\n x = int(i / 2)\r\n A[x] -= A[i]\r\n res += A[i]\r\n if i % 2 == 1:\r\n A[i - 1] -= A[i]\r\n A[i] = 0\r\n return res\r\nn = int(input())\r\nif n == 1 or n % 2 == 0:\r\n print(-1)\r\n exit()\r\nA = [0] * (n + 1)\r\nA[1:n + 1] = list(map(int, input().split()))\r\nprint(solve(A))# 1698410642.9966471", "n = int(input())\r\na = list(map(int, input().split()))\r\nif n < 3 or n % 2 == 0:\r\n print(-1)\r\nelse:\r\n a.insert(0, 0)\r\n ans = 0\r\n for i in range(n, 0, -1):\r\n ans += a[i]\r\n x = i//2\r\n a[x] = max(0, a[x] - a[i])\r\n a[2*x] = max(0, a[2*x] - a[i])\r\n\r\n print(ans)# 1690466045.439879", "n=int(input()) \r\nif n==1 or n%2==0:\r\n\tprint(-1)\r\n\texit()\r\nA=[0]*(n+1)\r\nA[1:n+1]=list(map(int,input().split()))\r\nans=0\r\nfor i in range(n,0,-1):\r\n\tif(A[i]<=0):continue\r\n\tx=int(i/2) \r\n\tA[x]-=A[i]\r\n\tans+=A[i]\r\n\tif i%2==1:\r\n\t\tA[i-1]-=A[i]\r\n\tA[i]=0 \r\nprint(ans)", "n = int(input())\r\nlst = list(map(int, input().split()))\r\nans, idx = 0,0\r\nif n < 3 or n % 2 == 0:\r\n print(-1)\r\n exit(0)\r\n\r\nwhile n > 2:\r\n n -= 2\r\n mx = max(lst[n], lst[n+1])\r\n ans += mx\r\n lst[n//2] -= min(lst[n//2], mx)\r\n\r\nprint(ans + lst[0])\r\n", "n = int(input())\nA = [int(i) for i in input().split()]\nif n == 1 or n % 2 == 0:\n print(-1)\n exit()\nans = 0\nfor i in range(n-1, 3, -2):\n diff = max(A[i], A[i-1])\n ans += diff\n A[(i-1)//2] -= diff\n A[(i-1)//2] = max(0, A[(i-1)//2])\nans += max(A[:3])\nprint(ans)\n\t\t\t\t\t\t \t\t\t \t\t \t \t\t\t \t \t \t\t \t\t", "t = int(input())\r\nline = input()\r\nlis = line.split()\r\nlis = [int(i) for i in lis]\r\nif t==1 or t%2==0 :\r\n print(\"-1\")\r\n quit()\r\ncount = 0\r\ni = t \r\nwhile i >= 4 :\r\n if i%2 == 1 :\r\n p = i-1 \r\n q = int(p/2)\r\n count = count + lis[i-1]\r\n lis[p-1] = lis[p-1] - lis[i-1]\r\n if lis[p-1] < 0 :\r\n lis[p-1] = 0\r\n lis[q-1] = lis[q-1] - lis[i-1]\r\n if lis[q-1] < 0 :\r\n lis[q-1] = 0\r\n lis[i-1] = 0\r\n else :\r\n p = i+1 \r\n q = int(i/2)\r\n count = count + lis[i-1]\r\n lis[p-1] = lis[p-1] - lis[i-1]\r\n if lis[p-1] < 0 :\r\n lis[p-1] = 0\r\n lis[q-1] = lis[q-1] - lis[i-1]\r\n if lis[q-1] < 0 :\r\n lis[q-1] = 0\r\n lis[i-1] = 0\r\n i = i-1\r\nm = max(lis[0], lis[1], lis[2])\r\ncount = count + m\r\nprint(count)", "import sys\r\nfrom array import array\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\nn, a = int(input()), array('h', [0] + [int(x) for x in input().split()])\r\nans = 0\r\nif n & 1 == 0 or n < 3:\r\n exit(print(-1))\r\n\r\nfor i in range(n, 1, -2):\r\n ix1, ix2, ix3 = i >> 1, i - 1, i\r\n ma = max(a[ix2], a[ix3])\r\n ans += ma\r\n\r\n for ix in (ix1, ix2, ix3):\r\n a[ix] = max(0, a[ix] - ma)\r\n\r\n if ix1 == 1:\r\n ans += a[ix1]\r\n a[ix1] = 0\r\nprint(-1 if any(a) else ans)\r\n", "n, s = int(input()), 0\r\na = [0] + list(map(int, input().split()))\r\nif n % 2 == 0 or n == 1:\r\n print(-1)\r\nelse:\r\n for i in range(n, 1, -2):\r\n mx = max(a[i], a[i - 1])\r\n s += mx\r\n a[i // 2] = max(0, a[i // 2] - mx)\r\n print(s + a[1])" ]
{"inputs": ["1\n1", "3\n1 2 3", "100\n269 608 534 956 993 409 297 735 258 451 468 422 125 407 580 769 857 383 419 67 377 230 842 113 169 427 287 75 372 133 456 450 644 303 638 40 217 445 427 730 168 341 371 633 237 951 142 596 528 509 236 782 44 467 607 326 267 15 564 858 499 337 74 346 443 436 48 795 206 403 379 313 382 620 341 978 209 696 879 810 872 336 983 281 602 521 762 782 733 184 307 567 245 983 201 966 546 70 5 973", "99\n557 852 325 459 557 350 719 719 400 228 985 674 942 322 212 553 191 58 720 262 798 884 20 275 576 971 684 340 581 175 641 552 190 277 293 928 261 504 83 950 423 211 571 159 44 428 131 273 181 555 430 437 901 376 361 989 225 399 712 935 279 975 525 631 442 558 457 904 491 598 321 396 537 555 73 415 842 162 284 847 847 139 305 150 300 664 831 894 260 747 466 563 97 907 42 340 553 471 411", "98\n204 880 89 270 128 298 522 176 611 49 492 475 977 701 197 837 600 361 355 70 640 472 312 510 914 665 869 105 411 812 74 324 727 412 161 703 392 364 752 74 446 156 333 82 557 764 145 803 36 293 776 276 810 909 877 488 521 865 200 817 445 577 49 165 755 961 867 819 260 836 276 756 649 169 457 28 598 328 692 487 673 563 24 310 913 639 824 346 481 538 509 861 764 108 479 14 552 752", "97\n691 452 909 730 594 55 622 633 13 359 246 925 172 25 535 930 170 528 933 878 130 548 253 745 116 494 862 574 888 609 18 448 208 354 133 181 330 89 364 198 412 157 152 300 910 99 808 228 435 872 985 364 911 634 289 235 761 978 631 212 314 828 277 347 965 524 222 381 84 970 743 116 57 975 33 289 194 493 853 584 338 987 686 926 718 806 170 902 349 137 849 671 783 853 564 495 711", "96\n529 832 728 246 165 3 425 338 520 373 945 726 208 404 329 918 579 183 319 38 268 136 353 980 614 483 47 987 717 54 451 275 938 841 649 147 917 949 169 322 626 103 266 415 423 627 822 757 641 610 331 203 172 814 806 734 706 147 119 798 480 622 153 176 278 735 632 944 853 400 699 476 976 589 417 446 141 307 557 576 355 763 404 87 332 429 516 649 570 279 893 969 154 246 353 920", "95\n368 756 196 705 632 759 228 794 922 387 803 176 755 727 963 658 797 190 249 845 110 916 941 215 655 17 95 751 2 396 395 47 419 784 325 626 856 969 838 501 945 48 84 689 423 963 485 831 848 189 540 42 273 243 322 288 106 260 550 681 542 224 677 902 295 490 338 858 325 638 6 484 88 746 697 355 385 472 262 864 77 378 419 55 945 109 862 101 982 70 936 323 822 447 437", "94\n311 135 312 221 906 708 32 251 677 753 502 329 790 106 949 942 558 845 532 949 952 800 585 450 857 198 88 516 832 193 532 171 253 918 194 752 339 534 450 625 967 345 199 612 936 650 499 256 191 576 590 73 374 968 382 139 50 725 38 76 763 827 905 83 801 53 748 421 94 420 665 844 496 360 81 512 685 638 671 960 902 802 785 863 558 276 15 305 202 669 276 621 841 192", "1\n546", "2\n707 629", "3\n868 762 256", "4\n221 30 141 672", "5\n86 458 321 157 829", "6\n599 78 853 537 67 706", "7\n760 154 34 77 792 950 159", "8\n113 583 918 562 325 1 60 769", "9\n275 555 451 102 755 245 256 312 230", "10\n636 688 843 886 13 751 884 120 880 439", "11\n989 117 23 371 442 803 81 768 182 425 888", "55\n1 1 2 2 2 2 1 1 1 1 2 1 2 1 2 2 1 1 2 2 1 2 1 2 1 1 1 2 1 2 2 2 1 2 2 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 2 2 2 2 2", "43\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", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "77\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "100\n999 1000 999 999 1000 1000 999 1000 999 999 999 999 1000 1000 1000 1000 1000 999 999 999 1000 999 1000 999 999 1000 1000 1000 1000 1000 1000 999 999 1000 1000 999 1000 1000 999 999 999 1000 999 1000 999 999 999 999 1000 1000 999 999 1000 999 1000 999 999 1000 999 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 1000 1000 999 999 999 999 1000 1000 1000 1000 1000 1000 999 1000 1000 999 999 999 1000 999 1000 999 1000 1000 1000 999 999 1000 999 1000", "47\n16 17 18 13 14 12 18 13 19 13 13 11 13 17 10 18 16 16 19 11 20 17 14 18 12 15 16 20 11 16 17 19 12 16 19 16 18 19 19 10 11 19 13 12 11 17 13", "74\n694 170 527 538 833 447 622 663 786 411 855 345 565 549 423 301 119 182 680 357 441 859 844 668 606 202 795 696 395 666 812 162 714 443 629 575 764 605 240 363 156 835 866 659 170 462 438 618 551 266 831 149 188 185 496 716 879 617 215 186 745 613 398 266 745 866 389 220 178 809 519 793 221 361", "99\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000", "99\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", "99\n1 1 1 1 1 2 2 1 2 2 1 2 2 2 1 1 2 1 1 1 1 1 1 1 1 2 2 2 1 2 1 2 1 2 2 2 1 2 2 2 1 1 2 1 2 1 1 2 2 2 1 2 2 2 1 2 1 1 1 2 1 2 1 1 1 1 2 1 1 1 1 2 1 2 2 1 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 2 1 1 1 1 2 2", "99\n3 1 3 2 3 2 3 1 1 1 2 1 1 2 2 3 1 1 2 1 3 1 3 2 2 3 3 1 1 2 1 2 3 1 3 3 1 3 3 2 3 3 1 2 1 3 3 3 1 1 3 2 1 3 1 3 1 3 3 1 3 1 3 2 1 3 1 1 1 1 2 1 2 3 2 1 3 2 2 2 2 2 2 1 3 3 2 3 1 3 1 2 3 2 3 3 2 1 2", "99\n3 3 3 3 3 2 2 3 3 2 2 3 2 2 2 3 3 3 2 3 3 3 3 2 2 2 3 2 3 3 3 3 3 2 2 2 3 2 3 2 2 2 3 2 3 3 3 2 2 3 2 3 2 2 2 3 3 2 3 2 2 3 2 2 2 3 2 2 3 3 3 3 3 3 3 3 3 3 2 3 3 2 3 2 3 3 2 2 3 3 3 3 3 3 3 2 2 2 3", "23\n2 2 2 2 2 2 2 2 1 1 2 2 1 1 2 1 1 1 2 2 1 1 1", "23\n1 2 1 3 2 2 3 1 3 3 3 2 1 1 2 3 1 2 3 3 2 1 1", "23\n2 3 3 2 2 2 2 2 3 2 2 3 2 2 2 3 3 3 3 3 2 3 2", "5\n2 2 2 2 2", "5\n2 2 1 1 1", "5\n2 1 2 2 1", "5\n1 2 2 1 2", "5\n1 1 2 4 4"], "outputs": ["-1", "3", "-1", "23450", "-1", "25165", "-1", "23078", "-1", "-1", "-1", "868", "-1", "1150", "-1", "2502", "-1", "1598", "-1", "3448", "32", "15", "-1", "27000", "-1", "278", "-1", "34000", "34", "57", "92", "98", "15", "21", "22", "4", "3", "4", "4", "6"]}
UNKNOWN
PYTHON3
CODEFORCES
9
19e898254aab6b1c7f5fa0c9454533fb
R3D3’s Summer Adventure
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher. There are *n* letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help. Given the costs *c*0 and *c*1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost. The first line of input contains three integers *n* (2<=≤<=*n*<=≤<=108), *c*0 and *c*1 (0<=≤<=*c*0,<=*c*1<=≤<=108) — the number of letters in the alphabet, and costs of '0' and '1', respectively. Output a single integer — minimum possible total a cost of the whole alphabet. Sample Input 4 1 2 Sample Output 12
[ "import sys,heapq\r\n#sys.stdin=open(\"data.txt\")\r\ninput=sys.stdin.readline\r\n\r\nn,a,b=map(int,input().split())\r\n\r\nif a<b: a,b=b,a\r\n\r\nif b==0:\r\n # 1 01 001 0001 ... is optimal, plus a long series of 0's\r\n print((n-1)*a)\r\nelse:\r\n # pascal's triangle thing\r\n pascal=[[1]*20005]\r\n for i in range(20004):\r\n newrow=[1]\r\n for j in range(1,20005):\r\n newrow.append(newrow[-1]+pascal[-1][j])\r\n if newrow[-1]>n: break\r\n pascal.append(newrow)\r\n def getcom(a,b):\r\n # return a+b choose b\r\n # if larger than n, return infinite\r\n if len(pascal[a])>b: return pascal[a][b]\r\n if b==0: return 1\r\n if b==1: return a\r\n return 100000005\r\n\r\n # start with the null node (prefix cost 0)\r\n # can split a node into two other nodes with added cost c+a+b\r\n # new nodes have prefix costs c+a, c+b\r\n # want n-1 splits in total\r\n remain=n-1\r\n ans=0\r\n possible=[[a+b,1]] # [c,count]\r\n while 1:\r\n # cost u, v leaves\r\n u,v=heapq.heappop(possible)\r\n while possible and possible[0][0]==u:\r\n v+=possible[0][1]\r\n heapq.heappop(possible)\r\n if remain<=v:\r\n ans+=u*remain\r\n break\r\n ans+=u*v\r\n remain-=v\r\n heapq.heappush(possible,[u+a,v])\r\n heapq.heappush(possible,[u+b,v])\r\n print(ans)", "import sys,heapq\r\n#sys.stdin=open(\"data.txt\")\r\ninput=sys.stdin.readline\r\n\r\nn,a,b=map(int,input().split())\r\n\r\nif a<b: a,b=b,a\r\n\r\nif b==0:\r\n # 1 01 001 0001 ... is optimal, plus a long series of 0's\r\n print((n-1)*a)\r\nelse:\r\n # start with the null node (prefix cost 0)\r\n # can split a node into two other nodes with added cost c+a+b\r\n # new nodes have prefix costs c+a, c+b\r\n # want n-1 splits in total\r\n remain=n-1\r\n ans=0\r\n possible=[[a+b,1]] # [c,count]\r\n while 1:\r\n # cost u, v leaves\r\n u,v=heapq.heappop(possible)\r\n while possible and possible[0][0]==u:\r\n v+=possible[0][1]\r\n heapq.heappop(possible)\r\n if remain<=v:\r\n ans+=u*remain\r\n break\r\n ans+=u*v\r\n remain-=v\r\n heapq.heappush(possible,[u+a,v])\r\n heapq.heappush(possible,[u+b,v])\r\n print(ans)" ]
{"inputs": ["4 1 2", "2 1 5", "3 1 1", "5 5 5", "4 0 0", "6 0 6", "6 6 0", "2 1 2", "100000000 1 0", "2 0 0", "2 100000000 100000000", "2 100000000 0", "2 0 100000000", "100000000 0 0", "100000000 100000000 100000000", "100000000 100000000 0", "100000000 0 100000000", "2 50000000 0", "2 50000000 100000000", "2 50000000 0", "2 50000000 100000000", "100000000 50000000 0", "100000000 50000000 100000000", "100000000 50000000 0", "100000000 50000000 100000000", "96212915 66569231 66289469", "39969092 91869601 91924349", "26854436 29462638 67336233", "39201451 80233602 30662934", "92820995 96034432 40568102", "81913246 61174868 31286889", "74790405 66932852 48171076", "88265295 26984472 18821097", "39858798 77741429 44017779", "70931513 41663344 29095671", "68251617 52232534 34187120", "44440915 82093126 57268128", "61988457 90532323 72913492", "13756397 41019327 86510346", "84963589 37799442 20818727", "99338896 62289589 49020203", "1505663 3257962 1039115", "80587587 25402325 8120971", "64302230 83635846 22670768", "6508457 32226669 8706339", "1389928 84918086 54850899", "37142108 10188690 35774598", "86813943 11824369 38451380", "14913475 61391038 9257618", "25721978 63666459 14214946", "73363656 63565575 76409698", "34291060 92893503 64680754", "85779772 26434899 86820336", "7347370 2098650 66077918", "28258585 6194848 49146833", "9678 133 5955", "9251 4756 2763", "1736 5628 2595", "5195 1354 2885", "1312 5090 9909", "8619 6736 9365", "151 7023 3093", "5992 2773 6869", "3894 9921 3871", "1006 9237 1123", "9708 3254 2830", "1504 1123 626", "8642 5709 51", "8954 4025 7157", "4730 8020 8722", "2500 5736 4002", "6699 4249 1068", "4755 6759 4899", "8447 1494 4432", "6995 4636 8251", "4295 9730 4322", "8584 4286 9528", "174 6826 355", "5656 7968 3400", "2793 175 3594", "2888 9056 3931", "6222 7124 6784", "8415 8714 2475", "2179 7307 8608", "1189 1829 6875"], "outputs": ["12", "6", "5", "60", "0", "30", "30", "3", "99999999", "0", "200000000", "100000000", "100000000", "0", "266578227200000000", "9999999900000000", "9999999900000000", "50000000", "150000000", "50000000", "150000000", "4999999950000000", "191720992950000000", "4999999950000000", "191720992950000000", "170023209909758400", "93003696194821620", "30373819153055635", "50953283386656312", "158135215198065044", "96084588586645841", "111690840882243696", "52835608063500861", "59709461677488470", "64816798089350400", "75694251898945158", "77907273273831800", "130757350538583270", "19895886795999000", "63754887412974663", "146320678028775569", "60023256524142", "32044560697691212", "77790985833197594", "2645634460061466", "1953921305304795", "19009588918065432", "51645349299460766", "9761450207212562", "20847031763747988", "133919836504944416", "66960630525688676", "114681463889615136", "3070602135161752", "14441957862691571", "196970292", "448302621", "73441521", "130236572", "98808420", "900966230", "5267919", "340564941", "299508763", "38974261", "391502526", "13538132", "135655830", "641304164", "484587068", "136264140", "196812772", "336456318", "298387478", "561476311", "346320888", "738058224", "2889605", "379249528", "36405762", "204521173", "547839384", "545452719", "192281235", "46521099"]}
UNKNOWN
PYTHON3
CODEFORCES
2
1a01e8cd6ea9e6b13f69248a9cdca0db
Monitor
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999 size so that its screen sides ratio becomes *x*:<=*y*, at the same time they want its total area to be maximal of all possible variants. Your task is to find the screen parameters of the reduced size model, or find out that such a reduction can't be performed. The first line of the input contains 4 integers — *a*, *b*, *x* and *y* (1<=≤<=*a*,<=*b*,<=*x*,<=*y*<=≤<=2·109). If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise. Sample Input 800 600 4 3 1920 1200 16 9 1 1 1 2 Sample Output 800 600 1920 1080 0 0
[ "from math import gcd\n\na, b, x, y = map(int, input().split())\nx, y = x // gcd(x, y), y // gcd(x, y)\nq = min(a // x, b // y)\nprint(x * q, y * q)", "'''\r\nBeezMinh\r\n15:36 UTC+7\r\n04/10/2023\r\n'''\r\nfrom sys import stdin\r\nfrom math import gcd\r\ninput = lambda: stdin.readline().rstrip()\r\na, b, x, y = map(int, input().split())\r\nd = gcd(x, y)\r\nx //= d\r\ny //= d\r\na //= x\r\nb //= y\r\nd = min(a, b)\r\nprint(d * x, d * y)", "import math\n\na,b,x,y = map(int,input().split())\n\nm = math.gcd(x,y)\n\nxFloor=x//m\nyFloor=y//m\n\nra = a//xFloor\nrb = b//yFloor\n\nm = min(ra,rb)\n\nprint(xFloor*m,yFloor*m)\n\n\t \t \t \t \t\t\t \t \t\t \t \t \t", "def gcd(a, b):\r\n if(a % b == 0):\r\n return b\r\n return gcd(b,a%b)\r\na , b, x, y = map(int,input().split())\r\nt = gcd(x,y)\r\nx ,y= x // t , y // t\r\nk = min(a//x,b//y)\r\nprint(k * x,k*y)\r\n", "\r\n \r\nimport math ;\r\na, b, x , y = map(int,input().split())\r\nz = math.gcd(x,y)\r\nx//=z ;y//=z; \r\n\r\ni =2 \r\nc = x\r\nd = y\r\nansx=0 ;ansy=0\r\nwhile(c<=a and d<=b):\r\n ansx = c ;ansy= d \r\n c= x *i; \r\n d = y *i \r\n i+=1\r\nprint(f\"{ansx} {ansy}\")\r\n", "import math\r\n\r\n\r\ndef main():\r\n a, b, x, y = map(int, input().split())\r\n\r\n x, y = x // math.gcd(x, y), y // math.gcd(x, y)\r\n a //= x\r\n b //= y\r\n\r\n print(x * min(a, b), y * min(a, b))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import math\n\nx, y, a, b = map(int, input().split())\n\nd = math.gcd(a, b)\na, b = a//d, b//d\n\nif x < a or y < b: \n print(\"0 0\")\n quit()\n\nra = x//a\nrb = y//b\n\nr = min(ra, rb)\nprint(r*a, r*b)\n\t \t\t\t\t\t \t \t \t \t\t \t\t \t \t", "a, b, x, y = list(map(int, input().split()))\r\n\r\ndef gcd(p, q):\r\n if p < q:\r\n p, q = q, p\r\n \r\n while q > 0:\r\n r = p % q\r\n p = q\r\n q = r\r\n \r\n return p\r\n\r\nd = gcd(x, y)\r\nx /= d\r\ny /= d\r\n\r\nif a < x or b < y:\r\n print(0, 0)\r\nelse:\r\n xs1 = 0\r\n ys1 = 0\r\n initial = a // x\r\n rg = initial\r\n\r\n if y * initial <= b:\r\n xs1 = x * initial\r\n ys1 = y * initial\r\n else:\r\n while rg > 0:\r\n if x * initial == a and y * initial == b:\r\n xs1 = a\r\n ys1 = b\r\n break\r\n elif y * initial < b:\r\n xs1 = x * initial\r\n ys1 = y * initial\r\n initial += (rg // 2)\r\n else:\r\n initial -= (rg // 2)\r\n rg = rg // 2\r\n \r\n xs2 = 0\r\n ys2 = 0\r\n initial = b // y\r\n rg = initial\r\n\r\n if x * initial <= a:\r\n xs2 = x * initial\r\n ys2 = y * initial\r\n else:\r\n while rg > 0:\r\n if x * initial == a and y * initial == b:\r\n xs2 = a\r\n ys2 = b\r\n break\r\n elif x * initial < a:\r\n xs2 = x * initial\r\n ys2 = y * initial\r\n initial += (rg // 2)\r\n else:\r\n initial -= (rg // 2)\r\n rg = rg // 2\r\n \r\n if xs1 * ys1 >= xs2 * ys2:\r\n print(int(xs1), int(ys1))\r\n else:\r\n print(int(xs2), int(ys2))", "from sys import stdin ,stdout\r\ninput=stdin.readline\r\nfrom math import gcd\r\ninp=lambda : map(int,input().split())\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end)\r\n\r\na,b,x,y =inp() ; l=1 ; r=10**9 ; ans=0 ; z=gcd(x,y) ; x//=z ; y//=z\r\nwhile l<=r : \r\n mid=(l+r) //2 \r\n if x*mid<=a and y*mid<=b : \r\n ans=mid \r\n l=mid+1 \r\n else : r=mid-1 \r\nprint(x*ans , y*ans)\r\n", "def gcd(a,b):\r\n\treturn a if b==0 else gcd(b,a%b)\r\na,b,x,y=map(int,input().split())\r\ng=gcd(x,y)\r\nx,y=x//g,y//g\r\nlo=0\r\nhi=2000000000\r\nwhile lo!=hi:\r\n\tmid=(lo+hi+1)//2\r\n\tif mid*x<=a and mid*y<=b :\r\n\t\tlo=mid\r\n\telse:\r\n\t\thi=mid-1\r\nprint(lo*x,lo*y)", "from math import gcd\r\n\r\nvar = list(map(int, input().split())) \r\nmcd = gcd(var[2], var[3]) \r\ns = min(var[0]//(var[2]//mcd), var[1]//(var[3]//mcd)) \r\nprint(str((var[2]//mcd)*s) + ' ' + str((var[3]//mcd)*s)) ", "\r\nfrom math import gcd\r\n \r\na, b, c, d = map(int, input().split())\r\ng = gcd(c, d)\r\nc, d = c//g, d//g\r\nt = min(a//c, b//d)\r\nprint(c*t, d*t)", "from math import gcd\r\n \r\nw, h, x, y = map(int, input().split())\r\n \r\nlo = 0\r\nhi = int(1e18)\r\n \r\nz = gcd(x, y)\r\nx = x // z\r\ny = y // z\r\n \r\nans = 0\r\nfor _ in range(100):\r\n mid = (lo + hi) // 2\r\n \r\n if y * mid <= h and x * mid <= w:\r\n ans = mid\r\n lo = mid + 1\r\n else:\r\n hi = mid - 1\r\n \r\nprint(ans * x, ans * y)", "import sys\r\nimport math\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\na, b, x, y = invr()\r\n\r\ngreat = math.gcd(x, y)\r\nx = x//great\r\ny = y//great\r\nif((a*b)//(x+y) == 0):\r\n print(\"0 0\")\r\nelse:\r\n h = x * min(a//x, b//y)\r\n w = y * min(a//x, b//y)\r\n print(h, w)", "def gcd(x, y):\r\n while(y):\r\n x, y = y, x % y\r\n return x\r\n\r\na, b, x, y = input().split()\r\na = int(a)\r\nb = int(b)\r\nx = int(x)\r\ny = int(y)\r\npig = gcd(x, y)\r\nx //= pig\r\ny //= pig\r\nlav = min(a // x, b // y)\r\nprint (lav * x, lav * y)\r\n", "def gcd(a,b):\r\n if b==0:\r\n return a\r\n else:\r\n return gcd(b, a%b)\r\n\r\na,b,x,y=map(int,input().split())\r\nt=gcd(x, y)\r\nx//=t\r\ny//=t\r\nkmax1=a//x\r\nkmax2=b//y\r\nmini=min(kmax1,kmax2)\r\nprint(mini*x,mini*y)\r\n\r\n#kmax3=a//y\r\n#kmax4=b//x\r\n#mini2=min(kmax3,kmax4)\r\n#print(mini2,mini)\r\n#if mini2<mini:\r\n# print(mini*x,mini*y)\r\n#else:\r\n# print(mini2*y,mini2*x)", "from fractions import gcd\r\na,b,x,y=map(int,input().split())\r\nz=gcd(x,y)\r\nx//=z\r\ny//=z\r\nc=min(a//x,b//y)\r\nprint(c*x,c*y)", "# Function to calculate the greatest common divisor\r\ndef gcd(x, y):\r\n return y if x == 0 else gcd(y % x, x)\r\n\r\n# Main function\r\ndef main():\r\n mot_a, mot_b, mot_x, mot_y = map(int, input().split())\r\n mot_gcd = gcd(mot_x, mot_y)\r\n mot_x //= mot_gcd\r\n mot_y //= mot_gcd\r\n mot_u = mot_a // mot_x\r\n mot_v = mot_b // mot_y\r\n mot_factor = mot_u if mot_u < mot_v else mot_v\r\n print(mot_factor * mot_x, mot_factor * mot_y)\r\n\r\n# Invoke the main function\r\nmain()\r\n", "import sys\r\nimport math\r\ninput = sys.stdin.readline\r\nmod=(10**9)+7\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\na,b,x,y=invr()\r\nh=math.gcd(x,y)\r\nx=x/h\r\ny=y/h\r\nif (x>a or y>b):\r\n print(\"0 0\")\r\nelse:\r\n m=[]\r\n f=min(a//x,b//y)\r\n m.append([x*f,y*f])\r\n f=min(b//x,a//y)\r\n m.append([f*x,y*f])\r\n print(\" \".join(str(int(i)) for i in m[0]))\r\n", "import math\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\na, b, x, y = map(int, input().split())\r\ng = math.gcd(x, y)\r\nx //= g\r\ny //= g\r\nc = min(a // x, b // y)\r\nans = [x * c, y * c]\r\nprint(*ans)", "import math\r\na,b,x,y = map(int,input().split())\r\nd = math.gcd(x,y)\r\nx = x // d\r\ny = y // d\r\nk = min(a // x,b // y)\r\nprint(k * x,k * y)", "from fractions import gcd\r\na, b, x, y = map(int, input().split())\r\ng = gcd(x, y)\r\nx, y, = x // g, y // g\r\nv = min(a // x, b // y)\r\nprint(v * x, v * y)", "import sys\r\nimport math\r\n#from queue import *\r\n#import random\r\n#sys.setrecursionlimit(int(1e6))\r\ninput = sys.stdin.readline\r\n \r\n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inara():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n################################################################\r\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\r\n\r\na,b,x,y=invr()\r\ng=math.gcd(x,y)\r\nx//=g\r\ny//=g\r\n\r\nhi=int(3e9)\r\nlo=0\r\nans=0\r\n\r\nwhile hi>=lo:\r\n\tmid=(hi+lo)//2\r\n\t\r\n\tif mid*x<=a and mid*y<=b:\r\n\t\tans=mid\r\n\t\tlo=mid+1\r\n\telse:\r\n\t\thi=mid-1\r\n\r\nprint(x*ans,y*ans)\r\n", "f=lambda x,y:f(y%x,x)if x else y\r\na,b,x,y=map(int,input().split())\r\nz=f(x,y)\r\nx//=z\r\ny//=z\r\nm=min(a//x,b//y)\r\nprint(m*x,m*y)", "from math import gcd\r\n \r\na, b, x, y = map(int, input().split())\r\nx, y = x // gcd(x, y), y // gcd(x, y)\r\nq = min(a // x, b // y)\r\nprint(x * q, y * q)", "def GCD(x, y): \n \n while(y): \n x, y = y, x % y \n \n return x\nn,m,x,y=map(int,input().split())\nq=GCD(x,y)\nx=x//q\ny=y//q\nn1=n//x\nn11=n1*x\nm1=n1*y\nm2=m//y\nm21=m2*y\nn2=m2*x\nc1=n11*m1\nc2=m21*n2\nc=n*m\n# print(n11,m1,n2,m21,c1,c2,c)\nif c>=c1 and c>=c2:\n if c1>=c2:\n print(n11,m1)\n else:\n print(n2,m21)\nelif c>=c1 and c<c2:\n print(n11,m1)\nelif c<c1 and c>=c2:\n print(n2,m21)\nelse:\n print(0,0)", "import math\r\na,b,c,d=map(int,input().split())\r\nm=math.gcd(c,d)\r\nc=c//m\r\nd=d//m\r\ne=a//c\r\nf=b//d\r\ng=min(e,f)\r\nprint(g*c,g*d)\r\n\r\n\r\n", "import math\r\np,q,r,s=[int(i) for i in input().split()]\r\ng=math.gcd(r,s)\r\nr//=g\r\ns//=g\r\ne=min(p//r,q//s)\r\nprint(e*r,e*s)\r\n", "def gcd(a, b):\r\n if a > b:\r\n a, b = b, a\r\n if b % a==0:\r\n return a\r\n return gcd(b % a, a)\r\n\r\ndef process(a, b, x, y):\r\n g = gcd(x, y)\r\n x = x//g\r\n y = y//g\r\n #a1 = m*x <= a\r\n #b1 = m*y <= b\r\n m = min(a//x, b//y)\r\n return [m*x, m*y]\r\n\r\na, b, x, y = [int(x) for x in input().split()]\r\na1, b1 = process(a, b, x, y)\r\nprint(f'{a1} {b1}')", "def dt(a,b):\r\n while b !=0:\r\n a,b = b, a%b\r\n return a\r\na1,b1,x,y = map(int, input().split())\r\nt = dt(x,y)\r\nx1 = x//t\r\ny1 = y//t\r\nd = min(a1//x1,b1//y1)\r\nprint(\"{} {}\".format(d*x1, d*y1))", "from math import gcd\r\n\r\na,b,x,y=map(int,input().split())\r\n\r\ng=x*y//gcd(x,y)\r\n\r\nOK=0\r\nNG=a*b+1\r\n\r\nfor tests in range(100):\r\n #print(OK,NG)\r\n mid=(OK+NG)/2\r\n if mid/y<=a and mid/x<=b:\r\n OK=mid\r\n else:\r\n NG=mid\r\n\r\nOK=int(OK)\r\n\r\nANS=OK//g*g\r\n\r\nprint(ANS//y,ANS//x)\r\n", "import math\r\na, b, c, d = map(int, input().split())\r\ng = math.gcd(c,d)\r\n\r\nc = c // g\r\nd = d // g\r\ne = min(a // c, b // d)\r\n\r\nprint(e * c, e * d)", "import math\r\na,b,x,y = map(int,input().split())\r\nm = math.gcd(x,y)\r\nx=x//m\r\ny=y//m\r\nif x>a or y>b:\r\n print(0,0)\r\nelif a==x and b>y or b==y and a>x:\r\n print(x,y)\r\nelse:\r\n print(x*min(a//x,b//y),y*min(a//x,b//y))\r\n", "def gcd(a, b): return gcd(b % a, a) if a else b\r\na, b, x, y = map(int, input().split())\r\nd = gcd(x, y)\r\nx, y = x // d, y // d\r\nk = min(a // x, b // y)\r\nprint(k * x, k * y) " ]
{"inputs": ["800 600 4 3", "1920 1200 16 9", "1 1 1 2", "1002105126 227379125 179460772 1295256518", "625166755 843062051 1463070160 1958300154", "248228385 1458744978 824699604 1589655888", "186329049 1221011622 90104472 1769702163", "511020182 242192314 394753578 198572007", "134081812 857875240 82707261 667398699", "721746595 799202881 143676564 380427290", "912724694 1268739154 440710604 387545692", "1103702793 1095784840 788679477 432619528", "548893795 861438648 131329677 177735812", "652586118 1793536161 127888702 397268645", "756278440 578150025 96644319 26752094", "859970763 1510247537 37524734 97452508", "547278097 1977241684 51768282 183174370", "62256611 453071697 240966 206678", "1979767797 878430446 5812753 3794880", "1143276347 1875662241 178868040 116042960", "435954880 1740366589 19415065 185502270", "664035593 983601098 4966148 2852768", "1461963719 350925487 135888396 83344296", "754199095 348965411 161206703 67014029", "166102153 494841162 14166516 76948872", "1243276346 1975662240 38441120 291740200", "535954879 1840366588 26278959 73433046", "764035592 1083601097 1192390 7267738", "1561963718 450925486 475523188 136236856", "854199094 448965410 364102983 125971431", "266102152 594841161 15854566 13392106", "1 1 2 1", "2000000000 2000000000 1 1999999999", "2000000000 2000000000 1999999999 1", "2000000000 2000000000 2 1999999999", "1000000000 1000000000 999999999 2", "2000000000 2000000000 1999999999 2", "2000000000 2000000000 1999999999 1999999998", "2000000000 2000000000 1999999998 1999999999"], "outputs": ["800 600", "1920 1080", "0 0", "0 0", "0 0", "206174901 397413972", "60069648 1179801442", "394753578 198572007", "105411215 850606185", "287353128 760854580", "881421208 775091384", "788679477 432619528", "525318708 710943248", "511554808 1589074580", "676510233 187264658", "562871010 1461787620", "543566961 1923330885", "62169228 53322924", "1342745943 876617280", "1140283755 739773870", "182099920 1739883360", "664032908 381448928", "572153868 350918568", "754119492 313489356", "91096406 494812252", "259477560 1969246350", "535849118 1497358892", "177777265 1083570463", "1561914768 447486816", "853687785 295356745", "266043102 224722482", "0 0", "1 1999999999", "1999999999 1", "2 1999999999", "999999999 2", "1999999999 2", "1999999999 1999999998", "1999999998 1999999999"]}
UNKNOWN
PYTHON3
CODEFORCES
34
1a3833e219a41346e746f849967f9b3c
Meeting
The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle whose sides are parallel to the coordinate axes and whose vertexes are located at the integer points of the plane. At each integer point which belongs to the table perimeter there is a chair in which a general sits. Some points on the plane contain radiators for the generals not to freeze in winter. Each radiator is characterized by the number *r**i* — the radius of the area this radiator can heat. That is, if the distance between some general and the given radiator is less than or equal to *r**i*, than the general feels comfortable and warm. Here distance is defined as Euclidean distance, so the distance between points (*x*1,<=*y*1) and (*x*2,<=*y*2) is Each general who is located outside the radiators' heating area can get sick. Thus, you should bring him a warm blanket. Your task is to count the number of warm blankets you should bring to the Super Duper Secret Place. The generals who are already comfortable do not need a blanket. Also the generals never overheat, ever if they are located in the heating area of several radiators. The radiators can be located at any integer points on the plane, even inside the rectangle (under the table) or on the perimeter (directly under some general). Even in this case their radius does not change. The first input line contains coordinates of two opposite table corners *x**a*, *y**a*, *x**b*, *y**b* (*x**a*<=≠<=*x**b*,<=*y**a*<=≠<=*y**b*). The second line contains integer *n* — the number of radiators (1<=≤<=*n*<=≤<=103). Then *n* lines contain the heaters' coordinates as "*x**i* *y**i* *r**i*", the numbers are separated by spaces. All input data numbers are integers. The absolute value of all coordinates does not exceed 1000, 1<=≤<=*r**i*<=≤<=1000. Several radiators can be located at the same point. Print the only number — the number of blankets you should bring. Sample Input 2 5 4 2 3 3 1 2 5 3 1 1 3 2 5 2 6 3 2 6 2 2 6 5 3 Sample Output 4 0
[ "xa, ya, xb, yb = tuple([int(x) for x in input().split()])\n\nxmax = max(xa, xb)\nxmin = min(xa, xb)\nymax = max(ya, yb)\nymin = min(ya, yb)\n# xa = 1; ya = 2; xb = 10; yb = 20\n\ncoord_dict = dict()\nfor i in range(xmin, xmax+1):\n\tcoord_dict[(i, ymin)] = 1\n\tcoord_dict[(i, ymax)] = 1\nfor i in range(ymin, ymax+1):\n\tcoord_dict[(xmin, i)] = 1\n\tcoord_dict[(xmax, i)] = 1\n\nn = int(input())\n\ndef cdist(x1, y1, x2, y2):\n\treturn ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5\n\nfor _ in range(n):\n\txi, yi, ri = tuple([int(x) for x in input().split()])\n\tfor k in coord_dict.keys():\n\t\tif(cdist(k[0], k[1], xi, yi) <= ri):\n\t\t\tcoord_dict[(k[0], k[1])] = 0\n\nprint(sum(coord_dict.values()))\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nxa, ya, xb, yb = map(int, input().split())\r\nxa, xb = min(xa, xb), max(xa, xb)\r\nya, yb = min(ya, yb), max(ya, yb)\r\nn = int(input())\r\nxyr = [tuple(map(int, input().split())) for _ in range(n)]\r\nans = 0\r\nx, y = xa, ya\r\nu = [xb - xa, yb - ya]\r\nv = [(1, 0), (0, 1), (-1, 0), (0, -1)]\r\nfor i in range(4):\r\n dx, dy = v[i]\r\n for _ in range(u[i % 2]):\r\n f = 0\r\n for x0, y0, r in xyr:\r\n if pow(x0 - x, 2) + pow(y0 - y, 2) <= r * r:\r\n f = 1\r\n break\r\n if not f:\r\n ans += 1\r\n x, y = x + dx, y + dy\r\nprint(ans)", "import sys\r\ninput=sys.stdin.readline\r\nxa,ya,xb,yb=map(int,input().split())\r\nv=[]\r\nblanket=0\r\nheated=0\r\ne=set()\r\nfor j in range(min(xa,xb),max(xa,xb)+1):\r\n for k in range(min(ya,yb),max(ya,yb)+1):\r\n if j < max(xa,xb) and j > min(xa,xb) and k==min(ya,yb) or k==max(ya,yb):\r\n v+=[[j,k]]\r\n elif j==max(xa,xb) or j==min(xa,xb):\r\n v+=[[j,k]]\r\nn=int(input())\r\nx=len(v)\r\nfor i in range(n):\r\n xi,yi,ri=map(int,input().split())\r\n for p in range(len(v)):\r\n if (((xi-v[p][0])**2)+((yi-v[p][1])**2))**0.5 <= ri and p not in e:\r\n e.add(p)\r\nprint(x-len(e))", "import math\r\n\r\n\r\ndef isCovered(general, rads):\r\n for rad in rads:\r\n dist = math.sqrt((general[0] - rad[0]) ** 2 + (general[1] - rad[1]) ** 2)\r\n if rad[2] >= dist:\r\n return True\r\n return False\r\ndef getMax(x, y):\r\n if x > y:\r\n return x\r\n return y\r\ndef getMin(x, y):\r\n if x < y:\r\n return x\r\n return y\r\n\r\n\r\nx1, y1, x2, y2 = input().split()\r\nx1 = int(x1)\r\ny1 = int(y1)\r\nx2 = int(x2)\r\ny2 = int(y2)\r\nlength = abs(x1 - x2)\r\nwidth = abs(y1 - y2)\r\nnumGens = perimeter = 2 * (length + width)\r\nn = int(input())\r\nradiators = []\r\nfor i in range(n):\r\n x, y, r = input().split()\r\n x = int(x)\r\n y = int(y)\r\n r = int(r)\r\n radiators.append((x, y, r))\r\ngenerals = []\r\nfor i in range(getMin(x1, x2), getMax(x1,x2) + 1):\r\n if (i, y1) not in generals:\r\n generals.append((i,y1))\r\n if (i, y2) not in generals:\r\n generals.append((i,y2))\r\nfor j in range(getMin(y1, y2), getMax(y1,y2) + 1):\r\n if (x1, j) not in generals:\r\n generals.append((x1,j))\r\n if (x2, j) not in generals:\r\n generals.append((x2,j))\r\n# print(generals)\r\n# print(radiators)\r\n\r\ncovCount = 0\r\nfor gen in generals:\r\n if isCovered(gen, radiators):\r\n covCount += 1\r\n\r\nprint(numGens - covCount)\r\n", "import sys\r\nimport math\r\n\r\n\r\ndef main():\r\n read = sys.stdin.readline\r\n x_a, y_a, x_b, y_b = (int(i) for i in read().split())\r\n # Generate all points for the generals\r\n generals = set()\r\n min_x = min(x_a, x_b)\r\n max_x = max(x_a, x_b)\r\n min_y = min(y_a, y_b)\r\n max_y = max(y_a, y_b)\r\n # Left vertical\r\n for i in range(min_y, max_y + 1):\r\n generals.add((min_x, i))\r\n # Right vertical\r\n for i in range(min_y, max_y + 1):\r\n generals.add((max_x, i))\r\n\r\n # Top horizontal\r\n for i in range(min_x + 1, max_x):\r\n generals.add((i, max_y))\r\n\r\n # Bottom horizontal\r\n for i in range(min_x + 1, max_x):\r\n generals.add((i, min_y))\r\n\r\n for _ in range(int(read())):\r\n x, y, r = (int(i) for i in read().split())\r\n remove = set()\r\n for general in generals:\r\n distance = math.sqrt(((general[1] - y) ** 2) + ((general[0] - x) ** 2))\r\n if distance <= r:\r\n remove.add(general)\r\n generals = generals - remove\r\n\r\n print(len(generals))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "import math\r\na, b, c, d = map(int, input().split())\r\n\r\nif a > c:\r\n a, c = c, a\r\nif b > d:\r\n b, d = d, b\r\n\r\nn = int(input())\r\nradiators = []\r\nfor i in range(n):\r\n x, y, r = map(int, input().split())\r\n radiators.append([x, y, r])\r\n\r\nres = 0\r\nfor x1 in range(a, c+1):\r\n y_cooordinates = [b, d] if x1 > a and x1 < c else [y_range for y_range in range(b, d+1)]\r\n for y1 in y_cooordinates:\r\n need = True\r\n for x2, y2, dis in radiators:\r\n diff = math.sqrt(((x1 - x2)**2) + ((y1 - y2)**2))\r\n if diff <= dis:\r\n need = False\r\n break\r\n if need:\r\n res += 1\r\nprint(res)\r\n", "import math\r\n\r\n# Read input\r\nxa, ya, xb, yb = map(int, input().split())\r\nn = int(input())\r\n\r\n# Read the coordinates and radii of the radiators\r\nradiators = []\r\nfor _ in range(n):\r\n xi, yi, ri = map(int, input().split())\r\n radiators.append((xi, yi, ri))\r\n\r\nxa,xb = min(xa,xb), max(xa,xb)\r\nya,yb = min(ya,yb), max(ya,yb)\r\n#print(xa,xb,ya,yb)\r\nans = 0\r\nfor i in range(xa,xa+1):\r\n for j in range(ya,yb+1):\r\n found = 0\r\n for k in range(n):\r\n xi, yi, ri = radiators[k]\r\n #print(((xi-i)**2 + (yi-j)**2)**0.5,ri,i,j,xi,yi)\r\n if ((xi-i)**2 + (yi-j)**2)**0.5 <= ri:\r\n found = 1\r\n break\r\n if not found:\r\n #print(i,j)\r\n ans += 1\r\nfor i in range(xb,xb+1):\r\n for j in range(ya,yb+1):\r\n found = 0\r\n for k in range(n):\r\n xi, yi, ri = radiators[k]\r\n #print(((xi-i)**2 + (yi-j)**2)**0.5,ri,i,j,xi,yi)\r\n if ((xi-i)**2 + (yi-j)**2)**0.5 <= ri:\r\n found = 1\r\n break\r\n if not found:\r\n #print(i,j)\r\n ans += 1\r\nfor i in range(xa+1,xb):\r\n for j in range(ya,ya+1):\r\n found = 0\r\n for k in range(n):\r\n xi, yi, ri = radiators[k]\r\n #print(((xi-i)**2 + (yi-j)**2)**0.5,ri,i,j,xi,yi)\r\n if ((xi-i)**2 + (yi-j)**2)**0.5 <= ri:\r\n found = 1\r\n break\r\n if not found:\r\n #print(i,j)\r\n ans += 1\r\nfor i in range(xa+1,xb):\r\n for j in range(yb,yb+1):\r\n found = 0\r\n for k in range(n):\r\n xi, yi, ri = radiators[k]\r\n #print(((xi-i)**2 + (yi-j)**2)**0.5,ri,i,j,xi,yi)\r\n if ((xi-i)**2 + (yi-j)**2)**0.5 <= ri:\r\n found = 1\r\n break\r\n if not found:\r\n #print(i,j)\r\n ans += 1\r\n\r\nprint(ans)\r\n" ]
{"inputs": ["2 5 4 2\n3\n3 1 2\n5 3 1\n1 3 2", "5 2 6 3\n2\n6 2 2\n6 5 3", "-705 595 -702 600\n1\n-589 365 261", "-555 674 -553 774\n5\n-656 128 631\n597 -220 999\n-399 793 155\n-293 -363 1000\n-557 -914 1000", "-210 783 -260 833\n10\n406 551 1000\n372 -373 999\n-12 -532 999\n371 -30 999\n258 480 558\n648 -957 1000\n-716 654 473\n156 813 366\n-870 425 707\n-288 -426 1000", "671 244 771 1000\n20\n701 904 662\n170 -806 1000\n-330 586 1000\n466 467 205\n-736 266 999\n629 734 42\n-616 630 999\n-94 416 765\n-98 280 770\n288 597 384\n-473 266 999\n-330 969 999\n492 -445 713\n352 -967 1000\n401 -340 645\n400 -80 425\n-177 560 848\n361 -7 400\n-564 -807 1000\n621 333 51", "-343 -444 -419 -421\n30\n363 -249 790\n704 57 999\n-316 -305 119\n-778 -543 373\n-589 466 904\n516 -174 893\n-742 -662 390\n-382 825 1000\n520 -732 909\n-220 -985 555\n-39 -697 396\n-701 -882 520\n-105 227 691\n-113 -470 231\n-503 98 525\n236 69 759\n150 393 951\n414 381 1000\n849 530 999\n-357 485 905\n432 -616 794\n123 -465 467\n768 -875 1000\n61 -932 634\n375 -410 718\n-860 -624 477\n49 264 789\n-409 -874 429\n876 -169 999\n-458 345 767", "0 0 1 1\n1\n-1 -1000 1000", "1 1 1000 1000\n1\n50 50 1"], "outputs": ["4", "0", "4", "49", "0", "20", "42", "4", "3996"]}
UNKNOWN
PYTHON3
CODEFORCES
7
1a3944c48c6207815c1e4c534d54831f
Sereja and Table
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. A 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. Can 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? The 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. Print -1, if it is impossible to meet the requirement. Otherwise, print the minimum number of cells which should be changed. Sample Input 5 5 2 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 3 4 1 1 0 0 0 0 1 1 1 1 1 1 0 3 4 1 1 0 0 1 0 1 1 0 1 0 0 1 Sample Output 1 -1 0
[ "from functools import *\r\n \r\nread_line = lambda: [int(i) for i in input().split()]\r\n \r\nn, m, k = read_line()\r\na = [read_line() for i in range(n)]\r\nif n < m:\r\n n, m, a = m, n, zip(*a)\r\n \r\nxs = [reduce(lambda x, b: 2 * x + b, y) for y in a]\r\nminm = lambda a: min(a, m - a)\r\nwork = lambda y: sum(minm(bin(x ^ y).count('1')) for x in xs)\r\nans = min(map(work, xs if m > k else range(1<<m)))\r\n \r\nprint(ans if ans <= k else -1)", "read_line = lambda: [int(i) for i in input().split()]\n\nn, m, k = read_line()\na = [read_line() for i in range(n)]\nif n < m:\n n, m, a = m, n, zip(*a)\n\nxs = []\nfor y in a:\n x = 0\n for b in y:\n x = 2 * x + b\n xs.append(x)\n\ndef work(y):\n tot = 0\n for x in xs:\n c = bin(x ^ y).count('1')\n tot += min(c, m - c)\n return tot\n\nans = min(map(work, xs if m > k else range(1<<m)))\n\nprint(ans if ans <= k else -1)\n", "# Idea is that all rows are either A or B where A flipped = B (same is true for columns)\r\n#\r\n# Thus, either n and m <= k and since max value of k == 10, we can just brute force all A\r\n#\r\n# Or, n or m > k. WLOG say m <= n.\r\n# Then, if A/B is not one of the existing rows, the number of flips to change each row\r\n# is at least 1 and thus total changes is at least m > k, which is impossible.\r\n#\r\n# Thus, if any A/B yields <= k changes, A/B must be one of the exiting rows.\r\n# (WLOG we can assume A is since if B is, we can just swap A and B\r\n# and this doesn't affect the possible values for the rows = {A, B} obviously)\r\n\r\nn, m, k = map(int, input().split())\r\n\r\na = [list(map(int, input().split())) for i in range(n)]\r\n\r\n# In the case of n or m > k, we will be iterating over rows/columns whichever is shorter\r\n# It is easier to iterate over rows, so we transpose if we need to iterate over columns\r\nif m > n:\r\n b = [[0]*n for i in range(m)]\r\n\r\n for i in range(n):\r\n for j in range(m):\r\n b[j][i] = a[i][j]\r\n\r\n a = b\r\n n, m = m, n\r\n\r\n\r\ndef cost_change(common_row):\r\n cost = 0\r\n\r\n for row in a:\r\n diff = 0\r\n\r\n for j, val in enumerate(row):\r\n diff += common_row[j] != val\r\n\r\n cost += min(diff, (m-diff))\r\n\r\n return cost\r\n\r\n\r\nans = k+1\r\n\r\nif n > k:\r\n # row we change to must be a current row (otherwise the cost to change each row must be at least 1, so the total\r\n # cost is at least m > k, which is impossible\r\n\r\n for row in a:\r\n ans = min(ans, cost_change(row))\r\nelse:\r\n # row could be anything\r\n for msk in range(1<<m):\r\n row = [msk>>k&1 for k in range(m)]\r\n\r\n ans = min(ans, cost_change(row))\r\n\r\nprint(-1 if ans == k+1 else ans)\r\n" ]
{"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", "3 4 1\n1 0 0 0\n0 1 1 1\n1 1 1 0", "3 4 1\n1 0 0 1\n0 1 1 0\n1 0 0 1", "8 1 4\n0\n0\n0\n1\n0\n1\n1\n0", "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", "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", "9 2 5\n0 1\n0 1\n1 1\n0 1\n0 1\n1 0\n1 1\n1 0\n1 1", "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", "9 2 10\n1 0\n0 1\n1 0\n1 1\n0 1\n1 0\n1 0\n1 1\n0 1", "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", "4 4 5\n1 0 1 0\n0 1 0 1\n0 1 0 1\n0 1 0 0", "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", "1 9 2\n1 0 1 0 0 0 0 1 0", "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", "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", "1 12 7\n0 0 0 1 0 0 1 1 1 1 0 1", "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", "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", "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", "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", "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", "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", "1 1 1\n1", "2 2 1\n1 1\n1 0", "3 3 1\n1 1 1\n1 0 1\n1 1 0", "3 3 2\n1 1 1\n1 0 1\n1 1 0", "9 9 10\n0 0 0 0 0 0 1 0 0\n1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0\n1 1 1 1 1 1 1 1 1\n1 1 1 0 1 1 1 1 1\n1 1 1 1 1 1 1 1 1\n0 0 0 0 1 0 1 0 0\n0 0 0 0 1 0 0 0 0\n0 0 0 0 1 0 0 0 0", "9 9 10\n0 0 0 0 0 0 1 0 1\n1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 1 0 0\n1 1 1 1 1 0 1 1 1\n1 1 1 0 0 1 1 1 1\n1 1 1 0 1 1 1 1 1\n0 0 1 0 1 0 1 0 0\n0 0 0 0 1 0 0 0 0\n0 0 0 0 1 0 0 0 0", "10 10 10\n1 0 0 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 1 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 1", "10 10 9\n0 0 0 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 1 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 1", "10 10 8\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 1 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 1", "10 10 7\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 1 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 1 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 1", "10 10 6\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 0\n0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 1 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 1", "10 10 1\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 1", "4 4 6\n1 1 1 0\n1 1 0 1\n1 0 1 1\n0 1 1 1", "100 2 10\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n0 1\n0 1\n1 0\n1 0\n0 1\n1 0\n0 1\n0 1\n1 0\n0 1\n0 1\n1 0\n1 0\n1 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n1 0\n0 1\n0 1\n0 1\n0 1\n0 1\n1 0\n0 1\n0 1\n1 0\n1 0\n0 1\n0 1\n0 1\n1 0\n1 0\n0 1\n0 1\n0 1\n0 1\n1 0\n0 1\n1 0\n1 0\n0 1\n1 0\n1 0\n0 1\n0 1\n0 1\n0 1\n0 1\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 1\n0 1\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0\n0 1\n0 1\n0 1\n0 1\n1 0\n1 0\n1 0\n0 1\n1 0\n0 1\n0 1\n0 1\n0 1\n1 0", "5 5 5\n0 1 1 1 1\n1 0 1 1 1\n1 1 0 1 1\n1 1 1 0 1\n1 1 1 1 0", "5 5 10\n1 1 1 1 0\n1 1 1 0 1\n1 1 0 1 1\n1 0 1 1 1\n0 1 1 1 1", "5 5 5\n1 1 1 1 0\n1 1 1 0 1\n1 1 0 1 1\n1 0 1 1 1\n0 1 1 1 1", "4 4 4\n0 1 1 1\n1 0 1 1\n1 1 0 1\n1 1 1 0"], "outputs": ["1", "-1", "0", "0", "6", "5", "3", "0", "2", "0", "1", "4", "0", "-1", "0", "0", "5", "2", "4", "6", "1", "-1", "0", "1", "-1", "2", "6", "-1", "10", "9", "8", "7", "6", "1", "4", "0", "5", "5", "5", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1a542256851fbf03363cd7fffc84c4a0
Bear and Tree Jumps
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of *n* vertices, numbered 1 through *n*. Limak recently learned how to jump. He can jump from a vertex to any vertex within distance at most *k*. For a pair of vertices (*s*,<=*t*) we define *f*(*s*,<=*t*) as the minimum number of jumps Limak needs to get from *s* to *t*. Your task is to find the sum of *f*(*s*,<=*t*) over all pairs of vertices (*s*,<=*t*) such that *s*<=&lt;<=*t*. The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=5) — the number of vertices in the tree and the maximum allowed jump distance respectively. The next *n*<=-<=1 lines describe edges in the tree. The *i*-th of those lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*) — the indices on vertices connected with *i*-th edge. It's guaranteed that the given edges form a tree. Print one integer, denoting the sum of *f*(*s*,<=*t*) over all pairs of vertices (*s*,<=*t*) such that *s*<=&lt;<=*t*. Sample Input 6 2 1 2 1 3 2 4 2 5 4 6 13 3 1 2 3 2 4 2 5 2 3 6 10 6 6 7 6 13 5 8 5 9 9 11 11 12 3 5 2 1 3 1 Sample Output 20 114 3
[ "import sys\r\ninput = sys.stdin.buffer.readline\r\nfrom collections import deque\r\n\r\nn, k = map(int, input().split())\r\ntot_dist = 0\r\nvis = [0]*(n+1)\r\ndist = [[[0]*2 for j in range(k)] for i in range(n+1)]\r\nadj = [[]for i in range(n+1)]\r\nfor i in range(n-1):\r\n u,v = map(int,input().split())\r\n adj[u].append(v)\r\n adj[v].append(u)\r\n\r\ns = deque([1])\r\nwhile s:\r\n c = s[-1]\r\n\r\n if not vis[c]:\r\n vis[c] = 1\r\n for ne in adj[c]:\r\n if not vis[ne]:\r\n s.append(ne)\r\n else:\r\n # update dists via pairing paths at the current node\r\n tot = [0]*k\r\n sum_dist = 0\r\n pairable = 0\r\n for ne in adj[c]:\r\n # direct jumps of exactly k\r\n tot_dist += pairable * sum([dist[ne][i][0] for i in range(k)]) + \\\r\n sum_dist * sum([dist[ne][i][1] for i in range(k)])\r\n # extra from remainder mod k\r\n for i in range(k):\r\n for j in range(k):\r\n tot_dist += (i+j+2+k-1)//k*dist[ne][i][1]*tot[j]\r\n # update pairable nodes\r\n for i in range(k):\r\n tot[i]+= dist[ne][i][1]\r\n pairable += dist[ne][i][1]\r\n sum_dist += dist[ne][i][0]\r\n # update paths\r\n for ne in adj[c]:\r\n for i in range(k):\r\n for j in range(2):\r\n dist[c][i][j] += dist[ne][(i+k-1)%k][j]\r\n dist[c][0][0] += dist[ne][k-1][1]\r\n dist[c][0][1] += 1\r\n # update dists from path directly to current node\r\n for i in range(k):\r\n tot_dist += dist[c][i][0] + (i+k-1)//k * dist[c][i][1]\r\n\r\n s.pop()\r\n\r\nprint(tot_dist)" ]
{"inputs": ["6 2\n1 2\n1 3\n2 4\n2 5\n4 6", "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12", "3 5\n2 1\n3 1", "2 1\n1 2", "2 5\n2 1", "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 7\n12 5\n8 7\n3 10\n10 2", "4 2\n3 4\n2 4\n3 1", "12 3\n5 11\n10 11\n6 4\n8 9\n4 12\n10 7\n4 1\n3 1\n2 12\n9 4\n9 10"], "outputs": ["20", "114", "3", "1", "1", "346", "7", "88"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1aa40a049ab142e496e372c4df124c0a
Perfect Security
Alice has a very important message *M* consisting of some non-negative integers that she wants to keep secret from Eve. Alice knows that the only theoretically secure cipher is one-time pad. Alice generates a random key *K* of the length equal to the message's length. Alice computes the bitwise xor of each element of the message and the key (, where denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)) and stores this encrypted message *A*. Alice is smart. Be like Alice. For example, Alice may have wanted to store a message *M*<==<=(0,<=15,<=9,<=18). She generated a key *K*<==<=(16,<=7,<=6,<=3). The encrypted message is thus *A*<==<=(16,<=8,<=15,<=17). Alice realised that she cannot store the key with the encrypted message. Alice sent her key *K* to Bob and deleted her own copy. Alice is smart. Really, be like Alice. Bob realised that the encrypted message is only secure as long as the key is secret. Bob thus randomly permuted the key before storing it. Bob thinks that this way, even if Eve gets both the encrypted message and the key, she will not be able to read the message. Bob is not smart. Don't be like Bob. In the above example, Bob may have, for instance, selected a permutation (3,<=4,<=1,<=2) and stored the permuted key *P*<==<=(6,<=3,<=16,<=7). One year has passed and Alice wants to decrypt her message. Only now Bob has realised that this is impossible. As he has permuted the key randomly, the message is lost forever. Did we mention that Bob isn't smart? Bob wants to salvage at least some information from the message. Since he is not so smart, he asks for your help. You know the encrypted message *A* and the permuted key *P*. What is the lexicographically smallest message that could have resulted in the given encrypted text? More precisely, for given *A* and *P*, find the lexicographically smallest message *O*, for which there exists a permutation π such that for every *i*. Note that the sequence *S* is lexicographically smaller than the sequence *T*, if there is an index *i* such that *S**i*<=&lt;<=*T**i* and for all *j*<=&lt;<=*i* the condition *S**j*<==<=*T**j* holds. The first line contains a single integer *N* (1<=≤<=*N*<=≤<=300000), the length of the message. The second line contains *N* integers *A*1,<=*A*2,<=...,<=*A**N* (0<=≤<=*A**i*<=&lt;<=230) representing the encrypted message. The third line contains *N* integers *P*1,<=*P*2,<=...,<=*P**N* (0<=≤<=*P**i*<=&lt;<=230) representing the permuted encryption key. Output a single line with *N* integers, the lexicographically smallest possible message *O*. Note that all its elements should be non-negative. Sample Input 3 8 4 13 17 2 7 5 12 7 87 22 11 18 39 9 12 16 10 331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951 226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667 Sample Output 10 3 28 0 14 69 6 44 128965467 243912600 4281110 112029883 223689619 76924724 429589 119397893 613490433 362863284
[ "import math\r\nimport random\r\nimport heapq, bisect\r\nimport sys\r\nfrom collections import deque, defaultdict\r\nfrom fractions import Fraction\r\nimport sys\r\nimport threading\r\nfrom collections import defaultdict\r\n#threading.stack_size(10**8)\r\nmod = 10 ** 9 + 7\r\nmod1 = 998244353\r\n \r\n# ------------------------------warmup----------------------------\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n#sys.setrecursionlimit(300000)\r\n \r\nBUFSIZE = 8192\r\n \r\n \r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n \r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n \r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n \r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n \r\n \r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n \r\n \r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n#-----------------------------------------trie---------------------------------\r\nclass Node:\r\n def __init__(self, data):\r\n self.data = data\r\n self.count=0\r\n self.left = None # left node for 0\r\n self.right = None # right node for 1\r\nclass BinaryTrie:\r\n def __init__(self):\r\n self.root = Node(0)\r\n def insert(self, pre_xor):\r\n self.temp = self.root\r\n for i in range(31, -1, -1):\r\n val = pre_xor & (1 << i)\r\n if val:\r\n if not self.temp.right:\r\n self.temp.right = Node(0)\r\n self.temp = self.temp.right\r\n self.temp.count+=1\r\n if not val:\r\n if not self.temp.left:\r\n self.temp.left = Node(0)\r\n self.temp = self.temp.left\r\n self.temp.count += 1\r\n self.temp.data = pre_xor\r\n def query(self, xor):\r\n self.temp = self.root\r\n for i in range(31, -1, -1):\r\n val = xor & (1 << i)\r\n if not val:\r\n if self.temp.left and self.temp.left.count>0:\r\n self.temp = self.temp.left\r\n elif self.temp.right:\r\n self.temp = self.temp.right\r\n else:\r\n if self.temp.right and self.temp.right.count>0:\r\n self.temp = self.temp.right\r\n elif self.temp.left:\r\n self.temp = self.temp.left\r\n self.temp.count-=1\r\n return xor ^ self.temp.data\r\n#-------------------------bin trie--------------------------------\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\ns=BinaryTrie()\r\nfor i in b:\r\n s.insert(i)\r\nfor i in a:\r\n print(s.query(i),end=\" \")", "def add(x):\r\n global tree\r\n now = 0\r\n tree[now][2] += 1\r\n for i in range(29, -1, -1):\r\n bit = (x>>i)&1\r\n if tree[now][bit]==0:\r\n tree[now][bit]=len(tree)\r\n tree.append([0, 0, 0])\r\n now = tree[now][bit]\r\n tree[now][2] += 1\r\n \r\ndef find_min(x):\r\n global tree\r\n now = ans = 0\r\n for i in range(29, -1, -1):\r\n bit = (x>>i)&1\r\n if tree[now][bit] and tree[tree[now][bit]][2]:\r\n now = tree[now][bit]\r\n else:\r\n now = tree[now][bit^1]\r\n ans |= (1<<i)\r\n tree[now][2] -= 1\r\n return ans\r\n \r\ntree = [[0, 0, 0]]\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nlist(map(add, map(int, input().split())))\r\n[print(x, end=' ') for x in list(map(find_min, a))]\r\n", "from sys import stdin\r\ninput=stdin.readline\r\nclass Node:\r\n def __init__(self,data):\r\n self.data=data\r\n self.left=None\r\n self.right=None\r\n self.count=0\r\nclass Trie():\r\n def __init__(self):\r\n self.root=Node(0)\r\n\r\n def insert(self,preXor):\r\n self.temp=self.root\r\n for i in range(31,-1,-1):\r\n val=preXor&(1<<i)\r\n if val:\r\n if not self.temp.right:\r\n self.temp.right=Node(0)\r\n self.temp=self.temp.right\r\n self.temp.count+=1\r\n else:\r\n if not self.temp.left:\r\n self.temp.left=Node(0)\r\n self.temp=self.temp.left\r\n self.temp.count+=1\r\n self.temp.data=preXor\r\n\r\n def query(self,val):\r\n self.temp=self.root\r\n for i in range(31,-1,-1):\r\n active=val&(1<<i)\r\n if active:\r\n if self.temp.right and self.temp.right.count>0:\r\n self.temp=self.temp.right\r\n elif self.temp.left:\r\n self.temp=self.temp.left\r\n else:\r\n if self.temp.left and self.temp.left.count>0:\r\n self.temp=self.temp.left\r\n elif self.temp.right:\r\n self.temp=self.temp.right\r\n self.temp.count-=1\r\n return val^(self.temp.data)\r\n\r\n\r\nn=input()\r\nl1=list(map(int,input().strip().split()))\r\nl2=list(map(int,input().strip().split()))\r\ntrie=Trie()\r\nfor i in l2:\r\n trie.insert(i)\r\nfor i in l1:\r\n print(trie.query(i),end=\" \")\r\n" ]
{"inputs": ["3\n8 4 13\n17 2 7", "5\n12 7 87 22 11\n18 39 9 12 16", "10\n331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951\n226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667", "5\n134 246 57 176 239\n14 83 97 175 187", "10\n241 187 20 18 151 144 238 193 86 63\n18 69 86 91 111 118 124 172 227 253", "4\n0 0 0 0\n0 0 0 0", "4\n5 5 3 3\n5 3 3 7"], "outputs": ["10 3 28", "0 14 69 6 44", "128965467 243912600 4281110 112029883 223689619 76924724 429589 119397893 613490433 362863284", "41 77 55 209 188", "12 23 6 68 116 203 129 132 32 67", "0 0 0 0", "0 2 0 0"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1aae09d59fdc0c4399e58e8469772e31
Equation
You are given an equation: Your task is to find the number of distinct roots of the equation and print all of them in ascending order. The first line contains three integer numbers *A*,<=*B* and *C* (<=-<=105<=≤<=*A*,<=*B*,<=*C*<=≤<=105). Any coefficient may be equal to 0. In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point. Sample Input 1 -5 6 Sample Output 2 2.0000000000 3.0000000000
[ "import math\r\na, b, c = map(int, input().split())\r\nd = 0\r\nif a == 0 and b == 0 and c == 0:\r\n print(-1)\r\n exit()\r\nif a == 0 and b == 0:\r\n print(0)\r\n exit()\r\nif a == 0:\r\n d -= c\r\n d /= b\r\n print(1)\r\n if d == -0:\r\n d = 0\r\n print(d)\r\n exit()\r\nd = b * b - (4 * a * c)\r\nif d < 0:\r\n print(0)\r\n exit()\r\nif d == 0:\r\n print(1)\r\n d -= b\r\n d /= 2 * a\r\n print(d)\r\n exit()\r\nif d > 0:\r\n print(2)\r\n q = -b + math.sqrt(d)\r\n q /= 2 * a\r\n w = -b - math.sqrt(d)\r\n w /= 2 * a\r\n if q > w:\r\n q, w = w, q\r\n print(q)\r\n print(w)\r\n exit()", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Jun 16 03:38:40 2018\r\n\r\n@author: anshul\r\n\"\"\"\r\nfrom math import sqrt\r\n\r\na,b,c=list(map(int,input().split()))\r\nif a==0 and b==0 and c==0:\r\n print(-1)\r\nelif a==0 and b==0:\r\n print(0)\r\nelif a==0:\r\n print(1)\r\n ans=(-1*c)/b\r\n print(ans)\r\nelse:\r\n d = b*b - 4*a*c\r\n if d<0:\r\n print(0)\r\n elif d>0:\r\n print(2)\r\n d=sqrt(d)\r\n ans1=(-b-d)/(2*a)\r\n ans2=(-b+d)/(2*a)\r\n if ans1<ans2:\r\n ans1,ans2=ans2,ans1\r\n print(ans2)\r\n print(ans1)\r\n else:\r\n print(1)\r\n ans=(-b)/(2*a)\r\n print(ans)", "from math import sqrt\r\na,b,c=map(int,input().split())\r\nif a==0:\r\n if b==0:\r\n print(-1 if c==0 else 0)\r\n else:\r\n print(1)\r\n print((c/b)*(-1))\r\nelse:\r\n d=b*b-4*a*c\r\n if d<0:\r\n print(0)\r\n elif d==0:\r\n print(1)\r\n print((b/a)*(1/2)*(-1))\r\n else:\r\n print(2)\r\n a1=((-1)*b+sqrt(d))/(2*a)\r\n a2=((-1)*b-sqrt(d))/(2*a)\r\n print(min(a1,a2))\r\n print(max(a1,a2))", "import math\r\n\r\n# Read the input coefficients\r\na, b, c = map(int, input().split())\r\n\r\nif a < 0:\r\n b = -b\r\n c = -c\r\n a = -a\r\n\r\nd = b*b - 4*a*c\r\n\r\nif a == 0:\r\n if b == 0:\r\n if c == 0:\r\n print(-1)\r\n else:\r\n print(0)\r\n else:\r\n print(1)\r\n print(\"{:.7f}\".format(-c*1.0/b))\r\nelif d == 0:\r\n print(1)\r\n print(\"{:.7f}\".format(-b/(2*a)))\r\nelif d > 0:\r\n print(2)\r\n print(\"{:.7f}\".format((-b-math.sqrt(d))/(2*a)))\r\n print(\"{:.7f}\".format((-b+math.sqrt(d))/(2*a)))\r\nelse:\r\n print(0)", "import math\r\n\r\na, b, c = map(int, input().split())\r\n\r\nif a == 0:\r\n if b == 0:\r\n if c == 0:\r\n print(\"-1\") \r\n else:\r\n print(\"0\") \r\n else:\r\n x = -c / b\r\n print(\"1\")\r\n print(\"{:.10f}\".format(x))\r\nelse:\r\n delta = b**2 - 4*a*c\r\n if delta < 0:\r\n print(\"0\") \r\n elif delta == 0:\r\n x = -b / (2*a)\r\n print(\"1\")\r\n print(\"{:.10f}\".format(x))\r\n else:\r\n x1 = (-b - math.sqrt(delta)) / (2*a)\r\n x2 = (-b + math.sqrt(delta)) / (2*a)\r\n print(\"2\")\r\n print(\"{:.10f}\".format(min(x1, x2)))\r\n print(\"{:.10f}\".format(max(x1, x2)))", "from math import sqrt\n\na, b, c = map(int, input().split())\ndisc = b * b - 4 * a * c\n\nif a == 0 and b == 0 and c == 0:\n print(-1)\nelif a == 0 and b == 0 or disc < 0:\n print(0)\nelif a == 0:\n print(1)\n # y = bx + c\n # -c / b\n print(-c / b)\nelif disc == 0:\n print(1)\n print(-b / 2 / a)\nelse:\n print(2)\n res = [(-b - sqrt(disc)) / (2.0 * a), (-b + sqrt(disc)) / (2.0 * a)]\n res.sort()\n print('{:7f}'.format(res[0]))\n print('{:7f}'.format(res[1]))\n", "#https://codeforces.com/problemset/problem/20/B\r\ndef main():\r\n a, b, c = map(int, input().split())\r\n d = b ** 2 - 4 * a * c\r\n if a == 0 and b == 0 and c == 0:\r\n print(-1)\r\n elif a == 0 and b == 0:\r\n print(0)\r\n elif a == 0:\r\n print(1)\r\n print(-c / b)\r\n elif d < 0:\r\n print(0)\r\n elif d == 0:\r\n print(1)\r\n print(-b / (2 * a))\r\n else:\r\n print(2)\r\n b = b / a\r\n d = d / (a ** 2)\r\n print((-b - d ** 0.5) / 2)\r\n print((-b + d ** 0.5) / 2)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "a,b,c=map(int,input().split())\r\nt=[1,-c/b]if b else[-(c==0)]\r\nif a:\r\n d,x=b*b-4*a*c, -2*a\r\n if d: t=[0]if d<0 else[2]+sorted([(b-d**0.5)/x,(b+d**0.5)/x])\r\n else: t=[1,b/x]\r\nprint(*t)\r\n", "a, b, c = map(int, input().split(\" \"))\r\nd = b * b - 4 * a * c\r\nif not a:\r\n if not b:\r\n if not c: print(-1)\r\n else: print(0)\r\n else: print(1) or print(-c/b)\r\nelse:\r\n if d < 0: print(0)\r\n elif not d: print(1) or print((-b + d ** 0.5) / 2 / a)\r\n else: print(2) or print(min((-b - d ** 0.5) / 2 / a, (-b + d ** 0.5) / 2 / a)) or print(max((-b - d ** 0.5) / 2 / a, (-b + d ** 0.5) / 2 / a))", "# -*- coding: utf-8 -*-\n\"\"\"Untitled2.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/17BZ7HVotHLIQKVge6uuANF1soACJs9-Y\n\"\"\"\n\na,b,c=map(int,input().split())\nt=[1,-c/b]if b else[-(c==0)]\nif a:\n d,x=b*b-4*a*c, -2*a\n if d: t=[0]if d<0 else[2]+sorted([(b-d**0.5)/x,(b+d**0.5)/x])\n else: t=[1,b/x]\nprint(*t)", "import math\n\na, b, c = map(int, input().split())\n\nif a == b == c == 0:\n print(\"-1\")\n exit()\n\nif a == 0:\n if b == 0:\n if c == 0:\n print(\"-1\")\n else:\n print(\"0\")\n else:\n x = -c / b\n print(\"1\")\n print(\"{:.5f}\".format(x))\n exit()\n\ndiscriminant = b**2 - 4*a*c\n\nif discriminant < 0:\n print(\"0\")\n exit()\n\nif discriminant == 0:\n x = -b / (2*a)\n print(\"1\")\n print(\"{:.5f}\".format(x))\nelse:\n x1 = (-b + math.sqrt(discriminant)) / (2*a)\n x2 = (-b - math.sqrt(discriminant)) / (2*a)\n print(\"2\")\n print(\"{:.5f}\".format(min(x1, x2)))\n print(\"{:.5f}\".format(max(x1, x2)))\n\n\t \t \t \t\t\t \t \t \t \t\t \t\t\t\t", "a, b, c = map(int, input().split())\r\nd = b**2-4*a*c\r\nif a==b==c==0:\r\n print('-1')\r\nelif d < 0 or a==b==0 and c != 0:\r\n print('0')\r\nelif a == 0:\r\n print('1')\r\n print(-c / b)\r\nelif d == 0:\r\n print('1')\r\n print((-b)/(2*a))\r\nelif d > 0:\r\n print('2')\r\n if (-b+d**0.5)/(2*a)>(-b-d**0.5)/(2*a):\r\n print((-b-d**0.5)/(2*a))\r\n print((-b+d**0.5)/(2*a))\r\n else:\r\n print((-b+d**0.5)/(2*a))\r\n print((-b-d**0.5)/(2*a))", "from math import sqrt\r\na, b, c = list(map(int,input().strip().split(' ')))\r\nif a == 0:\r\n if b != 0:\r\n print(1)\r\n print(-1 * c/b)\r\n else:\r\n if c == 0:\r\n print(-1)\r\n else:\r\n print(0)\r\nelse:\r\n if b ** 2 == 4 * a * c:\r\n print(1)\r\n print(-1 * b/(2 * a))\r\n elif b ** 2 < 4 * a * c:\r\n print(0)\r\n else:\r\n print(2)\r\n r1 = ((-1 * b) - sqrt(b ** 2 - 4 * a * c))/(2*a)\r\n r2 = ((-1 * b) + sqrt(b ** 2 - 4 * a * c))/(2*a)\r\n if r1 < r2:\r\n print(r1)\r\n print(r2)\r\n else:\r\n print(r2)\r\n print(r1)", "import math\r\n\r\ndef giaiPTBac2(a, b, c):\r\n flag = 0\r\n if a == 0:\r\n if b == 0:\r\n if c == 0:\r\n print(\"-1\") \r\n else: \r\n print(\"0\") \r\n else: # b!=0\r\n if c == 0:\r\n flag+=1\r\n print(flag)\r\n print(\"0\")\r\n else:\r\n flag+=1\r\n print(flag)\r\n print(-c/b)\r\n else: # a!=0\r\n delta = b * b - 4 * a * c;\r\n if (delta > 0):\r\n flag+=1\r\n x1 = (float)((-b + math.sqrt(delta)) / (2 * a))\r\n flag+=1\r\n x2 = (float)((-b - math.sqrt(delta)) / (2 * a))\r\n if x1>x2:\r\n print(flag)\r\n print(x2)\r\n print(x1)\r\n else:\r\n print(flag)\r\n print(x1)\r\n print(x2)\r\n elif (delta == 0):\r\n flag+=1\r\n x1 = (-b / (2 * a));\r\n print(flag)\r\n print(x1)\r\n else:\r\n print(\"0\");\r\n \r\na,b,c = map(float,input().split());\r\ngiaiPTBac2(a, b, c)", "import math\r\na,b,c=map(int,input().split())\r\nif a:\r\n if b*b-4*a*c>0:\r\n print(2)\r\n print(min((-b-math.sqrt(b*b-4*a*c))/2/a,(-b+math.sqrt(b*b-4*a*c))/2/a))\r\n print(max((-b-math.sqrt(b*b-4*a*c))/2/a,(-b+math.sqrt(b*b-4*a*c))/2/a))\r\n elif b*b-4*a*c==0:\r\n print(1)\r\n print(round(-b/2/a,5))\r\n else:\r\n print(0)\r\nelif b:\r\n print(1)\r\n print(-c/b)\r\nelse:\r\n print(0 if c else -1)\r\n ", "a,b,c = list(map(int,input().split()))\r\nif a!=0:\r\n k = (b*b) - 4*a*c\r\n if k<0:\r\n print(0)\r\n else:\r\n a1 = (-b+(k**.5))/(2*a)\r\n a2 = (-b-(k**.5))/(2*a)\r\n if a1==a2:\r\n print(1)\r\n print(str(a1)+\"0\"*5)\r\n if a1!=a2:\r\n print(2)\r\n print(str(min(a1,a2))+\"0\"*5)\r\n print(str(max(a1,a2))+\"0\"*5)\r\nelse:\r\n if b!=0:\r\n k = str((-c)/b)\r\n print(1)\r\n print(k+\"0\"*5)\r\n else:\r\n if c==0:\r\n print(-1)\r\n else:\r\n print(0)\r\n", "a, b, c = map(int, input().split())\r\n\r\nif a==0:\r\n\tif b==0:\r\n\t\tif c==0:\r\n\t\t\tprint(-1)\r\n\t\telse:\r\n\t\t\tprint(0)\r\n\telse:\r\n\t\tprint(1)\r\n\t\tprint(-c/b)\r\nelse:\r\n\tD = b*b - 4*a*c\r\n\tif D < 0:\r\n\t\tprint(0)\r\n\telif D == 0:\r\n\t\tprint(1)\r\n\t\tprint(-b/(2*a))\r\n\telse:\r\n\t\tx1 = (-b-D**0.5)/(2*a)\r\n\t\tx2 = (-b+D**0.5)/(2*a)\r\n\t\tprint(2)\r\n\t\tprint(min(x1, x2))\r\n\t\tprint(max(x1, x2))", "A,B,C = map(int,input().split())\r\nimport math\r\nD = B * B - 4 * A * C\r\n\r\nif A == 0 and B == 0 and C == 0:\r\n print(-1)\r\n\r\nelif A == 0 and B == 0:\r\n print(0) \r\n\r\nelif A == 0:\r\n x = - C / B\r\n print(1)\r\n print('%4.5f' % x)\r\n \r\nelif D < 0:\r\n print(0)\r\n\r\nelif D > 0:\r\n x1 = (- B + math.sqrt(D)) / (2 * A)\r\n x2 = (- B - math.sqrt(D)) / (2 * A)\r\n x1, x2 = (x1, x2) if x1 < x2 else (x2, x1)\r\n \r\n a = '%4.5f' % x1\r\n b = '%4.5f' % x2\r\n print(2)\r\n print(a)\r\n print(b)\r\n \r\nelif D == 0:\r\n x = - B / (2 * A)\r\n print(1)\r\n print('%4.5f' % x)", "a,b,c=list(map(float,input().split()))\r\nif a==0 and b==0 and c==0: print(-1)\r\nelif a==0 and b==0 and c!=0: print(0)\r\nelif a==0: \r\n print(1)\r\n print(-c/b)\r\nelif b*b-4*a*c<0: print(0)\r\nelse:\r\n a1,a2=(-b+(b*b-a*4*c)**0.5)/(2*a),(-b-(b*b-a*4*c)**0.5)/(2*a)\r\n if a1==a2:\r\n print(1)\r\n print('{0:.5f}'.format(a1))\r\n else: \r\n print(2)\r\n print('{0:.6f}'.format(min(a1,a2)))\r\n print('{0:.6f}'.format(max(a1,a2)))", "a,b,c=map(int,input().split())\r\nif a==0 and b==0 and c==0: print(-1)\r\nelif a==0 and b==0: print(0)\r\nelif a==0:\r\n\tprint(1)\r\n\tprint(-c/b)\r\nelse:\r\n\tx=b**2-1*4*a*c\r\n\tif x<0:\r\n\t\tprint(0)\r\n\telif x==0:\r\n\t\tprint(1)\r\n\t\tprint(-b/(2*a))\r\n\telse:\r\n\t\tl=[]\r\n\t\tl.append((-1*b-x**0.5)/(2*a))\r\n\t\tl.append((-1*b+x**0.5)/(2*a))\r\n\t\tl.sort()\r\n\t\tprint(2)\r\n\t\tprint(l[0])\r\n\t\tprint(l[-1])", "from math import *\na,b,c = input().split()\na,b,c = int(a),int(b),int(c)\nd_2 = (b**2) - (4 * a * c)\nif d_2 < 0:\n print(\"0\")\nelif a == 0 and b == 0:\n if c == 0:print(\"-1\")\n else:print('0')\nelif a == 0 and b != 0:\n print(\"1\")\n x_1 = -(float(c)/float(b))\n print(\"%.10f\" % x_1)\nelse:\n if d_2 == 0:\n print('1')\n print('%.10f' % (-b/(2*a)))\n exit()\n print(\"2\")\n x_small = float((-float(b) - sqrt(d_2)))/float(2 * a)\n x_big = float((-float(b) + sqrt(d_2)))/float(2 * a)\n print(\"%.10f\" % min(x_small,x_big) + '\\n' + \"%.10f\" % max(x_big,x_small))\n\n", "import math\r\n\r\na, b, c = list(map(int, input().split()))\r\n# -b+-sqrt(b^2-4ac)/2a\r\n\r\nd = (b*b-4*a*c)\r\n\r\nans = 'a'\r\nans2 = 'a'\r\n\r\nif (d<0):\r\n ans = 'n'\r\nelif (a==0 and b ==0 and c==0):\r\n ans='a'\r\nelif (a==0 and b==0):\r\n ans = 'n'\r\nelif (a==0):\r\n ans = -c/b\r\nelse:\r\n ans = float(-b+float(b*b-4*a*c)**0.5)/float(2*a)\r\n ans2 = float(-b-float(b*b-4*a*c)**0.5)/float(2*a)\r\n\r\nif (ans=='a'):\r\n print(-1)\r\nelif (ans=='n'):\r\n print(0)\r\nelif (ans2=='a' or ans==ans2):\r\n print(1)\r\n print(format(ans, '.6f'))\r\nelse:\r\n print(2)\r\n if (ans>ans2):\r\n print(format(ans2, '.6f'))\r\n print(format(ans, '.6f'))\r\n else:\r\n print(format(ans, '.6f'))\r\n print(format(ans2, '.6f'))", "a,b,c = map(int,input().split())\r\nif a == 0:\r\n if b == 0:\r\n if c == 0:\r\n print(-1)\r\n else:\r\n print(0)\r\n else:\r\n print(1)\r\n print(-c/b)\r\nelse:\r\n delta = b**2-4*a*c\r\n if delta<0:\r\n print(0)\r\n elif delta == 0:\r\n print(1)\r\n print(-b/(2*a))\r\n else:\r\n print(2)\r\n if a>0:\r\n print((-b-delta**0.5)/(2*a))\r\n print((-b+delta**0.5)/(2*a))\r\n else:\r\n print((-b+delta**0.5)/(2*a))\r\n print((-b-delta**0.5)/(2*a))\r\n \r\n ", "a, b, c = map(int, input().split())\r\n \r\nt = [1, -c / b] if b else [-(c == 0)]\r\n \r\nif a:\r\n \r\n d, x = b * b - 4 * a * c, -2 * a\r\n \r\n if d: t = [0] if d < 0 else [2] + sorted([(b - d ** 0.5) / x, (b + d ** 0.5) / x])\r\n \r\n else: t = [1, b / x]\r\n \r\nprint(*t)", "import math\r\ncoefficients=input().split()\r\na=int(coefficients[0])\r\nb=int(coefficients[1])\r\nc=int(coefficients[2])\r\nif (a==0 and b==0 and c==0):\r\n print(-1)\r\nelif (b**2)-4*a*c<0 or (a==0 and b==0):\r\n print(0)\r\nelif a==0:\r\n print(1)\r\n print(\"%.10f\"%(-c/b))\r\nelse:\r\n root1=(-b-math.sqrt((b**2)-4*a*c))/(2*a)\r\n root2=(-b+math.sqrt((b**2)-4*a*c))/(2*a)\r\n min_root=min(root1,root2)\r\n max_root=max(root1,root2)\r\n if (b**2)-4*a*c==0:\r\n print(1)\r\n print(\"%.10f\"%root1)\r\n else:\r\n print(2)\r\n print(\"%.10f\"%min_root)\r\n print(\"%.10f\"%max_root)\r\n", "a,b,c=list(map(int,input().split()))\r\nif a==0 and b==0 and c==0:\r\n print(-1)\r\nelif a==0 and b==0:\r\n print(0)\r\nelif a==0 and c==0:\r\n print(1)\r\n print(0)\r\nelif b==0 and c==0:\r\n print(1)\r\n print(0)\r\nelif a==0:\r\n print(1)\r\n print(-c/b)\r\nelse:\r\n if (b**2)-(4*a*c)>0:\r\n print(2)\r\n print(min((-b-((b**2)-(4*a*c))**0.5)/(2*a),(-b+((b**2)-(4*a*c))**0.5)/(2*a)))\r\n print(max((-b-((b**2)-(4*a*c))**0.5)/(2*a),(-b+((b**2)-(4*a*c))**0.5)/(2*a)))\r\n elif (b**2)-(4*a*c)==0:\r\n print(1)\r\n print(-b/(2*a))\r\n else:\r\n print(0)", "# LUOGU_RID: 101918539\nfrom decimal import *\r\na, b, c = map(Decimal, input().split())\r\nd = b * b - 4 * a * c\r\nif a == b == c == 0:\r\n print(-1)\r\nelif a == b == 0:\r\n print(0)\r\nelif a == 0:\r\n print(1, -c / b, sep='\\n')\r\nelif d > 0:\r\n e, f = (-b - d.sqrt()) / 2 / a, (-b + d.sqrt()) / 2 / a\r\n print(2, min(e, f), max(e, f), sep='\\n')\r\nelif d == 0:\r\n print(1, -b / 2 / a, sep='\\n')\r\nelse:\r\n print(0)\r\n", "from math import *\n\na, b, c = map(int, input().split())\n\nif a < 0:\n b = -b\n c = -c\n a = -a\n\ndelta = b*b - 4*a*c\n\nif a == 0:\n if b == 0:\n if c == 0:\n print(-1)\n else:\n print(0)\n else:\n print(1)\n print(\"%.5f\" % (-c*1.0/b))\nelif delta == 0:\n print(1)\n print(\"%.5f\" % (-b/(2*a)))\nelif delta > 0:\n print(2)\n print(\"%.5f\" % ((-b-sqrt(delta))/(2*a)))\n print(\"%.5f\" % ((-b+sqrt(delta))/(2*a)))\nelse:\n print(0)\n\t \t\t\t \t \t\t\t \t \t\t", "import math\r\na,b,c = list(map(int, input().split()))\r\nif a==b==c==0:print(-1)\r\nelif b*b - 4*a*c<0 or a==b==0:print(0)\r\nelif a==0:print(1);print(format((-c/b),'.6f'))\r\nelif b*b-4*a*c==0:\r\n d = math.sqrt(b*b-4*a*c)\r\n print(1)\r\n print(format(-b/(2*a),'.6f'))\r\nelse:\r\n d = math.sqrt(b*b-4*a*c)\r\n print(2)\r\n if a>0:\r\n print(format((-b-d)/(2*a),'.6f'))\r\n print(format((-b+d)/(2*a),'.6f'))\r\n else:\r\n print(format((-b+d)/(2*a),'.6f'))\r\n print(format((-b-d)/(2*a),'.6f'))", "import math\r\nA,B,C = map(int,input().split())\r\nD=B*B-4*A*C\r\n \r\nif A==0 and B==0 and C==0:\r\n print(-1)\r\n \r\nelif A==0 and B==0:\r\n print(0) \r\n \r\nelif A==0:\r\n x=-C/B\r\n print(1)\r\n print('%5.5f'%x)\r\n \r\nelif D<0:\r\n print(0)\r\n \r\nelif D>0:\r\n print(2)\r\n x1=(-B+math.sqrt(D))/(2*A)\r\n x2=(-B-math.sqrt(D))/(2*A)\r\n if x1 < x2:\r\n print(\"%5.5f\" % x1)\r\n print(\"%5.5f\" % x2)\r\n else:\r\n print(\"%5.5f\" % x2)\r\n print(\"%5.5f\" % x1)\r\n \"\"\"vyvodx1='%5.5f'%x1\r\n vyvodx2='%5.5f'%x2\"\"\"\r\n \r\n \"\"\"print(vyvodx1)\r\n print(vyvodx2)\"\"\"\r\n \r\nelif D==0:\r\n x=-B/(2*A)\r\n print(1)\r\n print('%5.5f'%x)\r\n \r\n", "a, b, c = map(int,input().split())\r\nd = b**2 - 4*a*c\r\nif a == 0 and b == 0 and c == 0:\r\n print(-1)\r\nelif a == 0 and b == 0:\r\n print(0)\r\nelif a == 0:\r\n print(1)\r\n print(-c/b)\r\nelif d < 0:\r\n print(0)\r\nelif d == 0:\r\n print(1)\r\n print(-b / (2 * a))\r\nelse:\r\n print(2)\r\n b = b / a\r\n d = d / (a**2)\r\n print((-b - d**0.5)/2)\r\n print((-b + d**0.5)/2)", "import sys\r\nimport collections \r\nimport random\r\nsys.setrecursionlimit(30000)\r\n\r\ndef main():\r\n a,b,c = [float(it) for it in input().split()]\r\n if a == 0:\r\n if b == 0:\r\n if c == 0:\r\n sys.stdout.write('-1 \\n')\r\n else:\r\n sys.stdout.write('0 \\n')\r\n else:\r\n x = ((c/b) * (-1.0))\r\n ## 0 2 0 -> -0.0 ???\r\n if x == -0.0:\r\n x = 0.0\r\n sys.stdout.write('1 \\n%.5f \\n'% x)\r\n elif a != 0:\r\n d = b*b - 4*a*c\r\n if d < 0:\r\n ## There is complex roots\r\n sys.stdout.write('0\\n')\r\n elif d == 0:\r\n ## There is one root\r\n x = -b/2/a\r\n sys.stdout.write('1 \\n%.5f \\n'% x)\r\n elif d > 0:\r\n ## There is two roots\r\n x1 = (-b + d**0.5)/2/a\r\n x2 = (-b - d**0.5)/2/a\r\n if x1 > x2:\r\n x1,x2 = x2,x1\r\n sys.stdout.write('2 \\n%.5f \\n%.5f \\n'% (x1,x2))\r\n \r\nif __name__ == \"__main__\":\r\n ##sys.stdin = open('f.in','r')\r\n ##sys.stdout = open('f.out','w')\r\n main()\r\n ##sys.stdin.close()\r\n ##sys.stdout.close()", "a, b, c = list(map(int, input().split()))\r\n\r\nif a == 0 and b == 0 and c == 0:\r\n print(-1)\r\nelif (b*b)<4*a*c:\r\n print(0)\r\nelif a == 0:\r\n if b == 0:\r\n print(0)\r\n else:\r\n print(1)\r\n print(\"{0:.5f}\".format(-(c/b)))\r\nelse:\r\n d = ((b*b) - 4*a*c)\r\n x1 = (-b + (d**0.5))/(2*a)\r\n x2 = (-b - (d**0.5))/(2*a)\r\n if x1 == x2:\r\n print(1)\r\n print(\"{0:.5f}\".format(x1))\r\n else:\r\n print(2)\r\n print(\"{0:.5f}\".format(min(x1, x2)))\r\n print(\"{0:.5f}\".format(max(x1, x2)))\r\n \r\n \r\n", "import math\r\n\r\ndef solve_const(x):\r\n\tif(x == 0):\r\n\t\tprint(-1)\r\n\telse:\r\n\t\tprint(0)\r\n\r\ndef solve_lineal(x, y):\r\n\tif(y == 0):\r\n\t\t#yt = 0 => t = 0\r\n\t\tprint(1)\r\n\t\tprint(0)\r\n\telse:\r\n\t\t#xt + y = 0 => t = -y/x\r\n\t\tprint(1)\r\n\t\tprint(-y / x)\r\n\r\ndef solve_square(x, y, z):\r\n\td = y * y - 4 * x * z\r\n\tif(d < 0):\r\n\t\tprint(0)\r\n\telif(d > 0):\r\n\t\tprint(2)\r\n\t\tx1 = (-y + math.sqrt(d)) / (2 * x)\r\n\t\tx2 = (-y - math.sqrt(d)) / (2 * x)\r\n\t\tprint(min(x1, x2))\r\n\t\tprint(max(x1, x2))\r\n\telse:\r\n\t\tprint(1)\r\n\t\tprint((-y) / (2 * x))\r\n\t\t\r\na, b, c = map(int, input().split())\r\n\r\nif(a == 0):\r\n\tif(b == 0):\r\n\t\tsolve_const(c)\r\n\telse:\r\n\t\tsolve_lineal(b, c)\r\nelse:\r\n\tsolve_square(a, b, c)", "a, b, c = map(int, input().split())\r\nch1, ch2, ch3 = (a == 0), (b == 0), (c == 0)\r\nif ch1 and ch2 and ch3:\r\n answer = -1\r\nelif ch1 and ch2:\r\n answer = 0\r\nelif (ch1 and ch3) or (ch2 and ch3):\r\n answer = 1\r\n answers = [0]\r\nelif ch1:\r\n answer = 1\r\n answers = [-c/b]\r\nelif ch2:\r\n if -c/a > 0:\r\n answer = 2\r\n answers = [-(-c/a)**0.5, (-c/a)**0.5]\r\n else:\r\n answer = 0\r\nelif ch3:\r\n answer = 2\r\n answers = [-b/a, 0]\r\nelse:\r\n D = b**2 - 4*a*c\r\n if D > 0:\r\n answer = 2\r\n answers = [(-b+D**0.5)/(2*a), (-b-D**0.5)/(2*a)]\r\n elif D == 0:\r\n answer = 1\r\n answers = [-b/(2*a)]\r\n else:\r\n answer = 0\r\nprint(answer)\r\nif answer > 0:\r\n for i in sorted(answers):\r\n print(i)\r\n", "a, b, c = [int(w) for w in input().split()]\n\nif a == b == c == 0:\n print(-1)\n exit(0)\n\nif a == b == 0 or b * b < 4 * a * c:\n print(0)\n exit(0)\n\nif a == 0:\n print(1)\n print(- c / b)\n exit(0)\n\nif b * b == 4 * a * c:\n print(1)\n print(- b / 2 / a)\n exit(0)\n\nprint(2)\nresult = [(- b - (b * b - a * c * 4) ** 0.5)/ 2 / a, (- b + (b * b - a * c * 4) ** 0.5)/ 2 / a]\nresult.sort()\nprint(*result)\n\n\n" ]
{"inputs": ["1 -5 6", "1 1 1", "1 2 1", "0 0 0", "0 -2 1", "0 -2 0", "0 0 1", "0 0 -100000", "0 10000 -100000", "1 100000 -100000", "0 3431 43123", "100 200 100", "50000 100000 50000", "-1 10 20", "-50000 100000 -50000", "1 -2 1", "1000 -5000 6000", "0 -100000 0", "1 -100000 0", "1223 -23532 1232", "-1 -2 -1", "1 0 0", "0 1 0", "0 0 1", "0 1 -1", "5 0 5", "-2 -5 0", "-2 -4 0", "-2 0 0", "0 -4 -4", "1 1 0", "1 0 1", "1 1 1", "0 0 0"], "outputs": ["2\n2.0000000000\n3.0000000000", "0", "1\n-1.0000000000", "-1", "1\n0.5000000000", "1\n0.0000000000", "0", "0", "1\n10.0000000000", "2\n-100000.9999900002\n0.9999900002", "1\n-12.5686388808", "1\n-1.0000000000", "1\n-1.0000000000", "2\n-1.7082039325\n11.7082039325", "1\n1.0000000000", "1\n1.0000000000", "2\n2.0000000000\n3.0000000000", "1\n0.0000000000", "2\n0.0000000000\n100000.0000000000", "2\n0.0524974745\n19.1887126645", "1\n-1.0000000000", "1\n0.0000000000", "1\n-0.0000000000", "0", "1\n1.0000000000", "0", "2\n-2.5000000000\n-0.0000000000", "2\n-2.0000000000\n-0.0000000000", "1\n-0.0000000000", "1\n-1.0000000000", "2\n-1.0000000000\n0.0000000000", "0", "0", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
36
1adf051fd4437e5a6984d9c248647615
Drazil and Date
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to positions (*x*<=+<=1,<=*y*), (*x*<=-<=1,<=*y*), (*x*,<=*y*<=+<=1) or (*x*,<=*y*<=-<=1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (*a*,<=*b*) and continue travelling. Luckily, Drazil arrived to the position (*a*,<=*b*) successfully. Drazil said to Varda: "It took me exactly *s* steps to travel from my house to yours". But Varda is confused about his words, she is not sure that it is possible to get from (0,<=0) to (*a*,<=*b*) in exactly *s* steps. Can you find out if it is possible for Varda? You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line. If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes". Sample Input 5 5 11 10 15 25 0 5 1 0 0 2 Sample Output No Yes No Yes
[ "a,b,s=map(int,input().split())\r\nif a<0:\r\n a*=-1\r\nif b<0:\r\n b*=-1\r\nif (s-a-b)%2==0 and (s-a-b)>=0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "x,y,s=[int(i) for i in input().split()]\r\nk=abs(x)+abs(y)\r\nif k<=s:\r\n s-=k\r\n if s%2==0:print('Yes')\r\n else:print('No')\r\nelse:print('No')\r\n", "l1 = [abs(int(x)) for x in input().split()]\r\nif l1[0]+l1[1]!=l1[2]:\r\n if l1[0]+l1[1]>l1[2]:\r\n print(\"NO\")\r\n elif (l1[0]+l1[1]-l1[2])%2:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n\r\n\r\nelse:\r\n print(\"Yes\")", "a, b, s = map(int, input().split())\r\nc = abs(a) + abs(b)\r\nif a == 0 and b == 0 and s % 2 == 0:\r\n print(\"Yes\")\r\nelif c == s:\r\n print(\"Yes\")\r\nelif c > s:\r\n print(\"No\")\r\nelif (c % 2 == 0 and s % 2 == 0) or (c % 2 != 0 and s % 2 != 0) :\r\n print(\"Yes\")\r\n\r\nelse:\r\n print(\"No\")", "a,b,s=map(int,input().split())\r\nif a<0:\r\n a=-1*a\r\nif b<0:\r\n b=-1*b\r\nc=a+b\r\nif s==c:\r\n print(\"YES\")\r\nelif s>c:\r\n if (s-c)%2==0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "# https://codeforces.com/problemset/problem/515/A\n\ndef handle():\n a, b, s = input().split(\" \")\n a = abs(int(a))\n b = abs(int(b))\n s = int(s)\n\n if a + b > s:\n return \"NO\"\n else:\n moves = a + b\n if (s - moves) % 2 == 0:\n return \"YES\"\n return \"NO\"\n\nprint(handle())", "from sys import stdin\r\n\r\ninp = stdin.readline\r\n\r\na, b, s = [int(x) for x in inp().strip().split()]\r\nif s < abs(a)+abs(b):\r\n print (\"no\")\r\nelif (a+b)%2 == 0:\r\n if s%2 == 0:\r\n print(\"yes\")\r\n else:\r\n print(\"no\")\r\nelif (a+b)%2 == 1:\r\n if s%2 == 1:\r\n print(\"yes\")\r\n else:\r\n print(\"no\")", "a,b,s = map(int,input().split())\r\nif ((abs(a)+abs(b))-s)%2 == 0 and (abs(a)+abs(b))<=s:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a,b,s=map(int,input().split());print('YNEOS'[(a+b+s)%2 or abs(a)+abs(b)>s::2])", "a , b ,s = input().split()\r\na = int(a)\r\nb = int(b)\r\ns = int(s)\r\n\r\nnbr = abs(a) + abs(b)\r\n\r\nif nbr <= s and (s-nbr)%2 ==0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")\r\n", "a,b,s=map(int,input().split())\r\n\r\nc=abs(a)+abs(b)\r\nif(c==s):\r\n print('Yes')\r\nelif(s>c):\r\n if((s-c)%2==0):\r\n print('Yes')\r\n else:\r\n print('No')\r\nelse:\r\n print('No')\r\n ", "import sys\r\ninput = sys.stdin.readline\r\n\r\na, b, s = map(int, input().split())\r\nif s < abs(a) + abs(b):\r\n print('No')\r\nelif (abs(a) + abs(b)) % 2 != s % 2:\r\n print('No')\r\nelse:\r\n print('Yes')\r\n", "a,b,s = map(int,input().split())\r\nif (abs(a)+abs(b))%2==0 and s>=(abs(a)+abs(b)) and s%2==0: print('Yes')\r\nelif (abs(a)+abs(b))%2!=0 and s>=(abs(a)+abs(b)) and s%2!=0: print('Yes')\r\nelse: print('No')", "a,b,s = map(int, input().split())\r\nif s >= abs(a) + abs(b) and (a+b)%2== s%2: print(\"Yes\")\r\nelse: print(\"No\")", "n,x,s=map(int,input().rstrip().split());s-=abs(n)+abs(x)\r\nif s>=0 and s%2==0:print(\"YES\")\r\nelse:print(\"NO\")\r\n ", "a, b, s = map(int, input().split())\r\ncnt = abs(a) + abs(b)\r\nif s < cnt:\r\n print(\"No\")\r\nelif (s - cnt) % 2 == 0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a,b,s = map(int,input().split())\ns1 = abs(a)+abs(b)-1\nif s1<=s and s1%2!=s%2:\n print(\"Yes\")\nelse:\n print(\"No\")", "import math\r\na,b,s=map(int,input().split(' '))\r\nbl=False\r\nif(s>=(abs(a)+abs(b))):\r\n v=abs(a)+abs(b)\r\n \r\n if(v%2==0 and s%2==0):\r\n bl=True\r\n if(v%2!=0 and s%2!=0):\r\n bl=True\r\nif(bl):\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")\r\n", "a, b, s = [int(i) for i in input().split(\" \")]\r\nif (abs(a)+abs(b)+s)%2 == 1 or abs(a)+abs(b) > s:\r\n print(\"No\")\r\nelse:\r\n print(\"Yes\")\r\n", "x, y, s = map(int, input().split())\nd = abs(x) + abs(y)\nif s < d:\n print('No')\nelif s % 2 != d % 2:\n print('No')\nelse:\n print('Yes')", "a, b, s = map(int, input().split())\r\n\r\ndistance = abs(a) + abs(b)\r\nparity = distance % 2\r\n\r\nif s < distance:\r\n print(\"No\")\r\n exit()\r\n\r\nif parity == s % 2:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a, b, s = map(int, input().split())\r\nif s < abs(a) + abs(b):\r\n print(\"NO\")\r\nelse:\r\n if (s - (abs(a) + abs(b))) % 2 == 0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "a,b,s=map(int,input().split());a,b=abs(a),abs(b)\r\nif s<(a+b):print('No')\r\nelif (s-(a+b))%2==0 :print('Yes')\r\nelse:print('No')", "a,b,s=map(int,input().split())\r\na=abs(a)\r\nb=abs(b)\r\nif s>=(a+b) and (a+b)%2==s%2:\r\n print('Yes')\r\nelse:\r\n print('No')", "x, y, s = map(int, input().split())\nval = s - (abs(x) + abs(y))\nif val < 0:\n print(\"No\")\nelif val == 0:\n print(\"Yes\")\nelse:\n if val % 2:\n print(\"No\")\n else:\n print(\"Yes\")\n", "a, b, s = map(int, input().split())\r\n\r\nmin_steps = abs(a) + abs(b)\r\n\r\nprint('No' if s < min_steps or (s - min_steps) % 2 != 0 else 'Yes')", "a,b,s=map(int,input().split())\r\nb=abs(b)\r\na=abs(a)\r\nif a+b<=s and (a+b)%2==s%2:\r\n print('Yes')\r\nelse:\r\n print('No')", "a, b, c = map(int, input().split())\r\nif(abs(a)+abs(b)>c):\r\n\tprint(\"No\")\r\nelse:\r\n\tif(abs(a)+abs(b)-c)%2==0:\r\n\t\tprint(\"Yes\")\r\n\telse:\r\n\t\tprint(\"No\")", "a,b,c=map(int,input().split())\r\na=abs(a)\r\nb=abs(b)\r\nprint(\"YES\" if (c-a-b)%2==0 and c>=(a+b) else \"NO\")", "def f(l):\r\n a,b,s = l\r\n a = a if a>=0 else -a\r\n b = b if b>=0 else -b\r\n return s-a-b>=0 and (s-a-b)%2==0\r\n\r\nl = list(map(int,input().split()))\r\nprint('YES' if f(l) else 'NO')\r\n", "def fun(x,y,z):\r\n d=abs(x)+abs(y)\r\n if d>z:\r\n return \"No\"\r\n elif (z-d)%2==0:\r\n return \"Yes\"\r\n else:\r\n return \"No\"\r\nif __name__==\"__main__\":\r\n x,y,z=map(int,input().split(\" \"))\r\n print(fun(x,y,z))", "a,b,s=map(int,input().split())\r\na=abs(a)\r\nb=abs(b)\r\nif s==a+b:\r\n print(\"Yes\")\r\nif s<a+b:\r\n print(\"No\")\r\nif s>a+b:\r\n m=s-(a+b)\r\n if m%2==0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "\r\n\r\ndef main():\r\n a, b, s = map(int, input().strip().split(\" \"))\r\n a = abs(a)\r\n b = abs(b)\r\n if a + b <= s and (s - a -b)%2 == 0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")\r\n\r\nif __name__ == \"__main__\":\r\n main()", "a, b, s = list(map(int, input().split()))\r\nres = 'Yes'\r\nif s < abs(a) + abs(b):\r\n res = 'No'\r\nelse:\r\n if (abs(a) + abs(b) - s) % 2 != 0:\r\n res = 'No'\r\nprint(res)", "a,b,s = map(int,input().split())\na = abs(a)\nb= abs(b)\ns = abs(s)\nif(a+b)>s:\n print(\"No\")\nelif (a+b)%2 == 0 and s%2 == 0:\n print(\"Yes\")\nelif (a+b)%2!=0 and s%2 !=0:\n print(\"Yes\")\nelse:\n print(\"No\")", "ab_s = list(map(int, input().split()))\r\nif (abs(ab_s[0]) + abs(ab_s[1])) <= ab_s[2]:\r\n\tif (ab_s[2] - (abs(ab_s[0]) + abs(ab_s[1]))) % 2 == 0:\r\n\t\tprint('Yes')\r\n\telse:\r\n\t\tprint('No')\r\nelse:\r\n\tprint('No')", "from sys import stdin\r\nfrom collections import defaultdict\r\ninput=lambda:stdin.readline().strip()\r\na,b,s=[int(i) for i in input().split()]\r\nif a<0:\r\n a=(-a)\r\nif b<0:\r\n b=(-b)\r\nd=s-(a+b)\r\nif d%2==0 and d>=0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")\r\n", "a,b,s = map(int,input().split())\r\nsteps = abs(a)+abs(b)\r\nif s>=steps and (s-steps)%2==0:\r\n print(\"Yes\")\r\nelse:\r\n print('No')", "from sys import stdin, stdout\nfrom collections import defaultdict\ndef read():\n\treturn stdin.readline().rstrip()\n\ndef read_int():\n\treturn int(read())\n\ndef read_ints():\n\treturn list(map(int, read().split()))\n\ndef solve():\n\ta,b,c=read_ints()\n\td=abs(a)+abs(b)\n\tif c>=d and (c-d)%2==0:\n\t\tprint(\"Yes\")\n\telse:\n\t\tprint(\"No\")\n\nsolve()\n", "a, b, s = map(int, input().split())\r\ns -= abs(a) + abs(b)\r\nprint('no' if s < 0 or s & 1 else 'yes')", "a,b,c=list(map(int,input().split()))\r\nif((abs(a)+abs(b))>c):\r\n print('NO')\r\nelse:\r\n if((c-(abs(a)+abs(b)))%2==0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "import math\r\n \r\na,b,s=map(int,input().split())\r\nr=abs(a)+abs(b)\r\n\r\nif r%2!=s%2:\r\n print(\"No\")\r\nelif s<r:\r\n print(\"No\")\r\nelse:\r\n print(\"Yes\")", "a, b, n = input().split()\r\n\r\na = abs(int(a))\r\nb = abs(int(b))\r\nn = int(n)\r\nrem = n-a-b\r\nif rem % 2 == 0 and n >= a+b:\r\n print(\"Yes\")\r\nelse:\r\n print(\"NO\")\r\n", "from sys import stdin\r\n\r\ndef readint():\r\n return int(stdin.readline())\r\n\r\n\r\ndef readarray(typ):\r\n return list(map(typ, stdin.readline().split()))\r\n\r\n\r\ndef readmatrix(n,m):\r\n M = []\r\n for _ in range(n):\r\n row = readarray(int)\r\n assert len(row) == m\r\n M.append(row)\r\n return M\r\n\r\n\r\ndef solve():\r\n a, b, s = readarray(int)\r\n a ,b ,s= abs(a) , abs(b) , abs(s)\r\n if a + b == s:\r\n print('Yes')\r\n elif a + b < s:\r\n if (s - (a+b)) %2 == 0:\r\n print('Yes')\r\n else:\r\n print('No')\r\n else:\r\n print('No')\r\n \r\n \r\n \r\nif __name__ == \"__main__\":\r\n T = 1\r\n #T = readint()\r\n for _ in range(T):\r\n solve()\r\n", "a, b, c = (abs(int(x)) for x in input().split());print(\"YES\" if a + b <= c and (c - (a + b)) % 2 == 0 else \"NO\")", "x,y,s = map(int,input().split())\r\nb = abs(x)+ abs(y)\r\nif s >= b:\r\n a = s - b\r\n if a%2 ==0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")\r\nelse:\r\n print(\"No\")", "a, b, s = map(int, input().split())\r\nif(abs(a)+abs(b)>s):\r\n print(\"No\")\r\nelse:\r\n if(abs(a)+abs(b)-s)%2==0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")\r\n", "a,b,s = input().split()\r\n\r\na = int(a)\r\nb = int(b)\r\ns = int(s)\r\n\r\nmin_steps = abs(a) + abs(b)\r\n\r\nif s >= min_steps and (s - min_steps)%2 == 0:\r\n print('Yes')\r\nelse:\r\n print('No')", "a,b,c=map(int,input().split())\r\na=abs(a)\r\nb=abs(b)\r\nif c<(a+b) or (c-a-b)%2!=0:\r\n print('No')\r\nelse :\r\n print('Yes')\r\n", "a,b,s=[int(i) for i in input().split()]\r\nif a<0:\r\n a=a*(-1)\r\nif b<0:\r\n b=b*(-1)\r\nif a==0 and b==0:\r\n if s%2==0:\r\n print('YES')\r\n else:\r\n print('NO')\r\nelse:\r\n tot=a+b\r\n if tot==s:\r\n print('YES')\r\n elif s>tot and (s-tot)%2==0:\r\n print('YES')\r\n else:\r\n print('NO')", "a, b, c = input().split(\" \")\r\n\r\na = abs(int(a))\r\nb = abs(int(b))\r\nc = abs(int(c))\r\n\r\nminsteps = a + b\r\n\r\nif c < minsteps:\r\n print(\"No\")\r\nelif c == minsteps:\r\n print(\"Yes\")\r\nelse:\r\n minsteps = minsteps - c\r\n if minsteps % 2 == 0:\r\n print(\"Yes\")\r\n else :\r\n print(\"NO\")", "def dad(arr):\r\n steps = abs(arr[0]) + abs(arr[1])\r\n k = arr[2] - steps\r\n if k < 0:\r\n return \"No\"\r\n elif k >= 0:\r\n if k%2 == 0:\r\n return \"Yes\"\r\n else:\r\n return \"No\"\r\narr = [int(x) for x in input().split()]\r\nprint(dad(arr))", "def require(a,b,c):\r\n a , b = abs(a), abs(b)\r\n steps = a + b\r\n if(steps == c):\r\n return True\r\n elif(steps < c):\r\n steps = c - steps\r\n if(steps % 2 == 0):\r\n return True\r\n else:\r\n return False\r\n else:\r\n return False\r\n\r\na,b,c = input().split(' ')\r\nif(require(int(a),int(b),int(c))):\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a,b,s=map(int,input().split())\r\np=abs(a)+abs(b)\r\nif(s<p):\r\n print(\"No\")\r\nelse:\r\n if(abs(s-p)%2==0):\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "def manhattan(start_pos, dest_pos):\r\n '''Drazil's move ablity is similar to measuring manhattan distance\r\n from his position to varda's position'''\r\n return sum(abs(e1-e2) for e1, e2 in zip(start_pos, dest_pos))\r\n\r\ndef dated(inputs):\r\n integers = inputs.split(' ')\r\n varda_pos = [int(i) for i in integers]\r\n s = varda_pos.pop(2)\r\n drazil_pos = [0, 0]\r\n # fastest way to get varda in manhattan fashion\r\n step = manhattan(drazil_pos, varda_pos)\r\n # possible additional step is always fasttest step plus 2 steps,\r\n # one for go further, one for back, and keep incrementing by 2\r\n possible_steps = range(step, 2*10**9+1, 2)\r\n if s in possible_steps:\r\n return 'Yes'\r\n return 'No'\r\n\r\n\r\nif __name__ == '__main__':\r\n inputs = input()\r\n print(dated(inputs))", "def main():\r\n a,b,s = map(int, input().split())\r\n if s >= abs(a) + abs(b) and (s - (abs(a) + abs(b))) % 2 == 0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\") \r\nmain()", "a,b,s =map(int,input().split())\r\nx = abs(a) + abs(b)\r\nprint(\"NO\" if s<x or (s-x)%2 else \"YES\")", "a,b,s = [int(i) for i in input().strip().split()]\r\nstps = abs(a)+abs(b)\r\nif stps>s or (s-stps)%2==1:\r\n print(\"No\")\r\nelse:\r\n print(\"Yes\")", "a_b_s = input().split()\r\n\r\nsub = abs(int(a_b_s[2])) - (abs(int(a_b_s[0])) + abs(int(a_b_s[1])))\r\nif sub == 0 or (sub > 0 and sub % 2 == 0):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a,b,s=map(int,input().split())\r\nreq=abs(a)+abs(b)\r\nif s<req:\r\n print(\"No\")\r\nelif s==req:\r\n print(\"Yes\")\r\nelif (s-req)%2==0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a , b , s = list(map(int,input().split()))\r\ncount = abs(a) + abs(b)\r\nif count > s : print(\"NO\")\r\nelif (count - s) % 2 == 0 : print(\"YES\")\r\nelse : print(\"NO\")", "def main():\r\n # input\r\n a, b, s = map(int, input().split())\r\n\r\n # soln\r\n if a < 0:\r\n a = -a\r\n if b < 0:\r\n b = -b\r\n if s >= (a+b) and (s-(a+b))%2 == 0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\nif __name__ == \"__main__\":\r\n main()", "a, b, c = [int(num) for num in input().split()]\na = abs(a)\nb = abs(b)\nif(a + b > c or (a + b) % 2 != c % 2):\n\tprint(\"No\")\nelse:\n\tprint(\"Yes\")", "a,b,s=list(map(int,input().split()))\r\nd=abs(a)+abs(b)\r\nif s>=d and (s-d)%2==0:print(\"Yes\")\r\nelse:print(\"No\")", "x=list(map(int, input().split()))\r\na=abs(x[0])\r\nb=abs(x[1])\r\ns=x[2]\r\nif a+b==s:\r\n print(\"Yes\")\r\nelif a+b>s:\r\n print(\"No\")\r\nelse:\r\n if (s-(a+b))%2==0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "x,y,d= map(int,input().split())\r\nif(abs(x)+abs(y)>d):\r\n print(\"No\")\r\nelif((d-abs(x)-abs(y))%2==0):\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a, b, s = [int(x) for x in input().split()]\r\n\r\nm = s - (abs(a) + abs(b))\r\nif m >= 0:\r\n if m % 2 == 0:\r\n print('Yes')\r\n else:\r\n print('No')\r\nelse:\r\n print('No')\r\n", "\r\nnum_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\na,b,s=map(int,input().split());print('YNEOS'[(a+b+s)%2 or abs(a)+abs(b)>s::2])", "a=input().split()\r\nd=int(a[2])-abs(int(a[0]))-abs(int(a[1]))\r\nif d%2 or d<0:print(\"No\")\r\nelse:print(\"Yes\")", "a,b,n=map(int,input().split())\r\nif abs(a)+abs(b)>n :\r\n print(\"No\")\r\nelif abs(a)+abs(b)<n and (n-abs(a)+abs(b))%2==1:\r\n print(\"No\")\r\nelse:\r\n print(\"Yes\")", "X = input ().split (' ')\r\n \r\nif abs (int (X [0])) + abs (int (X [1])) > int (X [2]):\r\n \r\n print ('No')\r\n \r\nelse:\r\n \r\n if (abs (int (X [0])) + abs (int (X [1])) - int (X [2])) % 2 != 0:\r\n \r\n print ('No')\r\n \r\n else:\r\n \r\n print ('Yes')\r\n", "a,b,s=map(int,input().split())\r\nmin=abs(a)+abs(b)\r\nif s<abs(min) or (s%2!=0 and min%2==0)or (s%2==0 and min%2!=0):\r\n print('no')\r\nelse:\r\n print('YES')", "a,b,s=map(int,input().split())\r\na=abs(a)\r\nb=abs(b)\r\nd=abs(a)+abs(b)\r\ndiff=abs(a+b-s)\r\nif(s<d):\r\n print(\"No\")\r\nelif diff%2==0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "x = [int(i) for i in input().split()]\r\na = x[0]\r\nb = x[1]\r\ns = x[2]\r\nif abs(a) + abs(b) > s :\r\n print(\"no\")\r\nelse :\r\n if (s - abs(a) - abs(b)) % 2 == 0 :\r\n print(\"yes\")\r\n else:\r\n print(\"no\")\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Jan 25 20:53:55 2022\r\n\r\n@author: sachd\r\n\"\"\"\r\ninp=input().split()\r\na=int(inp[0])\r\nb=int(inp[1])\r\ns=int(inp[2])\r\nmin_dist=abs(a)+abs(b)\r\nif s>=min_dist and (s-min_dist)%2==0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")\r\n", "a,b,s = map(int,input().split())\r\nif s >= abs(a)+abs(b) and (s-abs(a)+abs(b)) % 2 == 0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")\r\n", "a, b, s = map(int, input().split())\r\nn = s - (abs(a)+abs(b)) \r\nprint('Yes' if n >= 0 and n%2 == 0 else 'No')", "a,b,s=map(int,input().split())\r\nif abs(a)+abs(b)<=s and (s-a-b)%2==0: print('YES')\r\nelse: print('NO')", "a, b, s = map(int, input().split())\r\ndistance = abs(a) + abs(b)\r\nif distance > s:\r\n print(\"No\")\r\nelif (s - distance) % 2 == 0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a,b,c=map(int,input().split())\r\nx=c-(abs(a)+abs(b))\r\nif x%2==0 and x>=0:\r\n print('Yes')\r\nelse:\r\n print('No')", "a,b,s=map(int,input().split());print('NYOE S'[not (s-abs(a)-abs(b))%2 and s>=abs(a)+abs(b)::2])", "a,b,c = map(int,input().split())\r\nif abs(c)<abs(a)+abs(b):print(\"NO\")\r\nelse:\r\n\tif (abs(a)+abs(b)-abs(c))%2==0:print(\"YES\")\r\n\telse:print(\"NO\")", "a,b,s = map(int, input().split())\r\nprint([\"NO\", \"YES\"][(s >= (abs(a)+abs(b))) and (s-(abs(a) + abs(b)))%2 == 0])", "\r\na,b,s = [abs(int(x)) for x in input().split()]\r\nif a+b<=s and (s-a-b)%2==0:\r\n print('YES')\r\nelse:\r\n print('NO')\r\n\r\n \r\n", "a,b,c=map(int,input().split())\r\nif abs(a)+abs(b)<=c :\r\n if (c-(abs(a)+abs(b)))%2==0 :\r\n print('Yes')\r\n else:\r\n print(\"No\")\r\nelse :\r\n print(\"No\")", "from tkinter.messagebox import YES\r\n\r\n\r\na,b,s=input().split()\r\na=abs(int(a))\r\nb=abs(int(b))\r\ns=int(s)\r\nsum=a+b\r\nk=s-sum\r\nif(k%2==0 and k>=0):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\") \r\n", "a, b, s = map(int, input().split())\r\nif (s - abs(a) - abs(b)) % 2 == 0 and s >= abs(a) + abs(b):\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a, b, s = map(int, input().split())\r\nd = abs(a) + abs(b)\r\nprint('Yes' if d <= s and d % 2 == s % 2 else 'No')\r\n", "a,b,x = map(int,input().split())\r\nt = abs(a)+abs(b)\r\nif x<t:\r\n print(\"No\")\r\nelse:\r\n if (x-t)%2==0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "a,b,s=map(int,input().split())\r\ns-=abs(a)+abs(b)\r\nprint(['No','Yes'][s>=0 and s%2==0])", "a, b, s = map(int, input().split())\r\nd = abs(a) + abs(b)\r\nprint([\"NO\",\"YES\"][s >= d and s % 2 == d % 2])", "var_x, var_y, steps = [abs(int(x)) for x in input().split()]\nmin_steps = var_x + var_y\n\nif steps >= min_steps and min_steps%2 == steps%2:\n print('Yes')\nelse:\n print('No')\n", "a,b,s=map(int,input().split())\r\nx=s-(abs(a)+abs(b))\r\nif x<0:\r\n print(\"No\")\r\nelif x%2==0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "def main():\r\n a, b, s = map(int, input().split())\r\n min_s = abs(a) + abs(b)\r\n if s >= min_s and (s - min_s) % 2 == 0: print(\"YES\")\r\n else: print(\"NO\")\r\n \r\n\r\nmain()", "a,b,s=map(int,input().split())\r\ndiff=s-abs(a)-abs(b)\r\nif (diff<0 or diff%2!=0):\r\n\tprint(\"NO\")\r\nelse:\r\n\tprint(\"YES\")", "a,b,s = map(int, input().split())\r\nc = abs(a) + abs(b)\r\nif c <= s:\r\n if c %2 == 0:\r\n if s%2 == 0:\r\n print('Yes')\r\n else:\r\n print('No')\r\n else:\r\n if s%2 == 0:\r\n print('No')\r\n else:\r\n print('Yes')\r\nelse:\r\n print('No')", "a, b, s = map(int, input().split(' '))\r\nprint('Yes' if (s-abs(a)-abs(b)) % 2 == 0 and (s-abs(a)-abs(b)) >= 0 else 'No')", "l = list(int(x) for x in input().split())\r\na = abs(l[0])\r\nb = abs(l[1])\r\ns = l[2]\r\nif s<a+b:\r\n print('No')\r\nelif (s-(a+b))%2!=0:\r\n print('No')\r\nelse:\r\n print('Yes')", "a,b,s = map(int,input().split())\r\np = abs(a)+abs(b)\r\nif(p>s):\r\n print(\"NO\")\r\nelif(p==s):\r\n print(\"YES\")\r\nelse:\r\n if(s-p)%2==0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "a, b, s = (int(i) for i in input().split())\nd = abs(a) + abs(b)\nres = \"YES\" if s >= d and d & 1 == s & 1 else \"NO\"\nprint(res)\n", "a, b, s = map(int, input().split())\nif abs(a) + abs(b) > s:\n print(\"No\")\nelif abs(a) + abs(b) <= s:\n if(s - (abs(a) + abs(b))) % 2 == 0:\n print(\"Yes\")\n else:\n print(\"No\")\n", "a, b, k = map(int, input().split())\r\n\r\ntot = abs(a) + abs(b)\r\nif tot > k:\r\n print(\"No\")\r\nelif (k - tot) % 2 == 0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "# Фишки\r\n# n, m = map(int, input().split())\r\n# i = 1\r\n# while i <= m:\r\n# m -= i\r\n# i = i + 1 if i != n else 1\r\n# print(m) \r\n\r\n\r\n# Ехаб и очередной конструктив\r\n# x = int(input())\r\n# if x == 1:\r\n# print(-1)\r\n# else:\r\n# print(x - x % 2, 2)\r\n\r\n# Близнецы\r\n# n = int(input())\r\n# coins = list(map(int, input().split()))\r\n# coins.sort(reverse=True)\r\n\r\n# summa = 0\r\n# i = 0\r\n# while summa <= sum(coins[i::]):\r\n# summa += coins[i]\r\n# i += 1\r\n# print(i)\r\n\r\n# Чет и нечет\r\n# n, k = map(int, input().split())\r\n\r\n# if n % 2 == 1:\r\n# half_n = n // 2 + 1\r\n# else:\r\n# half_n = n // 2\r\n\r\n# if k > half_n:\r\n# print((k - half_n)*2)\r\n# else:\r\n# print(k * 2 - 1)\r\n\r\n# Дима и друзья\r\n# n = int(input())\r\n# list1 = list(map(int, input().split()))\r\n\r\n# summa = sum(list1)\r\n# count = 0\r\n# for i in range(1, 6):\r\n# if (summa + i) % (n + 1) != 1:\r\n# count += 1\r\n# print(count)\r\n\r\n\r\n\r\n# Андрюша и носки\r\n# n = int(input())\r\n# socks = input().split()\r\n\r\n\r\n# max_len = 0\r\n# checked_cnt = 0\r\n# for idx, x in enumerate(socks):\r\n# if x in socks[0:idx]:\r\n# checked_cnt += 2\r\n# max_len = max(max_len, len(socks[0:idx+1]) - checked_cnt)\r\n# print(max_len)\r\n\r\n\r\n# Тренировки Поликарпа\r\n# n = int(input())\r\n# a_n = sorted(map(int, input().split()))\r\n\r\n# pos = 1\r\n# for x in a_n:\r\n# if x >= pos:\r\n# pos += 1\r\n\r\n# print(pos - 1)\r\n\r\n\r\n# Социальная сеть\r\n# n, k = map(int, input().split())\r\n# id_n = input().split()\r\n\r\n# on_display = id_n[0:k-1] # беседы на телефоне\r\n# m = 0 # кол-во бесед\r\n\r\n\r\n# Drazil и свидание\r\na, b, s = map(int, input().split())\r\na, b = abs(a), abs(b)\r\n\r\nif a + b > s:\r\n print('No')\r\nelif (s - a - b) % 2 == 0:\r\n print('Yes')\r\nelse:\r\n print('No')", "from math import *\r\na,b,s=[int(x) for x in input().split()]\r\na,b=int(fabs(a)),int(fabs(b))\r\nif a+b>s:\r\n print('No')\r\nelse:\r\n if (a+b-s)%2!=0:\r\n print('No')\r\n else:\r\n print('Yes')", "a,b,s = input().split()\r\na = int(a)\r\nb = int(b)\r\ns = int(s)\r\n\r\nif(s >= abs(a)+abs(b) and (s - abs(a)+abs(b))%2==0):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a,b,s = map(int,input().split())\nif (((s-(abs(a)+abs(b))) % 2) == 0) and (s >= abs(a)+abs(b)):\n print('Yes')\nelse:\n print('No')\n\t \t \t \t \t\t \t\t\t\t\t\t\t \t \t\t", "a=input().split()\r\nif int(a[0])<0:\r\n b=0-int(a[0])\r\nelse:\r\n b=int(a[0])\r\nif int(a[1])<0:\r\n c=0-int(a[1])\r\nelse:\r\n c=int(a[1])\r\nd=int(a[2])\r\ne=(c+b)%2\r\nf=d%2\r\nif e==f and b+c<=d:\r\n print('Yes')\r\nelse:\r\n print('No')", "a, b, s = map(int, input().split())\r\na = abs(a)\r\nb = abs(b)\r\nprint(\"No\" if (s < a + b) or ((s - (a + b)) % 2 == 1) else \"Yes\")\r\n", "a, b, s = map(int, input().split())\r\na = abs(a)\r\nb = abs(b)\r\nif a + b <= s and (s - (a + b)) % 2 == 0:\r\n\tprint(\"Yes\")\r\nelse:\r\n\tprint(\"No\")", "# LUOGU_RID: 102441636\na, b, s = map(abs, map(int, input().split()))\r\nprint((a + b - s) % 2 == 0 and a + b <= s and 'Yes' or 'No')", "a, b, s = map(int, input().split(' '))\r\nx = abs(a) + abs(b)\r\nprint('NO' if (s < x) or (s - x) & 1 else 'YES')\r\n", "a, b, s = map(int, input().split())\r\n\r\nAns = s - abs(b) - abs(a)\r\n\r\nif Ans >= 0 and Ans % 2 == 0 :\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a, b, s = map(int, input().split())\r\nsteps = abs(a) + abs(b)\r\nflag = False if steps > s else (s - steps) % 2 == 0\r\nprint(\"Yes\") if flag else print(\"No\")", "a,b,s=map(int,input().split())\r\ns-=abs(a)+abs(b)\r\nprint('yes'if s>=0 and s%2==0 else 'No')", "try:\r\n a,b,s = map(int, input().split())\r\n a = abs(a)\r\n b = abs(b)\r\n if s<a+b or (s-a+b)%2 == 1:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\nexcept:\r\n pass", "def solve(a: int, b: int, n: int) -> str:\r\n if abs(a)+abs(b)>n :\r\n return(\"No\")\r\n elif abs(a)+abs(b)<n and (n-abs(a)+abs(b))%2==1:\r\n return(\"No\")\r\n else:\r\n return(\"Yes\")\r\n\r\na,b,n=map(int,input().split())\r\nprint(solve(a, b, n))\r\n", "a, b, s = list(map(int, input().split()))\r\n\r\nneed = abs(a) + abs(b)\r\nprint('YES' if s >= need and (s - need) % 2 == 0 else 'NO')", "a, b, s = (int(x) for x in input().split())\nx = s - abs(a) - abs(b)\nprint('Yes' if (x >= 0 and x % 2 == 0) else 'No')", "a,b,c=map(int,input().split())\r\nprint('NYoe s'[c%2 == (a+b)%2 and c >= abs(a)+abs(b)::2])", "a,b,s = map(int,input().split())\r\na = abs(a)\r\nb = abs(b)\r\nif a+b == s:\r\n print(\"Yes\")\r\nelif a+b>s:\r\n print(\"No\")\r\nelse:\r\n if (s - a+b)%2 == 0:\r\n print(\"Yes\")\r\n else:\r\n print(\"No\")", "a, b, s = map(int, input().split())\r\nif s>=abs(a)+abs(b) and (s-abs(a)+abs(b))%2 == 0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "def date(a, b, s):\n m = abs(a) + abs(b)\n return s >= m and (s - m) % 2 == 0\n\n\ndef main():\n a, b, s = readinti()\n print('Yes' if date(a, b, s) else 'No')\n\n##########\n\nimport sys\nimport time\nimport traceback\nfrom contextlib import contextmanager\nfrom io import StringIO\n\ndef readint():\n return int(input())\n\n\ndef readinti():\n return map(int, input().split())\n\n\ndef readintl():\n return list(readinti())\n\n\ndef readintll(k):\n return [readintl() for _ in range(k)]\n\n\ndef log(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n\n\n@contextmanager\ndef patchio(i):\n try:\n sys.stdin = StringIO(i)\n sys.stdout = StringIO()\n yield sys.stdout\n finally:\n sys.stdin = sys.__stdin__\n sys.stdout = sys.__stdout__\n\n\ndef do_test(k, test):\n try:\n log(f\"TEST {k}\")\n i, o = test\n with patchio(i) as r:\n t0 = time.time()\n main()\n t1 = time.time()\n if r.getvalue() == o:\n log(f\"OK ({int((t1-t0)*1000000)/1000:0.3f} ms)\\n\")\n else:\n log(f\"Expected:\\n{o}\"\n f\"Got ({int((t1-t0)*1000000)/1000:0.3f} ms):\\n{r.getvalue()}\")\n except Exception:\n traceback.print_exc()\n log()\n\n\ndef test(ts):\n for k in ts or range(len(tests)):\n do_test(k, tests[k])\n\n\ntests = [(\"\"\"\\\n5 5 11\n\"\"\", \"\"\"\\\nNo\n\"\"\"), (\"\"\"\\\n10 15 25\n\"\"\", \"\"\"\\\nYes\n\"\"\"), (\"\"\"\\\n0 5 1\n\"\"\", \"\"\"\\\nNo\n\"\"\"), (\"\"\"\\\n0 0 2\n\"\"\", \"\"\"\\\nYes\n\"\"\")]\n\n\nif __name__ == '__main__':\n from argparse import ArgumentParser\n parser = ArgumentParser()\n parser.add_argument('--test', '-t', type=int, nargs='*')\n args = parser.parse_args()\n main() if args.test is None else test(args.test)\n", "a,b,s = map(int, input().split())\r\ns = s-abs(a)-abs(b)\r\nif s==0:\r\n print(\"YES\")\r\nelif s>0 and s%2==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "s=list(map(int,input().split()))\nfor k in s:\n if s[0]<0:\n s[0]=-s[0]\n if s[1]<0:\n s[1]=-s[1]\n\nif (s[2]<s[1]+s[0]) or ((s[2]-s[1]-s[0])%2!=0):\n print(\"NO\")\nelse:\n print('YES')\n \t \t \t\t \t\t \t\t\t\t\t\t\t\t \t \t \t", "a,b,c=map(int,input().split())\r\nprint('YNeos'[c<abs(a)+abs(b) or (c-abs(a)-abs(b))&1::2])", "a,b,c=map(int,input().split());print(\"NO\"if (abs(a)+abs(b))>c or (abs(a)+abs(b))&1!=c&1 else \"YES\" )", "a,b,s=map(int,input().split())\r\nk=abs(a)+abs(b)\r\nl=abs(s-k)\r\nif l%2==0 and s>=k:\r\n\tprint(\"Yes\")\r\nelse:\r\n\tprint(\"No\")", "a,b,s = [int(x) for x in input().split()]\r\ntemp = s-abs(a)-abs(b)\r\nprint(\"Yes\" if temp%2==0 and temp>=0 else \"No\")", "m,n,a=map(int,input().split())\r\nif a>=abs(m)+abs(n) and (a-abs(m)+abs(n))%2==0:\r\n\tprint(\"YES\")\r\nelse:\r\n\tprint(\"NO\")\t\t\r\n", "a=input().split()\r\nb=abs(int(a[1]))\r\ns=abs(int(a[2]))\r\na=abs(int(a[0]))\r\nif((a+b)==s):\r\n print(\"YES\")\r\nelif (a+b)<s:\r\n s-=a+b\r\n if(s%2==0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\nelse:\r\n print(\"NO\")", "a, b, s = map(int, input().split())\r\nif s < abs(a) + abs(b):\r\n print('NO')\r\nelif s == a + b:\r\n print('YES')\r\nelse:\r\n if s % 2 == (abs(a)+abs(b)) % 2:\r\n print('YES')\r\n else:\r\n print('NO')\r\n ", "a,b,s=map(int,input().split())\r\nx=abs(b)+abs(a)\r\nif s<x:\r\n print(\"NO\")\r\nelif s==x:\r\n print(\"YES\")\r\nelse:\r\n if (s-x)%2==0:\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "a,b,s=[int(i) for i in input().split()]\r\nif a<0:\r\n a=a*(-1)\r\nif b<0:\r\n b=b*(-1)\r\nif s<a+b:\r\n print(\"No\")\r\nelse :\r\n s-=(a+b)\r\n if s%2==0:\r\n print(\"Yes\")\r\n else :\r\n print(\"No\")", "a,b,s = input().split()\r\n\r\na = abs(int(a))\r\nb = abs(int(b))\r\ns = abs(int(s))\r\n\r\nif (a+b>s):\r\n print(\"NO\")\r\n\r\nelif(a+b==s):\r\n print(\"YES\")\r\n\r\nelif(a+b<s):\r\n x = a+b\r\n if(x%2==0):\r\n if(s%2==0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n elif(x%2!=0):\r\n if(s%2!=0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "a,b,c=map(int,input().split())\r\nif c>=abs(a)+ abs(b) and (c-(abs(a)+abs(b)))%2==0 :\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")", "a,b,s=map(int,input().split())\nx=s-abs(a)-abs(b)\nif x>=0 and x%2==0:\n print(\"Yes\")\nelse:\n print(\"No\")", "\r\na, b, s = map(int, input().split())\r\ndistance = abs(a) + abs(b)\r\nif s >= distance and (s - distance) % 2 == 0:\r\n print('Yes')\r\nelse:\r\n print('No')", "a, b, s=[int(i) for i in input().split()]\r\nif a<0:\r\n a=abs(a)\r\nif b<0:\r\n b=abs(b)\r\nprint(\"No\" if a+b>s or (s-a+b)%2!=0 else \"Yes\")", "a,b,s = list(map(int, input().rstrip().split()))\r\nif a<0:\r\n a =-a\r\nif b<0:\r\n b =-b\r\nc = a+b\r\nd = s - c\r\nif d>-1 and d%2==0:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a,b,s=map(int,input().split())\r\ns1=abs(a)+abs(b)\r\nif(s<s1):\r\n print(\"NO\")\r\nelse:\r\n l=s-s1\r\n if(l%2==0):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")", "# import sys\r\n# input = sys.stdin.readline\r\n# for _ in range(int(input())):\r\na,b,s = map(int,input().split(\" \"))\r\nif s<abs(a)+abs(b) or (s-abs(a)-abs(b))%2:\r\n print(\"No\")\r\nelse:\r\n print(\"Yes\")", "a,b,c=map(int,input().split());print(\"YNEOS\"[(a+b+c)%2or abs(a)+abs(b)>c::2])", "from sys import stdin, stdout\r\n\r\nintn = lambda : int(stdin.readline())\r\nstrs = lambda : stdin.readline()[:-1]\r\nlstr = lambda : list(stdin.readline()[:-1])\r\nmint = lambda : map(int, stdin.readline().split())\r\nlint = lambda : list(map(int, stdin.readline().split()))\r\nout = lambda x: stdout.write(str(x)+\"\\n\")\r\nout_ = lambda x: stdout.write(str(x)+' ')\r\n\r\ndef main():\r\n a,b,s = mint()\r\n a, b = abs(a), abs(b)\r\n if s>=a+b and (s-(a+b))%2==0:\r\n out(\"Yes\")\r\n else:\r\n out(\"No\")\r\n\r\nif __name__ == \"__main__\":\r\n main()", "a, b, s = map(int, input().split())\r\n\r\n# Calculate the Manhattan distance between Drazil's and Varda's home.\r\nmanhattan_distance = abs(a) + abs(b)\r\n\r\n# Check if it's possible based on the conditions.\r\nif s >= manhattan_distance and (s - manhattan_distance) % 2 == 0:\r\n print(\"Yes\")\r\nelse:\r\n print(\"No\")\r\n", "a,b,s=map(int,input().split(\" \"))\r\nif(s>=(abs(a)+abs(b)) and (s-(abs(a) + abs(b)))%2==0):\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "a,b,s = map(int,input().split())\r\nif (a+b+s)%2 or abs(a)+abs(b)>s:\r\n print(\"No\")\r\nelse:\r\n print(\"Yes\")\r\n" ]
{"inputs": ["5 5 11", "10 15 25", "0 5 1", "0 0 2", "999999999 999999999 2000000000", "-606037695 998320124 820674098", "948253616 -83299062 1031552680", "711980199 216568284 928548487", "-453961301 271150176 725111473", "0 0 2000000000", "0 0 1999999999", "1000000000 1000000000 2000000000", "-1000000000 1000000000 2000000000", "-1000000000 -1000000000 2000000000", "-1000000000 -1000000000 1000000000", "-1 -1 3", "919785634 216774719 129321944", "-467780354 -721273539 1369030008", "-232833910 -880680184 1774549792", "45535578 402686155 1011249824", "-203250176 -30379840 233630015", "-814516648 -75830576 890347222", "869184175 -511854751 1381038923", "552884998 -262338193 815223187", "-133874494 857573117 991447611", "169406792 786701289 956108082", "30237137 -989203246 1019440385", "576608216 -617624133 1194232352", "-662360368 97618995 759979367", "-115989290 321714461 437703756", "-1 -3 2", "-2 -2 2", "0 0 1", "0 -1 7", "1 2 7", "0 5 6", "0 -4 2", "-5 5 2", "-5 -2 7", "5 -5 2"], "outputs": ["No", "Yes", "No", "Yes", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "Yes", "Yes", "Yes", "No", "No", "No", "No", "Yes", "No", "No", "No", "No", "No", "Yes", "No", "Yes", "No", "Yes", "No", "No", "No", "No", "Yes", "Yes", "No", "No", "No", "Yes", "No"]}
UNKNOWN
PYTHON3
CODEFORCES
146
1b086a205dcde6ba4c9ab03dfd1792b0
Two strings
You are given two strings *a* and *b*. You have to remove the minimum possible number of consecutive (standing one after another) characters from string *b* in such a way that it becomes a subsequence of string *a*. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from *b* and make it empty. Subsequence of string *s* is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string *s*. The first line contains string *a*, and the second line — string *b*. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 105 characters. On the first line output a subsequence of string *a*, obtained from *b* by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign). Sample Input hi bob abca accepted abacaba abcdcba Sample Output - ac abcba
[ "def solve(s1,s2):\r\n n=len(s1)\r\n m=len(s2)\r\n s1=' ' +s1 + ' '\r\n s2=' ' +s2 + ' '\r\n tmp=0\r\n v1=[0]*100005\r\n v2=[0]*100005\r\n for i in range(1,n+1):\r\n if s1[i]==s2[tmp+1]:\r\n tmp+=1\r\n v1[i]=tmp\r\n tmp=m+1\r\n v2[n+1]=tmp\r\n for i in range(n,0,-1):\r\n if s1[i]==s2[tmp-1]:\r\n tmp-=1\r\n v2[i]=tmp\r\n b=0\r\n mx=0\r\n for i in range(n+1):\r\n c=v1[i]+m-v2[i+1]+1\r\n if c>mx:\r\n mx=c\r\n b=i\r\n ans=[]\r\n if mx>=m:\r\n for i in range(1,m+1):\r\n ans.append(s2[i])\r\n else:\r\n for i in range(1,v1[b]+1):\r\n ans.append(s2[i])\r\n for i in range(v2[b+1],m+1):\r\n ans.append(s2[i])\r\n while len(ans)>0 and ans[-1]==' ':\r\n ans.pop()\r\n if len(ans)==0:\r\n ans=\"-\"\r\n return ''.join(ans)\r\n\r\ns1=input()\r\ns2=input()\r\nprint(solve(s1,s2))\r\n \r\n", "from macpath import curdir\r\nimport bisect\r\na=input()\r\nb=input()\r\nla=len(a)\r\nlb=len(b)\r\nforb=[la]*lb\r\ncur=0\r\nfor i in range(lb):\r\n while cur<la and a[cur]!=b[i]:\r\n cur+=1\r\n if cur<la:\r\n forb[i]=cur\r\n cur+=1\r\n else:\r\n break\r\ncur=la-1\r\nbacb=[-1]*lb\r\nfor i in range(lb-1,-1,-1):\r\n while cur>=0 and a[cur]!=b[i]:\r\n cur-=1\r\n if cur>=0:\r\n bacb[i]=cur\r\n cur-=1\r\n else:\r\n break\r\nres=lb\r\nstart=0\r\nend=lb\r\nfor i in range(lb):\r\n low=-1\r\n if i>0 :\r\n low=forb[i-1]\r\n if low>=la:\r\n break\r\n j=bisect.bisect_right(bacb,low)\r\n if res>j-i>=0:\r\n res=j-i\r\n start=i\r\n end=j\r\nif res==lb:\r\n print('-') \r\nelse:\r\n print(b[:start]+b[end:])\r\n \r\n \r\n \r\n ", "# cook your dish here\na = list(input())\nb = list(input())\n\nm = len(a)\nn = len(b)\n\ns = [-1]\ni = 0\nj = 0\n\nwhile i<m and j<n:\n if(a[i]==b[j]):\n s.append(i)\n j+=1\n i+=1\n \ne = [1000000]\n\ni = m-1\nj= n-1\n\nwhile i>=0 and j>=0:\n if(a[i]==b[j]):\n e.append(i)\n j-=1\n i-=1\n \n \ni = len(s)-1\nj = 0\n\nans = \"-\"\nctr = 0\n\nwhile j<len(e) and i>=0:\n if(s[i]<e[j]):\n if(i+j > ctr and i+j<=len(b)):\n ctr = i+j\n if(j>0):\n ans = b[:i] + b[-j:]\n else:\n ans = b[:i]\n j+=1\n else:\n i -= 1\n\nprint(''.join(ans)) \n \t\t\t\t \t\t \t \t\t \t \t\t\t \t \t \t\t\t", "import sys\r\n\r\ns, t = input(), '*'+input()\r\nn, m = len(s), len(t)-1\r\ninf = 10**9\r\n\r\npre, suf = [-1] + [inf]*(m+1), [-1]*(m+1) + [n]\r\n\r\ni = 0\r\nfor j in range(1, m+1):\r\n while i < n and s[i] != t[j]:\r\n i += 1\r\n if i == n:\r\n break\r\n pre[j] = i\r\n i += 1\r\n\r\ni = n-1\r\nfor j in range(m, 0, -1):\r\n while 0 <= i and s[i] != t[j]:\r\n i -= 1\r\n if i == -1:\r\n break\r\n suf[j] = i\r\n i -= 1\r\n\r\nmax_len, best_l, best_r = 0, 0, 0\r\nj = 1\r\nfor i in range(m+1):\r\n j = max(j, i+1)\r\n while j <= m and pre[i] >= suf[j]:\r\n j += 1\r\n if pre[i] == inf:\r\n break\r\n if max_len < i + m + 1 - j:\r\n max_len = i + m + 1 - j\r\n best_l, best_r = i, j\r\n\r\npre_s = t[1:best_l+1]\r\nsuf_s = t[best_r:]\r\n\r\nprint(pre_s + suf_s if max_len else '-')\r\n", "a = list(input())\nb = list(input())\n\ns = [-1]\ni = 0\nj = 0\n\nwhile i < len(a) and j < len(b):\n\tif a[i] == b[j]:\n\t\ts.append(i)\n\t\tj += 1\n\ti += 1\n\ne = [10**6]\ni = len(a) - 1\nj = len(b) - 1\n\nwhile i >= 0 and j >= 0:\n\tif a[i] == b[j]:\n\t\te.append(i)\n\t\tj -= 1\n\ti -= 1\n\nans_len = 0\nans = ['-']\n\ni = len(s) - 1\nj = 0\nwhile i >= 0 and j < len(e):\n\tif s[i] < e[j] and i + j - 1< len(b):\n\t\tnew_len = j + i\n\t\tif new_len > ans_len:\n\t\t\tans_len = new_len\n\t\t\tif j > 0:\n\t\t\t\tans = b[:i] + b[-j:]\n\t\t\telse:\n\t\t\t\tans = b[:i]\n\t\tj += 1\n\telse:\n\t\ti -= 1\n\nprint(''.join(ans))", "a, b = input(), input()\r\nn = len(b)\r\ndef f(a, b):\r\n i, t = 0, [0]\r\n for q in a:\r\n if i < n and q == b[i]: i += 1\r\n t.append(i)\r\n return t\r\nu, v = f(a, b), f(a[::-1], b[::-1])[::-1]\r\nt = [x + y for x, y in zip(u, v)]\r\ni = t.index(max(t))\r\nx, y = u[i], v[i]\r\ns = b[:x] + b[max(x, n - y):]\r\nprint(s if s else '-')", "from sys import stdin\r\n\r\n\r\ndef main():\r\n t = stdin.readline()\r\n s = stdin.readline()\r\n n = len(s) - 1\r\n m = len(t) - 1\r\n post = [-1] * n\r\n ss = n - 1\r\n st = m - 1\r\n while st >= 0 and ss >= 0:\r\n if t[st] == s[ss]:\r\n post[ss] = st\r\n ss -= 1\r\n st -= 1\r\n pre = [-1] * n\r\n ss = 0\r\n st = 0\r\n while st < m and ss < n:\r\n if t[st] == s[ss]:\r\n pre[ss] = st\r\n ss += 1\r\n st += 1\r\n low = 0\r\n high = n\r\n min_ans = n\r\n start = -1\r\n end = -1\r\n while low < high:\r\n mid = (low + high) >> 1\r\n ok = False\r\n if post[mid] != -1:\r\n if mid < min_ans:\r\n min_ans = mid\r\n start = 0\r\n end = mid - 1\r\n ok = True\r\n for i in range(1, n - mid):\r\n if pre[i - 1] != -1 and post[i + mid] != -1 and post[i + mid] > pre[i - 1]:\r\n if mid < min_ans:\r\n min_ans = mid\r\n start = i\r\n end = i + mid - 1\r\n ok = True\r\n if pre[n - mid - 1] != -1:\r\n if mid < min_ans:\r\n min_ans = mid\r\n start = n - mid\r\n end = n - 1\r\n ok = True\r\n if not ok:\r\n low = mid + 1\r\n else:\r\n high = mid\r\n ans = []\r\n for i in range(n):\r\n if start <= i <= end:\r\n continue\r\n ans.append(s[i])\r\n if min_ans == n:\r\n print('-')\r\n else:\r\n print(''.join(ans))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "# cook your dish here\n\na = list(input())\n\nb = list(input())\n\n\n\nm = len(a)\n\nn = len(b)\n\n\n\ns = [-1]\n\ni = 0\n\nj = 0\n\n\n\nwhile i<m and j<n:\n\n if(a[i]==b[j]):\n\n s.append(i)\n\n j+=1\n\n i+=1\n\n \n\ne = [1000000]\n\n\n\ni = m-1\n\nj= n-1\n\n\n\nwhile i>=0 and j>=0:\n\n if(a[i]==b[j]):\n\n e.append(i)\n\n j-=1\n\n i-=1\n\n \n\n \n\ni = len(s)-1\n\nj = 0\n\n\n\nans = \"-\"\n\nctr = 0\n\n\n\nwhile j<len(e) and i>=0:\n\n if(s[i]<e[j]):\n\n if(i+j > ctr and i+j<=len(b)):\n\n ctr = i+j\n\n if(j>0):\n\n ans = b[:i] + b[-j:]\n\n else:\n\n ans = b[:i]\n\n j+=1\n\n else:\n\n i -= 1\n\n\n\nprint(''.join(ans)) \n\n\n\n# Made By Mostafa_Khaled" ]
{"inputs": ["hi\nbob", "abca\naccepted", "abacaba\nabcdcba", "lo\neuhaqdhhzlnkmqnakgwzuhurqlpmdm", "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk", "npnkmawey\nareakefvowledfriyjejqnnaeqheoh", "fdtffutxkujflswyddvhusfcook\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc", "abacaba\naa", "edbcd\nd", "abc\nksdksdsdsnabc", "abxzxzxzzaba\naba", "abcd\nzzhabcd", "aa\naa", "test\nt", "aa\na", "aaaabbbbaaaa\naba", "aa\nzzaa", "zhbt\nztjihmhebkrztefpwty", "aaaaaaaaaaaaaaaaaaaa\naaaaaaaa", "abba\naba", "abbba\naba", "aaaaaaaaaaaa\naaaaaaaaaaaa", "aaa\naa", "aaaaaaaaaaaa\naaa", "aaaaabbbbbbaaaaaa\naba", "ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\nashish", "a\na", "aaaab\naab", "aaaaa\naaaa", "a\naaa", "aaaaaabbbbbbaaaaaa\naba", "def\nabcdef", "aaaaaaaaa\na", "bababsbs\nabs", "hddddddack\nhackyz", "aba\na", "ofih\nihfsdf", "b\nabb", "lctsczqr\nqvkp", "dedcbaa\ndca", "haddack\nhack", "abcabc\nabc", "asdf\ngasdf", "abab\nab", "aaaaaaa\naaa", "asdf\nfasdf", "bbaabb\nab", "accac\nbaacccbcccabaabbcacbbcccacbaabaaac", "az\naaazazaa", "bbacaabbaaa\nacaabcaa", "c\ncbcbcbbacacacbccaaccbcabaaabbaaa", "bacb\nccacacbacbccbbccccaccccccbcbabbbaababa", "ac\naacacaacbaaacbbbabacaca", "a\nzazaa", "abcd\nfaaaabbbbccccdddeda", "abcde\nfabcde", "a\nab", "ababbbbbbbbbbbb\nabbbbb", "bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab", "ab\naba", "aa\naaaa", "aaaaabbbaaaaa\naabbaa", "aaaaaaaaa\naaaa", "abbcc\naca", "b\ncb", "aac\naaa", "ba\nbb", "a\nb", "gkvubrvpbhsfiuyha\nihotmn", "ccccabccbb\ncbbabcc", "babababbaaabb\nabbab", "njtdhyqundyedsjyvy\nypjrs", "uglyqhkpruxoakm\ncixxkpaaoodpuuh", "a\naaaaaaaaa", "aaa\naaaaa", "abcabbcbcccbccbbcc\nacbcaabbbbcabbbaca", "caacacaacbaa\nacbbbabacacac", "aa\naaab", "acbc\ncacacbac", "bacbcaacabbaacb\ncbbaaccccbcaacacaabb", "baababaaaab\nbaababbbbbbb", "aaxyaba\naaba"], "outputs": ["-", "ac", "abcba", "-", "ouypvk", "a", "kvc", "aa", "d", "abc", "aba", "abcd", "aa", "t", "a", "aba", "aa", "zt", "aaaaaaaa", "aba", "aba", "aaaaaaaaaaaa", "aa", "aaa", "aba", "ashish", "a", "aab", "aaaa", "a", "aba", "def", "a", "abs", "hack", "a", "ih", "b", "q", "dca", "hack", "abc", "asdf", "ab", "aaa", "asdf", "ab", "aac", "a", "acaabaa", "c", "ba", "a", "a", "a", "abcde", "a", "abbbbb", "bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab", "ab", "aa", "aabbaa", "aaaa", "ac", "b", "aa", "b", "-", "ih", "cabcc", "abbab", "ys", "uh", "a", "aaa", "acbc", "aacacac", "aa", "ac", "cbcaabb", "baababb", "aaba"]}
UNKNOWN
PYTHON3
CODEFORCES
8
1b36d9af899bb91e38c9a85d7cb7a906
Data Recovery
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only *m*. The next day, the engineer's assistant filed in a report with all the *m* temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers *n*, *m*, *min*, *max* and the list of *m* temperatures determine whether you can upgrade the set of *m* temperatures to the set of *n* temperatures (that is add *n*<=-<=*m* temperatures), so that the minimum temperature was *min* and the maximum one was *max*. The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=&lt;<=*n*<=≤<=100; 1<=≤<=*min*<=&lt;<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Sample Input 2 1 1 2 1 3 1 1 3 2 2 1 1 3 2 Sample Output Correct Correct Incorrect
[ "a,b,c,d=map(int,input().split())\r\nz=list(map(int,input().split()))\r\nk=z.copy()\r\nif c in k:k.remove(c)\r\nif d in k:k.remove(d)\r\nif (max(z)>d or min(z)<c or len(k)+2>a ):print(\"Incorrect\")\r\nelse:print(\"Correct\")", "I = lambda: map(int, input().split())\r\n\r\nn, m, Tmin, Tmax = I()\r\nT = sorted(I())\r\n\r\nprint(('Inc' if ( T[0]<Tmin or T[-1]>Tmax\r\n or n-m<2 and T[0]!=Tmin and T[-1]!=Tmax) else 'C')+'orrect')", "x = 0\r\nres = 0\r\nn, m, mn, mx = list(map(int, input().split()))\r\nlst = list(map(int, input().split()))\r\nfor i in range(m):\r\n if lst[i] < mn or lst[i] > mx:\r\n res = \"Incorrect\"\r\n break\r\n if lst[i] == mn:\r\n x = 1\r\n elif lst[i] == mx:\r\n x = 1\r\nif res == \"Incorrect\":\r\n print(res)\r\nelse:\r\n if n - m >= 2 - x:\r\n print(\"Correct\")\r\n else:\r\n print(\"Incorrect\")\r\n", "n,m,mi,ma=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nans='Correct'\r\nif len(x)<n:\r\n if max(x)<ma:\r\n x.append(ma)\r\nif len(x)<n:\r\n if min(x)>mi:\r\n x.append(mi)\r\nif min(x)==mi and max(x)==ma:\r\n print('Correct')\r\nelse:\r\n print('Incorrect')\r\n", "n,m,a,b=map(int,input().split())\r\ns=list(map(int,input().split()))\r\nc,d=min(s),max(s)\r\nif (c<a or d>b):\r\n print('Incorrect')\r\nelif (n-1==m and c!=a and d!=b):\r\n print('Incorrect')\r\nelse:\r\n print('Correct')\r\n", "if __name__ == '__main__':\r\n cin = input\r\n n, m, ln, rn = map(int, cin().split())\r\n a = [int(v) for v in cin().split()]\r\n\r\n if ln < min(a) <= max(a) < rn:\r\n print([\"Incorrect\", \"Correct\"][n - m > 1])\r\n else:\r\n print([\"Correct\", \"Incorrect\"][min(a) < ln or max(a) > rn])\r\n", "n,m,mn,mx=map(int,input().split())\r\ns=list(map(int,input().split()))\r\nam,ax=min(s),max(s)\r\nif am<mn or ax>mx:print('Incorrect')\r\nelif n-1==m and am!=mn and ax!=mx:print('Incorrect')\r\nelse:print('Correct')", "n,m,mi,ma=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nans='Correct'\r\nif min(l)<mi or max(l)>ma: ans='Incorrect'\r\nc=2\r\nif mi in l: c-=1\r\nif ma in l: c-=1\r\nif n-m<c: ans='Incorrect'\r\nprint(ans)", "[n, m, min_t, max_t], t = map(int, input().split()), list(map(int, input().split()))\r\nmin_m, max_m = min(t), max(t)\r\nif min_m >= min_t and max_m <= max_t and (n - m) >= ((min_m != min_t) + (max_m != max_t)):\r\n print('Correct')\r\nelse:\r\n print('Incorrect')\r\n", "\r\nn,m,Min,Max=map(int,input().split())\r\nt=sorted(list(map(int,input().split())))\r\nif (t[m-1]!=Max and t[0]!= Min and n-m==1) or t[m-1]>Max or t[0]<Min:\r\n print('Incorrect')\r\nelse:\r\n print('Correct')\r\n\r\n \r\n \r\n ", "\r\n# Problem: A. Data Recovery\r\n# Contest: Codeforces - Coder-Strike 2014 - Round 2\r\n# URL: https://codeforces.com/contest/413/problem/A\r\n# Memory Limit: 256 MB\r\n# Time Limit: 1000 ms\r\n# Powered by CP Editor (https://github.com/cpeditor/cpeditor)\r\n\r\nfrom sys import stdin\r\ndef get_ints(): return list(map(int, stdin.readline().strip().split()))\r\n\r\nn,m,mn,mx = get_ints()\r\nar = get_ints()\r\ntoadd = n-m\r\namin = min(ar)\r\namax = max(ar)\r\nif toadd ==1 and ( amin != mn and amax != mx):\r\n\tprint(\"Incorrect\")\r\n\texit()\r\n\t\r\n\r\nif amin < mn or amax > mx:\r\n\tprint(\"Incorrect\")\r\n\texit()\r\n\t\r\nprint(\"Correct\")", "n, m, mi, ma = map(int, input().split())\r\na = sorted(list(map(int, input().split())))\r\nif n - m >= 2:\r\n if a[0] >= mi and a[-1] <= ma:\r\n print('Correct')\r\n else:\r\n print('Incorrect')\r\nelif n - m == 1:\r\n if (a[0] >= mi and a[-1] == ma) or (a[0] == mi and a[-1] <= ma):\r\n print('Correct')\r\n else:\r\n print('Incorrect')\r\nelse:\r\n if a[0] == mi and a[-1] == ma:\r\n print('Correct')\r\n else:\r\n print('Incorrect')", "n, m, mi, ma = map(int, input().split())\r\nk = n - m\r\ncounter = 2\r\ns = list(map(int, input().split()))\r\nif min(s) < mi:\r\n print('Incorrect'); quit()\r\nif max(s) > ma:\r\n print('Incorrect'); quit()\r\nif mi in s:\r\n counter -= 1\r\nif ma in s:\r\n counter -= 1\r\nif k >= counter:\r\n print('Correct')\r\nelse:\r\n print('Incorrect')", "mod = 1000000007\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nls = lambda : list(input())\r\nn,m,mn,mx=f()\r\nl=il()\r\nmn1=min(l)\r\nmx1=max(l)\r\nif mn1<mn or mx1>mx:\r\n print('Incorrect')\r\nelif mn1==mn and mx1==mx:\r\n print('Correct')\r\nelif (mn1==mn and n-m>=1) or (mx1==mx and n-m>=1):\r\n print('Correct')\r\nelif n-m>=2:\r\n print('Correct')\r\nelse:\r\n print('Incorrect')", "R = lambda :map(int,input().split())\nn,m,mi,ma= R()\ns = list(R())\na = {mi,ma}\nb = set()\nfor i in s:\n if mi<=i<=ma:\n a.add(i)\n b.add(i)\n else:\n print('Incorrect')\n exit(0)\nif len(a)>n:\n print('Incorrect')\nelse:\n if m<n-1:\n print('Correct')\n else:\n if (len(a)-len(b))<=n-m:\n print('Correct')\n else:\n print('Incorrect')\n\n", "# LUOGU_RID: 117415483\nn, m, a1, a2 = map(int, input().split())\r\ntemperatures = list(map(int, input().split()))\r\n\r\nif a1 > min(temperatures) or a2 < max(temperatures):\r\n print(\"Incorrect\")\r\nelse:\r\n differences = 0\r\n if a1 not in temperatures:\r\n differences += 1\r\n if a2 not in temperatures:\r\n differences += 1\r\n\r\n if n - m < differences:\r\n print(\"Incorrect\")\r\n else:\r\n print(\"Correct\")\r\n", "n, m, mi, ma = tuple(map(int, str.split(input())))\r\nts = tuple(map(int, str.split(input())))\r\nif max(ts) > ma or min(ts) < mi:\r\n\r\n ans = \"Incorrect\"\r\n\r\nelse:\r\n\r\n count = 2\r\n if mi in ts:\r\n\r\n count -= 1\r\n\r\n if ma in ts:\r\n\r\n count -= 1\r\n\r\n if n - m >= count:\r\n\r\n ans = \"Correct\"\r\n\r\n else:\r\n\r\n ans = \"Incorrect\"\r\n\r\nprint(ans)\r\n", "n, m, minimum, maximum = map(int, input().split())\r\n\r\nt = list(map(int, input().split()))\r\n\r\nif any(map(lambda tmp: not minimum<=tmp<=maximum, t)):\r\n print('Incorrect')\r\nelif len(t) + 2 - (minimum in t) - (maximum in t) > n:\r\n print('Incorrect')\r\nelse:\r\n print('Correct')", "def check(n, m, mi, ma, t):\r\n mit = min(t)\r\n mat = max(t)\r\n if (mi <= mit and ma >= mat) and (n - m >= 2 or (n - m >= 1 and (mit == mi or mat == ma)) or (mit == mi and mat == ma)):\r\n return 'Correct'\r\n else:\r\n return 'Incorrect'\r\nn, m, mi, ma = map(int, input().split())\r\nt = list(map(int, input().split()))\r\nresult = check(n, m, mi, ma, t)\r\nprint(result)# 1698066476.8566856", "#!/usr/bin/python\nimport re\nimport inspect\nfrom sys import argv, exit\n\ndef rstr():\n return input()\n\ndef rstrs(splitchar=' '):\n return [i for i in input().split(splitchar)]\n\ndef rint():\n return int(input())\n\ndef rints(splitchar=' '):\n return [int(i) for i in rstrs(splitchar)]\n\ndef varnames(obj, namespace=globals()):\n return [name for name in namespace if namespace[name] is obj]\n\ndef pvar(var, override=False):\n prnt(varnames(var), var)\n\ndef prnt(*args, override=False):\n if '-v' in argv or override:\n print(*args)\n\n# Faster IO\npq = []\ndef penq(s):\n if not isinstance(s, str):\n s = str(s)\n pq.append(s)\n\ndef pdump():\n s = ('\\n'.join(pq)).encode()\n os.write(1, s)\n\nif __name__ == '__main__':\n timesteps, ast, mn, mx = rints()\n to_add = timesteps - ast\n asts = rints()\n for t in asts:\n if t < mn or t > mx:\n print('Incorrect')\n exit(0)\n if mn not in asts:\n if to_add == 0:\n print('Incorrect')\n exit(0)\n else:\n to_add -= 1\n\n if mx not in asts:\n if to_add == 0:\n print('Incorrect')\n exit(0)\n else:\n to_add -= 1\n\n print('Correct')\n\n \n", "n, m, a, b = map(int, input().split())\r\nt = list(map(int, input().split()))\r\nx, y = min(t), max(t)\r\nprint('Correct' if a <= x and y <= b and len(t) + int(a < x) + int(y < b) <= n else 'Incorrect')", "if __name__ == '__main__':\r\n cin = input\r\n n, m, mj, mx = map(int, cin().split())\r\n a = [int(v) for v in cin().split()]\r\n l, r = min(a), max(a)\r\n\r\n if min(a) < mj or max(a) > mx:\r\n print(\"Incorrect\")\r\n elif mj < min(a) <= max(a) < mx:\r\n print([\"Incorrect\", \"Correct\"][n - m > 1])\r\n else:\r\n print(\"Correct\")\r\n", "import sys\r\n\r\ndef minp():\r\n\treturn sys.stdin.readline().strip()\r\n\r\ndef mint():\r\n\treturn int(minp())\r\n\r\ndef mints():\r\n\treturn map(int,minp().split())\r\n\r\nn,m,mi,ma = mints()\r\na = list(mints())\r\nmii = min(a)\r\nmaa = max(a)\r\nif mii > mi:\r\n\tm += 1\r\nif maa < ma:\r\n\tm += 1\r\nif mii < mi or maa > ma or m > n:\r\n\tprint(\"Incorrect\")\r\nelse:\r\n\tprint(\"Correct\")\r\n", "n, m, min_, max_ = map(int, input().split())\nl = sorted(list(map(int, input().split())))\nif l[0] < min_ or l[-1] > max_:\n print(\"Incorrect\")\nelse:\n if l[-1] < max_:\n l.append(max_)\n if l[0] > min_:\n l.append(min_)\n if len(l) <= n:\n print(\"Correct\")\n else:\n print(\"Incorrect\")\n\n", "def main():\n\tn, m, mn, mx = map(int, input().split())\n\tA = list(map(int, input().split()))\n\ta = min(A)\n\tb = max(A)\n\tif a < mn or b > mx:\n\t\tprint(\"Incorrect\")\n\t\treturn\n\tcnt = 0\n\tif a > mn:\n\t\tcnt += 1\n\tif b < mx:\n\t\tcnt += 1\n\tif m + cnt <= n:\n\t\tprint(\"Correct\")\n\telse:\n\t\tprint(\"Incorrect\")\n\nmain()", "import poplib\r\nimport string\r\nimport math\r\n\r\ndef main_function():\r\n n, m, min_t, max_t = [int(i) for i in input().split(\" \")]\r\n t = [int(i) for i in input().split(\" \")]\r\n difference = n - m\r\n if not min_t <= min(t) <= max(t) <= max_t:\r\n print(\"Incorrect\")\r\n else:\r\n if difference >= 2:\r\n if min_t <= min(t) <= max(t) <= max_t:\r\n print(\"Correct\")\r\n else:\r\n print(\"Incorrect\")\r\n elif difference == 0:\r\n if min_t == min(t) and max(t) == max_t:\r\n print(\"Correct\")\r\n else:\r\n print(\"Incorrect\")\r\n else:\r\n if min_t == min(t) or max(t) == max_t:\r\n print(\"Correct\")\r\n else:\r\n print(\"Incorrect\")\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n main_function()", "n, m, mi, ma = map(int, input().split())\r\nt = list(map(int, input().split()))\r\nmit = min(t)\r\nmat = max(t)\r\nif (mi <= mit and ma >= mat) and (n - m >= 2 or (n - m >= 1 and (mit == mi or mat == ma)) or (mit == mi and mat == ma)):\r\n print('Correct')\r\nelse:\r\n print('Incorrect')", "n,m,min1,max1=map(int,input().split())\r\na=list(map(int,input().split()))\r\nc=0\r\n\r\nif max1 not in a:\r\n a.append(max1)\r\n c+=1\r\nif min1 not in a:\r\n a.append(min1)\r\n c+=1\r\nif (n-m)>=c and max(a)==max1 and min(a)==min1:\r\n print(\"Correct\")\r\nelse:\r\n print(\"Incorrect\")", "I=lambda:list(map(int,input().split()))\r\nn,m,N,X=I()\r\nt=I()\r\nr=min(t)!=N\r\nr+=max(t)!=X\r\nprint(['C','Inc'][m+r>n or min(t)<N or max(t)>X]+'orrect')", "import sys\nfrom itertools import *\nfrom math import *\nMAX = 10000000\ndef solve():\n n, m, ss, ll = map(int, input().split())\n a = set(map(int, input().split()))\n wantothers = 0\n smallest = 100000000\n largest = -1\n for val in a:\n smallest = min(smallest, val)\n largest = max(largest, val)\n if smallest < ss or largest > ll:\n print(\"Incorrect\")\n return\n if ss not in a: wantothers+=1\n if ll not in a: wantothers+=1\n print(\"Correct\" if wantothers <= n - m else \"Incorrect\")\n\nif sys.hexversion == 50594544 : sys.stdin = open(\"test.txt\")\nsolve()\n", "n, m, v1, v2 = map(int, input().split())\nt = list(map(int, input().split()))\nt1, t2 = min(t), max(t)\nif t1 < v1 or t2 > v2:\n print('Incorrect')\nelif (v1 < t1) + (v2 > t2) > n - m:\n print('Incorrect')\nelse:\n print('Correct')\n", "n,m,mini,maxi = list(map(int,input().split()))\r\nar = list(map(int,input().split()))\r\nminix = min(ar)\r\nmaxix = max(ar)\r\ndiff = n-m\r\nif diff ==1 and ( minix != mini and maxix != maxi):\r\n\tprint(\"Incorrect\")\r\n\texit()\r\n\t\r\n \r\nif minix < mini or maxix > maxi:\r\n\tprint(\"Incorrect\")\r\n\texit()\r\n\t\r\nprint(\"Correct\")", "n,m,mi,ma = map(int, input().split())\r\na = list(map(int,input().split())) #m\r\nif any(list(map(lambda x:x>ma or x<mi, a))):\r\n\tprint(\"Incorrect\")\r\n\texit(0)\r\nc=0\r\nif mi not in a: c+=1\r\nif ma not in a: c+=1\r\nif c<=(n-m):\r\n\tprint(\"Correct\")\r\nelse:\r\n\tprint(\"Incorrect\")", "n, k, s, b = map(int, input().split())\nm = list(map(int, input().split()))\nprint(('Inc' if min(m)<s or max(m)>b or (max(m)!=b)+(min(m)!=s)>n-k else 'C') + 'orrect')\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Jun 19 11:07:51 2017\r\nYL A, recovery\r\n@author: User\r\n\"\"\"\r\na=lambda :list(map(int,input().split()))\r\nm,n,mi,ma=a()\r\ns=a()\r\nse=set(s)\r\ndl=m-n\r\nif max(s)>ma:\r\n print('Incorrect')\r\nelif min(s)<mi:\r\n print('Incorrect')\r\nelse:\r\n if ma not in se:\r\n dl-=1\r\n if mi not in se:\r\n dl-=1\r\n if dl<0:\r\n print('Incorrect')\r\n else:\r\n print('Correct')", "for _ in range(1):\n m, n, min_temp, max_temp = [int(x) for x in input().split()]\n temps = [int(x) for x in input().split()]\n if min(temps) < min_temp:\n print(\"Incorrect\")\n break\n if max(temps) > max_temp:\n print(\"Incorrect\")\n break\n if min_temp in temps and max_temp in temps:\n print(\"Correct\")\n break\n if min_temp not in temps and max_temp not in temps:\n if m - n < 2:\n print(\"Incorrect\")\n else:\n print(\"Correct\")\n break\n if m - n < 1:\n print(\"Incorrect\")\n else:\n print(\"Correct\")\n\t\t \t \t \t\t \t \t \t\t \t\t", "n, m, mmin, mmax = map(int, input().split())\r\ns = list(map(int, input().split()))\r\ns = sorted(s)\r\nif s[0] < mmin or s[m - 1] > mmax:\r\n print(\"Incorrect\")\r\nelif s[0] == mmin and s[m - 1] == mmax:\r\n print(\"Correct\")\r\nelif s[0] != mmin and s[m - 1] != mmax:\r\n if n - m < 2:\r\n print(\"Incorrect\")\r\n else:\r\n print(\"Correct\")\r\nelif s[0] != mmin or s[m - 1] != mmax:\r\n if n - m < 1:\r\n print(\"Incorrect\")\r\n else:\r\n print(\"Correct\")", "x=[int(w) for w in input().split()]\r\nt=[int(e) for e in input().split()]\r\n\r\nif max(t)>x[3]:\r\n print(\"Incorrect\")\r\nelif min(t)<x[2]:\r\n print(\"Incorrect\")\r\nelif (x[0]-x[1]==1) and (min(t)!=x[2] and max(t)!=x[3]):\r\n print(\"Incorrect\")\r\nelse:\r\n print(\"Correct\")" ]
{"inputs": ["2 1 1 2\n1", "3 1 1 3\n2", "2 1 1 3\n2", "3 1 1 5\n3", "3 2 1 5\n1 5", "3 2 1 5\n1 1", "3 2 1 5\n5 5", "3 2 1 5\n1 6", "3 2 5 10\n1 10", "6 5 3 6\n4 4 4 4 4", "100 50 68 97\n20 42 93 1 98 6 32 11 48 46 82 96 24 73 40 100 99 10 55 87 65 80 97 54 59 48 30 22 16 92 66 2 22 60 23 81 64 60 34 60 99 99 4 70 91 99 30 20 41 96", "100 50 1 2\n1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 2 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 2 2 1 2", "100 99 1 2\n2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 2 2 2 1 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 2 2 2", "3 2 2 100\n40 1", "3 2 2 3\n4 4", "5 2 2 4\n2 2", "5 1 1 4\n1", "9 7 1 4\n4 3 3 2 2 4 1", "9 5 2 3\n4 2 4 3 3", "6 3 1 3\n1 4 2", "3 2 1 99\n34 100", "4 2 1 99\n100 38", "5 2 1 99\n100 38", "4 2 1 99\n36 51", "7 6 3 10\n5 10 7 7 4 5", "8 6 3 10\n8 5 7 8 4 4", "9 6 3 10\n9 7 7 5 3 10", "16 15 30 40\n36 37 35 36 34 34 37 35 32 33 31 38 39 38 38", "17 15 30 40\n38 36 37 34 30 38 38 31 38 38 36 39 39 37 35", "18 15 30 40\n35 37 31 32 30 33 36 38 36 38 31 30 39 32 36", "17 16 30 40\n39 32 37 31 40 32 36 34 56 34 40 36 37 36 33 36", "18 16 30 40\n32 35 33 39 34 30 37 34 30 34 39 18 32 37 37 36", "19 16 30 40\n36 30 37 30 37 32 34 30 35 35 33 35 39 37 46 37", "2 1 2 100\n38", "3 1 2 100\n1", "4 1 2 100\n1", "91 38 1 3\n3 2 3 2 3 2 3 3 1 1 1 2 2 1 3 2 3 1 3 3 1 3 3 2 1 2 2 3 1 2 1 3 2 2 3 1 1 2", "4 3 2 10\n6 3 10", "41 6 4 10\n10 7 4 9 9 10", "21 1 1 9\n9", "2 1 9 10\n10", "2 1 2 9\n9", "8 7 5 9\n6 7 8 5 5 6 6", "3 2 2 8\n7 2", "71 36 1 10\n7 10 8 1 3 8 5 7 3 10 8 1 6 4 5 7 8 2 4 3 4 10 8 5 1 2 8 8 10 10 4 3 7 9 7 8", "85 3 4 9\n4 8 7", "4 3 4 10\n9 10 5", "2 1 1 5\n1", "91 75 1 10\n2 6 9 7 4 9 4 8 10 6 4 1 10 6 5 9 7 5 1 4 6 4 8 2 1 3 5 7 6 9 5 5 8 1 7 1 4 2 8 3 1 6 6 2 10 6 2 2 8 5 4 5 5 3 10 9 4 3 1 9 10 3 2 4 8 7 4 9 3 1 1 1 3 4 5", "10 4 1 8\n7 9 6 6", "18 1 3 10\n2", "6 2 4 8\n6 3", "17 6 2 8\n3 8 6 1 6 4", "21 1 5 8\n4", "2 1 1 10\n9", "2 1 4 8\n5", "2 1 1 7\n6", "2 1 4 9\n5", "2 1 3 8\n7", "2 1 5 9\n6", "3 2 1 10\n4 9", "2 1 4 10\n7", "2 1 2 9\n8", "2 1 3 9\n3", "3 2 6 7\n6 6", "6 4 1 10\n11 10 9 1", "7 6 3 8\n3 4 5 6 7 8", "5 3 1 5\n2 3 4"], "outputs": ["Correct", "Correct", "Incorrect", "Correct", "Correct", "Correct", "Correct", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Correct", "Correct", "Incorrect", "Incorrect", "Correct", "Correct", "Correct", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Correct", "Correct", "Correct", "Correct", "Incorrect", "Correct", "Correct", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Correct", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Incorrect", "Correct", "Correct", "Incorrect", "Correct", "Correct"]}
UNKNOWN
PYTHON3
CODEFORCES
38
1b5ef8cfd69d5dc48a7f392e465d3a59
A Colourful Prospect
Firecrackers scare Nian the monster, but they're wayyyyy too noisy! Maybe fireworks make a nice complement. Little Tommy is watching a firework show. As circular shapes spread across the sky, a splendid view unfolds on the night of Lunar New Year's eve. A wonder strikes Tommy. How many regions are formed by the circles on the sky? We consider the sky as a flat plane. A region is a connected part of the plane with positive area, whose bound consists of parts of bounds of the circles and is a curve or several curves without self-intersections, and that does not contain any curve other than its boundaries. Note that exactly one of the regions extends infinitely. The first line of input contains one integer *n* (1<=≤<=*n*<=≤<=3), denoting the number of circles. The following *n* lines each contains three space-separated integers *x*, *y* and *r* (<=-<=10<=≤<=*x*,<=*y*<=≤<=10, 1<=≤<=*r*<=≤<=10), describing a circle whose center is (*x*,<=*y*) and the radius is *r*. No two circles have the same *x*, *y* and *r* at the same time. Print a single integer — the number of regions on the plane. Sample Input 3 0 0 1 2 0 1 4 0 1 3 0 0 2 3 0 2 6 0 2 3 0 0 2 2 0 2 1 1 2 Sample Output 4 6 8
[ "from math import sqrt\r\ndef pt(x):\r\n print(x)\r\nrd = lambda: map(int, input().split())\r\nn = int(input())\r\ndef f(x1, y1, r1, x2, y2, r2):\r\n a = (r1 + r2) ** 2\r\n b = (r1 - r2) ** 2\r\n d = (x1 - x2) ** 2 + (y1 - y2) ** 2\r\n if d > a:\r\n return 1\r\n elif d == a:\r\n return 4\r\n elif d < b:\r\n return 3\r\n elif d == b:\r\n return 5\r\n else:\r\n return 2\r\ndef g(x1, y1, r1, x2, y2, r2):\r\n ds = (x1 - x2) ** 2 + (y1 - y2) ** 2\r\n d = sqrt(ds)\r\n A = (r1 ** 2 - r2 ** 2 + ds) / (2 * d)\r\n h = sqrt(r1 ** 2 - A ** 2)\r\n x = x1 + A * (x2 - x1) / d \r\n y = y1 + A * (y2 - y1) / d\r\n x3 = x - h * (y2 - y1) / d \r\n y3 = y + h * (x2 - x1) / d\r\n x4 = x + h * (y2 - y1) / d \r\n y4 = y - h * (x2 - x1) / d\r\n return x3, y3, x4, y4 \r\nif n is 1:\r\n pt(2)\r\nif n is 2:\r\n x1, y1, r1 = rd()\r\n x2, y2, r2 = rd()\r\n a = f(x1, y1, r1, x2, y2, r2)\r\n pt(4 if a is 2 else 3)\r\nif n is 3:\r\n x1, y1, r1 = rd()\r\n x2, y2, r2 = rd()\r\n x3, y3, r3 = rd()\r\n a = f(x1, y1, r1, x2, y2, r2)\r\n b = f(x1, y1, r1, x3, y3, r3)\r\n c = f(x3, y3, r3, x2, y2, r2)\r\n t = [a, b, c]\r\n t.sort()\r\n a, b, c = t\r\n if a is 1 and b is 1 and c in [1, 3, 4, 5]:\r\n pt(4)\r\n if a is 1 and b is 1 and c is 2:\r\n pt(5)\r\n if a is 1 and b is 2 and c is 2:\r\n pt(6)\r\n if a is 1 and b is 2 and c in [3, 4, 5]:\r\n pt(5)\r\n if a is 1 and b in [3, 4, 5]:\r\n pt(4)\r\n if a is 2 and b is 2 and c is 2:\r\n x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2)\r\n r = 8\r\n if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6:\r\n r -= 1\r\n if abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6:\r\n r -= 1\r\n pt(r)\r\n if a is 2 and b is 2 and c is 3:\r\n pt(6)\r\n if a is 2 and b is 2 and c in [4, 5]:\r\n x4, y4, x5, y5 = g(x1, y1, r1, x2, y2, r2)\r\n if abs((x4 - x3) ** 2 + (y4 - y3) ** 2 - r3 ** 2) < 1e-6 or abs((x5 - x3) ** 2 + (y5 - y3) ** 2 - r3 ** 2) < 1e-6:\r\n pt(6)\r\n else:\r\n pt(7)\r\n if a is 2 and b is 3:\r\n pt(5)\r\n if a is 2 and b in [4, 5]:\r\n pt(6)\r\n if a is 3 and b in [3, 4, 5]:\r\n pt(4)\r\n if a is 4 and b is 4 and c is 4:\r\n pt(5)\r\n if a is 4 and b is 4 and c is 5:\r\n pt(4)\r\n if a is 4 and b is 5 and c is 5:\r\n pt(5)\r\n if a is 5 and b is 5 and c is 5:\r\n pt(4)" ]
{"inputs": ["3\n0 0 1\n2 0 1\n4 0 1", "3\n0 0 2\n3 0 2\n6 0 2", "3\n0 0 2\n2 0 2\n1 1 2", "1\n0 0 10", "2\n-10 10 1\n10 -10 1", "2\n-6 6 9\n3 -6 6", "2\n-10 -10 10\n10 10 10", "3\n-4 1 5\n-7 7 10\n-3 -4 8", "3\n-2 8 10\n3 -2 5\n3 1 3", "3\n0 0 2\n0 0 4\n3 0 2", "3\n8 5 7\n7 3 7\n5 2 5", "3\n-6 5 7\n1 -2 7\n7 9 7", "3\n1 -7 10\n-7 9 10\n-2 -1 4", "3\n-2 -3 5\n-6 1 7\n5 4 5", "3\n3 -2 7\n-1 2 5\n-4 1 3", "3\n4 5 10\n1 -1 5\n-1 -5 5", "3\n-1 0 5\n-2 1 5\n-5 4 7", "3\n-3 3 5\n1 -1 7\n2 5 10", "3\n-4 4 3\n5 6 4\n1 -5 9", "3\n-4 4 4\n2 4 2\n-1 0 6", "3\n-10 4 10\n10 4 10\n0 -7 10", "3\n-4 -5 3\n-3 -4 1\n-6 0 9", "3\n4 0 1\n-1 1 9\n0 3 6", "3\n-3 -2 3\n-4 -6 3\n-6 -4 9", "3\n-3 6 4\n-1 4 7\n0 2 1", "3\n1 -1 2\n-6 -3 10\n-1 3 1", "3\n-2 -5 4\n-5 -1 5\n-6 -2 9", "3\n5 -2 3\n1 1 2\n4 -3 7", "3\n2 -6 3\n-2 0 1\n1 -4 6", "3\n-1 -2 3\n-5 -4 4\n-6 -5 8", "3\n-1 3 4\n-2 0 8\n3 6 1", "3\n-4 -1 2\n-6 -5 10\n1 3 1", "3\n-6 2 1\n0 -6 9\n-5 -3 2", "3\n-4 -5 4\n6 5 2\n-6 -6 7", "3\n-5 -2 3\n-1 1 8\n-4 -3 1", "3\n-3 -1 8\n0 3 3\n2 2 2", "3\n3 4 9\n2 -3 1\n-1 1 4", "3\n-5 -6 5\n-2 -2 10\n-3 4 3", "3\n2 6 5\n1 -1 5\n-2 3 10", "3\n3 -5 5\n-1 -2 10\n-5 1 5", "3\n0 0 6\n-4 -3 1\n-3 4 1", "3\n-5 -2 10\n3 -1 3\n-1 1 5", "3\n-1 -1 10\n-5 2 5\n1 -6 5", "3\n-4 1 1\n-2 -6 7\n-6 -3 2", "3\n3 -4 2\n-1 -1 3\n-5 2 8", "3\n6 -1 1\n1 1 4\n-2 5 9", "3\n2 -6 1\n-6 5 8\n-2 2 3", "3\n-6 -6 8\n-4 -5 1\n-1 -4 6", "3\n-4 -5 7\n2 -3 6\n-2 0 1", "3\n1 -5 1\n4 -3 3\n-6 -6 10", "3\n2 -1 4\n-1 -5 1\n-5 0 9", "3\n-6 -6 9\n4 -3 4\n-3 -1 1", "3\n-4 -2 7\n-6 -1 7\n-3 -5 2", "3\n2 -2 8\n6 -5 3\n3 -1 8", "3\n-3 1 4\n-1 6 9\n-6 5 9", "3\n-4 -1 5\n-1 3 10\n4 5 5", "3\n-2 2 3\n0 -6 3\n-6 -1 8", "3\n-1 -3 9\n0 -2 7\n-6 -6 10", "3\n-5 -6 8\n-2 -1 7\n1 -5 2", "3\n-5 3 4\n1 4 4\n-6 -6 10", "3\n6 2 6\n-6 5 7\n-2 -4 4", "3\n5 2 4\n-3 6 4\n-6 -6 10", "3\n5 -5 1\n-3 1 9\n2 -6 6", "3\n1 6 4\n4 2 9\n-4 -6 9", "3\n-6 -4 9\n0 4 1\n-1 3 1", "3\n-3 -6 4\n1 -3 1\n-2 1 4", "3\n-4 0 6\n-3 -6 6\n4 6 4", "3\n6 -5 1\n3 1 9\n-6 -6 9", "3\n-5 -6 7\n-6 0 6\n-2 3 1", "3\n-6 -6 9\n6 -5 3\n-5 -1 9", "3\n2 -5 2\n-5 -6 3\n-2 -2 3", "3\n-6 -6 9\n6 -4 1\n-3 -2 8", "3\n-6 -2 1\n-3 -1 1\n-2 1 4", "3\n5 -2 6\n-1 6 4\n2 2 1", "3\n2 1 2\n-6 -1 6\n6 4 7", "3\n0 4 4\n-6 -4 6\n-4 -2 4", "3\n5 -6 6\n-3 0 4\n-4 6 9", "3\n2 4 4\n3 -6 4\n-4 -4 6", "3\n6 -3 6\n2 0 1\n-6 6 9", "3\n-6 6 9\n6 1 4\n2 0 1", "3\n0 -5 2\n-6 3 2\n-3 -1 3", "3\n5 -4 1\n3 -5 5\n-3 3 5", "3\n1 3 1\n2 -6 7\n-3 6 6", "3\n-3 -4 2\n-6 -2 2\n0 0 3", "3\n-6 -2 7\n5 0 2\n2 4 3", "3\n-6 6 4\n-2 3 1\n-1 -3 1", "3\n-1 -5 2\n-6 -6 9\n4 4 5", "3\n-5 3 6\n4 -3 2\n-2 -1 1", "3\n-1 5 6\n-3 -4 5\n-6 -6 6", "3\n-2 -5 3\n1 -1 2\n-3 4 6", "3\n-6 -6 7\n1 4 2\n0 -5 2", "3\n-5 3 5\n5 -2 6\n-3 4 4", "3\n-2 0 2\n1 4 3\n-6 3 3", "3\n-4 3 4\n0 0 1\n-5 -4 3", "3\n2 5 4\n-6 -6 7\n1 6 6", "3\n-6 -6 8\n5 6 8\n2 2 3", "3\n6 1 2\n-6 -6 7\n5 -1 2", "3\n1 6 4\n-3 -6 5\n4 2 1", "3\n-5 5 4\n2 3 3\n-6 -6 7", "3\n-6 5 2\n-6 -1 4\n2 5 6", "3\n2 -2 5\n2 0 3\n2 -1 4", "3\n4 -3 8\n3 -3 7\n-3 -3 1", "3\n2 0 2\n4 0 4\n0 -4 4", "3\n-1 0 5\n5 0 5\n5 8 5", "3\n1 0 1\n-1 0 1\n0 1 1", "3\n2 0 2\n4 0 4\n0 -4 5", "3\n2 0 2\n4 0 4\n0 -4 3", "3\n2 0 2\n4 0 4\n0 -4 2", "3\n2 0 2\n4 0 4\n0 -4 8", "3\n-9 0 9\n-9 10 10\n9 4 10", "3\n-9 10 10\n9 4 10\n0 -2 6", "3\n9 5 10\n8 -2 9\n-9 -1 9", "3\n-4 -2 9\n8 4 9\n-10 10 10", "3\n1 8 2\n3 8 1\n3 -2 9", "3\n0 0 1\n0 3 2\n4 0 3", "3\n-3 0 5\n3 0 5\n0 0 4", "3\n4 1 5\n-4 1 5\n0 0 4", "3\n0 0 1\n0 1 1\n0 2 1", "3\n0 0 5\n1 7 5\n7 7 5", "2\n0 0 2\n3 0 2", "3\n0 0 2\n1 0 1\n-1 0 1", "3\n-2 0 2\n2 0 2\n0 0 4", "3\n3 4 5\n-3 4 5\n0 -5 5", "3\n0 0 1\n1 0 1\n2 0 1", "3\n2 2 4\n8 2 4\n5 10 5", "3\n0 0 5\n4 0 3\n8 0 5", "3\n0 0 1\n2 0 3\n-2 0 3", "3\n0 0 1\n2 0 1\n1 0 2", "3\n0 0 5\n8 0 5\n4 0 3", "3\n-10 0 2\n-8 2 2\n-4 -3 5"], "outputs": ["4", "6", "8", "2", "3", "3", "3", "8", "8", "6", "8", "8", "8", "7", "7", "6", "6", "7", "6", "7", "7", "4", "4", "5", "4", "4", "5", "4", "4", "6", "5", "5", "4", "4", "4", "5", "4", "4", "6", "5", "4", "7", "6", "5", "4", "4", "4", "5", "5", "6", "5", "5", "5", "6", "7", "6", "5", "6", "7", "8", "7", "6", "5", "6", "7", "6", "5", "5", "5", "6", "5", "5", "4", "4", "4", "7", "6", "5", "4", "6", "4", "4", "4", "5", "4", "4", "4", "4", "6", "5", "5", "5", "4", "4", "4", "4", "5", "4", "4", "5", "4", "4", "6", "6", "6", "7", "7", "5", "5", "8", "8", "8", "8", "7", "5", "6", "7", "7", "7", "4", "5", "5", "7", "7", "8", "6", "6", "5", "6", "7"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1b67757cd76a83e0896376acaf8af9eb
Vacations
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Sample Input 4 1 3 2 0 7 1 3 3 2 1 2 3 2 2 2 Sample Output 2 0 1
[ "n=int(input())\r\ndp=[[0 for i in range(3)]for j in range(n+1)]\r\nar=tuple(map(str,input().split()))\r\nfor i in range(1,n+1):\r\n x=ar[i-1]\r\n dp[i][0]=min(dp[i-1])+1 \r\n if(x=='1' or x=='3'):\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n else:\r\n dp[i][1]=dp[i-1][1]+1 \r\n if(x=='2' or x=='3'):\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1]) \r\n else:\r\n dp[i][2]=dp[i-1][2]+1 \r\n \r\nprint(min(dp[-1]))\r\n ", "from calendar import calendar\r\n\r\n\r\ndef List():\r\n return list(map(int,input().split()))\r\ndef Lst():\r\n return list(input())\r\ndef Int():\r\n return int(input())\r\ndef two():\r\n return map(int,input().split())\r\n\r\nnumOfVactions = Int()\r\ncalendar = List()\r\n\r\noutPut = 0\r\nprevState = 0\r\nfor currState in calendar:\r\n if currState == 3:\r\n prevState = currState - prevState\r\n elif currState == 0 or currState == prevState:\r\n outPut +=1\r\n prevState = 0\r\n else: \r\n prevState = currState\r\n\r\nprint(outPut)\r\n", "n = int(input())\r\nact = [int(i) for i in input().split()]\r\nrest = 0\r\ncurr = 0\r\nfor e in act:\r\n if e == 0:\r\n rest += 1\r\n curr = 0\r\n elif e == 1:\r\n if curr == 0 or curr == 1:\r\n curr = -1\r\n else:\r\n rest += 1\r\n curr = 0\r\n elif e == 2:\r\n if curr == 0 or curr == -1:\r\n curr = 1\r\n else:\r\n rest += 1\r\n curr = 0\r\n else:\r\n if curr == 0:\r\n continue\r\n else:\r\n curr *= -1\r\nprint(rest)\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\n\r\ndp = [[10**10] * 3 for i in range(n+1)]\r\ndp[0][0] = 0\r\ndp[0][1] = 0\r\ndp[0][2] = 0\r\n\r\nfor i in range(1, n+1):\r\n if a[i-1] == 0:\r\n dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1\r\n elif a[i-1] == 1:\r\n dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n elif a[i-1] == 2:\r\n dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n else:\r\n dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n\r\nprint(min(dp[n][0], dp[n][1], dp[n][2]))", "from collections import deque\r\nn = int(input())\r\nA = list(map(int, input().split()))\r\nanswer = 0\r\nt = 0\r\nanswer = 0\r\nfor i in range(n):\r\n if A[i] == 0:\r\n t = 0\r\n elif A[i] == 1:\r\n if t != 1:\r\n answer +=1\r\n t = 1\r\n else:\r\n t = 0\r\n elif A[i] == 2:\r\n if t!=2:\r\n answer +=1\r\n t = 2\r\n else:\r\n t = 0\r\n else:\r\n if t == 1:\r\n t = 2\r\n answer+=1\r\n elif t == 2:\r\n t = 1\r\n answer +=1\r\n else:\r\n t = 0\r\n answer+=1\r\nprint(n-answer)", "n = int(input())\r\ns = [0] + list(map(int, input().split()))\r\n\r\ndp = [[0] * (n + 1) for _ in range(3)]\r\n\r\nfor i in range(1, n + 1):\r\n dp[0][i] = min(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]) + 1\r\n dp[1][i] = dp[1][i - 1] + 1\r\n dp[2][i] = dp[2][i - 1] + 1\r\n if s[i] == 0:\r\n dp[0][i] = min(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]) + 1\r\n \r\n elif s[i] == 1:\r\n dp[2][i] = min(dp[1][i - 1], dp[0][i - 1])\r\n \r\n elif s[i] == 2:\r\n dp[1][i] = min(dp[2][i - 1], dp[0][i - 1])\r\n \r\n else:\r\n dp[2][i] = min(dp[1][i - 1], dp[0][i - 1])\r\n dp[1][i] = min(dp[2][i - 1], dp[0][i - 1])\r\n \r\nminim = 10000000000\r\n\r\nfor i in range(3):\r\n minim = min(dp[i][n], minim)\r\n\r\n\r\nprint(minim)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nlp, ls, lo = [0, 1], [0, 1], 0\r\nfor i in range(n):\r\n if a[i] == 0:\r\n lo = max(lo, lp[0]*lp[1], ls[0]*ls[1])\r\n ls[1], lp[1] = 0, 0\r\n elif a[i] == 1:\r\n lo, lp = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, ls[0] * ls[1]), 1]\r\n ls[1], lp[1] = 0, 1\r\n elif a[i] == 2:\r\n lo, ls = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, lp[0] * lp[1]), 1]\r\n ls[1], lp[1] = 1, 0\r\n else:\r\n lo, ls, lp = max(lo, lp[0] * lp[1], ls[0] * ls[1]), [1 + max(lo, lp[0] * lp[1]), 1], [1 + max(lo, ls[0] * ls[1]), 1]\r\n ls[1], lp[1] = 1, 1\r\nprint(n-max(lo, ls[0], lp[0]))", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndp = [[0,0,0] for _ in range(n)]\r\n\r\nfor i in range(n):\r\n \r\n dp[i][0] = max(dp[i-1])\r\n dp[i][1] = max(dp[i-1][0], dp[i-1][2])\r\n dp[i][2] = max(dp[i-1][0], dp[i-1][1])\r\n\r\n if a[i] == 1:\r\n dp[i][2]+=1\r\n elif a[i] == 2:\r\n dp[i][1]+=1\r\n elif a[i] == 3:\r\n dp[i][1]+=1\r\n dp[i][2]+=1\r\n \r\nprint(n-max(dp[-1]))", "def waiting(lst):\r\n v=[0]\r\n v+=lst\r\n dp=[]\r\n inf=1000000000000000000\r\n n=len(lst)\r\n for i in range(1,n+2):\r\n tmp=[]\r\n for j in range(3):\r\n tmp.append(inf)\r\n dp.append(tmp)\r\n dp[0][2]=0\r\n #print(dp)\r\n for i in range(1,n+1):\r\n for j in range(3):\r\n if dp[i-1][j]!=inf:\r\n if (v[i]&1) and j!=0:\r\n dp[i][0]=min(dp[i][0], dp[i-1][j])\r\n if (v[i]&2) and j!=1:\r\n dp[i][1]=min(dp[i][1], dp[i-1][j])\r\n dp[i][2]=min(dp[i][2], dp[i-1][j]+1)\r\n ans=min(dp[n][0],dp[n][1],dp[n][2])\r\n return ans\r\n\r\nn=input()\r\nlst=list(map(int,input().split()))\r\nprint(waiting(lst))\r\n", "import sys\ninput = sys.stdin.readline\nn = int(input())\na = list(map(int,input().split()))\ndp = [[0 for i in range(3)] for j in range(n)]\ndp[0][0] = 0\nif a[0]==1 or a[0]==3:\n\tdp[0][1] = 1\nif a[0]==2 or a[0]==3:\n\tdp[0][2] = 1\nfor i in range(1,n):\n\tdp[i][0] = max(dp[i-1])\n\tif a[i]==1 or a[i]==3:\n\t\tdp[i][1] = max(dp[i-1][0],dp[i-1][2])+1\n\tif a[i]==2 or a[i]==3:\n\t\tdp[i][2] = max(dp[i-1][0],dp[i-1][1])+1\n\nm = 0\nfor i in dp:\n\t# print (*i)\n\tm = max(m,max(i))\nprint (n-m)", "def main():\r\n N = int(input())\r\n A = list(map(int, input().split()))\r\n A = [-1] + A\r\n dp = [[0, 0, 0]] + [[1e10] * 3 for _ in range(N)]\r\n\r\n for i in range(1, N + 1):\r\n dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1\r\n\r\n if A[i] == 1 or A[i] == 3:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n\r\n if A[i] == 2 or A[i] == 3:\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n\r\n print(min(dp[N][0], dp[N][1], dp[N][2]))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "input()\r\np = 3\r\nc = 0\r\nfor i in list(map(int, input().split())):\r\n if i == p and p != 3:\r\n i = 0\r\n elif i==3 and p!=3:\r\n i -= p\r\n if i == 0:\r\n c += 1\r\n p = i\r\nprint(c)\r\n\r\nquit()\r\n", "n = int(input())\r\na = [int(i) for i in input().split()]\r\n\r\ndp = [[0]*(n+1), [0]*(n+1), [0]*(n+1)]\r\nINF = 1e9\r\n\r\n\r\nfor i in range(1, n + 1):\r\n dp[0][i] = min(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]) + 1\r\n\r\n if a[i - 1] == 0:\r\n dp[1][i] = INF\r\n dp[2][i] = INF\r\n elif a[i - 1] == 1:\r\n dp[1][i] = min(dp[0][i - 1], dp[2][i - 1])\r\n dp[2][i] = INF\r\n elif a[i - 1] == 2:\r\n dp[1][i] = INF\r\n dp[2][i] = min(dp[0][i - 1], dp[1][i - 1])\r\n elif a[i - 1] == 3:\r\n dp[1][i] = min(dp[0][i - 1], dp[2][i - 1])\r\n dp[2][i] = min(dp[0][i - 1], dp[1][i - 1])\r\n\r\nprint(min(dp[0][n], dp[1][n], dp[2][n]))", "input()\na1 = a2 = z = 0\nfor b in map(int, input()[::2]):\n if 0 < b < 3:\n if a1 == a2 == b:\n a1 = a2 = 0\n z += 1\n else:\n a1 = a2 = b\n elif b: # 3\n a1 = 2 if a1 == 1 else 1\n a2 = 1 if a2 == 2 else 2\n else: # 0\n a1 = a2 = 0\n z += 1\nprint(z)", "n = int(input())\nstring = input().split(\" \")\nresult = []\nresult.append([0, 0, 0])\nfor i in range(n):\n tmp = []\n tmp.append(min(result[i]) + 1)\n if (string[i] == '0' or string[i] == '1'):\n tmp.append(2147483647)\n else:\n tmp.append(min([result[i][0], result[i][2]]))\n if (string[i] == '0' or string[i] == '2'):\n tmp.append(2147483647)\n else:\n tmp.append(min([result[i][0], result[i][1]]))\n result.append(tmp)\n#print(result)\nprint(min(result[n]))", "if __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().strip().split()))\r\n INF = float(\"inf\")\r\n dp = [[INF] * 3 for _ in range(n + 1)]; dp[0][0] = 0\r\n for i in range(n):\r\n dp[i + 1][0] = min(dp[i][0], dp[i][1], dp[i][2]) + 1\r\n if a[i] == 1:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n elif a[i] == 2:\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1])\r\n elif a[i] == 3:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1])\r\n print(min(dp[n]))", "#0 faz nada\n#1 = contest\n#2 = ginasio\n#3 = ginasio ou contest\na = int(input())\nlista = list(map(int, input().split()))\ndescanso = 0\nante = 3\n\nfor dia in lista:\n if ante != 3:\n if dia == ante:\n dia = 0\n elif dia == 3:\n dia -= ante\n if dia == 0:\n descanso +=1\n ante = dia\n\nprint(descanso)\n\n", "n=int(input())\r\nx=list(map(int,input().split()))\r\nr=[[0]*n for _ in [0,1,2]]\r\nif x[0]&1==1: r[1][0]=1\r\nif x[0]&2==2: r[2][0]=1\r\nfor i in range(1,n):\r\n r[0][i]=max(r[0][i-1],r[1][i-1],r[2][i-1])\r\n if x[i]&1==1: r[1][i]=max(r[0][i-1],r[2][i-1])+1\r\n if x[i]&2==2: r[2][i]=max(r[0][i-1],r[1][i-1])+1\r\nprint(n-max(r[0][n-1],r[1][n-1],r[2][n-1]))\r\n", "n = int(input())\r\ns = list(map(int, input().split()))\r\nif s[0] == 0 :\r\n dp = [[0], [0], [0]]\r\nelif s[0] == 1 :\r\n dp = [[0], [1], [0]]\r\nelif s[0] == 2 :\r\n dp = [[0], [0], [1]]\r\nelse :\r\n dp = [[0], [1], [1]]\r\nfor i in range(1, n):\r\n dp[0].append(0)\r\n dp[1].append(0)\r\n dp[2].append(0)\r\n if s[i] == 0 :\r\n dp[0][i] = max(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1])\r\n dp[1][i] = 0 \r\n dp[2][i] = 0\r\n if s[i] == 1 :\r\n dp[0][i] = max(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1])\r\n dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + 1\r\n dp[2][i] = 0\r\n if s[i] == 2 :\r\n dp[0][i] = max(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1])\r\n dp[1][i] = 0\r\n dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + 1\r\n if s[i] == 3 :\r\n dp[0][i] = max(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1])\r\n dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + 1\r\n dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + 1\r\nprint(n - max(dp[0][n - 1], dp[1][n - 1], dp[2][n - 1]))\r\n", "from math import inf\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nf = [[inf]*3 for _ in range(n+1)] #第i天休息、比赛、健身的最少休息天数\r\nf[0] = [0, 0, 0]\r\n\r\nfor i, x in enumerate(a):\r\n f[i+1][0] = min(f[i])+1\r\n if x == 1 or x == 3:\r\n f[i+1][1] = min(f[i][0], f[i][2])\r\n if x == 2 or x == 3:\r\n f[i+1][2] = min(f[i][0], f[i][1])\r\nprint(min(f[n]))", "numDays = int(input())\r\nactivitySeq = list(map(int, input().split()))\r\n\r\ndp = [ [0]*3 for i in range(numDays + 1)]\r\n\r\nfor i in range(1, numDays + 1):\r\n if activitySeq[i - 1] == 0:\r\n minn = min(dp[i - 1])\r\n for j in range(3):\r\n dp[i][j] = minn + 1\r\n elif activitySeq[i - 1] == 3:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n elif activitySeq[i - 1] == 1:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n dp[i][1] = min(dp[i - 1]) + 1\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n elif activitySeq[i - 1] == 2:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n dp[i][2] = min(dp[i - 1]) + 1\r\n\r\nprint(min(dp[numDays]))", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nb = c = d = 0\r\n\r\nfor i in a:\r\n e, f, g = b, c, d\r\n d = min(e, f, g)+1\r\n if i == 0:\r\n c = 10**5\r\n b = 10**5\r\n if i == 1:\r\n c = 10**5\r\n b = min(f, g)\r\n if i == 2:\r\n b = 10**5\r\n c = min(e, g)\r\n if i == 3:\r\n b = min(f, g)\r\n c = min(e, g)\r\nprint(min(b, c, d))\r\n \r\n\r\n\r\n \r\n\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nc=0\r\nfor i in range(0,n-1):\r\n if i>0:\r\n if l[i]==3:\r\n if l[i-1]==1:\r\n l[i]=2\r\n if l[i+1]==2:\r\n c=c+1\r\n l[i+1]=-1\r\n elif l[i-1]==2:\r\n l[i]=1\r\n if l[i+1]==1:\r\n c=c+1\r\n l[i+1]=-1\r\n if l[i] == 1 and l[i + 1] == 1:\r\n c = c + 1\r\n l[i + 1] = -1\r\n elif l[i] == 2 and l[i + 1] == 2:\r\n c = c + 1\r\n l[i + 1] = -1\r\n elif l[i] == 0:\r\n c = c + 1\r\n\r\n\r\nif l[n-1]==0:\r\n c=c+1\r\n\r\n\r\nprint(c)\r\n", "a=int(input())\r\ns=input()\r\nA=[0,0,0]\r\nfor i in range(0,2*a-1,2):\r\n b=int(s[i])\r\n if b==0:A=[max(A),0,0]\r\n elif b==1:A=[max(A),max(A[0],A[2])+1,0]\r\n elif b==2:A=[max(A),0,max(A[0],A[1])+1]\r\n else:A=[max(A),max(A[0],A[2])+1,max(A[0],A[1])+1]\r\nprint(a-max(A))\r\n", "n = int(input())\na = list(map(int, input().split(' ')))\n\nd = [[0 for i in range(3)] for j in range(n+1)]\nmind = 0\nposd = 0\nfor i, ai in enumerate(a):\n if ai == 0:\n d[i+1][0] = mind + 1\n d[i+1][1] = mind + 1\n d[i+1][2] = mind + 1\n\n if d[i+1][0] <= d[i+1][1] and d[i+1][0] <= d[i+1][2]:\n mind = d[i+1][0]\n posd = 0\n elif d[i+1][1] < d[i+1][0] and d[i+1][1] < d[i+1][2]:\n mind = d[i+1][1]\n posd = 1\n elif d[i+1][2] < d[i+1][0] and d[i+1][2] < d[i+1][1]:\n mind = d[i+1][2]\n posd = 2\n else:\n mind = d[i+1][2]\n posd = 3\n\n continue\n\n if ai == 1:\n d[i+1][0] = mind + 1\n if posd == 1:\n d[i+1][1] = mind + 1\n else:\n d[i+1][1] = mind\n\n d[i+1][2] = mind + 1\n\n if d[i+1][0] <= d[i+1][1] and d[i+1][0] <= d[i+1][2]:\n mind = d[i+1][0]\n posd = 0\n elif d[i+1][1] < d[i+1][0] and d[i+1][1] < d[i+1][2]:\n mind = d[i+1][1]\n posd = 1\n elif d[i+1][2] < d[i+1][0] and d[i+1][2] < d[i+1][1]:\n mind = d[i+1][2]\n posd = 2\n else:\n mind = d[i+1][2]\n posd = 4\n\n continue\n\n if ai == 2:\n d[i+1][0] = mind + 1\n d[i+1][1] = mind + 1\n\n if posd == 2:\n d[i+1][2] = mind + 1\n else:\n d[i+1][2] = mind\n\n if d[i+1][0] <= d[i+1][1] and d[i+1][0] <= d[i+1][2]:\n mind = d[i+1][0]\n posd = 0\n elif d[i+1][1] < d[i+1][0] and d[i+1][1] < d[i+1][2]:\n mind = d[i+1][1]\n posd = 1\n elif d[i+1][2] < d[i+1][0] and d[i+1][2] < d[i+1][1]:\n mind = d[i+1][2]\n posd = 2\n else:\n mind = d[i+1][2]\n posd = 4\n\n continue\n\n if ai == 3:\n d[i+1][0] = mind + 1\n if posd == 1:\n d[i+1][1] = mind + 1\n else:\n d[i+1][1] = mind\n if posd == 2:\n d[i+1][2] = mind + 1\n else:\n d[i+1][2] = mind\n\n if d[i+1][0] <= d[i+1][1] and d[i+1][0] <= d[i+1][2]:\n mind = d[i+1][0]\n posd = 0\n elif d[i+1][1] < d[i+1][0] and d[i+1][1] < d[i+1][2]:\n mind = d[i+1][1]\n posd = 1\n elif d[i+1][2] < d[i+1][0] and d[i+1][2] < d[i+1][1]:\n mind = d[i+1][2]\n posd = 2\n else:\n mind = d[i+1][2]\n posd = 4\n\n continue\n\nprint(min(d[-1][0], d[-1][1], d[-1][2]))\n", "n = int(input())\nl = list(map(int, input().split()))\ncur = ans = 0\nfor a in l:\n if a == 0:\n ans += 1\n cur = 0\n elif a == 1:\n if cur in (0, 1):\n cur = 2\n else:\n ans += 1\n cur = 0\n elif a == 2:\n if cur in (0, 2):\n cur = 1\n else:\n ans += 1\n cur = 0\n else:\n cur = [0, 2, 1][cur]\nprint(ans)", "# Codeforces Round #363 (Div. 2)\r\n# problem: (C)\r\n# Vacations\r\n# Accepted\r\n\r\nnb_days = int(input())\r\nprevious, restday = 0, 0\r\njobs = [int(x) for x in input().split()]\r\nfor i in jobs:\r\n if i == 0:\r\n restday += 1\r\n previous = 0\r\n elif i == 3:\r\n previous = 3 - previous\r\n else:\r\n if previous == i:\r\n restday += 1\r\n previous = 0\r\n else:\r\n previous = i\r\nprint(restday)\r\n\r\n", "def min_rest_days(days):\r\n \r\n cache = {-1: [0, 0, 0]}\r\n \r\n for i in range(len(days)):\r\n prev_cache = cache[i-1]\r\n \r\n if days[i] == 0:\r\n cache[i] = [float('inf'),\r\n float('inf'),\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n \r\n elif days[i] == 1:\r\n if i > 0 and days[i] == days[i-1]:\r\n prev_min = prev_cache[2]\r\n else:\r\n prev_min = min(prev_cache[0], prev_cache[2])\r\n cache[i] = [float('inf'),\r\n prev_min,\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n \r\n elif days[i] == 2:\r\n if i > 0 and days[i] == days[i-1]:\r\n prev_min = prev_cache[2]\r\n else:\r\n prev_min = min(prev_cache[1], prev_cache[2])\r\n cache[i] = [prev_min,\r\n float('inf'),\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n \r\n elif days[i] == 3:\r\n first = min(prev_cache[1], prev_cache[2])\r\n second = min(prev_cache[0], prev_cache[2])\r\n if i > 0:\r\n if days[i-1] == 1:\r\n second = prev_cache[2]\r\n elif days[i-1] == 2:\r\n first = prev_cache[2]\r\n cache[i] = [first,\r\n second,\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n \r\n return min(cache[len(days) - 1])\r\n \r\n \r\nif __name__ == '__main__':\r\n _ = input()\r\n days = [int(el) for el in input().split()]\r\n print(min_rest_days(days))", "n=int(input())\r\narray=list(map(int,input().split()))\r\nans=[]\r\ni=0\r\ns=0\r\nlast=4\r\nwhile i<n:\r\n if array[i]==0:\r\n s+=1\r\n last=0\r\n elif array[i]==3:\r\n if last==1 or last==2:\r\n last=3-last\r\n elif array[i]==1:\r\n if last==1:\r\n s+=1\r\n last=0\r\n else:\r\n last=1\r\n else:\r\n if last==2:\r\n s+=1\r\n last=0\r\n else:\r\n last=2\r\n i+=1\r\nprint(s)\r\n", "from math import inf \r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n f = [[inf]*3 for i in range(n+1)]\r\n f[0] = [0] * 3\r\n\r\n\r\n for i in range(1, n+1):\r\n if a[i-1] == 1:\r\n f[i][1] = min(f[i-1][0], f[i-1][2])\r\n elif a[i-1] == 2:\r\n f[i][2] = min(f[i-1][0], f[i-1][1])\r\n elif a[i-1] == 3:\r\n f[i][1] = min(f[i-1][0], f[i-1][2])\r\n f[i][2] = min(f[i-1][0], f[i-1][1])\r\n f[i][0] = min(f[i-1][0], f[i-1][1], f[i-1][2]) + 1\r\n \r\n res = min(f[n])\r\n print(res)", "n=int(input())\r\na=list(map(int,input().split()))\r\nans=0\r\ngym=False\r\ncontest=False\r\nfor i in range(n):\r\n if a[i]==0:\r\n ans+=1\r\n gym=False\r\n contest=False\r\n elif a[i]==1:\r\n if contest==True:\r\n ans+=1\r\n contest=False\r\n gym=False\r\n else:\r\n contest=True\r\n gym=False\r\n elif a[i]==2:\r\n if gym==True:\r\n ans+=1\r\n contest = False\r\n gym = False\r\n else:\r\n contest=False\r\n gym=True\r\n else:\r\n if gym==True and contest==False:\r\n contest=True\r\n gym=False\r\n elif gym==False and contest==True:\r\n contest=False\r\n gym=True\r\n else:\r\n pos=i+1\r\n if pos==n:\r\n break\r\n else:\r\n if a[pos]==0:\r\n gym=True\r\n contest=False\r\n elif a[pos]==1:\r\n gym=True\r\n contest=False\r\n elif a[pos]==2:\r\n contest=True\r\n gym=False\r\nprint(ans)", "from math import inf\r\nt=int(input())\r\nl=list(map(int,input().split()))\r\n\r\ndef fdp(t,k):\r\n dp=[[inf for i in range(3)] for j in range(t)]\r\n # dp[day][0] rest \r\n # dp[day][1] contest\r\n # dp[day][2] gym\r\n # Preset values to avoid errors: \r\n dp[0][0]=1\r\n if k[0]==1:\r\n dp[0][1]=0\r\n dp[0][2]=inf\r\n if k[0]==2:\r\n dp[0][2]=0\r\n dp[0][1]=inf\r\n if k[0]==3:\r\n dp[0][2]=0\r\n dp[0][1]=0\r\n\r\n for i in range(1,t):\r\n if k[i]==0:\r\n dp[i][0]=1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1]=inf\r\n dp[i][2]=inf\r\n if k[i]==1:\r\n dp[i][0]=1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2]=inf\r\n if k[i]==2:\r\n dp[i][0]=1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1]=inf\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n if k[i]==3:\r\n dp[i][0]=1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n\r\n print(min(dp[t-1][0],dp[t-1][1],dp[t-1][2]))\r\n\r\n\r\nfdp(t,l)", "import sys\nfrom math import ceil, floor, sqrt, log2\nfrom collections import defaultdict, deque\ninput = lambda: sys.stdin.readline().strip()\nintlist = lambda: [int(i) for i in input().split()]\nflolist = lambda: [float(f) for f in input().split()]\nmat = lambda a, b, v: [[v] * b for _ in range(a)]\n\nn = int(input())\na = intlist()\n\ninf = float('inf')\n\nrest = 0\ncontest = 0\nwork = 0\nfor e in a:\n if e == 0:\n rest, contest, work = min(contest, work, rest) + 1, inf, inf\n elif e == 1:\n rest, contest, work = min(contest, work, rest) + 1, min(work, rest), inf\n elif e == 2:\n rest, contest, work = min(contest, work, rest) + 1, inf, min(contest, rest)\n else:\n rest, contest, work = min(contest, work, rest) + 1, min(work, rest), min(contest, rest)\n\nprint(min(rest, contest, work))", "n = int(input())\r\narr = [int(i) for i in input().split()]\r\ndp = [0] * n\r\ndp[0] = arr[0]\r\nfor i in range(n):\r\n if arr[i] == 1 and dp[i-1] != 1:\r\n dp[i] = 1\r\n elif arr[i] == 2 and dp[i-1] != 2:\r\n dp[i] = 2\r\n elif arr[i] == 3:\r\n if dp[i-1] == 1:\r\n dp[i] = 2\r\n elif dp[i-1] == 2:\r\n dp[i] = 1\r\n else:\r\n dp[i] = 3\r\nprint(dp.count(0))", "n = int(input())\r\narr = list(map(int, input().split()))\r\ndp = [[0 for i in range(3)] for j in range(2)]\r\n\r\ndp[0][1] = 1 if arr[0] & 1 else 0\r\ndp[0][2] = 1 if (arr[0] >> 1) & 1 else 0\r\n\r\n\r\nfor i in range(1, n):\r\n dp[i & 1][0] = max(dp[(i - 1) & 1])\r\n dp[i & 1][1] = dp[(i - 1) & 1][1]\r\n dp[i & 1][2] = dp[(i - 1) & 1][2]\r\n if arr[i] & 1:\r\n dp[i & 1][1] = 1 + max(dp[(i - 1) & 1][0], dp[(i - 1) & 1][2])\r\n if (arr[i] >> 1) & 1:\r\n dp[i & 1][2] = 1 + max(dp[(i - 1) & 1][0], dp[(i - 1) & 1][1])\r\n\r\nprint(n - max(dp[(n - 1) & 1]))\r\n", "def main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n dp = [[0] * 3 for _ in range(n)]\r\n\r\n if a[0] == 1 or a[0] == 3:\r\n dp[0][1] += 1\r\n if a[0] == 2 or a[0] == 3:\r\n dp[0][2] += 1\r\n\r\n for i in range(1, n):\r\n dp[i][0] = max(dp[i-1][0], max(dp[i-1][1], dp[i-1][2]))\r\n dp[i][1] = max(dp[i-1][0], dp[i-1][2])\r\n if a[i] == 1 or a[i] == 3:\r\n dp[i][1] += 1\r\n dp[i][2] = max(dp[i-1][0], dp[i-1][1])\r\n if a[i] == 2 or a[i] == 3:\r\n dp[i][2] += 1\r\n\r\n print(n - max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\r\nans = [0]+list(map(int,input().split()))\r\nlis=['@']*(n+1)\r\ni=1\r\nwhile i<n+1:\r\n# print(i,lis[i-1],lis[i])\r\n if ans[i]==0:\r\n lis[i]='r';\r\n elif ans[i]==1:\r\n if lis[i-1]=='c':\r\n lis[i]='r'\r\n else:\r\n lis[i]='c'\r\n elif ans[i]==2:\r\n if lis[i-1]=='g':\r\n lis[i]='r'\r\n else:\r\n lis[i]='g'\r\n else:\r\n if lis[i-1]=='g':\r\n lis[i]='c'\r\n elif lis[i-1]=='c':\r\n lis[i]='g'\r\n else: \r\n while i+1<=n and ans[i+1]==3:\r\n i+=1\r\n if i<=n and ans[i]==2:\r\n lis[i]='g'\r\n elif i<=n and ans[i]==1:\r\n lis[i]='c'\r\n elif i<=n and ans[i]==0:\r\n lis[i]='r'\r\n #i-=1 \r\n i+=1 \r\naa=0\r\n#print(lis)\r\nfor i in lis[1:]:\r\n if i=='r':\r\n aa+=1\r\nprint(aa) \r\n\r\n\r\n\r\n", "n = int(input())\r\n\r\nday = list(map(int, input().split()))\r\n\r\ninf = 10 ** 20\r\ndp = [[inf for _ in range(3)] for _ in range(n+5)]\r\n\r\n# 0: rest 1: sport 2: coding\r\n\r\ndp[0][0] = 0 \r\ndp[0][1] = 0\r\ndp[0][2] = 0\r\nfor i in range(n):\r\n\r\n dp[i+1][0] = 1 + min(dp[i][0], dp[i][1], dp[i][2])\r\n dp[i+1][1] = min(dp[i][0], dp[i][2])\r\n dp[i+1][2] = min(dp[i][0], dp[i][1])\r\n\r\n if day[i] == 0:\r\n dp[i+1][1] = inf\r\n dp[i+1][2] = inf\r\n elif day[i] == 1:\r\n dp[i+1][1] = inf\r\n elif day[i] == 2:\r\n dp[i+1][2] = inf \r\nprint(min(dp[n][0], dp[n][1], dp[n][2]))", "# Thank God that I'm not you.\r\n\r\nimport bisect\r\nfrom collections import Counter, deque\r\nimport heapq\r\nimport math\r\nimport random\r\nimport sys\r\nfrom types import GeneratorType;\r\n\r\n\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n stack.append(to)\r\n to = next(to)\r\n else:\r\n stack.pop()\r\n if not stack:\r\n break\r\n to = stack[-1].send(to)\r\n return to\r\n\r\n return wrappedfunc\r\n\r\n\r\ndef primeFactors(n):\r\n counter = Counter();\r\n while n % 2 == 0:\r\n counter[2] += 1\r\n n = n / 2\r\n\r\n for i in range(3, int(math.sqrt(n)) + 1, 2):\r\n\r\n while n % i == 0:\r\n counter[i] += 1;\r\n n = n // i\r\n\r\n if (n > 2):\r\n counter[n] += 1\r\n\r\n return counter\r\n\r\n\r\n\r\ninput = sys.stdin.readline;\r\n\r\n\r\nn = int(input())\r\n\r\narray = list(map(int, input().split()))\r\n\r\ndp = [[float('inf') for i in range(3)] for z in range(n)]\r\n\r\ndef executeGym(i):\r\n return min(dp[i - 1][0], dp[i - 1][1])\r\n\r\n\r\n\r\ndef executeCon(i):\r\n return min(dp[i - 1][0], dp[i - 1][2]);\r\n\r\n\r\n\r\nfor i in range(len(array)):\r\n if not i:\r\n if not array[i]:\r\n for z in range(3):\r\n dp[i][z] = 1;\r\n elif array[i] == 3:\r\n dp[i][1] = 0;\r\n dp[i][2] = 0;\r\n dp[i][0] = 1;\r\n else:\r\n dp[i][0] = 1;\r\n dp[i][array[i]] = 0;\r\n else:\r\n if array[i] == 3:\r\n dp[i][1] = executeCon(i)\r\n dp[i][2] = executeGym(i)\r\n else:\r\n if array[i] == 1:\r\n dp[i][1] = executeCon(i)\r\n elif array[i] == 2:\r\n dp[i][2] = executeGym(i);\r\n dp[i][0] = 1 + min(executeCon(i), executeGym(i))\r\n\r\n\r\n\r\nprint(min(dp[-1][0], dp[-1][1], dp[-1][2]))\r\n", "from sys import stdin,stdout\r\nnmbr = lambda: int(input())\r\nlst = lambda: list(map(int, input().split()))\r\n# 0=G'C'\r\n# 1=G'C\r\n# 2=GC'\r\n# 3=GC\r\nPI=float('inf')\r\ndef fn(pos,state):# state : 0->Rest, 1->Contest, 2->Gym\r\n if pos==0:return 0\r\n if a[pos-1]==0:\r\n ans=1+fn(pos-1,0)\r\n elif a[pos-1]==1:\r\n rest=contest=PI\r\n if state!=1:contest=fn(pos-1,1)\r\n rest=1+fn(pos-1,0)\r\n ans=min(contest,rest)\r\n elif a[pos-1]==2:\r\n gym=rest=PI\r\n if state!=2:gym=fn(pos-1,2)\r\n rest=1+fn(pos-1,0)\r\n ans=min(gym,rest)\r\n else:\r\n gym=contest=PI\r\n if state!=1:contest=fn(pos-1,1)\r\n if state!=2:gym=fn(pos-1,2)\r\n ans=min(gym,contest)\r\n return ans\r\n\r\nfor _ in range(1):#nmbr()):\r\n n=nmbr()\r\n a=lst()\r\n dp=[[PI for i in range(4)] for _ in range(n+1)]\r\n dp[0][0]=dp[0][1]=dp[0][2]=0\r\n for pos in range(1,n+1):\r\n for state in range(4):\r\n if a[pos - 1] == 0:\r\n dp[pos][state] = 1 + dp[pos-1][0]\r\n elif a[pos - 1] == 1:\r\n rest = contest = PI\r\n if state != 1: contest = dp[pos-1][1]\r\n rest = 1 + dp[pos-1][0]\r\n dp[pos][state] = min(contest, rest)\r\n elif a[pos - 1] == 2:\r\n gym = rest = PI\r\n if state != 2: gym = dp[pos-1][2]\r\n rest = 1 + dp[pos-1][0]\r\n dp[pos][state] = min(gym, rest)\r\n else:\r\n gym = contest = PI\r\n if state != 1: contest = dp[pos-1][1]\r\n if state != 2: gym = dp[pos-1][2]\r\n dp[pos][state] = min(gym, contest)\r\n print(min(dp[n]))", "def max_active_days(n, activities):\r\n d = [[0, 0, 0] for _ in range(n)]\r\n\r\n for i in range(n):\r\n if i == 0:\r\n d[i][0] = 0\r\n d[i][1] = 1 if activities[i] == 1 or activities[i] == 3 else 0\r\n d[i][2] = 1 if activities[i] == 2 or activities[i] == 3 else 0\r\n else:\r\n d[i][0] = max(d[i-1])\r\n d[i][1] = max(d[i-1][0] + (activities[i] == 1 or activities[i] == 3),\r\n d[i-1][2] + (activities[i] == 1 or activities[i] == 3))\r\n d[i][2] = max(d[i-1][0] + (activities[i] == 2 or activities[i] == 3),\r\n d[i-1][1] + (activities[i] == 2 or activities[i] == 3))\r\n \r\n max_active = max(d[n-1])\r\n min_rest = n - max_active\r\n return min_rest\r\n\r\n# Example usage\r\nn = int(input())\r\nactivities = list(map(int, input().split()))\r\nresult = max_active_days(n, activities)\r\nprint(result)\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nrest = 0 \r\np = 0 \r\nfor i in range(n):\r\n if a[i] == 0:\r\n rest+=1 \r\n p = 0\r\n elif not p:\r\n p=a[i]\r\n elif p == 3:\r\n p=a[i]\r\n elif p == 2 and a[i]!=2:\r\n p=1 \r\n elif p == 2 and a[i]==2:\r\n p = 0\r\n rest+=1 \r\n elif p == 1 and a[i] != 1:\r\n p = 2\r\n elif p == 1 and a[i]==1:\r\n p = 0\r\n rest+=1 \r\nprint(rest)", "'''\r\n# Sample code to perform I/O:\r\n\r\nname = input() # Reading input from STDIN\r\nprint('Hi, %s.' % name) # Writing output to STDOUT\r\n\r\n# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail\r\n'''\r\n\r\n# Write your code here\r\nn = int(input())\r\ndhoni = list(map(int, input().split()))\r\n\r\nrest = 0\r\nfor i in range(n):\r\n if(dhoni[i]==0):\r\n rest+=1\r\n elif(dhoni[i]==1):\r\n if(i-1>=0 and dhoni[i-1]==1):\r\n rest+=1\r\n dhoni[i] = 0\r\n elif(dhoni[i]==2):\r\n if(i-1>=0 and dhoni[i-1]==2):\r\n rest+=1\r\n dhoni[i] = 0\r\n elif(dhoni[i]==3):\r\n if(i-1>=0 and dhoni[i-1]==2 and i+1<0 and dhoni[i+1]==1):\r\n rest+=1\r\n elif(i-1>=0 and dhoni[i-1]==1 and i+1<0 and dhoni[i+1]==2):\r\n rest+=1\r\n elif(i-1>=0 and dhoni[i-1]==1):\r\n dhoni[i]=2\r\n elif(i-1>=0 and dhoni[i-1]==2):\r\n dhoni[i]=1\r\n #if(i==9):\r\n # print(i,rest)\r\n # print(dhoni)\r\nprint(rest)", "n = int(input())\na = list(map(int, input().split(' ')))\ncode, sport = [0]*n, [0]*n\nfor i in range(n):\n code[i] = max(code[i], a[i]%2)\n sport[i] = max(sport[i], a[i]//2)\n for j in range(i+1, n):\n if a[j]%2:\n code[j] = max(code[j], sport[i] + 1)\n if a[j]//2:\n sport[j] = max(sport[j], code[i] + 1)\n for j in range(i+2, n):\n if a[j]%2:\n code[j] = max(code[j], code[i] + 1)\n if a[j]//2:\n sport[j] = max(sport[j], sport[i] + 1)\nresult = n - max(max(code), max(sport))\nprint(result)\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nINF = float('inf')\r\ndp = [[INF] * 3 for i in range(n + 1)]\r\ndp[0][0] = 0\r\n\r\nfor i in range(n):\r\n k = a[i]\r\n dp[i + 1][0] = min(dp[i][0], dp[i][1], dp[i][2]) + 1\r\n if k == 1:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n elif k == 2:\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1])\r\n elif k == 3:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1])\r\n\r\nprint(min(dp[n]))\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nminr = ming = minc = 0\r\nfor i in a:\r\n if i == 0:\r\n minr = min(minr, ming, minc)+1\r\n ming = n\r\n minc = n\r\n elif i == 1:\r\n minc, minr, ming = min(minr, ming), min(minr, ming, minc)+1, n\r\n elif i == 2:\r\n ming, minr, minc = min(minr, minc), min(minr, ming, minc)+1, n\r\n else:\r\n minc, ming, minr = min(minr, ming), min(minr, minc), min(minr, ming, minc)+1\r\nprint(min(minr, ming, minc))", "# 1400\r\n# A. Vacations\r\ndef vacations():\r\n l = int(input())\r\n days = list(map(int, input().split()))\r\n # condition : (action code)\r\n # action set\r\n # 0: rest\r\n # 1: contest\r\n # 2: sport(gym)\r\n condition = {\r\n 0: [{0}, {1, 2}],\r\n 1: [{1, 0}, {2}],\r\n 2: [{2, 0}, {1}],\r\n 3: [{0, 1, 2}, {}],\r\n }\r\n memo = [[-1] * l for _ in range(3)] # *l (days) *3 (action)\r\n for i in range(l):\r\n d = days[i]\r\n included, excluded = condition[d]\r\n # print(included)\r\n\r\n for action in included:\r\n if i == 0:\r\n # start\r\n if action == 0:\r\n memo[action][i] = 1\r\n else:\r\n memo[action][i] = 0\r\n else:\r\n if action == 0:\r\n memo[action][i] = min(\r\n memo[0][i - 1] if memo[0][i - 1] != -1 else 10000,\r\n memo[1][i - 1] if memo[1][i - 1] != -1 else 10000,\r\n memo[2][i - 1] if memo[2][i - 1] != -1 else 10000\r\n ) + 1\r\n elif action == 1:\r\n memo[action][i] = min(\r\n memo[0][i - 1] if memo[0][i - 1] != -1 else 10000,\r\n memo[2][i - 1] if memo[2][i - 1] != -1 else 10000\r\n )\r\n else:\r\n memo[action][i] = min(\r\n memo[0][i - 1] if memo[0][i - 1] != -1 else 10000,\r\n memo[1][i - 1] if memo[1][i - 1] != -1 else 10000,\r\n )\r\n candidate = [\r\n memo[0][l - 1],\r\n memo[1][l - 1],\r\n memo[2][l - 1],\r\n ]\r\n print(min([c for c in candidate if c >= 0]))\r\n\r\nvacations()", "# Немного \"сличено\"\r\nn = int(input())\r\nl = [int(i) for i in input().split()]\r\ndp = [[0] * 3 for i in range(n)]\r\nif l[0] == 1:\r\n dp[0][1] = 1\r\nelif l[0] == 2:\r\n dp[0][2] = 1\r\nelif l[0] == 3:\r\n dp[0][2] = 1\r\n dp[0][1] = 1\r\nfor i in range(1, n):\r\n dp[i][0] = max(dp[i - 1])\r\n if l[i] == 1:\r\n dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + 1\r\n elif l[i] == 2:\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1\r\n elif l[i] == 3:\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1\r\nprint(n - max(dp[-1]))\r\n\"\"\"for i in range(n):\r\n print(*dp[i])\"\"\"\r\n", "numday = input()\r\ndayorder = input()\r\narray = map(int, dayorder.split(' '))\r\nsumrest = 0\r\nprev = 3\r\n \r\nfor i in array:\r\n if (i == prev and prev != 3):\r\n i = 0\r\n elif (i == 3 and prev != 3):\r\n i -= prev\r\n if i == 0:\r\n sumrest += 1\r\n \r\n prev = i\r\n \r\nprint(sumrest)", "n = int(input())\r\na = list(map(int, input().split()))\r\ns, o = 0, 3 \r\nfor i in range(n):\r\n\tif a[i] == o and o != 3:\r\n\t\ta[i] = 0 \r\n\telif a[i] == 3 and o != 3:\r\n\t\ta[i] -= o\r\n\tif a[i] == 0:\r\n\t\ts += 1\r\n\to = a[i]\r\nprint(s)", "from sys import stdin,stdout\r\n# from os import _exit\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict,Counter\r\n# from itertools import permutations\r\n# from math import gcd,ceil,sqrt,factorial\r\n# setrecursionlimit(int(1e5))\r\ninput,print = stdin.readline,stdout.write\r\n\r\nn = int(input())\r\nx = list(map(int,input().split()))\r\na = [False for i in range(n)]\r\nb = [False for i in range(n)]\r\nfor i in range(n):\r\n if x[i]==1:\r\n a[i] = True\r\n elif x[i]==2:\r\n b[i] = True\r\n elif x[i]==3:\r\n a[i],b[i] = True,True\r\ndp = [0 for i in range(n)]\r\nif x[0]!=3:\r\n dp[0] = x[0]\r\nans = 0\r\nfor i in range(1,n):\r\n if not a[i] and not b[i]:\r\n dp[i] = 0\r\n ans+=1\r\n elif a[i] and not b[i]:\r\n if dp[i-1]==1:\r\n dp[i] = 0\r\n ans+=1\r\n else:\r\n dp[i] = 1\r\n elif not a[i] and b[i]:\r\n if dp[i-1]==2:\r\n dp[i] = 0\r\n ans+=1\r\n else:\r\n dp[i] = 2\r\n elif dp[i-1]!=0:\r\n dp[i] = dp[i-1]^3\r\n\r\n#print(a)\r\n#print(b)\r\n#print(dp)\r\nif not x[0]:\r\n ans+=1\r\nprint(str(ans)+\"\\n\")\r\n", "\n# coding: utf-8\n\n# In[1]:\n\n\nn = int(input())\n\n\n# In[2]:\n\n\narr = list(map(int, input().rstrip().split()))\n\n\n# In[4]:\n\n\nrest = 0\npast = 0\ni = 0\nfor i in range(len(arr)):\n if arr[i]==0 or arr[i]==past:\n rest+=1\n past=0\n elif arr[i]==3:\n if past!=0:\n past=3-past\n else:\n past=arr[i] \n\n\n# In[6]:\n\n\nprint(rest)\n\n", "n=int(input())\r\narr=[]\r\np=list(map(int,input().split()))\r\nfor i in range(n):\r\n arr.append([10000,10000,10000,p[i]])\r\narr[0][0]=1\r\nif(arr[0][3]==1 or arr[0][3]==3):\r\n arr[0][1]=0\r\nif(arr[0][3]==2 or arr[0][3]==3):\r\n arr[0][2]=0\r\nfor i in range(1,n):\r\n arr[i][0]=1+min(arr[i-1][0], arr[i-1][1], arr[i-1][2])\r\n if(arr[i][3]==1 or arr[i][3]==3):\r\n arr[i][1]=min(arr[i-1][0], arr[i-1][2])\r\n if(arr[i][3]==2 or arr[i][3]==3):\r\n arr[i][2]=min(arr[i-1][0], arr[i-1][1])\r\nleast=10000\r\nfor i in range(0,3):\r\n least=min(least,arr[n-1][i])\r\nprint(least)\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nmemo = [[-1]*4 for i in range(n)]\r\n\r\ndef dp(i,prev):\r\n if i == n:\r\n return 0\r\n if memo[i][prev] == -1:\r\n memo[i][prev] = 1 + dp(i+1,0)\r\n if a[i] == 1 or a[i] == 2:\r\n if a[i] != prev:\r\n memo[i][prev] = min(memo[i][prev],dp(i+1,a[i]))\r\n elif a[i] == 3:\r\n for x in range(1,3):\r\n if x != prev:\r\n memo[i][prev] = min(memo[i][prev],dp(i+1,x))\r\n return memo[i][prev] \r\nprint(dp(0,0)) \r\n ", "n=int(input())\r\na=list(map(int,input().strip().split()))\r\narr=[]\r\nx=[0]*3\r\nfor i in range(n):\r\n arr.append(x.copy())\r\nintmax=10**9\r\narr[0][0]=1\r\n\r\nif(a[0]==1 or a[0]==3):\r\n arr[0][1]=0\r\nelse:\r\n arr[0][1]=intmax\r\nif(a[0]==2 or a[0]==3):\r\n arr[0][2]=0\r\nelse:\r\n arr[0][2]=intmax\r\n \r\nfor i in range(1,n):\r\n arr[i][0]=1+min(arr[i-1])\r\n \r\n if(a[i]==1 or a[i]==3):\r\n arr[i][1]=min(arr[i-1][0],arr[i-1][2])\r\n else:\r\n arr[i][1]=intmax\r\n if(a[i]==2 or a[i]==3):\r\n arr[i][2]=min(arr[i-1][0],arr[i-1][1])\r\n else:\r\n arr[i][2]=intmax\r\n \r\nprint(min(arr[n-1]))\r\n\r\n#// The truth is always either terrible or boring - kaushal02", "\"\"\" import sys\r\nsys.stdin = open('input.txt', 'r')\r\nsys.stdout = open('output.txt', 'w') \"\"\"\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ny, x = 0, 0\r\nfor i in a:\r\n if i == 0 or i == x:\r\n y = y + 1\r\n x = 0\r\n elif i != 3:\r\n x = i\r\n elif x > 0 and i == 3:\r\n x = 3 - x\r\nprint(y)\r\n", "input()\r\nprev = free_days = 0\r\n\r\nfor a in map(int, input().split()):\r\n if a == 0:\r\n prev, free_days = 0, free_days + 1\r\n elif a in (1, 2):\r\n if a == prev:\r\n prev, free_days = 0, free_days + 1\r\n else:\r\n prev = a\r\n elif prev in (1, 2):\r\n prev = 3 - prev\r\n\r\nprint(free_days)", "# http://codeforces.com/contest/699/problem/C\nimport random\n\ndef gym_day():\n\treturn 2\ndef contest_day():\n\treturn 1\n\ninput()\ndays = [int(n) for n in input().split()]\n# n = random.randint(1,5)\n# arr = [random.randint(0,3) for _ in range(n)]\n# arr = [3,2,2,2,2,2]\n# days = arr\n# print(\"days\", days)\n\ng,c = 0, 0\nfor day in days:\n\tog, oc = g, c\n\tif day == 3:\n\t\tt = g\n\t\tg = c\n\t\tc = t\n\tif day == 2:\n\t\tc = og\n\t\tg = 1 + min(og,oc)\n\tif day == 1:\n\t\tg = oc\n\t\tc = 1 + min(og,oc)\n\tif day == 0:\n\t\tg = 1 + min(og,oc)\n\t\tc = 1 + min(og,oc)\n\t# print(day, g,c)\n\n# print(g,c)\nprint(min(g,c))\n\n# ans = 0\n# prev = 3\n# for i in arr:\n# \tif(i == prev and prev != 3):\n# \t\ti = 0\n# \telif(i == 3 and prev != 3):\n# \t\ti -= prev\n# \tif(i == 0):\n# \t\tans += 1\n# \tprev = i\n# print(ans)\n\n# if min(g,c) != ans:\n# \tprint(\"==============\", days)", "\nn=int(input())\nn+=1\na=[int(i) for i in input().split()]\na.append(0)\nr=[[None for j in range(3)] for i in range(n)]\nr[0][0]=0\ndef howMany(ind,pos):\n if r[ind][pos]==None: return\n # print(r[ind][pos],r[ind+1][0])\n if r[ind+1][0]==None or (\n r[ind+1][0]<r[ind][pos]):\n r[ind+1][0]=r[ind][pos]\n if a[ind]%2==1 and pos!=1 and (\n r[ind+1][1]==None or r[ind][pos]+1>r[ind+1][1]):\n r[ind+1][1]=r[ind][pos]+1\n if a[ind]>=2 and pos!=2 and (r[ind+1][2]==None or r[ind][pos]+1>r[ind+1][2]):\n r[ind+1][2]=r[ind][pos]+1\nfor i in range(n-1):\n for j in range(3):\n howMany(i,j)\nfor i in range(3):\n if r[-1][i]==None: \n r[-1][i]=0\nprint(n-1-max(r[-1][0],r[-1][1],r[-1][2]))\n'''\nprint()\nfor i in range(n):\n for j in range(3):\n print(r[i][j],end=' ')\n print()\n'''\n", "from sys import stdin\n\nsize = int(stdin.readline())\ninp = list(map(int,stdin.readline().split()))\n\nboard = [[0,0,0] for y in range(size)]\n#0 for contest 1 for gym 2 for nothing\nif(inp[0] == 0):\n board[0] = [0,0,0]\nelif inp[0] == 1:\n board[0] = [0,1,0]\nelif inp[0] == 2:\n board[0] = [0,0,1]\nelse:\n board[0] = [0,1,1]\n\nfor n in range(1,len(inp)):\n board[n][0] = max(board[n-1])\n if(inp[n]==1 or inp[n]==3):\n board[n][1]=max(board[n-1][0]+1,board[n-1][2]+1)\n if(inp[n]==2 or inp[n]==3):\n board[n][2] = max(board[n-1][1]+1,board[n-1][0]+1)\nm = 0\nfor i in range(size):\n if(max(board[i])>m):\n m=max(board[i])\n\n#print(board)\nprint(size-m)", "n_days = int(input())\r\ndays = list(map(int, input().split()))\r\n\r\ndp = [[-1, -1, -1] for i in range(n_days)]\r\ndp.append([0, 0, 0])\r\n\r\n# def calc_max(day, last):\r\n# \tif day == n_days:\r\n# \t\treturn 0\r\n# \tactivities = [-1, -1, -1]\r\n# \tactivities[0] = calc_max(day + 1, 0)\r\n# \tif days[day] == 1 or days[day] == 3:\r\n# \t\tif last != 1:\r\n# \t\t\tactivities[1] = max(calc_max(day + 1, 1) + 1, calc_max(day + 1, 0))\r\n# \tif days[day] == 2 or days[day] == 3:\r\n# \t\tif last != 2:\r\n# \t\t\tactivities[2] = max(calc_max(day + 1, 2) + 1, calc_max(day + 1, 0))\r\n# \tbest = max(activities)\r\n# \tdp[day][activities.index(best)] = best\r\n# \treturn best\r\n\r\nfor i in range(n_days - 1, -1, -1):\r\n\tdp[i][0] = int(max(dp[i + 1]))\r\n\tif days[i] == 1 or days[i] == 3:\r\n\t\tdp[i][1] = int(max(max(dp[i + 1][0] + 1, dp[i + 1][2] + 1), dp[i + 1][1]))\r\n\tif days[i] == 2 or days[i] == 3:\r\n\t\tdp[i][2] = int(max(max(dp[i + 1][0] + 1, dp[i + 1][1] + 1), dp[i + 1][2]))\r\n\r\nprint(n_days - max(dp[0]))", "'''\r\n4\r\n1 3 2 0\r\n\r\n'''\r\nn = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\nans = 0\r\nstate = 0\r\nfor i in range(n):\r\n if i > 0 and nums[i - 1] != 3 and nums[i - 1] != 0 and nums[i] == 3:\r\n nums[i] -= state\r\n if (state == nums[i] or nums[i] == 0) and nums[i] != 3:\r\n ans += 1\r\n state = 0\r\n else:\r\n if nums[i] != 3:\r\n state = nums[i]\r\nprint(ans)\r\n", "n = int(input())\r\nls = list(map(int,input().split()))\r\n \r\nans = 0\r\nprev = 0\r\n\r\nfor i in range(len(ls)):\r\n\tif ls[i] == prev or not ls[i]:\r\n\t\tprev = 0\r\n\t\tans += 1\r\n\telif ls[i] < 3:\r\n\t\tprev = ls[i]\r\n\telif prev:\r\n\t\tprev = 3-prev\r\n\r\nprint(ans)", "import sys\r\nfrom math import sqrt, gcd, factorial, ceil, floor, pi, inf\r\nfrom collections import deque, Counter, OrderedDict\r\nfrom heapq import heapify, heappush, heappop\r\n#sys.setrecursionlimit(10**6)\r\n\r\n#======================================================#\r\ninput = lambda: sys.stdin.readline()\r\nI = lambda: int(input().strip())\r\nS = lambda: input().strip()\r\nM = lambda: map(int,input().strip().split())\r\nL = lambda: list(map(int,input().strip().split()))\r\n#======================================================#\r\n\r\n#======================================================#\r\ndef primelist():\r\n L = [False for i in range(10**9)]\r\n primes = [False for i in range(10**9)]\r\n for i in range(2,10**9):\r\n if not L[i]:\r\n primes[i]=True\r\n for j in range(i,10**9,i):\r\n L[j]=True\r\n return primes\r\ndef isPrime(n):\r\n p = primelist()\r\n return p[n]\r\n#======================================================#\r\ndef bst(arr,x):\r\n low,high = 0,len(arr)-1\r\n ans = -1\r\n while low<=high:\r\n mid = (low+high)//2\r\n if arr[mid]==x:\r\n return mid\r\n elif arr[mid]<x:\r\n ans = mid\r\n low = mid+1\r\n else:\r\n high = mid-1\r\n return ans\r\n#======================================================#\r\n\r\n\r\nn = I()\r\na = L()\r\nans = [[inf,inf,inf] for i in range(n)]\r\nans[0][0]=1\r\nif a[0]==1:\r\n ans[0][2]=0\r\nelif a[0]==2:\r\n ans[0][1]=0\r\nelif a[0]==3:\r\n ans[0][1]=0\r\n ans[0][2]=0\r\nfor i in range(1,n):\r\n if a[i]==0:\r\n ans[i][0]=1+min(ans[i-1])\r\n elif a[i]==1:\r\n ans[i][0]=1+min(ans[i-1])\r\n ans[i][2]=min(ans[i-1][0],ans[i-1][1])\r\n elif a[i]==2:\r\n ans[i][0]=1+min(ans[i-1])\r\n ans[i][1]=min(ans[i-1][0],ans[i-1][2])\r\n else:\r\n ans[i][0]=1+min(ans[i-1])\r\n ans[i][1]=min(ans[i-1][0],ans[i-1][2])\r\n ans[i][2]=min(ans[i-1][0],ans[i-1][1])\r\n\r\nprint(min(ans[-1]))\r\n\r\n\r\n", "n = int(input())\na = [int(i) for i in input().split()]\n\ndp = [{'r': float('inf'), 'g': float('inf'), 'c': float('inf')} for _ in range(n)]\n\ndp[0]['r'] = 1\n\nif a[0] == 1 or a[0] == 3:\n dp[0]['c'] = 0\nif a[0] == 2 or a[0] == 3:\n dp[0]['g'] = 0\n\nfor i in range(1, n):\n dp[i]['r'] = 1 + min(dp[i - 1]['r'], dp[i - 1]['g'], dp[i - 1]['c'])\n\n if a[i] == 1 or a[i] == 3:\n dp[i]['c'] = min(dp[i - 1]['g'], dp[i - 1]['r'])\n\n if a[i] == 2 or a[i] == 3:\n dp[i]['g'] = min(dp[i - 1]['c'], dp[i - 1]['r'])\n\nprint(min(dp[-1].values()))\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\np = a[0]\r\nif p == 0:\r\n rest = 1\r\nelse: \r\n rest = 0\r\n\r\nfor i in range(1, n):\r\n if a[i] == p and p != 3:\r\n a[i] = 0\r\n elif a[i] == 3 and p != 3:\r\n a[i] -= p\r\n if a[i] == 0:\r\n rest += 1\r\n p = a[i]\r\n\r\nprint(rest)", "mp={}\r\n\r\ndef rec(idx,prv):\r\n ans0,ans1,ans2=0,0,0\r\n if idx>=n:return 0\r\n if (idx,prv) in mp:return mp[(idx,prv)]\r\n if arr[idx]==1 and prv!=1:\r\n ans1=rec(idx+1,1)+1\r\n elif arr[idx]==2 and prv!=2:\r\n ans2=rec(idx+1,2)+1\r\n elif arr[idx]==3:\r\n if prv==1:ans2=rec(idx+1,2)+1\r\n elif prv==2:ans1=rec(idx+1,1)+1\r\n else:\r\n ans1=rec(idx+1,1)+1\r\n ans2=rec(idx+1,2)+1\r\n else:ans0=rec(idx+1,0)\r\n mp[(idx,prv)]=max(ans0,ans1,ans2)\r\n return max(ans0,ans1,ans2)\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nif arr[0]==0:print(n-rec(1,0))\r\nelse:print(n-rec(1,arr[0])-1)", "n = int(input())\r\nl = list(map(int,input().split()))\r\ncount = 0\r\nprev = 3\r\n\r\nfor i in l :\r\n\r\n if i == prev and prev != 3 :\r\n i = 0\r\n\r\n elif i == 3 and prev != 3 :\r\n i = i - prev\r\n\r\n if i == 0 :\r\n count +=1\r\n prev = i\r\n \r\nprint(count)\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\np = pp = res = 0\na = [int(i) for i in input().split()]\nfor i in a:\n if i == p or i == 0:\n p = 0\n res += 1\n elif i == 1 or i == 2:\n p = i\n else:\n if p != 0:\n p = 3 - p\nelse:\n print(res)\n", "# 0 todo cerrado\n# 1 concurso\n# 2 gym\n# 3 todo abierto\nprimera=False\nn=int(input())\nai=list(map(int,input().split(\" \")))\naux=[]\nfor a in range(n):\n aux.append(0)\n#print(aux) \nfor i in range(n):\n if ai[i]==0:\n aux[i]+=1\n if primera:\n if ai[i]==ai[i-1] and ai[i]!=3 and ai[i]!=0: \n aux[i]+=1\n ai[i]=0\n elif ai[i]==3 and ai[i-1]==1: \n ai[i]=2\n \n elif ai[i]==3 and ai[i-1]==2:\n ai[i]=1\n \n aux[i]+=aux[i-1]\n primera=True\n \nprint(max(aux))\n \t \t \t\t \t\t \t \t \t \t\t\t\t \t \t\t", "n = int(input())\r\nnums = list(map(int,input().split()))\r\n\r\nr,g,c = 0,n,n\r\nfor a in nums:\r\n if a==0:\r\n r,g,c = min(c,g,r)+1, n, n\r\n elif a==1:\r\n r,g,c = min(c,g,r)+1,n ,min(r,g)\r\n elif a==2:\r\n r,g,c = min(c,g,r)+1,min(r,c),n\r\n else:\r\n r,g,c = min(c,g,r)+1,min(r,c),min(r,g)\r\nprint(min(c,g,r))\r\n", "\nimport functools\ndef soln(arr):\n\n def gym(i):\n return arr[i] in [2, 3]\n\n def contest(i):\n return arr[i] in [1, 3]\n \n @functools.lru_cache(maxsize = len(arr) * 3)\n def dp(i, g, c):\n # dp(i, g, c) = min starting at index i. \n # g => can go to gym, c => can participate in contest.\n if i >= len(arr):\n return 0\n seq = [1 + dp(i + 1, True, True)]\n if g and gym(i) and c and contest(i):\n seq += [\n dp(i + 1, False, True),\n dp(i + 1, True, False),\n ]\n if g and gym(i):\n seq += [\n dp(i + 1, False, True),\n ]\n if c and contest(i):\n seq += [\n dp(i + 1, True, False),\n ]\n return min(seq)\n \n return dp(0, True, True)\n\ndef main():\n n = int(input())\n arr = [int(x) for x in input().split()]\n result = soln(arr)\n print(result)\n\nmain()", "n=int(input())\r\nl=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n if(l[i]==0):\r\n l[i]=0\r\n elif(l[i-1]==0):\r\n pass\r\n elif(l[i]==1 and (l[i-1]==31 or l[i-1]==1)):\r\n l[i]=0\r\n elif(l[i]==2 and (l[i-1]==32 or l[i-1]==2)):\r\n l[i]=0\r\n elif(l[i]==3 and (l[i-1]==31 or l[i-1]==1)):\r\n l[i]=32\r\n elif(l[i]==3 and (l[i-1]==32 or l[i-1]==2)) :\r\n l[i]=31\r\n else:\r\n pass\r\nprint(l.count(0))\r\n ", "dias=int(input())\nlista=[]\nentrada = map(int,input().strip().split(\" \"))\nfor elemento in entrada:\n lista+=[elemento]\nc=False\ng=False\nr=0\ni=0\nwhile(i<dias):\n if(lista[i]==0):\n r+=1\n g=False\n c=False\n elif(lista[i]==1):\n if(c==True):\n c=False\n r+=1\n else:\n c=True\n g=False\n elif(lista[i]==2):\n if(g==True):\n g=False\n r+=1\n else:\n g=True\n c=False\n else:\n if(c==True and g==False):\n c=False\n g=True\n elif(g==True and c==False):\n g=False\n c=True\n \n i+=1\nprint(r)\n \n", "nDays = int(input())\nsqc = input().split()\ninf = 1000000\n\ndp = [[0 for x in range(3)] for x in range(nDays+1)]\n\ndp[0][0] = 0\ndp[0][1] = 0\ndp[0][2] = 0\n\nfor i in range(nDays+1):\n if i == 0: continue\n dp[i][0] = 1 + min(dp[i-1][0], min(dp[i-1][1], dp[i-1][2]))\n dp[i][1] = min(dp[i-1][0], dp[i-1][2]) if sqc[i-1] == '1' or sqc[i-1] == '3' else inf\n dp[i][2] = min(dp[i-1][0], dp[i-1][1]) if sqc[i-1] == '2' or sqc[i-1] == '3' else inf\n\nprint(min(dp[nDays][0], min(dp[nDays][1], dp[nDays][2])))\n \t \t \t\t\t \t\t \t\t\t\t\t\t \t \t", "from functools import lru_cache\nn, = map(int, input().split())\nA = list(map(int, input().split()))\n\n# (rest, rest), (gym, rest), (rest, comp)\n# 0 1 2\ndp = [[float(\"inf\")] * 3 for _ in range(n+1)]\ndp[0] = [0,float(\"inf\"),float(\"inf\")]\n\nfor i in range(1,n+1):\n a = A[i-1] # what is open today?\n if a == 0: # both closed\n dp[i][0] = min(dp[i-1]) + 1\n elif a == 1: # contest open only\n dp[i][0] = min(dp[i-1]) + 1\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\n elif a == 2: # gym open only\n dp[i][0] = min(dp[i-1]) + 1\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\n elif a == 3: # both open\n dp[i][0] = min(dp[i-1]) + 1\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\n\nprint(min(dp[n]))\n\n#@lru_cache(maxsize=None)\n#def opt(i, gym=False, contest=False):\n# if i >= n:\n# return 0\n# a = A[i]\n#\n# rest = opt(i+1, False, False) + 1\n# do_contest = float(\"inf\") if contest else opt(i+1,False,True)\n# do_gym = float(\"inf\") if gym else opt(i+1,True,False)\n#\n# if a == 0:\n# return rest\n# elif a == 1:\n# return min(\n# rest,\n# do_contest,\n# )\n# elif a == 2:\n# return min(\n# rest,\n# do_gym,\n# )\n# elif a == 3:\n# return min(\n# rest,\n# do_contest,\n# do_gym\n# )\n#print(opt(0))\n", "n=int(input())\r\na=[int(x) for x in input().split()]\r\ndp = [[0 for x in range(3)] for x in range(n+1)]\r\ndp[0][0]=0\r\ndp[0][1]=0\r\ndp[0][2]=0\r\n\r\nfor i in range(1,n+1):\r\n\tdp[i][0] = max(dp[i-1][0], dp[i-1][1],dp[i-1][2])\r\n\tif a[i-1]==1:\r\n\t\tdp[i][1] = max(dp[i-1][0]+1,dp[i-1][2]+1)\r\n\telif a[i-1]==2:\r\n\t\tdp[i][2] = max(dp[i-1][0]+1,dp[i-1][1]+1)\r\n\telif a[i-1]==3:\r\n\t\tdp[i][1] = max(dp[i-1][0]+1,dp[i-1][2]+1)\r\n\t\tdp[i][2] = max(dp[i-1][0]+1,dp[i-1][1]+1)\r\n\r\nprint(n-max(dp[n]))", "n=int(input())\r\nli=[int(i) for i in input().split()]\r\nans,t=0,0\r\nif li[0] !=0:\r\n ans=1\r\n t=li[0]\r\nfor i in range(1,n):\r\n if li[i]==0:\r\n t=0\r\n elif li[i]==3:\r\n ans+=1\r\n if t!=0:\r\n t=3-t\r\n else:\r\n if li[i]==t:\r\n t=0\r\n else:\r\n ans+=1\r\n t=li[i]\r\nprint(n-ans)", "from collections import *\r\nfrom functools import *\r\nfrom itertools import *\r\nfrom operator import *\r\nfrom bisect import *\r\nfrom heapq import *\r\nimport math\r\nimport re\r\nimport os\r\nimport io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef I():\r\n return input().decode('utf-8').strip()\r\n \r\ndef II(base=10):\r\n return int(input(),base)\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n \r\nclass sol:\r\n def main(self,):\r\n n = II()\r\n A = LII()\r\n inf = math.inf\r\n a,b,c = 0,inf,inf\r\n for x in A:\r\n a,b,c = 1+min(a,b,c),min(a,c) if x&1 else inf,min(a,b) if x&2 else inf\r\n return min(a,b,c)\r\n \r\n \r\nfor _ in range(1):\r\n print(sol().main())\r\n ", "x = 0\r\ng = False\r\nc = False\r\nrest = 0\r\nn = int(input())\r\nlst = list(map(int,input().split()))\r\nfor i in lst:\r\n if g and i == 1 or c and i == 2:\r\n rest += 1\r\n g =False\r\n c = False\r\n elif i == 0:\r\n rest+=1\r\n g= False\r\n c = False\r\n elif i==3 :\r\n l = c\r\n c = g\r\n g = l\r\n elif i == 2:\r\n c = True\r\n g=False\r\n elif i ==1 :\r\n g = True\r\n c=False\r\nprint (rest)\r\n", "# 0, если в i-й день каникул не работает спортзал и не проводится контест;\r\n# 1, если в i-й день каникул не работает спортзал, но проводится контест;\r\n# 2, если в i-й день каникул работает спортзал и не проводится контест;\r\n# 3, если в i-й день каникул работает спортзал и проводится контест.\r\n# i-й элемент в кэше массив где\r\n# 0-й элемент минимальное количество дней если выбрать спортзал\r\n# 1-й элемент минимальное количество дней если выбрать контекст\r\n# 2-й элемент минимальное количество дней если выбрать отдых\r\n\r\ndef min_rest_days(days):\r\n cache = {-1: [0, 0, 0]}\r\n for i in range(len(days)):\r\n prev_cache = cache[i-1]\r\n if days[i] == 0:\r\n # никуда\r\n cache[i] = [float('inf'),\r\n float('inf'),\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n elif days[i] == 1:\r\n # контеcт\r\n if i > 0 and days[i] == days[i-1]:\r\n # prev_min = prev_cache[1] + 1\r\n prev_min = prev_cache[2]\r\n else:\r\n prev_min = min(prev_cache[0], prev_cache[2])\r\n cache[i] = [float('inf'),\r\n prev_min,\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n elif days[i] == 2:\r\n # спорт\r\n if i > 0 and days[i] == days[i-1]:\r\n prev_min = prev_cache[2]\r\n # prev_min = prev_cache[0] + 1\r\n else:\r\n prev_min = min(prev_cache[1], prev_cache[2])\r\n cache[i] = [prev_min,\r\n float('inf'),\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n elif days[i] == 3:\r\n # куда угодна\r\n first = min(prev_cache[1], prev_cache[2])\r\n second = min(prev_cache[0], prev_cache[2])\r\n if i > 0:\r\n if days[i-1] == 1:\r\n # в предыдущий мы делали контест\r\n # second = min(prev_cache[1], prev_cache[2]) + 1\r\n second = prev_cache[2]\r\n elif days[i-1] == 2:\r\n first = prev_cache[2]\r\n # first = min(prev_cache[0], prev_cache[2]) + 1\r\n cache[i] = [first,\r\n second,\r\n min(prev_cache[0], prev_cache[1], prev_cache[2]) + 1]\r\n # print(cache)\r\n return min(cache[len(days) - 1])\r\n\r\n\r\nif __name__ == '__main__':\r\n _ = input()\r\n days = [int(el) for el in input().split()]\r\n # days = [1,1,1,1,0,1,2,2,1,2,1,2,1,2,0] #-> 5\r\n # days = [2, 2, 2, 2] #-> 2\r\n # days = [3, 3, 1, 2, 2] #-> 1\r\n # days = [2, 2, 2, 1, 1, 3, 3, 1, 2, 3, 3, 2] #-> 3\r\n # days = [1, 0, 1] #-> 1\r\n # days = [3, 3, 1, 2] #-> 0\r\n # days = '3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3'.split(' ')\r\n # days = [int(el) for el in days]\r\n # print(days)\r\n # days = [1, 2, 2, 3, 1, 3, 3, 2]\r\n print(min_rest_days(days))\r\n\r\n", "from collections import deque, Counter, OrderedDict\r\nfrom heapq import nsmallest, nlargest\r\nfrom math import ceil,floor,log,log2,sqrt,gcd,factorial,pow\r\ndef binNumber(n,size=4):\r\n return bin(n)[2:].zfill(size)\r\n\r\ndef iar():\r\n return list(map(int,input().split()))\r\n\r\ndef ini():\r\n return int(input())\r\n\r\ndef isp():\r\n return map(int,input().split())\r\n\r\ndef sti():\r\n return str(input())\r\n\r\ndef par(a):\r\n return ' '.join(list(map(str,a)))\r\n\r\nclass pair:\r\n def __init__(self,f,s):\r\n self.fi = f\r\n self.se = s\r\n def __lt__(self,other):\r\n return (self.fi,self.se) < (other.fi,other.se)\r\n\r\n# ========= /\\ /| |====/|\r\n# | / \\ | | / |\r\n# | /____\\ | | / |\r\n# | / \\ | | / |\r\n# ========= / \\ ===== |/====| \r\n# code\r\n\r\nif __name__ == \"__main__\":\r\n n = ini()\r\n a = iar()\r\n dp = [[0]*3 for i in range(n+1)]\r\n # print(dp)\r\n # 0 - rest 1 - contest 2 - sport\r\n if n == 1:\r\n if a[0] == 0:\r\n print(1)\r\n else:\r\n print(0)\r\n quit()\r\n\r\n for i in range(n):\r\n dp[i+1][0] = max(dp[i])\r\n if a[i] == 1 or a[i] == 3:\r\n dp[i+1][1] = max(dp[i][0]+1,dp[i][2]+1)\r\n if a[i] == 2 or a[i] == 3:\r\n dp[i+1][2] = max(dp[i][0]+1,dp[i][1]+1)\r\n # print(dp[i],dp[i+1])\r\n print(n - max(dp[n]))", "x = 0\r\ny = 0\r\nc = 0\r\nn = int(input())\r\na = input().split()\r\nfor i in range(0, len(a)):\r\n a[i] = int(a[i])\r\nfor i in range(0, n):\r\n x = y\r\n y = a[i]\r\n if(y == x and y != 3):\r\n y = 0\r\n if( y != x and y == 3):\r\n y -= x\r\n if(y == 0):\r\n c += 1\r\nprint(c)\r\n \r\n", "import os,sys;from io import BytesIO, IOBase\r\nBUFSIZE = 8192\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n def __init__(self, file):\r\n self._fd = file.fileno();self.buffer = BytesIO();self.writable = \"x\" in file.mode or \"r\" not in file.mode;self.write = self.buffer.write if self.writable else None\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:break\r\n ptr = self.buffer.tell();self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n def readline(self):\r\n while self.newlines == 0:b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE));self.newlines = b.count(b\"\\n\") + (not b);ptr = self.buffer.tell();self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n def flush(self):\r\n if self.writable:os.write(self._fd, self.buffer.getvalue());self.buffer.truncate(0), self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file);self.flush = self.buffer.flush;self.writable = self.buffer.writable;self.write = lambda s: self.buffer.write(s.encode(\"ascii\"));self.read = lambda: self.buffer.read().decode(\"ascii\");self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ntry:sys.stdin,sys.stdout=open('in.txt','r'),open('out.txt','w')\r\nexcept:pass\r\nii1=lambda:int(sys.stdin.readline().strip()) # for interger\r\nis1=lambda:sys.stdin.readline().strip() # for str\r\niia=lambda:list(map(int,sys.stdin.readline().strip().split())) # for List[int]\r\nisa=lambda:sys.stdin.readline().strip().split() # for List[str]\r\nmod=int(1e9 + 7);from collections import *;from math import *\r\n# abc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\r\n# sys.setrecursionlimit(500000)\r\n###################### Start Here ######################\r\nfrom functools import lru_cache\r\n# from collections import defaultdict as dd \r\nfrom collections import deque as dq \r\nclass sol:\r\n def __init__(self):\r\n\r\n self.n = ii1()\r\n self.arr = iia()\r\n self.solve()\r\n def solve(self):\r\n\r\n @lru_cache(None)\r\n def fun(idx,state):\r\n if idx == self.n:\r\n return 0 \r\n if state == 0:\r\n curr = self.arr[idx]\r\n if curr == 0:\r\n return fun(idx+1,curr)\r\n elif curr == 1:\r\n return max(1+fun(idx+1,curr),fun(idx+1,0))\r\n elif curr==2:\r\n return max(1+fun(idx+1,curr),fun(idx+1,0))\r\n elif curr==3:\r\n return max(fun(idx+1,1)+1,fun(idx+1,2)+1,fun(idx+1,0))\r\n elif state == 1:\r\n curr = self.arr[idx]\r\n if curr == 0 :\r\n return fun(idx+1,curr)\r\n elif curr==1:\r\n return fun(idx+1,0)\r\n elif curr == 2:\r\n return max(1+fun(idx+1,curr),fun(idx+1,0))\r\n elif curr == 3:\r\n return max(1+fun(idx+1,2),fun(idx+1,0))\r\n elif state == 2:\r\n curr = self.arr[idx]\r\n if curr == 0 :\r\n return fun(idx+1,curr)\r\n elif curr == 1:\r\n return max(1+fun(idx+1,curr),fun(idx+1,0))\r\n elif curr == 2:\r\n return fun(idx+1,0)\r\n elif curr == 3:\r\n return max(1+fun(idx+1,1),fun(idx+1,0))\r\n else:\r\n curr = self.arr[idx]\r\n if curr==0:\r\n return fun(idx+1,curr)\r\n elif curr==1:\r\n return max(1+fun(idx+1,curr),fun(idx+1,0))\r\n elif curr == 2:\r\n return max(1+fun(idx+1,curr),fun(idx+1,0))\r\n else:\r\n return max(1+fun(idx+1,1),1+fun(idx+1,2),fun(idx+1,0)) \r\n ans = fun(0,-1)\r\n print(self.n - ans)\r\nsol()\r\n", "input()\r\ninf = 1 << 9\r\nminimum_counts = 0, 0, 0\r\n\r\nfor num in map(int, input().split()):\r\n minimum_counts = 1 + min(minimum_counts), min(minimum_counts[0], minimum_counts[2]) if num >> 1 else inf, min(minimum_counts[0], minimum_counts[1]) if 1 & num else inf\r\n\r\nprint(min(minimum_counts))\r\n", "n = int(input())\nd = [int(_) for _ in input().split()]\nff = {(0,n):0, (1,n):0, (2,n):0}\ndef f(t,k):\n if not((t,k) in ff):\n www = []\n for x in range(3):\n if x == 0:\n www.append(f(x, k+1) + 1)\n elif (x & d[k]) and (t == 0 or t != x):\n www.append(f(x, k+1))\n ff[ (t,k) ] = min(www)\n return ff[ (t,k) ]\n\nprint(f(0,0))\n\n\n", "n = int(input())\r\na = list(map(int, input().split()))\r\ndp = [-1 for i in range(n)]\r\ndp[0] = a[0]\r\n\r\nfor i in range(1, n):\r\n\tif(a[i] == 0):\r\n\t\tdp[i] = 0\r\n\telse:\r\n\t\tif(a[i] == dp[i - 1] and a[i] != 3):\r\n\t\t\tdp[i] = 0\r\n\t\telif(a[i] == 3 and dp[i - 1] != 3):\r\n\t\t\tdp[i] = abs(3 - dp[i - 1])\r\n\t\telse:\r\n\t\t\tdp[i] = a[i]\r\n\r\nprint(dp.count(0))", "N = int(input())\na = [int(i) for i in input().split()]\ndp = [[10000 for i in range(3)] for j in range(N)]\ndp[0][0] = 1\nif a[0] == 1 or a[0] == 3:\n dp[0][1] = 0\nif a[0] == 2 or a[0] == 3:\n dp[0][2] = 0\nfor i in range(1, N):\n dp[i][0] = 1 + min(dp[i-1])\n if a[i] == 1 or a[i] == 3:\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\n if a[i] == 2 or a[i] == 3:\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\nprint(min(dp[N-1]))\n", "# on a rest day Vaya does nothing\nlength = int(input())\ndays = list(map(int, input().split()))\ncontest = False\ngym = False\nrest = 0\nfor i in range(length):\n if days[i] == 0:\n rest += 1\n contest = False\n gym = False\n\n elif days[i] == 1:\n if contest:\n rest += 1\n contest = False\n else:\n contest = True\n gym = False\n\n elif days[i] == 2:\n if gym:\n rest += 1 \n gym = False\n else:\n gym = True\n contest = False\n \n elif days[i] == 3:\n if contest:\n if gym:\n rest+=1\n gym = False\n else:\n gym = True\n contest = False\n elif gym:\n if contest:\n rest += 1\n contest = False\n else:\n contest = True\n gym = False\nprint(rest)\n \t\t\t \t\t\t \t \t\t \t \t \t \t\t\t\t \t", "n = int(input())\r\na = list(map(int, input().split()))\r\ndp = [[0 for i in range(3)] for j in range(n)]\r\n\r\n#inisialisasi awal\r\nfor i in range(len(a)):\r\n dp[i][0] = dp[i][1] = dp[i][2] = 100\r\n\r\n#set hari ke-0 (hari pertama)\r\n \r\n## hari pertama semua opsi bisa istirahat\r\ndp[0][0] = 1\r\n\r\n## kalau hari pertama itu opsi 1/3, berarti tidak istirahat\r\nif a[0] == 1 or a[0] == 3:\r\n dp[0][1] = 0\r\n \r\n## kalau hari pertama itu opsi 2/3, berarti tidak istirahat\r\nif a[0] == 2 or a[0] == 3:\r\n dp[0][2] = 0\r\n\r\n#set hari ke-1 dst (hari kedua dst)\r\nfor i in range(1,n):\r\n \r\n ## bisa selalu istirahat di opsi 0\r\n dp[i][0] = 1 + min(dp[i-1][0], min(dp[i-1][1], dp[i-1][2]))\r\n \r\n ## jika mengambil contest\r\n if a[i] == 1 or a[i] == 3:\r\n ## hari sebelumnya harus istirahat atau gym\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n \r\n ## jika mengambil gym\r\n if a[i] == 2 or a[i] == 3:\r\n ## hari sebelumnya harus istirahat atau contest\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n\r\n#output - minimal hari untuk istirahat\r\nprint(min(dp[n-1][0], min(dp[n-1][1], dp[n-1][2])))\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nd=[0]*n\r\nif a[0]==0:\r\n d[0]=1\r\nelse:\r\n d[0]=0\r\nfor i in range(1,n):\r\n if a[i]==0:\r\n d[i]=d[i-1]+1\r\n elif (a[i-1]==1 and a[i]==1)or(a[i-1]==2 and a[i]==2):\r\n d[i] = d[i - 1] + 1\r\n a[i] = 0\r\n elif a[i]==3:\r\n if a[i - 1] == 1:\r\n a[i] = 2\r\n elif a[i-1] == 2:\r\n a[i] = 1\r\n elif a[i-1] == 0:\r\n a[i] = 0\r\n d[i] = d[i - 1]\r\n else:\r\n d[i] = d[i - 1]\r\nprint(d[n-1])", "vacation_days = int(input())\r\nday_activities = list(map(int, input().split()))\r\n\r\nrest = 0\r\ncontest = 1\r\ngym = 2\r\nboth = 3\r\n\r\nprevious = rest\r\n\r\nrest_days = 0\r\n\r\nfor day in day_activities:\r\n if day == rest:\r\n rest_days += 1\r\n previous = rest\r\n elif day == contest:\r\n if previous == contest:\r\n rest_days += 1\r\n previous = rest\r\n else:\r\n previous = contest\r\n elif day == gym:\r\n if previous == gym:\r\n rest_days += 1\r\n previous = rest\r\n else:\r\n previous = gym\r\n elif day == both:\r\n if previous == gym:\r\n previous = contest\r\n elif previous == contest:\r\n previous = gym\r\n\r\nprint(rest_days)", "from math import inf \r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n f0 = f1 = f2 = 0\r\n\r\n\r\n for i in range(1, n+1):\r\n if a[i-1] == 1:\r\n tmp = f1\r\n f1 = min(f0, f2)\r\n f0 = min(tmp, f1) + 1\r\n f2 = inf \r\n elif a[i-1] == 2:\r\n tmp = f2\r\n f2 = min(f0, f1)\r\n f0 = min(tmp, f2) + 1\r\n f1 = inf \r\n elif a[i-1] == 3:\r\n tmp1 = f1 \r\n tmp2 = f2\r\n f1 = min(f0, f2)\r\n f2 = min(f0, tmp1)\r\n f0 = min(tmp1, tmp2, f0) + 1\r\n else:\r\n f0 = min(f0, f1, f2) + 1\r\n f1 = inf \r\n f2 = inf\r\n \r\n res = min(f0, f1, f2)\r\n print(res)", "input()\r\nl = list(map(int,input().split()))\r\nc = [\" \"]\r\nfor i in range(len(l)):\r\n if l[i] == 0:\r\n c.append(\" \")\r\n elif l[i] == 1:\r\n if c[-1] != 'c':\r\n c.append('c')\r\n else:\r\n c.append(\" \")\r\n elif l[i] == 2:\r\n if c[-1] != 'g':\r\n c.append('g')\r\n else:\r\n c.append(\" \")\r\n elif l[i] == 3:\r\n if c[-1] == 'g':\r\n c.append('c')\r\n elif c[-1] == 'c':\r\n c.append('g')\r\n elif i + 1 < len(l):\r\n if l[i+1] == 1:\r\n c.append('g')\r\n elif l[i+1] == 2:\r\n c.append('c')\r\n \r\nc = c[1:]\r\n#print(c)\r\nprint(c.count(\" \"))\r\n ", "n=int(input())\na=map(int,input().split())\na=list(a)\ndp=[[n] * 3 for _ in range(n+4)]\ndp[0]=[0,0,0]\nfor ii in range(n):\n aa=a[ii]\n prev=dp[ii]\n now=dp[ii+1]\n now[0]=1+min(prev)\n if aa&1:\n now[1]=min(prev[0],prev[2])\n if aa&2:\n now[2]=min(prev[0],prev[1])\nprint(min(dp[n]))\n \t \t\t\t \t\t\t \t \t\t \t\t\t\t\t\t\t", "n = int(input())\r\na=[0]*n\r\na=list(map(int, input().strip().split())) \r\nd0, d1, d2 = [0], [0], [0]\r\nfor i in range(n):\r\n d0.append(max((d0[i], d1[i], d2[i])))\r\n d1.append(max(d0[i], d2[i]) + (1 if a[i] & 1 else 0))\r\n d2.append(max(d0[i], d1[i]) + (1 if a[i] & 2 else 0))\r\nprint(n - max((d0[-1], d1[-1], d2[-1])))\r\n", "int(input())\r\ndescanso = anterior = 0\r\nfor i in [int(k) for k in input().split()]:\r\n if i == 0 or i == anterior:\r\n descanso += 1\r\n anterior = 0\r\n elif i == 3:\r\n if anterior != 0:\r\n anterior = 3 - anterior\r\n else:\r\n anterior = i\r\nprint(descanso)", "n = int(input())\r\na = list(map(int, input().split()))\r\noo = n+10\r\nd = [[oo, oo, oo] for i in range(n + 1)]\r\nd[0][0] = d[0][1] = d[0][2] = 0\r\n\r\nfor i in range(n):\r\n d[i + 1][0] = min(d[i][0], d[i][1], d[i][2]) + 1\r\n if a[i] == 1 or a[i] == 3:\r\n d[i + 1][1] = min(d[i][0], d[i][2])\r\n if a[i] == 2 or a[i] == 3:\r\n d[i + 1][2] = min(d[i][0], d[i][1])\r\nprint(min([d[n][j] for j in range(3)]))", "n=int(input())\r\narr=list(map(int,input().split()))\r\nlast=0\r\nans=0\r\nfor i in arr:\r\n if i==0:\r\n ans+=1\r\n last=0\r\n if i==1:\r\n if last==1:\r\n ans+=1\r\n last=0\r\n else:\r\n last=1\r\n if i==2:\r\n if last==2:\r\n ans+=1\r\n last=0\r\n else:\r\n last=2\r\n if i==3:\r\n if last!=0:\r\n last=3-last\r\n\r\nprint(ans)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\ndp = [[False]*2 for i in range(n)]\r\nans = 0\r\nfor i in range(n):\r\n\tif a[i] == 1:\r\n\t\tif dp[i-1][1] == True and dp[i-1][0] == False: ans += 1\r\n\t\telse: dp[i][1] = True\r\n\telif a[i] == 2:\r\n\t\tif dp[i-1][0] == True and dp[i-1][1] == False: ans += 1\r\n\t\telse: dp[i][0] = True\r\n\telif a[i] == 3:\r\n\t\tif dp[i-1][0]: dp[i][1] = True\r\n\t\tif dp[i-1][1]: dp[i][0] = True\r\n\t\tif not dp[i-1][0] and not dp[i-1][1]: dp[i][1], dp[i][0] = True, True\r\n\telse: ans += 1\r\nprint(ans)", "import math\r\nREST = 0\r\nCONTEST = 1\r\nSPORT = 2\r\nn = int(input())\r\ndays = list(map(int,input().split()))\r\nactions = {0:{REST},1:{REST,CONTEST},2:{REST,SPORT},3:{REST,CONTEST,SPORT}}\r\n\r\nmemo = {}\r\ndef dfs(days,d,last_action):\r\n # print(d,last_action)\r\n if d==n:\r\n return 0\r\n if (d,last_action) in memo:\r\n return memo[(d,last_action)]\r\n ans = math.inf \r\n for action in actions[days[d]]:\r\n if action==REST:\r\n ans = min(ans,1+dfs(days,d+1,action))\r\n elif action!=last_action:\r\n ans = min(dfs(days,d+1,action),ans)\r\n memo[(d,last_action)] = ans\r\n return ans\r\n\r\nprint(dfs(days,0,-1))\r\n \r\n ", "n = int(input())\r\narr = [int(i) for i in input().split()]\r\ncount = 0\r\nlast = 'n'\r\nfor i in range(n):\r\n # print(last, end = ' ')\r\n if arr[i] == 0:\r\n count +=1\r\n last = 'n'\r\n elif arr[i] == 1:\r\n if last != 'c':\r\n last = 'c'\r\n else:\r\n last = 'n'\r\n count += 1\r\n elif arr[i] == 2:\r\n if last != 'g':\r\n last = 'g'\r\n else:\r\n last = 'n'\r\n count += 1\r\n else:\r\n if last == 'c':\r\n last= 'g'\r\n elif last == 'g':\r\n last = 'c'\r\n else:\r\n last = 'n'\r\nprint(count) \r\n\r\n", "#!/usr/bin/env\tpython\n#-*-coding:utf-8 -*-\ninput()\nINF=1<<9\nS=0,0,0\nfor a in map(int,input().split()):S=1+min(S),min(S[0],S[2])if a>>1 else INF,min(S[0],S[1])if 1&a else INF\nprint(min(S))\n\n\n\n\n# Made By Mostafa_Khaled", "import enum\nimport sys\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\ndef get_string(): return sys.stdin.readline().strip()\ndef get_int(): return int(sys.stdin.readline().strip())\ndef get_list_strings(): return list(map(str, sys.stdin.readline().strip().split()))\n\n\n# Output for list\n# sys.stdout.write(\" \".join(map(str, final)) + \"\\n\")\n\n# Output for int or str\n# sys.stdout.write(str(best) + \"\\n\")\n\n\n\ndef solve():\n n = get_int()\n arr = get_list()\n\n store = [[0, 0, 0]]\n\n for i, ele in enumerate(arr):\n if ele == 0:\n val = max(store[-1][0], store[-1][1], store[-1][2])\n store.append([val, val, val])\n elif ele == 1:\n contest = 1 + max(store[-1][0], store[-1][2])\n gym = max(store[-1])\n free = max(store[-1])\n\n store.append([free, contest, gym])\n elif ele == 2:\n gym = 1 + max(store[-1][0], store[-1][1])\n contest = max(store[-1])\n free = max(store[-1])\n\n store.append([free, contest, gym])\n else:\n gym = 1 + max(store[-1][0], store[-1][1])\n contest = 1 + max(store[-1][0], store[-1][2])\n free = max(store[-1])\n\n store.append([free, contest, gym])\n \n\n best = 0\n\n for ele in store:\n temp = max(ele)\n best = max(best, temp)\n \n print(n-best)\n\n\n\n\n\n\n\n\n\n\n\n\n\nsolve()\n", "days = int(input())\nprevious = 0\nrest = 0\n\ntemp = [int(e) for e in input().split()]\n\nfor aux in temp:\n if(aux == 0 or aux == previous):\n previous = 0\n rest += 1\n continue\n\n if(aux == 1 or aux == 2):\n previous = aux\n continue\n\n if(previous > 0 and aux == 3):\n previous = 3 - previous\n continue\n\nprint(rest)", "\r\ninput()\r\ndp1, dp2 = 0, 0\r\nfor v in map(int, input().split()):\r\n if v == 0: dp1 = dp2 = min(dp1, dp2) + 1\r\n elif v == 1: dp1, dp2 = min(dp1 + 1, dp2), min(dp1, dp2) + 1\r\n elif v == 2: dp1, dp2 = min(dp1, dp2) + 1, min(dp1, dp2 + 1)\r\n else: dp1, dp2 = min(dp1 + 1, dp2), min(dp1, dp2 + 1)\r\nprint(min(dp1, dp2))", "n = int(input())\r\nl = [int(x) for x in input().split()]\r\ndp = [[0 for _ in range(3)] for _ in range(len(l))]\r\nfor i in range(len(l)):\r\n if i == 0:\r\n if l[i] == 1:\r\n dp[i][1] = 1\r\n elif l[i] == 2:\r\n dp[i][2] = 1\r\n elif l[i] == 3:\r\n dp[i][1] = 1\r\n dp[i][2] = 1\r\n continue\r\n if l[i] == 0:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n if l[i] == 1:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1] = max(dp[i-1][0]+1,dp[i-1][1],dp[i-1][2]+1)\r\n dp[i][2] = 0\r\n if l[i] == 2:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1] = 0\r\n dp[i][2] = max(dp[i-1][0]+1,dp[i-1][1]+1,dp[i-1][2])\r\n if l[i] == 3:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1] = max(dp[i-1][0]+1,dp[i-1][1],dp[i-1][2]+1)\r\n dp[i][2] = max(dp[i-1][0]+1,dp[i-1][1]+1,dp[i-1][2])\r\nprint(len(l)-max(dp[-1]))", "def ss(i,l,q, dp):\r\n # print(i,q, l, dp)\r\n # print(i,q)\r\n if i>=len(l):\r\n return(0)\r\n if dp[q][i]!=-1:\r\n return(dp[q][i])\r\n if l[i]==0:\r\n dp[q][i]=1+min(ss(i+1,l,1, dp), ss(i+1,l,2, dp))\r\n return(dp[q][i])\r\n if l[i]==1:\r\n if q==1:\r\n dp[q][i]=min(ss(i+1,l,2, dp), 1+ss(i+1,l,1, dp))\r\n return dp[q][i]\r\n else:\r\n dp[q][i]=1+min(ss(i+1,l,2, dp), ss(i+1,l,1, dp))\r\n return dp[q][i]\r\n elif l[i]==2:\r\n if q==2:\r\n dp[q][i]=min(ss(i+1,l,1, dp), 1+ss(i+1,l,2, dp))\r\n return dp[q][i]\r\n else:\r\n dp[q][i]=1+min(ss(i+1,l,2, dp), ss(i+1,l,1, dp))\r\n return dp[q][i]\r\n else:\r\n if q==1:\r\n dp[q][i]=min(ss(i+1,l,2, dp), 1+ss(i+1,l,1, dp))\r\n return dp[q][i]\r\n else:\r\n dp[q][i]=min(ss(i+1,l,1, dp), 1+ss(i+1,l,2, dp))\r\n return dp[q][i]\r\n \r\n \r\n \r\n \r\n\r\n# for _ in range(int(input())):\r\nn=int(input())\r\nl=list(map(int, input().split()))\r\ndp=[[-1 for _ in range(n+1)] for _ in range(3)]\r\n# print(l)\r\nprint(min(ss(0, l, 1, dp),ss(0, l, 2, dp)))\r\n \r\n ", "n = int(input())\r\na = list(map(int, input().split()))\r\n# dp = [0] * n\r\nif n == 1 and a[0] != 0:\r\n print(0)\r\nelif n == 1 and a[0] == 0:\r\n print(1)\r\nelse:\r\n if a[0] == 3:\r\n if a[1] == 1:\r\n a[0] = 2\r\n elif a[1] == 2:\r\n a[0] = 1\r\n\r\n for i in range(1, n):\r\n if a[i - 1] == a[i] != 3:\r\n a[i] = 0\r\n elif a[i] == 3:\r\n if a[i - 1] == 2:\r\n a[i] = 1\r\n elif a[i - 1] == 1:\r\n a[i] = 2\r\n cnt = 0\r\n for i in range(n):\r\n if a[i] == 0:\r\n cnt += 1\r\n print(cnt)\r\n", "input()\nseq = [int(num) for num in input().split()]\n\nprev = 0\nrest = 0\n\nfor num in seq:\n if num == prev or num == 0:\n prev = 0\n rest += 1\n elif num < 3:\n prev = num\n elif prev:\n prev = 3 - prev\n\nprint(rest)\n", "def solucao(n):\r\n N = 3\r\n MAX = float('inf')\r\n\r\n arr = [[0 for _ in range(n + 1)] for _ in range(N)]\r\n\r\n v = [int(e) for e in input().split(\" \")]\r\n for i, aux in zip(range(1, n + 1), v):\r\n arr[0][i] = 1 + min(arr[0][i - 1], min(arr[1][i - 1], arr[2][i - 1]))\r\n arr[1][i] = MAX if (aux == 0 or aux == 1) else min(arr[0][i - 1], arr[2][i - 1])\r\n arr[2][i] = MAX if (aux == 0 or aux == 2) else min(arr[0][i - 1], arr[1][i - 1])\r\n\r\n return min(arr[0][n], min(arr[1][n], arr[2][n]))\r\n\r\nn = int(input())\r\nprint(solucao(n))", "n = int(input())\r\na = list(map(int, input().split()))\r\ndp = [[n + 179] * 3 for i in range(n + 1)]\r\ndp[0] = [0, 0, 0]\r\nfor i in range(n):\r\n dp[i + 1][0] = min(dp[i][0], dp[i][1], dp[i][2]) + 1\r\n if a[i] == 1 or a[i] == 3:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n if a[i] == 2 or a[i] == 3:\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1]) \r\nprint(min(dp[n][0], dp[n][1], dp[n][2]))", "import sys\r\ninput = sys.stdin.readline\r\nn = int(input())\r\nb = list(map(int,input().split()))\r\na = [0] + b;\r\nd = [[0 for _ in range(2)] for _ in range(n+1)]\r\nfor i in range(1,n+1):\r\n d[i][0] = min(d[i-1][0], d[i-1][1]) + 1\r\n d[i][1] = min(d[i-1][0], d[i-1][1]) + 1\r\n if a[i] == 2 or a[i] == 3:\r\n d[i][0] = min(d[i][0],d[i-1][1])\r\n if a[i] == 1 or a[i] == 3:\r\n d[i][1] = min(d[i][1],d[i-1][0])\r\n\r\nprint(min(d[n][0],d[n][1]))", "\r\nfrom collections import defaultdict\r\nfrom itertools import accumulate\r\nimport sys\r\ninput = sys.stdin.readline\r\n'''\r\nfor CASES in range(int(input())):\r\nn, m = map(int, input().split())\r\nn = int(input())\r\nA = list(map(int, input().split()))\r\nS = input().strip()\r\nsys.stdout.write(\" \".join(map(str,ANS))+\"\\n\")\r\n'''\r\ninf = 100000000000000000 # 1e17\r\nmod = 998244353\r\n\r\nn = int(input())\r\nA = list(map(int, input().split()))\r\n\r\nF=[[-inf for i in range(3)] for j in range(n+1)]\r\nF[-1][0]=0\r\nfor i in range(n):\r\n if A[i]==0:\r\n F[i][0]=max(max(F[i-1][0],F[i-1][1]),F[i-1][2])\r\n elif A[i]==1:\r\n F[i][1]=max(F[i-1][0],F[i-1][2])+1\r\n F[i][0] = max(max(F[i - 1][0], F[i - 1][1]), F[i - 1][2])\r\n elif A[i]==2:\r\n F[i][2]=max(F[i-1][0],F[i-1][1])+1\r\n F[i][0] = max(max(F[i - 1][0], F[i - 1][1]), F[i - 1][2])\r\n elif A[i]==3:\r\n F[i][1]=max(F[i-1][0],F[i-1][2])+1\r\n F[i][2] = max(F[i - 1][0], F[i - 1][1])+1\r\n F[i][0] = max(max(F[i - 1][0], F[i - 1][1]), F[i - 1][2])\r\nprint(n-max(F[n-1]))\r\n\r\n", "q=int(input())\r\nw=list(map(int,input().split()))\r\ne=0\r\nif w[0]==0:\r\n e+=1\r\nfor i in range(1,q):\r\n if w[i]==0:\r\n e+=1\r\n if w[i-1]==1 and w[i]==3:\r\n w[i]=2\r\n elif w[i-1]==2 and w[i]==3:\r\n w[i]=1\r\n elif (w[i-1]==1 and w[i]==1) or (w[i-1]==2 and w[i]==2):\r\n w[i]=0\r\n e+=1\r\nprint(e)", "\r\nmem = []\r\narr = []\r\nn = 0\r\n\r\nMAX = 10000000\r\n\r\n\r\ndef solve(i, prev):\r\n if i == n:\r\n return 0\r\n if mem[i][prev] != -1:\r\n return mem[i][prev]\r\n # do sports\r\n s1 = solve(i + 1, 2) if (prev != 2 and arr[i] in [2, 3]) else MAX\r\n # do contest\r\n s2 = solve(i + 1, 1) if (prev != 1 and arr[i] in [1, 3]) else MAX\r\n # have a rest\r\n s3 = solve(i + 1, 0) + \\\r\n 1 if arr[i] == 0 or (s1 == MAX and s2 == MAX) else MAX\r\n\r\n ret = min([s1, s2, s3])\r\n mem[i][prev] = ret\r\n return ret\r\n\r\n\r\nif __name__ == \"__main__\":\r\n # import sys\r\n # sys.stdin = open(\"in.txt\", \"r\")\r\n n = int(input())\r\n arr = [int(i) for i in input().split(\" \")]\r\n mem = [[-1] * 3 for i in range(n)]\r\n print(solve(0, 0))\r\n\r\n # for j in range(3):\r\n # for i in range(n):\r\n # print(mem[i][j], end=\"\\t\")\r\n # print()\r\n", "# Read input\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\n# Define constants\r\nREST = 0\r\nCONTEST = 1\r\nGYM = 2\r\n\r\n# Initialize dp array with -1\r\ndp = [[-1] * 3 for _ in range(n)]\r\n\r\n# Define recursive function to find minimum rest days\r\ndef solve(i, prev):\r\n # Base case: if all days are processed, return 0\r\n if i == n:\r\n return 0\r\n \r\n # Memoization: if already computed, return the value\r\n if dp[i][prev] != -1:\r\n return dp[i][prev]\r\n \r\n # Initialize result as infinity\r\n res = float('inf')\r\n \r\n # Case 1: Vasya rests on day i\r\n res = min(res, 1 + solve(i + 1, REST))\r\n \r\n # Case 2: Vasya does contest on day i (if possible and not done on previous day)\r\n if a[i] == CONTEST or a[i] == CONTEST + GYM:\r\n if prev != CONTEST:\r\n res = min(res, solve(i + 1, CONTEST))\r\n \r\n # Case 3: Vasya does gym on day i (if possible and not done on previous day)\r\n if a[i] == GYM or a[i] == CONTEST + GYM:\r\n if prev != GYM:\r\n res = min(res, solve(i + 1, GYM))\r\n \r\n # Store and return the result\r\n dp[i][prev] = res\r\n return res\r\n\r\n# Call the function from the first day with no previous activity\r\nans = solve(0, REST)\r\n\r\n# Print the answer\r\nprint(ans)", "d = {\n 3: {\n 2: 1,\n 1: 2\n },\n 2: {\n 2: 0\n },\n 1: {\n 1: 0\n }\n}\n\nn = int(input())\ncont = 0\nprev = 0\nfor day in [int(i) for i in input().split()]:\n try:\n prev = d[day][prev]\n except KeyError:\n prev = day\n if prev == 0:\n cont += 1\n\nprint(cont)\n \t\t \t \t\t \t\t \t \t \t\t \t \t", "import math\r\n\r\n\r\ndef main(arr):\r\n\r\n\r\n dp=[[float('inf') for j in range(3)] for i in range(len(arr))]\r\n dp[0][0]=1 \r\n dp[0][1]=0 if (arr[0]==1 or arr[0]==3) else float('inf')\r\n dp[0][2]=0 if (arr[0]==2 or arr[0]==3) else float('inf')\r\n for i in range(1,len(dp)):\r\n for j in range(len(dp[0])):\r\n if j==0:\r\n dp[i][j]=1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n elif j==1:\r\n if arr[i]==1 or arr[i]==3:\r\n \r\n dp[i][j]=min(dp[i-1][0],dp[i-1][2])\r\n else:\r\n if arr[i]==2 or arr[i]==3:\r\n dp[i][j]=min(dp[i-1][0],dp[i-1][1])\r\n \r\n return min(dp[-1])\r\n\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nprint(main(arr))\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n", "n = input()\na = 0 ##\nb = 0\nc = 0\nfor i, v in enumerate(list(map(int, input().split()))):\n e = f = g = min(a, b, c) + 1\n if v == 2 or v == 3:\n e = min(b, e)\n if v == 1 or v == 3:\n f = min(a, f)\n a, b, c = e, f, g\nprint(min(a, b, c))\n", "import math\r\nfrom collections import Counter, deque\r\nfrom sys import stdout\r\nimport time\r\nfrom math import factorial, log, gcd\r\nimport sys\r\n\r\n\r\ndef S():\r\n return sys.stdin.readline().split()\r\n\r\n\r\ndef I():\r\n return [int(i) for i in sys.stdin.readline().split()]\r\n\r\n\r\ndef II():\r\n return int(sys.stdin.readline())\r\n\r\n\r\ndef main():\r\n n = II()\r\n a = I()\r\n s = 0\r\n ans = 0\r\n for i in range(n):\r\n el = a[i]\r\n if el == 0:\r\n s = 0\r\n ans += 1\r\n elif el == 3:\r\n if s == 2:\r\n s = 1\r\n elif s == 1:\r\n s = 2\r\n else:\r\n s = 3\r\n elif el == 1:\r\n if s == 2:\r\n s = 0\r\n ans += 1\r\n else:\r\n s = 2\r\n elif el == 2:\r\n if s == 1:\r\n s = 0\r\n ans += 1\r\n else:\r\n s = 1\r\n print(ans)\r\n\r\n\r\nif __name__ == '__main__':\r\n # for _ in range(II()):\r\n # main()\r\n main()", "def main():\r\n n = int(input())\r\n aseq = read_ints()\r\n\r\n dp = [[0] * 3 for _ in range(n+1)]\r\n for i in range(n):\r\n dp[i+1][0] = 1 + min(dp[i])\r\n\r\n if aseq[i] == 1 or aseq[i] == 3:\r\n dp[i+1][1] = min(dp[i][0], dp[i][2])\r\n else:\r\n dp[i+1][1] = 1 + dp[i][1]\r\n\r\n if aseq[i] == 2 or aseq[i] == 3:\r\n dp[i+1][2] = min(dp[i][0], dp[i][1])\r\n else:\r\n dp[i+1][2] = 1 + dp[i][2]\r\n\r\n # for row in dp:\r\n # print(row)\r\n\r\n # print()\r\n print(min(dp[-1]))\r\n\r\n\r\n\r\ndef input(): return next(test).strip()\r\ndef read_ints(): return [int(c) for c in input().split()]\r\ndef print_lines(lst): print('\\n'.join(map(str, lst)))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n import sys\r\n from os import environ as env\r\n if 'COMPUTERNAME' in env and 'L2A6HRI' in env['COMPUTERNAME']:\r\n sys.stdout = open('out.txt', 'w')\r\n sys.stdin = open('in.txt', 'r')\r\n\r\n test = iter(sys.stdin.readlines())\r\n\r\n main()\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\na.insert(0,3)\r\nv = 0\r\nfor i in range(1,n+1):\r\n act = a[i]\r\n pAct = a[i-1]\r\n if act ==3:\r\n if pAct == 1:\r\n a[i] = 2\r\n elif pAct ==2:\r\n a[i] = 1\r\n elif act ==1:\r\n if pAct ==1:\r\n a[i] = 0\r\n v+=1\r\n elif act == 2:\r\n if pAct ==2:\r\n a[i]= 0\r\n v+=1\r\n else:\r\n v+=1\r\nprint(v)\r\n\r\n", "n = int(input())\r\na = [set()for i in range(n)]\r\nb = list(map(int,input().split()))\r\nif b[0] == 0:\r\n a[0] |= {(1, 0)}\r\nif b[0] == 1:\r\n a[0] |= {(0, 1)}\r\n a[0] |= {(1, 0)}\r\nif b[0] == 2:\r\n a[0] |= {(0, 2)}\r\n a[0] |= {(1, 0)}\r\nif b[0] == 3:\r\n a[0] |= {(0, 1)}\r\n a[0] |= {(0, 2)}\r\n a[0] |= {(1, 0)}\r\nfor i in range(1, n):\r\n for j in a[i-1]:\r\n if b[i] == 1:\r\n if j[1] != 1:\r\n a[i] |= {(j[0], 1)}\r\n if b[i] == 2:\r\n if j[1] != 2:\r\n a[i] |= {(j[0], 2)}\r\n if b[i] == 3:\r\n if j[1] != 2:\r\n a[i] |= {(j[0], 2)}\r\n if j[1] != 1:\r\n a[i] |= {(j[0], 1)}\r\n a[i] |= {(j[0] + 1, 0)}\r\nprint(min(a[-1])[0])", "n = int(input())\r\narr = [int(i) for i in input().split(\" \")]\r\n\r\nglobal dp\r\ndp = [[-1] * 5 for _ in range(len(arr))]\r\n\r\ndef dp_call(index, prev):\r\n # print(index, prev)\r\n if index >= len(arr):\r\n return 0\r\n \r\n if dp[index][prev] != -1:\r\n return dp[index][prev]\r\n\r\n res = 0\r\n if prev == 0:\r\n if arr[index] == 0:\r\n res = 1 + dp_call(index+1, 0)\r\n \r\n elif arr[index] == 1 or arr[index] == 2:\r\n res = dp_call(index+1, arr[index])\r\n \r\n else:\r\n res = min(dp_call(index+1, 1), dp_call(index+1, 2))\r\n \r\n elif prev == 1:\r\n \r\n if arr[index] == 1:\r\n res = 1 + dp_call(index+1, 0)\r\n \r\n elif arr[index] == 2:\r\n res = dp_call(index+1, 2)\r\n \r\n elif arr[index] == 3:\r\n res = dp_call(index+1, 2)\r\n \r\n else:\r\n res = 1 + dp_call(index+1, 0)\r\n \r\n \r\n elif prev == 2:\r\n \r\n if arr[index] == 2:\r\n res = 1 + dp_call(index+1, 0)\r\n \r\n elif arr[index] == 1:\r\n res = dp_call(index+1, 1)\r\n \r\n elif arr[index] == 3:\r\n res = dp_call(index+1, 1)\r\n \r\n else:\r\n res = 1 + dp_call(index+1, 0)\r\n \r\n dp[index][prev] = res\r\n return res\r\n \r\n# print(dp)\r\nprint(dp_call(0, 0))\r\n# print(dp)\r\n \r\n \r\n \r\n \r\n ", "from collections import Counter, defaultdict, deque\nfrom bisect import bisect_left, bisect_right\nfrom heapq import heapify, heappush, heappop\nfrom functools import cache, lru_cache\n\n\ndef solve():\n n = int(input())\n arr = list(map(int, input().split()))\n\n dp = [[1000 for _ in range(4)] for __ in range(n + 1)]\n\n dp[0] = [0, 0, 0]\n for i in range(1, n+1):\n for prev in range(3):\n flags = [0, 0]\n\n if arr[i - 1] == 1:\n flags[1] = 1\n elif arr[i - 1] == 2:\n flags[0] = 1\n elif arr[i - 1] == 3:\n flags = [1, 1]\n res = dp[i - 1][0] + 1\n if flags[0] and prev != 1:\n res = min(res, dp[i - 1][1])\n if flags[1] and prev != 2:\n res = min(res, dp[i - 1][2])\n dp[i][prev] = res\n print(min(dp[n]))\n\n\nsolve()\n", "def minrest():\r\n n=int(input().strip())\r\n a=[int(i) for i in input().strip().split()]\r\n r=[[0 for i in range(n)] for j in range(3)]\r\n r[0][-1]=1\r\n for i in range(1,3):\r\n r[i][-1]=1 if i&a[-1]==0 else 0\r\n for i in range(n-2,-1,-1):\r\n r[0][i]=1+min(r[1][i+1],r[2][i+1])\r\n for j in range(1,3):\r\n r[j][i]=1 if j&a[i]==0 else 0\r\n r[j][i]+=min(r[(j+1)%3][i+1],r[(j+2)%3][i+1])\r\n print(min(r[0][0],r[1][0],r[2][0]))\r\n\r\nminrest()", "x=int(input())\r\ny=list(map(int,input().split()))\r\nif (y[0] == 0):\r\n list=[[0,0,0]]\r\nelif (y[0] == 1):\r\n list = [[0, 1, 0]]\r\nelif (y[0] == 2):\r\n list = [[0, 0, 1]]\r\nelif (y[0] == 3):\r\n list = [[0, 1, 1]]\r\n\r\nfor i in range(1,x):\r\n if(y[i]==0):\r\n list.append([max(list[i-1]),max(list[i-1][0],list[i-1][2]),max(list[i-1][0],list[i-1][1])])\r\n elif(y[i]==1):\r\n list.append([max(list[i - 1]), max(list[i-1][0],list[i-1][2])+1, max(list[i-1][0],list[i-1][1])])\r\n elif(y[i]==2):\r\n list.append([max(list[i - 1]), max(list[i-1][0],list[i-1][2]), max(list[i-1][0],list[i-1][1])+1])\r\n elif(y[i]==3):\r\n list.append([max(list[i - 1]), max(list[i-1][0],list[i-1][2])+1, max(list[i-1][0],list[i-1][1])+1])\r\nprint(x-max(list[-1]))", "input()\r\nl = list(map(int,input().split()))\r\nr = 0\r\nprev = 3\r\nfor i in l:\r\n if (i==prev and prev!=3):\r\n i=0\r\n elif (i==3 and prev!=3):\r\n i-=prev\r\n if i==0:\r\n r+=1\r\n prev = i\r\n \r\nprint(r)", "n = int(input())\na = [int(x) for x in input().split()]\ninf = 100000\ndp = [[0,0,0] for i in range(n+1)]\nfor i in range(1,n+1):\n\tdp[i][0] = 1 + min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\n\tdp[i][1] = inf if a[i-1] == 0 or a[i-1] == 1 else min(dp[i-1][0],dp[i-1][2])\n\tdp[i][2] = inf if a[i-1] == 0 or a[i-1] == 2 else min(dp[i-1][0],dp[i-1][1])\n\nprint(min(dp[n][0], dp[n][1], dp[n][2]))\n\n", "# from sys import stdout\r\n\r\nlog = lambda *x: print(*x)\r\n\r\ndef cin(*fn, def_fn=str):\r\n\ti,r = 0,[]\r\n\tfor c in input().split(' '):\r\n\t\tr+=[(fn[i] if len(fn)>i else fn[0]) (c)]\r\n\t\ti+=1\r\n\treturn r\r\n\r\nINF = 1 << 33\r\n\r\n\r\ndef solve(a, n):\r\n\tdp = []\r\n\tfor i in range(n+1):\r\n\t\tdp += [[]]\r\n\t\tfor j in range(n+1):\r\n\t\t\tdp[i] += [{1:0,10:0,11:0}]\r\n\r\n\tfor i in range(n, -1, -1):\r\n\t\tfor t in range(n-1, -1, -1):\r\n\r\n\t\t\tfor tf in [11, 10, 1]:\r\n\t\t\t\tif i == n:\r\n\t\t\t\t\tdp[i][t][tf] = i-t\r\n\t\t\t\t\tcontinue\r\n\r\n\t\t\t\tcc = (tf//10) and (a[i]==1 or a[i]==3)\r\n\t\t\t\tcg = (tf%10) and (a[i]==2 or a[i]==3)\r\n\r\n\t\t\t\tif not (cc or cg):\r\n\t\t\t\t\tdp[i][t][tf] = dp[i+1][t][11]\r\n\t\t\t\t\tcontinue\r\n\r\n\t\t\t\ta1,a2=INF,INF\r\n\t\t\t\tif cc: a1 = dp[i+1][t+1][1]\r\n\t\t\t\tif cg: a2 = dp[i+1][t+1][10]\r\n\r\n\t\t\t\tdp[i][t][tf] = min(a1, a2)\r\n\t\t\t#}\r\n\t\t#}\r\n\treturn min(dp[0][0][1], dp[0][0][10])\r\n\r\n\r\nn, = cin(int)\r\na = cin(int)\r\n\r\nlog(solve(a, n))\r\n\r\n\r\n", "n = int(input())\r\n\r\na = [0 for i in range(n)]\r\nb = [0 for i in range(n)]\r\nc = [0 for i in range(n)]\r\n\r\n\r\nd = list(map(int, input().split()))\r\n\r\nif d[0] == 0:\r\n a[0] = 0\r\n b[0] = 0\r\n \r\nelif d[0] == 1:\r\n a[0] = 1\r\n b[0] = 0\r\n\r\nelif d[0] == 2:\r\n a[0] = 0\r\n b[0] = 1\r\n \r\nelse:\r\n a[0] = 1\r\n b[0] = 1\r\n\r\nfor i in range(1, n):\r\n if d[i] == 0:\r\n a[i] = 0\r\n b[i] = 0\r\n c[i] = max(a[i-1], b[i-1], c[i-1])\r\n \r\n elif d[i] == 1:\r\n a[i] = max(b[i-1], c[i-1]) + 1\r\n b[i] = 0\r\n c[i] = max(a[i-1], b[i-1], c[i-1])\r\n \r\n elif d[i] == 2:\r\n a[i] = 0\r\n b[i] = max(a[i-1], c[i-1]) + 1\r\n c[i] = max(a[i-1], b[i-1], c[i-1])\r\n \r\n else:\r\n a[i] = max(b[i-1], c[i-1]) + 1\r\n b[i] = max(a[i-1], c[i-1]) + 1\r\n c[i] = max(a[i-1], b[i-1], c[i-1])\r\n \r\nprint(n - max(a[n-1], b[n-1], c[n-1]))\r\n", "from sys import stdin, stdout\r\n#stdin = open('Vacations.txt', 'r') \r\ndef II(): return int(stdin.readline())\r\ndef LI(): return list(map(int, stdin.readline().split()))\r\n\r\nn = II()\r\na = LI()\r\nmaxRest = 101\r\n#minRest[i][x] - Minimum rest if we choose option x on ith day\r\n#x = 0 for rest, x = 1 for contest, x = 2 for Gym on ith day\r\nminRest = [[maxRest for x in range(3)] for y in range(n)]\r\nminRest[0][0] = 1\r\nif a[0] == 1 or a[0] == 3:\r\n minRest[0][1] = 0\r\nif a[0] == 2 or a[0] == 3:\r\n minRest[0][2] = 0\r\n\r\nfor i in range(1,n):\r\n minRest[i][0] = 1 + min( minRest[i-1][0], minRest[i-1][1], minRest[i-1][2])\r\n if a[i] == 1 or a[i] == 3:\r\n minRest[i][1] = min( minRest[i-1][0], minRest[i-1][2])\r\n if a[i] == 2 or a[i] == 3:\r\n minRest[i][2] = min( minRest[i-1][0], minRest[i-1][1])\r\nans = min(minRest[n-1])\r\nstdout.write(\"{} \\n\".format(ans))\r\n", "input()\r\n\r\nA = map(int, input().split(' '))\r\n\r\ntfo=0\r\nr=0\r\n\r\nfor a in A :\r\n if a==3:\r\n tfo= -tfo%3\r\n elif a==0:\r\n r+=1\r\n tfo=0\r\n else :\r\n if tfo==a:\r\n r+=1\r\n tfo=0\r\n else :\r\n tfo=a\r\n \r\nprint(r)", "n = int(input())\r\nai = list(map(int,input().split()))\r\nfor i in range(n):\r\n if i < n-1:\r\n if ai[i] % 3 != 0 and ai[i] == ai[i+1]:\r\n ai[i+1] = 0\r\n elif ai[i+1] == 3 and ai[i] % 3 != 0:\r\n ai[i+1] = 3 - ai[i]\r\n ai[i] = int(ai[i] > 0)\r\nprint(n - sum(ai))\r\n", "n=int(input());s=list(map(int,input().split()));res=0;crr=10\r\nla=['0','0 1','0 2','0 1 2'] \r\nfor x in s : \r\n l=list(map(int,la[x].split()))\r\n if crr in l : l.remove(crr)\r\n if max(l)==0 : res+=1;crr=10\r\n elif len(l)==3 : crr=10\r\n else: crr = max(l) \r\nprint(res)\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nd=[]\r\nj=[0,0,0]\r\nif l[0]==1 or l[0]==3:\r\n\tj[1]=1\r\nif l[0]==2 or l[0]==3:\r\n\tj[2]=1\r\nd.append(j)\r\nfor i in range(1,n):\r\n\tj=[0,0,0]\r\n\tj[0]=max(d[i-1])\r\n\tif l[i]==1 or l[i]==3:\r\n\t\tj[1]=max(d[i-1][0]+1,d[i-1][2]+1)\r\n\tif l[i]==2 or l[i]==3:\r\n\t\tj[2]=max(d[i-1][0]+1,d[i-1][1]+1)\r\n\td.append(j)\r\nprint(n-max(d[-1]))", "# maa chudaaye duniya\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nd0, d1, d2 = [0], [0], [0]\r\nfor i in range(n):\r\n d0.append(max((d0[i], d1[i], d2[i])))\r\n d1.append(max((d0[i], d2[i])) + (1 if a[i]&1 else 0))\r\n d2.append(max((d0[i], d1[i])) + (1 if a[i]&2 else 0))\r\n\r\nprint(n - max((d0[-1], d1[-1], d2[-1])))", "n = int(input())\r\n#print(n)\r\na = list(map(int,input().strip().split()))\r\n#print(a)\r\n\r\nrows, cols = (n+1, 3) \r\ndp = [[0 for i in range(cols)] for j in range(rows)] \r\n#print(dp)\r\n\r\nfor i in range(0,n):\r\n if a[i] == 0:\r\n dp[i+1][0] = min(dp[i][0],min(dp[i][1],dp[i][2])) + 1\r\n dp[i+1][1] = dp[i][1] + 1\r\n dp[i+1][2] = dp[i][2] + 1\r\n elif a[i] == 1:\r\n dp[i+1][0] = min(dp[i][0],min(dp[i][1],dp[i][2])) + 1\r\n dp[i+1][1] = min(dp[i][0],dp[i][2])\r\n dp[i+1][2] = dp[i][2] + 1\r\n elif a[i] == 2:\r\n dp[i+1][0] = min(dp[i][0],min(dp[i][1],dp[i][2])) + 1\r\n dp[i+1][1] = dp[i][1] + 1\r\n dp[i+1][2] = min(dp[i][0], dp[i][1])\r\n elif a[i] == 3:\r\n dp[i+1][0] = min(dp[i][0],min(dp[i][1],dp[i][2])) + 1\r\n dp[i+1][1] = min(dp[i][0], dp[i][2])\r\n dp[i+1][2] = min(dp[i][0], dp[i][1])\r\n\r\n\r\nprint(min(dp[n][0],min(dp[n][1],dp[n][2])))\r\n \r\n \r\n\r\n\r\n ", "def dp(l,x):\r\n if (l,x) in d:\r\n return(d[(l,x)])\r\n if len(l)==0:\r\n return(0)\r\n if l[0]==0:\r\n d[(l,x)]=1+dp(l[1:],\"r\")\r\n return(d[(l,x)])\r\n elif l[0]==1:\r\n if x==\"c\":\r\n d[(l,x)]=1+dp(l[1:],\"r\")\r\n return(d[(l,x)])\r\n else:\r\n d[(l,x)]=dp(l[1:],\"c\")\r\n return(d[(l,x)])\r\n elif l[0]==2:\r\n if x==\"g\":\r\n d[(l,x)]=1+dp(l[1:],\"r\")\r\n return(d[(l,x)])\r\n else:\r\n d[(l,x)]=dp(l[1:],\"g\")\r\n return(d[(l,x)])\r\n elif l[0]==3:\r\n if x==\"c\":\r\n d[(l,x)]=dp(l[1:],\"g\")\r\n return(d[(l,x)])\r\n elif x==\"g\":\r\n d[(l,x)]=dp(l[1:],\"c\")\r\n return(d[(l,x)])\r\n else:\r\n d[(l,x)]=min((dp(l[1:],\"c\")),(dp(l[1:],\"g\")))\r\n return(d[(l,x)])\r\nn=int(input())\r\nl=tuple([int(a) for a in input().split()])\r\nd={} \r\nprint(dp(l,\"r\")) ", "n=int(input())\r\nmas=list(map(int,input().split()))\r\nz=[0]*n\r\ncount=0\r\nfor i in range(n):\r\n if mas[i]==0:\r\n z[i]=0\r\n count+=1\r\n elif mas[i]==2 or mas[i]==1:\r\n if z[i-1]==mas[i]:\r\n z[i]=0\r\n count+=1\r\n else:\r\n z[i]=mas[i]\r\n else:\r\n if z[i-1]==1:\r\n z[i]=2\r\n elif z[i-1]==2:\r\n z[i]=1\r\n else:\r\n z[i]=0\r\n \r\n \r\nprint(count)\r\n\r\n\r\n", "import sys\r\nimport threading\r\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\nprint = stdout.write\r\nimport math\r\nfrom collections import Counter\r\n\r\ndef can(m ,s):\r\n return True if (s>=0 and s <= 9*m) else False\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input().strip())\r\n a = list(map(int, input().strip().split()))\r\n prev_assignment = a[0]\r\n if prev_assignment == 0:\r\n rest = 1\r\n else: \r\n rest = 0\r\n \r\n for i in range(1,n):\r\n if prev_assignment == a[i] and a[i]!= 3:\r\n #This means user has no choice but to rest\r\n a[i] = 0\r\n elif a[i] == 3 and prev_assignment != 3:\r\n a[i] -= prev_assignment\r\n \r\n if a[i] == 0:\r\n rest += 1\r\n \r\n prev_assignment = a[i]\r\n\r\n print(f\"{rest}\\n\")\r\n", "import sys\r\nimport math\r\nimport collections\r\nimport bisect\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\nn=int(input())\r\narr=get_list()\r\nans=[arr[0]]\r\nfor i in range(1,n):\r\n ele=arr[i]\r\n if ele==0:\r\n ans.append(0)\r\n elif ele==1:\r\n if ans[i-1]==1:\r\n ans.append(0)\r\n else:\r\n ans.append(1)\r\n elif ele==2:\r\n if ans[i-1]==2:\r\n ans.append(0)\r\n else:\r\n ans.append(2)\r\n else:\r\n if ans[i-1]==1:\r\n ans.append(2)\r\n elif ans[i-1]==2:\r\n ans.append(1)\r\n else:\r\n ans.append(3)\r\nprint(ans.count(0))", "import sys\nsys.setrecursionlimit(10000)\n\ndef count_rest(previous_act, day):\n\n if day >= len(schedule):\n return 0\n\n if pd[previous_act][day] == None:\n\n if schedule[day] == 0:\n pd[previous_act][day] = 1 + count_rest(0, day+1)\n \n elif previous_act == 0:\n\n if schedule[day] == 1:\n pd[previous_act][day] = min(1 + count_rest(0, day+1), count_rest(1, day+1))\n elif schedule[day] == 2:\n pd[previous_act][day] = min(1 + count_rest(0, day+1), count_rest(2, day+1))\n elif schedule[day] == 3:\n pd[previous_act][day] = min(1 + count_rest(0, day+1), count_rest(1, day+1), count_rest(2, day+1))\n \n elif previous_act == 1:\n\n if schedule[day] == 1:\n pd[previous_act][day] = 1 + count_rest(0, day+1)\n else:\n pd[previous_act][day] = min(1 + count_rest(0, day+1), count_rest(2, day+1))\n \n elif previous_act == 2:\n\n if schedule[day] == 2:\n pd[previous_act][day] = 1 + count_rest(0, day+1)\n else:\n pd[previous_act][day] = min(1 + count_rest(0, day+1), count_rest(1, day+1))\n \n return pd[previous_act][day]\n\nn = int(input())\nschedule = list(map(int, input().split()))\npd = [[None for _ in range(len(schedule))] for _ in range(3)]\n\nprint(count_rest(0, 0))", "'''\r\na i equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;\r\na i equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;\r\na i equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;\r\na i equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.\r\n\r\n'''\r\n\r\nn = int(input())\r\nalist = list(map(int, input().split()))\r\n\r\ndp = [[101 for _ in range(4)] for _ in range(n+1)]\r\n\r\nfor i in range(4):\r\n dp[0][i]=0\r\nfor i in range(1, n+1):\r\n dp[i][0] = min([dp[i-1][0],dp[i-1][1],dp[i-1][2]]) + 1\r\n if alist[i-1] == 1:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n elif alist[i-1] == 2:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n elif alist[i-1] == 3:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n \r\nprint(min([dp[n][0],dp[n][1],dp[n][2]]))\r\n \r\n\r\n \r\n ", "n=int(input())\r\narr =list(map(int,input().split()))\r\nfree_days=0\r\nx=0\r\nfor i in range(len(arr)):\r\n if arr[i]==0 or arr[i]==x:\r\n free_days+=1\r\n x=0\r\n elif arr[i]==3:\r\n if(x!=0):\r\n x=3-x\r\n else:\r\n x=arr[i]\r\nprint(free_days)", "abc = lambda: map(int, input().split())\r\nn = int(input())\r\nlis = [[0, 0, 0] for i in range(n + 1)]\r\n\r\nfor i, x in enumerate(abc()):\r\n lis[i][0] = min(lis[i - 1]) + 1\r\n if x == 3:\r\n lis[i][1] = min(lis[i - 1][0], lis[i - 1][2])\r\n lis[i][2] = min(lis[i - 1][0], lis[i - 1][1])\r\n elif x == 2:\r\n lis[i][1] = n + 1\r\n lis[i][2] = min(lis[i - 1][0], lis[i - 1][1])\r\n elif x == 1:\r\n lis[i][1] = min(lis[i - 1][0], lis[i - 1][2])\r\n lis[i][2] = n + 1\r\n else:\r\n lis[i] = [min(lis[i - 1]) + 1] * 3\r\n\r\nprint(min(lis[n - 1]))", "import sys\nfrom functools import lru_cache\n\npossible = {\n 0: {'r'},\n 1: {'r', 'c'},\n 2: {'r', 'g'},\n 3: {'r', 'c', 'g'}\n}\n\n@lru_cache(maxsize=None)\ndef min_rest(i, prev_action):\n if i == len(arr):\n return 0\n\n # At least one elem in the arr.\n p = possible[arr[i]]\n best = float(\"inf\")\n for act in p:\n if act == 'r':\n # Can always rest, no restrictions.\n best = min(best, 1 + min_rest(i + 1, 'r'))\n elif act != prev_action:\n best = min(best, min_rest(i + 1, act))\n return best\n\nif __name__ == \"__main__\":\n mat = []\n for e, line in enumerate(sys.stdin.readlines()):\n if e == 0:\n continue\n arr = list(map(int, line.strip().split()))\n print(min_rest(0, 'r'))\n", "if(__name__ == '__main__'):\n inf = 0x3f3f3f3f\n dp = []\n for i in range(105):\n dp.append([inf, inf, inf])\n\n\n n = int(input())\n dp[0][0] = 0\n i = 0\n for x in input().split(' '):\n i += 1\n x = int(x)\n dp[i][0] = min(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1\n if x == 1 or x == 3:\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\n if x == 2 or x == 3:\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\n print(min(dp[n][0], dp[n][1], dp[n][2]))\n \t\t \t\t\t\t\t\t \t \t \t \t \t \t \t\t", "def getMinRestDays(vacations,activities):\r\n\tw, h = vacations, 3\r\n\tMatrix = [[vacations+1 for x in range(w)] for y in range(h)]\r\n\tMatrix[0][0]=1\r\n\tif activities[0] in (1,3): # filling Contest\r\n\t\tMatrix[1][0]=0\r\n\tif activities[0] in (2,3): # filling Gym\r\n\t\tMatrix[2][0]=0\r\n\r\n\tfor i in range(1,w):\r\n\t\tMatrix[0][i]= 1+ min(Matrix[0][i-1],Matrix[1][i-1],Matrix[2][i-1])\r\n\t\tif activities[i] in (1,3):\r\n\t\t\tMatrix[1][i]= min(Matrix[0][i-1],Matrix[2][i-1])\r\n\t\tif activities[i] in (2,3):\r\n\t\t\tMatrix[2][i]= min(Matrix[0][i-1],Matrix[1][i-1])\r\n\tMinRest=min(Matrix[0][vacations-1],Matrix[1][vacations-1],Matrix[2][vacations-1])\r\n\treturn MinRest\r\n\r\n#__Main___\r\ndef main():\r\n # input\r\n\tvacations=int(input())\r\n\tactivities = [int(x) for x in input().split()]\r\n\t# return Min Rest days\r\n\t# Matrix,MinRest=\r\n\tMinRest=getMinRestDays(vacations,activities)\r\n\t#print(Matrix)\r\n\tprint(MinRest)\r\n\t# a=range(4)\r\n\t# print(a[3])\r\nif __name__ == \"__main__\":\r\n main()", "\r\nimport sys\r\n\r\n\r\n# Input Functions\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\n# Output Functions\r\ndef outp(s):\r\n sys.stdout.write(s + '\\n')\r\ndef loutp(l):\r\n sys.stdout.write(' '.join(map(str,l)) + '\\n')\r\n\r\ndef solve():\r\n\r\n n = inp()\r\n ds = inlt()\r\n\r\n db = None\r\n ans = 0\r\n for i, d in enumerate(ds):\r\n if d == 0:\r\n ans += 1\r\n elif d == db and d != 3:\r\n ans += 1\r\n ds[i] = 0\r\n elif d == 3 and db == 2:\r\n ds[i] = 1\r\n elif d == 3 and db == 1:\r\n ds[i] = 2\r\n db = ds[i]\r\n \r\n outp(str(ans))\r\n\r\n\r\nif __debug__:\r\n input = sys.stdin.readline\r\n solve()\r\n", "import math\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n#for _ in range (int(input())):\r\nn = int(input())\r\na = [int(i) for i in input().split()]\r\nc = a[0]\r\nfor i in range (1,n):\r\n if a[i] == c and c!=3:\r\n a[i] = 0\r\n elif c!=3 and a[i] == 3:\r\n if c == 2:\r\n a[i] = 1\r\n if c == 1:\r\n a[i] = 2\r\n c = a[i]\r\nprint(a.count(0))", "t=int(input())\r\ns=list(map(int,input().split()))\r\ndp1=[0 for i in range(t)]\r\ndp2=[0 for i in range(t)]\r\ndp1[0]=0 if s[0]&1 else 1\r\ndp2[0]=0 if s[0]&2 else 1\r\nfor i in range(1,t):\r\n if s[i]==3:\r\n dp1[i],dp2[i]=dp2[i-1],dp1[i-1]\r\n elif s[i]==2:\r\n dp1[i],dp2[i]=min(dp1[i-1],dp2[i-1])+1,dp1[i-1]\r\n elif s[i]==1:\r\n dp1[i],dp2[i]=dp2[i-1],min(dp1[i-1],dp2[i-1])+1\r\n else:\r\n dp2[i]=dp1[i]=min(dp1[i-1],dp2[i-1])+1\r\nprint(min(dp1[t-1],dp2[t-1]))", "n = int(input())\r\na = list(map(int,input().split()))\r\nrest = 0\r\nprev = 3\r\nfor i in a:\r\n if i==prev and prev!=3:\r\n i = 0\r\n elif i==3 and prev!=3:\r\n i -= prev\r\n if i==0:\r\n rest += 1\r\n prev = i\r\nprint(rest)", "n = int(input())\r\ndata = [int(x) for x in input().split()]\r\n\r\ncontest = [0] * (n + 1)\r\nsport = [0] * (n + 1)\r\ncontest_sum = [0] * (n + 1)\r\nsport_sum = [0] * (n + 1)\r\n\r\nfor i in range(n):\r\n if data[i] == 1:\r\n contest[i + 1] = 1\r\n elif data[i] == 2:\r\n sport[i + 1] = 1\r\n elif data[i] == 3:\r\n contest[i + 1] = 1\r\n sport[i + 1] = 1\r\n\r\ncontest_sum[1] = contest[0]\r\nsport_sum[1] = sport[0]\r\n\r\nfor i in range(1, n + 1):\r\n # Contest\r\n if contest_sum[i - 2] != contest_sum[i - 1]:\r\n contest_sum[i] = max(contest_sum[i - 1], sport_sum[i - 1] + contest[i])\r\n else:\r\n contest_sum[i] = max(contest_sum[i - 1] + contest[i], sport_sum[i - 1] + contest[i])\r\n\r\n # Sport\r\n if sport_sum[i - 2] != sport_sum[i - 1]:\r\n sport_sum[i] = max(sport_sum[i - 1], contest_sum[i - 1] + sport[i])\r\n else:\r\n sport_sum[i] = max(sport_sum[i - 1] + sport[i], contest_sum[i - 1] + sport[i])\r\n\r\nprint(n - max(contest_sum[-1], sport_sum[-1]))\r\n", "def find_rest_days(n, days):\n dp = [[None] * 3 for _ in range(n)]\n\n dp[0][0] = (1, 0)\n dp[0][1] = (0, 1) if 1 & days[0] else (1, 0)\n dp[0][2] = (0, 2) if 2 & days[0] else (1, 0)\n \n for i in range(1, n):\n prev_best = sorted(dp[i - 1], key=lambda x: x[0])\n dp[i][0] = (prev_best[0][0] + 1, 0)\n if days[i] & 1:\n best_allowed = list(filter(lambda x: x[1] != 1, prev_best))\n dp[i][1] = (best_allowed[0][0], 1)\n else:\n dp[i][1] = dp[i][0]\n if days[i] & 2:\n best_allowed = list(filter(lambda x: x[1] != 2, prev_best))\n dp[i][2] = (best_allowed[0][0], 2)\n else:\n dp[i][2] = dp[i][0]\n\n return min(dp[n - 1], key=lambda x: x[0])\n \n\nn = int(input())\ndays = list(map(int, input().split()))\n\nans = find_rest_days(n, days)\nprint(ans[0])", "n = int(input())\r\na = list(map(int, input().split(' ')))\r\ndp = [[0 for i in range(3)] for _ in range(102)]\r\n\r\nfor i in range(1, n + 1):\r\n if a[i - 1] == 0:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n dp[i][1] = dp[i - 1][1] + 1\r\n dp[i][2] = dp[i - 1][2] + 1\r\n\r\n elif a[i - 1] == 1:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n dp[i][2] = dp[i- 1][2] + 1\r\n\r\n elif a[i - 1] == 2:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n dp[i][1] = dp[i - 1][1] + 1\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n\r\n elif a[i - 1] == 3:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n\r\nprint(min(dp[n]))", "import collections\r\n\r\nfrom collections import defaultdict\r\nfrom sys import setrecursionlimit, stdin, stdout, stderr\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import defaultdict, deque, Counter\r\nfrom itertools import accumulate, combinations, permutations, product\r\nfrom functools import lru_cache, cmp_to_key, reduce\r\nfrom heapq import heapify, heappush, heappop, heappushpop, heapreplace\r\n\r\nN=int(input())\r\narr=list(map(int,input().split()))\r\ndp = [[float(\"INF\") for i in range(3)] for i in range(N+1)]\r\ndp[0][0] = 0\r\nfor i in range(N):\r\n dp[i+1][0] = min(dp[i])+1\r\n dp[i+1][1] = min(dp[i])+1\r\n dp[i+1][2] = min(dp[i])+1\r\n if arr[i]==1 or arr[i]==3:\r\n dp[i+1][1] = min(dp[i][0],dp[i][2])\r\n if arr[i]==2 or arr[i]==3:\r\n dp[i+1][2] = min(dp[i][0],dp[i][1])\r\n \r\nprint(min(dp[N]))", "\r\ndef answer(n, a):\r\n num_rest = 0\r\n if a[0] == 0:\r\n num_rest += 1\r\n # otherwise, guaranteed to do something. no restrictions yet.\r\n \r\n for i in range(1, n):\r\n if a[i] == 0:\r\n num_rest += 1\r\n elif (a[i] == 1) and (a[i-1] != 1):\r\n a[i] = 1\r\n elif (a[i] == 1) and (a[i-1] == 1):\r\n a[i] = 0\r\n num_rest += 1\r\n elif (a[i] == 2) and (a[i-1] != 2):\r\n a[i] = 2\r\n elif (a[i] == 2) and (a[i-1] == 2): \r\n a[i] = 0\r\n num_rest += 1\r\n elif (a[i] == 3) and (a[i-1] == 1):\r\n a[i] = 2\r\n elif (a[i] == 3) and (a[i-1] == 2):\r\n a[i] = 1\r\n \r\n return num_rest\r\n\r\ndef main():\r\n n = int(input())\r\n a = [int(i) for i in input().split()]\r\n print(answer(n, a))\r\n\r\n\r\n\r\n return\r\nmain()", "n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\ndp=[[0]*3 for i in range(n+1)]\r\nl.insert(0,0)\r\nfor i in range(1,n+1):\r\n if l[i] in [1,3]:\r\n dp[i][1]=max(dp[i-1][0],dp[i-1][2])+1\r\n if l[i] in [2,3]:\r\n dp[i][2]=max(dp[i-1][1],dp[i-1][0])+1\r\n\r\n dp[i][0]=max(dp[i-1])\r\n \r\n\r\nprint(n-max(dp[n]))\r\n", "from bisect import bisect_left, bisect_right\r\nfrom collections import Counter, deque\r\nfrom functools import lru_cache\r\nfrom math import factorial, comb, sqrt, gcd, lcm, log2\r\nfrom copy import deepcopy\r\nimport heapq\r\n\r\nfrom sys import stdin, stdout\r\n\r\n\r\ninput = stdin.readline\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n L = list(map(int, input().split()))\r\n dp1 = [float(\"inf\")] * (n + 1) # 健身\r\n dp2 = [float(\"inf\")] * (n + 1) # 比赛\r\n dp3 = [float(\"inf\")] * (n + 1) # 休息\r\n dp1[0] = 0\r\n dp2[0] = 0\r\n dp3[0] = 0\r\n for i in range(1, n + 1):\r\n dp3[i] = min(dp1[i - 1], dp2[i - 1], dp3[i - 1]) + 1\r\n if L[i - 1] in [2, 3]:\r\n dp1[i] = min(dp2[i - 1], dp3[i - 1])\r\n if L[i - 1] in [1, 3]:\r\n dp2[i] = min(dp1[i - 1], dp3[i - 1])\r\n print(min(dp1[-1], dp2[-1], dp3[-1]))\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\r\nl=[int(x) for x in input().split()]\r\na = [[0 for i in range(3)] for j in range(n)]\r\ninf = 10**9\r\na[0][0]=1\r\nif l[0]==1 or l[0]==3:\r\n a[0][1]=0 \r\nelse:\r\n a[0][1]=inf\r\nif l[0]==2 or l[0]==3:\r\n a[0][2]=0\r\nelse:\r\n a[0][2]=inf\r\n\r\nfor i in range(1,n):\r\n a[i][0] = min(a[i-1])+1 \r\n if l[i]==1 or l[i]==3:\r\n a[i][1] = min(a[i-1][0],a[i-1][2]) \r\n else:\r\n a[i][1]=inf \r\n if l[i]==2 or l[i]==3:\r\n a[i][2] = min(a[i-1][:-1]) \r\n else:\r\n a[i][2]=inf\r\nprint(min(a[n-1]))\r\n ", "if __name__ == '__main__':\n n = int(input())\n memo = [[0, 0, 0] for _ in range(n)]\n row1 = []\n row2 = []\n for c in map(int, input().split()):\n if c == 0:\n row1.append(0)\n row2.append(0)\n elif c == 1:\n row1.append(0)\n row2.append(1)\n elif c == 2:\n row1.append(1)\n row2.append(0)\n elif c == 3:\n row1.append(1)\n row2.append(1)\n memo[0] = [0, row1[0], row2[0]]\n for i in range(1, n):\n memo[i][0] = max(memo[i - 1])\n memo[i][1] = row1[i] + max(memo[i - 1][0], memo[i - 1][2])\n memo[i][2] = row2[i] + max(memo[i - 1][0], memo[i - 1][1])\n print(n - max(memo[-1]))\n\n\t\t \t\t\t \t \t\t\t\t\t\t \t \t\t", "\"\"\"\r\n## NOTE\r\n- good dp\r\n- we are looking for min total number of DAYS we will rest\r\n\r\n\r\n## INFO\r\n698_A_Vacations\r\nhttps://codeforces.com/problemset/problem/698/A\r\n\r\n## TAGS\r\n- dp\r\n- *1400\r\n\r\n## TESTS\r\n\r\nwe can do this: [1 2 rest 0=rest]\r\nor [1 rest 2 0=rest]\r\n-in:\r\n4\r\n1 3 2 0\r\n-out:\r\n2\r\n\r\n\r\n-in:\r\n7\r\n1 3 3 2 1 2 3\r\n-out:\r\n0\r\n\r\n-in:\r\n2\r\n2 2\r\n-out:\r\n1\r\n\r\n\"\"\"\r\n\r\n#%%\r\n\r\nimport sys\r\nimport time\r\n\r\nstart_time = time.time()\r\nFILE = False\r\n\r\n# ---------------------- HELPER INPUT FUNCTIONS ----------------------#\r\n\r\n\r\ndef get_int():\r\n return int(sys.stdin.readline())\r\n\r\n\r\ndef get_str():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\ndef get_list_int():\r\n return list(map(int, sys.stdin.readline().split()))\r\n\r\n\r\ndef get_list_str():\r\n return list(sys.stdin.readline().split())\r\n\r\n\r\n# -------------------------- SOLVE FUNCTION --------------------------#\r\n\r\n\r\ndef solve():\r\n n = get_int()\r\n arr = get_list_int()\r\n\r\n # rest = 1 if arr[0] == 0 else 0\r\n rest = int(arr[0] == 0)\r\n\r\n for i in range(1, n):\r\n if arr[i] == 3:\r\n arr[i] = 3 - arr[i - 1]\r\n elif arr[i] == 0 or arr[i] == arr[i - 1]:\r\n rest += 1\r\n arr[i] = 0\r\n\r\n print(rest)\r\n\r\n\r\n# -------------------------- MAIN FUNCTION --------------------------#\r\n\r\n\r\ndef main():\r\n if FILE:\r\n sys.stdin = open(\"./src/codeforces/input.txt\", \"r\")\r\n\r\n solve()\r\n\r\n if FILE:\r\n print(\"\\033[95m\" + \"> time elapsed: \", (time.time() - start_time) * 1000.0, \"ms\")\r\n\r\n\r\nmain()\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nc = ct = gm = 0\r\nfor i in range(n):\r\n if a[i]==0:\r\n ct=0\r\n gm=0\r\n c += 1\r\n elif a[i]==1 and ct==0:\r\n ct=1\r\n gm=0\r\n elif a[i]==2 and gm==0:\r\n gm=1\r\n ct=0\r\n elif a[i]==3:\r\n if ct==1:\r\n ct=0\r\n gm=1\r\n elif gm==1:\r\n gm=0\r\n ct=1\r\n else:\r\n ct=0\r\n gm=0\r\n c += 1\r\nprint(c)", "import sys\ninput = sys.stdin.readline\nprint = sys.stdout.write\n\ndef yes(): print(\"yes\\n\")\ndef no(): print(\"no\\n\")\ndef printl(l):\n\tfor n in l: print(str(n) + \" \")\n\tprint(\"\\n\")\ndef printi(i): print(str(i) + \"\\n\")\ndef read(): return int(input())\ndef readl(): return list(map(int, input().split(\" \")))\ndef readp(): return map(int, input().split(\" \"))\n\n### =========== CODE BEGINS HERE ==========\ndef solve(n, a):\n\tp = 0\n\tans = 0\n\tfor i in range(n):\n\t\tif a[i] == 0:\n\t\t\tans += 1\n\t\t\tp = 0\n\t\telif a[i] == 1:\n\t\t\tif p == 1:\n\t\t\t\tp = 0\n\t\t\t\tans += 1\n\t\t\telse:\n\t\t\t\tp = 1\n\t\telif a[i] == 2:\n\t\t\tif p == 2:\n\t\t\t\tp = 0\n\t\t\t\tans += 1\n\t\t\telse:\n\t\t\t\tp = 2\n\t\telse:\n\t\t\tif p != 0:\n\t\t\t\tp = 3 - p\n\treturn ans\n\n\ntc = 1\nfor t in range(tc):\n\tn = read()\n\ta = readl()\n\tprinti(solve(n, a))\n\n\t", "import sys\r\n\r\ndef minrest(v,n,i,last):\r\n\r\n if(i>=n):\r\n return 0\r\n\r\n if(dp[i][last]!=-1):\r\n return dp[i][last]\r\n\r\n if(v[i]==0):\r\n dp[i][last]=minrest(v,n,i+1,0)+1\r\n\r\n elif(v[i]==1):\r\n if(v[i]==last):\r\n dp[i][last]=minrest(v,n,i+1,0)+1\r\n else:\r\n dp[i][last]=minrest(v,n,i+1,1)\r\n \r\n elif(v[i]==2):\r\n if(v[i]==last):\r\n dp[i][last]=minrest(v,n,i+1,0)+1\r\n else:\r\n dp[i][last]=minrest(v,n,i+1,2)\r\n\r\n elif(v[i]==3):\r\n if(last==1):\r\n a=sys.maxsize\r\n else:\r\n a=minrest(v,n,i+1,1)\r\n\r\n if(last==2):\r\n b=sys.maxsize\r\n else:\r\n b=minrest(v,n,i+1,2)\r\n\r\n dp[i][last]=min(a,b)\r\n \r\n return dp[i][last]\r\n \r\n\r\ndp=[[-1]*3 for i in range(105)]\r\nn=int(input())\r\nv=list(map(int,input().split()))\r\n\r\nans=minrest(v,n,0,0)\r\n\r\nprint(ans)\r\n", "inf = 2**33\n\ndef solve(dp, activities, i, end, done):\n if (i == end):\n return(0)\n\n if (dp[i][done] == -1):\n best = solve(dp, activities, i + 1, end, 0) + 1\n if ((activities[i] == 1 or activities[i] == 3) and done != 2):\n best = min(best, solve(dp, activities, i + 1, end, 2))\n if ((activities[i] == 2 or activities[i] == 3) and done != 1):\n best = min(best, solve(dp, activities, i + 1, end, 1))\n dp[i][done] = best\n\n return(dp[i][done])\n\ndays = int(input())\nactivities = list(map(int, input().split()))\ndp = [[-1] * 4 for i in activities]\nanswer = solve(dp, activities, 0, days, 0)\n#print(dp)\nprint(answer)\n\n\n\n\n\n# 0 Nothing\n# 1 Sports\n# 2 Contest", "n = int(input())\na = list(map(int, input().split()))\n\nrest = 0\nprev, curr = 0, 0\n\nfor i in range(n):\n curr = a[i]\n if curr == 0:\n rest += 1\n prev = curr\n elif curr == 1:\n if prev == 1:\n rest += 1\n prev = 0\n else:\n prev = curr\n elif curr == 2:\n if prev == 2:\n rest += 1\n prev = 0\n else:\n prev = curr\n else:\n if prev == 1:\n prev = 2\n elif prev == 2:\n prev = 1\n else:\n prev = curr\n\nprint(rest)", "import math\r\nimport copy\r\nimport itertools\r\nimport bisect\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef ilst():\r\n return list(map(int,input().split()))\r\n\r\ndef inum():\r\n return map(int,input().split())\r\n \r\ndef comp(n):\r\n if n == 2:\r\n return 1\r\n elif n == 1:\r\n return 2\r\n else:\r\n return 3 ####\r\n \r\nn = int(input())\r\nl = ilst()\r\n\r\nprev = 3\r\nc = 0\r\nfor i in range(n):\r\n if l[i] == 0:\r\n c += 1\r\n prev = 3\r\n elif l[i] == 3:\r\n prev = comp(prev)\r\n else:\r\n if l[i] == prev:\r\n c += 1\r\n prev = 3\r\n else:\r\n prev = l[i]\r\nprint(c)\r\n ", "n = int(input())\r\nA = list(map(int, input().split()))\r\nf1 = 0\r\nf2 = 0\r\nt = 0\r\na = 0\r\nfor i in range(n):\r\n if A[i] == 0:\r\n a += 1\r\n f1 = 0\r\n f2 = 0\r\n elif A[i] == 1:\r\n if f1 == 1:\r\n a += 1\r\n f1 = 0\r\n else:\r\n f1 = 1\r\n f2 = 0\r\n elif A[i] == 2:\r\n if f2 == 1:\r\n a += 1\r\n f2 = 0\r\n else:\r\n f1 = 0\r\n f2 = 1\r\n elif A[i] == 3:\r\n if f1 == 1:\r\n f1 = 0\r\n f2 = 1\r\n elif f2 == 1:\r\n f1 = 1\r\n f2 = 0\r\nprint(a)", "from collections import *\r\nfrom bisect import *\r\nfrom heapq import *\r\nfrom itertools import *\r\nfrom math import *\r\nimport sys\r\n \r\n \r\nr = lambda:map(int, sys.stdin.readline().rstrip().split())\r\nn, = r()\r\narr = list(r())\r\ndp = [[0] * (n+1) for i in range(4)]\r\n \r\n \r\nfor i in range(n-1,-1,-1):\r\n \r\n if arr[i] == 3:\r\n a = 1 + min(dp[1][i+1],dp[2][i+1])\r\n dp[1][i] = min(a,dp[2][i+1])\r\n dp[2][i] = min(a,dp[1][i+1])\r\n elif arr[i] == 2 or arr[i] == 1:\r\n a = 1 + min(dp[1][i+1],dp[2][i+1])\r\n dp[1][i] = min(a,( 0 if arr[i] == 1 else 1) + dp[2][i+1])\r\n dp[2][i] = min(a,( 0 if arr[i] == 2 else 1) + dp[1][i+1])\r\n else:\r\n next_min = 1+min(dp[1][i+1], dp[2][i+1])\r\n dp[1][i] = next_min\r\n dp[2][i] = next_min\r\nans = min(dp[1][0],dp[2][0])\r\nprint(ans)\r\n\r\n\r\n# n = int(input())\r\n \r\n# a = list(map(int, input().split()))\r\n \r\n# ans = 0\r\n# s = 0\r\n \r\n# for i in range(n):\r\n# if a[i] == 0 or s == a[i]:\r\n# ans += 1\r\n# s = 0\r\n# elif a[i] == 3:\r\n# if s != 0:\r\n# s = 3 - s\r\n# else:\r\n# s = a[i]\r\n \r\n# print(ans)", "REST = 0\r\nGYM = 1\r\nCONTEST = 2\r\n\r\ndef dp(day, lastActivity):\r\n if day < 0:\r\n return 0\r\n\r\n if cache[day][lastActivity] != -1:\r\n return cache[day][lastActivity]\r\n \r\n activities = days[day]\r\n canDoContest = activities == 1 or activities == 3\r\n canDoGym =activities == 2 or activities == 3\r\n \r\n minRestDays = 1 + dp(day-1, REST)\r\n \r\n if lastActivity != GYM and canDoGym:\r\n minRestDays = min(minRestDays, dp(day-1, GYM))\r\n if lastActivity != CONTEST and canDoContest:\r\n minRestDays = min(minRestDays, dp(day-1, CONTEST))\r\n\r\n cache[day][lastActivity] = minRestDays\r\n return minRestDays\r\n\r\n\r\nn = int(input())\r\ndays = list(map(int, input().split(' ')))\r\n\r\ncache = [[-1 for _ in range(3)] for _ in range(n)]\r\nprint(dp(n-1, 0))\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nprev=0\r\ni=0\r\nr=0\r\nt=0\r\nwhile(i<n):\r\n if(a[i]==3):\r\n if(i-1>=0 and prev==0):\r\n t=0\r\n if prev==1:\r\n prev=2\r\n else:\r\n prev=1\r\n \r\n elif a[i]==0:\r\n r+=1\r\n prev=0\r\n t=1\r\n elif a[i]==1:\r\n if prev==1:\r\n if a[i-1]==3 and t==0:\r\n prev=1\r\n \r\n else:\r\n r+=1\r\n prev=0\r\n else:\r\n prev=1\r\n \r\n \r\n t=1 \r\n elif a[i]==2:\r\n if prev==2:\r\n if a[i-1]==3 and t==0:\r\n prev=2\r\n \r\n else:\r\n r+=1\r\n prev=0\r\n else:\r\n prev=2\r\n \r\n \r\n t=1\r\n \r\n i+=1\r\n \r\nprint(r)", "n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nk=3;m=0\r\nfor x in a :\r\n if x==0:\r\n k=3\r\n m+=1\r\n elif x==1:\r\n if k==2:\r\n m+=1\r\n k=3\r\n else:\r\n k=2\r\n elif x==2:\r\n if k==1:\r\n m+=1\r\n k=3\r\n else :\r\n k=1\r\n elif x==3:\r\n if k==1:\r\n k=2\r\n elif k==2:\r\n k=1\r\nprint(m)\r\n", "#****************************************\r\n\r\n#** Solution by BAZOOKA **\r\n\r\n#** Sponsored by RED BULL**\r\n\r\n#** I love ❤Kateryna Gret❤ **\r\n\r\n#****************************************/\r\n\r\ninput()\r\n\r\ninf = 1 << 9\r\n\r\nS=0,0,0\r\n\r\nfor a in map (int,input().split()):S=1+min(S),min(S[0],S[2])if a>>1 else inf,min(S[0],S[1])if 1&a else inf\r\n\r\nprint (min(S))\r\n\r\n#****************************************\r\n\r\n#** Solution by BAZOOKA **\r\n\r\n#** Sponsored by RED BULL**\r\n\r\n#** I love ❤Kateryna Gret❤ **\r\n\r\n#****************************************/", "n = int(input())\nact = list(map(int, input().split()))\np = [[0 for i in range(3)] for _ in range(n)]\n\np[0][0] = 0\np[0][1] = int(act[0] >= 2)\np[0][2] = int(act[0] % 2)\n\nfor i in range(1, n):\n p[i][0] = max(p[i - 1])\n\n if act[i] >= 2:\n p[i][1] = max(p[i - 1][0] + 1, p[i - 1][2] + 1)\n\n if act[i] % 2 == 1:\n p[i][2] = max(p[i - 1][0] + 1, p[i - 1][1] + 1)\n\nprint(n - max(p[-1]))\n ", "def solution(n, arr):\r\n memo = {}\r\n def rec(i, p):\r\n if (i, p) in memo:\r\n return memo[i, p]\r\n \r\n if i >= len(arr):\r\n return 0\r\n \r\n if p == 'rest':\r\n pass\r\n if arr[i] == 0:\r\n memo[i, p] = rec(i+1, 'rest') + 1\r\n elif arr[i] == 1:\r\n memo[i, p] = rec(i+1, 'gym')\r\n elif arr[i] == 2:\r\n memo[i, p] = rec(i+1, 'it')\r\n else:\r\n memo[i, p] = min(rec(i+1, 'it'), rec(i+1, 'gym'))\r\n elif p == 'gym':\r\n if arr[i] == 0:\r\n memo[i, p] = rec(i+1, 'rest') + 1\r\n elif arr[i] == 1:\r\n memo[i, p] = rec(i+1, 'rest') + 1\r\n elif arr[i] == 2:\r\n memo[i, p] = rec(i+1, 'it')\r\n else:\r\n memo[i, p] = rec(i+1, 'it')\r\n else:\r\n if arr[i] == 0:\r\n memo[i, p] = rec(i+1, 'rest') + 1\r\n elif arr[i] == 1:\r\n memo[i, p] = rec(i+1, 'gym')\r\n elif arr[i] == 2:\r\n memo[i, p] = rec(i+1, 'rest') + 1\r\n else:\r\n memo[i, p] = rec(i+1, 'gym')\r\n \r\n return memo[i, p]\r\n\r\n return rec(0, 'rest')\r\n\r\nn = int(input())\r\narr = list(map(int, input().split(' ')))\r\nprint(solution(n, arr))", "n = int(input())\na=list(map(int,input().split()))\nDP = [[-1 for _ in range(n)] for _ in range(3)]\ndef calc(last, ind):\n if ind>=n:\n return 0\n if DP[last][ind]!=-1:\n return DP[last][ind]\n possible1 = ((a[ind]==1 or a[ind]==3) and last!=1)\n possible2 = ((a[ind]==2 or a[ind]==3) and last!=2)\n DP[last][ind] = calc(0,ind+1)+1\n if possible1:\n DP[last][ind] = min(DP[last][ind], calc(1,ind+1))\n if possible2:\n DP[last][ind] = min(DP[last][ind], calc(2,ind+1))\n return DP[last][ind]\nprint(calc(0,0))\n", "n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nans = 0\r\ns = 0\r\n\r\nfor i in range(n):\r\n if a[i] == 0 or s == a[i]:\r\n ans += 1\r\n s = 0\r\n elif a[i] == 3:\r\n if s != 0:\r\n s = 3 - s\r\n else:\r\n s = a[i]\r\n\r\nprint(ans)\r\n", "n = int(input())\r\nls = list(map(int, input().split()))\r\n\r\nary = [[0, 0, 0] for j in range(n + 1)]\r\n# 1 for contest\r\n# 2 for gym\r\nfor i in range(1, n+ 1):\r\n ma = max(ary[i - 1])\r\n ary[i][0] = ma\r\n ary[i][1] = max(ary[i-1][0], ary[i-1][2]) + (ls[i-1] == 1 or ls[i-1] == 3)\r\n ary[i][2] = max(ary[i-1][0], ary[i-1][1]) + (ls[i-1] == 2 or ls[i-1] == 3)\r\n\r\nprint(n - max(ary[-1]))\r\n", "dp = {}\n\ndef f(i, n, seq, c=None):\n if i >= n:\n return 0\n\n # if i == n-1:\n\n if (i, c) in dp:\n return dp[(i, c)]\n\n if seq[i] == 0:\n dp[(i, c)] = 1 + f(i+1, n, seq)\n return dp[(i, c)]\n\n # if seq[i] == 1 and c == 1:\n # dp[(i, c)] = f(i+1, n, seq, 2)\n # return dp[(i, c)]\n #\n # if seq[i] == 2 and c == 2:\n # dp[(i, c)] = f(i+1, n, seq, 1)\n # return dp[(i, c)]\n\n if seq[i] == 3:\n if c == 1:\n dp[(i, c)] = min( f(i+1, n, seq, 2), f(i+1, n, seq) + 1 )\n return dp[(i, c)]\n if c == 2:\n dp[(i, c)] = min( f(i+1, n, seq, 1), f(i+1, n, seq) + 1 )\n return dp[(i, c)]\n\n dp[(i, c)] = min( f(i+1, n, seq, 1), f(i+1, n, seq, 2), f(i+1, n, seq)+1 )\n return dp[(i, c)]\n\n if c is None:\n if seq[i] == 1:\n dp[(i, c)] = min( f(i+1, n, seq, 2), f(i+1, n, seq)+1 )\n return dp[(i, c)]\n if seq[i] == 2:\n dp[(i, c)] = min( f(i+1, n, seq, 1), f(i+1, n, seq)+1 )\n return dp[(i, c)]\n\n if seq[i] == c:\n dp[(i, c)] = min(f(i+1, n, seq, 3-c), f(i+1, n, seq)+1)\n return dp[(i, c)]\n\n if seq[i] != c:\n dp[(i, c)] = f(i+1, n, seq)+1\n return dp[(i, c)]\n\nn = int(input())\nvacations = input().split()\nfor i in range(n):\n vacations[i] = int(vacations[i])\n\nprint(f(0, n, vacations))\n\n \t \t \t \t\t\t\t \t\t\t \t \t \t \t \t \t", "from collections import Counter\r\nfrom collections import defaultdict\r\nimport math\r\nimport random\r\nimport heapq as hq\r\nfrom math import sqrt\r\nimport sys\r\nfrom functools import reduce\r\n\r\n\r\ndef input():\r\n return sys.stdin.readline().strip()\r\n\r\n\r\ndef iinput():\r\n return int(input())\r\n\r\n\r\ndef tinput():\r\n return input().split()\r\n\r\n\r\ndef rinput():\r\n return map(int, tinput())\r\n\r\n\r\ndef rlinput():\r\n return list(rinput())\r\n\r\n\r\nmod = int(1e9)+7\r\n\r\n\r\ndef factors(n):\r\n return set(reduce(list.__add__,\r\n ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))\r\n\r\n\r\n# ----------------------------------------------------\r\n\r\nif __name__ == \"__main__\":\r\n n=iinput()\r\n a=rlinput()\r\n dp=[[float('inf') for i in range(3)] for i in range(n+1)]\r\n dp[0][0],dp[0][1],dp[0][2]=1,0,0\r\n a.insert(0,0)\r\n for day in range(1,n+1):\r\n if a[day]==1 or a[day]==3:\r\n dp[day][1]=min(dp[day-1][0],dp[day-1][2])\r\n if a[day]==2 or a[day]==3:\r\n dp[day][2]=min(dp[day-1][0],dp[day-1][1])\r\n dp[day][0]=1+min(dp[day-1])\r\n \r\n print(min(dp[n]))\r\n \r\n\r\n\r\n \r\n ", "N = int(input())\r\ndays = list(map(int, input().split()))\r\ndp = []\r\n\r\nprev = [[0, 1, 2], [0, 2], [0, 1]]\r\n\r\nfor i in range(N):\r\n\td = days[i]\r\n\trow = []\r\n\tfor j in range(3):\r\n\t\tif j == 1:\r\n\t\t\tif d != 1 and d != 3:\r\n\t\t\t\trow.append('x')\r\n\t\t\t\tcontinue\r\n\t\tif j == 2:\r\n\t\t\tif d != 2 and d != 3:\r\n\t\t\t\trow.append('x')\r\n\t\t\t\tcontinue\r\n\t\tmin_prev = 105\r\n\t\tprev_row = [0, 0, 0]\r\n\t\tif i > 0:\r\n\t\t\tprev_row = dp[i - 1]\r\n\t\tfor k in prev[j]:\r\n\t\t\tif prev_row[k] == 'x':\r\n\t\t\t\tcontinue\r\n\t\t\tmin_prev = min(min_prev, prev_row[k])\r\n\t\tif j == 0:\r\n\t\t\tmin_prev += 1\r\n\t\trow.append(min_prev)\r\n\tdp.append(row)\r\n\t\r\nans = 105\r\nfor c in dp[-1]:\r\n\tif c == 'x':\r\n\t\tcontinue\r\n\tans = min(ans, c)\r\n\r\nprint(ans)\r\n\t\t", "n=int(input())\r\ndata=list(map(int,input().split()))\r\ndp=[[float('inf')]*3 for _ in range(n)]\r\ndp[0][0]=1\r\nif data[0]==1:\r\n dp[0][1]=0\r\nif data[0]==2:\r\n dp[0][2]=0\r\nif data[0]==3:\r\n dp[0][1]=0\r\n dp[0][2]=0\r\nfor i in range(1,n):\r\n dp[i][0]=min(dp[i-1])+1\r\n if data[i]==1:\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n if data[i]==2:\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n if data[i]==3:\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\nprint(min(dp[n-1]))", "def f(x, y):\r\n if y in x:\r\n return x[y]\r\n else:\r\n return 10**6\r\n\r\n\r\nn=int(input())\r\nw=[int(k) for k in input().split()]\r\nres={0:0}\r\nz=0\r\nfor i in w:\r\n c=[]\r\n if i==0:\r\n #mn=sorted(res, key=lambda x: x[1])[0][1]\r\n res={0:min(res.values())+1}\r\n #z=0\r\n if i==1:\r\n res={0:min(res.values())+1, 2:min(f(res, 0), f(res, 1))}\r\n if i==2:\r\n res={0:min(res.values())+1, 1:min(f(res, 0), f(res, 2))}\r\n if i==3:\r\n res={0:min(res.values())+1, 1:min(f(res, 0), f(res, 2)), 2:min(f(res, 0), f(res, 1))}\r\nprint(min(res.values()))", "INF=10**9\nn=int(input())\nd=[0]+[int(i) for i in input().split()]\ndp=[[0,INF,INF]]+[[INF,INF,INF] for i in range(n)]\nfor i in range(1,n+1):\n if d[i]&1:\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\n if d[i]&2:\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\n if d[i]==0 or dp[i][2]==INF and dp[i][1]==INF:\n dp[i][0]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+1\nprint(min(dp[n]))\n", "import sys\r\n\r\ndef solve(n,lt):\r\n\r\n dp = []\r\n for i in range(n):\r\n # temp = [-1]*3\r\n temp = [sys.maxsize]*3\r\n dp.append(temp)\r\n # whatDone = [-1]*n\r\n\r\n def rec(i,prev):\r\n # print(i)\r\n if(i==n):\r\n return 0\r\n \r\n if(dp[i][prev]!=sys.maxsize):\r\n return dp[i][prev]\r\n \r\n if(lt[i]==0):\r\n dp[i][prev] = rec(i+1,0)+1\r\n return dp[i][prev]\r\n \r\n if(prev==0):\r\n if(lt[i]==3):\r\n ans = rec(i+1,1)\r\n ans = min(ans,rec(i+1,2))\r\n # print(i,ans,\"fuck ALL\")\r\n dp[i][prev] = ans\r\n return dp[i][prev]\r\n else:\r\n dp[i][prev] = rec(i+1,lt[i])\r\n return dp[i][prev]\r\n if(prev==1):\r\n if(lt[i]==1):\r\n dp[i][prev] = rec(i+1,0)+1\r\n return dp[i][prev]\r\n else:\r\n dp[i][prev] = rec(i+1,2)\r\n return dp[i][prev]\r\n if(prev==2):\r\n if(lt[i]==2):\r\n dp[i][prev] = rec(i+1,0)+1\r\n return dp[i][prev] \r\n else:\r\n dp[i][prev] = rec(i+1,1)\r\n return dp[i][prev] \r\n\r\n\r\n\r\n lol = rec(0,0)\r\n print(lol)\r\n # for i in range(n):\r\n # print(i, min(dp[i]),lt[i])\r\n # print(lt)\r\n # for i in range(1,n):\r\n # a = sys.maxsize\r\n # for kkk in range(3):\r\n # if dp[i][kkk]<a:\r\n # a = dp[i][kkk]\r\n # whatDone[i-1] = kkk\r\n\r\n # print(whatDone)\r\n\r\nn = int(input())\r\ntxt = input()\r\nlt = list(map(int,txt.split(\" \")))\r\nsolve(n,lt)\r\n", "from functools import lru_cache\r\n@lru_cache(None)\r\ndef rec(n,gym=0,con=0):\r\n if n==t:\r\n return 0\r\n if lis[n]==0:\r\n return rec(n+1)\r\n elif lis[n]==1:\r\n if con==0:\r\n return max(1+rec(n+1,0,1),rec(n+1))\r\n else:\r\n return rec(n+1)\r\n elif lis[n]==2:\r\n if gym==0:\r\n return max(1+rec(n+1,1,0),rec(n+1))\r\n else:\r\n return rec(n+1)\r\n else:\r\n s2=-1923829\r\n s1=-117238\r\n if gym==0:\r\n s1=max(1+rec(n+1,1,0),rec(n+1))\r\n if con==0:\r\n s2=max(1+rec(n+1,0,1),rec(n+1))\r\n return max(s1,s2)\r\n \r\n \r\nt=int(input())\r\nlis=list(map(int,input().split()))\r\nprint(t-rec(0,0,0))\r\n", "from collections import defaultdict, Counter\r\n\r\nM = int(1e9 + 7)\r\ninf = float('inf')\r\n\r\ndef I():\r\n return input()\r\n\r\ndef II():\r\n return int(I())\r\n\r\ndef LI():\r\n return list(I().split())\r\n\r\ndef LII():\r\n return list(map(int, LI()))\r\n\r\ndef rank(arr, lo, hi, target):\r\n while lo <= hi:\r\n mi = (lo + hi) >> 1\r\n if arr[mi] < target:\r\n lo = mi + 1\r\n else:\r\n hi = mi - 1\r\n return lo\r\n\r\ndef init(prev):\r\n curr = [[0] * 2 for _ in range(3)]\r\n for i in range(3):\r\n curr[i][1] = prev[i][1]\r\n return curr\r\n\r\ndef gym(val):\r\n return val == 2 or val == 3\r\n\r\ndef contest(val):\r\n return val == 1 or val == 3\r\n\r\ndef solve():\r\n n = II()\r\n arr = LII()\r\n prev = [[1, 0], [0, 0], [0, 0]]\r\n ans = inf\r\n for val in arr:\r\n # print(val)\r\n curr = init(prev)\r\n # update rest\r\n if prev[1][0]:\r\n curr[0][1] = min(curr[0][1], prev[1][1])\r\n if prev[2][0]:\r\n curr[0][1] = min(curr[0][1], prev[2][1])\r\n curr[0][1] += 1\r\n # update gym\r\n if gym(val):\r\n curr[1][0] = 1\r\n curr[1][1] = prev[0][1]\r\n if prev[2][0]:\r\n curr[1][1] = min(curr[1][1], prev[2][1])\r\n # update contest\r\n if contest(val):\r\n curr[2][0] = 1\r\n curr[2][1] = prev[0][1]\r\n if prev[1][0]:\r\n curr[2][1] = min(curr[2][1], prev[1][1])\r\n prev = curr\r\n # print(prev)\r\n ans = prev[0][1]\r\n if prev[1][0]:\r\n ans = min(prev[1][1], ans)\r\n if prev[2][0]:\r\n ans = min(prev[2][1], ans)\r\n print(ans)\r\n\r\nif __name__ == \"__main__\":\r\n solve()\r\n", "n = int(input())\r\ndays = input().strip().split()\r\n\r\n'''def assignJob(days, i, lastJob):\r\n sleepyDays = 0\r\n if i == len(days):\r\n return 0\r\n job = days[i]\r\n if job == '0':\r\n sleepyDays = 1 + assignJob(days, i+1, \"s\")\r\n elif job == '1':\r\n if lastJob == 'c':\r\n sleepyDays = 1 + assignJob(days, i+1, 's')\r\n else:\r\n sleepyDays = assignJob(days, i+1, 'c')\r\n elif job == '2':\r\n if lastJob == 'g':\r\n sleepyDays = 1 + assignJob(days, i+1, 's')\r\n else:\r\n sleepyDays = assignJob(days, i+1, 'g')\r\n elif job == '3':\r\n if lastJob == 'g':\r\n sleepyDays = assignJob(days, i+1, 'c')\r\n elif lastJob == 'c':\r\n sleepyDays = assignJob(days, i+1, 'g')\r\n else:\r\n sleepyDays = min(assignJob(days, i+1, 'c'), assignJob(days, i+1, 'g'))\r\n return sleepyDays\r\n\r\nprint(assignJob(days, 0, 's'))'''\r\ndp = [[0, 0, 0] for x in range(n+1)] #s,g,c\r\nfor x in range(n-1, -1, -1):\r\n job = days[x]\r\n if job == '0':\r\n dp[x][0] = 1+min(dp[x+1][0], dp[x+1][1], dp[x+1][2])\r\n dp[x][1] = 9999999\r\n dp[x][2] = 9999999\r\n elif job == '1':\r\n dp[x][0] = 1+min(dp[x+1][0], dp[x+1][1], dp[x+1][2])\r\n dp[x][1] = 9999999\r\n dp[x][2] = min(dp[x+1][0], dp[x+1][1])\r\n elif job == '2':\r\n dp[x][0] = 1+min(dp[x+1][0], dp[x+1][1], dp[x+1][2])\r\n dp[x][1] = min(dp[x+1][0], dp[x+1][2])\r\n dp[x][2] = 9999999\r\n elif job == '3':\r\n dp[x][0] = 1+min(dp[x+1][0], dp[x+1][1], dp[x+1][2])\r\n dp[x][1] = min(dp[x+1][0], dp[x+1][2])\r\n dp[x][2] = min(dp[x+1][0], dp[x+1][1])\r\nprint(min(dp[0][0], dp[0][1], dp[0][2]))\r\n", "REST_DAY = 0\r\nMAX_OPTIONS = 3\r\n\r\ndef inputs(f):\r\n return [f(e) for e in input().split()]\r\n\r\ndef solve(n, days): \r\n previous_day = 0\r\n rested = 0\r\n\r\n for day in days:\r\n if day == previous_day or day == REST_DAY:\r\n previous_day = REST_DAY\r\n rested += 1\r\n elif day < MAX_OPTIONS:\r\n previous_day = day\r\n elif previous_day:\r\n previous_day = MAX_OPTIONS - previous_day\r\n\r\n return rested\r\n\r\ndef main():\r\n n = inputs(int)\r\n days = inputs(int)\r\n\r\n print(solve(n, days))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nprev=0\r\nans=0\r\nfor i in range(n):\r\n k=a[i]\r\n if k==0:\r\n prev=0\r\n ans+=1\r\n elif k==1 or k==2:\r\n if prev==k:\r\n ans+=1\r\n prev=0\r\n else:\r\n prev=k\r\n else:\r\n if prev==1 or prev==2: prev=3-prev\r\n else: prev=4\r\nprint(ans)\r\n \r\n", "from enum import IntEnum, unique\nfrom typing import List, Optional\n\n@unique\nclass Activity(IntEnum):\n CONTEST = 0\n GYM = 1\n REST = 2\n \n\ndef solve(n: int, config: List[int]) -> None:\n prev_possibilites = {Activity.CONTEST: n, Activity.GYM: n, Activity.REST: 0}\n\n for value in config:\n possibilities = {Activity.CONTEST: n, Activity.GYM: n, Activity.REST: 0}\n possibilities[Activity.REST] = min(prev_possibilites[Activity.CONTEST], prev_possibilites[Activity.GYM], prev_possibilites[Activity.REST]) + 1\n if value in [1, 3]:\n possibilities[Activity.CONTEST] = min(prev_possibilites[Activity.REST], prev_possibilites[Activity.GYM])\n if value in [2, 3]:\n possibilities[Activity.GYM] = min(prev_possibilites[Activity.REST], prev_possibilites[Activity.CONTEST])\n prev_possibilites = {**possibilities}\n \n print(min(prev_possibilites.values()))\n\n \n\nif __name__ == \"__main__\":\n n = int(input())\n config = list(map(int, input().split(\" \")))\n\n solve(n, config)", "n = int(input())\r\nalist = list(map(int, input().split()))\r\n\r\ndp = [[101 for _ in range(4)] for _ in range(n+1)]\r\n\r\nfor i in range(4):\r\n dp[0][i]= 0\r\nfor i in range(1, n+1):\r\n dp[i][0] = min([dp[i-1][0],dp[i-1][1],dp[i-1][2]]) + 1\r\n if alist[i-1] == 1:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n elif alist[i-1] == 2:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n elif alist[i-1] == 3:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\nprint(min([dp[n][0],dp[n][1],dp[n][2]]))", "n=int(input())\nal=list(map(int,input().split()))\n\nres,prev=0,0\n\nfor x in al:\n\tif (x==0 or x==prev):\n\t\tprev=0\n\t\tres+=1\n\telif x==1 or x==2:\n\t\tprev=x\n\telif prev>0 and x==3:\n\t\tprev=3-prev\n\nprint(res)", "N = int(input())\r\nacts = [int(x) for x in input().split()]\r\n\r\ndp = [[float(\"inf\")] * 3 for i in range(N+1)]\r\n\r\nfor i in range(3):\r\n dp[0][i] = 0\r\n\r\nfor i in range(1,N+1):\r\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\r\n if acts[i-1] == 1:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n elif acts[i-1] == 2:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n elif acts[i-1] == 3:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n\r\nans = min(dp[N])\r\nprint(ans)", "n=int(input())\r\nl=list(map(int,input().split()))\r\nd=[[[-1]*3 for i in range(3)] for j in range(n+5)]\r\nfor i in range(3):\r\n for j in range(3):\r\n d[n][i][j]=0\r\nfor i in range(n-1,-1,-1):\r\n for j in range(2):\r\n for k in range(2):\r\n ans=0\r\n if l[i]==0:\r\n ans=1+d[i+1][0][0]\r\n elif l[i]==1:\r\n if k:\r\n ans=1+d[i+1][0][0]\r\n else:\r\n ans=min(1+d[i+1][0][0],d[i+1][0][1])\r\n elif l[i]==2:\r\n if j:\r\n ans=1+d[i+1][0][0]\r\n else:\r\n ans=min(1+d[i+1][0][0],d[i+1][1][0])\r\n else:\r\n if j:\r\n ans=min(1+d[i+1][0][0],d[i+1][0][1])\r\n elif k:\r\n ans=min(1+d[i+1][0][0],d[i+1][1][0])\r\n else:\r\n ans=min(1+d[i+1][0][0],d[i+1][1][0],d[i+1][0][1])\r\n d[i][j][k]=ans\r\nprint(d[0][0][0])\r\n", "n=int(input())\r\nA=list(map(int,input().split()))\r\ndp=[[0,0]for _ in range(n+1)]\r\nfor i in range(1,n+1):\r\n if A[i-1]==0:\r\n mx=max(dp[i-1])\r\n dp[i]=[mx,mx]\r\n elif A[i-1]==1:\r\n dp[i]=[max(dp[i-1]),max(dp[i-1][1],dp[i-1][0]+1)]\r\n elif A[i-1]==2:\r\n dp[i]=[max(dp[i-1][0],dp[i-1][1]+1),max(dp[i-1])]\r\n else:\r\n dp[i]=[dp[i-1][1]+1,dp[i-1][0]+1]\r\nprint(n-max(dp[-1]))", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\ndp = [[10000 for i in range(3)] for i in range(n+1)]\r\nfor i in range(n+1):\r\n dp[i][0] = i\r\n dp[i][1] = 0\r\n dp[i][2] = 0\r\n\r\nfor i in range(1, n+1):\r\n dp[i][0]=min({dp[i-1][0],dp[i-1][1],dp[i-1][2]})+1\r\n dp[i][1]=10000\r\n dp[i][2]=10000\r\n if(arr[i-1]&1):\r\n dp[i][1]=min(dp[i-1][2],dp[i-1][0])\r\n \r\n if(arr[i-1]&2):\r\n dp[i][2]=min(dp[i-1][1],dp[i-1][0])\r\n \r\nprint(min(dp[-1]))", "\r\ncin = [*open(0)]\r\nn = int(cin[0])\r\ndays = list(map(int, cin[1].split()))\r\n\r\ndef solve():\r\n # rest, contest, gym\r\n inf = 1_000_000\r\n ret = []\r\n ret.append((0, 0, 0))\r\n for d in days:\r\n a, b, c = ret[-1]\r\n if d == 0:\r\n ret.append((min(a,b,c)+1, inf, inf))\r\n elif d == 1:\r\n ret.append((min(a,b,c)+1, min(a,c), inf))\r\n elif d == 2:\r\n ret.append((min(a,b,c)+1, inf, min(a,b)))\r\n elif d == 3:\r\n ret.append((min(a,b,c)+1, min(a,c), min(a,b)))\r\n return min(ret[-1])\r\n\r\nprint(solve())\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nd=[[0]*(n+1),[0]*(n+1),[0]*(n+1)]\r\n \r\nfor i in range(1,n + 1):\r\n\r\n d[0][i] = max(d[0][i - 1],d[1][i - 1],d[2][i - 1])\r\n if l[i - 1] in [1,3]:\r\n d[1][i] = max(d[0][i - 1],d[2][i - 1] ) + 1\r\n if l[i - 1] in [2,3]:\r\n d[2][i] = max(d[0][i - 1],d[1][i - 1]) + 1\r\nprint(n - max(d[0][i],d[1][i],d[2][i]))", "n=int(input())\r\nl =list(map(int,input().split()))\r\nr=0\r\nx=0\r\nfor i in range(len(l)):\r\n if l[i]==0 or l[i]==x:\r\n r+=1\r\n x=0\r\n elif l[i]==3:\r\n if(x!=0):\r\n x=3-x\r\n else:\r\n x=l[i]\r\nprint(r)\r\n", "def main():\n\n n = int(input())\n vacation = [int(i) for i in input().split()]\n\n sum = 0\n i = 0\n\n res = []\n\n for i in range(n):\n\n row = []\n\n if i == 0:\n \n if vacation[i] == 0:\n row.append(1)\n row.append(101)\n row.append(101)\n\n elif vacation[i] == 1:\n row.append(1)\n row.append(0)\n row.append(101)\n \n\n elif vacation[i] == 2:\n row.append(1)\n row.append(101)\n row.append(0)\n\n\n else:\n row.append(1)\n row.append(0)\n row.append(0)\n\n else:\n\n if vacation[i] == 0:\n row.append(1 + min(res[i-1]))\n row.append(101)\n row.append(101)\n\n elif vacation[i] == 1:\n row.append(1 + min(res[i-1]))\n row.append(min(res[i-1][0], res[i-1][2]))\n row.append(101)\n \n\n elif vacation[i] == 2:\n row.append(1 + min(res[i-1]))\n row.append(101)\n row.append(min(res[i-1][0], res[i-1][1]))\n\n\n else:\n row.append(1 + min(res[i-1]))\n row.append(min(res[i-1][0], res[i-1][2]))\n row.append(min(res[i-1][0], res[i-1][1]))\n \n res.append(row)\n\n\n print(min(res[-1]))\n\n\nmain()\n \t \t\t \t\t \t \t \t \t\t\t \t\t", "n = int(input())\r\nactivity = list(map(int, input().split()))\r\n \r\ncount = 0\r\nprev_activity = 0\r\n\r\nfor to_do in activity:\r\n if to_do == 0 or to_do == prev_activity:\r\n count += 1\r\n prev_activity = 0\r\n elif to_do == 1 or to_do == 2:\r\n prev_activity = to_do\r\n elif prev_activity != 0 and to_do == 3:\r\n prev_activity = 3 - prev_activity\r\n \r\nprint(count)", "n=int(input())\narr=list(map(int,input().split()))\ndp=[[9999 for i in range(3)] for j in range(n)]\n'''dp[day][0] = current day is rest\n dp[day][1] = current day is contest \n dp[day][2] = current day is gym'''\ndp[0][0]=1\nif arr[0]==1 or arr[0]==3:\n dp[0][1]=0\nif arr[0]==2 or arr[0]==3:\n dp[0][2]=0\n# print(dp[0])\nfor i in range(1,n):\n for j in range(3):\n dp[i][0]=1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\n if arr[i]==1 or arr[i]==3:\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\n if arr[i]==2 or arr[i]==3:\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\n# print(dp)\nprint(min(dp[n-1][0],dp[n-1][1],dp[n-1][2]))\n\n", "input()\r\npre,ans = 3,0\r\nfor val in list(map(int, input().split())):\r\n if val==pre and pre!=3:\r\n val = 0\r\n elif val==3 and pre!=3:\r\n val-=pre\r\n if val==0:\r\n ans+=1\r\n pre = val\r\nprint (ans)", "n = int(input())\r\naa = map(int, input().split())\r\n\r\nv = [[0, 0], [0, 0]]\r\nfor a in aa:\r\n if a < 2:\r\n max_s = v[-1][0]\r\n else:\r\n max_s = max([v[-1][0], v[-2][0]+1, v[-1][1]+1])\r\n \r\n if a%2 == 0:\r\n max_c = v[-1][1]\r\n else:\r\n max_c = max([v[-1][1], v[-2][1]+1, v[-1][0]+1])\r\n \r\n v.append([max_s, max_c])\r\n\r\nprint(n-max(v[-1]))\r\n", "from collections import Counter\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n##########################################################\r\n#for _ in range(int(input())):\r\n#import math\r\nimport sys\r\n# from collections import deque\r\n#from collections import Counter\r\n# ls=list(map(int,input().split()))\r\n# for i in range(m):\r\n# for i in range(int(input())):\r\n#n,k= map(int, input().split())\r\n#arr=list(map(int,input().split()))\r\n#n=sys.stdin.readline()\r\n#n=int(n)\r\n#n,k= map(int, input().split())\r\n#arr=list(map(int,input().split()))\r\nimport sys\r\nimport math\r\n#for i in range(int(input())):\r\nn=int(input())\r\ninf=1000\r\ndp=[[inf,inf,inf] for i in range(n)]\r\narr=list(map(int,input().split()))\r\n#a=rest,b=gym,c=code\r\ndp[0][0]=1\r\ndp[0][1]=0 if arr[0]==2 or arr[0]==3 else inf\r\ndp[0][2]=0 if arr[0]==1 or arr[0]==3 else inf\r\nfor i in range(1,n):\r\n dp[i][0]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+1\r\n if arr[i]==1 or arr[i]==3:\r\n dp[i][2]=min(dp[i-1][1],dp[i-1][0])\r\n if arr[i]==2 or arr[i]==3:\r\n dp[i][1]=min(dp[i-1][2],dp[i-1][0])\r\nprint(min(dp[n-1][0],dp[n-1][1],dp[n-1][2]))\r\n", "import sys,random,bisect\r\nfrom collections import deque,defaultdict\r\nfrom heapq import heapify,heappop,heappush\r\nfrom itertools import permutations\r\nfrom math import gcd,log\r\nmod = int(1e9 + 7)\r\ninf = int(1e20)\r\ninput = lambda :sys.stdin.readline().rstrip()\r\nmi = lambda :map(int,input().split())\r\nli = lambda :list(mi())\r\n\r\n\r\n\r\n\r\nn=int(input())\r\n\r\narr=li()\r\n\r\nf=[[inf]*3 for _ in range(n)]\r\n\r\n# 0休息 1比赛 2运动\r\n\r\nfor i in range(n):\r\n if i==0:\r\n f[i][0]=1\r\n if arr[i]==1:\r\n f[i][1]=0\r\n elif arr[i]==2:\r\n f[i][2]=0\r\n elif arr[i]==3:\r\n f[i][1]=0\r\n f[i][2]=0\r\n else:\r\n f[i][0]=min(f[i-1])+1\r\n if arr[i]==1:\r\n f[i][1]=min(f[i-1][0],f[i-1][2])\r\n elif arr[i]==2:\r\n f[i][2]=min(f[i-1][0],f[i-1][1])\r\n elif arr[i]==3:\r\n f[i][1]=min(f[i-1][0],f[i-1][2])\r\n f[i][2]=min(f[i-1][0],f[i-1][1]) \r\n#print(f)\r\nprint(min(f[-1]))\r\n\r\n\r\n \r\n", "from collections import defaultdict\r\nn = int(input())\r\n\r\na = input().split()\r\na = [int(i) for i in a]\r\n\r\nmemo = defaultdict(lambda :-1)\r\ndef solve(cur, prev):\r\n if cur == n:\r\n return 0\r\n if memo[(cur, prev)] != -1:\r\n return memo[(cur, prev)]\r\n \r\n if a[cur] == 0:\r\n memo[(cur, prev)] = solve(cur+1, 0)+1\r\n elif a[cur] == 1 or a[cur] == 2:\r\n if prev == a[cur]:\r\n memo[(cur, prev)] = solve(cur+1, 0)+1\r\n else:\r\n memo[(cur, prev)] = min(solve(cur+1, 0)+1, solve(cur+1, a[cur]))\r\n else:\r\n if prev == 1:\r\n memo[(cur, prev)] = min(solve(cur+1, 0)+1, solve(cur+1, 2))\r\n elif prev == 2:\r\n memo[(cur, prev)] = min(solve(cur+1, 0)+1, solve(cur+1, 1))\r\n else:\r\n memo[(cur, prev)] = min(solve(cur+1, 0)+1, solve(cur+1, 1), solve(cur+1, 2))\r\n \r\n \r\n return memo[(cur, prev)] \r\n \r\nprint(solve(0, 0))\r\n \r\n", "dias = int(input())\ndescanso = 0\nanterior = 0\n\na = [int(e) for e in input().split()]\n\nfor d in a:\n if(d == 0 or d == anterior):\n anterior = 0\n descanso += 1\n continue\n\n if(d == 1 or d == 2):\n anterior = d\n continue\n\n if(anterior > 0 and d == 3):\n anterior = 3 - anterior\n continue\n\nprint(descanso)", "day = int(input())\r\nsituations = input().split(\" \")\r\n\r\n\r\ndp = [[float('inf') for _ in range(3)] for _ in range(day+1)]\r\n# Base Case:\r\nfor j in range(3):\r\n dp[0][j] = 0\r\n\r\n# Inductive Step:\r\nfor i in range(1, day+1):\r\n # 0: rest\r\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\r\n # 1: gym\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n # 2. contest\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n\r\n if situations[i-1] == '0':\r\n dp[i][1] = float('inf')\r\n dp[i][2] = float('inf')\r\n elif situations[i-1] == '1':\r\n dp[i][1] = float('inf')\r\n elif situations[i-1] == '2':\r\n dp[i][2] = float('inf')\r\n\r\n\r\n\r\n\r\nprint(min(dp[day][0], dp[day][1], dp[day][2]))", "inf=1e10\r\nmem=[[-1]*5 for _ in range(110)]\r\ndef solve(i,u):\r\n if mem[i][u]!=-1: return mem[i][u]\r\n if i==n: return 0\r\n g=h=inf\r\n if a[i]==0: g=1+solve(i+1,0)\r\n elif a[i]==1:\r\n if u==1: g=1+solve(i+1,0)\r\n else: g=solve(i+1,1)\r\n elif a[i]==2:\r\n if u==2: g=1+solve(i+1,0)\r\n else: g=solve(i+1,2)\r\n else:\r\n if u==1: g=solve(i+1,2)\r\n elif u==2: g=solve(i+1,1)\r\n else:\r\n g=solve(i+1,1)\r\n h=solve(i+1,2)\r\n mem[i][u]=min(g,h)\r\n return mem[i][u]\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nprint(solve(0,0))", "def rec(i,prv,ar):\r\n if(i<0):\r\n return 0\r\n else:\r\n ans = 10**7\r\n if(ar[i]==3):\r\n for j in range(3):\r\n if(j!=prv):\r\n if(j==0 ):\r\n ans=min(ans , 1+rec(i-1,j,ar))\r\n else:\r\n ans = min(ans , rec(i-1,j,ar))\r\n else:\r\n if(ar[i]==0):\r\n ans=min(ans , 1+rec(i-1,0,ar))\r\n elif ar[i]==1:\r\n if(ar[i]==prv): \r\n ans=min(ans , 1+rec(i-1,0,ar)) \r\n else:\r\n ans=min(ans , rec(i-1,1,ar))\r\n else:\r\n if(ar[i]==prv): \r\n ans=min(ans , 1+rec(i-1,0,ar))\r\n else:\r\n ans=min(ans ,rec(i-1,2,ar))\r\n return ans\r\n\r\n\r\n\r\ndef fun(n,ls):\r\n # print(rec(n-1,None,ls))\r\n dp = [[10**7 for i in range(n)] for i in range(3)]\r\n for i in range(n):\r\n for j in range(3):\r\n val=ls[i]\r\n if (i==0):\r\n if(val==0 or val==j):\r\n dp[j][i]=1\r\n else:\r\n dp[j][i]=0\r\n else:\r\n if (val==3):\r\n ans=10**7\r\n for k in range(3):\r\n if(k!=j):\r\n if(k==0):\r\n ans=min(ans , 1+dp[k][i-1])\r\n else:\r\n ans=min(ans , dp[k][i-1])\r\n dp[j][i]=ans\r\n else:\r\n ans = 10**7\r\n if(val==0):\r\n ans=min(ans , 1+dp[0][i-1])\r\n elif val==1:\r\n if(val==j): \r\n ans=min(ans , 1+dp[0][i-1]) \r\n else:\r\n ans=min(ans , dp[1][i-1])\r\n else:\r\n if(val==j): \r\n ans=min(ans , 1+dp[0][i-1])\r\n else:\r\n ans=min(ans , dp[2][i-1])\r\n dp[j][i]=ans\r\n print(dp[0][n-1])\r\n # print(dp)\r\n\r\n\r\n# T = int(input())\r\nT=1\r\nfor i in range(T):\r\n # var=input()\r\n # st=input()\r\n # val=int(input())\r\n # ks= list(map(int, input().split()))\r\n # ms= list(map(int, input().split()))\r\n n=int(input())\r\n ls= list(map(int, input().split()))\r\n fun(n,ls)", "\r\ndef getMinRest(array, startIdx, isGym, isCon, cache):\r\n if (startIdx, isGym, isCon) in cache:\r\n return cache[(startIdx, isGym, isCon)]\r\n if startIdx == len(array):\r\n return 0\r\n\r\n currentMin = float('inf')\r\n if array[startIdx] == 0:\r\n currentMin = min(currentMin, 1 + getMinRest(array,\r\n startIdx + 1, False, False, cache))\r\n elif array[startIdx] == 1:\r\n if not isCon:\r\n currentMin = min(currentMin, getMinRest(\r\n array, startIdx + 1, False, True, cache))\r\n currentMin = min(currentMin, 1 + getMinRest(array,\r\n startIdx + 1, False, False, cache))\r\n elif array[startIdx] == 2:\r\n if not isGym:\r\n currentMin = min(currentMin, getMinRest(\r\n array, startIdx + 1, True, False, cache))\r\n currentMin = min(currentMin, 1 + getMinRest(array,\r\n startIdx + 1, False, False, cache))\r\n elif array[startIdx] == 3:\r\n if not isGym:\r\n currentMin = min(currentMin, getMinRest(\r\n array, startIdx + 1, True, False, cache))\r\n\r\n if not isCon:\r\n currentMin = min(currentMin, getMinRest(\r\n array, startIdx + 1, False, True, cache))\r\n\r\n currentMin = min(currentMin, 1 + getMinRest(array,\r\n startIdx + 1, False, False, cache))\r\n cache[(startIdx, isGym, isCon)] = currentMin\r\n return currentMin\r\n\r\n\r\nn = int(input())\r\nsecondInput = input().split()\r\narray = []\r\nfor i in range(n):\r\n array.append(int(secondInput[i]))\r\n\r\nminRest = getMinRest(array, 0, False, False, {})\r\nprint(minRest)\r\n", "from sys import stdin, stdout\r\nfrom math import sqrt, floor, ceil\r\nfrom collections import defaultdict\r\nfrom collections import deque\r\n\r\n\r\ndef solve():\r\n pass\r\n\r\n\r\ndef main():\r\n for _ in range(1):\r\n n = int(input())\r\n A = [int(a) for a in input().split()]\r\n dp = [[0 for _ in range(4)] for _ in range(n)]\r\n MAXN = 1000\r\n\r\n if A[0] == 0:\r\n dp[0][0] = 1\r\n dp[0][1] = MAXN\r\n dp[0][2] = MAXN\r\n elif A[0] == 1:\r\n dp[0][0] = 1\r\n dp[0][1] = 0\r\n dp[0][2] = MAXN\r\n elif A[0] == 2:\r\n dp[0][0] = 1\r\n dp[0][1] = MAXN\r\n dp[0][2] = 0\r\n else:\r\n dp[0][0] = 1\r\n dp[0][1] = 0\r\n dp[0][2] = 0\r\n\r\n for i in range(1, n):\r\n if A[i] == 0:\r\n # Solo puede descansar.\r\n dp[i][0] = 1 + min([dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]])\r\n dp[i][1] = MAXN\r\n dp[i][2] = MAXN\r\n elif A[i] == 1:\r\n # Va al contest o a descansar.\r\n dp[i][0] = 1 + min([dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]])\r\n dp[i][1] = min([dp[i - 1][0], dp[i - 1][2]])\r\n dp[i][2] = MAXN\r\n elif A[i] == 2:\r\n # Va al gym o a descansar.\r\n dp[i][0] = 1 + min([dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]])\r\n dp[i][1] = MAXN\r\n dp[i][2] = min([dp[i - 1][0], dp[i - 1][1]])\r\n else:\r\n # Va al gym, al contest o a descansar.\r\n dp[i][0] = 1 + min([dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]])\r\n dp[i][1] = min([dp[i - 1][0], dp[i - 1][2]])\r\n dp[i][2] = min([dp[i - 1][0], dp[i - 1][1]])\r\n\r\n print(min([dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]]))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\nx=list(map(int,input().split()))\r\ndef solve(i,p=0,b=0):\r\n if i==n:\r\n return 0\r\n if x[i]==1 and (p!=1 or b):\r\n return solve(i+1,1)\r\n elif x[i]==2 and (p!=2 or b):\r\n return solve(i+1,2)\r\n elif x[i]==3:\r\n if p:\r\n return solve(i+1,[2,1][p-1])\r\n else:\r\n return (solve(i+1,0,b=1))\r\n else:\r\n return 1+solve(i+1)\r\nprint(solve(0))", "n = int(input())\nl = list(map(int,input().split()))\ndp = []\nfor i in range(n+1):\n temp = [110,110,110]\n dp.append(temp)\n\nfor i in range(3):\n dp[0][i] = 0\n#print(dp)\n\nfor i in range(1,n+1):\n if l[i-1]==0:\n dp[i][0] = 1 + min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\n elif l[i-1]==1:\n dp[i][1] = min(dp[i-1][0],dp[i-1][2])\n dp[i][0] = 1 + min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\n elif l[i-1]==2:\n dp[i][2] = min(dp[i-1][0],dp[i-1][1])\n dp[i][0] = 1 + min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\n else:\n dp[i][0] = 1 + min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\n dp[i][1] = min(dp[i-1][0],dp[i-1][2])\n dp[i][2] = min(dp[i-1][0],dp[i-1][1])\n #print(dp)\nprint(min(dp[n][0],dp[n][1],dp[n][2]))", "amt = int(input())\nnums = [int(i) for i in input().split()]\n'''\n0 = gym closed, contest closed\n1 = gym closed, contest open\n2 = gym open, contest closed\n3 = gym open, contest open\n'''\n\ndef open(num):\n\tif num == 0:\n\t\treturn [False, False]\n\telif num == 1:\n\t\treturn [False, True]\n\telif num == 2:\n\t\treturn [True, False]\n\telse:\n\t\treturn [True, True]\n\ngym = False\ncontest = False\nlastgym = False\nlastcontest = False\nans = 0\nfor i in range(amt):\n\tgym, contest = open(nums[i])\n\tif gym == False and contest == False:\n\t\tans += 1\n\t\tlastgym = False\n\t\tlastcontest = False\n\telif gym == True and contest == False:\n\t\tif lastgym == True:\n\t\t\tans += 1\n\t\t\tlastgym = False\n\t\t\tlastcontest = False\n\t\telse:\n\t\t\tlastgym = True\n\t\t\tlastcontest = False\n\telif gym == False and contest == True:\n\t\tif lastcontest == True:\n\t\t\tans += 1 \n\t\t\tlastgym = False\n\t\t\tlastcontest = False\n\t\telse:\n\t\t\tlastgym = False\n\t\t\tlastcontest = True\n\telse:\n\t\tif lastcontest == True and lastgym == True:\n\t\t\tans += 1\n\t\t\tlastgym = False\n\t\t\tlastcontest = False\n\t\telif lastcontest == True and lastgym == False:\n\t\t\tlastcontest = False\n\t\t\tlastgym = True\n\t\telif lastcontest == False and lastgym == True:\n\t\t\tlastcontest = True\n\t\t\tlastgym = False\n\t\telse:\n\t\t\tlastcontest = False\n\t\t\tlastgym = False\n\t#print(gym, contest)\n\t#print(lastgym, lastcontest)\n\t#print('\\n')\nprint(ans)\n\n\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nrest=0\r\nlast=''\r\nfor i in l:\r\n #print(last)\r\n if i==0 or (i==1 and last=='contest') or (i==2 and last=='gym'):\r\n rest+=1\r\n last=''\r\n elif i==1 and last!='contest':\r\n last='contest'\r\n continue\r\n elif i==2 and last!='gym':\r\n last='gym'\r\n continue\r\n else:\r\n if last=='gym':\r\n last='contest'\r\n elif last=='contest':\r\n last='gym'\r\nprint(rest)", "import copy\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nfrom collections import Counter, defaultdict\r\nimport math\r\nimport heapq\r\nimport bisect\r\nimport collections\r\ndef ceil(a, b):\r\n return (a + b - 1) // b\r\nBUFSIZE = 8192\r\ninf = float('inf')\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\nget = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\nMOD = 1000000007\r\ndef s():\r\n return list()\r\ndef gcd(x, y):\r\n while (y):\r\n x, y = y, x % y\r\n return x\r\n# for _ in range(int(get())):\r\n# n=int(get())\r\n# l=list(map(int,get().split()))\r\n# = map(int,get().split())\r\n###########################################################################\r\n###########################################################################\r\nn=int(get())\r\nl=list(map(int,get().split()))\r\ndp=[[inf for i in range(3)] for j in range(n)]\r\ndp[0][0]=1\r\nif l[0]==1:\r\n dp[0][1]=0\r\nif l[0]==2:\r\n dp[0][2]=0\r\nif l[0]==3:\r\n dp[0][0]=1\r\n dp[0][1] = 0\r\n dp[0][2] = 0\r\nfor i in range(1,n):\r\n dp[i][0]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+1\r\n if l[i]==1:\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n if l[i]==2:\r\n dp[i][2]=min(dp[i-1][1],dp[i-1][0])\r\n if l[i]==3:\r\n dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n dp[i][2] = min(dp[i - 1][1], dp[i - 1][0])\r\nprint(min(dp[n-1]))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "from math import inf\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndp0 = [inf] * n\r\ndp1 = [inf] * n\r\ndp2 = [inf] * n\r\n\r\ndp0[0] = 1\r\nif a[0] & 0b01:\r\n\tdp1[0] = 0\r\nif a[0] & 0b10:\r\n\tdp2[0] = 0\r\n\r\nfor i in range(1, n):\r\n\tdp0[i] = min(dp0[i-1], dp1[i-1], dp2[i-1]) + 1\r\n\tif a[i] & 0b01:\r\n\t\tdp1[i] = min(dp0[i-1], dp2[i-1])\r\n\tif a[i] & 0b10:\r\n\t\tdp2[i] = min(dp0[i-1], dp1[i-1])\r\n\r\nprint(min(dp0[-1], dp1[-1], dp2[-1]))\r\n\t\r\n\r\n\r\n", "from functools import lru_cache\r\n\r\nn = int(input())\r\narray = tuple(map(int, input().split(' ')))\r\n\r\n@lru_cache\r\ndef rest(array, day, previous):\r\n if day==len(array): return 0\r\n possibilities = []\r\n if array[day] in (1,3) and previous!='CONTEST':\r\n possibilities.append(rest(array, day+1, 'CONTEST'))\r\n if array[day] in (2,3) and previous!='GYM':\r\n possibilities.append(rest(array, day+1, 'GYM'))\r\n possibilities.append(rest(array,day+1,'REST')+1)\r\n return min(possibilities)\r\n\r\nprint(rest(array,0,'REST'))", "n = int(input())\r\nar = list(map(int, input().split()))\r\n\r\ndp0 = [0] * (n + 1)\r\ndp1 = [0] * (n + 1)\r\ndp2 = [0] * (n + 1)\r\n\r\ndp0[0] = 1\r\nif ar[0] == 1 or ar[0] == 3:\r\n dp1[0] = 0\r\nelse:\r\n dp1[0] = 10000000\r\n\r\nif ar[0] == 2 or ar[0] == 3:\r\n dp2[0] = 0\r\nelse:\r\n dp2[0] = 10000000\r\n\r\nfor i in range(1, n):\r\n dp0[i] = min(min(dp0[i-1], dp1[i-1]), dp2[i-1]) + 1\r\n if ar[i] == 1 or ar[i] == 3:\r\n dp1[i] = min(dp0[i-1], dp2[i-1])\r\n else:\r\n dp1[i] = 10000000\r\n if ar[i] == 2 or ar[i] == 3:\r\n dp2[i] = min(dp0[i-1], dp1[i-1])\r\n else:\r\n dp2[i] = 10000000\r\n\r\na = min(min(dp0[n-1], dp1[n-1]), dp2[n-1])\r\nprint(a)", "b=[0]*303\na=int(input())\na=list(map(int,input().split()))\ncount=0\nfor i in a:\n if i==0:\n c = min(b[count-1],b[count-2],b[count-3])\n b[count] = c+1\n b[count+1] = c+1\n b[count+2] = c+1\n elif i==1:\n c = min(b[count-1],b[count-2],b[count-3])\n b[count] = c+1\n b[count+1] = c+1\n b[count+2] = min(b[count-3], b[count-2])\n elif i==2:\n c = min(b[count-1],b[count-2],b[count-3])\n b[count] = c+1\n b[count+2] = c+1\n b[count+1] = min(b[count-3], b[count-1])\n else:\n c = min(b[count-1],b[count-2],b[count-3])\n b[count] = c+1\n b[count+1] = min(b[count-3],b[count-1])\n b[count+2] = min(b[count-3], b[count-2])\n count+=3\nprint(min(b[count-1],b[count-2],b[count-3]))\n", "n = int(input())\r\ninf = 10**9\r\nlist_of_activities = list(map(int, input().split()))\r\n# 0 - relax\r\n# 1 - contest\r\n# 2 - sport\r\ndp_list = [[5 for x in range(3)] for y in range(n)]\r\nfor i in range(n):\r\n if i == 0:\r\n dp_list[i][0] = 1\r\n dp_list[i][1] = 0 if list_of_activities[0] == 1 or list_of_activities[0] == 3 else inf\r\n dp_list[i][2] = 0 if list_of_activities[0] == 2 or list_of_activities[0] == 3 else inf\r\n else:\r\n dp_list[i][0] = 1 + min(dp_list[i - 1][0], dp_list[i - 1][1], dp_list[i - 1][2])\r\n dp_list[i][1] = min(dp_list[i - 1][0], dp_list[i - 1][2]) \\\r\n if list_of_activities[i] == 1 or list_of_activities[i] == 3 else inf\r\n dp_list[i][2] = min(dp_list[i - 1][0], dp_list[i - 1][1]) \\\r\n if list_of_activities[i] == 2 or list_of_activities[i] == 3 else inf\r\nprint(min(dp_list[n - 1]))", "n = int(input())\r\nl, dp = [int(i) for i in input().split()], [[0,0,0] for j in range(n+2)]\r\nfor i in range(1, n+1): dp[i][0],dp[i][1], dp[i][2] = min(dp[i - 1]) + 1, min(dp[i-1][0], dp[i-1][2]) if (l[i-1] in [1, 3]) else int(1e9), min(dp[i - 1][0], dp[i - 1][1]) if (l[i-1] in [2, 3]) else int(1e9)\r\nprint(min(dp[n]))", "n=int(input())\r\nA=list(map(int,input().split()))\r\na=b=0\r\nfor i in range(1,n+1):\r\n if A[i-1]==0:\r\n a=b=max(a,b)\r\n elif A[i-1]==1:\r\n a,b=max(a,b),max(b,a+1)\r\n elif A[i-1]==2:\r\n a,b=max(a,b+1),max(a,b)\r\n else:\r\n a,b=b+1,a+1\r\nprint(n-max(a,b))", "n = int(input())\r\na = list(map(int, input().split()))\r\nM = 1000\r\ndp = [0, M, M]\r\nfor x in a:\r\n dp = [min(dp) + 1, min(dp[0::2]) if x & 1 else M, min(dp[:2]) if x & 2 else M]\r\nprint(min(dp))", "n = int(input())\r\ndias = list(map(int, input().split()))\r\ndescanco = 0\r\nanterior = 3\r\n\r\nfor dia in dias:\r\n if anterior != 3:\r\n if dia == anterior:\r\n dia = 0\r\n elif dia == 3:\r\n dia -= anterior\r\n if dia == 0:\r\n descanco += 1\r\n anterior = dia\r\n \r\nprint(descanco)", "n = int(input())\r\na = [int(i) for i in input().split()]\r\n\r\nseen = {}\r\n\r\ndef r(i, last):\r\n\tif i < n:\r\n\t\tif (i, last) in seen:\r\n\t\t\treturn seen[(i, last)]\r\n\r\n\t\tai = a[i]\r\n\r\n\t\tp = []\r\n\t\tp.append( r(i+1, 0)+1 )\r\n\r\n\t\tif (ai&1) and (last != 1):\r\n\t\t\tp.append( r(i+1, 1) )\r\n\r\n\t\tif (ai&2) and (last != 2):\r\n\t\t\tp.append( r(i+1, 2) )\r\n\r\n\t\tret = min(p)\r\n\t\tseen[(i, last)] = ret\r\n\t\treturn ret\r\n\telse:\r\n\t\treturn 0\r\n\r\nprint(r(0, 0))", "from functools import *\r\nn = int(input())\r\nnums = list(map(int, input().split()))\r\ninf = 10 ** 14\r\n\r\n# pre: 0休息 1健身 2比赛\r\n@cache\r\ndef f(i, pre):\r\n if i == n: return 0\r\n ans = inf\r\n # 只能休息\r\n if nums[i] == 0:\r\n return 1 + f(i + 1, 0)\r\n # 休息 或者 比赛(前提是前一天没参加比赛)\r\n if nums[i] == 1:\r\n p1 = 1 + f(i + 1, 0) # 休息\r\n p2 = inf\r\n if pre != 2:\r\n p2 = f(i + 1, 2) # 比赛\r\n return min(p1, p2)\r\n # 休息 或者 健身(前提是前一天没健身)\r\n if nums[i] == 2:\r\n p1 = 1 + f(i + 1, 0) # 休息\r\n p2 = inf\r\n if pre != 1:\r\n p2 = f(i + 1, 1) # 健身\r\n return min(p1, p2)\r\n\r\n # 休息、健身、运动都行\r\n p1 = 1 + f(i + 1, 0) # 休息\r\n p2 = p3 = inf\r\n if pre != 1:\r\n p2 = f(i + 1, 1) # 健身\r\n if pre != 2:\r\n p3 = f(i + 1, 2) # 比赛\r\n\r\n return min(p1, p2, p3)\r\n\r\nprint(f(0, 0))", "p = lambda:list(map(int,input().split()))\r\n\r\nn = p()[0]\r\na = p()\r\n\r\ndp = [0,0,0]\r\n\r\nfor i in range(n):\r\n dp = [min(dp)+1,min(dp[0],dp[2]) if a[i]==3 or a[i]==2 else dp[1]+1,min(dp[0],dp[1]) if a[i]==1 or a[i]==3 else dp[2]+1]\r\n\r\nprint(min(dp))", "#!/usr/bin/python3\r\n#Vacations\r\ndef dfs(day,prev):\r\n global dp,inp\r\n if day==len(inp):\r\n return 0\r\n if (day,prev) in dp:\r\n return dp[(day,prev)]\r\n con=inp[day]&1\r\n gym=inp[day]>>1\r\n sel=[0]\r\n if con and prev!=1:\r\n sel.append(1)\r\n if gym and prev!=2:\r\n sel.append(2)\r\n ret=min((dfs(day+1,i)+(not bool(i)) for i in sel))\r\n dp[(day,prev)]=ret\r\n return ret\r\nn=int(input())\r\ninp=list(map(int,input().split()))\r\ndp={}\r\nprint(dfs(0,0))\r\n", "from sys import stdin\ninput = stdin.readline\n\nn = int(input())\na = list(map(int, input().split()))\n\ng, c, r = [float('inf') for i in range(n)], [float('inf') for i in range(n)], [float('inf') for i in range(n)]\n\n\nr[-1] = 1\n\nif a[-1] == 1:\n c[-1] = 0\n\nif a[-1] == 2:\n g[-1] = 0\n\nif a[-1] == 3:\n c[-1], g[-1] = 0, 0\n\n\nfor i in range(n - 2, -1, -1):\n r[i] = 1 + min(r[i + 1], g[i + 1], c[i + 1])\n \n if a[i] == 1:\n c[i] = min(g[i + 1], r[i + 1])\n elif a[i] == 2:\n g[i] = min(c[i + 1], r[i + 1])\n elif a[i] == 3:\n c[i] = min(g[i + 1], r[i + 1])\n g[i] = min(c[i + 1], r[i + 1])\n\n\nprint(min(g[0], c[0], r[0]))", "n = int(input())\r\na = list(map(int, input().split()))\r\nans = 0\r\nc = 3\r\nfor i in a:\r\n if c != 3 and i == c:\r\n i = 0\r\n elif c != 3 and i == 3:\r\n i -= c\r\n if i == 0:\r\n ans += 1\r\n c = i\r\nprint(ans)\r\n", "def dp(pos, nocon, nogym):\r\n global n, lst, mem\r\n if pos >= n:\r\n return 0\r\n if mem[pos][nocon][nogym] != -1:\r\n return mem[pos][nocon][nogym]\r\n if lst[pos] == 0:\r\n tot = dp(pos + 1, False, False) + 1\r\n if lst[pos] == 1:\r\n if nocon:\r\n tot = dp(pos + 1, False, False) + 1\r\n else:\r\n tot = dp(pos + 1, True, False)\r\n if lst[pos] == 2:\r\n if nogym:\r\n tot = dp(pos + 1, False, False) + 1\r\n else:\r\n tot = dp(pos + 1, False, True)\r\n if lst[pos] == 3:\r\n if not nogym and not nocon:\r\n tot1 = dp(pos + 1, False, True)\r\n tot2 = dp(pos + 1, True, False)\r\n tot = min(tot1, tot2)\r\n elif nogym:\r\n tot = dp(pos + 1, True, False)\r\n else:\r\n tot = dp(pos + 1, False, True)\r\n mem[pos][nocon][nogym] = tot\r\n return tot\r\n\r\n\r\n\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nmem = []\r\nfor _ in range(n):\r\n mem.append([[-1, -1], [-1, -1]])\r\n\r\n\r\nprint(dp(0, False, False))", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nactions = [\r\n [\"r\"],\r\n [\"c\", \"r\"],\r\n [\"g\", \"r\"],\r\n [\"g\", \"r\", \"c\"],\r\n]\r\n\r\nr, g, c = 0,0,0\r\nfor day in a:\r\n tr, tg, tc = 101,101,101\r\n opts = actions[day]\r\n for opt in opts:\r\n if opt == \"r\":\r\n tr = min(r, g, c) + 1\r\n elif opt == \"g\":\r\n tg = min(r, c)\r\n else:\r\n tc = min(r, g)\r\n r,g,c = tr,tg,tc\r\nprint(min(r,g,c))", "n = int(input())\r\na = list(map(int, input().split()))\r\ndp = [[0]*3 for i in range(n)]\r\ndp[0][0] = 0\r\nif a[0] == 1:\r\n dp[0][1] += 1\r\nelif a[0] == 2:\r\n dp[0][2] += 1\r\nelif a[0] == 3:\r\n dp[0][1] += 1\r\n dp[0][2] += 1\r\nfor i in range(1, n):\r\n dp[i][0] = max(dp[i-1])\r\n # if a[i] == 0:\r\n # dp[i][1] = dp[i - 1][1]\r\n # dp[i][2] = dp[i - 1][2]\r\n if a[i] == 1:\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1\r\n # dp[i][2] = dp[i-1][2]\r\n elif a[i] == 2:\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1\r\n # dp[i][1] = dp[i - 1][1]\r\n elif a[i] == 3:\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1\r\nprint(n-max(dp[-1]))\r\n\r\n# for i in range(n):\r\n# print(dp[i])", "n = int(input())\r\nls = list(map(int, input().split()))\r\n\r\ndays = 0\r\nprev = 0\r\nfor x in ls:\r\n if x == prev or not x:\r\n prev = 0\r\n days += 1\r\n elif x < 3:\r\n prev = x\r\n elif prev:\r\n prev = 3-prev\r\n\r\nprint(days)\r\n", "import sys\r\nn = int(sys.stdin.readline())\r\ninp = sys.stdin.readline()[:-1].split(' ')\r\ninp = [int(x) for x in inp]\r\nlast = 'start'\r\nans = 0\r\n\r\ndef whatToDO(day,lastReturn=0):\r\n if day==0:\r\n lastReturn = 0\r\n elif lastReturn ==0:\r\n if day <3:\r\n lastReturn = day\r\n else:\r\n lastReturn = 12\r\n elif lastReturn == 12:\r\n if day!=3:\r\n lastReturn = day\r\n elif lastReturn == 1:\r\n if day ==1:\r\n lastReturn = 0\r\n else:\r\n lastReturn = day\r\n if day==3:\r\n lastReturn = 2\r\n elif lastReturn == 2:\r\n if day ==2:\r\n lastReturn = 0\r\n else:\r\n lastReturn = day\r\n if day==3:\r\n lastReturn = 1\r\n return lastReturn\r\n\r\nlast = 0\r\nfor i in range(len(inp)):\r\n last = whatToDO(inp[i],last)\r\n if last==0:\r\n ans = ans+1\r\n\r\nprint(ans) \r\n", "import bisect\r\nimport collections\r\nimport math\r\ndef gcd(a,b):\r\n return math.gcd(a,b)\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\ndp=[[0 for i in range(3)] for j in range(n)]\r\nif arr[0]==1:\r\n dp[0][1]=1\r\nif arr[0]==2:\r\n dp[0][2]=1\r\nif arr[0]==3:\r\n dp[0][1]=1\r\n dp[0][2]=1\r\nfor i in range(1,n):\r\n if arr[i]==0:\r\n dp[i][1]=max(dp[i-1])\r\n dp[i][2]=max(dp[i-1])\r\n if arr[i]==1:\r\n dp[i][1]=max(dp[i-1][0],dp[i-1][2])+1\r\n dp[i][2]=max(dp[i-1])\r\n if arr[i]==2:\r\n dp[i][1]=max(dp[i-1])\r\n dp[i][2]=max(dp[i-1][0],dp[i-1][1])+1\r\n if arr[i]==3:\r\n dp[i][1]=max(dp[i-1][0],dp[i-1][2])+1\r\n dp[i][2]=max(dp[i-1][0],dp[i-1][1])+1\r\n dp[i][0]=max(dp[i-1])\r\n# for i in dp:\r\n# print(*i)\r\nprint(n-max(dp[n-1]))\r\n \r\n ", "# from dust i have come dust i will be\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndp = [[0] * 2 for i in range(n+1)]\r\n\r\nfor i in range(1, n + 1):\r\n\r\n # fill the gym\r\n if (a[i - 1] == 2 or a[i - 1] == 3):\r\n dp[i][0] = min(dp[i - 1][1], min(dp[i - 1][0], dp[i - 1][1]) + 1)\r\n else:\r\n dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + 1\r\n\r\n # fill the contest\r\n if (a[i - 1] == 1 or a[i - 1] == 3):\r\n dp[i][1] = min(dp[i - 1][0], min(dp[i - 1][0], dp[i - 1][1]) + 1)\r\n else:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 1\r\n\r\n\r\n#print(dp)\r\nprint(min(dp[n][0],dp[n][1]))", "import math,sys,bisect,heapq\r\nfrom collections import defaultdict,Counter,deque\r\nfrom itertools import groupby,accumulate\r\n#sys.setrecursionlimit(200000000)\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nilele = lambda: map(int,input().split())\r\nalele = lambda: list(map(int, input().split()))\r\nfrom functools import lru_cache\r\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\r\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\r\n#MOD = 1000000000 + 7\r\ndef Y(c): print([\"NO\",\"YES\"][c])\r\ndef y(c): print([\"no\",\"yes\"][c])\r\ndef Yy(c): print([\"No\",\"Yes\"][c])\r\n \r\nN = int(input())\r\nA = alele()\r\ndp = {}\r\ndef fun(N,day,prev = -1):\r\n if day >= N:\r\n return 0\r\n if dp.get((day,prev),-1) != -1:\r\n return dp[(day,prev)]\r\n if prev == -1:\r\n x = A[day]\r\n if x == 0:\r\n dp[(day,prev)] = 1 + fun(N,day+1,-1)\r\n return dp[(day,prev)]\r\n elif x == 1:\r\n dp[(day,prev)] = min(1 + fun(N,day+1,-1), fun(N,day+1,2))\r\n return dp[(day,prev)]\r\n elif x == 2:\r\n dp[(day,prev)] = min(1 + fun(N,day+1,-1),fun(N,day+1,3))\r\n return dp[(day,prev)]\r\n elif x == 3:\r\n dp[(day,prev)] = min(1 + fun(N,day+1,-1),fun(N,day+1,2),fun(N,day+1,3))\r\n return dp[(day,prev)]\r\n elif prev == 2:\r\n x = A[day]\r\n if x == 0:\r\n dp[(day,prev)] = 1 + fun(N,day+1,-1)\r\n return dp[(day,prev)]\r\n elif x == 1:\r\n dp[(day,prev)] = 1 + fun(N,day+1,-1)\r\n return dp[(day,prev)]\r\n elif x == 2:\r\n dp[(day,prev)] = min(1 + fun(N,day+1,-1),fun(N,day+1,3))\r\n return dp[(day,prev)]\r\n elif x == 3:\r\n dp[(day,prev)] = min(1 + fun(N,day+1,-1),fun(N,day+1,3))\r\n return dp[(day,prev)]\r\n elif prev == 3:\r\n x = A[day]\r\n if x == 0:\r\n dp[(day,prev)] = 1 + fun(N,day+1,-1)\r\n return dp[(day,prev)]\r\n elif x == 1:\r\n dp[(day,prev)] = min(1 + fun(N,day+1,-1), fun(N,day+1,2))\r\n return dp[(day,prev)]\r\n elif x == 2:\r\n dp[(day,prev)] =1 + fun(N,day+1,-1)\r\n return dp[(day,prev)]\r\n elif x == 3:\r\n dp[(day,prev)] = min(1 + fun(N,day+1,-1),fun(N,day+1,2))\r\n return dp[(day,prev)]\r\n \r\n\r\nprint(fun(N,0))\r\n \r\n \r\n \r\n ", "from sys import stdin, stdout\r\n\r\ndef main():\r\n n = int(stdin.readline())\r\n a = [0] + list(map(int, stdin.readline().split()))\r\n \r\n r = [0]*110\r\n c = [0]*110\r\n g = [0]*110\r\n \r\n for i in range(1, n+1):\r\n r[i] = min(c[i-1], g[i-1], r[i-1]) + 1\r\n \r\n if a[i] == 0:\r\n c[i] = 111\r\n g[i] = 111\r\n elif a[i] == 1:\r\n c[i] = min(g[i-1], r[i-1])\r\n g[i] = 111\r\n elif a[i] == 2:\r\n c[i] = 111\r\n g[i] = min(c[i-1], r[i-1])\r\n else:\r\n c[i] = min(g[i-1], r[i-1])\r\n g[i] = min(c[i-1], r[i-1])\r\n \r\n print(min(r[n], g[n], c[n]))\r\nmain()\r\n", "n_days=int(input())\nint_seq =list(map(int,input().split()))\nmin_days=0\nx=0\nfor i in range(len(int_seq)):\n if int_seq[i]==0 or int_seq[i]==x:\n min_days+=1\n x=0\n elif int_seq[i]==3:\n if(x!=0):\n x=3-x\n else:\n x=int_seq[i]\nprint(min_days)\n", "n=int(input())\r\na=list(map(int,input().split()))\r\narr=[[0,0,0]]\r\nfor i in range(n):\r\n f=a[i]\r\n r=max(arr[i][0],arr[i][1],arr[i][2])\r\n c=arr[i][1];g=arr[i][2]\r\n if f==1 or f==3:\r\n c=max(arr[i][0],arr[i][2])+1\r\n if f==2 or f==3:\r\n g=max(arr[i][0],arr[i][1])+1\r\n arr.append([r,c,g])\r\nprint(n-max(arr[-1][0],arr[-1][1],arr[-1][2]))\r\n", "from math import inf\r\n\r\n\r\nn = int(input())\r\na = [int(i) for i in input().split()]\r\ndp = [[0, 0, 0] for _ in range(n + 1)]\r\nfor i in range(n):\r\n dp[i + 1][0] = min(dp[i]) + 1\r\n if a[i] & 1:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n else:\r\n dp[i + 1][1] = inf\r\n if a[i] & 2:\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1])\r\n else:\r\n dp[i + 1][2] = inf\r\nprint(min(dp[-1]))\r\n", "n = int(input())\n\ndays = list(map(int, input().split()))\n\np_last = 0\ng_last = 0\nhas_p_last = False\nhas_g_last = False\nfor a in days:\n has_p = (a % 2 == 1)\n has_g = (a > 1)\n \n if has_p:\n if has_p_last:\n p = g_last\n else:\n p = min(p_last, g_last)\n else:\n p = 1 + min(p_last, g_last)\n \n \n if has_g:\n if has_g_last:\n g = p_last\n else:\n g = min(p_last, g_last)\n else:\n g = 1 + min(p_last, g_last)\n\n has_p_last = has_p\n has_g_last = has_g\n p_last = p\n g_last = g\n\nprint(min(p_last, g_last))\n", "n=int(input())\r\noption=list(map(int,input().split()))\r\ndp=['r']*n\r\nif option[0]==1:\r\n dp[0]='c'\r\nelif option[0]==2:\r\n dp[0]='s'\r\nelif option[0]==3:\r\n dp[0]='cs'\r\nfor i in range(1,n):\r\n if option[i]!=0:\r\n if dp[i-1]=='c':\r\n if option[i]==1:\r\n dp[i]='r'\r\n else:\r\n dp[i]='s'\r\n if dp[i-1]=='s':\r\n if option[i]==2:\r\n dp[i]='r'\r\n else:\r\n dp[i]='c'\r\n if dp[i-1]=='cs' or dp[i-1]=='r':\r\n if option[i]==1:\r\n dp[i]='c'\r\n if option[i]==2:\r\n dp[i]='s'\r\n if option[i]==3:\r\n dp[i]='cs'\r\n else:\r\n dp[i]='r'\r\nprint(dp.count('r'))", "def schedule(j, x):\r\n if x == -1:\r\n return 'r' if a[j] == 0 else 'c' if a[j] == 1 else 'g' if a[j] == 2 else \\\r\n 'c' if j < n-1 and schedule(j+1, x) != 'c' else 'g'\r\n if a[j] == 0:\r\n return 'r'\r\n elif a[j] == 1 and x != 'c':\r\n return 'c'\r\n elif a[j] == 2 and x != 'g':\r\n return 'g'\r\n elif a[j] == 3:\r\n if x == 'g':\r\n return 'c'\r\n elif x == 'c':\r\n return 'g'\r\n else:\r\n return 'r'\r\n\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ncount = 0\r\nk = -1\r\nfor i in range(n):\r\n d = schedule(i, k)\r\n k = d\r\n if k == 'r':\r\n count += 1\r\n\r\nprint(count)\r\n", "vvod1=int(input())\nvvod2=str(input())\nvvod2=vvod2.split(\" \")\nkcounter=0\nrest=0\ncounter1=0\n\nchecker=0#0 Otdix,1 Sport, CS 2\n'''def hardcase(counter1):\n global vvod2\n the_size=len(vvod2)\n \n while True:\n if vvod2[counter1]'''\n\nfor i in vvod2:\n vvod2[kcounter]=int(i)\n kcounter+=1\nfor k in vvod2:\n if k==0:\n counter1+=1\n rest+=1\n checker=0\n elif k==1:\n counter1+=1\n if checker==0:\n checker=2\n elif checker==1:\n checker=2\n else:\n checker=0\n rest+=1\n elif k==2:\n counter1+=1\n if checker==0:\n checker=1\n elif checker==1:\n checker=0\n rest+=1\n else:\n checker=1\n elif k==3:\n counter1+=1\n if checker==1:\n checker=2\n elif checker==2:\n checker=1\n else:\n checker=0\nprint(rest)\n\n \n\n\n\n\n\n", "'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"Vacations\"\r\n# Class: C\r\n\r\nimport sys, threading\r\n\r\nsys.setrecursionlimit(2147483647)\r\ninput = sys.stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n sys.stdout.write(sep.join(map(str, args)) + end)\r\n\r\ninf = float(\"inf\")\r\n\r\nd = {}\r\n\r\ndef func(i, p):\r\n global n, a\r\n if i==n: return 0\r\n if (i, p) not in d.keys():\r\n if a[i]==3:\r\n if p==0:\r\n x = min(func(i+1, 1), func(i+1, 2), func(i+1, 0)+1)\r\n d[(i, p)] = x\r\n return x\r\n elif p==1:\r\n x = min(func(i+1, 0)+1, func(i+1, 2))\r\n d[(i, p)] = x\r\n return x\r\n elif p==2:\r\n x = (min(func(i+1, 0)+1, func(i+1, 1)))\r\n d[(i, p)] = x\r\n return x\r\n elif a[i]==0:\r\n x = func(i+1, 0)+1\r\n d[(i, p)] = x\r\n return x\r\n else:\r\n if a[i]==p:\r\n x = func(i+1, 0)+1\r\n d[(i, p)] = x\r\n return x\r\n else:\r\n x = func(i+1, a[i])\r\n d[(i, p)] = x\r\n return x\r\n else:\r\n return d[(i, p)]\r\n\r\ndef Solve():\r\n global n, a\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n print(func(0, 0))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n threading.stack_size(10**8)\r\n threading.Thread(target=Solve).start()", "import math\r\ndef proC(i,job):\r\n global arr,mat\r\n \r\n if(i>len(arr)-1):\r\n return 0\r\n if(mat[i][job]!=-1):\r\n return mat[i][job]\r\n if(arr[i]==0):\r\n mat[i][job]=1+proC(i+1,0)\r\n \r\n if(arr[i]==1):\r\n if(job==arr[i]):\r\n mat[i][job]=proC(i+1,0)+1\r\n else:\r\n mat[i][job]=proC(i+1,1)\r\n \r\n if(arr[i]==2):\r\n if(job==arr[i]):\r\n mat[i][job]=proC(i+1,0)+1\r\n else:\r\n mat[i][job]=proC(i+1,2)\r\n if(arr[i]==3):\r\n a,b=math.inf,math.inf\r\n if(job!=1):\r\n a=proC(i+1,1)\r\n if(job!=2):\r\n b=proC(i+1,2)\r\n mat[i][job]=min(a,b)\r\n return mat[i][job]\r\n\r\n\r\n\r\nt=int(input())\r\narr=list(map(int,input().split()))\r\nmat=[]\r\nfor i in range(len(arr)):\r\n temp=[-1,-1,-1]\r\n mat.append(temp)\r\nprint(proC(0,0))", "vacation_days = int(input())\r\nevents = list(map(int, input().split()[:vacation_days]))\r\n\r\nrest_days = 0\r\nprevious_event = 0\r\n\r\nfor i in range(len(events)):\r\n if events[i] == 0:\r\n rest_days += 1\r\n previous_event = 0\r\n\r\n elif events[i] == 1:\r\n if previous_event == events[i]:\r\n rest_days += 1\r\n previous_event = 0\r\n else:\r\n previous_event = 1\r\n\r\n elif events[i] == 2:\r\n if previous_event == 2:\r\n rest_days += 1\r\n previous_event = 0\r\n else:\r\n previous_event = 2\r\n\r\n elif events[i] == 3:\r\n if previous_event != 0:\r\n previous_event = 3 - previous_event\r\n\r\nprint(rest_days)\r\n\r\n\r\n# 0 = gym closed, no contest\r\n# 1 = gym closed, contest\r\n# 2 = gym open, no contest\r\n# 3 = gym open, contest\r\n", "def main():\r\n n = int(input())\r\n ar = list(map(int, input().split()))\r\n ar = [-1] + ar\r\n dp = [[0] * 3 for _ in range(n + 1)]\r\n\r\n for i in range(1, n + 1):\r\n dp[i][0] = min(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 1\r\n\r\n if ar[i] == 1 or ar[i] == 3:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n else:\r\n dp[i][1] = dp[i - 1][1] + 1\r\n\r\n if ar[i] == 2 or ar[i] == 3:\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n else:\r\n dp[i][2] = dp[i - 1][2] + 1\r\n\r\n print(min(dp[n][0], dp[n][1], dp[n][2]))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "\r\nimport sys\r\n\r\n\r\n# Input Functions\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\n# Output Functions\r\ndef outp(s):\r\n sys.stdout.write(s + '\\n')\r\ndef loutp(l):\r\n sys.stdout.write(' '.join(map(str,l)) + '\\n')\r\n\r\ndef solve():\r\n\r\n n = inp()\r\n ds = inlt()\r\n\r\n dh = [[0,0,0]]\r\n for d in ds:\r\n db = dh[-1]\r\n dh.append([\r\n max(db),\r\n max([db[0], db[2]]) + (1 if d == 1 or d == 3 else 0),\r\n max([db[0], db[1]]) + (1 if d == 2 or d == 3 else 0)\r\n ])\r\n\r\n outp(str(n - max(dh[-1])))\r\n\r\n\r\nif __debug__:\r\n input = sys.stdin.readline\r\n solve()\r\n", "#\t!/bin/env python3\r\n#\tcoding: UTF-8\r\n\r\n\r\n#\t✪ H4WK3yE乡\r\n#\tMohd. Farhan Tahir\r\n#\tIndian Institute Of Information Technology and Management,Gwalior\r\n\r\n#\tQuestion Link\r\n#\r\n#\r\n\r\n# ///==========Libraries, Constants and Functions=============///\r\n\r\n\r\nimport sys\r\nsys.setrecursionlimit(2000)\r\n\r\ninf = float(\"inf\")\r\nmod = 1000000007\r\n\r\n\r\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\r\n\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().split())\r\n\r\n\r\ndef input(): return sys.stdin.readline()\r\n\r\n# ///==========MAIN=============///\r\n\r\n\r\ndef recurse(arr, i, flag):\r\n if i == len(arr):\r\n return 1\r\n if dp[i][flag] != inf:\r\n return dp[i][flag]\r\n\r\n if arr[i] == 0:\r\n dp[i][flag] = min(dp[i][flag], 1+recurse(arr, i+1, 2))\r\n elif arr[i] == 1:\r\n if flag != 1:\r\n dp[i][flag] = min(dp[i][flag], recurse(arr, i+1, 1), 1+recurse(arr, i+1, 2))\r\n else:\r\n dp[i][flag] = min(dp[i][flag], 1+recurse(arr, i+1, 2))\r\n elif arr[i] == 2:\r\n if flag != 0:\r\n dp[i][flag] = min(dp[i][flag], recurse(arr, i+1, 0), 1+recurse(arr, i+1, 2))\r\n else:\r\n dp[i][flag] = min(dp[i][flag], 1+recurse(arr, i+1, 2))\r\n elif arr[i] == 3:\r\n if flag == 0:\r\n dp[i][flag] = min(dp[i][flag], 1+recurse(arr, i+1, 2), recurse(arr, i+1, 1))\r\n elif flag == 1:\r\n dp[i][flag] = min(dp[i][flag], 1+recurse(arr, i+1, 2), recurse(arr, i+1, 0))\r\n elif flag == 2:\r\n dp[i][flag] = min(dp[i][flag], 1+recurse(arr, i+1, 2),\r\n recurse(arr, i+1, 0), recurse(arr, i+1, 1))\r\n return dp[i][flag]\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n arr = get_array()\r\n print(recurse(arr, 0, 2)-1)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n dp = [[inf for _ in range(3)] for _ in range(101)]\r\n main()\r\n", "from collections import defaultdict\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n a_list = list(map(int, input().split()))\r\n\r\n # 0: 休み, 1: contest, 2: gym\r\n dp = [[0] * 3 for _ in range(n)]\r\n dp[0][0] = 0\r\n dp[0][1] = 1 if a_list[0] in [1, 3] else 0\r\n dp[0][2] = 1 if a_list[0] in [2, 3] else 0\r\n\r\n for i in range(1, len(a_list)):\r\n a = a_list[i]\r\n\r\n dp[i][0] = max(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2])\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2])\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2])\r\n\r\n if a == 1:\r\n dp[i][1] = max(dp[i][1], dp[i - 1][0] + 1, dp[i - 1][2] + 1)\r\n elif a == 2:\r\n dp[i][2] = max(dp[i][2], dp[i - 1][0] + 1, dp[i - 1][1] + 1)\r\n elif a == 3:\r\n dp[i][1] = max(dp[i][1], dp[i - 1][0] + 1, dp[i - 1][2] + 1)\r\n dp[i][2] = max(dp[i][2], dp[i - 1][0] + 1, dp[i - 1][1] + 1)\r\n\r\n print(n - max(dp[-1][0], dp[-1][1], dp[-1][2]))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "tam = int(input())\nlista = list(map(int,input().split()))\n\ndp = [[-1 for i in range(tam+10)] for i in range(5)]\n\n\ndef solve(i,ultimo): # ultimo 0 -> pode os 2, 1 -> fez contest, 2 -> fez gym\n if i == tam:\n return 0\n if dp[ultimo][i] != -1:\n return dp[ultimo][i]\n\n hoje = lista[i]\n\n r = solve(i+1,0)+1\n if (hoje == 1 or hoje == 3) and (ultimo == 0 or ultimo == 2):\n r = min(r,solve(i+1,1))\n if (hoje == 2 or hoje == 3) and (ultimo == 0 or ultimo == 1):\n r = min(r,solve(i+1,2))\n dp[ultimo][i] = r\n return r\n\nprint(solve(0,0))\n\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\ncount, prev = 0, 3 \r\nfor i in arr:\r\n\tif i == prev and prev != 3:\r\n\t\ti = 0 \r\n\telif i == 3 and prev != 3:\r\n\t\ti -= prev\r\n\tif i == 0:\r\n\t\tcount += 1\r\n\tprev = i \r\nprint(count)", "n=int(input())\r\nl=[int(i) for i in input().split()]\r\nl2 = [0,0,0]\r\nfor i in range(n):\r\n\ta = l2[:]\r\n\tl2[0] = min(a)+1\r\n\tif l[i]==1 or l[i] == 3:\r\n\t\tl2[1] = min(a[0],a[2])\r\n\telse:\r\n\t\tl2[1] = 10**6\r\n\tif l[i] == 2 or l[i] == 3:\r\n\t\tl2[2] = min(a[0],a[1])\r\n\telse:\r\n\t\tl2[2] = 10**6\r\nprint(min(l2))\r\n", "n = int(input())\r\ns = list(map(int, input().split()))\r\ndp = [[0 for _ in range(3)] for _ in range(n + 1)]\r\nfor i in range(n):\r\n for j in range(3):\r\n if s[i] == 1 and j != 1:\r\n dp[i + 1][1] = max(dp[i][j] + 1, dp[i + 1][1])\r\n if s[i] == 2 and j != 2:\r\n dp[i + 1][2] = max(dp[i][j] + 1, dp[i + 1][2])\r\n if s[i] == 3:\r\n if j != 1:\r\n dp[i + 1][1] = max(dp[i][j] + 1, dp[i + 1][1])\r\n if j != 2:\r\n dp[i + 1][2] = max(dp[i][j] + 1, dp[i + 1][2])\r\n dp[i + 1][0] = max(dp[i][j], dp[i + 1][0])\r\nans = max(dp[n])\r\nprint(n - ans)", "n=int(input())\r\na=list(map(int,input().split()))\r\ndp=[[0 for i in range(3)] for j in range(n+1)]\r\nfor i in range(1,n+1):\r\n if a[i-1]==0:\r\n dp[i][0]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+1\r\n dp[i][1]=n+5\r\n dp[i][2]=n+5\r\n elif a[i-1]==1:\r\n dp[i][0]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+1\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2]=n+5\r\n elif a[i-1]==2:\r\n dp[i][0]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+1\r\n dp[i][1]=n+5\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n else:\r\n dp[i][0]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+1\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\nprint(min(dp[n]))", "n=int(input())\r\nal=list(map(int,input().split()))\r\n \r\nres,prev=0,0\r\n \r\nfor x in al:\r\n\tif (x==0 or x==prev):\r\n\t\tprev=0\r\n\t\tres+=1\r\n\telif x==1 or x==2:\r\n\t\tprev=x\r\n\telif prev>0 and x==3:\r\n\t\tprev=3-prev\r\n \r\nprint(res)", "import sys, math\r\ndef get(a):\r\n if a!=-1:\r\n return(a)\r\n return(1000000000)\r\nn=int(input())\r\nz=list(map(int,input().split()))\r\nfir = [0 for i in range(n+1)] #отдых\r\nsec = [0 for i in range(n+1)] #контест\r\nth = [0 for i in range(n+1)] #трен\r\nsec[0]=-1\r\nth[0]=-1\r\nfor i in range(n):\r\n if z[i]==0: #отдых\r\n fir[i+1]=min(fir[i]+1, get(sec[i])+1, get(th[i])+1)\r\n sec[i+1]=-1\r\n th[i+1]=-1\r\n elif z[i]==1: #контест\r\n fir[i+1]=min(fir[i]+1, get(sec[i])+1, get(th[i])+1)\r\n sec[i+1]=min(fir[i], get(th[i]))\r\n th[i+1]=-1\r\n elif z[i]==2:\r\n fir[i+1]=min(fir[i]+1, get(sec[i])+1, get(th[i])+1)\r\n sec[i+1]=-1\r\n th[i+1]=min(fir[i], get(sec[i]))\r\n else:\r\n fir[i+1]=min(fir[i]+1, get(sec[i])+1, get(th[i])+1)\r\n sec[i+1]=min(fir[i], get(th[i]))\r\n th[i+1]=min(fir[i], get(sec[i]))\r\nprint(min(fir[-1],get(sec[-1]), get(th[-1])))\r\n", "ndays =int(input())\n\ndays= input().split()\nrest=0\n\nfor day in range(len(days)):\n if days[day] == '0':\n rest+=1\n elif days[day] == '1' and day>0:\n if days[day-1] == '1':\n days[day] = '0'\n rest+=1\n elif days[day] == '2' and day>0:\n if days[day-1] == '2':\n days[day] = '0'\n rest+=1\n elif days[day] == '3' and day>0:\n if days[day-1] == '2':\n days[day] = '1'\n if days[day-1] == '1':\n days[day] = '2'\n\nprint(rest)\n \t\t \t\t\t\t \t\t\t\t \t \t \t", "n = int(input())\r\na = list(map(int,input().split()))\r\nbest = [0,0,0]\r\nfor i in range(n):\r\n nx_best = [0,0,0]\r\n if a[i] in (1,3):\r\n nx_best[1] = max(best[0],best[2])+1\r\n if a[i] in (2,3):\r\n nx_best[2] = max(best[0],best[1])+1\r\n nx_best[0] = max(best)\r\n best = nx_best[:]\r\nprint(n-max(best))\r\n", "n=int(input())\na=list(map(int,input().split()))\ndp=[-1 for i in range(n)]\ndp[0]=a[0]\nfor i in range(1,n):\n\tif(a[i]==0):\n\t\tdp[i]=0\n\telse:\n\t\tif(a[i]==dp[i-1] and a[i]!=3):\n\t\t\tdp[i]=0\n\t\telif(a[i]==3 and dp[i-1]!=3):\n\t\t\tdp[i]=abs(3-dp[i-1])\n\t\telse:\n\t\t\tdp[i]=a[i]\nprint(dp.count(0))\n\n\n", "n = int(input())\r\nmas = list(map(int,input().split()))\r\ni=1\r\ne = mas[0]\r\nif e==0:\r\n res=1\r\nelse:\r\n res=0\r\nif e==3:\r\n for i,x in enumerate(mas):\r\n if x!=3:\r\n break\r\n if mas[i]==3:\r\n print(0)\r\n from sys import exit\r\n exit()\r\n if mas[i]==2:\r\n e=1\r\n else:\r\n e=2\r\nfor k in range(i,n):\r\n r = mas[k]\r\n if r==0:\r\n res+=1\r\n e=0\r\n continue\r\n if e!=3:\r\n if r==3:\r\n if e==1:\r\n e=2\r\n elif e==2:\r\n e=1\r\n else:\r\n e=3\r\n else:\r\n if e==r:\r\n e=0\r\n res+=1\r\n else:\r\n e=r\r\n else:\r\n e=r\r\nprint(res)", "import math\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n values = list(map(int, input().split()))\r\n dp = [[math.inf for _ in range(3)] for _ in range(n + 1)]\r\n dp[0][0] = 0\r\n for i in range(1, n + 1):\r\n if values[i - 1] == 1 or values[i - 1] == 3:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n if values[i - 1] == 2 or values[i - 1] == 3:\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n print(min(dp[n]))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\r\na = input()\r\nA = list(map(int,list(a.split())))\r\ndp = [[0 for i in range(4)] for j in range(n+1)]\r\nfor i in range(1,n+1):\r\n if A[i-1] == 1:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1] = max(dp[i-1][0]+1,dp[i-1][2]+1)\r\n elif A[i-1] == 2:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][2] = max(dp[i-1][0]+1,dp[i-1][1]+1)\r\n elif A[i-1] == 3:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n dp[i][1] = max(dp[i-1][0]+1,dp[i-1][2]+1)\r\n dp[i][2] = max(dp[i-1][0]+1,dp[i-1][1]+1)\r\n else:\r\n dp[i][0] = max(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\nprint(n-max(dp[n]))", "n = int(input())\r\nvacations = list(map(int, input().split()))\r\n\r\ndef cal_vac(nums):\r\n l = len(nums)\r\n if l < 1:\r\n return 0\r\n dp = [[0] * 3 for _ in range(l)]\r\n dp[l-1][0] = 0 if nums[l-1] in {0, 2} else 1\r\n dp[l-1][1] = 0 if nums[l-1] in {0, 1} else 1\r\n dp[l-1][2] = 0\r\n for i in range(l-2, -1, -1):\r\n if nums[i] == 0:\r\n dp[i][0] = max(dp[i+1])\r\n dp[i][1] = max(dp[i+1])\r\n dp[i][2] = max(dp[i+1])\r\n elif nums[i] == 3:\r\n dp[i][0] = max(dp[i+1][1] + 1, dp[i+1][2] + 1)\r\n dp[i][1] = max(dp[i+1][0] + 1, dp[i+1][2] + 1)\r\n dp[i][2] = max(dp[i+1][0], dp[i+1][1])\r\n elif nums[i] == 1:\r\n dp[i][0] = max(dp[i+1][1] + 1, dp[i+1][2] + 1)\r\n dp[i][1] = max(dp[i+1][0], dp[i+1][2])\r\n dp[i][2] = max(dp[i+1][0], dp[i+1][1])\r\n else:\r\n dp[i][0] = max(dp[i+1][1], dp[i+1][2])\r\n dp[i][1] = max(dp[i+1][0] + 1, dp[i+1][2] + 1)\r\n dp[i][2] = max(dp[i+1][0], dp[i+1][1])\r\n # print(dp)\r\n return max(dp[0])\r\n\r\nprint(n - cal_vac(vacations))", "R = lambda: map(int, input().split())\r\nn = int(input())\r\ndp = [[0, 0, 0] for i in range(n + 1)]\r\nfor i, x in enumerate(R()):\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n if x == 3:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n elif x == 2:\r\n dp[i][1] = n + 1\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n elif x == 1:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n dp[i][2] = n + 1\r\n else:\r\n dp[i] = [min(dp[i - 1]) + 1] * 3\r\nprint(min(dp[n - 1]))", "act = int(input())\r\na = list(map(int,input().split()))\r\ndp = [[-1 for i in range(3)] for j in range(act+1)]\r\nc = 0\r\ndef ans(n,k):\r\n if n == act:\r\n return 0\r\n if dp[n][k] != -1:\r\n return dp[n][k]\r\n if a[n] == 0:\r\n dp[n][k] = 1+ans(n+1,0)\r\n return 1+ans(n+1,0)\r\n if a[n] == 1:\r\n if k == 1:\r\n dp[n][k] = 1+ans(n+1,0)\r\n return(1+ans(n+1,0))\r\n else:\r\n dp[n][k] = min(1+ans(n+1,0),ans(n+1,1))\r\n return(min(1+ans(n+1,0),ans(n+1,1)))\r\n if a[n] == 2:\r\n if k == 2:\r\n dp[n][k] = 1+ans(n+1,0)\r\n return(1+ans(n+1,0))\r\n else:\r\n dp[n][k] = min(1+ans(n+1,0),ans(n+1,2))\r\n return(min(1+ans(n+1,0),ans(n+1,2)))\r\n if a[n] == 3:\r\n if k == 2:\r\n dp[n][k] = min(1+ans(n+1,0),ans(n+1,1))\r\n return(min(1+ans(n+1,0),ans(n+1,1)))\r\n elif k == 1:\r\n dp[n][k] = min(1+ans(n+1,0),ans(n+1,2))\r\n return(min(1+ans(n+1,0),ans(n+1,2)))\r\n else:\r\n dp[n][k] = min(1+ans(n+1,0),ans(n+1,1),ans(n+1,2))\r\n return(min(1+ans(n+1,0),ans(n+1,1),ans(n+1,2)))\r\n\r\nk = ans(0,0)\r\nprint(k)\r\n \r\n \r\n \r\n", "n = int(input())\r\ndays = list(map(int, input().split(\" \")))\r\nstat = 3\r\ncount = 0\r\nfor day in days:\r\n if stat & day > 0:\r\n if stat == day:\r\n if stat != 3:\r\n stat = 3 - stat\r\n else:\r\n stat ^= day\r\n else:\r\n count += 1\r\n stat = 3\r\n \r\nprint(count)", "vacation_days = int(input())\ndays_information = [int(day) for day in input().split(' ')]\n\nrest_days = 0\nprevious_activity = -1\nfor i ,day in enumerate(days_information):\n if day == 0:\n rest_days += 1\n previous_activity = -1\n if day == 1:\n if previous_activity == 1:\n rest_days += 1\n previous_activity = -1\n else:\n previous_activity = 1\n if day == 2:\n if previous_activity == 2:\n rest_days += 1\n previous_activity = -1\n else:\n previous_activity = 2\n if day == 3:\n if previous_activity == 1:\n previous_activity = 2\n elif previous_activity == 2:\n previous_activity = 1\n elif i < vacation_days - 1 and days_information[i + 1] == 1:\n previous_activity = 2\n elif i < vacation_days - 1 and days_information[i + 1] == 2:\n previous_activity = 1\n \nprint(rest_days)\n \t \t\t \t \t \t\t \t\t\t \t \t \t\t", "def findMinRest(days, d, dayNo, prevDay, restCount, memo):\r\n global n\r\n\r\n key = dayNo, prevDay, restCount\r\n if key in memo:\r\n return memo[key]\r\n\r\n if dayNo == len(days):\r\n return restCount\r\n\r\n gym, contest = d[days[dayNo]]\r\n\r\n x = y = n\r\n\r\n if gym and prevDay != 'g':\r\n # going to gym\r\n x = findMinRest(days, d, dayNo + 1, 'g', restCount, memo)\r\n\r\n if contest and prevDay != 'c':\r\n # going to gym\r\n y = findMinRest(days, d, dayNo + 1, 'c', restCount, memo)\r\n\r\n z = findMinRest(days, d, dayNo + 1, 'r', restCount + 1, memo)\r\n\r\n to_return = min(x, y, z)\r\n memo[key] = to_return\r\n return to_return\r\n\r\n\r\nd = dict()\r\nd[0] = False, False\r\nd[1] = False, True\r\nd[2] = True, False\r\nd[3] = True, True\r\n\r\n\r\nn = int(input())\r\ndays = list(map(int, input().split()))\r\ndayNo = 0\r\nprevDay = 'r'\r\nrestCount = 0\r\nmemo = dict()\r\n\r\nprint(findMinRest(days, d, dayNo, prevDay, restCount, memo))\r\n", "INF=2e32\r\nd=[0,0,0]\r\nfor a in map(int,[*open(0)][1].split()):\r\n if a==0:\r\n d=[min(d)+1,INF,INF]\r\n elif a==1:\r\n d=[min(d)+1,min(d[0],d[2]),INF]\r\n elif a==2:\r\n d=[min(d)+1,INF,min(d[0:2])]\r\n else:\r\n d=[min(d)+1,min(d[0],d[2]),min(d[0:2])]\r\nprint(min(d))", "n = int(input())\r\nl = list(map(int,input().split()))\r\nlast = 0\r\nans = 0\r\nfor i in range(n):\r\n if l[i] == 0:\r\n last = 0\r\n ans+=1\r\n if l[i] == 1:\r\n if last == 1:\r\n ans+=1\r\n last = 0\r\n else:\r\n last = 1\r\n if l[i] == 2:\r\n if last == 2:\r\n ans+=1\r\n last = 0\r\n else:\r\n last = 2\r\n if l[i] == 3:\r\n if last!=0:\r\n last = 3-last\r\nprint(ans)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nans = [[n,n,n] for _ in range(n)]\r\n\r\nans[0][2] = 1 \r\nans[0][0] = 0 if a[0] in [1,3] else n\r\nans[0][1] = 0 if a[0] in [2,3] else n\r\n\r\nfor i in range(1,n):\r\n if a[i] == 0:\r\n pass\r\n elif a[i] == 1:\r\n ans[i][0] = min(ans[i-1][1],ans[i-1][2])\r\n elif a[i] == 2:\r\n ans[i][1] = min(ans[i-1][0],ans[i-1][2])\r\n elif a[i] == 3: \r\n ans[i][0] = min(ans[i-1][1],ans[i-1][2]) \r\n ans[i][1] = min(ans[i-1][0],ans[i-1][2])\r\n\r\n ans[i][2] = min(ans[i-1]) + 1\r\n\r\nprint(min(ans[n-1]),end=\"\")\r\n", "n = int(input())\na = [i for i in input().split(' ')]\ndp = []\nfor i in range(n + 1):\n dp.append([])\n for _ in range(3):\n dp[i].append(0)\n\nfor i in range(1, n + 1):\n dp[i][0] = max(dp[i - 1])\n if a[i - 1] == '1' or a[i - 1] == '3':\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2])\n dp[i][1] += 1\n else:\n dp[i][1] = max(dp[i - 1])\n if a[i - 1] == '2' or a[i - 1] == '3':\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1])\n dp[i][2] += 1\n else:\n dp[i][2] = max(dp[i - 1])\n # print(dp)\nprint(n - max(dp[n]))\n", "n = int(input())\r\ninMas = list(map(int, input().split()))\r\ncounter = 0\r\nif inMas[0] > 0:\r\n if inMas[0] == 3:\r\n inMas[0] = 0\r\n counter += 1\r\nfor i in range(1, n):\r\n if inMas[i] == 1:\r\n if inMas[i-1] % 2 == 0:\r\n counter += 1\r\n if inMas[i-1] == 1:\r\n inMas[i] = 0\r\n if inMas[i] == 2:\r\n if inMas[i-1] // 2 == 0:\r\n counter += 1\r\n if inMas[i-1] == 2:\r\n inMas[i] = 0\r\n if inMas[i] == 3:\r\n counter += 1\r\n if inMas[i-1] == 0:\r\n inMas[i] = 0\r\n else:\r\n inMas[i] -= inMas[i-1]\r\nprint(n - counter)\r\n", "import sys\r\nn = int(sys.stdin.readline())\r\na = list(map(int,sys.stdin.readline().split()))\r\ngrid = [-1]*n\r\ngrid[0] = a[0]\r\nfor i in range(1,n):\r\n temp = a[i]\r\n res = -1\r\n if temp == 3:\r\n if grid[i-1]==3:\r\n res = 3\r\n else:\r\n res = 3-grid[i-1]\r\n elif temp == 1 or temp == 2:\r\n if grid[i-1] == temp:\r\n res = 0\r\n else:\r\n res = temp\r\n else:\r\n res = 0\r\n grid[i] = res\r\nans = 0\r\nfor i in grid:\r\n if i == 0:\r\n ans+=1\r\nprint(ans)\r\n\r\n\r\n", "n = int(input())\r\ndhoni = list(map(int, input().split()))\r\n \r\nrest = 0\r\nfor i in range(n):\r\n if(dhoni[i]==0):\r\n rest+=1\r\n elif(dhoni[i]==1):\r\n if(i-1>=0 and dhoni[i-1]==1):\r\n rest+=1\r\n dhoni[i] = 0\r\n elif(dhoni[i]==2):\r\n if(i-1>=0 and dhoni[i-1]==2):\r\n rest+=1\r\n dhoni[i] = 0\r\n elif(dhoni[i]==3):\r\n \"\"\"if(i-1>=0 and dhoni[i-1]==2 and i+1<0 and dhoni[i+1]==1):\r\n rest+=1\r\n elif(i-1>=0 and dhoni[i-1]==1 and i+1<0 and dhoni[i+1]==2):\r\n rest+=1\"\"\"\r\n if(i-1>=0 and dhoni[i-1]==1):\r\n dhoni[i]=2\r\n elif(i-1>=0 and dhoni[i-1]==2):\r\n dhoni[i]=1\r\n \r\nprint(rest)", "n = int(input())\r\na = map(int, input().split())\r\nlast_act = 0\r\ncnt = 0\r\nfor act in a:\r\n if act == 0:\r\n last_act = 0\r\n cnt += 1\r\n elif act == 3:\r\n if last_act:\r\n last_act = 1 if last_act == 2 else 2\r\n elif act in [1, 2]:\r\n if last_act == act:\r\n cnt += 1\r\n last_act = 0\r\n else:\r\n last_act = act\r\n\r\nprint(cnt)\r\n\r\n", "# 698A\r\n\r\n\"\"\"\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nr = 0\r\ni = 0\r\nwhile i < n:\r\n if a[i] == 0:\r\n r += 1\r\n i += 1\r\n elif a[i] != 3:\r\n a1 = a[i]\r\n c = 0\r\n i += 1\r\n while (i < n) and (a[i] == 3):\r\n c += 1\r\n i += 1\r\n if i < n:\r\n if (a1 == a[i]) and (c % 2 == 0):\r\n r += 1\r\n i += 1\r\n elif (a1 != a[i]) and (c % 2 != 0):\r\n r += 1\r\n i += 1\r\nprint(r)\r\n\"\"\"\r\n\r\nn = int(input())\r\nl = list(map(int,input().split()))\r\nr = 0\r\nx = 0\r\nfor i in range(len(l)):\r\n if l[i] == 0 or l[i] == x:\r\n r += 1\r\n x = 0\r\n elif l[i] == 3:\r\n if (x != 0):\r\n x = 3 - x\r\n else:\r\n x = l[i]\r\nprint(r)\r\n", "n=int(input())\r\narr=[int(i) for i in input().split()]\r\n\r\ndp=[[-1]*3 for i in range(n+1)]\r\n\r\n# for prev contest=1 gym=2 nothing=0\r\n\r\ndef dfs(i=0,prev=0):\r\n if i==n:\r\n return 0\r\n a0=dp[i+1][0] if dp[i+1][0]!=-1 else dfs(i+1,0)\r\n dp[i+1][0]=a0\r\n a1=dp[i+1][1] if dp[i+1][1]!=-1 else dfs(i+1,1)\r\n dp[i+1][1]=a1\r\n a2=dp[i+1][2] if dp[i+1][2]!=-1 else dfs(i+1,2)\r\n dp[i+1][2]=a2\r\n if arr[i]==0:\r\n return 1+a0\r\n if arr[i]==1:\r\n if prev==1:\r\n return 1+a0\r\n return min(a1,1+a0)\r\n if arr[i]==2:\r\n if prev==2:\r\n return 1+a0\r\n return min(a2,1+a0)\r\n if prev==1:\r\n return min(a2,1+a0)\r\n if prev==2:\r\n return min(a1,1+a0)\r\n return min(a1,a2,1+a0)\r\n \r\nprint(dfs())", "n = int(input())\r\narr = list(map(int, input().split()))\r\ndp = []\r\nfor i in range(n):\r\n dp.append([0] * 3)\r\nif arr[0] == 1:\r\n dp[0][1] = 1\r\nelif arr[0] == 2:\r\n dp[0][2] = 1\r\nelif arr[0] == 3:\r\n dp[0][1] = 1\r\n dp[0][2] = 1\r\narr.pop(0)\r\nfor i, v in enumerate(arr, 1):\r\n dp[i][0] = max(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2])\r\n if v == 0:\r\n dp[i][1] = dp[i - 1][1]\r\n dp[i][2] = dp[i - 1][2]\r\n elif v == 1:\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1\r\n #dp[i][2] = dp[i - 1][2]\r\n dp[i][2] = 0\r\n elif v == 2:\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1\r\n #dp[i][1] = dp[i - 1][1]\r\n dp[i][1] = 0\r\n else:\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1\r\nprint(n - max(dp[-1]))\r\n# [] Rest\r\n# [] Contest\r\n# [] Gym\r\n# Something like this. Read the problem again and come up with a bulletproof plan before coding.\r\n# Do the same thing like planned and imagine a case -1 which is equal to 0, 0, 0\r\n\r\n# AAAAAAAAAAAAARRRRRRRRRRRRRRRRRRGGGGGGGGGGGGGGGGGGGGHHHHHHHHHHHHHHHHHHHHh", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndp = [[0]*n for i in range(2)] #top = gym, bottom = contest, 1 = closed/rest\r\nif a[0] == 0:\r\n dp[0][0] = 1\r\n dp[1][0] = 1\r\n \r\nelif a[0] == 1:\r\n dp[0][0] = 1\r\n\r\nelif a[0] == 2:\r\n dp[1][0] = 1\r\n\r\nfor i in range(1, n):\r\n if a[i] == 0:\r\n dp[0][i] = 1+min(dp[0][i-1], dp[1][i-1])\r\n dp[1][i] = 1+min(dp[0][i-1], dp[1][i-1])\r\n \r\n elif a[i] == 1:\r\n dp[0][i] = 1+min(dp[0][i-1], dp[1][i-1])\r\n dp[1][i] = dp[0][i-1]\r\n \r\n elif a[i] == 2:\r\n dp[0][i] = dp[1][i-1]\r\n dp[1][i] = 1+min(dp[0][i-1], dp[1][i-1])\r\n \r\n else:\r\n dp[0][i] = dp[1][i-1]\r\n dp[1][i] = dp[0][i-1]\r\n \r\nprint(min(dp[0][-1], dp[1][-1]))", "def days(n, activities):\r\n k = 3 \r\n INF = 100 \r\n dp = [[0 for _ in range(n + 1)] for _ in range(k)]\r\n for i in range(1, n + 1):\r\n a = activities[i - 1]\r\n dp[0][i] = 1 + min(dp[0][i - 1], min(dp[1][i - 1], dp[2][i - 1]))\r\n dp[1][i] = INF if a == 0 or a == 1 else min(dp[0][i - 1], dp[2][i - 1])\r\n dp[2][i] = INF if a == 0 or a == 2 else min(dp[0][i - 1], dp[1][i - 1])\r\n return min(dp[0][n], min(dp[1][n], dp[2][n]))\r\nn = int(input())\r\nact = list(map(int, input().split()))\r\nres = days(n, act)\r\nprint(res)# 1690914822.0124366", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\ninput=sys.stdin.readline\r\nn=int(input())\r\nl=[int(i) for i in input().split()]\r\nc=0\r\ndp=[]\r\nfor i in range(n+1):\r\n l1=[0,0]\r\n dp.append(l1)\r\nfor i in range(n):\r\n if(l[i]==0):\r\n dp[i+1][0]=min(dp[i][0]+1,dp[i][1]+1)\r\n dp[i+1][1]=min(dp[i][0]+1,dp[i][1]+1)\r\n elif(l[i]==1):\r\n dp[i+1][0]=min(dp[i][0]+1,dp[i][1]+1)\r\n dp[i+1][1]=min(dp[i][0],dp[i][1]+1)\r\n elif(l[i]==2):\r\n dp[i+1][0]=min(dp[i][0]+1,dp[i][1])\r\n dp[i+1][1]=min(dp[i][0]+1,dp[i][1]+1)\r\n else:\r\n dp[i+1][0]=min(dp[i][0]+1,dp[i][1])\r\n dp[i+1][1]=min(dp[i][0],dp[i][1]+1)\r\nprint(min(dp[n][0],dp[n][1]))", "mod = 1000000007\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nls = lambda : list(input())\r\nn = ii()\r\nl = il()\r\ndpc = [0]*(n+1)\r\ndpg = [0]*(n+1)\r\nfor i in range(1, n+1):\r\n if l[i-1] == 0:\r\n dpc[i] = max(dpc[i-1], dpg[i-1])\r\n dpg[i] = max(dpc[i-1], dpg[i-1])\r\n if l[i-1] == 1:\r\n dpc[i] = dpg[i-1]+1\r\n dpg[i] = max(dpc[i-1], dpg[i-1])\r\n if l[i-1] == 2:\r\n dpg[i] = dpc[i-1] + 1\r\n dpc[i] = max(dpc[i-1], dpg[i-1])\r\n if l[i-1]==3:\r\n dpg[i] = dpc[i-1]+1\r\n dpc[i] = dpg[i-1]+1\r\n\r\nprint(n-max(dpc[n], dpg[n]))", "x=int(input())\na=list(map(int,input().split()))\nk=0\nif a[0]==0:\n k+=1\n \n \nfor i in range(1,x):\n if a[i]==0 or (a[i]==a[i-1] and a[i]!=3):\n k+=1\n a[i]=0\n elif a[i]==3:\n if a[i-1]==1:\n a[i]=2\n elif a[i-1]==2:\n a[i]=1\n \nprint(k) \n \t \t\t \t \t\t\t \t \t\t\t\t \t\t\t\t \t", "import sys\r\nn = int(input())\r\nl = [int(x) for x in input().split()]\r\ndp = [[sys.maxsize for j in range(3)] for i in range(n+1)]\r\ndp[0][0] = 0\r\n# print(dp)\r\nfor i in range(1,n+1,1):\r\n dp[i][0] = 1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n if l[i-1]==1 or l[i-1]==3:\r\n dp[i][1] = min(dp[i-1][0],dp[i-1][2])\r\n if l[i-1]==2 or l[i-1]==3:\r\n dp[i][2] = min(dp[i-1][0],dp[i-1][1])\r\n # print(dp[i])\r\nprint(min(dp[-1]))\r\n", "n = int(input())\r\ndays = [0] + [int(c) for c in input().split()]\r\n\r\ndp = [[float('infinity')] * 3 for _ in range(n+1)]\r\n\r\ndp[0] = [0] * 3\r\nfor i in range(1, n+1):\r\n cur = days[i]\r\n dp[i][0] = 1 + min(dp[i-1])\r\n if cur == 2 or cur == 3:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n if cur == 1 or cur == 3:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n\r\n\r\nprint(min(dp[n]))\r\n", "import math\r\n\r\n# Press the green button in the gutter to run the script.\r\nif __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n f0, f1, f2 = 0, 0, 0\r\n for _, v in enumerate(a):\r\n g1, g2 = math.inf, math.inf\r\n if v & 1:\r\n g1 = min(f0, f2)\r\n if v >> 1:\r\n g2 = min(f0, f1)\r\n f0 = min(f0, f1, f2) + 1\r\n f1, f2 = g1, g2\r\n print(min(f0, f1, f2))", "import sys, collections, bisect, heapq, functools, itertools, math\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\nans = 0\r\nfor i in range(n):\r\n if a[i] == 0:\r\n ans += 1\r\n elif a[i] == 1 or a[i] == 2:\r\n if i > 0 and a[i - 1] == a[i]:\r\n ans += 1\r\n a[i] = 0\r\n elif a[i] == 3:\r\n if i > 0:\r\n if a[i - 1] == 1: a[i] = 2\r\n if a[i - 1] == 2: a[i] = 1\r\nprint(ans)", "from sys import stdin\r\n\r\n\r\ndef solve():\r\n n = int(stdin.readline())\r\n A = [int(x) for x in stdin.readline().split()]\r\n\r\n dp = [[0] * 3 for _ in range(n + 1)]\r\n\r\n for i, a in enumerate(A, 1):\r\n dp[i][0] = max(dp[i - 1])\r\n\r\n if a in (1, 3):\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1\r\n\r\n if a in (2, 3):\r\n dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1\r\n\r\n print(n - max(dp[n]))\r\n\r\n\r\nsolve()\r\n", "#!/usr/bin/env python3\n# vim: set fileencoding=utf-8\n\n# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation\n\n\n\"\"\"Module docstring\n\"\"\"\n\nimport functools\nimport heapq\nimport itertools\nimport logging\nimport math\nimport random\nimport string\nimport sys\nfrom argparse import ArgumentParser\nfrom collections import defaultdict, deque\nfrom copy import deepcopy\nfrom typing import Dict, List, Optional, Set, Tuple\n\n\ndef solve(values: List[int], n: int) -> Optional[int]:\n dp = [0] * (n + 1)\n for i, v in enumerate(values):\n if v == 0:\n # nothing open\n continue\n if v == 1 and dp[i] != 1:\n # contest\n dp[i + 1] |= 1\n if v == 2 and dp[i] != 2:\n # gym\n dp[i + 1] |= 2\n if v == 3:\n # both\n if dp[i] == 1:\n dp[i + 1] = 2\n elif dp[i] == 2:\n dp[i + 1] = 1\n else:\n dp[i + 1] = 3\n # to remove dp[0]\n return dp.count(0) - 1\n\n\ndef do_job():\n \"Do the work\"\n LOG.debug(\"Start working\")\n N = int(input())\n values = map(int, input().split())\n result = solve(values, N)\n print(result)\n sys.stdout.flush()\n sys.stderr.flush()\n\n\ndef print_output(testcase: int, result) -> None:\n \"Formats and print result\"\n if result is None:\n result = \"IMPOSSIBLE\"\n print(\"Case #{}: {}\".format(testcase + 1, result))\n # 6 digits float precision {:.6f} (6 is the default value)\n # print(\"Case #{}: {:f}\".format(testcase + 1, result))\n\n\ndef configure_log(log_file: Optional[str] = None) -> None:\n \"Configure the log output\"\n log_formatter = logging.Formatter(\n \"%(asctime)s - %(filename)s:%(lineno)d - \" \"%(levelname)s - %(message)s\"\n )\n if log_file:\n handler = logging.FileHandler(filename=log_file)\n else:\n handler = logging.StreamHandler(sys.stdout)\n handler.setFormatter(log_formatter)\n LOG.addHandler(handler)\n\n\nLOG = None\n# for interactive call: do not add multiple times the handler\nif not LOG:\n LOG = logging.getLogger(\"template\")\n configure_log()\n\n\ndef main(argv=None):\n \"Program wrapper.\"\n if argv is None:\n argv = sys.argv[1:]\n parser = ArgumentParser()\n parser.add_argument(\n \"-v\",\n \"--verbose\",\n dest=\"verbose\",\n action=\"store_true\",\n default=False,\n help=\"run as verbose mode\",\n )\n args = parser.parse_args(argv)\n if args.verbose:\n LOG.setLevel(logging.DEBUG)\n do_job()\n return 0\n\n\nif __name__ == \"__main__\":\n sys.exit(main())\n\n\nclass memoized:\n \"\"\"Decorator that caches a function's return value each time it is called.\n If called later with the same arguments, the cached value is returned, and\n not re-evaluated.\n \"\"\"\n\n def __init__(self, func):\n self.func = func\n self.cache = {}\n\n def __call__(self, *args):\n try:\n return self.cache[args]\n except KeyError:\n value = self.func(*args)\n self.cache[args] = value\n return value\n except TypeError:\n # uncachable -- for instance, passing a list as an argument.\n # Better to not cache than to blow up entirely.\n return self.func(*args)\n\n def __repr__(self):\n \"\"\"Return the function's docstring.\"\"\"\n return self.func.__doc__\n\n def __get__(self, obj, objtype):\n \"\"\"Support instance methods.\"\"\"\n return functools.partial(self.__call__, obj)\n", "n=int(input())\r\na=[int(x) for x in input().split()]\r\ninf=99999999999999999\r\ndp=[[inf]*3 for _ in range(n+1)]\r\ndp[1][0]=1 # take rest\r\nif a[0]==2 or a[0]==3:\r\n dp[1][1]=0 # go to gym\r\nif a[0]==1 or a[0]==3:\r\n dp[1][2]=0 # give contest\r\n\r\nfor i in range(2,n+1):\r\n dp[i][0]=1+min(dp[i-1][0],dp[i-1][1],dp[i-1][2])\r\n if a[i-1]==2 or a[i-1]==3:\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n if a[i-1]==1 or a[i-1]==3:\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n# print(dp)\r\nprint(min(dp[n][0],dp[n][1],dp[n][2]))", "from collections import *\nimport sys \n\n# \"\". join(strings) \n \ndef ri():\n return int(input())\n \ndef rl():\n return list(map(int, input().split()))\n\nn=ri()\n\na=rl()\n\ndR=[200]*n #200 is like infinity because >100\ndC=[200]*n\ndG=[200]*n\n\n\n#initialisation\ndR[0]=1\nif a[0]!=2 and a[0]!=0:\n\tdC[0]=0\nif a[0]!=1 and a[0]!=0:\n\tdG[0]=0\n\n\nfor i in range(1,n):\n\tdR[i] = 1 + min(dR[i-1],dC[i-1],dG[i-1])\n\tif a[i]!=2 and a[i]!=0:\n\t\tdC[i] = min(dR[i-1],dG[i-1])\n\tif a[i]!=1 and a[i]!=0:\n\t\tdG[i] = min(dR[i-1],dC[i-1])\n\t# print(dR[i], dC[i], dG[i])\n\nprint(min(dR[n-1], dG[n-1], dC[n-1]))\n\n\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Aug 4 14:25:34 2022\r\n\r\n@author: Conor\r\n\r\nCFSheet B Problem 42 - CF699-DIV2C\r\n\"\"\"\r\n\r\nn = int(input())\r\ndp = [[n+1]*3 for _ in range(n)]\r\n\"Min given you've 1. rested, competed, sported\"\r\n\r\nar = list(map(int,input().split()))\r\ndp[0][0] = 1\r\nif ar[0] == 1:\r\n dp[0][1] = 0\r\nelif ar[0] == 2:\r\n dp[0][2] = 0\r\nelif ar[0] == 3:\r\n dp[0][1] = 0\r\n dp[0][2] = 0\r\n\r\nfor i in range(1,n):\r\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\r\n if ar[i] == 1:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n elif ar[i] == 2:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n elif ar[i] == 3:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n\r\nprint(min(dp[-1]))", "# cook your dish here\r\n\r\n\r\n\r\nn = int(input())\r\ndp = [0, 0, 0]\r\nl = list(map(int,input().split()))\r\nfor i in l:\r\n tmp=dp[:]\r\n dp[0]= min(tmp)+1\r\n dp[1]= min(tmp[0], tmp[2]) if i==1 or i==3 else 10e6\r\n dp[2]= min(tmp[0], tmp[1]) if i==2 or i==3 else 10e6\r\nprint(min(dp))", "def main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n answer_arr = [(0, 0, 0)]\r\n for i in range(n):\r\n if arr[i] == 0:\r\n temp_tuple = (\r\n min(answer_arr[-1][0], answer_arr[-1][1], answer_arr[-1][2]) + 1,\r\n answer_arr[-1][1] + 1,\r\n answer_arr[-1][2] + 1,\r\n )\r\n elif arr[i] == 1:\r\n temp_tuple = (\r\n min(answer_arr[-1][0], answer_arr[-1][1], answer_arr[-1][2]) + 1,\r\n min(answer_arr[-1][0], answer_arr[-1][2]),\r\n min(answer_arr[-1][0], answer_arr[-1][1], answer_arr[-1][2]) + 1,\r\n )\r\n elif arr[i] == 2:\r\n temp_tuple = (\r\n min(answer_arr[-1][0], answer_arr[-1][1], answer_arr[-1][2]) + 1,\r\n min(answer_arr[-1][0], answer_arr[-1][1], answer_arr[-1][2]) + 1,\r\n min(answer_arr[-1][0], answer_arr[-1][1]),\r\n )\r\n else:\r\n temp_tuple = (\r\n min(answer_arr[-1][0], answer_arr[-1][1], answer_arr[-1][2]) + 1,\r\n min(answer_arr[-1][0], answer_arr[-1][2]),\r\n min(answer_arr[-1][0], answer_arr[-1][1]),\r\n )\r\n\r\n answer_arr.append(temp_tuple)\r\n\r\n print(min(answer_arr[-1]))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "day=int(input())\r\nprev=0\r\ncount=0\r\narr=[int(x) for x in input().split()]\r\nfor index,val in enumerate(arr):\r\n if val==prev or val==0:\r\n count+=1\r\n if val==3 or prev==val:\r\n if val==3 and prev==0 and index+1<len(arr):\r\n prev=val-arr[index+1]\r\n else:\r\n prev=val-prev\r\n else:\r\n prev=val\r\n \r\nprint(count)", "n = int(input())\r\narr = list(map(int, input().split()))\r\nres, prev = 0, 0\r\nfor x in arr:\r\n\tif x == prev or x == 0:\r\n\t\tprev = 0\r\n\t\tres += 1\r\n\telif x == 1 or x == 2:\r\n\t\tprev = x\r\n\telif prev > 0 and x == 3:\r\n\t\tprev = 3 - prev\r\nprint(res)\r\n", "n=int(input())\r\na=[*map(int,input().split())]\r\nk=0\r\nx=0\r\ng=0\r\nf=-1\r\nif a[0]==3:\r\n while x<n-1 and a[x]!=1 and a[x]!=2:x+=1\r\n if x==n-1 and a[x]!=1 and a[x]!=2:\r\n a[0]=1;g=1\r\n else:\r\n if -~-g:\r\n if 0==x%2:a[0]=a[x]\r\n else:a[0]=[0,2,1][a[x]]\r\ng=x=0\r\nfor i in range(n-1):\r\n if a[i]!=a[i+1]:\r\n if a[i+1]==3 and a[i]==0:\r\n while i+x<n-1 and a[i+x]!=1 and a[x+i]!=2:x+=1\r\n if x+i==n-1 and a[x+i]!=1 and a[x+i]!=2:a[i+1]=1;g=1\r\n else:\r\n if -~-g:\r\n if (i+1)%2==(i+x)%2:a[i+1]=a[i+x]\r\n else:a[i+1]=[0,2,1][a[i+x]]\r\n g=0\r\n x=0\r\n if a[i+1]==3:\r\n a[i+1]=[0,2,1][a[i]]\r\n if a[i+1]==0:\r\n k+=1\r\n else:\r\n if a[i]==a[i+1]:\r\n a[i+1]=0\r\n k+=1\r\nif a[0]==0:k+=1\r\nprint(k)\r\n", "z,zz=input,lambda:list(map(int,z().split()))\r\nfast=lambda:stdin.readline().strip()\r\nzzz=lambda:[int(i) for i in stdin.readline().split()]\r\nszz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())\r\nfrom string import *\r\nfrom re import *\r\nfrom collections import *\r\nfrom queue import *\r\nfrom sys import *\r\nfrom collections import *\r\nfrom math import *\r\nfrom heapq import *\r\nfrom itertools import *\r\nfrom bisect import *\r\nfrom collections import Counter as cc\r\nfrom math import factorial as f\r\nfrom bisect import bisect as bs\r\nfrom bisect import bisect_left as bsl\r\nfrom itertools import accumulate as ac\r\ndef lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))\r\ndef prime(x):\r\n p=ceil(x**.5)+1\r\n for i in range(2,p):\r\n if (x%i==0 and x!=2) or x==0:return 0\r\n return 1\r\ndef dfs(u,visit,graph):\r\n visit[u]=True\r\n for i in graph[u]:\r\n if not visit[i]:\r\n dfs(i,visit,graph)\r\n\r\n###########################---Test-Case---#################################\r\n\"\"\"\r\n\r\n\r\n\r\n\"\"\"\r\n###########################---START-CODING---##############################\r\n\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nINF = float('inf')\r\ndp = [[INF] * 3 for i in range(n + 1)]\r\ndp[0][0] = 0\r\n\r\nfor i in range(n):\r\n k = a[i]\r\n dp[i + 1][0] = min(dp[i][0], dp[i][1], dp[i][2]) + 1\r\n if k == 1:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n elif k == 2:\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1])\r\n elif k == 3:\r\n dp[i + 1][1] = min(dp[i][0], dp[i][2])\r\n dp[i + 1][2] = min(dp[i][0], dp[i][1])\r\n\r\nprint(min(dp[n]))\r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n", "# min number of days => max busy days\n\n# if only contest is open: do nothing/do contest/\n# if only gym is open: do nothing/do gym\n# if both are open, do nothing/do gym/ do contest\n\n# maximize the days where smth was done\n\n# dp [i][j] => j = 1,2,3\n# 1 : he did nothing\n# 2: he went to the gym\n# 3: he went to the contest\n\nn = int(input())\nnums = [int(num) for num in input().split(\" \")]\ndp = [[0]* 3 for _ in range(n+1)]\n\n# dp[i][j] = maximum number of days where he wont rest\n# if i days passed and j equals to\n# 0: rest\n# 1: contest\n# 2: gym\n# on the i-th day\nres = 0\nfor i in range(1, n+1):\n dp[i][0] = max(dp[i-1][0], dp[i-1][1], dp[i-1][2])\n if nums[i-1] == 1: # contest\n dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + 1\n elif nums[i-1] == 2: # gym\n dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + 1\n elif nums[i-1] == 3: # both\n dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + 1\n dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + 1\n res = max(max(dp[i]), res)\n# print(dp)\nprint(n-res)\n# if day == 1\n# just get the max of all the prev days 1,2,3\n\n# if day == 2:\n# do contest => get max of 1, 3\n# do nothing => get max of 1,2,3\n\n# if day = 3:\n# do gym => get max of (1, 3, and the day before that 2)\n# do nothing => get max of all\n\n# if day = 4:\n# do gym \n# do contest\n# do nothing\n", "n = int(input())\r\npossible_actions = [int(d) for d in input().split()]\r\n\r\nGYM_OPEN = 0b10\r\nCONTEST_AVAIL = 0b01\r\n\r\nGYM = 0\r\nCONTEST = 1\r\nREST = 2\r\n\r\nactions = {(-1, 0)}\r\n\r\nfor pa in possible_actions:\r\n last_actions = set(actions)\r\n actions = set()\r\n\r\n for a, r in last_actions:\r\n if pa & GYM_OPEN and a != GYM:\r\n actions.add((GYM, r))\r\n if pa & CONTEST_AVAIL and a != CONTEST:\r\n actions.add((CONTEST, r))\r\n actions.add((REST, r + 1))\r\n\r\nprint(min(actions, key=lambda t: t[1])[1])", "a=int(input())\r\ns=input()\r\nA=[0,0,0]\r\nfor i in range(0,2*a-1,2):A=[[max(A),0,0],[max(A),max(A[0],A[2])+1,0],[max(A),0,max(A[0],A[1])+1],[max(A),max(A[0],A[2])+1,max(A[0],A[1])+1]][int(s[i])]\r\nprint(a-max(A))\r\n", "from sys import stdin\nfrom collections import defaultdict\nn = int(stdin.readline())\ndays = [int(i) for i in stdin.readline().split(' ')]\n\ndp = defaultdict(lambda: 101) # Effectively sets non-initialized items to infinity.\ndp[(-1, \"r\")] = 0 # Base case.\nfor i in range(0, n):\n dp[(i, \"r\")] = 1+min(dp[(i-1, \"r\")], dp[(i-1, \"g\")], dp[(i-1, \"c\")])\n if days[i] >= 2:\n dp[(i, \"g\")] = min(dp[(i-1, \"r\")], dp[(i-1, \"c\")])\n if days[i] % 2 == 1:\n dp[(i, \"c\")] = min(dp[(i-1, \"r\")], dp[(i-1, \"g\")])\n\nprint(min(dp[(n-1, \"r\")], dp[(n-1, \"g\")], dp[(n-1, \"c\")]))\n# dp[(i, \"x\")] represents the minimum number of days you've rested at the end of the Ith day, where \"x\" is what you did that day.\n \t\t \t\t\t \t\t \t\t \t \t\t\t\t\t\t\t", "import sys\r\n\r\n\r\ndef next_activity(days, index, length):\r\n count_all = 0\r\n last_day = None\r\n for j in range(index + 1, length):\r\n if int(days[j]) == 3:\r\n count_all += 1\r\n else:\r\n last_day = int(days[j])\r\n return last_day, count_all\r\n return last_day, count_all\r\n\r\n\r\ninput_file = sys.stdin.read(-1).replace(\"\\r\\n\", \"\\r\")\r\ninput_file = input_file.split()\r\n\r\nnum_holidays = int(input_file[0])\r\ndel input_file[0]\r\n\r\nrest_days = 0\r\nlast_activity = None\r\nfor i in range(num_holidays):\r\n day_type = int(input_file[i])\r\n if day_type == 0:\r\n rest_days += 1\r\n last_activity = 0\r\n elif day_type == 1:\r\n if last_activity != 1:\r\n last_activity = 1\r\n else:\r\n last_activity = 0\r\n rest_days += 1\r\n elif day_type == 2:\r\n if last_activity != 2:\r\n last_activity = 2\r\n else:\r\n last_activity = 0\r\n rest_days += 1\r\n elif day_type == 3:\r\n if last_activity == 1:\r\n last_activity = 2\r\n elif last_activity == 2:\r\n last_activity = 1\r\n else:\r\n if i == num_holidays - 1:\r\n last_activity = 1\r\n else:\r\n end_day, count = next_activity(input_file, i, num_holidays)\r\n if count % 2 == 0:\r\n if end_day == 1:\r\n last_activity = 2\r\n else:\r\n last_activity = 1\r\n else:\r\n if end_day == 1:\r\n last_activity = 1\r\n else:\r\n last_activity = 2\r\nprint(rest_days)\r\n", "input()\r\nB = 10000\r\ns = [0, B, B]\r\nfor x in map(int, input().split()):\r\n\ts = [min(s) + 1, min(s[0::2]) if x & 1 else B, min(s[:2]) if x & 2 else B]\r\nprint(min(s))\r\n", "n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\ndp = [[0] * 3 for _ in range(n)]\r\n\r\nif a[0] == 1 or a[0] == 3:\r\n dp[0][1] = 1\r\nif a[0] == 2 or a[0] == 3:\r\n dp[0][2] = 1\r\n\r\nfor i in range(1, n):\r\n t = max(dp[i-1])\r\n contest = max(dp[i-1][0], dp[i-1][2])\r\n gym = max(dp[i-1][0], dp[i-1][1])\r\n if a[i] == 0:\r\n dp[i] = [t, t, t]\r\n elif a[i] == 1:\r\n dp[i] = [t, contest+1, t]\r\n elif a[i] == 2:\r\n dp[i] = [t, t, gym+1]\r\n elif a[i] == 3:\r\n dp[i] = [t, contest+1, gym+1]\r\nprint(n - max(dp[n-1]))\r\n\r\n", "n = int(input())\r\na = [int(x) for x in input().split()] #r->0, c->1, g->2\r\ndp =[[-1 for _ in range(n)] for _ in range(3)]\r\ndef solve(prev, i):\r\n if i == n:\r\n return 0\r\n if dp[prev][i]!=-1:\r\n return dp[prev][i]\r\n if a[i] == 0:\r\n dp[prev][i] = (1+solve(0, i+1))\r\n elif a[i] == 1:\r\n if prev == 1:\r\n dp[prev][i] = 1+solve(0, i+1)\r\n else:\r\n dp[prev][i] = solve(1, i+1)\r\n elif a[i] == 2:\r\n if prev == 2:\r\n dp[prev][i] = 1+solve(0, i+1)\r\n else:\r\n dp[prev][i] = solve(2, i+1)\r\n else:\r\n if prev == 1:\r\n dp[prev][i] = solve(2, i+1)\r\n elif prev == 2:\r\n dp[prev][i] = solve(1, i+1)\r\n else:\r\n dp[prev][i] = min(solve(2, i+1), solve(1, i+1))\r\n return dp[prev][i]\r\nprint(solve(0, 0))\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\na.insert(0, 0)\r\np = []\r\nfor i in range(n + 1):\r\n p.append([])\r\n p[i].append(0)\r\n p[i].append(0)\r\nfor i in range(1, n + 1):\r\n if a[i] == 1 or a[i] == 3:\r\n p[i][0] = max(p[i - 1][1] + 1, p[i - 1][0])\r\n else:\r\n p[i][0] = max(p[i - 1][0], p[i - 1][1])\r\n if a[i] == 2 or a[i] == 3:\r\n p[i][1] = max(p[i - 1][0] + 1, p[i - 1][1])\r\n else:\r\n p[i][1] = max(p[i - 1][0], p[i - 1][1])\r\nprint(n - max(p[n][0], p[n][1]))\r\n", "numDays = int(input())\nsched = [int(x) for x in input().split()]\n\nrest = 0\nprev = \"\"\n\nfor i in range(numDays):\n if sched[i] == 0:\n rest += 1\n prev = \"\"\n elif sched[i] == 1:\n if prev == \"c\":\n rest += 1\n prev = \"\"\n else:\n prev = \"c\"\n elif sched[i] == 2:\n if prev == \"g\":\n rest += 1\n prev = \"\"\n else:\n prev = \"g\"\n else:\n if prev == \"g\":\n prev = \"c\"\n elif prev == \"c\":\n prev = \"g\"\n\nprint(rest)\n\n\n\t\t\t\t\t\t \t \t\t\t\t \t \t\t \t\t\t\t \t\t\t", "n = int(input())\r\ninp = list(map(int, input().split()))\r\ndp = []\r\nfor i in range(3):\r\n dp.append([0] * (n + 1))\r\nfor i in range(1, n + 1):\r\n j = inp[i - 1]\r\n dp[0][i] = max(dp[0][i - 1], dp[1][i - 1], dp[2][i - 1])\r\n if j == 1 or j == 3:\r\n dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + 1\r\n if j == 2 or j == 3:\r\n dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + 1\r\nprint(n - max(dp[0][-1], dp[1][-1], dp[2][-1]))", "def schedule(a, l):\r\n if l == -1:\r\n return 'r' if e[a]==0 else 'c' if e[a]==1 else 'g' if e[a]==2 else \\\r\n 'c' if a < len(e)-1 and schedule(a+1, l) != 'c' else 'g'\r\n if e[a] == 0:\r\n return 'r'\r\n elif e[a] == 1 and l != 'c':\r\n return 'c'\r\n elif e[a] == 2 and l != 'g':\r\n return 'g'\r\n elif e[a] == 3:\r\n if l == 'g':\r\n return 'c'\r\n elif l=='c':\r\n return 'g'\r\n else:\r\n return 'r'\r\n\r\n\r\nn = input()\r\ne = list(map(int, input().split()))\r\nans = 0\r\nl = -1\r\nfor i, d in enumerate(e):\r\n a = schedule(i, l)\r\n l = a\r\n if a == 'r':\r\n ans += 1\r\n\r\nprint(ans)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndp = [[0, a[0]] if a[0] != 0 else [1, 0]]\r\n\r\nfor i in range(1, n):\r\n if a[i] == 0:\r\n dp.append([dp[-1][0] + 1, a[i]])\r\n elif a[i] == 3:\r\n if dp[-1][1] == 1:\r\n dp.append([dp[-1][0], 2])\r\n elif dp[-1][1] == 2:\r\n dp.append([dp[-1][0], 1])\r\n else:\r\n dp.append([dp[-1][0], a[i]])\r\n else:\r\n if dp[-1][1] == a[i]:\r\n dp.append([dp[-1][0] + 1, 0])\r\n else:\r\n dp.append([dp[-1][0], a[i]])\r\n\r\n\r\nprint(dp[-1][0])", "from functools import lru_cache\nn, = map(int, input().split())\nA = list(map(int, input().split()))\n\n\n@lru_cache(maxsize=None)\ndef opt(i, gym=False, contest=False):\n if i >= n:\n return 0\n a = A[i]\n\n rest = opt(i+1, False, False) + 1\n do_contest = float(\"inf\") if contest else opt(i+1,False,True)\n do_gym = float(\"inf\") if gym else opt(i+1,True,False)\n\n if a == 0:\n return rest\n elif a == 1:\n return min(\n rest,\n do_contest,\n )\n elif a == 2:\n return min(\n rest,\n do_gym,\n )\n elif a == 3:\n return min(\n rest,\n do_contest,\n do_gym\n )\nprint(opt(0))\n", "def no_of_rest(lst):\r\n \"\"\"given list of choice\"\"\"\r\n n = len(lst)\r\n dp = []\r\n for i in range(3):\r\n dp.append([0] * (n + 1))\r\n for i in range(n-1, -1, -1):\r\n for j in range(0, 3):\r\n choices = []\r\n choices.append(1+dp[0][i+1])\r\n if j != 1 and (lst[i]==1 or lst[i]==3):\r\n choices.append(dp[1][i+1])\r\n if j != 2 and (lst[i]==2 or lst[i]==3):\r\n choices.append(dp[2][i+1])\r\n dp[j][i] = min(choices)\r\n\r\n \r\n return dp[0][0]\r\n \r\n\r\nN = int(input())\r\nlst = [int(x) for x in input().split()]\r\nprint(no_of_rest(lst))", "import sys, collections, bisect, heapq, functools, itertools, math\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\n# ans = 0\r\n# for i in range(n):\r\n# if a[i] == 0:\r\n# ans += 1\r\n# elif a[i] == 1 or a[i] == 2:\r\n# if i > 0 and a[i - 1] == a[i]:\r\n# ans += 1\r\n# a[i] = 0\r\n# elif a[i] == 3:\r\n# if i > 0:\r\n# if a[i - 1] == 1: a[i] = 2\r\n# if a[i - 1] == 2: a[i] = 1\r\n# print(ans)\r\n\r\nf = [0] * 3\r\nfor x in a:\r\n nf = [math.inf] * 3\r\n nf[0] = min(f) + 1\r\n if x == 1 or x == 3:\r\n nf[1] = min(f[0], f[2])\r\n if x == 2 or x == 3:\r\n nf[2] = min(f[0], f[1])\r\n f = nf\r\nprint(min(f))\r\n\r\n# https://blog.csdn.net/weixin_51771856/article/details/123194105", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nif a[0] == 0:\r\n d = [[0, 0, 0]]\r\nelif a[0] == 1:\r\n d = [[0, 1, 0]]\r\nelif a[0] == 2:\r\n d = [[0, 0, 1]]\r\nelse:\r\n d = [[0, 1, 1]]\r\nfor i in range(1, n):\r\n d.append([0, 0, 0])\r\n d[i][0] = max(d[i-1])\r\n if a[i] == 1 or a[i] == 3:\r\n d[i][1] = max(d[i-1][0]+1, d[i-1][2]+1)\r\n if a[i] == 2 or a[i] == 3:\r\n d[i][2] = max(d[i-1][0]+1, d[i-1][1]+1)\r\nm = 0\r\nfor i in range(n):\r\n if max(d[i]) > m:\r\n m = max(d[i])\r\nprint(n-m)", "n = int(input())\r\nd = list(map(int,input().split()))[:n] \r\ndp = [[int(101) for i in range(100)] for j in range(3)]\r\ndp[0][0] = 1\r\nif d[0]==1 or d[0]==3:\r\n dp[1][0] = 0\r\nif d[0]==2 or d[0]==3:\r\n dp[2][0] = 0\r\nfor i in range(1,n):\r\n dp[0][i] = 1+min(dp[0][i-1],dp[1][i-1],dp[2][i-1])\r\n if d[i]==1 or d[i]==3:\r\n dp[1][i] = min(dp[0][i-1],dp[2][i-1]) \r\n if d[i]==2 or d[i]==3:\r\n dp[2][i] = min(dp[0][i-1],dp[1][i-1])\r\nprint(min(dp[0][n-1],dp[1][n-1],dp[2][n-1])) \r\n", "n = int(input())\na = list(map(int, input().split()))\nans = 0\nfor i in range(len(a)):\n if a[i] == 0:\n ans += 1\n elif i != 0 and a[i] == a[i - 1] and a[i] != 3:\n ans += 1\n a[i] = 0\n elif a[i] == 3:\n a[i] -= a[i - 1]\nprint(ans)\n", "\nn = int(input())\nnumbers = list(map(int, input().split(' ')))\n\nmemo = [[0 for _ in range(4)] for _ in range(n)]\n\nfirst = numbers[0]\nif first != 0:\n if first == 3:\n memo[0][1] = 1\n memo[0][2] = 1\n else:\n memo[0][first] = 1\n\nfor i in range(1,n):\n j = numbers[i]\n for k in range(0, i):\n if k == i-1:\n if j == 0 or j == 3:\n memo[i][0] = max(memo[i][0], max(memo[k]))\n if j == 1 or j == 3:\n memo[i][1] = max(memo[i][1], max(memo[k][2], memo[k][0]) + 1)\n if j == 2 or j == 3:\n memo[i][2] = max(memo[i][2], max(memo[k][1], memo[k][0]) + 1)\n else:\n maximum = max(memo[k])\n if j == 0:\n memo[i][0] = maximum\n elif j == 3:\n memo[i][1] = max(memo[i][1], maximum + 1)\n memo[i][2] = max(memo[i][2], maximum + 1)\n else:\n memo[i][j] = max(memo[i][j], maximum + 1)\n\nprint(n-max(memo[n-1]))\n \n ", "from functools import lru_cache\r\nn = int(input())\r\na = list(map(int,input().split()))\r\n\r\n@lru_cache(maxsize=None)\r\ndef r(idx,prev):\r\n if(idx == len(a)):\r\n return 0\r\n if(a[idx] == 0):\r\n return 1 + r(idx + 1,2)\r\n elif(a[idx] == 1 and (prev == 0 or prev == 2)):\r\n return r(idx + 1,1)\r\n elif(a[idx] == 1 and prev == 1):\r\n return 1 + r(idx + 1,2)\r\n elif(a[idx] == 2 and prev == 0):\r\n return 1 + r(idx + 1,2)\r\n elif(a[idx] == 2 and (prev == 1 or prev == 2)):\r\n return r(idx + 1,0)\r\n else:\r\n if(prev == 2):\r\n return min(r(idx + 1,0),r(idx + 1,1))\r\n elif(prev == 1):\r\n return r(idx + 1,0)\r\n else:\r\n return r(idx + 1,1)\r\n\r\nprint(r(0,2))", "memo = {}\n\ndef solveByRec(arr, start, n, prev):\n if start == n: return 0\n\n if (start, prev) in memo: return memo[(start, prev)]\n\n curr = arr[start]\n\n if curr == 0:\n ans = 1+ solveByRec(arr, start+1, n,0)\n memo[(start, prev)] = ans\n return ans\n \n if curr == 1:\n if prev == 1:\n ans = 1+ solveByRec(arr, start+1, n,0)\n memo[(start, prev)] = ans\n return ans\n \n op1 = 1+ solveByRec(arr, start+1, n,0)\n op2 = solveByRec(arr, start+1, n,1)\n\n ans = min(op1, op2)\n memo[(start, prev)] = ans\n return ans\n \n if curr == 2:\n if prev ==2:\n ans = 1+ solveByRec(arr, start+1, n,0)\n memo[(start, prev)] = ans\n return ans\n \n op1 = 1+ solveByRec(arr, start+1, n,0)\n op2 = solveByRec(arr, start+1, n,2)\n\n ans = min(op1, op2)\n memo[(start, prev)] = ans\n return ans\n \n if curr == 3:\n if prev == 2:\n op1 = 1+ solveByRec(arr, start+1, n,0)\n op2 = solveByRec(arr, start+1, n,1)\n\n ans = min(op1, op2)\n memo[(start, prev)] = ans\n return ans\n \n if prev == 1:\n op1 = 1+ solveByRec(arr, start+1, n,0)\n op2 = solveByRec(arr, start+1, n,2)\n\n ans = min(op1, op2)\n memo[(start, prev)] = ans\n return ans\n \n op1 = 1+ solveByRec(arr, start+1, n,0)\n op2 = solveByRec(arr, start+1, n,1)\n op3 = solveByRec(arr, start+1, n,2)\n\n ans = min(op1, op2, op3)\n memo[(start, prev)] = ans\n return ans\n\n\nn = int(input())\narr = list(map(int, input().split()))\n\nprint(solveByRec(arr, 0, n, 0))\n \n\n\n\n", "n = int(input())\r\n\r\ndata = [int(x) for x in input().split()]\r\n\r\nanswers = [[0 for _ in range(3)] for x in range(n + 1)]\r\n\r\nanswers[0] = [0, 0, 0]\r\nfor i in range(1, n + 1):\r\n for j in range(3):\r\n if j == 1 and (data[i - 1] == 1 or data[i - 1] == 3):\r\n answers[i][j] = max(answers[i - 1][0], answers[i - 1][2]) + 1\r\n elif j == 2 and (data[i - 1] == 3 or data[i - 1] == 2):\r\n answers[i][j] = max(answers[i - 1][0], answers[i - 1][1]) + 1\r\n else:\r\n answers[i][j] = max(answers[i - 1][0], answers[i - 1][2], answers[i - 1][1])\r\n\r\nprint(n - max(answers[-1]))\r\n", "t = 1\r\n\r\nfor qwe in range(t):\r\n \r\n # n = int(f.readline())\r\n n = int(input())\r\n \r\n # a = list(map(int, f.readline().split()))\r\n a = list(map(int, input().split()))\r\n \r\n \r\n temp = [0, 0, 0]\r\n \r\n temp.extend(a)\r\n \r\n a = temp\r\n \r\n ans = 0\r\n # Обработать случаи когда n = 1, 2, 3\r\n \r\n for i in range(n+3):\r\n \r\n if a[i] == 0:\r\n ans += 1\r\n a[i] = 0\r\n \r\n elif a[i] == 3:\r\n pass\r\n \r\n elif a[i] == 1:\r\n \r\n if a[i-1] == 0 or a[i-1] == 2:\r\n pass\r\n elif a[i-1] == 1:\r\n ans += 1\r\n a[i] = 0\r\n elif a[i-1] == 3:\r\n\r\n k = 1\r\n ind = i - 1\r\n while a[ind - 1] == 3:\r\n ind -= 1\r\n k += 1\r\n ind -= 1\r\n \r\n if k % 2 == 1:\r\n if a[ind] == 0 or a[ind] == 1:\r\n pass\r\n elif a[ind] == 2:\r\n ans += 1\r\n a[i] = 0\r\n else:\r\n if a[ind] == 0 or a[ind] == 2:\r\n pass\r\n elif a[ind] == 1:\r\n ans += 1\r\n a[i] = 0\r\n \r\n\r\n \r\n elif a[i] == 2:\r\n \r\n if a[i-1] == 0 or a[i-1] == 1:\r\n pass\r\n elif a[i-1] == 2:\r\n ans += 1\r\n a[i] = 0\r\n elif a[i-1] == 3:\r\n \r\n k = 1\r\n ind = i - 1\r\n \r\n # print(a[ind], ind, k)\r\n \r\n while a[ind - 1] == 3:\r\n # print(\"F1\")\r\n # print(a[ind], ind, k)\r\n ind -= 1\r\n k += 1\r\n \r\n ind -= 1\r\n \r\n \r\n if k % 2 == 1:\r\n if a[ind] == 0 or a[ind] == 2:\r\n pass\r\n elif a[ind] == 1:\r\n ans += 1\r\n a[i] = 0\r\n else:\r\n if a[ind] == 0 or a[ind] == 1:\r\n pass\r\n elif a[ind] == 2:\r\n ans += 1\r\n a[i] = 0\r\n \r\n a[ind] = 0\r\n \r\n # print(\"a =\", a[i], \"ans-3 =\", ans - 3)\r\n\r\n print(ans-3)\r\n", "N = int(input())\nA = list(map(int, input().split()))\n\nbef = 0 # 0: rest, 1: c, 2: g, 3: both ok\nans = 0\nfor a in A:\n if bef == 0:\n if a == 0:\n pass\n elif a == 1:\n ans += 1\n bef = 1\n elif a == 2:\n ans += 1\n bef = 2\n elif a == 3:\n ans += 1\n bef = 3\n elif bef == 1:\n if a == 0:\n bef = 0\n elif a == 1:\n bef = 0\n elif a == 2:\n ans += 1\n bef = 2\n elif a == 3:\n ans += 1\n bef = 2\n elif bef == 2:\n if a == 0:\n bef = 0\n elif a == 1:\n ans += 1\n bef = 1\n elif a == 2:\n bef = 0\n elif a == 3:\n ans += 1\n bef = 1\n elif bef == 3:\n if a == 0:\n bef = 0\n elif a == 1:\n ans += 1\n bef = 1\n elif a == 2:\n ans += 1\n bef = 2\n elif a == 3:\n ans += 1\n bef = 3\nprint(N - ans)\n", "'''\r\n@sksshivam007 - Template 1.0\r\n'''\r\nimport sys, re, math\r\nfrom collections import deque, defaultdict, Counter, OrderedDict\r\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians\r\nfrom heapq import heappush, heappop, heapify, nlargest, nsmallest\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef LIST(): return list(map(int, input().split()))\r\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\r\ndef sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx]))\r\ndef sortDictWithVal(passedDic):\r\n temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]\r\n toret = {}\r\n for tup in temp:\r\n toret[tup[0]] = tup[1]\r\n return toret\r\ndef sortDictWithKey(passedDic):\r\n return dict(OrderedDict(sorted(passedDic.items())))\r\nINF = float('inf')\r\nmod = 10 ** 9 + 7\r\n\r\n#1:can do contest only or rest\r\n#0:can do sport only or rest\r\n#2:can do anything on next day\r\n#\r\n# def solve(idx, ans, flag):\r\n# if(idx==n):\r\n# return ans\r\n#\r\n# if(a[idx]==0):\r\n# return solve(idx + 1, ans + 1, 2)\r\n# elif(a[idx]==1):\r\n# if(flag==1 or flag==2):\r\n# return min(solve(idx+ 1, ans + 1, 2), solve(idx+1, ans, 0))\r\n# else:\r\n# return solve(idx + 1, ans + 1, 2)\r\n# elif(a[idx]==2):\r\n# if(flag==0 or flag==2):\r\n# return min(solve(idx+1, ans+1, 2), solve(idx+ 1, ans, 1))\r\n# else:\r\n# return solve(idx + 1, ans + 1, 2)\r\n# else:\r\n# if(flag==2):\r\n# return min(solve(idx+1, ans+1, 2), solve(idx+ 1, ans, 1), solve(idx+1, ans, 2))\r\n# elif(flag==1):\r\n# return min(solve(idx + 1, ans + 1, 2), solve(idx + 1, ans, 0))\r\n# else:\r\n# return min(solve(idx + 1, ans + 1, 2), solve(idx + 1, ans, 1))\r\n\r\n\r\nn = INT()\r\n\r\na = LIST()\r\n\r\ndp = list2d(n, 3, INF)\r\n\r\ndp[0][0] = 1\r\nif(a[0]==1 or a[0]==3):\r\n dp[0][1] = 0\r\nif(a[0]==2 or a[0]==3):\r\n dp[0][2] = 0\r\n\r\nfor i in range(1, n):\r\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\r\n if(a[i]==1 or a[i]==3):\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n if(a[i]==2 or a[i]==3):\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n# print(dp)\r\nprint(min(dp[n-1]))", "# 尽可能构成12121212序列\r\n# 或者是2121212121...序列\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nans = 0\r\ni = 0\r\nwhile i < n:\r\n if a[i] == 0:\r\n ans += 1\r\n i += 1\r\n continue\r\n while i < n and a[i] == 3:\r\n i += 1\r\n if i == n:\r\n break\r\n pre = a[i]\r\n if pre == 0:\r\n continue\r\n i += 1\r\n while i < n and a[i] != 0:\r\n if a[i] == pre:\r\n ans += 1\r\n i += 1\r\n break\r\n pre = 2 if pre == 1 else 1\r\n i += 1\r\nprint(ans)", "import sys\r\nimport math\r\nimport bisect\r\nfrom math import sqrt\r\ndef input(): return sys.stdin.readline().strip()\r\ndef iinput(): return int(input())\r\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \r\nmod = int(1e9)+7\r\n\r\n# res = sys.maxsize\r\n\r\n# def solve(last, ind, rest):\r\n# \tif ind == n:\r\n# \t\tglobal res\r\n# \t\tres = min(res, rest)\r\n# \t\treturn\r\n\r\n# \tif a[ind] == 0:\r\n# \t\tsolve(0, ind+1, rest+1)\t\r\n# \telse:\r\n# \t\tif last == -1 or last == 0:\r\n# \t\t\tif a[ind] == 1 or a[ind] == 2:\r\n# \t\t\t\tsolve(a[ind], ind+1, rest)\r\n# \t\t\telse:\r\n# \t\t\t\tsolve(1, ind+1, rest)\r\n# \t\t\t\tsolve(2, ind+1, rest)\t\r\n\r\n# \t\telif last == 1:\r\n# \t\t\tif a[ind] == 1:\r\n# \t\t\t\tsolve(0, ind+1, rest+1)\r\n# \t\t\telse:\r\n# \t\t\t\tsolve(2, ind+1, rest)\r\n\r\n# \t\telif last == 2:\r\n# \t\t\tif a[ind] == 2:\r\n# \t\t\t\tsolve(0, ind+1, rest+1)\r\n# \t\t\telse:\r\n# \t\t\t\tsolve(1, ind+1, rest)\r\n\r\n\r\nn = iinput()\r\na = get_list()\r\n# solve(-1, 0, 0)\r\n\r\nrest = 0\r\nlast = -1\r\n\r\nfor i in range(n):\r\n\tif a[i] == 0 or a[i] == last:\r\n\t\trest += 1\r\n\t\tlast = 0\r\n\telif a[i] == 3:\r\n\t\tif last == 1:\r\n\t\t\tlast = 2\r\n\t\telif last == 2:\r\n\t\t\tlast = 1\r\n\telse:\r\n\t\tlast = a[i]\r\n\r\nprint(rest)\t\t", "def solve():\r\n n = int(input())\r\n *nums, = map(int, input().split())\r\n dp = [[1 << 60] * 3 for _ in range(n)]\r\n for i in range(n):\r\n if i == 0:\r\n dp[i][0] = 1 \r\n if nums[i] >= 2:\r\n dp[i][1] = 0\r\n if nums[i] == 1 or nums[i] == 3:\r\n dp[i][2] = 0\r\n else:\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n if nums[i] >= 2:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n if nums[i] == 1 or nums[i] == 3:\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n return min(dp[-1])\r\nprint(solve())", "#Anuneet Anand\r\n \r\nn = int(input())\r\nA = list(map(int,input().split()))\r\nc = 0\r\np = -1\r\nfor i in range(n):\r\n\tif A[i]==0:\r\n\t\tc = c + 1\r\n\t\tp = -1\r\n\tif A[i]==1:\r\n\t\tif A[i]==p:\r\n\t\t\tc = c + 1\r\n\t\t\tp = -1\r\n\t\telse:\r\n\t\t\tp = 1\r\n\tif A[i]==2:\r\n\t\tif A[i]==p:\r\n\t\t\tc = c + 1\r\n\t\t\tp = -1\r\n\t\telse:\r\n\t\t\tp = 2\r\n\tif A[i]==3:\r\n\t\tif p == 2:\r\n\t\t\tp = 1\r\n\t\telif p == 1:\r\n\t\t\tp = 2\r\n\t\telif i!=n-1 and A[i+1]==1:\r\n\t\t\tp = 2\r\n\t\telif i!=n-1 and A[i+1]==2:\r\n\t\t\tp = 1\r\n\t\telse:\r\n\t\t\tp = 0\r\nprint(c)", "n=int(input())\r\na=list(map(int,input().split()))\r\ncnt=0\r\nx=0\r\nfor i in range(n):\r\n\tif a[i]!=3:\r\n\t\tx=i\r\n\t\tbreak\r\nfor i in range(x,n):\r\n\tif a[i]==0:\r\n\t\tcnt+=1\r\n\tif i>0 and a[i]==2 and a[i-1]==2:\r\n\t\ta[i]=0\r\n\t\tcnt+=1\r\n\tif i>0 and a[i]==1 and a[i-1]==1:\r\n\t\ta[i]=0\r\n\t\tcnt+=1\r\n\tif a[i]==3 and a[i-1]==1:\r\n\t\ta[i]=2\r\n\tif a[i]==3 and a[i-1]==2:\r\n\t\ta[i]=1\r\nprint(cnt)\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\nans = 1 if arr[0]==0 else 0\r\n\r\nfor i in range(1, n):\r\n if arr[i]==0:\r\n ans+=1\r\n elif arr[i]==3:\r\n if arr[i-1]==1:\r\n arr[i] = 2\r\n elif arr[i-1]==2:\r\n arr[i] = 1\r\n elif arr[i]==arr[i-1]:\r\n ans+=1\r\n arr[i] = 0\r\n\r\nprint(ans)", "input()\r\np,c = 3,0\r\nfor i in list(map(int, input().split())):\r\n if i==p and p!=3:\r\n i = 0\r\n elif i==3 and p!=3:\r\n i-=p\r\n if i == 0:\r\n c+=1\r\n p = i\r\nprint(c)", "n = int(input())\r\narr = [int(x) for x in input().split()]\r\nrest = 0\r\ncheck = 0\r\nfor i in range( n):\r\n if arr[i] == 0:\r\n rest = rest + 1\r\n check = 0\r\n elif check == 2 and arr[i] != 2:\r\n check = 1\r\n elif check == 2 and arr[i] == 2 :\r\n check = 0\r\n rest = rest + 1\r\n elif check == 1 and arr[i] != 1:\r\n check = 2\r\n elif check == 1 and arr[i] == 1:\r\n check = 0\r\n rest = rest + 1\r\n else:\r\n check = arr[i] \r\nprint(rest) \r\n ", "n = int(input())\r\nk = list(map(int, input().split(\" \")))\r\nans = 0\r\nlast = \"n\"\r\nfor i in k:\r\n if i == 0:\r\n now = \"n\"\r\n elif i == 1 and last != \"p\":\r\n now = \"p\"\r\n elif i == 1:\r\n now = \"n\"\r\n elif i == 2 and last != \"s\":\r\n now = \"s\"\r\n elif i == 2:\r\n now = \"n\"\r\n elif last == \"s\":\r\n now = \"p\"\r\n elif last == \"p\":\r\n now = \"s\"\r\n else:\r\n now = 'a'\r\n if now == \"n\":\r\n ans += 1\r\n last = now\r\nprint(ans)\r\n", "n=int(input())\r\nA=list(map(int,input().split()))\r\ngym=[0]*(n+1)\r\ncontest=[0]*(n+1)\r\nfree=[0]*(n+1)\r\nfor i in range(n):\r\n v=A[i]\r\n if v==0:\r\n MIN=min(gym[i],contest[i],free[i])+1\r\n gym[i+1]=MIN\r\n contest[i + 1] = MIN\r\n free[i + 1] = MIN\r\n if v==1:\r\n gym[i+1]=min(gym[i],contest[i],free[i])+1\r\n contest[i + 1]=min(free[i],gym[i])\r\n free[i + 1] =min(gym[i],contest[i],free[i])+1\r\n if v==2:\r\n gym[i + 1] = min(free[i], contest[i])\r\n contest[i + 1] = min(gym[i], contest[i], free[i]) + 1\r\n free[i + 1] = min(gym[i], contest[i], free[i]) + 1\r\n if v==3:\r\n gym[i + 1] = min(free[i], contest[i])\r\n contest[i + 1]=min(free[i],gym[i])\r\n free[i + 1] = min(gym[i], contest[i], free[i]) + 1\r\nprint(min(gym[n],contest[n],free[n]))", "n = int(input())\ns = input()\nA = []\nSum = 0\nF = 0\nfor i in s.split():\n A.append(int(i))\nfor j in range(0,n):\n if A[j] == 0:\n Sum = Sum + 1\n F = 0\n elif A[j] == 1:\n if F == 0:\n F = 1\n elif F == 1:\n Sum = Sum+1\n F = 0\n elif F == 2:\n F = 1\n elif A[j] == 2:\n if F == 0:\n F = 2\n elif F == 1:\n F = 2\n elif F == 2:\n Sum = Sum + 1\n F = 0\n elif A[j] == 3:\n if F == 0:\n F = 0\n elif F == 1:\n F = 2\n elif F == 2:\n F = 1\nprint(Sum)\n \n ", "n=int(input())\r\na=list(map(int,input().split()))\r\nl=[0]*n\r\nl[0]=a[0]\r\ns=1 if l[0]==0 else 0\r\nfor i in range(1,n):\r\n\tif a[i]==0:l[i]=0;s+=1\r\n\telif a[i]==3:l[i]=l[i-1]^a[i]\r\n\telif a[i]==1:\r\n\t\tif l[i-1]==1:l[i]=0;s+=1\r\n\t\telse:l[i]=a[i]\r\n\telse:\r\n\t\tif l[i-1]==2:l[i]=0;s+=1\r\n\t\telse:l[i]=a[i]\r\nprint(s)", "n = int(input())\r\nline = input().split()\r\nstates = [int(x) for x in line]\r\n\r\nflag = 0\r\nrest = 0\r\n\r\ndef swap(flag):\r\n if flag == 1:\r\n return 2\r\n else:\r\n return 1\r\n\r\nfor state in states:\r\n if state == 0:\r\n rest += 1\r\n flag = 0\r\n if state == 1 or state == 2:\r\n if state == flag:\r\n rest += 1\r\n flag = 0\r\n else:\r\n flag = state\r\n if state == 3:\r\n if flag != 0:\r\n flag = swap(flag)\r\n \r\nprint(rest)\r\n\r\n ", "n = int(input())\r\ns = list(map(int, input().split()))\r\nlast = 2\r\nt = 0\r\nfor i in s:\r\n if i == 0:\r\n t += 1\r\n last = 2\r\n elif i == 1:\r\n if last == 0:\r\n t += 1\r\n last = 2\r\n else:\r\n last = 0\r\n elif i == 2:\r\n if last == 1:\r\n t += 1\r\n last = 2\r\n else:\r\n last = 1\r\n else:\r\n if last == 1:\r\n last = 0\r\n elif last == 0:\r\n last =1\r\nprint(t)\r\n", "import sys\r\nfrom collections import *\r\nsys.setrecursionlimit(10**5)\r\nitr = (line for line in sys.stdin.read().strip().split('\\n'))\r\nINP = lambda: next(itr)\r\ndef ni(): return int(INP())\r\ndef nl(): return [int(_) for _ in INP().split()]\r\n\r\n\r\n\r\nn = nl()\r\narr = nl()\r\nz = arr.count(0)\r\ns = []\r\ncur = 0\r\n#insight: Start at first 1 or 2, before that it will always be changed backwards\r\nfound = False\r\nis1 = False\r\nfor i in range(len(arr)):\r\n if not found:\r\n if arr[i] == 1 or arr[i] == 2:\r\n found = True\r\n if arr[i] == 1:\r\n is1 = True\r\n else:\r\n if arr[i] == 3:\r\n is1 = not is1\r\n if arr[i] == 0:\r\n is1 = False\r\n found = False\r\n if arr[i] == 2:\r\n if is1:\r\n is1 = not is1\r\n else:\r\n z += 1\r\n found = False\r\n is1 = False\r\n if arr[i] == 1:\r\n if is1:\r\n z += 1\r\n found = False\r\n is1 = False\r\n else:\r\n is1 = not is1\r\nprint(z)\r\n ", "n = int(input())\r\narr = list(map(int,input().split()))\r\nli = [0 for i in range(n)]\r\nfor i in range(n):\r\n\tif arr[i]==0:\r\n\t\tli[i]+=1\r\n\tif i!=0:\r\n\t\tif arr[i]==arr[i-1] and arr[i]!=3 and arr[i]!=0:\r\n\t\t\tli[i]+=1\r\n\t\t\tarr[i]=0\r\n\t\telif arr[i]==3 and arr[i-1]==1:\r\n\t\t\tarr[i]=2\r\n\t\telif arr[i]==3 and arr[i-1]==2:\r\n\t\t\tarr[i]=1\r\n\t\tli[i]+=li[i-1]\r\nprint(li[n-1])", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\ndp = []\r\nfor i in range(n):\r\n dp.append([0, 0])\r\n\r\nif arr[0] == 1 or arr[0] == 3:\r\n dp[0][0] = 1\r\nif arr[0] == 2 or arr[0] == 3:\r\n dp[0][1] = 1\r\n\r\nfor i in range(1, n):\r\n\r\n if arr[i] == 3:\r\n dp[i][0] = dp[i - 1][1] + 1\r\n dp[i][1] = dp[i - 1][0] + 1\r\n elif arr[i] == 1:\r\n dp[i][0] = dp[i - 1][1] + 1\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][1])\r\n elif arr[i] == 2:\r\n dp[i][1] = dp[i - 1][0] + 1\r\n dp[i][0] = max(dp[i - 1][0], dp[i - 1][1])\r\n else:\r\n dp[i][0] = max(dp[i - 1][0], dp[i - 1][1])\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][1])\r\n\r\nprint(n - max(dp[-1][0], dp[-1][1]))\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nn = int(input())\r\na = [0] + [int(i) for i in input().split()]\r\n\r\ndp = [[0] * 3 for i in range(n + 1)]\r\n\r\nfor i in range(1, n + 1):\r\n dp[i][0] = max(dp[i - 1])\r\n if a[i] & 1:\r\n dp[i][1] = 1 + max(dp[i - 1][0], dp[i - 1][2])\r\n if a[i] & 2:\r\n dp[i][2] = 1 + max(dp[i - 1][0], dp[i - 1][1])\r\n\r\nprint(n - max(dp[-1]))\r\n", "n=int(input())\r\ndays=list(map(int,input().split()))\r\nrest=0\r\nx=0\r\nfor i in range(n):\r\n if days[i]==0 or days[i]==x:\r\n rest+=1\r\n x=0\r\n elif days[i]==3:\r\n if x!=0: \r\n x=3-x\r\n else:\r\n x=days[i]\r\nprint(rest)", "n = int(input())\r\na = list(map(int, input().split()))\r\nk = 0\r\np = 0\r\nfor i in range(n):\r\n if a[i] == 0 or a[i] == p:\r\n k += 1\r\n p = 0\r\n elif a[i] == 3: \r\n if p != 0: p = 3 - p \r\n else: p = a[i]\r\nprint(k)", "n = int(input())\r\ns = list(map(int, input().split()))\r\n\r\nc = 0\r\nchoice = 'no'\r\nfor i in range(n):\r\n if s[i] == 0:\r\n c = c + 1\r\n choice = 'day off'\r\n elif s[i] == 1:\r\n if choice == 'contest':\r\n c = c + 1\r\n choice = 'day off'\r\n else:\r\n choice = 'contest'\r\n elif s[i] == 2:\r\n if choice == 'sport':\r\n c = c + 1\r\n choice = 'day off'\r\n else:\r\n choice = 'sport'\r\n elif s[i] == 3:\r\n if choice == 'sport':\r\n choice = 'contest'\r\n elif choice == 'contest':\r\n choice = 'sport'\r\n\r\nprint(c)", "#https://codeforces.com/problemset/problem/698/A\r\n\r\ndef main():\r\n\tn = int(input())\r\n\r\n\tdp_arr = [0,0,0]\r\n\tdays = [int(day) for day in input().split()]\r\n\tfor day in days:\r\n\t\tgym = dp_arr[0] + 1\r\n\t\tcontest = dp_arr[1] + 1\r\n\r\n\t\t#gym day\r\n\t\tif day == 2 or day == 3:\r\n\t\t\tgym = min(dp_arr[1], dp_arr[2])\r\n\r\n\t\t#contest\r\n\t\tif day == 1 or day == 3:\r\n\t\t\tcontest = min(dp_arr[0], dp_arr[2])\r\n\r\n\t\t#rest\r\n\t\trest = 1 + min(dp_arr)\r\n\r\n\t\tdp_arr = [gym,contest,rest]\r\n\r\n\tprint(min(dp_arr))\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()", "n = int(input())\r\n*a, = map(int, input().split())\r\nif a[0] != 3:\r\n dp = [a[0]] + [0] * (n - 1)\r\nelse:\r\n dp = [-1] + [0] * (n - 1)\r\nfor i in range(1, n):\r\n if a[i] == 0:\r\n dp[i] = a[i]\r\n elif a[i] == 1:\r\n if dp[i - 1] != 1:\r\n dp[i] = 1\r\n elif a[i] == 2:\r\n if dp[i - 1] != 2:\r\n dp[i] = 2\r\n else:\r\n if dp[i - 1] == 1:\r\n dp[i] = 2\r\n elif dp[i - 1] == 2:\r\n dp[i] = 1\r\n else:\r\n dp[i] = -1\r\nprint(dp.count(0))\r\n# print(dp)\r\n", "def main():\r\n n = int(input())\r\n A = list(map(int, input().split()))\r\n G = [[0] * (3) for _ in range(n + 1)]\r\n for i in range(1, n + 1):\r\n G[i][0] = max(G[i - 1])\r\n if A[i - 1] in [1, 3]:\r\n G[i][1] = max(G[i - 1][0], G[i - 1][2]) + 1\r\n if A[i - 1] in [2, 3]:\r\n G[i][2] = max(G[i - 1][0], G[i - 1][1]) + 1\r\n print(n - max(G[n]))\r\n return\r\nif __name__ == \"__main__\":\r\n main()", "# https://codeforces.com/problemset/problem/698/A\r\n\r\nn = int(input())\r\nvac, spo, con = [float('inf') for _ in range(n)], [float('inf') for _ in range(n)], [float('inf') for _ in range(n)]\r\nseq = tuple(map(int, input().split()))\r\nfor idx, item in enumerate(seq):\r\n if item == 0:\r\n if idx == 0:\r\n vac[0] = 1\r\n else:\r\n vac[idx] = min([vac[idx-1], spo[idx-1], con[idx-1]]) + 1\r\n elif item == 1:\r\n if idx == 0:\r\n vac[0] = 1\r\n con[0] = 0\r\n else:\r\n vac[idx] = min([vac[idx-1], spo[idx-1], con[idx-1]]) + 1\r\n con[idx] = min([vac[idx-1], spo[idx-1]])\r\n elif item == 2:\r\n if idx == 0:\r\n vac[0] = 1\r\n spo[0] = 0\r\n else:\r\n vac[idx] = min([vac[idx-1], spo[idx-1], con[idx-1]]) + 1\r\n spo[idx] = min([vac[idx-1], con[idx-1]])\r\n else:\r\n if idx == 0:\r\n vac[0] = 1\r\n spo[0] = 0\r\n con[0] = 0\r\n else:\r\n vac[idx] = min([vac[idx-1], spo[idx-1], con[idx-1]]) + 1\r\n spo[idx] = min([vac[idx-1], con[idx-1]])\r\n con[idx] = min([vac[idx-1], spo[idx-1]])\r\nprint(min(vac[n-1], spo[n-1], con[n-1]))\r\n\r\n\r\n", "\r\nd = int(input())\r\nl = list(input().split())\r\n\r\n# 3 = both\r\nrest = 0\r\nlast = '0'\r\nfor c in l:\r\n if c == '0':\r\n rest+=1\r\n last = '0'\r\n elif c == '1' and last != c:\r\n last = '1'\r\n elif c == '2' and last != c:\r\n last = '2'\r\n elif c == '3':\r\n if last == '1':\r\n last = '2'\r\n elif last == '2':\r\n last = '1'\r\n else:\r\n last = '0'\r\n else:\r\n rest += 1\r\n last = '0'\r\nprint (rest)", "def main():\n n = int(input())\n line = input().split()\n a = []\n for i in range(n):\n a.append(int(line[i]))\n it = [0]\n gym = [0]\n for i in range(n):\n best = 1+min(it[i], gym[i])\n if a[i] == 0:\n it.append(best)\n gym.append(best)\n elif a[i] == 1:\n it.append(min(best, gym[i]))\n gym.append(best)\n elif a[i] == 2:\n it.append(best)\n gym.append(min(best, it[i]))\n else:\n it.append(min(best, gym[i]))\n gym.append(min(best, it[i]))\n print(min(it[-1], gym[-1]))\n\n\nif __name__ == \"__main__\":\n main()\n \t \t \t \t\t \t\t \t\t \t\t\t \t\t \t\t", "n = int(input())\r\na = list(map(int, input().split()))\r\ndp = [[float('inf') for i in range(3)]for i in range(n + 1)]\r\ndp[0][0] = 0\r\ndp[0][1] = 0\r\ndp[0][2] = 0\r\nfor i in range(1, n + 1):\r\n if a[i - 1] == 1 or a[i - 1] == 3:\r\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\r\n if a[i - 1] == 2 or a[i - 1] == 3:\r\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\r\n dp[i][0] = min(dp[i - 1]) + 1\r\n\r\nprint(min(dp[n]))\r\n", "# Problem: A. Vacations\r\n# Contest: Codeforces - Codeforces Round 363 (Div. 1)\r\n# URL: https://codeforces.com/problemset/problem/698/A\r\n# Memory Limit: 256 MB\r\n# Time Limit: 1000 ms\r\n\r\nimport sys\r\nimport random\r\nfrom types import GeneratorType\r\nimport bisect\r\nimport io, os\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom contextlib import redirect_stdout\r\nfrom itertools import *\r\nfrom array import *\r\nfrom functools import lru_cache, reduce\r\nfrom heapq import *\r\nfrom math import sqrt, gcd, inf\r\nif sys.version >= '3.8': # ACW没有comb\r\n from math import comb\r\n\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\nRS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())\r\nRILST = lambda: list(RI())\r\nDEBUG = lambda *x: sys.stderr.write(f'{str(x)}\\n')\r\n# print = lambda d: sys.stdout.write(str(d) + \"\\n\") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法,需要print(' '.join(map(str, p))),确实会快。\r\n\r\nDIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 右下左上\r\nDIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),\r\n (-1, 1)] # →↘↓↙←↖↑↗\r\nRANDOM = random.randrange(2**62)\r\nMOD = 10**9 + 7\r\n# MOD = 998244353\r\nPROBLEM = \"\"\"https://codeforces.com/problemset/problem/698/A\r\n\r\n输入 n(1≤n≤100) 和长为 n 的数组 a(0≤a[i]≤3)。\r\n有 n 天,第 i 天的情况用 a[i]=0/1/2/3 表示,具体如下:\r\n\r\n0:健身房关闭,比赛不进行; \r\n1:健身房关闭,比赛进行;\r\n2:健身房开放,比赛不进行;\r\n3:健身房开放,比赛进行。\r\n\r\n在每一天,你可以休息、比赛 (如果比赛在这一天进行),或者做运动 (如果健身房在这一天是开放的)。\r\n但你不想连续两天做同样的活动,这意味着,你不会连续两天做运动,也不会连续两天参加比赛。\r\n输出你休息的最少天数。\r\n输入\r\n4\r\n1 3 2 0\r\n输出 2\r\n\r\n输入\r\n7\r\n1 3 3 2 1 2 3\r\n输出 0\r\n\r\n输入\r\n2\r\n2 2\r\n输出 1\r\n\"\"\"\r\n\r\n# ms\r\ndef solve():\r\n n, = RI()\r\n a = RILST()\r\n x=y=z=0\r\n for v in a:\r\n i,j,k = min(x,y,z)+1,inf,inf\r\n if v& 1:\r\n j = min(x,z)\r\n if v & 2:\r\n k = min(x,y)\r\n x,y,z= i,j,k\r\n print(min(x,y,z))\r\n\r\n\r\nif __name__ == '__main__':\r\n t = 0\r\n if t:\r\n t, = RI()\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\ndp = [[0 for _ in range(3)] for __ in range(n)]\r\n\r\nif a[0] == 1 or a[0] == 3:\r\n dp[0][1] = 1\r\nif a[0] == 2 or a[0] == 3:\r\n dp[0][2] = 1\r\n\r\nfor i in range(1, n):\r\n dp[i][0] = max(dp[i-1])\r\n if a[i] == 1 or a[i] == 3:\r\n dp[i][1] = 1 + max(dp[i-1][0], dp[i-1][2])\r\n if a[i] == 2 or a[i] == 3:\r\n dp[i][2] = 1 + max(dp[i-1][0], dp[i-1][1])\r\n\r\nprint(n - max(dp[n-1]))\r\n", "\r\n#from math import ceil, sqrt\r\n\r\n#import io, os, sys\r\n#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #input().decode().rstrip('\\r\\n')\r\n#print = lambda x: sys.stdout.write(str(x) + \"\\n\")\r\n \r\nII = lambda: int(input())\r\nMII = lambda: map(int, input().split())\r\nLMII = lambda: list(MII())\r\n#SLMII = lambda: sorted(LMII())\r\n\r\nn = II()\r\na = LMII()\r\n\r\n#ai=0, if gym=0 and contest=0\r\n#ai=1, if gym=0 and contest=1\r\n#ai=2, if gym=1 and contest=0\r\n#ai=3, if gym=1 and contest=1\r\n\r\nprev = 3\r\nfor i in range(n):\r\n if prev == 1:\r\n if a[i] == 1:\r\n a[i] = 0\r\n elif a[i] == 3:\r\n a[i] = 2\r\n if prev == 2:\r\n if a[i] == 2:\r\n a[i] = 0\r\n elif a[i] == 3:\r\n a[i] = 1\r\n prev = a[i]\r\n \r\nprint(a.count(0))\r\n\r\n\r\n \r\n ", "from functools import lru_cache\n\n@lru_cache(maxsize=400)\ndef solve(nums, i, prev):\n if i >= len(nums):\n return 0\n \n if nums[i] == 0:\n return 1 + solve(nums, i+1, 0)\n\n if nums[i] != 3:\n if prev == nums[i]:\n return 1 + solve(nums, i+1, 0)\n else:\n return solve(nums, i+1, nums[i])\n \n n = len(nums)\n for val in [1, 2]:\n if prev == val:\n n = min(n, 1 + solve(nums, i+1, 0))\n else:\n n = min(n, solve(nums, i+1, val))\n\n return n\n\n\n_ = input()\nnums = tuple(map(int, input().strip().split()))\nprint(solve(nums, 0, -1))\n\t \t \t\t\t \t \t \t \t \t\t \t \t\t\t\t \t", "from sys import stdin, stdout, setrecursionlimit\r\nimport threading\r\n\r\n# tail-recursion optimization\r\n# In case of tail-recusion optimized code, have to use python compiler.\r\n# Otherwise, memory limit may exceed.\r\n# declare the class Tail_Recursion_Optimization\r\nclass Tail_Recursion_Optimization:\r\n def __init__(self, RECURSION_LIMIT, STACK_SIZE):\r\n setrecursionlimit(RECURSION_LIMIT)\r\n threading.stack_size(STACK_SIZE)\r\n return None\r\n \r\nclass SOLVE:\r\n n = a = dp = None\r\n\r\n def DP(self, pos, gym, contest):\r\n if pos == self.n:\r\n return 0\r\n \r\n if self.dp[pos][gym][contest] != None:\r\n return self.dp[pos][gym][contest]\r\n \r\n \r\n if self.a[pos] == 0:\r\n self.dp[pos][gym][contest] = 1 + self.DP(pos+1, 0, 0)\r\n \r\n elif self.a[pos] == 1:\r\n if contest == 1:\r\n self.dp[pos][gym][contest] = 1 + self.DP(pos+1, 0, 0)\r\n else:\r\n self.dp[pos][gym][contest] = self.DP(pos+1, 0, 1)\r\n \r\n elif self.a[pos] == 2:\r\n if gym == 1:\r\n self.dp[pos][gym][contest] = 1 + self.DP(pos+1, 0, 0)\r\n else:\r\n self.dp[pos][gym][contest] = self.DP(pos+1, 1, 0)\r\n \r\n else:\r\n if gym == contest == 0:\r\n total1 = total2 = None\r\n total1 = self.DP(pos+1, 1, 0)\r\n total2 = self.DP(pos+1, 0, 1)\r\n self.dp[pos][gym][contest] = min(total1, total2)\r\n elif gym == 0:\r\n self.dp[pos][gym][contest] = self.DP(pos+1, 1, 0)\r\n else:\r\n self.dp[pos][gym][contest] = self.DP(pos+1, 0, 1)\r\n \r\n return self.dp[pos][gym][contest]\r\n \r\n def solve(self):\r\n R = stdin.readline\r\n #f = open('input.txt');R = f.readline\r\n W = stdout.write\r\n \r\n self.n = int(R())\r\n self.a = [int(x) for x in R().split()]\r\n self.dp = [[[None, None], [None, None]] for i in range(self.n)]\r\n \r\n W('%d\\n' % self.DP(0, 0, 0))\r\n return 0\r\n \r\ndef main():\r\n s = SOLVE()\r\n s.solve()\r\nTail_Recursion_Optimization(10**7, 100*1024**2) # recursion-call size, stack-size in byte (MB*1024**2)\r\nthreading.Thread(target=main).start()\r\n#main()", "# with open(\"input.txt\",'r') as f:\t\r\nn = int(input())\r\nvacation = list(map(int,input().split()))\r\ndp = [[0 for _ in range(3)] for _ in range(len(vacation)+1)]\r\nfor i in range(1,len(vacation)+1):\r\n\tdp[i][0] = max(max(dp[i-1][0],dp[i-1][1]),dp[i-1][2])\r\n\tif(vacation[i-1]==1 or vacation[i-1]==3):\r\n\t\tdp[i][1]=max(dp[i-1][0],dp[i-1][2])+1\r\n\tif(vacation[i-1]==2 or vacation[i-1]==3):\r\n\t\tdp[i][2] =max(dp[i-1][0],dp[i-1][1])+1\r\n\r\nnorest = max(dp[n][0],max(dp[n][1],dp[n][2]))\r\nprint(n-norest)", "n = int(input())\r\ntask = list(map(int,input().split()))\r\ndp = [[float('inf') for i in range(200)] for i in range(3)]\r\ndp[0][0]=0\r\n\r\nfor i in range(n):\r\n dp[0][i+1] = min( min(dp[0][i],dp[1][i]),dp[2][i] )\r\n dp[0][i+1] += 1\r\n \r\n if task[i]==1:\r\n dp[1][i+1] = min(dp[0][i], dp[2][i] )\r\n elif task[i]==2:\r\n dp[2][i+1] = min(dp[0][i], dp[1][i] )\r\n elif task[i]==3:\r\n dp[1][i+1] = min(dp[0][i], dp[2][i] )\r\n dp[2][i+1] = min(dp[0][i], dp[1][i] )\r\n \r\nres= min( min(dp[0][n],dp[1][n]) , dp[2][n] )\r\nprint(res)\r\n", "n = int(input())\r\ndays = [int(c) for c in input().split()]\r\nmemo = {}\r\n\r\n\r\ndef solve(day=0, prev=0):\r\n if (day, prev) in memo:\r\n return memo[(day, prev)]\r\n\r\n cur = days[day]\r\n\r\n if day == n-1:\r\n if cur == 0:\r\n return 1\r\n elif cur == 3:\r\n return 0\r\n elif cur == 1:\r\n return 1 if prev == 2 else 0\r\n elif cur == 2:\r\n return 1 if prev == 1 else 0\r\n\r\n options = [1 + solve(day+1, 0)]\r\n if (cur == 2 or cur == 3) and prev != 1:\r\n options.append(solve(day+1, 1))\r\n\r\n if (cur == 1 or cur == 3) and prev != 2:\r\n options.append(solve(day+1, 2))\r\n\r\n memo[(day, prev)] = min(options)\r\n\r\n return memo[(day, prev)]\r\n\r\n\r\ndef main():\r\n ans = solve()\r\n print(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\narr=list(map(int,input().split()))\r\na,b,c=0,0,0\r\nfor el in arr:\r\n if el==0:\r\n t=1+min(a,b,c)\r\n a=b=c=t\r\n elif el==1:\r\n t=1+min(a,b,c)\r\n p=min(a,c)\r\n q=1+min(a,b,c)\r\n a=t\r\n b=p\r\n c=q\r\n elif el==2:\r\n t=1+min(a,b,c)\r\n q=min(a,b)\r\n p=1+min(a,b,c)\r\n a=t\r\n b=p\r\n c=q\r\n else :\r\n t=1+min(a,b,c)\r\n p=min(a,c)\r\n q=min(a,b)\r\n a=t\r\n b=p\r\n c=q\r\nprint(min(a,b,c))", "def mlt(): return map(int, input().split())\r\n\r\n\r\ndef solv():\r\n x = int(input())\r\n s = list([*mlt()])\r\n\r\n dp = [[0, 0, 0] for n in range(x)]\r\n\r\n if s[0] == 1:\r\n dp[0][1] = 1\r\n elif s[0] == 2:\r\n dp[0][2] = 1\r\n elif s[0] == 3:\r\n dp[0] = [1, 1, 1]\r\n\r\n for n in range(1, x):\r\n dp[n][0] = max(dp[n-1])\r\n dp[n][1] = max(dp[n-1][2], dp[n-1][0])+int(s[n] == 3 or s[n] == 1)\r\n dp[n][2] = max(dp[n-1][0], dp[n-1][1])+int(s[n] == 3 or s[n] == 2)\r\n print(x-max(dp[-1]))\r\n\r\n\r\nsolv()\r\n", "n=int(input())\r\nV=[int(i) for i in input().split()]\r\nans=0\r\ndp=[0]*n\r\nif V[0]==0:\r\n ans+=1\r\nelif V[0]==3 and n>1:\r\n dp[0]=3-V[1]\r\nelse:\r\n dp[0]=V[0]\r\n\r\nfor i in range(1,n):\r\n if V[i]==0:\r\n ans+=1\r\n elif dp[i-1]==V[i] and V[i]!=3:\r\n dp[i]=0\r\n ans+=1\r\n else:\r\n if V[i]==3:\r\n dp[i]=3-dp[i-1]\r\n else:\r\n dp[i]=V[i]\r\nprint(ans)\r\n \r\n \r\n ", "n = int(input())\r\narr = [int(x) for x in input().split()]\r\ngym = [0 for i in range(n)]\r\ncontest = [0 for i in range(n)]\r\ngym[-1] = 0 if arr[-1] >= 2 else 1\r\ncontest[-1] = 0 if arr[-1] % 2 == 1 else 1\r\nfor i in reversed(range(n-1)):\r\n gym[i] = contest[i+1] if arr[i] >= 2 else (1 + min(contest[i+1], gym[i+1]))\r\n contest[i] = gym[i + 1] if arr[i] % 2 == 1 else (1 + min(contest[i + 1], gym[i + 1]))\r\nprint(min(contest[0], gym[0]))", "n = int(input())\r\nk = [int(i) for i in input().split()]\r\ndp = [[0] * 3 for i in range(n)]\r\nif k[0] == 1 or k[0] == 3:\r\n dp[0][2] = 1\r\nif k[0] == 2 or k[0] == 3:\r\n dp[0][1] = 1\r\nfor i in range(1, n):\r\n dp[i][0] = max(dp[i-1][0], dp[i-1][1], dp[i-1][2])\r\n if k[i] == 1 or k[i] == 3:\r\n dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + 1\r\n if k[i] == 2 or k[i] == 3:\r\n dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1\r\nm = max(dp[n-1][0], dp[n-1][1], dp[n-1][2])\r\nprint(n - max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef inp():\r\n return int(input())\r\n\r\ndef insr():\r\n s = input()\r\n return list(s[:len(s) - 1])\r\n\r\ndef invr():\r\n return map(int, input().split())\r\n\r\nif __name__ == '__main__':\r\n n = inp()\r\n s = list(invr())\r\n\r\n d = [[ 0 for _ in range(3) ] for _ in range(n)]\r\n \r\n # Initialization; first day\r\n d[0][0] = 0 # Vasya rests\r\n if s[0] == 1 or s[0] == 3: # Vasya may go to the gym\r\n d[0][1] = 1\r\n if s[0] == 2 or s[0] == 3: # Vasya may go to the contest\r\n d[0][2] = 1\r\n\r\n for i in range(1, n):\r\n d[i][0] = max(d[i-1][0], d[i-1][1], d[i-1][2])\r\n if s[i] == 1 or s[i] == 3:\r\n d[i][1] = max(d[i-1][0] + 1, d[i-1][2] + 1)\r\n if s[i] == 2 or s[i] == 3:\r\n d[i][2] = max(d[i-1][0] + 1, d[i-1][1] + 1)\r\n\r\n print(n - max(d[n-1][0], d[n-1][1], d[n-1][2]))", "n = int(input())\r\na = [int(x) for x in input().split(' ')]\r\n\r\n# minimum rest days given ith day is a - rest (0), contest (1), gym (2)\r\nm = [[float('inf')] * 3 for i in range(n)]\r\n\r\nm[0][0] = 1\r\nfor i in range(1, 3):\r\n if a[0] in [i, 3]:\r\n m[0][i] = 0\r\n else:\r\n pass\r\n\r\nfor j in range(1, n):\r\n m[j][0] = min(m[j - 1]) + 1\r\n for i in range(1, 3):\r\n if a[j] in [i, 3]:\r\n m[j][i] = min(m[j - 1][0], m[j - 1][3 - i])\r\n\r\n\r\nans = min(m[-1])\r\nprint(ans)", "N = int(input())\r\ndays = input().split()\r\nimpossible = None\r\nbad_days = 0\r\nx = 0\r\nwhile x<N:\r\n\ti = days[x]\r\n\tif i=='1':\r\n\t\tif impossible!='1':\r\n\t\t\timpossible='1'\r\n\t\telse:\r\n\t\t\tbad_days += 1\r\n\t\t\timpossible = None\r\n\telif i=='2':\r\n\t\tif impossible!='2':\r\n\t\t\timpossible='2'\r\n\t\telse:\r\n\t\t\tbad_days += 1\r\n\t\t\timpossible = None\r\n\telif i=='0':\r\n\t\tbad_days += 1\r\n\t\timpossible = None\r\n\telse:\r\n\t\tif impossible=='1':\r\n\t\t\timpossible = '2'\r\n\t\telif impossible=='2':\r\n\t\t\timpossible = '1'\r\n\t\telse:\r\n\t\t\tj = N-1\r\n\t\t\tfor j in range(x+1, N):\r\n\t\t\t\tif days[j]!='3':\r\n\t\t\t\t\tif days[j]=='0':\r\n\t\t\t\t\t\tx = j-1\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\telif days[j]=='1':\r\n\t\t\t\t\t\timpossible = '1'\r\n\t\t\t\t\t\tx = j\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\telif days[j]=='2':\r\n\t\t\t\t\t\timpossible = '2'\r\n\t\t\t\t\t\tx = j\r\n\t\t\t\t\t\tbreak\r\n\t\t\tif j==N-1 and days[j]==3:\r\n\t\t\t\tx = j\r\n\tx = x+1\r\nprint (bad_days)", "n = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\nans = [[0, 0, 0] for _ in range(n+1)]\r\nfor i in range(n):\r\n if nums[i] == 2:\r\n ans[i+1][2] = max(ans[i][0] + 1, ans[i][1]+1)\r\n elif nums[i] == 1:\r\n ans[i+1][1] = max(ans[i][0] + 1, ans[i][2]+1)\r\n elif nums[i] == 3:\r\n ans[i+1][2] = max(ans[i][0] + 1, ans[i][1]+1)\r\n ans[i+1][1] = max(ans[i][0] + 1, ans[i][2]+1)\r\n ans[i+1][0] = max(ans[i])\r\nprint(n-max(ans[-1]))", "n=int(input())\r\na=[int(v) for v in input().split()]\r\np=0\r\nc=0\r\nfor v in a:\r\n if v==3 and p!=0:\r\n if p==1:\r\n p=2\r\n else:\r\n p=1\r\n elif v==3 and p==0:\r\n continue\r\n elif v==0:\r\n c=c+1\r\n p=0\r\n elif p==v:\r\n c=c+1\r\n p=0\r\n elif p!=v:\r\n p=v\r\nprint(c)", "n = int(input())\r\narr = list(int(num) for num in input().strip().split())\r\n\r\nrest = 0\r\nlast = None\r\n\r\nfor i in range(n):\r\n if(arr[i] == 0):\r\n last = None\r\n rest += 1\r\n \r\n elif(arr[i] == 1):\r\n if(last == 1):\r\n last = None\r\n rest += 1\r\n else:\r\n last = 1\r\n \r\n elif(arr[i] == 2):\r\n if(last == 2):\r\n last = None\r\n rest += 1\r\n else:\r\n last = 2\r\n \r\n elif(arr[i] == 3):\r\n if(last == 1):\r\n last = 2\r\n elif(last == 2):\r\n last = 1\r\n else:\r\n last = None\r\n \r\nprint(rest)\r\n ", "n = int(input())\na = list(map(int, input().split()))\ndp = [[0, 0, 0] for i in range(n + 1)]\nfor i in range(1, n + 1):\n x = a[i - 1]\n dp[i][0] = max(dp[i - 1])\n if x == 1 or x == 3:\n dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][2] + 1)\n if x == 2 or x == 3:\n dp[i][2] = max(dp[i - 1][0] + 1, dp[i - 1][1] + 1)\nprint(n - max(dp[n]))", "from sys import stdin, stdout\r\nfrom math import inf\r\n\r\ndef read_list(): # read list of variables\r\n return [int(x) for x in stdin.readline().split()]\r\n\r\n\r\ndef readmv(): # read_multiple_variable\r\n return map(int, stdin.readline().split())\r\n\r\n\r\ndef readv(): # read variable\r\n return int(stdin.readline())\r\n\r\n\r\ndef printSol(test_case, x):\r\n ans_to_print = ''\r\n if type(x) == list:\r\n for el in x:\r\n ans_to_print += f'{el} '\r\n\r\n if type(x) == int or type(x) == float:\r\n ans_to_print = str(x)\r\n\r\n stdout.write(f'Case #{test_case + 1}: ' + ans_to_print + f'\\n')\r\n\r\ndef read():\r\n return stdin.readline().strip()\r\n\r\n\r\ndef solve(n, k, arr):\r\n left = k - 1\r\n pass\r\n\r\n# f(i, j) - minimalna liczba przerw konczac na indeksie i robiąc sport j\r\nfrom math import inf\r\ndef main():\r\n n = readv()\r\n arr = read_list()\r\n F = [[inf]*3 for _ in range(n)]\r\n\r\n# 0 - gym\r\n# 1 - contest\r\n ans = 0\r\n k = 1\r\n if arr[0] & (1 << (k - 1)): ## dla 1\r\n F[0][0] = 0\r\n\r\n k = 2\r\n if arr[0] & (1 << (k - 1)): ## dla 2\r\n F[0][1] = 0\r\n\r\n # if not arr[0]: ## dla 0\r\n F[0][2] = 1\r\n\r\n for i in range(1, n):\r\n\r\n k = 1\r\n if arr[i] & (1 << (k - 1)): ## dla 1\r\n F[i][0] = min(F[i-1][1], F[i-1][2])\r\n\r\n k = 2\r\n if arr[i] & (1 << (k - 1)): ## dla 2\r\n F[i][1] = min(F[i-1][0], F[i-1][2])\r\n\r\n # if not arr[i]: ## dla 0\r\n # F[i][0] += 1\r\n # F[i][1] += 1\r\n F[i][2] = min(F[i-1][0], F[i-1][1], F[i-1][2]) + 1\r\n\r\n # print(F)\r\n stdout.write(f\"{min(F[n-1])}\\n\")\r\n\r\ndef isKthBitSet(n, k):\r\n if n & (1 << (k - 1)):\r\n print(\"SET\")\r\n else:\r\n print(\"NOT SET\")\r\n\r\nmain()\r\n", "n = int(input())\na = list(map(int, input().split()))\n\n# 0 -> descanso; 1 -> contest; 2 -> esporte\ndp = [[-1 for _ in range(4)] for _ in range(n + 1)]\n\ndef ans(n: int, a: list, i: int, j: int) -> int:\n if i == n:\n return 0\n \n res = float('inf')\n\n if j != 1 and (a[i] == 1 or a[i] == 3):\n if dp[i+1][1] == -1:\n dp[i+1][1] = ans(n, a, i+1, 1)\n res = min(res, dp[i+1][1])\n \n if j != 2 and (a[i] == 2 or a[i] == 3):\n if dp[i+1][2] == -1:\n dp[i+1][2] = ans(n, a, i+1, 2)\n res = min(res, dp[i+1][2])\n\n if dp[i+1][0] == -1:\n dp[i+1][0] = ans(n, a, i+1, 0)\n \n return min(res, 1 + dp[i+1][0])\n\nprint(ans(n, a, 0, 0))\n\n \t \t\t \t \t \t \t\t \t\t \t", "n = int(input())\r\nliczby = list(map(int, input().split()))\r\nwynik = 0\r\nprevious = -1\r\n\r\nfor x in range(n):\r\n if liczby[x] == 0:\r\n wynik+=1\r\n previous = 0\r\n elif liczby[x] == 1:\r\n if previous == 1:\r\n wynik+=1\r\n previous = 0\r\n else:\r\n previous = 1\r\n elif liczby[x] == 2:\r\n if previous == 2:\r\n wynik+=1\r\n previous = 0\r\n else:\r\n previous = 2\r\n elif liczby[x] == 3:\r\n if previous == 1:\r\n previous = 2\r\n elif previous == 2:\r\n previous = 1\r\n elif previous == -1:\r\n previous = 0\r\nprint(wynik)", "n=int(input())\r\ndata=list(map(int,input().split()))\r\ndp=[[float('inf')]*3 for _ in range(n+1)]\r\ndp[0]=[0,0,0]\r\nfor i in range(1,n+1):\r\n dp[i][0]=min(dp[i-1])+1\r\n if data[i-1]==1:\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n if data[i-1]==2:\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n if data[i-1]==3:\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\nprint(min(dp[n]))", "import bisect\nimport math\nfrom collections import deque\nimport heapq\nimport functools\nfrom collections import defaultdict\n \nmod = 998244353 \nN = 200005\n \ngetnums = lambda: map(int, input().split())\ngetnum = lambda: int(input())\n \ndef mul(a, b):\n\treturn (a*b)%mod\n \ndef add(a, b):\n\treturn (a+b) if (a+b<mod) else (a+b)-mod\n \ndef sub(a, b):\n\treturn (a-b) if (a-b>=0) else (a-b)+mod\n \ndef powr(a, b):\n\tans = 1\n\twhile b>0:\n\t\tif b & 1:\n\t\t\tans=mul(ans,a)\n\t\ta = mul(a,a) \n\t\tb//=2\n\treturn ans\n \ndef inv(n):\n\treturn powr(n, mod-2)\n \ndef factlist():\n\tfact = [1]\n\tfor i in range(1, N):\n\t\tfact.append(mul(fact[i-1],i))\n\treturn fact\n \ndef invfactlist(fact):\n\tinvfact=[0]*N\n\tinvfact[0]=1\n\tinvfact[N-1]= inv(fact[N-1])\n\tfor i in range(N-2, 0, -1):\n\t\tinvfact[i]= mul(invfact[i+1],(i+1))\n\t\n\treturn invfact\n \ndef rot(S):\n\treturn list(zip(*S[::-1]))\n \ndef gcd(a, b):\n\tif b==0:\n\t\treturn a\n\treturn gcd(b, a%b)\n \ndef generate():\n\tans = [0]\n\twhile ans[-1]<1000000000:\n\t\tans.append(1+ans[-1]*2)\n\treturn ans\n \n \ndef __gcd(a, b):\n if (a == 0):\n return b\n return __gcd(b % a, a)\n \n \ndef LcmOfArray(arr, idx):\n \n if (idx == len(arr)-1):\n return arr[idx]\n a = arr[idx]\n b = LcmOfArray(arr, idx+1)\n return int(a*b/__gcd(a,b)) \n \n \n# con = dict()\n \nclass Node:\n\tdef __init__(self, val):\n\t\tself.val = val\n\t\tself.child = None\n\t\tself.parent = None\n \n \n\tdef addrear(self, y):\n\t\tself.child = y\n\t\ty.parent = self\n \n \n\tdef deleterear(self, y):\n\t\tself.child = None\n\t\ty.parent = None\n \n\tdef findparent(self):\n\t\tparent = self.parent\n\t\tnode = self\n\t\twhile parent:\n\t\t\tnode = parent\n\t\t\tparent = parent.parent\n\t\treturn node\n \n\tdef getelem(self):\n\t\tlst = [self.val]\n\t\tch = self.child\n\t\twhile ch:\n\t\t\tlst.append(ch.val)\n\t\t\tch= ch.child\n\t\treturn lst\n \n \ndef main():\n\tn = getnum()\n\ta = list(getnums())\n\tdp = [[0]*(n+1) for i in range(3)]\n\tfor i in range(n):\n\t\tind = i+1\n\t\tif a[i]%2:\n\t\t\tdp[1][ind] = max(dp[2][i], dp[0][i])+1\n\t\tif a[i]//2:\n\t\t\tdp[2][ind] = max(dp[1][i], dp[0][i])+1\n\t\tdp[0][ind] = max([dp[1][i], dp[0][i] ,dp[2][i]])\n\tans = max([dp[i][-1] for i in range(3)])\n\t# print(*dp)\n\tprint(n-ans)\n \nif __name__ == \"__main__\":\n\tmain()\n\t\t\n ", "def get_input(pregunta):\r\n return list(map(int, pregunta.split(\" \")))\r\n\r\nline_1 = int(input())\r\nline_2 = get_input(input())\r\n\r\narr = [[0]*3 for i in range(line_1)]\r\n\r\nif(line_2[0] == 1):\r\n arr[0][2] = 1\r\nelif(line_2[0] == 2):\r\n arr[0][1] = 1\r\nelif(line_2[0] == 3):\r\n arr[0][2] = 1\r\n arr[0][1] = 1\r\n\r\nfor i in range(1,line_1):\r\n for j in range(3):\r\n if(j == 0):\r\n arr[i][j] = max(arr[i-1])\r\n elif(j == 1):\r\n c = 0\r\n if(line_2[i] == 2 or line_2[i] == 3):\r\n c = 1\r\n arr[i][j] = max([arr[i-1][0],arr[i-1][2]]) + c\r\n elif(j == 2):\r\n c = 0\r\n if(line_2[i] == 1 or line_2[i] == 3):\r\n c = 1\r\n arr[i][j] = max([arr[i-1][0],arr[i-1][1]]) + c\r\nprint(line_1 - max(arr[-1]))", "n=int(input())\na=list(map(int,input().split()))\nb=[0,0,0]\n\ndp=[]\n\nfor i in range(n):\n dp.append([0,0,0])\n##print(dp)\n\nif a[0]==1 or a[0]==3:\n dp[0][1]+=1\n\nif a[0]==2 or a[0]==3:\n dp[0][2]+=1\n\nfor i in range(1,n):\n## print(dp[i])\n dp[i][0]=max(dp[i-1])\n dp[i][1]=max(dp[i-1][0],dp[i-1][2])\n if a[i] == 1 or a[i] == 3:\n dp[i][1]+=1\n dp[i][2]=max(dp[i-1][0],dp[i-1][1])\n if a[i] == 2 or a[i] == 3:\n dp[i][2]+=1\n\nprint(n-max(dp[n-1]))\n##print(dp)\n\n\t \t \t \t\t\t\t\t \t\t \t \t \t\t\t\t \t", "n = int(input())\r\ndias = list(map(int, input().split()))\r\nOPT = [[0]*3 for i in range(2)]\r\nfor i in range(n):\r\n if(dias[i] == 0):\r\n optimo_anterior = 1 + OPT[0][0]\r\n OPT[1][0] = optimo_anterior\r\n OPT[1][1] = optimo_anterior\r\n OPT[1][2] = optimo_anterior\r\n elif(dias[i] == 1):\r\n optimo_anterior = min(OPT[0][0]+1, OPT[0][2])\r\n OPT[1][0] = optimo_anterior\r\n OPT[1][1] = optimo_anterior\r\n OPT[1][2] = 1 + OPT[0][0]\r\n elif(dias[i] == 2):\r\n optimo_anterior = min(OPT[0][0]+1, OPT[0][1])\r\n OPT[1][0] = optimo_anterior\r\n OPT[1][2] = optimo_anterior\r\n OPT[1][1] = 1 + OPT[0][0]\r\n else:\r\n OPT[1][0] = min(OPT[0][0]+1, OPT[0][1], OPT[0][2])\r\n OPT[1][1] = min(OPT[0][0]+1, OPT[0][2])\r\n OPT[1][2] = min(OPT[0][0]+1, OPT[0][1])\r\n OPT[0][0] = OPT[1][0]\r\n OPT[0][1] = OPT[1][1]\r\n OPT[0][2] = OPT[1][2]\r\nprint(OPT[1][0])", "num = int(input())\r\ndays = list(map(int, input().split()))\r\n\r\nrest = 0\r\n\r\nflag = 0\r\nfor j in range(len(days)):\r\n if days[j] == 0:\r\n flag = 0\r\n rest += 1\r\n elif days[j] == 1:\r\n if flag is not 1:\r\n flag = 1\r\n else:\r\n rest += 1\r\n flag = 0\r\n elif days[j] == 2:\r\n if flag is not 2:\r\n flag = 2\r\n else:\r\n rest += 1\r\n flag = 0\r\n else:\r\n if flag is 0:\r\n continue\r\n if flag is 1:\r\n flag = 2\r\n else:\r\n flag = 1\r\n\r\nprint(rest)", "n = int(input())\r\ninfo = list(map(int, input().split()))\r\ninfo.insert(0, 0)\r\n\r\nINF = n + 1\r\n\r\nminRestDays = [[0 for j in range(3)] for i in range(1 + n)]\r\n\r\nminRestDays[0][0] = 0\r\nminRestDays[0][1] = INF\r\nminRestDays[0][2] = INF\r\nfor day in range(1, n + 1):\r\n if info[day] == 0: # 00 - the gym is closed and no contest is available in day day\r\n minRestDays[day][0] = 1 + min(minRestDays[day - 1][0],\r\n minRestDays[day - 1][1],\r\n minRestDays[day - 1][2])\r\n minRestDays[day][1] = INF\r\n minRestDays[day][2] = INF\r\n\r\n if info[day] == 1: # 01 - the gym is closed and the contest is running in day day\r\n minRestDays[day][0] = 1 + min(minRestDays[day - 1][0],\r\n minRestDays[day - 1][1],\r\n minRestDays[day - 1][2])\r\n minRestDays[day][1] = min(minRestDays[day - 1][0], \r\n minRestDays[day - 1][2])\r\n minRestDays[day][2] = INF\r\n\r\n if info[day] == 2: # 10 - the gym is open and no contest is available in day day\r\n minRestDays[day][0] = 1 + min(minRestDays[day - 1][0],\r\n minRestDays[day - 1][1],\r\n minRestDays[day - 1][2])\r\n minRestDays[day][1] = INF\r\n minRestDays[day][2] = min(minRestDays[day - 1][0],\r\n minRestDays[day - 1][1])\r\n\r\n if info[day] == 3: # 11 - the gym is open and the contest is running in day day\r\n minRestDays[day][0] = 1 + min(minRestDays[day - 1][0],\r\n minRestDays[day - 1][1],\r\n minRestDays[day - 1][2])\r\n minRestDays[day][1] = min(minRestDays[day - 1][0],\r\n minRestDays[day - 1][2])\r\n minRestDays[day][2] = min(minRestDays[day - 1][0],\r\n minRestDays[day - 1][1])\r\n\r\n\r\nanswer = min(minRestDays[n][0],\r\n minRestDays[n][1],\r\n minRestDays[n][2])\r\n\r\nprint(answer)", "n = int(input())\nl_n = list(map(int, input().split()))\n\np = l_n[0]\nt = 1 if p == 0 else 0\n\nfor i in range(1, n):\n if l_n[i] == p and p != 3:\n l_n[i] = 0\n elif l_n[i] == 3 and p != 3:\n l_n[i] -= p\n if l_n[i] == 0:\n t += 1\n p = l_n[i]\n\nprint(t)\n\t \t \t\t\t\t\t\t \t \t\t \t\t\t \t \t\t", "import sys \n\n# sys.stdin = open(\"input\",\"r\") \n\nfrom collections import *\nfrom heapq import * \nfrom functools import *\nfrom math import *\n\nn = int(input())\narr = list(map(int, input().split()))\n\n@lru_cache(None)\ndef dfs(i,pre):\n if i == n:\n return 0\n res = inf \n for cur in range(3):\n if cur > 0 and arr[i] == 0: continue\n if (cur == 0) or (pre != cur and ((arr[i]>>(cur-1))&1)):\n res = min(res, dfs(i+1,cur)+(cur==0)) \n # print(i,pre,res)\n return res\n\nprint(dfs(0,0))", "n = int(input())\r\narr = list(map(int, input().split()))\r\nmemo = [[-1 for _ in range(3)] for _ in range(n)]\r\n\r\ndef rec(i, last):\r\n if i == n:\r\n return 0\r\n \r\n if memo[i][last] != -1:\r\n return memo[i][last]\r\n \r\n rest = rec(i+1, 0) + 1\r\n if arr[i] == 0 or last == arr[i]:\r\n memo[i][last] = rest\r\n return rest\r\n if arr[i] == 3:\r\n if last == 1:\r\n act = rec(i+1, 2)\r\n elif last == 2:\r\n act = rec(i+1, 1)\r\n else:\r\n act = min(rec(i+1, 2), rec(i+1, 1))\r\n else:\r\n act = rec(i+1, arr[i])\r\n \r\n memo[i][last] = min(rest, act)\r\n return memo[i][last]\r\n \r\n \r\nprint(rec(0, 0))\r\n \r\n\r\n\r\n\r\n\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Jan 3 20:21:38 2019\r\n\r\n@author: Nishant Mittal aka nishantwrp\r\n\"\"\"\r\nn = int(input())\r\ndata = list(map(int,input().split()))\r\nans = 0\r\nprev = 0\r\ni=0\r\nwhile i<n:\r\n # I increment\r\n if data[i] is 0:\r\n ans = ans + 1\r\n prev = 0\r\n elif data[i] is 1:\r\n if prev is 1:\r\n ans += 1\r\n prev = 0\r\n else:\r\n prev = 1\r\n elif data[i] is 2:\r\n if prev is 2:\r\n ans += 1\r\n prev = 0\r\n else:\r\n prev = 2\r\n else:\r\n if prev is 1:\r\n prev = 2\r\n elif prev is 2:\r\n prev = 1\r\n else:\r\n j = i\r\n while j<n:\r\n if data[j] is not 3:\r\n i = j-1\r\n break\r\n j+=1\r\n i+=1\r\nprint(ans)", "# cook your dish here\r\nn = int(input())\r\ns = list(map(int,input().split()))\r\na=[]\r\nif s[0]==0:\r\n a.append(\"R\")\r\nelif s[0]==1:\r\n a.append(\"C\")\r\nelif s[0]==2:\r\n a.append(\"G\")\r\nelse:\r\n a.append(\"A\")\r\nfor i in range(1,n):\r\n if s[i]==0:\r\n a.append(\"R\")\r\n elif s[i]==1:\r\n if a[-1]==\"C\":\r\n a.append(\"R\")\r\n else:\r\n a.append(\"C\")\r\n elif s[i]==2:\r\n if a[-1]==\"G\":\r\n a.append(\"R\")\r\n else:\r\n a.append(\"G\")\r\n else:\r\n if a[-1]==\"G\":\r\n a.append(\"C\")\r\n elif a[-1]==\"C\":\r\n a.append(\"G\")\r\n else:\r\n a.append(\"A\")\r\nprint(a.count(\"R\"))\r\n \r\n \r\n \r\n", "n = int(input())\r\ndays = list(map(int, input().split()))\r\n\r\ncount = 0\r\nyesterday = 0\r\n\r\nfor today in days:\r\n\tif today == 0 or today == yesterday:\r\n\t count += 1\r\n\t yesterday = 0\r\n\telif today == 1 or today == 2:\r\n\t yesterday = today\r\n\telif yesterday != 0 and today == 3:\r\n\t yesterday = today - yesterday\r\n\r\nprint(count)", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndp = [[10 ** 9 for j in range(3)] for i in range(n + 1)]\r\ndp[0][0] = 0\r\n\r\nfor i in range(n):\r\n\tfor j in range(3):\r\n\t\tif dp[i][j] == 10 ** 9:\r\n\t\t\tcontinue\r\n\t\tdp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + 1)\r\n\t\tif j != 1 and (a[i] == 1 or a[i] == 3):\r\n\t\t\tdp[i + 1][1] = min(dp[i + 1][1], dp[i][j])\r\n\t\tif j != 2 and (a[i] == 2 or a[i] == 3):\r\n\t\t\tdp[i + 1][2] = min(dp[i + 1][2], dp[i][j])\r\n\r\nprint(min(dp[n]))", "from collections import defaultdict\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n a_list = list(map(int, input().split()))\r\n\r\n # 0: rest, 1: contest, 2: gym\r\n dp = [[0] * 3 for _ in range(n + 1)]\r\n\r\n for i, a in enumerate(a_list):\r\n dp[i + 1][0] = dp[i + 1][1] = dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])\r\n\r\n if a == 1 or a == 3:\r\n dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + 1, dp[i][2] + 1)\r\n if a == 2 or a == 3:\r\n dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + 1, dp[i][1] + 1)\r\n\r\n print(n - max(dp[-1][0], dp[-1][1], dp[-1][2]))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\ns = 0\r\nd = 0\r\nfor v in a:\r\n if s in [0, 3]:\r\n s = v\r\n elif s == 1:\r\n if v in [0, 1]:\r\n s = 0\r\n else:\r\n s = 2\r\n elif s == 2:\r\n if v in [0, 2]:\r\n s = 0\r\n else:\r\n s = 1\r\n if s == 0:\r\n d += 1\r\nprint(d)\r\n", "n = int(input())\narr = list(map(int, input().split()))\nres = [[0] * 3 for _ in range(n)]\nif arr[0] in [2, 3]:\n res[0][1] = 1\nif arr[0] in [1, 3]:\n res[0][2] = 1\nfor i in range(1, n):\n res[i][0] = max(res[i - 1][0], res[i - 1][1], res[i - 1][2])\n if arr[i] in [2, 3]:\n res[i][1] = max(res[i - 1][0], res[i - 1][2]) + 1\n if arr[i] in [1, 3]:\n res[i][2] = max(res[i - 1][0], res[i - 1][1]) + 1\nprint(n - max(res[n - 1][0], res[n - 1][1], res[n - 1][2]))", "from os import path\r\nimport sys,time, collections as c , math as m , pprint as p\r\nmaxx , localsys , mod = float('inf'), 0 , int(1e9 + 7) \r\nif (path.exists('input.txt')):\tsys.stdin=open('input.txt','r') ; \tsys.stdout=open('output.txt','w')\r\ninput = sys.stdin.readline\r\nn = int(input()) ; a = list(map (int , input().split()))\r\nans , prev = 0 , 3\r\nfor i in a:\r\n\tif i == 3 and prev != 3:\r\n\t\ti-=prev\r\n\telif i == prev and prev != 3:\r\n\t\ti = 0\r\n\tans += 1 if i == 0 else 0\r\n\tprev = i\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\np = list(map(int, input().split()))\r\n\r\nz = 0\r\ncol = 0\r\nfor c in p:\r\n if c == 0: ## ������\r\n z = 0\r\n elif c == 1: ## �������\r\n if z == 1:\r\n z = 0\r\n else:\r\n z = 1\r\n col += 1\r\n elif c == 2: ## ��������\r\n if z == 2:\r\n z = 0\r\n else:\r\n z = 2\r\n col += 1\r\n elif c == 3: ## ���\r\n if z == 0:\r\n z = 3\r\n elif z == 1:\r\n z = 2\r\n elif z == 2:\r\n z = 1\r\n col += 1\r\n\r\nprint(n - col)", "from sys import stdin,stdout\r\n\r\nn = int(stdin.readline())\r\n#a: [(gym,contest)]\r\na = list(map(lambda x:\r\n (False,False) if x==\"0\" else (False,True) if x==\"1\" else (True,False) if x==\"2\" else (True,True)\r\n ,stdin.readline().rstrip().split(\" \")))\r\n\r\n\r\ndp = [[100,100,100] for _ in range(n)]\r\n\r\ndp[0][0] = 1\r\nif a[0][0]:\r\n dp[0][1] = 0\r\nif a[0][1]:\r\n dp[0][2] = 0\r\n\r\nfor i in range(1,n):\r\n if a[i][0]:\r\n dp[i][1] = min(dp[i-1][2],dp[i-1][0])\r\n if a[i][1]:\r\n dp[i][2] = min(dp[i-1][1],dp[i-1][0])\r\n dp[i][0] = min(dp[i-1][1],min(dp[i-1][2],dp[i-1][0]))+1\r\n \r\nstdout.write(\"{}\".format(min(dp[n-1][1],min(dp[n-1][2],dp[n-1][0]))))", "import sys\r\ninput = sys.stdin.readline\r\nread_tuple = lambda _type: map(_type, input().split(' '))\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n a = list(read_tuple(int))\r\n dp = [[0 for _ in range(n)] for i in range(3)]\r\n if a[0] == 1:\r\n dp[1][0] = 1\r\n elif a[0] == 2:\r\n dp[2][0] = 1\r\n elif a[0] == 3:\r\n dp[1][0] = 1\r\n dp[2][0] = 1\r\n for i in range(1, n):\r\n dp[0][i] = max((dp[0][i - 1], dp[1][i - 1], dp[2][i - 1]))\r\n if a[i] in (1, 3):\r\n dp[1][i] = max((dp[0][i - 1] + 1, dp[2][i - 1] + 1))\r\n if a[i] in (2, 3):\r\n dp[2][i] = max((dp[0][i - 1] + 1, dp[1][i - 1] + 1))\r\n print(n - max((dp[0][-1], dp[1][-1], dp[2][-1])))\r\n\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n ", "dict={1:\"011\",2:\"101\",3:\"111\",0:\"001\"}\r\nINF=99**9\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nmemory=[]\r\nmemory.append([INF,INF,INF])\r\npo=dict[l[0]]\r\nif po[0] == \"1\":\r\n memory[0][0]=0\r\nif po[1] == \"1\":\r\n memory[0][1]=0\r\nif po[2]==\"1\":\r\n memory[0][2]=1\r\n# 0c 1g 2r\r\nfor i in range(1,n):\r\n t=l[i]\r\n po=dict[t]\r\n memory.append([INF,INF,INF])\r\n if po[0] == \"1\":\r\n memory[i][0]=min(memory[i-1][1],memory[i-1][2])\r\n\r\n if po[1] == \"1\":\r\n memory[i][1]=min(memory[i-1][0],memory[i-1][2])\r\n\r\n if po[2] == \"1\":\r\n memory[i][2]=min(memory[i-1][1],memory[i-1][2],memory[i-1][0])+1\r\n\r\n\r\n\r\n\r\nprint(min(memory[-1]))\r\n", "import sys\r\nfrom typing import Callable\r\n\r\n\r\n\r\ndef main() -> None:\r\n read: Callable[[], str] = sys.stdin.readline\r\n n = int(read())\r\n values = [int(i) for i in read().split()]\r\n matrix: list[list[int]] = [[0 for _ in range(3)] for _ in range(n + 1 )]\r\n\r\n for row in range(1, len(matrix)):\r\n day_value = values[row - 1]\r\n max_prev_value = max(matrix[row - 1][0], matrix[row - 1][1], matrix[row - 1][2])\r\n # We cannot do anything\r\n matrix[row][0] = max_prev_value\r\n # If we participate in context today, we either consider the previous date we took a contest, or the maximum of\r\n # the days we did not do anything OR did a contest + 1 bc is not repeated\r\n if day_value == 1 or day_value == 3:\r\n matrix[row][1] = max(matrix[row - 1][1], max(matrix[row - 1][0], matrix[row - 1][2] + 1))\r\n else:\r\n # IF we cannot participate in contest today, then there is nothing to do\r\n matrix[row][1] = max_prev_value\r\n if day_value == 2 or day_value == 3:\r\n matrix[row][2] = max(matrix[row - 1][2], max(matrix[row - 1][0], matrix[row - 1][1] + 1))\r\n else:\r\n matrix[row][2] = max_prev_value\r\n\r\n\r\n print(n - max(matrix[-1][0], matrix[-1][1], matrix[-1][2]))\r\n\r\nif __name__ == '__main__':\r\n main()", "n=int(input())\r\ndias=list(map(int,input().strip().split(\" \")))\r\ncont=0\r\nlargo=len(dias)\r\ni=1\r\nwhile i<largo:\r\n\tif dias[i]==3:\r\n\t\tif dias[i-1]==2:\r\n\t\t\tdias[i]=1\r\n\t\tif dias[i-1]==1:\r\n\t\t\tdias[i]=2\r\n\tif dias[i]==1 or dias[i]==2:\r\n\t\tif dias[i]==dias[i-1]:\r\n\t\t\tdias[i]=0\r\n\ti+=1\r\nj=largo-2\r\nwhile j>=0:\r\n\tif dias[j]==3:\r\n\t\tif dias[j+1]==2:\r\n\t\t\tdias[j]=1\r\n\t\tif dias[j+1]==1:\r\n\t\t\tdias[j]=2\r\n\tj-=1\r\nfor x in dias:\r\n\tif x==0:\r\n\t\tcont+=1\r\nprint(cont)", "input()\r\narr = map(int, input().split(' '))\r\nans = 0\r\nprev = 3\r\nfor i in arr:\r\n\tif(i == prev and prev != 3):\r\n\t\ti = 0\r\n\telif(i == 3 and prev != 3):\r\n\t\ti -= prev\r\n\tif(i == 0):\r\n\t\tans += 1\r\n\tprev = i\r\nprint(ans)", "a=int(input())\r\nb=input().split()\r\nflag=0\r\nsum=0\r\nfor i in range (0,a):\r\n if int(b[i])==0:\r\n sum+=1\r\n flag=0\r\n elif int(b[i])==1 or int(b[i])==2:\r\n if int(b[i])==flag:\r\n sum=sum+1\r\n flag=0\r\n else:\r\n flag=int(b[i])\r\n elif int(b[i])==3:\r\n flag=3-flag\r\nprint(sum)", "n = int(input())\r\ns = list(map(int,input().split()))\r\n\r\n\r\nd = [[0 for i in range(n+1)] for j in range(3)]\r\n\r\n\r\n\r\n \r\n \r\nfor i in range(1,n+1):\r\n \r\n #print('-------',s[i-1],'------------')\r\n d[0][i] = max( d[0][i-1], d[1][i-1], d[2][i-1] )\r\n if s[i-1] == 1 or s[i-1] == 3:\r\n d[1][i] = max ( d[2][i-1]+1 , d[0][i-1]+1)\r\n if s[i-1] == 2 or s[i-1] == 3:\r\n d[2][i] = max ( d[1][i-1]+1 , d[0][i-1]+1)\r\n''' \r\nfor i in range(3): \r\n print(d[i])\r\n'''\r\n \r\n \r\nprint(n - max(d[0][-1],d[1][-1],d[2][-1]))\r\n \r\n \r\n\r\n \r\n\r\n", "import math\r\nimport sys\r\n\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\ndef I():\r\n return input()\r\n\r\n\r\ndef ii():\r\n return int(input())\r\n\r\n\r\ndef li():\r\n return list(input().split())\r\n\r\n\r\ndef mi():\r\n return map(int, input().split())\r\n\r\n\r\ndef gmi():\r\n return map(lambda x: int(x) - 1, input().split())\r\n\r\n\r\ndef lgmi():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n\r\n\r\ndef lii():\r\n return list(map(int, input().split()))\r\n\r\nn = ii()\r\na = lii()\r\ninf = float('inf')\r\ndp = [[inf] * 3 for i in range(n + 1)]\r\ndp[0][2] = 0\r\nfor i in range(n):\r\n if a[i] >> 1 & 1:\r\n dp[i + 1][1] = min(dp[i + 1][1],dp[i][0],dp[i][1] + 1,dp[i][2])\r\n if a[i] & 1:\r\n dp[i + 1][0] = min(dp[i + 1][0],dp[i][1],dp[i][0] + 1,dp[i][2])\r\n dp[i + 1][2] = min(dp[i + 1][2],min(dp[i]) + 1)\r\nprint(min(dp[-1]))\r\n\r\n", "# Problem: A. Vacations\r\n# Contest: Codeforces - Codeforces Round 363 (Div. 1)\r\n# URL: https://codeforces.com/contest/698/problem/A\r\n# Memory Limit: 256 MB\r\n# Time Limit: 1000 ms\r\n\r\nimport sys\r\nimport random\r\nfrom types import GeneratorType\r\nimport bisect\r\nimport io, os\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom contextlib import redirect_stdout\r\nfrom itertools import *\r\nfrom array import *\r\nfrom functools import lru_cache, reduce\r\nfrom heapq import *\r\nfrom math import sqrt, gcd, inf\r\n\r\nif sys.version >= '3.8': # ACW没有comb\r\n from math import comb\r\n\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\nRS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())\r\nRILST = lambda: list(RI())\r\nDEBUG = lambda *x: sys.stderr.write(f'{str(x)}\\n')\r\n# print = lambda d: sys.stdout.write(str(d) + \"\\n\") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法,需要print(' '.join(map(str, p))),确实会快。\r\n\r\nDIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 右下左上\r\nDIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),\r\n (-1, 1)] # →↘↓↙←↖↑↗\r\nRANDOM = random.randrange(2 ** 62)\r\nMOD = 10 ** 9 + 7\r\n# MOD = 998244353\r\nPROBLEM = \"\"\"\r\n\"\"\"\r\n\r\n\r\n# ms\r\ndef solve():\r\n n, = RI()\r\n a = RILST()\r\n f = [0, 0, 0]\r\n for v in a:\r\n g = [min(f)+1, inf, inf]\r\n if v & 1:\r\n g[1] = min(f[0], f[2])\r\n if v & 2:\r\n g[2] = min(f[0], f[1])\r\n f = g\r\n print(min(f))\r\n\r\n\r\nif __name__ == '__main__':\r\n t = 0\r\n if t:\r\n t, = RI()\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "\r\nn=int(input())\r\nL=list(map(int,input().split()))\r\ndef pasa(x,y):\r\n return (x==1 and y==2) or (x==2 and y==1)\r\nif(n==1):\r\n print(L.count(0))\r\nelse:\r\n cont=0\r\n for k in range(1,n):\r\n if(L[k]!=0):\r\n if(not pasa(L[k],L[k-1])):\r\n if(L[k]==3 and not L[k-1]==3):\r\n L[k]-=L[k-1]\r\n elif(L[k]==L[k-1] and L[k]!=3):\r\n L[k]=0\r\n print(L.count(0))", "n = int(input())\r\na = list(map(int , input().split()))\r\nk = 0\r\npredok = 0\r\nfor i in range(len(a)):\r\n if a[i] == 0 or a[i] == predok:\r\n k+=1\r\n predok = 0\r\n elif a[i] == 3:\r\n if predok!=0:\r\n predok = 3 - predok\r\n else:\r\n predok =a[i]\r\nprint(k)\r\n\r\n ", "import sys\r\ndef li(): return list(map(int, sys.stdin.readline().split()))\r\ndef inp(): return int(sys.stdin.readline())\r\nfrom collections import Counter as cnt\r\nimport operator as op\r\nfrom functools import reduce\r\n \r\ndef ncr(n,r):\r\n r=min(r,n-r)\r\n numer=reduce(op.mul,range(n,n-r,-1),1)\r\n denom=reduce(op.mul,range(1,r+1),1)\r\n return numer//denom\r\n \r\ndef solve():\r\n n=inp()\r\n a=li()\r\n p,ans=3,0\r\n for i in a:\r\n if i==p and p!=3:\r\n i=0\r\n elif i==3 and p!=3:\r\n i-=p\r\n if i==0:\r\n ans+=1\r\n p=i\r\n print(ans)\r\n\t\r\nfor pratyush in range(1):\r\n\tsolve()", "\r\nn=int(input())\r\n*l,=map(int,input().split())\r\n\r\np=c=0\r\n\r\nfor i in l:\r\n if i==0:\r\n c+=1\r\n p=i\r\n \r\n if i==1:\r\n if p==1:\r\n p=0\r\n c+=1\r\n else:\r\n p=1\r\n\r\n if i==2:\r\n if p==2:\r\n p=0\r\n c+=1\r\n else:\r\n p=2 \r\n if i==3:\r\n if p==1:\r\n p=2\r\n continue\r\n if p==2:\r\n p=1\r\n \r\n if p==0:\r\n p=3\r\nprint(c) ", "input()\r\ninf=1<<9\r\nS=0,0,0\r\nfor a in map(int,input().split()):S=1+min(S),min(S[0],S[2])if a>>1 else inf,min(S[0],S[1])if 1&a else inf\r\nprint(min(S))", "import re\r\n\r\n\r\ndef solve(lst):\r\n dp=[[0,0,0]]\r\n for i in range(len(lst)):\r\n if lst[i]==0:\r\n dp.append([1,0,0])\r\n elif lst[i]==1:\r\n if dp[i][2]==1:\r\n dp.append([1,0,0])\r\n else:\r\n dp.append([0,0,1])\r\n elif lst[i]==2:\r\n if dp[i][1]==1:\r\n dp.append([1,0,0])\r\n else:\r\n dp.append([0,1,0])\r\n elif lst[i]==3:\r\n if dp[i][1]==1:\r\n dp.append([0,0,1])\r\n elif dp[i][2]==1:\r\n dp.append([0,1,0])\r\n else:\r\n dp.append([0,2,2])\r\n count=0\r\n for r in dp:\r\n count+=1 if r[0]==1 else 0\r\n return count\r\n\r\n\r\n \r\nn=int(input())\r\nlst=list(map(int,input().split()))[:n]\r\nprint(solve(lst))", "if __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int, input().strip().split()))\r\n INF = float(\"inf\")\r\n dp = [[0] * 3 for _ in range(n + 1)]\r\n for i in range(n):\r\n dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])\r\n if a[i] == 1 or a[i] == 3: # contest\r\n dp[i + 1][1] = max(dp[i][0], dp[i][2]) + 1\r\n if a[i] == 2 or a[i] == 3: # gym\r\n dp[i + 1][2] = max(dp[i][0], dp[i][1]) + 1\r\n print(n - max(dp[n]))", "n = int(input())\na = list(map(int, input().split()))\nprev = ans = 0\nfor i in a:\n if i == 0:\n prev = 0\n ans += 1\n if i == 1:\n if prev in (0, 2):\n prev = 1\n else:\n prev = 0\n ans += 1\n if i == 2:\n if prev in (0, 1):\n prev = 2\n else:\n prev = 0\n ans += 1\n if i == 3:\n prev = {0: 0, 1: 2, 2: 1}[prev]\n # print((prev, ans))\n# print(\"answer is %d\" % ans)\nprint(ans)", "n = int(input())\n\na = list(map(int, input().split()))\n\n\nmem = {}\ndef solve(i, previous):\n if i == n:\n return 0\n if a[i] == 0 or a[i] == previous:\n return solve(i+1, 0) + 1\n \n elif a[i] == 3:\n if previous == 0:\n return solve(i+1, 0)\n return solve(i+1, 2 if previous == 1 else 1)\n return solve(i+1, a[i])\n \n\nprint(solve(0, 0))", "from sys import stdin\r\nfrom math import inf\r\n\r\nn = int(stdin.readline())\r\ndp = [list([inf for i in range(4)]) for j in range(n+1)]\r\ndp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0\r\na = [0] + list(map(int, stdin.readline().split()))\r\nfor i in range(1, n+1):\r\n dp[i][0] = min(dp[i-1]) + 1\r\n if a[i] in (1, 3):\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n if a[i] in (2, 3):\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n if a[i] == 3:\r\n dp[i][3] = dp[i-1][0]\r\nprint(min(dp[n]))", "n=int(input())\r\ndays=list(map(int,input().split()))\r\nq=[[0,0,0] for g in range(n)]\r\nif days[0]:\r\n if days[0]==3:\r\n q[0][1]=1\r\n q[0][2]=1\r\n else: q[0][days[0]]=1\r\nfor i in range(1,n):\r\n d=days[i]\r\n q[i][0]=max(q[i-1])\r\n if d==1 or d==3: q[i][1]=max(q[i-1][2],q[i-1][0])+1\r\n if d==2 or d==3: q[i][2]=max(q[i-1][1],q[i-1][0])+1 \r\nprint(n-max(q[n-1]))\r\n ", "n = int(input())\r\nline = [int(x) for x in input().split()]\r\nd = [0]*3\r\nfor i in line:\r\n d_1 = d[:]\r\n d[0] = min(d_1) + 1\r\n if i == 1:\r\n d[1] = min(d_1[0], d_1[2])\r\n d[2] = 10**6\r\n elif i == 2:\r\n d[2] = min(d_1[0], d_1[1])\r\n d[1] = 10**6\r\n elif i == 3:\r\n d[1] = min(d_1[0], d_1[2])\r\n d[2] = min(d_1[0], d_1[1])\r\n elif i == 0:\r\n d[1] = 10**6\r\n d[2] = 10**6\r\nprint(min(d))\r\n", "from sys import stdin,stdout\r\nnmbr = lambda: int(input())\r\nlst = lambda: list(map(int, input().split()))\r\n# 0=G'C'\r\n# 1=G'C\r\n# 2=GC'\r\n# 3=GC\r\nPI=float('inf')\r\ndef fn(pos,state):# state : 0->Rest, 1->Contest, 2->Gym\r\n if pos==n:return 0\r\n if a[pos]==0:\r\n ans=1+fn(pos+1,0)\r\n elif a[pos]==1:\r\n contest=rest=PI\r\n if state!=1:contest=fn(pos+1,1)\r\n rest=1+fn(pos+1,0)\r\n ans=min(contest,rest)\r\n elif a[pos]==2:\r\n gym=rest=PI\r\n if state!=2:gym=fn(pos+1,2)\r\n rest=1+fn(pos+1,0)\r\n ans=min(gym,rest)\r\n else:\r\n gym=contest=PI\r\n if state!=1:contest=fn(pos+1,1)\r\n if state!=2:gym=fn(pos+1,2)\r\n ans=min(gym,contest)\r\n return ans\r\n\r\n\r\nfor _ in range(1):#nmbr()):\r\n n=nmbr()\r\n a=lst()\r\n dp=[[PI for i in range(4)] for _ in range(n+1)]\r\n dp[0][0]=dp[0][1]=dp[0][2]=dp[0][3]=0\r\n for i in range(n):\r\n for j in range(4):\r\n if a[i] == 0:\r\n dp[i+1][0] = min(dp[i+1][0],1 + dp[i][j])\r\n elif a[i] == 1:\r\n if j != 1:dp[i+1][1]=min(dp[i+1][1],dp[i][j]) #contest = fn(pos + 1, 1)\r\n dp[i+1][0]= min(dp[i+1][0],1+dp[i][j])#rest = 1 + fn(pos + 1, 0)\r\n elif a[i] == 2:\r\n if j != 2:dp[i+1][2]=min(dp[i+1][2],dp[i][j])# gym = fn(pos + 1, 2)\r\n dp[i+1][0]=min(dp[i+1][0],1+dp[i][j])# rest = 1 + fn(pos + 1, 0)\r\n else:\r\n if j != 1:dp[i+1][1]=min(dp[i+1][1],dp[i][j])# contest = fn(pos + 1, 1)\r\n if j != 2:dp[i+1][2]=min(dp[i+1][2],dp[i][j])# gym = fn(pos + 1, 2)\r\n print(min(dp[n]))\r\n\r\n\r\n", "from collections import Counter, defaultdict, deque\nfrom bisect import bisect_left, bisect_right\nfrom heapq import heapify, heappush, heappop\nfrom functools import cache, lru_cache\n\ndef solve():\n n = int(input())\n arr = list(map(int, input().split()))\n\n @lru_cache\n def recurr(i, prev):\n\n # Base Case\n if i < 0:\n return 0\n flags = [0, 0]\n\n if arr[i] == 1:\n flags[1] = 1\n elif arr[i] == 2:\n flags[0] = 1\n elif arr[i] == 3:\n flags = [1, 1]\n\n # Try to do either gym or contest\n res = recurr(i - 1, -1) + 1\n if flags[0] and prev != 1:\n res = min(res, recurr(i - 1, 1))\n if flags[1] and prev != 2:\n res = min(res, recurr(i - 1, 2))\n\n return res\n print(recurr(n - 1, -1))\n\n\nsolve()\n", "n = int(input())\r\ns = list(map(int, input().split()))\r\nfor i in range(1, n):\r\n if s[i] == 3 and s[i-1] == 1:\r\n s[i] = 2\r\n elif s[i] == 3 and s[i-1] == 2:\r\n s[i] = 1\r\n elif (s[i] == 2 and s[i-1] == 2) or (s[i] == 1 and s[i-1] == 1):\r\n s[i] = 0\r\nprint(s.count(0))", "n=int(input())\r\na = [int(x) for x in input().split()]\r\nc = 0\r\nlast = 0\r\nfor i in range(n):\r\n if a[i]==0 or a[i]==last:\r\n c+=1\r\n last = 0\r\n \r\n elif a[i]==3 :\r\n \r\n if(last!=0):\r\n \r\n last = 3 - last\r\n \r\n else:\r\n \r\n last=a[i]\r\n\r\nprint(c)", "from sys import stdin, stdout\r\ncin = stdin.readline\r\ncout = stdout.write\r\n\r\nn = int(cin())\r\na = list(map(int, cin().split()))\r\n\r\nf, day = 0, 0\r\n\r\nfor i in a:\r\n\tif i == 0:\r\n\t\tday += 1\r\n\t\tf = i\r\n\telif i == 1:\r\n\t\t#day += f == 2\r\n\t\t#f = (f != 2) * 2\r\n\t\tif f == 2:\r\n\t\t\tday += 1\r\n\t\t\tf = 0\r\n\t\telse:\r\n\t\t\tf = 2\r\n\telif i == 2:\r\n\t\t#day += f == 1\r\n\t\t#f = f != 1\r\n\t\tif f == 1:\r\n\t\t\tday += 1\r\n\t\t\tf = 0\r\n\t\telse:\r\n\t\t\tf = 1\r\n\telse:\r\n\t\t#f = (f==0)*3 + (f==1)*2 + f==2\r\n\t\tif f == 0:\r\n\t\t\tf = 3\r\n\t\telif f == 1:\r\n\t\t\tf = 2\r\n\t\telif f == 2:\r\n\t\t\tf = 1\r\n\t\telse:\r\n\t\t\tf = 0\r\ncout(str(day))\r\n\r\n#3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 \r\n#3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "n = int(input())\r\ndays = list(map(int, input().split()))\r\ndp = [[999,999,999] for x in range(100)]\r\ndp[0][0] = 1\r\nif (days[0] == 1):\r\n dp[0][1] = 0\r\nelif (days[0] == 2):\r\n dp[0][2] = 0\r\nelif days[0] == 3:\r\n dp[0][1] = 0\r\n dp[0][2] = 0\r\n\r\nfor i in range(1, n):\r\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\r\n if (days[i] == 1):\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n elif days[i] == 2:\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\n elif days[i] == 3:\r\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\r\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\r\nprint(min(dp[n-1][0], dp[n-1][1], dp[n-1][2]))\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nimport functools\r\[email protected]_cache(maxsize=None)\r\ndef dp(i,state):\r\n if i==n:\r\n return 0\r\n \r\n if state==0:\r\n if a[i]==0:\r\n return 1+dp(i+1,0)\r\n elif a[i]==1:\r\n return min(1+dp(i+1,0),dp(i+1,1))\r\n elif a[i]==2:\r\n return min(1+dp(i+1,0),dp(i+1,2))\r\n else:\r\n return min(1+dp(i+1,0),dp(i+1,1),dp(i+1,2))\r\n elif state==1:\r\n if a[i]==0:\r\n return 1+dp(i+1,0)\r\n elif a[i]==1:\r\n return (1+dp(i+1,0))\r\n elif a[i]==2:\r\n return min(1+dp(i+1,0),dp(i+1,2))\r\n else:\r\n return min(1+dp(i+1,0),dp(i+1,2))\r\n elif state==2:\r\n if a[i]==0:\r\n return 1+dp(i+1,0)\r\n elif a[i]==1:\r\n return min(1+dp(i+1,0),dp(i+1,1))\r\n elif a[i]==2:\r\n return (1+dp(i+1,0))\r\n else:\r\n return min(1+dp(i+1,0),dp(i+1,1))\r\n else:\r\n return 1+dp(i+1,0)\r\nprint(dp(0,0))\r\n", "n = int(input().strip())\narr = list(map(int, input().strip().split()))\nans = 0\nprev = 3\nfor i in arr:\n\tif i == prev and prev != 3:\n\t\ti = 0\n\telif i == 3 and prev != 3:\n\t\ti -= prev\n\tif i == 0:\n\t\tans += 1\n\tprev = i\nprint(ans)", "n=int(input())\r\na=[0]+list(map(int,input().split()))\r\nresult=0\r\nfor i in range(1,n+1):\r\n if a[i]==0:\r\n result+=1\r\n elif a[i]==3:\r\n a[i]=3-a[i-1]\r\n else:\r\n if a[i]==a[i-1]:\r\n a[i]=0\r\n result+=1\r\nprint(result)", "n = int(input())\nline = input().split()\ngym, cont, rest = 0, 0, 0\nfor value in line:\n if value == '0':\n rest += 1\n cont = 0\n gym = 0\n continue\n\n elif value == '1':\n if cont == 1:\n rest += 1\n cont = 0\n gym = 0\n continue\n cont = 1\n gym = 0\n\n elif value == '2':\n if gym == 1:\n rest += 1\n cont = 0\n gym = 0\n continue\n gym = 1\n cont = 0\n else:\n if cont == 1 and gym == 1:\n cont, gym = 0,0\n elif cont == 1:\n gym = 1\n cont = 0\n elif gym == 1:\n cont = 1\n gym = 0\n\nprint(rest)\n\t\t\t \t\t \t\t\t \t \t \t\t \t \t\t", "n = int(input())\r\nl = list(map(int, input().split()))\r\nmin_time = 0\r\nx = 0\r\nfor i in range(len(l)):\r\n if l[i] == 0 or l[i] == x:\r\n min_time += 1\r\n x = 0\r\n elif l[i] == 3:\r\n if x != 0:\r\n x = 3 - x\r\n else:\r\n x = l[i]\r\nprint(min_time)\r\n", "for t in range(1):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n prev=arr[0]\r\n if prev==0:\r\n count=1\r\n else:\r\n count=0\r\n for ele in range(1,n):\r\n i=arr[ele]\r\n if i==0:\r\n count+=1\r\n prev=0\r\n continue\r\n elif i==1:\r\n if prev==1:\r\n prev=0\r\n count+=1\r\n continue\r\n else:\r\n prev=1\r\n continue\r\n elif i==2:\r\n if prev==2:\r\n prev=0\r\n count+=1\r\n continue\r\n else:\r\n prev=2\r\n continue\r\n elif i==3:\r\n if prev==1:\r\n prev=2\r\n continue\r\n elif prev==2:\r\n prev=1\r\n continue\r\n else:\r\n prev=0\r\n continue\r\n print(count)", "n = int(input())\na = list(map(int, input().split()))\n\n# Rest, Contest, Sport\ndp = []\nfor i in range(n):\n dp.append([0,0,0])\n\n\nfor i in range(n):\n if a[i] == 0:\n dp[i][0] = min(dp[i-1]) + 1\n dp[i][1] = min(dp[i-1]) + 1\n dp[i][2] = min(dp[i-1]) + 1\n if a[i] == 1:\n dp[i][0] = min(dp[i-1]) + 1\n min_compat = min(dp[i-1][0], dp[i-1][2])\n if min_compat <= dp[i-1][1]:\n dp[i][1] = min_compat\n else:\n dp[i][1] = dp[i-1][1] + 1\n dp[i][2] = min(dp[i-1]) + 1\n if a[i] == 2:\n dp[i][0] = min(dp[i-1]) + 1\n min_compat = min(dp[i-1][0], dp[i-1][1])\n dp[i][1] = min(dp[i-1]) + 1\n if min_compat <= dp[i-1][2]:\n dp[i][2] = min_compat\n else:\n dp[i][2] = dp[i-1][2] + 1\n if a[i] == 3:\n dp[i][0] = min(dp[i-1]) + 1\n min_compat_1 = min(dp[i-1][0], dp[i-1][2])\n if min_compat_1 <= dp[i-1][1]:\n dp[i][1] = min_compat_1\n else:\n dp[i][1] = dp[i-1][1] + 1\n\n min_compat = min(dp[i-1][0], dp[i-1][1])\n if min_compat <= dp[i-1][2]:\n dp[i][2] = min_compat\n else:\n dp[i][2] = dp[i-1][2] + 1\n\nprint(min(dp[-1]))\n", "from sys import stdin,stdout\r\nnmbr=lambda:int(stdin.readline())\r\nlst=lambda:list(map(int,stdin.readline().split()))\r\n# 0=G'C'\r\n# 1=G'C\r\n# 2=GC'\r\n# 3=GC\r\nPI=float('inf')\r\nfor _ in range(1):#nmbr():\r\n n=nmbr()\r\n a=lst()\r\n dp=[[0 for _ in range(3)] for _ in range(n)]\r\n dp[0][0]=1\r\n for i in range(1,n):\r\n dp[i][0]=1+min(dp[i-1][0],dp[i-1][1] if a[i-1] in [2,3] else PI,dp[i-1][2] if a[i-1] in [1,3] else PI)\r\n if a[i] in [2,3]:dp[i][1]=min(dp[i-1][0],dp[i-1][2] if a[i-1] in [1,3] else PI)\r\n if a[i] in [1,3]:dp[i][2]=min(dp[i-1][0],dp[i-1][1] if a[i-1] in [2,3] else PI)\r\n print(min(dp[n-1][0],dp[n-1][1] if a[-1] in [2,3] else PI,dp[n-1][2] if a[-1] in [1,3] else PI))", "n = int(input()) \r\nzz = list(map(int, input().split())) \r\nk = 0 \r\notv = n\r\nfor gg in zz:\r\n if gg == 0:\r\n k = 0\r\n elif gg == 1:\r\n if k == 1:\r\n k = 0 \r\n else: \r\n k = 1 \r\n otv -= 1 \r\n elif gg == 2:\r\n if k == 2: \r\n k = 0 \r\n else: \r\n k = 2 \r\n otv -= 1 \r\n elif gg == 3:\r\n if k == 0: \r\n k = 3 \r\n elif k == 1: \r\n k = 2\r\n elif k == 2: \r\n k = 1 \r\n otv -= 1 \r\n \r\nprint(otv)", "from sys import stdin, maxsize\r\nfrom collections import defaultdict\r\ndef rei():\r\n return list(map(int, stdin.readline().strip().split(' ')))\r\ndef res():\r\n return stdin.readline().rstrip()\r\n\r\ndef prno(): print('NO')\r\n\r\ndef pryes(): print('YES')\r\n\r\ndef solve():\r\n n=rei()[0]\r\n a=rei()\r\n dp=[[maxsize for _ in range(3)] for _ in range(n+1)]\r\n dp[0][0], dp[0][1], dp[0][2] = 1, 0, 0\r\n for i in range(1, n+1):\r\n c=a[i-1]\r\n dp[i][0]=min(dp[i-1])+1\r\n if c in [1, 3]:\r\n dp[i][1]=min(dp[i-1][0], dp[i-1][2])\r\n if c in [2, 3]:\r\n dp[i][2]=min(dp[i-1][0], dp[i-1][1])\r\n print(min(dp[n]))\r\n\r\nif __name__ == '__main__':\r\n solve()", "n = int(input())\narr = list(map(int,input().split(' ')))\nMAX = 1000000\ndp = []\nfor i in range(n):\n dp.append([MAX]*3)\n\n# 0 rest 1 gym 2 contest\nif(arr[0] == 0):\n dp[0][0] = 1\nelif(arr[0] == 1):\n dp[0][0] = 1\n dp[0][2] = 0\nelif(arr[0] == 2):\n dp[0][0] = 1\n dp[0][1] = 0\nelse:\n dp[0][0] = 1\n dp[0][1] = 0\n dp[0][2] = 0\n\nfor i in range(1,n):\n if(arr[i] == 0):\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\n elif(arr[i] == 1):\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\n elif(arr[i] == 2):\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\n else:\n dp[i][0] = 1 + min(dp[i-1][0], dp[i-1][1], dp[i-1][2])\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\n\n\nprint(min(dp[n-1][0], dp[n-1][1], dp[n-1][2]))\n", "n = int(input())\r\na = list(map(int, input().split()))\r\np, c = 3, 0\r\nfor i in range(n):\r\n if(a[i] == p and a[i] != 3):\r\n a[i] = 0 \r\n elif(a[i] == 3 and p != 3):\r\n a[i] = a[i] - p\r\n if(a[i] == 0):\r\n c += 1\r\n p = a[i]\r\nprint(c)\r\n ", "n = int(input())\narr = list(map(int, input().split()))\n\ndp = [[float('inf')] * 3 for _ in range(101)]\n\ndp[0][0] = 1\n\nif arr[0] == 1 or arr[0] == 3:\n dp[0][1] = 0\n\nif arr[0] == 2 or arr[0] == 3:\n dp[0][2] = 0\n\nfor idx in range(1, n):\n dp[idx][0] = 1 + min(dp[idx - 1][0], dp[idx - 1][1], dp[idx - 1][2])\n\n if arr[idx] == 1 or arr[idx] == 3:\n dp[idx][1] = min(dp[idx - 1][0], dp[idx - 1][2])\n\n if arr[idx] == 2 or arr[idx] == 3:\n dp[idx][2] = min(dp[idx - 1][0], dp[idx - 1][1])\n\nprint(min(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]))", "n=int(input())\r\nlst=list(map(int,input().split()))\r\ncnt=0\r\nfor i in range (0,n):\r\n if lst[i]==0:\r\n cnt+=1\r\n if i==n-1:\r\n break\r\n else:\r\n if lst[i]==1:\r\n if lst[i+1]==1:\r\n lst[i+1]=0\r\n if lst[i+1]==3:\r\n lst[i+1]=2\r\n elif lst[i]==2:\r\n if lst[i+1]==2:\r\n lst[i+1]=0\r\n if lst[i+1]==3:\r\n lst[i+1]=1\r\n elif lst[i]==3:\r\n continue\r\nprint(cnt)", "n = int(input())\r\na = list(map(int, input().split()))\r\n \r\nINF = 10 ** 9\r\n \r\ndef get_t(n, t):\r\n return n & t\r\n \r\nres = [[0, 0, 0] for _ in range(n)]\r\nres[-1] = [1, 0 if get_t(a[-1], 1) else 1, 0 if get_t(a[-1], 2) else 1]\r\n \r\nfor i in range(n - 2, -1, -1):\r\n res[i] = [\r\n 1 + min(res[i + 1]),\r\n min(res[i + 1][0], res[i + 1][2]) if get_t(a[i], 1) else INF,\r\n min(res[i + 1][0], res[i + 1][1]) if get_t(a[i], 2) else INF\r\n ]\r\n \r\n \r\nprint(min(res[0]))", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = input()[:-1].replace(' ','')\r\n\r\nd = -1\r\nc = 0\r\nfor i in w:\r\n if i == '0':\r\n c += 1\r\n d = -1\r\n elif i == '1':\r\n if d == -1 or d == 1:\r\n d = 0\r\n else:\r\n d = -1\r\n c += 1\r\n elif i == '2':\r\n if d == -1 or d == 0:\r\n d = 1\r\n else:\r\n d = -1\r\n c += 1\r\n elif i == '3':\r\n if d == 1:\r\n d = 0\r\n elif d == 0:\r\n d = 1\r\n\r\nprint(c)", "n = int(input())\r\nvals = list(map(int, input().split()))\r\ndays = [(0,(int)(vals[0] & 1 == 1),(int)(vals[0] & 2 == 2))]\r\nfor i in range(1,n):\r\n zal = vals[i] & 1 == 1\r\n cont = vals[i] & 2 == 2\r\n days.append(( max(days[i-1]), (max(days[i-1][0],days[i-1][2]) + 1) if zal else 0,\r\n (max(days[i-1][0],days[i-1][1]) + 1) if cont else 0))\r\n\r\nprint(n-max(days[n-1]))", "n = int(input())\r\narr = input().split()\r\nfreeDays = 0\r\nprev = ''\r\ni = 0\r\nwhile i < n:\r\n if arr[i] == '0':\r\n freeDays += 1\r\n prev = '0'\r\n if arr[i] == '1' or arr[i] == '2':\r\n if arr[i] == prev:\r\n freeDays += 1\r\n prev = '0'\r\n else:\r\n prev = arr[i]\r\n if arr[i] == '3':\r\n if prev == '1':\r\n prev = '2'\r\n elif prev == '2':\r\n prev = '1'\r\n i += 1\r\nprint(freeDays)\r\n", "from functools import lru_cache\nn, = map(int, input().split())\nA = list(map(int, input().split()))\n\n# (rest, rest), (gym, rest), (rest, comp)\ndp = [[float(\"inf\")] * 3 for _ in range(n+1)]\ndp[0] = [0,float(\"inf\"),float(\"inf\")]\n\nfor i in range(1,n+1):\n a = A[i-1] # what is open today?\n dp[i][0] = min(dp[i-1]) + 1\n if a == 1 or a == 3:\n dp[i][2] = min(dp[i-1][0], dp[i-1][1])\n if a == 2 or a == 3:\n dp[i][1] = min(dp[i-1][0], dp[i-1][2])\n\nprint(min(dp[n]))\n\n\n", "size = int(input())\ndays = [int(a) for a in input().split()]\n\n\ndaysoff = 0\nyesterday = 0\n\n\nif days[0] == 0:\n daysoff += 1\n yesterday = 0\nelif days[0] == 3:\n yesterday = 0\nelse:\n yesterday = days[0]\nfor i in range(1, size):\n if days[i] == 0:\n yesterday = 0\n daysoff += 1\n elif days[i] == yesterday:\n yesterday = 0\n daysoff += 1\n elif days[i] == 3 and yesterday == 0:\n yesterday = 0\n elif days[i] == 3 and yesterday == 1:\n yesterday = 2\n elif days[i] == 3 and yesterday == 2:\n yesterday = 1\n else:\n yesterday = days[i]\n\nprint(daysoff)\n\t\t \t \t \t\t\t \t\t \t\t\t\t\t", "n = int(input())\narr = list(map(lambda x: int(x), input().split(\" \")))\ndp = [[None] * n for _ in range(3)]\nfirst = arr[0]\ndp[0][0] = 1\nif first == 1:\n dp[1][0] = 0\nif first == 2:\n dp[2][0] = 0\nif first == 3:\n dp[1][0] = 0\n dp[2][0] = 0\n\nfor c in range(1, n):\n val = arr[c]\n cand = [dp[0][c-1], dp[1][c-1], dp[2][c-1]]\n cand = list(filter(lambda x: x != None, cand))\n dp[0][c] = 1+min(cand)\n if val == 1 or val == 3:\n cand = [dp[0][c-1], dp[2][c-1]]\n cand = list(filter(lambda x: x != None, cand))\n dp[1][c] = min(cand)\n if val == 2 or val == 3:\n cand = [dp[0][c-1], dp[1][c-1]]\n cand = list(filter(lambda x: x != None, cand))\n dp[2][c] = min(cand)\n\ncand = [dp[0][-1], dp[1][-1], dp[2][-1]]\n#print(dp)\nprint(min(filter(lambda x: x != None, cand)))\n", "# Problem: A. Vacations\r\n# Contest: Codeforces - Codeforces Round 363 (Div. 1)\r\n# URL: https://codeforces.com/problemset/problem/698/A\r\n# Memory Limit: 256 MB\r\n# Time Limit: 1000 ms\r\n\r\nimport sys\r\nimport bisect\r\nimport random\r\nimport io, os\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom contextlib import redirect_stdout\r\nfrom itertools import *\r\nfrom array import *\r\nfrom functools import lru_cache, reduce\r\nfrom types import GeneratorType\r\nfrom heapq import *\r\nfrom math import sqrt, gcd, inf\r\n\r\nif sys.version >= '3.8': # ACW没有comb\r\n from math import comb\r\n\r\nRI = lambda: map(int, sys.stdin.readline().split())\r\nRS = lambda: map(bytes.decode, sys.stdin.readline().strip().split())\r\nRILST = lambda: list(RI())\r\nDEBUG = lambda *x: sys.stderr.write(f'{str(x)}\\n')\r\n# print = lambda d: sys.stdout.write(str(d) + \"\\n\") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法\r\n\r\nMOD = 10 ** 9 + 7\r\nPROBLEM = \"\"\"\r\n\"\"\"\r\n\r\n\r\ndef lower_bound(lo: int, hi: int, key):\r\n \"\"\"由于3.10才能用key参数,因此自己实现一个。\r\n :param lo: 二分的左边界(闭区间)\r\n :param hi: 二分的右边界(闭区间)\r\n :param key: key(mid)判断当前枚举的mid是否应该划分到右半部分。\r\n :return: 右半部分第一个位置。若不存在True则返回hi+1。\r\n 虽然实现是开区间写法,但为了思考简单,接口以[左闭,右闭]方式放出。\r\n \"\"\"\r\n lo -= 1 # 开区间(lo,hi)\r\n hi += 1\r\n while lo + 1 < hi: # 区间不为空\r\n mid = (lo + hi) >> 1 # py不担心溢出,实测py自己不会优化除2,手动写右移\r\n if key(mid): # is_right则右边界向里移动,目标区间剩余(lo,mid)\r\n hi = mid\r\n else: # is_left则左边界向里移动,剩余(mid,hi)\r\n lo = mid\r\n return hi\r\n\r\n\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n else:\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n stack.append(to)\r\n to = next(to)\r\n else:\r\n stack.pop()\r\n if not stack:\r\n break\r\n to = stack[-1].send(to)\r\n return to\r\n\r\n return wrappedfunc\r\n\r\n\r\n# ms\r\ndef solve():\r\n n, = RI()\r\n a = RILST()\r\n f = [[inf] * 3 for _ in range(n + 1)]\r\n # 0休息 1运动 2比赛\r\n f[0][0] = f[0][1] = f[0][2] = 0\r\n for i, v in enumerate(a):\r\n f[i + 1][0] = min(f[i][0], f[i][1], f[i][2]) + 1\r\n # 比赛进行\r\n if v == 1 or v == 3:\r\n f[i + 1][2] = min(f[i][0], f[i][1])\r\n # 健身房开放\r\n if v == 2 or v == 3:\r\n f[i + 1][1] = min(f[i][0], f[i][2])\r\n print(min(f[n]))\r\n\r\n\r\nif __name__ == '__main__':\r\n t = 0\r\n if t:\r\n t, = RI()\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "\nimport sys\nimport threading\ninput = sys.stdin.readline\nfrom collections import defaultdict\ninput = sys.stdin.readline\n\ndef main():\n \n\n n = int(input())\n a = list(map(int, input().split()))\n ans = 0\n e = 0\n\n for ai in a:\n # print(ai, e)\n if ai == 0:\n ans+=1\n e = 0\n elif e == 0:\n if ai == 1:\n e = 2\n elif ai == 2:\n e = 1\n elif ai!=3:\n if e != ai:\n ans+=1\n e = 0\n else:\n e = 2 if e == 1 else 1\n# \n else:\n e = 2 if e == 1 else 1\n print(ans)\n\n\n# Set the stack size\nthreading.stack_size(1 << 27)\n\n# Create and start the main thread\nmain_thread = threading.Thread(target=main)\nmain_thread.start()\n\n# Wait for the main thread to complete\nmain_thread.join()\n", "n=int(input())\r\na=list(map(int,input().split()))\r\ndp=[[10**9]*3 for i in range(n)]\r\nif a[0]==0:\r\n dp[0][0]=1\r\nelif a[0]==1:\r\n dp[0][0]=1\r\n dp[0][2]=0\r\nelif a[0]==2:\r\n dp[0][0]=1\r\n dp[0][1]=0\r\nelse:\r\n dp[0][0]=1\r\n dp[0][2]=dp[0][1]=0\r\nfor i in range(1,n):\r\n if a[i]==0:\r\n dp[i][0]=min(dp[i-1])+1\r\n elif a[i]==1:\r\n dp[i][0]=min(dp[i-1])+1\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n elif a[i]==2:\r\n dp[i][0]=min(dp[i-1])+1\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\n else:\r\n dp[i][0]=min(dp[i-1])+1\r\n dp[i][2]=min(dp[i-1][0],dp[i-1][1])\r\n dp[i][1]=min(dp[i-1][0],dp[i-1][2])\r\nprint(min(dp[-1]))", "n=int(input())\ndias=list(map(int,input().strip().split(\" \")))\ncont=0\nlargo=len(dias)\ni=1\nwhile i<largo:\n\tif dias[i]==3:\n\t\tif dias[i-1]==2:\n\t\t\tdias[i]=1\n\t\tif dias[i-1]==1:\n\t\t\tdias[i]=2\n\tif dias[i]==1 or dias[i]==2:\n\t\tif dias[i]==dias[i-1]:\n\t\t\tdias[i]=0\n\ti+=1\nj=largo-2\nwhile j>=0:\n\tif dias[j]==3:\n\t\tif dias[j+1]==2:\n\t\t\tdias[j]=1\n\t\tif dias[j+1]==1:\n\t\t\tdias[j]=2\n\tj-=1\nfor x in dias:\n\tif x==0:\n\t\tcont+=1\nprint(cont)", "import sys\nfrom functools import lru_cache\nfrom collections import defaultdict\n\npossible = {\n 0: {'r'},\n 1: {'r', 'c'},\n 2: {'r', 'g'},\n 3: {'r', 'c', 'g'}\n}\n\n@lru_cache(maxsize=None)\ndef min_rest(i, prev_action):\n if i == len(arr):\n return 0\n\n # At least one elem in the arr.\n p = possible[arr[i]]\n best = float(\"inf\")\n for act in p:\n if act == 'r':\n # Can always rest, no restrictions.\n best = min(best, 1 + min_rest(i + 1, 'r'))\n elif act != prev_action:\n best = min(best, min_rest(i + 1, act))\n return best\n\ndef iterative(arr):\n DP = defaultdict(int)\n for i in range(len(arr) - 1, -1, -1):\n p = possible[arr[i]]\n for prev_act in ('r', 'c', 'g'):\n best = float(\"inf\")\n for act in p:\n if act == 'r':\n # Can always rest, no restrictions.\n best = min(best, 1 + DP[('r', i + 1)])\n elif act != prev_act:\n best = min(best, DP[act, i + 1])\n DP[(prev_act, i)] = best\n return DP[('r', 0)]\n\nif __name__ == \"__main__\":\n mat = []\n for e, line in enumerate(sys.stdin.readlines()):\n if e == 0:\n continue\n arr = list(map(int, line.strip().split()))\n # print(min_rest(0, 'r'))\n print(iterative(arr))\n", "n=int(input())\r\narr=list(map(int,input().split()))\r\ndp=[[0 for i in range(4)]for j in range(n+1)]\r\n\r\n \r\nfor i in range(1,n+1):\r\n dp[i][0]=max(dp[i-1][1],dp[i-1][2],dp[i-1][0])\r\n if arr[i-1]==1 or arr[i-1]==3:\r\n dp[i][1]=max(dp[i-1][0]+1,dp[i-1][2]+1)\r\n if arr[i-1]==2 or arr[i-1]==3:\r\n dp[i][2]=max(dp[i-1][0]+1,dp[i-1][1]+1)\r\n \r\n \r\nprint(n-max(dp[-1]))\r\n ", "n=int(input())\r\nnum=map(int,input().split())\r\nrest=sport=contest=0\r\nfor i in num:\r\n if i==3:\r\n contest,sport,rest=max(contest,rest+1,sport+1),max(sport,contest+1,rest+1),max(rest,contest,sport)\r\n elif i==1:\r\n contest,rest=max(contest,rest+1,sport+1),max(rest,contest,sport)\r\n elif i==2:\r\n sport,rest=max(sport,contest+1,rest+1),max(rest,contest,sport)\r\n else:\r\n rest=max(rest,contest,sport)\r\nprint(n-max(rest,contest,sport))", "import math\r\n\r\nn = int(input())\r\nops = list(map(int,input().split()))\r\n\r\ndp = [[0 for i in range(3)] for i in range(n+1)]\r\nfor i in range(1,n+1):\r\n if ops[i-1] == 0:\r\n dp[i][0] = min(dp[i-1]) + 1\r\n dp[i][1] = math.inf\r\n dp[i][2] = math.inf\r\n elif ops[i-1] == 1:\r\n dp[i][0] = min(dp[i-1]) + 1\r\n dp[i][1] = min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2] = math.inf\r\n elif ops[i-1] == 2:\r\n dp[i][0] = min(dp[i-1]) + 1\r\n dp[i][1] = math.inf \r\n dp[i][2] = min(dp[i-1][0],dp[i-1][1])\r\n else:\r\n dp[i][0] = min(dp[i-1]) + 1\r\n dp[i][1] = min(dp[i-1][0],dp[i-1][2])\r\n dp[i][2] = min(dp[i-1][0],dp[i-1][1])\r\n\r\nprint(min(dp[n]))", "# https://codeforces.com/problemset/problem/698/A\n\nn = int(input())\na = [int(x) for x in input().split()]\n\nv = {}\nGYM = 'GYM'\nCONT = 'CONT'\nOFF = 'OFF'\n\noptions = [GYM, CONT, OFF]\nfirst = a[0]\nif first == 0:\n v[(0, OFF)] = 1\nelif first == 1:\n v[(0, CONT)] = 0\n v[(0, OFF)] = 1\nelif first == 2:\n v[(0, GYM)] = 0\n v[(0, OFF)] = 1\nelse:\n v[(0, CONT)] = 0\n v[(0, GYM)] = 0\n v[(0, OFF)] = 1\n\nvalid = {\n OFF: [GYM, CONT, OFF],\n GYM: [CONT, OFF],\n CONT: [GYM, OFF],\n}\n\nok = {\n 0: [OFF],\n 1: [OFF, CONT],\n 2: [OFF, GYM],\n 3: [OFF, CONT, GYM],\n }\n\nfor idx in range(n):\n cur = a[idx]\n for c in options:\n debug = idx == 1 and c == CONT\n if c not in ok[cur]:\n continue\n cmin = None\n for prev in valid[c]:\n prev_item = (idx-1, prev)\n if prev_item not in v:\n continue\n val = v[prev_item]\n if c == OFF:\n cand = val + 1\n else:\n cand = val\n if cmin is None or cand < cmin:\n cmin = cand\n if cmin is not None:\n v[(idx, c)] = cmin\n\nfmin = None\nfor c in options:\n if (n-1, c) not in v:\n continue\n val = v[(n-1, c)]\n if fmin is None or val < fmin:\n fmin = val\n\nprint(fmin)\n", "def solve(i,sport,contest):\r\n if i==n:\r\n return 0\r\n ans=0\r\n if d[i][sport][contest]!=-1:\r\n return d[i][sport][contest]\r\n if l[i]==0:\r\n ans=1+solve(i+1,0,0)\r\n elif l[i]==1:\r\n if contest:\r\n ans=1+solve(i+1,0,0)\r\n else:\r\n ans=min(1+solve(i+1,0,0),solve(i+1,0,1))\r\n elif l[i]==2:\r\n if sport:\r\n ans=1+solve(i+1,0,0)\r\n else:\r\n ans=min(1+solve(i+1,0,0),solve(i+1,1,0))\r\n else:\r\n if sport:\r\n ans=min(1+solve(i+1,0,0),solve(i+1,0,1))\r\n elif contest:\r\n ans=min(1+solve(i+1,0,0),solve(i+1,1,0))\r\n else:\r\n ans=min(1+solve(i+1,0,0),solve(i+1,1,0),solve(i+1,0,1))\r\n d[i][sport][contest]=ans\r\n return ans\r\n\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nd=[[[-1]*3 for i in range(3)] for j in range(n+5)]\r\n\r\nprint(solve(0,0,0))", "n=int(input())\nvec = list(map(int, input().split()))\nlibre = bandera = 0\nfor i in range(n):\n if vec[i] == 0:\n libre=libre+1\n bandera = 0\n elif vec[i]==1 or vec[i]==2:\n if bandera == vec[i]:\n libre=libre+1\n bandera = 0\n else:\n bandera =vec[i]\n else:\n if bandera == 1:\n bandera = 2\n elif bandera == 2: \n bandera = 1\nprint(libre)\n\t\t\t\t\t \t \t \t \t \t \t \t \t\t\t \t", "n = int(input())\na = list(map(int, input().split()))\nlast = 0\nwork = 0\nfor x in a:\n if x == 3:\n work += 1\n last = 3 if last in (0, 3) else 3 - last\n elif x == 0 or last == x:\n last = 0\n else:\n work += 1\n last = x\nprint(n - work)\n", "import sys, os.path\r\nfrom collections import*\r\nfrom copy import*\r\nimport math\r\nmod=10**9+7\r\nif(os.path.exists('input.txt')):\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n sys.stdout = open(\"output.txt\",\"w\") \r\n\r\ndef solve(i,sport,contest):\r\n if(i==n):\r\n return 0\r\n if(dp[i][sport][contest]!=-1):\r\n return dp[i][sport][contest]\r\n ans=0\r\n if(a[i]==0):\r\n ans=1+solve(i+1,0,0)\r\n elif(a[i]==1):\r\n if(contest):\r\n ans=1+solve(i+1,0,0)\r\n else:\r\n ans=min(1+solve(i+1,0,0),solve(i+1,0,1))\r\n elif(a[i]==2):\r\n if(sport):\r\n ans=1+solve(i+1,0,0)\r\n else:\r\n ans=min(1+solve(i+1,0,0),solve(i+1,1,0))\r\n else:\r\n if(sport):\r\n ans=min(1+solve(i+1,0,0),solve(i+1,0,1))\r\n elif(contest):\r\n ans=min(1+solve(i+1,0,0),solve(i+1,1,0))\r\n else:\r\n ans=min(solve(i+1,0,1),solve(i+1,1,0),1+solve(i+1,0,0))\r\n dp[i][sport][contest]=ans\r\n return dp[i][sport][contest]\r\n\r\n\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ndp=[[[-1 for k in range(3)]for j in range(3)]for i in range(105)]\r\nprint(solve(0,0,0))\r\n\r\n\r\n\r\n\r\n\r\n \r\n", "def minimum_rest_days(opt_list):\n prev_min = [0, 0, 0] # rest, contest, sport\n for opt in opt_list:\n cur_min = [None, None, None]\n cur_min[0] = min([_ for _ in prev_min if _ is not None]) + 1\n if opt in [1, 3]:\n cur_min[1] = min([x for i, x in enumerate(prev_min)\n if x is not None and i != 1])\n if opt in [2, 3]:\n cur_min[2] = min([x for i, x in enumerate(prev_min)\n if x is not None and i != 2])\n\n prev_min = cur_min\n return min([_ for _ in cur_min if _ is not None])\n\nif __name__ == '__main__':\n days = int(input())\n opt_list = [int(_) for _ in input().split(' ')]\n assert days == len(opt_list)\n \n print(minimum_rest_days(opt_list))\n", "n = int(input())\r\nlst1 = list(map(int,input().split()))\r\nlst2 = []\r\nfor i in range(len(lst1)):\r\n if i == 0:\r\n dict1 = {0:1}\r\n if lst1[0] == 1:\r\n dict1[1] = 0\r\n elif lst1[0] == 2:\r\n dict1[2] = 0\r\n elif lst1[0] == 3:\r\n dict1[1] = 0\r\n dict1[2] = 0\r\n lst2.append(dict1)\r\n else:\r\n dict1 = {}\r\n min1 = float('inf')\r\n for j in lst2[-1]:\r\n min1 = min(min1,lst2[-1][j])\r\n dict1[0] = min1+1\r\n if lst1[i] == 1:\r\n if 2 in lst2[-1]:\r\n dict1[1] = min(lst2[-1][2],lst2[-1][0])\r\n else:\r\n dict1[1] = lst2[-1][0]\r\n elif lst1[i] == 2:\r\n if 1 in lst2[-1]:\r\n dict1[2] = min(lst2[-1][1],lst2[-1][0])\r\n else:\r\n dict1[2] = lst2[-1][0]\r\n elif lst1[i] == 3:\r\n if 2 in lst2[-1]:\r\n dict1[1] = min(lst2[-1][2],lst2[-1][0])\r\n else:\r\n dict1[1] = lst2[-1][0]\r\n if 1 in lst2[-1]:\r\n dict1[2] = min(lst2[-1][1],lst2[-1][0])\r\n else:\r\n dict1[2] = lst2[-1][0]\r\n lst2.append(dict1)\r\n\r\nmin1 = float('inf')\r\nfor i in lst2[-1]:\r\n min1 = min(min1,lst2[-1][i])\r\n\r\nprint(min1)\r\n# print(lst2)", "n = int(input())\ndata = [-1] + [int(x) for x in input().split()]\nassert len(data) == n+1\n\n# gym, contest, rest\ndp = [[-1, -1, -1] for _ in range(n+1)]\n\ndp[0][2] = 0\n\nfor i,a in enumerate(data):\n if i == 0:\n continue\n\n for c in (0, 1):\n if ((1<<c) & a) == 0:\n dp[i][c] = -1\n else:\n dp[i][c] = max(dp[i-1][1-c], dp[i-1][2]) + 1\n dp[i][2] = max(dp[i-1])\n\nprint(n - max(dp[n]))\n", "import sys\r\nsys.setrecursionlimit(100000)\r\nn=int(input())\r\na=list(map(lambda x:int(x),input().split()))\r\ndef calculate(last_action,a,i,dp):\r\n if (last_action,i) in dp:\r\n return dp[(last_action,i)]\r\n # print(i)\r\n if i==len(a)-1:\r\n if last_action==1 and a[i]==2:\r\n return 1\r\n if last_action==1 and a[i]==3:\r\n return 0\r\n if last_action==1 and a[i]==0:\r\n return 1\r\n if last_action==1 and a[i]==1:\r\n return 0\r\n if last_action==0 and a[i]==0:\r\n return 1\r\n if last_action==0 and a[i] in [1,2,3]:\r\n return 0\r\n if last_action==2 and a[i]==2:\r\n return 0\r\n if last_action==2 and a[i]==3:\r\n return 0\r\n if last_action==2 and a[i]==0:\r\n return 1\r\n if last_action==2 and a[i]==1:\r\n return 1\r\n\r\n available_actions=[]\r\n if last_action==0 and a[i] in [1,2,3]:\r\n if a[i]==1:\r\n available_actions=[0,2]\r\n if a[i]==2:\r\n available_actions = [0,1]\r\n if a[i]==3:\r\n available_actions = [0,1,2]\r\n elif last_action==0 and a[i] not in [1,2,3]:\r\n available_actions=[0]\r\n elif last_action==1 and a[i] in [1,3]:\r\n available_actions=[0,2]\r\n elif last_action==1 and a[i] in [0,2]:\r\n available_actions=[0]\r\n elif last_action==2 and a[i] in [1,0]:\r\n available_actions=[0]\r\n elif last_action==2 and a[i] in [3,2]:\r\n available_actions=[0,1]\r\n minimum_days=1000\r\n for action in available_actions:\r\n if action==0:\r\n if (0,i+1) in dp:\r\n answer=1+dp[(0,i+1)]\r\n else:\r\n dp[(0, i + 1)]=calculate(0, a, i + 1, dp)\r\n answer = 1 + dp[(0, i + 1)]\r\n if answer<minimum_days:\r\n minimum_days=answer\r\n else:\r\n if (action, i + 1) in dp:\r\n answer = 0 + dp[(action, i + 1)]\r\n else:\r\n dp[(action, i + 1)] = calculate(action, a, i + 1, dp)\r\n answer = 0 + dp[(action, i + 1)]\r\n if answer<minimum_days:\r\n minimum_days=answer\r\n dp[(last_action,i)]=minimum_days\r\n return minimum_days\r\nprint(calculate(0,a,0,{}))", "n = int(input())\r\nd = [[0] * 3 for _ in range(n)]\r\na = list(map(int, input().split()))\r\nif a[0] == 1 or a[0] == 3:\r\n d[0][1] = 1\r\nif a[0] == 2 or a[0] == 3:\r\n d[0][2] = 1\r\nfor i in range(1, n):\r\n d[i][0] = max(d[i - 1])\r\n if a[i] == 1 or a[i] == 3:\r\n d[i][1] = max(d[i - 1][2] + 1, d[i - 1][0] + 1)\r\n if a[i] == 2 or a[i] == 3:\r\n d[i][2] = max(d[i - 1][1] + 1, d[i - 1][0] + 1)\r\nprint(n - max(d[n - 1]))\r\n", "n = int(input())\r\nd = list(map(int, input().split()))\r\n\r\ndp1 = [0 for _ in range(n)]\r\ndp2 = [0 for _ in range(n)]\r\n\r\ndp1[0] = 0 if d[0] & 1 else 1\r\ndp2[0] = 0 if d[0] & 2 else 1\r\n\r\nfor i in range(1, n):\r\n if d[i] == 3:\r\n dp1[i] = dp2[i-1]\r\n dp2[i] = dp1[i-1]\r\n elif d[i] == 2:\r\n dp1[i] = min(dp1[i-1], dp2[i-1])+1\r\n dp2[i] = dp1[i-1]\r\n elif d[i] == 1:\r\n dp2[i] = min(dp1[i-1], dp2[i-1])+1\r\n dp1[i] = dp2[i-1]\r\n elif d[i] == 0:\r\n dp2[i] = dp1[i] = min(dp1[i-1], dp2[i-1])+1\r\n\r\n\r\nprint(min(dp2[n-1], dp1[n-1]))\r\n", "from math import *\r\n\r\nfrom math import factorial as fact, comb as ncr \r\nfrom bisect import bisect_left as bl\r\nfrom bisect import bisect_right as br\r\nfrom collections import Counter as ctr\r\nfrom collections import deque as dq\r\n\r\nfrom array import array\r\nfrom re import search\r\n\r\nli=lambda : list(map(int,input().split()))\r\narr=lambda a: array('i',a)\r\nbi=lambda n: bin(n).replace(\"0b\", \"\")\r\nyn=lambda f: print('NYOE S'[f::2])\r\nsbstr=lambda a,s: search('.*'.join(a),s)\r\n\r\ndef solve():\r\n #for _ in range(int(input())):\r\n n=int(input())\r\n a=li()\r\n r=0\r\n x=0\r\n for c in a:\r\n if c==0 or c ==x:\r\n r+=1\r\n x=0\r\n elif c==3:\r\n if x!=0:\r\n x=3-x\r\n else:\r\n x=c\r\n print(r)\r\n\r\nsolve()", "n = int(input())\r\na, b, c, d = list(map(int, input().split())), [0 for i in range(n+1)], [0 for i in range(int(n+1))], [0 for i in range(n+1)]\r\nfor i in range(n):\r\n b[i+1] = max(b[i], c[i], d[i])\r\n if a[i] == 1:\r\n c[i+1] = max(b[i], d[i]) + 1\r\n elif a[i] == 2:\r\n d[i+1] = max(b[i], c[i]) + 1\r\n elif a[i] == 3:\r\n d[i+1] = max(b[i], c[i]) + 1\r\n c[i+1] = max(b[i], d[i]) + 1\r\nprint(n - max(b[-1], c[-1], d[-1]))\r\n", "n = int(input())\r\ndays = [int(_) for _ in input().split()]\r\n\r\n'''\r\nai равно 0, если в i-й день каникул не работает спортзал и не проводится контест;\r\nai равно 1, если в i-й день каникул не работает спортзал, но проводится контест;\r\nai равно 2, если в i-й день каникул работает спортзал и не проводится контест;\r\nai равно 3, если в i-й день каникул работает спортзал и проводится контест.\r\n'''\r\n\r\nff = {(0, n) : 0, (1, n) :0, (2, n):0}\r\ndef f(t, k):\r\n if not((t, k) in ff):\r\n www = []\r\n for x in range(3):\r\n if x == 0:\r\n www.append(f(x, k+1) + 1)\r\n elif (x & days[k]) and (t == 0 or t != x):\r\n www.append(f(x, k+1))\r\n ff[ (t, k) ] = min(www)\r\n return ff[ (t, k) ]\r\n \r\nprint(f(0, 0))\r\n \r\n \r\n", "n=int(input())\r\na=[int(i) for i in input().split()]\r\ndp=[[0 for i in range(n)] for j in range(2)]\r\nif a[0]==0:\r\n dp[0][0]+=1\r\n dp[1][0]+=1\r\nelif a[0]==1:\r\n dp[1][0]+=1\r\nelif a[0]==2:\r\n dp[0][0]+=1\r\nfor i in range(1,n):\r\n m=min(dp[0][i-1],dp[1][i-1])\r\n if a[i]==0:\r\n dp[0][i]=m+1\r\n dp[1][i]=m+1\r\n elif a[i]==1:\r\n dp[0][i]=min(dp[0][i-1]+1,dp[1][i-1])\r\n dp[1][i]=m+1\r\n elif a[i]==2:\r\n dp[1][i]=min(dp[1][i-1]+1,dp[0][i-1])\r\n dp[0][i]=m+1\r\n else:\r\n dp[0][i]=min(dp[0][i-1]+1,dp[1][i-1])\r\n dp[1][i]=min(dp[1][i-1]+1,dp[0][i-1])\r\nprint(min(dp[0][n-1],dp[1][n-1]))", "n = int(input())\na = [int(aa) for aa in input().split()]\ncounter = 0\nif n == 1 and a[0] == 0:\n print(1)\n exit()\nelif n == 1 and (a[0] == 1 or a[0] == 2):\n print(0)\n exit()\n\nfor i in range(1, len(a)):\n if a[i] == 3 and a[i-1] == 0:\n continue\n elif a[i] == 1 and a[i-1] == 1:\n a[i] = 0\n elif a[i] == 2 and a[i-1] == 2:\n a[i] = 0\n elif a[i] == 3 and a[i-1] == 1: \n a[i] = 2\n elif a[i] == 3 and a[i-1] == 2:\n a[i] = 1\n\nfor i in range(n):\n if a[i] == 0: counter += 1\n\n\nprint(counter)\n\t\t\t\t \t\t\t \t\t \t \t \t\t\t\t \t\t", "n = int(input())\r\nlist1 = [int(i)for i in input().split()]\r\ndp = []\r\nfor x in range(n):\r\n dp.append([10**9,10**9,10**9])\r\ndp[0][0]=1\r\nif list1[0]==0:\r\n dp[0][1]=1\r\n dp[0][2]=1\r\nelif list1[0]==1:\r\n dp[0][1]=0\r\n dp[0][2]=1\r\nelif list1[0]==2:\r\n dp[0][1]=1\r\n dp[0][2]=0\r\nelse:\r\n dp[0][1]=0\r\n dp[0][2]=0\r\nfor x in range(1,n):\r\n dp[x][0]=1+min([dp[x-1][0],dp[x-1][1],dp[x-1][2]])\r\n if list1[x]==0:\r\n dp[x][1]=1+min([dp[x-1][0],dp[x-1][1],dp[x-1][2]])\r\n dp[x][2]=1+min([dp[x-1][0],dp[x-1][1],dp[x-1][2]])\r\n elif list1[x]==1:\r\n dp[x][1]=min([dp[x-1][0],dp[x-1][2]])\r\n dp[x][2]=1+min([dp[x-1][0],dp[x-1][1],dp[x-1][2]])\r\n elif list1[x]==2:\r\n dp[x][1]=1+min([dp[x-1][0],dp[x-1][1],dp[x-1][2]])\r\n dp[x][2]=min([dp[x-1][0],dp[x-1][1]])\r\n else:\r\n dp[x][1]=min([dp[x-1][0],dp[x-1][2]])\r\n dp[x][2]=min([dp[x-1][0],dp[x-1][1]])\r\nprint(min([dp[n-1][0],dp[n-1][1],dp[n-1][2]]))", "n = int(input())\na_list = list(map(int, input().split()))\n\nsport = [0]\ngym = [0]\nrest = [0]\n\nMAX = 200\nfor a in a_list:\n if (a == 0):\n s = g = r = min(sport[len(sport) - 1], min(gym[len(gym) - 1], rest[len(rest) - 1])) + 1\n elif (a == 1):\n s = min(gym[len(gym) - 1], rest[len(rest) - 1])\n g = gym[len(gym) - 1] + 1\n r = min(sport[len(sport) - 1], rest[len(rest) - 1]) + 1\n elif (a == 2):\n s = sport[len(sport) - 1] + 1\n g = min(sport[len(sport) - 1], rest[len(rest) - 1]) \n r = min(gym[len(gym) - 1], rest[len(rest) - 1]) + 1\n else:\n s = min(gym[len(gym) - 1], rest[len(rest) - 1])\n g = min(sport[len(sport) - 1], rest[len(rest) - 1])\n r = min(gym[len(gym) - 1], min(sport[len(sport) - 1], rest[len(rest) - 1])) + 1\n\n sport.append(s)\n gym.append(g)\n rest.append(r)\n\nprint(min(sport[len(sport) - 1], min(gym[len(gym) - 1], rest[len(rest) - 1])))\n", "import math\r\n\r\ndef solve(n, arr):\r\n \"\"\"\"\r\n 0: Rest\r\n 1: Contest\r\n 2: Gym\r\n \"\"\"\r\n\r\n d = [[math.inf for i in range(3)] for i in range(n)]\r\n\r\n\r\n d[0][0] = 1\r\n d[0][1] = 1 if arr[0] == 0 or arr[0] == 2 else 0\r\n d[0][2] = 1 if arr[0] == 0 or arr[0] == 1 else 0\r\n\r\n\r\n for i in range(1, n):\r\n for j in range(3):\r\n if arr[i] == 0:\r\n d[i][j] = min(d[i-1][0], d[i-1][1], d[i-1][2]) + 1\r\n elif arr[i] == 3:\r\n d[i][j] = min(d[i-1][0], d[i-1][1] if j != 1 else math.inf, d[i-1][2] if j != 2 else math.inf)\r\n if j == 0:\r\n d[i][j] += 1\r\n elif arr[i] == 1: # gym is closed, contest is open\r\n if j == 2: # chosen gym\r\n d[i][j] = min(d[i-1][0], d[i-1][1], d[i-1][2]) + 1\r\n elif j == 1:\r\n d[i][j] = min(d[i-1][0], d[i-1][2])\r\n else:\r\n d[i][j] = min(d[i-1][0], d[i-1][1], d[i-1][2]) + 1\r\n elif arr[i] == 2: # gym is open, contest is close\r\n if j == 1: # chosen contest\r\n d[i][j] = min(d[i-1][0], d[i-1][1], d[i-1][2]) + 1\r\n elif j == 2: # chosen gym\r\n d[i][j] = min(d[i-1][0], d[i-1][1])\r\n else:\r\n d[i][j] = min(d[i-1][0], d[i-1][1], d[i-1][2]) + 1\r\n\r\n\r\n #print(d)\r\n min_rest = min(d[n-1][0], d[n-1][1], d[n-1][2])\r\n print(min_rest)\r\n\r\nn = int(input())\r\narr = list(map(int, input().split(\" \")))\r\n\r\nsolve(n, arr)\r\n", "input()\r\nl = list(map(int,input().split()))\r\nr = 0\r\nprev = 3\r\nfor i in l:\r\n if (i == prev and prev != 3):\r\n i = 0\r\n elif (i == 3 and prev != 3):\r\n i -= prev\r\n if i == 0:\r\n r = r + 1\r\n \r\n prev = i\r\n \r\nprint(r)", "\"\"\"\nAccomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\n\nTo modify the template, go to Preferences -> Editor -> File and Code Templates -> Other\n\"\"\"\nfrom functools import lru_cache\n\n\ndef solve(days):\n\n @lru_cache(None)\n def dfs(index, p_sport):\n if index >= len(days):\n return 0\n\n value = days[index]\n\n worked = 0\n\n for bit in range(2):\n p = (p_sport >> bit) & 1\n v = (value >> bit) & 1\n\n if v and not p:\n worked = max(worked, 1 + dfs(index + 1, 1 << bit))\n else:\n worked = max(worked, dfs(index + 1, 0))\n\n return worked\n\n return len(days) - dfs(0, 0)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n days = list(map(int, input().split()))\n\n print(solve(days))\n", "from math import inf\r\n \r\nn = int(input())\r\na = [int(i) for i in input().split()]\r\ndp = [[0, 0, 0] for i in range(n + 1)]\r\nfor i in range(1, n + 1):\r\n mn = min(dp[i - 1]) \r\n dp[i][0] = mn + 1\r\n\r\n \r\n mn = min((dp[i - 1][0], dp[i - 1][2]))\r\n if a[i - 1] <= 1:\r\n dp[i][1] = inf\r\n else:\r\n dp[i][1] = mn\r\n\r\n \r\n mn = min((dp[i - 1][0], dp[i - 1][1]))\r\n if a[i - 1] in (0, 2):\r\n dp[i][2] = inf\r\n else:\r\n dp[i][2] = mn\r\nprint(min(dp[-1]))\r\n", "import sys\r\nimport math\r\nimport collections\r\nfrom heapq import heappush, heappop\r\ninput = sys.stdin.readline\r\n \r\nints = lambda: list(map(int, input().split()))\r\n\r\nn = int(input())\r\na = ints()\r\n\r\ncache = {}\r\ndef dfs(i, status):\r\n if i == n:\r\n return 0\r\n if (i, status) in cache:\r\n return cache[(i, status)]\r\n \r\n ans = 1 + dfs(i + 1, 0)\r\n if status != 1 and (a[i] == 2 or a[i] == 3):\r\n ans = min(ans, dfs(i + 1, 1))\r\n if status != 2 and (a[i] == 1 or a[i] == 3):\r\n ans = min(ans, dfs(i + 1, 2))\r\n cache[(i, status)] = ans\r\n return ans\r\n\r\nprint(dfs(0, -1))", "# DP 1\n\n# n = int(input())\n# a = [i for i in input().split(' ')]\n# dp = []\n# for i in range(n + 1):\n# dp.append([])\n# for _ in range(3):\n# dp[i].append(0)\n\n# for i in range(1, n + 1):\n# dp[i][0] = max(dp[i - 1])\n# if a[i - 1] == '1' or a[i - 1] == '3':\n# dp[i][1] = max(dp[i - 1][0], dp[i - 1][2])\n# dp[i][1] += 1\n# else:\n# dp[i][1] = max(dp[i - 1])\n# if a[i - 1] == '2' or a[i - 1] == '3':\n# dp[i][2] = max(dp[i - 1][0], dp[i - 1][1])\n# dp[i][2] += 1\n# else:\n# dp[i][2] = max(dp[i - 1])\n# print(n - max(dp[n]))\n\n# DP 2\n\nn = int(input())\na = [i for i in input().split(' ')]\ndp = []\nfor i in range(n):\n dp.append([])\n for _ in range(3):\n dp[i].append(0)\n\ndp[0][0] = 1\nif a[0] == '1' or a[0] == '3':\n dp[0][1] = 0\nelse:\n dp[0][1] = 1\nif a[0] == '2' or a[0] == '3':\n dp[0][2] = 0\nelse:\n dp[0][2] = 1\nfor i in range(1, n):\n # import code\n # code.interact(local=locals())\n dp[i][0] = min(dp[i - 1]) + 1\n if a[i] == '1' or a[i] == '3':\n dp[i][1] = min(dp[i - 1][0], dp[i - 1][2])\n else:\n dp[i][1] = min(dp[i - 1]) + 1\n if a[i] == '2' or a[i] == '3':\n dp[i][2] = min(dp[i - 1][0], dp[i - 1][1])\n else:\n dp[i][2] = min(dp[i - 1]) + 1\nprint(min(dp[n - 1]))\n\n", "n = int(input())\r\nm = list(map(int, input().split()))\r\ncur=0\r\nans = 0\r\nfor i in m:\r\n if i == 0:\r\n ans+=1\r\n cur = 0\r\n if i == 1:\r\n if cur == 1:\r\n ans+=1\r\n cur = 0\r\n else:\r\n cur = 1\r\n if i == 2:\r\n if cur == 2:\r\n ans+=1\r\n cur = 0\r\n else:\r\n cur = 2\r\n if i == 3:\r\n if cur == 2:\r\n cur = 1\r\n elif cur == 1:\r\n cur = 2\r\nprint(ans)", "n = int(input())\r\nd = list(map(int,input().split()))\r\ndp = [[0 for i in range(n + 1)]for i in range(3)]\r\n\r\nfor i in range(1,n + 1):\r\n \r\n dp[0][i] = max(dp[0][i - 1],dp[1][i - 1],dp[2][i - 1])\r\n if d[i - 1] in [1,3]:\r\n dp[1][i] = max(dp[0][i - 1],dp[2][i - 1] ) + 1\r\n if d[i - 1] in [2,3]:\r\n dp[2][i] = max(dp[0][i - 1],dp[1][i - 1]) + 1\r\nprint(n - max(dp[0][i],dp[1][i],dp[2][i]))\r\n\r\n", "n = int(input())\r\na = [int(x) for x in input().split()]\r\n \r\nd0, d1, d2 = [0], [0], [0]\r\n \r\nfor i in range(n):\r\n d0.append(max((d0[i], d1[i], d2[i])))\r\n d1.append(max(d0[i], d2[i]) + (1 if a[i] & 1 else 0))\r\n d2.append(max(d0[i], d1[i]) + (1 if a[i] & 2 else 0))\r\n \r\nprint(n - max((d0[-1], d1[-1], d2[-1])))" ]
{"inputs": ["4\n1 3 2 0", "7\n1 3 3 2 1 2 3", "2\n2 2", "1\n0", "10\n0 0 1 1 0 0 0 0 1 0", "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "10\n2 3 0 1 3 1 2 2 1 0", "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3", "1\n1", "1\n2", "1\n3", "2\n1 1", "2\n1 3", "2\n0 1", "2\n0 0", "2\n3 3", "3\n3 3 3", "2\n3 2", "2\n0 2", "10\n2 2 3 3 3 3 2 1 3 2", "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0", "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1", "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2", "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0", "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3", "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2", "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1", "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3", "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3", "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0", "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2", "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3", "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0", "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2", "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2", "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0", "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1", "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3", "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2", "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3", "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0", "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2", "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3", "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0", "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2", "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3", "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0", "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2", "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3", "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1", "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3", "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3", "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1", "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1", "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1", "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0", "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1", "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1", "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1", "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0", "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3", "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0", "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3", "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3", "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1", "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1", "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2", "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1", "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2", "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2", "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2", "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3", "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2", "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "99\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", "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "2\n0 3", "2\n1 0", "2\n1 2", "2\n2 0", "2\n2 1", "2\n2 3", "2\n3 0", "2\n3 1", "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0"], "outputs": ["2", "0", "1", "1", "8", "16", "3", "6", "0", "0", "0", "1", "0", "1", "2", "0", "0", "0", "1", "2", "11", "4", "3", "12", "5", "4", "16", "5", "3", "22", "9", "2", "21", "11", "7", "28", "10", "8", "29", "8", "32", "16", "7", "40", "13", "7", "44", "15", "8", "35", "13", "6", "43", "16", "10", "51", "16", "11", "56", "17", "9", "54", "19", "9", "57", "17", "9", "61", "15", "14", "63", "15", "0", "0", "50", "50", "49", "0", "100", "1", "1", "0", "1", "0", "0", "1", "0", "50"]}
UNKNOWN
PYTHON3
CODEFORCES
490
1ba3cfe4997ee8dcd640bb7f5ff1c2d8
Orange
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase. The second line of the input is an integer between 0 and 26, inclusive. Output the required string. Sample Input AprilFool 14 Sample Output AprILFooL
[ "alphabet_lower=list('abcdefghijklmnopqrstuvwxyz')\r\ns=input()\r\ns=s.lower()\r\ns=list(s)\r\ncount=int(input())\r\nfor i in range(len(s)):\r\n if alphabet_lower.index(s[i])<count:\r\n s[i]=s[i].upper()\r\nprint(''.join(s))", "from sys import stdin,stdout\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict,Counter\r\n# from itertools import permutations\r\n# from math import gcd,ceil,sqrt,factorial\r\n# setrecursionlimit(int(1e5))\r\ninput,print = stdin.readline,stdout.write\r\n\r\ns = input().lower()\r\nn = int(input())\r\nans = \"\"\r\nfor i in s:\r\n if ord(i)-ord('a')<n:\r\n ans+=i.upper()\r\n else:\r\n ans+=i\r\nprint(ans+\"\\n\")\r\n", "s, x = input().lower(), int(input())\r\nprint(''.join(ch.upper() if ord(ch) < x + 97 else ch.lower() for ch in s))", "word = input().lower()\r\nlim = int(input())\r\n\r\nfor letter in word:\r\n if ord(letter)<lim+97:\r\n print(letter.upper(),end='')\r\n else:\r\n print(letter,end='')", "a=list(input().lower())\r\nn=int(input())\r\nb=list('abcdefghijklmnopqrstuvwxyz'[:n])\r\nfor i in range(len(a)):\r\n if a[i] in b:\r\n a[i]=a[i].upper()\r\nprint(*a, sep='') ", "a = 'abcdefghijklmnopqrstuvwxyz'\r\ns = input()\r\nn = int(input())\r\nnew = ''\r\n\r\nfor i in s:\r\n if i.lower() in a[:n]:\r\n new += i.upper()\r\n else:\r\n new += i.lower()\r\nprint(new)", "a=list(input().lower())\r\nb=int(input())\r\nc=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'][:b]\r\nf=len(a)\r\nfor i in range(f):\r\n if a[i] in c:\r\n a[i]=a[i].upper()\r\ns=' '\r\nfor i in a:\r\n s+=i\r\nprint(s[1:])", "a = input().lower()\r\nnum = int(input())\r\nc = \"\"\r\nfor i in a:\r\n if ord(i) < num+97:\r\n c += i.upper()\r\n else:\r\n c += i.lower()\r\nprint(c)\r\n", "s = input()\r\nn = int(input())\r\ns = s.lower()\r\nf = \"\"\r\nfor i in range(len(s)):\r\n o = s[i]\r\n if ord(o) < n + 97:\r\n f += o.upper()\r\n else:\r\n f += o.lower()\r\nprint(f)", "s=input().lower()\r\nn=int(input())\r\nss=\"\"\r\nfor i in s:\r\n if ord(i)<n+97:\r\n ss+=i.upper()\r\n else:\r\n ss+=i.lower()\r\nprint(ss)", "a = list(input().lower())\nb = int(input())\nfor i in range(len(a)):\n\tif ord(a[i]) - ord('a') < b:\n\t\ta[i] = a[i].upper()\nprint(''.join(a))", "a, s = input().lower(), int(input())\r\nprint(''.join(t.upper() if ord(t) < s + 97 else t.lower() for t in a))", "s = input()\r\nn = int(input())\r\nd = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'\r\ne = 'abcdefghijklmnopqrstuvwxyz'\r\nfor i in s:\r\n z = ord(i) - ord('a') if ord('a') <= ord(i) and ord(i) <= ord('z') else ord(i) - ord('A')\r\n if z < n:\r\n print(d[z], end = '')\r\n else:\r\n print(e[z], end = '')", "s, n = input(), int(input())\r\n\r\nres = ''\r\n\r\nfor x in s.lower():\r\n if ord(x) < n + 97: res += x.upper()\r\n else: res += x\r\n\r\nprint(res)", "text = input().lower()\ncaps = int(input())+97\nfor letter in text:\n\tprint(letter.upper(), end='')if letter < chr(caps) else print(letter, end='')\nprint()", "_27 = input()\r\n_16 = int(input())\r\n_27 = _27.lower()\r\n_4 = \"\"\r\nfor _26 in range(len(_27)):\r\n _19 = _27[_26]\r\n if ord(_19) < _16 + 97:\r\n _4 = _4 + _19.upper()\r\n else:\r\n _4 = _4 + _19.lower()\r\nprint(_4)\r\n" ]
{"inputs": ["AprilFool\n14", "abcdefabc\n3", "fgWjSAlPOvcAbCdDEFjz\n7", "sm\n26", "GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\n12", "sPWSFWWqZBPon\n3", "fQHHXCdeaintxHWcFcaSGWFvqnYMEByMlSNKumiFgnJB\n0", "RtsUOGkraqKyjTktAXloOEmQj\n18", "DuFhhnq\n4", "RvpuYTxsbDiJDOLauRlfatcfwvtnDzKyaewGrZ\n22", "isfvbcBEEPaXUDhbVhwddjEutVQqNdlimIKjUnajDQ\n2", "VtQISIHREYaEGPustEkzJRN\n20", "jWBVk\n17", "VWOibsVSFkxPCmyZLWIOxFbfXdlsNzxVcUVf\n8", "HXyXuYceFtVUMyLqi\n21", "tAjlldiqGZUayJZHFQHFJVRukaIKepPVucrkyPtMrhIXoxZbw\n12", "fBUycJpfGhsfIVnXAovyoDyndkhv\n9", "uehLuNwrjO\n0", "gfSAltDEjuPqEsOFuiTpcUpCOiENCLbHHnCgvCQtW\n13", "SICNEaKsjCnvOEcVqFHLIC\n16", "LdsmfiNFkPfJgRxytsSJMQZnDTZZ\n11", "xedzyPU\n13", "kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26", "WHbBHzhSNkCZOAOwiKdu\n17", "Ik\n3", "WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5", "IOJRIQefPFxpUj\n18", "vPuebwksPlxuevRLuWcACTBBgVnmcAUsQUficgEAhoEm\n9", "hQfrRArEPuVAQGfcSuoVKBKvY\n22", "TtQEIg\n24", "abczxy\n0", "aaaaaaAAAaaaaAaaAaaAaaaaAAaAAAaaAAaaaAAaaaaaAaaAAa\n2", "aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4", "bBbAbbbbaaAAAaabbBbaaabBaaaBaBbAaBabaAAAaaaaBabbb\n4", "BCABcbacbcbAAACCabbaccAabAAaaCCBcBAcCcbaABCCAcCb\n4", "cdccAAaBBAADdaCDBbDcaDDabdadAbBccCCCDDBADDcdAdC\n4", "EcCEECdCEBaaeCBEBbAaCAeEdeCEedCAdDeEbcACdCcCCd\n4", "cefEDAbedffbaCcEDfEeCEaAcCeFCcEabEecdEdcaFFde\n4", "nifzlTLaeWxTD\n0", "LiqWMLEULRhW\n1", "qH\n2", "R\n26", "MDJivQRiOIVRcCdkSuUlNbMEOkIVJRMTAnHbkVaOmOblLfignh\n25", "pFgLGSkFnGpNKALeDPGlciUNTTlCtAPlFhaIRutCFaFo\n24"], "outputs": ["AprILFooL", "ABCdefABC", "FGwjsAlpovCABCDDEFjz", "SM", "GnLFoqpEztpIBKvvLHADvGpGFqBtnLGmt", "spwsfwwqzBpon", "fqhhxcdeaintxhwcfcasgwfvqnymebymlsnkumifgnjb", "RtsuOGKRAQKyJtKtAxLOOEMQJ", "Dufhhnq", "RVPUyTxSBDIJDOLAURLFATCFwVTNDzKyAEwGRz", "isfvBcBeepAxudhBvhwddjeutvqqndlimikjunAjdq", "vTQISIHREyAEGPuSTEKzJRN", "JwBvK", "vwoiBsvsFkxpCmyzlwioxFBFxDlsnzxvCuvF", "HxyxUyCEFTvUMyLQI", "tAJLLDIqGzuAyJzHFqHFJvruKAIKEppvuCrKyptmrHIxoxzBw", "FBuyCjpFGHsFIvnxAovyoDynDkHv", "uehlunwrjo", "GFsALtDEJupqEsoFuItpCupCoIEnCLBHHnCGvCqtw", "sICNEAKsJCNvOECvqFHLIC", "lDsmFInFKpFJGrxytssJmqznDtzz", "xEDzypu", "KGQOPTBELCDUCOZGNNRYXGPCRQWSLOQEIBYFWDI", "wHBBHzHsNKCzOAOwIKDu", "ik", "wlwBrjvrozAkkxqECEDlrCnmvxqtlkBsy", "IOJRIQEFPFxPuJ", "vpuEBwksplxuEvrluwCACtBBGvnmCAusquFICGEAHoEm", "HQFRRAREPUVAQGFCSUOVKBKVy", "TTQEIG", "abczxy", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "BBBABBBBAAAAAAABBBBAAABBAAABABBAABABAAAAAAAABABBB", "BCABCBACBCBAAACCABBACCAABAAAACCBCBACCCBAABCCACCB", "CDCCAAABBAADDACDBBDCADDABDADABBCCCCCDDBADDCDADC", "eCCeeCDCeBAAeCBeBBAACAeeDeCeeDCADDeeBCACDCCCCD", "CefeDABeDffBACCeDfeeCeAACCefCCeABeeCDeDCAffDe", "nifzltlaewxtd", "liqwmleulrhw", "qh", "R", "MDJIVQRIOIVRCCDKSUULNBMEOKIVJRMTANHBKVAOMOBLLFIGNH", "PFGLGSKFNGPNKALEDPGLCIUNTTLCTAPLFHAIRUTCFAFO"]}
UNKNOWN
PYTHON3
CODEFORCES
16
1ba91a102a7f37aac8832718ae66b16b
Biridian Forest
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest. The forest The Biridian Forest is a two-dimensional grid consisting of *r* rows and *c* columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell. The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example): Moves Breeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions: - Do nothing. - Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees. - If you are located on the exit cell, you may leave the forest. Only you can perform this move — all other mikemon breeders will never leave the forest by using this type of movement. After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders). Mikemon battle If you and *t* (*t*<=&gt;<=0) mikemon breeders are located on the same cell, exactly *t* mikemon battles will ensue that time (since you will be battling each of those *t* breeders once). After the battle, all of those *t* breeders will leave the forest to heal their respective mikemons. Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders — there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell). Your goal You would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully. Goal of other breeders Because you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing. Your task Print the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make. The first line consists of two integers: *r* and *c* (1<=≤<=*r*,<=*c*<=≤<=1000), denoting the number of rows and the number of columns in Biridian Forest. The next *r* rows will each depict a row of the map, where each character represents the content of a single cell: - 'T': A cell occupied by a tree. - 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map. - 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map. - A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder). It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves. A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number. Sample Input 5 7 000E0T3 T0TT0T0 010T0T0 2T0T0T0 0T0S000 1 4 SE23 Sample Output 3 2
[ "\r\nimport sys\r\ninput = sys.stdin.readline\r\nfrom collections import deque, Counter\r\n\r\n\r\ndef is_ok(x, y):\r\n return 0 <= x < r and 0 <= y < c\r\n\r\n\r\nr, c = map(int, input().split())\r\ng = []\r\nfor i in range(r):\r\n s = input()[:-1]\r\n if 'E' in s:\r\n x = (i, s.index('E'), 0)\r\n g.append(s)\r\n\r\nd = [[0]*c for i in range(r)]\r\nq = deque([x])\r\nd[x[0]][x[1]] = 1\r\nf = Counter()\r\ny = 2 << 30\r\nwhile q:\r\n a, b, cc = q.popleft()\r\n if cc > y:\r\n break\r\n for i, j in [(0,1),(1,0),(-1,0),(0,-1)]:\r\n if is_ok(a+i, b+j) and d[a+i][b+j] != 1:\r\n d[a+i][b+j] = 1\r\n if g[a+i][b+j] == 'T':\r\n continue\r\n elif g[a+i][b+j] == 'S':\r\n y = cc+1\r\n else:\r\n q.append((a+i, b+j, cc+1))\r\n if g[a+i][b+j] == '0':\r\n continue\r\n else:\r\n f[cc+1] += int(g[a+i][b+j])\r\nprint(sum(f[i] for i in f if i <= y))", "from collections import defaultdict as dd, deque, Counter as C\r\n \r\nr, c = list(map(int, input().split()))\r\n \r\nA = [list(input()) for i in range(r)]\r\n \r\nstart = []\r\nend = []\r\noccs = []\r\n\r\nfor i in range(r):\r\n for j in range(c):\r\n if A[i][j] == \"S\":\r\n start = [i,j]\r\n elif A[i][j] == \"E\":\r\n end = [i,j]\r\n elif A[i][j] not in \"0T\":\r\n occs.append([i, j])\r\n \r\nq = deque()\r\nq.append([end[0], end[1],0])\r\nvis = [[-1 for i in range(c)] for j in range(r)]\r\n \r\nwhile(q):\r\n x, y, d = q.popleft()\r\n vis[x][y] = d\r\n row = [-1, 0, 0, 1]\r\n col = [0, -1, 1, 0]\r\n \r\n for k in range(4):\r\n a = x+row[k]\r\n b = y+col[k]\r\n if 0 <= a < r and 0 <= b < c and vis[a][b] == -1 and A[a][b] != \"T\":\r\n vis[a][b] = d+1\r\n q.append([a, b, d+1])\r\nx, y = start\r\nfinal_time = vis[x][y]\r\nfight = 0\r\n\r\nfor i in range(r):\r\n for j in range(c):\r\n if A[i][j] not in \"SET0\" and vis[i][j] <= final_time and vis[i][j] != -1:\r\n fight += int(A[i][j])\r\n \r\nprint(fight)", "from collections import deque\r\n\r\ndef inputs(f):\r\n return [f(e) for e in input().split()]\r\n\r\ndef parse_forest(rows, columns, forest):\r\n for i in range(rows):\r\n for j in range(columns):\r\n if forest[i][j] == \"S\":\r\n start = [i, j]\r\n elif forest[i][j] == \"E\":\r\n end = [i, j]\r\n\r\n return start, end\r\n\r\ndef populate(rows, columns, forest, end):\r\n queue = deque()\r\n queue.append([end[0], end[1], 0])\r\n vis = [[-1 for i in range(columns)] for j in range(rows)]\r\n\r\n while(queue):\r\n x, y, d = queue.popleft()\r\n vis[x][y] = d\r\n row = [-1, 0, 0, 1]\r\n col = [0, -1, 1, 0]\r\n for k in range(4):\r\n a = x + row[k]\r\n b = y + col[k]\r\n if 0 <= a < rows and 0 <= b < columns and vis[a][b] == -1 and forest[a][b] != \"T\":\r\n vis[a][b] = d + 1\r\n queue.append([a, b, d + 1])\r\n\r\n return vis\r\n\r\n\r\ndef find_fight(rows, columns, forest, start, vis):\r\n x, y = start\r\n final_time = vis[x][y]\r\n fight = 0\r\n\r\n for i in range(rows):\r\n for j in range(columns):\r\n if forest[i][j] not in \"SET0\" and vis[i][j] <= final_time and vis[i][j] != -1:\r\n fight += int(forest[i][j])\r\n\r\n return fight\r\n\r\ndef solve(rows, columns, forest):\r\n start, end = parse_forest(rows, columns, forest)\r\n\r\n vis = populate(rows, columns, forest, end)\r\n\r\n fight = find_fight(rows, columns, forest, start, vis)\r\n\r\n return fight\r\n\r\ndef main():\r\n rows, columns = inputs(int)\r\n\r\n forest = [list(input()) for i in range(rows)]\r\n\r\n result = solve(rows, columns, forest)\r\n\r\n print(result)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import sys\r\nfrom collections import defaultdict as dd, deque, Counter as C\r\n\r\ndef data(): \r\n return sys.stdin.readline().strip()\r\n\r\ndef out(*var, end=\"\\n\"): \r\n sys.stdout.write(' '.join(map(str, var)) + end)\r\n\r\ndef L(): \r\n return list(sp())\r\n\r\ndef sl(): \r\n return list(ssp())\r\n\r\ndef sp(): \r\n return map(int, data().split())\r\n\r\ndef ssp(): \r\n return map(str, data().split())\r\n\r\ndef l1d(n, val=0): \r\n return [val for i in range(n)]\r\n\r\ndef l2d(n, m, val=0): \r\n return [l1d(n, val) for j in range(m)]\r\n\r\ndef A2(n,m): \r\n return [[0] * m for i in range(n)]\r\n\r\ndef A(n):\r\n return [0] * n\r\n\r\nr, c = L()\r\n\r\nA = [list(input()) for i in range(r)]\r\n\r\nstart = []\r\nend = []\r\noccs = []\r\nfor i in range(r):\r\n for j in range(c):\r\n if A[i][j] == \"S\":\r\n start = [i, j]\r\n elif A[i][j] == \"E\":\r\n end = [i,j]\r\n elif A[i][j] not in \"0T\":\r\n occs.append([i, j])\r\n\r\nq = deque()\r\nq.append([end[0], end[1], 0])\r\nvis = [[-1 for i in range(c)] for j in range(r)]\r\n\r\nwhile(q):\r\n x,y,d = q.popleft()\r\n vis[x][y] = d\r\n row = [-1, 0, 0, 1]\r\n col = [0, -1, 1, 0]\r\n for k in range(4):\r\n a = x + row[k]\r\n b = y + col[k]\r\n if 0 <= a < r and 0 <= b < c and vis[a][b] == -1 and A[a][b] != \"T\":\r\n vis[a][b] = d + 1\r\n q.append([a, b, d + 1])\r\n\r\nx, y = start\r\nfinal_time = vis[x][y]\r\nfight = 0\r\nfor i in range(r):\r\n for j in range(c):\r\n if A[i][j] not in \"SET0\" and vis[i][j] <= final_time and vis[i][j] != -1:\r\n fight += int(A[i][j])\r\n\r\nprint(fight)", "from collections import deque as dq\nn, m = map(int, input().split())\ng = [list(input()) for i in range(n)]\nbreeders = []\nme = []\nexit = []\nfor i in range(n):\n for j in range(m):\n if g[i][j] == 'S':\n me = [i, j]\n elif g[i][j] == 'E':\n exit = [i, j]\n elif g[i][j] not in '0T':\n breeders.append([i, j])\n\nd = dq()\nd.append([exit[0], exit[1], 0])\n\nvis = [[-1 for i in range(m)] for j in range(n)]\n\nwhile len(d) > 0:\n x, y, nb = d.popleft()\n vis[x][y] = nb\n\n row = [-1, 0, 0, 1]\n col = [0, -1, 1, 0]\n\n for k in range(4):\n a = x+row[k]\n b = y+col[k]\n if 0 <= a < n and 0 <= b < m and vis[a][b] == -1 and g[a][b] != 'T':\n vis[a][b] = nb+1\n d.append([a, b, nb+1])\n\n\nx, y = me\nfinal_time = vis[x][y]\nans = 0\nfor i in range(n):\n for j in range(m):\n if g[i][j] not in 'SET0' and -1 < vis[i][j] <= final_time:\n ans += int(g[i][j])\n\nprint(ans)\n", "r, c = map(int, input().split())\r\n\r\nforest = []\r\nfor _ in range(r):\r\n line = input()\r\n forest.append(line)\r\n\r\nqueue = []\r\nflag = False\r\nvis = [[False for _ in range(c)] for _ in range(r)]\r\n\r\nfor i in range(r):\r\n for j in range(c):\r\n if forest[i][j] == 'E':\r\n queue.append((i, j))\r\n vis[i][j] = True\r\n break\r\n\r\nx = [-1, 0, 1, 0]\r\ny = [0, -1, 0, 1]\r\nres = 0\r\n\r\nwhile queue:\r\n queue2 = []\r\n\r\n while queue:\r\n i, j = queue.pop(0)\r\n\r\n for k in range(4):\r\n idxI, idxJ = i + x[k], j + y[k]\r\n\r\n if 0 <= idxJ < c and 0 <= idxI < r and not vis[idxI][idxJ] and forest[idxI][idxJ] != 'T':\r\n queue2.append((idxI, idxJ))\r\n vis[idxI][idxJ] = True\r\n if forest[idxI][idxJ] == 'S':\r\n flag = True\r\n\r\n try:\r\n res += int(forest[idxI][idxJ])\r\n except:\r\n continue\r\n\r\n if not flag:\r\n queue = queue2\r\n\r\nprint(res)\r\n", "from sys import stdin\r\n\r\nrints = lambda: [int(x) for x in stdin.readline().split()]\r\nrstr = lambda: stdin.readline().strip()\r\nrstr_2d = lambda n: [rstr() for _ in range(n)]\r\nvalid = lambda x, y: 0 <= x < n and 0 <= y < m and grid[x][y] != 'T'\r\ndx, dy = [0, 1, 0, -1, 1, -1, 1, -1], [1, 0, -1, 0, 1, -1, -1, 1]\r\n\r\nn, m = rints()\r\ngrid, ans, que, flag, vis = rstr_2d(n), 0, [], 0, [[0] * m for _ in range(n)]\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n if grid[i][j] == 'E':\r\n que.append((i, j))\r\n vis[i][j] = 1\r\n break\r\n\r\nwhile que:\r\n que1 = []\r\n while que:\r\n x, y = que.pop()\r\n for i in range(4):\r\n nx, ny = x + dx[i], y + dy[i]\r\n if valid(nx, ny) and not vis[nx][ny]:\r\n que1.append((nx, ny))\r\n vis[nx][ny] = 1\r\n\r\n if grid[nx][ny] == 'S':\r\n flag = 1\r\n\r\n try:\r\n ans += int(grid[nx][ny])\r\n except:\r\n continue\r\n\r\n if not flag:\r\n que = que1\r\n\r\nprint(ans)", "import sys\r\nfrom math import inf\r\ninput = sys.stdin.readline \r\n\r\nr, c = map(int, input().split()) \r\nl = [] \r\nfor i in range(r):\r\n l.append(input()[:-1]) \r\nans = [[0] * c for i in range(r)]\r\ndx = [1, -1, 0, 0] \r\ndy = [0, 0, 1, -1]\r\nd = [[inf] * c for i in range(r)]\r\nfor i in range(r):\r\n for j in range(c): \r\n if(l[i][j] == 'E'):\r\n vis = [[0] * c for i in range(r)] \r\n d[i][j] = 0 \r\n vis[i][j] = 1\r\n q = [[i, j]] \r\n while(q):\r\n u, v = q.pop(0) \r\n for _ in range(4):\r\n nx, ny = u + dx[_], v + dy[_] \r\n if(0 <= nx < r and 0 <= ny < c and not vis[nx][ny]):\r\n if(l[u][v] == 'T'):\r\n continue\r\n vis[nx][ny] = 1 \r\n q.append([nx, ny]) \r\n d[nx][ny] = min(d[nx][ny], d[u][v] + 1) \r\nu, v = 0, 0 \r\nfor i in range(r):\r\n for j in range(c):\r\n if(l[i][j] == 'S'):\r\n u, v = i, j \r\nans = 0 \r\nfor i in range(r):\r\n for j in range(c):\r\n if(l[i][j] in ['S', 'E', 'T', '0']):\r\n continue \r\n if(d[i][j] <= d[u][v]):\r\n ans += int(l[i][j]) \r\nprint(ans)\r\n\r\n \r\n \r\n \r\n " ]
{"inputs": ["5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000", "1 4\nSE23", "3 3\n000\nS0E\n000", "5 5\nS9999\nTTTT9\n99999\n9TTTT\n9999E", "1 10\n9T9TSET9T9", "10 1\nS\n9\n9\n9\n9\nE\n9\n9\n9\n9", "4 3\nS01\n234\n567\n89E", "2 2\nE9\nS4", "3 3\n920\n752\nE8S", "5 1\n9\nT\nE\n6\nS", "1 5\n78S6E", "9 8\n38030772\n697T83S2\n8T626740\n86T02062\n05402864\nT7504180\n3T368E08\n90637446\n12709560", "3 5\n00000\nS0E01\n00000"], "outputs": ["3", "2", "0", "135", "0", "72", "45", "9", "29", "6", "6", "194", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
8
1bbc1b8f93c00a8c754ecaa1479f9bbf
Lesha and array splitting
One spring day on his way to university Lesha found an array *A*. Lesha likes to split arrays into several parts. This time Lesha decided to split the array *A* into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array *A*. Lesha is tired now so he asked you to split the array. Help Lesha! The first line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array *A*. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=103<=≤<=*a**i*<=≤<=103) — the elements of the array *A*. If it is not possible to split the array *A* and satisfy all the constraints, print single line containing "NO" (without quotes). Otherwise in the first line print "YES" (without quotes). In the next line print single integer *k* — the number of new arrays. In each of the next *k* lines print two integers *l**i* and *r**i* which denote the subarray *A*[*l**i*... *r**i*] of the initial array *A* being the *i*-th new array. Integers *l**i*, *r**i* should satisfy the following conditions: - *l*1<==<=1 - *r**k*<==<=*n* - *r**i*<=+<=1<==<=*l**i*<=+<=1 for each 1<=≤<=*i*<=&lt;<=*k*. If there are multiple answers, print any of them. Sample Input 3 1 2 -3 8 9 -12 3 4 -4 -10 7 3 1 0 4 1 2 3 -5 Sample Output YES 2 1 2 3 3 YES 2 1 2 3 8 NO YES 4 1 1 2 2 3 3 4 4
[ "a=int(input())\r\nb=list(map(int,input().split()))\r\ns=0\r\nl=[]\r\nfor i in b:\r\n s+=i\r\nif s!=0:\r\n print(\"YES\")\r\n print(\"1\")\r\n print(\"1\",len(b))\r\nelif len(b)==b.count(0):\r\n print(\"NO\")\r\nelse:\r\n for i in b:\r\n if i!=0:\r\n break\r\n t=b.index(i)+1\r\n print('YES')\r\n print(2)\r\n print(\"1\",t)\r\n print(t+1,len(b))", "n=int(input())\r\nt=list(map(int,input().split()))\r\nx=-1\r\ny=0\r\nfor i in range(len(t)):\r\n if t[i]!=0:\r\n y+=t[i]\r\n x=i\r\nif y==0 and x==-1:\r\n print('NO')\r\nelif y!=0:\r\n print('YES')\r\n print('1')\r\n print('1',n)\r\nelse:\r\n print('YES')\r\n print('2')\r\n print('1',x)\r\n print(x+1,n)", "a=int(input())\r\nx=list(map(int, input().split()))\r\nz=x.count(0)\r\nif z!=a:\r\n print('YES')\r\n s=sum(x)\r\n if s==0:\r\n print(2)\r\n for i in x:\r\n if s-i!=0:\r\n print(1, x.index(i) + 1)\r\n print(x.index(i) + 2, a)\r\n break\r\n else:\r\n print(1)\r\n print(1, a)\r\nelse:\r\n print('NO')", "n=int(input())\r\nl=map(int,input().split(' '))\r\na=[i for i in l]\r\nle=len(a)\r\nif sum(a)!=0:\r\n print(\"YES\")\r\n print(1)\r\n print(1,n)\r\nelse:\r\n if (a==[0]*le):\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n c,i=0,0\r\n while c==0:\r\n c+=a[i]\r\n i+=1\r\n print(2)\r\n print(1,i)\r\n print(i+1,n)", "n = int(input())\r\narr = list(map(int, input().split()))\r\nif max(arr) == 0 and min(arr) == 0:\r\n print(\"NO\")\r\n exit()\r\nres = 0\r\nfor i in range(n):\r\n res += arr[i]\r\nif res != 0:\r\n print(\"YES\")\r\n print(1)\r\n print(1, n)\r\n exit()\r\nfor i in range(n):\r\n if arr[i] != 0:\r\n print(\"YES\")\r\n print(2)\r\n print(1, i + 1)\r\n print(i + 2, n)\r\n break\r\n", "# -*- coding: utf-8 -*-\n\"\"\"Untitled32.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1h3IpvwlE57gmpF-POk0U_uQ6SxX3l1i8\n\"\"\"\n\nt=int(input())\na=list(map(int,input().split()))\n\nc = a.count(0)\n\nif (c==t):\n print(\"NO\")\n\nelse:\n print(\"YES\")\n s=sum(a)\n\n if s!=0:\n print(1)\n print(1, t)\n\n else:\n for i in range(t):\n s=s-a[i]\n\n if s!=0:\n print(2)\n print(1, i + 1)\n print(i + 2, t)\n break", "n = int(input())\r\nA = list(map(int, input().split()))\r\nif sum(A) != 0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\nelse:\r\n if A == [0] * n:\r\n print('NO')\r\n else:\r\n print('YES')\r\n j = i = 0\r\n while j == 0:\r\n j += A[i]\r\n i += 1\r\n print(2)\r\n print(1,i)\r\n print(i+1, n)", "n=int(input())\r\na= list(map(int, input().split()))\r\n\r\nsum = 0\r\ncount = 0\r\nlist1 = [[0,0]]\r\n\r\nif max(a)!= 0 or min(a)!= 0:\r\n for i in range(n):\r\n if sum == 0 and a[i] == 0:\r\n continue\r\n\r\n if sum + a[i] != 0:\r\n sum += a[i]\r\n list1[count][1] = i\r\n else:\r\n count+= 1\r\n sum=a[i]\r\n list1 += [[i, i]]\r\n\r\n print('YES')\r\n print(count+1)\r\n for i in list1:\r\n print(i[0]+1,i[1]+1)\r\nelse:\r\n print('NO')", "n = int(input())\r\narr = [int(x) for x in input().split()]\r\nif arr.count(0) == n:\r\n print('NO')\r\n exit()\r\nprint('YES') \r\nif sum(arr)!= 0:\r\n print(1)\r\n print(1,n)\r\nelse:\r\n print(2)\r\n for i in range(n):\r\n if arr[i]!= 0:\r\n print(1,i+1)\r\n print(i+2,n) \r\n break \r\n\r\n \r\n\r\n\r\n ", "t = int(input())\r\na = list(map(int, input().split()))\r\nv = True\r\nif sum(a)!=0:\r\n print('YES')\r\n print('1')\r\n print('1 '+str(len(a)))\r\n v = False\r\nelse:\r\n sum = 0\r\n for i in range(0,t):\r\n sum+=a[i]\r\n if sum != 0:\r\n print('YES')\r\n print('2')\r\n print('1 '+str(i+1))\r\n print(str(i+2)+' '+str(t))\r\n v = False\r\n break\r\nif v: print('NO')", "n = int(input())\na = list(map(int, input().split()))\ns = sum(a)\n\nif s != 0:\n print(\"YES\")\n print(\"1\")\n print(\"1 {}\".format(n))\nelse:\n i = 0\n while i < n and a[i] == 0:\n i += 1\n if i == n:\n print(\"NO\")\n else:\n print(\"YES\")\n print(\"2\")\n print(\"{} {}\".format(1, i + 1))\n print(\"{} {}\".format(i + 2, n))", "n=int(input())\r\na=list(map(int,input().split()))\r\nif a.count(0)==n:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n if sum(a)!=0:\r\n print(1)\r\n print(1,n)\r\n else:\r\n b = a[0]\r\n c = 1\r\n for i in range(1, n, 1):\r\n c += 1\r\n x = a[i:n]\r\n if sum(x) != 0 and b != 0:\r\n print(2)\r\n print(1, i)\r\n print(i + 1, n)\r\n break\r\n else:\r\n b = b + a[i]\r\n", "x=int(input ())\r\na=list (map (int, input ().split()))\r\nif sum(a)!=0: \r\n print(\"YES\")\r\n print (1)\r\n print (1,x)\r\nelse:\r\n if a.count(0)==x:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n print(2)\r\n for i in range(x):\r\n if a[i]!=0:\r\n break \r\n print(1,1+i)\r\n print(2+i,x)", "# -*- coding: utf-8 -*-\n\"\"\"lesha.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1qPEL3ZvhPSjGqqN4uFZOtrE0gqsUMjGZ\n\"\"\"\n\nn=int(input())\nl1=list(map(int,input().split()))\nif l1.count(0)==n:\n print(\"NO\")\nelse:\n print(\"YES\")\n sum=sum(l1)\n if sum!=0:\n print(1)\n print(1, n)\n else:\n for i in range(n):\n sum-=l1[i]\n if sum!=0:\n print(2)\n print(1, i + 1)\n print(i + 2, n)\n break", "n = int(input())\r\nA = list(map(int,input().split()))\r\nsumA = sum(A)\r\nif sumA:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\n exit()\r\nfor x in range(n):\r\n sumA -= A[x]\r\n if sumA:\r\n print('YES')\r\n print(2)\r\n print(1,x+1)\r\n print(x+2,n)\r\n break\r\nelse:\r\n print('NO')", "# -*- coding: utf-8 -*-\n\"\"\"Untitled48.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1HcAE-KAbJxHaJBbMZKHasFZyjjv_ztxg\n\"\"\"\n\nn = int(input())\nl = list(map(int, input().split()))\n\nsum = 0\ncount = 0\noutputs = [[0,0]]\n\nif max(l) != 0 or min(l) != 0:\n for i in range(n):\n if sum == 0 and l[i] == 0:\n continue\n\n if sum + l[i] != 0:\n sum += l[i]\n outputs[count][1] = i\n else:\n count += 1\n sum = l[i]\n outputs += [[i, i]]\n\n print('YES')\n print(count + 1)\n for i in outputs:\n print(i[0] + 1, i[1] + 1)\nelse:\n print('NO')\n\n", "n=int(input())\r\narray=list(map(int,input().split()))\r\nm=0\r\nif sum(array)!=0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\nelse:\r\n for i in array:\r\n if i==0:\r\n m+=1\r\n if m==n:\r\n print('NO')\r\n else:\r\n print('YES')\r\n j=0\r\n k=0\r\n while j==0:\r\n j+=array[k]\r\n k+=1\r\n print(2)\r\n print(1,k)\r\n print(k+1,n)", "n=int(input())\r\nl=list(map(int,input().split()))\r\nif l.count(0)==n:\r\n print('NO')\r\nelse:\r\n print('YES')\r\nt=sum(l)\r\nif t!=0:\r\n print(1)\r\n print(1,n)\r\nelse:\r\n for i in range(n):\r\n t=l[i]\r\n if t!=0:\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)\r\n break", "# -*- coding: utf-8 -*-\n\"\"\"754.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1hYxPSks58iBj6lqO-ZFgsg_7bcRbm3l3\n\"\"\"\n\n#https://codeforces.com/contest/754/problem/A Lesha and array splitting\n\nn=int(input())\nl=list(map(int,input().split()))\nif (l.count(0)==n):\n print('NO')\nelse:\n print('YES')\ns=sum(l)\nif s!=0:\n print(1)\n print(1,n)\nelse:\n for i in range(n):\n s=l[i]\n if s!=0:\n print(2)\n print(1,i+1)\n print(i+2,n)\n break", "n = int(input())\r\nA = list(map(int, input().split()))\r\nsumA = sum(A)\r\nif sumA:\r\n print('YES')\r\n print(1)\r\n print(1, n)\r\n exit()\r\nfor x in range(n):\r\n sumA -= A[x]\r\n if sumA:\r\n print('YES')\r\n print(2)\r\n print(1, x + 1)\r\n print(x + 2, n)\r\n break\r\nelse:\r\n print('NO')", "n=int(input())\r\narr=list(map(int,input().split()))\r\ni=0\r\nansarr=[]\r\nwhile(i<n):\r\n\tcountx=0\r\n\tj=i\r\n\twhile(j<n and countx<2):\r\n\t\tif(countx==1 and arr[j]!=0):\r\n\t\t\tbreak\r\n\t\telif(arr[j]!=0):\r\n\t\t\tcountx+=1\r\n\t\tj+=1\r\n\tif(j==n and countx!=1):\r\n\t\tprint(\"NO\")\r\n\t\texit(0)\r\n\tansarr.append(i+1)\r\n\tansarr.append(j)\r\n\ti=j\r\nprint(\"YES\")\r\nprint(len(ansarr)//2)\r\n\r\nprint(*ansarr)\r\n\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nsum=0\r\nfor i in range(n):\r\n\tsum+=a[i]\r\nif sum!=0:\r\n\tprint(\"YES\")\r\n\tprint(1)\r\n\tprint(1,n)\r\nelse:\r\n\ti=1\r\n\tsum=a[0]\r\n\tcheck=0\r\n\tfor p in range(1,n):\r\n\t\tif sum==0:\r\n\t\t\ti+=1\r\n\t\t\tsum+=a[p]\r\n\t\telse:\r\n\t\t\tcheck=1\r\n\t\t\tbreak\r\n\tif check==1:\r\n\t\tprint(\"YES\")\r\n\t\tprint(2)\r\n\t\tprint(1,i)\r\n\t\tprint(i+1,n)\r\n\telse:\r\n\t\tprint(\"NO\")", "n= int(input())\r\nl = list(map(int, input().split()))\r\n\r\ns = 0\r\nc = 0\r\noutput = [[0,0]]\r\n\r\nif max(l) != 0 or min(l) != 0:\r\n for i in range(n):\r\n if s == 0 and l[i] == 0:\r\n continue\r\n\r\n if s + l[i] != 0:\r\n s += l[i]\r\n output[c][1] = i\r\n else:\r\n c += 1\r\n s = l[i]\r\n output += [[i, i]]\r\n\r\n print('YES')\r\n print(c + 1)\r\n for i in output:\r\n print(i[0] + 1, i[1] + 1)\r\nelse:\r\n print('NO')", "\r\nn = int(input())\r\n\r\narr = list(map(int,input().strip().split()))\r\n\r\nt = sum(arr)\r\nz = 0\r\nst = 0\r\n\r\nfor i in range(n-1,-1,-1):\r\n t-=arr[i]\r\n z+=arr[i]\r\n if t!=0 and z!=0:\r\n st = 1\r\n print(\"YES\")\r\n print(2)\r\n print(\"1 \"+str(i))\r\n print(str(i+1)+\" \"+str(n))\r\n break\r\n \r\n \r\nif st == 0:\r\n if sum(arr)!=0:\r\n print(\"YES\")\r\n print(1)\r\n print(\"1 \"+str(n))\r\n else:\r\n print(\"NO\")\r\n", "k,e = int(input()), list(map(int, input().split()))\r\nx = next((i for i, ai in enumerate(e) if ai), None) \r\nif x is None:\r\n print('NO')\r\nelif sum(e):\r\n print('YES', 1, '1 {}'.format(k), sep='\\n')\r\nelse:\r\n print('YES', 2, '1 {}'.format(x + 1), '{} {}'.format(x + 2, k), sep='\\n')\r\n \r\n \r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nif l.count(0)==n:\r\n print('NO')\r\nelif sum(l)!=0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\nelif sum(l)==0 and l.count(0)==0:\r\n print('YES')\r\n print(n)\r\n for i in range(1,n+1):\r\n print(i,i)\r\nelif sum(l)==0 and l[n-1]==0 and l[0]==0:\r\n print('YES') \r\n print(2)\r\n i=0\r\n while i<n and l[i]==0:\r\n i+=1\r\n print(1,i+1) \r\n print(i+2,n)\r\nelif sum(l)==0 and l[n-1]!=0:\r\n print('YES')\r\n print(2)\r\n print(1,n-1)\r\n print(n,n)\r\nelif sum(l)==0 and l[0]!=0:\r\n print('YES')\r\n print(2)\r\n print(1,1)\r\n print(2,n) ", "s=int(input())\r\narray=[i for i in map(int, input().split(' '))]\r\nif sum(array)!=0:\r\n print('YES')\r\n print(1)\r\n print(1,s)\r\nelse:\r\n if array==[0]*len(array):\r\n print('NO')\r\n else:\r\n print('YES')\r\n x=0\r\n i=0\r\n while x==0:\r\n x+=array[i]\r\n i+=1\r\n print(2)\r\n print(1,i)\r\n print(i+1,s)", "n = int(input())\nla = list(map(int, input().split()))\n\nlb = [i + 1 for i in range(n) if la[i] != 0]\n\nif len(lb) == 0:\n print('NO')\nelse:\n lb[-1] = n\n print('YES')\n print(len(lb))\n prev = 0\n for i in range(len(lb)):\n print(' '.join(map(str, [prev + 1, lb[i]])))\n prev = lb[i]\n", "n = int(input())\r\narray = list(map(int, input().split()))\r\nif sum(array) != 0:\r\n print('YES')\r\n print(1)\r\n print(1, n)\r\nelse:\r\n if array == [0] * len(array):\r\n print('NO')\r\n else:\r\n print('YES')\r\n c = 0\r\n i = 0\r\n while c == 0:\r\n c += array[i]\r\n i += 1\r\n print(2)\r\n print(1, i)\r\n print(i + 1, n)", "import sys,math\r\nn = int(input())\r\narray = list(map(int,input().split()))\r\nif array.count(0)==n:\r\n print('NO')\r\n sys.exit()\r\nif sum(array)==0:\r\n print('YES')\r\n print(2)\r\n i = 1\r\n while sum(array[0:i]) ==0 or sum(array[i:])==0:\r\n i+=1\r\n print(1,i)\r\n print(i+1,n)\r\nelse:\r\n print('YES')\r\n print(1)\r\n print(1,n)", "n=int(input())\r\na=list(map(int,input().split()))\r\nif a.count(0)==n:\r\n print('NO')\r\nelif sum(a)!=0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\nelif sum(a)==0 and a.count(0)==0:\r\n print('YES')\r\n print(n)\r\n for i in range(1,n+1):\r\n print(i,i)\r\nelif sum(a)==0 and a[n-1]==0 and a[0]==0:\r\n print('YES') \r\n print(2)\r\n i=0\r\n while i<n and a[i]==0:\r\n i+=1\r\n print(1,i+1) \r\n print(i+2,n)\r\nelif sum(a)==0 and a[n-1]!=0:\r\n print('YES')\r\n print(2)\r\n print(1,n-1)\r\n print(n,n)\r\nelif sum(a)==0 and a[0]!=0:\r\n print('YES')\r\n print(2)\r\n print(1,1)\r\n print(2,n)", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\nn=int(input())\r\narr=[int(x) for x in input().split()]\r\nif sum(arr)==0:\r\n for i in range(n):\r\n if arr[i]!=0:\r\n print('YES')\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)\r\n exit()\r\n break\r\n else:\r\n print('NO')\r\n exit()\r\nprint('YES')\r\nprint(1)\r\nprint(1,n)\r\n\r\n", "n = int(input())\r\nh = list(map(int,input().split()))\r\nk = len(h)\r\nm = 0\r\np = [1]\r\nl = h.count(0)\r\nif l == k:\r\n print(\"NO\")\r\n quit()\r\nfor i in range(k):\r\n if h[i]==0:\r\n continue\r\n m+=h[i]\r\n if m==0:\r\n p.append(i)\r\n p.append(i+1)\r\n m+=h[i]\r\ns = len(p)\r\nprint(\"YES\")\r\nif s%2==0:\r\n m = s//2\r\n print(s//2)\r\nelse:\r\n m = (s//2)+1\r\n print((s//2)+1)\r\n p.append(k)\r\nk = 0\r\nj = 0\r\nfor i in range(m):\r\n j += k\r\n print(p[j], p[j+1])\r\n k=2", "n = int(input())\r\nlist1= list(map(int,input().split()))\r\nsumlist1 = sum(list1)\r\nif sumlist1:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\n exit()\r\nfor x in range(n):\r\n sumlist1 -= list1[x]\r\n if sumlist1:\r\n print('YES')\r\n print(2)\r\n print(1,x+1)\r\n print(x+2,n)\r\n break\r\nelse:\r\n print('NO')\r\n ", "from sys import stdin, stdout\r\n\r\nn = int(stdin.readline())\r\nvalues = list(map(int, stdin.readline().split()))\r\ncnt = [values[0]]\r\n\r\nfor i in range(1, n):\r\n cnt.append(cnt[-1] + values[i])\r\n\r\nif values.count(0) == n:\r\n stdout.write('NO')\r\nelif cnt[-1]:\r\n stdout.write('YES\\n1\\n1 ' + str(n))\r\nelse:\r\n for i in range(n):\r\n if values[i]:\r\n m = i + 1\r\n break\r\n \r\n stdout.write('YES\\n2\\n1 ' + str(m) + '\\n' + str(m + 1) + ' ' + str(n))", "n=int(input())\r\nl=list(map(int,input().split()))\r\nif(l.count(0)==n):\r\n print(\"NO\")\r\nelse:\r\n s=0\r\n t=[1]\r\n d=[]\r\n for i in range(n):\r\n s=s+l[i]\r\n if(l[i]!=0 and s==0):\r\n t.append(i)\r\n d.append(t)\r\n t=[i+1]\r\n s=l[i]\r\n t.append(n)\r\n d.append(t)\r\n print(\"YES\")\r\n print(len(d))\r\n for i in d:\r\n print(i[0],i[1])\r\n", "tr=int(input())\r\nl=list(map(int,input().split()))\r\nif (l.count(0)==tr):\r\n print('NO')\r\nelse:\r\n print('YES')\r\n \r\nif sum(l) != 0:\r\n print(1)\r\n print(1,tr)\r\nelse:\r\n for t in range(tr):\r\n a = l[t]\r\n if a != 0:\r\n print(2)\r\n print(1, t+1)\r\n print(t+2, tr)\r\n break", "n=int(input())\r\nl=list(map(int, input().split()))\r\nif sum(l)!=0:\r\n print(\"YES\")\r\n print(1)\r\n print(1,n)\r\nelse:\r\n for i in range(1,n):\r\n if sum(l[:i])!=0:\r\n print(\"YES\")\r\n print(2)\r\n print(1,i)\r\n print(i+1,n)\r\n quit()\r\n print(\"NO\")", "R = lambda : list(map(int, input().split()))\nn,a,s = R(),R(),0\nfor x in a:\n\ts+=x\nif s:\n\tprint(\"YES\\n1\\n1 \"+str(len(a)))\nelse:\n\tp,f=0,0\n\tfor i in range(len(a)):\n\t\tp+=a[i]\n\t\tif(p!=0 and not f):\n\t\t\tprint(\"YES\\n2\\n1 %d\\n%d %d\" % (i+1, i+2, len(a)))\n\t\t\tf=1\n\tif not f:\n\t\tprint(\"NO\") \n\t\t\t\n\n", "n=int(input())\r\na=list(map(int, input().split()))\r\ns=0\r\nc=0\r\nb=[[0,0]]\r\nif min(a)!=0 or max(a)!=0:\r\n for i in range(n):\r\n if s==0 and a[i]==0:\r\n continue\r\n if s+a[i]!= 0:\r\n b[c][1] =i\r\n s=s+a[i]\r\n else:\r\n c=c+1\r\n s=a[i]\r\n b=b+[[i, i]]\r\n print('YES')\r\n print(c+1)\r\n for i in b:\r\n print(i[0]+1, i[1]+1)\r\nelse:\r\n print('NO')", "n = int(input())\ndata = list(map(int, input().split()))\n\n\ndef _temp(length):\n if sum(data[:length]) != 0:\n if sum(data[length:n]):\n return True\n else:\n return False\n else:\n return False\n\n\nif sum(data):\n print('YES')\n print(1)\n print(1, n)\nelif[0]*n == data:\n print('NO')\nelse:\n length = 1\n for i in range(n):\n if not _temp(length):\n\n length += 1\n else:\n break\n print('YES')\n print(2)\n print(1, length)\n print(length+1, n)\n", "i = int(input())\r\nl = list(map(int,input().split()))\r\nif set(l) == set([0,0,0]): print('NO')\r\nelse:\r\n log = []\r\n c = 1\r\n for x in range(i):\r\n if l[x] != 0: log.append([c,x+1]); c = x+2\r\n if l[-1]==0:\r\n log[-1][-1] = i\r\n print('YES'); print(len(log))\r\n for x in log:\r\n print(*x)", "n = int(input())\r\narr = list(map(int,input().split()))\r\nsm = sum(arr)\r\nif sm!=0:\r\n print(\"YES\")\r\n print(1)\r\n print(1,n)\r\nelse:\r\n sm = 0\r\n done = False\r\n for i in range(n):\r\n sm += arr[i]\r\n if sm!=0:\r\n print(\"YES\")\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)\r\n done = True\r\n break\r\n if not done: \r\n print(\"NO\")", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Jan 1 23:32:22 2022\r\n\r\n@author: Anshu\r\n\"\"\"\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nx=0\r\nif (a.count(0)==n):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n for j in range(n):\r\n x=x+a[j]\r\n if x!=0:\r\n print(1)\r\n print(1, n)\r\n else:\r\n for i in range(n):\r\n x-=a[i]\r\n if x!=0:\r\n print(2)\r\n print(1, i + 1)\r\n print(i + 2, n)\r\n break", "n = int(input())\r\na = list(map(int,input().split()))\r\nif sum(a) != 0:\r\n print('YES')\r\n print(1)\r\n print(1, n)\r\nelse:\r\n if a == [0] * n:\r\n print('NO')\r\n else:\r\n print('YES')\r\n j = i = 0\r\n while j == 0:\r\n j = j + a[i]\r\n i = i + 1\r\n print(2)\r\n print(1, i)\r\n print(i+1, n)", "def main():\r\n n = int(input())\r\n a = [int(c) for c in input().split()]\r\n\r\n if all(e == 0 for e in a):\r\n print('NO')\r\n return\r\n\r\n if sum(a) != 0:\r\n print('YES')\r\n print(1)\r\n print(1, n)\r\n return\r\n\r\n for i, e in enumerate(a, 1):\r\n if e != 0:\r\n print('YES')\r\n print(2)\r\n print(1, i)\r\n print(i + 1, n)\r\n return\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n, a = int(input()), list(map(int, input().split()))\r\nx = next((i for i, ai in enumerate(a) if ai), None) # find index of first non-zero elements in a\r\nif x is None:\r\n print('NO')\r\nelif sum(a):\r\n print('YES', 1, '1 {}'.format(n), sep='\\n')\r\nelse:\r\n print('YES', 2, '1 {}'.format(x + 1), '{} {}'.format(x + 2, n), sep='\\n')", "n=int(input())\r\nl=list(map(int,input().split()))\r\ns=0\r\ncondition=True\r\nfor i in l:\r\n s+=i\r\n if i!=0:\r\n condition=False\r\n \r\nif s!=0:\r\n print(\"YES\")\r\n print(1)\r\n print(1,len(l))\r\nelif condition:\r\n print(\"NO\")\r\nelse:\r\n a=[]\r\n b=[]\r\n s1=0\r\n for j in range(len(l)):\r\n s1+=l[j]\r\n if s1!=0:\r\n c=j\r\n b=l[j:]\r\n break\r\n a.append(l[j])\r\n print(\"YES\")\r\n print(2)\r\n print(1,c+1)\r\n print(c+2,len(l))", "n = int(input())\r\nlst = list(map(int, input().split()))\r\n \r\nif sum(lst) != 0:\r\n print(\"YES\\n1\\n1 %d\" % (n))\r\nelse:\r\n for i in range(1, n):\r\n if sum(lst[:i]) != 0:\r\n print(\"YES\\n2\\n1 %d\\n%d %d\" % (i, i+1, n))\r\n quit()\r\n print(\"NO\")", "n=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nif l.count(0)==n:\r\n print(\"NO\")\r\n\r\nelif sum(l)!=0:\r\n print(\"YES\")\r\n print(1)\r\n print(1,n)\r\n\r\nelse:\r\n print(\"YES\")\r\n print(n-l.count(0))\r\n\r\n if l.count(0)==0:\r\n for i in range(1,n+1):\r\n print(i,i)\r\n\r\n else:\r\n a = []\r\n for i in range(1,n+1): \r\n if l[i-1]!=0:\r\n a.append(i)\r\n\r\n for i in range(0,len(a)):\r\n if i == 0:\r\n print(1,a[1]-1)\r\n elif i == len(a)-1:\r\n print(a[i],n)\r\n else: \r\n print(a[i],a[i+1]-1)", "'https://codeforces.com/contest/754/problem/A'\r\nn=int(input())\r\nnum=list(map(int,input().split()))\r\nif(sum(num)!=0):\r\n\tprint(\"YES\")\r\n\tprint(1)\r\n\tprint(1,n)\r\nelse:\r\n\tans=0\r\n\tfor i in range(n):\r\n\t\tans+=num[i]\r\n\t\tif(ans!=0):\r\n\t\t\tprint(\"YES\")\r\n\t\t\tprint(\"2\")\r\n\t\t\tprint(1,i+1)\r\n\t\t\tprint(i+2,n)\r\n\t\t\tf=1\r\n\t\t\tbreak\r\n\t\telse:\r\n\t\t\tf=0\r\n\tif(f==0):\r\n\t\tprint(\"NO\")", "n=int(input())\r\na=[int(i) for i in input().split()]\r\nif a.count(0)==n:\r\n print('NO')\r\nelif sum(a)!=0:\r\n print('YES',1,sep='\\n')\r\n print(1,n)\r\nelse:\r\n print('YES',2,sep='\\n')\r\n for i in range(1,n):\r\n if sum(a[:i]):\r\n print(1,i)\r\n print(i+1,n)\r\n break", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nif all(i==0 for i in a): print('NO'); exit()\r\nif sum(a)!=0: \r\n print('YES')\r\n print(1)\r\n print(1,n)\r\nelse:\r\n s=0\r\n for i in range(n):\r\n s+=a[i]\r\n if s!=0:\r\n print('YES')\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)\r\n exit()", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nans = \"NO\"\r\nfor i in a:\r\n if i:\r\n ans = \"YES\"\r\nprint(ans)\r\nif ans == \"NO\":\r\n exit()\r\ns = sum(a)\r\nif s:\r\n k = 1\r\n ans = [\"1 \" + str(n)]\r\nelse:\r\n k = 2\r\n for i in range(n):\r\n if a[i]:\r\n ans = [\"1 \" + str(i + 1), str(i + 2) + \" \" + str(n)]\r\n break\r\nprint(k)\r\nsys.stdout.write(\"\\n\".join(ans))", "n = int(input())\r\na = [*map(int, input().split())]\r\nif sum(a) != 0:\r\n print(\"YES\")\r\n print(1)\r\n print(1, n)\r\n quit()\r\nelse:\r\n for i in range(n):\r\n if sum(a[:i + 1]) != 0 and sum(a[i + 1:]) != 0:\r\n print(\"YES\")\r\n print(2)\r\n print(1, i + 1)\r\n print(i + 2, n)\r\n quit()\r\nprint(\"NO\")", "a = int(input())\r\nx = list(map(int,input().split()))\r\nif(x.count(0) == a):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n k = sum(x)\r\n if k != 0:\r\n print(1)\r\n print(1, a)\r\n else:\r\n for i in range(a):\r\n k -= x[i]\r\n if k != 0:\r\n print(2)\r\n print(1, i + 1)\r\n print(i + 2, a)\r\n break", "n = int(input())\r\ns = list(map(int, input().split()))\r\n\r\nzero_count = 0\r\nnz_idx = -1\r\nfor i in range(len(s)):\r\n if s[i] == 0:\r\n zero_count += 1\r\n elif nz_idx == -1:\r\n nz_idx = i\r\n \r\nif zero_count == len(s):\r\n print('NO')\r\nelif sum(s) != 0:\r\n print('YES')\r\n print(1)\r\n print(f'1 {len(s)}')\r\nelse:\r\n print('YES')\r\n print(2)\r\n print(f'1 {nz_idx+1}')\r\n print(f'{nz_idx+2} {len(s)}')\r\n", "x = int(input())\r\nl_i = list(map(int, input().split()))\r\n\r\nl_s = list()\r\nc_l = list()\r\nc_s = 0\r\n\r\nc_l.append(1)\r\nfor i in range(len(l_i)):\r\n if l_i[i] + c_s == 0:\r\n if len(c_l) != 0 and c_s != 0:\r\n c_l.append(i)\r\n l_s.append(c_l)\r\n c_l = list()\r\n c_l.append(i + 1)\r\n c_s = 0\r\n c_s += l_i[i]\r\nc_l.append(len(l_i))\r\nl_s.append(c_l)\r\n\r\nif c_s == 0 and len(c_l) != 0:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n print(len(l_s))\r\n for l in l_s:\r\n print(\" \".join(str(x) for x in l))", "n,b=int(input()),0\r\na=[int(i) for i in input().split()]\r\nif sum(a)!=0:\r\n print(\"YES\",1,sep='\\n')\r\n print(1,n)\r\nelse:\r\n for i,j in enumerate(a):\r\n if j!=0:\r\n b=i+1\r\n break\r\n if b==0:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\",2,sep='\\n')\r\n print(1,b)\r\n print(b+1,n)", "n = int(input())\r\ns = [i for i in map(int, input().split(' '))]\r\nif sum(s) != 0:\r\n\tprint('YES')\r\n\tprint(1)\r\n\tprint(1, n)\r\nelse:\r\n\tif s == [0] * len(s):\r\n\t\tprint('NO')\r\n\telse:\r\n\t\tprint('YES')\r\n\t\tcount = 0\r\n\t\ti = 0\r\n\t\twhile count == 0:\r\n\t\t\tcount += s[i]\r\n\t\t\ti += 1\r\n\t\tprint(2)\r\n\t\tprint(1, i)\r\n\t\tprint(i + 1, n)", "n = int(input())\r\ninputArr = list(map(int,input().split()))[:n]\r\nsumArr = [inputArr[0]]\r\ncnt = 0\r\nif(inputArr[0]!=0):\r\n cnt += 1\r\nfor i in range(1, n):\r\n sumArr.append(sumArr[i-1]+inputArr[i])\r\n if sumArr[-1]!=0:\r\n cnt += 1\r\nif cnt == 0:\r\n print('NO')\r\nelse:\r\n print('YES')\r\n if sumArr[-1] != 0:\r\n print(1)\r\n print(1,n)\r\n else:\r\n for j in range(n-1, -1, -1):\r\n if sumArr[j] != 0:\r\n print(2)\r\n print(1,j+1)\r\n print(j+2,n)\r\n break;", "def main():\r\n N = int(input())\r\n arr = [ int(i) for i in input().split() ]\r\n\r\n C = [ 0 for i in range(N + 2) ]\r\n\r\n for i in range(N):\r\n C[i + 1] = C[i] + arr[i]\r\n \r\n a = 0\r\n b = N\r\n while(a < b):\r\n if(C[b] - C[a] != 0):\r\n break\r\n else:\r\n b -= 1\r\n \r\n if(a < b):\r\n print('YES')\r\n print('2' if b != N else '1')\r\n print(a + 1, b)\r\n if(b != N):\r\n print(b + 1, N)\r\n else:\r\n print('NO')\r\n\r\nmain()\r\n", "N = int(input())\nnums = [int(i) for i in input().split(' ')]\n\nsub = []\nstart = 0\nend = 0\nfor i in range(N):\n if nums[i] != 0:\n end = i\n sub.append([start, end])\n start = i + 1\nif end != N - 1 and len(sub) > 0:\n sub[-1][1] = N - 1\n\nif len(sub) > 0:\n print('YES')\n print(len(sub))\n for s in sub:\n print('%d %d' % (s[0] + 1, s[1] + 1))\nelse:\n print('NO')\n", "N = int(input())\r\na = list(map(int, input().split()))\r\nd = []\r\nfor i in range(N):\r\n if a[i] != 0:\r\n break\r\nelse:\r\n print('NO')\r\n exit()\r\n\r\nst = 0\r\nfor i in range(N):\r\n if a[i] != 0:\r\n for j in range(i + 1, N):\r\n if a[j] != 0:\r\n d.append((1, j))\r\n st = j\r\n break\r\n else:\r\n print('YES')\r\n print(1)\r\n print(1, N)\r\n exit()\r\n break\r\n\r\ni = st\r\nwhile i < N:\r\n j = i + 1\r\n while j < N and a[j] == 0:\r\n j += 1\r\n d.append((i + 1, j))\r\n i = j\r\n\r\n\r\nprint('YES')\r\nprint(len(d))\r\nfor i, j in d:\r\n print(i, j)\r\n\r\n", "n = int(input())\r\nl = list(map(int,input().split()))\r\nsum = sum(l)\r\nx = l.count(0)\r\nif x == n:\r\n print('NO')\r\nelse:\r\n if sum!=0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\n else:\r\n for i in range(n):\r\n sum = sum - l[i]\r\n if sum!=0:\r\n print('YES')\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)\r\n break", "n = int(input())\r\na = list(map(int,input().split()))\r\ns = sum(a)\r\nif a.count(0) == n:\r\n print('NO')\r\nelse :\r\n print('YES')\r\n if s != 0:\r\n print(1)\r\n print(1,n)\r\n else:\r\n for i in range(n):\r\n if s-a[i] != 0:\r\n print(2)\r\n print(1,i+1)\r\n print(i+2, n)\r\n exit()\r\n", "import sys\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\ncount=0\r\nfor i in a:\r\n if i == 0:\r\n count+=1\r\n if count == n:\r\n print('NO')\r\n sys.exit()\r\nif sum(a) != 0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\nelse:\r\n for j in range(n):\r\n if a[j]!=0:\r\n break\r\n print('YES')\r\n print(2)\r\n print(1,j+1)\r\n print(j+2,n)", "n=int(input())\r\nl=list(map(int,input().split()))\r\nzero=0\r\nfor i in l:\r\n\tif(i==0):\r\n\t\tzero+=1\r\nif(zero==n):\r\n\tprint(\"NO\")\r\n\texit(0)\r\nprint(\"YES\")\r\nans = []\r\ni = 0\r\nwhile(l[i]==0):\r\n\ti+=1\r\nans.append([0,i])\r\ni+=1\r\nwhile(i<n):\r\n\tif(l[i]==0):\r\n\t\t_l = ans[len(ans)-1]\r\n\t\tdel ans[len(ans)-1]\r\n\t\t_l[1]=i\r\n\t\tans.append(_l)\r\n\telse:\r\n\t\tans.append([i,i])\r\n\ti+=1\r\nprint(len(ans))\r\nfor i in ans:\r\n\tprint(i[0]+1,i[1]+1)\r\n", "n = int(input())\r\nL = list(map(int,input().split()))\r\nsumL= sum(L)\r\nif sumL:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\n exit()\r\nfor x in range(n):\r\n sumL -= L[x]\r\n if sumL:\r\n print('YES')\r\n print(2)\r\n print(1,x+1)\r\n print(x+2,n)\r\n break\r\nelse:\r\n print('NO')", "n=int(input())\r\nl=[int(x) for x in input().split()][:n]\r\nif l.count(0)==len(l):\r\n print(\"NO\")\r\nelif sum(l)!=0:\r\n print('YES',1,sep='\\n')\r\n print(1,n)\r\nelse:\r\n for i in range(n):\r\n if(l[i]!=0):\r\n break\r\n print('YES',2,sep=\"\\n\")\r\n print(1,i+1)\r\n print(i+2,n)", "# -*- coding: utf-8 -*-\n\"\"\"lesha1.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1eB7Wmyhui4KlLGPxuOoC5kzz9TDqKlYk\n\"\"\"\n\nx = int(input())\nlis = list(map(int,input().split()))\nans = 0\nif sum(lis) == 0:\n for i in range(1,x):\n s1 , s2 = lis[:i] , lis[i:]\n if sum(s1) != 0 and sum(s2) != 0:\n ans = 1\n print(\"YES\")\n print(2)\n print(1,i)\n print(i+1,len(lis))\n break\n if ans == 0:\n print(\"NO\")\nelse:\n print(\"YES\")\n print(1) \n print(1,len(lis))", "n = int(input())\r\na = list(map(int, input().split()))\r\nif list(set(a)) == [0]:\r\n print(\"NO\")\r\nelif sum(a) != 0:\r\n print(\"YES\")\r\n print(1)\r\n print(1, n)\r\nelse:\r\n for x in range(n):\r\n if sum(a[:x+1]) != 0 and sum(a[x+1:]) != 0:\r\n print(\"YES\")\r\n print(2)\r\n print(1, x+1)\r\n print(x+2, n)\r\n break\r\n \r\n \r\n \r\n \r\n \r\n ", "input()\r\narr = [int(x) for x in input().split()]\r\n\r\ndef solve():\r\n\r\n i = get_first(arr)\r\n if i is None:\r\n print('NO')\r\n return\r\n\r\n tail = arr[i+1:]\r\n\r\n if not len(tail):\r\n print('YES')\r\n print('1')\r\n print('1 {}'.format(str(len(arr))))\r\n return\r\n s = sum(tail)\r\n if s:\r\n print('YES')\r\n print('2')\r\n print('1', i+1)\r\n print(i+2, len(arr), sep=' ')\r\n return\r\n print('YES')\r\n print('1')\r\n print('1 {}'.format(str(len(arr))))\r\n return\r\n\r\n # for i, num in enumerate(arr):\r\n # if num != 0:\r\n # break\r\n # else:\r\n # print('NO')\r\n # return\r\n # if i == len(arr) - 1:\r\n # print('YES')\r\n # print('1')\r\n # print('1 {}'.format(str(len(arr))))\r\n # return\r\n # print('YES')\r\n # print('2')\r\n\r\n\r\ndef get_first(arr):\r\n for i, num in enumerate(arr):\r\n if num != 0:\r\n return i\r\n return None\r\n\r\nsolve()", "n = int(input())\na = [int(i) for i in input().split()]\nif sum(a) != 0:\n print('YES')\n print(1)\n print(1, n)\n exit()\nif n == 1 or a.count(0) == n:\n print('NO')\n exit()\ni = 0\nwhile a[i] == 0:\n i += 1\nprint('YES')\nprint(2)\nprint(1, i + 1)\nprint(i + 2, n)\n\n", "n=int(input())\r\ns=list(map(int,input().split()))\r\nle=len(s)\r\nif(s.count(0)==len(s)):\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n if(sum(s)!=0):\r\n print('1')\r\n print(1,len(s))\r\n else:\r\n x=0\r\n for i in range(0,len(s)):\r\n if(s[i]!=0):\r\n x=i\r\n break\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)\r\n", "n = int(input())\r\nl = list(map(int,input().split()))\r\n\r\nif all(i == 0 for i in l ): print('NO') ;exit()\r\n\r\nif sum(l) != 0 :\r\n print('YES')\r\n print('1')\r\n print(1 , n)\r\n\r\nelse:\r\n s = 0\r\n for i in range(n):\r\n s += l[i]\r\n if s != 0 :\r\n print('YES')\r\n print(2)\r\n print(1 , i + 1 )\r\n print(i + 2 , n)\r\n exit()\r\n", "def Main(n):\r\n arr = list(map(int, input().split()))\r\n if any(arr):\r\n print('YES')\r\n if sum(arr):\r\n print(1)\r\n print(1,n)\r\n else:\r\n for i, v in enumerate(arr):\r\n if v:\r\n print(2)\r\n print(1,i + 1)\r\n print(i + 2, n)\r\n break\r\n else:\r\n print('NO')\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n Main(n)", "n=int(input())\r\nj=list(map(int,input().split()))\r\nk=sum(j)\r\nif j.count(0)==n:\r\n print(\"NO\")\r\nelse:\r\n print(\"YES\")\r\n if k!=0:\r\n print(1)\r\n print(1,n)\r\n else:\r\n for i in range(n):\r\n if k-j[i]!=0:\r\n print(2)\r\n print(1,i+1)\r\n print(i+2, n)\r\n break", "#For fast I/O\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\nn = int(input())\r\nl = [int(i) for i in input().split()]\r\n\r\ns = sum(l)\r\nif s != 0:\r\n\tprint('YES')\r\n\tprint(1)\r\n\tprint(1,n)\r\nelse:\r\n\tpossible = False\r\n\r\n\tfor i in range(n):\r\n\t\tif l[i] != 0:\r\n\t\t\tpossible = True\r\n\t\t\tprint('YES')\r\n\t\t\tprint(2)\r\n\t\t\tprint(1,i+1)\r\n\t\t\tprint(i+2,n)\r\n\t\t\tbreak\r\n\r\n\tif not possible:\r\n\t\tprint('NO')\r\n", "#lesha/array splitting\r\nn = int(input())\r\nl_elements = list(map(int, input().split()))\r\nif (l_elements.count(0) != n):\r\n print('YES')\r\nelse:\r\n print('NO')\r\nn1 = sum(l_elements)\r\nif n1 != 0:\r\n print(1)\r\n print(1,n)\r\nelse:\r\n for _ in range(n):\r\n n1 = l_elements[_]\r\n if n1 != 0:\r\n print(2)\r\n print(1,_+1)\r\n print(_+2,n)\r\n break", "import sys\r\nimport itertools\r\n\r\ndef input(): return sys.stdin.readline().rstrip(\"\\r\\n\")\r\ndef List(): return list(map(int, input().split()))\r\ndef Num(): return int(input())\r\n\r\n\r\nn = Num()\r\na = List()\r\nif sum(a) != 0:\r\n print(\"YES\")\r\n print(1)\r\n print(1, n)\r\nelif a.count(0) == n:\r\n print(\"NO\")\r\nelse:\r\n if 0 not in a:\r\n print(\"YES\")\r\n print(n)\r\n for i in range(n):\r\n print(i + 1, i + 1)\r\n else:\r\n idx = []\r\n last = 0\r\n s = 0\r\n for i in range(n):\r\n s += a[i]\r\n if s != 0:\r\n idx.append([last + 1, i + 1])\r\n s = 0\r\n last = i + 1\r\n if len(idx) == 1:\r\n break\r\n if idx[0][1] != n:\r\n idx.append([idx[0][1] + 1, n])\r\n print(\"YES\")\r\n print(len(idx))\r\n for i in idx:\r\n print(*i)\r\n", "n = int(input())\r\nlst = list(map(int, input().split()))\r\nif sum(lst) != 0:\r\n print(\"YES\")\r\n print(1)\r\n print(f'1 {n}')\r\nelif lst.count(0) == n:\r\n print(\"NO\")\r\nelse:\r\n ndx = next(i for i, x in enumerate(lst) if x != 0)\r\n print(\"YES\")\r\n print(2)\r\n print(f'1 {1+ndx}')\r\n print(f'{2+ndx} {n}')", "n=int(input())\r\na=list(map(int,input().split()))\r\nsum = 0\r\nfor i in range(n):\r\n sum = sum + a[i]\r\nif sum:\r\n print (\"YES\")\r\n print (\"1\")\r\n print (\"1\",n)\r\nelse:\r\n teksum,ans = 0,0\r\n\r\n for i in range(n):\r\n if teksum:\r\n ans=i\r\n break\r\n else:\r\n teksum = teksum + a[i]\r\n if ans == 0:\r\n print(\"NO\")\r\n else:\r\n print(\"YES\")\r\n print(\"2\")\r\n print(\"1\",ans)\r\n ans = ans +1\r\n print(ans,n)\r\n", "n = int(input())\r\nls = list(map(int, input().split()))\r\n\r\nif all(i == 0 for i in ls):\r\n print('NO')\r\n quit()\r\nprint('YES')\r\nif sum(ls) != 0:\r\n print(1)\r\n print(1, n)\r\nelse:\r\n for i in range(n):\r\n if ls[i] != 0:\r\n print(2)\r\n print(1, i+1)\r\n print(i+2, n)\r\n break\r\n", "n=int(input())\r\nk=list(map(int,input().split()))\r\ns=sum(k)\r\nm=k.count(0)\r\nif m==n:\r\n print('NO')\r\nelse:\r\n if s!=0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\n else:\r\n for i in range(n):\r\n s=s-k[i]\r\n if s!=0:\r\n print('YES')\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)\r\n break", "n = int(input())\r\nl = list(map(int, input().split()))\r\nsum=int(0)\r\nn = len(l)\r\nfor ele in range(0, len(l)):\r\n sum = sum + l[ele]\r\nif sum:\r\n print(\"YES\")\r\n print(1)\r\n print(1, n)\r\n exit()\r\nfor i in range(n):\r\n for ele in range(0, len(l)):\r\n sum = sum + l[ele]\r\n sum=sum-l[i]\r\n if sum:\r\n print(\"YES\")\r\n print(2)\r\n print(1, i + 1)\r\n print(i + 2, n)\r\n break\r\nelse:\r\n print(\"NO\")", "n=int(input())\r\nl=[int(x) for x in input().split()][:n]\r\nif sum(l)!=0:\r\n print('YES')\r\n print(1)\r\n print(1,n)\r\nelif l==[0]*n:\r\n print(\"NO\")\r\nelse:\r\n for i in range(n):\r\n if(l[i]!=0):\r\n break\r\n print('YES')\r\n print(2)\r\n print(1,i+1)\r\n print(i+2,n)", "n = int(input())\r\no = list(map(int,input().split()))\r\na = 0\r\nif o.count(0) == n:\r\n result = 'NO'\r\n print(result)\r\nelse:\r\n result = 'YES'\r\n print(result)\r\nc = 0 \r\nif result == 'YES':\r\n for i in range(n):\r\n c += o[i]\r\nif result == 'YES':\r\n\r\n if c == 0:\r\n for i in range(n):\r\n a += o[i]\r\n if a == 0 and o[i] != 0:\r\n z = i\r\n x = 2\r\n print(x)\r\n print(1,z)\r\n print(z+1,n)\r\n\r\n elif c != 0:\r\n print(1)\r\n print(1,n)" ]
{"inputs": ["3\n1 2 -3", "8\n9 -12 3 4 -4 -10 7 3", "1\n0", "4\n1 2 3 -5", "6\n0 0 0 0 0 0", "100\n507 -724 -243 -846 697 -569 -786 472 756 -272 731 -534 -664 202 592 -381 161 -668 -895 296 472 -868 599 396 -617 310 -283 -118 829 -218 807 939 -152 -343 -96 692 -570 110 442 159 -446 -631 -881 784 894 -3 -792 654 -273 -791 638 -599 -763 586 -812 248 -590 455 926 -402 61 228 209 419 -511 310 -283 857 369 472 -82 -435 -717 -421 862 -384 659 -235 406 793 -167 -504 -432 -951 0 165 36 650 -145 -500 988 -513 -495 -476 312 -754 332 819 -797 -715", "100\n1 -2 -1 -1 2 2 0 1 -1 1 0 -2 1 -1 0 -2 -1 -1 2 0 -1 2 0 1 -2 -2 -1 1 2 0 -2 -2 -1 1 1 -1 -2 -1 0 -1 2 1 -1 -2 0 2 1 1 -2 1 1 -1 2 -2 2 0 1 -1 1 -2 0 0 0 0 0 0 -2 -2 2 1 2 2 0 -1 1 1 -2 -2 -2 1 0 2 -1 -2 -1 0 0 0 2 1 -2 0 -2 0 2 1 -2 -1 2 1", "7\n0 0 0 0 3 -3 0", "5\n0 0 -4 0 0", "100\n2 -38 51 -71 -24 19 35 -27 48 18 64 -4 30 -28 74 -17 -19 -25 54 41 3 -46 -43 -42 87 -76 -62 28 1 32 7 -76 15 0 -82 -33 17 40 -41 -7 43 -18 -27 65 -27 -13 46 -38 75 7 62 -23 7 -12 80 36 37 14 6 -40 -11 -35 -77 -24 -59 75 -41 -21 17 -21 -14 67 -36 16 -1 34 -26 30 -62 -4 -63 15 -49 18 57 7 77 23 -26 8 -20 8 -16 9 50 -24 -33 9 -9 -33", "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 -38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100\n0 0 -17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "3\n1 -3 3", "3\n1 0 -1", "3\n3 0 0", "3\n0 0 0", "3\n-3 3 0", "4\n3 -2 -1 3", "4\n-1 0 1 0", "4\n0 0 0 3", "4\n0 0 0 0", "4\n3 0 -3 0", "5\n-3 2 2 0 -2", "5\n0 -1 2 0 -1", "5\n0 2 0 0 0", "5\n0 0 0 0 0", "5\n0 0 0 0 0", "20\n101 89 -166 -148 -38 -135 -138 193 14 -134 -185 -171 -52 -191 195 39 -148 200 51 -73", "20\n-118 -5 101 7 9 144 55 -55 -9 -126 -71 -71 189 -64 -187 123 0 -48 -12 138", "20\n-161 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 -137 0 0 0 0 137", "40\n64 -94 -386 -78 35 -233 33 82 -5 -200 368 -259 124 353 390 -305 -247 -133 379 44 133 -146 151 -217 -16 53 -157 186 -203 -8 117 -71 272 -290 -97 133 52 113 -280 -176", "40\n120 -96 -216 131 231 -80 -166 -102 16 227 -120 105 43 -83 -53 229 24 190 -268 119 230 348 -33 19 0 -187 -349 -25 80 -38 -30 138 -104 337 -98 0 1 -66 -243 -231", "40\n0 0 0 0 0 0 324 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "40\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", "40\n0 0 0 0 0 308 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -308 0 0 0 0 0 0 0", "60\n-288 -213 -213 -23 496 489 137 -301 -219 -296 -577 269 -153 -52 -505 -138 -377 500 -256 405 588 274 -115 375 -93 117 -360 -160 429 -339 502 310 502 572 -41 -26 152 -203 562 -525 -179 -67 424 62 -329 -127 352 -474 417 -30 518 326 200 -598 471 107 339 107 -9 -244", "60\n112 141 -146 -389 175 399 -59 327 -41 397 263 -422 157 0 471 -2 -381 -438 99 368 173 9 -171 118 24 111 120 70 11 317 -71 -574 -139 0 -477 -211 -116 -367 16 568 -75 -430 75 -179 -21 156 291 -422 441 -224 -8 -337 -104 381 60 -138 257 91 103 -359", "60\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 -238 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "60\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", "60\n0 0 0 0 0 0 0 0 0 -98 0 0 0 0 0 0 0 0 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "80\n-295 -774 -700 -366 -304 -173 -672 288 -721 -256 -348 650 223 211 379 -13 -483 162 800 631 -550 -704 -357 -306 490 713 -80 -234 -669 675 -688 471 315 607 -87 -327 -799 514 248 379 271 325 -244 98 -100 -447 574 -154 554 -377 380 -423 -140 -147 -189 -420 405 464 -110 273 -226 -109 -578 641 -426 -548 214 -184 -397 570 -428 -676 652 -155 127 462 338 534 -782 -481", "80\n237 66 409 -208 -460 4 -448 29 -420 -192 -21 -76 -147 435 205 -42 -299 -29 244 -480 -4 -38 2 -214 -311 556 692 111 -19 -84 -90 -350 -354 125 -207 -137 93 367 -481 -462 -440 -92 424 -107 221 -100 -631 -72 105 201 226 -90 197 -264 427 113 202 -144 -115 398 331 147 56 -24 292 -267 -31 -11 202 506 334 -103 534 -155 -472 -124 -257 209 12 360", "80\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 668 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "80\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", "80\n0 0 0 0 0 0 0 0 0 0 0 0 -137 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100\n-98 369 544 197 -991 231 399 521 582 -820 -650 -919 -615 -411 -843 -974 231 140 239 -209 721 84 -834 -27 162 460 -157 -40 0 -778 -491 -607 -34 -647 834 -7 -518 -5 -31 -766 -54 -698 -838 497 980 -77 238 549 -135 7 -629 -892 455 181 527 314 465 -321 656 -390 368 384 601 332 561 -1000 -636 -106 412 -216 -58 -365 -155 -445 404 114 260 -392 -20 840 -395 620 -860 -936 1 882 958 536 589 235 300 676 478 434 229 698 157 -95 908 -170", "100\n-149 -71 -300 288 -677 -580 248 49 -167 264 -215 878 7 252 -239 25 -369 -22 526 -415 -175 173 549 679 161 -411 743 -454 -34 -714 282 -198 -47 -519 -45 71 615 -214 -317 399 86 -97 246 689 -22 -197 -139 237 -501 477 -385 -421 -463 -641 409 -279 538 -382 48 189 652 -696 74 303 6 -183 336 17 -178 -617 -739 280 -202 454 864 218 480 293 -118 -518 -24 -866 -357 410 239 -833 510 316 -168 38 -370 -22 741 470 -60 -507 -209 704 141 -148", "100\n0 0 697 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 475 0 0 0 0", "4\n0 0 3 -3", "4\n1 0 0 0", "4\n3 3 3 3", "2\n0 1", "4\n0 -1 1 0", "1\n1", "5\n0 0 1 0 0", "4\n0 0 1 0", "10\n1 2 0 0 3 -3 0 0 -3 0", "3\n0 -1 0", "2\n1 0", "5\n3 -3 0 0 0", "3\n0 1 0", "4\n0 0 0 1", "4\n1 -1 1 -1", "1\n-1", "2\n1 1", "2\n1 -1", "2\n0 0", "2\n0 -1", "2\n-1 1", "2\n-1 0", "2\n-1 -1", "3\n5 -5 5", "5\n1 0 -1 0 1", "6\n0 0 0 3 0 0", "3\n1 -1 1"], "outputs": ["YES\n3\n1 1\n2 2\n3 3", "YES\n8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8", "NO", "YES\n4\n1 1\n2 2\n3 3\n4 4", "NO", "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75...", "YES\n78\n1 1\n2 2\n3 3\n4 4\n5 5\n6 7\n8 8\n9 9\n10 11\n12 12\n13 13\n14 15\n16 16\n17 17\n18 18\n19 20\n21 21\n22 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 39\n40 40\n41 41\n42 42\n43 43\n44 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 56\n57 57\n58 58\n59 59\n60 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 73\n74 74\n75 75\n76 76\n77 77\n78 78\n79 79\n80 81\n82 82\n83 83\n84 84\n85 88\n89 89\n90 90\n91 92\n93 94\n95 95\n96 96\n...", "YES\n2\n1 5\n6 7", "YES\n1\n1 5", "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76...", "YES\n1\n1 100", "NO", "YES\n2\n1 34\n35 100", "YES\n3\n1 1\n2 2\n3 3", "YES\n2\n1 2\n3 3", "YES\n1\n1 3", "NO", "YES\n2\n1 1\n2 3", "YES\n4\n1 1\n2 2\n3 3\n4 4", "YES\n2\n1 2\n3 4", "YES\n1\n1 4", "NO", "YES\n2\n1 2\n3 4", "YES\n4\n1 1\n2 2\n3 4\n5 5", "YES\n3\n1 2\n3 4\n5 5", "YES\n1\n1 5", "NO", "NO", "YES\n20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20", "YES\n19\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 17\n18 18\n19 19\n20 20", "YES\n1\n1 20", "NO", "YES\n2\n1 19\n20 20", "YES\n40\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40", "YES\n38\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 36\n37 37\n38 38\n39 39\n40 40", "YES\n1\n1 40", "NO", "YES\n2\n1 32\n33 40", "YES\n60\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60", "YES\n58\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60", "YES\n1\n1 60", "NO", "YES\n2\n1 18\n19 60", "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75...", "YES\n80\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75...", "YES\n1\n1 80", "NO", "YES\n2\n1 13\n14 80", "YES\n99\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n75 75\n76...", "YES\n100\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54\n55 55\n56 56\n57 57\n58 58\n59 59\n60 60\n61 61\n62 62\n63 63\n64 64\n65 65\n66 66\n67 67\n68 68\n69 69\n70 70\n71 71\n72 72\n73 73\n74 74\n7...", "YES\n1\n1 100", "NO", "YES\n2\n1 95\n96 100", "YES\n2\n1 3\n4 4", "YES\n1\n1 4", "YES\n4\n1 1\n2 2\n3 3\n4 4", "YES\n1\n1 2", "YES\n2\n1 2\n3 4", "YES\n1\n1 1", "YES\n1\n1 5", "YES\n1\n1 4", "YES\n5\n1 1\n2 4\n5 5\n6 8\n9 10", "YES\n1\n1 3", "YES\n1\n1 2", "YES\n2\n1 1\n2 5", "YES\n1\n1 3", "YES\n1\n1 4", "YES\n4\n1 1\n2 2\n3 3\n4 4", "YES\n1\n1 1", "YES\n2\n1 1\n2 2", "YES\n2\n1 1\n2 2", "NO", "YES\n1\n1 2", "YES\n2\n1 1\n2 2", "YES\n1\n1 2", "YES\n2\n1 1\n2 2", "YES\n3\n1 1\n2 2\n3 3", "YES\n3\n1 2\n3 4\n5 5", "YES\n1\n1 6", "YES\n3\n1 1\n2 2\n3 3"]}
UNKNOWN
PYTHON3
CODEFORCES
88
1bc048bce4f6f19733a32be0b610de7a
Wonderful Randomized Sum
Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite that Valera is one of the best students, he failed to manage with the new homework. That's why he asks for your help. He has the following task. A sequence of *n* numbers is given. A prefix of a sequence is the part of the sequence (possibly empty), taken from the start of the sequence. A suffix of a sequence is the part of the sequence (possibly empty), taken from the end of the sequence. It is allowed to sequentially make two operations with the sequence. The first operation is to take some prefix of the sequence and multiply all numbers in this prefix by <=-<=1. The second operation is to take some suffix and multiply all numbers in it by <=-<=1. The chosen prefix and suffix may intersect. What is the maximum total sum of the sequence that can be obtained by applying the described operations? The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of elements in the sequence. The second line contains *n* integers *a**i* (<=-<=104<=≤<=*a**i*<=≤<=104) — the sequence itself. The first and the only line of the output should contain the answer to the problem. Sample Input 3 -1 -2 -3 5 -4 2 0 5 0 5 -1 10 -5 10 -2 Sample Output 6 11 18
[ "class Container:\n pass\n\nn = int(input())\nvalues = list(map(int, input().split()))\nbest_prefixes = (n + 1) * [ 0 ]\nplus = 0\nbest_double_minus = double_minus = 0\n\nfor i, x in enumerate(values):\n plus += x\n double_minus -= 2 * x\n best_double_minus = max(best_double_minus, double_minus)\n best_prefixes[i + 1] = plus + best_double_minus\n\nbest = best_prefixes[n]\nplus = 0\nbest_double_minus = double_minus = 0\nfor i in range(n - 1, -1, -1):\n x = values[i]\n plus += x\n double_minus -= 2 * x\n best_double_minus = max(best_double_minus, double_minus)\n best = max(best, best_prefixes[i] + plus + best_double_minus)\n\nprint(best)\n", "n = int(input())\nvalues = list(map(int, input().split()))\n\nbest_infix = infix = 0\nfor x in values:\n infix = max(0, infix + x)\n best_infix = max(best_infix, infix)\n\nprint(2 * best_infix - sum(values))\n", "# by the authority of GOD author: manhar singh sachdev #\r\n\r\nimport os,sys\r\nfrom io import BytesIO,IOBase\r\n\r\ndef main():\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n dp = [0 if a[-1]>0 else a[-1]]\r\n dp1 = [0 if a[-1]<0 else a[-1]]\r\n xx = a[-1]\r\n for i in range(n-2,0,-1):\r\n xx += a[i]\r\n dp.append(min(dp[-1],xx))\r\n dp1.append(max(dp1[-1],xx))\r\n dp.reverse()\r\n dp1.reverse()\r\n tot = sum(a)\r\n ans = abs(tot)\r\n x = 0\r\n for i in range(n-1):\r\n x += a[i]\r\n ans = max(ans,tot+abs(x)-x+max(abs(dp[i])-dp[i],abs(dp1[i])-dp1[i]))\r\n print(ans)\r\n\r\n#Fast IO Region\r\nBUFSIZE = 8192\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\nif __name__ == '__main__':\r\n main()", "n=int(input())\r\nans1=0\r\nans=0\r\nsum=0\r\nx=map(int,input().split())\r\nfor i in x:\r\n sum+=i\r\n ans1+=i\r\n ans1=max(ans1,0)\r\n ans=max(ans,ans1)\r\nprint(2*ans-sum)\r\n", "n = int(input())\nseq = list(map(int, input().split()))\n\nsoma, melhor = 0, 0\n\nfor i in seq:\n soma = max(0, soma + i)\n melhor = max(melhor, soma)\n\nprint(2*melhor - sum(seq))", "from sys import stdin\r\n\r\nn = int(stdin.readline())\r\n\r\nnums = [int(x) for x in stdin.readline().split()]\r\n\r\ntotal = sum(nums)*-1\r\n\r\nbest = 0\r\n\r\nleft = 0\r\nright = 0\r\n\r\ncurrent = 0\r\n\r\nwhile right < n:\r\n while current >= 0 and right < n:\r\n current += nums[right]\r\n best = max(best,current)\r\n right += 1\r\n while current < 0:\r\n current -= nums[left]\r\n left += 1\r\n best = max(best,current)\r\n\r\nprint(total+best*2)\r\n", "# LUOGU_RID: 111245501\nfrom sys import stdin \ninput = stdin.readline \n\ndef get() : \n return map(int,input().split())\n\nn = int(input()) \nlst = [0] + list(get()) \ntot = sum(lst) \n\nt = 0 \nres = 0 \n\nfor i in range(1, n + 1) : \n if t + lst[i] < 0 : t = 0 \n else : \n t += lst[i] \n res = max(res, t) \nres = max(res, t) \n\nprint(2 * res - tot)", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nf = [[-float('inf')] * 2 for _ in range(n)]\r\n# 换\r\nf[0][1] = -a[0]\r\nf[0][0] = max(a[0],-a[0])\r\n\r\nfor i in range(1,n):\r\n f[i][1]=f[i-1][1]-a[i]\r\n f[i][0]=max(f[i][1],f[i-1][0]+a[i])\r\n\r\n\r\nres=f[-1][0]\r\n\r\nsuf=[[-float('inf')]*2 for _ in range(n)]\r\nsuf[n-1][1]=-a[n-1]\r\nsuf[n-1][0]=max(a[-1],-a[-1])\r\nif n>=2:\r\n res=max(res,f[n-2][0]+suf[n-1][0])\r\nfor i in range(n-2,-1,-1):\r\n suf[i][1]=suf[i+1][1]-a[i]\r\n suf[i][0]=max(suf[i][1],suf[i+1][0]+a[i])\r\n if i>0:\r\n res=max(res,f[i-1][0]+suf[i][0])\r\n else:\r\n res=max(res,suf[0][0])\r\n\r\nprint(res)\r\n \r\n\r\n", "# import sys \n# sys.stdin = open('input.txt', 'r') \n# sys.stdout = open('output.txt', 'w')\n\nn = int(input())\na = list(map(int,input().split()))\ntotalSum = sum(a)\nprefixSum = [0]*(n+1)\nsuffixSum = [0]*(n+1)\nfor i in range(n):\n\tprefixSum[i+1] = prefixSum[i] + a[i]\n\tsuffixSum[n-i-1] = suffixSum[n-i] + a[n-i-1]\nmaxNegative = [0]*(n+1)\nfor i in range(1,n+1):\n\tmaxNegative[i] = min(maxNegative[i-1],prefixSum[i])\n# print(*maxNegative)\n# print(*suffixSum)\nans = 0\nfor i in range(n,-1,-1):\n\tans = min(ans,suffixSum[i]+maxNegative[i])\nprint(totalSum-2*ans)", "n = int(input())\r\ns = input().split()\r\na = []\r\nsum = 0\r\nfor i in range(0, n) :\r\n a.append(int(s[i]))\r\n sum += int(s[i])\r\nmaxx = 0\r\ns = 0\r\nfor i in range(0, n) :\r\n if (s + a[i] < 0) : s = 0\r\n else :\r\n s += a[i]\r\n maxx = max(maxx, s)\r\nmaxx = max(maxx, s)\r\nprint(maxx * 2 - sum)", "\r\nn=int(input())\r\nans1=0\r\nans=0\r\nsum=0\r\nx=list(input().split())\r\nfor i in range(len(x)):\r\n sum+=int(x[i])\r\n ans1+=int(x[i])\r\n ans1=max(ans1,0)\r\n ans=max(ans,ans1)\r\n\r\nprint(2*ans-sum)", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nprefs = [0]\r\nsufs = [0]\r\nmin_prefs = [0]\r\nmin_sufs = [0]\r\ns = sum(a)\r\nfor i in range(n):\r\n min_prefs.append(min(min_prefs[-1], prefs[-1] + a[i]))\r\n prefs.append(prefs[-1] + a[i])\r\n min_sufs.append(min(min_sufs[-1], a[n - 1 - i] + sufs[-1]))\r\n sufs.append(a[n - 1 - i] + sufs[-1])\r\nsufs.reverse()\r\nmin_sufs.reverse()\r\nans = s\r\nfor i in range(n + 1):\r\n ans = max(ans, s - 2 * (min_sufs[i] + min_prefs[i]))\r\nprint(ans)", "n = int(input())\r\nvalues = list(map(int, input().split()))\r\n\r\nbest_infix = infix = 0\r\nfor x in values:\r\n infix = max(0, infix + x)\r\n best_infix = max(best_infix, infix)\r\n\r\nprint(2 * best_infix - sum(values))", "n = int(input())\na = list(map(int,input().split()))\ns = sum(a)\ndp = [0]*n\ndp[0] = a[0]\nif n > 1:\n for i in range(1,n):\n dp[i] = max(dp[i-1]+a[i],a[i])\nT = max(dp)\nif max(a) <= 0:\n print(-s)\nelse:\n print(2*T-s)", "N = int(input())\n\nsequence = [int(d) for d in input().split()]\n\nSUM = []\nSUM.append(0)\nfor i in range(N):\n running = SUM[i] + sequence[i]\n SUM.append(running)\n\n\n\nLEFT = []\nLEFT.append(0)\nfor i in range(N):\n running = LEFT[i] - sequence[i]\n\n LEFT.append(running)\n\n\nRIGHT = []\nRIGHT.append(-SUM[-1])\n\nfor i in range(N):\n running = RIGHT[i] + sequence[i]\n\n RIGHT.append(running)\n\nbestest = 0\nleft_index = 0\n\n# Te amo Benjamín Rubio <3\nfor i in range(0, N+1):\n right_index = i\n\n new_left = LEFT[i]\n\n if new_left > LEFT[left_index]:\n left_index = i\n\n middle = SUM[right_index] - SUM[left_index]\n\n current_sum = LEFT[left_index] + middle + RIGHT[right_index]\n\n bestest = max(bestest, current_sum)\n\n\nprint(bestest)\n\t\t\t\t \t\t\t\t\t \t \t \t\t \t\t\t \t \t\t", "n, a = int(input()), list(map(int, input().split()))\r\nb = a[:: -1]\r\nfor i in range(n - 1): a[i + 1] += a[i]\r\nfor i in range(n - 1): b[i + 1] += b[i]\r\ns, a, b = a[-1], [0] + a, [0] + b\r\nfor i in range(n): a[i + 1] = min(a[i], a[i + 1])\r\nfor i in range(n): b[i + 1] = min(b[i], b[i + 1])\r\nb.reverse()\r\nprint(s - 2 * min(a[i] + b[i] for i in range(n)))", "n = int(input())\r\nsumm = 0\r\nmx = 0\r\nl = [*map(int ,input().split())]\r\nfor i in l:\r\n summ += i\r\n if summ < 0:\r\n summ = 0\r\n mx = max(summ , mx)\r\nsumm = 0\r\nfor i in l:\r\n summ += i\r\nprint(2*mx-summ)\r\n", "def f1(arr):\r\n n = len(arr)\r\n premax = [[0, 0] for _ in range(n + 1)]\r\n p0 = p1 = 0\r\n for i, x in enumerate(arr):\r\n q0 = max(p0, p1) + x\r\n q1 = p1 - x\r\n premax[i + 1][0] = p0 = q0\r\n premax[i + 1][1] = p1 = q1\r\n ans = sum(arr)\r\n ans = max(ans, -ans)\r\n s0 = 0\r\n for i in range(n - 1, -1, -1):\r\n ans = max(ans, s0 + max(premax[i + 1]))\r\n s0 -= arr[i]\r\n return ans\r\n\r\n\r\ndef f2(arr):\r\n p0 = p1 = p2 = 0\r\n for x in arr:\r\n q0 = p0 - x\r\n q1 = max(p0, p1) + x\r\n # 本题中p2可以不用从p0转移过来,因为p0和p2做的事是一样的,可以直接用p0代替\r\n # q2 = max(p0, p1, p2) - x\r\n q2 = max(p1, p2) - x\r\n p0, p1, p2 = q0, q1, q2\r\n return max(p0, p1, p2)\r\n\r\n\r\ndef f3(arr):\r\n n = len(arr)\r\n ans = sum(arr)\r\n ans = max(ans, -ans)\r\n for i in range(n):\r\n for j in range(i - 1, n):\r\n s0 = 0 if i == 0 else sum(arr[:i]) * -1\r\n s1 = 0 if j < i else sum(arr[i: j + 1])\r\n s2 = 0 if j + 1 == n else sum(arr[j + 1:]) * -1\r\n ans = max(ans, s0 + s1 + s2)\r\n return ans\r\n\r\n\r\ndef test():\r\n import numpy.random as r\r\n lo, hi = -10, 10\r\n N = 20\r\n for _ in range(10000):\r\n n = r.randint(1, N)\r\n arr = r.randint(lo, hi + 1, n).tolist()\r\n r1 = f1(arr)\r\n r2 = f2(arr)\r\n r3 = f3(arr)\r\n if not (r1 == r2 == r3):\r\n print(arr)\r\n print(1, r1, r2, r3)\r\n return\r\n lo, hi = -10, 10\r\n N = 200\r\n for _ in range(10):\r\n n = r.randint(1, N)\r\n arr = r.randint(lo, hi + 1, n).tolist()\r\n r1 = f1(arr)\r\n r2 = f2(arr)\r\n r3 = f3(arr)\r\n if not (r1 == r2 == r3):\r\n print(arr)\r\n print(2, r1, r2, r3)\r\n return\r\n print(\"ac\")\r\n\r\n\r\n# test()\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nprint(f1(arr))\r\n" ]
{"inputs": ["3\n-1 -2 -3", "5\n-4 2 0 5 0", "5\n-1 10 -5 10 -2", "1\n-3", "4\n1 4 -5 -2", "7\n-17 6 5 0 1 4 -1", "3\n0 -2 3", "2\n0 3", "15\n14 0 -10 -5 0 19 -6 0 -11 -20 -18 -8 -3 19 -7", "15\n0 -35 32 24 0 27 10 0 -19 -38 30 -30 40 -3 22", "100\n-43 0 -81 10 67 61 0 76 -16 1 -1 69 -59 -87 14 -20 -48 -41 90 96 8 -94 -2 27 42 84 19 13 0 -87 -41 40 -61 31 -4 100 -64 10 16 -3 85 91 -63 -34 96 42 -85 95 -84 78 94 -70 51 60 90 -16 69 0 -63 -87 67 -82 -75 65 74 0 23 15 0 5 -99 -23 38 85 21 0 77 61 46 11 -37 -86 -19 89 -82 -64 20 -8 93 12 -82 -74 -85 -30 -65 -55 31 -24 6 90", "100\n0 -36 40 0 0 -62 -1 -77 -23 -3 25 17 0 -30 26 1 69 0 -5 51 -57 -73 61 -66 53 -8 -1 60 -53 3 -56 52 -11 -37 -7 -63 21 -77 41 2 -73 0 -14 0 -44 42 53 80 16 -55 26 0 0 -32 0 56 -18 -46 -19 -58 80 -33 65 59 -16 -70 -56 -62 -62 6 -29 21 37 33 59 -8 -38 -31 0 23 -40 -16 73 -69 -63 -10 37 25 68 77 -71 73 -7 75 56 -12 -57 0 0 74", "20\n0 2 3 1 0 3 -3 0 -1 0 2 -1 -1 3 0 0 1 -3 2 0", "100\n6 2 -3 6 -4 -6 -2 -1 -6 1 3 -4 -1 0 -3 1 -3 0 -2 -3 0 3 1 6 -5 0 4 -5 -5 -6 3 1 3 4 0 -1 3 -4 5 -1 -3 -2 -6 0 5 -6 -2 0 4 -4 -5 4 -2 0 -5 1 -5 0 5 -4 2 -3 -2 0 3 -6 3 2 -4 -3 5 5 1 -1 2 -6 6 0 2 -3 3 0 -1 -4 0 -6 0 0 -6 5 -4 1 6 -5 -1 -2 3 4 0 6", "100\n40 0 -11 -27 -7 7 32 33 -6 7 -6 23 -11 -46 -44 41 0 -47 -4 -39 -2 49 -43 -15 2 -28 -3 0 0 -4 4 17 27 31 -36 -33 6 -50 0 -37 36 19 26 45 -21 -45 3 25 -3 0 -15 4 -16 -49 -23 -12 -27 -36 -4 44 -8 -43 34 -2 -27 -21 0 -49 7 8 0 -4 -30 0 -23 -43 0 -8 -27 -50 -38 -2 -19 25 33 22 -2 -27 -42 -32 14 0 -40 39 -8 33 -13 -21 15 4", "30\n8 -1 3 -7 0 -1 9 3 0 0 3 -8 8 -8 9 -3 5 -9 -8 -10 4 -9 8 6 0 9 -6 1 5 -6", "1\n7500", "2\n9944 -9293", "3\n5 -5 7", "5\n-23 -11 -54 56 -40", "10\n-8 6 0 12 0 2 3 8 2 6", "8\n3 0 -5 -2 -4 0 -5 0", "16\n57 59 -27 24 28 -27 9 -90 3 -36 90 63 1 99 -46 50", "7\n2 -1 -2 -4 -3 0 -3", "8\n57 -82 -146 -13 -3 -115 55 -76", "6\n9721 6032 8572 9026 9563 7626", "4\n26 9 -16 -24", "5\n-54 64 37 -71 -74", "100\n-42 -62 -12 -17 -80 -53 -55 -83 -69 -29 -53 -56 -40 -86 -37 -10 -55 -3 -82 -10 1 1 -51 -4 0 -75 -21 0 47 0 7 -78 -65 -29 -20 85 -13 28 35 -63 20 -41 -88 0 3 39 12 78 -59 -6 -41 -72 -69 -84 -99 -55 -61 -6 -58 -75 -36 -69 -12 -87 -99 -85 -80 -56 -96 -8 -46 -93 -2 -1 -47 -27 -12 -66 -65 -17 -48 -26 -65 -88 -89 -98 -54 -78 -83 -7 -96 -9 -42 -77 -41 -100 -51 -65 -29 -34", "100\n-88 -5 -96 -45 -11 -81 -68 -58 -73 -91 -27 -23 -89 -34 -51 -46 -70 -95 -9 -77 -99 -61 -74 -98 -88 -44 -61 -88 -35 -71 -43 -23 -25 -98 -23 0 -1 -80 -52 -47 -26 -92 -82 -73 -45 -37 -15 -49 -9 -7 -47 0 -6 -76 -91 -20 -58 -46 -74 -57 -54 -39 -61 -18 -65 -61 -19 -64 -93 -29 -82 -25 -100 -89 -90 -68 -36 -91 -59 -91 -66 -56 -96 0 -8 -42 -98 -39 -26 -93 -17 -45 -69 -85 -30 -15 -30 -82 -7 -81", "100\n87 89 48 10 31 32 68 58 56 66 33 83 7 35 38 22 73 6 13 87 13 29 3 40 96 9 100 48 33 24 90 99 40 25 93 88 37 57 1 57 48 53 70 9 38 69 59 71 38 65 71 20 97 16 68 49 79 82 64 77 76 19 26 54 75 14 12 25 96 51 43 52 58 37 88 38 42 61 93 73 86 66 93 17 96 34 35 58 45 69 65 85 64 38 36 58 45 94 26 77", "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", "4\n-83 -87 42 -96", "8\n103 395 377 -205 -975 301 548 346", "20\n18 1 10 0 14 17 -13 0 -20 -19 16 2 5 -2 4 9 1 16 12 4", "16\n-2 -11 -6 -2 -8 -2 0 3 -1 0 -5 2 -12 5 6 -9", "5\n81 26 21 28 88", "7\n2165 -8256 -9741 -9714 7347 5652 6199", "8\n4609 9402 908 9322 5132 0 1962 1069", "11\n100 233 -184 -200 -222 228 -385 -129 -126 -377 237", "5\n-4 -4 -4 -4 -4", "5\n-7 17 2 -6 -1", "8\n-1 1 4 -5 -2 3 -10 3", "9\n1 2 -4 3 6 1 1 2 -8", "9\n1 1 2 -4 1 -4 2 1 1", "14\n1 1 1 1 -3 1 -5 -3 2 -3 1 1 1 1", "7\n-12 12 -12 13 -12 12 -12", "1\n2", "5\n-2 0 0 -4 1", "13\n-2 6 6 0 6 -17 6 5 0 1 4 -1 0"], "outputs": ["6", "11", "18", "3", "12", "34", "5", "3", "74", "130", "1398", "795", "10", "64", "826", "41", "7500", "19237", "7", "184", "47", "19", "257", "15", "437", "50540", "75", "300", "4265", "5377", "5287", "0", "308", "1500", "75", "64", "244", "44744", "32404", "1491", "20", "33", "17", "22", "7", "11", "37", "2", "7", "22"]}
UNKNOWN
PYTHON3
CODEFORCES
18
1bc2b438bd8b82a4aa536af61323166e
Magazine Ad
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more than one hyphen. It is guaranteed that there are no adjacent spaces and no adjacent hyphens. No hyphen is adjacent to space. There are no spaces and no hyphens before the first word and after the last word. When the word is wrapped, the part of the word before hyphen and the hyphen itself stay on current line and the next part of the word is put on the next line. You can also put line break between two words, in that case the space stays on current line. Check notes for better understanding. The ad can occupy no more that *k* lines and should have minimal width. The width of the ad is the maximal length of string (letters, spaces and hyphens are counted) in it. You should write a program that will find minimal width of the ad. The first line contains number *k* (1<=≤<=*k*<=≤<=105). The second line contains the text of the ad — non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters. Output minimal width of the ad. Sample Input 4 garage for sa-le 4 Edu-ca-tion-al Ro-unds are so fun Sample Output 7 10
[ "n = int(input())\r\na = input()\r\nr=len(a)+1\r\na = a.replace(' ','- ').replace('-','- ').split()\r\nl = max(map(lambda x: len(x),a))\r\nwhile l < r:\r\n m,lines,x = (r-l)//2+l,1,0\r\n for b in a:\r\n if x+len(b) > m:\r\n x = len(b)\r\n lines += 1\r\n else:\r\n x += len(b)\r\n if lines > n:\r\n l = m+1\r\n else:\r\n r = m\r\nprint(r)", "import sys\r\n\r\nk = int(sys.stdin.buffer.readline().decode('utf-8'))\r\ns = sys.stdin.buffer.readline().decode('utf-8').rstrip()\r\nn = len(s)\r\nprev, words = -1, []\r\n\r\nfor i in range(n):\r\n if s[i] == ' ' or s[i] == '-':\r\n words.append(i-prev)\r\n prev = i\r\n\r\nwords.append(n-prev-1)\r\n\r\nok, ng = n+1, max(words)-1\r\nwhile abs(ok - ng) > 1:\r\n mid = (ok + ng) >> 1\r\n line, width = 1, 0\r\n\r\n for w in words:\r\n if width + w > mid:\r\n line += 1\r\n width = w\r\n else:\r\n width += w\r\n\r\n if line <= k:\r\n ok = mid\r\n else:\r\n ng = mid\r\n\r\nprint(ok)\r\n", "K = int(input())\r\nS = input()\r\nN = len(S)\r\n\r\nparts = []\r\nwords = S.split()\r\nfor i, w in enumerate(words):\r\n for seg in w.split(\"-\"):\r\n parts.append(len(seg) + 1)\r\nparts[-1] -= 1\r\n\r\n\r\nl = max(parts) - 1\r\nr = N + 5\r\nwhile r - l > 1:\r\n m = (l + r) // 2\r\n\r\n row = 1\r\n col = 0\r\n for p in parts:\r\n if col + p <= m:\r\n col += p\r\n else:\r\n row += 1\r\n col = p\r\n\r\n if row <= K:\r\n r = m\r\n else:\r\n l = m\r\n\r\nprint(r)\r\n", "k, s, mem = int(input()), input(), [0]\r\nfor i in s:\r\n mem[-1] += 1\r\n if i in (' ', '-'):\r\n mem.append(0)\r\n \r\nbe, en = max(mem), len(s)\r\nwhile be < en:\r\n md, val, line = (be + en) >> 1, 1, 0\r\n \r\n for i in mem:\r\n if line + i > md:\r\n line = i\r\n val += 1\r\n else:\r\n line += i\r\n \r\n if val > k:\r\n be = md + 1\r\n else:\r\n en = md\r\nprint(be)", "lo, hi = 0, 2000000\r\nans = 1000000\r\n\r\nn = int(input())\r\ns = input()\r\nc = 0\r\nl = []\r\n\r\nfor i in s:\r\n c += 1\r\n if i == ' ' or i == '-':\r\n l.append(c)\r\n c = 0\r\nl.append(c)\r\n\r\n\r\ndef positive(x):\r\n rows = 1\r\n curr = 0\r\n for ch in l:\r\n if ch > x:\r\n return False\r\n if (curr + ch) <= x:\r\n curr += ch\r\n else:\r\n rows += 1\r\n curr = ch\r\n return rows <= n\r\n\r\n\r\nwhile lo <= hi:\r\n mid = (lo + hi) // 2\r\n if positive(mid):\r\n ans = mid\r\n hi = mid - 1\r\n else:\r\n lo = mid + 1\r\n\r\nprint(ans)\r\n", "n = int(input())\nxs = list(map(lambda x: len(list(x)) + 1, input().replace('-', ' ').split()))\nxs[-1] -= 1\ndef f(xs, n, c):\n cnt = 1\n tmp = 0\n for x in xs:\n if c < x:\n return False\n elif c < tmp + x:\n tmp = 0\n cnt += 1\n tmp += x\n return cnt <= n\n\nl = 1\nr = sum(xs)\n\nwhile l + 1 < r:\n c = (l + r) // 2\n if f(xs, n, c):\n r = c\n else:\n l = c\n\nprint(r)\n", "n = int(input())\ns = input()\ns += ' '\n\n\ndef ok(w):\n wordcnt = 0\n lettercnt = 0\n linecnt = 0\n for j in range(len(s)):\n if not (s[j] == ' ' or s[j] == '-'):\n lettercnt += 1\n else:\n lettercnt += 1\n if j == len(s) - 1:\n lettercnt -= 1\n if (wordcnt + lettercnt) > w:\n linecnt += 1\n wordcnt = lettercnt\n else:\n wordcnt += lettercnt\n lettercnt = 0\n if wordcnt > w:\n return False\n\n if wordcnt:\n linecnt += 1\n if linecnt > n:\n return False\n else:\n return True\n\n\nl = 1\nr = 1000000\nanswer = -1\nwhile l <= r:\n mid = l + (r - l) // 2\n if ok(mid):\n answer = mid\n r = mid - 1\n else:\n l = mid + 1\nprint(answer)\n", "INF = 10**9\n\ndef solve(w,n):\n ans = 0\n l = 0\n while l < n:\n ans += 1\n r = l + w\n if r >= n:\n break\n while r > l and s[r - 1] != ' ' and s[r - 1] != '-':\n r -= 1\n if r == l:\n return INF\n l = r\n return ans\n\nk = int(input())\ns = input()\nn = len(s)\nl = 0\nr = n\n\nwhile r - l > 1:\n m = (l + r) // 2\n if solve(m,n) <= k:\n r = m\n else:\n l = m\n\nprint(r)\n\n\t\t\t\t \t\t\t \t\t\t \t\t\t\t \t\t \t", "import sys\r\n#import random\r\nfrom bisect import bisect_left as lb\r\nfrom collections import deque\r\n#sys.setrecursionlimit(10**8)\r\nfrom queue import PriorityQueue as pq\r\nfrom math import *\r\ninput_ = lambda: sys.stdin.readline().strip(\"\\r\\n\")\r\nii = lambda : int(input_())\r\nil = lambda : list(map(int, input_().split()))\r\nilf = lambda : list(map(float, input_().split()))\r\nip = lambda : input_()\r\nfi = lambda : float(input_())\r\nap = lambda ab,bc,cd : ab[bc].append(cd)\r\nli = lambda : list(input_())\r\npr = lambda x : print(x)\r\nprinT = lambda x : print(x)\r\nf = lambda : sys.stdout.flush()\r\ninv =lambda x:pow(x,mod-2,mod)\r\nmod = 10**9 + 7\r\n\r\nn = ii()\r\na = ip()\r\n\r\nb = []\r\nt = 0\r\n\r\nfor i in range (len(a)) :\r\n t += 1\r\n if (a[i] == '-' or a[i] == \" \") :\r\n b.append(t)\r\n t = 0\r\n\r\nb.append(t)\r\n\r\nl = 0\r\nh = 10**7\r\n\r\ndef check(x) :\r\n t1 = 1\r\n s = 0\r\n\r\n for i in b :\r\n if (s+i)<=x :\r\n s += i\r\n elif (i>x) :\r\n return False\r\n else :\r\n s = i\r\n t1 += 1\r\n\r\n if (t1 <= n) :\r\n return True\r\n else :\r\n return False\r\n\r\nans = -1\r\n#print(len(a))\r\np = -1\r\n \r\nwhile (l<=h) :\r\n m = (l+h)//2\r\n if (m == p) :\r\n break\r\n p = m\r\n\r\n if (check(m)) :\r\n #print(m)\r\n ans = m\r\n h = m\r\n else :\r\n l = m+1\r\n\r\nprint(ans)\r\n", "n=int(input())\r\ns=[]\r\nfor t in input().split():\r\n for u in t.split('-'):\r\n s.append(len(u)+1)\r\n\r\ns[-1]-=1\r\nm=len(s)\r\n\r\ndef calc(mid):\r\n cnt=1\r\n tmp=0\r\n for i in s:\r\n if i+tmp<=mid:\r\n tmp+=i\r\n elif i<=mid:\r\n cnt+=1\r\n tmp=i\r\n else:\r\n return False\r\n return cnt<=n\r\n\r\nng,ok=0,10**7\r\nwhile abs(ng-ok)>1:\r\n mid=(ng+ok)//2\r\n if calc(mid):\r\n ok=mid\r\n else:\r\n ng=mid\r\n\r\nprint(ok)", "k = int(input())\nad = input()\nn = int(len(ad))\ncheck = [None] * n\nif ad[0] == ' ' or ad[0] == '-':\n check[0] = 0\nfor i in range(1, n):\n if ad[i] == ' ' or ad[i] == '-':\n check[i] = i\n else:\n check[i] = check[i-1]\nm = 1\nma = n\nwhile m != ma:\n mi = (ma+m)//2\n i = -1\n for j in range(k-1):\n if i is None:\n break\n i = check[min(n - 1, i+mi)]\n if i is not None and n-i-1 <= mi:\n ma = mi\n else:\n m = mi + 1\nprint(m)\n", "import sys\nfrom itertools import accumulate as acm\n\ndef print(a):\n sys.stdout.write(str(a)+'\\n')\ndef input():\n return sys.stdin.readline().strip()\n \n\ndef BS(i,j,k):\n c=-1\n while(i<=j):\n m=i+((j-i)//2)\n if isComplete(k,m):\n j=m-1\n c=m\n else:\n i=m+1 \n return c \n\ndef isComplete(k,m):\n c,d=0,1\n for i in l:\n if i>m:\n return False\n if (c+i)<=m:\n c+=i\n else:\n c=i\n d+=1\n if d<=k:\n return True\n return False\n \ndef CP(k):\n sumL,maxL=0,0\n for i in l:\n sumL+=i\n if i>maxL:\n maxL=i\n return BS(maxL,sumL,k) \n \nn=int(input())\ns=input()\ns=s.replace('-','.')\ns=s.replace(' ','.')\n#print(s)\nk=s.split('.')\nl=[]\nfor i in k:\n l.append(len(i)+1)\nl[-1]-=1\n#print(l)\nprint(CP(n))\n\t\t\t \t \t \t \t\t\t \t \t\t \t", "from sys import stdin, stdout\r\nfrom random import randrange\r\n\r\n\r\nn = int(stdin.readline())\r\ns = stdin.readline().strip()\r\n\r\nl, r = 0, len(s)\r\nwhile r - l > 1:\r\n m = (l + r) >> 1\r\n previous = 0\r\n ind = previous - 1\r\n \r\n for j in range(n):\r\n if len(s) - previous <= m:\r\n previous = len(s)\r\n break\r\n \r\n for i in range(previous, min(previous + m, len(s))):\r\n if s[i] == ' ' or s[i] == '-':\r\n ind = i\r\n \r\n previous = ind + 1\r\n \r\n if previous >= len(s):\r\n r = m\r\n else:\r\n l = m\r\n\r\nstdout.write(str(r))", "k = int(input())\r\ns = input().strip()\r\ns = s.replace(' ','-')\r\nts = s.split('-')\r\nls = [len(i)+1 for i in ts]\r\nls[-1] -= 1\r\namin = max(ls)\r\nals = (len(s)+k-1)//k\r\nret = max(amin,als)\r\nwhile True:\r\n nb = 0\r\n idx = 0\r\n crtsize = 0\r\n while nb < k:\r\n if crtsize + ls[idx] <= ret:\r\n crtsize += ls[idx]\r\n else:\r\n nb += 1\r\n crtsize = ls[idx]\r\n idx += 1\r\n if nb < k and idx >= len(ls):\r\n break\r\n else:\r\n ret += 1\r\n continue\r\n break\r\nprint(ret)", "k = int(input())\r\nl = input()\r\np = [None] * len(l)\r\n\r\nif l[0] == ' ' or l[0] == '-':\r\n p[0] = 0\r\n\r\nfor i in range(1, len(l)):\r\n if l[i] == ' ' or l[i] == '-':\r\n p[i] = i\r\n else:\r\n p[i] = p[i - 1]\r\n\r\nstart_w = 1\r\nmax_w = len(l)\r\n\r\nwhile start_w != max_w:\r\n mid_w = (max_w + start_w) // 2\r\n i = -1\r\n for j in range(k - 1):\r\n if i is None:\r\n break\r\n i = p[min(len(l) - 1, i + mid_w)]\r\n if i is not None and len(l) - i - 1 <= mid_w:\r\n max_w = mid_w\r\n else:\r\n start_w = mid_w + 1\r\n \r\nprint(start_w)# 1698332664.4947417", "k = int(input())\r\nl = input()\r\nn = len(l)\r\np = [None] * n\r\nif l[0]==' ' or l[0]=='-':\r\n\tp[0] = 0\r\nfor i in range(1, n):\r\n\tif l[i]==' ' or l[i]== '-':\r\n\t\tp[i] = i\r\n\telse:\r\n\t\tp[i] = p[i-1]\r\nm = 1\r\nma = n\r\nwhile m != ma:\r\n\tmi = (ma+m)//2\r\n\ti = -1\r\n\tfor j in range(k-1):\r\n\t\tif i==None:\r\n\t\t\tbreak\r\n\t\ti = p[min(n-1, i+mi)]\r\n\tif i!=None and n-i-1 <= mi:\r\n\t\tma = mi\r\n\telse:\r\n\t\tm = mi + 1\r\nprint(m)", "k = int(input())\r\ns = input().split()\r\n\r\na = []\r\nfor word in s:\r\n chunks = word.split('-')\r\n for chunk in chunks:\r\n a.append(len(chunk)+1)\r\n\r\nn = len(a)\r\na[n-1] -= 1\r\nl = sum(a)\r\nbeg, end, ans = max(a), l, l\r\nwhile(beg <= end):\r\n mid = (beg + end)//2\r\n used, left = 0, mid\r\n for i in range(n):\r\n if(left - a[i] >= 0):\r\n left -= a[i]\r\n else:\r\n used += 1\r\n left = mid - a[i]\r\n if(left < mid):\r\n used += 1\r\n if(used <= k):\r\n ans = mid\r\n end = mid-1\r\n else:\r\n beg = mid+1\r\nprint(ans)\r\n", "# B - Magazine Ad\n\ndef can_split(sent, k, max_width):\n n = len(sent)\n ind_br = -1\n cur_width = 0\n num_lines = 1\n for i in range(n):\n cur_width += 1\n if cur_width > max_width:\n if ind_br == -1:\n return False\n else:\n # split sent at ind_br\n cur_width = i - ind_br\n # print(f'{sent[:ind_br+1]}, {cur_width}')\n ind_br = -1 # to search for next break\n num_lines += 1\n if sent[i] == ' ' or sent[i] == '-':\n ind_br = i\n if ind_br >= max_width * (num_lines + 1):\n return False\n if num_lines > k:\n return False\n return num_lines <= k\n\ndef bin_search(sent, k):\n n = len(sent)\n l = 1\n r = n\n min_width = -1\n while l <= r:\n m = l + (r - l) // 2\n can = can_split(sent, k, m)\n # print(l, m, r, can)\n if can:\n min_width = m\n r = m - 1\n else:\n l = m + 1\n return min_width\n\nk = int(input().strip())\nsent = input().strip()\nmin_width = bin_search(sent, k)\nprint(min_width)\n\n \t\t\t\t\t \t \t\t\t\t\t \t\t \t \t\t\t \t \t\t", "k = int(input())\nl = input()\nn = len(l)\n\nprev = [None] * n\nprev[0] = 0 if l[0] == ' ' or l[0] == '-' else None\nfor i in range(1, n):\n prev[i] = i if l[i] == ' ' or l[i] == '-' else prev[i - 1]\n\n\nmi = 1\nma = n\nwhile mi != ma:\n mid = (ma + mi) // 2\n pos = -1\n for _ in range(k - 1):\n if pos is None:\n break\n pos = prev[min(n - 1, pos + mid)]\n if pos is not None and n - pos - 1 <= mid:\n ma = mid\n else:\n mi = mid + 1\nprint(mi)\n", "#Bhargey Mehta (Sophomore)\r\n#DA-IICT, Gandhinagar\r\nimport sys, math, queue\r\n#sys.stdin = open(\"input.txt\", \"r\")\r\nMOD = 10**9+7\r\nsys.setrecursionlimit(1000000)\r\n\r\ndef ok(w):\r\n i = 0\r\n c = 0\r\n l = 0\r\n while i < len(x):\r\n if c+x[i] <= w:\r\n c += x[i]\r\n i += 1\r\n else:\r\n l += 1\r\n c = 0\r\n l += 1\r\n return l <= n\r\n\r\nn = int(input())\r\ns = list(input().split())\r\nx = []\r\nfor i in range(len(s)-1):\r\n s[i] += \" \"\r\nfor i in range(len(s)):\r\n s[i] = s[i].split('-')\r\nfor i in range(len(s)):\r\n for j in range(len(s[i])-1):\r\n x.append(len(s[i][j])+1)\r\n x.append(len(s[i][-1]))\r\nlow = max(x)\r\nhigh = sum(x)+1\r\nwhile low <= high:\r\n mid = (low+high)//2\r\n if ok(mid):\r\n ans = mid\r\n high = mid-1\r\n else:\r\n low = mid+1\r\nprint(ans)", "def isDone(a,maxl,maxr):\n s=0\n row=1\n for x in a:\n if x>maxl:\n return False\n if x+s<=maxl:\n s=s+x\n else:\n row+=1\n s=x \n if(row>maxr):\n return False \n return True\ndef minlen(a,maxr,l,r):\n ans=r\n while(l<=r):\n mid=(r-l)//2+l \n if isDone(a,mid,maxr):\n ans=mid \n r=mid-1 \n else:\n l=mid+1\n return ans \nmaxrow=int(input())\nst=input()\nn=len(st)\na=[]\npre=-1\nmin1=len(st)+2\nfor i in range(len(st)):\n if st[i]==\" \" or st[i]==\"-\":\n a.append(i-pre)\n min1=min(i-pre,min1)\n pre=i\na.append(len(st)-1-pre)\nmin1=min(min1,len(st)-1-pre)\nprint(minlen(a,maxrow,min1,n))\n\t \t \t \t \t \t\t \t\t \t \t\t \t\t \t", "lines_limit = int(input())\ntext = input()\ntokens = text.replace('-', ' ').split()\n\ndef is_enough(char_cnt_per_line: int) -> bool:\n remaining_cnt = char_cnt_per_line\n total_lines_cnt = 1\n for i, t in enumerate(tokens):\n if len(t) + (i != len(tokens) - 1) > remaining_cnt:\n total_lines_cnt += 1\n remaining_cnt = char_cnt_per_line\n remaining_cnt -= len(t) + (i != len(tokens) - 1)\n if remaining_cnt < 0:\n return False\n return total_lines_cnt <= lines_limit\n\nl, r = 0, len(text)\nwhile l < r:\n mid = (l + r) // 2\n if is_enough(mid):\n r = mid\n else:\n l = mid + 1\nprint(l)\n", "k = int(input())\r\ns = str(input())\r\n\r\nL = []\r\np = -1\r\nn = len(s)\r\nfor i in range(n):\r\n if s[i] == ' ' or s[i] == '-':\r\n L.append(i-p)\r\n p = i\r\nelse:\r\n L.append(n-1-p)\r\n#print(L)\r\ndef is_ok(x):\r\n cur = 0\r\n cnt = 1\r\n for i, l in enumerate(L):\r\n if l > x:\r\n return False\r\n if cur+l <= x:\r\n cur += l\r\n else:\r\n cur = l\r\n cnt += 1\r\n #print(x, cur, cnt)\r\n return cnt <= k\r\n\r\nng = 0\r\nok = n\r\nwhile ng+1 < ok:\r\n c = (ng+ok)//2\r\n if is_ok(c):\r\n ok = c\r\n else:\r\n ng = c\r\nprint(ok)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef binary_search(c1, c2):\r\n m = (c1 + c2 + 1) // 2\r\n while abs(c1 - c2) > 1:\r\n m = (c1 + c2 + 1) // 2\r\n if ok(m):\r\n c2 = m\r\n else:\r\n c1 = m\r\n ans = check(m)\r\n return ans\r\n\r\ndef ok(m):\r\n if m < m0:\r\n return False\r\n c = 0\r\n d = 0\r\n for i in x:\r\n if c + i > m:\r\n d += 1\r\n c = i\r\n else:\r\n c += i\r\n d += 1\r\n return True if d <= k else False\r\n\r\ndef check(m):\r\n for j in range(m + 5, m - 6, -1):\r\n if not ok(j):\r\n return j + 1\r\n return m\r\n\r\nk = int(input())\r\ns = list(input().rstrip())\r\nc = 0\r\nx = []\r\nfor i in s:\r\n if i == \" \" or i == \"-\":\r\n c += 1\r\n x.append(c)\r\n c = 0\r\n else:\r\n c += 1\r\nx.append(c)\r\nm0 = max(x)\r\ns0 = sum(x)\r\nans = binary_search(0, s0 + 1)\r\nprint(ans)", "k = int(input())\ntext = input()\ntokens = text.replace('-', '- ').split()\n\ndef ok(mid):\n lines_used = 1\n capacity = 0\n\n for i, token in enumerate(tokens):\n tok_len = len(token) + (token[-1] != '-' and i < len(tokens) - 1)\n\n if tok_len > mid:\n return False\n\n if capacity + tok_len <= mid:\n capacity += tok_len\n else:\n capacity = tok_len\n lines_used += 1\n if lines_used > k:\n return False\n\n return True\n\ndef bs(lo, hi):\n mid = (lo + hi) // 2\n\n if not ok(mid):\n return bs(mid + 1, hi)\n elif mid > lo and ok(mid - 1):\n return bs(lo, mid - 1)\n else:\n return mid\n\nprint(bs(1, len(text)))" ]
{"inputs": ["4\ngarage for sa-le", "4\nEdu-ca-tion-al Ro-unds are so fun", "1\nj", "10\nb", "1\nQGVsfZevMD", "1\nqUOYCytbKgoGRgaqhjrohVRxKTKjjOUPPnEjiXJWlvpCyqiRzbnpyNqDylWverSTrcgZpEoDKhJCrOOvsuXHzkPtbXeKCKMwUTVk", "100000\nBGRHXGrqgjMxCBCdQTCpQyHNMkraTRxhyZBztkxXNFEKnCNjHWeCWmmrRjiczJAdfQqdQfnuupPqzRhEKnpuTCsVPNVTIMiuiQUJ", "1\nrHPBSGKzxoSLerxkDVxJG PfUqVrdSdOgJBySsRHYryfLKOvIcU", "2\nWDJDSbGZbGLcDB-GuDJxmjHEeruCdJNdr wnEbYVxUZbgfjEHlHx", "2\nZeqxDLfPrSzHmZMjwSIoGeEdkWWmyvMqYkaXDzOeoFYRwFGamjYbjKYCIyMgjYoxhKnAQHmGAhkwIoySySumVOYmMDBYXDYkmwErqCrjZWkSisPtNczKRofaLOaJhgUbVOtZqjoJYpCILTmGkVpzCiYETFdgnTbTIVCqAoCZqRhJvWrBZjaMqicyLwZNRMfOFxjxDfNatDFmpmOyOQyGdiTvnprfkWGiaFdrwFVYKOrviRXdhYTdIfEjfzhb HrReddDwSntvOGtnNQFjoOnNDdAejrmNXxDmUdWTKTynngKTnHVSOiZZhggAbXaksqKyxuhhjisYDfzPLtTcKBZJCcuGLjhdZcgbrYQtqPnLoMmCKgusOmkLbBKGnKAEvgeLVmzwaYjvcyCZfngSJBlZwDimHsCctSkAhgqakEvXembgLVLbPfcQsmgxTCgCvSNliSyroTYpRmJGCwQlfcKXoptvkrYijULaUKWeVoaFTBFQvinGXGRj", "2\nWjrWBWqKIeSndDHeiVmfChQNsoUiRQHVplnIWkwBtxAJhOdTigAAzKtbNEqcgvbWHOopfCNgWHfwXyzSCfNqGMLnmlIdKQonLsmGSJlPBcYfHNJJDGlKNnOGtrWUhaTWuilHWMUlFEzbJYbeAWvgnSOOOPLxX-eJEKRsKqSnMjrPbFDprCqgbTfwAnPjFapVKiTjCcWEzhahwPRHScfcLnUixnxckQJzuHzshyBFKPwVGzHeJWniiRKynDFQdaazmTZtDGnFVTmTUZCRCpUHFmUHAVtEdweCImRztqrkQInyCsnMnYBbjjAdKZjXzyPGS TUZjnPyjnjyRCxfKkvpNicAzGqKQgiRreJIMVZPuKyFptrqhgIeWwpZFYetHqvZKUIscYuQttIRNuklmgqRYhbCWPgXpEygxYWMggVbQbiWNNBFMxRoPIRxcBLhayOizbixIRgaXczSibmlTnnYsnlltfDDwPolEIsjPilMiQQjUGeEyAWES", "10\nIBgDZeAHSUFhJxcZkQKqaTZT gqErHjXUahQpfDTcZZW nhLsPIrfflZWnwiQEWpt dcTGNMjzkuWNIVXrshBowdQ ugLvpovZZVWryM", "10\nlELWTeKqHCohtEOB PLhjMMwfpFlcnfft nWGsnztStldkrbGkJZz EtSrgwffzJSspzWpoMXGK-jmbVygQC BoIwaGSYKRsgmxBVwkoa", "100000\nBvbikpOjCTXWr-zqGzpEGswptPksN IsJVeilKfqoiicTMcmZeduDs KtZKEFZQztKq ynKDcPxbVfOKrjxAfQvKIIR HlsgVUeeGvfSc", "10\nTQEKPQiFXCqY iugCuECYdemF RqdrrpurDgeYK-fLJIgvtgWkPHma-kqoGdxPXvloehNNire JShAkvoJxjDMEoHiOp nHgyCAQMfiQSz", "4\na-aa", "6\na aa-aaa-aa a-aaa-a", "4\nasd asd asd asdf"], "outputs": ["7", "10", "1", "1", "10", "100", "100", "51", "34", "253", "322", "25", "22", "25", "19", "2", "5", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
25
1bc3e611b56cd450a7fb71b37744f2d8
Sagheer and Apple Tree
Sagheer is playing a game with his best friend Soliman. He brought a tree with *n* nodes numbered from 1 to *n* and rooted at node 1. The *i*-th node has *a**i* apples. This tree has a special property: the lengths of all paths from the root to any leaf have the same parity (i.e. all paths have even length or all paths have odd length). Sagheer and Soliman will take turns to play. Soliman will make the first move. The player who can't make a move loses. In each move, the current player will pick a single node, take a non-empty subset of apples from it and do one of the following two things: 1. eat the apples, if the node is a leaf. 1. move the apples to one of the children, if the node is non-leaf. Before Soliman comes to start playing, Sagheer will make exactly one change to the tree. He will pick two different nodes *u* and *v* and swap the apples of *u* with the apples of *v*. Can you help Sagheer count the number of ways to make the swap (i.e. to choose *u* and *v*) after which he will win the game if both players play optimally? (*u*,<=*v*) and (*v*,<=*u*) are considered to be the same pair. The first line will contain one integer *n* (2<=≤<=*n*<=≤<=105) — the number of nodes in the apple tree. The second line will contain *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=107) — the number of apples on each node of the tree. The third line will contain *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the parent of each node of the tree. Node *i* has parent *p**i* (for 2<=≤<=*i*<=≤<=*n*). Node 1 is the root of the tree. It is guaranteed that the input describes a valid tree, and the lengths of all paths from the root to any leaf will have the same parity. On a single line, print the number of different pairs of nodes (*u*,<=*v*), *u*<=≠<=*v* such that if they start playing after swapping the apples of both nodes, Sagheer will win the game. (*u*,<=*v*) and (*v*,<=*u*) are considered to be the same pair. Sample Input 3 2 2 3 1 1 3 1 2 3 1 1 8 7 2 2 5 4 3 1 1 1 1 1 4 4 5 6 Sample Output 1 0 4
[ "q= int(input())\na = [int(_) for _ in input().split()]\nc = [int(_) for _ in input().split()]\ndepth = [0] * (q)\nfor i in range(1,q):\n depth[i] = depth[c[i-1]-1] + 1\nMAX = max(depth)\nt = 0\nstore = {}\ntodo = []\np = 0\n\nfor i in range(q):\n if (MAX-depth[i]) % 2 == 0: # odd, useful\n t ^= a[i]\n todo.append(a[i])\n else:\n store[a[i]] = store.get(a[i],0) + 1\n p += 1\n\nres = 0\nfor i in todo:\n res += store.get(i^t,0)\n\nif t == 0:\n res += (p*(p-1)//2) + (q-p)*(q-p-1)//2\n\nprint(res)\n\t\t\t\t \t\t\t\t\t \t\t\t \t \t \t\t \t \t", "def coloring(i, ancestors, color):\r\n while i != 0 and color[ancestors[i - 1]] is None:\r\n color[ancestors[i - 1]] = not color[i]\r\n i = ancestors[i - 1]\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n ancestors = list(map(lambda x: int(x) - 1, input().split()))\r\n descendants = [[] for i in range(n)]\r\n for i in range(n - 1):\r\n descendants[ancestors[i]].append(i + 1)\r\n color = [None for i in range(n)]\r\n for i in range(n):\r\n if not descendants[i]:\r\n color[i] = True\r\n coloring(i, ancestors, color)\r\n reds = 0\r\n blues = 0\r\n xor = 0\r\n count_red = dict()\r\n count_blue = dict()\r\n for i in range(n):\r\n if color[i]:\r\n blues += 1\r\n xor ^= a[i]\r\n if str(a[i]) in count_blue:\r\n count_blue[str(a[i])] += 1\r\n else:\r\n count_blue[str(a[i])] = 1\r\n else:\r\n reds += 1\r\n if str(a[i]) in count_red:\r\n count_red[str(a[i])] += 1\r\n else:\r\n count_red[str(a[i])] = 1\r\n res = 0\r\n if xor == 0:\r\n res += (blues - 1) * blues // 2\r\n res += (reds - 1) * reds // 2\r\n for i in count_blue.items():\r\n if i[0] in count_red:\r\n res += i[1] * count_red[i[0]]\r\n else:\r\n for i in count_blue.items():\r\n if str(xor ^ int(i[0])) in count_red:\r\n res += i[1] * count_red[str(xor ^ int(i[0]))]\r\n print(res)\r\n\r\n\r\nmain()\r\n\r\n", "\"\"\" Prositka\r\n20.11.2022\"\"\"\r\n\r\nn= int(input())\r\na = [int(_) for _ in input().split()]\r\nc = [int(_) for _ in input().split()]\r\ndepth = [0] * (n)\r\nfor i in range(1,n):\r\n depth[i] = depth[c[i-1]-1] + 1\r\nMAX = max(depth)\r\nt = 0\r\nstore = {}\r\ntodo = []\r\np = 0\r\nfor i in range(n):\r\n if (MAX-depth[i]) % 2 == 0: # odd, useful\r\n t ^= a[i]\r\n todo.append(a[i])\r\n else:\r\n store[a[i]] = store.get(a[i],0) + 1\r\n p += 1\r\nans = 0\r\nfor i in todo:\r\n ans += store.get(i^t,0)\r\nif t == 0:\r\n ans += (p*(p-1)//2) + (n-p)*(n-p-1)//2\r\nprint(ans)" ]
{"inputs": ["3\n2 2 3\n1 1", "3\n1 2 3\n1 1", "8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6", "6\n7 7 7 7 7 7\n1 1 1 1 1", "6\n3 1 1 1 2 2\n1 1 1 1 1", "6\n1 2 3 4 5 6\n1 2 3 4 5", "7\n15 3 5 1 2 4 8\n1 1 2 2 3 3", "7\n15 3 5 1 2 4 9\n1 1 2 2 3 3", "7\n15 16 32 1 2 4 9\n1 1 2 2 3 3", "6\n49 70 74 18 64 63\n1 2 2 1 5", "9\n15 17 68 100 31 32 79 48 100\n1 2 3 4 3 6 6 2", "5\n87 100 12 93 86\n1 1 3 4", "3\n7751 9661 9437\n1 1", "8\n5201 769 1896 5497 1825 9718 7784 5952\n1 2 3 4 2 1 7", "2\n1848 2048\n1", "7\n588300 370437 481646 898447 78363 612652 998152\n1 2 3 2 5 1", "5\n753534 24400 461709 881954 452720\n1 2 3 1", "10\n191029 704946 159138 387479 61727 310778 534080 300097 442549 542174\n1 2 3 4 4 1 7 1 9", "4\n9849878 7525175 2569229 7972892\n1 2 2", "9\n734917 6649640 8476531 7374030 3139097 8258293 114238 8589112 7847119\n1 2 3 3 1 1 7 8", "10\n20 55 95 66 25 43 94 65 24 93\n1 2 3 2 5 5 1 8 9", "10\n9039 4789 3817 8625 516 4989 3436 1312 2989 3923\n1 2 3 3 1 6 7 6 9", "22\n324 4430 3495 8972 1547 9183 849 4663 2959 4715 8984 8016 2744 4451 8468 4549 9013 4124 9087 4823 4839 4635\n1 2 3 2 5 2 7 1 9 10 9 12 13 14 14 12 1 18 19 20 21", "21\n3735 1580 7599 9670 1414 8033 413 2852 5366 9196 4695 7629 7873 1731 9635 178 5637 3956 9520 8679 5006\n1 2 3 3 3 6 7 8 9 3 2 12 12 2 15 1 17 18 18 1", "23\n795895 158259 79726 699691 945099 38534 445699 515393 738257 857153 240818 675301 838661 323621 217120 707356 397865 725499 137739 272401 434551 135304 376364\n1 2 3 4 5 5 4 8 8 3 3 3 3 14 15 1 1 18 19 18 21 21", "22\n400941 84726 528265 945059 220341 935243 984080 215282 279808 757218 684733 72861 632695 371932 965754 849619 155281 780223 216197 591694 713921 293137\n1 2 3 4 5 6 3 8 8 1 11 12 13 13 11 16 17 11 1 20 20", "20\n889385 521616 271301 16205 522627 403737 958822 160624 675036 93618 352440 574828 756891 28294 239816 662464 835985 931516 576399 904671\n1 2 3 4 5 4 7 7 3 10 11 12 13 13 3 16 17 2 19", "19\n8746191 7960210 2540730 4331468 8492963 4996162 6655813 3805069 8827753 4274284 8410722 5213133 9813311 4714221 5980788 8244094 1518741 290394 4067514\n1 2 3 4 5 5 4 8 4 10 10 3 13 14 2 16 16 1", "21\n6194737 6429360 6047962 1014039 9196042 2483033 9232471 5444322 4437778 6614229 4791649 7417126 7679607 790939 3062370 174847 8404336 832859 2083127 9041108 3074902\n1 2 3 4 4 6 7 2 9 10 9 12 12 1 15 1 17 1 19 19"], "outputs": ["1", "0", "4", "0", "2", "6", "11", "2", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1bd2de89b88911f54537f09932bbfcf9
Degenerate Matrix
The determinant of a matrix 2<=×<=2 is defined as follows: A matrix is called degenerate if its determinant is equal to zero. The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements. You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is minimum possible. Determine ||*A*<=-<=*B*||. The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≤<=109), the elements of the first row of matrix *A*. The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≤<=109) the elements of the second row of matrix *A*. Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9. Sample Input 1 2 3 4 1 0 0 1 Sample Output 0.2000000000 0.5000000000
[ "a, b = map(int, input().split())\r\nc, d = map(int, input().split())\r\n\r\nz = a * d - b * c\r\nif z == 0:\r\n print(0)\r\n exit()\r\nt = max(abs(a + b + c + d), abs(a + d - c - b), abs(a + c - b - d), abs(a + b - c - d))\r\nprint(abs(z / t))", "a, b= map(int, input().split())\nc, d = map(int, input().split())\nif a * d - b * c == 0:\n print(0)\nelse:\n curpos = a * d - b * c >= 0\n small = 0;\n large = 1e18\n for iteration in range(200):\n avg = (small + large) / 2\n works = False\n for ach in range(-1, 2, 2):\n for bch in range(-1, 2, 2):\n for cch in range(-1, 2, 2):\n for dch in range(-1, 2, 2):\n newpos = (a + ach * avg) * (d + dch * avg) - (b + bch * avg) * (c + cch * avg) >= 0\n if newpos != curpos:\n works = True\n if works:\n large = avg\n else:\n small = avg\n print(small)\n", "import sys\r\nA,B,C,D=map(int,sys.stdin.read().split());k=max(map(abs,[A+B+C+D,A+B-C-D,A-B+C-D,A-B-C+D]))+1e-9\r\nprint((0,abs(A*D-B*C)/k)[bool(k)])", "#include <bits/stdc++.h>\r\n#define m(x,y) (x>y?x:y)\r\n#define a(x) m(x,-(x))\r\n#define solve() printf(\"%.9f\",(A||B||C||D?a(A*D-B*C)/m(m(a(A+B+C+D),a(A-B+C-D)),m(a(A-B-C+D),a(A+B-C-D))):0))\r\n#define moo main(){double A,B,C,D;std::cin>>A>>B>>C>>D;solve();}\r\n#define _ \\\r\n0; moo = 'moo'; import sys; A,B,C,D=map(int,sys.stdin.read().split()); k=max(map(abs,[A+B+C+D,A+B-C-D,A-B+C-D,A-B-C+D]))+1e-9; print('%.9f'%(0,abs(A*D-B*C)/k)[bool(k)]);\r\nmoo;\r\n", "EPS = 1e-11\nINF = float(\"inf\")\n\n\ndef multiply ( a , b ):\n m = INF\n M = -INF\n for i in range(2):\n for j in range(2):\n m = min(m, a[i] * b[j])\n M = max(M, a[i] * b[j])\n\n return (m, M)\n\ndef intersect ( a , b ):\n return (a[0] <= b[1] and b[0] <= a[1])\n\n\na, b = map(float, input().split())\nc, d = map(float, input().split())\n\n\nlo = 0\nhi = 1e9\n\nnIters = 0\nwhile nIters < 1000 and abs(lo - hi) > EPS:\n mi = (lo + hi) / 2\n\n i1 = multiply((a - mi, a + mi), (d - mi, d + mi))\n i2 = multiply((b - mi, b + mi), (c - mi, c + mi))\n\n if ( intersect(i1, i2) ):\n hi = mi\n else:\n lo = mi\n\n nIters += 1\n\nprint(\"{:.10f}\".format(hi))\n", "a=abs;A,B,C,D=map(int,(input()+' '+input()).split());print(a(A*D-B*C)/(max(a(A+B)+a(C+D),a(A-B)+a(C-D))+1e-9))", "A,B,C,D=map(int,(input()+' '+input()).split());k=max(map(abs,[A+B+C+D,A+B-C-D,A-B+C-D,A-B-C+D]))+1e-9;print(abs(A*D-B*C)/k)", "import sys\r\nA, B, C, D = [int(i) for i in sys.stdin.read().split()]\r\nif A * D - B * C == 0:\r\n result = 0\r\nelse:\r\n result = float(\"inf\")\r\n for sa in [-1, 1]:\r\n for sb in [-1, 1]:\r\n for sc in [-1, 1]:\r\n for sd in [-1, 1]:\r\n coefA = sa * sd - sb * sc\r\n coefB = sa * D + sd * A - sb * C - sc * B\r\n coefC = A * D - B * C\r\n if coefA == 0 and coefB != 0:\r\n v = -coefC / coefB\r\n result = min(result, abs(v))\r\nprint(result)\r\n", "def readInts():\r\n return map(int, input().split())\r\n\r\na11, a12 = readInts()\r\na21, a22 = readInts()\r\n\r\ndef zero(seg):\r\n left, right = seg\r\n return left <= 0 <= right\r\n \r\ndef mult_seg(seg1, seg2):\r\n\tl1, r1 = seg1\r\n\tl2, r2 = seg2\r\n\t\r\n\tends = [l1 * l2, l1 * r2, r1 * l2, r1 * r2]\r\n\tends.sort()\r\n\t\r\n\treturn ends[0], ends[-1]\r\n\t\r\ndef intersect(seg1, seg2):\r\n\tl1, r1 = seg1\r\n\tl2, r2 = seg2\r\n\t\r\n\treturn max(l1, l2) <= min(r1, r2)\r\n\r\ndef can(limit):\r\n b11 = a11 - limit, a11 + limit\r\n b12 = a12 - limit, a12 + limit\r\n b21 = a21 - limit, a21 + limit\r\n b22 = a22 - limit, a22 + limit\r\n \r\n # print(b11, b12, b21, b22)\r\n \r\n if (zero(b11) or zero(b22)) and (zero(b21) or zero(b12)):\r\n return True\r\n \r\n left_seg = mult_seg(b11, b22)\r\n right_seg = mult_seg(b12, b21)\r\n \r\n # print(left_seg, right_seg)\r\n \r\n return intersect(left_seg, right_seg)\r\n\r\n# debug = 0.2\r\n# can(debug)\r\n\r\nleft, right = 0, 1e9 + 1\r\nfor it in range(200):\r\n mid = (left + right) / 2\r\n \r\n # print(mid, can(mid))\r\n if can(mid):\r\n right = mid\r\n else:\r\n left = mid\r\n \r\nprint(right)", "def calc_range(x, y, d):\r\n l1 = x - d\r\n r1 = x + d\r\n l2 = y - d\r\n r2 = y + d\r\n points = sorted([l1 * l2, l1 * r2, r1 * l2, r1 * r2])\r\n return points[0], points[3]\r\n\r\ndef main():\r\n a, b = map(int, input().split())\r\n c, d = map(int, input().split())\r\n l = 0.0\r\n r = 1e10\r\n for iter in range(100):\r\n m = (l + r) / 2.0\r\n minA, maxA = calc_range(a, d, m)\r\n minB, maxB = calc_range(b, c, m)\r\n if maxA < minB or maxB < minA:\r\n l = m\r\n else:\r\n r = m\r\n print(r)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "def seg(x, y, h):\n A = [x - h, x + h]\n B = [y - h, y + h]\n Z = []\n for a in A:\n for b in B:\n Z.append(a * b)\n Z.sort()\n return (Z[0], Z[-1])\n\ndef check(a, b, c, d, h):\n x1, y1 = seg(a, d, h)\n x2, y2 = seg(b, c, h)\n return max(x1, x2) <= min(y1, y2)\n\na, b = map(int, input().split())\nc, d = map(int, input().split())\nl = 0\nr = max(abs(a), abs(b), abs(c), abs(d))\nfor i in range(100):\n m = (l + r) / 2\n if check(a, b, c, d, m):\n r = m\n else:\n l = m\nprint((r + l) / 2)\n\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect\nfrom itertools import chain, dropwhile, permutations, combinations\nfrom collections import defaultdict, deque\n\ndef VI(): return list(map(int,input().split()))\n\n\n\n\n\ndef main(info=0):\n a,b = VI()\n c,d = VI()\n\n # the problem intend was to use some optimization / binary search, but a\n # deterministic solution has been proposed and is used here. idea: given\n # A, the matrix B is same as A, with +/-x at every element (plus/minus\n # depend on the signs of A elements. It's easiest to compute all possible\n # cases (only 4). Then, we can formulate the equation for the determinant\n # of this B, and set it to 0.\n # This leads to:\n #\n # det(B) == 0 == ad-bc-x(a+b+c+d)+x^2-x^2 == ad-bc-x(a+b+c+d)+x^2-x^2\n #\n # since the first two terms are the determinant of A, and the last two go\n # away, we get:\n #\n # 0 == det(A) - x(a+b+c+d) <==> x=det(A)/(a+b+c+d)\n #\n # after taking care of the other signs, one gets other potential solutions\n # below.\n #\n # However, as has been noted, it has not been proven that this is the\n # optimal solution. But it seems to be.\n\n detA = a*d-b*c\n\n denom = max(abs(a + b + c + d), abs(a + d - c - b),\n abs(a + c - b - d), abs(a + b - c - d))\n ans = 0 if detA == 0 else abs(detA/denom)\n print(ans)\n\n\n\nif __name__ == \"__main__\":\n main()\n", "import sys;A,B,C,D=map(int,sys.stdin.read().split());k=max(map(abs,[A+B+C+D,A+B-C-D,A-B+C-D,A-B-C+D]))+1e-9;print((0,abs(A*D-B*C)/k)[bool(k)])", "def work(A,B,C,D):\r\n tmp0=A*D-B*C\r\n tmp1=a*D+d*A-b*C-c*B\r\n tmp2=a*d-b*c\r\n if (tmp0==0):\r\n if (tmp1==0 and tmp2==0):\r\n return 0\r\n elif (tmp1!=0):\r\n return abs(tmp2/tmp1)\r\n else:\r\n delta=tmp1*tmp1-tmp0*tmp2*4\r\n if (delta>=0):\r\n return abs((tmp1+delta**0.5)/(tmp0*2))\r\n return 1e18\r\n \r\na,b=map(int,input().strip().split())\r\nc,d=map(int,input().strip().split())\r\n\r\nans=1e18\r\nans=min(ans,work(1,1,1,1))\r\nans=min(ans,work(1,1,1,-1))\r\nans=min(ans,work(1,1,-1,1))\r\nans=min(ans,work(1,1,-1,-1))\r\nans=min(ans,work(1,-1,1,1))\r\nans=min(ans,work(1,-1,1,-1))\r\nans=min(ans,work(1,-1,-1,1))\r\nans=min(ans,work(1,-1,-1,-1))\r\nans=min(ans,work(-1,1,1,1))\r\nans=min(ans,work(-1,1,1,-1))\r\nans=min(ans,work(-1,1,-1,1))\r\nans=min(ans,work(-1,1,-1,-1))\r\nans=min(ans,work(-1,-1,1,1))\r\nans=min(ans,work(-1,-1,1,-1))\r\nans=min(ans,work(-1,-1,-1,1))\r\nans=min(ans,work(-1,-1,-1,-1))\r\nprint(\"%.10f\" % ans)\r\n", "A,B,C,D=map(int,(input()+' '+input()).split());print(abs(A*D-B*C)/(max(map(abs,[A+B+C+D,A+B-C-D,A-B+C-D,A-B-C+D]))+1e-9)) ", "#!/usr/bin/python3\n\nfrom math import sqrt\n\na, b = map(int, input().split())\nc, d = map(int, input().split())\n\nx = []\ns = []\n\ntry:\n x += [(-a*d + b*c)/(a - b - c + d)]\n s += [1, 1, 1, 1]\nexcept:\n pass\n\ntry:\n x += [-a/4 - b/4 + c/4 - d/4 - sqrt(a**2 + 2*a*b - 2*a*c - 6*a*d + b**2 + 6*b*c + 2*b*d + c**2 - 2*c*d + d**2)/4, \n -a/4 - b/4 + c/4 - d/4 + sqrt(a**2 + 2*a*b - 2*a*c - 6*a*d + b**2 + 6*b*c + 2*b*d + c**2 - 2*c*d + d**2)/4]\n s += [1, 1, 1, -1] * 2\nexcept:\n pass\n\ntry:\n x += [-a/4 + b/4 - c/4 - d/4 - sqrt(a**2 - 2*a*b + 2*a*c - 6*a*d + b**2 + 6*b*c - 2*b*d + c**2 + 2*c*d + d**2)/4, \n -a/4 + b/4 - c/4 - d/4 + sqrt(a**2 - 2*a*b + 2*a*c - 6*a*d + b**2 + 6*b*c - 2*b*d + c**2 + 2*c*d + d**2)/4]\n s += [1, 1, -1, 1] * 2\nexcept:\n pass\n\ntry:\n x += [(-a*d + b*c)/(a + b + c + d)]\n s += [1, 1, -1, -1]\nexcept:\n pass\n\ntry:\n x += [-a/4 - b/4 - c/4 + d/4 - sqrt(a**2 + 2*a*b + 2*a*c + 6*a*d + b**2 - 6*b*c - 2*b*d + c**2 - 2*c*d + d**2)/4,\n -a/4 - b/4 - c/4 + d/4 + sqrt(a**2 + 2*a*b + 2*a*c + 6*a*d + b**2 - 6*b*c - 2*b*d + c**2 - 2*c*d + d**2)/4]\n s += [1, -1, 1, 1] * 2\nexcept:\n pass\n\ntry:\n x += [(a*d - b*c)/(a - b + c - d)]\n s += [1, -1, 1, -1]\nexcept:\n pass\n\ntry:\n x += [(a*d - b*c)/(a + b - c - d)]\n s += [1, -1, -1, 1]\nexcept:\n pass\n\ntry:\n x += [-a/4 + b/4 + c/4 + d/4 - sqrt(a**2 - 2*a*b - 2*a*c + 6*a*d + b**2 - 6*b*c + 2*b*d + c**2 + 2*c*d + d**2)/4, \n -a/4 + b/4 + c/4 + d/4 + sqrt(a**2 - 2*a*b - 2*a*c + 6*a*d + b**2 - 6*b*c + 2*b*d + c**2 + 2*c*d + d**2)/4]\n s += [1, -1, -1, -1] * 2\nexcept:\n pass\n\ntry:\n x += [a/4 - b/4 - c/4 - d/4 - sqrt(a**2 - 2*a*b - 2*a*c + 6*a*d + b**2 - 6*b*c + 2*b*d + c**2 + 2*c*d + d**2)/4, \n a/4 - b/4 - c/4 - d/4 + sqrt(a**2 - 2*a*b - 2*a*c + 6*a*d + b**2 - 6*b*c + 2*b*d + c**2 + 2*c*d + d**2)/4]\n s += [-1, 1, 1, 1] * 2\nexcept:\n pass\ntry:\n s += [-1, 1, 1, -1]\n x += [(-a*d + b*c)/(a + b - c - d)]\nexcept:\n pass\n\ntry:\n x += [(-a*d + b*c)/(a - b + c - d)]\n s += [-1, 1, -1, 1]\nexcept:\n pass\n\ntry:\n x += [a/4 + b/4 + c/4 - d/4 - sqrt(a**2 + 2*a*b + 2*a*c + 6*a*d + b**2 - 6*b*c - 2*b*d + c**2 - 2*c*d + d**2)/4, \n a/4 + b/4 + c/4 - d/4 + sqrt(a**2 + 2*a*b + 2*a*c + 6*a*d + b**2 - 6*b*c - 2*b*d + c**2 - 2*c*d + d**2)/4]\n s += [-1, 1, -1, -1] * 2\nexcept:\n pass\n\ntry:\n x += [(a*d - b*c)/(a + b + c + d)]\n s += [-1, -1, 1, 1]\nexcept:\n pass\ntry:\n x += [a/4 - b/4 + c/4 + d/4 - sqrt(a**2 - 2*a*b + 2*a*c - 6*a*d + b**2 + 6*b*c - 2*b*d + c**2 + 2*c*d + d**2)/4, a/4 - b/4 + c/4 + d/4 + sqrt(a**2 - 2*a*b + 2*a*c - 6*a*d + b**2 + 6*b*c - 2*b*d + c**2 + 2*c*d + d**2)/4]\n s += [-1, -1, 1, -1] * 2\nexcept:\n pass\n\ntry:\n x += [a/4 + b/4 - c/4 + d/4 - sqrt(a**2 + 2*a*b - 2*a*c - 6*a*d + b**2 + 6*b*c + 2*b*d + c**2 - 2*c*d + d**2)/4, a/4 + b/4 - c/4 + d/4 + sqrt(a**2 + 2*a*b - 2*a*c - 6*a*d + b**2 + 6*b*c + 2*b*d + c**2 - 2*c*d + d**2)/4]\n s += [-1, -1, -1, 1] * 2\nexcept:\n pass\n\ntry:\n x += [(a*d - b*c)/(a - b - c + d)]\n s += [-1, -1, -1, -1]\nexcept:\n pass\n\nprint (min(map(abs,x)))\n\nfor i in range(len(x)):\n ss = s[4*i:4*i+4]\n #print (i, x[i], ss)\n aa = a + x[i] * ss[0]\n dd = d + x[i] * ss[1]\n bb = b + x[i] * ss[2]\n cc = c + x[i] * ss[3]\n #print (aa, bb, cc, dd)\n #print (aa * dd - bb * cc)\n", "from decimal import *\n\ngetcontext().prec = 50\na, b = map(int, input().split())\nc, d = map(int, input().split())\n\nanswer = None\n\nfor k in range(1 << 4):\n le = Decimal(0)\n rg = Decimal(10 ** 11)\n\n def f(t):\n fi = a\n if k & 1:\n fi += t\n else:\n fi -= t\n\n fi *= (d + t if k & (1 << 1) else d - t)\n\n se = (b + t if k & (1 << 2) else b - t)\n se *= (c + t if k & (1 << 3) else c - t)\n\n return abs(fi - se)\n\n for i in range(200):\n m1 = le + (rg - le) / Decimal(3)\n m2 = rg - (rg - le) / Decimal(3)\n\n if f(m1) > f(m2):\n le = m1\n else:\n rg = m2\n\n if f(le) < 1e-8:\n if answer == None:\n answer = le\n else:\n answer = min(answer, le)\n\nprint(answer)\n", "\"\"\"\r\nCodeforces Looksery Cup 2015 Problem H\r\n\r\nAuthor : chaotic_iak\r\nLanguage: Python 3.4.2\r\n\"\"\"\r\n\r\n################################################### SOLUTION\r\n\r\ndef minimize(m):\r\n ad = [m[0][0]*m[3][0], m[0][0]*m[3][1] + m[0][1]*m[3][0], m[0][1]*m[3][1]]\r\n bc = [m[1][0]*m[2][0], m[1][0]*m[2][1] + m[1][1]*m[2][0], m[1][1]*m[2][1]]\r\n det = [ad[0]-bc[0], ad[1]-bc[1], ad[2]-bc[2]]\r\n if det[0] != 0:\r\n disc = det[1]**2 - 4*det[0]*det[2]\r\n if disc < 0: return []\r\n return [(-det[1] + disc**.5) / (2*det[0]), (-det[1] - disc**.5) / (2*det[0])]\r\n if det[1] != 0:\r\n return [-det[2]/det[1]]\r\n if det[2] != 0:\r\n return []\r\n return [0]\r\n\r\ndef main():\r\n matrix = read() + read()\r\n import itertools\r\n r = range(4)\r\n ans = 10**18\r\n for i in range(5):\r\n for k in itertools.combinations(r, i):\r\n m = [((1 if j in k else -1), matrix[j]) for j in range(4)]\r\n for res in minimize(m):\r\n if abs(res) < ans: ans = abs(res)\r\n print(ans)\r\n\r\n\r\n\r\n#################################################### HELPERS\r\n\r\n\r\n\r\ndef read(mode=2):\r\n # 0: String\r\n # 1: List of strings\r\n # 2: List of integers\r\n inputs = input().strip()\r\n if mode == 0: return inputs\r\n if mode == 1: return inputs.split()\r\n if mode == 2: return list(map(int, inputs.split()))\r\n\r\ndef write(s=\"\\n\"):\r\n if s is None: s = \"\"\r\n if isinstance(s, list): s = \" \".join(map(str, s))\r\n s = str(s)\r\n print(s, end=\"\")\r\n\r\nwrite(main())", "# IAWT\r\nm = list(map(int, input().split() + input().split()))\r\n\r\ndef f(r):\r\n a = (m[0] + r) * (m[3] + r)\r\n b = (m[0] + r) * (m[3] - r)\r\n c = (m[0] - r) * (m[3] + r)\r\n d = (m[0] - r) * (m[3] - r)\r\n x1 = min(a, b, c, d)\r\n x2 = max(a, b, c, d)\r\n \r\n a = (m[1] + r) * (m[2] + r)\r\n b = (m[1] + r) * (m[2] - r)\r\n c = (m[1] - r) * (m[2] + r)\r\n d = (m[1] - r) * (m[2] - r)\r\n y1 = min(a, b, c, d)\r\n y2 = max(a, b, c, d)\r\n if y1 > x2 or x1 > y2: return False\r\n return True\r\n\r\n\r\nl = 0\r\nr = 10 ** 20\r\nfor i in range(10000):\r\n mid = (l + r) / 2\r\n if f(mid):\r\n r = mid\r\n else:\r\n l = mid\r\n\r\nprint(l)\r\n" ]
{"inputs": ["1 2\n3 4", "1 0\n0 1", "1000000000 0\n0 1000000000", "8205 9482\n11 -63", "0 0\n0 0", "1000000000 -1000000000\n1000000000 1000000000", "1000000000 1000000000\n1000000000 -1000000000", "-1 -1\n1 0", "5 2\n-15 -6", "2 -5\n-3 2", "-5 -2\n-1 -3", "-5 8\n1 6", "1 3\n3 2", "-42 63\n77 -32", "91 -7\n-21 91", "-67 -77\n-56 -75", "-26 53\n-48 -89", "97 -934\n-707 184", "689 412\n-794 -421", "-718 -387\n972 972", "-126 -376\n75 367", "-7 -3674\n845 5737", "-9912 755\n-8220 6419", "-3928 5185\n4331 6665", "2056 9614\n-5171 8965", "41642 63236\n-59604 20357", "-38387 -93294\n-52918 -51288", "92812 73253\n-46231 11374", "12784 -94506\n26149 85264", "955162 -709099\n-743655 578837", "160382 -103968\n301943 -156088", "-634398 -468280\n447621 78431", "-398622 -832591\n-506781 -656493", "-2665612 -7693032\n-2861368 -6201836", "1762462 700391\n-7134185 5042962", "6190536 5693104\n-8006293 -3712238", "553632 5653328\n-7246622 9164341", "43469186 94408326\n78066381 -19616812", "25683826 49101909\n88380777 46573745", "-87068851 98762810\n3727856 -87235696", "95145788 53456393\n42406028 83987544", "876432079 -414820618\n-816514132 -914565422", "-240038673 376842703\n-241080203 410087456", "938457872 -536526676\n867891897 -855194260", "116954418 255136645\n-851641472 174491320", "1 1\n1 5", "1 5\n1 1", "5 1\n1 1", "1 1\n5 1", "-1000000000 -1000000000\n1000000000 1000000000", "-1000000000 -1000000000\n999999999 999999999", "536870912 88\n536870912 22528", "268435456 268435456\n22512 22528", "-1 1\n1 1", "-1000 -999\n-1 0", "-801658422 -738703776\n910442649 -920729415", "-203893419 -777818\n295920256 -474540430", "448944609 529185527\n946362390 958011342", "348741875 -606207234\n-279810821 -14278204", "-202195424 182466434\n-722509868 -838173079", "-48 9\n17 -67", "12 180\n79 47", "-131 -87\n-66 -109", "171 17\n9 93", "221 20\n-22 -200", "372 -352\n-160 -423", "480 37\n-3 -459", "-535 -395\n-264 513", "-498 -685\n-532 526", "-16 450\n-848 27", "-621967643 610314360\n-660274542 -772630232", "222416863 97256131\n897661932 -426944193", "67861199 302935298\n883117733 559626116", "1000000000 1\n1000000000 2", "-2 1\n1 -2", "1000000000 999999995\n99999999 -199992543"], "outputs": ["0.2000000000", "0.5000000000", "500000000.0000000000", "35.0198432832", "0.0000000000", "1000000000.0000000000", "1000000000.0000000000", "0.3333333333", "0.0000000000", "0.9166666667", "1.1818181818", "2.1111111111", "0.7777777778", "16.3878504673", "38.7333333333", "2.5927272727", "29.6219512195", "334.2819979188", "16.0012953368", "105.5204985241", "19.1122881356", "298.5843320666", "2268.9886983324", "3969.3426099731", "3141.2387756983", "32033.4760659150", "12582.8868737997", "22109.0927374802", "18439.1869417765", "8557.1487662354", "8802.4244934460", "98147.3248125840", "66924.0413186624", "282203.1726406262", "1048758.9114990780", "957535.4624752104", "2140390.1895580233", "41883387.4306073852", "14987456.1603828062", "26110777.7289122988", "20815549.6776987243", "520028295.4718751899", "5983627.7655281517", "105349963.0995401485", "204147910.8375163887", "0.5000000000", "0.5000000000", "0.5000000000", "0.5000000000", "0.0000000000", "0.0000000000", "11219.7636804586", "7.9993289080", "1.0000000000", "0.4995000000", "744753719.5468964978", "99618123.5339717944", "24529803.2444389601", "143060520.9047362779", "190651913.7089770083", "21.7234042553", "42.9433962264", "21.7226463104", "54.3103448276", "94.5140388769", "216.4903748734", "224.9325842697", "321.2340966921", "503.1068273092", "284.2416107383", "611623765.8647500770", "125718637.9005708302", "126575973.2879779836", "0.4999999993", "0.5000000000", "142854098.7306812546"]}
UNKNOWN
PYTHON3
CODEFORCES
19
1be5e5a36186928a169b53c3d91ce365
Nephren Runs a Cinema
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume that yuan is a kind of currency in Regulu Ere.) There are three types of customers: some of them bring exactly a 50-yuan note; some of them bring a 100-yuan note and Nephren needs to give a 50-yuan note back to him/her; some of them bring VIP cards so that they don't need to pay for the ticket. Now *n* customers are waiting outside in queue. Nephren wants to know how many possible queues are there that they are able to run smoothly (i.e. every customer can receive his/her change), and that the number of 50-yuan notes they have after selling tickets to all these customers is between *l* and *r*, inclusive. Two queues are considered different if there exists a customer whose type is different in two queues. As the number can be large, please output the answer modulo *p*. One line containing four integers *n* (1<=≤<=*n*<=≤<=105), *p* (1<=≤<=*p*<=≤<=2·109), *l* and *r* (0<=≤<=*l*<=≤<=*r*<=≤<=*n*). One line indicating the answer modulo *p*. Sample Input 4 97 2 3 4 100 0 4 Sample Output 13 35
[ "import bisect\r\nimport copy\r\nimport decimal\r\nimport fractions\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport sys\r\nfrom collections import Counter,deque,defaultdict\r\nfrom functools import lru_cache,reduce\r\nfrom heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max\r\ndef _heappush_max(heap,item):\r\n heap.append(item)\r\n heapq._siftdown_max(heap, 0, len(heap)-1)\r\ndef _heappushpop_max(heap, item):\r\n if heap and item < heap[0]:\r\n item, heap[0] = heap[0], item\r\n heapq._siftup_max(heap, 0)\r\n return item\r\nfrom math import gcd as GCD\r\nread=sys.stdin.read\r\nreadline=sys.stdin.readline\r\nreadlines=sys.stdin.readlines\r\n\r\nclass Prime:\r\n def __init__(self,N):\r\n self.smallest_prime_factor=[None]*(N+1)\r\n for i in range(2,N+1,2):\r\n self.smallest_prime_factor[i]=2\r\n n=int(N**.5)+1\r\n for p in range(3,n,2):\r\n if self.smallest_prime_factor[p]==None:\r\n self.smallest_prime_factor[p]=p\r\n for i in range(p**2,N+1,2*p):\r\n if self.smallest_prime_factor[i]==None:\r\n self.smallest_prime_factor[i]=p\r\n for p in range(n,N+1):\r\n if self.smallest_prime_factor[p]==None:\r\n self.smallest_prime_factor[p]=p\r\n self.primes=[p for p in range(N+1) if p==self.smallest_prime_factor[p]]\r\n\r\n def Factorize(self,N):\r\n assert N>=1\r\n factorize=defaultdict(int)\r\n if N<=len(self.smallest_prime_factor)-1:\r\n while N!=1:\r\n factorize[self.smallest_prime_factor[N]]+=1\r\n N//=self.smallest_prime_factor[N]\r\n else:\r\n for p in self.primes:\r\n while N%p==0:\r\n N//=p\r\n factorize[p]+=1\r\n if N<p*p:\r\n if N!=1:\r\n factorize[N]+=1\r\n break\r\n if N<=len(self.smallest_prime_factor)-1:\r\n while N!=1:\r\n factorize[self.smallest_prime_factor[N]]+=1\r\n N//=self.smallest_prime_factor[N]\r\n break\r\n else:\r\n if N!=1:\r\n factorize[N]+=1\r\n return factorize\r\n\r\n def Divisors(self,N):\r\n assert N>0\r\n divisors=[1]\r\n for p,e in self.Factorize(N).items():\r\n A=[1]\r\n for _ in range(e):\r\n A.append(A[-1]*p)\r\n divisors=[i*j for i in divisors for j in A]\r\n return divisors\r\n\r\n def Is_Prime(self,N):\r\n return N==self.smallest_prime_factor[N]\r\n\r\n def Totient(self,N):\r\n for p in self.Factorize(N).keys():\r\n N*=p-1\r\n N//=p\r\n return N\r\n\r\ndef Extended_Euclid(n,m):\r\n stack=[]\r\n while m:\r\n stack.append((n,m))\r\n n,m=m,n%m\r\n if n>=0:\r\n x,y=1,0\r\n else:\r\n x,y=-1,0\r\n for i in range(len(stack)-1,-1,-1):\r\n n,m=stack[i]\r\n x,y=y,x-(n//m)*y\r\n return x,y\r\n\r\nclass MOD:\r\n def __init__(self,p,e=1):\r\n self.p=p\r\n self.e=e\r\n self.mod=self.p**self.e\r\n \r\n def Pow(self,a,n):\r\n a%=self.mod\r\n if n>=0:\r\n return pow(a,n,self.mod)\r\n else:\r\n assert math.gcd(a,self.mod)==1\r\n x=Extended_Euclid(a,self.mod)[0]\r\n return pow(x,-n,self.mod)\r\n\r\n def Build_Fact(self,N):\r\n assert N>=0\r\n self.factorial=[1]\r\n self.cnt=[0]*(N+1)\r\n for i in range(1,N+1):\r\n ii=i\r\n self.cnt[i]=self.cnt[i-1]\r\n while ii%self.p==0:\r\n ii//=self.p\r\n self.cnt[i]+=1\r\n self.factorial.append((self.factorial[-1]*ii)%self.mod)\r\n self.factorial_inv=[None]*(N+1)\r\n self.factorial_inv[-1]=self.Pow(self.factorial[-1],-1)\r\n for i in range(N-1,-1,-1):\r\n ii=i+1\r\n while ii%self.p==0:\r\n ii//=self.p\r\n self.factorial_inv[i]=(self.factorial_inv[i+1]*ii)%self.mod\r\n\r\n def Fact(self,N):\r\n return self.factorial[N]*pow(self.p,self.cnt[N],self.mod)%self.mod\r\n\r\n def Fact_Inv(self,N):\r\n if self.cnt[N]:\r\n return None\r\n return self.factorial_inv[N]\r\n\r\n def Comb(self,N,K,divisible_count=False):\r\n if K<0 or K>N:\r\n return 0\r\n retu=self.factorial[N]*self.factorial_inv[K]*self.factorial_inv[N-K]%self.mod\r\n cnt=self.cnt[N]-self.cnt[N-K]-self.cnt[K]\r\n if divisible_count:\r\n return retu,cnt\r\n else:\r\n retu*=pow(self.p,cnt,self.mod)\r\n retu%=self.mod\r\n return retu\r\n\r\ndef LCM(n,m):\r\n if n or m:\r\n return abs(n)*abs(m)//math.gcd(n,m)\r\n return 0\r\n\r\ndef CRT(lst_r,lst_m):\r\n assert len(lst_r)==len(lst_m)\r\n if not lst_r:\r\n return 0,1\r\n r,m=lst_r[0],lst_m[0]\r\n for r0,m0 in zip(lst_r[1:],lst_m[1:]):\r\n if (r0,m0)==(-1,0):\r\n r,m=-1,0\r\n break\r\n r0%=m0\r\n g=math.gcd(m,m0)\r\n l=LCM(m,m0)\r\n if r%g!=r0%g:\r\n r,m=-1,0\r\n break\r\n r,m=(r0+m0*(((r-r0)//g)*Extended_Euclid(m0//g,m//g)[0]%(m//g)))%l,l\r\n return r,m\r\n\r\nN,P,L,R=map(int,readline().split())\r\nPr=Prime(10**5)\r\nlst_r,lst_m=[],[]\r\nFact=Pr.Factorize(P).items()\r\ndel Pr\r\nfor p,e in Fact:\r\n mod=p**e\r\n MD=MOD(p,e)\r\n MD.Build_Fact(N)\r\n ans=0\r\n for n in range(N+1):\r\n l,r=L,R\r\n if (N-n)%2!=l%2:\r\n l+=1\r\n if (N-n)%2!=r%2:\r\n r-=1\r\n if N-n<l:\r\n continue\r\n if N-n<r:\r\n r=N-n\r\n ans+=MD.Comb(N,N-n)*(MD.Comb(N-n,(N-n+l)//2)-MD.Comb(N-n,(N-n+r)//2+1))\r\n ans%=mod\r\n lst_r.append(ans)\r\n lst_m.append(mod)\r\nans,_=CRT(lst_r,lst_m)\r\nprint(ans)" ]
{"inputs": ["4 97 2 3", "4 100 0 4", "13 143 6 11", "999 998244353 666 777", "23333 1000000007 0 23333", "100000 100160063 2332 99774", "100000 996991027 54321 67890", "1 1 0 0", "1 1 0 1", "1 233332 0 0", "1 999888663 0 1", "1 2000000000 1 1", "2 14 0 0", "2 39 0 1", "2 1999999999 0 2", "2 15 1 1", "2 2 1 2", "2 3 2 2", "3 6 0 0", "3 9 0 1", "3 12 0 2", "3 999 0 3", "3 998244352 1 1", "3 5241 1 2", "3 18 1 3", "3 2 2 2", "3 1234567890 2 3", "3 16 3 3", "4 17 2 4", "4 1 1 3", "4 12 0 3", "4 4 2 3", "4 7 0 0", "4 14 4 4", "95 10007 23 77", "95 1001 16 88", "1024 1073741824 16 512", "2287 1895283097 97 2084", "6536 692001792 2018 6535", "23333 764411904 222 23333", "23333 764411904 0 23332", "57684 1987654320 1 57683", "65536 1987654320 33333 44444", "89701 223092870 235 87777", "93527 223092870 0 93527", "98760 1338557220 16384 65536", "99998 1561650090 10387 99771", "99999 1293938646 55447 55447", "99999 2000000000 66666 66666", "100000 901800900 8765 98765", "100000 1073741824 2 98304", "100000 1064246657 7147 83628", "100000 491986259 0 100000", "100000 1 98766 99877", "100000 1285743549 0 0", "100000 1784742960 125 99988"], "outputs": ["13", "35", "129", "974283165", "192355111", "68169009", "884435812", "0", "0", "1", "2", "1", "2", "4", "5", "2", "1", "1", "4", "0", "0", "13", "5", "8", "9", "1", "4", "1", "14", "0", "10", "1", "2", "1", "181", "381", "716646144", "1319976811", "81144575", "405536868", "164956607", "1266501185", "1184495760", "167375370", "60956070", "1287074250", "1402030596", "639859770", "1847813839", "207662400", "754182784", "605219868", "188914619", "0", "975152502", "1592494880"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1c3d7c7c251da6bd6d5318dc55816483
On Segment's Own Points
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has *n* students. Dean's office allows *i*-th student to use the segment (*l**i*,<=*r**i*) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (*n*<=-<=1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1. The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. Sample Input 3 0 5 2 8 1 6 3 0 10 1 5 7 15 Sample Output 1 3
[ "n = int(input())\r\nseta = set()\r\nax,ay = map(int, input().split(\" \"))\r\nfor i in range(ax,ay):\r\n seta.add(i+0.5)\r\nfor i in range(0,n-1):\r\n nx,ny = map(int, input().split(\" \"))\r\n for j in range(nx,ny):\r\n seta.discard(j+0.5)\r\nprint(len(seta))", "# https://codeforces.com/problemset/problem/397/A\n# A. On Segment's Own Points\n\nn = int(input())\nrope = [True] * 100\nx1, y1 = map(int, input().split())\n\nfor _ in range(1, n):\n x , y = map(int, input().split())\n for i in range(x, y):\n rope[i] = False\n\ntotal_len = 0\nfor i in range(x1, y1):\n if rope[i] == True:\n total_len += 1\nprint(total_len)\n", "n = int(input())\r\nh = [1] * 100\r\na, b = map(int, input().split())\r\nfor i in range(n - 1):\r\n x, y = map(int, input().split())\r\n for j in range(x, y):\r\n h[j] = 0\r\n\r\nprint(sum(h[a : b]))", "n = int(input())\r\nlrs = []\r\n\r\nalr = input().split()\r\nal = int(alr[0])\r\nar = int(alr[1])\r\nat = ar - al\r\n\r\nfor i in range(n-1):\r\n lr = input().split()\r\n l = (int(lr[0]), 'l')\r\n r = (int(lr[1]), 'r')\r\n lrs.append(l)\r\n lrs.append(r)\r\n\r\nslrs = sorted(lrs, key = lambda x: x[0])\r\n\r\nc = 0\r\nlt = 101\r\n\r\nfor i in range(2 * (n - 1)):\r\n cur = slrs[i]\r\n if cur[1] == 'l':\r\n c += 1\r\n if c == 1:\r\n lt = cur[0]\r\n else:\r\n c -= 1\r\n if c == 0:\r\n if al <= cur[0] and cur[0] <= ar:\r\n if lt >= al:\r\n at -= (cur[0] - lt)\r\n elif lt < al:\r\n at -= (cur[0] - al)\r\n elif ar < cur[0]:\r\n if lt <= al:\r\n at = 0\r\n elif al < lt and lt < ar:\r\n at -= (ar - lt)\r\n if at <= 0:\r\n break\r\n lt = 101\r\n\r\nprint(at)\r\n", "n = int(input())\r\n\r\nl = [int(i) for i in input().split(\" \")]\r\nfirst = {f for f in range(l[0], l[1])}\r\n\r\nfor i in range(n - 1):\r\n l = [int(i) for i in input().split(\" \")]\r\n n = {f for f in range(l[0], l[1])}\r\n first -= n\r\n\r\nprint(len(first))", "quantity = [False]*101\r\nn = int(input())\r\nl, r = map(int, input().split())\r\nfor i in range(l, r):\r\n\tquantity[i] = True\r\nfor i in range(n-1):\r\n\tl, r = map(int, input().split())\r\n\tfor j in range(l, r):\r\n\t\tquantity[j] = False\r\nres = 0\r\nfor value in quantity:\r\n\tif value:\r\n\t\tres+=1\r\nprint(res)", "n = int(input())\r\nAl_r = input()\r\nAl = int(Al_r.split(' ')[0])\r\nAr = int(Al_r.split(' ')[1])\r\nAl_rList = list(range(Al,Ar))\r\nfor i in range(n-1):\r\n l_r = input()\r\n l = int(l_r.split(' ')[0])\r\n r = int(l_r.split(' ')[1])\r\n l_rList = list(range(l, r))\r\n for i in l_rList:\r\n if i in Al_rList:\r\n Al_rList.remove(i)\r\nprint(len(Al_rList))", "n=int( input() )\nl=[]\nr=[]\n\nfor i in range( 0, n ):\n a=list(map(int,input().split()))\n l.append(a[0])\n r.append(a[1])\n\nans=0\nfor j in range( l[0], r[0] ):\n for k in range(1, n):\n if j<r[k] and j>=l[k]:\n break\n else:\n ans+=1\n\nprint(str(ans))\n", "a=list()\r\nn=int(input())\r\nc=[1]*100\r\nl,r=map(int,input().split())\r\nfor i in range(n-1):\r\n b=list(map(int,input().split()))\r\n for j in range(b[0],b[1]):\r\n c[j]=0\r\nprint(sum(c[l:r]))", "n = int(input())\r\nd = [1] * 100\r\na, b = map(int, input().split())\r\nfor _ in range(n - 1):\r\n l, r = map(int, input().split())\r\n for i in range(l, r):\r\n d[i] = 0\r\nprint(sum(d[a:b]))", "# cook your dish here\r\nn=int(input())\r\nd=[]\r\ncount=0\r\nc=[]\r\nfor j in range(n):\r\n a,b=map(int,input().split())\r\n for i in range(a,b):\r\n if i not in c:\r\n c.append(i)\r\n if j!=0 :\r\n d.append(i)\r\nfor i in range(min(c),max(c)+1):\r\n if i in d:\r\n if i in c:\r\n c.remove(i)\r\nprint(len(c))", "n = int(input())\r\nm = []\r\nl, r = 0, 0\r\nfor i in range(n):\r\n b1, b2 = list(map(int, input().split(' ')))\r\n if i == 0:\r\n l, r = b1, b2\r\n m.append( (b1, 0))\r\n m.append( (b2, 0))\r\n else:\r\n m.append( (b1, 1))\r\n m.append( (b2, -1))\r\nm.sort()\r\n\r\nb, a = 0, []\r\ncont = False\r\nfor i in m:\r\n b += i[1]\r\n if not(cont) and i[1] == 0:\r\n cont = True\r\n elif cont and i[1] == 0:\r\n a.append((i[0], b))\r\n break\r\n if cont:\r\n a.append((i[0], b))\r\nans = 0\r\nfor i in range(len(a[:-1])):\r\n if a[i][1] == 0:\r\n ans += a[i+1][0] - a[i][0]\r\n\r\nprint (ans)\r\n", "bizy = [0]*100\r\nn = int(input())\r\na_l,a_r = map(int,input().split())\r\nfor i in range(a_l,a_r):\r\n bizy[i] = 1\r\nfor i in range (n-1):\r\n o_l,o_r = map(int,input().split())\r\n for i in range(o_l,o_r):\r\n bizy[i] -= 1\r\nprint(bizy[a_l:a_r].count(1))", "import sys; sys.setrecursionlimit(1000000)\n\ndef solve():\n n, = rv()\n count = [0] * 100\n leftmost, rightmost, = rv()\n for seg in range(n - 1):\n left, right, = rv()\n for val in range(left, right):\n count[val]+=1\n res = 0\n for val in range(leftmost, rightmost):\n if count[val] == 0: res+=1\n print(res)\n\ndef rv(): return map(int, input().split())\ndef rl(n): return [list(map(int, input().split())) for _ in range(n)]\nif sys.hexversion == 50594544 : sys.stdin = open(\"test.txt\")\nsolve()\n\n\n", "n = int(input())\r\na , b = (int(x) for x in input().split())\r\nl = [x for x in range(a,b)]\r\nfor i in range(0,n-1):\r\n a,b = (int(x) for x in input().split())\r\n for x in range(a,b):\r\n if x in l: l.remove(x)\r\n\r\nprint(len(l)) \r\n ", "l = [i for i in range(101)]\r\nc,x,y=0,0,0\r\nfor i in range(int(input())):\r\n\tn,m = map(int,input().split())\r\n\tif i==0:x,y = n,m\r\n\telse:\r\n\t\tfor j in range(n,m):\r\n\t\t\tl[j] = -1\r\nfor i in range(x,y):\r\n\tif l[i]!=-1 and l[i+1]==-1 or l[i]!=-1 and l[i+1]!=-1:\r\n\t\tc+=1\r\nprint(c)", "n, t = int(input()) - 1, [0] * 101\r\na, b = map(int, input().split())\r\nfor i in range(n) :\r\n l, r = map(int, input().split())\r\n t[l] += 1\r\n t[r] -= 1\r\nfor i in range(b - 1): t[i + 1] += t[i]\r\nprint(t[a: b].count(0))", "n= int(input())\r\nm=[]\r\nfor _ in range(n):\r\n l,r= map(int,input().split())\r\n o=[x for x in range(l+1,r+1)]\r\n m.append(o)\r\nc=0\r\np=[]\r\nfor i in range(1,n):\r\n p+=m[i]\r\np= list(set(p))\r\nfor i in m[0]:\r\n if i not in p:\r\n c+=1\r\nprint(c)", "used = [0] * 100\r\nn = int(input())\r\nl, r = map(int, input().split())\r\nfor _ in range(n-1):\r\n a, b = map(int, input().split())\r\n for i in range(a, b):\r\n used[i] = 1\r\nprint(used[l:r].count(0))\r\n", "n = int(input())\r\ndryer = [None] * 100\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n for j in range(a, b):\r\n dryer[j] = i\r\nprint(dryer.count(0))\r\n", "n=int(input())\r\nl,r=map(int,input().split())\r\nlst=[0]*100\r\nfor i in range(n-1):\r\n a1,a2=map(int,input().split())\r\n lst[a1:a2]=[1 for i in range(a2-a1)]\r\nc=0\r\nfor i in range(l,r):\r\n if lst[i]==0:c+=1\r\nprint(c)\r\n", "n = int(input())\nsags = list()\n\ni = 1\nwhile i <= n:\n a, b = input().split(' ')\n sags.append(list(range(int(a), int(b))))\n\n i += 1\n\nmysag = sags[0]\n\ni = 0\nwhile i < len(mysag):\n # print(mysag[i])\n j = 1\n while j < len(sags):\n if mysag[i] in sags[j]:\n mysag[i] = -1\n j += 1\n i += 1\n\nmyblock = [x for x in mysag if x != -1]\nprint(len(myblock))\n", "n = int(input())\nm, M = map(int, input().split())\nx = set((i, i + 1) for i in range(m, M))\nfor _ in range(n - 1):\n a, b = map(int, input().split())\n for i in range(a, b):\n if (i, i + 1) in x:\n x.remove((i, i + 1))\nprint(len(x))\n", "# read in data\nn = int(input())\nsegments = [0] * n\nfor i in range(n):\n segments[i] = tuple(map(int, input().split(' ')))\n\n# mark the segments\ndry_line = [0]*101\nfor s in range(1, n):\n l, r = segments[s]\n dry_line[l] -= 1\n dry_line[r] += 1\n\n# calculate cumulative sum\nfor i in range(1, 101):\n dry_line[i] += dry_line[i-1]\n\n# calculate sum of exclusive segment\nprint(sum(1 for part in range(segments[0][0], segments[0][1]) if dry_line[part] == 0))\n", "def solve(ranges):\r\n a = set(range(ranges[0][0], ranges[0][1]))\r\n for x, y in ranges[1:]:\r\n tmp1 = a & set(range(0, x))\r\n tmp2 = a & set(range(y, 100))\r\n a = tmp1 | tmp2\r\n return len(a)\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n ranges = list()\r\n for _ in range(n):\r\n ranges.append(list(map(int, input().split())))\r\n print(solve(ranges))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "n = int(input())\r\na1 = list()\r\nfor i in range(0,101):\r\n\ta1.insert(i,0)\r\n#\tprint(a1[i])\r\nfor i in range(0,n):\r\n\ta,b = map(int,input().split())\r\n\t#print(i)\r\n\tif i!=0:\r\n\t\tfor j in range(a, b):\r\n\t\t\t#print(j)\r\n\t\t\ta1[j] = 1\r\n\t\t\t#print(a1[j])\r\n\telse:\r\n\t\tl = a\r\n\t\tr = b\r\nans = 0\r\nfor i in range(l, r):\r\n\t#print(i)\r\n\tif a1[i]==0:\r\n\t\tans = ans+1\r\nprint(ans)\r\n\t\r\n", "import sys\r\nfrom math import *\r\n\r\ndef minp():\r\n\treturn sys.stdin.readline().strip()\r\n\r\ndef mint():\r\n\treturn int(minp())\r\n\r\ndef mints():\r\n\treturn map(int, minp().split())\r\n\r\nn = mint()\r\na = []\r\nfor i in range(n):\r\n\ta.append(tuple(mints()))\r\nr = 0\r\nfor i in range(*a[0]):\r\n\tr += 1\r\n\tfor j in range(1,len(a)):\r\n\t\tz = a[j]\r\n\t\tif z[0]<=i and z[1]>i:\r\n\t\t\tr -= 1\r\n\t\t\tbreak\r\nprint(r)", "def g(l) :\r\n if len(l)==1 :\r\n return l\r\n else:\r\n ans=[l[0]]\r\n for i in range(1,len(l)) :\r\n (a,b)=l[i]\r\n (c,d)=ans[-1]\r\n if a<=d :\r\n ans[-1]=(c,max(b,d))\r\n else:\r\n ans.append((a,b))\r\n return ans\r\n\r\ndef f(l) :\r\n (a,b)=l[0]\r\n if len(l)==1 :\r\n return b-a\r\n else:\r\n lnew=sorted(l[1:])\r\n lf=g(lnew)\r\n ans=b-a\r\n for i in range(len(lf)) :\r\n (c,d)=lf[i]\r\n if b<=c :\r\n break\r\n else:\r\n if c<a :\r\n if d>a:\r\n if d>b :\r\n return 0\r\n else:\r\n ans=ans-d+a\r\n else:\r\n if d>b :\r\n ans=ans-b+c\r\n else:\r\n ans=ans-d+c\r\n return ans\r\n \r\n \r\n\r\n\r\nn=int(input())\r\nl=[]\r\nt=0\r\nwhile t != n :\r\n t=t+1\r\n x=input().split(\" \")\r\n a=int(x[0])\r\n b=int(x[1])\r\n l.append((a,b))\r\nprint(f(l))\r\n", "n = int(input())\r\nsegs = []\r\ntotal = 0\r\nfound = True\r\n \r\nfor i in range(n):\r\n segs.append(list(map(int, input().split())))\r\n segs[i][0] += 0.5\r\n segs[i][1] -= 0.5\r\n\r\nstart, end = segs[0][0], segs[0][1]\r\ni = start\r\n\r\nwhile i <= end:\r\n found = True\r\n for seg in segs[1: ]:\r\n if i >= seg[0] and i <= seg[1]:\r\n found = False\r\n break\r\n if found:\r\n total += 1\r\n\r\n i += 1\r\n\r\nprint(total)\r\n \r\n", "n = int(input())\r\nx,y = map(int , input().split())\r\nr = [False]*(100)\r\nr[x:y]=[True]*(y-x)\r\nfor i in range(n-1):\r\n a,b = map(int , input().split())\r\n r[a:b] = [False]*(b-a)\r\nprint(r.count(True))", "n = int(input())\r\nlst = [0 for i in range(100)]\r\nl , r = map(int , input() . split())\r\nfor i in range(n - 1):\r\n x , y = map(int , input() . split())\r\n for j in range(x , y): \r\n lst[j] = 1\r\nans = 0\r\nfor i in range(l , r):\r\n if(lst[i] == 0): \r\n ans += 1\r\nprint(ans)", "N = int(input())\r\nlen1 = [0]*101\r\nfor i in range(1, N + 1) :\r\n l, r = [int(s) for s in input().split()]\r\n for j in range(l, r) :\r\n len1[j] = (1 if i == 1 else 0)\r\n \r\nprint(str(sum(len1)))", "n=int(input())\r\na=[1]*100\r\nx,y=map(int,input().split())\r\nfor i in range(n-1):\r\n\tl,r=map(int,input().split())\r\n\tfor j in range(l,r):\r\n\t\ta[j]=0;\r\nprint(sum(a[x:y]))", "#new algorithm\r\ndef seg_dis(arr, start, end, n):\r\n for i in range(n):\r\n for j in range(start[i], end[i]):\r\n arr[j] = i\r\n return arr\r\n\r\ndef fill_arr(arr, n):\r\n for i in range(n):\r\n arr.append(0)\r\n return arr\r\n\r\ndef count_zeros_range(arr, ini, end): \r\n cant = 0\r\n for i in range(ini, end):\r\n if(arr[i] == 0):\r\n cant = cant + 1\r\n return cant \r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n start = [None] * n\r\n end = [None] * n\r\n\r\n for i in range(n):\r\n ele = list(map(int, input().split()))\r\n start[i] = ele[0]\r\n end[i] = ele[1]\r\n my_arr = []\r\n fill_arr(my_arr, 100)\r\n my_arr = seg_dis(my_arr, start, end, n)\r\n zeros = count_zeros_range(my_arr, start[0], end[0])\r\n print(zeros)\r\n", "n=int(input())\r\nl=[]\r\nq=[0]*100\r\np=list(map(int,input().split()))\r\nl.append(p)\r\nfor i in range(n-1):\r\n p=list(map(int,input().split()))\r\n l.append(p)\r\n for k in range(p[0],p[1]):\r\n q[k]=1\r\nr=0\r\nfor i in range(l[0][0],l[0][1]):\r\n if(q[i]==0):\r\n r=r+1\r\nprint(r)", "n = int(input())\r\nans = [1]*100\r\n\r\na, b = map(int, input().split())\r\n\r\nfor k in range(n-1):\r\n l, r = map(int, input().split())\r\n for i in range(l, r):\r\n ans[i] = 0\r\n\r\nprint(sum(ans[a:b]))\r\n", "n = int(input())\r\na,b = map(int,input().split())\r\nli=[]\r\nfor i in range(n-1):\r\n x,y = map(int,input().split())\r\n li.append([x,y])\r\narr = [0]*(100+1)\r\nfor i in range(n-1):\r\n arr[li[i][0]] +=1 \r\n arr[li[i][1]] -=1\r\ns,ans= 0,0\r\nfor i in range(b+1):\r\n if i >a and s==0:\r\n ans+=1\r\n s+=arr[i]\r\nprint(ans) \r\n \r\n ", "def good_segments():\r\n\tcount = int(input())\r\n\r\n\tsegments = []\r\n\tright = 0\r\n\tfor _ in range(count):\r\n\t\tstart, end = [int(coor) for coor in input().split()]\r\n\t\tif end > right:\r\n\t\t\tright = end\r\n\t\tsegments.append((start, end))\r\n\r\n\tbooked_slots = [0]*right\r\n\t# populate 1 for other students slots\r\n\tfor seg in segments[1:]:\r\n\t\tfor i in range(seg[0], seg[1]):\r\n\t\t\tbooked_slots[i] = 1\r\n\t\r\n\tgood_slots = 0\r\n\tfor index in range(segments[0][0], segments[0][1]):\r\n\t\tif booked_slots[index] == 0:\r\n\t\t\tgood_slots += 1\r\n\r\n\tprint(good_slots)\r\n\r\n\r\ngood_segments()\r\n", "n=int(input())\r\nAl,Ar=map(int,input().split())\r\ncnt=[0]*101\r\nfor i in range(n-1):\r\n l,r=map(int,input().split())\r\n for j in range(l,r):\r\n cnt[j]=1\r\nans=0\r\nfor i in range(Al,Ar):\r\n if cnt[i]==0:\r\n ans+=1\r\nprint(ans)\r\n", "g = int(input())\no,p = map(int,input().split())\nm = set()\nfor i in range(g - 1):\n\tx,y = map(int,input().split())\n\tfor j in range(x,y):\n\t\tm.add(j)\nc = 0\nfor i in range(o,p):\n\tif i not in m:\n\t\tc += 1\nprint(c)", "from sys import stdin, stdout\r\n\r\nn = int(stdin.readline().strip())\r\nalex = list(map(int, stdin.readline().strip().split()))\r\nalex_lst = list(range(alex[0] + 1, alex[1] + 1))\r\nfor i in range(1, n):\r\n lst = list(map(int, stdin.readline().strip().split()))\r\n for j in range(lst[0] + 1, lst[1] + 1):\r\n if j in alex_lst:\r\n alex_lst.remove(j)\r\nstdout.write(str((len(alex_lst))))", "from collections import Counter\nfrom re import findall\n\nn = int(input())\ny = [int(i) for i in input().split()]\nalex = list(range(y[1]))\nfor i in range(n-1):\n a, b = [int(x) for x in input().split()]\n for j in range(a, min(b, y[1])):\n alex[j] = 'X'\n\no = [str(x) for x in (alex[y[0]:y[1]])]\no = filter(lambda el: el is not 'X', o)\n\nprint(len(list(o)))\n", "n=int(input())\r\nalexy = list(map(int, input().split(\" \")))\r\na=[False for i in range(101)]\r\nfor i in range(n-1):\r\n x = list(map(int, input().split(\" \")))\r\n for i in range(x[0],x[1]):\r\n a[i]=True\r\nprint(sum(a[i]==False for i in range(alexy[0],alexy[1])))\r\n", "def main():\n\tn = int(input())\n\t_input = list(map(int, input().split()))\n\t_start = _input[0]\n\t_end = _input[1]\n\tAlexey = []\n\tfor _ in range(_start, _end):\n\t\tAlexey.append(0)\n\n\tfor _ in range(n - 1):\n\t\t_input = list(map(int, input().split()))\n\t\tstart = _input[0]\n\t\tend = _input[1]\n\t\tfor _index in range(start - _start, end - _start):\n\t\t\tif _index >=0 and _index < len(Alexey):\n\t\t\t\tAlexey[_index] = 1\n\t# print(Alexey)\n\tprint(Alexey.count(0))\n\nif __name__ == '__main__':\n\tmain()", "'''\r\nA. Sobre puntos propios del segmento\r\ntiempo límite por prueba1 segundo\r\nlímite de memoria por prueba256 megabytes\r\nentradaentrada estándar\r\nsalidasalida estándar\r\nNuestro viejo amigo Alexey finalmente ingresó en la Universidad de City N, la capital de Berland. Alexey esperaba que su padre le consiguiera un lugar para vivir, pero su padre dijo que ya era hora de que Alexey practique cierta independencia financiera. Entonces, Alexey está viviendo en un dormitorio.\r\n\r\nEl dormitorio tiene exactamente un secador recto: una cuerda de 100 centímetros de largo para colgar la ropa. El secador tiene un sistema de coordenadas instalado: el extremo más a la izquierda del secador tiene la coordenada 0 , y el extremo opuesto tiene la coordenada 100 . En general, la universidad tiene n estudiantes. La oficina del decano permite que el i -alumno utilice el segmento ( l i ,  r i ) de la secadora. Sin embargo, las acciones de la oficina del decano son contradictorias y ¡ahora una parte de la secadora puede pertenecer a varios estudiantes!\r\n\r\nA Alexey no le gusta que alguien le toque la ropa. Por eso quiere que sea imposible que alguien le toque la ropa. Así que Alexey se pregunta: ¿cuál es la longitud total de las partes de la secadora que puede usar de tal manera que la ropa de los demás ( n  - 1) estudiantes no se seque allí? ¡Ayudalo! Tenga en cuenta que Alexey, como el estudiante más respetado, tiene el número 1.\r\n\r\nEntrada\r\nLa primera línea contiene un entero positivo n ( 1 ≤  n  ≤ 100 ). La línea ( i  + 1) contiene los números enteros l i y r i ( 0 ≤  l i  <  r i  ≤ 100 ) - los puntos finales del segmento correspondiente para el estudiante i -th.\r\n\r\nSalida\r\nEn una sola línea, imprima un solo número k , igual a la suma de las longitudes de las partes de la secadora que están dentro del segmento de Alexey y están fuera de todos los demás segmentos.\r\n\r\nEjemplos\r\nentradaDupdo\r\n3\r\n0 5\r\n2 8\r\n1 6\r\nsalidaDupdo\r\n1\r\nentradaDupdo\r\n3\r\n0 10\r\n1 5\r\n7 15\r\nsalidaDupdo\r\n3\r\nNota\r\nTenga en cuenta que no es importante que la ropa que se está secando en los segmentos en contacto (p. Ej. (0, 1) y (1, 2) ) se considere que está en contacto o no porque necesita encontrar la longitud de los segmentos.\r\n\r\nEn la primera muestra de prueba, Alexey puede usar el único segmento (0, 1) . En tal caso, su ropa no tocará la ropa en los segmentos (1, 6) y (2, 8) . La longitud del segmento (0, 1) es 1.\r\n\r\nEn la segunda muestra de prueba, Alexey puede secar su ropa en los segmentos (0, 1) y (5, 7) . La longitud total de estos segmentos es 3.\r\n'''\r\nestudiantes = int(input())\r\nx = tuple (map(int,input().split()))\r\nAlexey = {i for i in range(x[0],x[1])}\r\nfor i in range(estudiantes - 1):\r\n y = tuple (map(int,input().split()))\r\n est = {i for i in range(y[0],y[1])}\r\n Alexey -= est\r\nprint(len(Alexey))\r\n", "n = int(input())\r\n\r\nalex_space = [False]*100\r\n\r\nfor i in range(n):\r\n a, b = input().split()\r\n a, b = int(a), int(b)\r\n\r\n if i == 0:\r\n alex_space[a:b] = [True]*(b-a)\r\n else:\r\n alex_space[a:b] = [False]*(b-a)\r\n\r\nprint(sum([1 if x else 0 for x in alex_space]))\r\n\r\n", "# Design_by_JOKER\r\nimport math\r\nimport cmath\r\n\r\nn = int(input())\r\nm = 0\r\ndd = [0]*101\r\nl, r = map(int, input().split())\r\nfor _ in range(l, r):\r\n dd[_] = 1\r\n\r\nfor _ in range(n-1):\r\n a, b = map(int, input().split())\r\n for x in range(a, b):\r\n dd[x] = 0\r\nprint(sum(dd))", "n = int(input())\r\ns = [0 for q in range(0, 101)]\r\nla, ra = [int(q) for q in input().split()]\r\nfor i in range(la, ra):\r\n s[i] = 1\r\nfor j in range(n - 1):\r\n l, r = [int(q) for q in input().split()]\r\n for i in range(l, r):\r\n s[i] = 0\r\nprint(sum(s))", "if __name__ == '__main__':\n n = int(input())\n s = [0 for _ in range(100)]\n [al, ar] = [int(x) for x in input().split()]\n\n for i in range(al, ar):\n s[i] = 1\n\n for _ in range(1, n):\n [bl, br] = [int(x) for x in input().split()]\n for i in range(bl, br):\n s[i] = 0\n\n print(sum(s))\n", "n=int(input())\r\nd=[1]*100\r\na,b=map(int,input().split())\r\nfor i in range(n-1):\r\n l,r=map(int,input().split())\r\n for i in range(l,r):\r\n d[i]=0\r\nprint(sum(d[a:b]))", "a = int(input())\r\nx=[1]*101\r\nk=[int(j) for j in input().split()]\r\nl,r = k[0],k[1]\r\nfor i in range(a-1):\r\n\tk=[int(j) for j in input().split()]\r\n\tx[k[0]:k[1]]=[0]*(k[1]-k[0])\r\nprint(sum(x[l:r]))", "from operator import itemgetter\r\n\r\n\r\ndef get_length(input, n):\r\n result = 0\r\n result_dict = {}\r\n check = True\r\n for i in range(0, n):\r\n for j in range(input[i][0] , input[i][1]):\r\n if (check):\r\n result_dict[j] = True\r\n else:\r\n result_dict[j] = False\r\n check = False\r\n\r\n for key, value in result_dict.items():\r\n if value:\r\n result += 1\r\n\r\n # input = sorted(input, key=itemgetter(0))\r\n # for i in range(0, n-1):\r\n # print(input)\r\n # if input[i][0] < input[i+1][0]:\r\n # if input[i][1] > input[i+1][0]:\r\n # if input[i][1] < input[i+1][1]:\r\n # val = list([input[i][0], input[i+1][0]])\r\n # # input.pop(i)\r\n # # input.pop(i+1)\r\n # # input.insert(i,val)\r\n # result.append(list([input[i][0], input[i+1][0]]))\r\n # else:\r\n # # input.pop(i)\r\n # # input.insert(i, list([input[i][0], input[i + 1][0]]))\r\n # # input.pop(i+1)\r\n # if input[i+1][1] > input[i][1]:\r\n # val = list([input[i][1] , input[i+1][1]])\r\n # # input.insert(i+1,val )\r\n # result.append(list([input[i][1] , input[i+1][1]]))\r\n # else:\r\n # val = list([input[i + 1][1], input[i][1]])\r\n # # input.append(i+1, val)\r\n # result.append(list([input[i + 1][1], input[i][1]]))\r\n # print(result)\r\n return result\r\nn = int(input())\r\ninput_list = []\r\nfor i in range(0,n):\r\n x,y = map(int, input().split())\r\n input_list.append(list([x,y]))\r\n\r\nprint(get_length(input_list, n))", "class CodeforcesTask397ASolution:\n def __init__(self):\n self.result = ''\n self.n = 0\n self.segments = []\n\n def read_input(self):\n self.n = int(input())\n for x in range(self.n):\n self.segments.append([int(y) for y in input().split(\" \")])\n\n def process_task(self):\n segment = [1 if self.segments[0][0] <= x < self.segments[0][1] else 0 for x in range(100)]\n for x in range(self.n - 1):\n for y in range(self.segments[x + 1][0], self.segments[x + 1][1]):\n segment[y] = 0\n self.result = str(sum(segment))\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask397ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "n=int(input())\r\np,q=map(int,input().split(\" \"))\r\nalexey=set(range(p,q))\r\nUnion={}\r\nfor i in range(n-1):\r\n if(i==0):\r\n p,q=map(int,input().split(\" \"))\r\n Union=set(range(p,q))\r\n else:\r\n p,q=map(int,input().split(\" \"))\r\n student=set(range(p,q))\r\n Union=Union.union(student)\r\n \r\ninter=alexey.intersection(Union)\r\nprint((len(alexey))-(len(inter)))", "n = int(input())\r\nlst = [0]*101\r\nans=0\r\nx,y = list(map(int, input().split()))\r\n\r\nfor i in range(n-1):\r\n a,b = list(map(int, input().split()))\r\n\r\n for j in range(a,b):\r\n lst[j]+=1\r\n\r\nfor i in range(x,y):\r\n if lst[i]==0:\r\n ans+=1\r\n \r\nprint(ans)", "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\r\n| author: mr.math - Hakimov Rahimjon |\r\n| e-mail: [email protected] |\r\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\r\n#inp = open(\"lepus.in\", \"r\"); input = inp.readline; out = open(\"lepus.out\", \"w\"); print = out.write\r\nTN = 1\r\n\r\n\r\n# ===========================================\r\n \r\n \r\ndef solution():\r\n n = int(input())\r\n lx, rx = map(int, input().split())\r\n anss = [0 for i in range(101)]\r\n ans = 0\r\n for i in range(n-1):\r\n l, r = map(int, input().split())\r\n for i in range(l,r):\r\n anss[i] = 1\r\n for i in range(lx, rx):\r\n if not anss[i]: ans += 1\r\n print(ans)\r\n\r\n\r\n# ===========================================\r\nwhile TN != 0:\r\n solution()\r\n TN -= 1\r\n# ===========================================\r\n#inp.close()\r\n#out.close()", "n = int(input())\na,b = [int(i) for i in input().split()]\ns1 = set(range(a,b))\nfor i in range(n-1):\n x,y = [int(i) for i in input().split()]\n s1 -= set(range(x,y))\nprint(len(s1))", "\r\ns=[1 for i in range(100)]\r\nn=int(input())\r\nfor i in range(n):\r\n li=[int(x) for x in input().split()]\r\n if(i==0):\r\n x,y=li[0],li[1]\r\n else:\r\n x1,y1=li[0],li[1]\r\n for i in range(x1,y1):\r\n s[i]=0\r\nprint(s[x:y].count(1))", "n = int(input())\r\n\r\n\r\ndef nhap():\r\n temp = input()\r\n temp = temp.split(\" \")\r\n return [int(temp[0]), int(temp[1])]\r\n\r\nl0, r0 = nhap()\r\na = dict()\r\n_ = l0 + 0.5\r\nwhile _ < r0:\r\n a[_] = 1\r\n _ += 1\r\n\r\nfor i in range(n - 1):\r\n l, r = nhap()\r\n _ = l + 0.5\r\n while _ < r:\r\n a[_] = 0\r\n _ += 1\r\n\r\ntemp = a.values()\r\nsum = 0\r\nfor i in temp:\r\n sum += i\r\nprint(sum)", "N = int(input())\r\nL, R = map(int, input().split())\r\nP = [0] * 101\r\nfor i in range(N - 1):\r\n\tl, r = map(int, input().split())\r\n\tP[l] += 1\r\n\tP[r] -= 1\r\nfor i in range(1, 101):\r\n\tP[i] += P[i - 1]\r\nans = 0\r\nfor i in range(L, R):\r\n\tif P[i] == 0:\r\n\t\tans += 1\r\nprint(ans)", "n = int(input())\r\na = [0] * 100\r\nla, ra = map(int, input().split())\r\nfor i in range(1, n):\r\n l, r = map(int, input().split())\r\n a[l] += 1\r\n if r < 100:\r\n a[r] -= 1\r\nfor i in range(1, 100):\r\n a[i] += a[i - 1]\r\nans = 0\r\nfor i in range(la, ra):\r\n if a[i] == 0:\r\n ans += 1\r\nprint(ans)", "n = int(input())\r\nl = list(map(int,input().split()))\r\nk = set(range(l[0],l[1]))\r\nfor i in range(n-1):\r\n l = list(map(int,input().split()))\r\n x = set(range(l[0],l[1]))\r\n k -= x\r\nprint(len(k))", "n=int(input())\r\nar=[0 for i in range(100+1)]\r\na,b=map(int,input().split())\r\nfor i in range(a,b):\r\n ar[i]=1\r\n#print(ar[0:16])\r\nfor i in range(1,n):\r\n x,y=map(int,input().split())\r\n for j in range(x,y):\r\n ar[j]=2\r\n#print(ar[0:16])\r\ns=0\r\nflg=0\r\nfor i in range(a,b+1):\r\n if ar[i]==1:\r\n s+=1\r\n \r\nprint(s)\r\n", "n = int(input())\r\nx, y = map(int, input().split())\r\narr = list()\r\nfor i in range(n-1):\r\n v = tuple(map(int, input().split()))\r\n arr.append(v)\r\nans = 0\r\nfor i in range(x, y):\r\n result = True\r\n for j in arr:\r\n if j[0] <= i <= j[1] and j[0] <= i+1 <= j[1]:\r\n result = False\r\n if result:\r\n ans += 1\r\nprint(ans)", "l=[1]*100\r\nn=int(input())\r\na,b=list(map(int,input().split()))\r\nfor i in range(n-1):\r\n x,y=list(map(int,input().split()))\r\n for i in range(x,y):\r\n l[i]=0\r\nprint(sum(l[a:b]))", "n = int(input())\nmy_l, my_r = list(map(int,input().split()))\n\nrope = [0]*101\n\nfor i in range(my_l,my_r):\n rope[i] = 1\n\nfor i in range(n-1):\n l,r = list(map(int,input().split()))\n\n for j in range(l,r):\n rope[j] = 0\n\n\nprint(sum(rope))\n ", "n=int(input())\r\nx,y=map(int,input().split())\r\ns1=set(list(range(x,y)))\r\nentire=set(list(range(0,100)))\r\nfor i in range(n-1):\r\n x,y=map(int,input().split())\r\n s2=set(list(range(x,y)))\r\n s1=s1.intersection(entire-s2)\r\nprint(len(s1))\r\n", "N = int(input())\r\nsush = [0] * 101\r\nfor i in range(1, N + 1) :\r\n l, r = [int(s) for s in input().split()]\r\n for j in range(l, r) :\r\n sush[j] = (1 if i == 1 else 0)\r\nprint(str(sum(sush)))", "#code\r\nn=int(input())\r\nx,y=input().split()\r\nx,y = int(x),int(y)\r\nl=list(range(x,y))\r\ns=set(l)\r\nfor i in range (1,n):\r\n p,q=input().split()\r\n p,q=int(p),int(q)\r\n l1=list(range(p,q))\r\n s1=set(l1)\r\n s=s-s1\r\nprint(len(s))", "n = int(input())\r\nsegments = []\r\nfor _ in range(n):\r\n segments.append(list(map(int, input().split())))\r\nl = segments[0][0]\r\nr = segments[0][1]\r\nlist_of_tuples = []\r\nfor i in range(l,r):\r\n list_of_tuples.append((i,i+1))\r\ni=1\r\nwhile i<n:\r\n for j in range(segments[i][0],segments[i][1]):\r\n if (j,j+1) in list_of_tuples:\r\n list_of_tuples.remove((j,j+1))\r\n i += 1\r\nprint(len(list_of_tuples))", "num_of_student = int(input())\nsush = list()\n\nfor i in range(0, num_of_student):\n inp = input()\n inp_spl = inp.split(\" \")\n sush.append(int(inp_spl[0]))\n sush.append(int(inp_spl[1]))\n\none_range = [0 for i in range(0, max(sush)+1)]\n\nfor i in range(0, num_of_student*2, 2):\n for j in range(sush[i], sush[i+1]):\n one_range[j] = i+1\n\ncount = 0\nfor i in one_range:\n if i == 1:\n count += 1\n\nprint(count)\n", "# http://codeforces.com/problemset/problem/397/A\n\nimport sys\n\n\ndef main():\n n = int(sys.stdin.readline())\n intervals = []\n for _ in range(n):\n b, e = [int(x) for x in sys.stdin.readline().split()]\n intervals.append((b, e))\n\n arr = [0 for _ in range(101)]\n for i in range(intervals[0][0], intervals[0][1]):\n arr[i] = 1\n for interval in intervals[1:]:\n for i in range(interval[0], interval[1]):\n arr[i] = 2\n print(arr.count(1))\n\n\nif __name__ == '__main__':\n main()", "n = int(input())\r\nl = []\r\nh = []\r\nfor i in range(n):\r\n array = input().split()\r\n array = list(map(lambda x: int(x) if x.isdigit() else 0, array))\r\n l.append(array[0])\r\n h.append(array[1])\r\nsum = 0\r\nfor i in range(l[0],h[0]):\r\n ktra=0\r\n for j in range(1,len(l)):\r\n if(i>=l[j] and i+1<=h[j]):\r\n ktra=1\r\n if(ktra==0):\r\n sum+=1\r\nprint(sum)\r\n", "n = int(input())\nli = [0] * 100\n\nfor i in range(n):\n if i == 0:\n master = list(map(int, input().rstrip().split()))\n else:\n t = list(map(int, input().rstrip().split()))\n a = t[0]\n b = t[1]\n for x in range(a, b):\n li[x] = 1\nans = 0\nfor j in range(master[0], master[1]):\n if li[j] == 0:\n ans += 1\nprint(ans)", "\ndef do():\n n = int(input())\n x,y = map(int, input().split(\" \"))\n d = [1]*(y-x)\n for _ in range(n-1):\n a,b = map(int, input().split(\" \"))\n for i in range(max(x,a), min(y,b)):\n d[i-x] = 0\n return sum(d) if d else 0\n\n\n\n\nprint(do())\n", "# LUOGU_RID: 101541746\nc = [0] * 100\r\nfor _ in range(int(input())):\r\n for i in range(*map(int, input().split())):\r\n c[i] = int(_ == 0)\r\nprint(sum(c))\r\n", "n = int(input())\r\nl = [None]*n\r\nr = [0]*101\r\nfor i in range(n):\r\n l[i] = list(map(int, input().split()))\r\n\r\nfor i in range(l[0][0], l[0][1]):\r\n r[i] = 1\r\n\r\nfor i in range(1, n):\r\n il = l[i][0]\r\n ir = l[i][1]\r\n for j in range(il, ir):\r\n r[j] = 0\r\n\r\nprint(sum(r))\r\n\r\n\r\n", "n = int(input())\r\na = [0]*100\r\nl,r = map(int,input().split())\r\nfor i in range(n-1):\r\n x,y = map(int,input().split())\r\n for i in range(x,y): a[i] = 1\r\nans = 0\r\nfor i in range(l,r):\r\n if not a[i]: ans += 1\r\nprint(ans)", "n=int(input())\r\nl=[0]*100\r\nfor k in range(n):\r\n a,b=map(int,input().split())\r\n for i in range(a,b): l[i]=int(k==0)\r\nprint(sum(l))", "n=int(input())\r\nx,y=input().split()\r\nx,y=int(x),int(y)\r\nl=list(range(x,y))\r\ns=set(l)\r\nfor i in range(1,n):\r\n p,q=input().split()\r\n p,q=int(p),int(q)\r\n l1=list(range(p,q))\r\n s1=set(l1)\r\n s=s-s1\r\nprint(len(s))\r\n " ]
{"inputs": ["3\n0 5\n2 8\n1 6", "3\n0 10\n1 5\n7 15", "1\n0 100", "2\n1 9\n1 9", "2\n1 9\n5 10", "2\n1 9\n3 5", "2\n3 5\n1 9", "10\n43 80\n39 75\n26 71\n4 17\n11 57\n31 42\n1 62\n9 19\n27 76\n34 53", "50\n33 35\n98 99\n1 2\n4 6\n17 18\n63 66\n29 30\n35 37\n44 45\n73 75\n4 5\n39 40\n92 93\n96 97\n23 27\n49 50\n2 3\n60 61\n43 44\n69 70\n7 8\n45 46\n21 22\n85 86\n48 49\n41 43\n70 71\n10 11\n27 28\n71 72\n6 7\n15 16\n46 47\n89 91\n54 55\n19 21\n86 87\n37 38\n77 82\n84 85\n54 55\n93 94\n45 46\n37 38\n75 76\n22 23\n50 52\n38 39\n1 2\n66 67", "2\n1 5\n7 9", "2\n1 5\n3 5", "2\n1 5\n1 2", "5\n5 10\n5 10\n5 10\n5 10\n5 10", "6\n1 99\n33 94\n68 69\n3 35\n93 94\n5 98", "11\n2 98\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "10\n95 96\n19 20\n72 73\n1 2\n25 26\n48 49\n90 91\n22 23\n16 17\n16 17", "11\n1 100\n63 97\n4 33\n12 34\n34 65\n23 31\n43 54\n82 99\n15 84\n23 52\n4 50", "21\n0 100\n81 90\n11 68\n18 23\n75 78\n45 86\n37 58\n15 21\n40 98\n53 100\n10 70\n14 75\n1 92\n23 81\n13 66\n93 100\n6 34\n22 87\n27 84\n15 63\n54 91", "10\n60 66\n5 14\n1 3\n55 56\n70 87\n34 35\n16 21\n23 24\n30 31\n25 27", "40\n29 31\n22 23\n59 60\n70 71\n42 43\n13 15\n11 12\n64 65\n1 2\n62 63\n54 56\n8 9\n2 3\n53 54\n27 28\n48 49\n72 73\n17 18\n46 47\n18 19\n43 44\n39 40\n83 84\n63 64\n52 53\n33 34\n3 4\n24 25\n74 75\n0 1\n61 62\n68 69\n80 81\n5 6\n36 37\n81 82\n50 51\n66 67\n69 70\n20 21", "15\n22 31\n0 4\n31 40\n77 80\n81 83\n11 13\n59 61\n53 59\n51 53\n87 88\n14 22\n43 45\n8 10\n45 47\n68 71", "31\n0 100\n2 97\n8 94\n9 94\n14 94\n15 93\n15 90\n17 88\n19 88\n19 87\n20 86\n25 86\n30 85\n32 85\n35 82\n35 81\n36 80\n37 78\n38 74\n38 74\n39 71\n40 69\n40 68\n41 65\n43 62\n44 62\n45 61\n45 59\n46 57\n49 54\n50 52", "21\n0 97\n46 59\n64 95\n3 16\n86 95\n55 71\n51 77\n26 28\n47 88\n30 40\n26 34\n2 12\n9 10\n4 19\n35 36\n41 92\n1 16\n41 78\n56 81\n23 35\n40 68", "27\n0 97\n7 9\n6 9\n12 33\n12 26\n15 27\n10 46\n33 50\n31 47\n15 38\n12 44\n21 35\n24 37\n51 52\n65 67\n58 63\n53 60\n63 68\n57 63\n60 68\n55 58\n74 80\n70 75\n89 90\n81 85\n93 99\n93 98", "20\n23 24\n22 23\n84 86\n6 10\n40 45\n11 13\n24 27\n81 82\n53 58\n87 90\n14 15\n49 50\n70 75\n75 78\n98 100\n66 68\n18 21\n1 2\n92 93\n34 37", "11\n2 100\n34 65\n4 50\n63 97\n82 99\n43 54\n23 52\n4 33\n15 84\n23 31\n12 34", "60\n73 75\n6 7\n69 70\n15 16\n54 55\n66 67\n7 8\n39 40\n38 39\n37 38\n1 2\n46 47\n7 8\n21 22\n23 27\n15 16\n45 46\n37 38\n60 61\n4 6\n63 66\n10 11\n33 35\n43 44\n2 3\n4 6\n10 11\n93 94\n45 46\n7 8\n44 45\n41 43\n35 37\n17 18\n48 49\n89 91\n27 28\n46 47\n71 72\n1 2\n75 76\n49 50\n84 85\n17 18\n98 99\n54 55\n46 47\n19 21\n77 82\n29 30\n4 5\n70 71\n85 86\n96 97\n86 87\n92 93\n22 23\n50 52\n44 45\n63 66", "40\n47 48\n42 44\n92 94\n15 17\n20 22\n11 13\n37 39\n6 8\n39 40\n35 37\n21 22\n41 42\n77 78\n76 78\n69 71\n17 19\n18 19\n17 18\n84 85\n9 10\n11 12\n51 52\n99 100\n7 8\n97 99\n22 23\n60 62\n7 8\n67 69\n20 22\n13 14\n89 91\n15 17\n12 13\n56 57\n37 39\n29 30\n24 26\n37 38\n25 27", "10\n28 36\n18 26\n28 35\n95 100\n68 72\n41 42\n76 84\n99 100\n6 8\n58 60", "20\n69 72\n88 92\n77 80\n64 69\n66 67\n79 81\n91 96\n78 83\n81 86\n11 12\n48 53\n22 23\n81 84\n89 92\n56 60\n1 4\n1 5\n60 62\n20 23\n63 66", "71\n1 99\n11 69\n86 92\n7 49\n31 70\n42 53\n48 81\n86 96\n36 91\n19 38\n39 91\n41 64\n87 93\n83 97\n40 41\n3 32\n15 18\n58 65\n22 32\n1 71\n58 86\n64 77\n15 69\n4 34\n42 89\n9 66\n15 18\n58 65\n59 96\n39 89\n19 38\n6 63\n26 73\n29 47\n55 88\n5 78\n41 74\n48 81\n20 71\n59 96\n42 49\n4 69\n41 74\n87 93\n0 65\n2 34\n15 18\n10 56\n55 88\n33 56\n42 89\n86 92\n42 81\n65 82\n5 78\n13 52\n32 85\n7 65\n59 96\n4 65\n46 69\n10 56\n42 89\n4 69\n0 65\n32 35\n5 78\n32 75\n42 53\n55 59\n64 77", "1\n1 2"], "outputs": ["1", "3", "100", "0", "4", "6", "0", "4", "2", "4", "2", "3", "0", "3", "2", "1", "4", "1", "6", "2", "9", "5", "7", "19", "1", "3", "2", "1", "1", "3", "2", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
80
1c41a03010f966e896c90f173d265027
PLEASE
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. Then 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. After *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. Number *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 in other words, *n* is multiplication of all elements of the given array. Because 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 , where 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 109<=+<=7. Please note that we want of *p* and *q* to be 1, not of their remainders after dividing by 109<=+<=7. The first line of input contains a single integer *k* (1<=≤<=*k*<=≤<=105) — the number of elements in array Barney gave you. The second line contains *k* integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=1018) — the elements of the array. In the only line of output print a single string *x*<=/<=*y* where *x* is the remainder of dividing *p* by 109<=+<=7 and *y* is the remainder of dividing *q* by 109<=+<=7. Sample Input 1 2 3 1 1 1 Sample Output 1/2 0/1
[ "k = int(input())\n\nMOD = 10 ** 9 + 7\n\nantithree = pow(3, MOD - 2, MOD)\n\nantitwo = pow(2, MOD - 2, MOD)\n\npower = 1\n\nparity = False\n\nfor t in map(int, input().split()):\n\n power *= t\n\n power %= MOD - 1\n\n if t % 2 == 0:\n\n parity = True\n\nq = pow(2, power, MOD) * antitwo\n\nq %= MOD\n\nif parity:\n\n p = (q + 1) * antithree\n\n p %= MOD\n\nelse:\n\n p = (q - 1) * antithree\n\n p %= MOD \n\nprint(p, q, sep = '/')\n\n\n\n# Made By Mostafa_Khaled", "import sys\r\nfrom functools import reduce\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\nmod = 10 ** 9 + 7\r\nadd = lambda a, b: (a % mod + b % mod) % mod\r\nmult = lambda a, b: (a % mod * b % mod) % mod\r\ndiv = lambda a, b: mult(a, inv(b))\r\ninv = lambda a: pow(a, mod - 2, mod)\r\n\r\nn, a = int(input()), [int(x) for x in input().split()]\r\nq = div(reduce(lambda a, b: pow(a, b, mod), a, 2), 2)\r\nparity = reduce(lambda a, b: (a * b) & 1, a, 1)\r\np = div(add(q, 1), 3)\r\n\r\nif parity:\r\n p = div(add(q, -1), 3)\r\n\r\nprint(f'{p}/{q}')\r\n", "#!/usr/bin/python3\n\nclass Matrix:\n def __init__(self, n, m, arr=None):\n self.n = n\n self.m = m\n self.arr = [[0] * m for i in range(n)]\n if arr is not None:\n for i in range(n):\n for j in range(m):\n self.arr[i][j] = arr[i][j]\n\n def __mul__(self, other):\n assert self.m == other.n\n ans = Matrix(self.n, other.m)\n for i in range(self.n):\n for j in range(other.m):\n for k in range(self.m):\n ans.arr[i][j] = (ans.arr[i][j] + self.arr[i][k] * other.arr[k][j]) % (10 ** 9 + 7)\n return ans\n\n def __imul__(self, other):\n self = self * other\n return self\n\n def __pow__(self, n):\n if n == 0:\n ans = Matrix(self.n, self.n)\n for i in range(self.n):\n ans.arr[i][i] = 1\n return ans\n elif n & 1 == 1:\n return self * (self ** (n - 1))\n else:\n t = self ** (n >> 1)\n return t * t\n\n def __ipow__(self, n):\n self = self ** n\n return self\n\n def __eq__(self, other):\n if self.n != other.n or self.m != other.m:\n return False\n for i in range(self.n):\n for j in range(self.m):\n if self.arr[i][j] != other.arr[i][j]:\n return False\n return True\n\n\ndef fpow(a, n):\n if n == 0:\n return 1\n elif n & 1 == 1:\n return (a * fpow(a, n - 1)) % (10 ** 9 + 7)\n else:\n t = fpow(a, n >> 1)\n return (t * t) % (10 ** 9 + 7)\n\n\ntransform = Matrix(2, 2, [[1, 1], [0, 4]])\nmtx = transform\n\nk = int(input())\na = list(map(int, input().split()))\n\"\"\"\nf = False\nfor j in a:\n if j % 2 == 0:\n f = True\n break\nif f:\n print(a)\n tp = 1\n for j in a:\n if f and j % 2 == 0:\n j //= 2\n f = False\n print(j)\n mtx **= j\n ans = Matrix(2, 1, [[0], [1]])\n ans = mtx * ans\n print(ans.arr)\n print(\"%d/%d\" % (ans.arr[0][0], ans.arr[1][0]))\n\"\"\"\n\nx = 1\nfor j in a:\n x = (x * j) % (10 ** 9 + 6)\n\nx = (x - 1) % (10 ** 9 + 6)\n\nif x % 2 == 0:\n ans = (transform ** (x // 2)) * Matrix(2, 1, [[0], [1]])\n print(\"%d/%d\" % (ans.arr[0][0], fpow(2, x)))\nelse:\n y = (x - 1) % (10 ** 9 + 6)\n ans = (transform ** (y // 2)) * Matrix(2, 1, [[0], [1]])\n print(\"%d/%d\" % ((ans.arr[0][0] * 2 + 1) % (10 ** 9 + 7), (ans.arr[1][0] * 2) % (10 ** 9 + 7)))\n \n", "from functools import reduce\r\nMOD = 10 ** 9 + 7\r\nn, a = int(input()), map(int, input().split())\r\nn = reduce(lambda x,y:(x*y)%(MOD-1), a, 1)\r\n# 333333336 * 3 = 1\r\n# 500000004 * 2 = 1\r\nk = n % 2\r\nq = (pow(2, n, MOD) * 500000004) % MOD\r\nif k == 0:\r\n p = ((q + 1) * 333333336) % MOD\r\nelse:\r\n p = ((q - 1) * 333333336) % MOD\r\nprint(\"%d/%d\" % (p, q))", "from functools import reduce\r\nmod = 1000000007\r\nn = input()\r\nnumbers = list(map(int,input().split()))\r\nflag = 1 if len(list(filter(lambda x: x%2 == 0,numbers))) else -1\r\nb = reduce(lambda x,y:pow(x,y,mod),numbers,2)\r\nb = b*pow(2,mod-2,mod)%mod # b = 2^n-1\r\na = (b+flag)*pow(3,mod-2,mod)%mod #a = (2^n-1 -/+ 1) / 3\r\nprint(\"%d/%d\"%(a,b))\r\n\r\n", "p = int(1e9)+7\r\ninv2 = int(5e8)+4\r\ninv3 = (p+1)//3\r\n\r\ndef binpower(b,e):\r\n r = 1\r\n while e:\r\n if e&1: r = (r*b)%p\r\n e = e>>1\r\n b = (b*b)%p\r\n return r\r\n\r\ndef f(l):\r\n r = 2 #will=2^n%p\r\n odd = True\r\n for a in l:\r\n odd = odd and a%2\r\n r = binpower(r,a%(p-1)) #Fermat's Little Theorem\r\n fm = (r*inv2)%p\r\n fz = fm + (-1 if odd else 1)\r\n fz = (fz*inv3)%p\r\n return '%d/%d'%(fz,fm)\r\n\r\n_ = input()\r\nl = list(map(int,input().split()))\r\nprint(f(l))\r\n\r\n", "MOD = 10**9 + 7\r\nPHI = MOD - 1\r\n\r\ne = 1\r\nN = int(input())\r\nA = map(int, input().split())\r\nfor a in A:\r\n e = e * a % (2 * PHI)\r\nif e == 0:\r\n e += 2 * PHI\r\nnum = pow(2, e - 1, 3 * MOD)\r\nnum -= pow(-1, e - 1, 3 * MOD)\r\nnum //= 3\r\nnum %= MOD\r\nden = pow(2, e - 1, MOD)\r\nprint(f\"{num}/{den}\")" ]
{"inputs": ["1\n2", "3\n1 1 1", "1\n983155795040951739", "2\n467131402341701583 956277077729692725", "10\n217673221404542171 806579927281665969 500754531396239406 214319484250163112 328494187336342674 427465830578952934 951554014286436941 664022909283791499 653206814724654845 66704816231807388", "8\n137264686188377169 524477139880847337 939966121107073137 244138018261712937 158070587508987781 35608416591331673 378899027510195451 81986819972451999", "9\n174496219779575399 193634487267697117 972518022554199573 695317701399937273 464007855398119159 881020180696239657 296973121744507377 544232692627163469 751214074246742731", "12\n254904759290707697 475737283258450340 533306428548398547 442127134828578937 779740159015946254 272877594683860919 93000149670491971 349640818793278778 498293278222136720 551099726729989816 149940343283925029 989425634209891686", "1\n1", "1\n1000000000000000000", "1\n3", "1\n1000000006", "2\n500000004 1000000006", "1\n500000004", "2\n500000004 500000004", "1\n500000003", "2\n500000003 500000004", "2\n500000003 500000003", "1\n1000000005", "2\n1000000005 500000004"], "outputs": ["1/2", "0/1", "145599903/436799710", "63467752/190403257", "896298678/688896019", "993002178/979006521", "149736910/449210731", "674872752/24618241", "0/1", "453246046/359738130", "1/4", "500000004/500000004", "500000004/500000004", "666666672/1", "666666672/1", "833333339/500000004", "500000004/500000004", "833333339/500000004", "750000005/250000002", "416666670/250000002"]}
UNKNOWN
PYTHON3
CODEFORCES
7
1c6303b7e51d261699ad1d56d6f87efd
Seller Bob
Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally. The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Sample Input 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 3 win 5 sell 6 sell 4 Sample Output 1056 0
[ "max_x = 2001\r\nn = int(input())\r\nincome = [0]*n\r\nwin = {}\r\nfor i in range(n):\r\n s, a = input().split()\r\n a = int(a)\r\n if (i > 0):\r\n income[i] = income[i-1]\r\n if (s[0] == 'w'):\r\n win[a] = i;\r\n elif (win.get(a) != None):\r\n income[i] = max(income[i], income[win.get(a)] + 2**a)\r\nprint(income[n-1])\r\n\n# Sun Mar 22 2020 14:51:06 GMT+0300 (MSK)\n", "# Saw Answer\n\nn = int(input())\nsell = dict()\nwin = dict()\nc = []\n\nfor i in range(n):\n s, v = input().split()\n v = int(v) + 1\n c.append(v)\n if s[0] == \"s\":\n c[i] *= -1\n sell[v] = i\n else:\n if v not in win:\n win[v] = list()\n win[v].append(i)\nans = 0\nfor i in sorted(sell.keys(), reverse=True):\n if i not in win:\n continue\n while len(win[i]) and win[i][-1] > sell[i]:\n win[i].pop()\n if len(win[i]):\n if all(c[j] for j in range(win[i][-1], sell[i] + 1)):\n for j in range(win[i][-1], sell[i] + 1):\n c[j] = 0\n ans += 2 ** (i - 1)\nprint(ans)\n", "n = int(input())\r\n\r\ndp_things = [0]*n;\r\ndp_price = [0]*n;\r\n\r\nfor i in range(n):\r\n if (i > 0):\r\n dp_price[i] = dp_price[i-1];\r\n (s, num) = input().split();\r\n num = pow(2, int(num));\r\n if (s == 'win'):\r\n dp_things[i] = num;\r\n if (s == 'sell'):\r\n for j in range(i):\r\n if (dp_things[j] == num and dp_price[j] + num > dp_price[i]):\r\n dp_price[i] = dp_price[j] + num;\r\n\r\n\r\n \r\nprint (dp_price[n - 1]);\r\n\r\n\r\n\n# Sun Mar 25 2018 12:32:25 GMT+0300 (MSK)\n", "read = lambda: [int(i) for i in input().split()]\r\n\r\n\r\nn = int(input())\r\na = [0] * n\r\nfor i in range(n):\r\n\ts, x = input().split()\r\n\tx = int(x)\r\n\tif s == \"sell\":\r\n\t\ta[i] = x + 1\r\n\telse:\r\n\t\ta[i] = -x - 1\r\n\r\npos = dict()\r\nleft = [-1] * n\r\nfor i in range(n):\r\n\tif -a[i] in pos:\r\n\t\tleft[i] = pos[-a[i]]\r\n\tpos[a[i]] = i\r\n\r\ndp = [0] * n\r\nfor i in range(1, n):\r\n\tdp[i] = dp[i - 1]\r\n\tif a[i] > 0:\r\n\t\tj = left[i]\r\n\t\tif j == -1:\r\n\t\t\tcontinue\r\n\t\tdp[i] = max(dp[i], dp[j] + (1 << (a[i] - 1)))\r\n\r\nprint(dp[n - 1])\r\n", "n = int(input())\r\nl1 = []\r\nl2 = []\r\nused = [-1 for i in range(2001)]\r\nbad = [0 for i in range(n)]\r\nans = 0\r\nfor i in range(n):\r\n p = input().split()\r\n l2.append(int(p[1]))\r\n l1.append(p[0][0])\r\n if p[0][0] == 's':\r\n used[int(p[1])] = i\r\nfor i in range(2000, -1, -1):\r\n if used[i] == -1:\r\n continue\r\n cur = -1\r\n for j in range(used[i], -1, -1):\r\n if l1[j] == 'w' and l2[j] == i:\r\n cur = j\r\n break\r\n if cur != -1:\r\n ok = 1\r\n for j in range(cur, used[i]+1):\r\n if bad[j] == 1:\r\n ok = 0\r\n break\r\n if ok == 1:\r\n ans += pow(2, i)\r\n for j in range(cur, used[i]+1):\r\n bad[j] = 1\r\nprint(ans)\r\n", "n =int(input())\r\na =[0]*2018\r\nans =0\r\nfor i in range(n):\r\n s,x=input().split()\r\n if s=='win':\r\n a[int(x)] = ans +2**int(x)\r\n else:\r\n ans = max(ans , a[int(x)])\r\nprint(ans)", "import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn = int(input())\r\nquery = [input().split() for _ in range(n)]\r\ndp = [0] * (n + 1)\r\n\r\nfor i in range(n):\r\n if query[i][0] == 'win':\r\n for j in range(i + 1, n):\r\n if query[j][0] == 'sell' and query[j][1] == query[i][1]:\r\n dp[j] = max(dp[j], dp[i] + 2**int(query[i][1]))\r\n break\r\n dp[i + 1] = max(dp[i + 1], dp[i])\r\n\r\nprint(dp[-1])\r\n", "dp = [0 for i in range(2005)]\nn = input()\nn = int(n)\nans = 0\nfor i in range(n):\n inp = input().split()\n num = int(inp[1])\n if inp[0] == 'win':\n dp[num] = 2**num + ans\n else:\n ans = max(ans, dp[num])\nprint(ans)\n\n \t\t \t\t \t\t \t\t \t\t \t \t\t\t", "n = int(input()) # Number of working days\r\ntotal_earnings = 0 # Initialize total earnings\r\nmemory_stick_capacities = [0] * 2010 # Create a list to store memory stick capacities and their respective earnings\r\n\r\nfor i in range(n):\r\n option = input().split() # Read the input option (win or sell) and capacity\r\n action, capacity = option[0], int(option[1])\r\n\r\n if action == \"win\":\r\n memory_stick_capacities[capacity] = total_earnings + 2 ** capacity # If Bob wins a stick, update earnings\r\n else:\r\n total_earnings = max(total_earnings, memory_stick_capacities[capacity]) # If Bob sells a stick, update total earnings\r\n\r\nprint(total_earnings) # Output the maximum possible earnings for Bob\r\n", "n = int(input())\r\ndp = [0]*2020\r\nresp = 0\r\n\r\nfor i in range(n):\r\n s = input()\r\n cmd, _x = s.split()\r\n x = int(_x)\r\n if(cmd[0] == \"w\"):\r\n dp[x] = resp + 2**x\r\n else:\r\n resp = max(dp[x], resp)\r\n\r\nprint(resp)", "a = [-1] * 2002\r\nx = 0\r\n\r\nfor i in range(int(input())):\r\n t, v = input().split()\r\n v = int(v) + 1\r\n if t == \"win\":\r\n a[v] = x\r\n elif a[v] >= 0:\r\n x = max(x, a[v] + (1 << (v-1)))\r\n\r\nprint(x)", "dp = [-1] * 2005\r\nans = 0\r\nt = int(input())\r\nnow = 0\r\nmaxx = 0\r\nfor i in range(1, t + 1):\r\n a, b = input().split(' ')\r\n x = int(b)\r\n if a == \"win\":\r\n dp[x] = max(dp[x], maxx)\r\n for j in range(0, 2002):\r\n dp[j] = max(dp[j], dp[j])\r\n else:\r\n if dp[x] != -1:\r\n dp[2001] = max(dp[2001], dp[x] + pow(2, x))\r\n maxx = max(maxx, dp[2001])\r\n\r\nans = 0\r\nfor i in range(2005):\r\n ans = max(dp[i], ans)\r\nprint(ans)\r\n", "n = int(input())\n\nhave = [ -1 for i in range(0, 2005) ]\ndp = [ 0 for i in range(0, n+5) ]\n\ns, t = input().split()\nt = int(t)\n\nif(s == 'win'):\n have[t] = 0\n \nfor i in range(1, n):\n s, t = input().split()\n t = int(t)\n \n if(s == 'win'):\n have[t] = i\n dp[i] = dp[i-1]\n elif have[t] == -1:\n dp[i] = dp[i-1]\n else:\n dp[i] = max(dp[i-1], (1 << t) + dp[have[t]])\n \nprint(dp[n-1])\n \t \t\t\t\t \t\t \t\t\t\t \t \t \t \t\t\t", "def maxx(a, b):\r\n if a < b:\r\n return b\r\n return a\r\n\r\nn = int(input())\r\n\r\nt = []\r\nst = []\r\nfor i in range(n):\r\n g = input()\r\n if g[0] == 'w':\r\n t.append(0)\r\n else:\r\n t.append(1)\r\n \r\n s = ''\r\n ok = 0\r\n for x in g:\r\n if x == ' ':\r\n ok = 1\r\n continue\r\n if ok == 1:\r\n s = s + x\r\n \r\n st.append(int(s))\r\n \r\nb = []\r\nfor i in range(2002):\r\n b.append(-1)\r\n \r\ndp = []\r\nfor i in range(2):\r\n dp.append(b)\r\n \r\ndp[0][2001] = 0\r\nfor i in range(n):\r\n now = i % 2\r\n nxt = (i + 1) % 2\r\n for j in range(2002):\r\n if (dp[now][j] == -1):\r\n continue\r\n if t[i] == 1:\r\n if st[i] == j:\r\n dp[nxt][2001] = maxx(dp[nxt][2001], dp[now][j] + (2 ** j))\r\n else:\r\n dp[nxt][j] = maxx(dp[nxt][j], dp[now][j]); \r\n else:\r\n dp[nxt][j] = maxx(dp[nxt][j], dp[now][j])\r\n dp[nxt][st[i]] = maxx(dp[nxt][st[i]], dp[now][j])\r\n \r\nans = 0\r\nfor i in range(2002):\r\n ans = maxx(ans, dp[n % 2][i])\r\n\r\nprint(ans)\r\n \r\n \r\n \r\n ", "n = int(input())\n\ndp = [-1] * (2002)\ndp[0] = 0\n# mx = 0\nfor _ in range(n):\n cmd, x = input().split()\n x = int(x)\n if cmd == 'win':\n dp[x + 1] = dp[0] \n elif dp[x + 1] >= 0:\n dp[0] = max(dp[0], dp[x + 1] + 2 ** x)\nprint(dp[0])", "n = int(input())\r\nv = [0] * 2001\r\nprofit = int(0);\r\nfor i in range(0,n,1):\r\n s, a = map(str,input().split())\r\n a = int(a)\r\n if s == \"win\":\r\n v[a] = 2**a + profit\r\n else:\r\n profit = max(profit, v[a])\r\nprint(profit)\n# Mon Mar 25 2019 20:36:10 GMT+0300 (MSK)\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Aug 28 08:49:22 2021\r\n\r\n@author: Hermes\r\n\"\"\"\r\n\r\nn = int(input())\r\nm = [0]*2001\r\nearnings = 0\r\n\r\nfor i in range(n):\r\n e = input()\r\n if 'win' in e:\r\n x = int(e[4:])\r\n if x > 0:\r\n m[x] = earnings + (2<<x-1)\r\n else:\r\n m[x] = earnings + 1\r\n else:\r\n x = int(e[5:])\r\n earnings = max(earnings, m[x])\r\nprint(earnings)", "n = int(input())\r\nA = []\r\nB = []\r\nC = []\r\nfor i in range(n):\r\n s, t = input().split()\r\n t = int(t)\r\n if s == \"win\":\r\n A.append(t)\r\n C.append(t + 1)\r\n else:\r\n B.append(t)\r\n C.append(-t - 1)\r\n#print(A)\r\n#print(B)\r\ndp = []\r\nans = 0\r\nD = [-1] * 3000\r\nfor i in range(len(C)):\r\n dp.append(0)\r\n if C[i] < 0 and D[C[i] * (-1)] != -1:\r\n t = 0\r\n if D[C[i] * (-1)] != 0:\r\n t = dp[D[C[i] * (-1)] - 1]\r\n dp[i] = max(dp[i], t + 2 ** (C[i] * (-1) - 1))\r\n if C[i] > 0:\r\n D[C[i]] = i\r\n if i != 0:\r\n dp[i] = max(dp[i], dp[i - 1])\r\n ans = max(ans, dp[i])\r\nprint(ans)\n# Sat Mar 24 2018 13:22:05 GMT+0300 (MSK)\n", "n = int(input())\r\ndp = [0]*(n+1)\r\npos = [-1]*2001\r\n\r\nfor i in range(0,n): \r\n [s,x] = input().split(' ')\r\n x = int(x) \r\n dp[i+1] = dp[i]\r\n if(s == \"win\"): pos[x] = i\r\n elif pos[x] != -1:\r\n dp[i+1] = max(dp[i+1],dp[pos[x]] + 2 ** x)\r\nprint(dp[n])\r\n", "import sys\r\nfrom sys import stdin, stdout, stderr\r\nfrom pprint import pprint\r\n\r\n\r\n\r\ndef main():\r\n\tn = int(stdin.readline().strip())\r\n\tN = 2005\r\n\td = [-1] * N\r\n\tzero = N-1\r\n\td[zero] = 0\r\n\tfor i in range(n):\r\n\t\toption, value = list(input().split())\r\n\t\tvalue = int(value)\r\n\t\tif option[0] == 'w':\r\n\t\t\td[value] = max(d[value], d[zero])\r\n\t\telse:\r\n\t\t\tif d[value] != -1:\r\n\t\t\t\td[zero] = max(d[zero], d[value] + 2 ** value)\r\n\r\n\tprint(d[zero])\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "'''\n Python3(PyPy3) Template for Programming-Contest.\n'''\n\nfrom collections import defaultdict\nimport sys\n\n\n\ndef input():\n return sys.stdin.readline().rstrip()\n\n\nDXY = [(0, -1), (1, 0), (0, 1), (-1, 0)] # LDRU\nmod = 998244353\ninf = 1 << 64\nmaxn = 2010\n\n#buy = 1,sell = 0\n\n\ndef slv():\n n = int(input())\n\n A, B = [0]*(n), [0]*(n)\n when = [[-1]*(2010) for i in range(2)]\n used = [False]*(n)\n\n mp = defaultdict(list)\n for i in range(n):\n type, x = input().split()\n x = int(x)\n if type == \"win\":\n A[i], B[i] = 0, x\n mp[x].append(i)\n else:\n A[i], B[i] = 1, x\n when[1][x] = i\n\n for x in range(2010):\n if when[1][x] >= 0:\n while mp[x] and mp[x][-1] > when[1][x]:\n mp[x].pop()\n if mp[x]:\n when[0][x] = mp[x][-1]\n\n ans = 0\n for x in reversed(range(2010)):\n if 0 <= when[0][x] < when[1][x] and all(not used[i] for i in range(when[0][x], when[1][x] + 1)):\n ans += (1 << x)\n for j in range(when[0][x], when[1][x] + 1):\n used[j] = True\n\n print(ans)\n return\n\n\ndef main():\n testcase = 1\n #testcase = int(input())\n for _ in range(testcase):\n slv()\n return 0\n\n\nif __name__ == \"__main__\":\n main()\n", "s=int(input())\r\na={}\r\nsum=[]\r\nls=-1\r\nfor i in range(s):\r\n sum.append(0)\r\nfor i in range(s):\r\n n, z = map(str, input().split())\r\n m=int(z)\r\n if(n==\"win\"):\r\n a[m]=(1,i)\r\n if (n==\"sell\"):\r\n p = a.get(m, -1)\r\n if(p!=-1):\r\n if(sum[i-1]<2**m+sum[a[m][1]]):\r\n sum[i]=2**m+sum[a[m][1]]\r\n ls=i\r\n else:\r\n if(a[m][1]>ls):\r\n sum[i]=2**m+sum[i-1]\r\n ls=i\r\n if(sum[i]==0):\r\n sum[i]=sum[i-1]\r\nprint(sum[s-1])\r\n\n# Sun Mar 24 2019 13:38:31 GMT+0300 (MSK)\n", "n = int(input())\r\na = []\r\nb = []\r\ndp = [0]*(n+1)\r\nindices = {}\r\nfor _ in range(n):\r\n c,d = input().split()\r\n d = int(d)\r\n a.append(c)\r\n b.append(d)\r\nfor i in range(1,n+1):\r\n dp[i] = dp[i-1]\r\n if a[i-1] == 'sell' and b[i-1] in indices:\r\n dp[i] = max(dp[i],(1 << b[i-1])+dp[indices[b[i-1]]])\r\n if a[i-1] == 'win':\r\n indices[b[i-1]] = i-1\r\nprint(dp[-1])", "#!/usr/bin/python3\r\n\r\n\r\nN = int(input())\r\nmaxval = 0\r\ndp = [0]*N\r\nprev = [-1]*2010\r\nfor i in range(N):\r\n\tl = input().strip().split()\r\n\tl[1] = int(l[1])\r\n\tif l[0] == \"win\": prev[l[1]] = i\r\n\telif l[0] == \"sell\" and prev[l[1]] != -1: maxval = max(maxval,2**l[1]+dp[prev[l[1]]])\r\n\tdp[i] = maxval\r\n\r\nprint(maxval)", "d = [0]*2001\r\nn = int(input())\r\nans = 0\r\nfor i in range(0,n,1):\r\n s, x = map(str,input().split())\r\n x = int(x)\r\n if s==\"win\":\r\n d[x] = 2**x+ans\r\n if s==\"sell\":\r\n ans = max(ans,d[x])\r\nprint(ans) \r\n \r\n ", "n = int(input())\r\nd = [0 for i in range(5555)]\r\nans = 0\r\nfor i in range(n):\r\n s=input().split()\r\n x=int(s[1])\r\n if s[0] == \"win\":\r\n d[x] = ans+2**x\r\n else:\r\n ans=max(d[x],ans)\r\nprint(ans)\r\n\r\n", "n = int(input())\ndp = [0]*2001\nsum = 0\nfor i in range(n):\n s, x = map(str, input().split())\n x = int(x)\n if s == 'win':\n dp[x] = 2 ** x + sum\n if s == 'sell':\n sum = max(dp[x], sum)\nprint(sum)\n# Mon Mar 25 2019 19:31:09 GMT+0300 (MSK)\n", "import sys,math,string,bisect\ninput=sys.stdin.readline\nfrom collections import deque,defaultdict\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : map(int,input().split())\nI=lambda :int(input())\nn=int(input())\nx=[0]*2001\nhigh=0\nfor i in range(n):\n l,m=input().split()\n m=int(m)\n if(l==\"win\"):\n x[m]=high+2**m\n else:\n high=max(high,x[m])\n \nprint(high)\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\npow2 = [1]\r\nfor _ in range(2005):\r\n pow2.append(2 * pow2[-1])\r\nans = 0\r\ndp = [-pow2[2002]] * 2005\r\nfor _ in range(n):\r\n s, x = input().rstrip().split()\r\n x = int(x)\r\n if s == \"win\":\r\n dp[x] = ans\r\n else:\r\n ans = max(ans, dp[x] + pow2[x])\r\nprint(ans)", "n = int(input())\r\ndp = [0] * (n + 2)\r\nmp = {}\r\n\r\nfor i in range(n):\r\n s = input().split()\r\n x = int(s[1])\r\n if s[0] == 'win':\r\n mp[x] = i\r\n else:\r\n if x in mp:\r\n dp[i] = max(dp[i], dp[mp[x]] + 2**x)\r\n\r\n dp[i+1] = dp[i]\r\n\r\nprint(dp[n])\r\n\r\n", "n = int(input())\r\nd = [0 for i in range(2009)]\r\nans = 0\r\nfor i in range(n): \r\n s = input().split()\r\n x = int(s[1])\r\n if s[0] == 'win':\r\n d[x] = ans+ 2**x\r\n else:\r\n ans = max(d[x], ans)\r\nprint(ans)", "n = int(input())\nst = []\nval = []\nfor i in range(n):\n a, b = map(str, input().split())\n st.append(a)\n val.append(int(b))\n\ndp = [0] * n\nmx = [0] * n\nfor i in range(1, n):\n idx = -1\n if st[i] == \"sell\":\n for j in range(i):\n if st[j] == \"win\" and val[j] == val[i]:\n idx = j\n if idx != -1:\n dp[i] = max(dp[i-1], mx[idx] + (1 << val[idx]))\n else:\n dp[i] = dp[i-1]\n else:\n dp[i] = dp[i-1]\n mx[i] = max(dp[i], mx[i-1])\nprint(dp[n-1])\n ", "n = int(input())\r\na = [0] * (n + 1)\r\nb = [0] * (n + 1)\r\nfor i in range(1,n + 1):\r\n\top, x = input().split(\" \")\r\n\tif op == \"win\":\r\n\t\tb[i] = 0\r\n\telse:\r\n\t\tb[i] = 1\r\n\ta[i] = int(x)\r\nmx = [0] * (n + 1)\r\npos = [0] * (2002)\r\nans = [0] * (n + 1)\r\nfor i in range(1, n + 1):\r\n\tif b[i] == 0:\r\n\t\tpos[a[i]] = i\r\n\telif pos[a[i]] != 0:\r\n\t\tans[i] = mx[pos[a[i]]] + (1<<a[i])\r\n\tmx[i] = max(ans[i], mx[i - 1])\r\n\r\nprint(mx[n])", "n=int(input())\r\nar=[0]*(n+1)\r\nc=[]\r\nd=[]\r\nfor i in range(n):\r\n a,b=input().split()\r\n b=int(b)\r\n e=1\r\n if(a==\"sell\"):\r\n e=-e\r\n b=-b\r\n c.append(b)\r\n d.append(e)\r\nfor i in range(1,n+1):\r\n ar[i]=max(ar[i-1],ar[i])\r\n for j in range(i+1,n+1):\r\n if(c[i-1]+c[j-1]==0 and d[i-1]==1 and d[j-1]==-1):\r\n ar[j]=max(ar[j],ar[i]+2**c[i-1])\r\nprint(ar[n])\r\n", "N = int(input()) \r\nwinsell = (N)*[0] \r\npow = (2001)*[-1] \r\nans = 0 \r\nfor i in range(0,N): \r\n s, x = input().split() \r\n x = int(x) \r\n if s == \"win\": \r\n winsell[i] = x \r\n else: \r\n pow[x] = i; \r\n winsell[i] = -x \r\nfor i in range(2000,-1,-1): \r\n if pow[i] > 0: \r\n b = 0 \r\n for j in range(pow[i] - 1,-1,-1): \r\n if winsell[j] != 2001: \r\n if winsell[j] == i: \r\n b = 1 \r\n ans+=2**i \r\n for k in range(j,pow[i]+1): \r\n winsell[k]=2001 \r\n else: \r\n b = 1 \r\n if b == 1: \r\n break \r\nprint(ans)\n# Sun Mar 24 2019 15:56:18 GMT+0300 (MSK)\n", "n = int(input())\r\ndp=[0]*(n+1)\r\narr=[0]*(n+1)\r\ndp[0]=0\r\nmx=0\r\npw=[0]*3000\r\nfor i in range(1,n + 1):\r\n s,a=input().split()\r\n a=int(a)\r\n if (s==\"sell\"):\r\n w=2**a\r\n dp[i]=mx\r\n if(pw[a]!=0):\r\n ind = pw[a]\r\n dp[i]=max(dp[i],dp[ind]+w)\r\n \r\n else:\r\n pw[a]=i\r\n dp[i]=mx\r\n mx=max(mx,dp[i])\r\nprint(dp[n])\r\n\n# Sun Mar 22 2020 11:31:19 GMT+0300 (MSK)\n", "#!/usr/bin/python3\r\n\r\ndef binpow(a, b):\r\n if b == 0:\r\n return 1\r\n if b & 1 == 0:\r\n return binpow(a, b >> 1) ** 2\r\n return binpow(a, b - 1) * a\r\n\r\nn = int(input())\r\narr = []\r\nfor i in range(n):\r\n s = input().split()\r\n arr.append((s[0] == 'sell', int(s[1])))\r\n\r\ndp = [0 for i in range(n)]\r\ndp[n - 1] = 0\r\nd = dict()\r\n\r\nif arr[n - 1][0] == True:\r\n d[arr[n - 1][1]] = n - 1\r\n\r\nfor i in range(n - 2, -1, -1):\r\n dp[i] = dp[i + 1]\r\n if arr[i][0] == True:\r\n d[arr[i][1]] = i\r\n continue\r\n if not arr[i][1] in d.keys():\r\n continue\r\n pos = d[arr[i][1]]\r\n dp[i] = max(dp[i], binpow(2, arr[i][1]) + dp[pos])\r\n\r\nprint(dp[0])\r\n", "from queue import PriorityQueue\n\npq = PriorityQueue()\nn = int(input())\n\nlista = [[\"\", 0]]*n\npode = [True]*n\ncont = 0\n\nfor i in range(n):\n lista[i] = input().split()\n lista[i][1] = int(lista[i][1])\n if lista[i][0] == \"sell\":\n pq.put((-lista[i][1], i))\n cont += 1\n # l[1] = int(l[1])\nsaco = n-1\n\nans = 0\nfor i in range(cont):\n el = pq.get()\n # print(el)\n idx = el[1]\n while idx >= 0 and pode[idx]:\n\n if lista[idx][1] == -el[0] and lista[idx][0] == 'win':\n for j in range(el[1], idx-1, -1):\n pode[j] = False\n ans += (1 << -el[0])\n break\n\n idx -= 1\nprint(ans)\n\n \t \t \t\t\t\t \t \t\t \t\t\t\t \t \t", "R= lambda: map(int,input().split())\r\nn,=R()\r\nans=0\r\nl= [0 for _ in range(2002)]\r\nfor i in range(n):\r\n s=input().split()\r\n b=int(s[1])\r\n if s[0]=='win':\r\n l[b]=ans+2**b\r\n else:\r\n ans=max(ans,l[b])\r\nprint(ans)\r\n ", "n=int(input())\r\nstrs = [\"\" for x in range(n+1)]\r\ndp=[0]*(n+1)\r\nfor i in range (1,n+1):\r\n\tstrs[i]=input()\r\nfor i in range(1,n+1):\r\n\tst=strs[i].split()\r\n\tdp[i]=max(dp[i],dp[i-1])\r\n\tif st[0]=='win':\r\n\t\tfor j in range(i+1,n+1):\r\n\t\t\ts=strs[j].split()\r\n\t\t\tif s[0]=='sell' and st[1]==s[1]:\r\n\t\t\t\tdp[j]=max(dp[i-1]+2**int(st[1]),dp[j])\r\n\t\t\t\tbreak\r\nprint(dp[n])\r\n\t\t\r\n\r\n", "import sys\r\nreadline = sys.stdin.readline\r\n\r\nN = int(readline())\r\n\r\nDP = [0] * (N+1)\r\nMAX = 2100\r\nlast_t = [0] * MAX\r\n\r\nfor i in range(1, N + 1):\r\n DP[i] = DP[i-1]\r\n a, b = readline().split()\r\n b = int(b)\r\n if(a == \"win\"):\r\n DP[i] = DP[i-1]\r\n last_t[b] = i\r\n else:\r\n if last_t[b] == 0:\r\n continue\r\n DP[i] = max(DP[i], DP[last_t[b]] + (1 << b))\r\n\r\nprint(DP[-1])\r\n", "n =int(input())\r\na =[0]*2023\r\n\r\nans = 0\r\nfor i in range(n):\r\n t, pri = input().split()\r\n pri = int(pri)\r\n if t == \"win\":\r\n a[pri] = ans + 2**pri\r\n else:\r\n ans = max(ans, a[pri])\r\nprint(ans)", "n = int(input())\r\n\r\ndp = [0]*2001\r\nans = 0\r\n\r\nfor i in range(n):\r\n s = input().split()\r\n move = s[0]\r\n d = int(s[1])\r\n if move == \"win\":\r\n dp[d] = ans + 2**d\r\n else:\r\n ans = max(ans, dp[d])\r\nprint(ans)\n# Thu Mar 26 2020 09:12:32 GMT+0300 (MSK)\n", "n=int(input())\r\ndp=[0]*2010\r\nviv=0\r\nfor i in range(n):\r\n st=input().split()\r\n c=int(st[1])\r\n if st[0]=='win':\r\n dp[c]=viv+2**c\r\n else:\r\n viv=max(dp[c],viv)\r\nprint(viv)", "n = int(input())\nN = 2002\nzero = N - 1\nd = [-1] * N\nd[zero] = 0\n\nfor i in range(n):\n\toption, value = list(input().split())\n\tvalue = int(value)\n\tif option[0] == 'w':\n\t\td[value] = max(d[value], d[zero])\n\telse:\n\t\tif d[value] != -1:\n\t\t\td[zero] = max(d[zero], d[value] + 2 ** value)\n\t#print (value, d[zero], d[:11])\nprint (d[zero])\n", "n = int(input())\r\ndp = [0] * (n + 1)\r\nlast = [-1] * 2001\r\nlast_s = -1\r\nfor i in range(1, n + 1):\r\n s, temp = list(input().split())\r\n x = int(temp)\r\n dp[i] = dp[i - 1]\r\n if s == 'win':\r\n last[x] = i\r\n elif last[x] != -1:\r\n if last[x] > last_s:\r\n dp[i] += 2 ** x\r\n last_s = i\r\n else:\r\n if dp[last[x] - 1] + 2 ** x > dp[i]:\r\n dp[i] = dp[last[x] - 1] + 2 ** x\r\n last_s = i\r\n #print(dp[i])\r\nprint(dp[n])\n# Sun Mar 25 2018 12:11:46 GMT+0300 (MSK)\n", "read = lambda: [int(i) for i in input().split()]\r\n\r\n\r\nn = int(input())\r\na = [0] * n\r\nfor i in range(n):\r\n\ts, x = input().split()\r\n\tx = int(x)\r\n\tif s == \"sell\":\r\n\t\ta[i] = x + 1\r\n\telse:\r\n\t\ta[i] = -x - 1\r\n\r\ndp = [0] * n\r\nfor i in range(1, n):\r\n\tdp[i] = dp[i - 1]\r\n\tif a[i] > 0:\r\n\t\tfor j in range(0, i):\r\n\t\t\tif (a[j] == -a[i]):\r\n\t\t\t\tdp[i] = max(dp[i], dp[j] + (1 << (a[i] - 1)))\r\n\r\nprint(dp[n - 1])\r\n", "def intercept(x, y, a, b):\r\n\treturn not (y < a or x > b)\r\n\r\n\r\nn = int(input())\r\n\r\nday = []\r\nintervalo = []\r\nvalor = []\r\n\r\nfor i in range(n):\r\n\tline = input()\r\n\tline = line.split(' ')\r\n\tact = line[0]\r\n\tval = int(line[1])\r\n\tday.append(val)\r\n\tif (act == 'win'):\r\n\t\tcontinue\r\n\tfor j in range(i):\r\n\t\tif (day[j] == val):\r\n\t\t\tintervalo.append([j, i])\r\n\t\t\tvalor.append([val, len(intervalo)-1])\r\n\r\nvalor.sort()\r\n\r\nans = 0\r\n\r\nused = list(range(len(intervalo)+1))\r\n\r\nfor i in range(len(used)):\r\n\tused[i] = False\r\n\r\nfor i in range(len(valor)-1, -1, -1):\r\n\tind = valor[i][1]\r\n\tx1 = intervalo[ind][0]\r\n\ty1 = intervalo[ind][1]\r\n\tpos = True\r\n\tfor j in range(0, len(intervalo)):\r\n\t\tif (j == ind):\r\n\t\t\tcontinue\r\n\t\tif (used[j] and intercept(x1, y1, intervalo[j][0], intervalo[j][1])):\r\n\t\t\tpos = False\r\n\tif (pos):\r\n\t\tans += 2**valor[i][0]\r\n\t\tused[ind] = True\r\n\r\nprint(ans)", "n = int(input())\r\na = []\r\nb = []\r\nfor i in range(n): \r\n x = input().split()\r\n a.append(x[0][0])\r\n b.append(int(x[1]))\r\nres = 0\r\nf = [-1]*2002\r\nfor i in range(n):\r\n if (a[i]=='w'):\r\n f[b[i]] = res\r\n elif f[b[i]]>=0:\r\n res = max(res, f[b[i]]+2**b[i])\r\n \r\nprint(res)\r\n", "# LUOGU_RID: 90275995\nn=int(input())\r\nres=0\r\nf=[0]*2010\r\nfor i in range(n):\r\n opt=input().split()\r\n s,c=opt[0],int(opt[1])\r\n if s==\"win\":\r\n f[c]=res+2**c\r\n else:\r\n res=max(res,f[c])\r\nprint(res)", "n = int(input())\r\ntotal_earnings = 0\r\nmemory_stick_capacities = [0] * 2010\r\n\r\nfor i in range(n):\r\n option = input().split()\r\n action, capacity = option[0], int(option[1])\r\n\r\n if action == \"win\":\r\n memory_stick_capacities[capacity] = total_earnings + 2 ** capacity\r\n else:\r\n total_earnings = max(total_earnings, memory_stick_capacities[capacity])\r\n\r\nprint(total_earnings)# 1698072648.6443193", "n = int(input())\r\nsellday = [-1]*2022\r\nwin = [-1]*n\r\nfor i in range(n):\r\n\ta = input().split(' ')\r\n\tif a[0] == 'sell':\r\n\t\tsellday[int(a[1])] = i\r\n\telse:\r\n\t\twin[i] = int(a[1])\r\nans = 0\r\nfor i in range(2021,-1,-1):\r\n\tif sellday[i] != -1:\r\n\t\tl = sellday[i]\r\n\t\twhile l>=0 and win[l] != i:\r\n\t\t\tif win[l] == -2:\r\n\t\t\t\tbreak\r\n\t\t\tl -= 1\r\n\t\tif l>=0 and win[l] == i:\r\n\t\t\tans += 2**i\r\n\t\t\tfor i in range(l,sellday[i]+1):\r\n\t\t\t\twin[i] = -2\r\nprint(ans)", "import math\r\nn = int(input())\r\nwin = [0] * (n + 1)\r\nsell = [0] * (n + 1)\r\nfor i in range (0 , n):\r\n s, t = input().split()\r\n t = int(t)\r\n if(s == \"win\"):\r\n win[i] = t\r\n sell[i] = -1\r\n else:\r\n sell[i] = t\r\n win[i] = -1\r\nans = 0\r\nmaxans = 0\r\ndp = [-1] * 3000\r\nfor i in range(0, n):\r\n if(win[i] != -1):\r\n dp[win[i]] = maxans\r\n else:\r\n if(dp[sell[i]] != -1):\r\n maxans = max(maxans, dp[sell[i]] + 2**(sell[i]))\r\nfor i in range(0, 2500) :\r\n maxans = max(maxans, dp[i])\r\nprint(maxans)\r\n\r\n\n# Sun Mar 22 2020 13:19:40 GMT+0300 (MSK)\n", "n = int(input())\r\ndp = [0 for _ in range(n+1)]\r\npre = [0 for _ in range(2001)]\r\nfor i in range(1,n+1):\r\n s = input().split()\r\n dp[i] = dp[i-1]\r\n t = int(s[1])\r\n if s[0][0] == 'w':\r\n pre[t] = i\r\n else:\r\n if pre[t]:\r\n ans = dp[pre[t]] + (1<<t)\r\n if ans > dp[i]:\r\n dp[i] = ans\r\nprint (dp[n])", "a = [-1] * 2002\r\na[0] = 0\r\nfor i in range(int(input())):\r\n s, t= input().split()\r\n t = int(t) + 1\r\n #t = int(input())\r\n if(s[0] == 'w'):\r\n a[t] = a[0]\r\n elif a[t] >= 0:\r\n a[0] = max(a[0], a[t] + (1<<(t-1)))\r\nprint(a[0])\r\n", "n = int(input())\r\ns = [\"\" for _ in range(5005)]\r\na = [0 for _ in range(5005)]\r\nfor i in range(1,n+1):\r\n\tta,tb = input().split();\r\n\ts[i] = ta\r\n\ta[i] = int(tb)\r\njp = [0 for _ in range(5005)]\r\nvis = [0 for _ in range(5005)]\r\ndp = [0 for _ in range(5005)]\r\n\r\nnum = [(1<<_) for _ in range(2001)]\r\n\r\nfor i in range(1,n+1):\r\n\tif(s[i][0]=='w'):\r\n\t\tvis[a[i]] = i\r\n\telse:\r\n\t\tif(vis[a[i]]):\r\n\t\t\tjp[i] = vis[a[i]];\r\nfor i in range(1,n+1):\r\n\tif(s[i][0] == 's'):\r\n\t\tif(jp[i]>0):\r\n\t\t\tdp[i] = max(dp[i], dp[jp[i]-1] + num[a[i]]);\r\n\tdp[i] = max(dp[i-1], dp[i]);\r\n\r\nprint(dp[n])\t\t\t", "n = int(input())\r\ndp = [0] * (n+1)\r\n\r\nlast = [-1] * 2001\r\nfor i in range(0,n) :\r\n [s, x] = input().split(' ')\r\n x = int(x)\r\n dp[i + 1] = dp[i]\r\n if s == 'win' :\r\n last[x] = i\r\n elif last[x] != -1 :\r\n dp[i + 1] = max(dp[i + 1], dp[last[x]] + 2 ** x)\r\nprint(dp[n]);", "import math\n\ndef solve():\n n = int(input())\n ans = 0\n idx = [0]*2005\n dp = [0]*5005\n for i in range(1,n+1):\n opt, x = input().split()\n x = int(x)\n dp[i] = dp[i-1]\n if opt == \"win\":\n idx[x] = i\n else :\n if idx[x] != 0:\n dp[i] = max(dp[i], dp[idx[x]-1] + 2**x)\n print(dp[n])\n\nif __name__ == '__main__':\n solve()\n\t\t\t\t\t \t \t\t \t\t \t \t \t \t \t", "# from random import *\r\n# print(len(str(2 ** 2000)))\r\n\r\nn = int(input())\r\n\r\ndp = [0] * (n + 1)\r\n\r\nlast = [-1] * 2001\r\n\r\n\r\nfor i in range(1, n + 1):\r\n v = input().split()\r\n x = int(v[1])\r\n if v[0][0] == 'w':\r\n last[x] = i\r\n dp[i] = dp[i - 1]\r\n else:\r\n if last[x] == -1:\r\n dp[i] = dp[i - 1]\r\n continue\r\n dp[i] = max(dp[i - 1], dp[last[x]] + 2 ** x)\r\nprint(dp[n])\r\n\r\n# n = randint(2, 6)\r\n# v = [randint(1, 20) for i in range(n)]\r\n# f = open(\"sample.txt\", \"w\")\r\n# f2 = open(\"answer.txt\", \"w\")\r\n# f.write(str(n) + \"\\n\")\r\n# for i in v:\r\n# f.write(str(i) + \" \")\r\n# ans = []\r\n# for mask in range(1, (1 << n)):\r\n# i = 0\r\n# s = 0\r\n# while (1 << i) <= mask:\r\n# if (1 << i) & mask:\r\n# s += v[i]\r\n# i += 1\r\n# ans.append(s)\r\n# ans.sort()\r\n# v.sort()\r\n# print(v)\r\n# print(ans)\r\n# print(ans[(1 << (n - 1)) - 1])\r\n# f2.write(str(ans[(1 << (n - 1)) - 1]))\r\n# print((1 << 30))\r\n# print((1 << 24) * 24 )\r\n", "n = int(input())\r\ndp = [0]*2001\r\nans = 0\r\nfor i in range(n):\r\n s, x = input().split()\r\n x = int(x)\r\n if(s == 'sell'):\r\n ans = max(ans, dp[x])\r\n else:\r\n dp[x]=ans + 2**x\r\n \r\nprint(ans)\r\n# Sun Mar 24 2019 14:17:02 GMT+0300 (MSK)\r\n", "if __name__ == '__main__':\n n = int(input())\n data = [input().split() for _ in range(n)]\n data = [(event, int(x)) for event, x in data]\n\n max_earn = [0] * n\n sell_position = {}\n if data[-1][0] == 'sell':\n sell_position[data[-1][1]] = n - 1\n for i in range(n - 2, -1, -1):\n if data[i][0] == 'sell':\n sell_position[data[i][1]] = i\n max_earn[i] = max_earn[i + 1]\n else:\n if data[i][1] in sell_position:\n max_earn[i] = max(max_earn[i + 1], 2 ** data[i][1] + max_earn[sell_position[data[i][1]]]) \n else:\n max_earn[i] = max_earn[i + 1]\n\n print(max_earn[0])\n \n", "'''\r\nBeezMinh\r\n16:43 UTC+7\r\n16/08/2023\r\n'''\r\nfrom sys import stdin\r\ninput = lambda: stdin.readline().rstrip()\r\na = [0] * 2048\r\nans = 0\r\nfor i in range(int(input())):\r\n s, x = input().split()\r\n if s == 'win':\r\n a[int(x)] = ans + 2 ** int(x)\r\n else:\r\n ans = max(ans, a[int(x)])\r\nprint(ans)", "n = int(input())\r\nd = [0 for i in range(n + 1)]\r\nlast = [-1 for i in range(2001)]\r\nfor i in range(n):\r\n s, x = input().split()\r\n x = int(x)\r\n d[i + 1] = d[i]\r\n if s == 'win':\r\n last[x] = i\r\n elif last[x] != -1:\r\n d[i + 1] = max(d[i + 1], d[last[x]] + (1 << x))\r\nprint(d[n])", "n = int(input())\r\na = [0]*5000\r\nans = 0\r\nfor i in range(n):\r\n s,x = input().split()\r\n if s=='win':\r\n a[int(x)] = ans + 2**int(x)\r\n else:\r\n ans = max(ans , a[int(x)])\r\nprint(ans)", "n = int(input())\r\n\r\ndp = [0 for i in range(5000)]\r\n\r\nans = 0\r\n\r\nfor i in range(n):\r\n c = input().split()\r\n s = c[0]\r\n x = int(c[1])\r\n\r\n if s == \"win\":\r\n dp[x] = ans + 2**x\r\n else:\r\n ans = max(ans, dp[x])\r\n\r\nprint(ans)\n# Sun Mar 24 2019 15:04:02 GMT+0300 (MSK)\n" ]
{"inputs": ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4", "60\nwin 30\nsell 30\nwin 29\nsell 29\nwin 28\nsell 28\nwin 27\nsell 27\nwin 26\nsell 26\nwin 25\nsell 25\nwin 24\nsell 24\nwin 23\nsell 23\nwin 22\nsell 22\nwin 21\nsell 21\nwin 20\nsell 20\nwin 19\nsell 19\nwin 18\nsell 18\nwin 17\nsell 17\nwin 16\nsell 16\nwin 15\nsell 15\nwin 14\nsell 14\nwin 13\nsell 13\nwin 12\nsell 12\nwin 11\nsell 11\nwin 10\nsell 10\nwin 9\nsell 9\nwin 8\nsell 8\nwin 7\nsell 7\nwin 6\nsell 6\nwin 5\nsell 5\nwin 4\nsell 4\nwin 3\nsell 3\nwin 2\nsell 2\nwin 1\nsell 1", "10\nsell 179\nwin 1278\nsell 1278\nwin 179\nwin 788\nsell 788\nwin 1819\nwin 1278\nsell 1454\nsell 1819", "10\nsell 573\nwin 1304\nsell 278\nwin 1631\nsell 1225\nsell 1631\nsell 177\nwin 1631\nwin 177\nsell 1304", "10\nwin 1257\nwin 1934\nsell 1934\nsell 1257\nwin 1934\nwin 1257\nsell 495\nwin 495\nwin 495\nwin 1257", "10\nsell 1898\nsell 173\nsell 1635\nsell 29\nsell 881\nsell 434\nsell 1236\nsell 14\nwin 29\nsell 1165", "50\nwin 1591\nwin 312\nwin 1591\nwin 1277\nwin 1732\nwin 1277\nwin 312\nwin 1591\nwin 210\nwin 1591\nwin 210\nsell 1732\nwin 312\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 210\nwin 1732\nwin 1732\nwin 1591\nwin 1732\nwin 312\nwin 1732\nsell 1277\nwin 1732\nwin 210\nwin 1277\nwin 1277\nwin 312\nwin 1732\nsell 312\nsell 1591\nwin 312\nsell 210\nwin 1732\nwin 312\nwin 210\nwin 1591\nwin 1591\nwin 1732\nwin 210\nwin 1591\nwin 312\nwin 1277\nwin 1591\nwin 210\nwin 1277\nwin 1732\nwin 312", "50\nwin 596\nwin 1799\nwin 1462\nsell 460\nwin 731\nwin 723\nwin 731\nwin 329\nwin 838\nsell 728\nwin 728\nwin 460\nwin 723\nwin 1462\nwin 1462\nwin 460\nwin 329\nwin 1462\nwin 460\nwin 460\nwin 723\nwin 731\nwin 723\nwin 596\nwin 731\nwin 596\nwin 329\nwin 728\nwin 715\nwin 329\nwin 1799\nwin 715\nwin 723\nwin 728\nwin 1462\nwin 596\nwin 728\nsell 1462\nsell 731\nsell 723\nsell 596\nsell 1799\nwin 715\nsell 329\nsell 715\nwin 731\nwin 596\nwin 596\nwin 1799\nsell 838", "50\nwin 879\nwin 1153\nwin 1469\nwin 157\nwin 827\nwin 679\nsell 1229\nwin 454\nsell 879\nsell 1222\nwin 924\nwin 827\nsell 1366\nwin 879\nsell 754\nwin 1153\nwin 679\nwin 1185\nsell 1469\nsell 454\nsell 679\nsell 1153\nwin 1469\nwin 827\nwin 1469\nwin 1024\nwin 1222\nsell 157\nsell 1185\nsell 827\nwin 1469\nsell 1569\nwin 754\nsell 1024\nwin 924\nwin 924\nsell 1876\nsell 479\nsell 435\nwin 754\nwin 174\nsell 174\nsell 147\nsell 924\nwin 1469\nwin 1876\nwin 1229\nwin 1469\nwin 1222\nwin 157", "50\nsell 1549\nwin 1168\nsell 1120\nwin 741\nsell 633\nwin 274\nsell 1936\nwin 1168\nsell 614\nwin 33\nsell 1778\nwin 127\nsell 1168\nwin 33\nwin 633\nsell 1474\nwin 518\nwin 1685\nsell 1796\nsell 741\nsell 485\nwin 747\nsell 588\nsell 1048\nwin 1580\nwin 60\nsell 1685\nsell 1580\nsell 1535\nwin 485\nsell 31\nsell 747\nsell 1473\nsell 518\nwin 633\nsell 1313\nwin 1580\nsell 1560\nsell 127\nsell 274\nwin 123\nwin 31\nsell 123\nsell 33\nwin 1778\nsell 1834\nsell 60\nsell 1751\nsell 1287\nwin 1549", "1\nsell 2000", "1\nwin 2000", "2\nwin 2000\nsell 2000"], "outputs": ["1056", "0", "2147483646", "3745951177859672748085876072016755224158263650470541376602416977749506433342393741012551962469399005106980957564747771946546075632634156222832360666586993197712597743102870994304893421406288896658113922358079050393796282759740479830789771109056742931607432542704338811780614109483471170758503563410473205320757445249359340913055427891395101189449739249593088482768598397566812797391842205760535689034164783939977837838115215972505331175064745799973957898910533590618104893265678599370512439216359131269814745054...", "95482312335125227379668481690754940528280513838693267460502082967052005332103697568042408703168913727303170456338425853153094403747135188778307041838920404959089576368946137708987138986696495077466398994298434148881715073638178666201165545650953479735059082316661443204882826188032944866093372620219104327689636641547141835841165681118172603993695103043804276669836594061369229043451067647935298287687852302215923887110435577776767805943668204998410716005202198549540411238299513630278811648", "1556007242642049292787218246793379348327505438878680952714050868520307364441227819009733220897932984584977593931988662671459594674963394056587723382487766303981362587048873128400436836690128983570130687310221668877557121158055843621982630476422478413285775826498536883275291967793661985813155062733063913176306327509625594121241472451054995889483447103432414676059872469910105149496451402271546454282618581884282152530090816240540173251729211604658704990425330422792556824836640431985211146197816770068601144273...", "0", "2420764210856015331214801822295882718446835865177072936070024961324113887299407742968459201784200628346247573017634417460105466317641563795817074771860850712020768123310899251645626280515264270127874292153603360689565451372953171008749749476807656127914801962353129980445541683621172887240439496869443980760905844921588668701053404581445092887732985786593080332302468009347364906506742888063949158794894756704243685813947581549214136427388148927087858952333440295415050590550479915766637705353193400817849524933...", "3572417428836510418020130226151232933195365572424451233484665849446779664366143933308174097508811001879673917355296871134325099594720989439804421106898301313126179907518635998806895566124222305730664245219198882158809677890894851351153171006242601699481340338225456896495739360268670655803862712132671163869311331357956008411198419420320449558787147867731519734760711196755523479867536729489438488681378976579126837971468043235641314636566999618274861697304906262004280314028540891222536060126170572182168995779...", "16332912310228701097717316802721870128775022868221080314403305773060286348016616983179506327297989866534783694332203603069900790667846028602603898749788769867206327097934433881603593880774778104853105937620753202513845830781396468839434689035327911539335925798473899153215505268301939672678983012311225261177070282290958328569587449928340374890197297462448526671963786572758011646874155763250281850311510811863346015732742889066278088442118144", "1720056425011773151265118871077591733216276990085092619030835675616738576936900493041118761959770055340668032173576279597675976622004777210845027112875371906527379337573212312341811682481516081119925150514042583039122963732518350292624889782510925425243478590699982487521431988980734651291693696303059520879874887472437061826782122289965998009474317347011699360401227487786089319043200666474560882786695043543699741809763479940250459103751744852630592882730442346682844070898735881280272505893611419620868096", "0", "0", "1148130695274254524232833201177681984022317702088695200477642736825766261392370313856659486316506269918445964638987462773447118960863055331425931356166653185391299891453122800006887791482400448714289269900634862447816154636463883639473170260404663539709049965581623988089446296056233116495361642219703326813441689089844585056023794848079140589009347765004290027167066258305220081322362812917612678833172065989953964181270217798584040421598531832515408894339020919205549577835896720391600819572166305827553804255..."]}
UNKNOWN
PYTHON3
CODEFORCES
65
1c9df2f477b8d47d31cf463f5a731156
Joty and Chocolate
Little Joty has got a task to do. She has a line of *n* tiles indexed from 1 to *n*. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by *a* and an unpainted tile should be painted Blue if it's index is divisible by *b*. So the tile with the number divisible by *a* and *b* can be either painted Red or Blue. After her painting is done, she will get *p* chocolates for each tile that is painted Red and *q* chocolates for each tile that is painted Blue. Note that she can paint tiles in any order she wants. Given the required information, find the maximum number of chocolates Joty can get. The only line contains five integers *n*, *a*, *b*, *p* and *q* (1<=≤<=*n*,<=*a*,<=*b*,<=*p*,<=*q*<=≤<=109). Print the only integer *s* — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Sample Input 5 2 3 12 15 20 2 3 3 5 Sample Output 39 51
[ "from sys import stdin, stdout\ndef read():\n\treturn stdin.readline().rstrip()\n\ndef read_int():\n\treturn int(read())\n\ndef read_ints():\n\treturn list(map(int, read().split()))\n\ndef gcd(x,y):\n\twhile y>0:\n\t\tx,y=y,x%y\n\treturn x\n\ndef solve():\n\tn,a,b,p,q=read_ints()\n\tprint((n//a)*p + (n//b)*q - (n//(a*b//gcd(a,b)))*min(p,q))\n\nsolve()\n", "import math\r\nn,a,b,p,q = [int(x) for x in input().split()]\r\nmula = n//a\r\nmulb = n//b\r\ng = math.gcd(a,b)\r\nlcm = (a*b)//g\r\nmulab = n//lcm\r\nmula -= mulab\r\nmulb -= mulab\r\nans = 0\r\nans += p*mula\r\nans += q*mulb\r\nif p > q:\r\n ans += mulab*p\r\nelse:\r\n ans += mulab*q\r\nprint(ans)\r\n", "from math import gcd\r\n\r\n\r\ndef lcm(a, b):\r\n return a // gcd(a, b) * b\r\n\r\n\r\nn, a, b, p, q = [int(i) for i in input().split()]\r\ns3 = n // lcm(a, b)\r\ns1 = n // a - s3\r\ns2 = n // b - s3\r\ns = s1 * p + s2 * q + max(p, q) * s3\r\nprint(s)", "n, a, b, p, q = map(int, input().split())\r\nr, t = a, b\r\n\r\nwhile a != 0 and b != 0:\r\n if a > b:\r\n a = a % b\r\n else:\r\n b = b % a\r\n\r\nnod = a + b\r\nnok = r * t // nod\r\n\r\nprint((n // nok * max(p, q)) + (((n // r) - (n // nok)) * p) + (((n // t) - (n // nok)) * q))\r\n", "from math import lcm\r\nn,a,b,p,q=[int(e) for e in input().split()]\r\nprint(max(p*(n//a)+q*(n//b-n//lcm(a,b)),q*(n//b)+p*(n//a-n//lcm(a,b))))", "from math import floor, ceil, gcd\r\nn, a, b, p, q = map(int, input().split())\r\npc = floor(n / a)\r\nqc = floor(n / b)\r\nl = (a * b) // gcd(a, b)\r\nbc = floor(n / l)\r\npc -= bc\r\nqc -= bc\r\nans = p * pc + q * qc + (p * bc) * (p >= q) + (q * bc) * (q > p)\r\nprint(ans)", "from math import gcd\r\n\r\nn,a,b,p,q = map(int,input().split())\r\nlcm = a * b // gcd(a,b);\r\nans = n // lcm * max(p,q)\r\nans += (n // a - n // lcm) * p\r\nans += (n // b - n // lcm) * q\r\nprint(ans)", "from math import gcd\r\ndef lcm(a,b):\r\n return a*b//(gcd(a,b))\r\nn,a,b,p,q=map(int,input().strip().split())\r\nst1,st2=n//a,n//b\r\nst3=n//lcm(a,b)\r\nmn=min(p,q)\r\nmx=max(p,q)\r\nres=(st1*p)+(st2*q)-(st3*mn)\r\nprint(res)\r\n", "import math\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\ndef lcm(a, b):\r\n return a * b // math.gcd(a, b)\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nans = n // a * p + n // b * q - n // lcm(a, b) * min(p, q)\r\nprint(ans)", "def gcd(a, b):\r\n if a<b:\r\n return gcd(b, a)\r\n if b==0:\r\n return a\r\n return gcd(b, a%b)\r\n \r\ndef lcm(a, b):\r\n return (a*b)//gcd(a,b)\r\n \r\nn, a, b, p, q = map(int, input().split())\r\nsum = 0\r\nsum+=(n//a-n//lcm(a,b))*p\r\nsum+=(n//b-n//lcm(a,b))*q\r\nsum+=max(p,q)*(n//lcm(a,b))\r\nprint(sum)", "def gcd(a,b):\r\n if a%b==0:\r\n return b\r\n return gcd(b,a%b)\r\n\r\nn,a,b,p,q = map(int,input().split())\r\nx = a*b//gcd(a,b)\r\na1,b1,x1 = n//a,n//b,n//x\r\nif p>=q:\r\n b1-=x1\r\nelse:\r\n a1-=x1\r\nprint(a1*p+b1*q)\r\n", "n, a, b, p, q = map(int, input().split())\nfrom math import gcd\nprint((n // a) * p + (n // b) * q - (n // (a * b // gcd(a, b))) * min(p, q))\n", "import math\r\n\r\n\r\ndef nok(a, b):\r\n return a * b // math.gcd(a, b)\r\n\r\n\r\nn, a, b, p, q = [int(i) for i in input().split()]\r\nans = p * (n // a) + q * (n // b)\r\nminus_k = n // nok(a, b)\r\nif p > q:\r\n ans -= q * minus_k\r\nelse:\r\n ans -= p * minus_k\r\nprint(ans)\r\n", "from math import gcd\r\nn,a,b,p,q=map(int,input().split())\r\nx=min(p,q)\r\nl=a*b//gcd(a,b)\r\nprint((n//a)*p+(n//b)*q-(n//l)*x)", "from math import gcd\r\nn,a,b,p,q=map(int,input().split())\r\nprint((n//a)*p+(n//b)*q-(n//(a*b//gcd(a,b)))*(min(p,q)))", "import sys\n\ndef gcd(a,b):\n if b==0: return a\n return gcd(b, a%b)\n\ndef lcm(a,b):\n return (a*b)//gcd(a,b)\n\nn, a, b, p, q = map(int, input().split())\n\nAs = n//a\nBs = n//b\nif a==b:\n print(As*max(p,q))\n sys.exit()\n\ncommon = lcm(a,b)\ncom = n//common\n\nif p>q:\n Bs = Bs - com\n print(As*p + Bs*q)\nelse:\n As = As - com\n print(As*p + Bs*q)\n", "\r\nn,a,b,p,q=map(int,input().split())\r\ndef evklid(a, b): \r\n if a % b == 0:\r\n return b\r\n else:\r\n return evklid(b, a%b)\r\n \r\n\r\n\r\nnsk = a * b // evklid(a, b) \r\nw=n//a\r\nw1=n//b\r\nw2=n//nsk\r\nprint(w*p+w1*q-w2*min(p,q))\r\n", "from math import gcd\r\n\r\nn, a, b, p, q = map(int, input().split())\r\ng = n // (a * b // gcd(a, b))\r\nprint((n // a - g) * p + (n // b - g) * q + g * max(p, q))\r\n", "n, a, b, p, q = map(int, input().split())\nfrom math import gcd\nlcm = (a*b)//gcd(a, b)\n\nn1 = n//a\nn2 = n//b\nn3 = n//lcm\n\nif p >= q:\n print(p*n1+q*n2-q*n3)\n\nelse:\n print(p*n1+q*n2-p*n3)", "def gcd(m,n):\r\n if m< n:\r\n m, n = n, m\r\n if(m%n) == 0:\r\n return n\r\n else:\r\n return (gcd(n, m % n)) \r\n \r\nn, a, b, p, q= map(int, input().split())\r\nprint((n//a)*p + q*(n//b) - (n//(a*b//gcd(a,b)))*min(p,q))", "from math import gcd\r\nn,a,b,p,q=map(int,input().split())\r\nlcm=a*b//gcd(a,b)\r\nr=n//a-n//lcm\r\nb=n//b-n//lcm\r\nans=r*p+b*q+(n//lcm)*max(p,q)\r\nprint(ans)", "from math import floor, ceil, gcd\r\nn, a, b, p, q = map(int, input().split())\r\npc = n // a\r\nqc = n // b\r\nl = (a * b) // gcd(a, b)\r\nbc = n // l\r\npc -= bc\r\nqc -= bc\r\nans = p * pc + q * qc + max(p, q) * bc\r\nprint(ans)", "n,a,b,p,q=map(int,input().split())\r\ndef gcd(x, y):\r\n while y != 0:\r\n (x, y) = (y, x % y)\r\n return x\r\nlcm=a*b//gcd(a,b)\r\nans=(n//a)*p + (n//b)*q - (n//lcm)*min(p,q)\r\nprint(ans)\r\n \r\n ", "from math import gcd\r\nn,a,b,p,q=map(int,input().split())\r\nprint(n//a*p+n//b*q-n//(a*b//gcd(a,b))*min(p,q))", "from math import gcd as g\r\n\r\ndef lmc(a, b):\r\n return a // g(a, b)*b\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nans = 0\r\n\r\nans += (n//a)*p\r\nans += (n//b)*q\r\nans -= (n//lmc(a, b))*min(p, q)\r\n\r\nprint(ans)\r\n\r\n\"\"\"\r\ntr = False if p > q else True\r\n\r\nfor i in range(1, n+1):\r\n if not(tr):\r\n if i % a == 0:\r\n ans += p\r\n elif i % b == 0:\r\n ans += q\r\n else:\r\n if i % b == 0:\r\n ans += q\r\n elif i % a == 0:\r\n ans += p\r\nprint(ans)\r\n\"\"\"\r\n", "n,a,b,p,q=map(int,input().split())\r\nif p>=q:\r\n st=a\r\nelse:\r\n st=b \r\ndef gcd(a,b):\r\n if b==0: return a \r\n return gcd(b,a%b)\r\ndef lcm(a,b):\r\n return a*b//gcd(a,b)\r\nboth=lcm(a,b)\r\ndiva=n//a \r\ndivb=n//b \r\ndivboth=n//both \r\n#print(diva,divb,divboth)\r\ntot = (diva-divboth)*p+(divb-divboth)*q+divboth*max(p,q)\r\nprint(tot)\r\n'''\r\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \r\n 3 5 3 5 3 5 3 3 3 5 3 5 3 '''", "from math import floor, ceil, gcd\r\nn, a, b, p, q = map(int, input().split())\r\npc = floor(n / a) - ceil(1 / a) + 1\r\nqc = floor(n / b) - ceil(1 / b) + 1\r\nl = (a * b) // gcd(a, b)\r\nbc = floor(n / l) - ceil(1 / l) + 1\r\npc -= bc\r\nqc -= bc\r\nans = p * pc + q * qc\r\nif (p >= q):\r\n ans += (p * bc)\r\nelse:\r\n ans += (q * bc)\r\nprint(ans)", "from math import gcd\r\n\r\n\r\ndef main():\r\n n, a, b, p, q = map(int, input().split())\r\n g = gcd(a, b)\r\n lcm = a * b // g\r\n fa = n // a\r\n fb = n // b\r\n fab = n // lcm\r\n print((fa - fab) * p + (fb - fab) * q + fab * max(p, q))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\ndef lcm(a, b):\n return (a * b) // gcd(a, b)\n\nn, a, b, p, q = map(int, input().split())\na_cnt = n // a\nb_cnt = n // b\nab_cnt = n // lcm(a, b)\nif p > q:\n b_cnt -= ab_cnt\nelse:\n a_cnt -= ab_cnt\nans = p * a_cnt + q * b_cnt\nprint(ans)\n", "n,a,b,p,q=map(int,input().split())\r\nimport math\r\nx=(a*b)//math.gcd(a,b)\r\nif(p>q):\r\n print((n//a)*p+(n//b)*q-(n//x)*q)\r\nelse:\r\n print((n//a)*p+(n//b)*q-(n//x)*p)\r\n \r\n", "import sys\r\nfrom math import *\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nlcm = a * b / gcd(a, b)\r\nx = p * (int(n/a) - int(n/lcm)) + q * int(n/b)\r\ny = p * int(n/a) + q * (int(n/b) - int(n/lcm))\r\nprint(max(x,y))", "from math import*\r\nn,a,b,p,q=map(int,input().split())\r\ng=a*b//gcd(a,b)\r\nc1,c2,c3=(n//g)*max(p,q),(n//a-n//g)*p,(n//b-n//g)*q\r\nprint(c1+c2+c3)", "from math import gcd\r\ndef lcm(x,y):\r\n return x*y//gcd(x,y)\r\nn,a,b,p,q=map(int,input().split())\r\ncnt_a=n//a\r\ncnt_b=n//b\r\ncnt_ab=n//lcm(a,b)\r\nif p>=q:\r\n cnt_b-=cnt_ab\r\nelse:\r\n cnt_a-=cnt_ab\r\nprint(cnt_a*p+cnt_b*q)", "from math import *\r\nn,a,b,p,q=map(int,input().split())\r\nx=(n//a)*p\r\ny=(n//b)*q\r\nl=(a*b)//gcd(a,b)\r\nz=(n//l)\r\ns=x+y-(min(p,q)*z)\r\nprint(s)\r\n", "def lcm(a, b):\r\n if b == 0:\r\n return a\r\n return lcm(b, a % b)\r\n\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nx = n // a\r\ny = n // b\r\nz = n // (a * b // lcm(a, b))\r\ns = x * p + y * q - z * min(p, q)\r\nprint(s)\r\n", "from math import gcd\r\n\r\nn, a, b, p, q = map(int, input().split())\r\n\r\n# print(n, a, b, p, q)\r\nx = n // a * p\r\ny = n // b * q\r\nz = (n // (a * b // gcd(a, b))) * min(p, q)\r\n\r\nprint(x + y - z)", "import math\r\ns = str(input()).split()\r\nn = int(s[0])\r\na = int(s[1])\r\nb = int(s[2])\r\np = int(s[3])\r\nq = int(s[4])\r\nans = 0 \r\nmini = min(p, q)\r\nans = (n//a)*p\r\nans += (n//b)*q\r\ncommon = a*b//math.gcd(a, b)\r\nans -= (n//common)*mini\r\nprint(ans)\r\n \r\n", "'''\r\nName : Jaymeet Mehta\r\ncodeforces id :mj_13\r\nProblem : joty and chocolates\r\n'''\r\nfrom sys import stdin,stdout\r\nimport math\r\nn,a,b,p,q = map(int,stdin.readline().split())\r\nans=0\r\nlcm=(a*b)//math.gcd(a,b)\r\nans=p*(n//a)+q*(n//b)-p*(n//lcm)-q*(n//lcm)+max(p,q)*(n//lcm)\r\nprint(ans)", "from math import gcd\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nd = n // (a * b // gcd(a, b))\r\nprint( (n // a - d) * p + (n // b - d) * q + d * max(p, q) )", "import math\r\nfrom functools import reduce\r\ndef lcm_base(x, y):\r\n return (x * y) // math.gcd(x, y)\r\n\r\ndef lcm_list(numbers):\r\n return reduce(lcm_base, numbers, 1)\r\n\r\nn,a,b,p,q = map(int, input().split())\r\nl = lcm_base(a, b)\r\nans = p*(n//a-n//l)+q*(n//b-n//l)+max(p, q)*(n//l)\r\nprint(ans)\r\n", "import math\r\nn,a,b,p,q=map(int, input().split())\r\nprint((n//a)*p+(n//b)*q-(n//((a*b)// math.gcd(a,b)))*min(p,q))", "def gcd(a,b):\r\n if a<b:a,b=b,a\r\n while a%b!=0:\r\n a,b=b,a%b\r\n return b\r\n \r\nn,a,b,p,q=map(int,input().split())\r\n \r\n \r\nboth = n//((a*b)//gcd(a,b))\r\nonly_a = n//a - both\r\nonly_b = n//b - both\r\n \r\nres = only_a*p + only_b*q + both*max(p,q)\r\n \r\nprint(res)", "n,a,b,p,q = map(int,input().split())\r\n\r\ndef gcd(a,b):\r\n if a == 0:\r\n return b\r\n return gcd(b % a, a)\r\n\r\ndef lcm(a,b):\r\n return int((a / gcd(a,b))* b)\r\n\r\n\r\nprint((p*((n//a)-(n//lcm(a,b))))+(q*((n//b)-(n//lcm(a,b))))+(max(p,q)*(n//lcm(a,b))))", "from math import gcd\r\nn, a, b, p, q=map(int, input().split())\r\nif a!=b:\r\n if q>p: print((n//b)*q+(n//a)*p-p*(n//(a*b//gcd(a, b))))\r\n else: print((n//a)*p+(n//b)*q-q*(n//(a*b//gcd(a, b))))\r\nelse:\r\n if q>p: print((n//b)*q)\r\n else: print((n//a)*p)\r\n", "import math as mtx\nn,a,b,p,q = map(int , input().split())\nmx = max(p, q)\ntemp = n // ((a*b)//mtx.gcd(a,b))\nsum= (n//b)*q + (n//a)*p - (temp * min(p,q))\nprint(sum)\n\n \t\t\t\t \t\t\t\t \t\t \t\t \t\t\t \t \t", "'''Codeforces Problem 678C'''\r\nfrom time import process_time\r\nfrom sys import argv\r\n\r\nfrom math import gcd\r\ndef lcm(a, b):\r\n '''LCM of a and b'''\r\n return a * b // gcd(a, b)\r\ndef solve():\r\n '''Solve the problem'''\r\n n, a, b, p, q = map(int, input().split())\r\n print(n // a * p + n // b * q - n // lcm(a, b) * min(p, q))\r\n\r\nif len(argv) > 1:\r\n startTime = process_time()\r\n solve()\r\n print('Elapsed Time:', process_time() - startTime)\r\nelse:\r\n solve()\r\n", "# cook your dish here\r\nimport math\r\nn, a,b ,p, q = map(int,input().split())\r\n\r\nlcm = (a//math.gcd(a,b))*b\r\n\r\nans = (n//a - n//lcm)*p + (n//b - n//lcm)*q + (n//lcm)*max(p,q)\r\n\r\nprint(ans)", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nimport math\r\n\r\nN,a,b,p,q = map(int, input().split())\r\n\r\nc = a*b//math.gcd(a,b)\r\na1,b1,c1 = N//a,N//b,N//c\r\n\r\nans = 1\r\nif p>q:\r\n ans = a1*p+(b1-c1)*q\r\nelse:\r\n ans = (a1-c1)*p+b1*q\r\nprint(ans)\r\n", "import math\r\nn,a,b,p,q=map(int,input().split())\r\n\r\nc=math.gcd(a,b)\r\nd=(a*b)//c\r\nans=(n//a)*p+(n//b)*q-(n//d)*min(p,q)\r\nprint(ans)", "import math\r\nn,a,b,p,q=map(int,input().split())\r\nans=0\r\nlcm=(a*b)//math.gcd(a,b)\r\nprint((n//a)*p +(n//b)*q -(n//lcm)*min(p,q))", "import math\nn,a,b,p,q = map(int,input().split())\nx = n//a\ny = n//b\nz = n//((a*b)//math.gcd(a,b))\nans = (x-z)*p + (y-z)*q + z*max(p,q)\nprint(ans)\n", "n, a, b, p, q = map(int, input().split(\" \"))\r\n\r\ndef gcd(a, b): \r\n if (b == 0):\r\n return a\r\n return gcd(b, a % b)\r\n\r\ndef lcm(a, b): \r\n v = gcd(a, b)\r\n return a * b // v\r\n\r\nif p > q:\r\n v1 = n // a\r\n v2 = n // b\r\n v3 = n // lcm(a, b)\r\n print(v1 * p + (v2 - v3) * q)\r\nelse:\r\n v1 = n // b\r\n v2 = n // a\r\n v3 = n // lcm(a, b)\r\n print(v1 * q + (v2 - v3) * p)\r\n\r\n", "import fractions\nn, a, b, p, q = map(int, input().split())\nlca = a * b // fractions.gcd(a, b)\nk = p * (n // a) + q * (n // b) - (p + q - max(p, q)) * (n //lca)\nprint(k)\n", "def mmc(a,b): #mmc(a,b)*mdc(a,b)=a*b\n n1=a\n n2=b\n\n r = None\n while r != 0:\n r = n1%n2\n n1= n2\n n2 = r\n\n return (a*b)//n1\n\n\nn,a,b,p,q=map(int, input().split())\n\nresult = (n//a)*p\nresult += (n//b)*q\n\nresult -= (n//mmc(a,b))*min(p,q)\n\nprint(result)\n", "n,a,b,p,q = map(int, input().strip().split())\ndef gcd(x, y):\n if y==0:\n return x\n return gcd(y, x%y)\ndef lcm(x, y):\n return (x*y)//gcd(x,y)\ncomm = lcm(a, b)\nans = (n//a - n//comm)*p\nans += (n//b - n//comm)*q\nans += (n//comm)*max(p, q)\nprint(ans)", "import math\r\nn,a,b,p,q=map(int,input().split())\r\ncnt=n//a*p+n//b*q\r\nl=n//math.lcm(a,b)\r\nif p>q:\r\n cnt-=l*q\r\nelse:\r\n cnt-=l*p\r\nprint(cnt)", "from fractions import gcd\r\nn,a,b,p,q=map(int,input().split())\r\nmax=max(p,q)\r\nt=n//((a*b)//gcd(a,b))\r\nsum=(n//a)*p +(n//b)*q -(t*min(p,q))\r\nprint(sum)\r\n\r\n", "import math\r\nn,a,b,p,q=map(int,input().split())\r\nR=n//a\r\nB=n//b \r\nRB=n//((a*b)//math.gcd(a,b))\r\nprint((R-RB)*p+(B-RB)*q+max(p,q)*RB)", "n, a, b, p, q = [int(i) for i in input().split()]\r\n\r\n\r\ndef gcd(a, b):\r\n while a != 0 and b != 0:\r\n if a > b:\r\n a %= b\r\n else:\r\n b %= a\r\n\r\n return a + b\r\n\r\n\r\ndef lcm(a, b):\r\n return a // gcd(a, b) * b\r\n\r\nprint(p * (n // a) + q * (n // b) - (min(p, q) * (n // lcm(a, b))))", "from fractions import gcd\n\nX = [int(x) for x in input().split()]\nn = X[0]\na = X[1]\nb = X[2]\np = X[3]\nq = X[4]\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nres = (n//a*p) + (n//b*q) - min(p,q)*(n//lcm(a,b))\n\nprint(res)\n", "# cook your dish here\r\nfrom collections import deque, defaultdict\r\nfrom math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd\r\nimport bisect\r\nimport sys\r\nimport copy\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef input(): return sys.stdin.readline().strip()\r\n\r\ndef lcm(a,b):\r\n return (a*b)//gcd(a,b)\r\nn,a,b,p,q=get_ints()\r\na1=n//a\r\na2=n//b\r\na3=n//(lcm(a,b))\r\nif p>=q:\r\n a2-=a3\r\n ##print((p*a1)+(q*a2))\r\nelse:\r\n a1-=a3\r\nprint((p*a1)+(q*a2))", "#!/usr/bin/python\r\nimport math, sys\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\ndef lcm(a, b):\r\n return a * b // math.gcd(a, b)\r\n\r\nn, a, b, p, q = [int(x) for x in input().split()]\r\nnum_div_a = n // a\r\nnum_div_b = n // b\r\nnum_div_ab = n // (lcm(a, b))\r\nprint((num_div_a - num_div_ab) * p + (num_div_b - num_div_ab) * q + num_div_ab * max(p, q))\r\n", "def compute():\n\n def gcd(a,b):\n return a if b==0 else gcd(b,a%b)\n\n def lcm(a,b):\n return a*(b//gcd(a,b))\n\n n, a, b, p, q = map(int,input().split())\n return (n//a)*p + (n//b)*q - (n//(lcm(a,b)))*min(p,q)\n\nif __name__==\"__main__\":\n print(compute())\n", "from math import gcd\ndef lcm(a,b):\n return a*b//(gcd(a,b))\nn,a,b,p,q=map(int,input().strip().split())\nst1,st2=n//a,n//b\nst3=n//lcm(a,b)\nmn=min(p,q)\nmx=max(p,q)\nres=(st1*p)+(st2*q)-(st3*mn)\nprint(res)\n\n \t\t \t\t\t\t\t \t \t \t \t \t\t\t", "from math import gcd\r\n\r\ndef lcm(u, v):\r\n return u*v//gcd(u, v)\r\n\r\nn, a, b, p, q=[int(k) for k in input().split()]\r\nx, y, z=n//a, n//b, n//lcm(a, b)\r\nprint(p*(x-z)+q*(y-z)+max(p, q)*z)", "from math import gcd\r\nn,a,b,p,q = map(int,input().split())\r\nloh = ((n // a) * p + (n // b) * q) - min(p,q) * (n // (a * b // gcd(a,b)))\r\nprint(loh)", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Sat Jul 11 00:31:59 2020\n\n@author: shailesh\n\"\"\"\n\nimport math\n\nn,a,b,p,q = [int(i) for i in input().split()]\n\n\nn_red = n//a\n\nn_blue = n//b\n\nlcm = (a*b)//math.gcd(a,b)\n\nn_lcm = n//lcm\n\nif p > q:\n n_blue -= n_lcm\nelse:\n n_red -= n_lcm\n\n\nprint(n_red*p + n_blue*q)", "from math import gcd\nlcm=lambda x,y:x*y//gcd(x,y)\nn,a,b,p,q=map(int,input().split())\nprint(p*(n//a)+q*(n//b)-min(p,q)*(n//lcm(a,b)))", "var=input(\"\")\r\nvar=var.split(\" \")\r\nn,a,b,p,q=int(var[0]),int(var[1]),int(var[2]),int(var[3]),int(var[4])\r\nimport math \r\ndef pgcd(m,n): \r\n while m%n: \r\n r=m%n \r\n m=n \r\n n=r \r\n return n \r\n \r\ndef ppcm(m,n): \r\n return m*n//pgcd(m,n)\r\nif p>q:\r\n x,y=a,b\r\n mx,mn=p,q\r\nelse:\r\n x,y=b,a\r\n mx,mn=q,p\r\ns=0\r\nj=int(n/x)\r\ns+=mx*j\r\nk=int(n/y)\r\nl=int(n/ppcm(a,b))\r\ns+=mn*(k-l)\r\nprint(s)\r\n", "import math \r\n\r\nn,a,b,p,q = list(map(int, input().strip().split()))\r\n\r\ng = a*b // math.gcd(a,b)\r\n\r\nc = (n // a) * p + (n // b) * q - (n // g) * min(p,q)\r\nprint(c)", "def nok(a,b):\r\n n = a * b\r\n while a != b:\r\n if a > b:\r\n a -= b\r\n elif b > a:\r\n b -= a\r\n\r\n return n // a\r\n\r\n\r\nn, a, b, p, q = list(map(int,input().split()))\r\nnok1 = nok(a,b)\r\nk = ((n // a) * p + (n // b) * q - (n // nok1) * (p + q)) + (n // nok1) * max(p,q)\r\n\r\nprint(k)\r\n\r\n", "from fractions import gcd\n\nn, a, b, p, q = map(int, input().split())\nd = lambda n, i, x : x * (n // i)\nlcm = (a * b) // gcd(a, b)\nprint(d(n, a, p) + d(n, b, q) - d(n, lcm, min(p, q)))\n", "import math\r\nn,a,b,p,q = map(int,input().split())\r\nif p > q:\r\n a,b = b,a\r\n p,q = q,p\r\n\r\n# if b%a != 0 and a%b != 0:\r\nna = n // a\r\nnb = n // b\r\nif a%b != 0 and b%a != 0:\r\n nab = n // ((a * b)//math.gcd(a,b))\r\n na -= nab\r\n nb -= nab\r\n ans = na * p\r\n ans += ((nb + nab) * q)\r\n print(ans)\r\n\r\nelse:\r\n if a%b == 0:\r\n print(nb*q)\r\n\r\n else:\r\n na -= nb\r\n ans = nb*q\r\n ans += (na*p)\r\n print(ans)\r\n\r\n", "i = input().split(\" \");\ni = [int(a) for a in i]\n\ndef gcd(a,b):\n\treturn a if b == 0 else gcd(b, a%b)\n\nprint (i[0]//i[1] * i[3] + (i[0]//i[2]) * i[4] - i[0]//(i[1]*i[2]//gcd(i[1], i[2])) * min(i[3], i[4]))\n", "[n,a,b,p,q]=list(map(int,input().split()))\r\ndef gcd(a,b):\r\n a,b=max(a,b),min(a,b)\r\n if a%b==0:\r\n return b\r\n return gcd(b,a%b) \r\nlcm=(a*b)//gcd(a,b)\r\nx,y,z=n//a,n//b,n//lcm\r\nprint((x-z)*p+(y-z)*q+z*max(p,q))", "import sys\nimport math\n#from queue import *\n#import random\n#sys.setrecursionlimit(int(1e6))\ninput = sys.stdin.readline\n \n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inara():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\ndef invr():\n return(map(int,input().split()))\n################################################################\n############ ---- THE ACTUAL CODE STARTS BELOW ---- ############\n\ndef lcm(a,b):\n\treturn a*b//math.gcd(a,b)\n\t\nn,a,b,p,q=invr()\n\nlal=n//a\nnil=n//b\njekono=n//lcm(a,b)\n\nif p>q:\n\tnil-=jekono\nelse:\n\tlal-=jekono\n\nans=lal*p+nil*q\nprint(ans)\n\n\t \t \t \t\t\t\t \t\t \t \t \t\t \t\t\t\t", "import math\r\n\r\ndef solve(r,w,p,a,b):\r\n tmp=w*p//math.gcd(w,p)\r\n c=r//tmp\r\n d=r//w-c\r\n e=r//p-c\r\n #print(str(c) + \" \" + str(d) + \" \" + str(e))\r\n ans=d*a+e*b+c*max(a,b)\r\n return ans\r\n\r\nr,w,p,a,b=map(int,input().split())\r\nprint(solve(r,w,p,a,b))\r\n", "import math\r\n\r\nn, a, b, p, q = list(map(int,input().split()))\r\nx = math.gcd(a,b)\r\nans = 0\r\nif p==q:\r\n if a>b:\r\n ans = p*(n//a)+q*((n//b)-n//b//(a//x))\r\n else:\r\n ans = q*(n//b)+p*((n//a)-n//a//(b//x))\r\nif p>q:\r\n ans = p*(n//a)+q*((n//b)-n//b//(a//x))\r\nelse:\r\n ans = q*(n//b)+p*((n//a)-n//a//(b//x))\r\nprint(ans)", "def gys(a,b):\n if ( b > a ):\n t = a\n a = b\n b = t\n d = a % b\n while ( d != 0 ):\n a = b\n b = d\n d = a % b\n return b\ndef gbs(a,b):\n return int(a * b / gys(a,b))\n\nn,a,b,p,q = input().split()\nn = int(n)\na = int(a)\nb = int(b)\np = int(p)\nq = int(q)\ns = 0\ns = s + int(n / a) * p\ns = s + int(n / b) * q\ns = s - int(n / gbs(a,b)) * p\ns = s - int(n / gbs(a,b)) * q\ns = s + int(n / gbs(a,b)) * max(p,q)\nprint(s)\n\n\n \t\t\t\t\t\t\t \t \t \t\t\t \t\t \t\t \t\t", "import math\r\ndef lcm(a, b):\r\n return abs(a*b) // math.gcd(a, b)\r\nn,a,b,p,q=map(int,input().split())\r\nprint(p*(n//a)+q*(n//b)-min(p,q)*(n//lcm(a,b))) ", "n,a,b,p,q = map(int,input().split())\r\nAA = n // a\r\nBB = n // b\r\nQQ = 0\r\nimport math\r\ndef LCM(a,b):\r\n return a*b//math.gcd(a,b)\r\nQQ = n//LCM(a,b)\r\nAA -= QQ\r\nBB -= QQ\r\nprint(AA*p + BB*q + max(QQ*p,QQ*q))", "def lcm(a, b):\r\n m = a * b\r\n while a != 0 and b != 0:\r\n if a > b:\r\n a %= b\r\n else:\r\n b %= a\r\n return m // (a + b)\r\n\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nred, blue = n//a, n//b\r\nred_blue = n//lcm(a, b)\r\nif p >= q:\r\n blue -= red_blue\r\nelse:\r\n red -= red_blue\r\nprint(red*p + blue*q)", "from fractions import gcd\r\nn,a,b,p,q=map(int,input().split())\r\nx=n//(a*b//gcd(a,b))\r\nprint((n//a-x)*p+(n//b-x)*q+x*max(p, q))", "\r\n\r\n\r\nn,a,b,p,q = map(int,input().split())\r\n\r\n\r\n# numbers less or equal than n which are divisible by a\r\naa = (n//a)*p\r\n\r\nbb = (n//b)*q\r\n\r\nfrom math import gcd\r\n\r\ncommon = (a*b)//(gcd(a,b))\r\ncommon = n//common\r\n\r\nprint(aa+ bb - min(p,q)*common)\r\n", "import sys\n\ndef main():\n\tfor line in sys.stdin:\n\t\tline = line.split()\n\t\tn = int(line[0])\n\t\ta = int(line[1])\n\t\tb = int(line[2])\n\t\tp = int(line[3])\n\t\tq = int(line[4])\n\t\tdef gcd(x, y):\n\t\t\twhile(y):\n\t\t\t\tx, y = y, x % y\n\t\t\treturn x\n\t\tlcm = int(a*b/gcd(a,b))\n\n\n\n\t\tnumLCM = int(n/lcm)\n\t\tnumA = int(n/a) - numLCM\n\t\tnumB = int(n/b) - numLCM\n\t\tprint(numA * p + numB * q + numLCM * max(p,q))\n\nif __name__ == \"__main__\":\n main()", "from sys import stdin\r\ninput = stdin.readline\r\nn, a, b, p, q = map(int, input().split())\r\nfrom math import gcd\r\nlcm = lambda x,y: (x * y) // gcd(x, y)\r\naf = n // a\r\nbf = n // b\r\nabf = n // lcm(a, b)\r\nao = af - abf\r\nbo = bf - abf\r\nprint(ao * p + bo * q + abf * (max(p, q)))", "import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\n\nN,A,B,P,Q = map(int,input().split())\n\na,b = N//A,N//B\nc = N//lcm(A,B)\nif P>Q:\n print(P*a+Q*(b-c))\nelse:\n print(P*(a-c)+Q*b)\n\n", "import math\r\nn, a, b, p, q=map(int, input().rstrip().split())\r\nnum_a=int(n/a)\r\nnum_b=int(n/b)\r\nlcm=int((a*b)/math.gcd(a, b))\r\nif lcm>n:\r\n print((num_a*p)+(num_b*q))\r\nif lcm<=n:\r\n num_lcm=int(n/lcm)\r\n if p>=q:\r\n num_b-=num_lcm\r\n print((num_a*p)+(num_b*q))\r\n if p<q:\r\n num_a-=num_lcm\r\n print((num_a*p)+(num_b*q))", "import math\r\ndef lcm(a, b):\r\n return abs(a*b) // math.gcd(a, b)\r\n# t = int(input())\r\nfrom sys import stdin\r\nt = 1\r\nfor _ in range(t):\r\n n,a,b,p,q = [int(x) for x in input().split()]\r\n # n,k = list(map(int,stdin.readline().split()))\r\n x = lcm(a,b)\r\n if (p<q):\r\n c = ((n//a) - n//x )*p + (n//b)*q\r\n print( c)\r\n else:\r\n c = ((n//b) - n//x )*q + (n//a)*p\r\n print( c)\r\n ", "import math\r\n\r\ninputs = input().split()\r\n\r\nn = int(inputs[0])\r\na = int(inputs[1])\r\nb = int(inputs[2])\r\np = int(inputs[3])\r\nq = int(inputs[4])\r\ncount = 0\r\n\r\nminimum = min(a, b)\r\ngcds = math.gcd(a, b)\r\n\r\nlcm = a * b // gcds\r\nab_count = n // lcm\r\na_count = n // a\r\nb_count = n // b\r\n\r\nif p > q:\r\n larger = p\r\nelse:\r\n larger = q\r\n\r\ncount += ab_count * larger\r\ncount += (a_count - ab_count) * p\r\ncount += (b_count - ab_count) * q\r\nprint(int(count))", "import sys,math\r\nn,a,b,p,q=map(int,sys.stdin.readline().split())\r\nx=(n//a)*p \r\nx+=(n//b)*q\r\nlcm=(a*b)//math.gcd(a,b)\r\nx-=(n//lcm)*(min(p,q))\r\nprint(x)", "import sys\r\nfrom math import gcd\r\ninput = sys.stdin.readline \r\n\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nn1 = n // a \r\nn2 = n // b \r\n\r\nc = (a * b) // gcd(a, b) \r\nn3 = n // c \r\nn1 -= n3 \r\nn2 -= n3\r\n\r\nprint(n1 * p + n2 * q + max(p, q) * n3)\r\n\r\n", "import math\r\nn,a,b,p,q=list(map(int,input().split()))\r\nx=(n//a)*p+(n//b)*q\r\nlcm=(a*b)//math.gcd(a,b)\r\nd=(n//lcm)*(min(p,q))\r\nprint(x-d)", "from sys import stdin, stdout\r\n\r\n\r\ndef gcd(a, b):\r\n if not b:\r\n return a\r\n \r\n return gcd(b, a % b)\r\n\r\n\r\nn, a, b, p, q = map(int, stdin.readline().split())\r\nfirst, second, third = (n // a) * p, (n // b) * q, (n // (a * b // gcd(a, b))) * min(p, q)\r\nstdout.write(str(first + second - third))", "from math import gcd\r\nn, a, b, p, q = map(int, input().split())\r\nredch = n // a\r\nbluech = n // b\r\nif p > q:\r\n bluech -= n // ((a*b)//gcd(a, b))\r\nelse:\r\n redch -= n // ((a*b)//gcd(a, b))\r\nprint(redch * p + bluech * q)", "import sys\r\ninput = sys.stdin.readline\r\nfrom math import gcd\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nx = n//a\r\ny = n//b\r\nz = a // gcd(a, b) * b\r\nz = n//z\r\nx -= z\r\ny -= z\r\nprint(x*p + y*q + z*(max(p, q)))", "from math import *\r\nn,a,b,p,q=list(map(int,input().split()))\r\nprint(p*(n//a-n//(a*b//gcd(a,b)))+q*(n//b-n//(a*b//gcd(a,b)))+max(p,q)*(n//(a*b//gcd(a,b))))", "#rOkY\n#FuCk\n\n############################### kOpAl ##################################\n\nimport math\nn,a,b,c,d=map(int,input().split())\n\nx=n//a\ny=n//b\nz=a//int(math.gcd(a,b))*b\nm=n//z\nx-=m\ny-=m\nprint(x*c +y*d +max(c,d)*m)\n\n \t \t\t\t \t\t \t \t\t\t \t\t \t \t", "import math\r\nn, a, b, p, q = map(int, input().split())\r\nminimum = min(p, q)\r\ngcd = math.gcd(a, b)\r\nsum_a = (n//a)*p\r\nsum_b = (n//b)*q\r\ndelta = (n//((a*b)// gcd))*minimum\r\nprint(sum_a + sum_b - delta)\r\n", "import math\r\nn,a,b,p,q=map(int,input().split())\r\nlcm=a*b//math.gcd(a,b)\r\nz=n//lcm\r\nx=n//a-z\r\ny=n//b-z\r\nprint(x*p+y*q+z*max(p,q))", "from math import gcd\r\nn,a,b,p,q=map(int,input().split())\r\nprint((n//a)*p+(n//b)*q-(n//(a*b//gcd(a,b)))*(q if q<p else p))", "import sys\r\nfrom math import gcd\r\n\r\nn, a, b, p, q = map(int, input().split())\r\nans = (n // a) * p + (n // b) * q - (n // (a * b // gcd(a, b))) * min(p, q)\r\nprint(ans)\r\n", "from math import floor, gcd\r\ndef mmc(x, y):\r\n\tmaior = max(x, y)\r\n\twhile True:\r\n\t\tmmc = (x * y) // gcd(x,y)\r\n\t\treturn mmc\r\n\r\na,b,c,d,e = map(int, input().split())\r\nresp = d * (floor(a // b))\r\nresp += e * (floor(a // c))\r\nresp -= min(d,e) * (a // (mmc(b,c)))\r\nprint(resp)", "import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef gcd(a, b):\r\n if a > b:\r\n a, b = b, a \r\n if b % a==0:\r\n return a \r\n return gcd(b % a, a)\r\n \r\ndef process(n, a, b, p, q):\r\n lcm = (a*b)//gcd(a,b)\r\n g1 = n//lcm \r\n a1 = n//a-g1 \r\n b1 = n//b-g1 \r\n answer = p*a1+q*b1+max(p, q)*g1\r\n print(answer)\r\n \r\nn, a, b, p, q = [int(x) for x in input().split()]\r\nprocess(n, a, b, p, q)", "def gcd(a,b):\r\n while b:\r\n a,b=b,a%b\r\n return a\r\nn,a,b,p,q=map(int,input().split())\r\nm=(a*b)//gcd(a,b)\r\nif p>q:\r\n exit(print(((n//a)*p)+((n//b)*q)-(n//m)*q))\r\nexit(print(((n//b)*q)+((n//a)*p)-(n//m)*p))\r\n\r\n", "import math\r\nn,a,b,p,q=map(int,input().split())\r\nlcm=(a*b)//math.gcd(a,b)\r\nredorblue=n//lcm\r\nred=n//a - redorblue\r\nblue=n//b - redorblue\r\nprint(p*red + q*blue + max(p,q)*redorblue)", "n,a,b,p,q=map(int, input().split())\r\ndef lcm(a, b):\r\n return abs(a*b) // math.gcd(a, b)\r\nimport math\r\nprint(p*(n//a) + q*(n//b) - (min(p,q)*(n//(lcm(a,b)))))\r\n" ]
{"inputs": ["5 2 3 12 15", "20 2 3 3 5", "1 1 1 1 1", "1 2 2 2 2", "2 1 3 3 3", "3 1 1 3 3", "4 1 5 4 3", "8 8 1 1 1", "15 14 32 65 28", "894 197 325 232 902", "8581 6058 3019 2151 4140", "41764 97259 54586 18013 75415", "333625 453145 800800 907251 446081", "4394826 2233224 609367 3364334 898489", "13350712 76770926 61331309 8735000 9057368", "142098087 687355301 987788392 75187408 868856364", "1000000000 1 3 1000000000 999999999", "6 6 2 8 2", "500 8 4 4 5", "20 4 6 2 3", "10 3 9 1 2", "120 18 6 3 5", "30 4 6 2 2", "1000000000 7171 2727 191 272", "5 2 2 4 1", "1000000000 2 2 3 3", "24 4 6 5 7", "216 6 36 10 100", "100 12 6 1 10", "1000 4 8 3 5", "10 2 4 3 6", "1000000000 1000000000 1000000000 1000000000 1000000000", "10 5 10 2 3", "100000 3 9 1 2", "10 2 4 1 100", "20 6 4 2 3", "1200 4 16 2 3", "7 2 4 7 9", "24 6 4 15 10", "50 2 8 15 13", "100 4 6 12 15", "56756 9 18 56 78", "10000 4 6 10 12", "20 2 4 3 5", "24 4 6 10 100", "12 2 4 5 6", "100 2 4 1 100", "1000 4 6 50 50", "60 12 6 12 15", "1000 2 4 5 6", "1000000000 1 1 9999 5555", "50 2 2 4 5", "14 4 2 2 3", "100 3 9 1 2", "1000000000 4 6 1 1000000000", "12 3 3 45 4", "12 2 4 5 9", "1000000000 2 2 1000000000 1000000000", "50 4 8 5 6", "32 4 16 6 3", "10000 2 4 1 1", "8 2 4 100 1", "20 4 2 10 1", "5 2 2 12 15", "20 2 12 5 6", "10 2 4 1 2", "32 4 16 3 6", "50 2 8 13 15", "12 6 4 10 9", "1000000000 999999998 999999999 999999998 999999999", "20 2 4 10 20", "13 4 6 12 15", "30 3 6 5 7", "7 2 4 2 1", "100000 32 16 2 3", "6 2 6 1 1", "999999999 180 192 46642017 28801397", "12 4 6 1 1", "10 2 4 10 5", "1000000 4 6 12 14", "2000 20 30 3 5", "1000000000 1 2 1 1", "30 3 15 10 3", "1000 2 4 1 100", "6 3 3 12 15", "24 4 6 1 1", "20 2 12 4 5", "1000000000 9 15 10 10", "16 2 4 1 2", "100000 4 6 12 14", "24 6 4 1 1", "1000000 4 6 12 15", "100 2 4 5 6", "10 3 9 12 15", "1000000000 1 1 999999999 999999999", "6 2 4 2 3", "2 2 2 2 2", "6 6 2 1 1", "100 2 4 3 7", "1000000 32 16 2 5", "100 20 15 50 25", "1000000000 100000007 100000013 10 3", "1000000000 9999999 99999998 3 3", "10077696 24 36 10 100", "392852503 148746166 420198270 517065752 906699795", "536870912 60000 72000 271828 314159", "730114139 21550542 204644733 680083361 11353255", "538228881 766493289 791886544 468896052 600136703", "190 20 50 84 172", "1000 5 10 80 90", "99999999 999999998 1 271828 314159", "22 3 6 1243 1", "15 10 5 2 2", "1000000000 1000000000 1 1000000000 1000000000", "62 62 42 78 124", "2 2 2 2 1", "864351351 351 313 531 11", "26 3 6 1244 1", "1000 4 6 7 3", "134312 3 6 33333 1", "100 4 6 17 18", "6 2 4 5 6", "8 2 4 10 1", "10 2 4 3 3", "1000 1000 1000 1000 1000", "123123 3 6 34312 2", "1000000000 25 5 999 999", "100 4 2 5 12", "50 2 4 4 5", "24 4 6 100 333", "216 24 36 10 100", "50 6 4 3 8", "146 76 2 178 192", "55 8 6 11 20", "5 2 4 6 16", "54 2 52 50 188", "536870912 60000000 72000000 271828 314159", "1000000000 1000000000 1 1 100", "50 4 2 4 5", "198 56 56 122 118", "5 1000000000 1 12 15", "1000 6 12 5 6", "50 3 6 12 15", "333 300 300 300 300", "1 1000000000 1 1 2", "188 110 110 200 78", "100000 20 10 3 2", "100 2 4 1 10", "1000000000 2 1000000000 1 1000000", "20 3 6 5 7", "50 4 6 4 5", "96 46 4 174 156", "5 2 4 12 15", "12 3 6 100 1", "100 4 2 10 32", "1232 3 6 30000 3", "20 3 6 5 4", "100 6 15 11 29", "10000000 4 8 100 200", "1000000000 12 24 2 4", "123 3 6 3000 1", "401523968 1536 2664 271828 314159", "9 2 4 3 5", "999999999 724362018 772432019 46201854 20017479", "100 2 4 1 1000", "50 2 4 1 1000", "1000000000 2 1 2 1", "1000000000 2005034 2005046 15 12", "1000000000 999999999 1000000000 1 1", "999999999 500000000 1 100 1000", "50 8 6 3 4", "1000000000 1 1 1000000000 1000000000", "1000000000 999999862 999999818 15 12", "1000000000 10000019 10000019 21 17", "20 6 4 8 2", "1000000000 1000000000 1 1 1", "1000000000 12345678 123456789 1000000000 999999999", "1000000000 2 999999937 100000000 100000000", "1000000000 1 1 1000000000 999999999", "1000000000 50001 100003 10 10", "1000000000 1000000000 3 1 1", "10000 44 49 114 514", "30 5 15 2 1", "20 2 4 1 1", "100 8 12 5 6"], "outputs": ["39", "51", "1", "0", "6", "9", "16", "8", "65", "2732", "10431", "0", "0", "9653757", "0", "0", "1000000000000000000", "12", "625", "17", "4", "100", "20", "125391842", "8", "1500000000", "48", "900", "160", "1000", "21", "1000000000", "5", "44444", "203", "19", "675", "23", "100", "375", "444", "422502", "36662", "40", "440", "33", "2525", "16650", "150", "2750", "9999000000000", "125", "21", "44", "166666666166666667", "180", "42", "500000000000000000", "66", "48", "5000", "400", "55", "30", "51", "7", "30", "337", "38", "1999999997", "150", "54", "60", "6", "18750", "3", "399129078526502", "4", "50", "4333328", "531", "1000000000", "100", "25250", "30", "8", "41", "1555555550", "12", "433328", "8", "4499994", "275", "39", "999999999000000000", "7", "2", "3", "250", "312500", "375", "117", "330", "30792960", "1034131504", "4369119072", "22476810678", "0", "1188", "17000", "31415899685841", "8701", "6", "1000000000000000000", "202", "2", "1337898227", "9952", "1999", "1492318410", "577", "16", "40", "15", "1000", "1408198792", "199800000000", "600", "112", "1732", "660", "108", "14016", "224", "22", "1488", "4101909", "100000000000", "125", "366", "75", "913", "216", "300", "2", "200", "25000", "275", "500999999", "36", "72", "3936", "27", "400", "1600", "12300000", "30", "317", "375000000", "249999998", "123000", "117768531682", "16", "66219333", "25025", "12013", "1500000000", "13446", "2", "999999999000", "44", "1000000000000000000", "27", "2079", "32", "1000000000", "88999999992", "50000000100000000", "1000000000000000000", "299980", "333333334", "130278", "12", "10", "88"]}
UNKNOWN
PYTHON3
CODEFORCES
107
1cc716b77421e3d6b18974cbc830152f
Hard problem
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given *n* strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the dictionary), but he is not allowed to swap any of them. The only operation he is allowed to do is to reverse any of them (first character becomes last, second becomes one before last and so on). To reverse the *i*-th string Vasiliy has to spent *c**i* units of energy. He is interested in the minimum amount of energy he has to spent in order to have strings sorted in lexicographical order. String *A* is lexicographically smaller than string *B* if it is shorter than *B* (|*A*|<=&lt;<=|*B*|) and is its prefix, or if none of them is a prefix of the other and at the first position where they differ character in *A* is smaller than the character in *B*. For the purpose of this problem, two equal strings nearby do not break the condition of sequence being sorted lexicographically. The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of strings. The second line contains *n* integers *c**i* (0<=≤<=*c**i*<=≤<=109), the *i*-th of them is equal to the amount of energy Vasiliy has to spent in order to reverse the *i*-th string. Then follow *n* lines, each containing a string consisting of lowercase English letters. The total length of these strings doesn't exceed 100<=000. If it is impossible to reverse some of the strings such that they will be located in lexicographical order, print <=-<=1. Otherwise, print the minimum total amount of energy Vasiliy has to spent. Sample Input 2 1 2 ba ac 3 1 3 1 aa ba ac 2 5 5 bbb aaa 2 3 3 aaa aa Sample Output 1 1 -1 -1
[ "n = int(input())\r\nc = tuple(map(int, input().split()))\r\nw = [input() for i in range(n)]\r\nwr = [w[i][::-1] for i in range(n)]\r\n\r\ninf = 10**19\r\n\r\ndp = [inf] * n\r\ndpr = [inf] * n\r\ndpr[0] = c[0]\r\ndp[0] = 0\r\n\r\nfor i in range(1, n):\r\n if w[i] >= w[i - 1]:\r\n dp[i] = dp[i - 1]\r\n\r\n if w[i] >= wr[i - 1]:\r\n dp[i] = min(dp[i], dpr[i - 1])\r\n\r\n if wr[i] >= w[i - 1]:\r\n dpr[i] = dp[i - 1] + c[i]\r\n \r\n if wr[i] >= wr[i - 1]:\r\n dpr[i] = min(dpr[i], dpr[i - 1] + c[i])\r\n\r\n\r\nans = min(dp[n - 1], dpr[n - 1])\r\nif ans < inf:\r\n print(ans)\r\nelse:\r\n print(-1)", "n = int(input()) # 读取字符串数量\r\nenergy_costs = list(map(int, input().split())) # 读取每个字符串反转的能量成本\r\nstrings = []\r\nfor _ in range(n):\r\n strings.append(input()) # 读取每个字符串\r\n# 初始化动态规划数组\r\ndp_normal = [float('inf')] * n # 不反转时的最小能量成本\r\ndp_reversed = [float('inf')] * n # 反转时的最小能量成本\r\nreversed_strings = [s[::-1] for s in strings] # 提前计算每个字符串的反转\r\n# 第一个字符串可以选择反转或不反转\r\ndp_normal[0], dp_reversed[0] = 0, energy_costs[0]\r\n# 动态规划处理每对相邻的字符串\r\nfor i in range(1, n):\r\n # 比较字符串的正常和反转顺序,并更新动态规划数组\r\n if strings[i] >= strings[i - 1]:\r\n dp_normal[i] = min(dp_normal[i], dp_normal[i - 1])\r\n if strings[i] >= reversed_strings[i - 1]:\r\n dp_normal[i] = min(dp_normal[i], dp_reversed[i - 1])\r\n if reversed_strings[i] >= strings[i - 1]:\r\n dp_reversed[i] = min(dp_reversed[i], dp_normal[i - 1] + energy_costs[i])\r\n if reversed_strings[i] >= reversed_strings[i - 1]:\r\n dp_reversed[i] = min(dp_reversed[i], dp_reversed[i - 1] + energy_costs[i])\r\n# 计算排序字符串所需的最小能量\r\nresult = min(dp_normal[-1], dp_reversed[-1])\r\nprint(-1 if result == float('inf') else result)\r\n", "n = int(input())\r\nc = list(map(int, input().split()))\r\nq = [input() for _ in range(n)]\r\ndp = [[0, 0] for _ in range(n)]\r\ndp[0][0] = 0\r\ndp[0][1] = c[0]\r\nfor p in range(1, n):\r\n rr = q[p-1][::-1]\r\n rc = q[p][::-1]\r\n cA, cB = -1, -1\r\n if q[p-1] <= q[p] and dp[p-1][0] >= 0:\r\n cA = dp[p-1][0]\r\n if rr <= q[p] and dp[p-1][1] >= 0:\r\n cB = dp[p-1][1]\r\n if cA >= 0 and cB >= 0:\r\n dp[p][0] = min(cA, cB)\r\n elif cA >= 0:\r\n dp[p][0] = cA\r\n elif cB >= 0:\r\n dp[p][0] = cB\r\n else:\r\n dp[p][0] = -1\r\n cA, cB = -1, -1\r\n if q[p-1] <= rc and dp[p-1][0] >= 0:\r\n cA = dp[p-1][0] + c[p]\r\n if rr <= rc and dp[p-1][1] >= 0:\r\n cB = dp[p-1][1] + c[p]\r\n if cA >= 0 and cB >= 0:\r\n dp[p][1] = min(cA, cB)\r\n elif cA >= 0:\r\n dp[p][1] = cA\r\n elif cB >= 0:\r\n dp[p][1] = cB\r\n else:\r\n dp[p][1] = -1\r\nans = 0\r\nif dp[n-1][0] >= 0 and dp[n-1][1] >= 0:\r\n ans = min(dp[n-1][0], dp[n-1][1])\r\nelif dp[n-1][0] >= 0:\r\n ans = dp[n-1][0]\r\nelif dp[n-1][1] >= 0:\r\n ans = dp[n-1][1]\r\nelse:\r\n ans = -1\r\nprint(ans)# 1691068533.3342419", "import sys \r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(A, B):\r\n n = len(A)\r\n start = [0, A[0]]\r\n for i in range(1, n):\r\n new_s = []\r\n a, b = start\r\n new_a, new_b = float('inf'), float('inf')\r\n s1, s2 = B[i-1], B[i-1][::-1]\r\n t1, t2 = B[i], B[i][::-1]\r\n if s1 <= t1:\r\n new_a = min(new_a, a)\r\n if s2 <= t1:\r\n new_a = min(new_a, b)\r\n if s1 <= t2:\r\n new_b = min(new_b, a+A[i])\r\n if s2 <= t2:\r\n new_b = min(new_b, b+A[i])\r\n if new_a==float('inf') and new_b==float('inf'):\r\n sys.stdout.write('-1\\n')\r\n return \r\n start = [new_a, new_b]\r\n answer = min(start)\r\n sys.stdout.write(f'{answer}\\n')\r\nn = int(input())\r\nA = [int(x) for x in input().split()]\r\nB = []\r\nfor i in range(n):\r\n row = input().decode().strip()\r\n B.append(row)\r\nprocess(A, B)", "n = int(input())\r\nc = list(map(int, input().split()))\r\ns = [input() for _ in range(n)]\r\nr = [x[::-1] for x in s]\r\ndp = [[float('inf')] * 2 for _ in range(n)]\r\ndp[0][0], dp[0][1] = 0, c[0]\r\nfor i in range(1, n):\r\n if s[i] >= s[i-1]:\r\n dp[i][0] = min(dp[i][0], dp[i-1][0])\r\n if s[i] >= r[i-1]:\r\n dp[i][0] = min(dp[i][0], dp[i-1][1])\r\n if r[i] >= s[i-1]:\r\n dp[i][1] = min(dp[i][1], dp[i-1][0] + c[i])\r\n if r[i] >= r[i-1]:\r\n dp[i][1] = min(dp[i][1], dp[i-1][1] + c[i])\r\nans = min(dp[n-1])\r\nprint(ans if ans != float('inf') else -1)\r\n", "def min_energy(n, c, strings):\n # Initializing dp where dp[i][0] represents energy when string i is in original order\n # and dp[i][1] represents energy when string i is reversed\n dp = [[float('inf')] * 2 for _ in range(n)]\n \n dp[0][0] = 0\n dp[0][1] = c[0]\n\n for i in range(1, n):\n # If the current string is greater than or equal to the previous string\n # in its original order, then update the energy.\n if strings[i] >= strings[i - 1]:\n dp[i][0] = min(dp[i][0], dp[i - 1][0])\n\n # If the current reversed string is greater than or equal to the previous string\n # in its original order, then update the energy.\n if strings[i][::-1] >= strings[i - 1]:\n dp[i][1] = min(dp[i][1], dp[i - 1][0] + c[i])\n\n # If the current string is greater than or equal to the previous reversed string\n # then update the energy.\n if strings[i] >= strings[i - 1][::-1]:\n dp[i][0] = min(dp[i][0], dp[i - 1][1])\n\n # If the current reversed string is greater than or equal to the previous reversed string\n # then update the energy.\n if strings[i][::-1] >= strings[i - 1][::-1]:\n dp[i][1] = min(dp[i][1], dp[i - 1][1] + c[i])\n\n # If it's impossible to sort the strings, return -1\n if dp[n - 1][0] == dp[n - 1][1] == float('inf'):\n return -1\n\n return min(dp[n - 1])\n\n# Input\nn = int(input())\nc = list(map(int, input().split()))\nstrings = [input().strip() for _ in range(n)]\n\n# Output\nprint(min_energy(n, c, strings))\n", "from os import path\r\nfrom sys import stdin, stdout\r\nfrom types import GeneratorType\r\n\r\nfilename = \"../templates/input.txt\"\r\nif path.exists(filename):\r\n stdin = open(filename, 'r')\r\n\r\n\r\ndef input():\r\n return stdin.readline().rstrip()\r\n\r\n\r\ndef print(*args, sep=' ', end='\\n'):\r\n stdout.write(sep.join(map(str, args)))\r\n stdout.write(end)\r\n\r\n\r\ndef bootstrap(f, stack=[]):\r\n def wrappedfunc(*args, **kwargs):\r\n if stack:\r\n return f(*args, **kwargs)\r\n to = f(*args, **kwargs)\r\n while True:\r\n if type(to) is GeneratorType:\r\n stack.append(to)\r\n to = next(to)\r\n else:\r\n stack.pop()\r\n if not stack:\r\n break\r\n to = stack[-1].send(to)\r\n return to\r\n\r\n return wrappedfunc\r\n\r\n\r\ndef solution():\r\n @bootstrap\r\n def dp(i: int, rotated: int) -> int:\r\n if (i, rotated) in cache:\r\n yield cache[(i, rotated)]\r\n if i == n:\r\n ans = 0\r\n else:\r\n ans = INF\r\n prev_s = s[i - 1]\r\n if rotated:\r\n prev_s = prev_s[::-1]\r\n if s[i] >= prev_s:\r\n ans = min(ans, (yield dp(i + 1, 0)))\r\n if s[i][::-1] >= prev_s:\r\n ans = min(ans, (yield dp(i + 1, 1)) + c[i])\r\n cache[(i, rotated)] = ans\r\n yield ans\r\n\r\n\r\n INF = 10 ** 20\r\n n = int(input())\r\n c = [int(num) for num in input().split()]\r\n s = []\r\n for i in range(n):\r\n s.append(input())\r\n s.append('')\r\n cache = dict()\r\n print(dp(0, 0) if dp(0, 0) != INF else -1)\r\n\r\n\r\ndef main():\r\n t = 1\r\n while t:\r\n solution()\r\n t -= 1\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn=int(input())\r\nC=list(map(int,input().split()))\r\n\r\nS=[input().strip() for i in range(n)]\r\n\r\nDP0=[1<<60]*n\r\nDP1=[1<<60]*n\r\n\r\nDP0[0]=0\r\nDP1[0]=C[0]\r\n\r\nfor i in range(1,n):\r\n if S[i]>=S[i-1]:\r\n DP0[i]=min(DP0[i],DP0[i-1])\r\n if S[i]>=S[i-1][::-1]:\r\n DP0[i]=min(DP0[i],DP1[i-1])\r\n if S[i][::-1]>=S[i-1]:\r\n DP1[i]=min(DP1[i],DP0[i-1]+C[i])\r\n if S[i][::-1]>=S[i-1][::-1]:\r\n DP1[i]=min(DP1[i],DP1[i-1]+C[i])\r\n\r\nANS=min(DP0[-1],DP1[-1])\r\n\r\nif ANS==1<<60:\r\n print(-1)\r\nelse:\r\n print(ANS)\r\n", "I=input\r\nn=int(I())\r\nc=list(map(int,I().split()))\r\nl=r=''\r\na=b=0\r\nfor i in range(n):\r\n s=I();t=s[::-1];x=y=10**16\r\n if s>=l:x=a\r\n if s>=r:x=min(x,b)\r\n if t>=l:y=a+c[i]\r\n if t>=r:y=min(y,b+c[i])\r\n l=s;r=t;a=x;b=y\r\na=min(a,b)\r\nif a==10**16:a=-1\r\nprint(a)", "n=int(input())\r\narr=[int(i) for i in input().split()]\r\ns=[]\r\nfor _ in range(n):\r\n s.append(input())\r\ndp=[[float('inf'),float('inf')] for _ in range(n)]\r\n# dp => not flip, flip\r\ndp[0]=[0,arr[0]]\r\nfor i in range(1,n):\r\n if s[i]>=s[i-1]:\r\n dp[i][0]=min(dp[i][0],dp[i-1][0])\r\n if s[i]>=s[i-1][::-1]:\r\n dp[i][0]=min(dp[i][0],dp[i-1][1])\r\n if s[i][::-1]>=s[i-1]:\r\n dp[i][1]=min(dp[i][1],arr[i]+dp[i-1][0])\r\n if s[i][::-1]>=s[i-1][::-1]:\r\n dp[i][1]=min(dp[i][1],arr[i]+dp[i-1][1])\r\nif min(dp[n-1])==float('inf'):\r\n print(-1)\r\nelse:\r\n print(min(dp[n-1]))" ]
{"inputs": ["2\n1 2\nba\nac", "3\n1 3 1\naa\nba\nac", "2\n5 5\nbbb\naaa", "2\n3 3\naaa\naa", "4\n0 0 8 6\nbi\nqp\nbt\nya", "5\n8 0 4 8 2\nac\ncl\ngg\ngm\nfs", "10\n7 7 0 0 0 1 6 6 7 3\ndv\ngb\nvg\nxg\nkt\nml\nqm\nnq\nrt\nxn", "3\n999999999 999999999 999999999\nxosbqqnmxq\nsdbvjhvytx\naydpuidgvy", "3\n228 1488 228\nkek\nlol\nmda", "2\n1 1\naa\naa", "2\n1000000000 1000000000\nba\nac", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\nea\ndb\ncc\nbd\nae", "3\n1000000000 1000000000 1000000000\nca\nda\nab", "2\n1000000000 1000000000\naba\naab", "3\n1000000000 1000000000 1000000000\nza\nyb\nxc", "11\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\naz\nzb\nzc\nzd\nez\nfz\ngz\nzh\niz\nzj\nkz", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\nzaaaaaaaaaa\nyaaaaaaaaa\nxaaaaaaaa\nwaaaaaaa\nvaaaaaa\nuaaaaa\ntaaaa\nsaaa\nraa\nqa", "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\nza\nyb\nxc\nwd\nve\nuf", "5\n0 1000000000 1000000000 1000000000 1000000000\nb\nab\nab\nab\nab", "4\n1000000000 1000000000 1000000000 1000000000\nzaaaaaaaaaaaaaaa\nybbbbbbbbbbbbbbb\nxccccccccccccccc\nwddddddddddddddd", "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\nba\nab\ndc\ncd\nfe\nef", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\naaaaaaaaaaab\nab\naab\naaab\naaaab\naaaaab\naaaaaab\naaaaaaab\naaaaaaaab\naaaaaaaaab", "13\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\naz\nab\nac\nad\nae\naf\nag\nah\nai\naj\nak\nal\nam", "3\n1000000000 1000000000 1000000000\ndaa\ncab\nbac", "4\n1000000000 1000000000 1000000000 1000000000\nza\nbt\ncm\ndn", "4\n1000000000 1000000000 1000000000 1000000000\nza\nyb\nxc\nwd", "9\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\na\nba\nab\nc\ndc\ncd\nx\nyx\nxy", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\nbaaa\ncaaa\nbbbb\naaac\naaad\neeee\nadff\ngggg\nadah\naaai", "3\n900000000 3 87654321\nda\nbb\nad"], "outputs": ["1", "1", "-1", "-1", "8", "2", "6", "1999999998", "0", "0", "1000000000", "4000000000", "3000000000", "1000000000", "2000000000", "5000000000", "9000000000", "5000000000", "4000000000", "3000000000", "3000000000", "8000000000", "12000000000", "2000000000", "1000000000", "3000000000", "3000000000", "7000000000", "987654321"]}
UNKNOWN
PYTHON3
CODEFORCES
10
1cc7f991569d0b44661ef185c3842674
Party Lemonade
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of *n* different volumes at different costs. A single bottle of type *i* has volume 2*i*<=-<=1 liters and costs *c**i* roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least *L* liters of lemonade. How many roubles do you have to spend? The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=30; 1<=≤<=*L*<=≤<=109) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=109) — the costs of bottles of different types. Output a single integer — the smallest number of roubles you have to pay in order to buy at least *L* liters of lemonade. Sample Input 4 12 20 30 70 90 4 3 10000 1000 100 10 4 3 10 100 1000 10000 5 787787787 123456789 234567890 345678901 456789012 987654321 Sample Output 150 10 30 44981600785557577
[ "s=input()\r\ns1=s.split()\r\n\r\ntot=int(s1[1])\r\n\r\ns=input()\r\ns1=s.split()\r\n\r\nl=[int(i) for i in s1]\r\n\r\n\r\navg=[[l[i]/(2**i),i] for i in range(len(l))]\r\navg.sort()\r\ncost=0\r\ni=0\r\n\r\ndef fun(i,tot):\r\n\r\n if i==len(avg):\r\n\r\n return(1e8)\r\n\r\n if tot%(2**avg[i][1])==0:\r\n\r\n return((tot//(2**avg[i][1]))*l[avg[i][1]])\r\n else:\r\n\r\n a=(tot//(2**avg[i][1])+1)*l[avg[i][1]]\r\n\r\n b=(tot//(2**avg[i][1]))*l[avg[i][1]]+fun(i+1,tot%(2**avg[i][1]))\r\n\r\n return(min(a,b))\r\n\r\nprint(fun(0,tot))\r\n", "n,l=map(int,input().split())\r\na=list(map(int,input().split()))\r\nfor i in range(0,n-1):\r\n a[i+1]=min(a[i+1],2*a[i])\r\ns=0\r\nans=100**100\r\nfor i in range(n-1,-1,-1):\r\n d=l//(1<<i)\r\n s+=d*a[i]\r\n l-=d<<i;\r\n ans=min(ans,s+(l>0)*a[i])\r\nprint(ans)", "val = input()\nn, L = val.split()\nn = int(n)\nL = int(L)\nans = 0\nstring = input()\nstring = string.split()\nfor i in range(1, len(string)):\n if(2* int(string[i-1]) < int(string[i])):\n string[i] = 2*int(string[i-1])\nfor i in range(len(string)):\n if(ans > int(string[i])):\n ans = int(string[i])\n if(L & 1):\n ans += int(string[i])\n L //= 2\nL *= 2\nans += L*(int(string[n-1]))\nprint(ans)\n\n \t \t \t \t\t\t \t\t \t \t \t\t \t", "# for I/O for local system\r\nimport sys\r\nfrom os import path\r\nif(path.exists('Input.txt')):\r\n sys.stdin = open(\"Input.txt\",\"r\")\r\n sys.stdout = open(\"Output.txt\",\"w\")\r\n\r\n# For fast I/O\r\ninput = sys.stdin.buffer.readline\r\n# input = sys.stdin.readline\r\nprint = sys.stdout.write\r\n\r\n# Import libraries here whenever required\r\nfrom collections import deque,defaultdict\r\nfrom random import randint\r\n\r\n# Use this because normal dict can sometimes give TLE\r\nclass mydict:\r\n def __init__(self, func=lambda: 0):\r\n self.random = randint(0, 1 << 32)\r\n self.default = func\r\n self.dict = {}\r\n def __getitem__(self, key):\r\n mykey = self.random ^ key\r\n if mykey not in self.dict:\r\n self.dict[mykey] = self.default()\r\n return self.dict[mykey]\r\n def get(self, key, default):\r\n mykey = self.random ^ key\r\n if mykey not in self.dict:\r\n return default\r\n return self.dict[mykey]\r\n def __setitem__(self, key, item):\r\n mykey = self.random ^ key\r\n self.dict[mykey] = item\r\n def getkeys(self):\r\n return [self.random ^ i for i in self.dict]\r\n def __str__(self):\r\n return f'{[(self.random ^ i, self.dict[i]) for i in self.dict]}'\r\n\r\ndef expo(a, n): \r\n ans = 1\r\n while(n > 0):\r\n last_bit = n&1\r\n if(last_bit):\r\n ans = (ans*a)\r\n a = (a*a)\r\n n = n >> 1\r\n return ans\r\n\r\n# Solver function\r\ndef solve():\r\n n,l = map(int,input().split())\r\n a = [int(x) for x in input().split()]\r\n d = mydict()\r\n for i in range(n):\r\n d[i] = a[i]\r\n for i in range(n-1,-1,-1):\r\n for j in range(i,-1,-1):\r\n x = j\r\n y = i\r\n diff = y - x\r\n multi_by = expo(2,diff)\r\n d[y] = min(d[y] , multi_by * d[x])\r\n ans = 0\r\n fans = 10 ** 18\r\n for i in range(n-1,-1,-1):\r\n x = i\r\n need = l\r\n pw = expo(2,i)\r\n necessary_take = l // pw\r\n ans += necessary_take * d[i]\r\n l -= necessary_take * pw\r\n for j in range(n):\r\n pw = expo(2,j)\r\n take = (l + pw - 1) // pw\r\n fans = min(fans , ans + take * d[j])\r\n print(str(fans) + \"\\n\")\r\n \r\n# Main \r\nfor _ in range(1):\r\n solve()", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, L = map(int, input().split())\r\nw = list(map(int, input().split()))\r\nd = sorted([(w[i]/(2**i), 2**i, w[i]) for i in range(n)], reverse=1)\r\nc = 0\r\nx = 2 << 100\r\nwhile L:\r\n a1, a2, a3 = d.pop()\r\n c += L//a2 * a3\r\n L %= a2\r\n if L != 0:\r\n x = min(x, c+a3)\r\nx = min(x, c)\r\nprint(int(x))\r\n", "entrada = input().split()\nn = int(entrada[0])\nL = int(entrada[1])\narr_c = [int(c) for c in input().split()]\n\nfor i in range(0, n - 1):\n arr_c[i + 1] = min(arr_c[i + 1], 2 * arr_c[i])\n\nresult = 4*(10**18)\nsoma = 0\n\ni = n - 1\nwhile i >= 0:\n temp = L // (1 << i)\n soma += temp * arr_c[i]\n L -= temp << i\n result = min(result, soma + (L > 0) * arr_c[i])\n i -= 1\n\nprint(result)\n\t\t \t\t\t\t\t\t\t\t\t\t\t \t\t\t\t\t \t\t\t\t\t\t", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nN,L = map(int, input().split())\r\nA = list(map(int, input().split()))\r\n\r\nB = []\r\nfor i in range(N):\r\n B.append((A[i]/(2**i),A[i],2**i,i))\r\nB.sort()\r\n#print(B)\r\n\r\nans = float('inf')\r\npre = 0\r\nfor p,c,l,i in B:\r\n t = (L-1)//l+1\r\n ans = min(ans, pre+t*c)\r\n t = L//l\r\n pre+=t*c\r\n L%=l\r\nprint(ans)\r\n", "n,l=map(int,input().split())\na=list(map(int,input().split()))\nfor i in range(0,n-1):\n a[i+1]=min(a[i+1],2*a[i])\ns=0\nsol=100**100\nfor i in range(n-1,-1,-1):\n d=l//(1<<i)\n s+=d*a[i]\n l-=d<<i;\n sol=min(sol,s+(l>0)*a[i])\nprint(sol)\n\n\t\t \t\t \t\t\t \t\t \t\t \t\t \t \t \t\t\t\t", "# by the authority of GOD author: manhar singh sachdev #\r\n\r\nimport os,sys\r\nfrom io import BytesIO,IOBase\r\n\r\ndef main():\r\n n,L = map(int,input().split())\r\n c = list(map(int,input().split()))\r\n for i in range(n-2,-1,-1):\r\n c[i] = min(c[i],c[i+1])\r\n for i in range(1,n):\r\n c[i] = min(c[i],2*c[i-1])\r\n while len(c) != 31:\r\n c.append(c[-1]*2)\r\n mask,su,ans,tk = 1<<30,0,float(\"inf\"),0\r\n for i in range(30,-1,-1):\r\n if mask&L:\r\n z = L-tk\r\n ans = min(ans,su+c[z.bit_length()-(not z&z-1)])\r\n su += c[i]\r\n tk |= mask\r\n mask >>= 1\r\n print(ans)\r\n\r\n# Fast IO Region\r\nBUFSIZE = 8192\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n def __init__(self,file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd,max(os.fstat(self._fd).st_size,BUFSIZE))\r\n self.newlines = b.count(b\"\\n\")+(not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0,2),self.buffer.write(b),self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd,self.buffer.getvalue())\r\n self.buffer.truncate(0),self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self,file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s:self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda:self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda:self.buffer.readline().decode(\"ascii\")\r\nsys.stdin,sys.stdout = IOWrapper(sys.stdin),IOWrapper(sys.stdout)\r\ninput = lambda:sys.stdin.readline().rstrip(\"\\r\\n\")\r\nif __name__ == \"__main__\":\r\n main()", "from math import ceil\r\nn, l = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\ndp = [0 for i in range(32)]\r\n\r\nfor i in range(32):\r\n dp[i] = (2 ** i) * arr[0]\r\n\r\nfor i in range(1, n):\r\n for j in range(i, 32):\r\n f = 2 ** j\r\n cur = 2 ** i\r\n fac = f // cur\r\n dp[j] = min(dp[j], fac * arr[i])\r\n\r\ntemp = []\r\nfor i in range(n):\r\n temp.append([dp[i] / (2 ** i), 2 ** i, dp[i]])\r\ntemp.sort()\r\n\r\n\r\ndef checker(cost):\r\n cur_vol = 0\r\n while True:\r\n f = 0\r\n for i in range(n):\r\n if cost >= temp[i][2]:\r\n fac = cost // temp[i][2]\r\n num = fac*temp[i][1]\r\n cur_vol += num\r\n f = 1\r\n cost = cost - (fac * temp[i][2])\r\n break\r\n if f == 0:\r\n break\r\n if cur_vol >= l:\r\n return 1\r\n else:\r\n return - 1\r\n\r\n\r\nlow = 0\r\nhigh = 10 ** 19\r\nwhile low < high:\r\n mid = (low + high) // 2\r\n f = checker(mid)\r\n if f == 1:\r\n high = mid\r\n else:\r\n low = mid\r\n if high - low == 1:\r\n break\r\nif checker(low) == 1:\r\n print(low)\r\nelse:\r\n print(high)\r\n", "n,l = tuple(map(int,input().split()))\ncost = list(map(int,input().split()))\n\n##make it clean\n\nfor i in range(1,n):\n\n\tcost[i] = min(cost[i],2*cost[i-1])\n\nans,s = float(\"inf\"),0\nfor i in range(n-1,-1,-1):\n\n\tlitre = 1 << i\n\n\tneed = l // litre\n\n\n\ts += cost[i]*need\n\tl = l % litre\n\n\n\tans = min(ans, s+(l!=0)*cost[i])\nprint(ans)\n", "from math import inf\r\n\r\n\r\nn, L = [int(x) for x in input().split()]\r\nc = [int(x) for x in input().split()]\r\n\r\nf = [inf]*31\r\n\r\nfor i in range(n):\r\n f[i] = min(f[i], c[i])\r\n for j in range(i+1, 31):\r\n f[j] = min(f[j], c[i]<<(j-i))\r\n \r\nfor i in range(29, -1, -1):\r\n f[i] = min(f[i], f[i+1])\r\n\r\nans = 0; last = inf\r\nfor i in range(31):\r\n if ans > f[i]: ans = f[i]\r\n if L>>i&1: ans += f[i]\r\n \r\nprint(ans)", "import math\nn, L = tuple(int(x) for x in input().split())\nc = [int(x) for x in input().split()]\ncost_per_liter = sorted([(c[i]/(2**(i)),c[i],2**i) for i in range(n)])\nindex = 0\ncost = float('inf')\ncurr = [0,0]\nwhile index < n and curr[1] < L:\n amount = (L - curr[1]) // cost_per_liter[index][2]\n add_liter = amount * cost_per_liter[index][2]\n add_cost = amount * cost_per_liter[index][1]\n cost = min(cost, curr[0] + math.ceil((L - curr[1]) / cost_per_liter[index][2]) * cost_per_liter[index][1])\n curr[0] += add_cost\n curr[1] += add_liter\n index += 1\nprint(cost)\n\t\t\t \t \t \t\t \t \t\t\t \t\t\t\t \t\t\t \t", "from collections import defaultdict\nfrom fractions import *\nfrom math import inf\n\n\ndef solve(n, c, l) -> int:\n q = defaultdict(list)\n for i in range(n):\n q[Fraction(c[i], 2 ** i)].append((c[i], 2 ** i))\n\n ansp = []\n ans = 0\n qk = sorted(list(q.keys()))\n for i, k in enumerate(qk):\n cnt = inf\n lm = None\n for cc, ll in q[k]:\n d = l // ll\n\n ansp .append( ans + (d + 1) * cc )\n\n cnt = d * cc\n lm = l - d * ll\n ans += cnt\n l = lm\n return min(ans,min(ansp))\n\n\ndef main():\n # arr = [int(s) for s in input().split()]\n n, l = map(int, input().split())\n c = list(map(int, input().split()))\n print(solve(n, c, l))\n\n\ndef setup():\n import sys\n import os\n if 'DOCKER_HOST' in os.environ:\n print(87393281, solve(30,\n [1, 3, 7, 9, 21, 44, 81, 49, 380, 256, 1592, 1523, 4711, 6202, 1990, 48063, 112547,\n 210599, 481862,\n 1021025, 2016280, 643778, 4325308, 3603826, 20964534, 47383630, 100267203, 126018116,\n 187142230,\n 604840362], 719520853))\n print(solve(4, [10, 100, 1000, 10000], 3))\n print(solve(4, [20, 30, 70, 90], 12))\n print(solve(4, [10000, 1000, 100, 10], 3))\n sys.stdin = open('test.txt')\n\n\nif __name__ == '__main__':\n setup()\n main()\n", "import math\r\nimport bisect\r\nimport sys\r\nfrom collections import OrderedDict\r\ninput = sys.stdin.readline\r\ndef inp():\r\n\treturn(int(input()))\r\ndef inlt():\r\n\treturn(list(map(int,input().split())))\r\ndef insr():\r\n\ts = input()\r\n\treturn(s[:len(s)-1])\r\ndef invr():\r\n\treturn(map(int,input().split()))\r\n# N, M = inlt()\r\n# A = inlt()\r\n# T = inp()\r\n# MOD = 1000000007\r\n# print(MOD)\r\n# for t in range(T):\r\nN, L = invr()\r\nC = inlt()\r\nfor c in range(N-1):\r\n\tif C[c]*2 <= C[c+1]:\r\n\t\tC[c+1] = C[c]*2 \r\nout = 10**18\r\nsumm = 0\r\nfor i in range(N-1,-1,-1):\r\n\ta = 2**i\r\n\tcurr= L//(a)\r\n\tL = L%a\r\n\tsumm += curr*C[i] \r\n\tif L == 0:\r\n\t\tout = min(out,summ)\r\n\telse:\r\n\t\tout = min(out,summ+C[i])\r\nprint(out)", "n, liters = (int(x) for x in input().split())\nprices = list(map(int,input().split()))\nanswer = 10**18\ncache = 0\n\nfor i in range(n-1):\n prices[i+1] = min(prices[i+1], prices[i]*2)\n\nfor i in range(n-1,-1,-1):\n div = 1 << i\n cache += prices[i] * (liters//div)\n liters %= div\n mult = liters != 0\n answer = min(answer, cache + mult*prices[i] )\nprint(answer)\n\t\t\t \t \t\t \t\t\t\t \t\t\t \t\t \t\t \t\t", "'''\r\nhttps://codeforces.com/problemset/problem/913/C\r\n贪心 + 二进制 + 脑筋急转弯\r\n\r\nn杯柠檬水: 第i杯,体积为 2^i (i=0,1...n-1)\r\n价值为c[i]: 求购买至少L升柠檬水的最小花费\r\n\r\n1.\r\n 第i杯 体积 2^i-1 售价c[i]\r\n 第i+1杯 体积 2^i 售价c[i+1]\r\n if 2c[i]>=c[i+1] : 购买i+1杯得到的体积 严格优于买两杯 第i杯\r\n2.\r\n 由于 2^0+2^1+...+2^i<2^(i+1)\r\n 因此:\r\n 如果前面售价超过了当前c[i]的价格,不如单买这一杯所获得的体积大\r\n'''\r\nn,L=map(int,input().split())\r\narr=[int(i) for i in input().split()]\r\nfor i in range(1,n):\r\n arr[i]=min(2*arr[i-1],arr[i])\r\nfor i in range(n,32):\r\n arr.append(2 * arr[i - 1])\r\nans=0\r\nfor i in range(32):\r\n if ans>arr[i]:\r\n ans=arr[i]\r\n if L&(1<<i):\r\n ans+=arr[i]\r\nprint(ans)", "import sys\n\nn, L = map(int, input().split())\ncosts = list(map(int, input().split()))\n\nfor i in range(1, len(costs)):\n # either better to buy one of a_i or two of (a_{i - 1})\n costs[i] = min(2 * costs[i - 1], costs[i])\n\nans, sum = sys.maxsize, 0\nfor i in range(n - 1, -1, -1):\n liters = 2 ** i\n amt = L // liters\n L -= amt * liters\n # try to stop here and buy whatever we need to exceed L (good if the small liters are extremely expensive)\n ans = min(ans, sum + (amt + 1) * costs[i])\n sum += amt * costs[i] # try buying as much as we should to hit exactly L\n\nans = min(ans, sum)\nprint(ans)\n\n \t\t \t \t \t \t \t\t\t \t", "n,L=map(int,input().split())\r\nc=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n c[i]=min(c[i],c[i-1]*2)\r\nans=0 \r\ndef helper(i,rem):\r\n if i==0:\r\n return c[i]*rem \r\n else:\r\n t=1<<i \r\n return c[i]*(rem//t)+min(helper(i-1,rem%t),c[i])\r\n \r\n \r\n\r\nprint(helper(n-1,L))", "\r\ndef solution(T, unitPrices):\r\n if T == 0:\r\n return 0\r\n currentMin = float('inf')\r\n for pair in unitPrices:\r\n if pair[1] > T:\r\n currentMin = min(currentMin, pair[2])\r\n else:\r\n thisVolume = pair[1]\r\n tmpCost = ((T // thisVolume) * pair[2] + solution(T % thisVolume, unitPrices))\r\n currentMin = min(currentMin, tmpCost)\r\n break\r\n return currentMin\r\n \r\nfirstRow = input()\r\nsecondRow = input()\r\n\r\nT = int(firstRow.split(\" \")[1])\r\nN = int(firstRow.split(\" \")[0])\r\n\r\n# print(N, T)\r\n\r\ncosts = []\r\nfor i in range(N):\r\n costs.append(int(secondRow.split(\" \")[i]))\r\n\r\n# print(costs)\r\n\r\nunitPrices = []\r\nfor i in range(N):\r\n volume = pow(2, i)\r\n unitPrice = costs[i] / volume\r\n unitPrices.append((unitPrice, volume, costs[i]))\r\n\r\nunitPrices.sort(key=lambda x:x[0])\r\n\r\n\r\nprint(solution(T, unitPrices))", "n, liters_needed = input().split()\nn = int(n)\nliters_needed = int(liters_needed)\n\nbottle_prices = input().split()\ncheapest_price = [1000000001]*n\n\n\ndef get_liters(bottle_idx):\n return int(2**bottle_idx)\n\n\nfor bottle_idx, price in enumerate(bottle_prices):\n price = int(price)\n cheapest_price[bottle_idx] = int(min(2 * cheapest_price[bottle_idx - 1], price))\n\nprice_conjuncture = 0\nbottles_needed = 1 + (liters_needed // get_liters(n-1))\nmin_price = int(cheapest_price[n-1] * bottles_needed)\n\nfor bottle_idx in range(n - 1, -1, -1):\n if liters_needed <= 0:\n min_price = int(min(min_price, price_conjuncture))\n break\n liters = get_liters(bottle_idx)\n bottles_needed = liters_needed // liters\n if bottles_needed == 0:\n min_price = min(min_price, price_conjuncture + cheapest_price[bottle_idx])\n if bottles_needed > 0:\n liters_needed -= liters * bottles_needed\n price_conjuncture += int(bottles_needed * cheapest_price[bottle_idx])\n\nmin_price = min(min_price, price_conjuncture)\nprint(int(min_price))\n\n \t \t\t \t\t\t\t \t\t \t\t\t\t \t \t\t \t", "from math import ceil, inf\r\ndef put(): return map(int, input().split())\r\n\r\nn,k = put()\r\nl = list(put())\r\n\r\nfor i in range(1,n):\r\n l[i] = min(l[i], 2*l[i-1])\r\n\r\nsum = 0\r\nans = inf\r\nfor i in range(n-1, -1, -1):\r\n q = k // (1<<i)\r\n k %= (1<<i)\r\n z = 0 if k==0 else l[i]\r\n sum += q*l[i]\r\n ans = min(ans, z + sum)\r\nprint(ans)", "n, des = map(int, input().split())\r\nc = list(map(int, input().split()))\r\n\r\nwhile n < 34:\r\n n += 1\r\n c.append(c[-1] * 2)\r\n\r\nfor i in range(1, n):\r\n c[i] = min(c[i], 2 * c[i - 1])\r\n\r\ndes = bin(des)[2:]\r\nwhile len(des) < n:\r\n des = '0' + des\r\n\r\ndes = des[::-1]\r\n\r\nanswer = 0\r\nfor i in range(n):\r\n if des[i] == '1':\r\n answer += c[i]\r\n\r\nfirst_cost = answer\r\nfor i in range(n):\r\n if des[i] == '0':\r\n cur = first_cost + c[i]\r\n for j in range(i):\r\n if des[j] == '1':\r\n cur -= c[j]\r\n answer = min(answer, cur)\r\n\r\nprint(answer)", "from math import inf\r\n\r\n\r\ndef main():\r\n n, l = map(int, input().split())\r\n c = list(map(int, input().split()))\r\n m = [2**i for i in range(n)]\r\n for i in range(1, n):\r\n c[i] = min(c[i], 2 * c[i - 1])\r\n cost = 0\r\n alt_cost = inf\r\n i = -1\r\n while l > 0:\r\n if m[i] <= l:\r\n t = l // m[i]\r\n cost += c[i] * t\r\n l -= t * m[i]\r\n # cost += c[i]\r\n # l -= m[i]\r\n else:\r\n alt_cost = min(alt_cost, cost + c[i])\r\n i -= 1\r\n return min(cost, alt_cost)\r\n\r\n\r\nprint(main())", "n,l = map(int, input().split())\r\ncosts = list(map(int, input().split()))\r\n\r\nfor a in range(1,n):\r\n costs[a] = min(costs[a], 2 * costs[a -1])\r\n# print(costs)\r\n\r\nans = float('inf') \r\nsum = 0\r\n\r\nfor i in range(n - 1, -1, -1):\r\n bit = l // (1 << i) \r\n sum += bit * costs[i] \r\n l -= bit << i \r\n ans = min(ans, sum + (l > 0) * costs[i]) \r\n\r\nprint(ans)", "#for _ in range(int(input())):\r\n\r\n#n,k=map(int, input().split())\r\n#arr = list(map(int, input().split()))\r\n#ls= list(map(int, input().split()))\r\nimport math\r\n#n = int(input())\r\n\r\n#for _ in range(int(input())):\r\n\r\nn,l=map(int,input().split())\r\nll=l\r\ncost=list(map(int,input().split()))\r\nmin_cost=[0]*n\r\nmin_cost[0]=cost[0]\r\nfor i in range(1,n):\r\n\tmin_cost[i]=min(min_cost[i-1]*2,cost[i])\r\nans=0\r\nrealans=10**25\r\n\r\nfor i in range(n-1,-1,-1):\r\n\tif 2**i>=l:\r\n\t\trealans=min(realans,ans+min_cost[i])\r\n\telse:\r\n\t\ttimes=l//2**i\r\n\t\tans+=min_cost[i]*times\r\n\t\tl-=(2**i)*times\r\n\t\tif l==0:\r\n\t\t\trealans=min(realans,ans)\r\n\t\telse:\r\n\t\t\trealans=min(realans,ans+min_cost[i])\r\n\tif l<=0:\r\n\t\tbreak\r\n\t#print(realans)\r\nprint(realans)", "n,L=map(int,input().split())\r\na=[int(x) for x in input().split()]\r\n\r\n#12=1100\r\nfor i in range(1,n):\r\n a[i]=min(a[i],a[i-1]*2)\r\n\r\nans=float('inf')\r\ncos=0\r\n#print(a)\r\nfor i in range(n-1,-1,-1):\r\n tem=L//(1<<i)\r\n cos+=tem*a[i]\r\n L-=tem<<i\r\n #print(\"L\",L)\r\n if L>0:\r\n ans=min(ans,cos+a[i])\r\n else:\r\n ans=min(ans,cos)\r\n \r\nprint(ans)\r\n\r\n\r\n", "from sys import stdin\r\ninput=lambda : stdin.readline().strip()\r\nfrom math import ceil,sqrt,factorial,gcd\r\nfrom collections import deque\r\nfrom bisect import bisect_left,bisect_right\r\nn,k=map(int,input().split())\r\nb=bin(k)[2:][::-1]\r\nl=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n\tl[i]=min(l[i],2*l[i-1])\r\nans=0\r\nfor i in range(max(0,len(b)-len(l))):\r\n\tl.append(l[-1]*2)\r\nfor i in range(len(l)):\r\n\tif i<len(b):\r\n\t\tif b[i]==\"1\":\r\n\t\t\tif 2*l[i]<ans+l[i]:\r\n\t\t\t\tans=2*l[i]\r\n\t\t\telse:\r\n\t\t\t\tans+=l[i]\r\n\t\telse:\r\n\t\t\tif l[i]<ans:\r\n\t\t\t\tans=l[i]\r\n\telse:\r\n\t\tif l[i]<ans:\r\n\t\t\tans=l[i]\r\nprint(ans)\r\n\r\n", "import functools\r\nimport math\r\n\r\ndef compare(a,b):\r\n\tA=a[0]/a[1]\r\n\tB=b[0]/b[1]\r\n\r\n\tif A < B:\r\n\t\treturn -1\r\n\tif A > B:\r\n\t\treturn 1\r\n\tif(A==B):\r\n\t\tif a[1]>b[1]:\r\n\t\t\treturn -1\r\n\t\telse:\r\n\t\t\treturn 1\r\n\t\r\n\r\n\r\nn,L =input().split()\r\nn= int(n)\r\nL = int(L)\r\na = [int(x) for x in input().split()]\r\nv = []\r\n\r\nfor i in range(n):\r\n\tif i==0:\r\n\t\tv.append([a[i],math.pow(2,i)])\r\n\telse:\r\n\t\ta[i] = min(a[i],2*a[i-1])\r\n\t\tv.append([a[i],math.pow(2,i)])\r\n\t\t\r\n#print(v)\r\nv = sorted(v, key=functools.cmp_to_key(compare))\r\n#print(v)\r\n\r\ndef solve(dp,L,m):\r\n\tfor i in range(len(dp)):\r\n\t\tif dp[i][0]<=m:\r\n\t\t\tpp=m//dp[i][0]\r\n\t\t\tm-=(dp[i][0]*pp)\r\n\t\t\tL-=(dp[i][1]*pp)\r\n\t\t\tif L <= 0:\r\n\t\t\t\treturn True\r\n\tif L<=0 :\r\n\t\treturn True\r\n\telse:\r\n\t\treturn False\r\nl = 1\r\nr = 10000000000000000000\r\nres= r\r\n\r\nwhile l <= r:\r\n\tif l == r:\r\n\t\tif solve(v,L,l):\r\n\t\t\tres=min(res,l)\r\n\t\tbreak\r\n\telse:\r\n\t\tm = (l+r)//2;\r\n\t\tif solve(v,L,m) == True:\r\n\t\t\tres=min(res,m)\r\n\t\t\tr=m-1\r\n\t\telse:\r\n\t\t\tl=m+1\r\n\r\nprint(res)", "s = 0\r\nans = 100 ** 1000\r\nn, l = map(int, input().split())\r\na = list(map(int, input().split()))\r\nfor i in range(0,n-1):\r\n a[i+1] = min(a[i+1], 2*a[i])\r\nfor i in range(n-1, -1, -1):\r\n d = l // (1 << i)\r\n s += d * a[i]\r\n l -= d << i;\r\n ans = min(ans, s+(l > 0) * a[i])\r\nprint(ans)", "# tutorial codeforces :(\n# مخم گوزید ناموسا\nn, l = map(int, input().split())\nc = list(map(int, input().split()))\nres = 0\nfor i in range(1, n):\n c[i] = min(c[i - 1]*2, c[i])\np = 1 << (n - 1) # 2 ** (n - 1)\ny = l // p\nl-= y * p\nres+= c[n - 1] * y # y or equal to 0 or y > 0\nRES = []\nif l > 0: # if l not equal to 0 then we can take one more (2 ** (n-1)) and recieve to answer\n RES.append(res + c[n - 1])\n\n\nfor i in range(n - 2, -1, -1):\n p//= 2\n y = l // p\n if y == 1:\n res+= c[i]\n l-= (1 << i)\n if l > 0:\n RES.append(res + c[i])\n else: # y == 0\n if l > 0:\n RES.append(res + c[i])\nRES.append(res)\nprint(min(RES))\n\n\n \n\n\n\n\n", "n, l = map(int, input().split())\r\nc = list(map(int, input().split()))\r\nfor i in range(1, n):\r\n\tc[i] = min(c[i], c[i - 1] * 2)\r\nwhile len(c) < 32:\r\n\tc.append(c[-1] * 2)\r\nz = 0\r\nfor i in range(32):\r\n\tif l >> i & 1:\r\n\t\tz += c[i]\r\n\telse:\r\n\t\tz = min(z, c[i])\r\nprint(z)", "# Asif Islam - asifislam510\nn, L = map(int, input().split())\nc = list(map(int, input().split()))\n\nfor i in range(n - 1):\n c[i + 1] = min(c[i + 1], 2 * c[i])\n\nans = float(\"inf\") # python infinity\nsum_val = 0\n\n# bit shift to quickly due 2 ^ n\nfor i in range(n - 1, -1, -1):\n need = L // (1 << i)\n sum_val += need * c[i]\n L -= need << i\n ans = min(ans, sum_val + (L > 0) * c[i])\n\nprint(ans)\n\n\t\t \t \t\t \t\t \t\t \t \t \t\t \t \t", "n,L=map(int,input().split())\r\na=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n a[i]=min(a[i],a[i-1]*2)\r\nb=bin(L)[2:]\r\nb='0'*(n-len(b))+b\r\nb='0'+b\r\nb=b[::-1]\r\nfor j in range(n,len(b)):\r\n a.append(a[-1]*2)\r\nans=0\r\nfor i in range(len(b)):\r\n if b[i]=='0':\r\n ans=min(ans,a[i])\r\n else:\r\n ans+=a[i]\r\nprint(ans)\r\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, l = map(int, input().split())\r\nc = list(map(int, input().split()))\r\ninf = 4 * pow(10, 18) + 1\r\nfor _ in range(31 - n):\r\n c.append(inf)\r\nn = 31\r\nfor i in range(1, n):\r\n c[i] = min(c[i], 2 * c[i - 1])\r\npow2 = [1]\r\nfor _ in range(n - 1):\r\n pow2.append(2 * pow2[-1])\r\nans = inf\r\ns = 0\r\nfor i, j in zip(c[::-1], pow2[::-1]):\r\n if l < j:\r\n ans = min(ans, s + i)\r\n if l & j:\r\n l ^= j\r\n s += i\r\nans = min(ans, s)\r\nprint(ans)", "ans = 9e18\r\nn, l = map(int, input().split())\r\nc = list(map(int, input().split()))\r\n\r\nfor i in range(1, len(c)):\r\n c[i] = min(c[i], 2 * c[i - 1])\r\nwhile l <= 1 << 30:\r\n z = l\r\n t = 0\r\n for i in range(n - 1, -1, -1):\r\n t += (z >> i) * c[i]\r\n z %= (1 << i)\r\n ans = min(ans, t)\r\n l += l & -l\r\nprint(ans)", "n, l=[int(k) for k in input().split()]\r\nw=[int(k) for k in input().split()]\r\nw=[[2**k, w[k]] for k in range(n)]\r\nw.sort(key=lambda x: x[1]*2**30//x[0])\r\nres=0\r\nc=0\r\nnew=[]\r\nwhile l>0:\r\n if l>=w[c][0]:\r\n res+=(l//w[c][0])*w[c][1]\r\n l=l%w[c][0]\r\n if l!=0:\r\n new.append(res+w[c][1])\r\n else:\r\n new.append(res)\r\n else:\r\n new.append(res+w[c][1])\r\n c+=1\r\nprint(sorted(new)[0])", "n,l=map(int,input().split())\r\ncost=list(map(int,input().split()))\r\nfor i in range(1,n):\r\n cost[i]=min(cost[i],2*cost[i-1])\r\nans=float(\"inf\")\r\ns=0\r\nfor i in range(n-1,-1,-1):\r\n litres=1<<i\r\n req=l//litres\r\n s+=cost[i]*req\r\n l=l%litres\r\n ans=min(ans,s+(l!=0)*cost[i])\r\nprint(ans)", "def my_sort(listt,column=0):\r\n a=column\r\n if len(listt)<=1:\r\n return listt\r\n else:\r\n mid=len(listt)//2\r\n return merge(my_sort(listt[:mid],column=a),my_sort(listt[mid:],column=a),column=a)\r\ndef merge(listt1,listt2,column):\r\n i=0\r\n j=0\r\n listt=[]\r\n while i<len(listt1) and j<len(listt2):\r\n if listt1[i][column]<listt2[j][column]:\r\n listt.append(listt1[i])\r\n i+=1\r\n \r\n else:\r\n listt.append(listt2[j])\r\n j+=1\r\n while i<len(listt1):\r\n listt.append(listt1[i])\r\n i+=1\r\n while j<len(listt2):\r\n listt.append(listt2[j])\r\n j+=1\r\n return listt\r\n \r\ndef int_input():\r\n return int(input())\r\ndef list_input():\r\n return list(map(int,input().split()))\r\ndef list_str_input():\r\n return list(input())\r\ndef str_input():\r\n return input()\r\ndef gcd(a,b):\r\n maxi=max(a,b)\r\n mini=min(a,b)\r\n while mini!=0:\r\n a=maxi%mini\r\n maxi=mini\r\n mini=a\r\n return maxi\r\n \r\n \r\n \r\n \r\n \r\n \r\n########om namah shivay#######\r\nimport math\r\nn,m=map(int, input().split())\r\ns=list_input()\r\narray=[]\r\nfor j in range(n):\r\n array.append([s[j],j,math.log2(s[j])+n-j-1])\r\narray=my_sort(array,column=2)\r\nans=0\r\nindi=0\r\nsum=0\r\n#print(array)\r\nlistt=[]\r\nleft=m\r\nwhile left>0:\r\n a=2**array[indi][1]\r\n b=(left//a)\r\n if left%a!=0:\r\n x=1+b\r\n else:\r\n x=b\r\n now=sum+array[indi][0]*x\r\n listt.append(now)\r\n \r\n sum+=array[indi][0]*b\r\n left-=a*b\r\n indi+=1\r\nlistt.append(sum)\r\nprint(min(listt))", "def solution():\n def solve(l,nums):\n import math\n\n for i in range(len(nums) - 1):\n nums[i+1] = min(nums[i+1], nums[i] * 2)\n maxCost = math.inf\n currTot = 0\n for i in range(len(nums) - 1, -1, -1):\n currCost = l // (1 * (2**i))\n currTot += currCost * nums[i]\n l -= currCost * (2**i)\n maxCost = min(maxCost, currTot + (nums[i] if l > 0 else 0))\n return maxCost\n n,l = [int(x) for x in input().split()]\n nums = [int(x) for x in input().split()]\n print(solve(l,nums))\nsolution()\n\t\t\t\t \t\t \t\t\t\t \t\t \t \t \t \t", "n, l = map(int, input().split())\r\na = list(map(int, input().split()))\r\nfor i in range(0, n-1):\r\n a[i+1] = min(a[i+1], 2*a[i])\r\ns = 0\r\nans = 100**100\r\nfor i in range(n-1, -1, -1):\r\n d = l // (1<<i)\r\n s += d * a[i]\r\n l -= d<<i;\r\n ans = min(ans, s+(l>0)*a[i])\r\nprint(ans)", "import sys\ninput = sys.stdin.readline\n\n\ndef solve(n, L, C):\n cpl = [(float(2**i)/float(C[i]), i) for i in range(n)]\n cpl.sort(key=lambda x:x)\n res = 0\n ans = float(\"inf\")\n while cpl and L > 0:\n unit, idx = cpl.pop()\n ans = min(ans, res + C[idx] * ((L // (2 ** idx)) + 1))\n res += C[idx] * (L // (2 ** idx))\n L -= (2**idx) * (L // (2**idx))\n\n if L == 0:\n print(min(res, ans))\n else:\n print(ans)\n\n\nn, L = map(int, input().split())\nC = list(map(int, input().split()))\nsolve(n, L, C)", "n, L = map(int, input().split())\r\nA = list(map(int, input().split())) + [1 << 64] * 30\r\nn += 30\r\nfor i in range(1, n):\r\n A[i] = min(A[i], A[i - 1] * 2);\r\ncur = 0\r\nnow_cost = 0\r\nans = 1 << 64\r\nfor i in range(n - 1, -1, -1):\r\n if (cur | (1 << i)) >= L:\r\n ans = min(ans, now_cost + A[i])\r\n else:\r\n cur |= 1 << i\r\n now_cost += A[i]\r\nprint(ans)", "import random\r\nimport sys\r\nimport math\r\n\r\nn, target = [int(x) for x in input().split()]\r\nprecos = [int(x) for x in input().split()]\r\nefic = [(2**i) / precos[i] for i in range(n)]\r\n\r\n\r\ndef solve(k, limite):\r\n maisEff = 0\r\n for i in range(limite):\r\n if efic[i] > efic[maisEff]:\r\n maisEff = i\r\n \r\n\r\n comprasIdeal = math.ceil(k/(2**maisEff))\r\n precoIdeal = comprasIdeal * precos[maisEff]\r\n litrosIdeal = comprasIdeal * (2 ** maisEff)\r\n\r\n if litrosIdeal == k:\r\n return precoIdeal\r\n \r\n comprasRedux = comprasIdeal - 1\r\n precoRedux = comprasRedux * precos[maisEff]\r\n litrosRedux = comprasRedux * (2 ** maisEff)\r\n \r\n return min(precoIdeal, precoRedux + solve(k - litrosRedux, maisEff))\r\n\r\nprint(solve(target, n))\r\n\r\n \r\n", "from collections import defaultdict\r\nfrom math import ceil\r\ndef f(a,k):\r\n\tfor i in range(1,len(a)):\r\n\t\ta[i]=min(a[i],2*(a[i-1]))\r\n\tans=float(\"inf\")\r\n\ts=0\r\n\tfor i in range(len(a)-1,-1,-1):\r\n\t\tneed=k//(1<<i)\r\n\t\ts+=need*a[i]\r\n\t\tk-=(need<<i)\r\n\t\tans=min(ans,s+(((k>0)*a[i])))\r\n\treturn ans\r\n\r\nn,k=map(int,input().strip().split())\r\nl=[*map(int,input().strip().split())]\r\nprint(f(l,k))", "n, L = map(int, input().split())\nc = list(map(int, input().split()))\n\nfor i in range(n - 1):\n c[i + 1] = min(c[i + 1], c[i] * 2)\n\nres = float('inf')\nmid = 0\n\nfor i in range(n - 1, -1, -1):\n currVolume = 2 ** i\n need = L // currVolume\n \n mid += need * c[i]\n L -= need * currVolume\n \n if L > 0:\n res = min(res, mid + c[i])\n else:\n res = min(res, mid)\n\nprint(res)\n\n \t\t\t\t\t\t \t\t \t \t\t \t\t \t \t\t\t\t\t \t \t" ]
{"inputs": ["4 12\n20 30 70 90", "4 3\n10000 1000 100 10", "4 3\n10 100 1000 10000", "5 787787787\n123456789 234567890 345678901 456789012 987654321", "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390133 65783782 988164990 606389825 877178711 513188067 609539702 558894975 271129128 956393790 981348376 608410525 61890513 991440277 682151552", "30 719520853\n1 3 7 9 21 44 81 49 380 256 1592 1523 4711 6202 1990 48063 112547 210599 481862 1021025 2016280 643778 4325308 3603826 20964534 47383630 100267203 126018116 187142230 604840362", "30 604179824\n501412684 299363783 300175300 375965822 55881706 96888084 842141259 269152598 954400269 589424644 244226611 443088309 914941214 856763895 380059734 9424058 97467018 912446445 609122261 773853033 728987202 239388430 617092754 182847275 385882428 86295843 416876980 952408652 399750639 326299418", "1 1000000000\n1000000000", "1 1\n1", "30 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "5 25\n52 91 84 66 93", "10 660\n2316 3782 9667 4268 4985 2256 6854 9312 4388 9913", "20 807689532\n499795319 630489472 638483114 54844847 209402053 71113129 931903630 213385792 726471950 950559532 396028074 711222849 458354548 937511907 247071934 160971961 333550064 4453536 857363099 464797922", "30 842765745\n2 2 2 4 6 8 12 12 18 28 52 67 92 114 191 212 244 459 738 1078 1338 1716 1860 1863 2990 4502 8575 11353 12563 23326", "1 1\n1000000000", "1 1000000000\n1", "30 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "30 1000000000\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", "30 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "1 570846883\n300888960", "2 245107323\n357416000 761122471", "3 624400466\n824008448 698922561 760128125", "5 972921345\n496871039 134331253 959524096 747165691 981088452", "8 700735368\n931293374 652764228 183746499 853268148 653623691 684604018 902322304 186452621", "13 695896744\n495801986 946818643 421711713 151976207 616318787 713653645 893406153 42255449 871957806 865208878 547381951 478062469 516417162", "21 186982676\n261355063 273322266 663309548 981847874 432074163 204617748 86151188 381783810 725544703 947880176 870951660 226330358 680228931 959825764 972157951 874066182 208942221 587976360 749662969 377541340 841644620", "29 140874704\n948286516 335531500 165926134 633474522 606947099 21370216 16126534 254131475 624116869 824903957 541685498 351709345 925541565 253434732 759289345 168754543 993046389 636985579 332772332 103110829 311797311 739860627 233674609 950017614 387656468 939870312 161573356 176555912 592529105", "6 566613866\n1 3 3 16 11 13", "11 435675771\n2 2 2 4 4 5 5 8 10 18 21", "13 688240686\n2 4 1 15 7 1 34 129 295 905 1442 1198 3771", "15 645491742\n2 2 2 2 3 3 4 8 10 14 19 37 42 74 84", "29 592983020\n2 3 7 8 30 45 125 132 124 61 1231 1626 7470 14538 18828 35057 34820 219967 359159 362273 1577550 2434174 1736292 15104217 17689384 39467552 50809520 13580992 414752454", "29 42473833\n13 18 21 32 45 72 134 203 320 342 400 565 1039 1093 2142 3383 5360 7894 13056 17053 26524 38453 63285 102775 156618 252874 304854 600862 857837", "28 48504243\n1 1 6 1 32 37 125 212 187 676 1679 771 485 9030 1895 26084 109430 96769 257473 383668 645160 1550917 6195680 6309095 16595706 13231037 99591007 255861473", "28 17734553\n13 22 33 59 93 164 166 308 454 532 771 898 1312 2256 3965 5207 6791 13472 13793 26354 47030 68133 118082 199855 221897 257395 417525 536230", "27 358801274\n2 3 6 10 2 30 124 35 249 268 79 4013 1693 3522 17730 17110 52968 235714 155787 405063 1809923 667660 2266461 14291190 15502027 54103386 14154765", "27 437705674\n13 13 21 21 25 31 49 83 148 243 246 263 268 282 475 867 1709 3333 4587 5947 11467 22629 25843 31715 34392 45690 47657", "26 519355202\n2 2 6 3 4 23 124 115 312 883 526 3158 2901 14398 797 8137 127577 112515 54101 426458 877533 3978708 6725849 5496068 14408348 27866871", "26 707933691\n13 17 31 44 69 70 89 158 246 320 605 934 1635 2364 4351 8660 10262 11664 14090 18908 35845 51033 59963 78775 117479 179510", "25 269843721\n1 4 5 12 6 16 123 195 374 475 974 2303 4109 8890 16632 64699 71115 251461 476703 447854 2042296 3095451 2796629 13478163 13314670", "25 978161707\n13 22 24 34 66 73 145 287 289 521 693 996 1230 1486 1517 2663 3770 3776 5286 7953 15775 30877 42848 84850 114828", "5 304398130\n328619601 758941829 198270024 713154224 371680309", "10 354651161\n676522959 11809337 625434179 312329830 399019943 545095979 566206452 292370104 819250687 361397475", "10 907948615\n369010656 907829481 622481545 200317148 960270397 26028213 655060035 796833494 123373353 324969455", "10 590326547\n540224591 578261545 271951966 787805881 165741203 795359732 547118852 746648763 284153835 602102300", "20 264504887\n256244331 292829612 807171068 120710 900798902 214013876 575261859 40214283 293542999 366877272 353675296 705322168 205009788 86530854 620744650 766826836 240331588 700218303 406369581 649737981", "20 749478720\n148277091 195065491 92471169 473441125 104827125 387256363 959435633 241640 395794406 734016994 107553118 129783960 812331272 999596018 837854100 215240378 598412225 653614923 933185587 845929351", "20 628134337\n706690396 73852246 47785764 655257266 217430459 211108098 623632685 631391825 628008556 962083938 616573502 326152383 7023992 288143889 264733804 886206130 342256543 779010688 657787839 476634612", "20 708413057\n985177466 224645388 772550594 994150052 856456221 65855795 599129505 903908498 200612104 575185982 507918207 574454347 607410366 738301336 274020952 556522307 665003603 363184479 760246523 952436964", "20 228553575\n966247381 207786628 69006100 269956897 359963312 510868514 95130877 473280024 180071136 34097367 898985854 981155909 369570614 803892852 773207504 603654899 500850166 632114017 442730466 348136258", "25 975185569\n680624205 925575600 711019438 10306 879760994 355425133 204004301 536007340 585477874 216944098 296555029 104013726 892946593 309410720 689188172 687796636 375461496 689356349 680367324 137692780 879054435 925597905 677631315 592123801 742526898", "30 16804972\n38413642 603358594 93465125 772633637 516421484 75369617 249460374 6747 89975200 3230679 944379663 407211965 820471861 763861258 4711346 787274019 447412797 861015104 104795044 430023687 445411345 316560503 908322702 232775431 33149898 101978638 453254685 587956325 920401353 237657930", "30 939625169\n799744449 316941501 911543330 868167665 272876554 951480855 826347879 102948940 684991931 833689399 277289558 186462 220073415 602419892 22234767 320279157 908288280 357866038 758158565 784960311 772460297 956631291 623631325 328145434 76400621 637950037 63094834 358429163 210185094 824743978", "30 649693919\n523756282 905125099 661420695 854128708 504404014 33547776 632846834 593955985 19432317 644543651 552904895 988070696 321825330 923971248 718082642 900061181 310986828 14810582 525301 623288859 578749693 424452633 901712228 411022879 757920556 825042513 796572495 544557755 747250675 987028137", "30 941342434\n719914212 905507045 191898825 570606628 687781371 937025497 673960221 557202851 29071681 518803370 894863536 212709126 614432746 924724833 699415275 748075226 796159664 198063404 56538360 649136911 46540367 337023198 45896775 548611961 777908744 873523820 99863819 335685200 503317538 894159729", "30 810430346\n807519316 377786333 874568334 100500951 872031247 252690899 923103133 769288634 300502982 184749135 481527896 932556233 978317077 980235169 677287 308980653 527243473 763242606 219639015 712288933 901059456 30978091 127839849 9946626 456644060 226102694 611552752 816642473 434613587 723611518", "30 187125289\n660214771 614231774 943973836 50780694 214277957 695192266 425421684 100830325 236002350 233594142 318777769 611117973 758216803 141783036 487402819 42225289 132824573 354540681 64152506 838447015 853800951 605421421 151364012 455396619 928950961 236389207 47829341 743089941 577129072 792900471", "30 129428748\n954910836 756938357 407311375 992660029 134837594 230127140 815239978 545145316 559077075 373018190 923169774 981420723 349998683 971610245 428903049 879106876 229199860 842029694 817413103 141736569 236414627 263122579 394309719 946134085 550877425 544748100 732982715 933907937 67960170 145090225", "30 12544876\n528459681 350718911 432940853 266976578 679316371 959899124 158423966 471112176 136348553 752311334 979696813 624253517 374825117 338804760 506350966 717644199 528671610 10427712 256677344 288800318 711338213 778230088 616184102 968447942 275963441 257842321 753599064 812398057 815035849 207576747", "30 7\n476599619 58464676 796410905 224866489 780155470 404375041 576176595 767831428 598766545 225605178 819316136 781962412 217423411 484904923 194288977 597593185 181464481 65918422 225080972 53705844 584415879 463767806 845989273 434760924 477902363 145682570 721445310 803966515 927906514 191883417", "30 9324\n205304890 806562207 36203756 437374231 230840114 828741258 227108614 937997270 74150322 673068857 353683258 757136864 274921753 418595773 638411312 307919005 304470011 439118457 402187013 371389195 981316766 26764964 293610954 177952828 49223547 718589642 982551043 395151318 564895171 138874187", "30 512443535\n2 10 30 20 26 9 2 4 24 25 4 27 27 9 13 30 30 5 3 24 10 4 14 14 8 3 2 22 25 25", "30 553648256\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "30 536870912\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "30 504365056\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "30 536870913\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "30 536870911\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "30 571580555\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913", "1 1000000000\n1", "4 8\n8 4 4 1", "2 3\n10 1", "30 915378355\n459233266 779915330 685344552 78480977 949046834 774589421 94223415 727865843 464996500 268056254 591348850 753027575 142328565 174597246 47001711 810641112 130836837 251339580 624876035 850690451 290550467 119641933 998066976 791349365 549089363 492937533 140746908 265213422 27963549 109184295", "3 7\n20 20 30", "1 1000000000\n1000000000", "5 787787787\n1 2 3 4 5", "2 3\n10 5", "28 146201893\n79880639 962577454 837935105 770531287 992949199 401766756 805281924 931353274 246173135 378375823 456356972 120503545 811958850 126793843 720341477 413885800 272086545 758855930 979214555 491838924 465216943 706180852 786946242 646685999 436847726 625436 360241773 620056496", "5 9\n2 100 100 10 13", "1 134217728\n1000000000", "1 536870912\n1000000000", "5 5\n34 22 21 20 30", "1 787787787\n1", "7 7\n34 22 21 20 30 20 20", "5 5\n34 22 21 25 30", "5 787787787\n123456789 234567890 345678901 456789012 1", "6 6\n34 22 21 25 30 35"], "outputs": ["150", "10", "30", "44981600785557577", "371343078", "87393281", "564859510", "1000000000000000000", "1", "2000000000", "186", "13164", "27447142368", "42251", "1000000000", "1000000000", "1000000000", "2", "1", "171761524945111680", "87605278957368000", "118656089186285061", "59657618590751221", "1020734127854016", "87737726572314", "134782258380", "338129268", "230186887", "8934765", "21507522", "3309432", "61009202", "304854", "5610124", "257395", "27680968", "333599", "25264103", "3829673", "101191398", "6718647", "7071174590398871", "250332233709431", "437565141462561", "655248513971940", "327898333295", "1209345077739", "571078505096", "1287105522843", "151787408488", "43630079726", "34613997", "766068050", "1213432868", "1443990241", "964822722", "143488023", "67960170", "207576747", "53705844", "26764964", "16", "553648259", "536870913", "504365061", "536870915", "536870913", "571580565", "1000000000", "1", "2", "111854196", "60", "1000000000000000000", "246183685", "10", "3127180", "12", "134217728000000000", "536870912000000000", "20", "787787787", "20", "25", "49236737", "25"]}
UNKNOWN
PYTHON3
CODEFORCES
46
1ccc257b517cd0fd9a4117df8d25e6ba
Broken Clock
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. You 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. For 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. The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The 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. The 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. Sample Input 24 17:30 12 17:30 24 99:99 Sample Output 17:30 07:30 09:09
[ "def f(x):\r\n if(x==0): return(\"00\")\r\n elif(len(str(x))==1): return(\"0\"+str(x))\r\n else: return (str(x))\r\n\r\ndef ch(a,b):\r\n q=0\r\n for i in range(len(a)): q+=int(a[i]!=b[i])\r\n return q\r\n\r\ntf=int(input())\r\ntime=[x for x in input().split(':')]\r\nhr12=[]\r\nhr24=[]\r\nmins=[]\r\nfor i in range(1,13): hr12.append(f(i))\r\nfor i in range(24): hr24.append(f(i))\r\nfor i in range(60): mins.append(f(i))\r\n\r\nans=10\r\nif(tf==12):\r\n for x in hr12:\r\n ans=min(ans,ch(time[0],x))\r\nelse:\r\n for x in hr24:\r\n ans=min(ans,ch(time[0],x))\r\na2=10\r\nfor x in mins:\r\n a2=min(a2,ch(x,time[1]))\r\n\r\nfin=[None,None]\r\nif(tf==12):\r\n for x in hr12:\r\n if(ch(x,time[0])==ans):\r\n fin[0]=x\r\nelse:\r\n for x in hr24:\r\n if(ch(time[0],x)==ans):\r\n fin[0]=x\r\nfor x in mins:\r\n if(ch(x,time[1])==a2):\r\n fin[1]=x\r\n\r\nprint(':'.join(fin))\r\n\r\n", "n = input()\nhour = input()\nhour = list(hour)\n\nif n == '24':\n if int(hour[0]+hour[1]) > 23:\n hour[0] = '0'\n if int(hour[3]+hour[4]) > 59:\n hour[3] = '0'\nelse:\n if int(hour[0]+hour[1]) > 12:\n hour[0] = '0'\n if int(hour[0]+hour[1]) == 0:\n hour[0] = '1'\n if int(hour[3]+hour[4]) > 59:\n hour[3] = '0'\n\nprint(\"\".join(hour))", "n=int(input())\r\na=input()\r\nx=int(a[:2])\r\ny=int(a[3:])\r\nif(n==12):\r\n\tif(x==0):\r\n\t\ta=\"10\"+a[2:]\r\n\telif(x>12):\r\n\t\tif(a[1]==\"0\"):\r\n\t\t\ta=\"1\"+a[1:]\r\n\t\telse:\r\n\t\t\ta=\"0\"+a[1:]\r\n\tif(y>59):\r\n\t\ta=a[:3]+\"0\"+a[-1]\r\nelse:\r\n\tif(x>23):\r\n\t\ta=\"0\"+a[1:]\r\n\tif(y>59):\r\n\t\ta=a[:3]+\"0\"+a[-1]\r\nprint(a)\r\n ", "n = int(input())\na, b = map(int, input().split(':'))\n\nwhile b > 59:\n\tb -= 10\n\nif 12 == n:\n\twhile a <= 0:\n\t\ta += 10\n\n\twhile a > 12:\n\t\ta -= 10\n\nif 24 == n:\n\twhile a >= 24:\n\t\ta -= 10\n\nprint('%02d:%02d'%(a, b))\n\n# 1511879405647\n", "n = int(input())\r\ns,s2 = input().split(\":\")\r\nif n == 24:\r\n\tif s >= \"24\":\r\n\t\ts = \"0\"+s[1]\r\nelse:\r\n\tif s >= \"13\":\r\n\t\ts = \"0\"+s[1]\r\n\tif s == \"00\":\r\n\t\ts = \"10\"\r\nif s2 >= \"60\":\r\n\ts2 = \"1\"+s2[1]\r\nprint(s+\":\"+s2)\r\n", "def relogio(formato, hora):\n\ta = int(hora.split(\":\")[0])\n\tb = int(hora.split(\":\")[1])\n\t\n\tif formato == 12:\n\t\tif a > 12 and a % 10 != 0:\n\t\t\ta = a % 10\n\t\telif (a > 12 or a < 1) and a % 10 == 0:\n\t\t\ta = (a % 10) + 10\t\t\t\t\t\t\n\telse:\n\t\tif a > 23 and a % 10 != 0:\n\t\t\ta = a % 10\n\t\telif a > 23 and a % 10 == 0:\n\t\t\ta = (a % 10) + 10\t\t\n\t\n\tif b > 59 and b % 10 != 0:\n\t\tb = b % 10\n\telif b > 59 and b % 10 == 0:\n\t\tb = (b % 10) + 10\n\t\t\n\treturn(\"%02d:%02d\" %(a,b))\n\n\nformato = int(input())\nhora = input()\nprint(relogio(formato, hora))\n\n\t\t\t \t\t\t \t\t \t\t\t\t\t \t \t \t", "n = int(input())\r\nh, m = input().split(\":\")\r\nif m[0] >= '6':\r\n m = '0' + m[1]\r\nif n == 12:\r\n if h[1] == '0' and h[0] != '1':\r\n h = \"10\"\r\n elif h > \"12\":\r\n h = '0' + h[1]\r\nelif n == 24:\r\n if h >= \"24\":\r\n h = \"1\" + h[1]\r\nprint(h + \":\" + m)\r\n", "from itertools import product\r\nfrom functools import reduce\r\nt=['{0:02d}:{1:02d}'.format(h, m) for h, m in product(range(24) if input()=='24' else range(1, 13), range(60))]\r\ns=input()\r\nf=lambda t: sum(1 for i, j in zip(s, t) if i!=j)\r\nprint(reduce(lambda x, y: x if f(x)<f(y) else y, t))", "from collections import defaultdict\r\nimport sys, os, math\r\n\r\nif __name__ == \"__main__\":\r\n #n, m = list(map(int, input().split()))\r\n #sys.stdout.flush()\r\n s = input()\r\n time = input()\r\n ans = ''\r\n num = 0\r\n num += int(time[1])\r\n num += 10 * int(time[0])\r\n if s == \"12\":\r\n if num >= 1 and num <= 12:\r\n ans += time[:2]\r\n else:\r\n if time[1] == '0':\r\n ans += \"10\"\r\n else:\r\n ans += ('0' + time[1])\r\n else:\r\n if num >= 0 and num <= 23:\r\n ans += time[:2]\r\n else: \r\n ans += ('0' + time[1]) \r\n ans += \":\"\r\n if time[3] not in \"012345\":\r\n ans += \"0\"\r\n else:\r\n ans += time[3]\r\n ans += time[4]\r\n print(ans)\r\n \r\n \r\n \r\n ", "time = int(input())\nx = input()\na = int(x[0])\nb = int(x[1])\nc = int(x[3])\nd = int(x[4])\n\nif time == 12:\n if a==0 and b == 0: b = 1\n elif a > 1 and b > 0: a = 0\n elif a > 1 and b==0: a = 1\n elif a == 1 and b > 2: b = 0\n if c > 5: c = 0\n\nelse:\n if a>2: a = 0\n elif a == 2 and b > 3: b = 0\n if c>5: c = 0\n\nprint(\"{}{}:{}{}\".format(a, b, c, d))\n", "c = input()\nh, m = list(map(int, input().split(':')))\nif m >= 60:\n\tm %= 10\nif c == '12' and h == 0:\n\th = 1\nelif c == '12' and h > 12:\n\tif h % 10:\n\t\th %= 10\n\telse:\n\t\th = 10\nelif c == '24' and h > 23:\n\th %= 10\nprint('%02d:%02d' % (h,m))\n\t \t\t \t\t \t \t\t \t\t \t\t \t", "n = int(input())\ns,s2 = input().split(\":\")\nif n == 24:\n\tif s >= \"24\":\n\t\ts = \"0\"+s[1]\nelse:\n\tif s >= \"13\":\n\t\ts = \"0\"+s[1]\n\tif s == \"00\":\n\t\ts = \"10\"\nif s2 >= \"60\":\n\ts2 = \"1\"+s2[1]\nprint(s+\":\"+s2)", "def brocken_clock(n, s):\r\n t = list(s)\r\n if n == 24:\r\n if int(t[0]) > 2:\r\n t[0] = '1'\r\n if t[0] == '2' and int(t[1]) > 3:\r\n t[1] = '0'\r\n else:\r\n if int(t[0]) > 1:\r\n if t[1] == '0':\r\n t[0] = '1'\r\n else:\r\n t[0] = '0'\r\n if t[0] == '1' and int(t[1]) > 2:\r\n t[1] = '1'\r\n if t[0] == '0' and t[1] == '0':\r\n t[1] = '1'\r\n if int(t[3]) >= 6:\r\n t[3] = '0'\r\n return ''.join(t)\r\n\r\n\r\nm = int(input())\r\nz = input()\r\nprint(brocken_clock(m, z))\r\n", "#!/usr/bin/env\tpython\n#-*-coding:utf-8 -*-\nn=input()[0]\nh,m=map(int,input().split(':'))\nif 23<h or'2'>n and not 0<h<13:h=1+(9+h)%10\nif 59<m:m-=40\nprint('{:02}:{:02}'.format(h,m))\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ns = input()[:-1]\r\na = s[:2]\r\nb = s[3:]\r\nif n == 12:\r\n if a[0] == '0':\r\n if a[1] == '0':\r\n a = '01'\r\n elif a[0] == '1':\r\n if int(a[1]) > 2:\r\n a = '10'\r\n else:\r\n if a[1] == '0':\r\n a = '10'\r\n else:\r\n a = '0' + a[1]\r\nelse:\r\n if a[0] == '2':\r\n if int(a[1]) > 3:\r\n a = '20'\r\n elif int(a[0]) > 2:\r\n a = '0' + a[1]\r\n\r\nif int(b[0]) > 5:\r\n b = '0' + b[1]\r\nprint(a+':'+b)", "a=input()\r\ns=input()\r\nind=s.index(':')\r\nh=s[0:ind]\r\nm=s[ind+1:]\r\ncount=0\r\nif a=='12':\r\n if (int(h)>=1 and int(h)<=12) and (int(m)>=0 and int(m)<=59):\r\n print(s)\r\n else:\r\n if not (int(h)>=1 and int(h)<=12):\r\n if h[len(h)-1]=='0':\r\n h=''+'1'+h[len(h)-1]\r\n else:\r\n h=''+'0'+h[len(h)-1]\r\n if not (int(m)>=0 and int(m)<=59):\r\n m=''+'0'+m[1]\r\n print(h+':'+m)\r\nelse:\r\n if (int(h)>=0 and int(h)<=23) and (int(m)>=0 and int(m)<=59):\r\n print(s)\r\n else:\r\n if not (int(h)>=0 and int(h)<=23):\r\n h=''+'1'+h[1]\r\n if not (int(m)>=0 and int(m)<=59):\r\n m=''+'0'+m[1]\r\n print(h+':'+m)", "\ndef change(n):\n #seperate digits\n d2 = n%10\n n = n//10\n d1 = n\n if d1 == 0 or d2 == 0:\n d1 = 1\n else:\n d1 = 0\n\n return d1*10+d2\n \n#input\nfrmat = int(input())\ntime = input()\ntime = time.strip().split(\":\")\n\nhh = int(time[0])\nmm = int(time[1])\ndel(time)\n\n#processing\nif frmat == 12:\n if hh == 0 or hh > 12:\n hh = change(hh)\nif frmat == 24:\n if hh > 23:\n hh = change(hh)\nif mm > 59:\n mm = change(mm)\n\n#output\nhrs = str(hh)\nmins = str(mm)\nif hh < 10:\n hrs = \"0\" + hrs\nif mm < 10:\n mins = \"0\" + mins\n\nprint(f\"{hrs}:{mins}\")\n\n\t\t \t\t \t\t \t \t\t \t \t\t\t\t \t", "time_format = input()\r\nhours, minutes = input().split(':')\r\nif time_format == '12':\r\n if not 1 <= int(hours) <= 12:\r\n if hours[1] != '0':\r\n hours = '0' + hours[1]\r\n else:\r\n hours = '10'\r\nif time_format == '24':\r\n if not 0 <= int(hours) <= 23:\r\n hours = '1' + hours[1]\r\nif not 0 <= int(minutes) <= 59:\r\n minutes = '1' + str(minutes)[1]\r\nprint(':'.join([hours, minutes]))", "t = input()\ntime = input().split(':')\nh = int(time[0])\nm = int(time[1])\n\nif (m >= 60):\n m = m%10\n\nif t == '12':\n \n if h >= 13 or h ==0:\n \n if h%10==0:\n h = 10\n else:\n h = h%10\nelse:\n\n if h >= 24:\n h = h%10\n\nprint('%02d:%02d' %(h,m))\n# 1511879868160\n", "def main():\n s = input() == \"12\"\n h, m = map(int, input().split(':'))\n if not 0 <= h - s < (2 - s) * 12:\n h = (h - s) % ((2 - s) * 10) + s\n print(\"{:0>2d}:{:0>2d}\".format(h, m % 60))\n\n\nif __name__ == '__main__':\n main()\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nx = int(input())\r\nhm = list(input().rstrip())\r\ns = [\"0\"] * 5\r\ns[2] = \":\"\r\nl = 0 if x ^ 12 else 1\r\nr = 24 if x ^ 12 else 13\r\nans = \"?\"\r\nd = 5\r\nfor i in range(l, r):\r\n s[0], s[1] = str(i // 10), str(i % 10)\r\n for j in range(60):\r\n s[3], s[4] = str(j // 10), str(j % 10)\r\n d0 = 0\r\n for k in range(5):\r\n if not hm[k] == s[k]:\r\n d0 += 1\r\n if d > d0:\r\n d = d0\r\n ans = \"\".join(s)\r\nprint(ans)", "\r\n\r\na = int(input())\r\nb = input()\r\nc = b[0:2]\r\nd = b[3:5]\r\n\r\nif a == 12:\r\n if c[0] == '0':\r\n if c[1] == '0':\r\n c = c[0] + '1'\r\n elif c[0] == '1':\r\n if int(c[1]) > 2:\r\n c = c[0] + '1'\r\n else:\r\n if c[1] == '0':\r\n c = '1' + c[1]\r\n else:\r\n c = '0' + c[1]\r\nelif a == 24:\r\n if int(c[0]) > 2:\r\n c = '0' + c[1]\r\n elif c[0] == '2':\r\n if int(c[1]) > 3:\r\n c = c[0] + '0'\r\n\r\nif int(d[0]) > 5:\r\n d = '0' + d[1]\r\n\r\n\r\nprint(c + ':' + d)\r\n ", "n=input()[0]\r\nh,m=map(int,input().split(':'))\r\nif 23<h or '2'>n and not 0<h<13:h=1+(9+h)%10\r\nif 59<m:m-=40\r\nprint('{:02}:{:02}'.format(h,m))", "f= input()\r\na= input().split(\":\")\r\nh= int(a[0])\r\nm= int(a[1])\r\nif f==\"12\":\r\n if h>0 and h<=12:\r\n b= a[0]+\":\"\r\n elif h==0:\r\n b= \"10:\"\r\n else:\r\n if a[0][1]==\"0\":\r\n b= \"10:\"\r\n else:\r\n b= \"0\"+a[0][1]+\":\"\r\nelse:\r\n if h>=0 and h<24:\r\n b= a[0]+\":\"\r\n else:\r\n b= \"0\"+a[0][1]+\":\"\r\nif m>59:\r\n b+= \"0\"+a[1][1]\r\nelse:\r\n b+= a[1]\r\nprint(b)", "# LUOGU_RID: 101646528\nn = int(input())\r\nh, m = map(int,input().split(':'))\r\nif h >= 24 or n == 12 and not 1 <= h <= 12:\r\n h = (h + 9) % 10 + 1\r\nif m >= 60:\r\n m -= 40\r\nprint(f'{h:02}:{m:02}')", "form = int(input())\r\nh, m = input().split(':')\r\nh1, m1 = map(int, (h, m))\r\nif m[0] >= '6':\r\n m = '0' + m[1]\r\nif form == 24:\r\n if h1 > 23:\r\n h = '0' + h[1]\r\nif form == 12:\r\n if h1 == 0:\r\n h = '01'\r\n elif h1 > 12 and h1 % 10 == 0:\r\n h = '1' + h[1]\r\n elif h1 > 12:\r\n h = '0' + h[1]\r\nprint(h, m, sep = ':')\r\n", "n = int(input())\r\nif n == 12:\r\n time = list(input())\r\n if time[3] > '5':\r\n time[3] = '2'\r\n if (time[0] == '0' and time[1] == '0'):\r\n time[0] = '1'\r\n if time[0] > '1':\r\n if time[1] != '0':\r\n time[0] = '0'\r\n else:\r\n time[0] = '1'\r\n\r\n if time[0] == '1' and time[1] > '2':\r\n time[1] = '1'\r\n print(''.join(time))\r\nelse:\r\n time = list(input())\r\n if time[3] > '5':\r\n time[3] = '2'\r\n if time[0] > '2' or (time[0] >= '2' and time[1] >= '4'):\r\n time[0] = '1'\r\n print(''.join(time))", "def solve(now, r):\n t = float('inf')\n for x in r:\n s = '%02d' % x\n y = 0\n if now[0] != s[0]:\n y += 1\n if now[1] != s[1]:\n y += 1\n if y < t:\n t = y\n z = s\n return z\nmode = input()\nh, m = input().split(':')\nprint( solve(h, range(24) if mode == '24' else range(1, 13)) + ':' + solve(m, range(60)))\n\n\n \t \t \t \t \t \t \t\t\t \t\t\t \t", "n = int(input())\r\n\r\ntime = input()\r\n\r\ndef d(s, t):\r\n cnt = 0\r\n for i in range(0, len(s)):\r\n if (s[i] != t[i]):\r\n cnt += 1\r\n return cnt\r\n\r\nans = \"12:00\"\r\n\r\nif (n == 12):\r\n for h in range(1, 13):\r\n for m in range(0, 60):\r\n h_f = str(h)\r\n if (len(h_f) == 1):\r\n h_f = \"0\" + h_f\r\n m_f = str(m)\r\n if (len(m_f) == 1):\r\n m_f = \"0\" + m_f\r\n t = h_f + \":\" + m_f\r\n if (d(t, time) < d(ans, time)):\r\n ans = t\r\nif (n == 24):\r\n for h in range(0, 24):\r\n for m in range(0, 60):\r\n h_f = str(h)\r\n if (len(h_f) == 1):\r\n h_f = \"0\" + h_f\r\n m_f = str(m)\r\n if (len(m_f) == 1):\r\n m_f = \"0\" + m_f\r\n t = h_f + \":\" + m_f\r\n if (d(t, time) < d(ans, time)):\r\n ans = t\r\n\r\nprint(ans)", "\n\nt=input()\ns=input().split(\":\")\nhh=s[0]\nmm=s[1]\n\nif(int(hh)>23):\n\thh=\"0\"+hh[1]\nif(int(mm)>59):\n\tmm=\"0\"+mm[1]\n\nif(t==\"24\"):\n\tprint(hh+\":\"+mm)\n\texit()\n\nif(int(hh)>12):\n\thh=\"0\"+hh[1]\nif(int(hh)==0):\n\thh=\"1\"+hh[1]\n\nprint(hh+\":\"+mm)", "fmt = int(input())\nh, m = map(int, input().split(':'))\nm %= 60\nif fmt == 12:\n if h == 0:\n h = 1\n elif h > 12:\n if h % 10:\n h %= 10\n else:\n h = 10\nelse:\n if h > 23:\n h %= 10\nprint(\"{:0>2}:{:0>2}\".format(h, m))\n", "f = int(input())\r\nh = input().split(\":\")\r\n \r\nif(int(h[0])>f or int(h[0])==24):\r\n h[0]='0'+h[0][1]\r\n \r\nif(int(h[0])==0 and f==12):\r\n h[0]='1'+h[0][1]\r\n \r\nif(int(h[1])>=60):\r\n h[1]='0'+h[1][1]\r\n \r\nprint(f\"{h[0]}:{h[1]}\")", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nn = input()\nhour,min = map(int,input().split(':'))\n\nif n == \"12\":\n if not 1 <= hour <= 12:\n hour %= 10\n if hour == 0:\n hour = 10\nelse:\n if not 0 <= hour <= 23:\n hour %= 10\nif not 0 <= min <= 59:\n min %= 10\n\nprint(\"{0:02d}:{1:02d}\".format(hour,min))\n\n\n", "import sys\r\nimport math\r\nimport bisect\r\n\r\ndef query_distance(s, t):\r\n n = len(s)\r\n ans = 0\r\n for i in range(n):\r\n if s[i] != t[i]:\r\n ans += 1\r\n return ans\r\n\r\ndef solve(n, s):\r\n min_val = 10 ** 18\r\n sol = None\r\n if n == 24:\r\n for i in range(0, 24):\r\n for j in range(0, 60):\r\n t = str(i).zfill(2) + ':' + str(j).zfill(2)\r\n val = query_distance(s, t)\r\n if min_val > val:\r\n min_val = val\r\n sol = t\r\n elif n == 12:\r\n for i in range(1, 13):\r\n for j in range(0, 60):\r\n t = str(i).zfill(2) + ':' + str(j).zfill(2)\r\n val = query_distance(s, t)\r\n if min_val > val:\r\n min_val = val\r\n sol = t\r\n return sol\r\n\r\ndef main():\r\n n = int(input())\r\n s = input()\r\n ans = solve(n, s)\r\n print(ans)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "def broken_clock():\r\n\r\n\tform = int(input())\r\n\ttime = input().split(':')\r\n\r\n\t\r\n\tif form == 12 and int(time[0]) not in range(1, 13):\r\n\r\n\t\tif time[0][1] == '0':\r\n\t\t\ttime[0] = '1' + time[0][1]\r\n\t\telse:\r\n\t\t\ttime[0] = '0' + time[0][1]\r\n\r\n\telif form == 24 and int(time[0]) not in range(0, 24):\r\n\r\n\t\tif time[0] == '24':\r\n\t\t\ttime[0] = '23'\r\n\t\telse:\r\n\t\t\ttime[0] = '0' + time[0][1]\r\n\t\r\n\r\n\tif int(time[1]) > 59:\r\n\t\ttime[1] = '1' + time[1][1]\r\n\r\n\treturn time[0] + ':' + time[1]\r\n\r\nprint(broken_clock())", "first = int(input())\r\ndate = input().split(\":\")\r\n\r\nhours = date[0]\r\nmins = date[1]\r\n\r\n\r\nif first == 12:\r\n if int(hours) == 0:\r\n hours = 1\r\n elif int(hours) < 1 or int(hours) > 12:\r\n if int(hours) % 10 == 0:\r\n hours = 10\r\n else:\r\n hours = int(hours) % 10\r\n if int(mins) < 0 or int(mins) > 59:\r\n mins = int(mins) % 10\r\n hours = (\"0\" * (2 - len(str(hours)))) + str(hours)\r\n mins = (\"0\" * (2 - len(str(mins)))) + str(mins)\r\n print(\":\".join([str(hours), str(mins)]))\r\nelse:\r\n if int(hours) < 0 or int(hours) > 23:\r\n hours = int(hours) % 10\r\n if int(mins) < 0 or int(mins) > 59:\r\n mins = int(mins) % 10\r\n hours = (\"0\" * (2 - len(str(hours)))) + str(hours)\r\n mins = (\"0\" * (2 - len(str(mins)))) + str(mins)\r\n print(\":\".join([str(hours), str(mins)]))\r\n\r\n \r\n\r\n\r\n\r\n# print(\":\".join([hours, mins]))", "c = input()\r\nh, m = map(int, input().split(':'))\r\nif m >= 60:\r\n\tm %= 10\r\nif c == '12' and h == 0:\r\n\th = 1\r\nelif c == '12' and h > 12:\r\n\tif h % 10:\r\n\t\th %= 10\r\n\telse:\r\n\t\th = 10\r\nelif c == '24' and h > 23:\r\n\th %= 10\r\nprint('%02d:%02d' % (h,m))", "r=range(24) if input()=='24' else range(1, 13)\r\nt=['{0:02d}:{1:02d}'.format(h, m) for m in range(60) for h in r]\r\ns=input()\r\nf=lambda s, t: sum(1 for i, j in zip(s, t) if i!=j)\r\nfrom functools import reduce\r\nprint(reduce(lambda x, y: x if f(s, x)<f(s, y) else y, t))", "n = int(input())\r\ns = input().split(':')\r\nif n == 12:\r\n if s[0] == '00':\r\n s[0] = '01'\r\n elif int(s[0]) > 12 and s[0][1] == '0':\r\n s[0] = '10'\r\n elif int(s[0]) > 12:\r\n s[0] = '0' + s[0][1]\r\nelse:\r\n if int(s[0]) > 23:\r\n s[0] = '0' + s[0][1]\r\nif int(s[1]) > 59:\r\n s[1] = '0' + s[1][1]\r\nprint(':'.join(s))", "def doze(tempo):\n retorno = \"\"\n\n if (int(tempo[0:2]) == 00):\n tempo = tempo[:1]+ \"1\" + tempo[2:]\n\n if (int(tempo[0]) > 1):\n tempo = \"1\" + tempo[1:3] + tempo[3:] \n\n if (int(tempo[0:2]) < 12):\n if (int(tempo[3:]) < 60):\n retorno = tempo\n return tempo\n\n if (int(tempo[0:2]) > 12):\n tempo = \"0\" + tempo[1:3] + tempo[3:] \n\n if (int(tempo[3:]) >= 60):\n tempo = tempo[:3] + \"0\" + tempo[4:]\n\n retorno = tempo\n return retorno\n\ndef vinte_e_quatro(tempo):\n retorno = \"\"\n\n if (int(tempo[0:2]) < 24):\n if (int(tempo[3:]) < 60):\n retorno = tempo\n return retorno\n \n if (int(tempo[0:2]) > 23):\n tempo = \"0\" + tempo[1:3] + tempo[3:]\n \n if (int(tempo[3:]) >= 60):\n tempo = tempo[:3] + \"0\" + tempo[4:]\n \n retorno = tempo\n return retorno\n\n\nformato_horas = int(input())\ntempo_atual = str(input())\n\nif (formato_horas == 12):\n print(doze(tempo_atual))\nelse:\n print(vinte_e_quatro(tempo_atual))\n\n\t \t \t\t \t \t \t \t \t\t\t\t \t\t \t\t", "# 722A\r\n# θ(1) time\r\n# θ(1) space\r\n\r\n__author__ = 'artyom'\r\n\r\n\r\n# SOLUTION\r\n\r\ndef main():\r\n s = read(0)\r\n t = read(0).split(':')\r\n if s == '12':\r\n if t[0][1] == '0':\r\n t[0] = '10'\r\n elif int(t[0]) > 12:\r\n t[0] = '0' + t[0][1]\r\n elif int(t[0]) > 23:\r\n t[0] = '0' + t[0][1]\r\n if int(t[1]) > 59:\r\n t[1] = '0' + t[1][1]\r\n return t[0] + ':' + t[1]\r\n\r\n\r\n\r\n# HELPERS\r\n\r\ndef read(mode=1, size=None):\r\n # 0: String\r\n # 1: Integer\r\n # 2: List of strings\r\n # 3: List of integers\r\n # 4: Matrix of integers\r\n if mode == 0: return input().strip()\r\n if mode == 1: return int(input().strip())\r\n if mode == 2: return input().strip().split()\r\n if mode == 3: return list(map(int, input().strip().split()))\r\n a = []\r\n for _ in range(size):\r\n a.append(read(3))\r\n return a\r\n\r\n\r\ndef write(s=\"\\n\"):\r\n if s is None: s = ''\r\n if isinstance(s, tuple) or isinstance(s, list): s = ' '.join(map(str, s))\r\n s = str(s)\r\n print(s, end=\"\\n\")\r\n\r\n\r\nwrite(main())", "hour_format = int(input())\r\nh, m = (map(int, input().split(\":\")))\r\n\r\nif hour_format ==12:\r\n if(h<1 or h>12):\r\n if(h%10==0):\r\n h=10\r\n else:\r\n h = h%10\r\n if(m<0 or m>59):\r\n m = m%10\r\nelse:\r\n if(h<1 or h>23):\r\n h = h%10\r\n if(m<0 or m>59):\r\n m = m%10\r\nprint(\"{:02d}:{:02d}\".format(h,m))", "def get(x):\r\n if (x < 10):\r\n return \"0\" + str(x)\r\n return str(x)\r\ndef diff(a, b):\r\n ans = 0\r\n for i in range(len(a)):\r\n if (a[i] != b[i]):\r\n ans += 1\r\n return ans\r\n\r\nx = int(input())\r\n\r\ns = input()\r\n\r\nif (x == 12):\r\n best = \"01:30\"\r\n for a in range(1, 13):\r\n for b in range(60):\r\n h = get(a) + \":\" + get(b)\r\n if (diff(s, h) < diff(best, s)):\r\n best = h\r\n print(best)\r\nelse:\r\n best = \"01:30\"\r\n for a in range(24):\r\n for b in range(60):\r\n h = get(a) + \":\" + get(b)\r\n if (diff(s, h) < diff(best, s)):\r\n best = h\r\n print(best)\r\n", "n = int(input())\ntm = tuple(map(int, input().split(':')))\n\ncost = [[0 for i in range(100)] for j in range(100)]\nfor i in range(100):\n for j in range(100):\n x, y = i, j\n for k in range(2):\n cost[i][j] += (x % 10) != (y % 10)\n x //= 10\n y //= 10\n\nhr_range = range(1, 13)\nif n == 24:\n hr_range = range(0, 24)\n\nbest_time = None\nbest_val = 123\nfor h in hr_range:\n for m in range(60):\n cur = cost[h][tm[0]] + cost[m][tm[1]]\n if cur < best_val:\n best_val = cur\n best_time = '{:02d}:{:02d}'.format(h, m)\n\nprint(best_time)\n", "n = int(input())\r\ns = input()\r\nnum = 5\r\nans = ''\r\nfor k1 in range(3):\r\n for k2 in range(10):\r\n for k3 in range(10):\r\n for k4 in range(10):\r\n tmp = 0\r\n if n == 24:\r\n if 0 <= k1 < 2 and 0 <= k2 < 10 and 0 <= k3 < 6 and 0 <= k4 < 10:\r\n tmp += int(k1 != int(s[0])) + int(k2 != int(s[1])) + int(k3 != int(s[3])) + int(k4 != int(s[4]))\r\n if tmp < num:\r\n num = tmp\r\n ans = str(k1) + str(k2) + ':' + str(k3) + str(k4)\r\n elif k1 == 2 and 0 <= k2 < 4 and 0 <= k3 < 6 and 0 <= k4 < 10:\r\n tmp += int(k1 != int(s[0])) + int(k2 != int(s[1])) + int(k3 != int(s[3])) + int(\r\n k4 != int(s[4]))\r\n if tmp < num:\r\n num = tmp\r\n ans = str(k1) + str(k2) + ':' + str(k3) + str(k4)\r\n else:\r\n if k1 == 0 and 0 < k2 < 10 and 0 <= k3 < 6 and 0 <= k4 < 10:\r\n tmp += int(k1 != int(s[0])) + int(k2 != int(s[1])) + int(k3 != int(s[3])) + int(\r\n k4 != int(s[4]))\r\n if tmp < num:\r\n num = tmp\r\n ans = str(k1) + str(k2) + ':' + str(k3) + str(k4)\r\n elif k1 == 1 and 0 <= k2 <= 2 and 0 <= k3 < 6 and 0 <= k4 < 10:\r\n tmp += int(k1 != int(s[0])) + int(k2 != int(s[1])) + int(k3 != int(s[3])) + int(\r\n k4 != int(s[4]))\r\n if tmp < num:\r\n num = tmp\r\n ans = str(k1) + str(k2) + ':' + str(k3) + str(k4)\r\n\r\nprint(ans)", "r=range(24) if input()=='24' else range(1, 13)\r\ns=input()\r\nc=100\r\nans=''\r\nfor h in r:\r\n for m in range(60):\r\n t='{0:02d}:{1:02d}'.format(h, m)\r\n l=sum(1 for i, j in zip(s, t) if i!=j)\r\n if c>l:\r\n c, ans=l, t\r\nprint(ans)", "n = int(input())\ns = input()\nans = [int(i) if i!=':' else i for i in s]\nif ans[3] > 5:\n\tans[3] = 0\nif n == 24:\n\tif ans[0] == 2:\n\t\tif ans[1] > 3:\n\t\t\tans[1] = 0\n\tif ans[0] > 2:\n\t\tans[0] = 0\nif n == 12:\n\tif ans[0] == 1:\n\t\tif ans[1] > 2:\n\t\t\tans[1] = 0\n\tif ans[0] > 1:\n\t\tif ans[1] == 0:\n\t\t\tans[0] = 1\n\t\telse:\n\t\t\tans[0] = 0\n\tif ans[0] == 0:\n\t\tif ans[1] == 0:\n\t\t\tans[1] = 1\nfinal = \"\"\nfor i in ans:\n\tfinal += str(i)\nprint(final)", "\r\nn=int(input());\r\nx=list(input());\r\nm=int(x[3])*10+int(x[4]);\r\nh=int(x[0])*10+int(x[1]);\r\nif(m>=60):\r\n x[3]='0';\r\nif(n==12):\r\n if(h<1):\r\n x[1]='1';\r\n if h>12:\r\n \tif(h%10==0):\r\n \t\tx[0]='1';\r\n \telse:\r\n \t\tx[0]='0';\r\nif(n==24):\r\n if(h>23):\r\n x[0]='1';\r\nprint(''.join(x));", "mode = input()\nt = input()\n\nh, m = map(int, t.split(':'))\n\nif m >= 60:\n new_m = 10 + m % 10\nelse:\n new_m = m\n\nif mode == '24':\n if h >= 24:\n new_h = 10 + h % 10\n else:\n new_h = h\nelse:\n if h == 0:\n new_h = 10\n elif h > 12:\n if h % 10 == 0:\n new_h = 10\n else:\n new_h = h % 10\n else:\n new_h = h\n\nprint('{:02}:{:02}'.format(new_h, new_m))\n", "formats=int(input())\r\ns=input()\r\nif s==\"00:30\":\r\n print(s)\r\nelse:\r\n hour=int(s[0]+s[1])\r\n hours=s[0]+s[1]\r\n q=hours\r\n minute=int(s[3]+s[4])\r\n minutes=s[3]+s[4]\r\n if (hour>formats or hour==24) or hour==0:\r\n hour=int(\"0\"+hours[1])\r\n hours=\"0\"+hours[1]\r\n\r\n if hours[1]==\"0\" and hours[0]!=\"1\" and hours[0]!=\"0\":\r\n hour=9\r\n hours=str(hour)\r\n if len(hours)==1:\r\n hours=\"0\"+hours\r\n if minute>59:\r\n minutes=\"0\"+minutes[1]\r\n if hours==\"00\" and q[1]==\"0\":\r\n hours=\"10\"\r\n elif hours==\"00\":\r\n hours=\"01\"\r\n print(hours+\":\"+minutes)\r\n \r\n", "a = int(input())\r\ns = input()\r\nc = 0\r\nans = []\r\nfor i in range (0,len(s)) :\r\n ans.append(s[i])\r\nif ( s[3] > '5' ) :\r\n ans[3] = 0 \r\nif a == 12 : \r\n if(s[0] == '0' and s[1] == '0') :\r\n ans[1] = '1'\r\n if(s[0] == '1' and s[1] > '2' ) :\r\n ans[1] = '2'\r\n if(s[0] > '1' and s[1] == '0') :\r\n ans[0] = '1'\r\n if(s[0] > '1' and s[1] != '0') :\r\n ans[0] = '0'\r\nelse :\r\n if(s[0] == '2' and s[1] > '3' ) :\r\n ans[1] = '3'\r\n if(s[0] > '2' ) :\r\n ans[0] = '0'\r\nfor ii in ans :\r\n print(ii ,end = \"\")", "#!/usr/bin/env python3\r\n\r\n\r\ndef main():\r\n try:\r\n while True:\r\n n = input()\r\n a, b = input().split(':')\r\n c, d = b\r\n a, b = a\r\n if c >= '6':\r\n c = '5'\r\n if n == \"24\":\r\n if a == '2':\r\n if b >= '4':\r\n b = '3'\r\n elif a >= '3':\r\n a = '1'\r\n else:\r\n if a == b == '0':\r\n b = '1'\r\n elif a == '1':\r\n if b >= '3':\r\n b = '2'\r\n elif a >= '2':\r\n if b == '0':\r\n a = '1'\r\n else:\r\n a = '0'\r\n\r\n print(\"%s%s:%s%s\" % (a, b, c, d))\r\n\r\n except EOFError:\r\n pass\r\n\r\n\r\nmain()\r\n", "form = int(input())\r\nhs, ms = input().split(\":\")\r\nif int(ms) > 59:\r\n ms = \"0\" + ms[1]\r\nif form == 24:\r\n if int(hs) > 23:\r\n hs = \"0\" + hs[1]\r\nelse:\r\n if int(hs) > 12:\r\n if hs[1] == \"0\":\r\n hs = \"10\"\r\n else:\r\n hs = \"0\" + hs[1]\r\n elif int(hs) == 0:\r\n hs = \"01\"\r\nprint(hs + \":\" + ms)", "#! /usr/bin/python\n# kmwho\n\nfrom __future__ import print_function\n\ndef solvecase():\n form = int(input().strip())\n hh,mm = map(int,input().strip().split(\":\"))\n if mm > 59:\n mm = mm % 10\n if form == 24:\n if hh > 23:\n hh = hh % 10\n elif form == 12:\n if hh > 12:\n if hh % 10:\n hh = hh % 10\n else:\n hh = 10\n if hh == 0:\n hh = 1\n return \"%02d:%02d\" % (hh,mm)\n\ndef main():\n\t#solve()\n\tprint(solvecase())\n\n\nmain()\n", "def best(h, n, x):\n best = ''\n bestCnt = 10\n begin = 0\n end = n\n if x == 'h':\n if n == 12:\n begin = 1\n end = 13\n for i in range(begin, end):\n si = str(i)\n if len(si) == 1:\n si = '0' + si\n bad = 0\n for x, y in zip(h, si):\n if x != y:\n bad += 1\n if bad < bestCnt:\n bestCnt = bad\n best = si\n return best\n\nn = int(input())\ns = input()\nh = s[0:2]\nm = s[3:5]\nprint(best(h, n, 'h'), best(m, 60, 'm'), sep=':')\n", "f = input()\r\nh, m = input().split(':')\r\n\r\nif f == '12':\r\n if h == '00':\r\n h = '01'\r\n elif int(h) > 12:\r\n if h[1] == '0':\r\n h = '10'\r\n else:\r\n h = '0' + h[1]\r\n\r\nif f == '24' and int(h) > 23:\r\n h = '1' + h[1]\r\n\r\nif int(m) > 59:\r\n m = '3' + m[1]\r\n\r\nprint(h + ':' + m)", "n=int(input())\r\ns=str(input())\r\nh1=int(s[0])\r\nh2=int(s[1])\r\nm1=int(s[3])\r\nm2=int(s[4])\r\nhh=h1*10+h2\r\nmm=m1*10+m2\r\nl1=[\"01\",\"02\",\"03\",\"04\",\"05\",\"06\",\"07\",\"08\",\"09\",\"10\",\"11\",\"12\"]\r\nl2=[\"00\",\"01\",\"02\",\"03\",\"04\",\"05\",\"06\",\"07\",\"08\",\"09\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\"]\r\nif mm>59:\r\n m1=1\r\nif n==12:\r\n ma=2\r\n s1=s[:2]\r\n for i in range(12):\r\n x=0\r\n if s[0]!=l1[i][0]:\r\n x+=1\r\n if s[1]!=l1[i][1]:\r\n x+=1\r\n if x<ma:\r\n ma=x\r\n s1=l1[i]\r\nelse:\r\n ma=2\r\n s1=s[:2]\r\n for i in range(24):\r\n x=0\r\n if s[0]!=l2[i][0]:\r\n x+=1\r\n if s[1]!=l2[i][1]:\r\n x+=1\r\n if x<ma:\r\n ma=x\r\n s1=l2[i]\r\nprint(s1+\":\"+str(m1)+str(m2))", "format = input()\r\ntime = input()\r\nhours,minutes = time.split(\":\")\r\nihours = int(hours)\r\n\r\nif(int(minutes) > 59):\r\n\tminutes = \"3\" + minutes[1]\r\n\r\nif(format == \"12\"):\r\n\tmaxf = 12\r\n\tminf = 1\r\nelse:\r\n\tmaxf = 23\r\n\tminf = 0\r\n\r\nif(maxf < int(hours)):\r\n\thours = \"0\" + hours[1]\r\n\r\nif(int(hours) < minf):\r\n\thours = \"1\" + hours[1]\r\n\r\n\r\nprint(hours + \":\" + minutes)", "if __name__ == '__main__':\r\n f = int(input())\r\n h, m = map(str, input().split(':'))\r\n if m > '59':\r\n m = '0' + m[1]\r\n if f == 24:\r\n if h > '23':\r\n h = '1' + h[1]\r\n elif f == 12:\r\n if h > '12':\r\n h = '0' + h[1]\r\n if h == '00':\r\n h = '10'\r\n print(h + ':' + m)\r\n", "n = int(input())\r\nh, m = input().split(':')\r\nans = 1000\r\nans1 = ''\r\nif n == 12:\r\n h1, m1 = '', ''\r\n for i in range(1, 13):\r\n for j in range(0, 60):\r\n h1 = (2 - len(str(i))) * '0' + str(i)\r\n m1 = (2 - len(str(j))) * '0' + str(j)\r\n cnt = 4\r\n if h1[0] == h[0]:\r\n cnt -= 1\r\n if h1[1] == h[1]:\r\n cnt -= 1\r\n if m1[0] == m[0]:\r\n cnt -= 1\r\n if m1[1] == m[1]:\r\n cnt -= 1\r\n if cnt < ans:\r\n ans = cnt\r\n ans1 = h1 + ':' + m1 \r\n print(ans1)\r\nelse:\r\n h1, m1 = '', ''\r\n for i in range(24):\r\n for j in range(0, 60):\r\n h1 = (2 - len(str(i))) * '0' + str(i)\r\n m1 = (2 - len(str(j))) * '0' + str(j)\r\n cnt = 4\r\n if h1[0] == h[0]:\r\n cnt -= 1\r\n if h1[1] == h[1]:\r\n cnt -= 1\r\n if m1[0] == m[0]:\r\n cnt -= 1\r\n if m1[1] == m[1]:\r\n cnt -= 1\r\n if cnt < ans:\r\n ans = cnt\r\n ans1 = h1 + ':' + m1 \r\n print(ans1)", "form=int(input())\nti=list(map(int,input().split(':')))\nif form==12:\n\tif ti[-1] >59 :\n\t\tti[-1]=10+ti[-1]%10\n\tif ti[0]%10 == 0 and ti[0] != 10:\n\t\tti[0] = 10\n\telif ti[0] > 12 :\n\t\tti[0]=ti[0]%10\nelse :\n\tif ti[-1] >59 :\n\t\tti[-1]=10+ti[-1]%10\n\tif ti[0]%10 == 0 and ti[0] != 10 and ti[0] != 20 and ti[0]!=0 :\n\t\tti[0] = 10\n\telif ti[0] > 23 :\n\t\tti[0]=ti[0]%10\n\nl=[str(i) for i in ti]\nif len(l[0])<2:\n\tprint(0,end='')\nprint(l[0],end=':')\nif len(l[1])<2:\n\tprint(0,end='')\nprint(l[1],end='')", "I=input\r\nR=range\r\nR=R(1,13)if I()=='12'else R(24)\r\na=I()\r\nb=':'+[a[3],'0'][int(a[3])>5]+a[4]\r\na=a[:2]\r\nF=lambda x,y:(x[0]!=y[0])+(x[1]!=y[1])\r\nc='10'\r\nfor i in R:\r\n\ts='0'*(i<=9)+str(i)\r\n\tif F(c,a)>F(s,a):c=s\r\nprint(c+b)" ]
{"inputs": ["24\n17:30", "12\n17:30", "24\n99:99", "12\n05:54", "12\n00:05", "24\n23:80", "24\n73:16", "12\n03:77", "12\n47:83", "24\n23:88", "24\n51:67", "12\n10:33", "12\n00:01", "12\n07:74", "12\n00:60", "24\n08:32", "24\n42:59", "24\n19:87", "24\n26:98", "12\n12:91", "12\n11:30", "12\n90:32", "12\n03:69", "12\n33:83", "24\n10:45", "24\n65:12", "24\n22:64", "24\n48:91", "12\n02:51", "12\n40:11", "12\n02:86", "12\n99:96", "24\n19:24", "24\n55:49", "24\n01:97", "24\n39:68", "24\n24:00", "12\n91:00", "24\n00:30", "12\n13:20", "12\n13:00", "12\n42:35", "12\n20:00", "12\n21:00", "24\n10:10", "24\n30:40", "24\n12:00", "12\n10:60", "24\n30:00", "24\n34:00", "12\n22:00", "12\n20:20"], "outputs": ["17:30", "07:30", "09:09", "05:54", "01:05", "23:00", "03:16", "03:07", "07:03", "23:08", "01:07", "10:33", "01:01", "07:04", "01:00", "08:32", "02:59", "19:07", "06:08", "12:01", "11:30", "10:32", "03:09", "03:03", "10:45", "05:12", "22:04", "08:01", "02:51", "10:11", "02:06", "09:06", "19:24", "05:49", "01:07", "09:08", "04:00", "01:00", "00:30", "03:20", "03:00", "02:35", "10:00", "01:00", "10:10", "00:40", "12:00", "10:00", "00:00", "04:00", "02:00", "10:20"]}
UNKNOWN
PYTHON3
CODEFORCES
62
1cdc43323dd7fe34277766feb4665594
Gargari and Bishops
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a *n*<=×<=*n* chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number *x* written on it, if this cell is attacked by one of the bishops Gargari will get *x* dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money. We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2000). Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=109) — description of the chessboard. On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=*n*), where *x**i* is the number of the row where the *i*-th bishop should be placed, *y**i* is the number of the column where the *i*-th bishop should be placed. Consider rows are numbered from 1 to *n* from top to bottom, and columns are numbered from 1 to *n* from left to right. If there are several optimal solutions, you can print any of them. Sample Input 4 1 1 1 1 2 1 1 0 1 1 1 0 1 0 0 1 Sample Output 12 2 2 3 2
[ "import sys\r\ninput = sys.stdin.readline \r\n\r\nn = int(input())\r\na =[]\r\nfor i in range(n):\r\n a.append(list(map(int, input().split()))) \r\nb1, b2 = [0] * (2 * n), [0] * (2 * n)\r\nfor i in range(n):\r\n for j in range(n):\r\n b1[i + j] += a[i][j] \r\n b2[n + i - j] += a[i][j] \r\nx, y = [1, 2], [1, 1] \r\nans = [0, 0]\r\nfor i in range(n):\r\n for j in range(n): \r\n t = (i + j) & 1\r\n c = b1[i + j] + b2[n + i - j] - a[i][j] \r\n if(c > ans[t]):\r\n ans[t], x[t], y[t] = c, i + 1, j + 1 \r\nprint(sum(ans)) \r\nprint(x[0], y[0], x[1], y[1])\r\n", "import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n\r\n_str = str\r\nstr = lambda x=b\"\": x if type(x) is bytes else _str(x).encode()\r\n\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._file = file\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\ndicP = dict()\r\ndicN = dict()\r\n\r\nN = int(input())\r\n\r\nM= []\r\n\r\nfor i in range(N):\r\n M.append(list(map(int, input().split())))\r\n\r\nfor i in range(N):\r\n for j in range(N):\r\n if i + j not in dicP:\r\n dicP[i+j] = 0\r\n \r\n if i - j not in dicN:\r\n dicN[i-j] = 0\r\n \r\n dicP[i+j] += M[i][j]\r\n dicN[i-j] += M[i][j]\r\n\r\nmaxxEven = -1000000007\r\nmaxxOdd = -1000000007\r\n\r\npointOdd = (0,0)\r\npointEven = (0,0)\r\n\r\nfor i in range(N):\r\n for j in range(N):\r\n if (i + j) % 2 == 0:\r\n if dicP[i+j] + dicN[i-j] - (M[i][j]) > maxxEven:\r\n pointEven = (i+1,j+1)\r\n maxxEven = max(maxxEven, dicP[i+j] + dicN[i-j] - (M[i][j]))\r\n else:\r\n if dicP[i+j] + dicN[i-j] - (M[i][j]) > maxxOdd:\r\n pointOdd = (i+1,j+1)\r\n maxxOdd = max(maxxOdd, dicP[i+j] + dicN[i-j] - (M[i][j]))\r\nprint(maxxEven + maxxOdd)\r\n\r\nprint(*pointEven, *pointOdd)", "n=int(input())\r\narr=[]\r\nfor i in range(n):\r\n f=[int(r) for r in input().split()]\r\n arr.append(f)\r\nsumright={}\r\nsumleft={}\r\nfor i in range(n):\r\n for j in range(n):\r\n sumright[i+j]=0\r\n sumleft[i-j]=0\r\nfor i in range(n):\r\n for j in range(n):\r\n sumright[i+j]+=arr[i][j]\r\n sumleft[i-j]+=arr[i][j]\r\nmax_e=0\r\nmax_o=0\r\no=[0]*2\r\ne=[0]*2\r\nfor i in range(n):\r\n for j in range(n):\r\n if (i+j)%2==0:\r\n if sumright[i+j]+sumleft[i-j]-arr[i][j]>=max_e:\r\n max_e=sumright[i+j]+sumleft[i-j]-arr[i][j]\r\n e[0]=i\r\n e[1]=j\r\n elif (i+j)%2!=0:\r\n if sumright[i+j]+sumleft[i-j]-arr[i][j]>=max_o:\r\n max_o=sumright[i+j]+sumleft[i-j]-arr[i][j]\r\n o[0]=i\r\n o[1]=j\r\nprint(max_e+max_o)\r\nprint(e[0]+1,e[1]+1,o[0]+1,o[1]+1)\r\n", "''' C. Gargari and Bishops\nhttps://codeforces.com/contest/463/problem/C\n'''\n\nimport io, os, sys\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline # decode().strip() if str\noutput = sys.stdout.write\n\nDEBUG = os.environ.get('debug') not in [None, '0']\n\nif DEBUG:\n from inspect import currentframe, getframeinfo\n from re import search\n\ndef debug(*args):\n if not DEBUG: return\n frame = currentframe().f_back\n s = getframeinfo(frame).code_context[0]\n r = search(r\"\\((.*)\\)\", s).group(1)\n vnames = r.split(', ')\n var_and_vals = [f'{var}={val}' for var, val in zip(vnames, args)]\n prefix = f'{currentframe().f_back.f_lineno:02d}: '\n print(f'{prefix}{\", \".join(var_and_vals)}')\n\n# for int dict key\nfrom random import randrange\nRAND = randrange(1 << 62)\ndef conv(x): return x ^ RAND\n\nINF = float('inf')\n\n# -----------------------------------------\n\ndef solve(N, grid):\n # diagonal sums\n S1, S2 = [0] * (2 * N), [0] * (2 * N)\n for i in range(N):\n # left up\n r, c, s = i, 0, 0\n while 0 <= r < N and 0 <= c < N:\n s += grid[r][c]\n r -= 1\n c += 1\n S1[r + c] = s\n\n # right down\n r, c, s = i, N-1, 0\n while 0 <= r < N and 0 <= c < N:\n s += grid[r][c]\n r += 1\n c -= 1\n S1[r + c] = s\n\n # left down\n r, c, s = i, 0, 0\n while 0 <= r < N and 0 <= c < N:\n s += grid[r][c]\n r += 1\n c += 1\n S2[r - c] = s\n\n # right up\n r, c, s = i, N-1, 0\n while 0 <= r < N and 0 <= c < N:\n s += grid[r][c]\n r -= 1\n c -= 1\n S2[r - c] = s\n\n mx = [(-1, -1, -1), (-1, -1, -1)]\n for r in range(N):\n for c in range(N):\n cand = (S1[r + c] + S2[r - c] - grid[r][c], r + 1, c + 1)\n p = (r + c) % 2\n mx[p] = max(mx[p], cand)\n \n return mx[0][0] + mx[1][0], (mx[0][1], mx[0][2], mx[1][1], mx[1][2])\n\n\ndef main():\n N = int(input())\n grid = [list(map(int, input().split())) for _ in range(N)]\n s, coords = solve(N, grid)\n print(s)\n print(*coords)\n\n\nif __name__ == '__main__':\n main()\n\n", "def update(c, i, j, val):\r\n if val > ans[c]:\r\n ans[c] = val\r\n ans_mas[c] = [i, j]\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n mas = [[]]+[[0]+[int(s) for s in input().split()] for _ in range(n)]\r\n\r\n d_mas_1 = [0]*4002\r\n d_mas_2 = [0]*4002\r\n\r\n for i in range(1, n+1):\r\n for j in range(1, n+1):\r\n d_mas_1[i+j] += mas[i][j]\r\n d_mas_2[i-j+n] += mas[i][j]\r\n\r\n for i in range(1, n+1):\r\n for j in range(1, n+1):\r\n update((i+j) & 1, i, j, d_mas_1[i+j]+d_mas_2[i-j+n]-mas[i][j])\r\n\r\n print(ans[0]+ans[1])\r\n ans_1, ans_2 = sorted(ans_mas)\r\n print(' '.join(str(s) for s in ans_1), ' '.join(str(s) for s in ans_2))\r\n\r\n\r\nif __name__ == '__main__':\r\n ans = [-1, -1]\r\n ans_mas = [[], []]\r\n solve()\r\n", "from sys import stdin\r\ninput = stdin.buffer.readline\r\nn=int(input())\r\nl=[[*map(int,input().split())] for _ in range(n)]\r\nd={};su={};s=0;an=[1,1,2,1]\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\td[i-j]=d.get(i-j,0)+l[i][j]\r\n\t\tsu[i+j]=su.get(i+j,0)+l[i][j]\r\nposition=[2,1,1,1]\r\nx,y=0,0\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tp=d[i-j]+su[i+j]-l[i][j]\r\n\r\n\t\tif (i+j)%2:\r\n\t\t\tif p>x:\r\n\t\t\t\tx=p\r\n\t\t\t\tposition[:2]=[i+1,j+1]\r\n\t\telse:\r\n\t\t\tif p>y:\r\n\t\t\t\ty=p\r\n\t\t\t\tposition[2:]=[i+1,j+1]\r\nprint(x+y)\r\nprint(*position)", "from bisect import bisect_left as bl, bisect_right as br, insort_left, insort_right\nfrom collections import deque, Counter as counter, defaultdict as dd\nfrom copy import copy, deepcopy\nfrom functools import cache, cmp_to_key, lru_cache, reduce, partial\nfrom heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge, nlargest, nsmallest\nfrom itertools import count, cycle, repeat, accumulate, chain, groupby, starmap, product, permutations, combinations, combinations_with_replacement, zip_longest, islice\nfrom math import ceil, comb, factorial, floor, gcd, lcm, prod, log, sqrt, acos, asin, atan, dist, sin, cos, tan, degrees, radians, pi, e, inf\nfrom operator import add, sub, mul, truediv, floordiv, mod, xor, and_, or_, eq, ne, neg, concat, contains\nfrom random import randint, choice, shuffle, sample\nfrom string import ascii_lowercase as lowers, ascii_uppercase as uppers, ascii_letters as all_letters, digits\nfrom sys import stdin, argv, setrecursionlimit\n\ndef lmap(function, iterable): return list(map(function, iterable))\ndef line(): return stdin.readline().strip()\ndef rd(converter): return converter(line())\ndef rl(converter, delimeter = None): return lmap(converter, line().split(delimeter))\ndef rls(num_lines, converter): return [rd(converter) for i in range(num_lines)]\ndef rg(num_lines, converter, delimeter = None): return [rl(converter,delimeter) for i in range(num_lines)]\n\nMOD = 10**9+7\nMULTIPLE_CASES = 0\n\ndef main():\n N = rd(int)\n grid = rg(N,int)\n main_diag_sums = dd(int)\n anti_diag_sums = dd(int)\n\n def main_diag_coords(r,c):\n diff = min(r,c)\n return r-diff,c-diff\n\n def anti_diag_coords(r,c):\n diff = min(r,N-1-c)\n return r-diff,c+diff\n\n for r in range(N):\n for c in range(N):\n main_diag_sums[main_diag_coords(r,c)] += grid[r][c]\n anti_diag_sums[anti_diag_coords(r,c)] += grid[r][c]\n\n ans1,ans2 = -inf,-inf\n ans1_coords,ans2_coords = None,None\n\n for r in range(N):\n for c in range(N):\n if (r+c)%2 == 0:\n ans = main_diag_sums[main_diag_coords(r,c)]+anti_diag_sums[anti_diag_coords(r,c)]-grid[r][c]\n\n if ans > ans1:\n ans1 = ans\n ans1_coords = (r,c)\n else:\n ans = main_diag_sums[main_diag_coords(r,c)]+anti_diag_sums[anti_diag_coords(r,c)]-grid[r][c]\n\n if ans > ans2:\n ans2 = ans\n ans2_coords = (r,c)\n\n print(ans1+ans2)\n print(ans1_coords[0]+1,ans1_coords[1]+1,ans2_coords[0]+1,ans2_coords[1]+1)\n\nfor i in range(rd(int) if MULTIPLE_CASES else 1): main()", "from sys import stdin\r\ninput = stdin.buffer.readline\r\nfrom collections import defaultdict as dd\r\nI = lambda : list(map(int,input().split()))\r\n\r\nn,=I()\r\nl=[];d=dd(int);su=dd(int);s=0;an=[1,1,2,1]\r\nfor i in range(n):\r\n\tl.append(I())\r\n\tfor j in range(n):\r\n\t\td[i-j]+=l[i][j]\r\n\t\tsu[i+j]+=l[i][j]\r\nx=0;y=0\r\nfor i in range(n):\r\n\tfor j in range(n):\r\n\t\tl[i][j]=d[i-j]+su[i+j]-l[i][j]\r\n\t\tif (i+j)%2:\r\n\t\t\tif l[i][j]>x:\r\n\t\t\t\tan[0],an[1]=i+1,j+1\r\n\t\t\t\tx=l[i][j]\r\n\t\telse:\r\n\t\t\tif l[i][j]>y:\r\n\t\t\t\tan[2],an[3]=i+1,j+1\r\n\t\t\t\ty=l[i][j]\r\ns=x+y\r\nprint(s)\r\nprint(*an)", "\r\nfrom sys import stdin\r\ninput = stdin.buffer.readline\r\nI = lambda : list(map(int,input().split()))\r\n\r\nmat=[]\r\nfor _ in range(int(input())):\r\n mat.append(I())\r\nn=len(mat)\r\ndef sumDiag(mat):\r\n diag_sum=[]\r\n diag_sum2=[]\r\n n=len(mat)\r\n for i in range(n):\r\n s=0\r\n for j in range(0,n-i):\r\n s+=mat[j][(j+i)]\r\n diag_sum.append(s)\r\n if i!=0:\r\n s=0\r\n for j in range(0,n-i):\r\n s+=mat[j+i][(j)]\r\n diag_sum2.append(s)\r\n return diag_sum2[::-1]+diag_sum\r\n\r\ndef antiDiag(mat):\r\n def mirror(mat):\r\n for i in range(len(mat)):\r\n for j in range(len(mat[0])//2):\r\n t=mat[i][j]\r\n mat[i][j]=mat[i][len(mat[0])-1-j]\r\n mat[i][len(mat[0])-1-j]=t\r\n return mat\r\n mat=mirror(mat)\r\n out=sumDiag(mat)\r\n mirror(mat)\r\n return out[::-1]\r\n\r\nd1=sumDiag(mat)\r\nd2=antiDiag(mat)\r\ndef ret(i,j):\r\n return d1[n-1-(i-j)]+d2[i+j]-mat[i][j]\r\n\r\nm1=0\r\nm2=0\r\nbest1=(1,1)\r\nbest2=(1,2)\r\nfor i in range(n):\r\n for j in range(n):\r\n if (i+j)%2==0 and m1<ret(i,j):\r\n m1=ret(i,j)\r\n best1=(i+1,j+1)\r\n elif (i+j)%2==1 and m2<ret(i,j):\r\n m2=ret(i,j)\r\n best2=(i+1,j+1)\r\n\r\nprint(m1+m2)\r\nprint(\" \".join(map(str,[best1[0],best1[1],best2[0],best2[1]])))", "# ﷽\r\nfrom collections import defaultdict\r\nimport sys\r\ninput = lambda: sys.stdin.readline().strip()\r\ndef inlst():return [int(i) for i in input().split()]\r\n\r\ndef solve():\r\n n=int(input())\r\n lst=[inlst() for i in range(n) ]\r\n drow=defaultdict(int)\r\n dcol=defaultdict(int)\r\n for i in range(n):\r\n for j in range(n):\r\n drow[i+j]+=lst[i][j]\r\n dcol[i-j]+=lst[i][j]\r\n \r\n maxeven=-1 \r\n poseven=[-1,-1]\r\n maxodd=-1 \r\n posodd=[-1,-1] \r\n\r\n for i in range(n):\r\n for j in range(n):\r\n if (i+j)%2 ==0:\r\n if drow[i+j]+dcol[i-j]-lst[i][j]>maxeven:\r\n maxeven=drow[i+j]+dcol[i-j]-lst[i][j]\r\n poseven=[i+1,j+1]\r\n \r\n else:\r\n \r\n if drow[i+j]+dcol[i-j]-lst[i][j]>maxodd:\r\n maxodd=drow[i+j]+dcol[i-j]-lst[i][j]\r\n posodd=[i+1,j+1]\r\n \r\n \r\n print(maxeven+maxodd)\r\n print(*poseven,*posodd)\r\n \r\n\r\nif __name__ == \"__main__\":\r\n # for i in range(int(input())):\r\n solve()\r\n" ]
{"inputs": ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1", "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 24 32 16 5 48 98 74\n38 49 78 2 91 3 43 96 93 46\n35 100 84 2 94 56 90 98 54 43\n88 3 95 72 78 78 87 82 25 37\n8 15 85 85 68 27 40 10 22 84\n7 8 36 90 10 81 98 51 79 51\n93 66 53 39 89 30 16 27 63 93", "10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0", "15\n2 6 9 4 8 9 10 10 3 8 8 4 4 8 7\n10 9 2 6 8 10 5 2 8 4 9 6 9 10 10\n3 1 5 1 6 5 1 6 4 4 3 3 9 8 10\n5 7 10 6 4 9 6 8 1 5 4 9 10 4 8\n9 6 10 5 8 6 9 9 3 4 4 7 6 2 4\n8 6 10 7 3 3 8 10 3 8 4 8 8 3 1\n7 3 6 8 8 5 5 8 3 7 2 6 3 9 7\n6 8 4 7 7 7 10 4 6 4 3 10 1 10 2\n1 6 7 8 3 4 2 8 1 7 4 4 4 9 5\n3 4 4 6 1 10 2 2 5 8 7 7 7 7 6\n10 9 3 6 8 6 1 9 5 4 7 10 7 1 8\n3 3 4 9 8 6 10 2 9 5 9 5 3 7 3\n1 8 1 3 4 8 10 4 8 4 7 5 4 6 7\n3 10 9 6 8 8 1 8 9 9 4 9 5 6 5\n7 6 3 9 9 8 6 10 3 6 4 2 10 9 7", "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5", "13\n9 9 3 3 5 6 8 2 6 1 10 3 8\n10 4 9 2 10 3 5 10 10 7 10 7 3\n5 8 4 1 10 2 1 2 4 7 9 1 10\n6 3 10 10 10 1 3 10 4 4 2 10 4\n1 7 5 7 9 9 7 4 1 8 5 4 1\n10 10 9 2 2 6 4 1 5 5 1 9 4\n4 2 5 5 7 8 1 2 6 1 2 4 6\n5 1 10 8 1 1 9 1 2 10 6 7 2\n2 1 2 10 4 7 4 1 4 10 10 4 3\n7 7 5 1 2 1 1 4 8 2 4 8 2\n8 8 8 4 1 1 7 3 1 10 1 4 2\n4 5 1 10 8 8 8 4 10 9 4 10 4\n3 1 10 10 5 7 9 4 2 10 4 8 4", "9\n3 9 6 1 7 6 2 8 4\n5 4 1 1 7 2 7 4 10\n7 9 9 4 6 2 7 2 8\n5 7 7 4 9 5 9 1 3\n7 3 10 2 9 4 2 1 2\n5 8 7 4 6 6 2 2 3\n4 8 4 3 4 2 1 8 10\n5 8 2 8 4 4 7 5 4\n2 8 7 4 3 6 10 8 1"], "outputs": ["12\n2 2 3 2", "2242\n6 6 7 6", "0\n1 1 1 2", "361\n7 9 9 8", "159\n4 4 5 4", "280\n6 6 7 6", "181\n5 4 6 4"]}
UNKNOWN
PYTHON3
CODEFORCES
10
1ce225768b73b495b489addb4d0fd10a
Okabe and Boxes
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the stack and throw it in the trash. Okabe wants Daru to throw away the boxes in the order from 1 to *n*. Of course, this means that it might be impossible for Daru to perform some of Okabe's remove commands, because the required box is not on the top of the stack. That's why Daru can decide to wait until Okabe looks away and then reorder the boxes in the stack in any way he wants. He can do it at any point of time between Okabe's commands, but he can't add or remove boxes while he does it. Tell Daru the minimum number of times he needs to reorder the boxes so that he can successfully complete all of Okabe's commands. It is guaranteed that every box is added before it is required to be removed. The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes. Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of the stack. It is guaranteed that exactly *n* lines contain "add" operations, all the boxes added are distinct, and *n* lines contain "remove" operations. It is also guaranteed that a box is always added before it is required to be removed. Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. Sample Input 3 add 1 remove add 2 add 3 remove remove 7 add 3 add 2 add 1 remove add 4 remove remove remove add 6 add 7 add 5 remove remove remove Sample Output 1 2
[ "n=int(input())\ndata=[]\nneed=1\nanswer=0\ni=0\nwhile i!=n:\n s=input()\n if s[0:3]=='add':\n data.append(int(s[4::]))\n else:\n if len(data)==0:\n need += 1\n elif data[-1]==need:\n need+=1\n data.pop()\n else:\n answer+=1\n data=[]\n need +=1\n i += 1\nprint(answer)\n\n \t \t\t \t \t\t \t\t\t\t\t \t \t\t\t", "from sys import stdin,stdout\r\ninput = stdin.readline\r\nimport heapq\r\nn = int(input())\r\ncount = 1\r\ncurr = 0\r\nans = 0\r\nlst2 = []\r\ndct1 = {}\r\nfor i in range(2*n):\r\n lst = list(map(str,input().split()))\r\n if len(lst) == 1:\r\n if lst2 != []:\r\n if lst2[-1] != count:\r\n ans += 1\r\n lst2.pop()\r\n for _ in range(len(lst2)):\r\n dct1[lst2.pop()] = True\r\n else:\r\n lst2.pop()\r\n count += 1\r\n else:\r\n lst2.append(int(lst[1]))\r\nprint(ans)", "n=int(input())\nstk=[]\nc=0\ntop=1\nfor i in range(2*n):\n l=list(map(str,input().split()))\n if(l[0]=='add'):\n stk.append(int(l[1]))\n else:\n if not stk:\n top+=1\n elif stk[-1]==top:\n stk.pop()\n top+=1\n else:\n stk=[]\n c+=1\n top+=1\n \nprint(c)\n\t \t\t\t \t\t\t\t\t\t \t\t \t\t\t\t \t\t", "import heapq\r\n\r\n\r\nqty = 0\r\nstack = []\r\nn = 2 * int(input())\r\ncur = 1\r\n\r\ncmds = {'add':1, 'remove':2}\r\n\r\nfor i in range(n):\r\n \r\n cmd_list = input().split()\r\n cmd = cmds.get(cmd_list[0])\r\n \r\n if cmd == 1:\r\n heapq.heappush(stack, (-i, cmd_list[1]))\r\n else:\r\n if stack:\r\n #print(int(stack[0][1]), cur)\r\n \r\n if (int(stack[0][1]) == cur):\r\n heapq.heappop(stack)\r\n else:\r\n qty += 1\r\n while stack:\r\n heapq.heappop(stack)\r\n \r\n cur += 1\r\nprint(qty)", "t=int(input())\r\nl=[]\r\nc=0\r\nln=0\r\nfor i in range(0,2*t):\r\n q=input().split()\r\n if q[0]==\"add\":\r\n a=q[1]\r\n a=int(a)\r\n l.append(a)\r\n else:\r\n ln=ln+1\r\n if len(l):\r\n if ln!=l[-1]:\r\n c=c+1\r\n l=[]\r\n else:\r\n l.pop()\r\nprint(c)", "#!/usr/bin/env python3\nfrom sys import stdin, stdout\n\ndef rint():\n return map(int, stdin.readline().split())\n#lines = stdin.readlines()\n\nn = int(input())\ncnt = 0\ncurr = 1\nstr = []\nstack = []\nfor i in range(2*n):\n str = list(input().split())\n cmd = str[0]\n if len(str) == 2:\n num = int(str[1])\n if cmd == 'add':\n stack.append(num)\n else:\n if len(stack) != 0:\n if stack[-1] == curr:\n stack.pop()\n else:\n stack = []\n cnt += 1\n curr += 1\nprint(cnt)\n\n\n\n", "def remove():\r\n global c,tot,s\r\n c+=1\r\n if not s: return\r\n elif s.pop()==c-1: return\r\n tot,s=tot+1,[]\r\ns,tot,c=[],0,1\r\nfor _ in range(int(input())*2):\r\n cmd= list(input().split())\r\n if cmd[0]=='add':\r\n s.append(int(cmd[1]))\r\n else: remove()\r\nprint(tot)\r\n ", "import sys\n\nS = []\nA=set()\ncnt = 0\nr = 0\nfor i in range(2*int(sys.stdin.readline().strip())):\n cmd = sys.stdin.readline().strip().split()\n if cmd[0] == \"add\":\n S.append(int(cmd[1]))\n else:\n r += 1\n if S == []:\n if r in A:\n continue\n elif S[-1] == r:\n S.pop()\n continue\n else:\n cnt += 1\n A.union(S)\n S = []\n\nprint(cnt)\n ", "n = 2*int(input())\r\nst = []\r\ncur = 1\r\nans = 0\r\nfor _ in range(n):\r\n op = input().split()\r\n if op[0]==\"add\":\r\n val = int(op[1])\r\n st.append(val)\r\n else:\r\n if st:\r\n if st[-1]==cur: st.pop()\r\n else:\r\n ans += 1\r\n st = []\r\n cur += 1\r\nprint(ans)", "n = int(input())\nbox_stack = []\ncnt = num_rem = 0\n\nfor _ in range(2*n):\n inp = input().split(\" \")\n if inp[0] == \"add\":\n box_stack.append(int(inp[1]))\n else:\n num_rem += 1\n if len(box_stack) == 0:\n \tcontinue\n elif box_stack[-1] == num_rem:\n \tbox_stack.pop()\n \t\n else:\n \tcnt += 1\n \tbox_stack.clear()\n \t\n # print(box_stack)\nprint(cnt)\n \t\t\t\t \t\t\t\t\t\t \t\t \t\t\t\t \t \t", "n = int(input())\r\nindexToDel = 1\r\nstack = [];\r\ncount = 0;\r\nfor i in range(n*2):\r\n line = input().split()\r\n if line[0] == 'remove':\r\n if len(stack) != 0:\r\n if stack[-1] == indexToDel:\r\n stack.pop();\r\n else:\r\n count+=1\r\n stack = []\r\n indexToDel+=1\r\n else:\r\n stack.append(int(line[1]))\r\n \r\nprint(count)", "n=int(input())\r\nlist=[]\r\nans=0\r\nptr=1\r\nfor i in range(2*n):\r\n s=input()\r\n if(s[0]=='a'):\r\n list.append(int(s[4:]))\r\n else:\r\n if(len(list)==0):\r\n ptr+=1\r\n elif list[-1]==ptr:\r\n list.pop()\r\n ptr+=1\r\n else:\r\n list=[]\r\n ans+=1\r\n ptr+=1\r\n \r\nprint(ans)\r\n \r\n", "n=int(input())\r\ns=[]\r\nj=0\r\na=0\r\nfor i in range(2*n):\r\n q=input()\r\n if q=='remove':\r\n if len(s)>0:\r\n x=s.pop()\r\n if x!=j+1:a+=1;s=[]\r\n j+=1\r\n else:s.append(int(q[3:]))\r\nprint(a)", "# /**\r\n# * author: brownfox2k6\r\n# * created: 06/08/2023 16:01:29 Hanoi, Vietnam\r\n# **/\r\n\r\ninput = __import__(\"sys\").stdin.readline\r\n\r\nn = int(input())\r\nst = []\r\nans = 0\r\ncurrentRequired = 1\r\n\r\nfor _ in range(2*n):\r\n command = input().split()\r\n if command[0][0] == 'a':\r\n st.append(int(command[1]))\r\n else:\r\n if st:\r\n if st[-1] == currentRequired:\r\n del st[-1]\r\n else:\r\n ans += 1\r\n st.clear()\r\n currentRequired += 1\r\n\r\nprint(ans)", "n = int(input())\nstack = []\nmi = 1\n\nc=0\nfor _ in range(2*n):\n inp = input()\n if inp[0] == 'a':\n num = int(inp.split()[1])\n stack.append(num)\n else:\n if stack:\n if stack[-1] == mi:\n stack.pop()\n else:\n c+=1\n stack = []\n mi+=1\n\nprint(c)\n \t\t\t \t \t \t \t\t\t \t \t \t", "stack = []\r\nnext_pop_num = 1\r\nr = 0\r\n\r\n\r\nfor _ in range(2 * int(input())):\r\n command = input()\r\n if command.startswith('add'):\r\n n = int(command[4:])\r\n stack.append(n)\r\n else:\r\n if stack and stack[-1] != next_pop_num:\r\n r += 1\r\n stack = []\r\n if stack:\r\n stack.pop(-1)\r\n next_pop_num += 1\r\n\r\nprint(r)", "n = int(input())\r\ncnt = 1\r\nans = 0\r\nl = list()\r\nfor i in range(2*n):\r\n s = input()\r\n if(s[0]=='a'):\r\n l.append(int(s[4:]))\r\n else:\r\n if(len(l)==0):\r\n pass\r\n elif(l[-1]==cnt):\r\n l.pop()\r\n else:\r\n ans += 1\r\n l = list()\r\n cnt += 1\r\nprint(ans)\r\n", "# your code goes here\nc=0\nl=[]\nk=0\nfor _ in range(2*(int(input()))):\n\ta=input()\n\tif a=='remove':\n\t\tif len(l)>0:\n\t\t\tm=l.pop()\n\t\t\tif m!=k+1:\n\t\t\t\tc+=1\n\t\t\t\tl=[]\n\t\tk+=1\t\n\telse:\n\t\tl.append(int(a[3:]))\n\nprint(c)\n\t\t\t\n \t\t\t\t\t \t\t\t\t\t\t\t\t\t \t \t \t\t \t", "import sys\n\ndef main():\n n = int(input())\n n = n*2\n u = 0\n res = 0\n x = []\n for i in range(n):\n s = sys.stdin.readline()\n if s[0] == 'r':\n u+=1\n if len(x)==0:\n continue\n if x[-1] == u:\n x.pop()\n else:\n x = []\n res +=1\n else:\n a,b = s.split()\n x.append(int(b))\n print(res)\n\n\nmain()", "import sys\n\ndef main(input):\n n = int(next(input))\n result = 0\n last_rebuild = -1\n required_box = 0\n boxes = []\n for i in range(2 * n):\n query = next(input).split()\n if query[0] == 'add':\n id = int(query[1]) - 1\n boxes.append((i, id))\n else:\n last_box = boxes[-1]\n while last_box[1] < required_box:\n boxes.pop()\n last_box = boxes[-1]\n if last_box[1] != required_box and last_rebuild < last_box[0]:\n result += 1\n last_rebuild = i\n required_box += 1\n print(result)\n\n\nif __name__ == '__main__':\n main(iter(sys.stdin.readlines()))", "N = int(input())\r\n\r\nans = 0\r\nstack = []\r\n\r\ncurr = 1\r\n\r\nfor _ in range(2 * N):\r\n line = input().split()\r\n # print(stack)\r\n if len(line) == 2:\r\n stack.append(int(line[1]))\r\n elif line[0] == \"remove\":\r\n if len(stack) > 0:\r\n if stack[-1] == curr:\r\n stack.pop()\r\n else:\r\n ans += 1\r\n stack = []\r\n curr += 1\r\n # print(stack)\r\n \r\nprint(ans)\r\n\r\n# n = int(input())\r\n# st = []\r\n# curr = 1\r\n# ans = 0\r\n# for i in range(2*n):\r\n# str = input()\r\n# assert(str[0]=='a' or str[0]=='r')\r\n# if str[0]=='a':\r\n# x = int(input())\r\n# st.append(x)\r\n# elif str[0]=='r':\r\n# if st:\r\n# if st[-1]==curr: #last thing added is what we need to remove\r\n# st.pop()\r\n# else: #last thing we added is NOT what we need to remove\r\n# ans += 1\r\n# st = [] #clears the stack\r\n# curr += 1\r\n# print(ans)", "n = int(input())\r\nstck = []\r\nst = set()\r\ncur_remove = 1\r\nans = 0\r\nfor q in range(n * 2):\r\n s = input().split()\r\n c = s[0]\r\n if c == 'add':\r\n val = int(s[1])\r\n stck.append(val)\r\n else:\r\n if (len(stck) > 0 and cur_remove == stck[len(stck) - 1]) or (len(stck) == 0 and cur_remove in st):\r\n if len(stck) > 0 and cur_remove == stck[len(stck) - 1]:\r\n stck.pop()\r\n cur_remove += 1\r\n continue\r\n ans += 1\r\n for j in stck:\r\n st.add(j)\r\n stck.clear()\r\n cur_remove += 1\r\nprint(ans)", "from sys import stdout, stdin\r\ninput = stdin.readline\r\n\r\nn = int(input())\r\nstk, res, t = [], 0, 1\r\nfor i in range(2*n):\r\n x = input().split()\r\n if len(x) == 2: \r\n stk.append(int(x[1]))\r\n continue\r\n if stk:\r\n if stk[-1] != t:\r\n res += 1\r\n stk = []\r\n else:\r\n stk.pop()\r\n t += 1\r\nprint(str(res))\r\n", "from heapq import heappush, heappop, nsmallest\r\n\r\nn = int(input())\r\n\r\n\r\nstack_head = -1\r\nrems = 0\r\nans = 0\r\nnums = []\r\nstack = []\r\n\r\nfor i in range(2*n):\r\n command = input().split()\r\n\r\n if command[0] == 'add':\r\n box = int(command[1])\r\n stack.append(box)\r\n\r\n else:\r\n rems += 1\r\n\r\n if len(stack) == 0:\r\n continue\r\n\r\n elif stack[-1] == rems:\r\n stack.pop()\r\n\r\n else:\r\n ans += 1\r\n stack.clear()\r\n\r\n\r\nprint(ans)", "from collections import deque\r\nn=int(input())\r\ns=0\r\nc=1\r\nq=deque([])\r\nl=False\r\nfor i in range(2*n):\r\n t=input()\r\n if t[0]=='a':\r\n m=int(t[4:])\r\n q.append(m)\r\n l=False\r\n else:\r\n if len(q)>0:\r\n f=q.pop()\r\n if l==False and f!=c:\r\n s+=1\r\n l=True\r\n q=[]\r\n c+=1\r\nprint(s)", "n = int(input())\r\nc = 1\r\nl = []\r\nt = 0\r\nfor _ in range(2 * n):\r\n i = input().split()\r\n if i[0] == \"add\":\r\n l.append(int(i[1]))\r\n else:\r\n if l:\r\n if l[-1] == c:\r\n l.pop()\r\n else:\r\n t += 1\r\n l = []\r\n c += 1\r\nprint(t)\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom heapq import *\r\n\r\nN = int(input())\r\n\r\nans = 0\r\nv,tmp = [],[]\r\ncur = 1\r\nfor _ in range(2*N):\r\n arr = input().split()\r\n if arr[0]=='add':\r\n tmp.append(int(arr[1]))\r\n else:\r\n if tmp:\r\n if tmp[-1]==cur:\r\n tmp.pop()\r\n else:\r\n for k in tmp:\r\n heappush(v, k)\r\n tmp = []\r\n ans+=1\r\n heappop(v)\r\n else:\r\n heappop(v)\r\n cur+=1\r\n \r\nprint(ans)\r\n \r\n \r\n ", "import sys\nimport queue\n\ndef main(lines):\n n = int(lines[0])\n result = 0\n last_rebuild = -1\n required_box = 0\n boxes = []\n add_time = [0] * n\n is_deleted = [False] * n\n for i in range(2 * n):\n query = lines[i + 1].split()\n if query[0] == 'add':\n id = int(query[1]) - 1\n boxes.append((i, id))\n else:\n last_box = boxes[-1]\n while is_deleted[last_box[1]]:\n boxes.pop()\n last_box = boxes[-1]\n if last_box[1] != required_box and last_rebuild < last_box[0]:\n result += 1\n last_rebuild = i\n is_deleted[required_box] = True\n required_box += 1\n print(result)\n\n\nif __name__ == '__main__':\n main(sys.stdin.readlines())", "n=int(input())\r\nst=[]\r\nans,now=0,1\r\nfor i in range(2*n):\r\n s=input()\r\n if s[0]==\"a\":\r\n st.append(int(s[4:]))\r\n else:\r\n if len(st)==0:\r\n now+=1\r\n else:\r\n if st[-1]==now:\r\n now+=1\r\n st.pop()\r\n else:\r\n st=[]\r\n ans+=1\r\n now+=1\r\nprint(ans)\r\n", "n=int(input())\nl=[]\ntmp=0 \nc=0\nfor _ in range(2*n):\n s=input().split()\n if s[0]=='add':\n l.append(int(s[1]))\n else:\n tmp+=1 \n m=len(l)\n if m>0 and l[-1]==tmp:\n l.pop()\n elif m>0:\n l=[]\n c+=1 \nprint(c)\n\t \t\t\t \t \t\t\t\t\t \t\t \t\t \t", "# Time : 2017-6-26 14:30\r\n# Auther : Anjone\r\n# URL : http://codeforces.com/contest/821/problem/C\r\n\r\n\r\nans = 0\r\nnum = 1\r\nstack = []\r\nn = int(input())\r\nfor i in range(2*n):\r\n\ts = input()\r\n\tif s.find(\"add\") != -1:\r\n\t\tstack.append(int(s.split()[1]) )\r\n\telse:\r\n\t\tif len(stack) != 0 and stack[-1] != num:\r\n\t\t\tstack = []\r\n\t\t\tans+=1\r\n\t\tif len(stack):\r\n\t\t\tstack.pop()\r\n\t\tnum += 1\r\nprint(ans)\r\n\r\n", "n = int(input())\nc = 1\nsorts = 0\nboxes = []\n\nfor _ in range(2 * n):\n s = input()\n if s[0] == 'a':\n boxes.append(int(s[4:]))\n else:\n if boxes:\n if boxes[-1] != c:\n boxes = []\n sorts += 1\n else:\n boxes.pop()\n c += 1\nprint(sorts)\n", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Mar 3 21:30:07 2023\r\n\r\n@author: manisarthak\r\n\"\"\"\r\n\r\n\r\nimport sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\n\r\n\r\ndef solve():\r\n n = int(input())\r\n l = []\r\n ans = 0\r\n curr = 1\r\n for i in range(2*n):\r\n ss = list(input().split())\r\n if ss[0] == 'add':\r\n l.append(ss[1])\r\n\r\n else:\r\n if len(l) == 0:\r\n \r\n pass\r\n elif l[-1] == str(curr) :\r\n l.pop()\r\n else:\r\n ans += 1 \r\n l = []\r\n curr += 1\r\n print(ans)\r\n \r\n \r\n\r\nsolve()\r\n# for _ in range(int(input())):\r\n# solve()\r\n\r\n\r\n " ]
{"inputs": ["3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove", "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove", "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremove", "2\nadd 1\nremove\nadd 2\nremove", "1\nadd 1\nremove", "15\nadd 12\nadd 7\nadd 10\nadd 11\nadd 5\nadd 2\nadd 1\nadd 6\nadd 8\nremove\nremove\nadd 15\nadd 4\nadd 13\nadd 9\nadd 3\nadd 14\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "14\nadd 7\nadd 2\nadd 13\nadd 5\nadd 12\nadd 6\nadd 4\nadd 1\nadd 14\nremove\nadd 10\nremove\nadd 9\nadd 8\nadd 11\nadd 3\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "11\nadd 10\nadd 9\nadd 11\nadd 1\nadd 5\nadd 6\nremove\nadd 3\nadd 8\nadd 2\nadd 4\nremove\nremove\nremove\nremove\nremove\nadd 7\nremove\nremove\nremove\nremove\nremove", "3\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove", "4\nadd 1\nadd 3\nadd 4\nremove\nadd 2\nremove\nremove\nremove", "6\nadd 3\nadd 4\nadd 5\nadd 1\nadd 6\nremove\nadd 2\nremove\nremove\nremove\nremove\nremove", "16\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "2\nadd 2\nadd 1\nremove\nremove", "17\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "18\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "4\nadd 1\nadd 2\nremove\nremove\nadd 4\nadd 3\nremove\nremove", "19\nadd 1\nadd 2\nadd 3\nadd 4\nadd 5\nadd 6\nadd 7\nadd 8\nadd 9\nadd 10\nadd 11\nadd 12\nadd 13\nadd 14\nadd 15\nadd 16\nadd 17\nadd 18\nadd 19\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove\nremove", "5\nadd 4\nadd 3\nadd 1\nremove\nadd 2\nremove\nremove\nadd 5\nremove\nremove", "7\nadd 4\nadd 6\nadd 1\nadd 5\nadd 7\nremove\nadd 2\nremove\nadd 3\nremove\nremove\nremove\nremove\nremove", "8\nadd 1\nadd 2\nadd 3\nadd 7\nadd 8\nremove\nremove\nremove\nadd 6\nadd 5\nadd 4\nremove\nremove\nremove\nremove\nremove", "4\nadd 1\nadd 4\nremove\nadd 3\nadd 2\nremove\nremove\nremove", "7\nadd 1\nadd 2\nadd 3\nadd 5\nadd 7\nremove\nremove\nremove\nadd 4\nremove\nremove\nadd 6\nremove\nremove", "4\nadd 4\nadd 1\nadd 2\nremove\nremove\nadd 3\nremove\nremove", "5\nadd 1\nadd 3\nadd 4\nadd 5\nremove\nadd 2\nremove\nremove\nremove\nremove", "5\nadd 2\nadd 1\nremove\nremove\nadd 5\nadd 3\nremove\nadd 4\nremove\nremove", "9\nadd 3\nadd 2\nadd 1\nadd 4\nadd 6\nadd 9\nremove\nremove\nremove\nremove\nadd 5\nremove\nremove\nadd 8\nadd 7\nremove\nremove\nremove", "10\nadd 9\nadd 10\nadd 4\nadd 3\nadd 2\nadd 1\nremove\nremove\nremove\nremove\nadd 8\nadd 7\nadd 5\nadd 6\nremove\nremove\nremove\nremove\nremove\nremove"], "outputs": ["1", "2", "2", "0", "0", "2", "3", "2", "0", "1", "1", "1", "0", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "0", "1", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
33
1cec334a5ccee5eb45955d9a63427621
Graph Coloring
You are given an undirected graph that consists of *n* vertices and *m* edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edges with an endpoint in this vertex change the color to red. Find the minimum possible number of moves required to make the colors of all edges equal. The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — the number of vertices and edges, respectively. The following *m* lines provide the description of the edges, as the *i*-th of them contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the indices of the vertices connected by the *i*-th edge, and a character *c**i* () providing the initial color of this edge. If *c**i* equals 'R', then this edge is initially colored red. Otherwise, *c**i* is equal to 'B' and this edge is initially colored blue. It's guaranteed that there are no self-loops and multiple edges. If there is no way to make the colors of all edges equal output <=-<=1 in the only line of the output. Otherwise first output *k* — the minimum number of moves required to achieve the goal, then output *k* integers *a*1,<=*a*2,<=...,<=*a**k*, where *a**i* is equal to the index of the vertex that should be used at the *i*-th move. If there are multiple optimal sequences of moves, output any of them. Sample Input 3 3 1 2 B 3 1 R 3 2 B 6 5 1 3 R 2 3 R 3 4 B 4 5 R 4 6 R 4 5 1 2 R 1 3 R 2 3 B 3 4 B 1 4 B Sample Output 1 2 2 3 4 -1
[ "from collections import deque\r\n \r\nn, m = map(int, input().split())\r\nadj = [[] for i in range(n)]\r\nfor i in range(m):\r\n u, v, c = input().split()\r\n u, v = int(u)-1, int(v)-1\r\n adj[u].append((v, c))\r\n adj[v].append((u, c))\r\n \r\nvisited = S = T = None\r\n \r\ndef bfs(i, k):\r\n q = deque([(i, 0)])\r\n while q:\r\n u, p = q.pop()\r\n \r\n if visited[u] >= 0:\r\n if visited[u] == p: continue\r\n else: return False\r\n \r\n visited[u] = p\r\n if p: S.append(u)\r\n else: T.append(u)\r\n \r\n for v, c in adj[u]:\r\n nxt = p if c == k else p^1\r\n q.appendleft((v, nxt))\r\n \r\n return True\r\n \r\ndef solve(k):\r\n global visited, S, T\r\n visited = [-1]*n\r\n res = []\r\n for i in range(n):\r\n if visited[i] < 0:\r\n S, T = [], []\r\n if not bfs(i, k):\r\n return [0]*(n+1)\r\n else:\r\n res.extend(S if len(S) < len(T) else T)\r\n return res\r\n \r\nres1 = solve(\"R\")\r\nres2 = solve(\"B\")\r\n \r\nif min(len(res1), len(res2)) > n:\r\n print (-1)\r\nelse:\r\n print (min(len(res1), len(res2)))\r\n print (\" \".join(map(lambda x: str(x+1), res1 if len(res1) < len(res2) else res2)))\r\n" ]
{"inputs": ["3 3\n1 2 B\n3 1 R\n3 2 B", "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R", "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B", "6 6\n1 2 R\n1 3 R\n2 3 R\n4 5 B\n4 6 B\n5 6 B", "3 3\n1 2 R\n1 3 R\n2 3 R", "11 7\n1 2 B\n1 3 R\n3 2 R\n4 5 R\n6 7 R\n8 9 R\n10 11 R", "2 1\n1 2 B"], "outputs": ["1\n2 ", "2\n3 4 ", "-1", "-1", "0", "5\n3 4 6 8 10 ", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1cf5b764b7c020a63fed240ea3c9ed09
Pasha and Phone
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly *n* digits. Also Pasha has a number *k* and two sequences of length *n*<=/<=*k* (*n* is divisible by *k*) *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* and *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k*. Let's split the phone number into blocks of length *k*. The first block will be formed by digits from the phone number that are on positions 1, 2,..., *k*, the second block will be formed by digits from the phone number that are on positions *k*<=+<=1, *k*<=+<=2, ..., 2·*k* and so on. Pasha considers a phone number good, if the *i*-th block doesn't start from the digit *b**i* and is divisible by *a**i* if represented as an integer. To represent the block of length *k* as an integer, let's write it out as a sequence *c*1, *c*2,...,*c**k*. Then the integer is calculated as the result of the expression *c*1·10*k*<=-<=1<=+<=*c*2·10*k*<=-<=2<=+<=...<=+<=*c**k*. Pasha asks you to calculate the number of good phone numbers of length *n*, for the given *k*, *a**i* and *b**i*. As this number can be too big, print it modulo 109<=+<=7. The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(*n*,<=9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that *n* is divisible by *k*. The second line of the input contains *n*<=/<=*k* space-separated positive integers — sequence *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* (1<=≤<=*a**i*<=&lt;<=10*k*). The third line of the input contains *n*<=/<=*k* space-separated positive integers — sequence *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k* (0<=≤<=*b**i*<=≤<=9). Print a single integer — the number of good phone numbers of length *n* modulo 109<=+<=7. Sample Input 6 2 38 56 49 7 3 4 8 2 1 22 3 44 5 4 3 2 Sample Output 8 32400
[ "MOD=10**9+7\r\nn,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nk1,k2,ans=10**k,10**(k-1),1\r\nfor i in range(n//k):\r\n z,x=a[i],b[i]\r\n if b[i]>0: c=(x*k2-1)//z+(k1-1)//z-((x+1)*k2-1)//z+1\r\n else: c=(k1-1)//z-(k2-1)//z\r\n ans=ans*c%MOD\r\nprint(ans)", "def get_arr(Len):\r\n buff = input().split()\r\n a = []\r\n for i in range(Len):\r\n a.append(int(buff[i]))\r\n return a\r\n\r\nbase = int(1e9 + 7)\r\nbuff = input().split()\r\nn = int(buff[0])\r\nk = int(buff[1])\r\na = get_arr(n//k)\r\nb = get_arr(n//k)\r\nc = []\r\n\r\nfor i in range(n//k):\r\n ans = 0\r\n if (b[i] != 0):\r\n ans += (pow(10, k ) - 1) // a[i]\r\n ans -= ( (b[i] * pow(10, k - 1)) + pow(10, k - 1) - 1) // a[i]\r\n ans += ( ((b[i] - 1) * pow(10, k - 1)) + pow(10, k - 1) - 1) // a[i]\r\n ans += 1 # 00000..00\r\n else:\r\n ans = (pow( 10, k ) - 1) // a[i]\r\n ans -= (pow(10, k - 1) - 1) // a[i]\r\n c.append(ans % base)\r\nans = 1\r\nfor i in range(n//k):\r\n ans *= c[i]\r\n ans %= base\r\nprint(ans)", "M = 10**9 + 7\n\n\ndef good(k, a, b):\n t = (10**k - 1) // a + 1\n s = (b * 10**(k-1) - 1) // a + 1\n e = ((b+1) * 10**(k-1) - 1) // a + 1\n return (t - (e - s)) % M\n\n\ndef total_good(k, ai, bi):\n p = 1\n for a, b in zip(ai, bi):\n p = (p * good(k, a, b)) % M\n return p\n\n\nif __name__ == '__main__':\n n, k = map(int, input().split())\n assert n % k == 0\n ai = map(int, input().split())\n bi = map(int, input().split())\n print(total_good(k, ai, bi))\n", "import math\nn,k = map(int, input().split())\na = map(int, input().split())\nb = map(int, input().split())\n\n\n\ndef calc_ans(k,a,b):\n\tdiv = (10**k-1)//a + 1\n\t\n\tb_min = b*10**(k-1)\n\tb_max = (b+1)*10**(k-1) - 1\n\n\n\td_min_inc = math.ceil(b_min/a)\n\td_max_inc = math.floor(b_max/a)\n\t# if d_min_inc*a > b_max:\n\t# \treturn div\n\t# else:\n\n\n\t# print (k,a,b,div,div - (d_max_inc - d_min_inc + 1))\n\n\treturn div - (d_max_inc - d_min_inc + 1)\n\np = 10**9 + 7\n\nans = 1\nfor ai,bi in zip(a,b):\n\tans = (ans*calc_ans(k, ai, bi)) % p\n\nprint(ans)\n\ndef easy_calc(k,a,b):\n\tans = 0\n\tfor i in range(10**k):\n\t\tc = str(i)\n\t\tfirst = int(c[0]) if len(c) == k else 0\n\t\tif i%a == 0 and not first==b:\n\t\t\tans += 1\n\treturn ans\n\n# import random\n# for i in range(100):\n# \tk = random.randrange(4,5)\n# \ta = random.randrange(1,10**k)\n# \tb = random.randrange(0, 10)\n# \tif easy_calc(k,a,b) != calc_ans(k,a,b):\n# \t\tprint(k,a,b, easy_calc(k,a,b), calc_ans(k,a,b))\n# \t\t1/0", "import math\n\nn, k = [int(x) for x in input().split()]\n\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\n\nc = 1\nfor i in range(n // k):\n count = (10 ** k - 1) // a[i] + 1\n mmin = b[i] * (10 ** (k-1))\n mmax = (b[i] + 1) * (10 ** (k-1)) - 1\n mcount = mmax // a[i] - math.ceil(mmin / a[i]) + 1\n c = (c * (count - mcount)) % ((10 ** 9) + 7)\n\nprint(c)\n", "mod = 10**9 + 7\r\n\r\nn,k = map(int,input().split())\r\n\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\n\r\nans = 1;\r\n\r\nfor i in range(n//k):\r\n cnt = (10**k - 1)//a[i] - (10**(k-1)*(b[i]+1) - 1 )//a[i]\r\n if b[i] != 0:\r\n cnt += (10**(k-1)*b[i] - 1)//a[i] + 1\r\n ans=ans*cnt%mod\r\nprint(ans)\r\n", "from math import *\r\nN, K = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nans = 1\r\nM = 10**9 + 7\r\np = 10**K - 1\r\nu = 10**(K - 1)\r\nfor i in range(N // K):\r\n ans *= (p // a[i] + 1 - ((u * (b[i] + 1) + a[i] - 1) // a[i] - (b[i] * u + a[i] - 1) // a[i]))\r\n ans %= M\r\nprint((ans + M) % M)", "n, k = [int(i) for i in input().split()]\r\nsum = 1\r\na = [int(i) for i in input().split()]\r\nb = [int(i) for i in input().split()]\r\nfor i in range(n // k):\r\n if n == 0:\r\n x = (10 ** k - 1) // a[i] - ((b[i] + 1) * 10 ** (k-1) - 1) // a[i]\r\n else:\r\n x = (10 ** k - 1) // a[i] - ((b[i] + 1) * 10 ** (k-1) - 1) // a[i] + (b[i] * 10 ** (k-1) - 1) // a[i] + 1\r\n sum *= x\r\n sum %= 10 ** 9 + 7\r\nprint(sum)\r\n", "mod=10**9+7\r\nea,b=map(int,input().split())\r\nx=list(map(int,input().split()))\r\ny=list(map(int,input().split()))\r\nd,e,result=10**b,10**(b-1),1\r\nfor now in range(ea//b):\r\n tt,s=x[now],y[now]\r\n if y[now]>0: h=(s*e-1)//tt+(d-1)//tt-((s+1)*e-1)//tt+1\r\n else: h=(d-1)//tt-(e-1)//tt\r\n result=result*h%mod\r\nprint(result)", "R = lambda : map(int,input().split())\n\nn,k = R()\nt = 1\nmod = 10**9+7\n\ndef gn(x,p):\n if x < 0:\n return 0\n\n return x//p+1\n\ndef solve(a,b,k):\n if k == 1:\n return 9//a if b%a==0 else 9//a+1\n\n m = b*pow(10,k-1,a)%a\n w = 10**(k-1)-1+m\n r = gn(10**k-1,a)-(gn(w,a)-gn(m-1,a))\n return r\n\na = list(R())\nb = list(R())\n\nfor i in range(len(a)):\n t *= solve(a[i],b[i],k)\n t %= mod\n\nprint(t%mod)\n", "def cnt(l, r, x):\r\n return (r - l) // x + (l % x == 0) + (l % x > r % x)\r\n#\r\n(n, k) = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nans = 1\r\nfor i in range(n // k):\r\n l = b[i] * pow(10, k - 1)\r\n r = (b[i] + 1) * pow(10, k - 1) - 1\r\n ans = (ans * (cnt(0, pow(10, k) - 1 ,a[i]) - cnt(l, r, a[i]))) % (pow(10, 9) + 7)\r\n #print(ans)\r\nprint(ans)\r\n", "n, k = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nt = 10 ** (k - 1)\r\nres = 1;\r\nq = 10 ** 9 + 7\r\nfor i in range(n // k):\r\n res1 = (((t * 10) - 1) // a[i] + 1) % q;\r\n z = ((t * b[i]) - 1) // a[i] + 1\r\n if (b[i] == 0):\r\n z = 0\r\n x = (((t * b[i] + t - 1) // a[i])) + 1\r\n res1 = (res1 - x + z) % q\r\n res = (res * res1) % q\r\nprint(res)\r\n", "from math import *\n\nMOD = 1000000007\n\nn, k = map(int, input().split())\n\na = [int(i) for i in input().split()]\nb = [int(i) for i in input().split()]\n\nres = 1\nfor i in range(n // k):\n cont = ceil(10**k / a[i]) - ceil((b[i] + 1) * 10**(k-1) / a[i]) + ceil(b[i] * 10**(k-1) / a[i])\n # print(cont)\n res = (res * cont) % MOD\n\nprint(res)\n", "\"\"\"\nCodeforces Round #330 (Div. 2)\n\nProblem 595 B\n\n@author yamaton\n@date 2015-11-08\n\"\"\"\n\nimport itertools as it\nimport functools\nimport operator\nimport collections\nimport math\nimport sys\n\nBASE = 1000000007\n\ndef count(k, a, b):\n x = count_multiples(a, 0, 10**k-1)\n y = count_multiples(a, b * 10**(k-1), (b + 1) * 10**(k-1) - 1)\n return x - y\n\n\ndef count_multiples(a, _from, _to):\n if _from == 0:\n return _to // a - (_from - 1) // a\n else:\n return _to // a - (_from - 1) // a\n\n\ndef solve(xs, ys, n, k):\n result = 1\n for (a, b) in zip(xs, ys):\n result = (result * count(k, a, b)) % BASE\n return result\n\ndef main():\n [n, k] = [int(i) for i in input().strip().split()]\n xs = [int(i) for i in input().strip().split()]\n ys = [int(i) for i in input().strip().split()]\n assert len(xs) == len(ys) == n // k\n result = solve(xs, ys, n, k)\n print(result)\n\n\nif __name__ == '__main__':\n main()\n", "from math import ceil\r\nfrom math import floor\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nln = n // k\r\np = 1\r\nmod = 1000000007\r\n\r\nfor i in range(ln):\r\n tmp = (10 ** k - 1) // a[i] + 1\r\n l = ceil(b[i] * (10 ** (k - 1)) / a[i])\r\n r = floor(((b[i] + 1) * (10 ** (k - 1)) - 1) / a[i])\r\n tmp -= r - l + 1\r\n p = (p * tmp) % mod\r\n\r\nprint(p)\r\n\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nMOD = 10**9+7\r\nans = 1\r\n\r\nfor ai, bi in zip(a, b):\r\n if bi==0:\r\n h = 10**(k-1)-1\r\n cnt = h//ai+1\r\n else:\r\n h = bi*10**(k-1)+10**(k-1)-1\r\n l = (bi-1)*10**(k-1)+10**(k-1)-1\r\n cnt = h//ai-l//ai\r\n\r\n ans *= (10**k-1)//ai+1-cnt\r\n ans %= MOD\r\n\r\nprint(ans)", "inp = list(map(int, input().split()))\r\n\r\nn = inp[0]\r\nk = inp[1]\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\n\r\ncnt = 10 ** k\r\ncnt1 = 10 ** (k - 1)\r\nl = n // k\r\nans = 1\r\n\r\nfor i in range(l):\r\n c = ((cnt - 1) // a[i]) + 1\r\n c -= (((b[i] + 1) * cnt1 - 1) // a[i] + 1) - (((b[i] * cnt1 - 1) // a[i] + 1) if b[i] >= 0 else 0)\r\n ans *= c\r\n ans %= int(1e9 + 7)\r\nprint(ans)\r\n\r\nimport time, sys\r\nsys.stderr.write('{0:.3f} ms\\n'.format(time.clock() * 1000));", "from math import *\r\ndef solve():\r\n res = 1\r\n for i in range(n // k):\r\n tmp = P\r\n tmp = ceil(tmp / a1[i])\r\n t = ceil(P / 10 * a2[i] / a1[i]) * a1[i]\r\n t = ceil((P - t - P//10*(9-a2[i])) / a1[i])\r\n #print(t)\r\n if t < 0 : t = 0\r\n tmp -= t\r\n #print(tmp)\r\n res = (res * tmp) % M \r\n print(res)\r\nn, k = map(int,input().split())\r\na1 = list(map(int,input().split()))\r\na2 = list(map(int,input().split()))\r\nM = int(1e9 + 7)\r\nP = tmp = pow(10, k)\r\nsolve()", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nMOD = 10**9+7\r\nN,K = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nB = list(map(int, input().split()))\r\n\r\nD = []\r\nfor i in range(N//K):\r\n a = A[i]\r\n b = B[i]\r\n \r\n cnt = 0\r\n for j in range(10):\r\n if j==b:continue\r\n l = max(0,(10**(K-1))*j-1)\r\n r = (10**(K-1))*(j+1)-1\r\n \r\n #print(l,r,r//a-l//a)\r\n cnt+=r//a-l//a\r\n if j==0:\r\n cnt+=1\r\n D.append(cnt)\r\n #print('---')\r\n \r\nans = 1\r\nfor a in D:\r\n ans*=a\r\n ans%=MOD\r\nprint(ans)\r\n", "mod = 1000000000+7\r\nn,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\nblo = n//k\r\nans=1\r\nfor i in range(blo):\r\n cnt= (10**k -1)//a[i] - (10**(k-1)*(b[i]+1)-1)//a[i]\r\n if b[i]>0:\r\n cnt+=(10**(k-1)*b[i]-1)//a[i] + 1\r\n ans = (ans*cnt)%mod\r\nprint(ans) \r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nc = n//k\r\nans = 1\r\nfor i in range(c):\r\n t_ans = ((10**k - 1)//a[i]+1) + (b[i]*10**(k-1))//a[i] - ((b[i]+1)*10**(k-1))//a[i]\r\n if (b[i]*10**(k-1))%a[i] == 0:\r\n t_ans -= 1\r\n if ((b[i]+1)*10**(k-1))%a[i] == 0:\r\n t_ans += 1 \r\n ans *= t_ans\r\n ans = ans%(10**9 +7)\r\nprint(ans)\r\n \r\n", "n,k = map(int,input().split())\r\nb = list(map(int,input().split()))\r\nc = list(map(int,input().split()))\r\nmod = 1000000007\r\nans = 1\r\nfor x in range(0,n//k):\r\n po = 10**(k-1)\r\n p = c[x]*po\r\n q = (c[x]+1)*po\r\n res = 0\r\n if p%b[x] == 0:\r\n res -= 1\r\n if q%b[x] == 0:\r\n res += 1\r\n if (po*10)%b[x] == 0:\r\n res -= 1\r\n res += 1\r\n res += 10*po//b[x] - q//b[x] + p//b[x]\r\n ans = ((ans%mod)*(res%mod))%mod\r\nprint(ans)\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nd = n // k\r\nr = [0] * d\r\nfor i in range(d):\r\n r[i] = int('1' * k) * 9 // a[i] + 1\r\n x = int(str(b[i]) + (k - 1) * '9') // a[i] + 1\r\n if b[i] > 0:\r\n x -= int(str(b[i] - 1) + (k - 1) * '9') // a[i] + 1\r\n r[i] -= x\r\np = 1\r\nfor i in range(d):\r\n r[i] %= 10 ** 9 + 7\r\n p = (p * r[i]) % (10 ** 9 + 7)\r\nprint(p)\r\n", "from math import ceil\n\nn,k = map(int,input().split())\n\narr1 = list(map(int,input().split()))\narr2 = list(map(int,input().split()))\n\np = 10**k\n\nans = 1\n\nfor i in range(n//k):\n x,y = arr1[i],arr2[i]\n a,b = y * 10**(k - 1),(y + 1) * 10**(k - 1)\n ans *= ceil(p / x) - (ceil(b / x) - ceil(a / x))\n ans %= 10**9 + 7\n\nprint(ans)\n", "n, k = map(int, input().split())\r\nAs = list(map(int, input().split()))\r\nBs = list(map(int, input().split()))\r\n\r\ndef solve(n, k, As, Bs):\r\n mod = 10 ** 9 + 7\r\n c = 1\r\n for a, b in zip(As, Bs):\r\n c *= f(a, b, k, mod)\r\n c %= mod\r\n return c\r\n\r\ndef f(a, b, k, mod):\r\n total = (10 ** k - 1) // a + 1\r\n p = ((b + 1) * (10 ** (k-1)) - 1) // a\r\n q = (b * (10 ** (k-1)) - 1) // a\r\n return (total - p + q) % mod\r\n\r\n\r\nprint(solve(n, k, As, Bs))", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(x, y):\r\n return x // y + 1\r\n\r\nn, k = map(int, input().split())\r\nmod = pow(10, 9) + 7\r\na = list(map(int, input().split()))\r\nb = list(map(int, input().split()))\r\nu = pow(10, k) - 1\r\nv = pow(10, k - 1)\r\nans = 1\r\nfor i, j in zip(a, b):\r\n ans = ans * (f(u, i) - (f((j + 1) * v - 1, i) - f(j * v - 1, i))) % mod\r\nprint(ans)", "n, k = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nb = [int(i) for i in input().split()]\r\nres, MOD = 1, int(1e9 + 7)\r\npow10 = 10 ** k\r\nfor i in range(n // k):\r\n lo = (pow10 // 10) * b[i] - 1\r\n up = (pow10 // 10) * (b[i] + 1) - 1\r\n tmp = (pow10 - 1) // a[i] + 1\r\n tmp -= up // a[i]\r\n tmp += lo // a[i]\r\n res = (res * tmp) % MOD\r\nprint(res)\r\n", "p = 10**9+7\nn,k = map(int,input().split())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nans = 1\nfor i in range(n//k):\n\tcnt = (10**k-1)//a[i] - (10**(k-1)*(b[i]+1)-1)//a[i]\n\tif b[i] != 0:\n\t\tcnt += (10**(k-1)*b[i]-1)//a[i] + 1\n\tans = ans * cnt % p\nprint (ans)", "# import sys\r\n# n = int(input())\r\n# s = input().strip()\r\n# a = [int(tmp) for tmp in input().split()]\r\n# for i in range(n):\r\nn, k = [int(tmp) for tmp in input().split()]\r\na = [int(tmp) for tmp in input().split()]\r\nb = [int(tmp) for tmp in input().split()]\r\nBIG = 10 ** 9 + 7\r\nm = n // k\r\nans = [0] * m\r\nfor i in range(m):\r\n ans[i] = (10 ** k + a[i] - 1) // a[i]\r\n x = 10 ** (k - 1) * b[i] % a[i]\r\n if x != 0:\r\n ans[i] -= (10 ** (k - 1) + x + a[i] - 1) // a[i] - 1\r\n else:\r\n ans[i] -= (10 ** (k - 1) + x + a[i] - 1) // a[i]\r\nall_ans = 1\r\nfor i in range(m):\r\n all_ans = (all_ans * ans[i]) % BIG\r\nprint(all_ans)", "\ninp = list(map(int, input().split()))\n\nn = inp[0]\nk = inp[1]\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\n\ncnt = 10 ** k\ncnt1 = 10 ** (k - 1)\nl = n // k\nans = 1\n\nfor i in range(l):\n c = ((cnt - 1) // a[i]) + 1\n c -= (((b[i] + 1) * cnt1 - 1) // a[i] + 1) - (((b[i] * cnt1 - 1) // a[i] + 1) if b[i] >= 0 else 0)\n ans *= c\n ans %= int(1e9 + 7)\nprint(ans)\n\nimport time, sys\nsys.stderr.write('{0:.3f} ms\\n'.format(time.clock() * 1000));\n" ]
{"inputs": ["6 2\n38 56 49\n7 3 4", "8 2\n1 22 3 44\n5 4 3 2", "2 1\n9 9\n9 9", "2 1\n9 9\n0 9", "4 1\n4 3 2 1\n1 2 3 4", "18 9\n2 3\n0 4", "4 4\n1122\n2", "10 5\n8378 11089\n7 5", "10 5\n52057 11807\n0 1", "10 1\n3 1 1 4 8 7 5 6 4 1\n0 0 0 5 5 6 8 8 4 0", "100 4\n388 2056 122 1525 2912 1465 3066 257 5708 3604 3039 6183 3035 626 1389 5393 3321 3175 2922 2024 3837 437 5836 2376 1599\n6 5 5 2 9 6 8 3 5 0 6 0 1 8 5 3 5 2 3 0 5 6 6 7 3", "100 1\n5 3 1 5 6 2 4 8 3 3 1 1 2 8 2 3 8 2 5 2 6 2 3 5 2 1 2 1 2 8 4 3 3 5 1 4 2 2 2 5 8 2 2 6 2 9 2 4 1 8 1 5 5 6 6 1 2 7 3 3 4 2 4 1 2 6 6 4 9 4 3 2 3 8 2 3 1 4 1 4 1 3 5 3 5 5 2 3 4 1 1 8 1 5 6 9 4 2 5 1\n6 0 4 5 3 1 0 7 5 3 9 4 5 4 0 2 1 6 2 2 4 3 1 9 5 9 2 2 6 8 6 5 9 6 4 9 9 7 5 4 5 6 0 3 2 0 8 0 3 9 5 3 8 0 9 3 6 2 9 5 9 3 2 2 2 2 0 8 1 2 9 0 9 8 0 3 2 0 7 9 4 3 7 2 3 1 8 9 8 2 6 0 3 2 9 8 9 2 3 4", "100 5\n5302 4362 11965 14930 11312 33797 17413 17850 79562 17981 28002 40852 173 23022 55762 13013 79597 29597 31944 32384\n9 8 7 0 6 6 7 7 5 9 1 3 4 8 7 1 1 6 4 4", "1 1\n2\n0"], "outputs": ["8", "32400", "1", "1", "540", "505000007", "8", "99", "8", "209952", "652599557", "27157528", "885507108", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
30
1cfd8e00daefe70b7d76fc42938a21b8
New Password
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists. Print any password which satisfies all conditions given by Innokentiy. Sample Input 4 3 6 6 5 2 Sample Output java python phphp
[ "n, k = map(int,input().split())\r\n\r\nprint(('abcdefghijklmnopqrstuvwxyz' [:k]*n )[:n])", "from string import ascii_lowercase as alph\r\nn, k = map(int, input().split())\r\nprint(''.join(alph[i % k] for i in range(n)))", "n,k=[int(n) for n in input().split()]\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\np=s[0:k]\r\nq=p*n\r\nprint(q[0:n])", "from string import ascii_lowercase as alphabet\r\nn, k = map(int, input().split())\r\nind = 0\r\ns = ''\r\nfor i in range(n):\r\n\ts += alphabet[ind]\r\n\tind += 1\r\n\tif ind == k:\r\n\t\tind = 0\r\nprint(s)", "n, k = [int(x) for x in input().split()]\r\norigk = k\r\nres = \"\"\r\nwhile n>0:\r\n k = origk\r\n o = 97\r\n while k>0 and n>0:\r\n res = res+ chr(o)\r\n o+=1\r\n k-=1\r\n n-=1\r\nprint(res)\r\n\r\n", "n,k = map(int,input().split())\r\npw = ''\r\nfor i in range(k):\r\n pw += chr(97+i)\r\npw *= n//k+1\r\nprint(pw[0:n])", "n, k = map(int, input().split())\r\nanswer = ''\r\nfor i in range(n):\r\n answer += chr(97 + i % k)\r\nprint(answer)\r\n", "def generatePassword(n, k):\r\n password = []; idx = 0\r\n for i in range(n):\r\n password.append(chr(idx+ord('a')))\r\n idx = (idx+1)%k\r\n return ''.join(password)\r\n\r\nn, k = list(map(int, input().split(' ')))\r\nprint(generatePassword(n, k))\r\n", "import random\r\ncondition=list(map(int,input().split(\" \")))\r\npassword,last,count=\"\",0,0\r\nwhile count< condition[1]:\r\n char = random.randrange(0,26)\r\n if chr(char+97)!= last and chr(char+97) not in password:\r\n password=password+chr(char+97)\r\n last=char\r\n count+=1\r\nlast,count=password[len(password)-1],0\r\nwhile count< condition[0]-condition[1]:\r\n char=random.choice(password)\r\n if char!= last:\r\n password=password+char\r\n last=char\r\n count+=1\r\nprint(password)", "n, k = map(int, input().split())\r\n \r\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\r\n \r\nprint((alphabets[:k])*(n//k)+alphabets[:n%k])", "n , k = map(int,input().split())\r\n\r\nres = ''\r\n\r\nfor i in range(n):\r\n\r\n res += chr( 97 + (i % k ))\r\n\r\nprint(res)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n1=input().split(\" \")\r\nn=int(n1[0])\r\nk=int(n1[1])\r\nalp=\"abcdefghijklmnopqrstuvwxyz\"\r\ns=\"\"\r\ns1=\"\"\r\ns2=\"\"\r\nfor i in range(k):\r\n s+=alp[i]\r\ns2=s*(n-k)\r\nfor i in range(n-k):\r\n s1+=s2[i]\r\nprint(s+s1)\r\n ", "n,k=map(int,input().split())\r\nimport string\r\nd=string.ascii_lowercase\r\nmylist=[]\r\nmylist+=d\r\nnewlist=[]\r\nimport random\r\nrandom.shuffle(mylist)\r\nfor i in range(k):\r\n newlist+=mylist[i]\r\nnewword=''\r\ncount=0\r\nwhile(count<n):\r\n for i in range(0,k):\r\n newword+=newlist[i]\r\n count+=1\r\n if count==n:\r\n break\r\nprint(newword)\r\n", "n, k = map(int, input().split())\r\nletters = \"abcdefghijklmnopqrstuvwxyz\"[:k]\r\nprint(''.join(letters[i%k] for i in range(n)))", "n,k = map(int,input().split())\r\nalph = \"qwertyuiopasdfghjklzxcvbnm\"\r\nprint(alph[:k] * (n//k)+ alph[:n%k])\r\n", "nk = input().split()\r\n\r\nprint((\"zxcvbnmasdfghjklqwertyuiop\"[:int(nk[1])] * int(nk[0]))[:int(nk[0])])\r\n", "# ██████╗\r\n# ███ ███═█████╗\r\n# ████████╗ ██████╗ ████████╗ ████ █████ ████╗\r\n# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║\r\n# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝\r\n# ██╔═══╝ ██║ ██╗ ██╔═══╝ ███ ███╔══╝\r\n# ████████╗ ╚██████╔╝ ████████╗ ███ ██╔═╝\r\n# ╚═══════╝ ╚═════╝ ╚═══════╝ ███╔══╝\r\n# Legends ╚══╝\r\n\r\nimport sys\r\ninput = sys.stdin.readline\r\nprint = sys.stdout.write\r\n\r\nn, k = map(int, input().split())\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\npassword = \"\"\r\nif n == k:\r\n print(alpha[0:n])\r\nelse:\r\n password = alpha[0:k]\r\n for i in range(n-k):\r\n password += alpha[i % k]\r\nprint(password)\r\n", "import math\r\na,b=map(int,input().split())\r\nc='qazwsxedcrfvtgbyhnujmikolp'\r\nd=c[0:b]\r\nk=math.ceil(a/b)\r\nd=d*k\r\nd=d[0:a]\r\nprint(d)\r\n\r\n", "l, k = map(int, input().split())\r\nstart = ord('a')\r\nres = \"\"\r\nfor i in range(l):\r\n res += chr(start)\r\n start = (start+1)\r\n if start - ord('a') >= k:\r\n start = ord('a')\r\nprint(res)", "l=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\nn,k=map(int,input().split())\r\ns=\"\".join(l[:k])\r\nj=n-k\r\nfor i in range(j):\r\n if i%2==0:\r\n s=s+s[0]\r\n else:\r\n s=s+s[1]\r\nprint(s)", "import string\nalphabet = string.ascii_lowercase\n\nn, k = map(int, input().split())\npassword = ['' for _ in range(n)]\ncandidates = alphabet[:k]\ncurr = 0\nfor i in range(n):\n password[i] = candidates[curr%k]\n curr += 1\n\nprint(''.join(password))\n", "n, k = (int(x) for x in input().split())\r\n\r\npwd = [chr(ord('a') + (i % k)) for i in range(n)]\r\nprint(*pwd, sep='')", "s = 'abcdefghijklmnopqrstuvwxyz'\r\ns2 = ''\r\nn, k = map(int, input().split())\r\nfor i in range(0, n):\r\n s2 += s[i % k]\r\nprint(s2)\r\n", "n, k = map(int, input().split())\r\na = 'abcdefghijklmnopqrstuvwxyz'\r\nx = a[:k]\r\nprint((x * (n//k)) + a[:n%k])", "# New Password\r\n# url: https://codeforces.com/contest/770/problem/A\r\n\r\n\"\"\"\r\n Thinking time: 3\r\n Coding time: 4\r\n Debugging time: 3\r\n -----------------------------\r\n Total time: 10 minutes\r\n \r\nNumber of Submissions: 2\r\n\"\"\"\r\nimport string\r\nimport random\r\n\r\nn, k = map(int, input().split(' '))\r\n\r\nalphabetList = list(string.ascii_lowercase)\r\nrandom.shuffle(alphabetList)\r\nuniqueStr = ''.join(alphabetList)[:k:]\r\npassword = uniqueStr * (n // k + n % k)\r\n\r\nprint(password[:n:])\r\n", "n,k=[int(x) for x in input().split()]\r\nlst=[chr(i) for i in range(97,97+k)]\r\nfor i in range(n):\r\n print(lst[i%k],end='')", "alpha='abcdefghijklmnopqrstuvwxyz'\r\nn,m=map(int,input().split())\r\ns=''\r\ns+=alpha[0:m]\r\ni=0\r\nwhile(len(s)<n):\r\n s+=chr(ord('a')+i)\r\n i+=1\r\n if i==m:\r\n i=0\r\nprint(s) ", "n , k = map(int,input().split())\r\nl = []\r\np = [i for i in l]\r\nfor i in range(1,k+1):\r\n\tl.append(chr(i+96))\r\nwhile len(p)<n:\r\n\tfor j in l:\r\n\t\tp.append(j)\r\np = \"\".join(p)\r\nprint(p[0:n])\r\n\r\n\r\n", "n, k = map(int, input().split())\r\nalpha = 'abcdefghijklmnopqrstuvwxyz'\r\nidx = 0\r\n\r\nfor i in range(0, n):\r\n if idx == k:\r\n idx = 0\r\n print(alpha[idx], end='')\r\n idx += 1\r\n", "n,k=map(int,input().split())\npassword=\"ab\"\nadd=ord('c')\nfor i in range(2,n):\n\tif k>i:\n\t\tpassword+=chr(add)\n\t\tadd+=1\n\telse:\n\t\tpassword+=password[i-2]\nprint(password)", "import string\n\nalpha = string.ascii_lowercase\nn, k = [int(i) for i in input().split(\" \")]\nnew_alpha = alpha[:k]\nnew_password = \"\"\nfor i in range(n):\n new_password += new_alpha[i%k]\nprint(new_password)", "\r\nx = list(map(int,input().split(' ')))\r\n\r\ndic = [chr(x) for x in range(ord('a'),ord('a')+x[1])]\r\n\r\npassword = ''\r\nfor i in range(x[0]):\r\n password += dic[i % x[1]]\r\n\r\nprint(password)", "n, k = map(int, input().split())\r\na = range(ord(\"a\"), ord(\"a\") + k)\r\n\r\nfor i in range(n):\r\n print(chr(a[i%k]), end=\"\")", "inp = input()\r\nn = int(inp.split()[0])\r\nk = int(inp.split()[1])\r\npassword =''\r\ncha = 97\r\nfor i in range(n):\r\n password+=chr(cha+(i % k))\r\nprint(password)", "n, k = map(int, input().split())\r\nprint(''.join(chr(i) for i in range(97, 97 + k)) + 'ab' * ((n - k)//2) + ('a' if (n - k) % 2 != 0 else ''))", "n,m = map(int,input().split())\r\nx = 'abcdefghijklmnopqrstuvwxyz'[:m]\r\nprint(x*(n//m)+x[:n%len(x)])", "n,k=map(int,input().split())\nans=\"\"\nfor i in range(k):\n ans+=chr(97+i)\nfor i in range(k,n):\n if(i%2==0):\n ans+='a'\n else:\n ans+='b'\nprint(ans)\n\n \t \t\t \t\t \t \t\t \t\t\t \t\t\t\t \t \t", "n,m=map(int,input().split())\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\ns=s[:m]*(n)\r\nprint(s[:n])\r\n", "import random\r\n\r\nn,r =map(int,(input().split())) \r\nx=''\r\ni=0\r\n\r\n\r\nsimple_list= list(map(chr, range(97, 97+r)))\r\n\r\nwhile len(x) < n:\r\n x=x+simple_list[i]\r\n i+=1\r\n if(i==r):\r\n i=0\r\n\r\n\r\nprint(x)", "a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\nC=[]\nx=input()\nxx=[int(i) for i in x.split()]\nn=xx[0]\nk=xx[1]\n\nwhile(len(C)!=n):\n x=n-len(C)\n for i in range(x):\n C.append(a[i])\n if i==k-1:\n break\n \nfor i in C:\n print(i,end='')\n\t \t\t\t\t \t \t \t\t \t \t\t \t", "\r\nletters = []\r\nletters = \"a b c d e f g h i j k l m n o p q r s t u v w x y z\".split()\r\ns = input()\r\nn_k_list = []\r\noutlist = []\r\n\r\n\r\nn_k_list = list(map(int, s.split()))\r\n\r\nfor i in range(n_k_list[1]):\r\n outlist.append(letters[i])\r\nfor i in range(n_k_list[0] - n_k_list[1]):\r\n outlist.append(outlist[len(outlist) - 2])\r\n\r\n\r\nprint(\"\".join(outlist))\r\n", "n = input()\r\nn = n.split()\r\nk = int(n[1])\r\nn = int(n[0])\r\na = \"\"\r\nfor i in range(k):\r\n a = a + chr(97+i)\r\n\r\ny = n - k\r\nif y % 2 == 0:\r\n for i in range(y//2):\r\n a = a + 'ab'\r\nelse:\r\n for i in range((y-1)//2):\r\n a = a + 'ab' \r\n a = a + 'a'\r\n \r\nprint(a) \r\n\r\n\r\n ", "from string import ascii_lowercase\r\n \r\nn, k = map(int, input().split())\r\ntoRep = ascii_lowercase[:k]\r\nrep = 1 + n // k\r\nprint((toRep * rep)[:n])", "import string\n\nn, k = map(int, input().split())\n\nalpha = list(string.ascii_lowercase)\nans = alpha[0:k] + alpha[0:2]*(n-k)\n\n\nprint(\"\".join(ans[0:n]))", "n, k = map(int, input().split())\r\nalpha = \"qwertyuiopasdfghjklzxcvbnm\"\r\npassword = alpha[:k]\r\npassword *= n//k\r\nindex = n % k\r\nif index != 0:\r\n password += password[:index]\r\nprint(password)\r\n", "arr = list(map(str, 'abcdefghijklmnopqrstuvwxyz'))\nn = [int(_) for _ in input().split()]\narr = arr[:n[1]]\nans = []\n\nwhile n[0] >= 1:\n ans.append(arr[n[0] % len(arr)])\n n[0] -= 1\n\nprint(''.join(ans))\n\n", "n,k=map(int,input().split())\nans=''\nfor i in range(k):\n ans=ans+chr(97+i)\n\nans=ans+((n-k)//2)*'ab'\nif((n-k)%2):\n ans=ans+'a'\nprint(ans)\n\n\n\n\n\n\n", "\r\n\r\nl = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\n\r\na,b = map(int,input().split())\r\n\r\ndef rec(n,k,i):\r\n if i ==-1:\r\n return rec(n,k,b-1)\r\n if n == 1:\r\n return l[i]\r\n else:\r\n return l[i] + rec(n-1,k,i-1)\r\n\r\n\r\n\r\nprint(rec(a,b,b-1))\r\n", "import string\r\nn,k = map(int,input().split())\r\nans = string.ascii_lowercase\r\na = ans[:k]\r\nif len(a) < n:\r\n curr = 0\r\n while (len(a) < n):\r\n if curr == n:\r\n curr = 0\r\n else:\r\n a += a[curr]\r\n curr += 1\r\n \r\nprint(a)\r\n", "import string\r\n\r\nalphabet_string = string.ascii_lowercase\r\n\r\nn, k = list(map(int, input().split(' ')))\r\nans = alphabet_string[:k]\r\nprint(ans*(n//k) + alphabet_string[:(n%k)])", "#https://codeforces.com/contest/770/problem/A\r\n\r\n\r\nn,k = [int(i) for i in input().split(' ')]\r\n\r\ndef generate_letters(nr):\r\n letters=[]\r\n for i in range(97,97+nr):\r\n letters.append(chr(i))\r\n return letters\r\n\r\nletters=generate_letters(k)\r\n\r\n\r\nc=0\r\nfin=''\r\nfor i in range(n):\r\n if (c >= k):\r\n c = 0\r\n current = letters[c]\r\n fin += current\r\n c+=1\r\nprint(fin)", "n, k = map(int, input().split())\r\n\r\ndistinct_symbols = \"abcdefghijklmnopqrstuvwxyz\"[:k]\r\npassword = distinct_symbols[0]\r\n\r\nfor i in range(1, n):\r\n if i < len(distinct_symbols):\r\n password += distinct_symbols[i]\r\n else:\r\n password += distinct_symbols[i % len(distinct_symbols)]\r\n\r\nprint(password)", "# tc = int(input())\r\nfor i in range(1):\r\n # n = int(input())\r\n # li =list(map(int,input().split()))\r\n n,k = map(int,input().split())\r\n ans = \"\"\r\n i = 0\r\n for i in range(k):\r\n ans+=chr((97+(i)%26))\r\n for i in range(n-k):\r\n ans+=chr((97+(i%k)%26))\r\n \r\n print(ans)\r\n\r\n\r\n\r\n\r\n", "letters= \"asdfghjklqwertyuiopzxcvbnm\"\r\n\r\ndef convert(z):\r\n str1 = \"\"\r\n return(str1.join(z))\r\n\r\nx = list(map(int , input().split()))\r\n\r\na= x[0]\r\nb= x[1]\r\n\r\nw=[]\r\np=[]\r\n\r\nfor i in range(b):\r\n w.append(letters[i])\r\n\r\n\r\nif a == b :\r\n print(convert(w))\r\nelse :\r\n j = a - b\r\n\r\n for i in range(j):\r\n v = 0\r\n if len(p) > 0 and p[-1] == w[v]:\r\n v= v + 1\r\n p.append(w[v])\r\n print(convert(w)+convert(p))\r\n\r\n\r\n\r\n\r\n", "n,k=map(int,input().split())\r\nbal=\"qwertyuiopasdfghjklzxcvbnm\"\r\nf=bal[:k]*100\r\nprint(f[:n])", "import random\r\n\r\ndef New_password(letters_limit,symbols_limit):\r\n symbols=[]\r\n word=\"\"\r\n i=0\r\n while(i<symbols_limit):\r\n c=random.randint(97,122)\r\n if(c not in symbols):\r\n symbols.append(c)\r\n i+=1\r\n for i in range(letters_limit):\r\n word+=chr(symbols[i%symbols_limit])\r\n print(word)\r\n\r\ndef main():\r\n inp=list(map(int,input().strip().split()))\r\n New_password(inp[0],inp[1])\r\n\r\nif __name__==\"__main__\":\r\n main()\r\n", "import string\r\nimport random\r\nl=list(string.ascii_lowercase)\r\nn,k=map(int,input().split())\r\np=\"\"\r\nindex=0\r\nfor i in range(k):\r\n p+=l[i]\r\n\r\nwhile len(p)!=n:\r\n if index>k-1:\r\n index=0\r\n p+=p[index]\r\n index+=1\r\nprint(p)\r\n \r\n\r\n", "n, k = map(int, input().split())\r\ns = \"\"\r\nfor i in range(k):\r\n s += chr(ord(\"a\") + i)\r\n\r\ns += s*(n-k)\r\nprint(s[:n])", "'''\n\nWelcome to GDB Online.\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\nC#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\nCode, Compile, Run and Debug online from anywhere in world.\n\n'''\nn,k=map(int,input().split())\na,b=divmod(n,k)\nfor i in range(a):\n for j in range(k):\n print(chr(97+j),end='')\nfor j in range(b):\n print(chr(97+j),end='')", "\r\nn,k=list(map(int, input().split()))\r\nstr=\"qwertzuiopasdfghjklyxcvbnm\"\r\n\r\nstrr=\"\"\r\n\r\nfor i in range(n):\r\n strr+=str[i%k]\r\n\r\nprint(strr)", "# New Password\ndef password(n, k):\n cur = 97\n ans = \"\"\n while len(ans) != k:\n ans += chr(cur)\n cur += 1\n if cur == 123:\n cur = 97\n while len(ans) < n:\n ans += ans\n return ans[:n]\n\n\nn, k = list(map(int, input().split()))\nprint(password(n, k))\n", "import random\r\n\r\n\r\ndef randomCharPassword(k, CharList):\r\n q = k\r\n i = 0\r\n for i in range((q)):\r\n x = random.randint(0, 25)+97\r\n if chr(x) in CharList:\r\n q = +1\r\n continue\r\n CharList.append(chr(x))\r\n\r\n\r\n\r\nn,k=[int(x) for x in input().split()]\r\nCharList = []\r\nrandomCharPassword(k,CharList)\r\npassword=\"\"\r\n\r\nwhile k!=len(CharList):\r\n randomCharPassword((k-len(CharList)),CharList)\r\n\r\nfor i in range(n):password+=CharList[i%len(CharList)]\r\n\r\nprint(password)", "n , k = [int(x) for x in input().split(\" \")]\r\nalphapet = [chr(x) for x in range(ord(\"a\") , ord(\"z\") + 1)]\r\nprint(\"\".join([alphapet[x%k] for x in range(n)]))", "import sys\r\nimport os.path\r\nfrom math import *\r\nfrom bisect import *\r\nfrom itertools import *\r\nfrom collections import defaultdict as dd, Counter\r\nfrom itertools import accumulate\r\nfrom operator import add\r\nfrom tkinter import N\r\n#from sortedcontainers import SortedList as SL, SortedSet as SS, SortedDict as SD\r\n\r\nif os.path.exists(\"input.txt\"):\r\n sys.stdin = open(\"input.txt\", \"r\")\r\n sys.stdout = open(\"output.txt\", \"w\")\r\n\r\ndef st():\r\n return str(sys.stdin.buffer.readline().strip())[2:-1]\r\ndef li():\r\n return list(map(int, sys.stdin.buffer.readline().split()))\r\ndef mp():\r\n return map(int, sys.stdin.buffer.readline().split())\r\ndef inp():\r\n return int(sys.stdin.buffer.readline())\r\n\r\nmod = 1000000007\r\nINF = float(\"inf\")\r\n\r\n\r\nn,k= mp()\r\nn-=k\r\ns=''\r\nx = 'a'\r\nwhile(k>0):\r\n s+=x\r\n x=chr(ord(x)+1)\r\n k-=1\r\nc=1\r\nwhile(n>0):\r\n if c&1:\r\n s+=s[0]\r\n c=0\r\n else:\r\n s+=s[1]\r\n c=1\r\n n-=1\r\nprint(s)\r\n\r\n \r\n # ---- CHECK FOR CORNER CASES ----\r\n \r\n# for _ in range(inp()):\r\n# solve()", "n, k = map(int, input().split())\ndistinct = 1\nfor i in range(n):\n print(chr(96+distinct), end=\"\")\n if distinct < k:\n distinct += 1\n else:\n distinct = 1", "d=[chr(i) for i in range(97,123)]\r\nn,k=map(int,input().split())\r\ns=''.join(map(str,d[:k]))\r\ns=s*(n//k)+s[:n%k]\r\nprint(s)\r\n", "if __name__ == \"__main__\":\r\n\tn, k = (int(x) for x in input().split(' '))\r\n\tpassword = []\r\n\tcharacters = [chr(x) for x in range(97, 97 + k)]\r\n\tj = 0\r\n\tfor i in range(0, n):\r\n\t\tif j >= k:\r\n\t\t\tj = 0\r\n\t\tpassword.append(characters[j])\r\n\t\tj += 1\r\n\tprint(''.join(password))\r\n\t\t\r\n\t\t\r\n", "a,b = [int(x) for x in input().split(' ')]\r\narray = []\r\nfor i in range(b):\r\n array.append(chr(ord('a')+i))\r\ns = []\r\nfor i in range(a):\r\n s.append(array[i%b])\r\nprint(\"\".join(s))\r\n", "### Hello! World ... ###\nimport string\narr = list(map(int, input().split()))\nchar = string.ascii_lowercase\n# f = (char[:arr[1]]*(arr[0]//arr[1]))+char[:arr[0]%arr[1]]\nprint((char[:arr[1]]*(arr[0]//arr[1]))+char[:arr[0]%arr[1]])\n# print(len((char[:arr[1]]*(arr[0]//arr[1]))+char[:arr[0]%arr[1]]))\n# s = [c for c in f]\n# print(len(set(s)))", "# import sys\r\n# sys.stdin = open('input.txt','r')\r\n# sys.stdout = open('output.txt','w')\r\n\r\n\r\na,b =map(int,input().split())\r\nans = ''\r\nfor i in range(b):\r\n\tans += chr(i+97)\r\n\r\nans = ans*a\r\nprint(ans[:a])\r\n\r\n\r\n\r\n", "# New Password - Code Forces\r\n# Link : https://codeforces.com/contest/770/problem/A\r\n\r\n# there are simpler solution of this problem,\r\n# the solution does not require any\r\n# shuffling at all (and will be accepted)\r\n# however, i think that no password should be predictable\r\n\r\nimport string\r\nimport random\r\n\r\nlength, numberOfDistinctSymbols = map(int, input().split())\r\n\r\n\r\nalphabet = list(string.ascii_lowercase)\r\n\r\nrandom.shuffle(alphabet)\r\n\r\noutput = ''\r\n\r\nfor i in range(length):\r\n output += alphabet[i % numberOfDistinctSymbols]\r\n\r\nprint(output)\r\n", "def main():\r\n [n, k] = list(map(int, input().split()))\r\n\r\n s = \"\"\r\n c = 0\r\n for i in range(n):\r\n s += chr(ord('a') + (i + c) % k)\r\n print(s)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "tmp = (list(map(int, input().split())))\nn = tmp[0]\nk = tmp[1]\nimport random as rd\nl = []\nwhile(True):\n \n l.append(rd.randint(ord(\"a\"), ord('z')))\n if len(set(l)) == k:\n break\n\ns = \"\"\nl = list(set(l))\nfor i in range(n):\n s += chr(l[i%k])\n\n\nprint(s)", "n,k=list(map(int,input().split()))\r\nb=\"abcdefghijklmnopqrstuvwxyz\"\r\nc=b[:k]\r\nprint(c*(n//k),c[:n%k],sep=\"\")\r\n", "x,y=map(int,input().split())\r\nasc=97\r\nfor j in range(x) :\r\n print(chr((asc+j%y)),end='')", "import string\r\n\r\na= string.ascii_lowercase\r\n\r\n\r\nn, k= map(int,input().split())\r\n\r\nc= a[0:k]\r\n\r\n#letter to be added\r\nd= n- k\r\n\r\nfor i in range(d):\r\n if d>0:\r\n\r\n c+='a'\r\n d-=1\r\n if d>0:\r\n c+='b'\r\n d-=1\r\n else:\r\n break\r\n else:\r\n break\r\nprint(c)\r\n \r\n\r\n", "m,n=map(int,input().split())\r\nprint((\"abcdefghijklmnopqrstuvwxyz\"[:n]*m)[:m])\r\n\r\n\r\n ", "a, b = list(map(int, input().split()))\r\nimport string\r\ns = list(string.ascii_lowercase)\r\nans = ''\r\ni = 0\r\nwhile len(ans) < a and b > 0:\r\n\tans += s[i]\r\n\ti +=1\r\n\tb -= 1\r\ni = 0\r\nwhile len(ans) < a:\r\n\tans += ans[i]\r\n\ti+=1\r\nprint(ans)\r\n", "n, k = map(int, input().split())\r\n\r\n# create a string of k distinct characters\r\npassword = ''.join(chr(ord('a') + i) for i in range(k))\r\n\r\n# repeat the string until we reach the desired length n\r\nwhile len(password) < n:\r\n password += password\r\n\r\n# trim the string to the desired length n\r\npassword = password[:n]\r\n\r\nprint(password)\r\n", "# 5\r\nn,k = list(map(int,input().split()))\r\n\r\n\r\nletters = 'abcdefghijklmnopqrstuvwxyz'\r\n\r\nword = \"\"\r\n\r\nlength = n\r\n\r\ni = 0\r\n\r\nwhile k != 0:\r\n word += letters[i]\r\n k -= 1\r\n i += 1\r\n\r\ni = 0\r\n\r\nwhile n != 0:\r\n word += word[i]\r\n n -= 1\r\n i += 1\r\nprint(word[:length])\r\n", "\r\nn, k = map(int, input().split())\r\nabc = list('abcdefghijklmnopqrstuvwxyz')\r\ndl = ''\r\nfor i in range(k):\r\n dl += abc[i]\r\n# print(dl)\r\n\r\npassword = ''\r\n\r\nwhile len(password) < n:\r\n for j in range(k):\r\n password += dl[j]\r\n if len(password) == n:\r\n break\r\n\r\nprint(password)\r\n\r\n", "n,k=input().split()\r\npassw=''\r\nfor i in range (0,int(n)):\r\n passw=passw+chr(ord('a')+i%int(k))\r\nprint(passw)\r\n ", "import string\r\n\r\npass_length, num_distinct = map(int, input().split())\r\n\r\nprint((string.ascii_lowercase[:num_distinct] * pass_length)[:pass_length])\r\n", "import string\r\nn,x = list(map(int,input().split()))\r\ncounter,result=0,\"\"\r\nwhile len(result) < n:\r\n result+=string.ascii_lowercase[:x]\r\nprint(result[:n])", "a=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\nn,k=input().split()\r\ns=[]\r\nc=0\r\nwhile c<int(n) : \r\n for i in a[:int(k)] : \r\n if len(s) < int(n) :\r\n s.append(i)\r\n c+=1\r\nprint(\"\".join(s)) \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "import itertools\r\n\r\nn, k = map(int, input().split())\r\nabc = [\r\n \"a\",\r\n \"b\",\r\n \"c\",\r\n \"d\",\r\n \"e\",\r\n \"f\",\r\n \"g\",\r\n \"h\",\r\n \"i\",\r\n \"j\",\r\n \"k\",\r\n \"l\",\r\n \"m\",\r\n \"n\",\r\n \"o\",\r\n \"p\",\r\n \"q\",\r\n \"r\",\r\n \"s\",\r\n \"t\",\r\n \"u\",\r\n \"v\",\r\n \"w\",\r\n \"x\",\r\n \"y\",\r\n \"z\",\r\n]\r\npw = \"\".join(abc[a] for _, a in itertools.product(range(n), range(k)))\r\n\r\nprint(pw[:n])\r\n", "from sys import stdin\r\n\r\nn,k = map(int,stdin.readline().split())\r\nch = 0\r\nfor i in range(n):\r\n\tprint(chr(ch+97),end='')\r\n\tch = (ch+1)%k\r\n", "\"\"\"\r\nPROBLEM LINK : http://codeforces.com/contest/770/problem/A\r\n\"\"\"\r\n\r\nimport string\r\nALPHABETS = string.ascii_lowercase\r\n\r\n# n : is the length of the password.\r\n# k : is the number of distinct symbols in password.\r\ndef getNewPassword(n, k):\r\n newPassword = \"\"\r\n\r\n for i in range(n):\r\n newPassword += ALPHABETS[i%k]\r\n\r\n return newPassword\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n constrains = input().strip().split()\r\n\r\n n = int(constrains[0])\r\n k = int(constrains[1])\r\n\r\n res = getNewPassword(n, k)\r\n\r\n print(res)\r\n \r\n\r\n \r\n ", "import string\r\nn,b=list(map(int,input().split()))\r\nstr1=string.ascii_lowercase\r\nresult=str1[0:b]\r\ns=n-b\r\nfor x in range(0,s):\r\n result+=result[x]\r\nprint(result)", "def generate_characters(n):\r\n return [chr(i) for i in range(97, 97+n)]\r\ndef generate_string(a, n):\r\n characters = generate_characters(n)\r\n return ''.join(characters * (a // n) + characters[:a % n])\r\na,b = map(int, input().split())\r\npassword = generate_string(a,b)\r\nprint(password)", "n, k = (int(el) for el in input().split())\r\n\r\nal = \"\"\r\nfor i in range(ord('a'), ord('z') + 1):\r\n al += chr(i)\r\n\r\npos = 0\r\npassword = \"\"\r\nwhile len(password) < k:\r\n password += al[pos]\r\n pos = (pos + 1) % 26\r\n\r\nold_len = len(password)\r\npos = 0\r\nwhile len(password) < n:\r\n password += password[pos]\r\n pos = (pos + 1) % old_len\r\n \r\nprint(password)", "import random\nimport string\n\nnandk = input(\"\").split(\" \")\nn = int(nandk[0])\nk = int(nandk[1])\n\n\ndef GenerateRandomCharacter(k):\n dictionary = {}\n while (len(dictionary) < k):\n dictionary[f\"{random.choices(string.ascii_lowercase, k=1)[0]}\"] = f\"{random.choices(string.ascii_lowercase, k=1)[0]}\"\n return dictionary\n\n\ndef GeneratePassword(n, k):\n dictionary = GenerateRandomCharacter(k)\n password = \"\"\n while (len(password) < n):\n for characterX in dictionary:\n if len(password) == n:\n break\n password += characterX\n\n print(password)\n return\n\n\nGeneratePassword(n, k)\n \t\t\t\t\t\t\t\t \t \t\t\t \t\t\t \t \t \t\t \t", "alpha = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nn, k = list(map(int, input().split()))\r\npassword = []\r\nfor i in range(k):\r\n password.append(alpha[i])\r\nfor i in range(n - k):\r\n password.append(alpha[i % k])\r\nprint(''.join(password))", "n, k =map(int, input().split())\r\nlatin=\"abcdefghijklmnopqrstuvwxyz\"\r\n\r\np=\"\"\r\nfor i in range(n):\r\n\tp+=latin[i%k]\r\nprint(p)", "s = input().split(\" \") # n = s[0], k = s[1]\r\ns[0] = int(s[0]); s[1] = int(s[1])\r\n\r\nl = []\r\nchar = 97\r\nwhile s[1]:\r\n l.append(char)\r\n char += 1\r\n s[1] -= 1\r\n\r\nj = 0\r\nfor i in range(s[0]):\r\n if(j == len(l)): j = 0\r\n print(chr(l[j]), end = \"\")\r\n j += 1\r\n \r\nprint()\r\n\r\n# print(s)\r\n\r\n", "import sys\r\n\r\nlength = 0\r\ndistinct = 0\r\nletters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nfor line in sys.stdin:\r\n line = line.split()\r\n length = int(line[0])\r\n distinct = int(line[1])\r\n break\r\n\r\nnew_pass = ''\r\nletters_to_use = letters[:distinct]\r\nidx = 0\r\nfor i in range(length):\r\n if idx >= len(letters_to_use):\r\n idx = 0\r\n new_pass += letters_to_use[idx]\r\n idx += 1\r\n \r\nprint(new_pass)\r\n \r\n", "letters = 'abcdefghijklmnopqrstuvwxyz'\r\nnumbers = list(map(int, input().split(\" \")))\r\n\r\npassword = ''\r\n\r\nfor i in range(numbers[0]):\r\n password += letters[i % numbers[1]]\r\n \r\nprint(password) ", "n, k = [int(i) for i in input().split()]\r\ncl =\"qwertyuiopasdfghjklzxcvbnm\"\r\ncl = cl[:k]\r\npw = \"\"\r\nfor i in range(n):\r\n x = i//k\r\n if i<k:\r\n pw += str(cl[i])\r\n else:\r\n pw += str(cl[i-k*x])\r\nprint(pw)", "n, k = map(int, input().split())\r\ns = 'abcdefghijklmnopqrstuvwxyz'\r\nprint(s[:k]*(n//k)+s[:n % k])\r\n", "import string\nalphabet = list(string.ascii_lowercase)\n\ndef handle_input():\n n,k = tuple(map(int,input().split()))\n return n,k\n\nn,k = handle_input()\n\npassword = \"\"\nfor i in range(n):\n password += alphabet[i%k]\nprint(password)\n\t \t\t\t \t \t \t \t \t \t\t\t \t \t \t\t", "n, k = input().split()\r\na = []\r\nr = [0]*int(n)\r\nalpha = 'a'\r\nfor i in range(0, 26):\r\n a.append(alpha)\r\n alpha = chr(ord(alpha) + 1)\r\ns = a[:int(k)]\r\nc = 0\r\nfor i in range(len(r)):\r\n r[i] = s[c]\r\n if c == len(s)-1:\r\n c = -1\r\n c += 1\r\nq = \"\"\r\nfor i in r:\r\n q += i\r\nprint(q)\r\n\r\n", "n, k= map(int, input().split())\nletters = \"abcdefghijklmnopqrstuvwxyz\"[:k]\npassword = \"\"\ncount = 0\nfor x in range(n):\n password += letters[count]\n count += 1\n if count == k: count = 0\nprint(password)", "a,b = map(int,input().split())\r\nx = 'qwertyuiopasdfghjklzxcvbnm'[:b]\r\nif a == b:\r\n print(x)\r\n exit()\r\nelse:\r\n txt = ''\r\n count = 1\r\n i = 0\r\n while count <= a:\r\n txt += x[i]\r\n i += 1\r\n count += 1\r\n if i == b:\r\n i = 0\r\nprint(txt)", "n,k = list(map(int,input().split()))\r\ns = ''\r\nfor i in range(n):\r\n s+=chr(i%k + 97)\r\nprint(s)\r\n", "n,k=map(int,input().split())\r\nal=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nans1=''\r\nfor x in range(k):\r\n ans1+=al[x]\r\nans=ans1\r\nwhile len(ans)<n:\r\n ans+=ans1\r\nprint(ans[:n])\r\n", "import string\r\nn,k=list(map(int,input().split()))\r\nif (n-k)%2 !=0:print(string.ascii_lowercase[:k]+\"a\"+\"ba\"*((n-k)//2))\r\nelse:print(\"\" if n==0 else string.ascii_lowercase[:k]+\"ab\"*((n-k)//2) )", "x ,y = map(int,input().split())\r\npassword=[]\r\ns=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nj=0\r\nif x%y==0:\r\n z=int(x/y)\r\n for i in range(z):\r\n j=0\r\n for k in range(y):\r\n password.append(s[j])\r\n j+=1\r\nif x%y!=0:\r\n z=int(x/y)\r\n l=x-(y*z)\r\n for i in range(z):\r\n j=0\r\n for k in range(y):\r\n password.append(s[j])\r\n j+=1\r\n j=0\r\n for k in range(l):\r\n password.append(s[j])\r\n j += 1\r\nres =''\r\nfor i in password:\r\n res+=i\r\nprint(res)", "n=list(map(int,input().split()))\r\ns=''\r\nz='abcdefghijklmnopqrstuvwxyz'\r\nfor i in range(n[1]):\r\n s+=z[i]\r\nif(len(s)!=n[0]):\r\n w=n[0]-len(s)\r\n for i in range(w):\r\n s+=s[i]\r\nprint(s)\r\n", "n, k = list(map(int, input().split()))\r\nletters = 'abcdefghijklmnopqrstuvwxyz'\r\nresult = letters[0:k]\r\n\r\nfor i in range(n-k):\r\n result += result[i]\r\n\r\nprint(result)\r\n", "n,k=map(int,input().split())\nch='a'\nres=\"\"\nfor i in range(k):\n res+=ch\n ch=chr(ord(ch)+1)\nif ch=='a':\n ch='b'\n prev='a'\nelse:\n ch='a'\n prev='b'\nfor j in range(n-k):\n res+=ch\n ch,prev=prev,ch\nprint(res)\n \t \t\t\t \t \t\t \t\t \t\t", "n,k=input().split()\r\nn=int(n)\r\nk=int(k)\r\nAlpha=\"abcdefghijklmnopqrstuvwxyz\"\r\nres=Alpha[0:k]\r\ni=0\r\n\r\nwhile n!= len(res):\r\n res=res+res[i]\r\n i=i+1\r\n if i==k:\r\n i=0\r\n\r\nprint(res)", "alp=\"abcdefghijklmnopqrstuvwxyz\"\r\nn,k=map(int,input().split())\r\npsw=\"\"\r\ntmp=0\r\nfor i in range(n):\r\n psw+=alp[tmp]\r\n tmp+=1\r\n if tmp==k:\r\n tmp=0\r\nprint(psw)", "n,k=[int(i) for i in input().split()]\r\nl='a b c d e f g h i j k l m n o p q r s t u v w x y z'\r\nl=[i for i in l.split(' ')]\r\ntemp=[]\r\nf=''\r\nif k>=n:\r\n i=0\r\n while(n!=0):\r\n f+=l[i]\r\n n-=1\r\n i+=1\r\n print(f)\r\nelse:\r\n i=0\r\n letters_left=n-k\r\n while(k!=0):\r\n f+=l[i]\r\n k-=1\r\n temp.append(l[i])\r\n i+=1\r\n temp=\"\".join(temp)\r\n temp*=letters_left\r\n i=0\r\n while(letters_left!=0):\r\n f+=temp[i]\r\n letters_left-=1\r\n i+=1\r\n print(f)\r\n", "\"\"\"\r\nInnokentiy decides to change the password in the social net \"Contact!\", but he is too lazy to invent a new password by himself. That is why he needs your help.\r\n\r\nInnokentiy decides that new password should satisfy the following conditions:\r\n\r\nthe length of the password must be equal to n,\r\nthe password should consist only of lowercase Latin letters,\r\nthe number of distinct symbols in the password must be equal to k,\r\nany two consecutive symbols in the password must be distinct.\r\nYour task is to help Innokentiy and to invent a new password which will satisfy all given conditions.\r\n\r\nInput\r\nThe first line contains two positive integers n and k (2 ≤ n ≤ 100, 2 ≤ k ≤ min(n, 26)) — the length of the password and the number of distinct symbols in it.\r\n\r\nPay attention that a desired new password always exists.\r\n\r\nOutput\r\nPrint any password which satisfies all conditions given by Innokentiy.\r\n\"\"\"\r\n\r\nfrom string import ascii_lowercase\r\nfrom math import ceil\r\n\r\nn, k = map(int, input().split())\r\n\r\nprint((ascii_lowercase[:k] * ceil(n / k))[:n])\r\n\r\n", "def generate_string(n):\r\n return ''.join(chr(ord('a') + i) for i in range(n))\r\n\r\nn, k = map(int, input().split())\r\nprint(generate_string(k) * (n//k) + generate_string(n%k))", "n, k = map(int, input().split())\r\na = []\r\n\r\nfor i in range(97, 98 + k):\r\n a.append(chr(i))\r\n\r\ni = 0\r\nwhile i < n:\r\n print(a[i % k], end='')\r\n i += 1\r\n", "n, k =[int(x) for x in input().split()]\ns = 'abcdefghijklmnopqrstuvwxyz'\nq_s = ''\nr_s = ''\nfor i in range(0,k):\n q_s += s[i]\nrem = n - (n//k)*k\nfor i in range(rem):\n r_s += s[i]\nprint(q_s*(n//k)+r_s) ", "import string\r\nalphabet = list(string.ascii_lowercase)\r\n\r\nparams = input().split()\r\nn, k = int(params[0]), int(params[1])\r\n\r\ndistinct = alphabet[:k+1]\r\npassword = str()\r\nfor index in range(n):\r\n password += distinct[index%k]\r\nprint(password)", "n,k = map(int, input().split())\r\nar = [0 for i in range(26)]\r\ns=''\r\nwhile len(s)<n:\r\n for i in range(26):\r\n if k == 0:\r\n if ar[i] == 1 and s[-1] != chr(97+i):\r\n s+=chr(97+i)\r\n break\r\n else:\r\n if ar[i] == 0:\r\n s+=chr(97+i)\r\n ar[i]=1\r\n k-=1\r\n break\r\nprint(s)", "import string\r\n\r\nn,k = map(int,input().split())\r\n\r\nnew_password = [0]*n\r\nletter = list(string.ascii_lowercase)\r\nusable = letter[:k]\r\ni = 0\r\nwhile i<n:\r\n new_password[i] = usable[i % k]\r\n i += 1\r\n \r\nprint(''.join(new_password))", "import random\r\n\r\nL=input().split(' ')\r\n\r\nn=int(L[0])\r\nk=int(L[1])\r\n\r\npassword=\"\"\r\na=0\r\nfor i in range(n):\r\n\r\n password+=chr(97+ a)\r\n a=(a+1)%k\r\n\r\nprint(password)", "\r\n\r\nb = 'abcdefghijklmnopqrstuvwxyz'\r\nc = [int(i) for i in input().split()]\r\nprint(((b[:c[1]])*(c[0]//c[1] + 1))[:c[0]])\r\n", "n,k=map(int,input().split())\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\nprint(s[:k]*(n//k)+s[:n%k])", "import string\r\nimport random\r\nn,k = [int(i) for i in input().split()]\r\nletters = list(string.ascii_lowercase)\r\npassword = \"\"\r\nwhile n > 0:\r\n if k > 0:\r\n temp = random.choice(letters)\r\n password = password + temp\r\n letters.remove(temp)\r\n k -= 1\r\n elif k <=0:\r\n password = password + password[-2]\r\n n -= 1\r\n\r\n\r\nprint(password)\r\n", "alf = \"abcdefghijklmnopqrstuvwxyz\"\r\nalfdelite = list(alf)\r\na,b = map(int,input().split())\r\ne = []\r\nfor i in range(b):\r\n e+=[alf[i]]\r\nr = a-len(e)\r\nfor i in range(r):\r\n e+=[e[i]]\r\nfor i in e:\r\n print(i,end = \"\")\r\n", "import random as rd\r\n\r\nn, k = list(map(int, input().split()))\r\nh = [chr(i) for i in range(97, 123)]\r\n\r\nl = set()\r\nwhile len(l) < k:\r\n l.add(rd.choice(h))\r\ns = ''.join(l)\r\nw = s * (n//k) + s[:n%k]\r\nprint(w)", "chars = \"abcdefghijklmnopqrstuvwxyz\"\npassword = []\nn, k = map(int, input().split())\nfor i in range(n):\n password.append(chars[i%k])\nprint(\"\".join(password))", "n = list(map(int, input().split()))\nn,m = n[0], n[1]\ns = \"abcdefghijklmnopqrstuvwxyz\"\ns2 = \"\"\ns3 = \"\"\nfor i in range(m):\n\ts2 += s[i]\ng=0\nfor i in range(n):\n\tif g == m:\n\t\tg=0\n\ts3 +=s2[g]\n\tg+=1\n\nprint(s3)", "alph = 'abcdefghijklmnopqrstuvwxyz'\r\nn, k = map(int, input().split())\r\ndistinct_letters = alph[:k]\r\nw = distinct_letters * n \r\nw = w[:n]\r\nprint(w)\r\n\r\n\r\n\r\n", "def new_password(string_length, distinct_char):\r\n password = \"\"\r\n distinct_count = 0\r\n for i in range(string_length):\r\n password += chr(97 + distinct_count)\r\n distinct_count += 1\r\n if distinct_count == distinct_char:\r\n distinct_count = 0\r\n return password\r\n \r\nstring_length,distinct_char = input().split()\r\nprint(new_password(int(string_length), int(distinct_char)))\r\n", "import string\r\nn,k = map(int, input().split())\r\n\r\nalphabet = [] \r\nfor letter in string.ascii_lowercase:\r\n alphabet.append(letter)\r\n\r\nkitu = alphabet[:k]\r\nfor i in range(0,n):\r\n print(kitu[i%k],end=\"\")", "a, b = map(int, input().split())\r\nm = 'abcdefghijklmnopqrstuvwxyz'\r\ns = \"\"\r\nfor i in range(a):\r\n s += m[i % b]\r\nprint(s)", "def solution(l1):\r\n alfie=\"abcdefghijklmnopqrstuvwxyz\"\r\n snippet=alfie[:l1[1]]\r\n c_out=(snippet*l1[0])[:l1[0]]\r\n\r\n return c_out\r\ndef answer():\r\n l1 = [int(x) for x in input().split()]\r\n print(solution(l1))\r\nanswer()", "b = input().split()\r\ns = \"abcdefghijklmnopqrstuvwxyz\"\r\ng = int(b[0])\r\nf = int(b[1])\r\nd = []\r\nwhile len(d) < g :\r\n i = 0\r\n while i < f :\r\n if len(d) == g :\r\n break\r\n d.append(s[i])\r\n i = i + 1\r\nprint(\"\".join(d))", "n, k = [int(j) for j in input().split()]\r\nvalue = 97\r\noutput = ''\r\nfor j in range(k):\r\n output += chr(value)\r\n value += 1\r\n if value == 123:\r\n value = 97\r\npointer = 0\r\nwhile len(output) < n:\r\n output += output[pointer]\r\n pointer += 1\r\n pointer %= k\r\nprint(output)\r\n", "import sys\r\nfrom collections import deque\r\ndef rs(): return sys.stdin.readline().rstrip()\r\ndef ri(): return int(sys.stdin.readline())\r\ndef ria(): return deque(map(int, sys.stdin.readline().split()))\r\ndef ws(s): sys.stdout.write(s)\r\ndef wi(n): sys.stdout.write(str(n) + '\\n')\r\ndef wia(a): sys.stdout.write('\\n'.join([str(x) for x in a]) + '\\n')\r\n #--------------------Solution------------------------\r\nn,k=ria()\r\nx=[chr(i) for i in range(97,k+97)]\r\nz=0\r\nfor i in range(n):\r\n if z==k:\r\n z=0\r\n ws(x[z])\r\n z+=1", "n,k = map(int,input().split())\nname,r = '',k\nwhile n>0:\n\tif k>0:\n\t\tk-=1\n\t\tname+=chr(97+k)\n\tif k==0:k=r\n\tn-=1\nprint(name)\n", "n,k = map(int,input().split())\r\nalpha = 'qwertyuiopasdfghjklzxcvbnm'\r\nq = n//k\r\nr = n%k\r\nans = alpha[:k]*q + alpha[:r]\r\nprint(ans)", "def new_password():\r\n import string\r\n n,k = map(int, input().split())\r\n chars = string.ascii_lowercase[:k]\r\n password = \"\"\r\n for i in range(n):\r\n password += chars[i%k]\r\n \r\n return password\r\nprint(new_password())", "n, k = list(map(int, input().split()))\n\npassword = \"\"\nindex = 97\nmax = index + k - 1\nfor i in range(n) :\n password += chr(index)\n if index == max :\n index = 97\n else :\n index += 1\n\nprint(password)\n\n\t \t \t\t\t \t\t \t \t \t\t\t\t\t \t", "n, k = map(int, input().split())\r\nletters = [chr(i) for i in range(97, 123)]\r\nfor _ in range(n // k):\r\n print(''.join(letters[:k]), end='')\r\nprint(''.join(letters[:n%k]))", "l=[int(x) for x in input().split()]\r\nn=l[0]\r\nm=l[1]\r\nans=''\r\nx='a'\r\nl=[]\r\nfor i in range (m):\r\n ans+=x\r\n l.append(x)\r\n x=chr(ord(x)+1)\r\n \r\n\r\n \r\n\r\n# print(z)\r\n# print((ord(z)+1)%100)\r\nx='a'\r\nk=0\r\nfor i in range(n-m):\r\n ans+=l[k]\r\n k=(k+1)%len(l)\r\n\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n", "n,k=map(int,input().split())\r\nanswer=\"\"\r\nc=97\r\nmax=c+k-1\r\nfor i in range(n):\r\n answer+=chr(c)\r\n if c==max:\r\n c=97\r\n else:\r\n c+=1\r\n\r\n\r\n\r\n\r\n\r\nprint(answer)\r\n\r\n", "n, k = map(int, input().split(\" \"))\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\noutput = \"\"\r\n\r\nfor i in range(n):\r\n output+=s[i%k]\r\n\r\nprint(output)", "n,k=input().split()\nl=[]\nv=[]\nm=97\nn=int(n)\nk=int(k)\nfor i in range (0,n):\n l.append(chr(m))\n m=m+1\nwhile(len(v)<n):\n v=v+l[:k]\nprint(*v[:n],sep=\"\")\n \t\t\t\t \t \t\t \t\t \t\t\t \t", "import string\r\nalphabet = list(string.ascii_lowercase)\r\n\r\ndef handle_input():\r\n n,k = tuple(map(int,input().split()))\r\n return n,k\r\n\r\nn,k = handle_input()\r\n\r\npassword = \"\"\r\nfor i in range(n):\r\n password += alphabet[i%k]\r\nprint(password)", "# https://codeforces.com/contest/770/problem/A\r\n\r\npass_len, unique_chars = [int(i) for i in input().split()]\r\n\r\n# print(pass_len, unique_chars)\r\n\r\nalpha_set = []\r\nstart = 'a'\r\n\r\n# print(chr(ord('a')+1))\r\n\r\nfor i in range(unique_chars):\r\n if i == 0:\r\n alpha_set.append(start)\r\n else:\r\n start = chr(ord(start)+1)\r\n alpha_set.append(start)\r\n# print(alpha_set)\r\n\r\ncurr_pos = 0\r\npass_output = ''\r\n\r\n\r\nfor i in range(pass_len):\r\n pass_output += alpha_set[i % unique_chars]\r\n\r\nprint(pass_output)", "# http://codeforces.com/contest/770/problem/A\n\ndef solution(n, k):\n lowercase = [chr(97 + i) for i in range(26)]\n password = []\n\n for i in range(n):\n password.append(lowercase[i % k])\n\n return ''.join(password)\n\nif __name__ == \"__main__\":\n n, k = map(int, input().split())\n print(solution(n, k))", "n, k = [int(x) for x in input().split(sep=\" \")]\r\na_z = \"abcdefghijklmnopqrstuvwxyz\"\r\npasswd = \"\"\r\nfor i in range(0, n):\r\n passwd = passwd + a_z[i%k]\r\nprint(passwd)", "import string\r\nn, k = input().split()\r\nletters = string.ascii_lowercase\r\nres = \"\"\r\nidx = 0\r\nfor i in range (0, int(k)):\r\n res += letters[i]\r\nfor i in range (int(n)-int(k)):\r\n if idx < int(k):\r\n res += letters[idx]\r\n idx += 1\r\n else:\r\n idx = 0\r\n res += letters[idx]\r\n idx += 1\r\nprint(res)", "lenP, count = map(int, input().split())\r\nalpha = 'abcdefghijklmnopqrstuvwxyz'\r\nchars = alpha[:count]\r\npassword = ''\r\nasd = 0\r\nfor _ in range(lenP):\r\n if asd >= len(chars):\r\n asd = 0\r\n password += chars[asd]\r\n asd += 1\r\nprint(password)\n# Wed Sep 14 2022 12:51:03 GMT+0000 (Coordinated Universal Time)\n", "import string\r\nn, k = map(int, input().split())\r\na = list(string.ascii_lowercase)\r\nf = str()\r\ni = 0\r\nwhile len(f) != n:\r\n if(i < k):\r\n f += a[i]\r\n i += 1\r\n else:\r\n i = 0\r\nprint(f)\r\n", "n , k = [int(i) for i in input().split()]\r\n\r\nalpha = []\r\n\r\nchar = 'a'\r\nfor i in range(26):\r\n alpha.append(char)\r\n char = chr(ord(char) + 1)\r\n\r\nans = ''\r\nfor i in range(k):\r\n ans += (alpha[i])\r\n\r\nj = 0\r\nwhile j < (n - k):\r\n ans += ans[j]\r\n j += 1\r\nprint(ans) ", "m = list(map(int, input().split()))\r\nn=m[0]\r\nk=m[1]\r\ns=[]\r\ncount=97\r\ncount1=0\r\nwhile(count1<n):\r\n for j in range(k):\r\n if(count1==n):\r\n break\r\n s.append(chr(count))\r\n count1+=1\r\n count+=1\r\n count-=k\r\nfor i in range(n):\r\n print(s[i],end='')", "lst = []\r\nn, k = list(map(int, input().split()))\r\ni = 0\r\nj = 0\r\nwhile i < n:\r\n lst.append(chr(97 + j))\r\n limit = k - 1\r\n if j == limit:\r\n j = 0\r\n elif i == n:\r\n break\r\n else:\r\n j += 1\r\n i += 1\r\nprint(''.join(lst))\r\n\r\n", "import string\r\nn, k = [int(i) for i in input().split()] \r\ndistinct = string.ascii_lowercase[:k]\r\nrepeated = distinct*n\r\nprint(repeated[:n])", "n,k=map(int,input().split())\r\nfor i in range(k):\r\n print(chr(97+i),end=\"\")\r\nfor i in range(n-k):\r\n e=\"ab\"\r\n print(e[i%2],end=\"\")", "n,k = map(int, input().split())\r\nalphabet = \"abcdefghijklmnopqrstuvwxyz\"\r\nks = alphabet[:k]\r\npw = \"\"\r\nfor i in range(n):\r\n pw += ks[i%k]\r\nprint(pw)", "n,x=map(int,input().split())\r\nd=dict()\r\ns='abcdefghijklmnopqrstuvwxyz'\r\nfor i in range(26):\r\n\td[i+1]=s[i]\r\nk=1\r\nfor i in range(1,n+1):\r\n\tprint(d[k],end=\"\")\r\n\tif i%x==0:\r\n\t\tk=1\r\n\telse:k+=1\r\n#print(d)", "import string\r\nl = string.ascii_letters\r\n\r\nn, k = map(int, input().split())\r\n\r\nres = \"\"\r\nfor i in range(n):\r\n res += l[i % k]\r\n\r\nprint(res)", "from string import ascii_lowercase\r\nn, k = map(int, input().split())\r\nletters = list(ascii_lowercase)\r\ns, i = '', 0\r\nwhile len(s) < n:\r\n s += letters[i]\r\n i += 1\r\n if i == k:\r\n i = 0\r\nprint(s)", "# @Chukamin ZZU_TRAIN\n\ndef main():\n n, k = map(int, input().split())\n for i in range(n):\n print(chr(97 + i % k), end = '')\n \nif __name__ == '__main__':\n main()\n\n \t \t \t\t\t\t\t\t \t \t\t \t\t\t\t\t", "n, k = map(int, input().split())\r\nletters = [chr(ord('a') + i) for i in range(k)]\r\npattern = ''.join(letters)\r\nresult = pattern * (n // k) + pattern[:n % k]\r\nprint(result)", "n, k = map(int, input().split())\r\nletters = 'abcdefghijklmnopqrstuvwxyz'\r\npw = []\r\nfor i in range(n):\r\n pw.append(letters[i])\r\n if len(pw) >= k:\r\n break\r\nfor i in range(n - len(pw)):\r\n pw.append(pw[i])\r\n\r\npw = ''.join(pw)\r\nprint(pw)\r\n", "\nletters = \"abcdefghijklmnopqrstuvwxyz\"\nn, k = list(map(int, input().split()))\noutput = \"\"\ncurrent = 0\nfor i in range(n):\n if current == k :\n current = 0\n output += letters[current]\n current += 1\n\nprint(output)", "n,k = list(map(int, input().split()))\r\ns=[chr(i) for i in range(97,97+k)]\r\ns=\"\".join(s)\r\nprint(s*(n//k)+s[:n%k])", "import random\r\nx = input()\r\nx = x.split()\r\nl = []\r\nL = []\r\nc = True\r\nfor i in range(int(x[0])):\r\n l.append(0)\r\n#print(l)\r\nfor i in range(int(x[1])-1):\r\n if c:\r\n L.append(chr(random.randint(ord('a'), ord('z'))))\r\n c = False\r\n while not c:\r\n y = chr(random.randint(ord('a'), ord('z')))\r\n try:\r\n L.index(y)\r\n except:\r\n L.append(y)\r\n break\r\n#print(L)\r\nc = 0\r\nfor i in range(len(l)):\r\n while True:\r\n try:\r\n l[i] = L[c]\r\n c += 1\r\n except:\r\n c = 0\r\n else:\r\n break\r\nl = \"\".join(l)\r\nprint(l)", "n,k=map(int,input().split())\r\np=\"\"\r\nx=ord(\"a\")\r\nfor i in range(k):\r\n p+=chr(x)\r\n x+=1\r\nans=\"\"\r\nfor i in range(n):\r\n ans+=p[i%k]\r\nprint(ans)", "import string\r\n\r\n\r\ndef main():\r\n n, k = list(map(int, input().split()))\r\n distinct_chars = string.ascii_lowercase[:k]\r\n\r\n password = \"\"\r\n pointer = 0\r\n while len(password) < n:\r\n password += distinct_chars[pointer]\r\n pointer = (pointer + 1) % k\r\n \r\n print(password)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import string\r\n\r\nletters=string.ascii_lowercase\r\n\r\nn,k=list(map(int,input().split(' ')))\r\n\r\nfor i in range(n):\r\n\tcoordinate=i%k\r\n\tprint(letters[coordinate], end=\"\")\r\nprint()", "n,k=map(int, input().split())\na=\"abcdefghijklmnopqrstuvwxyz\"\nb=a[0:k]\ni=0\nwhile n!=len(b):\n b=b+b[i]\n i+=1 \n if i==k:\n i=0\nprint(b)", "n,k = map(int, input().split())\r\n\r\ncrs = [chr((i)+97) for i in range(k)]\r\ns=''\r\nfor i in range(n):\r\n s = s + crs[i%k]\r\nprint(s)\r\n", "\r\nchars = \"abcdefghijklmnopqrstuvwxyz\"\r\nn , k = input().split()\r\nn = int(n)\r\nk = int(k)\r\npassword = chars[0:k]*100\r\n\r\nprint(password[0:n])\r\n", "import string\r\n\r\nn, k = map(int, input().split())\r\nj = 0\r\nchars = string.ascii_lowercase\r\npassword = \"\"\r\nwhile(n!=0):\r\n for i in range(k):\r\n if n == 0:\r\n break\r\n password += chars[i]\r\n n-=1\r\nprint(password)", "import random\r\nimport math\r\n\r\nn ,k = map(int,input().split())\r\nif(k > 26):\r\n k = 26\r\nletters = \"abcdefghijklmnopqrstuvwxyz\"\r\nres = []\r\nfor i in range(n):\r\n res.append(letters[i%k])\r\nprint(\"\".join(res))\r\n", "length, distinct = map(int, input().split())\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\nstring = \"\"\r\n\r\nfor i in range(distinct):\r\n string += alpha[i]\r\n\r\nwhile True:\r\n\r\n for j in range(distinct):\r\n \r\n if len(string) == length:\r\n break\r\n \r\n else:\r\n string += alpha[j]\r\n \r\n if len(string) == length:\r\n break\r\n \r\nprint(string)", "n , k = map(int,input().split(' ')) # 4 3 \r\nq = n - k # 1 \r\ns = ''\r\nfor i in range(97,97+k) : \r\n s = s + chr(i) \r\n\r\n \r\nfor i in range(0,q) : \r\n s = s+s[i] \r\nprint(s)", "n,s=map(int,input().split())\r\nl=[chr(i) for i in range(ord('a'),ord('z')+1)]\r\na=[]\r\nc=0\r\nfor k in range(s):\r\n a.append(l[k])\r\n\r\nfor i in range(n):\r\n print(a[c],end=\"\")\r\n c=c+1\r\n if(c==s):\r\n c=0", "inn = list(map(int, input().split(\" \")))\nlent = inn[0]\ndist = inn[1]\nlets = []\ni = 97\nfor _ in range(dist):\n lets.append(chr(i))\n i += 1\npasscd = \"\".join(lets)\nwhile len(passcd)<lent:\n passcd += passcd\nprint(passcd[:lent])", "n,k = map(int,input().split())\r\nprint(('abcdefghijklmnopqrstuvwxyz'[:k]*n)[:n])\r\n", "alphList = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'\r\nalphList = list(alphList.split(' '))\r\npLen,rLen = map(int, input().split())\r\npswrd = []\r\nfor i in range(rLen):\r\n pswrd.append(alphList[i])\r\npswrd = pswrd*(pLen//rLen+1)\r\nnPswrd = []\r\ni=0\r\nwhile i<pLen:\r\n nPswrd.append(pswrd[i])\r\n i+=1\r\ns = ''\r\ns = s.join(nPswrd)\r\nprint(s)", "import string\r\nlett=string.ascii_lowercase\r\nx=input()\r\nn,k=list(map(int,x.split()))\r\nlett=lett[0:k]\r\nlett1=lett*n\r\nprint(lett1[0:n])\r\n ", "n, k = (int(i) for i in input().split())\na, res = ord(\"a\"), []\nfor i in range(n):\n res.append(chr(a + (i % k)))\nres = \"\".join(res)\nprint(res)\n", "n,k = map(int, input().split())\r\nchu = list(range(97,123))\r\n\r\na = chu[:k]\r\npw = \"\"\r\nfor i in range(n):\r\n pw += chr(a[i % len(a)])\r\nprint(pw)", "n, k = map(int, input().split())\r\nalphabet = 'qwertyuiopasdfghjklzxcvbnm'\r\nres, i = '', 0\r\nfor _ in range(n):\r\n res += alphabet[i]\r\n if i < k - 1:\r\n i += 1\r\n else:\r\n i = 0\r\nprint(res)", "# A. New Password\n\nfrom string import ascii_lowercase\n\nn, k = map(int, input().split())\nans = \"\"\ni = 0\nwhile i < n:\n ans += ascii_lowercase[:min(k, n-i)]\n i += k\nprint(ans)\n", "n, k = map(int, input().split())\r\na = ''\r\nfor i in range(97, 97+k):\r\n a += chr(i)\r\n\r\nprint(a*(n//k), end = '')\r\n\r\nn -= (n//k)*k\r\nprint(a[:n])", "letters = [chr(i) for i in range(97, 123)]\r\nn, k = map(int, input().split())\r\npassword = ''\r\nfor i in range(n):\r\n cur = i%k\r\n password += letters[cur]\r\nprint(password)\r\n", "num=[int(num) for num in input().split()]\r\nlist_1=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\nindex=0\r\nindex_2=0\r\nword=\"\"\r\nwhile (index<num[0]):\r\n if (index_2==(num[1]-1)):\r\n word=word+list_1[index_2]\r\n index_2=0\r\n else:\r\n word=word+list_1[index_2]\r\n index_2+=1\r\n index+=1\r\nprint(word)", "import string\r\nalpha=string.ascii_lowercase\r\ncnt=0\r\nn,k=map(int,input().split(' '))\r\nfor i in range(n):\r\n print(alpha[cnt%k],end='')\r\n cnt+=1\r\n\r\n\r\n", "import random\r\nn = list(map(int,input().split()))\r\nalpha = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\"]\r\nran = []\r\nwhile len(ran) != n[1] :\r\n r = random.choice(alpha)\r\n if r not in ran :\r\n ran.append(r)\r\n\r\nx = 0\r\nwhile len(ran) != n[0] :\r\n ran.insert(len(ran),ran[x])\r\n x += 1\r\n\r\n\r\nprint(\"\".join(ran).lower())", "l1=[int(i) for i in input().split()]\r\nn=l1[0] #len of pswd\r\nk=l1[-1] #no of distinct letter\r\ns=\"\"\r\ni=1\r\nwhile len(s)!=n:\r\n if i!=k:\r\n s=s+chr(i+96)\r\n else :\r\n i=0\r\n s=s+chr(k+96)\r\n i+=1\r\nprint(s)", "s1 = 'abcdefghijklmnopqrstuvwxyz'\r\ns2 = ''\r\nn ,k = input().split(\" \")\r\nn = int(n)\r\nk = int(k)\r\nfor i in range(n):\r\n s2+=s1[i % k]\r\nprint(s2)\r\n", "n,k=[int(x) for x in input().split()]\r\nch=97\r\npw=''\r\nfor i in range(0,k):\r\n pw+=chr(ch)\r\n ch+=1\r\nprint((n//k)*pw+pw[:n%k])\r\n", "n, k = list(map(int, input().split(' ')))\r\na = 'zxcvbnmasdfghjklqwertyuiop'\r\nb = a[:k]\r\ns = ''\r\nfor i in range(n):\r\n s += b[i % k]\r\nprint(s)", "n,k=map(int,input().split())\r\n\r\nchar=[]\r\ninitial='a'\r\nans=''\r\nfor i in range(0,k):\r\n char.append(initial)\r\n initial=chr(ord(initial)+1)\r\ng=0\r\nfor i in range(0,n):\r\n ans=ans+char[g]\r\n g=g+1\r\n if g==len(char):\r\n g=0\r\nprint(ans)", "n, k = map(int, input().split())\r\nABC = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nx = 0\r\ns = ''\r\nfor i in range(n):\r\n if x+1 != k:\r\n s+=ABC[x]\r\n x+=1\r\n else:\r\n s+=ABC[x]\r\n x = 0\r\nprint(s)", "n,k = list(map(int,input().split()))\r\n\r\nfor i in range(n):\r\n print(chr(ord('a')+i%k),end=\"\")\r\n", "n, k = list(map(int, input().split()))\r\nlatin_letters = ['a', 'b', 'c', 'd', 'e', \r\n 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', \r\n 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', \r\n 'v', 'w', 'x', 'y', 'z']\r\n \r\npassword_char = latin_letters[:k+1]\r\nres = []\r\nj = 0\r\nfor i in range(n):\r\n if i % k == 0:\r\n j = 0\r\n res.append(password_char[j])\r\n j += 1\r\nprint(''.join(res))", "alfa = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nn,k = map(int,input().split())\r\nx = y = t = 0\r\npassword = str()\r\nwhile n > 0:\r\n if t < k:\r\n password = password + alfa[x]\r\n t += 1\r\n x += 1\r\n n -= 1\r\n else:\r\n if y > k-1:\r\n y = 0\r\n password = password + alfa[y]\r\n y += 1\r\n n -= 1\r\nprint(password)\r\n ", "from sys import stdin,stdout\nfrom math import gcd,sqrt,floor,ceil\n# Fast I/O\ninput = stdin.readline\n#print = stdout.write\n\ndef list_inp(x):return list(map(x,input().split()))\ndef map_inp(x):return map(x,input().split())\n\ndef lcm(a,b): return (a*b)/gcd(a,b)\n\ns1 = 'abcdefghijklmnopqrstuvwxyz'\na,b = map_inp(int)\n\nq = s1[:b]\nq1 = q*a\nprint(q1[:a])\n\n\n", "from string import ascii_lowercase\nfrom random import choice\n(n, k) = input().split()\nn = int(n)\nk = int(k)\nletters = [char for char in ascii_lowercase]\nmy_random_letters = []\nfor i in range(k):\n letter = choice(letters)\n my_random_letters.append(letters.pop(letters.index(letter)))\nl = 0\nfor i in range(n):\n if l == k:\n l = 0\n print(my_random_letters[l], end='')\n l += 1", "import string\r\nn,k =map(int,input().split())\r\nd=string.ascii_letters[:k]\r\npw =d\r\nd =d*(n//k +1)\r\npw = pw +d[:n-k]\r\nprint(pw)\r\n", "def new_password(n, k):\r\n result = []\r\n start = ord('a')\r\n for _ in range(k):\r\n result.append(chr(start))\r\n start += 1\r\n is_a = True\r\n for i in range(n - k):\r\n if is_a:\r\n result.append('a')\r\n is_a = False\r\n else:\r\n result.append('b')\r\n is_a = True\r\n return ''.join(result)\r\n \r\nn, k = map(int, input().split())\r\nprint(new_password(n, k))", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n#\r\n# ------------------------------------------------------------------------------\r\n# Author: Mohammad Mohsen\r\n# Date: Tue Dec 28 07:53:26 2021\r\n# problem name: New_Password\r\n# contest: 770-VK Cup 2017 - Qualification 2\r\n# problem difficulty: A-\r\n# problem url: https://codeforces.com/contest/770/problem/A\r\n# ------------------------------------------------------------------------------\r\n\r\nfrom typing import *\r\nfrom string import ascii_lowercase\r\nfrom io import StringIO\r\n\r\n\r\nclass Problem(object):\r\n\r\n def __init__(self, name: str) -> None:\r\n self.name = name\r\n\r\n def solution(self) -> Union[str, int, float]:\r\n password_len, unique_count = [int(i) for i in input().strip().split()]\r\n password: StringIO = StringIO()\r\n index: int = 0\r\n \r\n while password_len:\r\n password.write(f\"{ascii_lowercase[index]}\")\r\n index = (index + 1) % unique_count\r\n password_len -= 1\r\n\r\n return password.getvalue()\r\n\r\n\r\nproblem = Problem(\"New_Password\")\r\n\r\nif __name__ == \"__main__\":\r\n solution: Union[str, int, float] = problem.solution()\r\n print(solution)\r\n\r\n", "n, k = list(map(int, input().split()))\r\n\r\nchars = 'abcdefghijklmnopqrstuvwxyz'\r\nresult = []\r\n\r\nfor i in range(n):\r\n result.append(chars[i % k])\r\n \r\nprint(\"\".join(result))\r\n", "n, k = map(int, input().split())\r\ncount = ord(\"a\") # 97+25\r\nans = \"\"\r\nfor i in range(n):\r\n ans += chr(count)\r\n if count == 97:\r\n count += 1\r\n elif count < 97 + k - 1:\r\n count += 1\r\n else:\r\n count -= 1\r\nprint(ans)", "\r\nimport string\r\nimport random\r\n\r\n(n, k) = tuple(map(int, input().split()))\r\n\r\n\r\nunique_char = list()\r\nwhile (k != 0):\r\n random_char = random.choices(string.ascii_letters, k=1)[0].lower()\r\n if random_char in unique_char:\r\n continue\r\n\r\n unique_char.append(random_char)\r\n k-=1 \r\n \r\n\r\npassword = str()\r\n# concatinate the unique characters \r\nfor index in range (n):\r\n password += unique_char[index % len(unique_char)]\r\n \r\nprint(password)", "import math\r\nnANDk = input()\r\nnANDk = nANDk.split()\r\nn = int(nANDk[0]) # total len of word\r\nk = int(nANDk[1]) # distinct characters\r\nalphabet = \"abcdefghijklmnopqrstuvwxyz\"\r\nword = \"\"\r\nactualword = \"\"\r\nindex = 0\r\nwhile k > 0:\r\n word = str(word+alphabet[index])\r\n index = index + 1\r\n k = k - 1\r\nword = word*(math.ceil(n/int(nANDk[1])))\r\nindex = 0\r\nwhile n > 0:\r\n actualword = actualword+word[index]\r\n index = index + 1\r\n n = n - 1\r\nprint(actualword)", "n, k = map(int, input().split())\n\nalphabet = list(\"abcdefghijklmnopqrstuvwxyz\")\n\ns = alphabet[:k]\n\ni = 0\nwhile len(s) != n:\n if i % 2 == 0:\n s += s[0]\n else:\n s += s[1]\n i += 1\n\nprint(\"\".join(s))", "import math\r\nn,k=map(int,input().split())\r\np=\"abcdefghijklmnopqrstuvwxyz\"\r\np=p[0:k:]\r\np=p*math.ceil(n/k)\r\nprint(p[0:n:1])\r\n \r\n", "n,k=map(int,input().split())\r\ns='abcdefghijklmnopqrstuvwxyz'\r\na=s[:k];i=0\r\nwhile len(a)<n:\r\n a+=a[i]\r\n i+=1\r\nprint(a) \r\n", "n, k = map(int, input().split())\na = \"abcdefghijklmnopqrstuvwxyz\"\nprint((a[:k] * n)[:n])\n", "nx , kx = input().split()\r\nn = int(nx)\r\nk = int(kx)\r\nword = []\r\nletters = list('abcdefghijklmnopqrstuvwxyz ') \r\nfor i in range(k):\r\n\tword.append(letters[i])\r\ni = 0\r\nwhile n>len(word):\r\n\tword.append(word[i])\r\n\ti += 1\r\n\r\nprint(''.join(word))\r\n", "a, b = map(int, input().split())\r\nfor i in range(b):\r\n print(chr(i + ord('a')), end='')\r\n\r\nfor i in range(a - b):\r\n if i & 1 == 0:\r\n print('a', end='')\r\n else:\r\n print('b', end='')\r\n", "#_____________32____________#\r\n# p,r=map(int,input().split())\r\n# for i in range(1,11):\r\n# if (i*p)%10==r or (i*p)%10==0:\r\n# print(i)\r\n# exit()\r\n\r\n#_____________33____________#\r\n# li=set(input().split())\r\n# print(4-len(li))\r\n\r\n#_____________34____________#\r\n# s=input()\r\n# t=input()\r\n# i=0\r\n# for c in t:\r\n# if c==s[i]:\r\n# i+=1\r\n# print(i+1)\r\n\r\n#_____________36____________#\r\n# n=int(input())\r\n# wires=[int(x) for x in input().split()]\r\n# tries=int(input())\r\n# for Try in range(tries):\r\n# i,j=map(int,input().split())\r\n# if i>1:\r\n# wires[i-2]+=j-1\r\n# if i<n:\r\n# wires[i]+=wires[i-1]-j\r\n# wires[i-1]=0\r\n# for i in wires:\r\n# print(i)\r\n\r\n#_____________36____________#\r\n# n,b,d=map(int,input().split())\r\n# li=[int(x) for x in input().split()]\r\n# trash=0\r\n# count=0\r\n# for o in li:\r\n# if o>b:\r\n# continue\r\n# trash+=o\r\n# if trash>d:\r\n# count+=1\r\n# trash=0\r\n# print(count)\r\n\r\n#_____________43____________#\r\n# n=int(input())\r\n# li=input().split()\r\n# maths=[]\r\n# pe=[]\r\n# prog=[]\r\n\r\n# for i in range(n):\r\n# if li[i]=='1':\r\n# prog.append(i+1)\r\n# elif li[i]=='2':\r\n# maths.append(i+1)\r\n# else:\r\n# pe.append(i+1)\r\n# if len(maths)==0 or len(prog)==0 or len(pe)==0:\r\n# print(0)\r\n# exit()\r\n# print(min(len(maths),len(prog),len(pe)))\r\n# for a,b,c in zip(prog,maths,pe):\r\n# print(a,b,c)\r\n\r\n#_____________43____________#\r\nimport string,random\r\nn,k=map(int,input().split())\r\nli='abcdefghijklmnopqrstuvwxyz'\r\nword=''\r\nword+=li[0:k]\r\nwhile len(word)<n:\r\n ch=random.choice(word)\r\n if word[-1] != ch:\r\n word+=ch\r\nprint(word)\r\n", "n, k = list(map(int, input().split()))\n\npw = \"\"\ndistinct = 0\nchar_code = 97\nfor i in range(n):\n if distinct < k:\n pw += chr(char_code)\n distinct += 1\n char_code += 1\n else:\n char_code = 97\n distinct = 0\n pw += chr(char_code)\n distinct += 1\n char_code += 1\n\nprint(pw)\n \t\t \t \t \t \t\t \t\t\t\t \t\t\t\t \t", "n, k =map(int, input().split(\" \"))\r\nlet=\"qwertyuioplkjhgfdsazxcvbnm\"\r\nres=\"\"\r\nfor i in range(n):\r\n res+=let[i%k]\r\nprint(res)", "l = 'qwertyuiopasdfghjklzxcvbnm'\r\nt = input().split(' ')\r\nn, k = int(t[0]), int(t[1])\r\nl = l[:k] * n\r\nprint(l[:n])", "import string\r\nn,k = map(int, input().split(' '))\r\nvar = (string.ascii_lowercase[:k])\r\nvar *= n // k\r\nx = n % k\r\nvar += var[:x]\r\nprint(var)", "import random\r\n\r\nn, k = [int(i) for i in input().split(\" \")]\r\ndistinct_chars = []\r\npassword = \"\"\r\n# number of distinct chars\r\n\r\nwhile len(password) < n:\r\n if len(distinct_chars) < k:\r\n new_char = chr(random.randrange(ord('a'), ord('z')+1))\r\n if new_char not in distinct_chars:\r\n distinct_chars.append(new_char)\r\n password+=new_char\r\n else:\r\n new_char = distinct_chars[random.randrange(0, len(distinct_chars))]\r\n if password[-1] != new_char:\r\n password+=new_char\r\nprint(password)\r\n", "n, k = map(int, input().split())\r\nsym = 'abcdefghijklmnopqrstuvwxyz'\r\nout = ''\r\n\r\nfor i in range(k):\r\n out += sym[abs(i-25)]\r\nout += (n // k - 1) * out + out[0:n % k]\r\n\r\nprint(out)", "import random \nimport string \n\ninput_ = input()\nn = int(input_.split()[0])\nk = int(input_.split()[1])\n\ndef generate(n, k):\n p=''\n possible_chars = string.ascii_letters[:k]\n while (True):\n if len(p) < n :\n p+=possible_chars\n else : \n break\n \n return p[:n]\n \n\nprint(generate(n, k))\n\n\t \t\t \t \t\t \t\t\t \t \t \t\t\t\t \t\t", "import string\r\nn, k = map(int, input().split())\r\nalphas = list(string.ascii_lowercase)\r\nfor i in range(n):\r\n print(alphas[i % k], end='')\r\n \r\n\r\n", "n , k = map(int , input().split())\r\na = 'abcdefghijklmnopqrstuvwxyz'\r\ns1 = a[:k]\r\ni = 0\r\nfor i in range(n - k):\r\n s1+=s1[i]\r\n i+=1\r\n if (i == k):\r\n i = 0\r\nprint(s1)", "n, k = map(int,input().split())\r\nstring = \"a\"*n\r\nfor i in range(1, k):\r\n string = list(string)\r\n times = n//(i+1)\r\n for j in range(1,times+1):\r\n string[j*(i+1)-1] = chr(97+i)\r\n\r\nprint(''.join(string))\r\n\r\n", "import string\r\nfrom math import ceil\r\n\r\nn,k = list(map(int, input().split(\" \")))\r\nletters = list(string.ascii_lowercase)\r\narr = letters[:k] * ceil(n/k)\r\npassword=[0] * n\r\n\r\nfor i in range(n):\r\n password[i] = arr[i]\r\n\r\nprint(''.join(password))\r\n\r\n", "n,k = map(int,input().split())\r\ns = \"\"\r\nfor i in range(k):\r\n s+=chr(97+i)\r\ns = s*(n//k+1)\r\nprint(s[:n])", "# import sys\r\n# sys.stdout = open('DSA/Stacks/output.txt', 'w')\r\n# sys.stdin = open('DSA/Stacks/input.txt', 'r')\r\n\r\nalphs = [chr(i) for i in range(97,123)]\r\n\r\nn, k = map(int, input().split())\r\n\r\nss = \"\"\r\nfor i in range(k):\r\n ss+=alphs[i]\r\ni = 1\r\ncc=0\r\nwhile i<=n-k:\r\n if cc>len(ss):\r\n cc=0\r\n ss+=ss[cc]\r\n cc+=1\r\n i+=1\r\n\r\nprint(ss)", "n, k = map(int,input().split())\r\nfor i in range(n):\r\n print(chr(ord('a') +i%k) ,end=\"\")", "n, k = map(int, input().split())\r\npassword = \"\"\r\nlet = \"abcdefghijklmnopqrstuvwxyz\"\r\nlis = list(let[:k])\r\n\r\ni = 0\r\nwhile i<n:\r\n if i>len(lis)-1:\r\n password += lis[i%(len(lis))]\r\n i += 1\r\n continue\r\n password +=lis[i]\r\n i += 1\r\n \r\nprint(password)", "n,k = map(int,input().split())\r\nans = \"\"\r\nxdxd = \"abcdefghijklmnopqrstuvwxyz\"\r\nwhile n != 0 :\r\n for i in range(k):\r\n ans += xdxd[i]\r\n n-=1\r\n if n == 0 :\r\n break\r\nprint(ans)", "l=list(map(int,input().split()))\r\n\r\ntemp=''\r\n\r\nwhile(len(temp)<l[0]):\r\n for i in range(l[1]):\r\n temp+=chr(97+i)\r\nprint(temp[:l[0]])", "L=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nx=list(map(int,input().split(\" \")))\r\nlength=x[0]\r\ndistinct=x[1]\r\n\r\nstr = ((\"\".join(L[:distinct]))* (length//distinct)) + \"\".join(L[:length%distinct])\r\nprint(str)\r\n", "n, k = map(int, input().split())\r\nans = \"\"\r\n\r\nfor c in range(ord('a'), ord('z') + 1):\r\n ans += chr(c)\r\n k -= 1\r\n if k == 0:\r\n break\r\n\r\na = ans[:n - k]\r\nwhile len(ans) < n:\r\n ans += a\r\n\r\nleng = len(ans) - n\r\nif len(ans) > n:\r\n ans = ans[leng:]\r\n\r\nprint(ans)", "import string\r\nn,k,x = *map(int,input().split()),0\r\ns = string.ascii_lowercase[:k]\r\nfor _ in range(n):\r\n print(s[x],end=\"\")\r\n if x >= len(s)-1:\r\n x = 0\r\n else:\r\n x+=1", "s = input().split(\" \")\r\nn = int(s[0])\r\nk = int(s[1])\r\n\r\nans = \"\"\r\ntmp = ord('a')\r\nfor i in range(k):\r\n ans += chr(tmp)\r\n tmp += 1\r\n\r\ndeff = n - k\r\nfor i in range(0, deff):\r\n if i % 2 == 0:\r\n ans += 'a'\r\n else:\r\n ans += 'b'\r\n \r\nprint(ans)", "n, k = map(int, input().split())\r\ns= \"\"\r\nfor i in range(n):\r\n s+= chr(ord(\"a\") + i%k )\r\nprint(s) \r\n", "l=[int(i)for i in input().split()][:2]\r\nn=l[0]\r\nk=l[1]\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\nl1=[]\r\nfor i in range(k):\r\n l1.append(s[i])\r\nz=n-k\r\nif(z>0):\r\n for i in range(z):\r\n m=l1[i]\r\n l1.append(m)\r\ns2=''.join(l1)\r\nprint(s2)", "inp=input()\r\ninp=inp.split()\r\nn=int(inp[0])\r\nk=int(inp[1])\r\nlst=[]\r\nnumber=97\r\n\r\nwhile (len(lst)<=k):\r\n lst.append(chr(number))\r\n number+=1\r\n\r\nnumber=0\r\nfor i in range(n):\r\n if number==k-1:\r\n print(lst[k-1],end='')\r\n number=0\r\n \r\n else:\r\n print(lst[number],end='')\r\n number+=1\r\n \r\n", "\r\nfrom string import ascii_lowercase as alpha\r\nn, k = [int(x) for x in input().split()]\r\npart = alpha[:k]\r\npassword = part*int((((n-(n % k))/k))) + alpha[0:n % k]\r\nprint(password)\r\n", "def generate_password(n, k):\r\n # Create a string containing k distinct characters\r\n distinct_chars = ''.join(chr(ord('a') + i) for i in range(k))\r\n\r\n # Initialize the password as an empty string\r\n password = ''\r\n\r\n # Append characters from the distinct_chars string to the password until its length reaches n\r\n while len(password) < n:\r\n password += distinct_chars\r\n\r\n # If the password's length exceeds n, trim it to the desired length\r\n password = password[:n]\r\n\r\n return password\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n, k = map(int, input().split())\r\n password = generate_password(n, k)\r\n print(password)\r\n", "#Strings always win!\r\n\r\nW = input().split()\r\n(a,b) = (int(W[0]),int(W[1]))\r\nAlphabet = 'qwertyuiopasdfghjklzxcvbnm'\r\n\r\n\r\npassword = ''\r\nfor j in range(int(a/b)):\r\n password+=Alphabet[:b]\r\n\r\nif len(password)<a:\r\n password += Alphabet[:a-len(password)]\r\n\r\nprint(password)\r\n", "import string;import random;\r\nn,k=map(int,input().split()); s=\"\"\r\nlist_items =random.sample( list(string.ascii_lowercase), k)\r\nfor i in range(n):\r\n s+=list_items[i%k]\r\nprint(s)", "n,k=map(int,input().split())\r\nres=''\r\nfor i in range(n):\r\n res+=chr((i%k)+97)\r\nprint(res)", "\"\"\"\r\ninput().split()\r\n\"\"\"\r\n\r\n\"\"\"\r\nimport random\r\n\r\nn, k = input().split()\r\nn = int(n)\r\nk = int(k)\r\n\r\nalphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nword = []\r\ni = 0\r\nx = 0\r\nprevious_letter = \"\"\r\nchoosen_letter = \"\"\r\n\r\nwhile i != n:\r\n\r\n choosen_letter = random.choice(alphabet)\r\n if n - k <= k:\r\n choosen_letter = word[x]\r\n word.append(choosen_letter)\r\n previous_letter = choosen_letter\r\n i = i + 1\r\n x = x + 1\r\n elif choosen_letter != previous_letter:\r\n if choosen_letter not in word: \r\n word.append(choosen_letter)\r\n previous_letter = choosen_letter\r\n i = i + 1\r\n\r\nprint(''.join(word))\r\n\"\"\"\r\nn, k = input().split()\r\nn = int(n)\r\nk = int(k)\r\n\r\ni = 0\r\n\r\nalphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nword = []\r\n\r\nwhile n > i:\r\n if(len(word) >= n):\r\n break\r\n word.append(alphabet[i])\r\n i = i + 1\r\n if(i == k):\r\n i = 0\r\n\r\nprint(''.join(word))\r\n", "n , k = map(int, input().split())\r\npassword = ''\r\na = 97\r\n\r\nfor i in range(1,n+1):\r\n password += chr(a)\r\n a += 1\r\n if i % k == 0:\r\n a = 97\r\n\r\nprint(password)\r\n", "n, k = [int(i) for i in input().split()]\r\nc = 97\r\npassword = \"\"\r\nfor i in range(k):\r\n password += chr(c)\r\n c += 1\r\n\r\nfor i in range(k, n):\r\n password += \"a\" if i%2==0 else \"b\"\r\nprint(password)", "alphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nn, k = map(int, input().split())\r\ni, j = 0, 0\r\nwhile(j < n):\r\n if(i == k):\r\n i = 0\r\n print(alphabet[i], end=\"\")\r\n i += 1\r\n j += 1\r\n", "n,k = map(int,input().split())\r\nwhile n:\r\n n=n-1\r\n print(chr(97+n%k),end=\"\")", "ans = \"\"\nn,k = map(int,input().split())\ni = 97\nfor j in range(n):\n ans += chr(i)\n i+=1\n if(k==i-97):\n i=97\nprint(ans)", "from string import ascii_lowercase as l\r\nn, k = map(int, input().split())\r\ndistK = l[:k]\r\ni = 0\r\nfor _ in range(n):\r\n print(distK[i], end = '')\r\n i = (i+1 if i< k - 1 else 0)", "n, k = map(int, input().split())\r\n\r\na = ord('a')\r\n\r\nfor i in range(0, n):\r\n print( chr(a+ (i%k)) ,end='')\r\n\r\n", "n , k = input().split()\r\nn = int(n); k = int(k)\r\nans = \"\"\r\nj = 0\r\nfirst_char = ord('a')\r\nfor i in range(n):\r\n ans += chr(first_char+j)\r\n j+=1\r\n if j == k:\r\n j = 0\r\nprint(ans)\r\n", "n, k = map(int, input().split())\r\n\r\nalphabet = \"abcdefghijklmnopqrstuvwxyz\"\r\npassword = \"\"\r\n\r\nfor i in range(n):\r\n password += alphabet[i % k]\r\n\r\nprint(password)\r\n", "n, k = map(int, input().split())\r\narray = [chr(i) for i in range(97, 97 + k)]\r\nstring = ''\r\nwhile len(string) != n:\r\n for i in array:\r\n string += i\r\n if len(string) == n:\r\n break\r\nprint(string)\r\n", "import sys\r\nfrom string import ascii_lowercase as az\r\n\r\ndef main():\r\n n, k = map(int, sys.stdin.read().strip().split())\r\n return n//k*az[:k] + az[:n%k]\r\n\r\nprint(main())\r\n", "a,b = map(int, input().split())\r\n\r\nc = ''\r\nfor i in range(a):\r\n c += chr(97 + (i % b) )\r\nprint(c)", "import math\r\nn,m=map(int,input().strip().split()[:2])\r\nk=[chr(x) for x in range(97,97+m)]\r\np=''.join(k)\r\np+=p*math.ceil(n/m)\r\np=p[:n]\r\nprint(p)", "import random\nn, k = [int(x) for x in input().split()]\nalphabet = list(\"abcdefghijklmnopqrstuvwxyz\")\nword = ''\nletters = []\nfor i in range(k):\n x = random.choice(alphabet)\n while x in letters:\n x = random.choice(alphabet)\n letters.append(x)\ni = 1\nwhile len(word) < n:\n if (i <= k):\n word = word + letters[i - 1]\n i = i + 1\n else:\n i = 1\nprint(word)\n \t \t \t\t \t \t \t \t \t \t\t\t \t", "n,k = map (int,input().split())\r\nch=''\r\nfor x in range(k) : \r\n ch+=chr(x+97)\r\nc=n%k\r\nc1=n//k\r\nprint(ch*c1+ch[:c])", "n,k= [int(x) for x in input().split()]\r\ni=0\r\nchar=97\r\nl=[]\r\nwhile i<n:\r\n if i<k:\r\n l.append(chr(char))\r\n i+=1\r\n char+=1\r\ni=0\r\nwhile i<n-k:\r\n l.append(l[i])\r\n i+=1\r\n\r\nprint(''.join(l))\r\n \r\n \r\n \r\n ", "from sys import stdin, stdout\r\n\r\ndef get_ints(): return list(map(int, stdin.readline().strip().split()))\r\n\r\ndef get_string(): return stdin.readline().strip()\r\n\r\ndef solve():\r\n n,k = get_ints()\r\n ans=\"\"\r\n for i in range(n-k+2):\r\n if (i%2==0): ans+=chr(97)\r\n else: ans+=chr(98)\r\n for i in range(k-2):\r\n ans+=chr(99+i)\r\n stdout.write(ans+\"\\n\")\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n ", "n , k = map(int,input().split())\r\nst = \"abcdefghijklmnopqrstuvwxyz\"\r\noutput = st[:k]\r\nst = st[:k]\r\ni = 0\r\nwhile len(output) != n :\r\n if i == len(st):\r\n i = 0\r\n output += st[i]\r\n i+=1\r\nprint(output)", "from random import randint\r\n\r\ndata = input().split(' ')\r\nlong = int(data[0])\r\ndifferent = int(data[1])\r\npossibilities = []\r\nwhile len(possibilities) < different:\r\n var = chr(randint(97, 122))\r\n if possibilities.count(var) == 0:\r\n possibilities.append(var)\r\nresult = ''\r\nwhile len(result) < long:\r\n for x in possibilities:\r\n if len(result) >= long:\r\n break\r\n result += x\r\nprint(result)", "from string import ascii_lowercase\nn,k = map(int,input().split())\npart = ascii_lowercase[:k]\nrepetitions = n//k \nres = part * repetitions\nlast = n % k\nres += part[:last]\nprint(res)", "\"\"\"\r\n@auther:Abdallah_Gaber \r\n\"\"\"\r\nimport random\r\nlst = [int(x) for x in input().split()]\r\nn = lst[0]\r\nk = lst[1]\r\npassword = []\r\nwhile len(password) < k:\r\n rand_letter = chr(random.randint(97, 122))\r\n if rand_letter not in password:\r\n password.append(rand_letter)\r\ni=0\r\nwhile len(password) < n:\r\n password.append(password[i])\r\n i+=1\r\n\r\nchar = \"\"\r\nfor item in password:\r\n char+=item\r\nprint(char)\r\n\r\n", "n, k = list(map(int, input().split()))\r\nword = []\r\nnext = unique_num = 0\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\nfor _ in range(n):\r\n if unique_num == k:\r\n next = 0\r\n unique_num = 0\r\n word.append(alpha[next])\r\n next += 1\r\n unique_num +=1\r\n\r\nprint(\"\".join(word))", "\r\n\r\nl = input().split()\r\nn = int(l[0])\r\nk = int(l[1])\r\n\r\nletters = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\npassword = \"\"\r\nfor i in range(n):\r\n password += letters[i%k]\r\n\r\n\r\nprint(password)", "import string\r\nnum , le = list(map(int,input().split()))\r\nx = string.ascii_lowercase\r\ns = ''\r\nif num ==le :\r\n print(x[:le])\r\nelse:\r\n for i in range(num):\r\n if i == le :\r\n s+=x[:i]\r\n break\r\n for j in range(num):\r\n if len(s) < num:\r\n s =s *le\r\n elif len(s) ==num:\r\n print(s)\r\n break\r\n else:\r\n s = s[:num]\r\n print(s)\r\n break", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\n\r\nfor i in range(n):\r\n print(chr(i % k + 97), end='')", "n,k=list(map(int,input().split()))\r\ns=\"\"\r\nfor i in range(k):\r\n ch=chr(ord('a')+i)\r\n s=s+ch\r\nb=s\r\ni=k\r\nj=0\r\nwhile(i<n):\r\n if(j==k):\r\n j=0\r\n b=b+s[j]\r\n j+=1\r\n i+=1\r\nprint(b)", "from random import randint\r\n\r\n\r\ndef createPassword(n, k):\r\n password = []\r\n start = 97 # a\r\n end = start + k\r\n symbols = [chr(i) for i in range(start, end)]\r\n for _ in range(int(n / k)):\r\n password.append(\"\".join(symbols))\r\n password.append(\"\".join(symbols[: n % k]))\r\n return \"\".join(password)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n, k = map(int, input().split())\r\n print(createPassword(n, k))\r\n", "n,k=tuple(map(int,input(\"\").split(\" \")))\r\npan=\"abcdefghijklmnopqrstuvwxyz\"\r\nres=\"\"\r\nwhile len(res)<n:\r\n res+=pan[0:k] \r\n\r\nprint(res[0:n])", "from itertools import cycle, islice\nn, k = map(int, input().split())\n\nalphabet = \"abcdefghijklmnopqrstuvwxyz\"\nprint(alphabet[:k] + ''.join(islice(cycle('ab'), n - k)))", "import string\nn, k = map(int, input().split())\nprint(\"\".join([string.ascii_lowercase[c%k] for c in range(n)]))\n", "x=97\r\n\r\nn, k = map(int, input().split())\r\n\r\nlis=list()\r\n\r\nfor i in range (k):\r\n lis.append(chr(x))\r\n x=x+1\r\n\r\nlis2=lis.copy()\r\n#print(lis2)\r\n\r\nj=0\r\nfor i in range(n-k):\r\n if j>(k-1):j=0\r\n lis2.append(lis[j])\r\n j=j+1\r\n#print(lis2)\r\n\r\nfor i in lis2:\r\n print(i, end=\"\")\r\nprint(\"\")", "str=input()\r\narr=str.split(' ')\r\ncount=0\r\nk=int(arr[0])\r\ns=int(arr[1])\r\narr=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\narr2=[]\r\nstr=''\r\nfor i in range (s):\r\n arr2.append(arr[i])\r\nfor i in range(k):\r\n str=str+arr2[i%s]\r\nprint(str)", "import random\r\nlst2=[]\r\nn, k=map(int, input().split(' '))\r\nt=0\r\nlst=[chr(i) for i in range(97,123)]\r\nfor x in range(k):\r\n aa=random.choice(lst)\r\n lst2.append(aa)\r\n lst.remove(aa)\r\n\r\nslovo=[]\r\n\r\nslovo.append(lst2[0])\r\n\r\nfor i in range(n-1):\r\n t=t+1\r\n if t==k:\r\n t=0\r\n slovo.append(lst2[t])\r\n if slovo[i]==slovo[i+1]:\r\n while slovo[i]==slovo[i+1]:\r\n slovo[i+1]=random.choice(lst2)\r\n \r\nprint(''.join(slovo))\r\n\r\n \r\n", "n, k = map(int, input().split())\r\n\r\nabc = [chr(x) for x in range(97,123)]\r\nans = ''\r\nindex = 0\r\nwhile len(ans) < n:\r\n ans += abc[index]\r\n if index < k - 1:\r\n index += 1\r\n else:\r\n index = 0\r\n\r\nprint(ans)\r\n \r\n", "inp = input().split()\r\nn = int(inp[0])\r\nk = int(inp[1])\r\n\r\nans = \"\"\r\nloopStr = \"\"\r\n\r\nword = 97\r\nfor i in range(k):\r\n loopStr += chr(word)\r\n word += 1\r\n\r\nfor i in range(n):\r\n ans += loopStr\r\n if len(ans) > n:\r\n break\r\n\r\n\r\nprint(ans[0:n])\r\n", "def main():\r\n l=list()\r\n l=input()\r\n l=l.split()\r\n n=int(l[0])\r\n k=int(l[1])\r\n l=list()\r\n st=str()\r\n for i in range(ord('a'),ord('z')+1):\r\n l.append(chr(i))\r\n for i in range(k):\r\n st+=l[i]\r\n if len(st) <n:\r\n st=st*(n)\r\n print(st[:n])\r\n else:\r\n print(st)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n,k = map(int,input().split())\npassword = ''\nj = 0\nfor i in range(n):\n password+=chr(j+97)\n j = (j+1)%k\nprint(password)\n", "import string\r\nl=input()\r\nl=l.split()\r\nn=int(l[0])\r\nk=int(l[1])\r\nletters=list(string.ascii_lowercase)\r\npassword=\"\"\r\ntmp=0\r\nwhile n>0:\r\n for i in range(k):\r\n n-=1\r\n password+=letters[i]\r\n\r\nprint(password[:int(l[0])])\r\n", "import string\r\ndef solve():\r\n n, k = map(int, input().split())\r\n chrs = string.ascii_letters\r\n print(n//k * chrs[:k] + chrs[:n % k])\r\nsolve()\r\n", "n,k=map(int,input().split())\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\ns1=s[:k]\r\nb=abs(n-k)\r\nfor i in range(b):\r\n s1+=s1[i]\r\nprint(s1)", "from string import ascii_lowercase\nimport random\nn, k = [int(v) for v in input().split()]\nchars = random.sample(ascii_lowercase, k)\nprint(''.join(chars[i%k] for i in range(n)))\n", "n, k = map(int,input().split())\r\nabc = [chr(i) for i in range(97,97+k)]\r\nfor i in range(n):\r\n print(abc[i%k],end=\"\")", "alpha ='abcdefghijklmnopqrstuvwxyz'\r\ntemp = [int(x) for x in input().split()]\r\ntemp2 = alpha[:temp[1]]\r\nanswer = ''\r\nfor i in range(temp[0]):\r\n answer += temp2[i % temp[1]]\r\nprint(answer)", "n,k = map(int,input().split())\r\npas = ''\r\narr = ['a','b','c','d','e','f','g',\r\n 'h','i','j','k','l','m','n',\r\n 'o','p','q','r','s','t','u',\r\n 'v','w','x','y','z']\r\nfor i in range(0,n):\r\n pas+=arr[i%k]\r\nprint(pas)\r\n \r\n", "import string\r\nn, k = map(int, input().split())\r\ns = list(string.ascii_lowercase)[:k]\r\nfor i in range(n):\r\n print(s[i%k], end = '')\r\nprint()", "n,k=list(map(int,input().split(\" \")))\r\nalphabetToUse=[chr(i) for i in range(97,97+k)]\r\nch=\"\".join(alphabetToUse)\r\nresult=ch*(n//k)+ch[:(n%k)]\r\nprint(result)\r\n", "n, k = list(map(int, input().split()))\n\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\ns = alphabets[0:k]\n# q = n // k\ns = s * (n//k) + s[0:n % k]\n\nprint(s)\n", "n,k = map(int, input().split())\r\nt = 0\r\nwhile t!=n:\r\n c = 97\r\n for j in range(k):\r\n print(chr(c),end='')\r\n c+=1\r\n t+=1\r\n if t==n:\r\n break", "def I(): return(list(map(int,input().split())))\r\n\r\nn,k=I()\r\ns2=\"\".join([chr(i) for i in range(99,99+k-2)])\r\ns1=\"ab\"*((n-k+2)//2)\r\nif (n-k+2)%2!=0:\r\n\ts1+=\"a\"\r\n# if k==2:\r\n# \tprint(s1) if len(s1)==n else print(s1+\"a\")\r\n# else:\r\n# \tprint(s1+s2)\r\nprint(s2+s1)", "L=\"abcdefghijklmnopqrstuvwxyz\"\r\ni=input()\r\ni=i.split(\" \")\r\nn=int(i[0])\r\nk=int(i[1])\r\nl=L[:k]\r\no=\"\"\r\nfor i in range(n):\r\n o+=l[i%k]\r\n\r\nprint(o) ", "INPUT = input().split()\nn = int(INPUT[0])\nk = int(INPUT[1])\ndistinct_chars = 'abcdefghijklmnopqrstuvwxyz'\nfinal_pass = list()\nchar_list = list()\nfor x in range(k):\n char_list.append(distinct_chars[x])\n\nfor x in range(n):\n final_pass.append(char_list[x%len(char_list)])\n\nprint(''.join(final_pass))\n\n", "nums= input().split()\r\nn = int(nums[0])\r\nk = int(nums[1])\r\nalph = \"abcdefghijklmnopqrstuvwxyz\"\r\nout = \"\"\r\nfor i in range(n//k):\r\n for j in range(k):\r\n out+=alph[j]\r\nfor i in range(n%k):\r\n out += alph[i]\r\nprint(out)\r\n", "from string import ascii_lowercase\n\nn, k = map(int, input().split())\n\nindex = 0\nfor i in range(n):\n if index >= k:\n index = 0\n print(ascii_lowercase[index], end =\"\")\n index += 1", "exec(bytes('湛欬⁝‽楬瑳洨灡椨瑮‬楬瑳椨灮瑵⤨献汰瑩✨✠⤩⤩愊獮㴠∠ਢ潦⁲⁩湩爠湡敧㤨ⰷ㤠⬷⥫਺愉獮⬠‽档⡲⥩਻潦⁲⁩湩爠湡敧〨‬⵮⥫਺椉⡦⁩‥′㴽〠㨩ऊ愉獮⬠‽湡孳崰ऊ汥敳਺उ湡⁳㴫愠獮ㅛ੝牰湩⡴湡⥳','u16')[2:])", "# password is changed for \"Contact!\"\"\n# needs a new one\n# len(res) == n\n# only lowercase letters\n# k distinct symbols\n# two consecutive symbols must be distinct\n\nn, k = list(map(int, input().split(' ')))\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\n\nbucket = alpha[:k]\nres = \"\"\nwhile n - len(bucket) > 0:\n res += bucket\n n -= len(bucket)\n\nres += bucket[:n]\nprint(res)\n", "a = 97\r\nz = 122\r\n\r\nl,d = map(int,input().split())\r\nuc = [chr(i) for i in range(97,123)]\r\nucc = uc[:d]\r\ns = \"\"\r\nfor i in range(100):\r\n x = \"\".join(ucc)\r\n s += x\r\nprint(s[:l])\r\n\r\n", "[n, k] = list(map(int, input().split()))\r\nletters = \"a b c d e f g h i j k l m n o p q r s t u v w x y z\".split(\" \")\r\n\r\nchosen_letter = letters[:k]\r\nnum_each = int(n/k)\r\nremain = n%k \r\n\r\nresult_arr = []\r\nfor i in range(len(chosen_letter)):\r\n amount = num_each\r\n if remain > 0:\r\n amount = num_each + 1\r\n remain -= 1\r\n \r\n result_arr.append([chosen_letter[i]]*amount)\r\n\r\n\r\nstr_output = \"\"\r\nstart_indx = 0\r\nflag = False\r\nwhile True:\r\n for arr in result_arr:\r\n str_output += arr[start_indx]\r\n if len(str_output) >= n:\r\n flag = True\r\n break\r\n start_indx += 1\r\n if flag:\r\n break\r\n\r\nprint(str_output)\r\n\r\n\r\n\r\n", "n, k = map(int, input().split())\r\n\r\nchars = []\r\nj = 97\r\nfor i in range(k):\r\n chars.append(chr(j))\r\n j+=1\r\npwd = ''\r\nfor i in range(n):\r\n pwd+=chars[i%k]\r\n \r\nprint(pwd)", "n, k = [int(i) for i in input().split()]\r\n\r\ndef main(n, k):\r\n letters = 'abcdefghijklmnopqrstuvwxyz'[:k]\r\n password = ''\r\n for i in range(n):\r\n password += letters[i%k]\r\n return password\r\nprint(main(n, k))", "n, k = map(int, input().split())\r\n\r\nfor i in range(n):\r\n print(chr(ord('a') + i % k), end=\"\")", "#!/usr/bin/python3\n\nimport sys\nimport argparse\nimport json\n\ndef main():\n n, k = map(int, sys.stdin.readline().rstrip().split(\" \"))\n\n s = list(\"abcdefghijklmnopqrstuvwxyz\")\n\n result = \"\"\n for i in range(0, n):\n index = i % k\n result += s[index]\n print(result)\n\ndef get_tests():\n #tests = [(\"512 4\", \"50\")]\n\n for test in tests:\n print(json.dumps({\"input\": test[0], \"output\": test[1]}))\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser()\n parser.add_argument(\"--get-tests\", action=\"store_true\")\n args = parser.parse_args()\n\n if args.get_tests:\n get_tests()\n else:\n main()\n", "n,k=[int(i) for i in input().split()]\r\ni=0\r\nfin=\"\"\r\nfor _ in range(n):\r\n fin=fin+chr(i%k+97)\r\n i+=1\r\nprint(fin)", "n,k = [int(x) for x in input(\"\").split()]\r\nstr = \"\"\r\npos = 0\r\nwhile len(str) < n:\r\n if pos == k:\r\n pos = 0\r\n str += chr(97+pos)\r\n pos+=1\r\nprint(str)\r\n", "n,k=map(int,input().split())\r\na=[]\r\nfor i in range(k):\r\n\tx=ord('a')\r\n\ta.append(chr(x+i))\r\nif n>k:\r\n\ti=0\r\n\twhile(len(a)<n):\r\n\t\ta.append(a[i])\r\n\t\ti+=1\r\n\t\tif i==len(a):\r\n\t\t\ti=0\r\nprint(*a,sep='')", "n,k=map(int,input().split())\r\ns=\"abcdefghijklmnopqrstuvwxyz\"\r\ntimes=int(n/k)\r\nprint(s[:k]*times,s[:n%k],sep=\"\")", "x,y = input().split()\r\nx,y = int(x), int(y)\r\nstr1 = str()\r\ni=0\r\nwhile len(str1)<x:\r\n\tif i >= y:\r\n\t\ti=0\r\n\tstr1 += chr(97+i)\r\n\ti+=1\r\nprint(str1)", "Alpha=\"abcdefghijklmnopqrstuvwxyz\"\r\nn,k=map(int,input().split())\r\nN=n//k\r\nR=n%k\r\nAns=\"\"\r\nfor i in range(N):\r\n Ans+=Alpha[:k]\r\nAns+=Alpha[:R]\r\nprint(Ans)", "import string\nn,m = map(int,input().split())\nx = list(string.ascii_lowercase)\nx = x[:m]\nq = 0\npassword = ''\nfor i in range(n):\n\tpassword = password + x[q]\n\tq=q+1\n\tif q==m:\n\t\tq=0\nprint(password)\n \t \t \t \t\t\t\t \t \t\t \t \t \t\t \t\t", "import string\r\n\r\nn, k = (int(x) for x in input().split())\r\n\r\nsymbols = string.ascii_lowercase[0:k]\r\n\r\nif n > k:\r\n symbols *= k*((n // k) + 1)\r\n\r\npwd = symbols[0:n]\r\nprint(pwd)", "import sys\r\nimport math\r\nimport heapq\r\nimport string\r\nfrom collections import defaultdict,Counter,deque\r\n \r\ninput = sys.stdin.readline\r\n \r\ndef I():\r\n return input()\r\n \r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n \r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n \r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n \r\ndef WRITE(out):\r\n return print('\\n'.join(map(str, out)))\r\n \r\ndef WS(out):\r\n return print(' '.join(map(str, out)))\r\n \r\ndef WNS(out):\r\n return print(''.join(map(str, out)))\r\n\r\n'''\r\ncompare max\r\n\r\n4 6 10\r\n8 10 12 14\r\n'''\r\ndef solve():\r\n n, k = MII()\r\n s = string.ascii_lowercase[:k]\r\n rem = n%k\r\n print(s*(n//k) + s[:rem])\r\n\r\n\r\nsolve()", "n, k = map(int, input().split())\na = list(range(k)) + [0, 1] * ((n - k) // 2) + [0] * ((n - k) % 2)\nprint(\"\".join(chr(ord(\"a\") + x) for x in a))\n", "n, k = map(int, input().split())\r\nchar_list = list()\r\nfor i in range(k):\r\n char_list.append(chr(97+i))\r\npassword = ''\r\nflag = 1\r\nwhile True:\r\n for j in range(k):\r\n password += char_list[j]\r\n if len(password) > n:\r\n password = password[:n]\r\n break\r\nprint(password)\r\n", "n,k=map(int,input().split())\r\n\r\n\r\ni,j=0,0\r\nwhile(i<n):\r\n\tif(j<k):\r\n\t\tprint(chr(97+j),end=\"\")\r\n\telse:\r\n\t\tprint(\"a\",end=\"\")\r\n\t\tj=0\r\n\ti+=1\r\n\tj+=1\r\n", "import string\r\nalp = list(string.ascii_lowercase)\r\nn,k= map(int,input().split())\r\nkk = []\r\ns = n//k\r\nt = n%k\r\nwhile s>0:\r\n s-=1\r\n for i in range(k):\r\n kk.append(alp[i])\r\n\r\nif t>0:\r\n kk+=alp[:t]\r\n print(\"\".join(kk))\r\nelse:\r\n print(\"\".join(kk))\r\n\r\n\r\n", "import string\n\nn, k = [int(v) for v in input().split()]\npassword = string.ascii_letters[:k] + \"ab\" * ((n - k) // 2)\nif (n - k) & 1 == 1:\n password += \"a\"\nprint(password)", "a='abcdefghijklmnopqrstuvwxyz'\r\nn,k=map(int,input().split())\r\ns=a[0:k]\r\np=0\r\nfor i in range(n-k):\r\n\tif p%2==0:\r\n\t\ts+='a'\r\n\telse:\r\n\t\ts+='b'\r\n\tp+=1\r\nprint(s)", "n, k = map(int, input().split())\r\nalpha = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',\r\n 'u', 'v', 'w', 'x', 'y', 'z'}\r\nused = set({})\r\npasswd = ''\r\nwhile len(passwd) < n:\r\n if len(used) == k:\r\n for a in used:\r\n if len(passwd) == 0 or passwd[len(passwd) - 1] != a:\r\n passwd += a\r\n break\r\n else:\r\n for a in alpha:\r\n if len(passwd) == 0 or passwd[len(passwd) - 1] != a:\r\n passwd += a\r\n used.add(a)\r\n alpha.remove(a)\r\n break\r\nprint(passwd)", "import random\r\nimport string\r\nalphabet = string.ascii_lowercase\r\nn,k = [int(_) for _ in input().split()]\r\nlettersused= random.sample(alphabet,k)\r\nmystring = \"\".join(lettersused)\r\n\r\nwhile len(mystring) < n:\r\n randomized=random.sample(lettersused,1)\r\n if randomized[0] != mystring[-1]:\r\n mystring +=randomized[0]\r\nprint(mystring)\r\n", "n, k = map(int, input().split())\nresult = \"\"\nfor i in range(n):\n result += chr(ord(\"a\") + (i % k))\nprint(result)\n", "n, k = list(map(int, input().split()))\r\ns = \"\".join([chr(ord('a') + i) for i in range(k)])\r\npassword = s * (n // k) + s[:n % k]\r\nprint(password)\r\n", "s=input().split()\r\n\r\nn=int(s[0])\r\nk=int(s[1])\r\n\r\npassword=''\r\n\r\nl=[]\r\nc='a'\r\nfor i in range(k):\r\n l.append(c)\r\n c=chr(ord(c)+1)\r\n\r\nfor i in range(n):\r\n password+=l[i%k]\r\n\r\nprint(password)\r\n", "import string\r\nn,k=map(int,input().split())\r\nprint((n*string.ascii_lowercase[:k])[:n])", "\r\nnum = list(map(int, input().split()))\r\nletters = \"abcdefghijklmnopqrstuvwxyz\"\r\nstr1 = ''\r\nfor i in range(num[1]):\r\n str1 += letters[i]\r\nres = str1\r\nfor i in range(1, int(num[0] / num[1])):\r\n str1 += res\r\n\r\nif num[0] % num[1] != 0:\r\n for i in range(num[0] % num[1]):\r\n str1 += str1[i]\r\nprint(str1)", "import random\r\nn, k = map(int, input().split())\r\nflag = k\r\ni = 0\r\nsame = n - k\r\nword = []\r\nletter = []\r\n\r\nfor i in range(n):\r\n t = 97 + (i % k)\r\n word.append(chr(t))\r\n \r\ns = \"\".join(word)\r\nprint(s)\r\n \r\n\r\n\r\n# for i in range(ord(\"a\"), ord(\"z\")):\r\n# letter.append(chr(i))\r\n\r\n\r\n# while len(word) != n:\r\n# ran = random.randint(97, 122)\r\n# t = chr(ran)\r\n# if len(word) != 0:\r\n# if t in word and word[i-1] != t and same > 0:\r\n# word.append(t)\r\n# same -= 1\r\n# i += 1\r\n# else:\r\n# if word[i-1] != t and same > 0:\r\n# word.append(t)\r\n# same -= 1\r\n# i += 1\r\n# else:\r\n# word.append(t)\r\n# i += 1\r\n\r\n\r\n# s = ''.join(word)\r\n# print(s)\r\n\r\n\r\n# for i in range(n):\r\n# if len(word) == 0:\r\n# word += letter[ran]\r\n", "from string import ascii_lowercase\nx = ascii_lowercase\nn,a = map(int,input().split())\nx = x[:a]\nans = []\ncounter = 0\nwhile n!= 0:\n if counter == a-1:\n ans.append(x[counter])\n counter = 0\n n-=1\n else:\n ans.append(x[counter]) \n counter+=1\n n-=1\nprint(\"\".join(ans)) \n\n\n", "n, k = map(int, input().split())\r\n\r\n# Generate a string with the first k letters of the alphabet repeated\r\n# ceil(n/k) times, and then truncate it to length n.\r\ns = ('abcdefghijklmnopqrstuvwxyz'[:k] * ((n + k - 1) // k))[:n]\r\n\r\nprint(s)\r\n", "a, b = map(int, input().split())\r\n\r\nall_letters = [chr(ord('a') + i) for i in range(26)]\r\n\r\nfor i in range(0, a):\r\n print(all_letters[i % b], end='')", "import string\r\nimport random\r\nn,k = input().split()\r\ndef random_string_generator(str_size, allowed_chars):\r\n return ''.join(random.sample(allowed_chars,str_size))\r\n \r\nchars = string.ascii_lowercase\r\nsize = int(k)\r\ns = random_string_generator(size, chars)\r\ni = 0\r\nwhile len(s) < int(n): \r\n s = s + s[i] \r\n i += 1 \r\nprint(s)", "a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nn,k=map(int,input().split())\r\npassword=[]\r\nfor i in range(n):\r\n if i<k:\r\n password.append(a[i])\r\n else:\r\n password.append(a[(i-k)%k])\r\nprint(\"\".join(password))\r\n", "import string\r\nimport sys\r\nimport math\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return (int(input()))\r\n\r\n\r\ndef inlt():\r\n return (list(map(int, input().split())))\r\n\r\n\r\ndef insr():\r\n s = input()\r\n return (list(s[:len(s) - 1]))\r\n\r\n\r\ndef invr():\r\n return (map(int, input().split()))\r\n\r\n\r\nlt = inlt()\r\nletters = string.ascii_lowercase[:lt[1]]\r\nans = letters * math.floor(lt[0] / lt[1])\r\nif lt[0] % lt[1] != 0:\r\n ans += letters[:lt[0] % lt[1]]\r\n\r\nprint(ans)\r\n", "n,d=list(map(int,input().split()))\r\na=\"abcdefghijklmnopqrstuvwxyz\"\r\nw=\"\"\r\ni=0\r\nwhile len(w)!=n:\r\n if i==d:\r\n i=0\r\n w+=a[i]\r\n else:\r\n w+=a[i]\r\n i+=1\r\nprint(w)", "n, k = map(int, input().split())\r\ndistinct_symbols = \"abcdefghijklmnopqrstuvwxyz\"[:k]\r\npassword = ''\r\n\r\nfor i in range(n):\r\n password += distinct_symbols[i % k]\r\n\r\nprint(password)\r\n", "alpha = \"abcdefghijklmnopqrstuvwxyz\"\ndetails = input()\ndetails = [int(x) for x in details.split(' ')]\nletters = alpha[:details[1]]\nans = ''\nfor i in range(details[0]):\n ans += letters[i%details[1]]\nprint(ans)", "import string\r\nstrin=string.ascii_lowercase\r\nn,k=list(map(int,input().split()))\r\np=''\r\nfor i in range(k):\r\n p+=strin[i]\r\nt=n-k\r\nst=-1\r\nif t ==1:\r\n p+=p[0]*t \r\n\r\nelse:\r\n while len(p)<n:\r\n if len(p)<n and p[-1]!=p[0]:\r\n p+=strin[0]\r\n elif len(p)<n and p[-1]==p[0]:\r\n p+=strin[1]\r\n\r\nprint(p)", "import string\n\nn , k = map(int,input().split())\nletters = list(string.ascii_lowercase)\nletters_in_password = letters[:k]\npassword = letters_in_password * n\nprint(\"\".join(password[0:n]))\n\n\t \t\t\t\t\t\t \t\t \t \t \t\t\t \t\t\t \t\t \t", "n, k = list(map(int, input().split()))\r\na = 0\r\nfor i in range(n):\r\n print(chr(97 + a), end='')\r\n a += 1\r\n if a == k:\r\n a = 0", "nk = input().strip().split(' ')\nn = int(nk[0])\nk = int(nk[1])\n\nseed = ord('a')\n# end = ord('z')\n\nvocab = ''.join([chr(i) for i in range(seed, seed+k)])\n\nif n<=k:\n print(vocab[:n])\nelse:\n password = ''\n for i in range(n//k+1):\n password += vocab\n print(password[:n])\n \n \n \n\n\n\n \n ", "from sys import stdin\r\nimport string\r\n\r\ndef solution():\r\n n,k = [int(x) for x in stdin.readline().strip().split()]\r\n alpha = string.ascii_lowercase\r\n\r\n i = 0\r\n res = ''\r\n for j in range(0,n):\r\n res += alpha[i]\r\n i = (i+1) % k\r\n\r\n return res\r\n\r\nprint(solution())", "n, k = map(int, input().split())\nabc = \"abcdefghijklmnopqrstuvwxyz\"\ns = abc[:k]\ns1 = s\nwhile len(s1) < n:\n s1 += s\ns1 = s1[:n]\nprint(s1)\n", "import string\r\n\r\nn, k = map(int, input().split())\r\n\r\nletters = string.ascii_lowercase\r\npassword = \"\"\r\nfor i in range(k):\r\n\tpassword += letters[i]\r\ni = 0\r\nwhile len(password) < n:\r\n\tpassword += password[i]\r\n\ti += 1\r\nprint(password)\r\n", "import random\r\nl, d = map(int, input().split(\" \"))\r\na = d\r\nword = \"\"\r\n\r\n'''\r\n start = 97 => \r\n end = 122 => \r\n'''\r\nfor i in range(l):\r\n if a:\r\n # print(chr(a), a)\r\n word += chr(96+a)\r\n a -= 1\r\n else:\r\n n = ord(word[-1])\r\n arr = list(range(97,n)) + list(range(n+1, 97+d))\r\n # print(arr, n)\r\n word += chr(random.choice(arr))\r\nprint(word)", "n, m = list(map(int, input().split()))\r\npassword = ''\r\nalpha = 'abcdefghijklmnopqrstuvwxyz'\r\n\r\ncomp = n/m\r\n\r\nif comp == 1:\r\n for i in range(n):\r\n password += alpha[i]\r\nelse:\r\n for i in range(m):\r\n password += alpha[i]\r\n \r\n for i in range(n-m):\r\n password += password[i]\r\nprint(password)", "n,k=map(int,input().split())\r\na=list(map(chr,range(97,97+k)))\r\ni=0\r\nj=0\r\nb=[]\r\nwhile i<n:\r\n b.append(a[j])\r\n if j==len(a)-1:\r\n j=0\r\n else:\r\n j+=1\r\n i+=1\r\nfor i in b:\r\n print(i,end=\"\")\r\n\r\n", "# 770A\r\nfrom random import randint\r\nalphabet = \"abcdefghijklmnopqrstuvwxyz\"\r\nreq = list(map(int, input().split()))\r\nn = req[0]; k = req[1]\r\npwd = \"\"\r\n\r\nfor i in range(n):\r\n pwd += alphabet[i % k]\r\n\r\nprint(pwd)", "import string\r\n\r\nn, k = [int(x) for x in input().split()]\r\n\r\na = list(string.ascii_lowercase)\r\n\r\nq, r = divmod(n, k)\r\n\r\nret = q * a[:k] + a[:r]\r\n\r\nprint(''.join(ret))", "s = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\na, b = input().split()\r\n\r\nfor i in range(0,int(b)):\r\n print(s[i], end=\"\")\r\n\r\ndiff = int(a)-int(b)\r\nj = 0\r\n\r\nfor i in range(0,diff,1):\r\n print(s[j], end=\"\")\r\n j+=1\r\n\r\n if j == int(b):\r\n j=0\r\n", "import string\r\nn, k = list(map(int, input().split()))\r\n\r\nmyString = \"\"\r\nfor i in string.ascii_letters:\r\n if k < 1: break\r\n myString += i\r\n k -= 1\r\n\r\nfor i in range(n):\r\n print(myString[i%len(myString)], end = '')\r\n", "#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\nn, k = list(map(int, input().split()))\r\nr = [chr(ord('a') + i) for i in range(k)]\r\nres = []\r\nfor i in range(n // k):\r\n res += r\r\nres += r[:(n % k)]\r\nprint(''.join(res))\r\n", "import sys\r\nfrom math import ceil\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\ndef main():\r\n abjad = list(\"abcdefghijklmnopqrstuvwxyz\")\r\n n,k =[int(item) for item in input().split(\" \")]\r\n ans = abjad[0:k]\r\n an = []\r\n count = 0\r\n while(len(an)<n):\r\n an.append(ans[count])\r\n count+=1\r\n if(count>=k):\r\n count=0\r\n print(\"\".join(an))\r\n\r\nif __name__ == '__main__':\r\n main()", "import string\r\ny=list(string.ascii_lowercase)\r\ndef password(n,k):\r\n\tpasswordop=\"\"\r\n\t# for i in range(k):\r\n\t# \tpasswordop+=y[i]\r\n\r\n\t\r\n\tj=0\r\n\twhile (n-j*k)>0:\r\n\t\tfor i in range(min(k,n-j*k)):\r\n\t\t\tpasswordop+=y[i]\r\n\r\n\t\tj+=1\r\n\r\n\r\n\tprint(passwordop)\r\n\treturn\r\n\r\n\r\n\r\nn,k=map(int,input().split())\r\npassword(n,k)\r\n", "charecter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\ns = \"\"\r\nn, k = input().split()\r\n\r\ncharecter = charecter[:int(k)]\r\n\r\ncharecter = charecter * 100;\r\n\r\n#print(charecter)\r\n \r\nfor i in range(int(n)):\r\n s += charecter[i]\r\n\r\n\r\n#print(len(charecter))\r\nprint(s)", "n, k = input().split()\r\nn = int(n)\r\nk = int(k)\r\nlowercase_alphabet = \"abcdefghijklmnopqrstuvwxyz\"\r\npassword = \"\"\r\nfor i in range(k):\r\n password += lowercase_alphabet[i]\r\n i = 0\r\nwhile len(password) < n:\r\n if i >= k:\r\n i = 0\r\n password += lowercase_alphabet[i]\r\n i += 1\r\nprint(password)\r\n", "import random\r\nimport string\r\nimport math\r\n\r\nn ,k = map(int, input().split()) \r\ns = string.ascii_letters\r\nh = \"\"\r\nfor j in range(k):\r\n h = h + s[j]\r\nm = n/k\r\nm = math.ceil(m)\r\na = h * m\r\nc = \"\"\r\nfor i in range(n):\r\n c = c + a[i]\r\nprint(c)", "n, k = list(map(int, input().split()))\nans = \"\"\nfor i in range(n):\n i %= k\n ans += chr(ord(\"a\")+i)\nprint(ans)", "n,k=map(int,input().split())\r\ns=\"qwertyuiopasdfghjklzxcvbnm\";an=\"\"\r\ni=0\r\nwhile len(an)<n:\r\n an+=s[i%k]\r\n i+=1\r\nprint(an)", "n,k = map(int,input().split())\r\ns = \"qwertyuiopasdfghjklzxcvbnm\"\r\nif n==k:\r\n print(s[0:n])\r\nelse:\r\n z = n//k\r\n x = n%k\r\n print(s[0:k]*z+s[0:x])", "n,k=map(int,input().split())\r\na='abcdefghijklmnopqrstuvwxyz'\r\npassword=''\r\nfor i in range(k):\r\n password=password+a[i]\r\nb=n-len(password)\r\nc=''\r\nc=c+password*b\r\nfor i in range(b):\r\n \r\n password=password+c[i]\r\nprint(password)\r\n \r\n", "n, m = map(int, input().split())\r\nbase = ''\r\nstart = 97\r\nfor i in range(m):\r\n base += chr(start)\r\n start += 1\r\ndiff = n - len(base)\r\nif diff == 0:\r\n print(base)\r\nelse:\r\n use = diff // len(base)\r\n base += base * use\r\n final = n - len(base)\r\n for i in range(final):\r\n base += base[i]\r\n print(base)", "n, k = map(int, input().split())\r\na = \"\"\r\nfor i in range(97,97+k):\r\n a += chr(i)\r\nsol = a*(n//k) + a[:n%k]\r\nprint(sol)", "n,k=map(int,input().split())\r\nalpha='abcdefghijklmnopqrstuvwxyz'\r\nprint((alpha[:k]*n)[:n])", "import string\r\nimport random\r\n\r\nil = list(map(int, input().split()))\r\nn = il[0]\r\nd = il[1]\r\nalphal = list(string.ascii_lowercase)\r\na1 = alphal[0:d]\r\nstr1 = []\r\ndL = []\r\n\r\nfor i in range(n):\r\n if(i == 0):\r\n str1.append(a1[i])\r\n dL.append(a1[i])\r\n else:\r\n x = random.randint(0,d-1)\r\n if(len(dL) != d):\r\n while(a1[x] == str1[i-1] or a1[x] in dL):\r\n x = random.randint(0,d-1)\r\n str1.append(a1[x])\r\n dL.append(a1[x])\r\n else:\r\n while(a1[x] == str1[i-1]):\r\n x = random.randint(0,d-1)\r\n str1.append(a1[x])\r\n\r\nprint(\"\".join(str1))", "n,k = map(int, input().split())\r\na = \"\"\r\ns = \"abcdefghijklmnopqrstuvwxyz\"\r\nfor i in range(n):\r\n a = a + s[i%k]\r\n i = i + 1\r\nprint(a)", "a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\n\r\nx,y = input().split()\r\n\r\nn=int(x)\r\nm=int(y)\r\n\r\nstring = ''\r\nif n==m:\r\n for i in range(0,n):\r\n string=string + a[i]\r\nelse:\r\n rounds=int(n/m)\r\n rounds2=n%m\r\n for i in range(0,rounds):\r\n for j in range(0,m):\r\n string=string + a[j]\r\n for i in range(0,rounds2):\r\n string=string + a[i]\r\n \r\nprint(string)", "import sys\r\nfrom collections import Counter, deque\r\n\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\n\r\ndef solve():\r\n n, m = map(int, input().split())\r\n ans = \"\"\r\n for i in range(n):\r\n ans = ans + chr(ord('a') + (i%m))\r\n print(ans)\r\n\r\nif __name__ == \"__main__\":\r\n t = 1\r\n # t = int(input())\r\n for _ in range(t):\r\n solve()\r\n", "x=[int(x) for x in input().split()]\r\nn=x[0]\r\nk=x[1]\r\npas=''\r\nc=97\r\nfor i in range(k):\r\n pas=pas+chr(c)\r\n c+=1\r\ny=len(pas)//2\r\nx=pas[len(pas)//2] \r\nfor j in range(n-k):\r\n first=pas[0]\r\n last=pas[-1]\r\n if x!=first:\r\n pas=x+pas\r\n elif x!=last:\r\n pas+=x\r\n else:\r\n x=pas[1]\r\n pas+=x\r\nprint(pas) ", "n, k = map(int, input().split())\r\ndistinct_chars = \"\".join(chr(i+ord('a')) for i in range(k))\r\npassword = \"\".join(distinct_chars[i%k] for i in range(n))\r\nprint(password)\r\n", "# http://codeforces.com/contest/770/problem/A\r\n\r\nimport string\r\n\r\nn, k = list(map(int, input().split()))\r\n\r\ns = string.ascii_lowercase[:k]\r\n\r\nfor i in range(n):\r\n print(s[i % k], end=\"\")", "a,b = map(int,input().split())\r\nch=''\r\nk = [chr(97 + x) for x in range(0,b) ]\r\nfor i in range(a):\r\n ch+=''.join(k[i%b])\r\nprint(ch) ", "from string import ascii_lowercase\nimport random\nn, k = [int(v) for v in input().split()]\nprint(''.join(ascii_lowercase[:k]*(n//k+1))[:n])\n", "from string import ascii_lowercase\nn, k = map(int, input().split())\nprint(\"\".join([ascii_lowercase[c%k] for c in range(n)]))\n", "n,d=map(int,input().split())\r\nl=[]\r\nfor i in range(d):\r\n l.append(chr(97+i))\r\nfor i in range(n-d):\r\n l.append(l[i])\r\nprint(\"\".join(l))", "import string\r\n\r\nn, k = (int(x) for x in input().split())\r\n\r\nsymbols = string.ascii_lowercase[0:k]\r\n\r\npwd = [symbols[i%len(symbols)] for i in range(n)]\r\nprint(*pwd, sep='')", "n,k = map(int,input().split())\r\ns =''\r\ni = 0\r\nwhile len(s)!=n:\r\n s+=chr(97+i)\r\n i+=1\r\n if i==k:\r\n i= 0\r\nprint(s)", "from collections import Counter,defaultdict,deque\r\n#import heapq as hq\r\n#from itertools import count, islice\r\n#from functools import reduce\r\nalph = 'abcdefghijklmnopqrstuvwxyz'\r\n#from math import factorial as fact\r\n#a,b = [int(x) for x in input().split()]\r\nimport math\r\nimport sys\r\n\r\ninput=sys.stdin.readline\r\nn,k = [int(x) for x in input().split()]\r\ns = alph[:k]*100\r\nprint(s[:n])\r\n", "s=''\r\nfor i in range(26):\r\n s+=chr(ord('a')+i)\r\na,b=map(int,input().split())\r\nprint((s[:b])*(a//b)+s[:a%b])\r\n", "n,k=map(int,input().split())\r\nres=\"\"\r\nif n==k:\r\n for _ in range(97, 97 + k):\r\n res+=chr(_)\r\nelse:\r\n while(n>k):\r\n for idx in range(97, 97 + k):\r\n res = res + chr(idx)\r\n n-=k\r\n if n<k:\r\n k=n\r\n res+=res[:n]\r\nprint(res)", "n,k=map(int,input().split())\r\nalph=\"abcdefghijklmnopqrstuvwxyz\"\r\npassoword=(alph[:k]*int(n/k))+alph[:n-(k*int(n/k))]\r\nprint(passoword)", "n , k = [int(c) for c in input().split()]\nlst = []\nfor i in range(ord('a'), ord('a')+k+1) :\n lst.append(chr(i))\nfor i in range(n):\n print(lst[i%k], end='')\n\t \t\t \t \t \t\t\t \t\t\t\t\t \t\t \t \t", "ans=\"\"\r\nlow=\"abcdefghijklmnopqwxyzrstuv\"\r\nn,k=list(map(int,input().split()))\r\nfor i in range(n):\r\n j=i%k\r\n ans+=low[j]\r\nprint(ans)", "n,k=map(int,input().split())\r\ns='abcdefghijklmnopqrstuvwxyz'\r\nx=n//k\r\ny=n%k\r\nr=s[:k]*x\r\nr=r+s[:y]\r\nprint(r)\r\n", "import string\r\nimport random\r\nn, k = map(int, input().split())\r\ns=[]\r\nfor i in range(0,k):\r\n lower = string.ascii_lowercase\r\n s.append(lower[i])\r\nj=0\r\nfor i in range(0,n-k):\r\n s.append(s[j])\r\n j=j+1\r\ns1=''.join(s)\r\nprint(s1)", "n,k=map(int,input().split())\r\nalphabet = list(map(chr, range(97, 123))) \r\nans=\"\"\r\ni=0\r\nwhile len(ans)<n:\r\n ans+=alphabet[i]\r\n if i+1==k or i==26:\r\n i=0\r\n else:\r\n i+=1\r\nprint(ans) \r\n", "n, k = map(int, input().split())\nli = 'abcdefghijklmnopqrstuvwxyz'\nps = ''\ni = 0\nwhile n > 0:\n ps += li[i]\n i += 1\n n -= 1\n if i == k:\n i = 0\n\nprint(ps)\n\t\t\t\t \t\t \t \t \t\t\t \t\t\t \t\t", "from math import floor , sqrt\r\nfrom sys import stdin\r\n\r\n# input = stdin.readline\r\n\r\nfor _ in range(1):\r\n\r\n n, k = map(int , input().split())\r\n password = \"\"\r\n j = 0\r\n for i in range(n):\r\n password = password + chr(97 + j%(k))\r\n j += 1\r\n \r\n print(password)", "n,k=map(int,input().split())\r\na='abcdefghijklmnopqrstuvwxyz'\r\ns=(a[:k])*(n//k)+(a[:n%k])\r\nprint(s)\r\n", "import string \r\nimport random\r\nresult = string.ascii_lowercase\r\nans = ''\r\nn,k = map(int,input().split())\r\nfor i in range(n):\r\n ans+=result[i%k]\r\n \r\nprint(ans)", "from random import *\r\nn,k=map(int,input(\"\").split())\r\nt=[]\r\nfor i in range (0,26):\r\n t.append(chr(i+97))\r\n\r\n\r\n\r\nans=\"\"\r\n\r\nwhile len(ans)<n : \r\n for b in range (0,k):\r\n \r\n ans+=t[b]\r\n if len(ans)==n :\r\n\r\n break\r\n\r\n\r\n \r\n\r\n\r\nprint(ans)\r\n", "a='abcdefghijklmnopqrstuvwxyz'\r\nn,k=map(int,input().split())\r\nu=''\r\nfor i in range(k):\r\n u+=a[i]\r\nwhile len(u)<n:\r\n u+=u\r\nwhile len(u)!=n:\r\n u=u[0:len(u)-1]\r\nprint(u)\r\n \r\n", "n,k = map(int,input().split())\r\nimport string\r\nabc = string.ascii_lowercase\r\nnewpass = ''\r\nals = abc[:k]\r\n\r\nfor i in range(n):\r\n if len(newpass) > n:\r\n newpass = newpass[:len(newpass)-(len(newpass)-n)]\r\n print(newpass)\r\n break\r\n newpass += als\r\nif n == 2 and k == n:\r\n print('ab')\r\nelif n == 1:\r\n print('a')\r\n", "\r\nn , k = map(int, input().split())\r\ns = \"\"\r\n\r\nfor i in range (k) :\r\n s+= chr(97+i)\r\n\r\nwhile(len(s) < n) :\r\n s += s\r\n\r\nprint(s[0:n])", "n,k=map(int,input().split())\r\na=''.join([chr(97+i) for i in range(k)])\r\nprint(a*(n//k)+a[:n%k])", "n, k = map(int, input().split())\r\nref = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\npassw = ''\r\ntemp = ''\r\nif n==k:\r\n\r\n for i in range(n):\r\n passw += ref[i]\r\n print(passw)\r\nelse:\r\n for j in range(k):\r\n temp += ref[j]\r\n for k in range((n//k)+1):\r\n passw += temp\r\n print(passw[0:n])", "import string\r\nstrin=string.ascii_lowercase\r\nn,k=list(map(int,input().split()))\r\np=''\r\nfor i in range(k):\r\n p+=strin[i]\r\n\r\nwhile len(p)<n:\r\n if len(p)<n and p[-1]!=p[0]:\r\n p+=strin[0]\r\n elif len(p)<n and p[-1]==p[0]:\r\n p+=strin[1]\r\n\r\nprint(p)", "inputs = list(map(int,input().split()))\n\ncharacters = [chr(i) for i in range(97,123)]\n\nn = inputs[0]\nk = inputs[1]\n\nfor i in range(0,n):\n\tprint(characters[i % k],end=\"\")\n\nprint()\n", "import string\r\nn,k=list(map(int,input().split()))\r\ns1=string.ascii_lowercase\r\nb=\"\"\r\nfor x in range(k):\r\n b+=s1[x]\r\nb=b*n\r\nprint(b[0:n])", "alp= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\n\r\nx = input().split()\r\n\r\na = int(x[0])\r\nb = int(x[1])\r\n\r\ns=\"\"\r\nfor i in range(b):\r\n s=s+alp[i]\r\n\r\ny = len(s)\r\nd = int(a/y)*s\r\nr = len(d)\r\n\r\nj = a-r\r\nif a%y==0:\r\n print((a//y)*s)\r\nelse:\r\n e = int(a/y)*s+s[0:j]\r\n print(e)", "n, k = map(int, input().split())\r\n\r\ni = 0\r\nalph = 'abcdefghijklmnopqrstuvwxyz'\r\nans = \"\"\r\n\r\nfor j in range(n):\r\n ans += alph[i]\r\n i += 1\r\n i %= k\r\n \r\nprint(ans)", "from string import ascii_lowercase\r\n\r\nn, k = map(int, input().split())\r\na = ascii_lowercase[:k]\r\nret = list(a)\r\nfor i in range(k, n):\r\n for ch in a:\r\n if ch != ret[-1]:\r\n ret.append(ch)\r\n break\r\nprint(''.join(ret))", "import string; \r\nimport random; \r\nn, k = map(int, input().split()); \r\npassword = []; \r\nfor i in range(k):\r\n char1 = random.choice(string.ascii_lowercase);\r\n while char1 in password:\r\n char1 = random.choice(string.ascii_lowercase);\r\n password.append(char1);\r\nj = 0;\r\nfor i in range(n - k):\r\n password.append(password[j]);\r\n j += 1; \r\nprint(''.join(str(x) for x in password));\r\n \r\n ", "import string\r\n\r\nn,k=map(int,input().split())\r\ns= (n*string.ascii_lowercase[:k])[:n]\r\nprint(s)\r\n", "import string, random\nalpha = string.ascii_lowercase\npassword_letters = []\npassword = \"\"\nx = input().split(\" \")\n\nwhile len(password_letters) < int(x[1]):\n letter = random.choice(alpha)\n if letter not in password_letters:\n password_letters.append(letter)\n\nfor k in password_letters:\n password = password + k\n\nwhile len(password) < int(x[0]):\n password_letter = random.choice(password_letters)\n if password[len(password) - 1] != password_letter:\n password = password + password_letter\n\nprint(password)\n \t \t\t\t\t \t \t \t \t \t \t \t \t \t", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Jul 23 14:21:21 2022\r\n\r\n@author: Conor\r\n\r\nCFSheet A Problem 29 - CF770-DIV2A\r\n\"\"\"\r\n\r\nnewLetter = 97\r\nsize, numDist = map(int,input().split())\r\npword = [\" \"]*size\r\nfor i in range(numDist):\r\n pword[i] = chr(newLetter)\r\n newLetter += 1\r\nfor i in range(numDist, size):\r\n pword[i] = chr(97 + (i-numDist)%2)\r\n\r\nprint(\"\".join(pword))", "arr = []\r\nx = list(map(int, input().split()))\r\ni = 97\r\nwhile i < min(x[1]+97,123):\r\n result = chr(i)\r\n arr.append(result)\r\n i+=1\r\nfor i in range(x[0]):\r\n if(i+1 > len(arr)):\r\n print(arr[i % len(arr)],end='')\r\n else:\r\n print(arr[i],end='')", "m,n = map(int,input().split())\r\na = \"abcdefghijklmnopqrstuvwxyz\"\r\ns = a[0:n]*(m//n)\r\ns +=a[0:m%n]\r\nprint(s)", "import bisect\r\nimport collections\r\nimport copy\r\nimport functools\r\nimport heapq\r\nimport itertools\r\nimport math\r\nimport random\r\nimport re\r\nimport sys\r\nimport time\r\nimport string\r\nfrom typing import List\r\nsys.setrecursionlimit(99999)\r\n\r\n\r\nn,k = map(int,input().split())\r\n\r\nans = \"\"\r\nwhile len(ans)<n:\r\n ans+= string.ascii_lowercase[:k]\r\nprint(ans[:n])", "n = list(map(int , input() . split()))\r\nl = []\r\nfor i in range(n[0]):\r\n l.append(chr(97+(i%n[1])))\r\n\r\nprint(\"\".join(l))\r\n", "a, b = map(int, input().split())\r\nalpha = [chr(i + 97) for i in range(b)]\r\n\r\nc = 0 \r\nfor i in range(a):\r\n if c == b:\r\n c = 0\r\n print(alpha[c], end='')\r\n c += 1\r\n", "#53\nl, a = input().split()\nl = int(l)\nalpha = int(a)\nstrt = ord('a')\npassword = ''\nfor i in range(l):\n\tif alpha >= l:\n\t\t password += chr(strt + i)\n\telse:\n\t\tpassword += chr(strt + (i % alpha))\nprint(password)\n\n#2000000000000000000 26", "def generate_password(n, k):\r\n password = \"\"\r\n for i in range(n):\r\n password += chr(97 + (i % k))\r\n return password\r\n\r\ndef main():\r\n n, k = map(int, input().split())\r\n password = generate_password(n, k)\r\n print(password)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n\r\n# See PyCharm help at https://www.jetbrains.com/help/pycharm/\r\n", "n, k = map(int, input().split())\r\nletter = 0\r\nfor i in range(n):\r\n print(chr(ord('a') + letter), end='')\r\n letter += 1\r\n if letter == k:\r\n letter = 0", "a,b = map(int,input().split())\r\nd = 'abcdefghijklmnopqrstuvwxyz'[:b]\r\np =''\r\nfor i in range(a):\r\n p += d[i % b]\r\nprint(p)\r\n\r\n\r\n", "n, k = list(map(int, input().split()))\r\na = \"abcdefghijklmnopqrstuvwxyz\"\r\ni = 0\r\no = ''\r\nif k == n:\r\n for i in range(n):\r\n print(a[i], end='')\r\nelse:\r\n while True:\r\n o += a[i]\r\n i += 1\r\n if i == k:\r\n i = 0\r\n\r\n if len(o) == n:\r\n break\r\nprint(o)\r\n", "import random\r\nd = [int(d) for d in input().split()]\r\na = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\ns = []\r\nword = ''\r\nwhile len(word) != d[0]:\r\n x = random.randint(0, 25)\r\n if a[x] not in s and len(s) < d[1]:\r\n s.append(a[x])\r\n word += a[x]\r\n elif len(s) == d[1]:\r\n c = random.choice(s)\r\n if c != word[-1]:\r\n word += c\r\n # else:\r\n # while c == word[:-1]:\r\n # c = random.choice(s)\r\n # word += c\r\nprint(word)\r\n", "s = ''\r\nn, k = map(int, input().split())\r\nfor i in range(k):\r\n s += chr(97+i)\r\nremain_length = n - len(s)\r\nif remain_length > 0:\r\n s += (s*(remain_length//len(s)))\r\nadd_length = n - len(s)\r\nif add_length > 0:\r\n s += s[:add_length]\r\nprint(s)", "n,b = map(int,input().split())\r\nchar = 97\r\nfor j in range(n):\r\n print(chr(char+j%b),end='')\r\nprint()", "a,b=input().split()\na=int(a);b=int(b)\nhij=\"\"\nj=0\nfirst_char = ord ('a')\nfor i in range (a):\n hij+= chr(first_char+j)\n j+=1\n if j == b :\n j=0\nprint(hij)\n\n\t \t \t\t\t \t\t \t \t\t \t\t\t", "import string\r\n\r\nn, k = map(int, input().split())\r\ns = string.ascii_lowercase\r\nword = ''\r\nfor i in range(k):\r\n word += s[i]\r\nfor i in range(n - k):\r\n if i % 2 == 0:\r\n word += 'a'\r\n else:\r\n word += 'b'\r\nprint(word)", "n, k = map(int, input().split())\r\nprint(('abcdefghijklmnopqrstuvwxyz'[:k]*n)[:n])", "import math\r\n\r\nn,k=map(int,input().split())\r\n\r\nal='abcdefghijklmnopqrstuvwxyz'\r\n\r\nword=al[:k]\r\n\r\nm=math.ceil(n/k)\r\n\r\npwd=word*m\r\n\r\nprint(pwd[:n])", "\r\nstring = input()\r\nn =int(string.split(\" \")[0])\r\nk=int(string.split(\" \")[1])\r\nres=''\r\npossible=[]\r\nfirst_letter='a'\r\nfor i in range(k):\r\n possible.append(first_letter)\r\n first_letter=chr(ord(first_letter)+1)\r\n\r\nfor i in range(n):\r\n res=res+str(possible[i%len(possible)])\r\n\r\nprint(res)", "import string\r\nalphabets = string.ascii_lowercase\r\nn, k = map(int, input().split())\r\ntemp = alphabets[:k]\r\nwhile True:\r\n if len(temp) >= n:\r\n break\r\n temp += temp\r\nprint(temp[:n])", "n, k = map(int, input().split())\r\n\r\n\r\npassword = ''\r\nfor i in range(n):\r\n symbol = chr(ord('a') + (i % k))\r\n\r\n password += symbol\r\n\r\nprint(password)", "n, k = map(int, input().split())\r\nlst = [chr(x) for x in range(97, 97 + k)]\r\nwhile n > 0:\r\n for x in lst:\r\n print(x, end = \"\")\r\n n -= 1\r\n if n == 0: break", "\r\narr = input().split(' ')\r\nn = int(arr[0])\r\nk = int(arr[1])\r\ns=''\r\ni=0\r\nwhile n:\r\n n-=1\r\n s+= chr(97+i)\r\n i+=1\r\n if(i==k):\r\n i=0 \r\nprint(s)\r\n", "x,n=map(int,input().split())\r\nz=\"abcdefghijklmnopqrstuvwxyz\"\r\nc=\"\"\r\nfor i in range(n):\r\n c+=z[i]\r\nv=x-len(c)\r\nif v==0:\r\n print(c)\r\nelse:\r\n for i in range(v):\r\n c+=c[i]\r\n print(c)", "ans='abcdefghijklmnopqrstuvwxyz' \r\n \r\nn,k=map(int,input().split()) \r\n\r\nans=ans[:k] \r\n\r\nans=ans*(n//k)\r\n\r\nrem=n%k \r\nans+=ans[0:rem]\r\nprint(ans)\r\n", "\n\n\n\n\nn, k = map(int, input().split())\n\n\n\n\nchars = \"abcdefghijklmnopqrstuvwxyz\"\nusedc = [*chars[:k]]\n\nc = 0\nwhile len(usedc) < n :\n usedc.append(chars[c % k])\n c += 1\n \n\n\nswap = True\n\nwhile swap :\n swap = False\n for i in range(len(usedc) - 2) :\n if usedc[i] == usedc[i + 1] :\n usedc[i + 2], usedc[i + 1] = usedc[i + 1], usedc[i + 2]\n swap = True\n\nprint(\"\".join(usedc))\n \n \n\n\n\n\n \t\t \t \t\t\t \t \t \t\t \t \t\t\t \t", "n,k = map(int,input().split())\r\n\r\nalphabet= \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nrep=''\r\n\r\nseq = alphabet[:k]\r\n\r\nfor i in range(n):\r\n rep+=seq[i%k]\r\n\r\nprint(rep)", "import sys\r\n\r\ndef main():\r\n n,k = map(int,sys.stdin.readline().split())\r\n password = \"\"\r\n for i in range(k):\r\n c = chr(97+i)\r\n password += c\r\n if n>k :\r\n i = 0\r\n while i<n-k :\r\n j = i\r\n password += password[j]\r\n if j == len(password) :\r\n j == 0\r\n i+=1 \r\n sys.stdout.write(password) \r\nmain() ", "import math\r\ns = \"abcdefghijklmnopqrstuvwxyz\"\r\n[n, k] = list(map(int,input().split(\" \")))\r\nprint((s[:k]*math.ceil(n/k))[:n])\r\n \r\n \r\n \r\n\r\n\r\n \r\n", "n,k = map(int, input().split(\" \"))\r\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\r\nalpha = alpha[:k]\r\npwd = \"\"\r\nj = 0\r\nfor i in range(n):\r\n if j == k:\r\n j = 0\r\n pwd += alpha[j]\r\n j += 1\r\nprint(pwd)", "n, k = map(int, input().split())\r\na = [chr(x) for x in range(ord('a'), ord('z') + 1)]\r\nres = (a[:k] * (n // k + 1))[:n]\r\nprint(''.join(res))", "n, k = map(int, input().split())\r\nwords = [chr(i) for i in range(97, 97 + k)]\r\npwd = ''.join(words)\r\npwd = pwd * n\r\nprint(pwd[:n])\r\n", "n, k = list(map(int,input().split()))\r\n\r\nletters = \"abcdefghijklmnopqrstuvwxyz\"\r\nloop = letters[:k]\r\nnumLoops = n // k\r\nnumExtra = n % k\r\n\r\nprint(loop*numLoops, end=\"\")\r\nprint(loop[:numExtra]) ", "n,k = map(int,input().split())\r\n\r\nalpha = [chr(ord('a')+i) for i in range(k)]\r\n\r\nres = \"\"\r\ni = 0\r\nwhile n:\r\n if len(res)==0 or alpha[i] != res[-1]: \r\n res+=alpha[i] \r\n n-=1\r\n \r\n i = (i+1)%k\r\n \r\n \r\nprint(res)\r\n ", "n,k = input().split()\r\nn= int(n)\r\nk = int(k)\r\ns=''\r\na = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L','M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\r\nfor i in range(k):\r\n s+=a[i].lower()\r\nfor i in range(n-k):\r\n for l in range(k):\r\n if s[l] != s[-1]:\r\n s+=s[l].lower()\r\n break\r\nprint(s)", "# -*- coding: utf-8 -*-\n\"\"\"A.new password\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1ccSSWJPdktkWCKEXPtvB9d1PclYxVraJ\n\"\"\"\n\nn,k = input().split()\nna= int(n)\nka= int(k)\n\na = \"abcdefghijklmnopqrstuvwxyz\"\nb = \"\"\n \nfor i in range(na):\n b = b + a[i%ka]\nprint(b)\n\n", "n , k = map(int,input().split())\r\noutput = \"\"\r\n\r\nif n == k:\r\n for i in range(97,97+k):\r\n output = output + chr(i)\r\nelse:\r\n while True:\r\n for i in range(97,97+k):\r\n output = output + chr(i)\r\n if len(output) == n:\r\n break\r\n \r\n if len(output) == n:\r\n break\r\n\r\nprint(output)", "from string import ascii_lowercase\r\nn,k=str(input()).split()\r\nn=int(n)\r\nk=int(k)\r\nc=0\r\nif n<k:\r\n print(ascii_lowercase[0:n])\r\nr=n%k\r\nrep=n//k\r\ns=ascii_lowercase[0:k]\r\nus=rep*s\r\nmus=us+ascii_lowercase[0:r]\r\nprint(mus)\r\n", "def new_pasword():\r\n base_arr = \"abcdefghijklmnopqrstuvwxyz\"\r\n word = \"\"\r\n\r\n size, distinct = map(int, input().split())\r\n\r\n arr = base_arr[0:distinct]\r\n aux = 0\r\n\r\n for i in range(size):\r\n if i % distinct == 0 and i > 1:\r\n aux -= distinct\r\n\r\n word += arr[i + aux]\r\n\r\n\r\n print(word)\r\n\r\nnew_pasword()", "n,k = map(int, input().split())\r\nans = \"\"\r\nfor i in range(n):\r\n ans += chr((i%k)+ord('a'))\r\nprint(ans)\r\n", "def solve(n, k):\r\n alf = 'abcdefghijklmnopqrstuvwxyz'\r\n slov = alf[:k]\r\n for i in range(n-k):\r\n slov+=slov[i]\r\n return slov\r\n \r\n \r\n \r\nn, k = map(int, input().split())\r\nprint(solve(n, k))", "if __name__ == '__main__':\r\n line = input()\r\n\r\n n, k = line.split()\r\n \r\n n = int(n)\r\n k = int(k)\r\n \r\n x = []\r\n i = 0\r\n while i < k:\r\n x.append(chr(ord('a') + i))\r\n i += 1\r\n\r\n y = []\r\n c = 0\r\n for i in range(n):\r\n y.append(x[c])\r\n c += 1\r\n c = c % k\r\n v = ''.join(y)\r\n print(v)\r\n\r\n", "n,k=input().split()\r\nn=int(n)\r\nk=int(k)\r\nl=[]\r\ni=0\r\nflag=0\r\nwhile True:\r\n for j in range(1,k+1):\r\n l.append(chr(j+96))\r\n i+=1\r\n if i==n:\r\n flag=0\r\n break\r\n else:\r\n flag=1\r\n if flag==0:\r\n break\r\nprint(\"\".join(l))", "alpha = 'abcdefghijklmnopqrstuvwxyz'\r\nn = [int(x) for x in input().split()]\r\ncounter = 1\r\npassword = ''\r\n\r\nfor i in range(n[0]):\r\n if counter <= n[1]:\r\n password += alpha[i]\r\n counter += 1\r\n else:\r\n for e in range(abs(n[0]-i)):\r\n password += password[e]\r\n break\r\nprint(password)", "n=\"ansqwertyuiopdfghjklzxcvbm\"\r\na,b=map(int,input().split())\r\nabc=\"\"\r\nfor i in range(b):\r\n abc+=n[i]\r\ncc=abc*int(a)\r\nprint(cc[0:a])", "\"\"\"609C\"\"\"\r\ndef main():\r\n\tn,k = map(int,input().split())\r\n\tres = ''\r\n\tfor i in range(min(k,n)):\r\n\t\tres += chr(ord('a')+i)\r\n\tfor i in range(k,n):\r\n\t\tres += res[i-k]\r\n\tprint(res)\r\nmain() ", "alphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nn, k = map(int, input().split())\r\nq, r = divmod(n, k)\r\npassword = alphabet[:k] * q + alphabet[:r]\r\nprint(password)", "import random\r\nimport string\r\n\r\nn, k = map(int, input().split())\r\npass_ = random.sample(list(string.ascii_lowercase), k)\r\nfor i in range(n-k):\r\n if n > k:\r\n pass_.append(pass_[i])\r\n continue\r\n if n == k:\r\n break\r\nfor letter in pass_:\r\n print(''.join(letter), end='')\r\n", "n, k = input().split()\r\nn = int(n)\r\nk = int(k)\r\npassword = \"\"\r\nfor i in range(n):\r\n password += chr(97 + i%k)\r\nprint(password)\r\n", "n,k =map(int,input().split())\r\nprint((('abcdefghijklmnopqrstuvwxyz')[:k]*n)[:n])", "n, k = map(int, input().split())\r\n \r\nprint(('abcdefjhigklmnopqrstuvwxyz'[:k] * n)[:n])", "from string import ascii_lowercase as s\r\nn,k=map(int,input().split())\r\nm=s[:k]\r\nfor i in range(n-k):\r\n if m[-1]==\"a\":\r\n m+=\"b\"\r\n else:\r\n m+=\"a\"\r\nprint(m)\r\n", "from string import ascii_lowercase as eng_letters_lowercase\r\n\r\nn, k = (int(x) for x in input().split())\r\npassword = ''\r\nidx = 0\r\nfor i in range(n):\r\n if idx == k:\r\n idx = 0\r\n\r\n password += eng_letters_lowercase[idx]\r\n idx += 1\r\nprint(password)\r\n", "import operator as op\r\nimport re\r\nimport sys\r\nfrom bisect import bisect, bisect_left, insort, insort_left\r\nfrom collections import Counter, defaultdict, deque\r\nfrom copy import deepcopy\r\nfrom decimal import Decimal\r\nfrom functools import reduce\r\nfrom itertools import (\r\n accumulate, combinations, combinations_with_replacement, groupby,\r\n permutations, product)\r\nfrom math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,\r\n log2, pi, radians, sin, sqrt, tan)\r\nfrom operator import itemgetter, mul\r\nfrom string import ascii_lowercase, ascii_uppercase, digits\r\n\r\n\r\ndef inp():\r\n return(int(input()))\r\n\r\n\r\ndef inlist():\r\n return(list(map(int, input().split())))\r\n\r\n\r\ndef instr():\r\n s = input()\r\n return(list(s[:len(s)]))\r\n\r\n\r\ndef invr():\r\n return(map(int, input().split()))\r\n\r\n\r\ndef def_value():\r\n return []\r\n\r\n\r\nn, k = invr()\r\ntemp = \"\"\r\nfor i in range(k):\r\n temp += chr(i + ord('a'))\r\nmul = (n // k)+1\r\nres = temp * mul\r\nprint(res[:n])\r\n", "import string\r\n\r\nalphabet = list(string.ascii_lowercase)\r\nnew_password = ''\r\nindex = 0\r\nn, k = [int(x) for x in input().split()]\r\nfor i in range(n):\r\n if i <= (k-1):\r\n new_password += alphabet[i]\r\n else :\r\n new_password += alphabet[index]\r\n if index < k-1:\r\n index += 1\r\n else:\r\n index = 0\r\nprint(new_password)", "import random\r\n\r\nn, k = map(int, input().strip().split())\r\n\r\nletters = []\r\nletters.append(random.randint(97, 122))\r\n\r\nwhile (len(letters) < k):\r\n char = random.randint(97, 122)\r\n if not(char in letters):\r\n letters.append(char)\r\n\r\npassword = \"\"\r\ni = 0\r\n\r\nwhile(len(password) < n):\r\n if i >= k:\r\n i = 0\r\n password += chr(letters[i])\r\n i += 1\r\n\r\nprint(password)", "import random\r\nimport math \r\narr = list(map(int, input().split()))\r\n\r\nindex = random.sample(range(97,123),arr[1] )\r\n\r\nif(arr[1] <=1 and arr[0]>=1):\r\n print('')\r\nelif(arr[0]<arr[1]):\r\n print(''.join(list(map(chr,random.sample(range(97,123),arr[0] )))))\r\nelse:\r\n index= index*(arr[0]//arr[1])+index[:(arr[0]%arr[1])]\r\n print(''.join(list(map(chr,index))))", "n,k=map(int,input().split())\r\nz=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\nlist=[]\r\nfor i in range(k):\r\n list.append(z[i])\r\nfor i in range(n-k):\r\n list.append(list[i])\r\nfor i in range(1):\r\n for j in range(len(list)):\r\n print(list[j],end=\"\")\r\n \r\n", "import string\r\nalphabet_string = string.ascii_lowercase\r\nn, k = map(int, input().split())\r\npassword = \"\"\r\ncounter = 0\r\nfor x in range(n):\r\n\t\r\n\tif k > 0:\r\n\t\tpassword += alphabet_string[counter]\r\n\t\tcounter += 1\r\n\t\tk -= 1\r\n\telse:\r\n\t\tpassword += password[-2]\r\n\r\nprint(password)\r\n", "import string\r\nn,b=map(int,input().split())\r\nprint((string.ascii_lowercase[:b]*n)[:n])", "n, k = [int(i) for i in input().split()]\ns = \"\"\nfor i in range(97, 97+k):\n s += chr(i)\no = \"\"\nwhile len(o) < n:\n o += s\nprint(o[:n])", "\r\nn, k = map(int, input().split())\r\n\r\nans = ''\r\nfor i in range(k):\r\n\tans += chr(97 + i)\r\n\r\nans *= 100\r\nprint(ans[:n])", "n, k = map(int, input().split())\r\nl = []\r\n\r\nfor i in range(97, 97+k):\r\n l.append(chr(i))\r\n\r\nif n == k:\r\n print(''.join(l))\r\nelse:\r\n g = ''\r\n for j in range(n):\r\n g += l[j%k]\r\n\r\n print(g) ", "n, k = list(map(int, input().split())) # n = number of characters, k = number of same symbols\r\npassword = str()\r\n\r\nD_CHAR = list(map(str, [chr(i) for i in range(97, 97 + k)])) # number of distinct characters in string\r\n\r\nfor i in D_CHAR: # Placing all distinct characters in the password first\r\n password += i\r\n\r\nprev_char = password[-1]\r\n\r\nfor i in range(0, n - k): # using a loop to fill in duplicates\r\n for j in D_CHAR:\r\n if j != prev_char:\r\n password += j\r\n prev_char = j\r\n break\r\n\r\nprint(password)\r\n\r\n", "alfa = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nalfabackup = []\r\nn,k = map(int,input().split())\r\nleng = n\r\nx = y = t = 0\r\npassword = str()\r\nwhile leng > 0:\r\n if t < k:\r\n password = password + alfa[x]\r\n alfabackup.append(alfa[x])\r\n t += 1\r\n x += 1\r\n leng -= 1\r\n else:\r\n if y > k-1:\r\n y = 0\r\n password = password + alfabackup[y]\r\n y += 1\r\n leng -= 1\r\n else:\r\n password = password + alfabackup[y]\r\n y += 1\r\n leng -= 1\r\nprint(password)", "from string import ascii_lowercase as small\n\npassword = \"\"\nn, k = map(int, input().split())\n\nfor i in range(k):\n password += small[i]\n\nfor i in range(n-k):\n password += password[i]\n\nprint(password)", "n, k = list(map(int, input().split()))\r\nstart = 97\r\nfor i in range(n):\r\n print(chr(97+i%k), end='')", "s = 'abcdefghijklmnopqrstuvwxyz'\r\nn,k = map(int, input().split())\r\ntemp = (s[:k])\r\nt = n//k\r\nif n%k==0:\r\n print(t*temp)\r\nelse:\r\n ans = t* temp + temp\r\n print(ans[:n])\r\n", "import string\r\nn,k=map(int,input().split())\r\nl=list(string.ascii_lowercase)\r\nl1=l[:k]*(n//k)\r\na=(l[:k])[:n-len(l1)]\r\nprint(*(l1+a),sep='')", "[n, k] = [int(num) for num in input().split()]\r\nletters = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm']\r\nres = \"\"\r\npos = 0\r\nfor _ in range(n):\r\n res += letters[pos]\r\n if pos != k-1:\r\n pos += 1\r\n else:\r\n pos = 0\r\nprint(res)\r\n", "import string\na=string.ascii_lowercase\nn,k=map(int,input().split())\n#r=n+1\n#for i in range (k):\ns=a[0:k]\n#print(s)\nl=''\n#while (r!=0):\n \nfor i in range(n):\n \n for c in s:\n #print(c)\n l=l+c\n \ng=l[0:n] \nprint(g) \n\n\t\t\t \t\t\t \t\t\t \t\t\t\t\t \t \t\t\t \t", "n, k = map(int,input().split())\r\na = 0\r\nfor _ in range(n):\r\n\tprint(chr(a+97),end=\"\")\r\n\ta+=1\r\n\tif a == k:\r\n\t\ta = 0", "from string import ascii_letters\r\nn, k = map(int, input().split())\r\nl = ascii_letters\r\n \r\na = \"\"\r\nfor i in range(n):\r\n\ta = a + l[i%k]\r\nprint(a)", "n,k=map(int, input().split())\r\ns=''\r\no=ord('a')\r\np=0\r\nfor i in range(n):\r\n s+=chr(o+p)\r\n if p<k-1:\r\n p+=1\r\n else:\r\n p=0\r\nprint(s)\r\n", "import string\n\nlowercase_letters = string.ascii_lowercase\npassword = \"\"\n\npassword_length, number_of_distinct_symbols = [int(x) for x in input().split()]\n\nfor index in range(password_length):\n password += lowercase_letters[index % number_of_distinct_symbols]\n\nprint(password)", "import random\r\nimport string\r\n\r\nn, k = list(map(int, input().strip().split()))[:2]\r\n\r\nletters = list(string.ascii_lowercase)\r\npassword = ''\r\n# while ( len(set(password)) != k ) or (any(c1 == c2 for c1, c2 in zip(password, password[1:]))):\r\nfor i in range(n):\r\n password += ''.join(letters[i % k])\r\n\r\nprint(password)\r\n", "a=\"abcdefghijklmnopqrstuvwxyz\"\r\nb, c = map(int, input().split())\r\nz= a[:c]\r\n# print(z)\r\n# print(b//c)\r\nz=z*(b//c)\r\n# print(z)\r\nprint(z+z[:b-len(z)])", "n,k = map(int,input().split())\r\nm=min(n,k)\r\ns=\"\"\r\nfor i in range(m):\r\n s+=(chr(97+i))\r\ns+=s*((n-k)//k)\r\ns+=s[:n%k]\r\nprint(s)", "import string\n\n\nn, k = map(int, input().split())\n\nprint(string.ascii_lowercase[:k]*(n // k) + string.ascii_lowercase[:(n % k)])\n\n", "lis1=[int(x) for x in input().split(\" \")]\r\nm=lis1[0]\r\nn=lis1[1]\r\nref=\"abcdefghijklmnopqrstuvwxyz\"\r\nlis2=[]\r\ndata=\"\"\r\nfor i in range(n):\r\n lis2.append(ref[i])\r\nfor i in range(m):\r\n data+= lis2[i%n]\r\nprint(data)", "n,k = [int(x) for x in input().split()]\r\ns=''\r\n\r\nfor i in range(n):\r\n s +=chr(ord('a')+i%k) #k=3 0 1 2 0\r\nprint(s)", "# n=4 k=3\n# abcc\nn,k=map(int, input().split())\npassword=''\nfor i in range(k): # 0 -> a -> 97\n password+= chr(i+97)\n# abcab\nsiz = len(password)\ndif = n - siz\nidx = 0\nwhile dif > 0:\n password += password[idx]\n idx += 1\n dif -= 1\n if idx == siz:\n idx = 0\nprint(password)\n\n\n \t \t\t\t\t \t\t\t\t\t\t \t\t \t\t \t", "n, d = map(int, input().split())\r\nprint(('abcdefghijklmnopqrstuvwxyz'[:d] * n)[:n])\r\n", "import sys\r\na,b=input().split()\r\nm=int(a)\r\nn=int(b)\r\nd=''\r\nk=\"abcdefghijklmnopqrstuvwxyz\"\r\nj=m//n\r\ng=m%n\r\nif m>n and g!=0:\r\n b=k[0:n]\r\n for i in range(0,j):\r\n d=d+b\r\n d=d+b[0:g]\r\n print(d)\r\nelif m>n and g==0:\r\n b=k[0:n]\r\n for i in range(0,j):\r\n d=d+b\r\n print(d)\r\nelse:\r\n print(k[0:m])", "\r\n\r\nn, k = map(int, input().split())\r\n\r\nletters = 'abcdefghijklmnopqrstuvwxyz'\r\npassword = ''\r\n\r\ni = 0\r\nwhile n >0:\r\n password += letters[i]\r\n i += 1\r\n n -= 1\r\n if i == k:\r\n i = 0\r\n \r\nprint(password)\r\n \r\n ", "from sys import stdin\r\nfrom bisect import bisect_left as bl\r\nfrom collections import defaultdict\r\nfrom math import ceil\r\n\r\ninput = stdin.readline\r\nread = lambda: map(int, input().strip().split())\r\n\r\nn, k = read()\r\ns = \"\".join([chr(97 + i) for i in range(k)])\r\nprint((s * ceil(n / k) * k)[:n])\r\n", "import random \r\nimport string\r\n\r\nx, y = [int(i) for i in input().split()]\r\n\r\nl1 = []\r\nwhile len(set(l1)) != y:\r\n l1.append(random.choice(string.ascii_lowercase))\r\n\r\nl = list(set(l1))\r\nl2 = []\r\nfor i in range(x):\r\n l2.append(l[(i%y)])\r\n\r\n\r\ns = \"\".join(l2)\r\nprint(s)", "n, k = map(int, input().split())\r\ns = ''\r\nletters = [chr(int(e)) for e in range(97, 97 + k)]\r\nfor i in range(n): s += letters[i % len(letters)]\r\nprint(s)", "n,k=map(int,input().split())\ns=''\nfor i in range(k):\n s+=chr(i+97)\ndif=n-k\nidx=0\nsiz=len(s)\nwhile dif>0:\n s+=s[idx]\n idx+=1\n if(idx==siz):\n idx=0\n dif-=1\nprint(s)\n\t \t\t \t \t\t \t \t \t \t", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Jun 24 05:14:41 2023\r\n\r\n@author: RadmediX\r\n\"\"\"\r\nimport string\r\n\r\n(n, dist) = tuple(map(int,input().split()))\r\n\r\nalpha = list(string.ascii_lowercase)\r\n\r\nind = range(dist)\r\npas = ''\r\ny = 0\r\n\r\nfor i in range(n):\r\n pas += alpha[ind[y]]\r\n if y >= len(ind) -1:\r\n y = 0\r\n else:\r\n y += 1\r\n \r\nprint(pas)\r\n ", "n, k = map(int, input().split())\r\nch = 97\r\nfor i in range(n):\r\n if i%k==0: ch = 97\r\n \r\n print(chr(ch), end=\"\")\r\n ch += 1", "#!/usr/bin/env python\r\n\r\nimport math\r\nimport sys\r\nimport itertools\r\nimport fractions\r\n\r\nif __name__ == '__main__':\r\n wtf = sys.stdin.read()\r\n wtf = wtf.strip().split('\\n')\r\n n,k = map(int, wtf[0].split())\r\n S = ''\r\n for i in range(26):\r\n S += chr(ord('a')+i)\r\n print(S[:k]*(n//k)+S[:n%k])\r\n", "n,k=map(int,input().split())\r\nl=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\nt=l[:k]\r\nif n%k==0:\r\n print(\"\".join(t*(n//k)))\r\nelse:\r\n print(\"\".join(t*(n//k)+l[:n%k]))\r\n ", "w=input().split()\nn,k=int(w[0]),int(w[1])\ns=\"\"\nfor i in range(n):\n s+= chr(ord('a')+((i%k)%26))\nprint(s)\n", "n,k = map(int,input().split())\r\n\r\nalfabeto = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\n\r\nresp = \"\"\r\n\r\nfor i in range(k):\r\n resp += alfabeto[i]\r\n\r\nrepeticao = len(resp)\r\nj = 0\r\nacabar = n - repeticao\r\n\r\nwhile acabar != 0:\r\n resp += alfabeto[j]\r\n j += 1\r\n if j > k-1:\r\n j = 0\r\n acabar -= 1\r\n\r\nfor j in range(n - len(resp)):\r\n resp += alfabeto[j]\r\n\r\nprint(resp)\r\n", "n, k = map(int, input().split())\r\nalpha = \"qwertyuiopasdfghjklzxcvbnm\"\r\nprint(alpha[:k] * (n // k) + alpha[:n % k])\r\n", "X, Temp = list(map(int, input().split())), \"\"\r\nfor i in range(X[1]):Temp += chr(ord('a') + i)\r\nprint(Temp * (X[0] // X[1]) + Temp[:X[0] % X[1]])\r\n\r\n# Hope the best for Ravens\r\n# Never give up\r\n", "n, k = map(int, input().split())\r\n\r\ns = \"\"\r\n\r\nwhile len(s) != n:\r\n i = 0\r\n \r\n while len(s) != n and i < k:\r\n s += chr(i + 97)\r\n i += 1\r\n \r\nprint(s)", "n,k=map(int,input().split())\r\ns='qwertyuiopasdfghjklzxcvbnm'\r\ns2=''\r\nwhile len(s2)<n:\r\n for i in range (k):\r\n if len(s2)<n:\r\n s2+=s[i]\r\n else :\r\n quit\r\n \r\nprint(s2) ", "n,m = map(int, input().split())\r\ns = \"\"\r\nd = \"\"\r\nalph = \"qwertyuiopasdfghjklzxcvbnm\"\r\n\r\nfor i in range(m):\r\n\td += alph[i];\r\n\r\nd *= 500\r\n\r\nfor i in range(n):\r\n\tprint(d[i], end=\"\")", "from sys import stdin\r\nalphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nlength, letters = stdin.readline().strip().split(\" \")\r\nword = alphabet[:int(letters)]\r\nwhile len(word) < int(length):\r\n word += word\r\nprint(word[:int(length)])", "alpha = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nn, k = list(map(int, input().split()))\r\n\r\nnew_s = \"\"\r\nindex = 0\r\nfor i in range(n):\r\n new_s += alpha[index]\r\n index+=1\r\n if index % k == 0:\r\n index = 0\r\n\r\nprint(new_s)", "# https://codeforces.com/contest/770/problem/A\n\nl = input().split()\nn, k = int(l[0]), int(l[1])\n\nm = ord('a')\npassword_set = list(range(m, m+k))\n# print(password_set)\nans = ''\nfor i in range(n):\n # print(chr(password_set[i%k]))\n ans += chr(password_set[i%k])\nprint(ans)", "from string import ascii_lowercase\nNewPass = \"\"\nN,K =[int(x) for x in input().split()]\ni = 0\nwhile len(NewPass) != N:\n if i == K:\n i = 0\n NewPass += ascii_lowercase[i]\n i += 1\nprint(NewPass)\n\n \t\t\t\t \t \t \t \t \t \t\t\t\t\t \t\t \t", "n, k = map(int, input().split())\r\nal = \"abcdefghijklmnopqrstuvwxyz\"\r\ns = \"\"\r\nfor j in range(k):\r\n s += al[j]\r\nd = n - k\r\nif d != 0:\r\n while d:\r\n for j in range(k):\r\n d = d-1\r\n s += al[j]\r\n if d == 0:\r\n break\r\nprint(s)\r\n", "alpha ='abcdefghijklmnopqrstuvwxyz'\r\ninin = input().split()\r\nx = int(inin[0])\r\nc = int(inin[1])\r\npassword = ''\r\nfor i in range(0,c):\r\n password +=alpha[i] \r\nfor i in range(c,x):\r\n password+= password[i-c]\r\nprint(password)", "# import sys\r\n# sys.stdin = open('./input.txt', 'r')\r\n# sys.stdout = open('./output.txt', 'w') \r\n\r\nn , k = map(int,input().split())\r\nalphabet = [chr(i) for i in range(97,123)]\r\npassword = \"\"\r\nfor i in range(n):\r\n password += alphabet[i%k]\r\nprint(password)", "# New Password\r\n# https://codeforces.com/contest/770/problem/A\r\n#\r\n# Author: eloyhz\r\n# Date: Aug/26/2020\r\n\r\n\r\nif __name__ == '__main__':\r\n n, k = [int(x) for x in input().split()]\r\n r = n // k\r\n password = ''\r\n for _ in range(r):\r\n for i in range(k):\r\n password += str(chr(ord('a') + i))\r\n r = n % k\r\n for i in range(r):\r\n password += str(chr(ord('a') + i))\r\n print(password)\r\n", "n, k = map(int, input().split())\r\npassword = ''\r\na = 97\r\nfor i in range(1, n + 1):\r\n password = password + chr(a)\r\n a += 1\r\n if i % k == 0:\r\n a = 97\r\nprint(str(password))", "n, k = map(int, input().split())\r\nalpha = \"qwertyuiopasdfghjklzxcvbnm\"\r\npassword = alpha[:k]\r\npassword *= n//k\r\npassword += password[:n % k]\r\nprint(password)\r\n", "n,k=map(int,input().split())\r\nlst=[]\r\nfor i in range(n):\r\n lst.append(chr(ord(\"a\")+i%k))\r\n\r\nresult_str = ''.join(i for i in lst)\r\nprint(result_str)\r\n", "n,k = map(int, input().split())\r\nabc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\npw = ''\r\n\r\nfor i in range(n):\r\n for a in range(k):\r\n pw += abc[a]\r\n\r\nprint(pw[:n])", "list = input().split()\r\nlist = [int(x) for x in list]\r\nn = list[0]\r\nk = list[1]\r\n\r\nalphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\nb = []\r\n\r\nfor i in range(0, k):\r\n b.append(alphabet[i])\r\n\r\nword1 = ''\r\nfor j in b:\r\n word1 = word1 + j\r\n \r\nm = int(n%k)\r\nt = int((n - m)/k)\r\nword2 = word1[0:m]\r\n\r\nword3 = ''\r\nu = 0\r\nwhile(u < t):\r\n word3 = word3 + word1\r\n u = u + 1\r\n \r\nprint(word3 + word2)\r\n", "import random\r\n \r\n \r\ndef f(m):\r\n p1 = []\r\n while len(p1) != m:\r\n c = chr(random.randint(97, 122))\r\n if c not in p1:\r\n p1.append(c)\r\n return ''.join(p1)\r\nn, k = map(int, input().split(' '))\r\nif k > n:\r\n end = n\r\n print(f(end))\r\nelif k == n:\r\n end = n\r\n print(f(end))\r\nelse:\r\n end = k\r\n a = n//k\r\n b = n%k\r\n p = f(k)\r\n r = p*a + p[:b]\r\n print(r)", "n, k = list(map(int, input().split()))\r\ntemp = 97\r\nfor i in range(n):\r\n if (i % k == 0):\r\n temp = 97\r\n print(chr(temp), end=\"\")\r\n temp += 1\r\n ", "k,n = map(int,input().split())\nprint(('abcdefghijklmnopqrstuvwxyz'[:n]*k)[:k])\n\t \t\t \t \t\t\t \t\t\t \t \t\t \t \t\t \t\t", "def main():\n\t#read n and k\n\t(n,k) = (int(inp) for inp in input().split())\n\tascii_start_lowercase = 97\n\n\t#use first k letters of alphabet to generate password\n\tpassword = ''.join([chr(97 + i%k) for i in range(n)]) \n\tprint(password)\n\treturn password\n\nif __name__ == \"__main__\":\n\tmain()\n \t \t\t\t\t \t\t \t\t \t \t\t \t\t\t\t\t", "from operator import mod\r\nimport string\r\n\r\n\r\nn,k=list(map(int,input().split()))\r\nalph=string.ascii_letters\r\nseq=alph[:k]\r\nprint(seq*int((n/k)),seq[:int(mod(n,k))],sep='')\r\n", "# https://codeforces.com/contest/770/problem/A\r\n\r\nlengthOfPassword, noOfDistinctSymbols = [int(x) for x in input().split(' ')]\r\n\r\npassword = ''\r\npossibleChars = 'xabcdefghijklmnopqrstuvwxyz' # It starts from 1 so x in added in the start\r\nnoOfDistinctSymbolsInPassword = 0\r\n\r\nfor i in range(lengthOfPassword):\r\n if noOfDistinctSymbolsInPassword < noOfDistinctSymbols:\r\n noOfDistinctSymbolsInPassword += 1\r\n password += possibleChars[noOfDistinctSymbolsInPassword]\r\n else:\r\n if noOfDistinctSymbols % 2 == 0:\r\n if i % 2 == 0:\r\n password += possibleChars[noOfDistinctSymbolsInPassword - 1]\r\n else:\r\n password += possibleChars[noOfDistinctSymbolsInPassword]\r\n else:\r\n if i % 2 == 0:\r\n password += possibleChars[noOfDistinctSymbolsInPassword]\r\n else:\r\n password += possibleChars[noOfDistinctSymbolsInPassword-1]\r\n\r\nprint(password)\r\n", "n, k = map(int, input().split())\r\nres = ''\r\nfor i in range(k):\r\n res += chr(97 + i)\r\n\r\nfor i in range(n-k):\r\n res += chr(97 + i % k)\r\n\r\nprint(res)", "n, k = map(int, input().split(\" \"))\n\nout = []\n\ni = 0\nwhile len(out) < n:\n if i == 26 or i == k:\n i = 0\n\n out.append(chr(i + 97))\n i += 1\n\nprint(\"\".join(out))\n", "import string\ns=string.ascii_lowercase\nn,k=map(int,input().split())\nans=s[:k]*(n//k)+s[:(n%k)]\nprint(ans)\n \t\t \t \t\t \t\t \t \t \t\t \t\t", "a,b=map(int,input().split(\" \"))\r\nalph=[ chr(i) for i in range(97,97+b)]\r\ns=\"\"\r\nfor i in range(a):\r\n s+=alph[i%b]\r\n\r\nprint(s) ", "n, k = map(int, input().split())\r\nt = \"\"\r\nfor i in range(97, 97 + k): t += chr(i);\r\nt *= 100\r\nprint(t[:n])\r\n\r\n", "s = \"abcdefghijklmnopqrstuvwxyz\"\ns2 = \"\"\nn,k= input().split()\nn = int(n)\nk = int(k)\nfor i in range(n):\n s2 +=s[i%k]\nprint(s2)\n\t \t\t\t \t \t\t \t\t\t \t\t \t\t\t\t \t", "n, k = map(int, input().split())\r\ns = \"abcdefghijklmnopqrstuvwxyz\"\r\nans = s[0:k] + (\"ab\"*(n-k))\r\nprint(ans[0:n])", "n,k=map(int,input().split())\r\ns=\"\"\r\nfor i in range(97,97+k):\r\n\ts+=chr(i)\r\ns=s*(n//k)+s[:n%k]\r\nprint(s)", "s='abcdefghijklmnopqrstuvwxyz'\r\nn,k=map(int,input().split())\r\nc=''\r\nwhile n>0:\r\n if n<k:\r\n c=c+s[0:n]\r\n n=-1\r\n else:\r\n c=c+s[0:k]\r\n n=n-k\r\nprint(c)", "n,k = map(int,input().split())\r\na=\"abcdefghijklmnopqrstuvwxyz\"\r\ni = 0\r\nj = 0\r\ns =\"\"\r\nwhile i < n:\r\n s += a[j]\r\n i += 1\r\n j += 1\r\n if j == k:\r\n j = 0\r\nprint(s)", "a,b=map(int,input().split())\r\nx=\"abcdefghijklmnopqrstuvxwyz\"\r\nq=0\r\nfor i in range(a):\r\n print(x[q],end='')\r\n q+=1\r\n if q==b:\r\n q=0", "n, k =map(int,input().split())\r\nwordlist = []\r\nc = k\r\nfor i in range(n):\r\n if len(wordlist)==n:\r\n break\r\n wordlist.append(chr(97+(i%k)))\r\n if len(wordlist)==n:\r\n break\r\nprint(''.join(wordlist))", "n,k=map(int, input().split())\r\n#n=int(input())\r\n#l=list(map(int, input().split()))\r\n\r\nfor i in range(n):\r\n print(chr(97+i%k),end='')", "n,k = [int(_) for _ in input().split()]\r\ns1=\"abcdefghijklmnopqrstuvwxyz\"\r\ns2=\"\"\r\nfor i in range(n):\r\n s2+=s1[i%k]\r\nprint(s2)", "m=\"abcdefghijklmnopqrstuvwxyz\"\r\nn,k = map(int, input().split())\r\nz= m[:k]\r\n# print(z)\r\n# print(n//k)\r\nz=z*(n//k)\r\nprint(z+z[:n-len(z)])", "import math\r\n\r\n# test = int(input())\r\n# for q in range(test):\r\nx, y = map(int, input().split())\r\n# n = int(input())\r\n# s = input()\r\ns = \"\"\r\ni = 0\r\nwhile i<x:\r\n for j in range(min(y, x-i)):\r\n s += chr(ord(\"a\")+j)\r\n i += j + 1\r\nprint(s)", "\r\nn,k = map(int,input().split())\r\nalpha = 'abcdefghijklmnopqrstuvwxyz' \r\nrepeat = ((n-k) // k) +1\r\npart = ((n-k) % k) \r\nword = alpha[:k]\r\nprint(word * repeat + word[:part])\r\n", "import random\r\nimport string\r\n\r\nn, k = [int(i) for i in input().split(\" \")]\r\nchars = random.sample(string.ascii_lowercase, k)\r\n\r\ns = \"\"\r\n\r\nfor i in range(n):\r\n s += chars[i%k]\r\nprint(s)\r\n", "n, k = map(int, input().split())\r\n\r\npassword = \"\"\r\nletters = \"abcdefghijklmnopqrstuvwxyz\"\r\nj = 0\r\nfor i in range(n):\r\n password += letters[j]\r\n j += 1\r\n if(j == k):\r\n j = 0\r\n\r\nprint(password)\r\n", "import random\r\n\r\nn,k=map(int,input().split())\r\npassword=[]\r\n\r\nwhile len(password)!=k:\r\n a=chr(random.randint(97,122))\r\n if a not in password:\r\n password.append(a)\r\n\r\nwhile len(password)!=n:\r\n a = chr(random.randint(97, 122))\r\n if password[-1]!=a and a in password:\r\n password.append(a)\r\nprint(''.join(password))", "if __name__ == \"__main__\":\n n, k = map(int, input().split())\n alphabet = list('abcdefghijklmnopqrstuvwxyz')\n password = ''\n\n i = 0\n while k > 0:\n password= password + alphabet[i]\n k= k - 1\n i= i + 1\n\n i = 0\n while len(password) < n:\n if i == k:\n i = 0\n password= password + password[i]\n i= i + 1\n\n print(password)\n \t \t \t \t \t\t \t \t \t \t \t\t\t", "n,k = map(int,input().split(\" \"))\r\nchars = \"\"\r\npassword = \"\"\r\nfor i in range(97,97+k):\r\n chars += chr(i)\r\n\r\npointer = 0\r\nfor i in range(n):\r\n password += chars[pointer]\r\n if pointer == len(chars)-1:\r\n pointer = pointer % len(chars)-1\r\n else:\r\n pointer += 1\r\n\r\nprint(password)", "import string\r\n\r\nn,k = map(int,input().split())\r\nalpha = list(string.ascii_lowercase)[0:k:]\r\ns = ''\r\ncur_alpha = 0\r\nfor i in range(n):\r\n s += alpha[cur_alpha]\r\n cur_alpha = (cur_alpha + 1) % k\r\n\r\nprint(s)", "n,k = map(int , input().split())\r\nlistofchars = [chr(x+97) for x in range(k)]\r\nword=\"\"\r\nfor i in range(n):\r\n word+=listofchars[i%k]\r\n \r\nprint(word)", "import string\r\nimport random\r\n \r\nn , k = map(int , input().split())\r\n \r\ndef generate(n , k):\r\n p = ''\r\n r = string.ascii_letters[:k]\r\n while(True):\r\n if len(p) < n:\r\n p +=r\r\n else:\r\n break\r\n return p[:n]\r\nprint(generate(n,k))\r\n", "n, k = map(int, input().split())\r\na = \"abcdefghijklmnopqrstuvwxyz\"\r\nprint((a[:k]*n)[:n])", "n, k = list(map(int,input().split()))\r\nm = ''.join([chr(i + 97) for i in range(26)][:k])\r\nprint(m * (n//k) + m[:n % k])", "n, k = map(int, input().split())\r\n\r\ndistinct_letters = [chr(ord('a') + i) for i in range(k)]\r\n\r\npassword = \"\"\r\n\r\nfor i in range(n):\r\n password += distinct_letters[i % k]\r\n\r\nprint(password)\r\n", "n,k=map(int,input().split())\r\na=[]\r\nfor i in range(k):\r\n a.append(chr(97+i))\r\nres=\"\"\r\nb=n//k\r\nres+=b*(''.join(a))\r\nc=n%k\r\nres+=(''.join(a[0:c]))\r\nprint(res)", "n,k=map(int,input().split())\r\nalpha='abcdefghijklmnopqrstuvwxyz'\r\npas=''\r\ni=0\r\nwhile(len(pas)!=k):\r\n pas=pas+alpha[i]\r\n i+=1\r\n\r\nupper_bound=i\r\ni=0\r\nwhile len(pas)!=n:\r\n if i!=upper_bound:\r\n pas=pas+alpha[i]\r\n \r\n i+=1\r\n else:\r\n i = 0\r\n pas=pas+alpha[i]\r\n\r\n i+=1\r\n\r\nprint(pas)", "n,k=map(int,input().split())\r\ny=''\r\nx='abcdefghijklmnopqrstuvwxyz'\r\nfor i in range(k):\r\n y+=x[i]\r\nfor i in range(n):\r\n if len(y)<n:\r\n y+=y[i]\r\nprint(y)", "from string import ascii_lowercase\r\nfrom itertools import cycle\r\nn, k = map(int, input().split())\r\n\r\nuseable = cycle([ascii_lowercase[i:i+1] for i in range(k)])\r\n\r\npassw = \"\"\r\ni = 0\r\nwhile len(passw) < n:\r\n passw += next(useable)\r\n i += 1\r\n\r\n\r\nprint(passw)", "n,k=map(int,input().split())\r\ne=k\r\ns=''\r\nx=97\r\ni=0\r\nwhile n>0:\r\n s+=chr(x+i)\r\n i+=1\r\n k-=1\r\n n-=1\r\n if k==0:\r\n k=e\r\n i=0\r\nprint(s)", "kl = 'qwertyuiopasdfghjklzxcvbnm'\r\nn, m = map(int, input(). split())\r\nprint(kl[ : m], end = '')\r\nkl = kl[ : m]\r\nn = n - m\r\nd = 0\r\nwhile n > 0:\r\n if n > 0 and d == 0:\r\n print(kl[0], end = '')\r\n n -= 1\r\n d = 1\r\n elif n > 0 and d == 1:\r\n print(kl[1], end = '')\r\n d = 0\r\n n -= 1\r\n", "n,k=map(int,input().split())\r\nc=0\r\nfor i in range(n):\r\n print(chr(97+c),end='')\r\n c+=1\r\n if(c==k):\r\n c=0\r\n", "import string\nn, k = map(int, input().split())\nprint(string.ascii_letters[:k] * (n // k) + string.ascii_letters[:n % k])", "x = input().split(\" \")\nn = int(x[0])\nk = int(x[1])\n\n# the length of the password must be equal to n,\n# the password should consist only of lowercase Latin letters,\n# the number of distinct symbols in the password must be equal to k,\n# any two consecutive symbols in the password must be distinct. \nchars = 'abcdefghijklmnopqrstuvwxyz'\npassword = ''\ncounter = 0\n\nfor i in range(n):\n password += chars[counter]\n counter +=1\n if counter >= k:\n counter = 0\n\nprint(password)\n\n\n", "n, k = list( map(int, input().split()) )\r\n\r\nlst1 = [ chr(97+i) for i in range(26) ]\r\nlst2 = []\r\n\r\nfor i in range(k):\r\n print(lst1[i], sep='', end='')\r\n lst2.append(lst1[i])\r\n\r\nn -= k\r\nwhile n > 0:\r\n for ch in lst2:\r\n print(ch, sep='', end='')\r\n n -= 1\r\n if n == 0:\r\n break\r\n", "import random\r\nn,m = map(int,input().split())\r\nz = \"abcdefghijklmnopqrstuvwxyz\"\r\nfor i in range(n):\r\n print(z[i%m],end=\"\")\r\n \r\n", "n, k = map(int, input().split())\r\nto_choose = \"abcdefghijklmnopqrstuvwxyz\"\r\nindex = 0\r\nk_cnt = 0\r\nres = []\r\n\r\nfor i in range(n):\r\n if k_cnt == k:\r\n index = 0\r\n k_cnt = 0\r\n\r\n res.append(to_choose[index])\r\n index += 1\r\n k_cnt += 1\r\n\r\nprint(\"\".join(res))", "import random\r\nconstraints = [int(n) for n in input().split()]\r\nn = constraints[0]\r\nk = constraints[1]\r\n\r\nmySet = set()\r\nwhile (len(mySet)<k ):\r\n mySet.add(random.randint(0,25))\r\n\r\n\r\nmySet = list(mySet)\r\nsety=0\r\npassw=\"\"\r\nfor i in range(n):\r\n passw += (chr(ord('a') +mySet[sety]))\r\n sety+=1\r\n sety = 0 if sety> k-1 else sety\r\n\r\nprint(passw)", "import sys, string\r\ninput = sys.stdin.readline\r\n\r\n\r\n(n, k) = tuple(map(int, input().split()))\r\n\r\nalpha = string.ascii_lowercase[0:k]\r\n\r\nprint(((n // k) * alpha) + alpha[0:n%k])", "a, b = map(int , input().split())\r\nfor i in range(a):\r\n print(chr(97 + i % b),end=\"\")", "length, numbers = map(int, input().split())\nletters = \"abcdefghijklmnopqrstuvwxyz\"\nprint(letters[:numbers]*(length//numbers) + letters[:length % numbers])", "a,b=map(int,input().split())\r\nl=\"abcdefghijklmnopqrstuvwxyz\"\r\ns=l[:b]\r\nu=a//b\r\ns=s*u\r\nr=a-b*u\r\ns=s+l[:r]\r\nprint(s)\r\n", "n, m = map(int, input().split(\" \"))\r\ns = ''\r\nk = 0\r\nh = n-m\r\nfor i in range(m):\r\n c = chr(ord('a') + k)\r\n s += c\r\n k += 1\r\nfor i in range(h):\r\n s += s[i]\r\n\r\nprint(s)\r\n", "n,k = map(int, input().split())\r\nres=''\r\nfor i in range(n):\r\n res+= chr(ord('a') + i%k)\r\n\r\nprint(res)", "n,k = map(int,input().split())\r\nans = \"\"\r\nfor i in range(k):\r\n ans += chr(97+i) \r\nans *= n//k+1\r\nprint(ans[0:n])\r\n", "n, k = map(int, input().split())\r\nst, num, alfavit = ('', 0, 'abcdefghijklmnopqrstuvwxyz')\r\nwhile len(st) < n:\r\n for num in range(k):\r\n st += alfavit[num]\r\n num += 1\r\n if len(st) == n:\r\n break\r\n num = 0\r\nprint(st)\r\n", "password_length, number_of_distinct_letters = map(int, input().split())\npassword_distinct_letters = [chr(97 + i) for i in range(number_of_distinct_letters)]\npassword_repeated_letters = [password_distinct_letters[i % number_of_distinct_letters]\n for i in range(password_length - number_of_distinct_letters)]\nformatted_password = ''\nfor letter in password_distinct_letters + password_repeated_letters:\n formatted_password += letter\nprint(formatted_password)\n", "n, k = map(int, input().split())\r\n\r\nalphabet = 'qwertyuiopasdfghjklzxcvbnm'\r\nsymbol = alphabet[:k]\r\n\r\nif n == k:\r\n print(symbol)\r\nelif n > k:\r\n s = symbol * (n // k)\r\n if len(s) != n:\r\n s += symbol[:n-len(s)]\r\n print(s)\r\nelse:\r\n print(symbol[:n])\r\n", "n = list(input().split())\r\nchar = ''\r\nfor i in range(int(n[0])):\r\n i = i % int(n[1])\r\n char += chr(97+i % int(n[1]))\r\nprint(char)\r\n", "from math import ceil \r\nn,k=input().split()\r\nn=int(n)\r\nk=int(k)\r\nl=[chr(x) for x in range(ord('a'),ord('z')+1)]\r\ns=\"\"\r\nS=\"\"\r\nfor i in range(k):\r\n\ts+=l[i]\r\nlength=ceil(n/k)\r\nfor _ in range(length):\r\n\tS+=s\r\nprint(S[:n])\r\n", "#!/usr/bin/env python3\nimport random\nimport sys\ninput = sys.stdin.readline\n\n############ ---- Input Functions, coutery of 'thekushalghosh' ---- ############\n\n\ndef inp():\n return(int(input()))\n\n\ndef inlt():\n return(list(map(int, input().split())))\n\n\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\n\n\ndef invr():\n return(map(int, input().split()))\n\n\nif __name__ == \"__main__\":\n n, k = invr()\n letters = random.sample(range(97, 123), k)\n password = []\n for i in range(n):\n password.append(chr(letters[i % k]))\n print(''.join(password))\n", "\r\nletters = list('abcdefghijklmnopqrstuvwxyz')\r\n\r\nn, k = list(map(int, input().split()))\r\n\r\npwd = (n // k)*letters[:k]\r\npwd += letters[:(n-len(pwd))]\r\nprint(\"\".join(pwd))", "n, k = [int(x) for x in input().split()]\n\nletter = 97\npw = \"\"\n\nfor i in range(n):\n if k > 0:\n pw += chr(letter)\n letter+=1\n k-=1 \n else:\n pw += pw[-2]\n \nprint(pw)\n\t \t\t \t\t \t\t\t \t\t \t\t\t\t \t", "ls = list(map(int,input().split()))\r\nn = ls[0]\r\nk = ls[1]\r\na = ''\r\nfor c in range(97, 97+k): \r\n a = a+chr(c);\r\nfor i in range(n-k):\r\n a = a+a[i] \r\nprint(a)", "n, k = map(int, input().split())\r\n\r\npassword = []\r\ni = 0\r\nwhile i < k:\r\n password.append(chr(97 + i))\r\n i += 1\r\nj = 0\r\nwhile (i < n):\r\n password.append(password[j])\r\n i += 1\r\n j += 1\r\n\r\nprint(''.join(password))\r\n\r\n", "a,b=input().split();print(('qwertyuiopasdfghjklzxcvbnm'[:int(b)]*50)[:int(a)])", "nk=input().split()\r\nn=int(nk[0])\r\nk=int(nk[1])\r\nL=[chr(97+i) for i in range (26)]\r\nt=''\r\nfor i in range(0,k):\r\n\tt+=L[i]\r\nm=n//k\r\nr=n%k\r\ns=t*m+t[0:r]\r\nprint(s)\r\n\r\n", "s=\"zxcvbnmasdfghjklqwertyuiop\" \r\nn,b=map(int,input().split())\r\nprint((s[:b]*n)[:n])", "import math\r\nx = input().split()\r\nn = int(x[0])\r\nk = int(x[1])\r\nstr1 = \"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nlist1 = []\r\ny = str1[0:k]\r\nlist1.append(y)\r\nremain = math.ceil((n-k) / len(y))\r\ntemp = y * remain\r\nlist1.append(temp[0:(n-k)])\r\n\r\n\r\nprint(''.join(list1))\r\n", "n,k=map(int,input().split())\r\nx=ord(\"a\")\r\nans=\"\"\r\nfor i in range(n):\r\n ans+=chr(x+i%k)\r\nprint(ans)", "n, k = map(int, input().split())\nprint(('abcdefghijklmnopqrstuvwxyz'[:k] * n)[:n])\n\t \t\t \t \t \t\t \t \t \t", "[n, k] = [int(x) for x in input().split()]; s = ''\r\nfor i in range(n): s += chr((i%k)+97)\r\nprint(s)\r\n", "import string \r\n\r\nalphabet = list(string.ascii_lowercase)\r\nlenn, symb = map(int,input().split())\r\nletter = list()\r\n\r\n\r\nwhile len(letter) < lenn:\r\n for i in range(symb):\r\n letter.append(alphabet[i])\r\n if len(letter) == lenn:\r\n break\r\npassword = ''.join(letter)\r\nprint(password)\r\n", "import string\nn, k = map(int, input().split())\nalph = string.ascii_lowercase[:k]\nprint(alph*(n//len(alph)), end=\"\")\nprint(alph[:n % k])\n", "n, k=map(int, input().split())\r\npassword=\"\"\r\nfor i in range(k):\r\n password+= chr(97+i)\r\nfor i in range(n-k):\r\n password+=password[i]\r\nprint(password)", "nums = input()\r\nnums = nums.split(' ')\r\nn = int(nums[0])\r\nk = int(nums[1])\r\nalphabets = \"abcdefghijklmnopqrstuvwxyz\"\r\nchars = alphabets[0:k]\r\nchars = n * chars\r\nprint(chars[0:n])", "inpt = input().split(' ')\r\nn = int(inpt[0])\r\nk = int(inpt[1])\r\npassword = \"\"\r\nfor i in range(n):\r\n password += chr(ord('a') + (i % k))\r\nprint(password)", "numLetters, distinct = map(int, input().split())\r\nrepeats = ((numLetters - distinct)/2.0) + 1\r\nans = \"\"\r\nif repeats == int(repeats):\r\n ans += \"ab\" * int(repeats)\r\nelse:\r\n ans += \"ab\" * int(repeats - 0.5) + \"a\"\r\n\r\nfor i in range(distinct - 2):\r\n ans += chr((i+1+1+97)%124)\r\n\r\nprint(ans)", "n, k = [int(x) for x in input().split()]\nkc = k\nalphabet = 'abcdefghijklmnopqrstuvwxyz'\nalphabet = list(alphabet)\npassword = ''\ni = 0\nwhile kc > 0:\n password += alphabet[i]\n kc -= 1\n i += 1\ni = 0\nwhile len(password) < n:\n if i == k:\n i = 0\n password += password[i]\n i += 1\nprint(password)\n\t\t \t\t \t\t\t \t \t\t\t \t \t\t\t", "import string\r\nz=string.ascii_lowercase\r\nn,k=map(int,input().split())\r\nx=\"\"\r\nfor i in range(k):\r\n x+=z[i]\r\nif len(x)!=n:\r\n for v in range(n-len(x)):\r\n x+=x[v]\r\nprint(x)", "n, k = map(int, input().split())\r\nchar = 'a'\r\npassword = []\r\nfor i in range(k):\r\n password.append(char)\r\n char = chr(ord(char) + 1)\r\nindex = 0\r\nwhile len(password) != n:\r\n password.append(password[index])\r\n if index == len(password) - 1:\r\n index = 0\r\n else:\r\n index += 1\r\nfor i in password:\r\n print(i, end=\"\")\r\n", "# Not Completed\n\n\na, b = map(int, input().split())\n\nalphset = [\n \"a\",\n \"b\",\n \"c\",\n \"d\",\n \"e\",\n \"f\",\n \"g\",\n \"h\",\n \"i\",\n \"j\",\n \"k\",\n \"l\",\n \"m\",\n \"n\",\n \"o\",\n \"p\",\n \"q\",\n \"r\",\n \"s\",\n \"t\",\n \"u\",\n \"v\",\n \"w\",\n \"x\",\n \"y\",\n \"z\",\n]\n\nrandLet = set()\npassword = \"\"\n\nfor i in range(b):\n randLet.add(alphset[i])\n\nwhile len(password) < a:\n for i in randLet:\n if len(password) == a:\n break\n password += i\n\nprint(password)\n", "import math\r\n\r\nl, nc = map(int, input().split())\r\nletters = \"abcdefghijklmnopqrstuvwxyz\"\r\nbp = letters[:nc] * math.ceil(l / nc)\r\nprint(bp[:l])\r\n", "n, k = map(int, input().split())\n\nA = [chr(i) for i in range(ord(\"a\"), ord(\"z\")+1)]\n\nfor i in range(n):\n print(A[i%k], end=\"\")\nprint()", "import io, os\r\nimport sys\r\nfrom atexit import register\r\nimport string\r\n\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\nsys.stdout = io.BytesIO()\r\nregister(lambda: os.write(1, sys.stdout.getvalue()))\r\n\r\ntokens = []\r\ntokens_next = 0\r\n\r\n\r\ndef nextStr():\r\n global tokens, tokens_next\r\n while tokens_next >= len(tokens):\r\n tokens = input().split()\r\n tokens_next = 0\r\n tokens_next += 1\r\n\r\n if type(tokens[tokens_next - 1]) == str:\r\n return tokens[tokens_next - 1]\r\n return tokens[tokens_next - 1].decode()\r\n\r\n\r\ndef nextInt():\r\n return int(nextStr())\r\n\r\n\r\ndef nextIntArr(n):\r\n return [nextInt() for i in range(n)]\r\n\r\n\r\ndef print(s, end='\\n'):\r\n sys.stdout.write((str(s) + end).encode())\r\n\r\n\r\nn = nextInt()\r\nk = nextInt()\r\n\r\nchars = string.ascii_lowercase[:k]\r\nchars = list(chars)\r\n\r\nfor i in range(n):\r\n print(chars[i % k], '')\r\n", "import random as rand \r\nli=[ ]\r\nfor i in range(0,26):\r\n x=chr(97+i)\r\n li.append(x)\r\n#print(li)\r\nn,k=map(int,input().split(\" \"))\r\nsub1=li[:k]\r\nsub1=(sub1)*(n//k)\r\nsub2=sub1[:(n%k)]\r\nans=sub1+sub2\r\nfor i in range(0,len(ans)):\r\n print(ans[i],end=\"\")", "password_len, no_of_distinct_char = map(int, input().split())\n\nalpha = \"abcdefghijklmnopqrstuvwxyz\"\n\ndistinct = alpha[:no_of_distinct_char]\nremaining = password_len % no_of_distinct_char\nrepeat = password_len // no_of_distinct_char\nprint((distinct * repeat)+ distinct[:remaining])", "cset=\"qwertyuiopasdfghjklzxcvbnm\"\r\nn,k=map(int,input().split())\r\ns=cset[:k]\r\nprint(s*(n//k)+s[:n%k])", "import math\r\nimport sys\r\nimport string\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n sys.stdout.write(sep.join(map(str, args)) + end)\r\n\r\ndef main() -> None:\r\n lower_case = string.ascii_lowercase\r\n n, k = map(int, input().split())\r\n print((lower_case[:k] * (math.ceil(n / k)))[:n])\r\n\r\nif __name__ == '__main__':\r\n main()", "import string\r\nn,b=map(int,input().split())\r\ns=string.ascii_lowercase\r\nk,s2=0,s[0:b]\r\nfor i in range(n-b) :\r\n if k==b : k=0\r\n s2=s2+s[k]\r\n k+=1\r\nprint(s2)", "n,k=input().split()\r\nn=int(n)\r\nk=int(k)\r\ns=[]\r\ncounting=97\r\ncount=0\r\nwhile(count<n):\r\n for j in range(0,k):\r\n if(count==n):\r\n break\r\n s.append(chr(counting))\r\n count+=1\r\n counting+=1\r\n counting-=k\r\nfor i in range(0,n):\r\n print(s[i],end='')", "n, k = map(int, input().split())\r\ns = \"\"\r\nfor i in range(97, 97+k):\r\n s += chr(i)\r\nprint(s*(n//k) + s[:(n%k)])" ]
{"inputs": ["4 3", "6 6", "5 2", "3 2", "10 2", "26 13", "100 2", "100 10", "3 3", "6 3", "10 3", "50 3", "90 2", "6 2", "99 3", "4 2", "100 3", "40 22", "13 8", "16 15", "17 17", "19 4", "100 26", "100 25", "26 26", "27 26", "2 2", "26 25", "99 2", "99 26", "4 4", "5 3", "5 4", "5 5", "24 22", "26 14", "26 15", "30 12", "35 4", "79 3", "79 14", "85 13", "90 25", "90 19", "26 24", "100 17", "26 2"], "outputs": ["abca", "abcdef", "ababa", "aba", "ababababab", "abcdefghijklmabcdefghijklm", "abababababababababababababababababababababababababababababababababababababababababababababababababab", "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "abc", "abcabc", "abcabcabca", "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab", "ababababababababababababababababababababababababababababababababababababababababababababab", "ababab", "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc", "abab", "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca", "abcdefghijklmnopqrstuvabcdefghijklmnopqr", "abcdefghabcde", "abcdefghijklmnoa", "abcdefghijklmnopq", "abcdabcdabcdabcdabc", "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyza", "ab", "abcdefghijklmnopqrstuvwxya", "abababababababababababababababababababababababababababababababababababababababababababababababababa", "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu", "abcd", "abcab", "abcda", "abcde", "abcdefghijklmnopqrstuvab", "abcdefghijklmnabcdefghijkl", "abcdefghijklmnoabcdefghijk", "abcdefghijklabcdefghijklabcdef", "abcdabcdabcdabcdabcdabcdabcdabcdabc", "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca", "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi", "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg", "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno", "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn", "abcdefghijklmnopqrstuvwxab", "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno", "ababababababababababababab"]}
UNKNOWN
PYTHON3
CODEFORCES
611
1d1a1e0764f53ad7c036de5671142880
Sad powers
You're given *Q* queries of the form (*L*,<=*R*). For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=&gt;<=0, *p*<=&gt;<=1 such that *x*<==<=*a**p*. The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105). The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018). Output *Q* lines — the answers to the queries. Sample Input 6 1 4 9 9 5 7 12 29 137 591 1 1000000 Sample Output 2 1 0 3 17 1111
[ "from math import *\nimport bisect as bs\n\n\ndef full():\n limit = 10**18\n ds = []\n for a in range(2, 10**6+1):\n ap = a*a*a\n while ap <= limit:\n if floor(sqrt(ap))**2 != ap:\n ds.append(ap)\n ap *= a\n ds.sort()\n n = 0\n for i in range(1, len(ds)):\n if ds[i] > ds[i-1]:\n n += 1\n ds[n] = ds[i]\n a = ds[:n+1]\n q = int(input())\n for _ in range(q):\n L, R = map(int, input().split())\n ketqua = bs.bisect_right(a, R) - bs.bisect_left(a, L)\n u = int(sqrt(L))\n while u*u < L:\n u += 1\n v = int(sqrt(R))\n while v*v > R:\n v -= 1\n ketqua += v-u+1\n print(ketqua)\n\n\nfull()\n\t \t\t \t \t\t \t\t \t\t\t \t\t\t\t \t\t", "import sys\r\ninput = sys.stdin.readline\r\ndef s1(n, k):\r\n l = 0\r\n r = int(n ** (1 / k)) + 2\r\n while r - l > 1:\r\n m = (l + r) // 2\r\n if m ** k <= n:\r\n l = m\r\n else:\r\n r = m\r\n return l\r\ndef s(n, k):\r\n l = 0\r\n r = len(step[k])\r\n while r - l > 1:\r\n m = (l + r) // 2\r\n if step[k][m] <= n:\r\n l = m\r\n else:\r\n r = m\r\n return l\r\nstep = [[] for i in range(61)]\r\nfor i in range(6, 61):\r\n l = 1\r\n while l ** i <= 10 ** 18:\r\n step[i].append(l ** i)\r\n l += 1\r\n for j in range(l, l + 4):\r\n step[i].append(j ** i)\r\na = [2, 3, 5, 30, 7, 42, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59]\r\nb = [6, 10, 15, 14, 21, 35, 22, 33, 55, 26, 39, 34, 51, 38, 57, 46, 58]\r\nfor __ in range(int(input())):\r\n l, r = [int(xx) for xx in input().split()]\r\n l -= 1\r\n ans = 0\r\n for i in range(len(b)):\r\n if b[i] >= 6:\r\n ans -= s(r, b[i])\r\n else:\r\n ans -= s1(r, b[i])\r\n for i in range(len(a)):\r\n if a[i] >= 6:\r\n ans += s(r, a[i])\r\n else:\r\n ans += s1(r, a[i])\r\n for i in range(len(b)):\r\n if b[i] >= 6:\r\n ans += s(l, b[i])\r\n else:\r\n ans += s1(l, b[i])\r\n for i in range(len(a)):\r\n if a[i] >= 6:\r\n ans -= s(l, a[i])\r\n else:\r\n ans -= s1(l, a[i])\r\n if not l:\r\n print(ans - 2)\r\n else:\r\n print(ans)\r\n" ]
{"inputs": ["6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000", "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770"], "outputs": ["2\n1\n0\n3\n17\n1111", "1\n4\n5\n6\n14\n32\n20\n9\n0\n2\n1\n1\n6\n4\n4\n15\n26\n2\n2\n4"]}
UNKNOWN
PYTHON3
CODEFORCES
2
1d43ed69859cb281bfafbf1d2a06eb3f
Promocodes with Mistakes
During a New Year special offer the "Sudislavl Bars" offered *n* promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ. As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum *k*, that the promotional code could be uniquely identified if it was typed with no more than *k* errors. At that, *k*<==<=0 means that the promotional codes must be entered exactly. A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits. The first line of the output contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of promocodes. Each of the next *n* lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0". Print the maximum *k* (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most *k* mistakes. Sample Input 2 000000 999999 6 211111 212111 222111 111111 112111 121111 Sample Output 2 0
[ "n=int(input())\r\nl=[input() for i in range(n)]\r\nprint(min([sum(a!=b for a,b in zip(l[i],l[j]))-1 for i in range(n) for j in range(i+1,n)]+[12])//2)", "s, r = [13], range(int(input()))\r\nt = [input() for i in r]\r\nfor i in r: s += [sum(x != y for x, y in zip(t[i], t[j])) for j in r[i + 1:]]\r\nprint(min(s) - 1 >> 1)", "n = int(input())\r\npromo = [input() for _ in range(n)]\r\nk = 6\r\nfor i in range(n):\r\n for j in range(i + 1, n):\r\n c = sum(1 for r in range(6) if promo[i][r] != promo[j][r])\r\n tmp = (c - 1) // 2\r\n k = min(k, tmp)\r\nprint(k)# 1691760217.7491696", "n = int(input())\ncodes = [tuple(input()) for i in range(n)]\nmind = 13 #Dirty hack for n=1\nfor i in range(n-1):\n for j in range(i+1, n):\n d = sum(x!=y for x,y in zip(codes[i], codes[j]))\n if d<mind:\n mind = d\nprint((mind-1)//2)", "#Here u can check fast your code!\r\ndef main():\r\n\tdef checcker(x, y):\r\n\t\tp = 0\r\n\t\tfor mkT in range(6):\r\n\t\t\tif x[mkT]==y[mkT]:\r\n\t\t\t\tp=p+1\r\n\t\treturn p\r\n\tdef first_funct():\r\n\t\tkList = []\r\n\t\tx = int(input())\r\n\t\tk = 0\r\n\t\tfor i in range(x):\r\n\t\t\tkList.append(input())\r\n\t\tfor fmN in range(x-1):\r\n\t\t\tfor KKT in range(fmN+1,x):\r\n\t\t\t\tp = checcker(kList[fmN], kList[KKT])\r\n\t\t\t\tif p>k:\r\n\t\t\t\t\tk = p\r\n\t\t\t\tif k>=4:\r\n\t\t\t\t\tbreak\r\n\t\t\tif k>=4:\r\n\t\t\t\tbreak\r\n\t\tif x!=1:\r\n\t\t\tif k>=4: #2, 1, 0\r\n\t\t\t\tprint('0')\r\n\t\t\telif k==3 or k==2: #3 5\r\n\t\t\t\tprint('1')\r\n\t\t\telif k==1 or k==0:\r\n\t\t\t\tprint('2')\r\n\t\telse:\r\n\t\t\tprint(6)\r\n\tfirst_funct()\r\nmain()", "#!/usr/bin/python3\n\ndef dist(str1, str2):\n\tk = 0\n\tfor i in range(6):\n\t\tif str1[i] != str2[i]:\n\t\t\tk += 1\n\n\treturn k\n\ndef solve(promos):\n\tn = len(promos)\n\n\tdist_list = [0,0,0,1,1,2,2]\n\tmin_k = 6\n\n\tfor i in range(n):\n\t\tfor j in range(i+1, n):\n\t\t\td = dist(promos[i], promos[j])\n\n\t\t\tk = dist_list[d]\n\t\t\tif k < min_k: min_k = k\n\t\t\tif k == 0: break\n\n\treturn min_k\n\n\ndef test():\n\timport random\n\timport string\n\timport time\n\n\twhile True:\n\t\tn = 1000\n\t\tpromos = []\n\t\tfor i in range(n):\n\t\t\tpromo = ''.join([random.choice(string.digits) for i in range(6)])\n\t\t\tpromos.append(promo)\n\n\t\tif len(set(promos)) == n:\n\t\t\tbreak\n\n\tstart = time.clock()\n\tk = solve(promos)\n\tprint(k)\n\tend = time.clock()\n\n\tprint('Time: {} sec'.format(end-start))\n\n\ndef main():\n\tn = int(input())\n\tpromos = [None]*n\n\tfor i in range(n):\n\t\tpromos[i] = input()\n\n\tk = solve(promos)\n\n\tprint(k)\n\n\nif __name__ == '__main__':\n\t# test()\n\tmain()\n", "n = int(input())\n\ncodes = []\nfor _ in range(n):\n codes.append(input())\n\nmx = 13\nfor i in range(1, n):\n for j in range(i):\n c = sum([1 if codes[i][l] != codes[j][l] else 0 for l in range(6)])\n mx = min(c, mx)\nprint((mx - 1) // 2)", "ans = 12\r\nl=[input() for i in range(int(input()))]\r\nfor i in range(len(l)):\r\n\tfor j in range(i+1,len(l)):\r\n\t\td=0\r\n\t\tfor w in range(6):\r\n\t\t\td+= l[i][w] != l[j][w]\r\n\t\tans=min(d-1,ans)\r\nprint(ans//2)", "n=int(input())\r\na=list(map(lambda i:input(),range(n)))\r\nm=13\r\nfor i in range(n):\r\n for j in range(i+1,n):\r\n m=min(m,sum(a[i][k]!=a[j][k] for k in range(6)))\r\nprint((m-1)//2)\r\n", "def cmp(o1, o2):\r\n result = 0\r\n for i in range(6):\r\n if o1[i] != o2[i]:\r\n result += 1\r\n return result\r\n\r\ncount = int(input())\r\nlst = []\r\nfor i in range(count):\r\n lst += [str(input())]\r\nif count == 1:\r\n print(6)\r\n exit()\r\n\r\ndiv = 6\r\nfor n in range(1, count):\r\n for i in range(n-1, -1, -1):\r\n div = min(div, cmp(lst[n], lst[i]))\r\n if div <= 2:\r\n print(0)\r\n exit()\r\nif div >= 5:\r\n print(2)\r\nelif div >= 3:\r\n print(1)\r\n\r\n", "\ncount = int(input())\n\nif count == 1:\n print('6')\nelse:\n hamming = 6\n codes = []\n for _ in range(count):\n new_code = input()\n for code in codes:\n distance = 0\n distance += 0 if new_code[0] == code[0] else 1\n distance += 0 if new_code[1] == code[1] else 1\n distance += 0 if new_code[2] == code[2] else 1\n distance += 0 if new_code[3] == code[3] else 1\n distance += 0 if new_code[4] == code[4] else 1\n distance += 0 if new_code[5] == code[5] else 1\n\n hamming = min(hamming, distance)\n\n codes.append(new_code)\n\n print(int(hamming/2 - 0.5))\n", "import operator\r\nimport itertools\r\nn = int(input())\r\nstrings = [input() for i in range(n)]\r\nif n == 1:\r\n print(6)\r\nelse:\r\n minDiff = 6;\r\n for a, b in itertools.combinations(strings, 2):\r\n minDiff = min(minDiff, list(map(operator.eq, a, b)).count(False))\r\n print(int((minDiff - 1) / 2))", "l=[];s=12\r\nfor i in range(int(input())):\r\n y=input()\r\n s=min({sum(a!=b for a,b in zip(x,y))-1 for x in l}|{s})\r\n l+=[y]\r\nprint(s//2)", "n = int(input())\ncodes = [input() for i in range(n)]\ndef dist(w1, w2):\n assert len(w1) == len(w2)\n d = 0\n for i in range(len(w1)):\n if w1[i] != w2[i]: d += 1\n return max(0, (d-1)//2)\nd = 6\nfor i in range(n):\n for j in range(i+1, n):\n d = min(d, dist(codes[i], codes[j]))\nprint(d)\n", "def mp(): return map(int,input().split())\r\ndef lt(): return list(map(int,input().split()))\r\ndef pt(x): print(x)\r\ndef ip(): return input()\r\ndef it(): return int(input())\r\ndef sl(x): return [t for t in x]\r\ndef spl(x): return x.split()\r\ndef aj(liste, item): liste.append(item)\r\ndef bin(x): return \"{0:b}\".format(x)\r\n\r\ndef dist(s,t):\r\n c = 0\r\n for i in range(6):\r\n if s[i] != t[i]:\r\n c += 1\r\n return c\r\nn = it()\r\nL = []\r\nfor i in range(n):\r\n L.append(ip())\r\nmindist = 13\r\nfor i in range(n-1):\r\n for j in range(i+1,n):\r\n mindist = min(mindist,dist(L[i],L[j]))\r\nprint((mindist+1)//2-1)" ]
{"inputs": ["2\n000000\n999999", "6\n211111\n212111\n222111\n111111\n112111\n121111", "1\n123456", "2\n000000\n099999", "2\n000000\n009999", "2\n000000\n000999", "2\n000000\n000099", "2\n000000\n000009", "1\n000000", "1\n999999", "10\n946965\n781372\n029568\n336430\n456975\n119377\n179098\n925374\n878716\n461563", "10\n878711\n193771\n965021\n617901\n333641\n307811\n989461\n461561\n956811\n253741", "10\n116174\n914694\n615024\n115634\n717464\n910984\n513744\n111934\n915684\n817874", "10\n153474\n155468\n151419\n151479\n158478\n159465\n150498\n157416\n150429\n159446", "10\n141546\n941544\n141547\n041542\n641545\n841547\n941540\n741544\n941548\n641549", "10\n114453\n114456\n114457\n114450\n114459\n114451\n114458\n114452\n114455\n114454", "5\n145410\n686144\n859775\n922809\n470967", "9\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652", "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "20\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832", "50\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173", "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "10\n234531\n597023\n859775\n063388\n701652\n686144\n470967\n145410\n318298\n922809", "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "10\n145410\n686144\n859775\n922809\n470967\n234531\n597023\n318298\n701652\n063386", "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "58\n114788\n281502\n080213\n093857\n956352\n501424\n512092\n145410\n673001\n128551\n594100\n396463\n758447\n133173\n411841\n538266\n908733\n318920\n872248\n720334\n055121\n691385\n160045\n232727\n947198\n452683\n443254\n859775\n583935\n470967\n742565\n766870\n799299\n061796\n817406\n377719\n034349\n303546\n254914\n635832\n686144\n806017\n295078\n246631\n569318\n831650\n600679\n207280\n325695\n774622\n922809\n975584\n019664\n667953\n189826\n984471\n868189\n364237", "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482", "58\n145410\n686144\n766870\n859775\n922809\n470967\n034349\n318920\n019664\n667953\n295078\n908733\n691385\n774622\n325695\n443254\n817406\n984471\n512092\n635832\n303546\n189826\n128551\n720334\n569318\n377719\n281502\n956352\n758447\n207280\n583935\n246631\n160045\n452683\n594100\n806017\n232727\n673001\n799299\n396463\n061796\n538266\n947198\n055121\n080213\n501424\n600679\n254914\n872248\n133173\n114788\n742565\n411841\n831650\n868189\n364237\n975584\n023482"], "outputs": ["2", "0", "6", "2", "1", "1", "0", "0", "6", "6", "1", "1", "0", "0", "0", "0", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "1", "1", "1", "1", "1", "2", "2", "2", "2", "2"]}
UNKNOWN
PYTHON3
CODEFORCES
15
1d8453764c751d2f477673148a740919
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw *n* distinct points and *m* segments on the *OX* axis. He can draw each point with either red or blue. The drawing is good if and only if the following requirement is met: for each segment [*l**i*,<=*r**i*] consider all the red points belong to it (*r**i* points), and all the blue points belong to it (*b**i* points); each segment *i* should satisfy the inequality |*r**i*<=-<=*b**i*|<=≤<=1. Iahub thinks that point *x* belongs to segment [*l*,<=*r*], if inequality *l*<=≤<=*x*<=≤<=*r* holds. Iahub gives to you all coordinates of points and segments. Please, help him to find any good drawing. The first line of input contains two integers: *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=100). The next line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100) — the coordinates of the points. The following *m* lines contain the descriptions of the *m* segments. Each line contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=100) — the borders of the *i*-th segment. It's guaranteed that all the points are distinct. If there is no good drawing for a given test, output a single integer -1. Otherwise output *n* integers, each integer must be 0 or 1. The *i*-th number denotes the color of the *i*-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them. Sample Input 3 3 3 7 14 1 5 6 10 11 15 3 4 1 2 3 1 2 2 3 5 6 2 2 Sample Output 0 0 01 0 1
[ "n, m = map(int, input().split())\nt = list(enumerate(list(map(int, input().split()))))\nt.sort(key=lambda x: x[1])\np = ['0' for i in range(n)]\nfor i, x in t[::2]:\n\tp[i] = '1'\nprint(' '.join(p))\n", "n, m = map(int, input().split())\r\nc = list(map(int, input().split()))\r\ncc = c.copy()\r\nd = []\r\nfor i in range(m):\r\n input()\r\n\r\noutput = []\r\ncc.sort()\r\nfor i in c:\r\n index = cc.index(i)\r\n if index % 2 == 0:\r\n output.append(\"0\")\r\n else:\r\n output.append(\"1\")\r\n\r\nprint(\" \".join(output))\r\n", "n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx = sorted([[x[i], i] for i in range(n)])\nfor i in range(n):\n x[i].append(i % 2)\nx.sort(key=lambda el: el[1])\nprint(*map(lambda el: el[2], x))\n", "import sys\nread = lambda t=int:list(map(t,sys.stdin.readline().split()))\n_, M = read()\nxs = read()\nfor _ in range(M):\n _ = read()\n\nxs = sorted((x,i) for i,x in enumerate(xs))\nxs = sorted((i,j) for j,(x,i) in enumerate(xs))\nprint(\" \".join(str(j%2) for _,j in xs))\n", "input()\r\nP=list(map(int,input().split()))\r\nl=sorted([[P.index(p),i%2] for i,p in enumerate(sorted(P))])\r\nfor a,b in l:print(b)", "def f(a, q):\r\n\r\n\tpath=[-1]*(max(a)+1)\r\n\tans=[0]*len(a)\r\n\tq.sort()\r\n\tq.sort(key=lambda s:s[1]-s[0],reverse=True)\r\n\ta=list(zip(range(len(a)),a))\r\n\ta=sorted(a,key=lambda s:s[1])\r\n\tres=0\r\n\tfor id,val in a:\r\n\t\tans[id]=res\r\n\t\tres^=1\r\n\treturn ans\r\n\r\nn,m=map(int,input().strip().split())\r\nq=[]\r\na=[*map(int,input().strip().split())]\r\nfor i in range(m):\r\n\tl, r = map(int, input().strip().split())\r\n\tq.append((l,r))\r\nprint(*f(a,q))", "n,m = map(int,input().split())\nX = [int(x) for x in input().split()]\nsegs = [[int(x) for x in input().split()] for _ in range(m)]\n\nD = {e:i%2 for i,e in enumerate(sorted(X))}\n\nfor i in range(n):\n X[i] = D[X[i]]\nprint(*X)\n", "a, b = map(int, input().split(' '))\r\npts = list(map(int, input().split(' ')))\r\npts2 = [[pts[i], i, 0] for i in range(len(pts))]\r\npts2.sort()\r\nfor i in range(1, a, 2):\r\n pts2[i][2] = 1\r\n \r\npts2.sort(key = lambda x:x[1])\r\nstring = ''\r\nfor i in pts2:\r\n string += str(i[2])\r\n string += ' '\r\n\r\nprint(string.strip())\r\n", "\r\nN,M = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nB = []\r\nfor _ in range(M):\r\n a,b = map(int, input().split())\r\n B.append((a,b))\r\n \r\nB = []\r\nfor i,a in enumerate(A):\r\n B.append((a,i))\r\n \r\nB.sort()\r\n \r\nans = [0]*N\r\nfor i,(a,j) in enumerate(B):\r\n ans[j] = i%2\r\nprint(*ans)", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nfor i in range(n):\r\n arr[i] = (arr[i], i)\r\narr.sort()\r\nres = [0] * n\r\nfor i in range(n):\r\n res[arr[i][1]] = i % 2\r\nprint(*res)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nw = [str(i[1]) for i in sorted([(j[1], i%2) for i, j in enumerate(sorted([(j, i) for i, j in enumerate(map(int, input().split()))]))])]\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n\r\nprint(' '.join(w))", "import sys\r\nimport math\r\nimport random\r\nn, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = sorted(a)\r\nfor i in range(len(a)):\r\n for j in range(len(b)):\r\n if a[i] == b[j]:\r\n if j % 2 == 0:\r\n print('1 ', end = '')\r\n else:\r\n print('0 ', end = '')\r\n ", "def main():\r\n a = input()\r\n b = [int(i) for i in input().split()]\r\n n = len(b)\r\n c = [(i, index) for index, i in enumerate(b)]\r\n c.sort()\r\n res = [0]*n\r\n flag = 0\r\n for i, j in c:\r\n res[j] = flag\r\n flag ^= 1\r\n print(\" \".join(str(i) for i in res))\r\n\r\n\r\n\r\nmain()\r\n", "import operator as a\r\ninput()\r\nl = sorted([[p,i,0] for i,p in enumerate (map(int,input().split()))])\r\nfor i in range(len(l)):l[i][2]=i%2\r\nl.sort(key=a.itemgetter(1))\r\nprint(' '.join ([str(ll[2]) for ll in l]))", "n,m=map(int,input().split())\r\n\r\nL=list(map(int,input().split()))\r\n\r\nfor i in range(n):\r\n L[i]=(L[i],i)\r\nL.sort()\r\nAns=[0]*n\r\nfor i in range(n):\r\n Ans[L[i][1]]=i%2\r\nfor i in range(n):\r\n print(Ans[i],end=\" \")\r\n", "import fileinput\n\ndef solve(n, m, p, s):\n\tz = [(x, i) for i, x in enumerate(p)]\n\tz = [(i, j%2) for j, (x, i) in enumerate(sorted(z))]\n\treturn [c for i, c in sorted(z)]\n\nf = fileinput.input()\nn, m = tuple(map(int, f.readline().rstrip().split()))\np = list(map(int, f.readline().rstrip().split()))\ns = [tuple(map(int, f.readline().rstrip().split())) for _ in range(m)]\nprint(\" \".join(map(str, solve(n, m, p, s))))", "# Made By Mostafa_Khaled \nbot = True \ninput()\nP=list(map(int,input().split()))\nfor a,b in sorted([[P.index(p),i%2]for i,p in enumerate(sorted(P))]):print(b)\n\n\n# Made By Mostafa_Khaled", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nres=[]\r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\n res.append((a,b))\r\n\r\nz=[(el,i) for i,el in enumerate(arr)]\r\nz.sort()\r\nans=[0]*n\r\np=0\r\nfor i in range(n):\r\n ans[z[i][1]]=p\r\n p=(p+1)%2\r\nprint(*ans)\r\n ", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = []\r\nfor i in range(n):\r\n b.append((a[i], i))\r\nb.sort()\r\nfor i in range(n):\r\n b[i] = b[i][0], b[i][1], i % 2\r\nc = []\r\nfor i in b:\r\n c.append((i[1], i[0], i[2]))\r\nc.sort()\r\nfor i in c:\r\n print(i[2], end = ' ')", "n, m = map(int, input().split())\r\nxs = list(map(int, input().split()))\r\nys = sorted(range(n), key=xs.__getitem__)\r\nzs = sorted((ys[i], i % 2) for i in range(n))\r\nprint(*(z[1] for z in zs))", "R = lambda: list(map(int, input().split()))\r\n\r\nn, m = R()\r\n\r\na = R()\r\nexist = [False for i in range(200)]\r\n\r\nfor i in range(m):\r\n l, r = R()\r\n for j in a:\r\n if l <= j <= r:\r\n exist[j] = True\r\n\r\nb = a[:]\r\nb.sort()\r\nans = [0 for i in range(200)]\r\n\r\nflag = 0\r\nfor i in b:\r\n if exist[i]:\r\n ans[i]=flag\r\n flag ^= 1\r\n\r\nfor i in a:\r\n print(ans[i], end=' ')", "n, m = map(int, input().split())\r\npoints = list(map(int, input().split()))\r\nsegments = [input().split() for _ in range(m)]\r\nsorted_points = sorted(points)\r\nans = [-1] * n\r\n\r\nfor i in range(n):\r\n c = '0' if i % 2 else '1'\r\n ans[points.index(sorted_points[i])] = c\r\n\r\nprint(' '.join(ans))\r\n", "n, m = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nb = sorted([[a[i], i] for i in range(n)])\r\nfor i in range(m):\r\n l, r = map(int, input().split())\r\nfor i in range(n):\r\n a[b[i][1]] = str(i%2) \r\nprint(' '.join(a))", "from operator import *\r\nR = lambda: map(int, input().split())\r\nn, m = R()\r\nx = sorted(enumerate(R()), key=itemgetter(1))\r\ny = [0] * n\r\nfor i in range(n):\r\n y[x[i][0]] = i % 2\r\nprint(' '.join(map(str, y)))", "n, m = map(int, input().split())\npoints = list(zip(map(int, input().split()), range(n)))\n\npoints.sort()\n\nres = []\ncurr = 0\nfor point in points:\n\tres.append((point[1], (curr + 1) % 2))\n\tcurr += 1\nres.sort()\n\nfor point in res:\n\tprint(point[1], end=' ')", "n, m = map(int, input().split())\r\np = sorted((x[1], x[0]) for x in enumerate(map(int, input().split())))\r\np = sorted((x[1], str(i % 2)) for i, x in enumerate(p))\r\nprint(' '.join(x[1] for x in p))", "n,m=list(map(int,input().split()))\npoints = [(v,i) for i,v in enumerate(map(int,input().split()))]\nfor _ in range(m):\n input()\nblue=True\nans=[0]*n\npoints = sorted(points)\nfor p in points:\n v,i = p\n ans[i] = int(blue)\n blue=not blue\nfor v in ans:\n print(v,end=' ')\nprint()\n", "input()\nP=list(map(int,input().split()))\nfor a,b in sorted([[P.index(p),i%2]for i,p in enumerate(sorted(P))]):print(b)", "n, m = map(int, input().split())\r\nt = list(enumerate(list(map(int, input().split()))))\r\nt.sort(key = lambda x: x[1])\r\np = ['0'] * n\r\nfor i, x in t[:: 2]: p[i] = '1'\r\nprint(' '.join(p))" ]
{"inputs": ["3 3\n3 7 14\n1 5\n6 10\n11 15", "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "10 10\n3 4 2 6 1 9 0 5 8 7\n5 7\n2 6\n0 1\n5 6\n3 4\n2 5\n2 10\n4 6\n3 6\n3 7", "3 3\n50 51 52\n1 5\n6 10\n11 15", "3 1\n1 2 3\n2 3"], "outputs": ["0 0 0", "1 0 1 ", "0 1 1 1 0 0 1 0 1 0 ", "1 0 1 ", "1 0 1 "]}
UNKNOWN
PYTHON3
CODEFORCES
29
1d95be69ba194a67b9185fef152c655f
Army Creation
As you might remember from our previous rounds, Vova really likes computer games. Now he is playing a strategy game known as Rage of Empires. In the game Vova can hire *n* different warriors; *i*th warrior has the type *a**i*. Vova wants to create a balanced army hiring some subset of warriors. An army is called balanced if for each type of warrior present in the game there are not more than *k* warriors of this type in the army. Of course, Vova wants his army to be as large as possible. To make things more complicated, Vova has to consider *q* different plans of creating his army. *i*th plan allows him to hire only warriors whose numbers are not less than *l**i* and not greater than *r**i*. Help Vova to determine the largest size of a balanced army for each plan. Be aware that the plans are given in a modified way. See input section for details. The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100000). The second line contains *n* integers *a*1, *a*2, ... *a**n* (1<=≤<=*a**i*<=≤<=100000). The third line contains one integer *q* (1<=≤<=*q*<=≤<=100000). Then *q* lines follow. *i*th line contains two numbers *x**i* and *y**i* which represent *i*th plan (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*). You have to keep track of the answer to the last plan (let's call it *last*). In the beginning *last*<==<=0. Then to restore values of *l**i* and *r**i* for the *i*th plan, you have to do the following: 1. *l**i*<==<=((*x**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. *r**i*<==<=((*y**i*<=+<=*last*) *mod* *n*)<=+<=1; 1. If *l**i*<=&gt;<=*r**i*, swap *l**i* and *r**i*. Print *q* numbers. *i*th number must be equal to the maximum size of a balanced army when considering *i*th plan. Sample Input 6 2 1 1 1 2 2 2 5 1 6 4 3 1 1 2 6 2 6 Sample Output 2 4 1 3 2
[ "class segtree():\r\n def __init__(self,init,func,ide):\r\n self.n=len(init)\r\n self.func=func\r\n self.ide=ide\r\n self.size=1<<(self.n-1).bit_length()\r\n self.tree=[self.ide for i in range(2*self.size)]\r\n for i in range(self.n):\r\n self.tree[self.size+i]=init[i]\r\n for i in range(self.size-1,0,-1):\r\n self.tree[i]=self.func(self.tree[2*i], self.tree[2*i|1])\r\n \r\n def update(self,k,x):\r\n k+=self.size\r\n self.tree[k]=x\r\n k>>=1\r\n while k:\r\n self.tree[k]=self.func(self.tree[2*k],self.tree[k*2|1])\r\n k>>=1\r\n \r\n def get(self,i):\r\n return self.tree[i+self.size]\r\n \r\n def query(self,l,r):\r\n L=l\r\n l+=self.size\r\n r+=self.size\r\n ans=0\r\n while l<r:\r\n if l&1:\r\n ans+=count(self.tree[l],L)\r\n l+=1\r\n if r&1:\r\n r-=1\r\n ans+=count(self.tree[r],L)\r\n l>>=1\r\n r>>=1\r\n return ans\r\n \r\n def debug(self,s=10):\r\n print([self.get(i) for i in range(min(self.n,s))])\r\n\r\ndef op(x,y):\r\n return sorted(x+y)\r\n\r\nimport bisect\r\ndef count(arr,x):\r\n return bisect.bisect_left(arr,x)\r\n\r\nfrom sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,k=map(int,input().split())\r\na=list(map(lambda x:int(x)-1,input().split()))\r\nidx=[[] for i in range(10**5)]\r\nb=[0]*n\r\nfor i in range(n):\r\n if len(idx[a[i]])<k:\r\n b[i]=-1\r\n else:\r\n b[i]=idx[a[i]][-k]\r\n idx[a[i]].append(i)\r\n\r\nseg=segtree([[i] for i in b],op,[])\r\nlst=0\r\nq=int(input())\r\nfor _ in range(q):\r\n x,y=map(int,input().split())\r\n l=(x+lst)%n\r\n r=(y+lst)%n\r\n if l>r:\r\n l,r=r,l\r\n ans=seg.query(l,r+1)\r\n print(ans)\r\n lst=ans" ]
{"inputs": ["6 2\n1 1 1 2 2 2\n5\n1 6\n4 3\n1 1\n2 6\n2 6", "5 5\n3 4 4 2 1\n5\n5 5\n5 4\n5 4\n3 4\n5 5", "5 5\n2 1 2 4 1\n5\n5 3\n1 1\n5 1\n2 1\n2 3", "10 5\n4 5 7 3 5 6 6 8 10 9\n5\n10 8\n9 8\n7 5\n8 10\n5 8", "20 5\n9 5 4 10 2 1 8 9 7 4 1 5 4 9 8 10 5 8 4 10\n5\n9 13\n17 13\n6 12\n13 11\n8 8", "100 5\n45 51 23 10 62 69 48 47 47 59 58 14 54 34 66 78 92 66 42 25 96 68 35 50 58 77 87 100 57 42 43 76 24 70 26 98 33 11 41 9 17 65 53 23 45 5 24 98 73 91 92 73 51 68 82 95 24 61 88 3 64 74 28 7 77 49 55 62 64 4 51 86 72 26 65 82 13 55 31 44 10 59 83 16 27 67 2 36 52 12 3 26 36 38 58 25 23 3 69 16\n5\n13 49\n86 62\n91 77\n84 50\n33 66", "1 1\n1\n1\n1 1", "1 5\n8\n9\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "5 1\n10 7 6 6 6\n8\n5 2\n4 5\n2 1\n5 2\n3 1\n3 1\n4 1\n5 2"], "outputs": ["2\n4\n1\n3\n2", "1\n2\n2\n2\n1", "4\n1\n2\n2\n5", "9\n2\n3\n3\n8", "5\n17\n7\n19\n1", "37\n77\n15\n35\n68", "1", "1\n1\n1\n1\n1\n1\n1\n1\n1", "3\n1\n1\n2\n3\n2\n2\n1"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1dab00c247d5b6f4504eecd845bdc5a9
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three. He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes). Implement this feature to help Polycarp test his editor. The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome. Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above. Sample Input 3 2 .*. .*. 9 20 **....... ****..... ******... *******.. ..******. ....****. ......*** *.....*** ********* ********* ********* ********* ....**... ...****.. ..******. .******** ****..*** ***...*** **.....** *.......* Sample Output .... .... **** **** .... .... ********......**********........******** ********......**********........******** ********........********......********.. ********........********......********.. ..********......********....********.... ..********......********....********.... ..********......********..********...... ..********......********..********...... ....********....****************........ ....********....****************........ ....********....****************........ ....********....****************........ ......******************..**********.... ......******************..**********.... ........****************....**********.. ........****************....**********.. ............************......********** ............************......**********
[ "w, h = map(int, input().split())\r\na = []\r\nfor i in range(h):\r\n a.append(list(input()))\r\nb = [[0 for j in range(h)] for i in range(w)] \r\nfor i in range(h):\r\n for j in range(w):\r\n b[j][i] = a[i][j] \r\nfor i in range(w):\r\n x = ''\r\n for j in range(h):\r\n x = x + b[i][j] + b[i][j]\r\n print(x)\r\n print(x)\r\n ", "w,h = input().split()\nw,h = int(w),int(h)\nS = []\nfor i in range(0,h):\n ts = input()\n S += [ts]\nfor i in range(0,2*w):\n idxi = i // 2\n tans = \"\"\n for j in range(0,2*h):\n idxj = j // 2\n tans += S[idxj][idxi]\n print(tans)\n", "w, h = map(int, input().split())\r\nfile = [[] for i in range(w)]\r\n\r\nfor i in range(h):\r\n l = list(input())\r\n for j in range(w):\r\n file[j].append(l[j])\r\n\r\nfor i in range(w):\r\n print(''.join([c*2 for c in file[i]]))\r\n print(''.join([c*2 for c in file[i]]))", "w,h = map(int,input().split())\r\nl = []\r\nfor i in range(h):\r\n s = input()\r\n l.append(s)\r\nfor i in range(w):\r\n s =''\r\n for j in range(h-1,-1,-1):\r\n s += l[j][i]*2\r\n s = s[::-1]\r\n print(s)\r\n print(s)", "import sys\r\nw,h = map(int,sys.stdin.readline().split())\r\nizn=[\"\"]*h\r\nfor i in range(h):\r\n izn[i]=input()\r\nnov=[\"\"]*w\r\nfor i in range(0,w):\r\n for j in range(h-1,-1,-1):\r\n nov[i] += izn[j][i]\r\n nov[i]=nov[i][::-1]\r\n g=\"\"\r\n for j in range(h):\r\n g+= (nov[i][j])*2\r\n for i in range(2):\r\n print(g)", "w, h = map(int, input().split())\r\na = [ ]\r\nfor i in range(h):\r\n a.append(input())\r\na = [\"\".join(a[j][i] for j in range(h)) for i in range(w)]\r\nfor row in a:\r\n ls = [ ]\r\n for c in row:\r\n ls.extend((c, c))\r\n s = \"\".join(ls)\r\n print(s, s, sep='\\n')\r\n", "w,h = map(int,input().split())\r\nl=[\"\"]*h\r\nfor i in range(h):\r\n l[i]=input()\r\n\r\n\r\n#l=s.split()\r\nn=[\"\"]*w\r\n#ROTATION\r\nfor i in range(0,w):\r\n for x in range(h-1,-1,-1):\r\n n[i] += l[x][i]\r\n n[i]=n[i][::-1]\r\n f=\"\"\r\n for z in range(h):\r\n f+= (n[i][z])*2\r\n print(f)\r\n print(f)\r\n", "inp = str(input()).split(' ')\r\nw, h = int(inp[0]), int(inp[1])\r\nimage = []\r\nfor x in range(h):\r\n row = str(input())\r\n image.append([x for x in row])\r\n\r\n\r\ndef turn90():\r\n turned = []\r\n for x in range(w):\r\n row = []\r\n for y in range(h):\r\n row.append(image[y][x])\r\n turned.append(row)\r\n return turned\r\n\r\nimage = turn90()\r\n\r\ndef mirror():\r\n mirroed = []\r\n for row in image:\r\n row.reverse()\r\n mirroed.append(row)\r\n return mirroed\r\n\r\ndef multiply():\r\n multi = []\r\n for row in image:\r\n multi.append(''.join([y * 2 for y in row]))\r\n multi.append(''.join([y * 2 for y in row]))\r\n for row in multi:\r\n print(''.join(row))\r\n\r\nmultiply()", "w, h = map( int, input( ).split( ) )\nstgs = [ ]\n\nfor i in range( h ):\n stgs.append( input( ) )\n\nm = [0] * h\nfor i in range(h):\n m[i] = [0] * w\n\nfor i in range( h ):\n for j in range( w ):\n m[ i ][ j ] = stgs[ i ][ j ]\n\nfor i in range( h ):\n m[ i ].reverse( )\n\nsk = 1\nst = \"\"\n\nfor i in range( w - 1, -1, -1 ):\n for j in range( h ):\n st += m[ j ][ i ] + m[ j ][ i ]\n print( st, st, sep = '\\n' )\n st = ''\n", "\r\nw, h = map(int, input().split())\r\nl = [[] for _ in range(w)]\r\nfor _ in range(h):\r\n\tip = input()\r\n\tfor i in range(w):\r\n\t\tl[i].append(ip[i])\r\n\r\n\r\nans = []\r\nfor i in range(w):\r\n\ttarget = l[i]\r\n\tetc = []\r\n\tfor j in target:\r\n\t\tetc.append(j * 2)\r\n\r\n\tans.append(etc)\r\n\tans.append(etc)\r\n\r\n\r\nfor i in ans:\r\n\tprint(*i, sep = '')", "a, b = [int(x) for x in input().split()]\r\nz = a * b\r\nc = []*z\r\n \r\nfor i in range(0, b):\r\n c += [[*str(input())]]\r\n \r\nfor i in range(0, a):\r\n for j in range(0, 2):\r\n for k in range(0, b):\r\n for l in range(0, 2):\r\n print(c[k][i],end=\"\")\r\n print(\"\")", "n, m = list(map(int, input().split())) \r\n\r\ndata = [list(input()) for i in range(m)] \r\n\r\ndata_transp = [[''] * m for i in range(n)] \r\n\r\nfor i in range(n): \r\n for j in range(m): \r\n data_transp[i][j] = data[m - j - 1][i] \r\n\r\ndata_mirror = [[''] * m for i in range(n)] \r\n\r\nfor i in range(n): \r\n for j in range(m): \r\n data_mirror[i][j] = data_transp[i][m - j - 1] \r\n\r\ndata_large = [[''] * (m * 2) for i in range(n * 2)] \r\n\r\nfor i in range(n): \r\n for j in range(m): \r\n data_large[i * 2][j * 2] = data_mirror[i][j] \r\n data_large[i * 2 + 1][j * 2] = data_mirror[i][j] \r\n data_large[i * 2][j * 2 + 1] = data_mirror[i][j] \r\n data_large[i * 2 + 1][j * 2 + 1] = data_mirror[i][j] \r\n\r\nfor i in range(2 * n): \r\n data_large[i] = ''.join(data_large[i]) \r\n\r\nprint('\\n'.join(data_large)) \r\n", "w, h = [int(i) for i in input().split()]\nbitmap = [list(input()) for i in range(h)]\n\nbitmap = [[bitmap[i // 2][j // 2] for i in range(2 * h)] for j in range(2 * w)]\n\nprint('\\n'.join(''.join(i) for i in bitmap))\n", "n = input().split()\r\nold = []\r\nnew = []\r\nfor i in range(int(n[1])):\r\n\told.append(list(input()))\r\nfor i in range(int(n[0])):\r\n\tnew.append([])\r\n\tfor j in range(int(n[1])):\r\n\t\tnew[-1].append(old[j][i])\r\n\t\tnew[-1].append(old[j][i])\r\n\tnew.append(new[-1])\r\nfor i in new:\r\n\tprint(''.join(i))", "def function():\r\n\tsize = input().split(' ')\r\n\tw = int(size[0])\r\n\th = int(size[1])\r\n\tif not (1 <= w <= 100) and not (1 <= h <= 100):\r\n\t\treturn None\r\n\tmatrix_result = [[None for j in range(0, 2*h)] for i in range(0, 2*w)]\r\n\t\r\n\tfor i in range(0, h):\r\n\t\tarr = list(input())\r\n\t\tfor j in range(0, w):\r\n\t\t\tmatrix_result[2*j][2*i] = arr[j]\r\n\t\t\tmatrix_result[2*j + 1][2*i] = arr[j]\r\n\t\t\tmatrix_result[2*j][2*i + 1] = arr[j]\r\n\t\t\tmatrix_result[2*j + 1][2*i + 1] = arr[j]\r\n\t\t\t\r\n\tfor i in range(0, 2*w):\r\n\t\tprint(''.join(str(x) for x in matrix_result[i]))\r\n\r\nfunction()", "w,h=(int(x) for x in input().split(' '))\r\nmassive=[]\r\nfor i in range(h):\r\n mass=[]\r\n for elem in input(): \r\n mass.append(elem)\r\n mass.append(elem)\r\n massive.append(mass)\r\n massive.append(mass)\r\n\r\n\r\n \r\nfor i in range(2*w):\r\n for j in range(2*h):\r\n print(massive[j][i],end='')\r\n print()\r\n \r\n", "\nimport sys\n#sys.stdin = open('A.in', 'r')\n\nw, h = (int(x) for x in input().split())\n\n#print(w, h)\n\npic = [['']*2*h for _ in range(2*w)]\n\nfor (i, row) in enumerate(sys.stdin):\n # Just in case\n if not row.strip() or i >= h:\n break\n\n for (j, c) in enumerate(row[:-1]):\n if j >= w:\n continue\n\n pic[2*j][2*i] = c\n pic[2*j][2*i+1] = c\n pic[2*j+1][2*i] = c\n pic[2*j+1][2*i+1] = c\n\n if i == h - 1:\n break\n\nprint('\\n'.join(''.join(row) for row in pic))\n", "m=0\r\nl=input()\r\na=''\r\nb=''\r\nwhile l[m]!= \" \":\r\n a=a+str(l[m])\r\n m+=1\r\na=int(a)\r\nwhile m!=len(l):\r\n b=b+str(l[m])\r\n m+=1\r\n \r\nb=int(b)\r\nh=0\r\nkartina=[]\r\nfor lo in range(b):\r\n o=list(input())\r\n kartina.append(o)\r\nfor k in range (a):\r\n for t in range (b):\r\n \r\n print(kartina[t][k],end=\"\")\r\n print(kartina[t][k],end=\"\")\r\n print() \r\n for t in range (b):\r\n print(kartina[t][k],end=\"\")\r\n print(kartina[t][k],end=\"\")\r\n print() \r\n", "w, h = map(int, input().split())\r\na = [input().strip() for _ in range(h)]\r\na = list(zip(*a[::-1]))\r\na = a[::-1]\r\na = list(zip(*a[::-1]))\r\na = list(zip(*a[::-1]))\r\nfor i in a:\r\n for _ in range(2):\r\n for j in i:\r\n print(j*2,end='')\r\n print()\r\n", "W, H = map( int, input().split() )\r\nmat = [ input() for i in range( H ) ]\r\n \r\nfor i in range( 2 * W ):\r\n print( ''.join( mat[ j // 2 ][ i // 2 ] for j in range( 2 * H ) ) )", "n, m = [int(x) for x in input().split()]\narr = []\nturn = []\nfor i in range(n):\n turn.append([None] * m)\n\nfor i in range(m):\n arr.append(list(input()))\n \nfor i in range(m):\n for j in range(n):\n turn[j][i] = arr[i][n - j - 1]\n\ns = []\nfor i in range(n):\n s.append(list(turn[i]))\n#------------------------------------------\n\n\nfor i in range(m):\n for j in range(n):\n turn[j][i] = s[n - j - 1][i]\n\n\nfor i in range(n):\n for k in range(2):\n for j in range(m):\n print(turn[i][j] * 2, end=\"\")\n print()\n \n\n \n", "'''from typing import List\n\ndef rotate_flip_zoom(w: int, h: int, a: List[str]) -> List[str]:\n new = [ [None] * (2*h) for i in range(2*w)] # create new array to store the image the new dimension is 2h by 2w\n for i in range(h):\n for j in range(w):\n new[2*(w-j-1)+1][2*(h-i-1)+1] = a[i][j]\n new[2*(w-j-1)+1][2*(h-i-1)] = a[i][j]\n new[2*(w-j-1)][2*(h-i-1)+1] = a[i][j]\n new[2*(w-j-1)][2*(h-i-1)] = a[i][j]\n return [''.join(row) for row in new] # concatinate each row\n'''\nfrom typing import List\n\ndef rotate_flip_zoom(w: int, h: int, a: List[str]) -> List[str]:\n new = [ ['.'] * (2*h) for i in range(2*w)] # create new array to store the image the new dimension is 2h by 2w\n for i in range(h):\n for j in range(w):\n new[2*j+1][2*i+1] = a[i][j]\n new[2*j+1][2*i] = a[i][j]\n new[2*j][2*i+1] = a[i][j]\n new[2*j][2*i] = a[i][j]\n return [''.join(row) for row in new] # concatinate each row\nw,h = [int(i) for i in input().split()]\nx = []\nfor i in range(h):\n x.append(list(input()))\ny = rotate_flip_zoom(w, h, x)\nfor i in y:\n print(i)\n", "import sys\n\nw, h = map(int, sys.stdin.readline().split())\ngrid = []\nfor i in range(h):\n grid.append(sys.stdin.readline().strip())\n\nfor j in range(w):\n res = []\n for i in range(h):\n res.append(grid[i][j] * 2)\n sys.stdout.write(''.join(res) + '\\n')\n sys.stdout.write(''.join(res) + '\\n')\n", "n,m=map(int,input().split())\r\na=[]\r\nfor i in range(m):\r\n s = input()\r\n a.append(s)\r\na.reverse()\r\n#print(a)\r\nb=[]\r\n\r\nfor i in range(n):\r\n s=''\r\n for j in range(m):\r\n s+=a[j][i]\r\n b.append(s)\r\n\r\nfor i in b:\r\n val = i[::-1]\r\n for j in val:\r\n print(j*2,end=\"\")\r\n print()\r\n for j in val:\r\n print(j*2,end=\"\")\r\n print()", "\r\n[w,h] = [int(x) for x in input().split()]\r\n\r\nimage = []\r\n\r\nfor i in range(h):\r\n image.append(input())\r\n\r\n\r\nfor x in range(w*2):\r\n for y in range(h*2):\r\n final_x = int(y/2)\r\n final_y = int(x/2)\r\n # print('flipped ', final_x, final_y)\r\n # final_x = int(x/2)\r\n # final_y = int(y/2)\r\n final_x = h - final_x - 1\r\n\r\n # print('flipped ' , final_x, final_y)\r\n\r\n temp_y = final_y\r\n temp_x = final_x\r\n\r\n final_x = temp_y\r\n final_y = h - temp_x - 1\r\n # print(final_x, final_y)\r\n print(image[final_y][final_x],end='')\r\n print('')\r\n\r\n", "import poplib\r\nimport string\r\nimport math\r\n\r\ndef main_function():\r\n w, h = [int(i) for i in input().split(\" \")]\r\n image = [list(input()) for i in range(h)]\r\n new_image = [[] for i in range(w)]\r\n for i in range(w):\r\n for j in range(h):\r\n new_image[i].append(image[j][i])\r\n for i in range(len(new_image) * 2):\r\n new_i = i // 2\r\n for j in range(len(new_image[new_i])):\r\n print(new_image[new_i][j], end=\"\")\r\n print(new_image[new_i][j], end=\"\")\r\n if j == len(new_image[new_i]) - 1:\r\n print()\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n main_function()", "n,m=map(int,input().split())\r\narray=[]\r\narray1=[]\r\narray2=[]\r\nfor i in range(m):\r\n s=input()\r\n array+=[s]\r\nfor j in range(n):\r\n s=''\r\n for i in range(m):\r\n s+=array[i][j]\r\n array1+=[s]\r\n array2+=[s]\r\nq=len(array1)\r\narray=[]\r\nfor i in range(q):\r\n array+=[array1[i]]\r\n array+=[array2[i]]\r\narray1=[]\r\nfor i in range(2*n):\r\n s=''\r\n for j in range(m):\r\n s+=array[i][j]\r\n s+=array[i][j]\r\n array1+=[s]\r\nfor i in range(len(array)):\r\n print(array1[i])\r\n \r\n \r\n ", "[w,h]=[int(x) for x in input().split()]\r\nmatrix_photo=[ [x for x in input()] for y in range(h)]\r\ndef print_matrix(matrix):\r\n for row in matrix:\r\n print(\"\".join(row))\r\n#print_matrix(matrix_photo)\r\ndef rotate(matrix):\r\n h=len(matrix)\r\n w=len(matrix[0])\r\n result=[]\r\n for i in range(w):\r\n column = [matrix[j][i] for j in range(h)]\r\n result.append(column)\r\n return result\r\n\r\nrotated = rotate(matrix_photo)\r\n#print_matrix(rotated)\r\ndef flip(matrix):\r\n h=len(matrix)\r\n w=len(matrix[0])\r\n result=[]\r\n for i in range(h):\r\n row = matrix[i]\r\n new_row = row[::-1]\r\n result.append(new_row)\r\n return result\r\nfliped = flip(rotated)\r\n#print_matrix(fliped)\r\ndef zoom(matrix):\r\n h=len(matrix)\r\n w=len(matrix[0])\r\n result=[]\r\n for row in matrix:\r\n new_row = []\r\n for i in range(w):\r\n new_row.append(row[i])\r\n new_row.append(row[i])\r\n result.append(new_row)\r\n result.append(new_row)\r\n return result\r\nzoomed = zoom(fliped)\r\n#print_matrix(zoomed)\r\nfinal = flip(zoomed)\r\nprint_matrix(final)", "w,h=map(int,input().split())\r\nq,r=[],[\"\"]*w\r\nfor i in range(h):\r\n q.append(list(input()))\r\nfor i in range(w):\r\n for j in range(h):\r\n r[i]+=str(q[j][i])*2\r\nfor i in r:\r\n print(i)\r\n print(i)", "n,m = map(int,input().split(' '))\r\na = [ '' for i in range(m)]\r\nfor i in range(m) :\r\n a[i] = input()\r\n\r\ndef printImage(table) :\r\n for s in table :\r\n ans = ''\r\n for c in s :\r\n ans+=c*2\r\n print(ans)\r\n print(ans)\r\n\r\nb = []\r\nfor i in range(n) :\r\n ans = ''\r\n for s in a : ans+=s[i]\r\n b.append(ans)\r\n\r\nprintImage(b)\r\n \r\n \r\n \r\n \r\n", "__author__ = 'ruckus'\n\nx, y = map(int, input().split())\n\na = []\n\nfor i in range(y):\n a.append(input())\n\nfor i in range(x):\n for k in range(2):\n for j in range(y):\n print(a[j][i], end='')\n print(a[j][i], end='')\n print()", "w, h = [int(i) for i in input().split()]\r\na = []\r\nfor i in range(h):\r\n a.append([])\r\n a[i] = [q for q in input().strip()]\r\nfor i in range(w):\r\n now_str = ''\r\n for q in range(h):\r\n now_str += a[q][i] * 2\r\n print(now_str)\r\n print(now_str)", "w, h = map(int, input().split())\na = []\nfor i in range(h):\n\ta.append(input())\nb = [[None]*(2*h) for _ in range(2*w)]\nfor i in range(w):\n\tfor j in range(h):\n\t\tb[2*i ][2*j ] = a[j][i]\n\t\tb[2*i ][2*j+1] = a[j][i]\n\t\tb[2*i+1][2*j ] = a[j][i]\n\t\tb[2*i+1][2*j+1] = a[j][i]\n\nprint('\\n'.join([''.join(i) for i in b]))", "class Image(object):\r\n def __init__ (self, width, height, stringImage):\r\n self._width = width\r\n self._height = height\r\n self._stringImage = stringImage\r\n self._pixelMatrix = [[]]\r\n \r\n # filling pixel matrix\r\n line = 0 \r\n for i in self._stringImage:\r\n if (i == '\\n'):\r\n self._pixelMatrix.append([])\r\n line+=1\r\n else:\r\n self._pixelMatrix[line].append(i)\r\n \r\n def __str__ (self):\r\n resultedString = ''\r\n for line in self._pixelMatrix:\r\n for j in line:\r\n resultedString += j\r\n resultedString += '\\n'\r\n return resultedString[:-1]\r\n \r\n def rotate90right(self):\r\n # new matrix\r\n newPixelMatrix = []\r\n for i in range(self._width):\r\n newPixelMatrix.append([])\r\n for j in range(self._height):\r\n newPixelMatrix[i].append('.')\r\n \r\n # rotating elements \r\n for i in range (self._height):\r\n for j in range(self._width):\r\n newPixelMatrix[j][self._height-1-i] = self._pixelMatrix[i][j]\r\n \r\n self._pixelMatrix = newPixelMatrix\r\n temp = self._height\r\n self._height = self._width\r\n self._width = temp\r\n \r\n def mirrorGorizont(self):\r\n # new matrix\r\n newPixelMatrix = []\r\n for i in range(self._height):\r\n newPixelMatrix.append([])\r\n for j in range(self._width):\r\n newPixelMatrix[i].append('.')\r\n \r\n # mirroring elements \r\n for i in range (self._height):\r\n for j in range(self._width):\r\n newPixelMatrix[i][self._width-1-j] = self._pixelMatrix[i][j]\r\n \r\n self._pixelMatrix = newPixelMatrix\r\n \r\n def doubleTheSize(self):\r\n # creating new matrix, double the size!\r\n newPixelMatrix = []\r\n for i in range(self._height*2):\r\n newPixelMatrix.append([])\r\n for j in range(self._width*2):\r\n newPixelMatrix[i].append('.')\r\n \r\n # transport data\r\n for i in range (self._height):\r\n for j in range(self._width):\r\n newPixelMatrix[i*2][j*2] = self._pixelMatrix[i][j]\r\n newPixelMatrix[i*2][j*2+1] = self._pixelMatrix[i][j]\r\n newPixelMatrix[i*2+1][j*2] = self._pixelMatrix[i][j]\r\n newPixelMatrix[i*2+1][j*2+1] = self._pixelMatrix[i][j]\r\n \r\n self._pixelMatrix = newPixelMatrix\r\n self._height *= 2\r\n self._width *= 2\r\n\r\ninputString = input()\r\nlistOfInput = inputString.split()\r\nwidth = -1\r\nheight = -1\r\nfor i in listOfInput:\r\n if i.isdigit() and width == -1:\r\n width = int(i)\r\n elif i.isdigit():\r\n height = int(i)\r\n\r\nimage = input()\r\nfor i in range(height-1):\r\n image += '\\n'\r\n image += input()\r\n\r\na = Image(width, height, image)\r\na.doubleTheSize()\r\na.rotate90right()\r\na.mirrorGorizont()\r\nprint(a)\r\n ", "w,h = map(int,input().split())\r\na = []\r\nfor i in range(h):\r\n a.append(list(input()))\r\nb = []\r\nfor i in range(w):\r\n b.append([a[j][i] for j in range(h)])\r\nfor i in range(w):\r\n b[i] == b[i][::-1]\r\nout = ''\r\nfor i in range(w):\r\n t = ''\r\n for j in range(h):\r\n t += b[i][j] + b[i][j]\r\n out += t + '\\n' + t + '\\n'\r\nprint(out[:-1])", "a, b = [int(i) for i in input().split()]\n\n\nmatrix_in = [[0 for i in range(a)] for j in range(b)]\nfor i in range(b):\n line = input()\n for j in range(a):\n matrix_in[i][j] = line[j]\n\n# Right rotate and flip\nmatrix_rotated = [[0 for i in range(b)] for j in range(a)]\nfor i in range(a):\n for j in range(b):\n matrix_rotated[i][j] = matrix_in[j][i]\n\n# Print\nfor i in range(a):\n toprint=\"\"\n for j in range(b): \n toprint += matrix_rotated[i][j]*2\n print(toprint)\n print(toprint)\n", "w, h = map(int, input().split())\nz = [None] * h\nfor i in range(h):\n z[i] = input()\nfor i in range(w):\n for j in range(2):\n for k in range(h):\n print(z[k][i] + z[k][i], end = '')\n print()\n", "a,b = map(int,input().split())\r\ns = [input().strip()for i in range(b)]\r\ns1 = [[s[j][i]* 2 for j in range(b)]for i in range(a)for _ in range(2) ]\r\nfor i in s1:\r\n f = ''\r\n for j in i:\r\n f += j\r\n print(f)", "w, h=input().split()\r\nw=int(w)\r\nh=int(h)\r\na=list()\r\nfor i in range(h):\r\n row = input()\r\n a.append(row)\r\nb=[['0' for i in range(h)] for j in range(w)]\r\nfor i in range(h):\r\n for j in range(w):\r\n b[j][i]=a[i][j]\r\ns=str()\r\nc=list()\r\nfor j in range(w):\r\n for i in range(h):\r\n s=s+b[j][i]+b[j][i]\r\n c.append(s)\r\n s=''\r\nfor i in range(w):\r\n print(c[i])\r\n print(c[i])", "\r\nw, h = list(map(int, input().split()))\r\nfirst_matr = list()\r\nsecond_matr = [' '] * w\r\nfor i in range(w):\r\n second_matr[i] = [' '] * h\r\n\r\nthird_matr = [' '] * 2 * w\r\nfor i in range(2 * w):\r\n third_matr[i] = [' '] * 2 * h\r\n\r\nfor i in range(h):\r\n s = input()\r\n first_matr.append([])\r\n for j in s:\r\n first_matr[i].append(j)\r\n\r\nfor i in range(w):\r\n for j in range(h):\r\n second_matr[i][j] = first_matr[j][i]\r\n\r\nfor i in range(w):\r\n for j in range(h):\r\n third_matr[2*i][2*j] = third_matr[2*i+1][2*j] = third_matr[2*i][2*j+1] = third_matr[2*i+1][2*j+1] = second_matr[i][j]\r\n\r\nfor k in third_matr:\r\n for j in k:\r\n print(j, end=\"\")\r\n print()\r\n", "m, n = map(int, input().split())\r\n\r\nmat = []\r\nfor i in range(n):\r\n row = input()\r\n mat.append(row)\r\n\r\nfor i in range((m * 2)):\r\n for j in range((n * 2)):\r\n print(mat[j // 2][i // 2], end='')\r\n print()", "\ndef transpose(a):\n h, w = len(a), len(a[0])\n b = [[0 for j in range(h)] for i in range(w)]\n for i in range(h):\n for j in range(w):\n b[j][i] = a[i][j]\n return b\n\ndef read_field(lines_raw):\n lines = list(filter(lambda x: len(x) > 0, map(lambda y: y.strip(), lines_raw)))\n return [list(x) for x in lines]\n\ndef magnify(a, factor=2):\n h, w = len(a), len(a[0])\n b = [['#' for j in range(factor*w)] for i in range(factor*h)]\n for i in range(h):\n for j in range(w):\n for dx in range(factor):\n for dy in range(factor):\n b[factor * i + dx][factor * j + dy] = a[i][j]\n return b\n\ndef dump(a):\n return '\\n'.join((''.join((x for x in row))) for row in a)\n\n\na, b = input().split()\nlines = []\nfor _ in range(int(b)):\n lines.append(input())\n\nprint(dump(magnify(transpose(read_field(lines)))))\n\n\n", "size = input().split()\nw = int(size[0])\nh = int(size[1])\n\nimage = []\nfor i in range(h):\n row = []\n for c in input():\n row.append(c)\n image.append(row)\n\nfor i in range(w):\n row = []\n for k in range(h):\n row.append(image[k][i] * 2)\n str_row = ''.join(row)\n print(str_row)\n print(str_row)", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nw, h = map(int, input().split())\r\ng = [input()[:-1] for _ in range(h)]\r\ng = list(map(lambda x:''.join(x), zip(*g)))\r\nfor i in range(w):\r\n s = ''\r\n for j in range(h):\r\n s += g[i][j] * 2\r\n g[i] = s\r\n\r\nd = []\r\nfor i in g:\r\n d.append(i)\r\n d.append(i)\r\n\r\nfor i in d:\r\n print(i)", "w, h = map(int, input().split())\r\nli = []\r\nfor i in range(h):\r\n temp = list(input())\r\n li.append(temp)\r\n\r\nfor i in (range(w)): \r\n temp = ''\r\n for j in (range(h)):\r\n temp += 2*li[j][i]\r\n print(temp)\r\n print(temp)\r\n", "w, h = map(int, input().split())\r\n\r\ns = []\r\nfor i in range(h):\r\n s.append(input())\r\n\r\na = []\r\nfor i in range(w):\r\n a.append([0] * h)\r\n\r\nfor i in range(h):\r\n for j in range(w):\r\n a[j][i] = s[i][j]\r\n\r\nfor i in range(w):\r\n st = ''\r\n for c in a[i]:\r\n st += c * 2\r\n print(st)\r\n print(st)", "m,n = map(int,input().split())\r\na = [ [0]*m for i in range(n)]\r\nfor i in range(n):\r\n h = input()\r\n for j in range(m):\r\n a[i][j]=h[j]\r\ns = list(zip(*a))\r\nb = [ [0]*2*n for i in range(2*m)]\r\nfor i in range(2*m):\r\n for j in range(2*n):\r\n b[i][j]=s[i//2][j//2]\r\nfor i in b:\r\n print(''.join(map(str,i)))\r\n", "from sys import stdin, stdout\n\ndef pcol2(s, i):\n\twrite = stdout.write\n\tfor j in range(len(s)):\n\t\twrite(s[j][i]*2)\n\twrite('\\n')\n\nnext(stdin)\ns = stdin.read().split()\nfor i in range(len(s[0])):\n\tpcol2(s, i)\n\tpcol2(s, i)\n", "w, h = map(lambda s: int(s), input().split())\nimg = []\ntmp = []\ncols = []\nfor i in range(0, h):\n img.append(list(input()))\n\n\nfor i in range(0, w):\n line = str()\n for j in range(0, h):\n val = img[j][i]\n line = line + val + val\n print(line)\n print(line)\n", "w, h = [int(i) for i in input().split()]\r\npic = [list(input()) for i in range(h)]\r\npic1 = [[None] * h for i in range(w)]\r\nfor i in range(h):\r\n for j in range(w):\r\n pic1[j][i] = pic[i][j]\r\n#pic2 = [[None] * h for i in range(w)]\r\n#for i in range(w):\r\n# pic2[i][h - j - 1] = pic1[i][j]\r\npic3 = [[None] * 2 * h for i in range(2 * w)]\r\nfor i in range(w):\r\n for j in range(h):\r\n pic3[2 * i][2 * j] = pic1[i][j]\r\n pic3[2 * i + 1][2 * j] = pic1[i][j]\r\n pic3[2 * i][2 * j + 1] = pic1[i][j]\r\n pic3[2 * i + 1][2 * j + 1] = pic1[i][j]\r\nfor i in range(2 * w):\r\n for j in range(2 * h):\r\n print(pic3[i][j], end = '')\r\n print()", "class CodeforcesTask523ASolution:\n def __init__(self):\n self.result = ''\n self.w_h = []\n self.image = []\n\n def read_input(self):\n self.w_h = [int(x) for x in input().split(\" \")]\n for x in range(self.w_h[1]):\n self.image.append(list(input()))\n\n def process_task(self):\n rotated = [[\"_\" for x in range(self.w_h[1])] for y in range(self.w_h[0])]\n for x in range(self.w_h[1]):\n for y in range(self.w_h[0]):\n rotated[y][x] = self.image[x][y]\n zoomed = [[c + c for c in row] for row in rotated]\n for row in zoomed:\n print(\"\".join(row))\n print(\"\".join(row))\n\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask523ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "ar1 = []\r\nn, m = map(int, input().split())\r\nar = []\r\nfor i in range(m):\r\n s1 = []\r\n s = input().rstrip()\r\n for j in range(n):\r\n s1.append(s[j])\r\n ar.append(s1)\r\nark = []\r\nfor i in range(m):\r\n ark.append(ar[m - i - 1])\r\nar = ark[:]\r\nfor i in range(n):\r\n s = []\r\n for j in range(m - 1, -1 , -1):\r\n s.append(ar[j][i])\r\n ar1.append(s)\r\nfor i in range(n):\r\n for j in ar1[i]:\r\n print(j*2, end = '')\r\n\r\n print()\r\n for j in ar1[i]:\r\n print(j*2, end = '') \r\n print()\r\n ", "# LUOGU_RID: 101574102\nm, n = map(int,input().split())\r\nt = [input()for _ in range(n)]\r\nfor r in [[t[i][j] * 2 for i in range(n)] for j in range(m)]:\r\n s=''.join(r);\r\n print(s + '\\n' + s)", "s=input()\r\nw=int(s.split()[0])\r\nh=int(s.split()[1])\r\n\r\nL=[]\r\nL2=[]\r\ns2=''\r\n\r\n\r\nfor i in(range(h)):\r\n L.append(input()) \r\nfor i in(range(w)):\r\n for k in(range(h-1,-1,-1)):\r\n s2=s2+L[k][i]\r\n L2.append(s2)\r\n s2=''\r\n \r\nL3=[]\r\ns3=''\r\nfor i in((range(w))):\r\n for k in((range(h-1,-1,-1))):\r\n s3=s3+L2[i][k]\r\n L3.append(s3)\r\n s3='' \r\n \r\nL4=[]\r\nfor i in((range(w))):\r\n for k in((range(h))):\r\n s3=s3+((L3[i][k]*2))\r\n L4.append(s3)\r\n L4.append(s3)\r\n s3=''\r\nw2=w*2\r\nfor i in (range(w2)):\r\n print(L4[i])\r\n", "import sys\r\ndef main():\r\n w,h = [int(i) for i in input().split()]\r\n p = []\r\n for i in range(h):\r\n s = input()\r\n p.append(s)\r\n p = zip(*p)\r\n for s in p:\r\n result = ''\r\n for ch in s:\r\n result += ch+ch\r\n print(result)\r\n print(result)\r\nif __name__ == \"__main__\":\r\n ##sys.stdin = open(\"in.txt\",'r') \r\n ##sys.stdout = open(\"out.txt\",'w')\r\n main()\r\n ##sys.stdin.close()\r\n ##sys.stdout.close()\r\n", "w, h = map(int, input().split())\r\narr = [[] for i in range(h)]\r\nfor i in range(h):\r\n for j in input():\r\n arr[i].append(j)\r\narr2 = [['' for j in range(h)] for i in range(w)]\r\nfor i in range(h):\r\n for j in range(w):\r\n arr2[j][h - 1 - i] = arr[i][j]\r\nfor i in range(h // 2):\r\n for j in range(w):\r\n arr2[j][i], arr2[j][h - i - 1] = arr2[j][h - i - 1], arr2[j][i]\r\narr3 = [['' for j in range(2 * h)] for i in range(2 * w)]\r\nfor i in range(2 * w):\r\n for j in range(2 * h):\r\n arr3[i][j] = arr2[i // 2][j // 2]\r\nfor i in range(2 * w):\r\n for j in range(2 * h):\r\n print(arr3[i][j], end = '')\r\n print()", "def main():\n w, h = map(int, input().split())\n h *= 2\n l = [None] * h\n for i in range(0, h, 2):\n l[i] = l[i + 1] = input()\n l = [''.join(_) for _ in zip(*l)]\n for s in l:\n print(s)\n print(s)\n\n\nif __name__ == '__main__':\n main()\n", "def mash(pole):\r\n ans = []\r\n for i in range(len(pole)):\r\n s = pole[i]\r\n new = ''\r\n for i in s:\r\n new += (i * 2)\r\n ans.append(new)\r\n ans.append(new)\r\n return ans\r\n\r\ndef change(pole, a, b):\r\n x = len(pole[0]) % 2\r\n fir = []\r\n sec = []\r\n new = []\r\n for i in range(b):\r\n s = ''\r\n for j in range(a):\r\n s += pole[j][i]\r\n if i + 1 <= len(pole[0]) // 2:\r\n fir.append(s)\r\n continue\r\n if i + 1 >= (len(pole[0]) // 2 + x):\r\n sec.append(s)\r\n for i in range(len(sec[0])):\r\n s = ''\r\n for j in range(len(sec) + len(fir)):\r\n if j < len(sec):\r\n s += sec[j][i]\r\n else:\r\n s += fir[j - len(sec)][i]\r\n new.append(s)\r\n return new\r\ndef pov(pole, a, b):\r\n new = []\r\n for i in range(a):\r\n s = ''\r\n for j in range(b):\r\n s += pole[j][i]\r\n new.append(s)\r\n return new\r\n \r\na, b = map(int, input().split())\r\npole = []\r\nfor i in range(b):\r\n s = input()\r\n pole.append(s)\r\nnew = mash(pov(pole, a, b))\r\nfor i in new:\r\n print(i)\r\n", "def rot(x):\r\n matrix = [[0]*h for i in range(w)]\r\n for i in range(w):\r\n for j in range(h):\r\n matrix[i][j] = x[h-1-j][i]\r\n #for i in matrix:(print(i))\r\n #print()\r\n return matrix\r\ndef mir(x):\r\n matrix = [[0]*h for i in range(w)]\r\n for i in range(w):\r\n for j in range(h):\r\n matrix[i][j] = x[i][h-j-1]\r\n #for i in matrix:(print(i))\r\n #print()\r\n return matrix\r\ndef scale(x):\r\n matrix = [[0]*2*h for i in range(w*2)]\r\n for i in range(2*w):\r\n for j in range(2*h):\r\n matrix[i][j] = x[i//2][j//2]\r\n #for i in matrix:(print(i))\r\n #print()\r\n return matrix\r\n\r\nw, h = map(int,input().split())\r\nx = []\r\nfor i in range(h):\r\n x.append(list(input()))\r\nx = scale(mir(rot(x)))\r\nfor i in x: print(''.join(i))\r\n\r\n \r\n \r\n ", "w, h = [int(s) for s in input().split()]\r\nmas = [[' '] * 100 for i in range(100)]\r\n\r\nfor i in range(h):\r\n j = 0\r\n for ch in input():\r\n mas[j][i] = ch\r\n j += 1\r\nfor i in range(w):\r\n s = ''\r\n for j in range(h):\r\n s += mas[i][j] * 2\r\n print(s)\r\n print(s)\r\n\r\n", "def main():\r\n w, h = map(int, input().split())\r\n a = [input() for i in range(h)]\r\n for i in range(w):\r\n b = [a[j][i]*2 for j in range(h)]\r\n s = ''.join(b)\r\n print(s)\r\n print(s)\r\nif __name__ == '__main__':\r\n main()\r\n", "\r\ns = input()\r\nw = \"\"\r\nh = \"\"\r\nb = True\r\ns = list(s)\r\nfor f in s:\r\n if not b:\r\n h += f\r\n if f != \" \" and b:\r\n w += f\r\n else:\r\n b = False\r\nw = int(w)\r\nh = int(h)\r\nsimbolos = []\r\n\r\n\r\nfor e in range(0,h):\r\n simbolos.append([])\r\n caracteres = input()\r\n for n in caracteres:\r\n simbolos[e].append(n)\r\n #print(simbolos)\r\n\r\nsimbolos2 = []\r\n\r\nfor e in range(0,w):\r\n simbolos2.append([])\r\n for i in range(0,h):\r\n simbolos2[e].append(i)\r\n \r\n#print(simbolos2)\r\n\r\n\r\nj = h -1\r\nfor x in range(0,h): \r\n for y in range(0,w):\r\n simbolos2[y].pop(j)\r\n simbolos2[y].insert(j,simbolos[x][y])\r\n j -= 1 \r\n#print(simbolos2)\r\n\r\nsimbolos3 = []\r\nfor e in simbolos2:\r\n e.reverse()\r\n simbolos3.append(e)\r\n\r\n#print(simbolos3)\r\n\r\nfor e in simbolos3:\r\n letras = \"\"\r\n for i in e: \r\n letras += str(i)*2\r\n \r\n print(letras)\r\n print(letras)", "w, h = map(int, input().split())\t\t\r\nimage = [input() for i in range(h)]\r\nfor i in range(w):\r\n image2 = \"\"\r\n for j in range(h):\r\n temp = image[j][i]\r\n print(temp+temp,end=\"\")\r\n image2 += temp + temp\r\n print()\r\n print(image2)\r\n", "import sys\r\ndef main():\r\n w,h = [int(i) for i in input().split()]\r\n p = []\r\n for i in range(h):\r\n s = input()\r\n p.append(s)\r\n for i in range(w):\r\n for j in range(h):\r\n print(p[j][i]+p[j][i],end='')\r\n print()\r\n for j in range(h):\r\n print(p[j][i]+p[j][i],end='')\r\n print()\r\n \r\nif __name__ == \"__main__\":\r\n ##sys.stdin = open(\"in.txt\",'r') \r\n ##sys.stdout = open(\"out.txt\",'w')\r\n main()\r\n ##sys.stdin.close()\r\n ##sys.stdout.close()\r\n", "w, h = [int(x) for x in input().split()]\r\nori = []\r\nfor i in range(h):\r\n l = list(input())\r\n ori.append(l)\r\nro = []\r\nfor i in range(w):\r\n l = []\r\n for j in range(h):\r\n l.append(ori[j][i])\r\n ro.append(l)\r\ndu1 = []\r\nfor i in range(w):\r\n l = []\r\n for j in range(0, 2 * h):\r\n l.append(ro[i][int(j/2)])\r\n du1.append(l)\r\ndu2 = []\r\nfor i in range(0, 2 * w):\r\n du2.append(du1[int(i/2)])\r\nfor i in range(len(du2)):\r\n print(''.join(du2[i]))\r\n\r\n" ]
{"inputs": ["3 2\n.*.\n.*.", "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "1 100\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.", "1 100\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*", "1 100\n.\n*\n.\n.\n.\n*\n.\n.\n.\n*\n*\n*\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n*\n.\n*\n.\n.\n*\n*\n.\n*\n.\n.\n*\n.\n.\n*\n*\n.\n.\n.\n.\n.\n*\n.\n*\n.\n*\n.\n.\n.\n.\n*\n*\n*\n.\n.\n.\n.\n*\n.\n.\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n.\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n.\n.\n*\n*\n*\n*\n*\n*\n*\n.\n.\n*\n.\n.\n*\n*\n.", "100 1\n****************************************************************************************************", "100 1\n*...***.....**.*...*.*.**.************.**..**.*..**..**.*.**...***.*...*.*..*.*.*......**..*..*...**", "1 1\n.", "1 1\n*", "2 2\n.*\n*.", "1 2\n*\n.", "2 1\n*."], "outputs": ["....\n....\n****\n****\n....\n....", "********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......********..********......\n..********......********..********......\n....********....****************........\n....********....****************........\n....********....****************........\n....********....****************........\n......*...", "........................................................................................................................................................................................................\n........................................................................................................................................................................................................", "********************************************************************************************************************************************************************************************************\n********************************************************************************************************************************************************************************************************", "..**......**......******............**......**..**....****..**....**....****..........**..**..**........******........**....********..**********..********************....**************....**....****..\n..**......**......******............**......**..**....****..**....**....****..........**..**..**........******........**....********..**********..********************....**************....**....****..", "**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n...", "**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n**\n**\n**\n**\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n..\n..\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n**\n**\n**\n**\n..\n..\n**\n**\n..\n..\n**\n**\n**\n**\n..\n..\n..\n..\n..\n..\n**\n**\n...", "..\n..", "**\n**", "..**\n..**\n**..\n**..", "**..\n**..", "**\n**\n..\n.."]}
UNKNOWN
PYTHON3
CODEFORCES
65
1dad4aab8c75f71ea2952a36002504ad
Predict Outcome of the Game
There are *n* games in a football tournament. Three teams are participating in it. Currently *k* games had already been played. You are an avid football fan, but recently you missed the whole *k* games. Fortunately, you remember a guess of your friend for these *k* games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be *d*1 and that of between second and third team will be *d*2. You don't want any of team win the tournament, that is each team should have the same number of wins after *n* games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament? Note that outcome of a match can not be a draw, it has to be either win or loss. The first line of the input contains a single integer corresponding to number of test cases *t* (1<=≤<=*t*<=≤<=105). Each of the next *t* lines will contain four space-separated integers *n*,<=*k*,<=*d*1,<=*d*2 (1<=≤<=*n*<=≤<=1012; 0<=≤<=*k*<=≤<=*n*; 0<=≤<=*d*1,<=*d*2<=≤<=*k*) — data for the current test case. For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes). Sample Input 5 3 0 0 0 3 3 0 0 6 4 1 0 6 3 3 0 3 3 3 2 Sample Output yes yes yes no no
[ "from sys import stdin ,stdout\r\ninput=stdin.readline\r\ninp = lambda : map(int,input().split())\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end) \r\n\r\n\r\ndef check() :\r\n global ans , arr , n , k\r\n for i in arr : \r\n if i<0 : return 0 \r\n ans += max(arr ) - i \r\n if ans== n -k : return 1\r\n elif n-k - ans > 0 and (n-k - ans )%3==0: return 1 \r\n return 0 \r\n\r\ndef summ() :\r\n global arr \r\n z= 0 \r\n for i in arr : \r\n z+=abs(i) \r\n return z\r\n\r\nfor _ in range(int(input())) : \r\n n , k , d1 , d2 = inp() \r\n if (k-d1-d2 ) % 3 == 0 : \r\n b= (k - d1-d2)//3 ; a= b+d1 ; c = b+d2 ; arr=[a,b,c] ; ans=0\r\n if check() : print(\"yes\") ; continue\r\n if (k- (d1 -d2)) %3==0 : \r\n b= (k-(d1-d2))//3 ; a= b+d1 ; c = b-d2 ; arr=[a,b,c] ; ans=0\r\n if check() : print(\"yes\") ; continue\r\n \r\n if (k-(d2-d1)) %3==0 : \r\n b= (k-(d2-d1))//3 ; a= b-d1 ; c = b+d2 ; arr=[a,b,c] ; ans=0\r\n if check() : print(\"yes\") ; continue\r\n \r\n if (k-(-d2-d1)) %3==0 : \r\n b= (k-(-d2-d1))//3 ; a= b-d1 ; c = b-d2 ; arr=[a,b,c] ; ans=0\r\n if check() : print(\"yes\") ; continue\r\n \r\n print(\"no\")" ]
{"inputs": ["5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2"], "outputs": ["yes\nyes\nyes\nno\nno"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1dafc81807943eded66d0fe91f4eb6db
Help Chef Gerasim
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently. To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). Sample Input 5 270 250 250 230 250 5 250 250 250 250 250 5 270 250 249 230 250 Sample Output 20 ml. from cup #4 to cup #1. Exemplary pages. Unrecoverable configuration.
[ "def help_chef():\r\n\tcount = int(input())\r\n\r\n\tvolumes = []\r\n\ttotal = 0\r\n\tfor _ in range(count):\r\n\t\tvolume = int(input())\r\n\t\tvolumes.append(volume)\r\n\t\ttotal += volume\r\n\t\r\n\tif total % count != 0:\r\n\t\tprint(\"Unrecoverable configuration.\")\r\n\telif len(set(volumes)) == 1:\r\n\t\tprint(\"Exemplary pages.\")\r\n\telse:\r\n\t\tdiffs = []\r\n\t\tvol = None\r\n\t\tsource = target = None\r\n\t\taverage = total//count\r\n\t\tfor volume in volumes:\r\n\t\t\tdiff = volume - average\r\n\t\t\tdiffs.append(diff)\r\n\t\t\r\n\t\tfor index, diff in enumerate(diffs):\r\n\t\t\tif diff > 0:\r\n\t\t\t\tif target is None:\r\n\t\t\t\t\ttarget = index+1\r\n\t\t\t\t\tvol = diff\r\n\t\t\t\telse:\r\n\t\t\t\t\tprint(\"Unrecoverable configuration.\")\r\n\t\t\t\t\tbreak\r\n\t\t\telif diff < 0:\r\n\t\t\t\tif source is None:\r\n\t\t\t\t\tsource = index+1\r\n\t\t\t\telse:\r\n\t\t\t\t\tprint(\"Unrecoverable configuration.\")\r\n\t\t\t\t\tbreak\r\n\t\telse:\r\n\t\t\tprint(\"{} ml. from cup #{} to cup #{}.\".format(vol, source, target))\r\n\r\n\r\nhelp_chef()", "n = int(input())\r\na = []\r\nfor i in range(n):\r\n\ta.append(int(input()))\r\n\r\nif(sum(a)%n != 0):\r\n\tprint(\"Unrecoverable configuration.\")\r\nelse:\r\n\tk = sum(a)//n\r\n\tres = []\r\n\tflag = 0\r\n\tfor i in range(n):\r\n\t\tif(a[i] != k):\r\n\t\t\tflag = 1\r\n\t\t\tres.append([a[i],i])\r\n\r\n\tif(flag == 0):\r\n\t\tprint(\"Exemplary pages.\")\r\n\telse:\r\n\t\tif(len(res) == 2):\r\n\t\t\tres.sort()\r\n\t\t\tprint(str(res[1][0]-k) + \" ml. from cup #\" + str(res[0][1]+1) + \" to cup #\" +str(res[1][1]+1) + \".\")\r\n\t\telse:\r\n\t\t\tprint(\"Unrecoverable configuration.\")\r\n", "def s():\r\n\tn = int(input())\r\n\ta = [int(input()) for _ in range(n)]\r\n\tmi = min(enumerate(a),key = lambda x:x[1])\r\n\tma = max(enumerate(a),key = lambda x:x[1])\r\n\tp = sum(a)\r\n\tif p%n != 0:\r\n\t\treturn 'Unrecoverable configuration.'\r\n\tif mi[1] == ma[1]:\r\n\t\treturn 'Exemplary pages.'\r\n\tif a.count(mi[1]) > 1 or a.count(ma[1]) > 1:\r\n\t\treturn 'Unrecoverable configuration.'\r\n\treturn '{} ml. from cup #{} to cup #{}.'.format((ma[1]-mi[1])//2,mi[0]+1,ma[0]+1)\r\nprint(s())", "n=int(input())\r\na=[]\r\nfor i in range(1,n+1): a.append(int(input()))\r\nmina,maxa=min(a),max(a)\r\nminai,maxai=a.index(mina),a.index(maxa)\r\nif (maxa-mina)%2!=0:\r\n print(\"Unrecoverable configuration.\")\r\nelif mina==maxa:\r\n print(\"Exemplary pages.\")\r\nelse:\r\n mid=(maxa-mina)//2\r\n a[maxai]-=mid\r\n a[minai]+=mid\r\n if len(set(a))==1:\r\n print(str(mid)+' ml. from cup #'+str(minai+1)+' to cup #'+str(maxai+1)+'.')\r\n else:\r\n print(\"Unrecoverable configuration.\")\r\n \r\n", "n=int(input())\r\nar=[int(input()) for i in range(n)]\r\nif(len(set(ar))==1):\r\n print(\"Exemplary pages.\")\r\n quit()\r\nmn=min(ar)\r\nmx=max(ar)\r\nmni=ar.index(mn)\r\nmxi=ar.index(mx)\r\nvl=(mx-mn)//2\r\nar[mni]+=vl\r\nar[mxi]-=vl\r\nif(len(set(ar))==1):\r\n print(str(vl)+\" ml. from cup #\"+str(mni+1)+\" to cup #\"+str(mxi+1)+\".\")\r\n quit()\r\nelse:\r\n print(\"Unrecoverable configuration.\")\r\n quit()", "def print_ans(from_idx, to_idx, amount):\r\n print('{} ml. from cup #{} to cup #{}.'.format(amount, from_idx, to_idx))\r\n\r\nn = int(input())\r\na = []\r\n\r\nfor i in range(n):\r\n a.append((int(input()), i + 1))\r\n \r\na.sort()\r\n\r\nb = [a[i][0] for i in range(n)]\r\n\r\nbad = 'Unrecoverable configuration.'\r\n\r\nif len(set(b)) == 1:\r\n print('Exemplary pages.')\r\nelif n == 2:\r\n if (b[1] - b[0]) % 2:\r\n print(bad)\r\n else:\r\n print_ans(a[0][1], a[1][1], b[1] - (b[1] + b[0]) // 2)\r\nelif len(set(b)) != 3:\r\n print(bad)\r\nelif b.count(b[0]) != 1 or b.count(b[-1]) != 1:\r\n print(bad)\r\nelif b[-1] - b[1] != b[1] - b[0]:\r\n print(bad)\r\nelse:\r\n print_ans(a[0][1], a[-1][1], b[1] - b[0])\r\n ", "n=int(input())\r\nx=[]\r\nfor i in range(n):\r\n x.append(int(input()))\r\ny=sorted(x)\r\nz=sorted(x,reverse=True)\r\nif y==z:print('Exemplary pages.')\r\nelse:\r\n z=y.copy();t=[]\r\n while(y[n-1]>0):\r\n y[0]+=1;y[n-1]-=1\r\n if y[0]==y[n-1]:break\r\n y.sort();t=sorted(y,reverse=True)\r\n if y==t:print('%d ml. from cup #%d to cup #%d.'%(y[0]-z[0],x.index(z[0])+1,x.index(z[n-1])+1))\r\n else:print('Unrecoverable configuration.')\r\n", "n=int(input())\r\na=[0]*n\r\n\r\nfor i in range(n):\r\n a[i]=int(input())\r\n\r\navg=sum(a)\r\n\r\nif avg%n!=0:\r\n print('Unrecoverable configuration.')\r\n exit(0)\r\n\r\navg=avg//n\r\n\r\nx=[]\r\nfor i in range(n):\r\n if a[i]!=avg:\r\n x.append(i)\r\n\r\nif len(x)==0:\r\n print('Exemplary pages.')\r\n\r\nelif len(x)==2:\r\n if (a[x[0]]+a[x[1]])//2==avg:\r\n d=abs(a[x[0]]-a[x[1]])//2\r\n\r\n if a[x[0]]>a[x[1]]:\r\n print(str(d)+' ml. from cup #'+str(x[1]+1)+' to cup #'+str(x[0]+1)+'.')\r\n\r\n else:\r\n print(str(d)+' ml. from cup #'+str(x[0]+1)+' to cup #'+str(x[1]+1)+'.')\r\n else:\r\n print('Unrecoverable configuration.')\r\n\r\nelse:\r\n print('Unrecoverable configuration.')", "n = int(input())\r\na = []\r\nsum = 0\r\nfor i in range(n):\r\n a.append(int(input()))\r\n sum+=a[i]\r\nc = sum//n\r\nfro = 0\r\nto = 0\r\ncou = 0\r\nfor i in range(n):\r\n if c<a[i]:\r\n to = i+1\r\n cou+=1\r\n elif c>a[i]:\r\n fro = i+1\r\n cou+=1\r\namt = (a[to-1]-a[fro-1])//2\r\na[to-1]-=amt\r\na[fro-1]+=amt\r\nif fro == to:\r\n print(\"Exemplary pages.\")\r\nelse:\r\n c = a[0]\r\n flag = 0\r\n for i in range(n):\r\n if c != a[i]:\r\n flag = 1\r\n break\r\n if flag:\r\n print(\"Unrecoverable configuration.\")\r\n else:\r\n s=str(amt)+\" ml. from cup #\"+str(fro)+ \" to cup #\"+str(to)+\".\"\r\n print(s)\r\n \r\n", "n = int(input())\r\n\r\nd = {}\r\n\r\nfor i in range(n):\r\n s = int(input())\r\n if s in d:\r\n d[s] += [i + 1]\r\n else:\r\n d[s] = [i + 1]\r\n\r\nmx = max(d)\r\nmn = min(d)\r\nl = len(d)\r\n\r\nif l == 1:\r\n print(\"Exemplary pages.\")\r\n exit()\r\nelif l == 2:\r\n if len(d[mx]) != 1 or len(d[mn]) != 1:\r\n print('Unrecoverable configuration.')\r\n exit()\r\n if (mx + mn) % 2:\r\n print(\"Unrecoverable configuration.\")\r\n exit()\r\nelif l == 3:\r\n if len(d[mx]) != 1 or len(d[mn]) != 1:\r\n print('Unrecoverable configuration.')\r\n exit()\r\n md = (set(d) - {mx, mn}).pop()\r\n if (mx + mn) / 2 != md:\r\n print(\"Unrecoverable configuration.\")\r\n exit()\r\nelse:\r\n print(\"Unrecoverable configuration.\")\r\n exit()\r\n\r\nprint((mx - mn) // 2, ' ml. from cup #', *d[mn], ' to cup #', *d[mx], '.', sep='')", "while True:\r\n\ttry:\r\n\t\tdef soln(n, a, s):\r\n\t\t\ta.sort()\r\n\t\t\t#print(a)\r\n\t\t\tif a[-1][0] == a[0][0]:\r\n\t\t\t\tprint(\"Exemplary pages.\")\r\n\t\t\telif s%n == 0:\r\n\t\t\t\tmn, cng, cun = a[0][0], 0, 0\r\n\t\t\t\tfor i in range(1, n-1, 1):\r\n\t\t\t\t\tif a[i][0] != a[i-1][0] :\r\n\t\t\t\t\t\tcng += 1\r\n\t\t\t\t\tif mn == a[i][0]:\r\n\t\t\t\t\t\tcun += 1\r\n\t\t\t\t#print(mn, cng)\r\n\t\t\t\tif cun == 0 and cng <= 1 :\r\n\t\t\t\t\t print(a[-1][0]-(s//n),\"ml.\", \"from cup\",\"#\"+str(a[0][1]),\"to cup\",\"#\"+str(a[-1][1])+\".\")\r\n\t\t\t\telse:print(\"Unrecoverable configuration.\")\r\n\t\t\telse:print(\"Unrecoverable configuration.\")\r\n\t\t\t\r\n\t\t\t\t\r\n\r\n\t\tdef read():\r\n\t\t\tn = int(input())\r\n\t\t\ta = list()\r\n\t\t\tsum = 0\r\n\t\t\tfor i in range(n):\r\n\t\t\t\ta.append([int(input()),i+1])\r\n\t\t\t\tsum += a[i][0]\r\n\t\t\t#print(a)\r\n\t\t\tsoln(n, a, sum)\r\n\t\tif __name__ == \"__main__\":\r\n\t\t\tread()\r\n\t\t\t\r\n\t\t\t\"\"\"def soln(n, a, s):\r\n\t\t\ta.sort()\r\n\t\t\tif a[-1][0] == a[0][0]:print(\"Exemplary pages.\")\r\n\t\t\telif s%n == 0 and a[-1][0]-(s//n) ==a[-1][0]-(s/n) :\r\n\t\t\t\tprint(a[-1][0]-(s//n),\"ml.\", \"from cup\",\"#\"+str(a[0][1]),\"to cup\",\"#\"+str(a[-1][1])+\".\")\r\n\t\t\telse:print(\"Unrecoverable configuration.\")\r\n\t\t\t\"\"\"\r\n\t\t\t\r\n\texcept EOFError:\r\n\t\tbreak", "n=int(input())\r\ns=[]\r\nfor i in range(n):\r\n s.append(int(input()))\r\nx=list(set(s))\r\nx.sort()\r\nif len(x)==1:\r\n print('Exemplary pages.')\r\nelif len(s)==2 and sum(x)%2==0:\r\n print('{} ml. from cup #{} to cup #{}.'.format((x[1]-x[0])//2,s.index(x[0])+1,s.index(x[1])+1))\r\nelif len(x)==3 and s.count(x[0])==1 and s.count(x[2])==1 and x[1]-x[0]==x[2]-x[1]:\r\n v=x[1]-x[0]\r\n q=s.index(x[0])+1\r\n k=s.index(x[2])+1\r\n print('{} ml. from cup #{} to cup #{}.'.format(v,q,k))\r\nelse:\r\n print('Unrecoverable configuration.')\r\n", "n = int(input())\r\na = []\r\nsum = 0\r\nfor i in range(n):\r\n x = int(input())\r\n sum += x\r\n a.append(x)\r\nave = sum / n\r\nif int(ave) == ave:\r\n ave = int(ave)\r\n b = set()\r\n cnt = 0\r\n for i in range(n):\r\n if abs(ave - a[i])!=0:\r\n b.add(abs(ave - a[i]))\r\n t = ave - a[i]\r\n if t > 0:\r\n A = i + 1\r\n else:\r\n B = i + 1\r\n cnt += 1\r\n if len(b) == 1 and cnt == 2:\r\n print(str(abs(t)) + \" ml. from cup #\" + str(A) +\" to cup #\" + str(B) + \".\")\r\n elif len(b) == 0:\r\n print(\"Exemplary pages.\")\r\n else:\r\n print(\"Unrecoverable configuration.\")\r\nelse:\r\n print('Unrecoverable configuration.')", "from sys import *\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom fractions import *\r\nfrom datetime import *\r\nfrom math import *\r\n\r\nInput = []\r\n\r\n#stdin = open('in', 'r')\r\n#stdout = open('out', 'w')\r\n\r\n## for i, val in enumerate(array, start_i_value)\r\n\r\ndef Out(x):\r\n stdout.write(str(x) + '\\n')\r\n\r\ndef In():\r\n return stdin.readline().strip()\r\n\r\ndef inputGrab():\r\n for line in stdin:\r\n Input.extend(map(str, line.strip().split()))\r\n'''--------------------------------------------------------------------------------'''\r\n\r\ndef main():\r\n n = int(In())\r\n v = [int(In()) for _ in range(n)]\r\n \r\n Min = min(v)\r\n Max = max(v)\r\n \r\n if Min == Max:\r\n print(\"Exemplary pages.\")\r\n else:\r\n extra = Max-Min\r\n MaxInd = v.index(Max)\r\n MinInd = v.index(Min)\r\n v[MaxInd] -= extra//2\r\n v[MinInd] += extra//2\r\n \r\n if v.count(Min+extra//2) == len(v) and extra%2 == 0:\r\n print(\"%d ml. from cup #%d to cup #%d.\" %(extra/2, MinInd+1, MaxInd+1))\r\n else:\r\n print(\"Unrecoverable configuration.\")\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n l.append(int(input()))\r\na=set(l)\r\nif(len(a)==1):\r\n print(\"Exemplary pages.\")\r\nelse:\r\n m=min(l)\r\n n=max(l)\r\n r=(n-m)//2\r\n q=l.index(n)\r\n w=l.index(m)\r\n l[q]-=r\r\n l[w]+=r\r\n b=set(l)\r\n if(len(b)==1):\r\n print(str(r)+\" ml. from cup #\"+str(w+1)+\" to cup #\"+str(q+1)+\".\")\r\n else:\r\n print(\"Unrecoverable configuration.\")\r\n" ]
{"inputs": ["5\n270\n250\n250\n230\n250", "5\n250\n250\n250\n250\n250", "5\n270\n250\n249\n230\n250", "4\n200\n190\n210\n200", "4\n1\n2\n3\n4", "1\n0", "2\n0\n0", "2\n0\n1", "2\n0\n2", "2\n1\n0", "2\n1\n1", "2\n1\n2", "2\n2\n0", "2\n2\n1", "2\n2\n2", "3\n0\n0\n0", "3\n0\n0\n1", "3\n0\n0\n2", "3\n0\n1\n0", "3\n0\n1\n1", "3\n0\n1\n2", "3\n0\n2\n0", "3\n0\n2\n1", "3\n0\n2\n2", "3\n1\n0\n0", "3\n1\n0\n1", "3\n1\n0\n2", "3\n1\n1\n0", "3\n1\n1\n1", "3\n1\n1\n2", "3\n1\n2\n0", "3\n1\n2\n1", "3\n1\n2\n2", "3\n2\n0\n0", "3\n2\n0\n1", "3\n2\n0\n2", "3\n2\n1\n0", "3\n2\n1\n1", "3\n2\n1\n2", "3\n2\n2\n0", "3\n2\n2\n1", "3\n2\n2\n2", "4\n0\n0\n0\n0", "4\n0\n0\n0\n1", "4\n0\n0\n0\n2", "4\n0\n0\n1\n0", "4\n0\n0\n1\n1", "4\n0\n0\n1\n2", "4\n0\n0\n2\n0", "4\n0\n0\n2\n1", "4\n0\n0\n2\n2", "4\n0\n1\n0\n0", "4\n0\n1\n0\n1", "4\n0\n1\n0\n2", "4\n0\n1\n1\n0", "4\n0\n1\n1\n1", "4\n0\n1\n1\n2", "4\n0\n1\n2\n0", "4\n0\n1\n2\n1", "4\n0\n1\n2\n2", "4\n0\n2\n0\n0", "4\n0\n2\n0\n1", "4\n0\n2\n0\n2", "4\n0\n2\n1\n0", "4\n0\n2\n1\n1", "4\n0\n2\n1\n2", "4\n0\n2\n2\n0", "4\n0\n2\n2\n1", "4\n0\n2\n2\n2", "4\n1\n0\n0\n0", "4\n1\n0\n0\n1", "4\n1\n0\n0\n2", "4\n1\n0\n1\n0", "4\n1\n0\n1\n1", "4\n1\n0\n1\n2", "4\n1\n0\n2\n0", "4\n1\n0\n2\n1", "4\n1\n0\n2\n2", "4\n1\n1\n0\n0", "4\n1\n1\n0\n1", "4\n1\n1\n0\n2", "4\n1\n1\n1\n0", "4\n1\n1\n1\n1", "4\n1\n1\n1\n2", "4\n1\n1\n2\n0", "4\n1\n1\n2\n1", "4\n1\n1\n2\n2", "4\n1\n2\n0\n0", "4\n1\n2\n0\n1", "4\n1\n2\n0\n2", "4\n1\n2\n1\n0", "4\n1\n2\n1\n1", "4\n1\n2\n1\n2", "4\n1\n2\n2\n0", "4\n1\n2\n2\n1", "4\n1\n2\n2\n2", "4\n2\n0\n0\n0", "4\n2\n0\n0\n1", "4\n2\n0\n0\n2", "4\n2\n0\n1\n0", "4\n2\n0\n1\n1", "4\n2\n0\n1\n2", "4\n2\n0\n2\n0", "4\n2\n0\n2\n1", "4\n2\n0\n2\n2", "4\n2\n1\n0\n0", "4\n2\n1\n0\n1", "4\n2\n1\n0\n2", "4\n2\n1\n1\n0", "4\n2\n1\n1\n1", "4\n2\n1\n1\n2", "4\n2\n1\n2\n0", "4\n2\n1\n2\n1", "4\n2\n1\n2\n2", "4\n2\n2\n0\n0", "4\n2\n2\n0\n1", "4\n2\n2\n0\n2", "4\n2\n2\n1\n0", "4\n2\n2\n1\n1", "4\n2\n2\n1\n2", "4\n2\n2\n2\n0", "4\n2\n2\n2\n1", "4\n2\n2\n2\n2", "27\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n2626\n5599\n5599\n5599\n5599\n5599\n8572\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599", "98\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n1204\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n197\n702\n702\n702\n702\n702\n702\n702\n702\n702", "54\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6859\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n5389\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124", "50\n9636\n9678\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9596\n9636\n9636\n9636\n9636\n9636\n9636", "19\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n82\n5001\n9919\n5001\n5001", "74\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n3918\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n6742\n5330\n5330"], "outputs": ["20 ml. from cup #4 to cup #1.", "Exemplary pages.", "Unrecoverable configuration.", "10 ml. from cup #2 to cup #3.", "Unrecoverable configuration.", "Exemplary pages.", "Exemplary pages.", "Unrecoverable configuration.", "1 ml. from cup #1 to cup #2.", "Unrecoverable configuration.", "Exemplary pages.", "Unrecoverable configuration.", "1 ml. from cup #2 to cup #1.", "Unrecoverable configuration.", "Exemplary pages.", "Exemplary pages.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #1 to cup #3.", "Unrecoverable configuration.", "1 ml. from cup #1 to cup #2.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #2 to cup #3.", "Unrecoverable configuration.", "Exemplary pages.", "Unrecoverable configuration.", "1 ml. from cup #3 to cup #2.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #2 to cup #1.", "Unrecoverable configuration.", "1 ml. from cup #3 to cup #1.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Exemplary pages.", "Exemplary pages.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #1 to cup #4.", "Unrecoverable configuration.", "1 ml. from cup #1 to cup #3.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #1 to cup #2.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #2 to cup #4.", "Unrecoverable configuration.", "1 ml. from cup #2 to cup #3.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #3 to cup #4.", "Unrecoverable configuration.", "Exemplary pages.", "Unrecoverable configuration.", "1 ml. from cup #4 to cup #3.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #3 to cup #2.", "Unrecoverable configuration.", "1 ml. from cup #4 to cup #2.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #2 to cup #1.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1 ml. from cup #3 to cup #1.", "Unrecoverable configuration.", "1 ml. from cup #4 to cup #1.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Unrecoverable configuration.", "Exemplary pages.", "2973 ml. from cup #11 to cup #17.", "Unrecoverable configuration.", "735 ml. from cup #37 to cup #29.", "Unrecoverable configuration.", "Unrecoverable configuration.", "1412 ml. from cup #36 to cup #72."]}
UNKNOWN
PYTHON3
CODEFORCES
15
1df64825d70c19acab8be693fb95a789
Bear and Three Musketeers
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). Sample Input 5 6 1 2 1 3 2 3 2 4 3 4 4 5 7 4 2 1 3 6 5 1 1 7 Sample Output 2 -1
[ "from collections import defaultdict,deque\r\ndef main():\r\n n,m = map(int, input().split())\r\n d = defaultdict(set)\r\n for i in range(m):\r\n a,b = map(int,input().split())\r\n d[a].add(b)\r\n d[b].add(a)\r\n ans = 1e10\r\n for key,v in d.items():\r\n for j in v:\r\n for k in v:\r\n if k in d[j]:\r\n ans = min(ans,len(v)+len(d[j])+len(d[k])-6)\r\n print(ans if ans != 1e10 else \"-1\")\r\n\r\nif __name__ == \"__main__\":\r\n main()", "f = lambda: map(int, input().split())\r\nn, m = f()\r\np, s = [], [set() for i in range(n + 1)]\r\nfor j in range(m):\r\n a, b = f()\r\n p += [(a, b, c) for c in s[a].intersection(s[b])]\r\n s[a].add(b)\r\n s[b].add(a)\r\nk = [len(s[i]) for i in range(n + 1)]\r\nprint(min(k[a] + k[b] + k[c] for a, b, c in p) - 6 if p else -1)\r\n\r\n ", "n, m = map(int, input().split())\nINF = float('inf')\n\ngraph = []\nfor i in range(n):\n graph.append(set())\n\nfor i in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n\n graph[a].add(b)\n graph[b].add(a)\n\n\ncandidates = set()\nfor i in range(n):\n if len(graph[i]) >= 2:\n candidates.add(i)\n\nans = INF\nfor i in candidates:\n for j in graph[i]:\n if j not in candidates:\n continue\n for k in graph[j]:\n if k not in candidates:\n continue\n if i in graph[k]:\n ans = min(\n ans, len(graph[i]) + len(graph[j]) + len(graph[k]) - 6)\n\nif ans < INF:\n print(ans)\nelse:\n print(-1)\n", "from sys import stdin\r\n\r\nnV, nE = map(int, stdin.readline().split())\r\nadj = [[0 for _ in range(nV + 1)] for _ in range(nV + 1)]\r\nd = [0] * (nV + 1)\r\nedges = []\r\nfor _ in range(nE):\r\n u, v = map(int, stdin.readline().split())\r\n adj[u][v] = adj[v][u] = 1\r\n d[u] += 1\r\n d[v] += 1\r\n edges.append((u, v))\r\nret = float('inf')\r\nfor a, b in edges:\r\n for c in range(1, nV + 1):\r\n if adj[a][b] and adj[a][c] and adj[b][c]:\r\n ret = min(ret, d[a] + d[b] + d[c] - 6)\r\nprint(ret if ret != float('inf') else -1)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nG = [[0]*n for _ in range(n)]\r\ndeg = [0]*n\r\nedges = []\r\n\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n G[a-1][b-1] = 1\r\n G[b-1][a-1] = 1\r\n deg[a-1] += 1\r\n deg[b-1] += 1\r\n edges.append((a-1, b-1))\r\n\r\nans = 10**18\r\n\r\nfor a, b in edges:\r\n for c in range(n):\r\n if c!=a and c!=b and G[a][c]==1 and G[b][c]==1:\r\n ans = min(ans, deg[a]+deg[b]+deg[c]-6)\r\n\r\nif ans==10**18:\r\n print(-1)\r\nelse:\r\n print(ans)", "n, m = map(int,input().split())\r\nSet = [set() for i in range(n)]\r\nedges = []\r\n\r\nfor i in range(m):\r\n a = tuple(map(int, input().split()))\r\n a = (a[0]-1,a[1]-1)\r\n edges.append(a)\r\n Set[a[0]].add(a[1])\r\n Set[a[1]].add(a[0])\r\n\r\nlens = [0]*n\r\n\r\nfor i in range(n):\r\n lens[i] = len(Set[i]) \r\n \r\nmini = 1000000\r\n\r\nfor i in range(m):\r\n a = edges[i][0]\r\n b = edges[i][1]\r\n inter = Set[a] & Set[b]\r\n for elem in inter:\r\n mini = min(mini, lens[a]+lens[b]+lens[elem]-6)\r\n \r\nif mini == 1000000:\r\n print('-1')\r\nelse:\r\n print(mini)", "input_values = input().split()\r\nn = int(input_values[0])\r\nm = int(input_values[1])\r\nnumber_of_pairs = m\r\nvalues = []\r\nfor i in range(n+1):\r\n values.append([])\r\n\r\nwhile number_of_pairs > 0:\r\n input_values = input().split()\r\n ai = int(input_values[0])\r\n bi = int(input_values[1])\r\n values[ai].append(bi)\r\n values[bi].append(ai)\r\n number_of_pairs -= 1\r\n\r\nmin_sum = n * 3\r\nfor i in range(1, n - 1):\r\n if len(values[i]) >= 2:\r\n for j in values[i]:\r\n if len(values[j]) >= 2:\r\n for k in values[j]:\r\n if k in values[i]:\r\n aux = len(values[i]) + len(values[j]) + len(values[k]) - 6\r\n if aux < min_sum:\r\n min_sum = aux\r\n\r\nif min_sum < n*3:\r\n print(min_sum)\r\nelse:\r\n print(-1)", "def main():\n from itertools import combinations\n n, m = map(int, input().split())\n n += 1\n l, cnt, res = [[] for _ in range(n)], [0] * n, []\n for _ in range(m):\n a, b = map(int, input().split())\n if a < b:\n l[a].append(b)\n else:\n l[b].append(a)\n cnt[a] += 1\n cnt[b] += 1\n for a, la, x in zip(range(n), l, cnt):\n la.sort()\n for b, c in combinations(la, 2):\n if c in l[b]:\n res.append(x + cnt[b] + cnt[c])\n print(min(res) - 6 if res else -1)\n\n\nif __name__ == '__main__':\n main()\n", "def Solve(graph):\r\n cycles = []\r\n for vertex in graph:\r\n cycle = [vertex]\r\n for kid1 in graph[vertex]:\r\n cycle = [vertex,kid1]\r\n for kid2 in graph[vertex]:\r\n if kid2 in graph[kid1]:\r\n cycle.append(kid2)\r\n cycles.append(cycle)\r\n cycle = [vertex,kid1]\r\n\r\n min_degree = float('inf')\r\n for cycle in cycles:\r\n total = 0\r\n for i in cycle:\r\n total += len(graph[i])\r\n if total < min_degree:\r\n min_degree = total\r\n\r\n if min_degree == float('inf'):\r\n print (-1)\r\n return\r\n print (min_degree-6)\r\n \r\n\r\ndef main():\r\n n,m = map(int,input().split())\r\n graph = {}\r\n\r\n for i in range(1,n+1):\r\n graph[i] = []\r\n\r\n for i in range(m):\r\n a,b = map(int,input().split())\r\n graph[a].append(b)\r\n graph[b].append(a)\r\n\r\n (Solve(graph))\r\n\r\nmain()\r\n", "n, m = map(int,input().split())\r\nt = m\r\ngrafo = [[] for i in range( n + 1 )]\r\n \r\nwhile t > 0:\r\n ai,bi = map(int,input().split())\r\n grafo[ai].append(bi)\r\n grafo[bi].append(ai)\r\n t -= 1\r\n\r\nminimo = n * 3\r\n \r\nfor i in range(1 , n-1):\r\n if len(grafo[i]) < 2:\r\n continue\r\n\r\n else:\r\n for j in grafo[i]:\r\n if len(grafo[j]) < 2:\r\n continue\r\n\r\n else:\r\n for k in grafo[j]:\r\n if k in grafo[i]:\r\n\r\n aux = len(grafo[i]) + len(grafo[j]) + len(grafo[k]) - 6\r\n if aux < minimo:\r\n minimo = aux\r\nif minimo < n*3:\r\n print(minimo)\r\nelse:\r\n print(-1)", "from collections import defaultdict\nMAX = float('inf')\ndef minimal_recognitions(graph):\n sum_recognitions = MAX\n for n1 in graph:\n for n2 in graph[n1]:\n for n3 in graph[n2]:\n if(n3 in graph[n1]):\n sum_recognitions = min(sum_recognitions, len(graph[n3]) + len(graph[n2]) + len(graph[n1]))\n return sum_recognitions\n \n\nn, m = map(int, input().split())\ngraph = defaultdict(list)\nfor i in range(m):\n x1, x2 = map(int, input().split())\n graph[x1].append(x2)\n graph[x2].append(x1)\n\nminimal_sum_recognitions = minimal_recognitions(graph)\nif(minimal_sum_recognitions == MAX):\n print(-1)\nelse:\n print(minimal_sum_recognitions-6)", "import sys\nsys\ninput = sys.stdin.readline\nI = lambda : list(map(int,input().split()))\n\nn,m=I()\ng=[[0]*n for i in range(n)]\ned=[]\nan=n*n\ndg=[0]*n\nfor i in range(m):\n\tx,y=I()\n\tx-=1;y-=1\n\tdg[x]+=1;dg[y]+=1\n\tg[x][y]=1\n\tg[y][x]=1\n\ted.append([x,y])\nfor i in range(m):\n\ta,b=ed[i]\n\tfor j in range(n):\n\t\tif j!=a and j!=b and g[a][j] and g[j][b]:\n\t\t\tan=min(an,dg[a]+dg[b]+dg[j]-6)\nif an==n*n:\n\tan=-1\nprint(an)", "n, m = map(int,input().split())\r\ngr = [set() for _ in range(n)]\r\ndeg = [0] * n\r\nans = 10 ** 10\r\nedg = [None] * m\r\nfor i in range(m):\r\n a,b = map(int,input().split())\r\n gr[a - 1].add(b - 1)\r\n gr[b - 1].add(a - 1)\r\n deg[a - 1] += 1\r\n deg[b - 1] += 1\r\n edg[i] = (a - 1, b - 1)\r\nfor t, t1 in edg:\r\n if deg[t] > deg[t1]:\r\n t, t1 = t1, t\r\n for j in gr[t]:\r\n if j in gr[t1]:\r\n ans = min(ans, deg[t] + deg[t1] + deg[j] - 6)\r\nprint(ans if ans != 10 ** 10 else - 1)", "n,m = map(int,input().split())\r\ng = [set() for i in range(n)]\r\ne = []\r\nres = 10**10000\r\nl = [0]*n\r\nfor i in range(m):\r\n a = tuple(map(int, input().split()))\r\n a = (a[0]-1,a[1]-1)\r\n e.append(a)\r\n g[a[0]].add(a[1])\r\n g[a[1]].add(a[0])\r\nfor i in range(n):\r\n l[i] = len(g[i]) \r\nfor i in range(m):\r\n a = e[i][0]\r\n b = e[i][1]\r\n c = g[a] & g[b]\r\n for f in c:\r\n res = min(res, l[a] + l[b] + l[f]-6) \r\nif res != 10**10000:print(res)\r\nelse:print(-1)", "import io, os\r\ninput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\nadj = [[0]*4001 for i in range(4001)]\r\nrecog = 10**18\r\ndeg = [0]*4001\r\n\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n adj[a][b] = 1\r\n adj[b][a] = 1\r\n deg[a] += 1\r\n deg[b] += 1\r\n \r\nfor i in range(1, 1+n):\r\n for j in range(i+1, 1+n):\r\n if adj[i][j]:\r\n for k in range(j+1, n+1):\r\n if adj[i][k] and adj[j][k]:\r\n recog = min(recog, deg[i]+deg[j]+deg[k])\r\n \r\nprint(recog-6 if recog != 10**18 else -1)", "def find_cycles(graph):\r\n cycles = []\r\n for v1 in graph:\r\n for v2 in graph[v1]:\r\n for j1 in graph[v2]:\r\n if (j1 in graph[v1]):\r\n cycles.append((v1, v2, j1))\r\n return cycles\r\n\r\n\r\ndef f(graph):\r\n cycles = find_cycles(graph)\r\n if (len(cycles) == 0):\r\n return -1\r\n min = 10**5\r\n for c in cycles:\r\n total = 0\r\n for v in c:\r\n total += len(graph[v]) - 2\r\n if (total < min):\r\n min = total\r\n return min\r\n\r\n\r\nn, m = map(int, input().split())\r\ngraph = {}\r\n\r\nfor i in range(1, n+1):\r\n graph[i] = []\r\nfor i in range(m):\r\n origin, destiny = map(int, input().split())\r\n graph[origin].append(destiny)\r\n graph[destiny].append(origin)\r\n\r\nprint(f(graph))\r\n", "n, m = map(int, input().split())\r\n\r\nd = [0] * n\r\nt = []\r\nfor i in range(n):\r\n t.append([0] * n)\r\n\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n t[a - 1][b - 1] = t[b - 1][a - 1] = 1\r\n d[a - 1] += 1\r\n d[b - 1] += 1\r\n\r\nres = 10000005\r\nfor i in range(n):\r\n for j in range(i + 1, n):\r\n if t[i][j]:\r\n for k in range(j + 1, n):\r\n if t[i][k] and t[j][k]:\r\n res = min(res, d[i] + d[j] + d[k])\r\n\r\nif res == 10000005:\r\n print(-1)\r\nelse:\r\n print(res - 6)\r\n", "arestas = []\r\ninit = 10**10000\r\nresultado = init\r\n\r\nn,m = map(int,input().split())\r\ngrafo = [set() for _ in range(n)]\r\n\r\n\r\nfor _ in range(m):\r\n warriors = tuple(map(int, input().split()))\r\n warriors = (warriors[0]-1,warriors[1]-1)\r\n arestas.append(warriors)\r\n grafo[warriors[0]].add(warriors[1])\r\n grafo[warriors[1]].add(warriors[0])\r\n\r\narr = [0]*n\r\nfor i in range(n):\r\n arr[i] = len(grafo[i]) \r\n \r\nfor i in range(m):\r\n x = arestas[i][0]\r\n y = arestas[i][1]\r\n intersec = grafo[x] & grafo[y]\r\n for elem in intersec:\r\n resultado = min(resultado, arr[x] + arr[y] + arr[elem]-6)\r\n \r\nif resultado != init:\r\n print(resultado)\r\nelse:\r\n print(-1)", "def bear_three(graph):\r\n sum_rec = 4000\r\n for m1 in graph:\r\n for m2 in graph[m1]:\r\n for m3 in graph[m2]:\r\n if (m3 in graph[m1]):\r\n sum_rec = min(sum_rec, len(graph[m1]) + len(graph[m2]) + len(graph[m3]) -6)\r\n return sum_rec if sum_rec != 4000 else -1\r\n\r\nn, m = map(int, input().split())\r\ngraph = {}\r\nfor i in range(1, n+1):\r\n graph[i] = []\r\nfor _ in range(m):\r\n musk1, musk2 = map(int, input().split())\r\n graph[musk1].append(musk2)\r\n graph[musk2].append(musk1)\r\n\r\nprint(bear_three(graph))", "M = int(1e12)\n\nn, m = map(int, input().split())\ng = [set() for _ in range(n + 1)]\ne = []\n\nfor _ in range(m):\n a, b = map(int, input().split())\n e += [(a, b)]\n g[a] |= {b}\n g[b] |= {a}\n\nans = M\nfor a, b in e:\n for i in g[a] & g[b]:\n ans = min(ans, len(g[a]) + len(g[b]) + len(g[i]) - 6)\n\nprint(ans if ans < M else -1)\n", "n, m = [int(i) for i in input().split()]\r\n \r\nv = [set() for i in range(n+1)]\r\n \r\nfor i in range(m):\r\n x, y = [int(i) for i in input().split()]\r\n v[x].add(y)\r\n v[y].add(x)\r\n\r\nvp = {}\r\ninitalValue = 10**10000\r\nresultSum = initalValue\r\nfor i in range(1, n+1):\r\n for j in v[i]:\r\n a = str(i) + str(j)\r\n b = str(j) + str(i)\r\n if(a in vp or b in vp): continue\r\n \r\n terceiros = v[i].intersection(v[j])\r\n \r\n for k in terceiros:\r\n soma = len(v[i]) + len(v[j])\r\n soma += len(v[k]) - 6\r\n resultSum = min(resultSum, soma)\r\n \r\n vp[a] = 1\r\n vp[b] = 1\r\n \r\nif(resultSum == initalValue):\r\n print(-1)\r\nelse:\r\n print(resultSum)", "__author__ = 'Juan Barros'\r\n'''\r\nhttp://codeforces.com/problemset/problem/574/B\r\n'''\r\n\r\ninf = 9999999999\r\n\r\nn, m = list(map(int, input().split()))\r\ndegree = [0]*(n+1)\r\nM = [[False]*(n+1) for i in range(n+1)]\r\nfor i in range(m):\r\n a, b = list(map(int, input().split()))\r\n M[a][b] = True\r\n M[b][a] = True\r\n degree[a] += 1\r\n degree[b] += 1\r\nresult = inf\r\nfor i in range(n+1):\r\n for j in range(n+1):\r\n if M[i][j]:\r\n for k in range(j + 1, n +1):\r\n if M[i][k] and M[j][k]:\r\n result = min(result, degree[i]+degree[j]+degree[k])\r\nprint(-1 if result == inf else (result - 6))", "n, m = map(int, input().split())\r\nadj = [[] for i in range(n)]\r\n\r\nfor i in range(m):\r\n joints = list(map(int, input().split()))\r\n adj[joints[0] - 1].append(joints[1] - 1)\r\n adj[joints[1] - 1].append(joints[0] - 1)\r\n\r\npopularity = []\r\nfor i in range(n):\r\n popularity.append(len(adj[i]))\r\n\r\nmin_popularity = m + 1\r\nfor first in range(0, n - 2):\r\n if popularity[first] >= 2:\r\n for second in range(first + 1, n - 1):\r\n if popularity[second] >= 2 and second in adj[first]:\r\n for third in range(second + 1, n):\r\n if third in adj[first] and third in adj[second] and \\\r\n (popularity[first] + popularity[second] + popularity[third] - 6) < min_popularity:\r\n min_popularity = popularity[first] + popularity[second] + popularity[third] - 6\r\n\r\nprint((-1, min_popularity)[min_popularity != m + 1])\r\n", "def musketeers(n, m, E):\n N = {i:set() for i in range(1, n+1)}\n for a, b in E:\n N[a].add(b)\n N[b].add(a)\n m = -1\n for a, b in E:\n c = min(N[a] & N[b], key=lambda c: len(N[c]), default=None)\n if c:\n v = len(N[a]) + len(N[b]) + len(N[c]) - 6\n m = v if m == -1 else min(m, v)\n return m\n\n\ndef pe():\n a, b = map(int, input().split())\n return a, b\n\n\ndef main():\n n, m = map(int, input().split())\n E = [pe() for _ in range(m)]\n print(musketeers(n, m, E))\n\n##########\n\nimport sys\nimport time\nimport traceback\nfrom contextlib import contextmanager\nfrom io import StringIO\n\ndef log(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n\n\n@contextmanager\ndef patchio(i):\n try:\n sys.stdin = StringIO(i)\n sys.stdout = StringIO()\n yield sys.stdout\n finally:\n sys.stdin = sys.__stdin__\n sys.stdout = sys.__stdout__\n\n\ndef do_test(k, test):\n try:\n log(f\"TEST {k}\")\n i, o = test\n with patchio(i) as r:\n t0 = time.time()\n main()\n t1 = time.time()\n if r.getvalue() == o:\n log(f\"OK ({int((t1-t0)*1000000)/1000:0.3f} ms)\\n\")\n else:\n log(f\"Expected:\\n{o}\"\n f\"Got ({int((t1-t0)*1000000)/1000:0.3f} ms):\\n{r.getvalue()}\")\n except Exception:\n traceback.print_exc()\n log()\n\n\ndef test(ts):\n for k in ts or range(len(tests)):\n do_test(k, tests[k])\n\n\ntests = [(\"\"\"\\\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n\"\"\", \"\"\"\\\n2\n\"\"\"), (\"\"\"\\\n7 4\n2 1\n3 6\n5 1\n1 7\n\"\"\", \"\"\"\\\n-1\n\"\"\")]\n\n\nif __name__ == '__main__':\n from argparse import ArgumentParser\n parser = ArgumentParser()\n parser.add_argument('--test', '-t', type=int, nargs='*')\n args = parser.parse_args()\n main() if args.test is None else test(args.test)\n", "n,m = map(int,input().split())\r\nn += 1\r\nvv,cnt,res = [set() for i in range(n)],[0]*n,[]\r\n\r\nfor i in range(m):\r\n\r\n a,b = map(int,input().split())\r\n\r\n for c in vv[a].intersection(vv[b]):\r\n\r\n res.append((a,b,c))\r\n\r\n vv[a].add(b)\r\n\r\n vv[b].add(a)\r\n\r\n cnt[a]+=1\r\n\r\n cnt[b]+=1\r\n\r\nf = cnt.__getitem__\r\n\r\nprint (min(sum(map(f,i)) for i in res)-6 if res else \"-1\")\r\n", "n, m = map(int, input().split())\nd2 = []\nod = []\narestas = []\n\nfor i in range(n):\n d2.append(set())\n od.append(0)\n\nfor i in range(m):\n a, b = map(int, input().split())\n arestas.append((a - 1, b - 1))\n d2[a - 1].add(b - 1)\n d2[b - 1].add(a - 1)\n od[a - 1] += 1\n od[b - 1] += 1\n\nminisum = 1000000\nfor edg in arestas:\n a, b = edg\n nerd = d2[a]&d2[b]\n for c in nerd:\n tmpsum = od[a] + od[b] + od[c] - 6\n if(tmpsum < minisum):\n minisum = tmpsum\n\nif(minisum == 1000000):\n print(\"-1\")\nelse:\n print(minisum)", "\r\n(n,m) = (int(i) for i in input().split())\r\nc={}\r\nb=[0]*(n+1)\r\nq=10000000\r\nfor j in range(m):\r\n (a,g) = (int(i) for i in input().split())\r\n if(a in c.keys()):\r\n c[a].append(g)\r\n else:\r\n c[a]=[g]\r\n if(g in c.keys()):\r\n c[g].append(a)\r\n else:\r\n c[g]=[a]\r\n b[a]=b[a]+1\r\n b[g]=b[g]+1\r\n\r\nfor first in c.keys():\r\n for second in c[first]:\r\n if(first>second):\r\n for third in c[second]:\r\n if(third in c[first])and(third!=first)and(second>third):\r\n if(q>b[third]+b[second]+b[first]-6):\r\n q=b[third]+b[second]+b[first]-6\r\n\r\n\r\nif(q==10000000):\r\n print(-1)\r\nelse:\r\n print(q)\r\n\r\n\r\n\r\n", "import sys\r\ninput=sys.stdin.readline\r\nfrom collections import defaultdict\r\nn,m=map(int,input().split())\r\ng=defaultdict(set)\r\nl=[]\r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\n g[a].add(b)\r\n g[b].add(a)\r\n l.append((a,b))\r\nans=10**10\r\nfor i,j in l:\r\n for k in range(1,n+1):\r\n if k in g[i] and k in g[j]:\r\n ans=min(ans,len(g[i])+len(g[j])+len(g[k]))\r\nif ans==10**10:print(-1)\r\nelse:\r\n ans-=6\r\n print(ans)", "n, m = map(int, input().split())\r\naux = [0] * (n+1)\r\nfor i in range(n+1): \r\n aux[i] = []\r\nfor i in range(m):\r\n u, v = map(int, input().split())\r\n aux[u].append(v)\r\n aux[v].append(u)\r\nans = 4000\r\nfor i in range(1, n+1):\r\n distinct = set(aux[i])\r\n for j in aux[i]:\r\n for k in aux[j]:\r\n if k in distinct:\r\n ans = min(ans, len(aux[i]) + len(aux[j]) + len(aux[k]) - 6)\r\nprint(ans if ans != 4000 else -1)", "n,m = map(int,input().split())\r\n \r\nedge = []\r\narr = [set() for i in range(n+1)]\r\n \r\nfor i in range(m):\r\n u,v = map(int,input().split())\r\n edge.append((u,v))\r\n arr[u].add(v)\r\n arr[v].add(u)\r\n \r\nret = 1e19\r\nfor u,v in edge:\r\n tmp = arr[u] & arr[v]\r\n for h in tmp:\r\n if h in arr[u] and h in arr[v]:\r\n ret = min(ret,len(arr[h])+len(arr[v])+len(arr[u])-6)\r\n \r\nif ret == 1e19:\r\n ret=-1\r\n\r\nprint(ret)", "n, m = map(int, input().split())\r\n \r\ngraph = []\r\n \r\nv = [set() for _ in range(n + 1)]\r\n \r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n graph += [(a, b)]\r\n v[a] |= {b}\r\n v[b] |= {a}\r\n \r\nk = [len(v[i]) for i in range(n+1)]\r\nanswer = -1\r\n \r\nfor a, b in graph:\r\n w = v[a] & v[b]\r\n for i in w:\r\n check = k[a] + k[b] + k[i] - 6\r\n if answer == -1 or (answer > check >= 0):\r\n answer = check\r\n\r\nprint(answer)", "n,m = map(int,input().split())\r\ne = [set() for i in range(n+1)] #khoi tao mang e chua cac tap hop chua dinh ke\r\n # index tu 1 den n tuong ung voi cac dinh\r\nE=[] # khoi tao mang E chua 2 dinh co quan he\r\nfor i in range(m):\r\n a,b = map(int, input().split())\r\n E.append((a,b)) # dua (a,b) vao mang chua 2 dinh co qan he\r\n e[a]|={b} # dua b vao tap hop dinh ke dinh a\r\n e[b]|={a} # dua a vao tap dinh ke dinh b\r\n # |= la phep hop tap hop\r\n\r\nl = [0]*(n+1)\r\nfor i in range(n+1):\r\n l[i] = len(e[i]) #l[i] so dinh ke voi dinh i\r\n\r\nlmin = 12000\r\n \r\n#xu li\r\n# xet tung cap dinh co quan he (a,b). lay giao cua 2 tap hop e[a],e[b]\r\n# xet tung phan tu x trong tap hop giao xem e[x] co chua a,b hay ko?\r\n\r\nfor a,b in E:\r\n t = e[a]&e[b] # & phep giao tap hop\r\n for x in t:\r\n if (a in e[x])and(b in e[x]):\r\n w = l[a] + l[b] + l[x] - 6\r\n if lmin > w:\r\n lmin = w\r\n\r\nprint(-1 if lmin==12000 else lmin)\r\n", "from collections import defaultdict\r\n\r\nn, m = map(int, input().split())\r\ngraph = defaultdict(list)\r\n\r\nfor i in range(m):\r\n v1, v2 = map(int, input().split())\r\n graph[v1].append(v2)\r\n graph[v2].append(v1)\r\n\r\nsum_recogs = float('inf')\r\n\r\nfor i in graph:\r\n for j in graph[i]:\r\n for k in graph[j]:\r\n if k in graph[i]:\r\n sum_recogs = min(sum_recogs, len(graph[i]) + len(graph[k]) + len(graph[j]))\r\n\r\nif sum_recogs == float('inf'):\r\n print(-1)\r\n\r\nelse:\r\n print(sum_recogs-6)", "\r\n\r\n#B. Bear and Three Musketeers\r\n\r\nfrom collections import deque ,defaultdict\r\nn , m = map(int,input().split())\r\n\r\ng = defaultdict(list)\r\n\r\nfor i in range(m):\r\n x , y = map(int,input().split())\r\n g[x].append(y)\r\n g[y].append(x)\r\n\r\nv = []\r\nres = 10**6+1\r\nfor i in range(1 , n + 1):\r\n curr = g[i]\r\n for j in g[i]:\r\n for k in g[j]:\r\n if k in curr:\r\n res = min(res , len(g[i]) + len(g[j]) + len(g[k]) - 6)\r\n\r\n#print(res)\r\n\r\nif res == 10**6+1:\r\n print('-1')\r\n\r\nelse:\r\n print(res)\r\n\r\n", "n, m = list(map(int, input().split()))\r\nadj = {}\r\n\r\ndef minSum(adj):\r\n sum = 4001\r\n for i in adj:\r\n for j in adj[i]:\r\n for k in adj[j]:\r\n if k in adj[i]:\r\n sum = min(len(adj[i]) + len(adj[j]) + len(adj[k]), sum)\r\n return sum\r\n \r\nfor i in range(m):\r\n x, y = list(map(int, input().split()))\r\n if x in adj: adj[x].append(y)\r\n else: adj[x] = [y]\r\n if y in adj: adj[y].append(x)\r\n else: adj[y] = [x]\r\n \r\nres = minSum(adj)\r\nif res == 4001: print('-1')\r\nelse: print(res-6)\r\n\r\n", "I = lambda : map(int, input().split())\r\nn, m = I()\r\ng = [set() for _ in range(n)]\r\n\r\nfor _ in range(m):\r\n a, b = I()\r\n g[a-1].add(b-1)\r\n g[b-1].add(a-1)\r\n\r\nresult = 99999\r\nfor i in range(n):\r\n for j in g[i]:\r\n for k in g[j]:\r\n if(k in g[i]):\r\n result = min(result, len(g[i]) + len(g[j]) + len(g[k]) - 6)\r\n\r\nif(result == 99999):\r\n print(-1)\r\nelse:\r\n print(result)", "n, m = map(int, input().split())\np = []\ns = [set() for _ in range(n+1)]\nh = [0] * (n+1)\nfor _ in range(m):\n a, b = map(int, input().split())\n p += [(a, b, c) for c in s[a].intersection(s[b])]\n s[a].add(b)\n s[b].add(a)\n h[a] += 1\n h[b] += 1\n\nprint(min(h[a] + h[b] + h[c] for a, b, c in p) - 6 if p else -1)\n", "def main():\r\n import sys\r\n \r\n tokens = [int(i) for i in sys.stdin.read().split()]\r\n tokens.reverse()\r\n \r\n n, m = tokens.pop(), tokens.pop()\r\n degree = [0] * n\r\n edges = [None] * m\r\n graph = [set() for i in range(n)]\r\n for i in range(m):\r\n a, b = tokens.pop() - 1, tokens.pop() - 1\r\n degree[a] += 1; degree[b] += 1\r\n edges[i] = (a, b)\r\n graph[a].add(b)\r\n graph[b].add(a)\r\n \r\n result = 10 ** 9\r\n for a, b in edges:\r\n if degree[a] > degree[b]: a, b = b, a\r\n for c in graph[a]:\r\n if c in graph[b]:\r\n result = min(result, degree[a] + degree[b] + degree[c])\r\n \r\n if result == 10 ** 9:\r\n print(-1)\r\n else:\r\n print(result - 6)\r\n \r\n \r\n \r\nmain()\r\n", "def main():\n from bisect import bisect\n n, m = map(int, input().split())\n l = [[] for _ in range(n + 1)]\n for _ in range(m):\n a, b = map(int, input().split())\n l[a].append(b)\n l[b].append(a)\n for la in l:\n la.sort()\n res = []\n for a, la in enumerate(l):\n le = len(la)\n for i in range(bisect(la, a), le - 1):\n b = la[i]\n for j in range(i + 1, le):\n c = la[j]\n if c in (l[b]):\n res.append(le + len(l[b]) + len(l[c]))\n print(min(res) - 6 if res else -1)\n\n\nif __name__ == '__main__':\n main()\n", "from collections import defaultdict, deque\nfrom functools import lru_cache\nfrom heapq import heappush, heappop\n\n #int(input())\n #list(map(int, input().split()))\n #map(int, input().split())\n #n,m = map(int, input().split())\n #graph = defaultdict(list)\n\n #a,b = map(int, input().split())\n #graph[a].append(b)\n #graph[b].append(a)\ndef solution():\n n,m = map(int, input().split())\n indegree = [0]*(n+1)\n graph = defaultdict(set)\n for _ in range(m):\n a,b = map(int, input().split())\n graph[a].add(b)\n graph[b].add(a)\n indegree[a] += 1\n indegree[b] += 1\n\n res = float(\"inf\")\n for node in graph:\n for nbr in graph[node]:\n for gc in graph[nbr].intersection(graph[node]):#\n if gc == nbr or gc == node:\n continue\n res = min(res, indegree[node] + indegree[nbr] + indegree[gc])\n\n if res == float(\"inf\"):\n print(-1)\n return;\n print(res - 6)\n\n\n\n#import sys\n#import threading\n#sys.setrecursionlimit(1 << 30)\n#threading.stack_size(1 << 27)\n#thread = threading.Thread(target=solution)\n#thread.start(); thread.join()\nsolution()\n", "import sys\n\nn, m = map(int, input().split())\n\nnarr = dict() # NO_ARESTA\nfreq = [0]*n\narestas = []\nfor _ in range(m):\n w1, w2 = map(int, input().split())\n narr[w1] = narr.get(w1, []) + [w2]\n narr[w2] = narr.get(w2, []) + [w1]\n freq[w1 - 1] += 1\n freq[w2 - 1] += 1\n arestas.append([w1, w2])\n\nfor i in range(1, n + 1):\n if (i not in narr):\n narr[i] = []\n \n\nminReco = sys.maxsize\nfor aresta in range(len(arestas)):\n no1 = arestas[aresta][0]\n no2 = arestas[aresta][1]\n\n for node in range(1, n+1):\n if (node != no1 and node != no2):\n if (no1 in narr[node] and no2 in narr[node]):\n recognitions = freq[no1 - 1] + freq[no2 - 1] + freq[node - 1] - 6\n if (recognitions < minReco):\n minReco = recognitions\n\n\nprint(\"-1\" if minReco == sys.maxsize else minReco)", "\nn, m = map(int,input().split())\nt = m\ngraph = [[] for _ in range(n+1)]\nwhile t > 0:\n a, b = map(int,input().split())\n graph[a].append(b)\n graph[b].append(a)\n t -= 1\nmin_rec = n*3\nfor i in range(1, n-1):\n if len(graph[i]) < 2:\n continue\n else:\n for j in graph[i]:\n if len(graph[j]) >= 2:\n for k in graph[j]:\n if k in graph[i]:\n temp = len(graph[i]) + len(graph[j]) + len(graph[k]) - 6\n if temp < min_rec:\n min_rec = temp\nif min_rec < n*3:\n print(min_rec)\nelse:\n print(-1)", "def build_graph(arr, largest):\r\n result = [[] for j in range(largest)]\r\n\r\n for a, b in arr:\r\n result[a - 1].append(b - 1)\r\n\r\n result[b - 1].append(a - 1)\r\n\r\n return result\r\n\r\n\r\ndef solve(graph):\r\n minimum = -1\r\n\r\n # Warrior friends\r\n for w in range(len(graph)):\r\n # Warrior friend friends\r\n for f in graph[w]:\r\n # Has a cycle. (The warrior is friend of its friend)\r\n for ff in graph[f]:\r\n if (w in graph[ff]):\r\n friendSum = len(graph[w]) + \\\r\n len(graph[f]) + len(graph[ff]) - 6\r\n if (minimum == -1 or friendSum < minimum):\r\n minimum = friendSum\r\n\r\n return minimum\r\n\r\n\r\nn, m = map(int, input().split())\r\n\r\n\r\ninputs = []\r\nlargest = 0\r\n\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n inputs.append((a, b))\r\n largest = max(largest, a, b)\r\n\r\ngraph = build_graph(inputs, largest)\r\nprint(solve(graph))", "n, m = map(int, input().split())\r\n\r\nedge = []\r\n\r\nconjunto = [set() for i in range(n + 1)]\r\n\r\nfor i in range(m):\r\n\r\n u, v = map(int, input().split())\r\n\r\n edge += [(u, v)]\r\n conjunto[u] |= {v}\r\n conjunto[v] |= {u}\r\n\r\nk = [len(conjunto[i]) for i in range(n+1)]\r\n\r\nsaida = -1\r\n\r\nfor u, v in edge:\r\n\r\n w = conjunto[u] & conjunto[v]\r\n for i in w:\r\n\r\n res = k[u] + k[v] + k[i] - 6\r\n\r\n if saida == -1 or (saida > res >= 0):\r\n\r\n saida = res\r\n\r\nprint(saida)\r\n", "from collections import defaultdict\r\nimport sys\r\n\r\nn,m = list(map(int,input().split()))\r\ngraph = defaultdict(list)\r\ndeg = {}\r\nfor i in range(m):\r\n a,b = list(map(int,input().split()))\r\n graph[a].append(b)\r\n graph[b].append(a)\r\nfor i in graph:\r\n deg[i] = len(graph[i])\r\nans = sys.maxsize\r\nfor i in graph:\r\n for j in graph[i]:\r\n for k in graph[j]:\r\n if i in graph[k]:\r\n ans = min(ans,deg[i]+deg[j]+deg[k]-6)\r\nif sys.maxsize==ans:\r\n ans=-1\r\n print(ans)\r\nelse:\r\n print(ans)", "R = lambda: map(int, input().split())\r\n\r\nn, m = R()\r\ngraph = [list() for _ in range(n + 1)]\r\nfor _ in range(m):\r\n u, v = R()\r\n graph[u].append(v)\r\n graph[v].append(u)\r\nres = 10 ** 9\r\nfor i in range(1, n + 1):\r\n for j1 in range(len(graph[i])):\r\n for j2 in range(j1 + 1, len(graph[i])):\r\n if graph[i][j1] in graph[graph[i][j2]]:\r\n res = min(res, len(graph[i]) + len(graph[graph[i][j1]]) + len(graph[graph[i][j2]]) - 6)\r\nprint(res if res < 10 ** 9 else -1)", "n, m = [int(x) for x in input().split()]\r\nadj_mat = [[False]*n for _ in range(n)]\r\ndeg = [0]*n\r\nedge_list = []\r\n\r\nfor _ in range(m):\r\n a, b = [int(x)-1 for x in input().split()]\r\n adj_mat[a][b] = adj_mat[b][a] = True\r\n edge_list.append((a,b))\r\n deg[a] += 1\r\n deg[b] += 1\r\n\r\nbest = float('inf')\r\nfor u, v in edge_list:\r\n for i in range(n):\r\n if adj_mat[i][u] and adj_mat[i][v] and i != u and i != v:\r\n best = min(best, deg[u]+deg[v]+deg[i]-6)\r\nif best < float('inf'):\r\n print(best)\r\nelse:\r\n print(-1)\r\n\r\n", "n,m = map(int,input().split())\r\ngrafo = [set() for i in range(n)]\r\narestas = []\r\nminimo = 1000000\r\n\r\nfor i in range(m):\r\n a = tuple(map(int, input().split()))\r\n a = (a[0]-1,a[1]-1)\r\n arestas.append(a)\r\n grafo[a[0]].add(a[1])\r\n grafo[a[1]].add(a[0])\r\nlens = [0]*n\r\nfor i in range(n):\r\n lens[i] = len(grafo[i]) \r\n \r\nfor i in range(m):\r\n a = arestas[i][0]\r\n b = arestas[i][1]\r\n inter = grafo[a] & grafo[b]\r\n for elem in inter:\r\n minimo = min(minimo, lens[a]+lens[b]+lens[elem]-6)\r\n \r\nif minimo == 1000000:\r\n print(-1)\r\nelse:\r\n print(minimo)\r\n", "from sys import stdin,stdout\r\nfrom collections import defaultdict\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nfor _ in range(1):#nmbr()):\r\n g=defaultdict(set)\r\n n,eg=lst()\r\n ans=float('inf')\r\n for i in range(eg):\r\n u,v=lst()\r\n g[u].add(v)\r\n g[v].add(u)\r\n for a in range(1,n+1):\r\n for b in g[a]:\r\n for c in g[a]&g[b]:\r\n ans=min(ans,len(g[a])+len(g[b])+len(g[c])-6)\r\n print(ans if ans!=float('inf') else -1)", "from collections import *\n\ndef li():return [int(i) for i in input().rstrip('\\n').split(' ')]\ndef st():return input().rstrip('\\n')\ndef val():return int(input())\n\nn, m = li()\nd = defaultdict(set)\nl = [0]*n\nfor i in range(m):\n a, b = li()\n d[a].add(b)\n d[b].add(a)\n l[a-1] += 1\n l[b-1] += 1\n\nfor i in d:\n d[i] = sorted(list(d[i]),key = lambda x:l[x-1])\nans = 100000000000000000000000000\nfor i in sorted(list(d),key = lambda x:l[x-1]):\n for j in d[i]:\n for k in d[j]:\n if k not in d[i]:continue\n else:\n ans = min(ans,l[i-1] + l[j-1] + l[k-1])\n break\n\n\nprint(ans - 6 if ans != 100000000000000000000000000 else -1)", "n, m = map(int, input().split())\r\n\r\nadj = [[] for _ in range(n)]\r\ndeg = [0] * n\r\n\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n adj[a - 1].append(b - 1)\r\n adj[b - 1].append(a - 1)\r\n deg[a - 1] += 1\r\n deg[b - 1] += 1\r\n\r\n# recogintion -- узнаваемость\r\nmin_rec = 3 * n\r\n\r\nfor i in range(n):\r\n for j in adj[i]:\r\n sumdeg = deg[i] + deg[j]\r\n for k in adj[j]:\r\n if i in adj[k] and sumdeg + deg[k] < min_rec:\r\n min_rec = sumdeg + deg[k]\r\n\r\nprint(min_rec - 6 if min_rec < 3 * n else -1)\r\n", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nn,m=(int(i) for i in input().split())\r\nadj=[[0 for i in range(n)] for j in range(n)]\r\ndeg=[0 for i in range(n)]\r\nfor i in range(m):\r\n u,v=(int(i) for i in input().split())\r\n adj[u-1][v-1]=1\r\n adj[v-1][u-1]=1\r\n deg[u-1]+=1\r\n deg[v-1]+=1\r\nans=10000000\r\nfor i in range(n):\r\n for j in range(i+1,n):\r\n if(adj[i][j]==1):\r\n for k in range(j+1,n):\r\n if(adj[i][k]==1 and adj[j][k]==1):\r\n ans=min(ans,deg[i]+deg[j]+deg[k]-6)\r\nif(ans==10000000):\r\n print(-1)\r\nelse:\r\n print(ans)", "ans = -1\r\nedge = list()\r\nn, m = map(int, input().split())\r\ns = [set() for i in range(n+1)]\r\nfor i in range(m):\r\n u, v = map(int, input().split())\r\n edge += [(u, v)]\r\n s[u] |= {v}\r\n s[v] |= {u}\r\nk = [len(s[i]) for i in range(n+1)]\r\nfor u, v in edge:\r\n w = s[u] & s[v]\r\n for i in w:\r\n res = k[u] + k[v] + k[i] - 6\r\n if ans == -1 or (ans > res >= 0):\r\n ans = res\r\nprint(ans)", "ans = 9999999999999\r\n\r\nn,m = map(int,input().split())\r\nd={}\r\nfor _ in range(m):\r\n a,b = map(int,input().split())\r\n if a in d:\r\n d[a].append(b)\r\n else:\r\n d[a]=[b]\r\n if b in d:\r\n d[b].append(a)\r\n else:\r\n d[b] = [a]\r\n\r\nfor i in d:\r\n for j in d[i]:\r\n for k in d[j]:\r\n if i in d[k]:\r\n ans = min(ans,len(d[i])+len(d[j])+len(d[k]))\r\nif ans==9999999999999:\r\n print(-1)\r\nelse:\r\n print(ans-6)", "n, m = map(int, input().split())\r\nedges = [set() for i in range(n + 1)]\r\nres = 10**10\r\npairs = []\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n edges[a] |= {b}\r\n edges[b] |= {a}\r\n pairs.append([a, b])\r\nfor pair in pairs:\r\n union = edges[pair[0]] & edges[pair[1]]\r\n a = pair[0]\r\n b = pair[1]\r\n for v in union:\r\n if a in edges[v] and b in edges[v]:\r\n res = min(len(edges[a]) + len(edges[b]) + len(edges[v]) - 6, res)\r\nprint(-1 if res == 10**10 else res)\r\n", "n, m = (int(x) for x in input().split())\r\n\r\nadj = [0] * n\r\n\r\nfor i in range(n):\r\n adj[i] = []\r\n\r\n\r\nfor i in range(m):\r\n a, b = (int(x) for x in input().split())\r\n adj[a-1].append(b - 1)\r\n adj[b-1].append(a - 1)\r\n\r\n# print(adj)\r\n\r\nbest = 1000000\r\n\r\nfor i in range(n):\r\n cur_set = set(adj[i])\r\n for j in adj[i]:\r\n for k in adj[j]:\r\n if k in cur_set:\r\n best = min(best, len(adj[i]) + len(adj[j]) + len(adj[k]) - 6)\r\n\r\nif best == 1000000:\r\n best = - 1\r\n\r\nprint(best)\r\n", "def main():\r\n M = int(1e12) # $$ +\\infty $$\r\n\r\n n, m = map(int, input().split())\r\n graph = [set() for _ in range(n + 1)]\r\n edges = []\r\n for _ in range(m):\r\n a, b = map(int, input().split())\r\n edges += [(a, b)]\r\n graph[a] |= {b}\r\n graph[b] |= {a}\r\n\r\n res = M\r\n for a, b in edges:\r\n for common in graph[a] & graph[b]:\r\n res = min(res, len(graph[a]) + len(graph[b]) + len(graph[common]) - 6)\r\n print(res if res < M else -1)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "import itertools\r\nimport math\r\nfrom math import gcd as gcd\r\nimport sys\r\nimport queue\r\nimport itertools\r\nfrom heapq import heappop, heappush\r\nimport random\r\n\r\n\r\ndef solve():\r\n n, m = map(int, input().split())\r\n\r\n g = [set() for i in range(n)]\r\n\r\n for i in range(m):\r\n a, b = map(int, input().split())\r\n a -= 1\r\n b -= 1\r\n g[a].add(b)\r\n g[b].add(a)\r\n\r\n res = 1 << 60\r\n\r\n for f in range(n):\r\n for s in g[f]:\r\n cand = g[f] & g[s]\r\n if len(cand) != 0:\r\n for k in cand:\r\n res = min(res, len(g[f]) + len(g[s]) - 4 + len(g[k]) - 2)\r\n\r\n if res == 1 << 60:\r\n print(-1)\r\n else:\r\n print(res)\r\n\r\n\r\nif __name__ == '__main__':\r\n multi_test = 0\r\n\r\n if multi_test:\r\n t = int(sys.stdin.readline())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "def minSum(adj):\n sum = 4001\n for i in adj:\n for j in adj[i]:\n for k in adj[j]:\n if k in adj[i]:\n sum = min(len(adj[i]) + len(adj[j]) + len(adj[k]), sum)\n return sum\n\nn, m = list(map(int, input().split()))\nadj = {}\n\nfor i in range(m):\n a, b = list(map(int, input().split()))\n if a in adj: adj[a].append(b)\n else: adj[a] = [b]\n if b in adj: adj[b].append(a)\n else: adj[b] = [a]\n\nresult = minSum(adj)\nif result == 4001: print('-1')\nelse: print(result-6)", "from collections import defaultdict\r\nfrom itertools import combinations\r\n\r\nread_many = lambda type_: list(map(type_, input().split()))\r\n\r\ndef main():\r\n n, m = read_many(int) \r\n relations = defaultdict(lambda: {})\r\n\r\n d={}\r\n\r\n\r\n for i in range(m):\r\n w1, w2 = read_many(int)\r\n relations[w1][w2] = 0\r\n relations[w2][w1] = 0\r\n \r\n # Procura 3 mosqueteiros que se conhecem e minimizam o problema\r\n lowest_rec, know_each_other_penalty = float(\"inf\"), 6\r\n for w1 in range(1, n+1): \r\n w1_k = relations[w1].keys()\r\n w1_rec = len(w1_k)\r\n if w1_rec >= 2:\r\n for w2 in w1_k:\r\n w2_k = set(relations[w2].keys())\r\n w2_rec = len(w2_k)\r\n common_friends = set(w1_k).intersection(w2_k)\r\n for w3 in common_friends:\r\n rec_group = w1_rec + w2_rec + len(relations[w3]) - know_each_other_penalty\r\n\r\n if rec_group < lowest_rec: \r\n lowest_rec = rec_group\r\n \r\n print( -1 if lowest_rec == float(\"inf\") else lowest_rec )\r\n\r\nif __name__==\"__main__\":\r\n main()", "read = lambda: map(int, input().split())\r\nn, m = read()\r\nG = [set() for i in range(n + 1)]\r\nS = [0 for i in range(n + 1)]\r\nfor i in range(m):\r\n a, b = read()\r\n G[a].add(b)\r\n G[b].add(a)\r\n S[a] += 1\r\n S[b] += 1\r\nans = 10 ** 10\r\nfor i in range(1, n + 1):\r\n for j in G[i]:\r\n for k in G[j]:\r\n if i in G[k]:\r\n x = S[i] + S[j] + S[k] - 6\r\n ans = min(x, ans)\r\nif ans == 10 ** 10:\r\n ans = -1\r\nprint(ans)", "n,m=map(int,input().split())\r\ne=[set() for i in range(n+1)]\r\nE=[]\r\nmi=1000000000000\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\n E+=[(a,b)]\r\n e[a]|={b}\r\n e[b]|={a}\r\nl=[len(e[i]) for i in range(n+1)]\r\nfor a,b in E:\r\n t=e[a]&e[b]\r\n for x in t:\r\n if a in e[x] and b in e[x]:\r\n k=l[a]+l[b]+l[x]-6\r\n if k<mi: mi=k\r\nprint(-1 if mi==1000000000000 else mi)", "n, m = map(int, input().split())\r\namatr = [[0] * n for i in range(n)]\r\nalist = [[] for i in range(n)]\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n amatr[a - 1][b - 1] = 1\r\n amatr[b - 1][a - 1] = 1\r\n alist[a - 1].append(b - 1)\r\n alist[b - 1].append(a - 1)\r\n\r\nknown = [len(alist[i]) for i in range(n)]\r\n\r\nans = 10**10\r\n\r\nfor first in range(n):\r\n for second in alist[first]:\r\n if amatr[first][second] == 1:\r\n for third in alist[second]:\r\n if amatr[third][second] == 1:\r\n if amatr[first][third] == 1:\r\n ans = min(ans, known[first] + known[second] + known[third] - 6)\r\n amatr[first][second] = 0\r\n amatr[second][first] = 0\r\n\r\nprint(ans if ans < 10 ** 10 else -1)", "n, m = map(int,input().split())\r\ngr = [set() for _ in range(n)]\r\ndeg = [0 for i in range(n)]\r\nans = 10 ** 10\r\nfor _ in range(m):\r\n a,b = map(int,input().split())\r\n gr[a - 1].add(b - 1)\r\n gr[b - 1].add(a - 1)\r\n deg[a - 1] += 1\r\n deg[b - 1] += 1\r\nfor i in range(n):\r\n if deg[i] < 2:\r\n continue\r\n for j in gr[i]:\r\n for k in gr[i]:\r\n if j in gr[k]:\r\n ans = min(ans, deg[i] + deg[j] + deg[k] - 6)\r\nprint(ans if ans != 10 ** 10 else - 1)\r\n", "n, m = map(int, input().split())\r\nlistaAdj = [[] for j in range(n)]\r\nsoma = float('inf')\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n listaAdj[a - 1].append(b - 1)\r\n listaAdj[b - 1].append(a - 1)\r\ntotal = [len(listaAdj[i]) for i in range(n)]\r\nfor i in range(n):\r\n for j in listaAdj[i]:\r\n for k in set(listaAdj[i]).intersection(set(listaAdj[j])):\r\n soma = min(soma, total[i]+total[j]+total[k]-6)\r\nif soma == float('inf'):\r\n print(-1)\r\nelse:\r\n print(soma)", "mod = int(1e9+7)\nans = 0\nN = int(5005)\nadj = [[]for i in range(N)]\nadjm = [[False for i in range(N)]for j in range(N)]\nvisited = [False for i in range(N)]\ndegree = [0 for i in range(N)]\ndp = [-1]*N\ninf = int(1e10)\n\ndef solve():\n\tn,m = map(int,input().split())\n\tfor i in range(m):\n\t\ta,b = map(int,input().split())\n\t\tadjm[a][b] = True\n\t\tadjm[b][a] = True\n\t\tdegree[a]+=1\n\t\tdegree[b]+=1\n\tres = inf\n\tfor i in range(1,n+1):\n\t\tfor j in range(i+1,n+1):\n\t\t\tif adjm[i][j]:\n\t\t\t\tfor k in range(j+1,n+1):\n\t\t\t\t\tif adjm[i][k] and adjm[j][k]:\n\t\t\t\t\t\tres = min(res,degree[i]+degree[j]+degree[k])\n\tif res==inf:\n\t\tprint(-1)\n\telse:\n\t\tprint(res-6)\n\n\n\n\n\n\n\n\t\n\n\n\n\n# number of test cases\nt = 1\n#t = int(input())\nfor i in range(t):\n\tsolve()\n\n\n\n\n\n\n\n\n\n", "n, m = list(map(lambda x: int(x), input().split()))\r\n\r\nt = [[False for j in range(4001)] for i in range(4001)]\r\ndegree = [0 for i in range(4001)]\r\n\r\nfor i in range(m):\r\n a, b = list(map(lambda x: int(x), input().split()))\r\n t[a][b] = True\r\n t[b][a] = True\r\n degree[a] += 1\r\n degree[b] += 1\r\n\r\nres = 30000\r\nfor i in range(1, n+1):\r\n for j in range(i+1, n+1):\r\n if t[i][j]:\r\n for k in range(j+1, n+1):\r\n if t[i][k] and t[j][k]:\r\n res = min(res, degree[i]+degree[j]+degree[k])\r\n\r\nif res == 30000: \r\n print(\"-1\")\r\nelse: \r\n print(res - 6)", "a, b = map(int, input().split())\r\nc = [[] for i in range(a)]\r\n\r\nfor i in range(b):\r\n first, second = map(int, input().split())\r\n c[first-1].append(second-1)\r\n c[second-1].append(first-1)\r\n\r\nres = 100000\r\nfor i in range(a):\r\n current = set(c[i])\r\n for j in c[i]:\r\n for k in c[j]:\r\n if k in current:\r\n res = min(res, len(c[i]) + len(c[j]) + len(c[k]) - 6)\r\n\r\nprint(-1 if res == 100000 else res)", "def calc_tamanhos(num_guerreiros, tamanhos):\r\n for i in range(num_guerreiros):\r\n tamanhos[i] = len(grafo[i])\r\n return tamanhos\r\n\r\nnum_guerreiros, num_pares = map(int, input().split())\r\n\r\ngrafo = [set() for i in range(num_guerreiros)]\r\narestas = []\r\nfor i in range(num_pares):\r\n guerreiro_a, guerreiro_b = map(int, input().split())\r\n guerreiro_a = guerreiro_a -1\r\n guerreiro_b = guerreiro_b - 1\r\n par = (guerreiro_a, guerreiro_b)\r\n arestas.append(par)\r\n grafo[guerreiro_a].add(guerreiro_b)\r\n grafo[guerreiro_b].add(guerreiro_a)\r\n\r\ntamanhos = [0] * num_guerreiros\r\ntamanhos = calc_tamanhos(num_guerreiros, tamanhos)\r\n\r\naux = 10**10000\r\nsaida = aux\r\nfor i in range(num_pares):\r\n j = arestas[i][0]\r\n k = arestas[i][1]\r\n total = grafo[j] & grafo[k]\r\n for elem in total:\r\n saida = min(saida, tamanhos[j] + tamanhos[k] + tamanhos[elem] - 6)\r\n \r\nif saida == aux:\r\n print(-1)\r\nelse:\r\n print(saida)", "n, m = map(int, input().split())\r\na = [[False] * n for _ in range(n)]\r\nedges = []\r\nd = [0] * n\r\nfor i in range(m):\r\n u, v = map(int, input().split())\r\n a[u - 1][v - 1] = a[v - 1][u - 1] = True\r\n edges.append((u - 1, v - 1))\r\n d[u - 1] += 1\r\n d[v - 1] += 1\r\nans = int(1e10)\r\nfor i in range(m):\r\n u, v = edges[i][0], edges[i][1]\r\n for j in range(n):\r\n if a[u][j] and a[v][j] and u != j and v != j:\r\n ans = min(ans, d[u] + d[v] + d[j] - 6)\r\nprint(-1 if ans == int(1e10) else ans)", "# Mateus Brito de Sousa Rangel - 117110914\r\n\r\nn, m = map(int, input().split())\r\nadj = [0] * n\r\n\r\nfor i in range(n): \r\n adj[i] = []\r\n \r\nfor i in range(m):\r\n u, v = map(int, input().split())\r\n adj[u-1].append(v-1)\r\n adj[v-1].append(u-1)\r\n \r\nres = int(1e6)\r\nfor i in range(n):\r\n curr = set(adj[i])\r\n \r\n for j in adj[i]:\r\n for k in adj[j]:\r\n if k in curr:\r\n res = min(res, len(adj[i]) + len(adj[j]) + len(adj[k]) - 6)\r\n \r\nprint(-1 if res == int(1e6) else res)", "n, m = map(int, input().split())\r\naux = m\r\ngraph = [[] for j in range(n + 1)]\r\n\r\nwhile (aux > 0):\r\n e1, e2 = map(int, input().split())\r\n graph[e1].append(e2)\r\n graph[e2].append(e1)\r\n aux = aux - 1\r\n\r\nminimum = n * 3\r\n\r\nfor i in range(1, (n - 1)):\r\n if (len(graph[i]) < 2):\r\n continue\r\n else:\r\n for e in graph[i]: \r\n if (len(graph[e]) < 2):\r\n continue\r\n else:\r\n for z in graph[e]:\r\n if z in graph[i]:\r\n temp = len(graph[i]) + len(graph[e]) + len(graph[z]) - 6\r\n if (temp < minimum):\r\n minimum = temp\r\n \r\nif (minimum < (n * 3)):\r\n print(minimum)\r\nelse:\r\n print(-1)", "n, m = map(int, input().split())\r\n\r\nMAX = 4107\r\nrecognition = [0] * MAX\r\nt = [[False] * MAX for i in range(MAX)]\r\n\r\nfor i in range(m):\r\n a, b = map(int,input().split())\r\n t[a][b] = True\r\n t[b][a] = True\r\n recognition[a] += 1\r\n recognition[b] += 1\r\n\r\nresult = int(1e9)\r\n\r\nfor a in range(1, n+1):\r\n for b in range(a+1, n+1):\r\n if t[a][b]:\r\n for c in range(b+1,n+1):\r\n if t[a][c] and t[b][c]:\r\n result = min(result, recognition[a]+recognition[b]+recognition[c] - 6)\r\n\r\nif result == int(1e9):\r\n print(\"-1\")\r\nelse:\r\n print(result)", "n, m = map(int, input().split())\r\nEs = [set() for i in range(n)]\r\nedges = set()\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n a -= 1\r\n b -= 1\r\n Es[a].add(b)\r\n Es[b].add(a)\r\n edges.add((a, b))\r\nrecord = float('inf')\r\nfor a, b in edges:\r\n cost_a = len(Es[a]) - 2\r\n cost_b = len(Es[b]) - 2\r\n cost = cost_a + cost_b\r\n if cost >= record:\r\n continue\r\n if cost_a > cost_b:\r\n a, b = b, a\r\n for c in Es[a]:\r\n cost_abc = cost + len(Es[c]) - 2\r\n if b in Es[c]:\r\n if cost_abc < record:\r\n record = cost_abc\r\nif record == float('inf'):\r\n print(-1)\r\nelse:\r\n print(record)\r\n", "#!/usr/bin/env python\n# 574B_musk.py - Codeforces.com 574B Musk program by Sergey 2015\n\nimport unittest\nimport sys\n\n###############################################################################\n# Musk Class\n###############################################################################\n\n\nclass Musk:\n \"\"\" Musk representation \"\"\"\n\n def __init__(self, test_inputs=None):\n \"\"\" Default constructor \"\"\"\n\n it = iter(test_inputs.split(\"\\n\")) if test_inputs else None\n\n def uinput():\n return next(it) if it else sys.stdin.readline().rstrip()\n\n # Reading single elements\n self.n, self.m = map(int, uinput().split())\n\n # Reading multiple lines of pairs\n pairs = (\" \".join(uinput() for i in range(self.m))).split()\n self.numa = [int(pairs[i])-1 for i in range(0, 2*self.m, 2)]\n self.numb = [int(pairs[i])-1 for i in range(1, 2*self.m, 2)]\n\n # Array of sets\n self.sets = [set() for i in range(self.n)]\n for i in range(self.m):\n self.sets[self.numa[i]].add(self.numb[i])\n self.sets[self.numb[i]].add(self.numa[i])\n\n MAX = 10000000000000000\n self.min_rank = MAX\n for i in range(self.n):\n for j in self.sets[i]:\n if j > i:\n un = len(self.sets[i]) + len(self.sets[j])\n intersect = self.sets[i].intersection(self.sets[j])\n for s in intersect:\n uns = un + len(self.sets[s])\n rank = uns - 6\n if rank < self.min_rank:\n self.min_rank = rank\n if self.min_rank == MAX:\n self.min_rank = -1\n\n def calculate(self):\n \"\"\" Main calcualtion function of the class \"\"\"\n\n result = self.min_rank\n\n return str(result)\n\n###############################################################################\n# Unit Tests\n###############################################################################\n\n\nclass unitTests(unittest.TestCase):\n\n def test_single_test(self):\n \"\"\" Musk class testing \"\"\"\n\n # Constructor test\n test = \"5 6\\n1 2\\n1 3\\n2 3\\n2 4\\n3 4\\n4 5\"\n d = Musk(test)\n self.assertEqual(d.n, 5)\n self.assertEqual(d.m, 6)\n self.assertEqual(d.numa, [0, 0, 1, 1, 2, 3])\n self.assertEqual(d.numb, [1, 2, 2, 3, 3, 4])\n\n self.assertEqual(d.sets[0], {1, 2})\n self.assertEqual(d.sets[3], {1, 2, 4})\n\n # Sample test\n self.assertEqual(Musk(test).calculate(), \"2\")\n\n # Sample test\n test = \"7 4\\n2 1\\n3 6\\n5 1\\n1 7\"\n self.assertEqual(Musk(test).calculate(), \"-1\")\n\n # Sample test\n test = \"1\\n1 2\\n1\"\n # self.assertEqual(Musk(test).calculate(), \"0\")\n\n # My tests\n test = \"1\\n1 2\\n1\"\n # self.assertEqual(Musk(test).calculate(), \"0\")\n\n # Time limit test\n # self.time_limit_test(5000)\n\n def time_limit_test(self, nmax):\n \"\"\" Timelimit testing \"\"\"\n import random\n import timeit\n\n # Random inputs\n test = str(nmax) + \" \" + str(nmax) + \"\\n\"\n numnums = [str(i) + \" \" + str(i+1) for i in range(nmax)]\n test += \"\\n\".join(numnums) + \"\\n\"\n nums = [random.randint(1, 10000) for i in range(nmax)]\n test += \" \".join(map(str, nums)) + \"\\n\"\n\n # Run the test\n start = timeit.default_timer()\n d = Musk(test)\n calc = timeit.default_timer()\n d.calculate()\n stop = timeit.default_timer()\n print(\"\\nTimelimit Test: \" +\n \"{0:.3f}s (init {1:.3f}s calc {2:.3f}s)\".\n format(stop-start, calc-start, stop-calc))\n\nif __name__ == \"__main__\":\n\n # Avoiding recursion limitaions\n sys.setrecursionlimit(100000)\n\n if sys.argv[-1] == \"-ut\":\n unittest.main(argv=[\" \"])\n\n # Print the result string\n sys.stdout.write(Musk().calculate())\n", "n, m = map(int, input().split())\r\n\r\nadj = [[] for _ in range(n)]\r\n\r\nfor i in range(m):\r\n p, q = map(int, input().split())\r\n adj[p - 1].append(q - 1)\r\n adj[q - 1].append(p - 1)\r\n \r\nans = 10000 \r\nfor i in range(n):\r\n for j in adj[i]:\r\n for k in adj[j]:\r\n if k in adj[i] and len(adj[i]) + len(adj[j]) + len(adj[k]) - 6 < ans:\r\n ans = len(adj[i]) + len(adj[j]) + len(adj[k]) - 6\r\n \r\nprint(-1 if ans == 10000 else ans)", "def main():\n n, m = map(int, input().split())\n n += 1\n vv, cnt, res = [set() for _ in range(n)], [0] * n, []\n for _ in range(m):\n a, b = map(int, input().split())\n for c in vv[a].intersection(vv[b]):\n res.append((a, b, c))\n vv[a].add(b)\n vv[b].add(a)\n cnt[a] += 1\n cnt[b] += 1\n f = cnt.__getitem__\n print(min(sum(map(f, abc)) for abc in res) - 6 if res else -1)\n\n\nif __name__ == '__main__':\n main()\n", "n, m = map(int, input().split())\r\n\r\nadj = [[] for _ in range(n)]\r\ndeg = [0] * n\r\nedges = []\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n adj[a - 1].append(b - 1)\r\n adj[b - 1].append(a - 1)\r\n deg[a - 1] += 1\r\n deg[b - 1] += 1\r\n edges.append((a - 1, b - 1))\r\n\r\n# recogintion -- узнаваемость\r\nmin_rec = 3 * n\r\n\r\nfor a, b in edges:\r\n for i in adj[a]:\r\n if b in adj[i]:\r\n if deg[a] + deg[b] + deg[i] < min_rec:\r\n min_rec = deg[a] + deg[b] + deg[i]\r\n\r\nprint(min_rec - 6 if min_rec < 3 * n else -1)\r\n", "__author__ = 'JohnHook'\r\n\r\nn, m = list(map(int, input().split()))\r\n\r\ngraph = []\r\nfor i in range(n):\r\n graph.append([])\r\nused = [False] * n\r\nfor i in range(m):\r\n temp = list(map(int, input().split()))\r\n graph[temp[0] - 1].append(temp[1] - 1)\r\n graph[temp[1] - 1].append(temp[0] - 1)\r\n\r\nmn = float('Inf')\r\ndef rec(v):\r\n for i in graph[v]:\r\n if not used[i]:\r\n for j in graph[i]:\r\n if not used[j]:\r\n if j in graph[i] and j in graph[v]:\r\n global mn\r\n mn = min(mn, len(graph[v]) + len(graph[i]) + len(graph[j]) - 6)\r\n used[v] = True\r\n\r\nfor i in range(n):\r\n rec(i)\r\nprint(mn if mn != float('Inf') else -1)", "n, m = [int(x) for x in input().split()]\r\n\r\nadj = [set() for i in range(n + 1)]\r\ndegree = [0 for i in range(n + 1)]\r\nanswer = 999999\r\nedges = []\r\n\r\nfor i in range(m):\r\n u, v = [int(x) for x in input().split()]\r\n edges.append((u, v))\r\n\r\n adj[u].add(v)\r\n degree[u] += 1\r\n\r\n adj[v].add(u)\r\n degree[v] += 1\r\n\r\nfor e in edges:\r\n for w in adj[e[0]]:\r\n if w in adj[e[1]]:\r\n answer = min(answer, degree[w] + degree[e[0]] + degree[e[1]] - 6)\r\n\r\nif answer == 999999: print(-1)\r\nelse: print(answer)\r\n\r\n", "n, m = list(map(int, input().split()))\r\n \r\nma = [[] for i in range(n+1)]\r\n\r\n# preenchendo a matriz de adjacencias\r\nfor i in range(m):\r\n a, b = list(map(int, input().split()))\r\n ma[a].append(b)\r\n ma[b].append(a)\r\n \r\nmin_ = 999999\r\n \r\ndef rec(a, b=None, c=None):\r\n r1 = len(ma[a]) - 2\r\n r2 = len(ma[b]) - 2 if b else 0\r\n r3 = len(ma[c]) - 2 if c else 0\r\n return r1 + r2 + r3\r\n \r\nfor i in range(1, n+1):\r\n if rec(i) < 0:\r\n continue\r\n for j in ma[i]:\r\n if rec(j) < 0:\r\n continue\r\n for k in ma[j]:\r\n if k in ma[i]:\r\n r = rec(i, j, k)\r\n if(r < min_):\r\n min_ = r\r\n\r\nif(min_ != 999999):\r\n print(min_)\r\nelse:\r\n print(-1)\r\n", "\"\"\" Homework\n\n1) Implement island with BFS\n\n2) Think about a tree that answers queries:\n\"1 L R x\" - for every i in interval [L, R], change a[i] to x\n\"2 i\" - print a[i]\n\n2a) implement your version with (x, last_time) - DONE\n2b) implement a version with (x) only (avoid double memory)\nLazy propagation - when you are at vertex v, push its value to both its children\n\n3) implement gcd problem from scratch (well, you can cheat a little bit and take my code)\nTODO, next time (not your homework now)\n\n4) https://codeforces.com/problemset/problem/574/B\n\n\nNext time: binary search on a tree, Dijkstra\n\n\"\"\"\n\n# 1)\n\n# n = 4\n# m = [\n# [0, 0, 0, 1],\n# [1, 0, 1, 0],\n# [1, 1, 1, 0],\n# [1, 0, 1, 0],\n# ]\n\n# visited = set()\n\n# count = 0\n\n# directions = ((-1, 0), (1, 0), (0, 0), (0, -1), (0, 1))\n\n# def is_inside(r, c):\n# return 0 <= r and r < n and 0 <= c and c < n\n\n# def bfs(i, j):\n# l = [(i, j)]\n# for item in l:\n# visited.add(item)\n# for direction in directions:\n# r = item[0] + direction[0]\n# c = item[1] + direction[1]\n# if is_inside(r, c) and (r, c) not in visited and m[r][c] == 1:\n# l.append((r, c))\n\n# for i in range(n):\n# for j in range(n):\n# if m[i][j] == 1 and (i, j) not in visited:\n# bfs(i, j)\n# count += 1\n# print(count)\n\n# 2b)\n\n# n, q = [int(i) for i in input().split(' ')]\n# a = [int(i) for i in input().split(' ')]\n\n# base = 1\n# while base < n:\n# base *= 2\n\n# t = [None] * (base * 2)\n\n# for i in range(n):\n# t[base + i] = a[i]\n\n# def change(i, s, e, q_s, q_e, v):\n# if e < q_s or q_e < s:\n# return\n# if q_s <= s and q_e >= e:\n# if t[i] is None:\n# t[i] = v\n# return\n# if i < base:\n# change(i * 2, s, e, q_s, q_e, t[i])\n# change(i * 2 + 1, s, e, q_s, q_e, t[i])\n# t[i] = v\n# return\n# mid = (s + e) // 2\n# change(2 * i, s, mid, q_s, q_e, v)\n# change(2 * i + 1, mid + 1, e, q_s, q_e, v)\n\n\n# def query(index):\n# node = (base + index) // 2\n# value = t[base + index]\n# while node != 1:\n# if t[node] is not None:\n# value = t[node]\n# node //= 2\n# return value\n\n# for _ in range(q):\n# x = [int(i) for i in input().split(' ')]\n# if x[0] == 1:\n# change(1, 0, base - 1, x[1], x[2], x[3])\n# if x[0] == 2:\n# print(query(x[1]))\n\n# 4)\n\nn, m = [int(i) for i in input().split(' ')]\ngraph = {}\n\nfor _ in range(m):\n node = [int(i) for i in input().split(' ')]\n graph.setdefault(node[0], set())\n graph[node[0]].add(node[1])\n graph.setdefault(node[1], set())\n graph[node[1]].add(node[0])\n\noptions = set()\n\nfor i in graph:\n if len(graph[i]) >= 2:\n for j in graph[i]:\n if len(graph[j]) >= 2:\n for k in graph[j]:\n if i in graph[j] and j in graph[k] and k in graph[i]:\n options.add(tuple(sorted([i, j, k])))\n\nminimum = 4000 * 3\nif options:\n for option in options:\n minimum = min(minimum, len(graph[option[0]]) + len(graph[option[1]]) + len(graph[option[2]]) - 6)\n print(minimum)\nelse:\n print(-1)\n", "n,m = map(int, input().split())\r\nadj_list = [[] for j in range(n+1)]\r\nedges = {}\r\nfor i in range(m):\r\n u,v = map(int, input().split())\r\n adj_list[u].append(v)\r\n adj_list[v].append(u)\r\n edges[(min(u,v), max(u,v))] = True\r\n\r\ncost = float('inf')\r\nfor i in range(1, n):\r\n for j in adj_list[i]:\r\n for ele in adj_list[j]:\r\n if (min(ele,i) ,max(ele,i)) in edges:\r\n cost = min(cost, (len(adj_list[i]) + len(adj_list[j]) + len(adj_list[ele]))-6)\r\nif cost == float('inf'):\r\n print(-1)\r\nelse:\r\n print(cost)", "n,m = [int(index) for index in input().split()]\r\n \r\nv = [set() for index in range(n+1)]\r\n \r\nfor index in range(m):\r\n x,y = [int(index) for index in input().split()]\r\n v[x].add(y)\r\n v[y].add(x)\r\n\r\nvp = {}\r\ninitalValue = 10**10000\r\nresultSum = initalValue\r\nfor index in range(1,n+1):\r\n for j in v[index]:\r\n a = str(index)+str(j)\r\n b = str(j)+str(index)\r\n if(a in vp or b in vp): continue\r\n \r\n terceiros = v[index].intersection(v[j])\r\n \r\n for k in terceiros:\r\n soma = len(v[index])+len(v[j])\r\n soma+=len(v[k])-6\r\n resultSum = min(resultSum,soma)\r\n \r\n vp[a] = 1\r\n vp[b] = 1\r\n \r\nif(resultSum == initalValue):\r\n print(-1)\r\nelse:\r\n print(resultSum)", "firstLine = input().split(' ')\nwarriorsNum = int(firstLine[0])\nrelationsNum = int(firstLine[1])\nwarriors = []\nrelations = [0]* warriorsNum\nfor i in range(warriorsNum):\n warriors.append([False] * warriorsNum)\n\nfor i in range(relationsNum):\n line = input().split(' ')\n warrior1 = int(line[0]) - 1\n warrior2 = int(line[1]) - 1\n relations[warrior1] += 1\n relations[warrior2] += 1\n\n warriors[warrior1][warrior2] = True\n warriors[warrior2][warrior1] = True\n\nresult = -1\nfor i in range(warriorsNum):\n warriorRelations = relations[i]\n for j in range(i, warriorsNum):\n if(warriors[i][j]):\n for k in range(warriorsNum):\n if(warriors[k][i] and warriors[k][j]):\n recognitions = relations[i] + relations[j] + relations[k] - 6\n if(result == -1 or recognitions < result):\n result = recognitions \n\nprint(result)\n\n", "def bearAndThreeMustketeers(n,m,grafo):\r\n aux = m \r\n while aux > 0:\r\n entradaA, entradaB = map(int, input().split())\r\n grafo[entradaA].append(entradaB)\r\n grafo[entradaB].append(entradaA)\r\n aux -= 1\r\n resposta = n*3\r\n \r\n for i in range(1, n + 1):\r\n for j in range(len(grafo[i])):\r\n for k in range(j + 1, len(grafo[i])):\r\n if(grafo[i][j] in grafo[grafo[i][k]]):\r\n resposta = min(resposta, len(grafo[i]) + len(grafo[grafo[i][j]]) + len(grafo[grafo[i][k]]) - 6)\r\n \r\n if(resposta < n*3):\r\n print(resposta)\r\n else:\r\n print(-1)\r\n\r\nn, m = map(int, input().split())\r\ngrafo = [list() for _ in range(n + 1)]\r\nbearAndThreeMustketeers(n,m,grafo)", "def search_cicles(graph):\r\n ciclos = []\r\n for v1 in graph:\r\n for v2 in graph[v1]:\r\n for j1 in graph[v2]:\r\n if (j1 in graph[v1]):\r\n ciclos.append((v1, v2, j1))\r\n\r\n return ciclos\r\n\r\ndef chooses_musketeers(graph):\r\n ciclos = search_cicles(graph)\r\n if (len(ciclos) == 0):\r\n return -1\r\n\r\n samller = 10**5\r\n for cycle in ciclos:\r\n total = 0\r\n for v in cycle:\r\n result = len(graph[v]) - 2\r\n total += result\r\n\r\n if (total < samller):\r\n samller = total\r\n return samller\r\n\r\nn, m = map(int, input().split())\r\ngraph = {}\r\n\r\nfor i in range(1, n + 1):\r\n graph[i] = []\r\n\r\nfor i in range(m):\r\n origin, destiny = map(int, input().split())\r\n graph[origin].append(destiny)\r\n graph[destiny].append(origin)\r\n\r\nprint(chooses_musketeers(graph))", "#!/usr/bin/python\r\n\r\nimport sys\r\n\r\ninf = float('inf')\r\nsys.setrecursionlimit(100000)\r\n\r\nclass Graph(object):\r\n def __init__(self, v):\r\n self.edges = {}\r\n self.vertex_map = [[False for j in range(v+1)] for i in range(v+1)]\r\n\r\n def add_edge(self, u, v):\r\n edges, vertex_map = self.edges, self.vertex_map\r\n if not u in edges: edges[u] = []\r\n if not v in edges: edges[v] = []\r\n edges[u].append(v)\r\n edges[v].append(u)\r\n vertex_map[u][v] = vertex_map[v][u] = True\r\n\r\n def has_edge(self, u, v):\r\n edges, vertex_map = self.edges, self.vertex_map\r\n return self.vertex_map[u][v]\r\n\r\n def adj(self, u):\r\n edges, vertex_map = self.edges, self.vertex_map\r\n return [] if not u in edges else edges[u]\r\n\r\ndef dfs(graph, u, visited, rps):\r\n adju = graph.adj(u)\r\n ret = inf\r\n if len(adju) == 0 or visited[u]: return ret\r\n visited[u] = True\r\n # puts \"visited: #{u} #{adju}\"\r\n for v in adju:\r\n if visited[v]: continue\r\n r = dfs(graph, v, visited, rps)\r\n if ret > r: ret = r\r\n for v in adju:\r\n ae = set(adju) & set(graph.adj(v)) - set([u, v])\r\n if len(ae) == 0: continue\r\n for p in ae:\r\n if not visited[v]: continue\r\n if ret > rps[u] + rps[v] + rps[p] - 6:\r\n # print(u, v, p, graph.adj(u), graph.adj(v), graph.adj(p), rps[u], rps[v], rps[p])\r\n ret = rps[u] + rps[v] + rps[p] - 6\r\n return ret\r\n\r\ndef algo():\r\n vc, lc = [int(i) for i in input().split(' ')]\r\n graph = Graph(vc)\r\n rps = [0 for i in range(vc+1)]\r\n for i in range(1, lc+1):\r\n u, v = [int(i) for i in input().split(' ')]\r\n graph.add_edge(u, v)\r\n rps[u] += 1\r\n rps[v] += 1\r\n ret = inf\r\n visited = [False for i in range(vc+1)]\r\n for u in range(1, vc+1):\r\n r = dfs(graph, u, visited, rps)\r\n if ret > r: ret = r\r\n if ret == inf: ret = -1\r\n print(ret)\r\n\r\nalgo()\r\n", "from sys import stdin,stdout \r\ninput = stdin.readline\r\n\r\nn,m = map(int,input().split())\r\ngraph = [set([]) for i in range(n+1)]\r\npopularity = [0 for i in range(n+1)]\r\n\r\nconnections = []\r\nfor _ in range(m):\r\n x,y = map(int,input().split())\r\n graph[x].add(y)\r\n graph[y].add(x)\r\n connections.append((x,y))\r\n popularity[x] += 1\r\n popularity[y] += 1\r\n\r\n\r\nbest = 1e9\r\n\r\nfor x,y in connections:\r\n \r\n d = [0]*(n+1)\r\n for i in graph[x]:\r\n d[i] = 1\r\n \r\n for i in graph[y]:\r\n if(d[i] == 1):\r\n best = min(best,popularity[x]+popularity[y]+popularity[i]-6)\r\n\r\nif(best == 1e9):\r\n best = -1\r\n\r\nstdout.write(str(best))", "# # https://codeforces.com/blog/entry/20040\n# import sys\n# N, M = 4000 + 10, 4000 + 10\n# n, m = map(int, input().split())\n# g = [[0] * N for _ in range(N)]\n# deg = [0] * N\n# for _ in range(m):\n# u, v = map(int, input().split())\n# g[u][v] = 1\n# g[v][u] = 1\n# deg[u] += 1\n# deg[v] += 1\n\n# ans = sys.maxsize\n\n# for x in range(1, n + 1):\n# for y in range(x + 1, n + 1):\n# # we are O(n^2) times here\n# if g[x][y]:\n# # we are O(m) times here\n# for z in range(y + 1, n + 1):\n# # O(m * n) times here\n# if g[x][z] and g[y][z]:\n# ans = min(ans, deg[x] + deg[y] + deg[z])\n\n# print(\n# -1 if ans == sys.maxsize else ans - 6\n# )\n\n\n# 不会TLE的版本\nn, m = map(int, input().split())\nadj = [0] * n\nfor i in range(n):\n adj[i] = []\nfor i in range(m):\n u, v = map(int, input().split())\n adj[u-1].append(v-1)\n adj[v-1].append(u-1)\nres = int(1e6)\nfor i in range(n):\n curr = set(adj[i])\n for j in adj[i]:\n for k in adj[j]:\n if k in curr:\n res = min(res, len(adj[i]) + len(adj[j]) + len(adj[k]) - 6)\nprint(-1 if res == int(1e6) else res)\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n# AUTHOR: haya14busa\nimport sys\nimport io\n\nfrom collections import defaultdict\nfrom itertools import combinations\n\n\ndef solve(n, m, pairs):\n # return: minimum possible sum of their recognitions\n assert 3 <= n <= 4000 # number of warioor\n assert 0 <= m <= 4000 # number of pairs of warriors knowing each other\n # for (a, b) in pairs:\n # assert 1 <= a < b <= n \n\n recognitions = defaultdict(set)\n\n for (a, b) in pairs:\n recognitions[a].add(b)\n recognitions[b].add(a)\n\n minr = float('inf')\n\n for candidate, recognition in [(c, rs) for c, rs in recognitions.items() if len(rs) > 1]:\n for c2, c3 in [(a, b) for a, b in combinations(recognition, 2)\n if a in recognitions[b]]:\n sum_r = sum(map(lambda x: len(recognitions[x]), [candidate, c2, c3]))\n minr = min([sum_r, minr])\n if minr == float('inf'):\n return -1\n else:\n return minr - 2 * 3\n\n\n\ndef getinput():\n def getint():\n return int(input())\n\n def getints_line():\n return list(map(int, input().split(' ')))\n\n def getints(n):\n return [getint() for _ in range(n)]\n\n def getints_lines(n):\n return [getints_line() for _ in range(n)]\n n, m = getints_line()\n return [n, m, getints_lines(m)]\n\n\ndef iosolve():\n return str(solve(*getinput()))\n # return 'YES' if solve(*getinput()) else 'NO' # for boolean output\n # return '\\n'.join(map(str, solve(*getinput()))) # for multiple line output\n\n\ndef main():\n if sys.stdin.isatty():\n test()\n stdin_lines = getstdin_lines()\n sys.stdin = io.StringIO('\\n'.join(stdin_lines))\n if stdin_lines:\n print(iosolve())\n else:\n test()\n\n\ndef test():\n IO_TEST_CASES = [\n\n (\n # INPUT\n '''\\\n5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n ''',\n # EXPECT\n '''\\\n2\n '''\n ),\n\n (\n # INPUT\n '''\\\n7 4\n2 1\n3 6\n5 1\n1 7\n ''',\n # EXPECT\n '''\\\n-1\n '''\n ),\n\n\n ]\n\n # List[(List[arg for solve()], expect)]\n TEST_CASES = [\n # ([], None),\n ]\n\n # You do need to see below\n import unittest # to save memory, import only if test required\n import sys\n import io\n\n class Assert(unittest.TestCase):\n def equal(self, a, b):\n self.assertEqual(a, b)\n\n def float_equal(self, actual, expect, tolerance):\n self.assertTrue(expect - tolerance < actual < expect + tolerance)\n\n art = Assert()\n\n for inputs, expect in TEST_CASES:\n art.equal(solve(*inputs), expect)\n\n for stdin, expect in IO_TEST_CASES:\n sys.stdin = io.StringIO(stdin.strip())\n art.equal(iosolve(), expect.strip())\n # art.float_equal(float(iosolve()), float(expect.strip()), 10 ** -6)\n\n\ndef getstdin_lines():\n stdin = []\n while 1:\n try:\n stdin.append(input())\n except EOFError:\n break\n return stdin\n\nif __name__ == '__main__':\n main()\n", "number1,number2 = map(int,input().split())\r\n\r\naux = [[] for _ in range(number1+1)]\r\nmin = number1*3\r\n\r\nwhile number2>0:\r\n ai,bi = map(int,input().split())\r\n aux[ai].append(bi)\r\n aux[bi].append(ai)\r\n number2 -= 1\r\n\r\nfor i in range(1,number1-1):\r\n if len(aux[i]) < 2:\r\n continue\r\n else:\r\n for j in aux[i]: \r\n if len(aux[j]) < 2:\r\n continue\r\n else:\r\n for l in aux[j]:\r\n if l in aux[i]:\r\n temp = len(aux[i]) + len(aux[j]) + len(aux[l]) - 6\r\n if temp < min:\r\n min = temp\r\n \r\nif min < number1*3:\r\n print(min)\r\nelse:\r\n print(-1)", "def main():\r\n mode=\"filee\"\r\n if mode==\"file\":f=open(\"test.txt\",\"r\")\r\n get = lambda :[int(x) for x in (f.readline() if mode==\"file\" else input()).split()]\r\n [n,m]=get()\r\n mus={}\r\n for z in range(n):\r\n mus[z+1]=[]\r\n for z in range(m):\r\n [x,y]=get()\r\n mus[x].append(y)\r\n mus[y].append(x)\r\n removed=set()\r\n for i in range(n):\r\n if len(mus[i+1])==0:\r\n mus.pop(i+1)\r\n continue\r\n if len(mus[i+1])==1:\r\n removed.add(i+1)\r\n minn=4500\r\n found=False\r\n #print(mus)\r\n for i in mus:\r\n to_check = list(set(mus[i])-removed)\r\n for j in range(len(to_check[:-1])):\r\n if mus[i][j] in removed:\r\n continue\r\n for k in range(j+1,len(to_check)):\r\n if to_check[j] in mus[to_check[k]]:\r\n minn=min(minn,len(mus[i])+len(mus[to_check[j]]) + len(mus[to_check[k]])-6)\r\n #print(i,to_check[j],to_check[k])\r\n found=True\r\n print((minn if found else \"-1\"))\r\n if mode==\"file\":f.close()\r\n\r\n\r\nif __name__==\"__main__\":\r\n main()\r\n", "minimo = 1000000000000\r\ninf = minimo\r\n\r\ndef fill_list(limit):\r\n lista = []\r\n for i in range(limit):\r\n lista.append([0,0])\r\n return lista\r\n\r\ndef fill_matrix(limit):\r\n matrix = []\r\n for i in range(limit):\r\n line = []\r\n for j in range(limit):\r\n line.append(0)\r\n matrix.append(line)\r\n return matrix\r\n\r\ndef fill_dic(key):\r\n if (key in dic_roads):\r\n dic_roads[key] += 1\r\n else:\r\n dic_roads[key] = 1\r\n\r\nentrada = input().split()\r\nn = int(entrada[0])\r\nm = int(entrada[1])\r\n\r\npares = fill_list(m)\r\nadj_matrix = fill_matrix(n)\r\ndic_roads = {}\r\n\r\nfor i in range(m):\r\n values = input().split()\r\n u = int(values[0])\r\n v = int(values[1])\r\n\r\n pares[i][0] = u\r\n pares[i][1] = v\r\n\r\n u -= 1\r\n v -= 1\r\n\r\n fill_dic(u)\r\n fill_dic(v)\r\n\r\n adj_matrix[u][v] = 1\r\n adj_matrix[v][u] = 1\r\n\r\nfor i in range(m):\r\n u = pares[i][0] - 1\r\n v = pares[i][1] - 1\r\n\r\n for j in range(n):\r\n if (adj_matrix[u][j] == 1 and adj_matrix[v][j] == 1):\r\n total = dic_roads[u] + dic_roads[v] + dic_roads[j] - 6\r\n if (total < minimo):\r\n minimo = total\r\n\r\nif (minimo == inf):\r\n print(-1)\r\nelse:\r\n print(minimo)", "def main():\n n, m = map(int, input().split())\n n += 1\n vv, ee, cnt, res = [set() for _ in range(n)], [], [0] * n, []\n for _ in range(m):\n a, b = map(int, input().split())\n if a < b:\n vv[a].add(b)\n else:\n vv[b].add(a)\n cnt[a] += 1\n cnt[b] += 1\n ee.append((a, b))\n for a, b in ee:\n x = cnt[a] + cnt[b]\n for c in vv[a].intersection(vv[b]):\n res.append(x + cnt[c])\n print(min(res) - 6 if res else -1)\n\n\nif __name__ == '__main__':\n main()\n", "n, m = map(int, input().split())\r\nsolutions = []\r\nrecognitions = []\r\nknowledges = []\r\n\r\nfor i in range(n+1):\r\n knowledges.append(set())\r\n recognitions.append(0)\r\n \r\nfor i in range(m):\r\n x, y = map(int, input().split())\r\n\r\n for j in (knowledges[x].intersection(knowledges[y])):\r\n solutions.append((x, y, j))\r\n\r\n knowledges[x].add(y)\r\n knowledges[y].add(x)\r\n\r\n recognitions[x] += 1\r\n recognitions[y] += 1\r\n\r\nresult = -1\r\n\r\nfor i in solutions:\r\n sum = recognitions[i[0]] + recognitions[i[1]] + recognitions[i[2]] - 6\r\n if (result > 0):\r\n result = min(result, sum)\r\n else:\r\n result = sum \r\n\r\nprint(result) \r\n\r\n\r\n\r\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\nG = [[] for _ in range(n + 1)]\r\ns = set()\r\ncnt = [0] * (n + 1)\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n G[a].append(b)\r\n G[b].append(a)\r\n s.add((a, b))\r\n s.add((b, a))\r\n cnt[a] += 1\r\n cnt[b] += 1\r\ninf = pow(10, 9) + 1\r\nans = inf\r\nfor i in range(1, n + 1):\r\n u = G[i]\r\n for j in G[i]:\r\n for k in G[i]:\r\n if (j, k) in s:\r\n ans = min(ans, cnt[i] + cnt[j] + cnt[k] - 6)\r\nans = (ans + 1) % (inf + 1) - 1\r\nprint(ans)", "f = lambda: map(int, input().split())\r\nn, m = f()\r\nk = n + 1\r\ns = set()\r\nd = [[] for i in range(k)]\r\nfor j in range(m):\r\n u, v = f()\r\n if u > v: u, v = v, u\r\n s.add((u, v))\r\n d[u].append(v)\r\n d[v].append(u)\r\nfor t in d: t.sort()\r\np = [len(t) for t in d]\r\nb = 3 * n\r\nfor x in range(k):\r\n for i, u in enumerate(d[x]):\r\n for v in d[x][i + 1:]:\r\n if (u, v) in s:\r\n a = p[u] + p[v] + p[x]\r\n if a < b: b = a\r\nprint(b - 6 if b < 3 * n else -1)", "n,m = map(int,input().split())\nd = dict()\nfor i in range(1,n+1,1):\n d[i] = []\nX = []\nZ = set()\nfor i in range(m):\n u,v = map(int,input().split())\n d[u].append(v)\n d[v].append(u)\n X.append([u,v])\n Z.add((u,v))\n Z.add((v,u))\nans = [] \ncnt = 0 \nfor c in X:\n u,v = c[0],c[1]\n for j in range(1,n+1,1):\n if (u,j) in Z and (v,j) in Z:\n cnt += 1 \n ans.append([u,v,j])\nif cnt > 0:\n res = 1e9 + 7 \n for c in ans:\n u,v,j = c[0],c[1],c[2]\n t = len(d[u]) - 2 + len(d[v]) - 2 + len(d[j]) - 2 \n res = min(t,res)\n print(res)\nelse:\n print(-1)", "n, m = map(int, input().split())\n \nedge = []\n \nadjacent_vertex = [set() for _ in range(n + 1)]\n \nfor _ in range(m):\n u, v = map(int, input().split())\n edge += [(u, v)]\n adjacent_vertex[u] |= {v}\n adjacent_vertex[v] |= {u}\n \nk = [len(adjacent_vertex[i]) for i in range(n+1)]\nresult = -1\n \nfor u, v in edge:\n w = adjacent_vertex[u] & adjacent_vertex[v]\n for i in w:\n recognition = k[u] + k[v] + k[i] - 6\n if result == -1 or (result > recognition >= 0):\n result = recognition\n \nprint(result)\n\n\n", "n,m = map(int, input().split())\nd=[[] for i in range(n)]\n#f=[[0] for i in range(n)]\nf=[0]*n\nfor i in range(m):\n\ta=list(map(int, input().split()))\n\tf[a[0]-1]+=1\n\tf[a[1]-1]+=1\n\ta.sort()\n\td[a[1]-1]+=[a[0]]\n\t#d[a[0]-1]+=[a[1]]\nans=[]\nfor i in range(n):\n\td[i].sort()\n\td[i].reverse()\n\tfor j in d[i]:\n\t\t\n\t#\td[i].sort()\n\t#\td[i].reverse()\n\t\t#if d[j-1]\n\t\tfor k in d[i]: \n\t\t\tif k in d[j-1]:\n\t\t\t\t\n\t\t\t\t#print(k)\n\t\t\t\tres=f[k-1]-2+f[j-1]-2+f[i]-2\n\t\t\t\tans+=[res]\n\t\t\t\t#print(res)\n\t\t\t\t#print(k,f[k-1]-2,j,f[j-1]-2,i+1,f[i]-2)\nif ans:\n\tprint(min(ans))\t\nelse:\n\tprint('-1')\n#print(d)\n#print(f)\n" ]
{"inputs": ["5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "7 4\n2 1\n3 6\n5 1\n1 7", "5 0", "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "15 15\n4 15\n12 1\n15 6\n11 6\n15 7\n6 8\n15 10\n6 12\n12 8\n15 8\n15 3\n11 9\n7 3\n6 4\n12 11", "12 66\n9 12\n1 4\n8 4\n5 3\n10 5\n12 2\n3 2\n2 7\n1 7\n3 7\n6 2\n4 2\n6 10\n8 10\n4 6\n8 5\n12 6\n11 9\n7 12\n5 4\n11 7\n9 4\n10 4\n6 3\n1 6\n9 7\n3 8\n6 11\n10 9\n3 11\n11 1\n5 12\n8 2\n2 1\n3 1\n12 4\n3 9\n10 12\n8 11\n7 10\n11 5\n9 5\n8 7\n11 4\n8 1\n2 11\n5 1\n3 4\n8 12\n9 2\n10 11\n9 1\n5 7\n10 3\n11 12\n7 4\n2 10\n12 3\n6 8\n7 6\n2 5\n1 10\n12 1\n9 6\n8 9\n6 5", "3 0", "3 2\n2 3\n2 1", "3 3\n3 1\n3 2\n2 1", "4 6\n3 4\n1 3\n4 1\n3 2\n2 1\n4 2", "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 3\n5 8\n3 5\n7 8\n1 6", "15 17\n1 3\n7 10\n7 9\n8 13\n6 15\n8 2\n13 6\n10 5\n15 3\n4 15\n4 6\n5 11\n13 9\n12 2\n11 14\n4 12\n14 1", "25 10\n19 11\n19 13\n13 11\n13 22\n19 23\n19 20\n13 17\n19 14\n13 15\n19 4", "987 50\n221 959\n221 553\n959 695\n553 959\n819 437\n371 295\n695 553\n959 347\n595 699\n652 628\n553 347\n868 589\n695 221\n282 714\n351 703\n104 665\n755 436\n556 511\n695 347\n221 347\n243 874\n695 847\n863 501\n583 145\n786 221\n38 286\n72 397\n808 658\n724 437\n911 548\n405 759\n681 316\n648 328\n327 199\n772 139\n932 609\n859 576\n915 507\n379 316\n381 348\n918 871\n261 450\n443 389\n549 246\n901 515\n930 923\n336 545\n179 225\n213 677\n458 204", "4000 0"], "outputs": ["2", "-1", "-1", "5", "4", "27", "-1", "-1", "0", "3", "2", "3", "7", "6", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
101
1e05022190289ddb4726bb4ad2a1b069
Ancient Berland Circus
Nowadays all circuses in Berland have a round arena with diameter 13 meters, but in the past things were different. In Ancient Berland arenas in circuses were shaped as a regular (equiangular) polygon, the size and the number of angles could vary from one circus to another. In each corner of the arena there was a special pillar, and the rope strung between the pillars marked the arena edges. Recently the scientists from Berland have discovered the remains of the ancient circus arena. They found only three pillars, the others were destroyed by the time. You are given the coordinates of these three pillars. Find out what is the smallest area that the arena could have. The input file consists of three lines, each of them contains a pair of numbers –– coordinates of the pillar. Any coordinate doesn't exceed 1000 by absolute value, and is given with at most six digits after decimal point. Output the smallest possible area of the ancient arena. This number should be accurate to at least 6 digits after the decimal point. It's guaranteed that the number of angles in the optimal polygon is not larger than 100. Sample Input 0.000000 0.000000 1.000000 1.000000 0.000000 1.000000 Sample Output 1.00000000
[ "from decimal import Decimal\r\nimport math\r\n\r\ndef dis(x1, y1, x2, y2):\r\n\treturn math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))\r\n\r\ndef ang(a, b, c):\r\n\treturn math.acos((a*a + b * b - c * c) / (2.0 * a*b))\r\n\r\ndef zero(n):\r\n\treturn (n < 1e-3) and (n > -1e-3)\r\n\r\ndef check(n):\r\n\treturn zero(n - math.trunc(n + 0.5000))\r\n\r\nx1, y1 = map(Decimal, input().split())\r\nx2, y2 = map(Decimal, input().split())\r\nx3, y3 = map(Decimal, input().split())\r\n\r\na = dis(x1, y1, x2, y2)\r\nb = dis(x1, y1, x3, y3)\r\nc = dis(x2, y2, x3, y3)\r\n\r\ncc = 0.5 * (a + b + c)\r\n\r\nSabc = math.sqrt(cc * (cc - a) * (cc - b) * (cc - c))\r\n\r\nA = ang(a, b, c) / math.pi\r\nB = ang(b, c, a) / math.pi\r\nC = ang(c, a, b) / math.pi\r\n\r\nfor i in range(3, 1001):\r\n if check(A*i) and check(B*i) and check(C*i):\r\n break\r\n\r\nR = a * b * c / (4.0 * Sabc)\r\nt = 2.0 * math.pi / i\r\nMinS = R * R * math.sin(t) * math.pi / t\r\nprint('%.8f' % (MinS))\r\n", "from math import *\r\np =[list(map(float,input().split())) for i in range(3)] \r\n\r\n# print(p)\r\na,b,c=[hypot(x1-x2,y1-y2) for (x1,y1),(x2,y2) in [(p[0],p[1]),(p[0],p[2]),(p[1],p[2])]]\r\n# print(f\"a={a}, b={b}, c={c}\")\r\n\r\nA,B,C=[acos((y*y+z*z-x*x)/2/z/y) for x,y,z in [(a,b,c),(b,c,a),(c,a,b)]]\r\n# print(f\"A={A}, B={B}, C={C}\")\r\n\r\nR=a/2/sin(A) \r\n\r\ndef g(x,y):\r\n return x if y<1e-3 else g(y,fmod(x,y))\r\n\r\nu=2*g(A,g(B,C))\r\nprint(round(R * R * pi / u * sin(u),7))", "import math\r\nn1,n2,n3 = [float(y) for y in input().split()],[float(y) for y in input().split()],[float(y) for y in input().split()]\r\n\r\nlines = []\r\n\r\ndef farey(n):\r\n n1 = 0\r\n d1 = 1\r\n n2 = 1\r\n d2 = 1\r\n \r\n while True:\r\n nm = n1+n2\r\n dm = d1+d2\r\n if n*dm > nm:\r\n n1 = nm\r\n d1 = dm\r\n else:\r\n n2 = nm\r\n d2 = dm\r\n if abs(nm/dm - n) < 0.0000005:\r\n return nm,dm\r\n \r\ndef lcm(a,b):\r\n return a*b//math.gcd(a,b)\r\n\r\nfor i in [[n1,n2],[n1,n3],[n2,n3]]:\r\n if i[0][1] == i[1][1]:\r\n continue\r\n if len(lines) == 2:\r\n break\r\n grad = (i[0][0]-i[1][0])/(i[1][1]-i[0][1])\r\n px = (i[0][0]+i[1][0])/2\r\n py = (i[0][1]+i[1][1])/2\r\n lines.append([grad,py-grad*px])\r\n\r\ncentrex = (lines[1][1]-lines[0][1]) / (lines[0][0]-lines[1][0])\r\ncentrey = lines[0][0]*centrex+lines[0][1]\r\nrad2 = (centrex-n1[0])**2+(centrey-n1[1])**2\r\n\r\nnums = []\r\n\r\nfor i in [[n1,n2],[n1,n3],[n2,n3]]:\r\n angle = math.acos((2*rad2-((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1])**2))/(2*rad2)) / (2*math.pi)\r\n num,den = farey(angle)\r\n nums.append(den)\r\n\r\nsides = lcm(lcm(nums[0],nums[1]),nums[2])\r\nprint(1/2 * sides * rad2 * math.sin(2*math.pi/sides))", "import math\r\nx1,y1=map(float,input().split())\r\nx2,y2=map(float,input().split())\r\nx3,y3=map(float,input().split())\r\nA=x1-x3\r\nB=y1-y3\r\nC=(x1*x1-x3*x3)/2+(y1*y1-y3*y3)/2\r\nD=x3-x2\r\nE=y3-y2\r\nF=(x3*x3-x2*x2)/2+(y3*y3-y2*y2)/2\r\nX=(B*F-C*E)/(B*D-A*E)\r\nY=(C*D-A*F)/(B*D-A*E)\r\nR=((X-x1)**2+(Y-y1)**2)**0.5\r\nd12=((x1-x2)**2+(y1-y2)**2)**0.5\r\ncos1=(2*R*R-d12**2)/(2*R*R)\r\nd32=((x3-x2)**2+(y3-y2)**2)**0.5\r\ncos2=(2*R*R-d32**2)/(2*R*R)\r\nd13=((x1-x3)**2+(y1-y3)**2)**0.5\r\ncos3=(2*R*R-d13**2)/(2*R*R)\r\nif cos1<-1:\r\n cos1=-1\r\nif cos1>1:\r\n cos1=1\r\nif cos2<-1:\r\n cos2=-1\r\nif cos2>1:\r\n cos2=1\r\nif cos3<-1:\r\n cos3=-1\r\nif cos3>1:\r\n cos3=1\r\n\r\ndef transform(cos1):\r\n angle=math.pi*2/math.acos(cos1)\r\n t=angle\r\n while abs(round(t)-t)>pow(10,-4):\r\n t+=angle\r\n return round(t)\r\n\r\nangle1,angle2,angle3=transform(cos1),transform(cos2),transform(cos3)\r\n\r\n\r\ndef gcd(x1,x2):\r\n while x1%x2!=0 and x2%x1!=0:\r\n if x1>x2:\r\n x1=x1%x2\r\n else:\r\n x2=x2%x1\r\n return min(x1,x2)\r\n\r\nlcm=angle1*angle2//gcd(angle1,angle2)\r\nlcm=lcm*angle3//gcd(lcm,angle3)\r\nANGLE=2*math.pi/lcm\r\narea=R*R/2*math.sin(ANGLE)\r\nprint(area*lcm)", "import math\n\ndef gcd(x,y):\n if y > x:\n temp = x \n x = y\n y = temp \n if y < 1e-3:\n return x\n else:\n return gcd(y,x - (1.0 * x//y)*y)\n\nx1, y1 = list(map(float,input().split()))\nx2, y2 = list(map(float,input().split()))\nx3, y3 = list(map(float,input().split()))\n\na = math.sqrt((x3-x2)**2 + (y3-y2)**2)\nb = math.sqrt((x1-x3)**2 + (y1-y3)**2)\nc = math.sqrt((x2-x1)**2 + (y2-y1)**2)\n\nA = math.acos((b**2 + c**2 - a**2) / (2*b*c))\nB = math.acos((c**2 + a**2 - b**2) / (2*c*a))\nC = math.acos((a**2 + b**2 - c**2) / (2*a*b))\n\nR = a / (2 * math.sin(A))\nangle = 2*gcd(A,gcd(B,C))\n\narea = R*R*math.sin(angle)*math.pi/angle\nprint(round(area,12))", "from math import *\r\np=[list(map(float,input().split())) for i in range(3)]\r\na,b,c=[hypot(x1-x2,y1-y2) for (x1,y1),(x2,y2) in [(p[0],p[1]),(p[0],p[2]),(p[1],p[2])]]\r\nA,B,C=[acos((y*y+z*z-x*x)/2/z/y) for x,y,z in [(a,b,c),(b,c,a),(c,a,b)]]\r\nR=a/2/sin(A)\r\ndef g(x,y):return x if y<1e-3 else g(y,fmod(x,y))\r\nu=2*g(A,g(B,C))\r\nprint(round(R*R*pi/u*sin(u),7))", "import math\r\n\r\nPI = math.pi\r\npoint = [[0 for j in range(2)] for i in range(3)]\r\nql = [0 for i in range(3)]\r\ncosa = [0 for i in range(3)]\r\nqsina = [0 for i in range(3)]\r\nqsina_0 = 0\r\nqsina_1 = 0\r\nqsina_2 = 0\r\na = [0 for i in range(3)]\r\nb = [1 for i in range(3)]\r\nc = [0 for i in range(3)]\r\nd = 0\r\nmind = -1\r\nres = 0\r\nqr = 0\r\ns = 0\r\n\r\nfor i in range(3):\r\n point[i][0], point[i][1] = map(float, input().split())\r\n\r\nfor i in range(3):\r\n ql[i] = (point[i][0] - point[(i + 1) % 3][0]) ** 2 + (point[i][1] - point[(i + 1) % 3][1]) ** 2\r\n\r\nfor i in range(3):\r\n cosa[i] = (ql[(i + 2) % 3] + ql[(i + 1) % 3] - ql[i]) / (2 * math.sqrt(ql[(i + 1) % 3]) * math.sqrt(ql[(i + 2) % 3]))\r\n qsina[i] = 1 - cosa[i] * cosa[i]\r\n if i == 0:\r\n qsina_0 = qsina[i]\r\n elif i == 1:\r\n qsina_1 = qsina[i]\r\n else:\r\n qsina_2 = qsina[i]\r\n a[i] = int(math.acos(cosa[i]) * 1e5)\r\n\r\nqr = (ql[0] / qsina[0] + ql[1] / qsina[1] + ql[2] / qsina[2]) / 12\r\n\r\nwhile sum(b) <= 100:\r\n c[0] = a[0] // b[0]\r\n c[1] = a[1] // b[1]\r\n c[2] = a[2] // b[2]\r\n d = abs(c[0] - c[1]) + abs(c[1] - c[2]) + abs(c[2] - c[0])\r\n if mind == -1 or mind > d:\r\n mind = d\r\n res = b[0] + b[1] + b[2]\r\n i = 0\r\n if a[0] // b[0] < a[1] // b[1]:\r\n i = 1\r\n if a[i] // b[i] < a[2] // b[2]:\r\n i = 2\r\n b[i] += 1\r\n\r\ns = qr * math.sin(2 * PI / res) * res / 2\r\nprint(\"%.8f\" % s)\r\n", "import math\r\n\r\nx1, y1 = map(float, input().split())\r\nx2, y2 = map(float, input().split())\r\nx3, y3 = map(float, input().split())\r\n\r\ndef triangle_area(x1, y1, x2, y2, x3, y3):\r\n return abs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / 2\r\n\r\na, b, c = (math.hypot(x2 - x1, y2 - y1),\r\n math.hypot(x3 - x2, y3 - y2),\r\n math.hypot(x1 - x3, y1 - y3))\r\n\r\nR = (a * b * c / (4 * triangle_area(x1, y1, x2, y2, x3, y3)))\r\n\r\nA, B, C = (math.acos((b ** 2 + c ** 2 - a ** 2) / (2 * b * c)),\r\n math.acos((a ** 2 + c ** 2 - b ** 2) / (2 * a * c)),\r\n math.acos((a ** 2 + b ** 2 - c ** 2) / (2 * a * b)))\r\n\r\n\r\ndef float_gcd(a, b, tol = 1e-04):\r\n t = min(abs(a), abs(b))\r\n while abs(b) > tol:\r\n a, b = b, a % b\r\n return a\r\n\r\nn = math.pi / float_gcd(float_gcd(A, B), C)\r\n\r\nS = n * R ** 2 * math.sin(2 * math.pi / n) / 2\r\n\r\nprint(S)", "from math import*\r\np=[list(map(float,input().split()))for i in range(3)]\r\na,b,c=[hypot(x1-x2,y1-y2)for(x1,y1),(x2,y2)in[(p[i],p[(i+1)%3])for i in[0,1,2]]]\r\nA,B,C=[acos((y*y+z*z-x*x)/2/z/y)for(x,y,z)in[(a,b,c),(b,c,a),(c,a,b)]]\r\nR=a/2/sin(A)\r\ndef g(x,y):return x if y<1e-3 else g(y,fmod(x,y))\r\nu=2*g(A,g(B,C))\r\nprint(round(R*R*pi/u*sin(u),7))", "from math import sqrt, acos, pi, sin\r\n\r\ndef find_side(p1, p2):\r\n return sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2 )\r\n\r\ndef find_angle(a,b,c):\r\n return acos((b*b+c*c-a*a)/(2*b*c))\r\n\r\ndef find_gcd(A,B):\r\n if (A < B):\r\n return find_gcd(B,A)\r\n if (abs(B)< 0.001):\r\n return A\r\n return find_gcd(B, A - (A//B)*B)\r\n\r\n\r\npoints = []\r\nfor i in range(3):\r\n x,y = map(float,input().split())\r\n points.append([x,y])\r\n\r\na = find_side(points[0], points[1])\r\nb = find_side(points[1], points[2])\r\nc = find_side(points[2], points[0])\r\n\r\np = (a+b+c)/2\r\ns = sqrt(p*(p-a)*(p-b)*(p-c))\r\nr = (a*b*c/(4*s))\r\n\r\nA = find_angle(a,b,c)\r\nB = find_angle(b,c,a)\r\nC = find_angle(c,a,b)\r\n\r\nx = 2 * find_gcd(A, find_gcd(B,C))\r\n\r\nn = round(2*pi/x)\r\n\r\ns = 0.5 *n*r*r*sin(2*pi/n)\r\n\r\nprint(\"%.6f\" %s)", "import math\r\n\r\na,b = (float(i) for i in input().split())\r\nc,d = (float(i) for i in input().split())\r\ne,f = (float(i) for i in input().split())\r\n\r\nx = (b-f)*(a*a+b*b-c*c-d*d)/2 + (d-b)*(a*a+b*b-e*e-f*f)/2\r\ny = (e-a)*(a*a+b*b-c*c-d*d)/2 + (a-c)*(a*a+b*b-e*e-f*f)/2\r\ndet = (b-f)*(a-c)-(b-d)*(a-e)\r\nx = x/det\r\ny = y/det\r\n\r\ndef next(a,b,c,d,x,y):\r\n e = (x-c)*(a*(x-c)+b*(y-d)) + (d-y)*(-(a-2*x)*(d-y)+(b-2*y)*(c-x)) \r\n f = (y-d)*(a*(x-c)+b*(y-d)) + (x-c)*(-(a-2*x)*(d-y)+(b-2*y)*(c-x)) \r\n det = (x-c)*(x-c)+(y-d)*(y-d)\r\n e = e/det\r\n f = f/det\r\n return e,f\r\n\r\ndef get_steps(a,b,c,d,x,y):\r\n step = 2\r\n a1,b1,c1,d1 = a,b,c,d\r\n e1,f1 = next(a1,b1,c1,d1,x,y)\r\n eps = 1e-6\r\n while (e1-a)*(e1-a)+(f1-b)*(f1-b)>eps:\r\n step += 1\r\n a1,b1,c1,d1 = c1,d1,e1,f1\r\n e1,f1 = next(a1,b1,c1,d1,x,y)\r\n return step \r\n\r\ns1 = get_steps(a,b,c,d,x,y)\r\ns2 = get_steps(c,d,e,f,x,y)\r\ns3 = get_steps(a,b,e,f,x,y)\r\n\r\ndef gcd(a,b):\r\n if b:\r\n return gcd(b,a%b)\r\n else:\r\n return a\r\n\r\nl1 = s1*s2//gcd(s1,s2)\r\nn = s3*l1//gcd(s3,l1)\r\ns = n*0.5*math.sin(math.pi*2/n)*((x-a)*(x-a)+(y-b)*(y-b))\r\nprint(s)", "from itertools import count\nfrom math import atan2, cos, hypot, inf, sin, tau\n\n\ndef circumcenter(x1, y1, x2, y2, x3, y3):\n assert not (y1 == y2 == y3) and not (x1 == x2 == x3)\n if y1 == y2:\n return circumcenter(x1, y1, x3, y3, x2, y2)\n if y3 == y2:\n return circumcenter(x2, y2, x1, y1, x3, y3)\n x4 = (x1 + x2) / 2\n x5 = (x3 + x2) / 2\n y4 = (y1 + y2) / 2\n y5 = (y3 + y2) / 2\n p4 = (x1 - x2) / (y2 - y1)\n p5 = (x3 - x2) / (y2 - y3)\n x = (y5 - y4 + p4 * x4 - p5 * x5) / (p4 - p5)\n return (x, y4 + p4 * (x - x4))\n\n\ndef triangle_area(x1, y1, x2, y2, x3, y3):\n return abs(x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3) / 2\n\n\ndef polygon_area(cx, cy, x1, y1, sides):\n radius = hypot(cy - y1, cx - x1)\n a1 = atan2(y1 - cy, x1 - cx)\n a2 = a1 + tau / sides\n x2 = cx + cos(a2) * radius\n y2 = cy + sin(a2) * radius\n return triangle_area(x1, y1, x2, y2, cx, cy) * sides\n\n\ndef close_divisor(numer, denom):\n x = (numer / denom) % 1\n return min(x, 1 - x)\n\n\ndef get_sides(d12, d13, d23):\n ans = [inf, inf, inf]\n for sides in range(3, 101):\n a = tau / sides\n maxi = max(close_divisor(d12, a), close_divisor(d13, a), close_divisor(d23, a))\n ans.append(maxi * sides)\n return ans.index(min(ans))\n\n\nx1, y1, x2, y2, x3, y3 = map(float, open(0).read().split())\ncx, cy = circumcenter(x1, y1, x2, y2, x3, y3)\na1 = atan2(y1 - cy, x1 - cx)\na2 = atan2(y2 - cy, x2 - cx)\na3 = atan2(y3 - cy, x3 - cx)\nd12 = abs(a1 - a2)\nd13 = abs(a1 - a3)\nd23 = abs(a2 - a3)\nsides = get_sides(d12, d13, d23)\nprint(polygon_area(cx, cy, x1, y1, sides))\n", "import math\r\n\r\nPI = 3.141592654\r\n\r\npoint = [[0.0] * 2 for _ in range(3)]\r\nql = [0.0] * 3\r\ncosa = [0.0] * 3\r\nqsina = [0.0] * 3\r\nqr = 0.0\r\ns = 0.0\r\ni = 0\r\na = [0] * 3\r\nres = 0\r\ng = 0\r\nb = [0] * 3\r\nc = [0] * 3\r\nd = 0\r\nmind = float('inf')\r\n\r\nfor i in range(3):\r\n point[i][0], point[i][1] = map(float, input().split())\r\n\r\nfor i in range(3):\r\n ql[i] = (point[i][0] - point[(i + 1) % 3][0]) ** 2 + (point[i][1] - point[(i + 1) % 3][1]) ** 2\r\n\r\nfor i in range(3):\r\n cosa[i] = (ql[(i + 2) % 3] + ql[(i + 1) % 3] - ql[i]) / (2 * math.sqrt(ql[(i + 1) % 3]) * math.sqrt(ql[(i + 2) % 3]))\r\n qsina[i] = 1 - cosa[i] * cosa[i]\r\n a[i] = int(math.acos(cosa[i]) * 1e5)\r\n\r\nqr = (ql[0] / qsina[0] + ql[1] / qsina[1] + ql[2] / qsina[2]) / 12\r\nb[0] = b[1] = b[2] = 1\r\n\r\nwhile b[0] + b[1] + b[2] <= 100:\r\n c[0] = a[0] // b[0]\r\n c[1] = a[1] // b[1]\r\n c[2] = a[2] // b[2]\r\n d = abs(c[0] - c[1]) + abs(c[1] - c[2]) + abs(c[2] - c[0])\r\n \r\n if mind > d:\r\n mind = d\r\n res = b[0] + b[1] + b[2]\r\n \r\n i = 0\r\n if a[0] // b[0] < a[1] // b[1]:\r\n i = 1\r\n if a[i] // b[i] < a[2] // b[2]:\r\n i = 2\r\n b[i] += 1\r\n\r\ns = qr * math.sin(2 * PI / res) * res / 2\r\nprint(\"{:.8f}\".format(s))\r\n", "import math\n\nPI = math.pi\npoint = [[0 for j in range(2)] for i in range(3)]\nql = [0 for i in range(3)]\ncosa = [0 for i in range(3)]\nqsina = [0 for i in range(3)]\nqsina_0 = 0\nqsina_1 = 0\nqsina_2 = 0\na = [0 for i in range(3)]\nb = [1 for i in range(3)]\nc = [0 for i in range(3)]\nd = 0\nmind = -1\nres = 0\nqr = 0\ns = 0\n\nfor i in range(3):\n point[i][0], point[i][1] = map(float, input().split())\n\nfor i in range(3):\n ql[i] = (point[i][0] - point[(i + 1) % 3][0]) ** 2 + (point[i][1] - point[(i + 1) % 3][1]) ** 2\n\nfor i in range(3):\n cosa[i] = (ql[(i + 2) % 3] + ql[(i + 1) % 3] - ql[i]) / (2 * math.sqrt(ql[(i + 1) % 3]) * math.sqrt(ql[(i + 2) % 3]))\n qsina[i] = 1 - cosa[i] * cosa[i]\n if i == 0:\n qsina_0 = qsina[i]\n elif i == 1:\n qsina_1 = qsina[i]\n else:\n qsina_2 = qsina[i]\n a[i] = int(math.acos(cosa[i]) * 1e5)\n\nqr = (ql[0] / qsina[0] + ql[1] / qsina[1] + ql[2] / qsina[2]) / 12\n\nwhile sum(b) <= 100:\n c[0] = a[0] // b[0]\n c[1] = a[1] // b[1]\n c[2] = a[2] // b[2]\n d = abs(c[0] - c[1]) + abs(c[1] - c[2]) + abs(c[2] - c[0])\n if mind == -1 or mind > d:\n mind = d\n res = b[0] + b[1] + b[2]\n i = 0\n if a[0] // b[0] < a[1] // b[1]:\n i = 1\n if a[i] // b[i] < a[2] // b[2]:\n i = 2\n b[i] += 1\n\ns = qr * math.sin(2 * PI / res) * res / 2\nprint(\"%.8f\" % s)", "from math import *\r\nx1,y1 = map(float,input().split())\r\nx2,y2 = map(float,input().split())\r\nx3,y3 = map(float,input().split())\r\ns1 = sqrt((x2-x1)**2+(y2-y1)**2)\r\ns2 = sqrt((x3-x2)**2+(y3-y2)**2)\r\ns3 = sqrt((x1-x3)**2+(y1-y3)**2)\r\ns = (s1+s2+s3)/2\r\nA = sqrt(s*(s-s1)*(s-s2)*(s-s3))\r\nR = s1*s2*s3/4/A\r\n\r\n#aprint(s3/R/2)\r\nang1 = 2*asin(min(s1/2/R,1))\r\nang2 = 2*asin(min(s2/2/R,1))\r\nang3 = 2*asin(min(s3/2/R,1))\r\n'''\r\nprint(R)\r\nprint(ang1*180/pi)\r\nprint(ang2*180/pi)\r\nprint(ang3*180/pi)\r\n'''\r\nangs = [ang1,ang2,ang3]\r\nangs.sort()\r\nang1,ang2,ang3 = angs\r\nang2-=ang1\r\nang3-=ang1\r\n'''\r\nprint()\r\nprint(ang2*180/pi)\r\nprint(ang3*180/pi)\r\n'''\r\nif(abs(ang2-ang3)>0.05):\r\n while(ang2>0.05):\r\n #print(ang2*180/pi,ang3*180/pi)\r\n ang3-=(ang3//ang2)*ang2\r\n t = ang3\r\n ang3 = ang2\r\n ang2 = t\r\n ang2 = ang3\r\n ang3 = 2*pi\r\n while(ang2>0.05):\r\n #print(ang2*180/pi,ang3*180/pi)\r\n ang3-=(ang3//ang2)*ang2\r\n t = ang3\r\n ang3 = ang2\r\n ang2 = t\r\nelse:\r\n ang3 = 2*pi\r\n ang2 = ang1\r\n while(ang2>0.05):\r\n #print(ang2*180/pi,ang3*180/pi)\r\n ang3-=(ang3//ang2)*ang2\r\n t = ang3\r\n ang3 = ang2\r\n ang2 = t\r\n\r\n#print()\r\n#print(2*pi/ang3)\r\nprint(R*R*sin(ang3)*pi/ang3)" ]
{"inputs": ["0.000000 0.000000\n1.000000 1.000000\n0.000000 1.000000", "71.756151 7.532275\n-48.634784 100.159986\n91.778633 158.107739", "18.716839 40.852752\n66.147248 -4.083161\n111.083161 43.347248", "-13.242302 -45.014124\n-33.825369 51.083964\n84.512928 -55.134407", "115.715093 141.583620\n136.158119 -23.780834\n173.673212 64.802787", "17.288379 68.223317\n48.776683 71.688379\n23.170559 106.572762", "76.820252 66.709341\n61.392328 82.684207\n44.267775 -2.378694", "-46.482632 -31.161247\n19.689679 -70.646972\n-17.902656 -58.455808", "34.236058 108.163949\n28.639345 104.566515\n25.610069 86.002927", "25.428124 39.407248\n17.868098 39.785933\n11.028461 43.028890", "36.856072 121.845502\n46.453956 109.898647\n-30.047767 77.590282", "-18.643272 56.008305\n9.107608 -22.094058\n-6.456146 70.308320", "88.653021 18.024220\n51.942488 -2.527850\n76.164701 24.553012", "80.181999 -38.076894\n23.381778 122.535736\n47.118815 140.734014", "1.514204 81.400629\n32.168797 100.161401\n7.778734 46.010993", "84.409605 38.496141\n77.788313 39.553807\n75.248391 59.413884", "12.272903 101.825792\n-51.240438 -12.708472\n-29.729299 77.882032", "35.661751 27.283571\n96.513550 51.518022\n97.605986 131.258287", "-20.003518 -4.671086\n93.588632 6.362759\n-24.748109 24.792124", "93.583067 132.858352\n63.834975 19.353720\n33.677824 102.529376", "-7.347450 36.971423\n84.498728 89.423536\n75.469963 98.022482", "51.679280 56.072393\n-35.819256 73.390532\n-10.661374 129.756454", "97.326813 61.492460\n100.982131 57.717635\n68.385216 22.538372", "-16.356805 109.310423\n124.529388 25.066276\n-37.892043 80.604904", "103.967164 63.475916\n86.466163 59.341930\n69.260229 73.258917", "122.381894 -48.763263\n163.634346 -22.427845\n26.099674 73.681862", "119.209229 133.905087\n132.001535 22.179509\n96.096673 0.539763", "77.145533 85.041789\n67.452820 52.513188\n80.503843 85.000149", "28.718442 36.116251\n36.734593 35.617015\n76.193973 99.136077", "0.376916 17.054676\n100.187614 85.602831\n1.425829 132.750915", "46.172435 -22.819705\n17.485134 -1.663888\n101.027565 111.619705", "55.957968 -72.765994\n39.787413 -75.942282\n24.837014 128.144762", "40.562163 -47.610606\n10.073051 -54.490068\n54.625875 -40.685797", "20.965151 74.716562\n167.264364 81.864800\n5.931644 48.813212", "105.530943 80.920069\n40.206723 125.323331\n40.502256 -85.455877", "104.636703 49.583778\n85.940583 95.426299\n69.375168 93.234795", "72.873708 -59.083734\n110.911118 -6.206576\n-44.292395 13.106202", "49.320630 48.119616\n65.888396 93.514980\n27.342377 97.600590", "6.949504 69.606390\n26.139268 72.136945\n24.032442 57.407195", "-21.925928 -24.623076\n-33.673619 -11.677794\n4.692348 52.266292", "109.515505 37.575315\n5.377080 101.729711\n17.501630 103.324931", "-56.880888 172.997993\n81.126977 42.144034\n-51.413417 17.057807", "80.895061 94.491414\n42.361631 65.191687\n77.556800 76.694829", "165.094169 94.574129\n46.867578 147.178855\n174.685774 62.705213", "146.604506 -3.502359\n24.935572 44.589981\n106.160918 -51.162271", "139.847022 19.153937\n104.096879 75.379874\n49.164271 46.404632", "31.312532 151.532355\n182.646053 56.534075\n15.953947 127.065925", "42.147045 64.165917\n70.260284 4.962470\n10.532991 76.277713", "129.400249 -44.695226\n122.278798 -53.696996\n44.828427 -83.507917", "28.420253 0.619862\n10.966628 21.724132\n14.618862 10.754642"], "outputs": ["1.00000000", "9991.27897663", "4268.87997505", "16617.24002771", "24043.74046813", "1505.27997374", "6503.44762335", "23949.55226823", "780.93431702", "1152.21351717", "5339.35578947", "9009.25177521", "1452.52866331", "28242.17663744", "3149.43107333", "438.85760782", "24908.67540438", "13324.78113326", "11191.04493104", "10866.49390021", "8977.83404724", "7441.86549199", "1840.59945324", "22719.36404168", "1621.96700296", "22182.51901824", "16459.52899209", "1034.70898496", "6271.48941610", "13947.47744984", "16483.23337238", "32799.66697178", "31224.34817875", "30115.26346791", "36574.64621711", "2632.68754075", "19244.42781859", "2437.50897386", "372.09309018", "5669.99444283", "25142.85604936", "29051.57171313", "2386.01792476", "32087.47120554", "13799.61044048", "7083.26303902", "25712.80766033", "14261.92257159", "26227.47891833", "1760.14006648"]}
UNKNOWN
PYTHON3
CODEFORCES
15
1e05c048abf89b10b87662857fb3d340
Porcelain
During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed. The collection of porcelain is arranged neatly on *n* shelves. Within each shelf the items are placed in one row, so that one can access only the outermost items — the leftmost or the rightmost item, not the ones in the middle of the shelf. Once an item is taken, the next item on that side of the shelf can be accessed (see example). Once an item is taken, it can't be returned to the shelves. You are given the values of all items. Your task is to find the maximal damage the princess' tantrum of *m* shrieks can inflict on the collection of porcelain. The first line of input data contains two integers *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=10000). The next *n* lines contain the values of the items on the shelves: the first number gives the number of items on this shelf (an integer between 1 and 100, inclusive), followed by the values of the items (integers between 1 and 100, inclusive), in the order in which they appear on the shelf (the first number corresponds to the leftmost item, the last one — to the rightmost one). The total number of items is guaranteed to be at least *m*. Output the maximal total value of a tantrum of *m* shrieks. Sample Input 2 3 3 3 7 2 3 4 1 5 1 3 4 4 3 1 2 Sample Output 15 9
[ "def main():\r\n inp = list(map(int, input().split()))\r\n dp = [0] * (inp[1] + 1)\r\n \r\n for _ in range(inp[0]):\r\n total, *shelf = map(int, input().split())\r\n max_val= [0] * (total + 1)\r\n \r\n shelf= [0] + shelf\r\n \r\n for j in range(1, total + 1):\r\n shelf[j]= shelf[j] + shelf[j - 1]\r\n \r\n for j in range(total + 1):\r\n for k in range(j, total + 1):\r\n max_val[j + total - k] = max(max_val[total - k + j], shelf[j] + shelf[total] - shelf[k])\r\n \r\n for j in range(inp[1], 0, -1):\r\n for k in range(1, min(j, total) + 1):\r\n dp[j] = max(dp[j], dp[j - k] + max_val[k])\r\n \r\n print(dp[inp[1]])\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()" ]
{"inputs": ["2 3\n3 3 7 2\n3 4 1 5", "1 3\n4 4 3 1 2", "1 4\n6 5 1 10 1 1 5", "3 2\n1 10\n1 2\n1 5", "1 68\n100 26 58 15 8 69 66 49 97 18 74 27 39 19 76 37 25 4 88 75 17 79 41 21 44 39 7 42 63 82 92 87 41 85 25 30 43 80 95 70 98 88 16 15 97 74 81 76 33 19 64 3 14 72 17 36 33 21 34 59 38 75 48 1 57 20 81 56 74 67 14 89 51 94 4 66 94 58 64 58 25 99 33 97 31 5 54 87 6 64 70 40 93 25 50 62 53 80 75 68 13", "1 1\n1 100"], "outputs": ["15", "9", "21", "15", "3636", "100"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1e20de0e4e64dcaf65977de7275cd6b7
Array
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: 1. The product of all numbers in the first set is less than zero (<=&lt;<=0). 1. The product of all numbers in the second set is greater than zero (<=&gt;<=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set. Help Vitaly. Divide the given array. The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. In the first line print integer *n*1 (*n*1<=&gt;<=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set. In the next line print integer *n*2 (*n*2<=&gt;<=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set. In the next line print integer *n*3 (*n*3<=&gt;<=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set. The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. Sample Input 3 -1 2 0 4 -1 -2 -3 0 Sample Output 1 -1 1 2 1 0 1 -1 2 -3 -2 1 0
[ "\nn = int(input())\na = list(map(int,input().split()))\n\nnegative = []\npositive = []\nzeros = []\n\na = sorted(a)\n\nif a[-1] > 0:\n positive.append(a[-1])\n negative.append(a[0])\n a.pop(0)\n a.pop(-1)\n zeros = a\nelse:\n positive.append(a[0])\n positive.append(a[1])\n negative.append(a[2])\n a.pop(0)\n a.pop(0)\n a.pop(0)\n zeros = a\n\nprint(len(negative),end= \" \")\n\nfor i in range(len(negative)):\n if i != len(negative)-1:\n print(negative[i], end=\" \")\n else:\n print(negative[i])\n\nprint(len(positive),end= \" \")\n\nfor i in range(len(positive)):\n if i != len(positive)-1:\n print(positive[i], end=\" \")\n else:\n print(positive[i])\n\nprint(len(zeros),end= \" \")\n\nfor i in range(len(zeros)):\n if i != len(zeros)-1:\n print(zeros[i], end=\" \")\n else:\n print(zeros[i])\n\n\n\n \t\t\t\t \t \t\t\t\t \t \t\t\t \t\t\t \t", "p = int(input())\r\nq = list(int(x) for x in input().split())\r\na = []\r\nb = []\r\nc = []\r\nfor i in q:\r\n if i<0:\r\n a.append(i)\r\n elif i>0:\r\n b.append(i)\r\n else:\r\n c.append(i)\r\n\r\nif len(b)==0 and len(a)>2:\r\n for i in range(2):\r\n b.append(a[i])\r\n a.remove(a[0])\r\n a.remove(a[0])\r\n\r\nwhile len(a)>1:\r\n c.append(a[1])\r\n a.remove(a[1])\r\n\r\nprint(len(a),end=\" \")\r\nfor i in a:\r\n print(i,end=\" \")\r\nprint()\r\n\r\nprint(len(b),end=\" \")\r\nfor i in b:\r\n print(i,end=\" \")\r\nprint()\r\n\r\nprint(len(c),end=\" \")\r\nfor i in c:\r\n print(i,end=\" \")", "n = int(input())\nnum_arr = list(map(int, input().split()))\n\narr_neg = []\narr_pos = []\narr_zero = []\nnum_neg = 1\nind = 0\nwhile len(arr_neg)==0:\n if num_arr[ind]<0:\n arr_neg.append(num_arr[ind])\n num_arr.pop(ind)\n ind+=1\n\nnum_pos = 0\nfor elem in num_arr:\n if elem > 0:\n arr_pos.append(elem)\n num_arr.remove(elem)\n num_pos+=1\n\nif num_pos == 0:\n count_neg = 0\n for elem in num_arr:\n \n if elem < 0 and count_neg!=2:\n arr_pos.append(elem)\n num_pos+=1\n count_neg+=1\n for elem in arr_pos:\n num_arr.remove(elem)\n\nnum_zero = 0\nfor elem in num_arr:\n arr_zero.append(elem)\n num_zero+=1\n\nprint(num_neg, *arr_neg)\nprint(num_pos, *arr_pos)\nprint(num_zero, *arr_zero)\n \t\t\t\t \t\t \t\t \t \t \t \t\t\t \t\t", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nans1 = []\r\nans2 = []\r\nans3 = []\r\n\r\nfor i in a:\r\n\tif(i==0):\r\n\t\tans3.append(i)\r\n\telif(i>0):\r\n\t\tans2.append(i)\r\n\telse:\r\n\t\tans1.append(i)\r\n\r\nif(len(ans1)%2==0):\r\n\tx = ans1.pop()\r\n\tans3.append(x)\r\nif(len(ans2)==0):\r\n\tp = ans1.pop()\r\n\tq = ans1.pop()\r\n\tans2.append(p)\r\n\tans2.append(q)\r\n\r\n\r\nprint(len(ans1),*ans1)\r\nprint(len(ans2),*ans2)\r\nprint(len(ans3),*ans3)", "n=int(input())\r\narr=list(map(int,input().split(\" \")))\r\npos=[]\r\nneg=[]\r\nzero=[]\r\nfor i in range(len(arr)):\r\n if arr[i]>0:\r\n pos.append(arr[i])\r\n elif arr[i]==0:\r\n zero.append(arr[i])\r\n else:\r\n neg.append(arr[i])\r\n\r\nif len(pos)==0:\r\n #print(\"yes no elements in positive\")\r\n pos.append(neg[0])\r\n pos.append(neg[1])\r\n neg.pop(1)\r\n neg.pop(0)\r\n\r\nif len(neg)%2==0:\r\n #print(\"yes negative one is even\")\r\n zero.append(neg[0])\r\n neg.pop(0)\r\n\r\nprint(len(neg),end=\" \")\r\nfor i in range(len(neg)):\r\n print(neg[i],end=\" \")\r\nprint()\r\nprint(len(pos),end=\" \")\r\nfor i in range(len(pos)):\r\n print(pos[i],end=\" \")\r\nprint()\r\nprint(len(zero),end=\" \")\r\nfor i in range(len(zero)):\r\n print(zero[i],end=\" \")", "import sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef ini():\r\n return(int(input()))\r\ndef inl():\r\n return(list(map(int,input().split())))\r\ndef ins():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef inm():\r\n return(map(int,input().split()))\r\n\r\ndef p(s):\r\n print(s)\r\n\r\ndef pa(s):\r\n print(\" \".join(str(x) for x in s))\r\n\r\ndef pj(arr):\r\n print(\"\".join(str(x) for x in arr))\r\n\r\n\r\ndef gcd(a,b):\r\n if b == 0:\r\n return a\r\n else:\r\n return gcd(b,a%b)\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n arr = inl()\r\n\r\n\r\n a = []\r\n b = []\r\n c = []\r\n\r\n for i in range(n):\r\n if arr[i] < 0:\r\n a.append(arr[i])\r\n \r\n if arr[i] > 0:\r\n b.append(arr[i])\r\n \r\n if arr[i] == 0:\r\n c.append(arr[i])\r\n \r\n \r\n if len(b) == 0:\r\n b.append(a.pop())\r\n b.append(a.pop())\r\n \r\n if len(a) % 2 == 0:\r\n c.append(a.pop())\r\n \r\n print(len(a), \" \".join(str(x) for x in a))\r\n print(len(b), \" \".join(str(x) for x in b))\r\n print(len(c), \" \".join(str(x) for x in c))", "def divide_array(arr):\r\n # Initialize lists to store negative, positive, and zero numbers\r\n neg_nums = []\r\n pos_nums = []\r\n zero_nums = []\r\n\r\n # Iterate through the input array and categorize numbers\r\n for num in arr:\r\n if num < 0:\r\n neg_nums.append(num) # Add negative numbers to the neg_nums list\r\n elif num > 0:\r\n pos_nums.append(num) # Add positive numbers to the pos_nums list\r\n else:\r\n zero_nums.append(num) # Add zero numbers to the zero_nums list\r\n\r\n # Check if the count of negative numbers is even\r\n # If even, move one negative number to the zero_nums list\r\n if len(neg_nums) % 2 == 0:\r\n zero_nums.append(neg_nums.pop())\r\n\r\n # If there are no positive numbers, move two negative numbers to the pos_nums list\r\n if len(pos_nums) == 0 and len(neg_nums) > 2:\r\n pos_nums.append(neg_nums.pop())\r\n pos_nums.append(neg_nums.pop())\r\n\r\n # Print the sizes and contents of each categorized list\r\n print(len(neg_nums), *neg_nums)\r\n print(len(pos_nums), *pos_nums)\r\n print(len(zero_nums), *zero_nums)\r\n\r\ndef main():\r\n n = int(input()) # Read the number of elements in the array\r\n\r\n arr = list(map(int, input().split())) # Read the array elements\r\n\r\n divide_array(arr) # Call the function to divide and print the arrays\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n=int(input())\na=list(map(int,input().split()))\na=sorted(a)\np=[]\nq=[]\nr=[]\nfor i in a:\n if i<0:\n p.append(i)\n if i>0:\n q.append(i)\n if i==0:\n r.append(i)\nif len(p)%2==0:\n t=p[0]\n p.remove(t)\n r.append(t)\nif len(q)==0:\n m=p[len(p)-1]\n p.remove(m)\n q.append(m)\n n=p[len(p)-1]\n p.remove(n)\n q.append(n)\np=[str(u) for u in p]\nq=[str(u) for u in q]\nr=[str(u) for u in r]\nprint(str(len(p))+' '+' '.join(p))\nprint(str(len(q))+' '+' '.join(q))\nprint(str(len(r))+' '+' '.join(r))\n \t \t\t\t \t \t\t\t\t \t \t\t \t \t", "'''input\r\n3\r\n-1 2 0\r\n'''\r\nimport sys\r\nfrom math import *\r\nfrom copy import *\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom functools import *\r\nfrom heapq import *\r\nfrom array import array\r\nINF = 2147483647\r\nINF64 = 9223372036854775807\r\ninput = sys.stdin.readline\r\ndef getstr(): return input().rstrip('\\r\\n')\r\ndef getint(): return int(input().strip())\r\ndef getints(): return list(map(int, input().strip().split()))\r\ndef impossible(): print(-1),exit(0)\r\n\r\ndef solve():\r\n\tn = getint()\r\n\tarr = sorted(getints())\r\n\ts = set(arr)\r\n\tprint(1, arr[0])\r\n\ts.remove(arr[0])\r\n\tcnt = 0\r\n\tfor e in s:\r\n\t\tif e<0:cnt+=1\r\n\tif cnt>=2:\r\n\t\tprint(2, arr[1], arr[2])\r\n\t\ts.remove(arr[1])\r\n\t\ts.remove(arr[2])\r\n\t\tprint(len(s), *s)\r\n\telse:\r\n\t\tprint(1, arr[-1])\r\n\t\tprint(n-2, *arr[1:-1])\r\n\r\n\r\nif __name__==\"__main__\":\r\n\tt = 1\r\n\tfor i in range(t):\r\n\t\tsolve()", "'''\r\n\r\nWelcome to GDB Online.\r\nGDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,\r\nC#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.\r\nCode, Compile, Run and Debug online from anywhere in world.\r\n\r\n'''\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\n#print(l)\r\nneg=0\r\na1=[]\r\na2=[]\r\na3=[]\r\npos=0\r\n#s=input()\r\nfor i in l:\r\n if(i<0):a1.append(i)\r\n if(i>0):\r\n a2.append(i)\r\n if(i==0):a3.append(i)\r\n \r\nif(len(a2)==0):\r\n a2.append(a1.pop())\r\n a2.append(a1.pop())\r\nif(len(a1)%2==0):\r\n a3.append(a1.pop())\r\n\r\nprint(len(a1),end=\" \")\r\nfor i in a1:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(a2),end=\" \")\r\nfor i in a2:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(a3),end=\" \")\r\nfor i in a3:\r\n print(i,end=\" \")\r\nprint()\r\n ", "n = int(input())\r\nlst = list(map(int, input().split()))\r\nb = []\r\nlst.sort()\r\n\r\nif lst[len(lst)-1]>0:\r\n print('1', lst[0])\r\n print('1', lst[len(lst)-1])\r\n print(len(lst)-2, end=\" \")\r\n for i in lst[1:len(lst)-1]:\r\n print(i, end=\" \")\r\nelse:\r\n print('1', lst[0])\r\n print('2', lst[1], lst[2])\r\n print(len(lst)-3, end=\" \")\r\n for i in lst[3:len(lst)]:\r\n print(i, end=\" \")", "t= int(input())\r\nl=list(map(int,input().split()))\r\nnl=[]\r\nn=0\r\npl=[]\r\np=0\r\nzl=[]\r\nz=0\r\nfor i in l:\r\n if i > 0:\r\n p+=1\r\n pl.append(i)\r\n elif i < 0:\r\n n+=1\r\n nl.append(i)\r\n else:\r\n z+=1\r\n zl.append(i)\r\nif p==0:\r\n x,y=nl.pop(),nl.pop()\r\n pl.append(x)\r\n pl.append(y)\r\n p+=2\r\n n-=2\r\nif n%2==0:\r\n x=nl.pop()\r\n zl.append(x)\r\n z+=1\r\n n-=1\r\nprint(n,*nl)\r\nprint(p,*pl)\r\nprint(z,*zl)\r\n", "#https://codeforces.com/problemset/problem/300/A\nn=int(input())\nl=list(map(int,input().split()))\npos=[]\nneg=[]\nzero=[]\nfor i in l:\n\tif i > 0:\n\t\tpos.append(i)\n\telif i < 0:\n\t\tneg.append(i)\n\telse:\n\t\tzero.append(i)\nif not len(neg) &1:\n\tzero.append(neg[0])\n\tneg.pop(0)\nif not len(pos):\n\tpos.append(neg[0])\n\tpos.append(neg[1])\n\tneg.pop(0)\n\tneg.pop(0)\nprint(len(neg),*neg)\nprint(len(pos),*pos)\nprint(len(zero),*zero)\n", "n=int(input())\r\nx=[int(i)for i in input().split()]\r\na,b=[],[]\r\nfor i in x:\r\n if i<0:\r\n a+=[i]\r\n break\r\nfor i in x:\r\n if i>0:\r\n b+=[i]\r\n break\r\nif b==[]:\r\n x.pop(x.index(a[0]))\r\n for i in x:\r\n if i<0:\r\n b+=[i]\r\n break\r\n x.pop(x.index(b[0]))\r\n for i in x:\r\n if i<0:\r\n b+=[i]\r\n break\r\n x.pop(x.index(b[1]))\r\n print(1,a[0])\r\n print(2,*b)\r\n print(len(x),*x)\r\nelse:\r\n x.pop(x.index(a[0]))\r\n x.pop(x.index(b[0]))\r\n print(1,a[0])\r\n print(1,b[0])\r\n print(len(x),*x)", "n=int(input())\r\nl=list(map(int,input().split()))\r\nneg=[]\r\nz=[]\r\npos=[]\r\nfor i in l:\r\n if(i>0):\r\n pos.append(i)\r\n elif(i==0):\r\n z.append(i)\r\n else:\r\n neg.append(i)\r\nif(len(pos)==0):\r\n pos.append(neg[0])\r\n pos.append(neg[1])\r\n neg.remove(neg[0])\r\n neg.remove(neg[0])\r\nif(len(neg)%2==0):\r\n z.append(neg[0])\r\n neg.remove(neg[0])\r\nprint(len(neg),end=\" \")\r\nfor i in neg:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(pos),end=\" \")\r\nfor i in pos:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(z),end=\" \")\r\nfor i in z:\r\n print(i,end=\" \")\r\nprint()\r\n", "num = input()\ndigits = [int(i) for i in input().split()]\npos_nums = []\nneg_nums = []\nzero = []\n\nfor i in range(len(digits)):\n if digits[i] == 0:\n zero.append(digits[i])\n continue\n elif digits[i] > 0:\n pos_nums.append(digits[i])\n continue\n else:\n neg_nums.append(digits[i])\n\nif len(pos_nums) == 0:\n pos_nums, neg_nums = neg_nums[:2], neg_nums[2:]\nzero += neg_nums[1:]\nneg_nums = neg_nums[0]\nprint(1, neg_nums)\nprint(len(pos_nums), \" \".join(str(i) for i in pos_nums))\nprint(len(zero), \" \".join(str(i) for i in zero))\n \t\t \t\t\t\t \t \t \t\t \t\t \t \t", "# neg all neg even (to zero) odd -\n# pos all pos empty (two from neg)\n# zero all zero\n\nn = int(input())\narr = [int(i) for i in input().split()]\nneg, pos, zero = [], [], []\nfor element in arr:\n if element < 0:\n neg.append(element)\n elif element > 0:\n pos.append(element)\n else:\n zero.append(element)\nif len(neg) % 2 == 0:\n zero.append(neg[-1])\n neg.pop()\nif pos == []:\n pos += neg[-2:]\n neg.pop()\n neg.pop()\nprint(len(neg), end=\" \")\nprint(*neg)\nprint(len(pos), end=\" \")\nprint(*pos)\nprint(len(zero), end=\" \")\nprint(*zero)\n\t\t \t \t \t \t\t \t\t\t\t\t \t\t", "n = int(input())\r\na = list(map(int, input().split()))\r\nlist_1 = []\r\nlist_2 = []\r\nlist_3 = []\r\nlist_mau = []\r\nfor i in range(n):\r\n if a[i] > 0:\r\n list_2.append(a[i])\r\n elif a[i] < 0:\r\n list_mau.append(a[i])\r\n else:\r\n list_3.append(a[i])\r\nif len(list_2) == 0:\r\n list_2.append(list_mau[0])\r\n list_2.append(list_mau[1])\r\n list_mau.remove(list_mau[0])\r\n list_mau.remove(list_mau[0])\r\nif len(list_mau) % 2 == 0:\r\n list_3.append(list_mau[0])\r\n list_mau.remove(list_mau[0])\r\nlist_1 = list_mau\r\nprint(len(list_1), end=' ')\r\nfor i in range(len(list_1)):\r\n print(list_1[i], end=' ')\r\nprint('')\r\nprint(len(list_2), end=' ')\r\nfor i in range(len(list_2)):\r\n print(list_2[i], end=' ')\r\nprint('')\r\nprint(len(list_3), end=' ')\r\nfor i in range(len(list_3)):\r\n print(list_3[i], end=' ')\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\npos=0\r\nfor i in range(0,n):\r\n if(l[i]>0):\r\n pos=pos+1;\r\nl1=[]\r\nl2=[]\r\nl3=[]\r\nif(pos>0):\r\n for i in range(0,n):\r\n if(l[i]>0 and len(l2)<1):\r\n l2.append(l[i])\r\n elif(l[i]<0 and len(l1)<1):\r\n l1.append(l[i])\r\n else:\r\n l3.append(l[i])\r\nelse:\r\n for i in range(0,n):\r\n if(l[i]!=0 and len(l2)<2):\r\n l2.append(l[i])\r\n elif(l[i]!=0 and len(l1)<1):\r\n l1.append(l[i])\r\n else:\r\n l3.append(l[i])\r\nprint(len(l1),end=\" \")\r\nfor i in range(0,len(l1)):\r\n print(l1[i],end=\" \")\r\nprint() \r\nprint(len(l2),end=\" \")\r\nfor i in range(0,len(l2)):\r\n print(l2[i],end=\" \")\r\nprint()\r\nprint(len(l3),end=\" \")\r\nfor i in range(0,len(l3)):\r\n print(l3[i],end=\" \")", "n=int(input())\r\nl = list(map(int,input().split()))\r\npos=[]\r\nneg=[]\r\nzero=[]\r\nfor x in range(n):\r\n\tif l[x]>0:\r\n\t\tpos.append(l[x])\r\n\telif l[x]<0:\r\n\t\tneg.append(l[x])\r\n\telse:\r\n\t\tzero.append(0)\r\n\r\nif len(pos)==0:\r\n\tpos.append(neg[-1])\r\n\tpos.append(neg[-2])\r\n\tneg=neg[:-2]\r\nif len(neg)%2==0:\r\n\tzero.append(neg[-1])\r\n\tneg=neg[:-1]\r\nprint(len(neg),*neg)\r\nprint(len(pos),*pos)\r\nprint(len(zero),*zero)", "#%%\r\nn = input()\r\nins = input().split(\" \")\r\n\r\nnegs = [num for num in ins if int(num) < 0]\r\nposs = [num for num in ins if int(num) > 0]\r\n\r\nprint(f\"1 {negs.pop()}\")\r\n\r\nif len(negs) >= 2: print(f\"{len(poss) + 2} {' '.join(poss+[negs.pop(), negs.pop()])}\")\r\nelse: print(f\"{len(poss)} {' '.join(poss)}\")\r\n\r\nprint(f\"{1 + len(negs)} 0 {' '.join(negs)}\")\r\n\r\n# %%\r\n", "quantity = input()\nvalues = list(map(int, input().split()))\n\nfirst = [] # <0\nsecond = [] # > 0\nthird = [] # == 0\n\nfor i in range(len(values)):\n if values[i] < 0:\n first.append(values[i])\n elif values[i] > 0:\n second.append(values[i])\n else:\n third.append(values[i])\n\nif len(first) % 2 == 0:\n third.append(first.pop())\n\nif len(second) == 0:\n second.append(first.pop())\n second.append(first.pop())\n\nprint(len(first), *first)\nprint(len(second), *second)\nprint(len(third), *third)\n\t \t \t \t \t \t \t\t \t \t", "n = int(input())\r\narr = list(map(int,input().split()))\r\narr = sorted(arr)\r\nif n==3:\r\n print(1,arr[0])\r\n print(1,arr[2])\r\n print(1,arr[1])\r\nelse:\r\n if arr[len(arr)-1]>0:\r\n print(1,arr[0])\r\n print(1, arr[len(arr) - 1])\r\n print(n-2,end=\" \")\r\n for i in range(1,n-1):\r\n print(arr[i],end=\" \")\r\n else:\r\n print(1,arr[0])\r\n print(2,arr[1],arr[2])\r\n print(n-3,end=\" \")\r\n for i in range(3,n):\r\n print(arr[i],end=\" \")", "n = int(input())\r\nd_i = list(map(int, input().split()))\r\n\r\nc_n = None\r\nd_n = set()\r\nd_p = set()\r\nd_0 = set()\r\n\r\nfor i in d_i:\r\n if i < 0:\r\n if i not in d_n and i not in d_p:\r\n if len(d_n) != 1:\r\n d_n.add(i)\r\n elif not c_n:\r\n c_n = i\r\n elif i != c_n:\r\n d_p.add(c_n)\r\n d_p.add(i)\r\n c_n = None\r\n elif i > 0:\r\n d_p.add(i)\r\n else:\r\n d_0.add(i)\r\n\r\nprint(str(len(d_n)) + \" \" + \" \".join(str(x) for x in d_n))\r\nprint(str(len(d_p)) + \" \" + \" \".join(str(x) for x in d_p))\r\nprint(str(len(d_0) + (1 if c_n else 0)) + \" 0\" + (\"\" if not c_n else \" %d\" % c_n))", "sayi_adedi = input('')\r\nsayilar = input('').split()\r\nneg = []\r\npos = []\r\nfor sayi in sayilar:\r\n if int(sayi)<0:\r\n neg.append(int(sayi))\r\n elif int(sayi)>0:\r\n pos.append(int(sayi))\r\n\r\nif len(pos)!=0: ####tek sayida negatif varsa\r\n st1 = ''\r\n for i in pos:\r\n st1 += str(i) + ' '\r\n st2 = ''\r\n for i in neg[1:]:\r\n st2 += str(i) + ' '\r\n print(1, neg[0])\r\n print(len(pos), st1)\r\n print(len(neg), 0, st2 )\r\nelif len(pos)==0: \r\n st = ''\r\n for i in neg[3:]:\r\n st += str(i) + ' '\r\n print(1 ,neg[0])\r\n print(2, neg[1], neg[2])\r\n print(len(neg[3:])+1, 0, st)", "def print_arr():\r\n print(len(neg), end=\" \")\r\n for i in neg:\r\n print(i, end=\" \")\r\n print()\r\n print(len(pos), end=\" \")\r\n for i in pos:\r\n print(i, end=\" \")\r\n print()\r\n print(len(zero), end=\" \")\r\n for i in zero:\r\n print(i, end=\" \")\r\n\r\n\r\nn = int(input())\r\narr = [int(i) for i in input().split()]\r\nneg = []\r\npos = []\r\nzero = []\r\nfor i in arr:\r\n if i<0:\r\n neg.append(i)\r\n elif i>0:\r\n pos.append(i)\r\n else:\r\n zero.append(i)\r\n\r\nif len(pos)==0:\r\n if len(neg)%2==0:\r\n ele1 = neg.pop()\r\n pos.append(ele1)\r\n ele1 = neg.pop()\r\n pos.append(ele1)\r\n ele1 = neg.pop()\r\n zero.append(ele1)\r\n print_arr()\r\n\r\n else:\r\n ele1 = neg.pop()\r\n pos.append(ele1)\r\n ele1 = neg.pop()\r\n pos.append(ele1)\r\n print_arr()\r\n\r\nelif len(neg)%2==0:\r\n ele1 = neg.pop()\r\n zero.append(ele1)\r\n print_arr()\r\n\r\nelse:\r\n print_arr()\r\n\r\n", "n = int(input())\r\n\r\na=[int(x) for x in input().split()]\r\nnega = 0\r\ncnt = 0\r\nfor i in a:\r\n if i<0:\r\n nega+=1\r\nx=[]\r\ny=[]\r\nz=[]\r\nfor i in a:\r\n if i<0 and len(x)==0:\r\n x.append(i)\r\n nega-=1\r\n elif i==0:\r\n z.append(i)\r\n elif i>0:\r\n y.append(i)\r\n else:\r\n if nega>=2 and cnt!=2:\r\n y.append(i)\r\n cnt+=1\r\n else:\r\n z.append(i)\r\n \r\nprint(len(x),*x)\r\nprint(len(y),*y)\r\nprint(len(z),*z)\r\n", "n, a = int(input()), sorted(int(i) for i in input().split())\nres = ([a[0]], [a[-1]], [*a[1:-1]]) if a[-1] > 0 else ([a[0]], [*a[1:3]], [*a[3:]])\nfor i in res:\n print(len(i), *i)\n", "def array(arr):\r\n\tset1 = []\r\n\tset2 = []\r\n\tset3 = []\r\n\tfor i in arr:\r\n\t\tif i>0:\r\n\t\t\tset2.append(i)\r\n\t\telif i == 0:\r\n\t\t\tset3.append(i)\r\n\t\telse:\r\n\t\t\tset1.append(i)\r\n\tif len(set1)%2 == 0:\r\n\t\tset3.append(set1.pop())\r\n\tif len(set2) == 0:\r\n\t\tset2.append(set1.pop())\r\n\t\tset2.append(set1.pop())\r\n\r\n\tprint(len(set1), *set1)\r\n\tprint(len(set2), *set2)\r\n\tprint(len(set3), *set3)\r\n\r\ninput()\r\narray(list(map(int, input().split())))", "def divide_array():\n element = []\n no_of_elements = int(input())\n element = list(map(int, input().split()))\n\n element.sort()\n\n zero = []\n positive = []\n negative = []\n\n if element[-1] > 0:\n positive.append(element[-1])\n element.pop()\n negative.append(element[0])\n zero_start = 1\n else:\n positive.append(element[0])\n positive.append(element[1])\n negative.append(element[2])\n zero_start = 3\n\n for i in range(zero_start, len(element)):\n zero.append(element[i])\n\n print(\"1\", negative[-1])\n print(len(positive), end=' ')\n print(*positive)\n print(len(zero), end=' ')\n print(*zero)\n\n\ndivide_array()\n\n\t\t \t \t\t \t \t \t \t\t\t \t\t\t \t\t", "import sys\ninput = sys.stdin.readline\n\nn = int(input())\na = list(map(int, input().split()))\n\nlist_neg = []\nlist_zero = []\nlist_pos = []\n\nfor x in a:\n if x < 0: list_neg.append(x)\n elif x > 0: list_pos.append(x)\n else: list_zero.append(x)\n\nif len(list_pos) == 0:\n list_pos.append(list_neg.pop()) \n list_pos.append(list_neg.pop()) \n\nif len(list_neg) % 2 == 0:\n list_zero.append(list_neg.pop())\n\nprint(len(list_neg), ' '.join(str(x) for x in list_neg))\nprint(len(list_pos), ' '.join(str(x) for x in list_pos))\nprint(len(list_zero), ' '.join(str(x) for x in list_zero))\n \t\t\t \t\t\t \t\t \t\t\t \t \t\t\t\t\t\t \t", "n = int(input())\r\na = list(map(int,input().split()))\r\na.sort()\r\nprint('1', a[0])\r\nif a[-1] > 0:\r\n print('1',a[-1])\r\n print(n-2, *a[1:-1])\r\nelse:\r\n print('2', a[1], a[2])\r\n print(n-3, *a[3:])", "a=int(input())\nlst=list(map(int,input().split()))\npositive=[];negative=[];zeroes=[]\nfor i in range(len(lst)):\n if lst[i]==0:\n zeroes.append(lst[i])\n elif lst[i]>0:\n positive.append(lst[i])\n else:\n negative.append(lst[i])\nif len(positive)==0:\n positive.append(negative.pop())\n positive.append(negative.pop())\nif len(negative)%2==0:\n zeroes.append(negative.pop())\nans=[negative,positive,zeroes]\nfor i in range(3):\n print(len(ans[i]),*ans[i])\n \t \t \t \t\t\t\t\t \t\t \t \t \t", "n=int(input())\nlst=list(map(int,input().split()))\nneg,pos,zer=[],[],[]\nfor i in range(n):\n if lst[i]==0:\n zer.append(lst[i])\n elif lst[i]<0:\n neg.append(lst[i])\n else:\n pos.append(lst[i])\nif len(pos)==0:\n pos.append(neg.pop())\n pos.append(neg.pop())\nif len(neg)%2==0:\n zer.append(neg.pop())\nprint(len(neg),*neg)\nprint(len(pos),*pos)\nprint(len(zer),*zer)\n\t\t \t \t\t \t \t\t\t \t \t\t \t\t\t\t \t\t\t", "\nn = int(input())\na = sorted([int(i) for i in input().split()])\n\ns1, s2, s3 = [],[],[]\ns1.append(a[0])\na.remove(a[0])\nif a[-1] > 0:\n s2.append(a[-1])\n a.remove(a[-1])\n for i in a:\n s3.append(i)\nelse:\n s2.append(a[0])\n a.remove(a[0])\n s2.append(a[0])\n a.remove(a[0])\n for i in a:\n s3.append(i)\n\n\n\nprint(len(s1), *s1)\nprint(len(s2), *s2)\nprint(len(s3), *s3)\n\n\t\t \t\t \t \t\t\t\t\t \t \t \t \t\t", "n=int(input())\r\nnums=list(map(int,input().split()))\r\nminus=[]\r\npos=[]\r\ncheck=[]\r\ncount=0\r\nfor i,item in enumerate(nums):\r\n if item ==0:\r\n check.append(item)\r\n \r\n elif item <0:\r\n count+=1\r\n minus.append(item)\r\n else:\r\n pos.append(item) \r\n\r\nif len(pos)==0:\r\n print(1,minus[0])\r\n if count%2==0:\r\n print(len(minus)-2,*minus[2:])\r\n check.extend(minus[1:2])\r\n else:\r\n print(len(minus[1:]),*minus[1:])\r\n\r\n print(len(check),*check)\r\nelse:\r\n print(1,minus[0])\r\n print(len(pos),*pos)\r\n check.extend(minus[1:])\r\n print(len(check),*check) \r\n\r\n\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nlzero = []\r\ngzero = []\r\nzero = []\r\nl = 1\r\nm = 1\r\nz = 1\r\nfor i in range(n):\r\n if(a[i]<0 ):\r\n lzero.append(a[i])\r\n elif(a[i]>0):\r\n gzero.append(a[i])\r\n else:\r\n zero.append(a[i])\r\nif(len(gzero)==0 and len(lzero)>2):\r\n gzero.append(lzero.pop())\r\n gzero.append(lzero.pop())\r\nif(len(lzero)%2==0):\r\n zero.append(lzero.pop())\r\nprint(len(lzero),*lzero)\r\nprint(len(gzero),*gzero)\r\nprint(len(zero),*zero)\r\n \r\n \r\n \r\n \r\n", "n = int(input())\r\n\r\narr = [int(i) for i in input().split()]\r\n\r\narr.sort()\r\n\r\nprint(1, arr[0])\r\n\r\nif(arr[len(arr)-1] == 0):\r\n print(2, arr[1], arr[2])\r\n print(len(arr) - 3, end = \" \")\r\n for i in range(3, len(arr)):\r\n print(arr[i], end = \" \")\r\n print()\r\nelse:\r\n print(1, arr[len(arr)-1])\r\n print(len(arr) - 2, end = \" \")\r\n for i in range(1, len(arr)-1):\r\n print(arr[i], end = \" \")\r\n print()", "n=int(input())\r\nl=list(map(int,input().split()))\r\npos=[]\r\nneg=[]\r\nzero=[]\r\nfor i in range(n):\r\n if(l[i]>0):\r\n pos.append(l[i])\r\n elif l[i]<0:\r\n neg.append(l[i])\r\n else:\r\n zero.append(l[i])\r\nif(len(pos)==0):\r\n pos=[neg[-2],neg[-1]]\r\n neg=neg[:-2]\r\nif(len(neg)%2==0):\r\n zero.append(neg[-1])\r\n neg=neg[:-1]\r\nprint(len(neg),end=\" \")\r\nfor i in range(len(neg)):\r\n print(neg[i],end=\" \")\r\nprint(\"\")\r\nprint(len(pos),end=\" \")\r\nfor i in range(len(pos)):\r\n print(pos[i],end=\" \")\r\nprint(\"\")\r\nprint(len(zero),end=\" \")\r\nfor i in range(len(zero)):\r\n print(zero[i],end=\" \")\r\nprint(\"\")\r\n\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\ncnt_zero = 0\r\ncnt_pos = 0\r\ncnt_neg = 0\r\nneg = []\r\npos = []\r\nzero = []\r\nfor i in arr:\r\n if i < 0:\r\n cnt_neg += 1\r\n neg.append(i)\r\n elif i > 0:\r\n cnt_pos += 1\r\n pos.append(i)\r\n else:\r\n cnt_zero += 1\r\n zero.append(i)\r\nif cnt_pos>0:\r\n if cnt_neg&1:\r\n print(cnt_neg,*neg)\r\n print(cnt_pos,*pos)\r\n print(cnt_zero,*zero)\r\n else:\r\n print(cnt_neg-1,*neg[:-1])\r\n print(cnt_pos,*pos)\r\n print(cnt_zero+1,*zero,neg[-1])\r\nelse:\r\n if cnt_neg%2==0:\r\n print(cnt_neg-3,*neg[:-3])\r\n print(2,neg[-3],neg[-2])\r\n print(cnt_zero+1,*zero,neg[-1])\r\n else:\r\n print(cnt_neg-2,*neg[:-2])\r\n print(2,neg[-2],neg[-1])\r\n print(cnt_zero,*zero)\r\n\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nx,y,z=[],[],[]\r\nf1,f2,f3=0,0,0\r\nng,p,d=0,0,0\r\n\r\nfor i in a:\r\n if i<0:\r\n ng+=1\r\n elif i>0:\r\n p+=1\r\n else:\r\n d+=1\r\nfor i in a:\r\n if i<0 and f1==0:\r\n x.append(i)\r\n f1=1\r\n elif i>0:\r\n y.append(i)\r\n else:\r\n z.append(i)\r\nif not y:\r\n z.sort()\r\n y.append(z[0])\r\n y.append(z[1])\r\n del z[0]\r\n del z[0]\r\n \r\nprint(len(x),*x)\r\nprint(len(y),*y)\r\nprint(len(z),*z)", "temp = int(input())\nsomething = [int(x) for x in input().split()]\none = set()\ntwo = set()\nthree = set()\nfor i in something:\n if i == 0:\n three.add(0)\n elif i < 0:\n one.add(i)\n else:\n two.add(i)\nif len(one) % 2 == 0:\n three.add(one.pop())\nif len(two) == 0:\n two.add(one.pop())\n two.add(one.pop())\nprint(len(one), \"\".join([str(x) + \" \" for x in one]))\nprint(len(two), \"\".join([str(x) + \" \" for x in two]))\nprint(len(three), \"\".join([str(x) + \" \" for x in three]))", "n = int(input())\r\na = list(map(int, input().split()))\r\nneg = []\r\npos = []\r\nzero = []\r\nfor i in range(n):\r\n if a[i] > 0:\r\n pos.append(a[i])\r\n elif a[i] < 0:\r\n neg.append(a[i])\r\n else:\r\n zero.append(a[i])\r\nif len(pos) == 0:\r\n pos.append(neg.pop())\r\n pos.append(neg.pop())\r\nif len(neg)%2 == 0:\r\n zero.append(neg.pop())\r\nprint(len(neg), *neg)\r\nprint(len(pos), *pos)\r\nprint(len(zero), *zero)\r\n ", "n = int(input())\r\nr = lambda : list(map(int, input().split()))\r\narr = r()\r\nneg = [i for i in arr if i < 0]\r\npos = [i for i in arr if i > 0]\r\nzero = [0]\r\n\r\nif len(neg)%2==0:\r\n pos.extend(neg[1:-1])\r\n zero.append(neg[-1])\r\n neg = neg[:1]\r\nelse:\r\n if len(pos) == 0:\r\n pos.extend(neg[-2:])\r\n neg = neg[:-2]\r\n\r\n\r\nprint(len(neg) , *neg)\r\nprint(len(pos) , *pos)\r\nprint(len(zero) , *zero)\r\n\r\n\r\n\r\n\r\n", "import sys\r\ninpu = sys.stdin.buffer.readline\r\nprin = sys.stdout.write\r\nn = int(inpu())\r\na = list(map(int, inpu().split()))\r\na.sort()\r\nprin(\"1 \" + str(a[0]) + '\\n')\r\nif a[1] < 0 and a[2] < 0:\r\n for i in range(3, n) :\r\n if a[i] > 0:\r\n prin(str(n - i + 2) + ' ' + ' '.join(map(str, a[i :])) + ' ' + str(a[1]) + ' ' + str(a[2]) + '\\n')\r\n prin(str(i - 3) + ' ' + ' '.join(map(str, a[3 : i])) + '\\n')\r\n break\r\n else :\r\n prin('2 ' + str(a[1]) + ' ' + str(a[2]) + '\\n')\r\n prin(str(n - 3) + ' ' + ' '.join(map(str, a[3 : n])) + '\\n')\r\nelse :\r\n for i in range(1, n) :\r\n if a[i] > 0:\r\n prin(str(n - i) + ' ' + ' '.join(map(str, a[i :])) + '\\n')\r\n prin(str(i - 1) + ' ' + ' '.join(map(str, a[1 : i])) + '\\n')\r\n break", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\npos1 = -1\r\nneg1, neg2, neg3 = -1, -1, -1\r\n\r\nfor i in range(len(a)):\r\n if a[i] > 0:\r\n pos1 = i \r\n elif a[i] < 0:\r\n if neg1 == -1:\r\n neg1 = i \r\n elif neg2 == -1:\r\n neg2 = i \r\n else:\r\n neg3 = i\r\n \r\nif pos1 != -1:\r\n print(1, a[neg1]) # Tập hợp < 0. Chỉ cần đúng 1 số âm thì tích sẽ âm\r\n print(1, a[pos1]) # Tập hợp > 0. Chỉ cần đúng 1 số dương thì tích sẽ dương\r\n print(n - 2, end = ' ')\r\n for i in range(n): # In tất cả các số còn lại trong mảng a, ngoại trừ pos1 và neg1\r\n if i != neg1 and i != pos1:\r\n print(a[i], end = ' ')\r\nelse:\r\n print(1, a[neg1])\r\n print(2, a[neg2], a[neg3]) # Dùng hai số âm\r\n print(n - 3, end = ' ')\r\n for i in range(n):\r\n if i not in [neg1, neg2, neg3]:\r\n print(a[i], end = ' ')", "def printArr(array):\r\n print(len(array), end=\" \")\r\n for i in array: print(i, end=\" \")\r\n print()\r\n\r\nn=int(input())\r\noriginal=list(map(int,input().split()))\r\nsetPos=[]\r\nsetNeg=[]\r\nsetZero=[]\r\ncountNeg=0\r\ncountPos=0\r\noriginal.sort(reverse=True)\r\nfor i in original:\r\n if i>0 and countPos<=1: \r\n setPos.append(i)\r\n countPos+=1\r\n elif i<0 and len(setNeg)<1:\r\n setNeg.append(i)\r\n elif i<0 and countNeg<2 and countPos<=1: \r\n setPos.append(i)\r\n countNeg+=1\r\n else: setZero.append(i)\r\nprintArr(setNeg)\r\nprintArr(setPos)\r\nprintArr(setZero)", "n = int(input())\r\nnums = sorted(list(map(int,input().split())))\r\nif nums[-1] == 0:\r\n print(1,nums[-2])\r\n print(2,*nums[-3:-5:-1])\r\n print(len(nums[:-4])+1, *([0] + nums[:-4]))\r\nelse:\r\n print(1,nums[0])\r\n print(1,nums[-1])\r\n print(len(nums[1:-1]),*nums[1:-1])", "def main():\n n = int(input())\n a = list(map(int, input().split()))\n posL = []\n negL = []\n zeroL = []\n for i in range(n):\n if a[i] > 0:\n posL.append(str(a[i]))\n elif a[i] < 0:\n negL.append(str(a[i]))\n else:\n zeroL.append(str(a[i]))\n \n print(1, negL[0])\n \n if len(posL) == 0:\n print(2, negL[1], negL[2])\n print(len(negL) + len(zeroL) - 3, \" \".join(negL[3:]), \" \".join(zeroL))\n else:\n print(len(posL), \" \".join(posL))\n print(len(negL) + len(zeroL) - 1, \" \".join(zeroL), \" \".join(negL[1:]))\nmain()\n\t\t\t \t \t \t\t \t \t\t\t \t\t\t \t", "from math import *\nn=int(input())\nlst=list(map(int,input().split()))\npos=0\nneg=0\nzero=0\nfirst=0\nx=[]\ny=[]\nz=[]\nfor a in lst:\n\tif a>0:\n\t\tpos+=1\n\telif a<0:\n\t\tneg+=1\n\t\tfirst=a\n\telse:\n\t\tzero+=1\n\nif neg%2==1:\n\tx.append(first)\n\tfor a in lst:\n\t\tif a!=first:\n\t\t\tif(a==0):\n\t\t\t\tz.append(a)\n\t\t\telse:\n\t\t\t\ty.append(a)\nelse:\n\tflag=0\n\tz.append(first)\n\tfor a in lst:\n\t\tif a!=first:\n\t\t\tif(a==0):\n\t\t\t\tz.append(a)\n\t\t\telif a<0 and flag==0:\n\t\t\t\tx.append(a)\n\t\t\t\tflag+=1\n\t\t\telse:\n\t\t\t\ty.append(a)\n\nprint(len(x),end=\" \")\nfor a in x:\n\tprint(a,end=\" \")\nprint(\"\\n\")\nprint(len(y),end=\" \")\nfor a in y:\n\tprint(a,end=\" \")\nprint(\"\\n\")\nprint(len(z),end=\" \")\nfor a in z:\n\tprint(a,end=\" \")\nprint(\"\\n\")\n\n\n", "n = int(input())\r\nnums = list(map(int, input().split()))\r\nnums.sort()\r\nnegatives = nums.index(0)\r\npositives = nums[::-1].index(0)\r\n#print(negatives,positives)\r\nprint(1, nums[0])\r\nif positives == 0:\r\n print(2, nums[1], nums[2])\r\n print(n-3, end = ' ')\r\n for i in range(3,n):\r\n print(nums[i],end = ' ')\r\n print()\r\nelse:\r\n print(1, nums[-1])\r\n print(n-2, end= ' ')\r\n for i in range(1,n-1):\r\n print(nums[i], end= ' ')\r\n print()", "from collections import defaultdict, deque\nfrom functools import lru_cache\nfrom heapq import heappush, heappop\nfrom typing import Counter\nimport math\n #int(input())\n #arr = list(map(int, input().split()))\n #n,m = map(int, input().split())\n #graph = defaultdict(list)\n \n #a,b = map(int, input().split())\n #graph[a].append(b)\n #graph[b].append(a)\n #MOD = 10**9 + 7\n\ndef solution():\n n = int(input())\n arr = list(map(int, input().split()))\n zeros = []\n postives = []\n negatives = []\n\n for val in arr:\n if val > 0:\n postives.append(val)\n if val == 0:\n zeros.append(val)\n if val < 0:\n negatives.append(val)\n\n if len(negatives)%2 == 0:\n zeros.append(negatives.pop())\n\n if len(postives) == 0:\n postives.append(negatives.pop())\n postives.append(negatives.pop())\n\n print(len(negatives),\" \".join(map(str,negatives)))# there must be atleast on enegative\n print(len(postives),\" \".join(map(str,postives))) # if no postives take two\n print(len(zeros),\" \".join(map(str,zeros)))#there must be atleast one zero\n \n\n\n\n#import sys\n#import threading\n#sys.setrecursionlimit(1 << 30)\n#threading.stack_size(1 << 27)\n#thread = threading.Thread(target=solution)\n#thread.start(); thread.join()\nsolution()\n", "import math\nn = int(input())\n# a = [int(i) for i in input().split()]\nneg = []\nnegs = 0\npos = []\nposs = 0\nzero = []\nzeros = 0\nfor k in input().split():\n i = int(k)\n if i < 0:\n neg.append(i)\n negs += 1\n elif i == 0:\n zero.append(i)\n zeros += 1\n else:\n pos.append(i)\n poss += 1\n\nif negs%2 == 0 and negs > 0:\n zero.append(neg[0])\n zeros += 1\n neg = neg[1:]\n negs -= 1\n\nif poss == 0:\n pos = neg[:2]\n poss += 2\n neg = neg[2:]\n negs -= 2\n\nprint(negs,' '.join(map(str,neg)))\nprint(poss,' '.join(map(str,pos)))\nprint(zeros,' '.join(map(str,zero)))\n", "def PROBLEM():\r\n n=int(input())\r\n a=sorted(list(map(int,input().split())))\r\n print(1,a[0])\r\n P=a.index(0)\r\n k=0\r\n if len(a[1:P])>0 and len(a[1:P])%2!=0:\r\n k=1\r\n print(len(a[1:P-k])+len(a[P+1:]),end=' ')\r\n print(*a[1:P-k],*a[P+1:])\r\n if k==1:\r\n print(2,0,a[P-1])\r\n else:\r\n print('1 0') \r\n \r\nPROBLEM()", "import sys,math\n'''\nclass node:\n def __init__(self,left,right,val):\n self.left = left\n self.right = right\n self.val = val\n\n\nlf2 = node(None,None,5)\nrf2 = node(None,None,9)\n\nlf1 = node(lf2,rf2,'+')\nrf1 = node(None,None,2)\nleft = node(None,None,3)\n\nright = node(lf1,rf1,'*')\nroot = node(left,right,'+')\n\ndef cal(root):\n if root.left == None and root.right == None:\n return root.val\n else:\n op = root.val\n if op == '+':\n return cal(root.left)+cal(root.right)\n if op == '*':\n return cal(root.left)*cal(root.right)\n\nprint(cal(root))\n'''\ndef ispositive(a):\n for i in a:\n if i>0:\n return True\n return False\nn = int(input())\na = list(map(int,input().split()))\na1=[]\na2=[]\na3=[]\nif ispositive(a):\n for i in a:\n if len(a1) == 0 and i<0:\n a1.append(i)\n elif len(a2) == 0 and i>0:\n a2.append(i)\n else:\n a3.append(i)\nelse:\n for i in a:\n if len(a1) == 0 and i<0:\n a1.append(i)\n elif len(a2) < 2 and i<0:\n a2.append(i)\n else:\n a3.append(i)\n\nprint(1,a1[0])\nprint(len(a2),' '.join(map(str,a2)))\nprint(len(a3),' '.join(map(str,a3)))\n", "n=int(input())\r\na=sorted(map(int,input().split()))\r\nq=[]\r\nif a[-1]>0:\r\n print(1,a[0])\r\n print(1,a[-1])\r\n for i in range(1,n-1):q+=[a[i]]\r\n print(n-2,*q)\r\nelse:\r\n print(1,a[0])\r\n print(2,a[1],a[2])\r\n for i in range(3,n):q+=[a[i]]\r\n print(n-3,*q)", "n=int(input())\r\nl=list(map(int,input().split()))\r\nl1=[];l2=[];l3=[]\r\nfor i in range(len(l)):\r\n if(l[i]>0):\r\n l2.append(l[i])\r\n elif(l[i]<0):\r\n l1.append(l[i])\r\n elif(l[i]==0):\r\n l3.append(l[i])\r\nif(l2==[]):\r\n l2.append(l1[0])\r\n l1.remove(l1[0])\r\n l2.append(l1[0])\r\n l1.remove(l1[0])\r\nif(len(l1)%2==0):\r\n l3.append(l1[0])\r\n l1.remove(l1[0])\r\nprint(len(l1),end=\" \")\r\nfor i in l1:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(l2),end=\" \")\r\nfor i in l2:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(l3),end=\" \")\r\nfor i in l3:\r\n print(i,end=\" \")", "N = int(input())\r\n\r\narray = list(map(int, input().split()))\r\n\r\nset1, set2, set3 = [], [], []\r\n\r\nfor i in range(N):\r\n if array[i] < 0:\r\n set1.append(array[i])\r\n elif array[i] > 0:\r\n set2.append(array[i])\r\n elif array[i] == 0:\r\n set3.append(array[i])\r\n\r\nif len(set2) == 0:\r\n set2.append(set1.pop())\r\n set2.append(set1.pop())\r\nif len(set1)%2 == 0:\r\n set3.append(set1.pop())\r\n\r\nprint(len(set1), \" \".join(map(str, set1)))\r\nprint(len(set2), \" \".join(map(str, set2)))\r\nprint(len(set3), \" \".join(map(str, set3)))", "# while 1:\r\n# try:\r\n\r\n# data = int(input())\r\n# values = [int(i) for i in input().split(' ')]\r\n\r\n# negative_set = list()\r\n# positive_set = list()\r\n# zero_set = list()\r\n\r\n# # since it is guaranteed that the solution exitsts\r\n# # so i can just put 1 negative in the 1st set zeros in the 3rd set\r\n# # other can all be inside the 2nd set \r\n# check_one_negative_number = 0\r\n# for i in values:\r\n# if i == 0:\r\n# zero_set.append(i)\r\n# elif i > 0:\r\n# positive_set.append(i)\r\n# else:\r\n# if check_one_negative_number == 0:\r\n# negative_set.append(i)\r\n# check_one_negative_number = 1\r\n# else:\r\n# positive_set.append(i)\r\n \r\n \r\n# print(len(negative_set),str(negative_set[0]))\r\n# print(len(positive_set),' '.join(str(i) for i in positive_set))\r\n# print(len(zero_set),' '.join(str(i) for i in zero_set).strip())\r\n# except:\r\n# break\r\n\r\n#=========================================================================\r\n# i misunderstand the question\r\n# set zero can put negative number in because if there is at least 1 zero in it \r\n# then the product of set zero must be zero\r\n# so there are things the consider \r\n\r\nwhile 1:\r\n try:\r\n data = int(input())\r\n values = [int(i) for i in input().split(' ')]\r\n \r\n negative_set = list()\r\n positive_set = list()\r\n zero_set = list()\r\n \r\n # so we put every negative number in the negative set\r\n # if there are not enough positive number , we pop 2 of them to the positive\r\n # then we check if there are even number of negative numbers\r\n # if it's even , we pop 1 more negative number to the 3rd set\r\n # check_negative_number = 0\r\n for i in values:\r\n if i < 0:\r\n negative_set.append(i)\r\n elif i > 0:\r\n positive_set.append(i)\r\n else:\r\n zero_set.append(i)\r\n \r\n if len(positive_set) == 0:\r\n positive_set.append(negative_set[-1])\r\n positive_set.append(negative_set[-2])\r\n negative_set.pop()\r\n negative_set.pop()\r\n\r\n if len(negative_set) % 2 == 0:\r\n zero_set.append(negative_set[-1])\r\n negative_set.pop()\r\n \r\n print(len(negative_set),' '.join(str(i) for i in negative_set))\r\n print(len(positive_set),' '.join(str(i) for i in positive_set))\r\n print(len(zero_set),' '.join(str(i) for i in zero_set))\r\n except:\r\n break", "t=int(input())\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nc0=arr.count(0)\r\np0=arr.index(0)\r\nc1=len(arr[0:p0])\r\nc2=len(arr[p0+c0::])\r\nz=arr[p0:p0+c0]\r\nn=arr[0:p0]\r\np=arr[p0+1::]\r\nif c2==0:\r\n p=n[0:2]\r\n z=z+n[3::]\r\n n=[n[2]]\r\nelse:\r\n z=z+n[1::]\r\n n=[n[0]]\r\nn=[str(i) for i in n]\r\np=[str(i) for i in p]\r\nz=[str(i) for i in z]\r\nprint(len(n),\" \".join(n))\r\nprint(len(p),\" \".join(p))\r\nprint(len(z),\" \".join(z))\r\n", "n = int(input())\nL = list(map(int,input().split()))\nL1 = []\nL2 = []\na = 0\nb = 0\nfor x in L:\n if x > 0:\n a = a + 1\n elif x < 0:\n b = b + 1\nL.sort()\nif a > 0:\n for i in L:\n if i == L[-1]:\n print(1,i)\n break\n elif i < 0 and i == L[0]:\n print(1,i)\n else:\n L1.append(i)\n print(len(L1),end = ' ')\n for i in L1:\n if i != L1[-1]:\n s = ' '\n else :\n s = '\\n'\n print(i,end = s)\nelse:\n for i in L:\n if i < 0 and i == L[0]:\n print(1,i)\n elif i < 0 and i <= L[2]:\n L2.append(i)\n if i == L[2]:\n print(len(L2),end = ' ')\n for j in L2:\n if j == L2[-1]:\n s = '\\n'\n else :\n s = ' '\n print(j,end = s)\n else:\n L1.append(i)\n print(len(L1),end = ' '),\n for i in L1:\n if i != L1[-1]:\n s = ' '\n else :\n s = '\\n'\n print(i,end = s)\n\t \t \t\t\t \t \t \t \t\t \t\t", "n = int(input())\r\narr = list(map(int, input().split()))\r\nnegative_cnt = 0\r\narr1 = []\r\narr2 = []\r\narr3 = []\r\nfor i in range(0, n):\r\n if arr[i] < 0:\r\n arr1.append(arr[i])\r\n negative_cnt += 1\r\n elif arr[i] > 0:\r\n arr2.append(arr[i])\r\n elif arr[i] == 0:\r\n arr3.append(arr[i])\r\n\r\nif len(arr2) == 0:\r\n for k in range(2):\r\n arr2.append(arr1.pop())\r\n\r\n\r\n\r\nif negative_cnt % 2 == 0:\r\n arr3.append(arr1.pop())\r\n\r\n\r\nprint(len(arr1), *arr1, sep=\" \")\r\nprint(len(arr2), *arr2, sep=\" \")\r\nprint(len(arr3), *arr3, sep=\" \")\r\n", "def main_function():\r\n input()\r\n array = [int(i) for i in input().split(\" \")]\r\n array_1 = []\r\n array_2 = []\r\n array_3 = []\r\n count_zero = 0\r\n count_positive = 0\r\n count_negative = 0\r\n positives = []\r\n negatives = []\r\n zeros = []\r\n for i in array:\r\n if i == 0:\r\n count_zero += 1\r\n zeros.append(i)\r\n elif i > 0:\r\n count_positive += 1\r\n positives.append(i)\r\n else:\r\n count_negative += 1\r\n negatives.append(i)\r\n array_3.append(negatives[-1])\r\n negatives.pop()\r\n if len(positives) > 0:\r\n array_1.append(positives[-1])\r\n positives.pop()\r\n else:\r\n array_1.append(negatives[-1])\r\n negatives.pop()\r\n array_1.append(negatives[-1])\r\n negatives.pop()\r\n array_2 = zeros + positives + negatives\r\n print(str(len(array_3)) + \" \" + \" \".join([str(i) for i in array_3]))\r\n print(str(len(array_1)) + \" \" + \" \".join([str(i) for i in array_1]))\r\n print(str(len(array_2)) + \" \" + \" \".join([str(i) for i in array_2]))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()", "_, arr = input(), list(map(int, input().split()))\npos = []; neg = []; zeros = [];\nneg_nums = [n for n in arr if n < 0]\npos_nums = [n for n in arr if n > 0]\nzeros = [n for n in arr if n == 0]\n\n\npos.extend(pos_nums)\n\n\nif len(neg_nums) % 2 == 0: # Even number of negative values\n neg.append(neg_nums.pop())\n if pos == []:\n \n pos.extend([neg_nums.pop(), neg_nums.pop()])\n zeros.extend(neg_nums)\n \n else:\n zeros.extend(neg_nums)\n \nelse: # Odd number of negative values\n neg.append(neg_nums.pop())\n pos.extend(neg_nums)\n \n \nfor sign_arr in [neg, pos, zeros]:\n print(len(sign_arr), ' '.join(list(map(str, sign_arr))))\n\n\n\n \t \t \t\t \t \t \t\t \t\t\t\t \t \t", "n = int(input())\r\na = list(map(int,input().split()))\r\np = []\r\nne = []\r\nz = []\r\nfor i in range(n):\r\n if(a[i] > 0): p.append(a[i])\r\n elif(a[i] < 0): ne.append(a[i])\r\n else: z.append(a[i])\r\nif(len(ne)%2 == 0):\r\n if(len(p) == 0):\r\n p.append(ne[-1])\r\n p.append(ne[-2])\r\n z.append(ne[-3])\r\n print(len(ne) - 3 , end = \" \")\r\n for i in range(len(ne) - 3):\r\n if(i == len(ne)-4): print(ne[i])\r\n else: print(ne[i] , end = \" \")\r\n print(len(p) , end = \" \")\r\n for i in range(len(p)):\r\n if(i == len(p)-1): print(p[i])\r\n else: print(p[i] , end = \" \")\r\n print(len(z) , end = \" \")\r\n for i in range(len(z)):\r\n print(z[i] , end = \" \")\r\n else:\r\n z.append(ne[-1])\r\n print(len(ne) - 1 , end = \" \")\r\n for i in range(len(ne) - 1):\r\n if(i == len(ne)-2): print(ne[i])\r\n else: print(ne[i] , end = \" \")\r\n print(len(p) , end = \" \")\r\n for i in range(len(p)):\r\n if(i == len(p)-1): print(p[i])\r\n else: print(p[i] , end = \" \")\r\n print(len(z) , end = \" \")\r\n for i in range(len(z)):\r\n print(z[i] , end = \" \")\r\nelse:\r\n if(len(p) == 0):\r\n p.append(ne[-1])\r\n p.append(ne[-2])\r\n print(len(ne) - 2 , end = \" \")\r\n for i in range(len(ne) - 2):\r\n if(i == len(ne)-3): print(ne[i])\r\n else: print(ne[i] , end = \" \")\r\n print(len(p) , end = \" \")\r\n for i in range(len(p)):\r\n if(i == len(p)-1): print(p[i])\r\n else: print(p[i] , end = \" \")\r\n print(len(z) , end = \" \")\r\n for i in range(len(z)):\r\n print(z[i] , end = \" \")\r\n else:\r\n print(len(ne) , end = \" \")\r\n for i in range(len(ne)):\r\n if(i == len(ne)-1): print(ne[i])\r\n else: print(ne[i] , end = \" \")\r\n print(len(p) , end = \" \")\r\n for i in range(len(p)):\r\n if(i == len(p)-1): print(p[i])\r\n else: print(p[i] , end = \" \")\r\n print(len(z) , end = \" \")\r\n for i in range(len(z)):\r\n print(z[i] , end = \" \")", "\r\ndef answer(n, a):\r\n s1 = set()\r\n s2 = set()\r\n s3 = set()\r\n for e in a:\r\n if e < 0:\r\n s1.add(e)\r\n elif e > 0:\r\n s2.add(e)\r\n else:\r\n s3.add(e)\r\n if len(s2) == 0: #no positive numbers\r\n s2.add(s1.pop())\r\n s2.add(s1.pop())\r\n if len(s1) % 2 == 0: #an even number of negative numbers.\r\n s3.add(s1.pop())\r\n \r\n print(len(s1), ' '.join(map(str, s1)))\r\n print(len(s2), ' '.join(map(str, s2)))\r\n print(len(s3), ' '.join(map(str, s3)))\r\n return #null\r\n\r\ndef main():\r\n n = int(input())\r\n a = [int(i) for i in input().split()]\r\n answer(n, a)\r\n\r\n\r\n return\r\nmain()", "n=int(input())\r\na=list(map(int,input().split()))\r\nodd=[]\r\neven=[]\r\nzero=[]\r\nfor i in a:\r\n if i<0:\r\n odd.append(i)\r\n elif i>0:\r\n even.append(i)\r\n else:\r\n zero.append(0)\r\ns1=[odd[-1]]\r\nodd.pop()\r\ns2=[]\r\nif len(odd)>=2:\r\n s2.append(odd.pop())\r\n s2.append(odd.pop())\r\nelse:\r\n s2.append(even.pop())\r\ns3=odd+even+zero\r\nprint(len(s1),*s1)\r\nprint(len(s2),*s2)\r\nprint(len(s3),*s3)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\n\r\na = list(map(int,input().split()))\r\n\r\ncountPos = 0\r\ncountNeg = 0\r\ncountZero = 0\r\n\r\nzeroSet = []\r\nnegSet = []\r\nposSet = []\r\n\r\nfor i in range(len(a)):\r\n if a[i]==0:\r\n countZero+=1\r\n zeroSet.append(a[i])\r\n \r\n if a[i]>0:\r\n countPos+=1\r\n posSet.append(a[i])\r\n \r\n if a[i]<0:\r\n countNeg+=1\r\n negSet.append(a[i])\r\n\r\n\r\n\r\n\r\nif len(posSet)==0:\r\n posSet.append(negSet.pop())\r\n posSet.append(negSet.pop())\r\n\r\nif len(negSet)%2==0:\r\n zeroSet.append(negSet.pop())\r\n\r\nprint(len(negSet),*negSet)\r\nprint(len(posSet),*posSet)\r\nprint(len(zeroSet),*zeroSet)\r\n", "import sys,math\n'''\nclass node:\n def __init__(self,left,right,val):\n self.left = left\n self.right = right\n self.val = val\n\n\nlf2 = node(None,None,5)\nrf2 = node(None,None,9)\n\nlf1 = node(lf2,rf2,'+')\nrf1 = node(None,None,2)\nleft = node(None,None,3)\n\nright = node(lf1,rf1,'*')\nroot = node(left,right,'+')\n\ndef cal(root):\n if root.left == None and root.right == None:\n return root.val\n else:\n op = root.val\n if op == '+':\n return cal(root.left)+cal(root.right)\n if op == '*':\n return cal(root.left)*cal(root.right)\n\nprint(cal(root))\n'''\nn = int(input())\na = sorted(map(int, input().split()))\nb = [a.pop(0)]\nc = [a.pop()] if a[-1] > 0 else [a.pop(0), a.pop(0)]\nfor L in b, c, a:\n print(len(L), ' '.join(map(str, L)))\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ns1 = [i for i in a if i < 0]\r\ns2 = [i for i in a if i > 0]\r\ns3 = [i for i in a if i == 0]\r\n\r\n\r\ndef pr(x):\r\n print(len(x), \" \".join(map(str, x)))\r\n\r\n\r\nif len(s2) == 0:\r\n s2.append(s1.pop())\r\n s2.append(s1.pop())\r\n\r\nif len(s1) % 2 == 0:\r\n s3.append(s1.pop())\r\n\r\npr(s1)\r\npr(s2)\r\npr(s3)\r\n", "n = int(input())\r\narr = [int(i) for i in input().split()]\r\nneg = []\r\npos = []\r\nzero = [0]\r\nfor i in range(n):\r\n if arr[i] < 0:\r\n neg.append(arr[i])\r\n elif arr[i] > 0:\r\n pos.append(arr[i])\r\nif len(neg) >= 1:\r\n print(1, neg[0])\r\n neg.pop(0)\r\nif len(pos) == 0:\r\n if len(neg) >= 2:\r\n print(2,neg[0],neg[1])\r\n neg.pop(0)\r\n neg.pop(0)\r\nelse:\r\n print(1,pos[0])\r\n pos.pop(0)\r\nzeros = neg+pos+[0]\r\nprint(len(zeros),end=\" \")\r\nprint(*zeros)\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = []\r\nc = []\r\nd = []\r\n\r\nfor x in a:\r\n if x < 0: b.append(x)\r\n elif x > 0: c.append(x)\r\n else: d.append(x)\r\n\r\nm = len(b)\r\nk = len(c)\r\np = len(d)\r\nif k == 0:\r\n c.append(b[m-1])\r\n c.append(b[m-2])\r\n b.pop()\r\n b.pop()\r\n k += 2\r\n m -= 2\r\nif m%2 == 0:\r\n d.append(b[m-1])\r\n b.pop()\r\n p += 1\r\n m -= 1\r\n\r\nprint(m, end=' ')\r\nfor x in b:\r\n print(x, end=' ')\r\nprint()\r\n\r\nprint(k, end=' ')\r\nfor x in c:\r\n print(x, end=' ')\r\nprint()\r\n\r\nprint(p, end=' ')\r\nfor x in d:\r\n print(x, end=' ')\r\nprint()", "\n\nn = int(input())\nl = sorted([int(x) for x in input().split()])\n\nmulti1 = [x for x in l if x < 0]\nmulti2 = [x for x in l if x > 0]\nmulti3 = [x for x in l if x == 0]\n\nif len(multi2) == 0:\n multi2.append(multi1.pop())\n multi2.append(multi1.pop())\n\nif len(multi1) > 1:\n multi3.extend(multi1[:-1])\n multi1 = [multi1[-1]]\n\nprint(len(multi1), *multi1)\nprint(len(multi2), *multi2)\nprint(len(multi3), *multi3)\n \n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ncount_neg = 0\r\ncount_pos = 0\r\nfor el in a:\r\n if el < 0:\r\n count_neg += 1\r\n elif el > 0:\r\n count_pos += 1\r\n\r\nneg, pos, zero = [],[],[]\r\nj,k = 0,0\r\nif count_pos == 0:\r\n for i in range(n):\r\n if a[i] < 0 and j < 2:\r\n pos.append(a[i])\r\n count_neg -= 1\r\n j += 1\r\n elif a[i] < 0 and k < 1:\r\n neg.append(a[i])\r\n count_neg -= 1\r\n k += 1\r\n else:\r\n zero.append(a[i])\r\nelse:\r\n for i in range(n):\r\n if a[i] > 0:\r\n pos.append(a[i])\r\n elif a[i] < 0 and k < 1:\r\n neg.append(a[i])\r\n count_neg -= 1\r\n k += 1\r\n else:\r\n zero.append(a[i])\r\n\r\nprint (len(neg), *neg)\r\nprint (len(pos), *pos)\r\nprint (len(zero), *zero)", "# Description of the problem can be found at http://codeforces.com/problemset/problem/300/A\r\n\r\nn = int(input())\r\nl_i = list(map(int, input().split()))\r\n\r\nc_n = None\r\nl_n = set()\r\nl_p = set()\r\nl_0 = set()\r\n\r\nfor i in l_i:\r\n if i < 0:\r\n if i not in l_n and i not in l_p:\r\n if len(l_n) != 1:\r\n l_n.add(i)\r\n elif not c_n:\r\n c_n = i\r\n elif i != c_n:\r\n l_p.add(c_n)\r\n l_p.add(i)\r\n c_n = None\r\n elif i > 0:\r\n l_p.add(i)\r\n else:\r\n l_0.add(i)\r\n\r\nprint(str(len(l_n)) + \" \" + \" \".join(str(x) for x in l_n))\r\nprint(str(len(l_p)) + \" \" + \" \".join(str(x) for x in l_p))\r\nprint(str(len(l_0) + (1 if c_n else 0)) + \" 0\" + (\"\" if not c_n else \" %d\" % c_n))", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\npositive_index = []\r\nfor i in range(n):\r\n\tif arr[i] > 0:\r\n\t\tpositive_index.append(i)\r\n\t\tbreak\r\n\r\nif len(positive_index) == 0:\r\n\tfor i in range(n):\r\n\t\tif arr[i] < 0:\r\n\t\t\tpositive_index.append(i)\r\n\t\t\tif len(positive_index) == 2:\r\n\t\t\t\tbreak\r\n\t\r\n\r\ndef is_existing(arr, num):\r\n\tfor i in arr:\r\n\t\tif i == num:\r\n\t\t\treturn True\r\n\t\t\r\n\treturn False\r\n\r\n\r\nnegative_index = []\r\n\r\nfor i in range(n):\r\n\tif arr[i] < 0 and not is_existing(positive_index, i):\r\n\t\tnegative_index.append(i)\r\n\t\tbreak\r\n\t\t\r\nzero_index = []\r\n\r\nfor i in range(n):\r\n\tif not is_existing(positive_index, i) and not is_existing(negative_index, i):\r\n\t\tzero_index.append(i)\r\n\t\t\r\ndef get_value(a):\r\n\tval = []\r\n\tfor i in a:\r\n\t\tval.append(arr[i])\r\n\treturn val\r\n\r\n\r\nseparator = ' '\r\nprint(len(negative_index), separator.join(map(str, get_value(negative_index))))\r\nprint(len(positive_index), separator.join(map(str, get_value(positive_index))))\r\nprint(len(zero_index), separator.join(map(str, get_value(zero_index))))", "def main():\r\n n = int(input())\r\n li = list(map(int, input().split()))\r\n li.sort()\r\n print(1, li[0])\r\n if li[-1] > 0:\r\n print(1, li[-1])\r\n print(n - 2, *li[1: -1])\r\n else:\r\n print(2, li[1], li[2])\r\n print(n - 3, *li[3:])\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "def divide_array(arr):\r\n neg_nums = []\r\n pos_nums = []\r\n zero_nums = []\r\n\r\n for num in arr:\r\n if num < 0:\r\n neg_nums.append(num)\r\n elif num > 0:\r\n pos_nums.append(num)\r\n else:\r\n zero_nums.append(num)\r\n\r\n if len(neg_nums) % 2 == 0:\r\n zero_nums.append(neg_nums.pop())\r\n\r\n if len(pos_nums) == 0:\r\n pos_nums.append(neg_nums.pop())\r\n pos_nums.append(neg_nums.pop())\r\n\r\n print(len(neg_nums), ' '.join(map(str, neg_nums)))\r\n print(len(pos_nums), ' '.join(map(str, pos_nums)))\r\n print(len(zero_nums), ' '.join(map(str, zero_nums)))\r\n\r\ndef main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n divide_array(arr)\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\ngroup1 = []\r\ngroup2 = []\r\ngroup3 = []\r\nfor i in range(n):\r\n if (a[i] < 0 and len(group1) < 3):\r\n group1.append(a[i])\r\n elif (a[i] > 0 and len(group3) < 2):\r\n group2.append(a[i])\r\n else:\r\n group3.append(a[i])\r\nif (len(group2) == 0):\r\n group2 = group1[1:3]\r\n group1 = group1[0:1]\r\nif (len(group1) == 2):\r\n group3.append(group1[-1])\r\n group1 = group1[0:1]\r\n\r\nprint(len(group1), end=' ')\r\nfor i in group1:\r\n print(i, end=' ')\r\nprint()\r\nprint(len(group2))\r\nfor i in group2:\r\n print(i, end=' ')\r\nprint()\r\nprint(len(group3), end=' ')\r\nfor i in group3:\r\n print(i, end=' ')", "n = input()\nk = list(map(int, input().split()))\nfirst = []\nsecond = []\nthird = []\n\nfor i in range(0, len(k)):\n if k[i] < 0:\n first.append(k[i])\n elif k[i] > 0:\n second.append(k[i])\n else:\n third.append(k[i])\n\nif len(second) == 0:\n second.append(first.pop())\n second.append(first.pop())\nif len(first) % 2 == 0:\n third.append(first.pop())\n\nprint(len(first), end=\" \")\nprint(*first)\nprint(len(second), end=\" \")\nprint(*second)\nprint(len(third), end=\" \")\nprint(*third)\n\n\t\t\t\t\t\t\t \t \t \t \t\t\t \t\t \t \t", "n = int(input())\r\narr = list(map(int, input().split()))\r\nneg = [x for x in arr if x < 0]\r\npos = [x for x in arr if x > 0]\r\na1 = [neg.pop()]\r\nif len(pos) > 0: a2 = [pos.pop()]\r\nelse: a2 = [neg.pop(), neg.pop()]\r\na3 = neg + pos + [0]\r\nprint(len(a1), *a1)\r\nprint(len(a2), *a2)\r\nprint(len(a3), *a3)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nn1 = 0\r\nlist1 = []\r\n\r\nn2 = 0\r\nlist2 = []\r\n\r\nn3 = 0\r\nlist3 = []\r\n\r\nneg1 = 0\r\nneg2 = 0\r\ncount = 0\r\n\r\nfor i in range(n):\r\n if a[i] == 0:\r\n n3 += 1\r\n list3.append(a[i])\r\n elif a[i] > 0:\r\n n2 += 1\r\n list2.append(a[i])\r\n else:\r\n if count == 0:\r\n count += 1\r\n neg1 = a[i]\r\n elif count == 1:\r\n count += 1\r\n neg2 = a[i]\r\n else:\r\n n2 += 2\r\n list2.append(neg1)\r\n list2.append(neg2)\r\n\r\n count = 1\r\n neg1 = a[i]\r\n\r\nif count == 1:\r\n n1 += 1\r\n list1.append(neg1)\r\nelse:\r\n n1 += 1\r\n list1.append(neg1)\r\n\r\n n3 += 1\r\n list3.append(neg2)\r\n\r\nprint(n1, *list1)\r\nprint(n2, *list2)\r\nprint(n3, *list3)", "n = int(input())\nlst = list(map(int, input().rstrip().split()))\npos=[]\nneg=[]\nzero=[]\nlst.sort()\nif lst[-1] > 0:\n pos.append(lst[-1])\n lst.pop(-1)\n neg.append(lst[0])\n zero=lst[1:]\nelse:\n pos.append(lst[0])\n pos.append(lst[1])\n neg.append(lst[2])\n zero=lst[3:]\nprint(len(neg),*neg)\nprint(len(pos),*pos)\nprint(len(zero),*zero)\n \t \t\t \t\t\t \t\t \t\t\t \t \t\t \t \t\t", "def solution(l):\n negatives = []\n zeros = []\n postives = []\n\n for i in l:\n if i > 0:\n postives.append(i)\n elif i < 0:\n negatives.append(i)\n else:\n zeros.append(i)\n\n print(1, negatives.pop())\n if postives:\n print(1, postives.pop())\n else:\n print(2, negatives.pop(), negatives.pop())\n zeros.extend(postives)\n zeros.extend(negatives)\n\n print(len(zeros), \" \".join(str(i) for i in zeros))\n\n\n\nif __name__ == '__main__':\n n = int(input())\n\n l = [int(i) for i in input().split()]\n solution(l)\n \t \t \t \t\t\t\t \t\t \t \t\t \t\t\t \t", "n=int(input())\r\ns=list(map(int,input().split()))\r\na=[]\r\nb=[]\r\nc=[]\r\nfor i in range(n):\r\n\tif s[i]<0:\r\n\t\ta.append(s[i])\r\n\telif s[i]>0:\r\n\t\tb.append(s[i])\r\n\telse:\r\n\t\tc.append(s[i])\r\nif len(a)%2==0:\r\n\td=a.pop()\r\n\tc.append(d)\r\nif len(b)==0:\r\n\te=a.pop()\r\n\tb.append(e)\r\n\tf=a.pop()\r\n\tb.append(f)\r\nprint(len(a),*list(a))\r\nprint(len(b),*list(b))\r\nprint(len(c),*list(c))\r\n", "n = int(input())\r\nlst = list(map(int, input().split()))\r\n\r\npos = []\r\nneg = []\r\nzero = []\r\n\r\nfor i in range(n):\r\n if lst[i] < 0:\r\n neg.append(lst[i])\r\n elif lst[i] > 0:\r\n pos.append(lst[i])\r\n else:\r\n zero.append(lst[i])\r\n\r\nif len(neg) % 2==0:\r\n zero.append(neg.pop())\r\nif len(pos) == 0:\r\n pos.append(neg.pop())\r\n pos.append(neg.pop())\r\n\r\nprint(len(neg), end = ' ')\r\nfor i in range(len(neg)):\r\n print(neg[i],end= ' ')\r\nprint()\r\n\r\nprint(len(pos), end = ' ')\r\nfor i in range(len(pos)):\r\n print(pos[i],end= ' ')\r\nprint()\r\n\r\nprint(len(zero), end = ' ')\r\nfor i in range(len(zero)):\r\n print(zero[i],end= ' ')\r\nprint()", "n=int(input())\nlst=list(map(int,input().split()))\npos, neg ,zero=[],[],[]\nfor el in lst:\n if el>0:\n pos.append(el)\n elif el<0:\n neg.append(el)\n else:\n zero.append(el)\nif len(neg)%2==0:\n zero.append(neg[-1])\n neg.pop()\nif len(pos)==0:\n pos.append(neg[-1])\n neg.pop()\n pos.append(neg[-1])\n neg.pop()\nprint(len(neg),*neg)\nprint(len(pos),*pos)\nprint(len(zero),*zero)\n \t \t\t\t \t\t \t \t \t \t\t \t \t", "from sys import stdin\r\ndef input(): return stdin.readline()[:-1]\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\na=[]\r\nfa=False\r\nb=[]\r\nfb=False\r\nc=[]\r\nfor i in range(n):\r\n\tif l[i]==0:\r\n\t\tc.append(0)\r\n\telif l[i]>0:\r\n\t\tif not fb:\r\n\t\t\tb.append(l[i])\r\n\t\t\tfb=True\r\n\t\telse:\r\n\t\t\tc.append(l[i])\r\n\telse:\r\n\t\tif not fa:\r\n\t\t\ta.append(l[i])\r\n\t\t\tfa=True\r\n\t\telse:\r\n\t\t\tc.append(l[i])\r\nprint(1,*a)\r\nif len(b):\r\n\tprint(1,*b)\r\nelse:\r\n\tcnt=2\r\n\ti=0\r\n\twhile cnt:\r\n\t\tif c[i]<0:\r\n\t\t\tb.append(c[i])\r\n\t\t\tc.remove(c[i])\r\n\t\t\tcnt-=1\r\n\t\t\ti-=1\r\n\t\ti+=1\r\n\tprint(2,*b)\r\nprint(len(c),*c)", "import sys, os\r\n# import numpy as np\r\nfrom math import sqrt, gcd, ceil, log, floor\r\nfrom bisect import bisect, bisect_left\r\nfrom collections import defaultdict, Counter, deque\r\nfrom heapq import heapify, heappush, heappop\r\nfrom itertools import permutations\r\ninput = sys.stdin.readline\r\nread = lambda: list(map(int, input().strip().split()))\r\n# read_f = lambda file: list(map(int, file.readline().strip().split()))\r\n# from time import time\r\n# sys.setrecursionlimit(5*10**6)\r\n\r\nMOD = 10**9 + 7\r\n\r\n\r\ndef main():\r\n\t# file1 = open(\"C:\\\\Users\\\\shank\\\\Desktop\\\\Comp_Code\\\\input.txt\", \"r\")\r\n\t# n = int(file1.readline().strip()); \r\n\t# arr = list(map(int, file1.read().strip().split(\" \")))\r\n\t# file1.close()\r\n\t# n = int(input())\r\n\t# for _ in range(int(input())):\r\n\tn = int(input());\r\n\tarr = read()\r\n\r\n\tpos, neg, zer = [], [], []\r\n\tfor i in arr:\r\n\t\tif i > 0:\r\n\t\t\tpos.append(i)\r\n\t\telif i < 0:\r\n\t\t\tneg.append(i)\r\n\t\telse:\r\n\t\t\tzer.append(0)\r\n\r\n\tif len(pos) == 0:\r\n\t\tpos.extend([neg.pop(), neg.pop()])\r\n\tif len(neg) % 2 == 0:\r\n\t\tzer.append(neg.pop())\r\n\tprint(len(neg), *neg)\r\n\tprint(len(pos), *pos)\r\n\tprint(len(zer), *zer)\r\n\r\n\r\n\r\n\r\n\t# file = open(\"output.txt\", \"w\")\r\n\t# file.write(ans+\"\\n\")\r\n\t# file.close()\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()\r\n\r\n\"\"\"\r\n6\r\n\r\n1 0 1 0 0 1 \r\n\r\n\"\"\"", "n=int(input())\r\nl=list(map(int,input().split()))\r\na1=0\r\nfor p in l:\r\n if(p<0):\r\n a1=p\r\n break\r\na2=0\r\na3=0\r\nl1=[]\r\nl2=[]\r\nfor p in l:\r\n if(p>0):\r\n a2+=1\r\n l1.append(p)\r\n if(a2>0):\r\n break\r\n if(p<0 and p!=a1):\r\n a3+=1\r\n l2.append(p)\r\n if(a3>1):\r\n break\r\nif(len(l1)>0):\r\n print(1,a1)\r\n print(1,l1[0])\r\n print(n-2,end=' ')\r\n l4=[p for p in l if(p!=a1 and p!=l1[0])]\r\n print(*l4)\r\nelse:\r\n print(1,a1)\r\n print(2,l2[0],l2[1])\r\n print(n-3,end=' ')\r\n l4=[p for p in l if(p!=a1 and p!=l2[0] and p!=l2[1])]\r\n print(*l4)", "input()\r\nls = sorted(list(map(int, input().split())))\r\n\r\n# print(\"Sorted List is --> \", ls)\r\n\r\nprint(1, ls[0]); ls.remove(ls[0])\r\n# print(\"Sorted List is --> \", ls)\r\nl = len (ls)\r\nif ls[l-1] > 0 : \r\n print(1, ls[l - 1]);\r\n print(l - 1, end = ' ')\r\n for i in ls[:l-1] : \r\n print(i, end=' ')\r\n print()\r\n \r\n\r\nif ls[l - 1] == 0 : \r\n print(2, ls[l - 3], ls[l - 2])\r\n print(l - 2, end = ' ')\r\n for i in ls[:l-3] :\r\n print(i, end = ' ')\r\n print(ls.pop())", "from typing import SupportsFloat\r\n\r\n\r\nn = int(input())\r\na = list(map(int, input().split(\" \")))\r\ni = 0\r\nneg = []\r\npos = []\r\nfor i in range(n):\r\n if (a[i] < 0):\r\n neg.append(a[i])\r\n elif (a[i] > 0):\r\n pos.append(a[i])\r\n \r\n\r\n\r\nif len(pos) == 0:\r\n print (\"1\", end = \" \")\r\n print (neg[0])\r\n print (2, end = \" \")\r\n print (neg[1], end = \" \")\r\n print (neg[2])\r\n\r\n print (len(neg)- 2, end = \" \")\r\n for i in range (3,len(neg)):\r\n if (i == len(neg) - 1):\r\n print (neg[i], end = \" \")\r\n else:\r\n print (neg[i], end = \" \")\r\n print (\"0\")\r\n\r\nelse:\r\n print (\"1\", end = \" \")\r\n print (neg[0])\r\n print (len(pos), end = \" \")\r\n for i in range (0, len(pos)):\r\n if i == len(pos) -1:\r\n print (pos[i])\r\n else:\r\n print (pos[i], end = \" \")\r\n \r\n if (len(neg) > 1):\r\n print (len(neg), end = \" \")\r\n for i in range(1, len(neg)):\r\n if i == len(neg) -1:\r\n print (neg[i], end = \" 0\")\r\n else:\r\n print (neg[i], end = \" \")\r\n else:\r\n print (\"1 0\")\r\n\r\n\r\n", "n=int(input())\r\narr=[int(ele)for ele in input().split()]\r\ns1=set()\r\ns2=set()\r\ns3=set()\r\nnegative=0\r\nfor i in arr:\r\n if i==0:\r\n s3.add(i)\r\n elif i<0:\r\n s2.add(i)\r\n negative+=1\r\n else:\r\n s1.add(i)\r\nif negative%2==0:\r\n v=s2.pop()\r\n s3.add(v)\r\nif len(s1)==0:\r\n v1=s2.pop()\r\n v2=s2.pop()\r\n s1.add(v1)\r\n s1.add(v2)\r\n\r\nprint(len(s2),end=' ')\r\nfor i in s2:\r\n print(i,end=' ')\r\nprint()\r\n\r\nprint(len(s1),end=' ')\r\nfor i in s1:\r\n print(i,end=' ')\r\nprint()\r\n\r\nprint(len(s3),end=' ')\r\nfor i in s3:\r\n print(i,end=' ')\r\n", "n = int(input())\narr = list(map(int,input().split()))\npos,neg,zeros = [],[],[]\nfor i in arr:\n if i <0:\n neg.append(str(i))\n if i > 0:\n pos.append(str(i))\n if i ==0:\n zeros.append(str(i))\nif len(pos) ==0 :\n pos.extend([neg.pop(),neg.pop()])\nif len(neg) %2==0 :\n zeros.append(neg.pop())\nprint(len(neg),' '.join(neg))\nprint(len(pos),' '.join(pos))\nprint(len(zeros),' '.join(zeros))\n\n", "def print_array(a):\r\n print(len(a), end=\" \")\r\n for i in a:\r\n print(i, end=\" \")\r\n print()\r\n return\r\n\r\n#input\r\nn = int(input())\r\n_array = list(map(int, input().split()))\r\n\r\n#process\r\nset1, set2, set3 = [] , [], []\r\nfor i in _array:\r\n if i < 0:\r\n set1.append(i)\r\n elif i > 0:\r\n set2.append(i)\r\n else:\r\n set3.append(i)\r\n\r\nif len(set1) % 2 == 0:\r\n set3.append(set1.pop())\r\n\r\nif len(set2) == 0:\r\n set2.append(set1.pop())\r\n set2.append(set1.pop())\r\n \r\n\r\n#output\r\nprint_array(set1)\r\nprint_array(set2)\r\nprint_array(set3)\r\n\r\n", "a = input()\nb = [int(i) for i in input().split(\" \")]\n\nneg = []\npos = []\nzero = []\n\nfor elt in b:\n if elt > 0:\n pos.append(str(elt))\n if elt == 0:\n zero.append(str(elt))\n\nfor elt_2 in b:\n if elt_2 < 0:\n if len(pos) == 0 or (pos[0][0] == \"-\" and len(pos) == 1):\n pos.append(str(elt_2))\n elif len(neg) == 0:\n neg.append(str(elt_2))\n else:\n zero.append(str(elt_2))\n\nprint(len(neg), \" \".join(neg))\nprint(len(pos), \" \".join(pos))\nprint(len(zero), \" \".join(zero))\n \t\t \t \t \t\t \t\t\t \t \t\t\t\t\t", "N = int(input())\r\nA = list(map(int, input().strip().split()))\r\n\r\nn1 = []\r\nn2 = []\r\nn3 = []\r\nfor i, a in enumerate(A):\r\n if a == 0:\r\n n3 += [a]\r\n elif a < 0:\r\n n1 += [a]\r\n else:\r\n n2 += [a]\r\n\r\nif len(n2) == 0:\r\n n2 += [n1[-1]]\r\n n1.pop()\r\n n2 += [n1[-1]]\r\n n1.pop()\r\n\r\nif len(n1) % 2 == 0:\r\n n3 += [n1[-1]]\r\n n1.pop()\r\n \r\n\r\nprint(len(n1), *n1)\r\nprint(len(n2), *n2)\r\nprint(len(n3), *n3)\r\n", "def print_ans(arr):\r\n print(len(arr), end=' ')\r\n print(' '.join([str(x) for x in arr]))\r\n\r\n\r\nn = int(input())\r\narr = [int(x) for x in input().split(' ')]\r\nnegatives = [x for x in arr if x < 0]\r\narr1 = [negatives[0]]\r\nnegatives = negatives[1:]\r\ncnt = len(negatives)\r\narr2 = negatives[:cnt - cnt % 2] + [x for x in arr if x > 0]\r\narr3 = negatives[cnt - cnt % 2:] + [0]\r\n\r\nprint_ans(arr1)\r\nprint_ans(arr2)\r\nprint_ans(arr3)", "n = int(input())\na = [int(i) for i in input().split()]\n\nneg = []\nzer = []\npos = []\nfor i in a:\n if i < 0:\n neg.append(i)\n if i == 0:\n zer.append(i)\n if i > 0:\n pos.append(i)\n\nprint(1, neg[0])\nneg = neg[1:]\nif len(pos) == 0:\n print(2, neg[0], neg[1])\n neg = neg[2:]\nelse:\n print(1, pos[0])\n pos = pos[1:]\nprint(len(zer) + len(pos) + len(neg), *zer, *pos, *neg)\n", "n = int(input())\narr = list(map(int, input().split()))\nless = [x for x in arr if x < 0]\nmore = [x for x in arr if x > 0]\nzero = [x for x in arr if x == 0]\nif len(less) % 2 == 0:\n\tzero.append(less.pop())\nif len(more) == 0 and len(less) > 2:\n\tmore.append(less.pop())\n\tmore.append(less.pop())\n\nprint(len(less), \" \".join([str(x) for x in less]))\nprint(len(more), \" \".join([str(x) for x in more]))\nprint(len(zero), \" \".join([str(x) for x in zero]))\n\t\t \t\t \t \t\t \t\t \t\t\t \t\t\t", "n = int(input())\narr = list(map(int, input().split()))\n\nneg = []\npos = []\nzero = []\n\nfor num in arr:\n if num > 0:\n pos.append(num)\n elif num < 0:\n neg.append(num)\n else:\n zero.append(num)\n\nif not pos:\n for i in range(2):\n pos.append(neg.pop())\n if len(neg)%2 == 0:\n zero.append(neg.pop())\n\nelse:\n if len(neg)%2 == 0:\n zero.append(neg.pop())\n\nprint(len(neg), *neg)\nprint(len(pos), *pos)\nprint(len(zero), *zero)\n", "\ndef solve(arr) :\n pos=[]\n neg=[]\n zer=[x for x in arr if x==0 ]\n arr=[x for x in arr if x!=0]\n for i in arr :\n if i<0 :\n neg.append(i)\n else:\n pos.append(i)\n if len(pos)==0 :\n pos.append(neg[-1])\n pos.append(neg[-2])\n neg.pop()\n neg.pop()\n zer.extend(neg[1:])\n neg=[neg[0]]\n\n\n print(len(neg),''.join(str(x)+' ' for x in neg).strip())\n print(len(pos),''.join(str(x)+' ' for x in pos).strip())\n print(len(zer),''.join(str(x)+' ' for x in zer).strip())\n\n\n\n\n\n\n\n \n\n \nn=int(input())\narr=[int(x) for x in input().split()]\n\nsolve(arr)\n\n\n\n'''\nn,m= [int(x) for x in input().split()]\narr=[]\nfor i in range(n):\n arr.append([int(x) for x in input().split()])\n'''\n'''\nn=int(input())\narr=[int(x) for x in input().split()]\n'''", "n = int(input())\nless = []\nmore = []\nequal = []\n\narr = [int(i) for i in input().split()]\nfor i in range(n):\n if arr[i] < 0:\n less.append(arr[i])\n elif arr[i] > 0:\n more.append(arr[i])\n else:\n equal.append(arr[i])\n\nif len(more) == 0:\n more.append(less.pop())\n more.append(less.pop())\n\nif len(less)%2==0:\n equal.append(less.pop())\n\nprint(len(less), *less)\nprint(len(more), *more)\nprint(len(equal), *equal)\n\n\n \t\t\t \t \t \t\t\t \t\t\t \t \t\t\t\t\t \t\t", "x = int(input())\r\narr = input().split( )\r\n\r\nset1 = []\r\nset2 = []\r\nset3 = []\r\n\r\ndef max_num():\r\n global max_arr\r\n max_arr = int(arr[0])\r\n for i in arr:\r\n if int(i) > max_arr:\r\n max_arr = int(i)\r\n return max_arr\r\n\r\ndef min_num():\r\n global min_arr\r\n min_arr = int(arr[0])\r\n for i in arr:\r\n if int(i) < min_arr:\r\n min_arr = int(i)\r\n return(min_arr)\r\n\r\nmax_num()\r\nmin_num()\r\nif max_arr > 0:\r\n set2.append(max_arr)\r\n arr.remove(str(max_arr))\r\n set1.append(min_arr)\r\n arr.remove(str(min_arr))\r\n set3 = arr\r\n\r\nelif max_arr == 0:\r\n set1.append(min_arr)\r\n arr.remove(str(min_arr))\r\n set3.append(\"0\")\r\n arr.remove(\"0\")\r\n min_num()\r\n set2.append(min_arr)\r\n arr.remove(str(min_arr))\r\n min_num()\r\n set2.append(min_arr)\r\n arr.remove(str(min_arr))\r\n set3 += arr\r\n\r\nprint(len(set1), *set1, sep=\" \")\r\nprint(len(set2), *set2, sep=\" \")\r\nprint(len(set3), *set3, sep=\" \")\r\n\r\n ", "n=int(input())\r\na=list(map(int,input().split()))\r\nc=0\r\nd=0\r\nl1=[]\r\nl2=[] \r\nl3=[]\r\nfor i in a:\r\n if i<0:\r\n c+=1 \r\n l1.append(i)\r\n if i==0:\r\n l2.append(i) \r\n if i>0:\r\n l3.append(i) \r\nif c%2==0:\r\n l2.append(l1[0])\r\n l1=l1[1:] \r\nif l3==[]:\r\n l3.append(l1[0])\r\n l3.append(l1[1])\r\n l1=l1[2:]\r\n \r\nprint(len(l1),end=\" \")\r\nprint(*l1)\r\nprint(len(l3),end=\" \")\r\nprint(*l3)\r\nprint(len(l2),end=\" \")\r\nprint(*l2)\r\n\r\n\r\n", "n=int(input())\r\nl=list(map(int, input().split()))\r\nl.sort()\r\nif l[n-1]==0:\r\n a=[l[0]]\r\n b=[l[1],l[2]]\r\n c=l[3:n]\r\nelse:\r\n a=[l[0]]\r\n b=[l[n-1]]\r\n c=l[1:n-1]\r\nprint(len(a),end=\" \")\r\nfor i in a:\r\n print(i,end=\" \")\r\nprint(\"\")\r\nprint(len(b),end=\" \")\r\nfor i in b:\r\n print(i,end=\" \")\r\nprint(\"\")\r\nprint(len(c),end=\" \")\r\nfor i in c:\r\n print(i,end=\" \")\r\nprint(\"\")", "\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\narr.sort()\r\ni = 0\r\nwhile(arr[i]<0 and i<n):\r\n i += 1\r\nneg=i-1\r\nzero = i\r\ni += 1\r\npos =0\r\nwhile (i<n and arr[i]>0):\r\n i += 1\r\n pos = i\r\nif pos>zero:\r\n print(1, arr[0])\r\n print(1, arr[zero+1])\r\n print(n-2, end=' ')\r\n for j in range(1, n):\r\n if j!=zero+1:\r\n print(arr[j], end=' ')\r\nelse:\r\n print(1, arr[0])\r\n print(2, arr[1], arr[2])\r\n print(n-3, end=' ')\r\n for j in range(3, n):\r\n print(arr[j], end=' ')", "from lib2to3.pgen2.token import LESS\r\n\r\n\r\nn = int(input())\r\nless = []\r\ngreat = []\r\none = []\r\ntwo = []\r\nthree = []\r\n\r\narray = [less.append(int(x)) if int(x) < 0 else [great.append(int(x)) if int(x) > 0 else three.append(0)] for x in input().split()]\r\n\r\none.append(less.pop())\r\n\r\nif len(less)%2:\r\n three.append(less.pop())\r\n\r\ntwo.extend(less)\r\ntwo.extend(great)\r\n\r\nprint(len(one), end = '')\r\nfor i in one:\r\n print('', i, end='')\r\nprint()\r\n\r\nprint(len(two), end = '')\r\nfor i in two:\r\n print('', i, end='')\r\nprint()\r\n\r\nprint(len(three), end = '')\r\nfor i in three:\r\n print('', i, end='')\r\nprint()", "N=int(input())\r\narr=list(map(int,input().split()))\r\na=[arr[i] for i in range(len(arr)) if(arr[i]<0)]\r\nb=[arr[i] for i in range(len(arr)) if(arr[i]>0)]\r\nc=[0 for i in range(len(arr)) if(arr[i]==0)]\r\n\r\nif(len(b)==0):\r\n b.append(a[len(a)-1])\r\n b.append(a[len(a)-2])\r\n a.pop()\r\n a.pop()\r\nif(len(a)%2==0):\r\n c.append(a[len(a)-1])\r\n a.pop()\r\nprint(len(a),*a)\r\nprint(len(b),*b)\r\nprint(len(c),*c)", "n=int(input())\r\nn=[]\r\np=[]\r\nz=[]\r\nfor x in input().split(\" \"):\r\n a=int(x)\r\n if a<0:\r\n n.append(a)\r\n elif a==0:\r\n z.append(a)\r\n else:\r\n p.append(a)\r\nprint(f\"1 {n[0]}\")\r\nif len(p)==0:\r\n p.append(n[1])\r\n p.append(n[2])\r\n for x in range(3,len(n)):\r\n z.append(n[x])\r\nelse :\r\n for x in range(1,len(n)):\r\n z.append(n[x])\r\nprint(len(p),end=\" \")\r\nfor x in p:\r\n print(x, end=\" \")\r\nprint(\"\")\r\nprint(len(z),end=\" \")\r\nfor x in z:\r\n print(x, end=\" \")\r\n", "\"\"\"\"\"\nNhư vậy cách sắp xếp là:\n+ Cho hết tất cả số 0 vào set 3 ngay lập tức\n\n+ Nếu có chẵn n số âm:\n1. nếu số số âm = 2:\nxếp 1 số vào set 1, 1 số vào set 3, xếp tiếp số dương\n2. nếu số số âm >=4:\nxếp 1 số vào set 1\nxếp 2 số vào set 2\nxếp số âm, dương còn lại vào set 3\n\n+ nếu lẻ số âm:\n1. nếu số số âm = 1:\nxếp số đó vào set 1\nxếp các số dương vào set 2, return\n2. nếu số số âm >= 3:\nxếp 1 số vào set 1\nxếp 2 số vào set 2\nxếp số âm, dương còn lại vào set 3\n\"\"\"\nn = int(input())\narr = list(map(int, input().split()))\nnegative = []\npositive = []\nzero = []\nfor i in range(len(arr)):\n if arr[i] < 0:\n negative.append(arr[i])\n elif arr[i] > 0:\n positive.append(arr[i])\n else:\n zero.append(arr[i])\n\nsetNeg = []\nsetPos = []\nif len(negative) == 1:\n setNeg.append(negative[0])\n for nums in positive:\n setPos.append(nums)\nelif len(negative) == 2:\n setNeg.append(negative[0])\n zero.append(negative[1])\n for nums in positive:\n setPos.append(nums)\nelif len(negative) >= 3:\n setNeg.append(negative[0])\n setPos.append(negative[1])\n setPos.append(negative[2])\n remainNeg = negative[3:]\n for nums in remainNeg:\n zero.append(nums)\n for nums in positive:\n setPos.append(nums)\n\ndef printResult(setNums):\n print(len(setNums), end=\" \")\n for num in setNums:\n print(num, end=\" \")\n print()\n\nprintResult(setNeg)\nprintResult(setPos)\nprintResult(zero)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "n = int (input())\nlst =list (map(int , input().split()))\nneg =[]\npos =[]\nzer =[]\nfor i in range (len(lst)) :\n if lst[i] > 0:\n pos.append( lst[i])\n elif lst[i]< 0:\n neg.append(lst[i])\n else:\n zer.append(lst[i])\nif len(pos) ==0 :\n pos.append(neg.pop())\n pos.append(neg.pop())\nif len(neg) % 2==0:\n zer.append(neg.pop())\nprint(len(neg),*neg)\nprint(len(pos),*pos)\nprint(len(zer),*zer)\n#################\n \t\t\t \t\t\t \t\t\t \t\t \t\t \t \t \t\t \t\t \t", "def main():\n n = int(input()) \n lista = [int(x) for x in input().split()]\n neg,pos,zero = [],[],[]\n for elem in lista:\n if elem == 0:\n zero.append(elem)\n elif elem < 0:\n neg.append(elem)\n else:\n pos.append(elem)\n if len(neg) % 2 == 0:\n zero.append(neg[-1])\n neg.pop()\n if pos == []:\n pos += neg[-2:]\n neg.pop()\n neg.pop()\n\n print(len(neg),end=\" \")\n for elem in neg[:-1]:\n print(elem,end=\" \")\n print(neg[-1])\n\n print(len(pos),end=\" \")\n for elem in pos[:-1]:\n print(elem,end=\" \")\n print(pos[-1])\n\n print(len(zero),end=\" \")\n for elem in zero[:-1]:\n print(elem,end=\" \")\n print(zero[-1])\n\n\nmain()\n\n\"\"\"\n\n\n\"\"\"", "def divide_array(n, array):\r\n first, second, third = [], [], []\r\n\r\n for a in array:\r\n if a == 0:\r\n third.append(a)\r\n if a > 0:\r\n second.append(a)\r\n if a < 0:\r\n first.append(a)\r\n\r\n if len(second) == 0:\r\n for b in range(2):\r\n second.append(first.pop())\r\n\r\n if len(first) % 2 == 0:\r\n third.append(first.pop())\r\n\r\n print(len(first), *first)\r\n print(len(second), *second)\r\n print(len(third), *third)\r\n\r\n\r\n\r\nn = int(input())\r\narray = list(map(int, input().split()))\r\n\r\n\r\ndivide_array(n, array)\r\n\r\n \r\n \r\n \r\n\r\n \r\n ", "\r\n\r\nn=int(input());arr=list(map(int,input().rstrip().split()))\r\narr3=[];arr1=[];arr2=[];d=0\r\nfor e in range(n):\r\n if arr[e]==0:arr3.append(arr[e])\r\n elif arr[e]<0:arr2.append(arr[e])\r\n else :arr1.append(arr[e])\r\n\r\nprint(1, arr2[0]);arr2.pop(0);\r\n\r\n\r\n\r\n\r\nif len(arr2)%2==0:\r\n print(len(arr1)+len(arr2),*arr2,*arr1,sep=\" \" )\r\nelse:\r\n d=arr2[0];arr2.pop(0)\r\n print(len(arr1)+len(arr2),*arr2,*arr1,sep=\" \" )\r\n\r\n\r\nif d!=0:\r\n print(len(arr3)+1,d,*arr3, sep =\" \")\r\nelse:\r\n print(len(arr3),*arr3, sep =\" \")\r\n", "n = int(input())\nx = list(map(int, input().split()))\npos, neg, zeros = [], [], 0\nfor item in x:\n if item > 0:\n pos.append(item)\n elif item < 0:\n neg.append(item)\n else:\n zeros += 1\nprint(1, neg[0])\nif pos:\n print(len(pos), *pos)\nelse:\n print(2, neg[1], neg[2])\n del neg[1]\n del neg[1]\nthird = []\nif len(neg) > 1:\n third = neg[1:].copy() + zeros * [0]\nelse:\n third = zeros * [0]\nprint(len(third), *third)\n", "n=int(input())\nlst=list(map(int,input().split()))\npos,neg,zer=[],[],[]\nfor el in lst:\n if el<0:\n neg.append(el)\n elif el>0:\n pos.append(el)\n else:\n zer.append(el)\nif len(pos)==0:\n pos.append((neg.pop()))\n pos.append((neg.pop()))\nif len(neg)% 2==0:\n zer.append(neg.pop())\nprint(len(neg),*neg)\nprint(len(pos),*pos)\nprint(len(zer),*zer)\n\n\n\n\n\n\t\t\t \t \t\t\t\t \t\t\t\t\t \t \t \t \t \t", "def printLst(L):\r\n print(str(len(L)) + ' ' + \" \".join(str(y) for y in L))\r\n\r\nm = int(input())\r\nlst = list(map(int, input().split()))\r\nnegNdx = []\r\nfor i, x in enumerate(lst):\r\n if x < 0:\r\n negNdx.append(i)\r\n if len(negNdx) == 3: break\r\nneg = [lst[negNdx[0]]]\r\nif len(negNdx) == 3:\r\n pos = [lst[j] for j in negNdx[1:]]\r\n zro = [x for i, x in enumerate(lst) if i not in negNdx]\r\nelse:\r\n posNdx = next(i for i, x in enumerate(lst) if x > 0)\r\n pos = [lst[posNdx]]\r\n zro = [x for i, x in enumerate(lst) if i not in [negNdx[0], posNdx]]\r\n\r\nprintLst(neg)\r\nprintLst(pos)\r\nprintLst(zro)", "import math\r\nfrom collections import defaultdict, Counter, deque\r\n\r\nINF = float('inf')\r\n\r\ndef gcd(a, b):\r\n\twhile b:\r\n\t\ta, b = b, a%b\r\n\treturn a\r\n\r\ndef isPrime(n):\r\n\tif (n <= 1): \r\n\t\treturn False\r\n\ti = 2\r\n\twhile i ** 2 <= n:\r\n\t\tif n % i == 0:\r\n\t\t\treturn False\r\n\t\ti += 1\r\n\treturn True\r\n\r\ndef primeFactor(n):\r\n\tif n % 2 == 0:\r\n\t\treturn 2\r\n\ti = 3\r\n\twhile (i ** 2) <= n:\r\n\t\tif n % i == 0:\r\n\t\t\treturn i \r\n\t\ti += 1\r\n\treturn n\r\n\r\ndef vars():\r\n\treturn map(int, input().split())\r\n\r\ndef array():\r\n\treturn list(map(int, input().split()))\r\n\r\ndef main():\r\n\tm = int(input())\r\n\tarr = array()\r\n\r\n\tn = []\r\n\to = []\r\n\tp = []\r\n\r\n\tfor i in range(m):\r\n\t\tif arr[i] < 0:\r\n\t\t\tn.append(arr[i])\r\n\t\telif arr[i] == 0:\r\n\t\t\to.append(arr[i])\r\n\t\telse:\r\n\t\t\tp.append(arr[i])\r\n\r\n\r\n\tif len(p) == 0 and len(n) > 2:\r\n\t\tp.append(n[0])\r\n\t\tn.pop(0)\r\n\t\tp.append(n[0])\r\n\t\tn.pop(0)\r\n\telif len(p) == 0 and len(o) > 1:\r\n\t\tp.append(o[0])\r\n\t\to.pop(0)\r\n\r\n\tif len(n) % 2 == 0:\r\n\t\to.append(n[-1])\r\n\t\tn.pop(-1)\r\n\r\n\r\n\tprint(len(n), *n)\r\n\tprint(len(p), *p)\r\n\tprint(len(o), *o)\r\n\r\n\t\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\t# t = int(input())\r\n\tt = 1\r\n\tfor _ in range(t):\r\n\t\tmain()\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nneg = []\r\npos = []\r\nzero = [0]\r\nfor i in range(len(a)):\r\n if a[i] < 0: neg.append(a[i])\r\n elif a[i] > 0: pos.append(a[i])\r\nprint(\"1 \" + str(neg[0]))\r\nif len(neg[1:]) % 2 == 0:\r\n pos += neg[1:]\r\nelse:\r\n pos += neg[1 : len(neg) - 1] \r\n zero.append(neg[-1])\r\nprint(str(len(pos)) + \" \" + \" \".join(map(str, pos)))\r\nprint(str(len(zero)) + \" \" + \" \".join(map(str, zero)))\r\n", "n = int(input())\narr = list(map(int, input().split()))\n\nneg,pos = 0,0\n\nfor i in arr:\n if i<0 :\n neg += 1\n elif i>0:\n pos += 1\n\narr = sorted(arr)\nprint(\"1\", arr[0])\nif pos==0:\n print(\"2\", arr[1], arr[2])\nelse :\n print(\"1\", arr[-1])\nif pos==0:\n print(n-3, end=\" \")\n for i in arr[3:]:\n print(i, end=\" \")\nelse:\n print(n-2, end=\" \")\n for i in arr[1:-1]:\n print(i, end=\" \")\n", "#!/usr/bin/env/python\r\n# -*- coding: utf-8 -*-\r\nm = int(input())\r\nn = list(map(int, input().split()))\r\n\r\ns = [[], [], []]\r\nfor c in n:\r\n if c == 0:\r\n s[0].append(0)\r\n elif c > 0:\r\n s[1].append(c)\r\n else:\r\n s[2].append(c)\r\nif not s[1]:\r\n s[1] += s[2][:2]\r\n del s[2][:2]\r\nif not len(s[2]) & 1:\r\n s[0].append(s[2][-1])\r\n del s[2][-1]\r\nfor i in range(2, -1, -1):\r\n print(len(s[i]), end=' ')\r\n for c in s[i]:\r\n print(c, end=' ')\r\n print()\r\n\r\n\r\n\r\n\r\n", "n=int(input())\r\na=[int(x) for x in input().split()];b=[];c=[];d=[0]\r\nfor i in a:\r\n if i<0:\r\n b.append(i)\r\n if i>0:\r\n c.append(i)\r\nif len(b)%2==0:\r\n d.append(b.pop(0))\r\nif len(c)==0:\r\n c.append(b.pop(0));c.append(b.pop(0))\r\nprint(len(b),\" \".join([str(x) for x in b]))\r\nprint(len(c),\" \".join([str(x) for x in c]))\r\nprint(len(d),\" \".join([str(x) for x in d]))\r\n", "n = int(input())\r\n\r\nl = list(map(int,input().split()))\r\n\r\na = {1:[],-1:[],0:[]}\r\n\r\nfor i in l:\r\n if i<0:\r\n a[-1].append(i)\r\n elif i==0:\r\n a[0].append(i)\r\n elif i>=1:\r\n a[1].append(i)\r\n\r\nif len(a[-1])%2==0:\r\n a[0].append(a[-1].pop())\r\nif len(a[1])==0:\r\n t = a[-1].pop()\r\n a[1]=a[1]+a[-1]\r\n a[-1]=[t]\r\n\r\nprint(len(a[-1]),' '.join(list(map(str,a[-1]))))\r\nprint(len(a[1]),' '.join(list(map(str,a[1]))))\r\nprint(len(a[0]),' '.join(list(map(str,a[0]))))", "n=int(input())\r\nlist1=[None]*n\r\nlist1=list(map(int,input().split()))\r\nlist1.sort()\r\nlist2=list1[:list1.index(0)]\r\nlist3=list1[list1.index(0)+1:]\r\nlist4=list1[:list1.index(0)-1]\r\n\r\nif list1[-1]!=0:\r\n if len(list2) % 2 != 0:\r\n\r\n print(len(list2),end=\" \")\r\n print(*list2)\r\n\r\n print(len(list3),end=\" \")\r\n print(*list3)\r\n print(\"1\", end=\" \")\r\n print(\"0\")\r\n else:\r\n print(len(list4), end=\" \")\r\n print(*list4)\r\n\r\n print(len(list3), end=\" \")\r\n print(*list3)\r\n\r\n print(\"2\", end=\" \")\r\n print(list1[list1.index(0) - 1], end=\" \")\r\n print(\"0\")\r\nelse:\r\n if len(list2)%2!=0:\r\n list7=list1[:list1.index(0)-2]\r\n print(len(list7),end=\" \")\r\n print(*list7)\r\n list6 = list1[list1.index(0) - 2:list1.index(0)]\r\n print(len(list6), end=\" \")\r\n print(*list6)\r\n print(\"1\",end=\" \")\r\n print(0)\r\n else:\r\n list8=list1[:list1.index(0)-3]\r\n print(len(list8),end=\" \")\r\n print(*list8)\r\n\r\n list9=list1[list1.index(0)-3:list1.index(0)-1]\r\n print(len(list9),end=\" \")\r\n print(*list9)\r\n print(\"2\",end=\" \")\r\n print(list1[list1.index(0)-1],end=\" \")\r\n print(\"0\")\r\n\r\n", "input()\r\nz = sorted(map(int, input().split()))\r\nn = [z.pop(0)] #A List of one negative number \r\n\r\np = (z[-1] > 0 and [z.pop()]) or ([z.pop(0), z.pop(0)]) # We need either one positve element or two negative elements , btw \"C\" is the list of positive numbers\r\n\r\n\r\nfor i in n,p,z:\r\n print(len(i), *i)", "\r\n\r\n\r\nn = int(input())\r\n\r\n\r\nt = list(map(int,input().split()))\r\n\r\n\r\n\r\na=[]\r\n\r\nb=[]\r\nc=[]\r\n\r\nfor k in t:\r\n if k<0:\r\n a.append(k)\r\n elif k>0:\r\n b.append(k)\r\n else:\r\n c.append(k)\r\n\r\n\r\n\r\n\r\nprint(1,a[0])\r\na.remove(a[0])\r\n\r\nif len(b)>0:\r\n print(len(b),*b)\r\nelse:\r\n if len(a)>=2:\r\n print(2,*a[:2])\r\n a.remove(a[0])\r\n a.remove(a[0])\r\n\r\n\r\nprint(len(a)+len(c),*(a+c))\r\n\r\n", "n = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\nneg,a2 = [],\"\"\r\n\r\nfor item in arr:\r\n \r\n if item < 0:\r\n \r\n neg.append(item)\r\n \r\n elif item > 0:\r\n \r\n a2 = a2 + str(item) + \" \"\r\n \r\na3,v = \"\",len(neg)\r\n \r\nif v % 2 == 0:\r\n \r\n print(1,neg[0])\r\n \r\n a3 = \"2 0 \" + str(neg[1])\r\n \r\n for i in range(2,v):\r\n \r\n a2 = a2 + str(neg[i]) + \" \"\r\n \r\n print(n-3,a2)\r\n \r\n print(a3)\r\n \r\nelse:\r\n \r\n print(1,neg[0])\r\n \r\n for i in range(1,v):\r\n \r\n a2 = a2 + str(neg[i]) + \" \"\r\n \r\n print(n-2,a2)\r\n \r\n print(1,0)", "n = int(input())\nl1 = list(map(int,input().split()))\n\nl1.sort()\nif l1[-1]!=0:\n print(\"1\"+\" \"+str(l1[0]))\n print(\"1\"+\" \"+str(l1[-1]))\n l1.pop(0)\n l1.pop(-1)\n print(str(len(l1))+\" \",*l1)\nelse:\n print(\"1\"+\" \"+str(l1[0]))\n print(\"2\"+\" \",*l1[1:3])\n print(str(len(l1)-3)+\" \",*l1[3:])\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nneg=0\r\np=[]\r\npos=0\r\nfor i in range (n):\r\n if(l[i]<0):\r\n neg=l[i]\r\n n_index=i\r\n elif(l[i]>0):\r\n pos=l[i]\r\n p_index=i\r\n\r\nif(neg<0):\r\n l.pop(n_index)\r\n print(1,neg)\r\nif(pos>0):\r\n if(p_index<n_index):\r\n l.pop(p_index)\r\n else:\r\n l.pop(p_index-1)\r\n print(1,pos)\r\n print(n-2,*l)\r\nelse:\r\n p=[]\r\n p1=0\r\n i1=[]\r\n for i in range (n-1):\r\n if(l[i]<0 and p1<2):\r\n p.append(l[i])\r\n i1.append(i)\r\n print(2,p[0],p[1])\r\n l.pop(i1[0])\r\n l.pop(i1[1]-1)\r\n print(n-3,*l)", "t = int(input())\r\na = list(map(int , input().split()))\r\n\r\npos = []\r\nneg = []\r\nz = []\r\n\r\nfor el in a : \r\n if(el > 0):\r\n pos.append(str(el))\r\n elif(el == 0):\r\n z.append(str(el))\r\n else:\r\n neg.append(str(el))\r\n \r\nif(len(neg) % 2 == 0):\r\n z.append(neg[0])\r\n del neg[0]\r\n\r\nif(len(pos) == 0):\r\n pos.append(neg[0])\r\n pos.append(neg[1])\r\n del neg[0]\r\n del neg[0]\r\ns1 = ''\r\ns2 = ''\r\ns3 = ''\r\ns1 = ' '.join(pos)\r\ns2 = ' '.join(neg)\r\ns3 = ' '.join(z)\r\nprint(str(len(neg)) + ' ' + s2)\r\nprint(str(len(pos)) + ' ' + s1)\r\nprint(str(len(z)) + ' ' + s3)", "n = int(input())\na = list(map(int, input().split()))\nlsta = []\nlstb = []\nlstc = []\nfor i in a:\n if i < 0:\n lsta.append(i)\n elif i > 0:\n lstb.append(i)\n else :\n lstc.append(i)\n# print(lsta, lstb, lstc)\nif len(lsta)%2 == 0:\n p = lsta.pop(0)\n lstc.append(p)\nif lstb == []:\n lstb += lsta[:2]\n lsta = lsta[2:]\nprint(len(lsta), *lsta)\nprint(len(lstb), *lstb)\nprint(len(lstc), *lstc)", "n=int(input())\r\nlist=[int(i) for i in input().split()]\r\nneg,pos,zero=0,0,0\r\nposarr,zeroarr=[],[]\r\nfor i in range(n):\r\n if(list[i]==0):\r\n zero+=1\r\n elif(list[i]<0):\r\n neg+=1\r\n elif(list[i]>0):\r\n pos+=1\r\nif(zero+neg==n):\r\n flag,j=True,0\r\n for i in range(n):\r\n if(list[i]<0 and flag):\r\n negarr=list[i]\r\n flag=False\r\n elif(list[i]<0 and j<2):\r\n posarr.append(list[i])\r\n j+=1\r\n else:\r\n zeroarr.append(list[i])\r\n print(1,negarr)\r\n print(2,posarr[0],posarr[1])\r\n print(n-3,end=\" \")\r\n for i in range(n-3):\r\n print(zeroarr[i],end=\" \")\r\nelse:\r\n flag1,flag2,zeroarr=True,True,[]\r\n for i in range(n):\r\n if(list[i]<0 and flag1):\r\n negarr=list[i]\r\n flag1=False\r\n elif(list[i]>0 and flag2):\r\n posarr.append(list[i])\r\n flag2=False\r\n else:\r\n zeroarr.append(list[i])\r\n print(1,negarr)\r\n print(1,posarr[0])\r\n print(n-2,end=\" \")\r\n for i in range(n-2):\r\n print(zeroarr[i],end=\" \")", "n = int(input())\n\nnums = [int(i) for i in input().split()]\n\nneg = [i for i in nums if i < 0]\npos = [i for i in nums if i > 0]\nzero = [i for i in nums if i == 0]\n\nif len(pos) == 0:\n pos = neg[-2:]\n neg = neg[:-2]\n\nif len(neg)%2 == 0:\n zero.append(neg[-1])\n neg = neg[:-1]\n\nprint(len(neg), *neg)\nprint(len(pos), *pos)\nprint(len(zero), *zero)\n", "n=int(input())\r\nneg,pos,z = [],[],0\r\nfor i in map(int, input().split()):\r\n if i<0:\r\n neg.append(i)\r\n elif i>0:\r\n pos.append(i)\r\n else:\r\n z+=1\r\nprint(1,neg.pop(0))\r\nif pos:\r\n print(1, pos.pop(0))\r\n print(n-2, *(pos+neg+[0]*z))\r\nelse:\r\n print(2, neg.pop(0), neg.pop(0))\r\n print(n-3, *(pos+neg+[0]*z))", "n = int(input())\nnumbers = sorted(map(int, input().split()))\nprint(1, numbers[0])\nif numbers[-1] > 0:\n print(1, numbers[-1])\n print(n - 2, *numbers[1:-1])\nelse:\n print(2, numbers[1], numbers[2])\n print(n - 3, *numbers[3:])\n\t \t\t \t \t\t \t\t\t\t \t \t \t\t \t\t", "def extract_negative(a):\n neg = next(ai for ai in a if ai < 0)\n a.remove(neg)\n return neg\n\n\nn = int(input())\na = list(map(int, input().split()))\na.remove(0)\nneg1 = extract_negative(a)\nprint(1, neg1)\nif sum(ai < 0 for ai in a) & 1:\n neg2 = extract_negative(a)\n print(n - 3, *a)\n print(2, 0, neg2)\nelse:\n print(n - 2, *a)\n print(1, 0)\n", "n=int(input())\r\nA=list(map(int,input().split()))\r\nA.sort()\r\nl1=[]\r\nl2=[]\r\nl3=[]\r\nfor x in A:\r\n if x<0:\r\n l1.append(x)\r\n elif x>0:\r\n l2.append(x)\r\n else:\r\n l3.append(x)\r\nif len(l1)%2==0:\r\n x=l1.pop()\r\n l3.append(x)\r\nif len(l2)==0:\r\n x=l1.pop()\r\n y=l1.pop()\r\n l2.append(x)\r\n l2.append(y)\r\nprint(len(l1),end=\" \")\r\nprint(*(i for i in l1))\r\nprint(len(l2),end=\" \")\r\nprint(*(i for i in l2))\r\nprint(len(l3),end=\" \")\r\nprint(*(i for i in l3))\r\n", "\n\n\nnbNumbers=int(input())\nnumbers = list(map(int, input().split(\" \")))\nsets = [[], [], []]\none, two = False, False\nif max(numbers)>0:\n positive = True\nelse:\n positive = False\n\n\nfor nb in numbers:\n if not one and nb<0:\n sets[0].append(nb)\n one = True\n elif not two and nb>0:\n sets[1].append(nb)\n two = True\n elif not two and not positive and nb<0:\n sets[1].append(nb)\n if len(sets[1])==2:\n two = True\n else:\n sets[2].append(nb)\n\nfor i in range(3):\n print(str(len(sets[i])) + \" \" + \" \".join([str(j) for j in sets[i]]))\n\n \t\t\t \t \t\t \t \t \t\t\t", "n = int(input())\r\nnums = [int(e) for e in input().split()]\r\n\r\nres1 = []\r\nres2 = []\r\nres3 = []\r\nfor num in nums:\r\n if num < 0:\r\n res1.append(str(num))\r\n elif num > 0:\r\n res2.append(str(num))\r\n else:\r\n res3.append(str(num))\r\n\r\nif len(res1) % 2 == 0:\r\n x = res1.pop()\r\n res3.append(x)\r\nif len(res2) == 0:\r\n x, y = res1.pop(), res1.pop()\r\n res2.append(x)\r\n res2.append(y)\r\n\r\nprint(f\"{len(res1)} {' '.join(res1)}\")\r\nprint(f\"{len(res2)} {' '.join(res2)}\")\r\nprint(f\"{len(res3)} {' '.join(res3)}\")\r\n\r\n", "def divide_array():\r\n n = int(input())\r\n array = list(map(int, input().split()))\r\n array.sort()\r\n if array[-1] > 0:\r\n negative_set = [array[0]]\r\n positive_set = [array[-1]]\r\n zero_set = array[1:-1]\r\n else:\r\n negative_set = [array[0]]\r\n positive_set = array[1:3]\r\n zero_set = array[3:]\r\n print(len(negative_set), *negative_set)\r\n print(len(positive_set), *positive_set)\r\n print(len(zero_set), *zero_set)\r\nif __name__ == \"__main__\":\r\n divide_array()\r\n", "import math\r\n#s = input()\r\n#n= (map(int, input().split()))\r\n\r\n#(map(int, input().split()))\r\n\r\nn = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nmy_list_one = list()\r\nmy_list_two = list()\r\nmy_list_three = list()\r\n\r\nfor i in a:\r\n if(i<0):\r\n if(len(my_list_one)==0):\r\n my_list_one.append(i)\r\n else:\r\n my_list_three.append(i)\r\n elif i == 0:\r\n my_list_three.append(i)\r\n else:\r\n my_list_two.append(i)\r\n\r\n\r\nif(len(my_list_two)==0):\r\n j = 0\r\n k = 0\r\n while(k<len(my_list_three)):\r\n if(my_list_three[k]<0):\r\n my_list_two.append(my_list_three[k])\r\n del my_list_three[k]\r\n j += 1\r\n k -= 1\r\n if(j==2):\r\n break\r\n k += 1\r\n\r\n\r\nprint(len(my_list_one), end=\" \")\r\nfor i in my_list_one:\r\n print(i, end=\" \")\r\nprint()\r\n\r\nprint(len(my_list_two), end=\" \")\r\nfor i in my_list_two:\r\n print(i, end=\" \")\r\nprint()\r\n\r\nprint(len(my_list_three), end=\" \")\r\nfor i in my_list_three:\r\n print(i, end=\" \")\r\nprint()\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "l = input(); arr = list(map(int, input().split()))\nnegs = [n for n in arr if n < 0]\npos = [n for n in arr if n > 0]\nzeros = [n for n in arr if n == 0]\n\nif len(pos) == 0:\n pos.extend([negs.pop(), negs.pop()])\n \nif len(negs) % 2 == 0:\n zeros.append(negs.pop())\n \nfor sign_arr in [negs, pos, zeros]:\n print(len(sign_arr), ' '.join(list(map(str, sign_arr))))\n\t\t \t \t \t \t\t \t \t\t \t\t \t \t\t \t", "#* Tóm tắt đề:\r\n# Một mảng n phần tử, 3<= n <= 100.\r\n# Chia mảng thành 3 mảng con:\r\n# - Mảng 1: Tích các phần tử < 0. -3\r\n# - Mảng 2: Tích các phần tử > 0. -2 -5\r\n# - Mảng 3: Tích các phần tử = 0. 0\r\n\r\n\r\n# Nhận xét:\r\n# - 2 số âm nhân lại -> số dương.\r\n# - Mảng 3 ít nhất phải có 1 số 0.\r\n\r\n# Xây dựng:\r\n# Mảng 1: -> Số phẩn tử âm của mảng 1 phải là số lẻ.\r\n# Mảng 2: Chứa sao cũng được :> Miễn là > 0. [Rỗng -> đem 2 số âm xuống]\r\n# Mảng 3: Đưa hết tất cả số 0 vào mảng 3. <-- -2*0 = 0\r\n# Không được có mảng nào rỗng.\r\n\r\n\r\n# 1. Đọc vào mảng nums.\r\nn = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\n\r\n# 2. Xây dựng mảng:\r\nneg_arr = []\r\nn_neg = 0\r\npos_arr = []\r\nn_pos = 0\r\nzeros_arr = []\r\nn_zeros = 0\r\n\r\nfor i in range(n):\r\n # - Đẩy hết số âm vào neg_arr.\r\n if (nums[i] < 0):\r\n neg_arr.append(nums[i])\r\n n_neg += 1\r\n # - Đẩy hết số dương vào pos_arr.\r\n if (nums[i] > 0):\r\n pos_arr.append(nums[i])\r\n n_pos += 1\r\n # - Đẩy hết số 0 vào zeros_arr.\r\n if (nums[i] == 0):\r\n zeros_arr.append(nums[i])\r\n n_zeros += 1\r\n\r\n# 3. Kiểm tra ràng buộc:\r\n# - Nếu mảng 1 chẵn -> Đem 1 phần tử xuống mảng 3.\r\n# -> Lẻ\r\nif n_neg % 2 == 0:\r\n zeros_arr.append(neg_arr[n_neg - 1])\r\n n_neg -= 1\r\n n_zeros += 1\r\n\r\n# - Nếu mảng 2 bị rỗng -> đem 2 phần tử của mảng 1 xuống.\r\nif n_pos == 0:\r\n pos_arr.append(neg_arr[n_neg - 1])\r\n n_neg -= 1\r\n pos_arr.append(neg_arr[n_neg - 1])\r\n n_neg -= 1\r\n n_pos += 2\r\n\r\n# In kq\r\nprint(n_neg, end = \" \")\r\nfor i in range(n_neg):\r\n print(neg_arr[i],end = \" \")\r\nprint()\r\nprint(n_pos, end=\" \")\r\nfor i in range(n_pos):\r\n print(pos_arr[i], end=\" \")\r\nprint()\r\n\r\nprint(n_zeros, end=\" \")\r\nfor i in range(n_zeros):\r\n print(zeros_arr[i], end=\" \")\r\nprint()\r\n\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nl1=[]\r\nl2=[]\r\nl3=[]\r\nfor i in range(len(l)):\r\n if l[i]<0:\r\n l1.append(l[i])\r\n elif l[i]==0:\r\n l2.append(l[i])\r\n else:\r\n l3.append(l[i])\r\n\r\nif len(l1)%2==0:\r\n l2.append(l1[0])\r\n l1=l1[1:]\r\n\r\nif len(l3)==0:\r\n l3.append(l1[0])\r\n l1=l1[1:]\r\n l3.append(l1[0])\r\n l1=l1[1:]\r\n\r\nl1.insert(0,len(l1))\r\nl2.insert(0,len(l2))\r\nl3.insert(0,len(l3))\r\n\r\nfor i in l1:\r\n print(i,end=' ')\r\nprint()\r\nfor i in l3:\r\n print(i,end=' ')\r\nprint()\r\nfor i in l2:\r\n print(i,end=' ')\r\n \r\n", "n = str(input())\narr = str(input())\ndef vitalyarray(n, arr):\n l = [int(x) for x in arr.split()]\n #print(l)\n l.remove(0)\n l.sort()\n array1 = [] #product needs to be negative\n array2 = [] #product needs to be positive\n array3 = [0] #product needs to be zero\n counter = 0\n for i in l: #find number of negative elements in the initial array.\n if i < 0:\n counter += 1\n if (counter % 2): \n array1.append(l[0])\n l.pop(0)\n array2 += l\n else:\n array1.append(l[0])\n array3.append(l[1])\n l.pop(1)\n l.pop(0)\n array2 += l \n def printarray(arr):\n print(str(len(arr))+' ',end='')\n for i in arr:\n print(str(i) + ' ', end='')\n print()\n printarray(array1)\n printarray(array2)\n printarray(array3)\nvitalyarray(n, arr)\n\t \t\t \t \t\t\t\t\t\t \t\t \t \t\t\t", "n = int(input())\ns = input()\n\nl = [int(i) for i in s.split()]\n\nif max(l) > 0:\n print(1, min(l))\n print(1, max(l))\n \n del l[l.index(min(l))]\n del l[l.index(max(l))]\n \n print(n - 2, ' '.join([str(i) for i in l]))\nelse:\n print(1, min(l))\n del l[l.index(min(l))]\n \n t = min(l)\n del l[l.index(min(l))]\n print(2, t, min(l))\n del l[l.index(min(l))]\n \n print(n - 3, ' '.join([str(i) for i in l]))\n \t \t\t \t\t\t \t\t\t \t\t \t \t\t", "n=int(input())\r\na=input()\r\nb=a.split(\" \")\r\nab=list()\r\nfor i in b:\r\n c=int(i)\r\n ab.append(c)\r\nac=list()\r\nad=list()\r\nd=list()\r\nfor i in ab:\r\n if (i<0):\r\n ac.append(i)\r\n elif (i>0):\r\n ad.append(i)\r\n elif (i==0):\r\n d.append(i)\r\nif (len(ac)%2==0):\r\n s=ac[0]\r\n d.append(s)\r\n ac.pop(0)\r\nif (len(ad)==0):\r\n e=ac[0]\r\n w=ac[1]\r\n ad.append(e)\r\n ad.append(w)\r\n ac.remove(e)\r\n ac.remove(w)\r\nprint(len(ac),end=\" \")\r\nfor i in ac:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(ad),end=\" \")\r\nfor i in ad:\r\n print(i,end=\" \")\r\nprint()\r\nprint(len(d),end=\" \")\r\nfor i in d:\r\n print(i)", "n = int(input())\r\na = list(map(int,input().split()))\r\nneg, pos = 0,0\r\nans = []\r\nfor i in a:\r\n if i > 0 and pos == 0:\r\n pos = i\r\n elif i < 0 and neg == 0:\r\n neg = i\r\n else:\r\n ans.append(i)\r\nprint(1,neg)\r\nif pos > 0:\r\n print(1,pos)\r\n print(n-2,*ans)\r\nelse:\r\n print(2,*[val for val in ans if val < 0][:2])\r\n cnt = 2\r\n print(n-3, end=' ')\r\n for i in ans:\r\n if i < 0:\r\n if cnt > 0:\r\n cnt -= 1\r\n continue\r\n print(i, end = \" \")", "n =int(input())\r\npos ,neg, zero = [] ,[] ,[]\r\nflag_pos , flag_neg = True , True\r\nl = list(map(int , input().split()))\r\nfor i in l : \r\n if i > 0 and flag_pos : \r\n pos.append(i)\r\n flag_pos = False\r\n elif i < 0 and flag_neg :\r\n neg.append(i)\r\n flag_neg =False\r\n else: \r\n zero.append(i) \r\nif pos == []:\r\n i = 0\r\n j = len(zero) -1 \r\n while j > -1 and i < 2: \r\n if zero[::][j] <0 :\r\n pos.append(zero[j])\r\n zero.pop(j)\r\n i+= 1\r\n j -= 1\r\n pos = pos[:2]\r\n if len(pos) != 2 :\r\n pos = []\r\nprint(len(neg) , *neg)\r\nprint(len(pos) , *pos)\r\nprint(len(zero) , *zero)", "k=int(input())\r\nl=list(map(int,input().rstrip().split()))\r\nn=0\r\np=0\r\nz=0\r\nN=[]\r\nP=[]\r\nZ=[]\r\na=1\r\nfor i in range(k):\r\n if l[i]<0:\r\n n=n+1\r\n elif l[i]>0:\r\n p=p+1\r\n else:\r\n z=z+1\r\nif p==0:\r\n if n%2==0:\r\n for i in range(k):\r\n if l[i]<0 and a==1:\r\n Z.append(l[i])\r\n a=a+1\r\n elif l[i]<0 and 1<a<=3:\r\n P.append(l[i])\r\n a=a+1\r\n elif l[i]<0 and a>3:\r\n N.append(l[i])\r\n a=a+1\r\n else:\r\n Z.append(l[i])\r\n else:\r\n for i in range(k):\r\n if l[i]<0 and 1<=a<=2:\r\n P.append(l[i])\r\n a=a+1\r\n elif l[i]<0 and a>2:\r\n N.append(l[i])\r\n a=a+1\r\n else:\r\n Z.append(l[i])\r\nelse:\r\n if n%2==0:\r\n for i in range(k):\r\n if l[i]<0 and a==1:\r\n Z.append(l[i])\r\n a=a+1\r\n elif l[i]<0 and a>1:\r\n N.append(l[i])\r\n a=a+1\r\n elif l[i]==0:\r\n Z.append(l[i])\r\n else:\r\n P.append(l[i])\r\n else:\r\n for i in range(k):\r\n if l[i]<0:\r\n N.append(l[i])\r\n elif l[i]==0:\r\n Z.append(l[i])\r\n else:\r\n P.append(l[i])\r\n\r\nprint(len(N),end=\" \")\r\nfor i in range(len(N)):\r\n if i!=len(N)-1:\r\n print(N[i],end=\" \")\r\n else:\r\n print(N[i])\r\nprint(len(P),end=\" \")\r\nfor i in range(len(P)):\r\n if i!=len(P)-1:\r\n print(P[i],end=\" \")\r\n else:\r\n print(P[i])\r\nprint(len(Z),end=\" \")\r\nfor i in range(len(Z)):\r\n if i!=len(Z)-1:\r\n print(Z[i],end=\" \")\r\n else:\r\n print(Z[i])\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "oas = int(input())\ner = list(map(int, input().split()))\npositive, negative, zero = [], [], []\nfor k in er:\n if k<0:\n negative.append(k)\n elif k>0:\n positive.append(k)\n else:\n zero.append(k)\nif len(positive)==0:\n positive.append(negative.pop())\n positive.append(negative.pop())\nif len(negative) % 2 == 0:\n zero.append(negative.pop())\nprint(len(negative), *negative)\nprint(len(positive), *positive)\nprint(len(zero), *zero)\n\t\t\t\t \t \t\t \t \t \t\t\t \t\t", "n=int(input())\r\na=list(map(int,input().split()))\r\nm=0 \r\np=0\r\nb=[]\r\nc=[]\r\nfor i in a:\r\n if i<0:\r\n b.append(i)\r\n m+=1 \r\n elif i>0:\r\n c.append(i)\r\n p+=1\r\nz=n-m-p\r\nprint(1,b[0])\r\nif p==0:\r\n print(2,b[1],b[2])\r\n print(m-3+z,*b[3:],\"0 \"*z)\r\nelse:\r\n print(p,*c)\r\n print(m-1+z,*b[1:],\"0 \"*z)", "n = int(input())\r\nlist_of_numbers = list(map(int,input().split()))\r\nprint(1, end=\" \")\r\nprint(min(list_of_numbers))\r\nlist_of_numbers.remove(min(list_of_numbers))\r\ncount_negatives = 0\r\nfor i in range (len(list_of_numbers)):\r\n if list_of_numbers[i] < 0:\r\n count_negatives += 1\r\nif (count_negatives) % 2 == 0:\r\n list_of_numbers.remove(0)\r\n print(len(list_of_numbers), end=\" \")\r\n print(*list_of_numbers)\r\n print(1, end=\" \")\r\n print (0)\r\nelse:\r\n second_min = min(list_of_numbers)\r\n list_of_numbers.remove(second_min)\r\n list_of_numbers.remove(0)\r\n print(len(list_of_numbers), end=\" \")\r\n print(*list_of_numbers)\r\n print (2, end=\" \")\r\n print(second_min, end=\" \")\r\n print(0)", "import math\r\ndef main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n set1, set2, set3 = list(), list(), list()\r\n flag = 0\r\n\r\n cnt = 0\r\n for i in range(n):\r\n if a[i] > 0:\r\n cnt += 1\r\n if cnt > 0:\r\n for i in range(n):\r\n if a[i] == 0:\r\n set3.append(a[i])\r\n elif a[i] > 0:\r\n set2.append(a[i])\r\n elif a[i] < 0 and flag:\r\n set3.append(a[i])\r\n elif a[i] < 0 and not flag:\r\n flag = 1\r\n set1.append(a[i])\r\n else:\r\n count = 0\r\n for i in range(n):\r\n if a[i] == 0:\r\n set3.append(a[i])\r\n elif a[i] > 0:\r\n set2.append(a[i])\r\n elif a[i] < 0 and count < 1:\r\n set1.append(a[i])\r\n count += 1\r\n elif a[i] < 0 and 1 <= count < 3:\r\n set2.append(a[i])\r\n count += 1\r\n elif a[i] < 0 and count >= 3:\r\n set3.append(a[i])\r\n print(len(set1), end=' ')\r\n print(*set1)\r\n print(len(set2), end=' ')\r\n print(*set2)\r\n print(len(set3), end=' ')\r\n print(*set3)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\nli = [int(x) for x in input().split()]\nli.sort()\nx = 0\nfor i in range(n):\n if li[i]==0:\n x=i\nneg = li[:x]\nnul = [li[x]]\npos=[]\nif len(li[x+1:])>0:\n pos=li[x+1:]\nif len(pos)==0:\n pos.append(neg[-2])\n pos.append(neg[-1])\n neg=neg[:len(neg)-2]\n if len(neg)%2==0:\n nul.append(neg[-1])\n neg=neg[:len(neg)-1]\nif len(pos)>0 and len(neg)%2==0:\n nul.append(neg[-1])\n neg=neg[:len(neg)-1]\nne = str(len(neg))+\" \"\npo = str(len(pos))+\" \"\nnu = str(len(nul))+\" \"\nneg.sort()\npos.sort()\nnul.sort()\nfor i in range(len(neg)-1):\n ne+=str(neg[i])+\" \"\nne+=str(neg[-1])\nfor i in range(len(pos)-1):\n po+=str(pos[i])+\" \"\npo+=str(pos[-1])\nfor i in range(len(nul)-1):\n nu+=str(nul[i])+\" \"\nnu+=str(nul[-1])\nprint(ne)\nprint(po)\nprint(nu)\n\t \t\t \t\t \t\t\t\t \t \t\t\t \t", "t=int(input())\r\na=list(map(int,input().split()))\r\nn=0\r\np=0\r\nz=0\r\nfinal=[[] for i in range(3)]\r\nfor i in a:\r\n if i<0:\r\n n+=1\r\n elif i>0:\r\n p+=1\r\n else:\r\n z+=1\r\nif p!=0:\r\n if n%2==0:\r\n n-=1\r\n z+=1\r\n co=0\r\n for i in a:\r\n if i<0:\r\n if co>=n:\r\n final[2].append(i)\r\n else:\r\n final[0].append(i)\r\n co+=1\r\n elif i>0:\r\n final[1].append(i)\r\n else:\r\n final[2].append(i)\r\n \r\nelse:\r\n if n%2==0:\r\n p+=2\r\n n-=3\r\n z+=1\r\n req=2\r\n fr=0\r\n co=0\r\n for i in a:\r\n if i<0:\r\n if co>=n:\r\n if fr>=req:\r\n final[2].append(i)\r\n else:\r\n final[1].append(i)\r\n fr+=1\r\n else:\r\n final[0].append(i)\r\n co+=1\r\n elif i>0:\r\n final[1].append(i)\r\n else:\r\n final[2].append(i)\r\n else:\r\n p+=2\r\n n-=2\r\n co=0\r\n for i in a:\r\n if i<0:\r\n if co>=n:\r\n final[1].append(i)\r\n else:\r\n final[0].append(i)\r\n co+=1\r\n elif i>0:\r\n final[1].append(i)\r\n else:\r\n final[2].append(i)\r\nfor i in range(len(final)):\r\n if i==0:\r\n print(n,end=\" \")\r\n print(*final[i],sep=\" \")\r\n elif i==1:\r\n print(p,end=\" \")\r\n print(*final[i],sep=\" \")\r\n else:\r\n print(z,end=\" \")\r\n print(*final[i],sep=\" \")\r\n \r\n", "n=int(input())\r\na=list(map(int,input().strip().split()))\r\nc=0\r\np=[]\r\nq=[]\r\nr=[]\r\nl=[]\r\nfor i in range(n):\r\n if a[i]<0:\r\n c+=1\r\n l.append(i)\r\n elif a[i]>0:\r\n r.append(a[i])\r\n else:p.append(a[i])\r\nif c%2==0:\r\n p.append(a[l[0]])\r\n q.append(a[l[1]])\r\n if len(l)>2:\r\n for x in l[2:]:\r\n r.append(a[x])\r\nelse:\r\n q.append(a[l[0]])\r\n if len(l)>1:\r\n for x in l[1:]:\r\n r.append(a[x])\r\nprint(len(q),end=' ')\r\nprint(*q)\r\nprint(len(r),end=' ')\r\nprint(*r)\r\nprint(len(p),end=' ')\r\nprint(*p)", "n = int(input())\r\narr = [int(i) for i in input().split()]\r\n\r\narr.sort()\r\n\r\n\r\ns1 = []\r\ns2 = []\r\ns3 = []\r\n\r\ns1.append(arr.pop(0))\r\n\r\nif arr[-1] == 0 :\r\n s2.append(arr.pop(0))\r\n\r\n s2.append(arr.pop(0))\r\nelse :\r\n s2.append(arr.pop())\r\n\r\ns3 = arr \r\n\r\nprint(len(s1), *s1)\r\nprint(len(s2), *s2)\r\nprint(len(s3), *s3)\r\n\r\n\r\n\r\n\"\"\"\r\nThe product of all numbers in the first set is less than zero (<0).\r\nThe product of all numbers in the second set is greater than zero ( > 0).\r\nThe product of all numbers in the third set is equal to zero.\r\n\"\"\"", "n = input()\r\na = list(map(int,input().split()))\r\n\r\na1=[]\r\na2=[]\r\na3=[]\r\na.sort()\r\nfor i in a:\r\n if(i<0):\r\n a1.append(i)\r\n break\r\na.remove(i)\r\n#print(a)\r\na.reverse()\r\na3.append(0)\r\na.remove(0)\r\nmul = a[0]\r\n\r\na2.append(a[0])\r\na.remove(a[0])\r\n#print(a)\r\ni=0\r\nwhile(mul<0):\r\n \r\n mul = mul*a[i]\r\n a2.append(a[i])\r\n a.remove(a[i])\r\n\r\n#print(a)\r\nfor i in a:\r\n a3.append(i)\r\n \r\nprint(1, end=' ')\r\nfor i in a1:\r\n print(i, end=' ')\r\n\r\nprint()\r\nprint(len(a2), end=' ')\r\nfor i in a2:\r\n print(i, end=' ')\r\nprint()\r\nprint(len(a3), end=' ')\r\nfor i in a3:\r\n print(i, end=' ')\r\nprint()", "n = int(input())\narr = [int(x) for x in input().split()]\nlist1 = []\nlist2 = []\nlist3 = []\nlist1_num_neg = 0\nlist2_num_neg = 0\nfor i in range(len(arr)):\n\tif(arr[i] == 0):\n\t\tlist3.append(arr[i])\n\telif(arr[i] < 0):\n\t\tif(list1_num_neg % 2 == 0):\n\t\t\tlist1.append(arr[i])\n\t\t\tlist1_num_neg += 1\n\t\telif(list2_num_neg % 2 == 1):\n\t\t\tlist2.append(arr[i])\n\t\t\tlist2_num_neg += 1\n\t\telse:\n\t\t\t# if(len(list2) == 0):\n\t\t\t# \tlist2.append()\n\t\t\tlist3.append(arr[i])\n\telse:\n\t\tlist2.append(arr[i])\n\nif(len(list2) == 0):\n\ti = 0\n\tnum_removed = 0\n\twhile(i < len(list3)):\n\t\tif(list3[i] < 0):\n\t\t\tlist2.append(list3[i])\n\t\t\tlist3.remove(list3[i])\n\t\t\ti -= 1\n\t\t\tnum_removed += 1\n\t\tif(num_removed == 2):\n\t\t\tbreak\n\t\ti += 1\n\n\nstr1 = \"%d \" * (len(list1)+1)\nstr2 = \"%d \" * (len(list2)+1)\nstr3 = \"%d \" * (len(list3)+1)\nprint(str1%(len(list1), *list1))\nprint(str2%(len(list2), *list2))\nprint(str3%(len(list3), *list3))", "\"\"\"\r\nproblem : https://codeforces.com/problemset/problem/300/A\r\nauther : Jay Saha\r\nhandel : ponder_\r\ndate : 15/07/2020\r\n\"\"\"\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nf, s, t = [], [], []\r\nfor elm in arr:\r\n if elm < 0:\r\n f.append(elm)\r\n elif elm > 0:\r\n s.append(elm)\r\n else:\r\n t.append(elm)\r\n\r\nif len(f) % 2 == 0:\r\n t.append(f.pop())\r\nif len(s) == 0:\r\n s.append(f.pop())\r\n s.append(f.pop())\r\n\r\ndef printArray(a):\r\n print(len(a), end = \" \")\r\n for elm in a:\r\n print(elm, end=\" \")\r\n print()\r\n\r\nprintArray(f)\r\nprintArray(s)\r\nprintArray(t)", "n = int(input())\r\n\r\nlst = list(map(int, input().split()))\r\n\r\nneg=[]\r\npos=[]\r\nzeros=[]\r\n\r\nfor i in range(n):\r\n if lst[i] < 0:\r\n neg.append(lst[i])\r\n elif lst[i] > 0:\r\n pos.append(lst[i])\r\n elif lst[i] == 0:\r\n zeros.append(lst[i])\r\n\r\nif len(pos) == 0:\r\n pos.append(neg.pop())\r\n pos.append(neg.pop())\r\nif len(neg)%2 == 0:\r\n zeros.append(neg.pop())\r\nprint(len(neg),\" \".join(map(str, neg)))\r\nprint(len(pos),\" \".join(map(str, pos)))\r\nprint(len(zeros),\" \".join(map(str, zeros)))", "n=int(input())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nl1=[]\r\nl2=[]\r\nl3=[]\r\nfor x in l:\r\n\tif x<0:\r\n\t\tl1.append(x)\r\n\telif x>0:\r\n\t\tl2.append(x)\r\n\telse:\r\n\t\tl3.append(x)\r\nif len(l1)%2==0:\r\n\tz=l1.pop()\r\n\tl3.append(z)\r\nif len(l2)==0:\r\n\tx=l1.pop()\r\n\ty=l1.pop()\r\n\tl2.append(x)\r\n\tl2.append(y)\r\nprint(len(l1),end=\" \")\r\nprint(*(i for i in l1))\r\nprint(len(l2),end=\" \")\r\nprint(*(i for i in l2))\r\nprint(len(l3),end=\" \")\r\nprint(*(i for i in l3))\r\n", "import sys\nimport bisect\nimport heapq\nimport math\nfrom functools import lru_cache\nfrom collections import defaultdict,Counter\n\n\n#sys.setrecursionlimit(10**6)\ninput = sys.stdin.readline\nI = lambda: int(input())\nS = lambda: input()\nL = lambda: list(map(int, input().split()))\n###################################################\n\n\n\n\ndef solution(n, arr):\n neg = []\n pos = []\n zero = []\n arr.sort()\n if arr[-1]==0:\n pos+=[arr[0], arr[1]]\n if len(arr)%2==0:\n neg+=arr[2:-1]\n zero += [arr[-1]]\n else:\n neg+=arr[2:-2]\n zero += arr[-2:]\n else:\n number_of_neg = 0\n for i in arr:\n if i<0:\n number_of_neg+=1\n if number_of_neg%2!=0:\n neg+=arr[:number_of_neg]\n zero+=[arr[number_of_neg]]\n pos+=arr[number_of_neg+1:]\n else:\n neg+=arr[:number_of_neg-1]\n zero+=arr[number_of_neg-1:number_of_neg+1]\n pos+=arr[number_of_neg+1:]\n \n print(len(neg), *neg)\n print(len(pos), *pos)\n print(len(zero), *zero)\n\n\n\nif __name__=='__main__':\n n = I()\n arr = L()\n solution(n, arr)", "n = int(input())\r\narr = list(map(int, input().split()))\r\nneg = []\r\npos = []\r\nzer = []\r\n\r\nfor i in arr:\r\n if i == 0:\r\n zer.append(i)\r\n if i < 0:\r\n neg.append(i)\r\n if i > 0:\r\n pos.append(i)\r\n\r\n\r\nif len(pos) == 0:\r\n for i in range(0, 2):\r\n pos.append(neg[-1])\r\n neg.pop(-1)\r\n\r\nif len(neg) % 2 == 0:\r\n zer.append(neg[-1])\r\n neg.pop(-1)\r\n\r\nprint(len(neg), end=\" \")\r\nfor i in range(len(neg)):\r\n if i == len(neg) - 1:\r\n print(neg[i])\r\n else:\r\n print(neg[i], end=\" \")\r\n\r\nprint(len(pos), end=\" \")\r\nfor i in range(len(pos)):\r\n if i == len(pos) - 1:\r\n print(pos[i])\r\n else:\r\n print(pos[i], end=\" \")\r\n\r\nprint(len(zer), end=\" \")\r\nfor i in range(len(zer)):\r\n if i == len(zer) - 1:\r\n print(zer[i])\r\n else:\r\n print(zer[i], end=\" \")\r\n", "import math\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nl1 = []\r\nl2 = []\r\nl3 = []\r\n\r\nfor i in a:\r\n if i < 0:\r\n l1.append(i)\r\n if i > 0:\r\n l2.append(i)\r\n if i == 0:\r\n l3.append(i)\r\n\r\nif len(l1) % 2 == 0:\r\n l3.append(l1.pop())\r\nif len(l2) == 0:\r\n if len(l1) > 2:\r\n l2.append(l1.pop())\r\n l2.append(l1.pop())\r\n elif len(l1) == 1 and len(l3) > 2:\r\n l2.append(l3.pop())\r\n l2.append(l3.pop())\r\n\r\n\r\nprint(len(l1), *l1)\r\nprint(len(l2), *l2)\r\nprint(len(l3), *l3)", "\n# from collections import deque\n\nn = int(input())\nlst = list(map(int, input().split()))\nlst.sort()\nneg, pos, zero = [], [], []\nneg.append(lst[0])\ni = 1\nwhile i < n:\n if lst[i] < 0 and lst[i + 1] < 0:\n pos.append(lst[i])\n pos.append(lst[i + 1])\n i += 1\n elif lst[i] <= 0:\n zero.append(lst[i])\n else:\n pos.append(lst[i])\n i += 1\n\nprint(len(neg), end=' ')\nprint(*neg)\nprint(len(pos), end=' ')\nprint(*pos)\nprint(len(zero), end=' ')\nprint(*zero)\n\n \t\t \t\t\t \t \t\t \t\t \t \t \t\t\t\t", "n = int(input())\r\narr = list(map(int, input().split()))\r\nnum_neg, num_pos, num_zero = 0, 0, 0\r\narr1, arr2, arr3 = [], [], []\r\nfor num in arr:\r\n if num < 0:\r\n num_neg += 1\r\n elif num > 0:\r\n num_pos += 1\r\n else:\r\n num_zero += 1\r\n\r\nif num_neg & 1:\r\n neg_added = False\r\n for num in arr:\r\n if num < 0 and not neg_added:\r\n neg_added = True\r\n arr1.append(num)\r\n elif num == 0:\r\n arr3.append(num)\r\n else:\r\n arr2.append(num)\r\nelse:\r\n neg_added = False\r\n one_neg_destroyed = False\r\n for num in arr:\r\n if num < 0 and not neg_added:\r\n if not one_neg_destroyed:\r\n one_neg_destroyed = True\r\n arr3.append(num)\r\n else:\r\n arr1.append(num)\r\n neg_added = True\r\n elif num == 0:\r\n arr3.append(num)\r\n else:\r\n arr2.append(num)\r\n\r\nprint(len(arr1), *arr1)\r\nprint(len(arr2), *arr2)\r\nprint(len(arr3), *arr3)\r\n", "input()\r\ns=[int(i) for i in input().split()]\r\ns.sort()\r\ns0=[s.pop(s.index(0))]\r\nsp=[i for i in s if i>0]\r\nsm=[i for i in s if i<0]\r\nif len(sm)%2==0 and len(sm)>1: s0.append(sm.pop())\r\nif not sp:\r\n sp.append(sm.pop())\r\n sp.append(sm.pop())\r\nprint(len(sm),*sm)\r\nprint(len(sp),*sp)\r\nprint(len(s0),*s0)", "n=int(input())\r\na=list(map(int, input().split()))\r\np=[]\r\nq=[]\r\nr=[]\r\nn1=[]\r\nn2=[]\r\nn3=[]\r\nfor i in range(len(a)):\r\n if a[i]>0:\r\n p.append(a[i])\r\n elif a[i]<0:\r\n q.append(a[i])\r\n else:\r\n r.append(a[i])\r\nif len(p)==0:\r\n p.append(q[-1])\r\n q.pop(-1)\r\n p.append(q[-1])\r\n q.pop(-1)\r\nif len(q)%2==0:\r\n r.append(q[-1])\r\n q.pop(-1)\r\nq.insert(0, len(q))\r\np.insert(0, len(p))\r\nr.insert(0, len(r))\r\nprint(' '.join(map(str,q)))\r\nprint(' '.join(map(str,p)))\r\nprint(' '.join(map(str,r)))", "'''\r\n# Submitted By [email protected]\r\nDon't Copy This Code, Try To Solve It By Yourself\r\n'''\r\n# Problem Name = \"Array\"\r\n# Class: A\r\n\r\ndef Solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n l1, l2, l3 = [], [], []\r\n for i in a:\r\n if i < 0:\r\n l1.append(i)\r\n elif i > 0:\r\n l2.append(i)\r\n else:\r\n l3.append(i)\r\n \r\n if len(l2)<1:\r\n l2.extend(l1[-2:])\r\n l1=l1[:-2]\r\n\r\n if len(l1)%2==0:\r\n l3.append(l1[-1])\r\n l1=l1[:-1]\r\n \r\n print(len(l1), *l1)\r\n print(len(l2), *l2)\r\n print(len(l3), *l3)\r\n \r\n\r\n\r\nif __name__ == \"__main__\":\r\n Solve()", "\r\nt=int(input())\r\nn=list(map( int ,input().split()))[:t]\r\na=[]\r\nb=[]\r\nc=[]\r\n \r\n \r\nfor i in n:\r\n if(i==0):\r\n c.append(i)\r\n elif(i<0):\r\n a.append(i)\r\n else:\r\n b.append(i)\r\nif(len(a)%2==0):\r\n c.append(a[0])\r\n a.remove(a[0])\r\nif(len(b)==0):\r\n for i in range(2):\r\n b.append(a[0])\r\n a.remove(a[0])\r\nprint(len(a),*a)\r\nprint(len(b),*b)\r\nprint(len(c),*c)", "n=int(input());p1,p2,p3=[],[],[]\r\nfor i in list(map(int,input().split())):\r\n if i < 0:\r\n p1.append(i)\r\n if i > 0:\r\n p2.append(i)\r\n if i == 0:\r\n p3.append(i)\r\nif len(p1)%2==0:\r\n p3.append(p1.pop())\r\nif len(p2)==0:\r\n p2.append(p1.pop())\r\n p2.append(p1.pop())\r\nprint(*[len(p1)]+p1)\r\nprint(*[len(p2)]+p2)\r\nprint(*[len(p3)]+p3)", "n = int(input())\r\nlst = list(map(int,input().split()))\r\npos_lst = []\r\nneg_lst =[]\r\nz_lst =[]\r\nfor ele in lst:\r\n if ele<0:\r\n neg_lst.append(ele)\r\n elif ele>0:\r\n pos_lst.append(ele)\r\n else:\r\n z_lst.append(ele)\r\n\r\nif len(neg_lst) % 2 ==0 and len(neg_lst)>1:\r\n z_lst.append(neg_lst.pop())\r\nif len(pos_lst)==0 and len(neg_lst)>=2:\r\n pos_lst.append(neg_lst.pop())\r\n pos_lst.append(neg_lst.pop())\r\nprint(len(neg_lst),end=' ')\r\nfor ele in neg_lst:\r\n print(ele,end=' ')\r\nprint()\r\nprint(len(pos_lst),end=' ')\r\nfor ele in pos_lst:\r\n print(ele,end=' ')\r\n\r\nprint()\r\n \r\nprint(len(z_lst),end=' ')\r\nfor ele in z_lst:\r\n print(ele,end=' ') \r\n \r\n ", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nn1 = 0\r\nlist1 = []\r\n\r\nn2 = 0\r\nlist2 = []\r\n\r\nn3 = 0\r\nlist3 = []\r\n\r\nneg1 = 0\r\nneg2 = 0\r\ncount = 0\r\n\r\nfor i in range(n):\r\n\tif a[i] == 0:\r\n\t\tn3 += 1\r\n\t\tlist3.append(a[i])\r\n\telif a[i] > 0:\r\n\t\tn2 += 1\r\n\t\tlist2.append(a[i])\r\n\telse:\r\n\t\tif count == 0:\r\n\t\t\tcount += 1\r\n\t\t\tneg1 = a[i]\r\n\t\telif count == 1:\r\n\t\t\tcount += 1\r\n\t\t\tneg2 = a[i]\r\n\t\telse:\r\n\t\t\tn2 += 2\r\n\t\t\tlist2.append(neg1)\r\n\t\t\tlist2.append(neg2)\r\n\t\t\t\r\n\t\t\tcount = 1\r\n\t\t\tneg1 = a[i]\r\n\r\nif count == 1:\r\n\tn1 += 1\r\n\tlist1.append(neg1)\r\nelse:\r\n\tn1 += 1\r\n\tlist1.append(neg1)\r\n\t\t\r\n\tn3 += 1\r\n\tlist3.append(neg2)\r\n\t\r\nprint(n1, end = \" \")\r\nfor i in range(n1):\r\n\tprint(list1[i], end = \" \")\r\nprint()\r\n\r\nprint(n2, end = \" \")\r\nfor i in range(n2):\r\n\tprint(list2[i], end = \" \")\r\nprint()\r\n\r\nprint(n3, end = \" \")\r\nfor i in range(n3):\r\n\tprint(list3[i], end = \" \")", "n = int(input())\narr = list(map(int, input().split()))\nneg, pos, zero = [], [], []\nfor i in arr:\n if i == 0:\n zero.append(i)\n elif i > 0:\n pos.append(i)\n else:\n neg.append(i)\nif len(pos) == 0:\n x = neg.pop()\n y = neg.pop()\n pos.append(x)\n pos.append(y)\nif len(neg) % 2 ==0:\n z = neg.pop()\n zero.append(z)\nprint(len(neg),end = ' ')\nfor i in neg:\n print(i, end = ' ')\nprint()\nprint(len(pos), end = ' ')\nfor i in pos:\n print(i, end = ' ')\nprint()\nprint(len(zero),end = ' ')\nfor i in zero:\n print(i, end = ' ')\nprint()\n\n\n\t\t\t \t\t\t \t\t \t\t\t \t\t \t\t\t \t \t\t", "# input\r\nn = int(input())\r\nthe_list = list(map(int,input().split()))\r\n\r\nnegative_num = 0\r\nfor i in range(len(the_list)):\r\n if the_list[i] > 0:\r\n negative_num += 1\r\n\r\npositive_num = 0\r\nfor i in range(len(the_list)):\r\n if the_list[i] > 0:\r\n positive_num += 1\r\n\r\nif positive_num == 0:\r\n# array 2\r\n array_2 = []\r\n for i in range(len(the_list)):\r\n if the_list[i] != 0:\r\n array_2.append(the_list[i])\r\n if len(array_2) > 1:\r\n break\r\n \r\n array_1 = []\r\n for i in range(len(the_list)):\r\n if the_list[i] not in array_2 and the_list[i] != 0:\r\n array_1.append(the_list[i])\r\n break\r\n \r\n # array 3\r\n array_3 = []\r\n for i in range(len(the_list)):\r\n if the_list[i] not in array_1 and the_list[i] not in array_2:\r\n array_3.append(the_list[i])\r\nelse:\r\n array_1 = []\r\n for i in range(len(the_list)):\r\n if the_list[i] < 0:\r\n array_1.append(the_list[i])\r\n break\r\n \r\n array_2 = []\r\n for i in range(len(the_list)):\r\n if the_list[i] > 0:\r\n array_2.append(the_list[i])\r\n \r\n array_3 = []\r\n for i in range(len(the_list)):\r\n if the_list[i] not in array_1 and the_list[i] not in array_2:\r\n array_3.append(the_list[i])\r\n\r\n\r\n# print\r\nprint(len(array_1), end= ' ')\r\nfor i in range(len(array_1)):\r\n print(array_1[i], end= ' ')\r\n\r\nprint(len(array_2), end= ' ')\r\nfor i in range(len(array_2)):\r\n print(array_2[i], end= ' ')\r\n\r\nprint(len(array_3), end= ' ')\r\nfor i in range(len(array_3)):\r\n print(array_3[i], end= ' ')", "n=int(input())\nne=[] ; po=[] ; z=[] \na=list(map(int,input().split()))\nfor el in a:\n if el<0:\n ne.append(el)\n elif el>0:\n po.append(el)\n else: \n z.append(el)\nif len(po)==0:\n po.append(ne[-1])\n ne.pop()\n po.append(ne[-1])\n ne.pop()\nif len(ne)%2==0:\n z.append(ne[-1])\n ne.pop()\nprint(len(ne),*ne)\nprint(len(po),*po)\nprint(len(z),*z)\n \t \t\t \t\t\t\t\t\t \t\t \t \t", "def print_set(set_arr):\r\n\tprint(len(set_arr), end = ' ')\r\n\tfor i in set_arr:\r\n\t\tprint(i, end = ' ')\r\n\tprint(\"\")\r\n\t\r\n\r\nn = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nset1 = []\r\nset2 = []\r\nset3 = []\r\n\r\nfor i in a:\r\n\tif i < 0:\r\n\t\tset1.append(i)\r\n\telif i == 0:\r\n\t\tset3.append(i)\r\n\telse:\r\n\t\tset2.append(i)\r\n\r\n\r\nif len(set2) == 0:\r\n\tset2 = set1[-2:]\r\n\tset1 = set1[:-2]\r\n\t\r\nif len(set1)%2 == 0:\r\n\titem_shift = set1.pop()\r\n\tset3.append(item_shift)\r\n\r\nprint_set(set1)\r\nprint_set(set2)\r\nprint_set(set3)", "n = int(input())\r\na = list(map(int, input().split(\" \")))\r\n\r\ndef split_number(n, a):\r\n negative_array, positive_array, zero_array = [], [], []\r\n for i in range(0, n, 1):\r\n if a[i] < 0:\r\n negative_array.append(a[i])\r\n elif a[i] > 0:\r\n positive_array.append(a[i])\r\n else:\r\n zero_array.append(a[i])\r\n return negative_array, positive_array, zero_array\r\n\r\nnegative_array, positive_array, zero_array = split_number(n, a)\r\nset_1, set_2, set_3 = [], [], []\r\nset_1.append(negative_array[0])\r\ndel negative_array[0]\r\nset_2 = positive_array\r\nset_3 = zero_array\r\nif len(negative_array) % 2 !=0:\r\n set_3.append(negative_array[0])\r\n del negative_array[0]\r\n set_2+=negative_array\r\nelse:\r\n set_2+=negative_array\r\n\r\nprint(f\"{len(set_1)} {set_1}\".replace('[','').replace(']','').replace(',',''))\r\nprint(f\"{len(set_2)} {set_2}\".replace('[','').replace(']','').replace(',',''))\r\nprint(f\"{len(set_3)} {set_3}\".replace('[','').replace(']','').replace(',',''))", "n=input()\nn=int(n)\n\nlist=list(map(int,input().split()))\n\npos=[]\nneg=[]\nzero=[]\nfor i in list:\n if i>0:\n pos.append(i)\n elif i<0:\n neg.append(i)\n else:\n zero.append(i)\n\nif len(neg)%2==0:\n num=neg.pop()\n zero.append(num)\n\nif len(pos)==0:\n num = neg.pop()\n pos.append(num)\n num = neg.pop()\n pos.append(num)\n\nprint(len(neg),*neg)\nprint(len(pos),*pos)\nprint(len(zero),*zero)\n\n\n\n \t\t \t \t \t \t\t \t\t\t", "n=int(input())\r\narr=list(map(int,input().split()))\r\npos=[]\r\nneg=[]\r\nzero=[]\r\nfor item in arr:\r\n if item==0:\r\n zero.append(item)\r\n continue\r\n if item>0:\r\n pos.append(item)\r\n continue\r\n else:\r\n neg.append(item)\r\nif len(pos)==0:\r\n if len(neg)%2==1:\r\n print (len(neg)-2,end=\" \")\r\n for i in range(2,len(neg)):\r\n print (neg[i],end=\" \")\r\n print (\" \")\r\n if len(neg)>2:\r\n print (2,end=\" \")\r\n print (neg[0],end=\" \")\r\n print (neg[1])\r\n print (len(zero),end=\" \")\r\n for item in zero:\r\n print (item,end=\" \")\r\n print (\" \")\r\n else:\r\n print (len(neg)-3,end=\" \")\r\n for i in range(3,len(neg)):\r\n print (neg[i],end=\" \")\r\n print (\" \")\r\n if len(neg)>2:\r\n print (2,end=\" \")\r\n print (neg[0],end=\" \")\r\n print (neg[1])\r\n print (len(zero)+1,end=\" \")\r\n print (neg[2],end=\" \")\r\n for item in zero:\r\n print (item,end=\" \")\r\n print (\" \")\r\nelse:\r\n if len(neg)%2==1:\r\n print (len(neg),end=\" \")\r\n for item in neg:\r\n print (item,end=\" \")\r\n print (\" \")\r\n print (len(pos),end=\" \")\r\n for it in pos:\r\n print (it,end=\" \")\r\n print ('')\r\n print (len(zero),end=\" \")\r\n for item in zero:\r\n print (item,end=\" \")\r\n print (\" \")\r\n else:\r\n print (len(neg)-1,end=\" \")\r\n for i in range(1,len(neg)):\r\n print (neg[i],end=\" \")\r\n print (\" \")\r\n print (len(pos),end=\" \")\r\n for it in pos:\r\n print (it,end=\" \")\r\n print ('')\r\n print (len(zero)+1,end=\" \")\r\n print (neg[0],end=\" \")\r\n for item in zero:\r\n print (item,end=' ')", "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n############ ---- Input Functions ---- ############\r\n\r\ndef Array():\r\n n = inp()\r\n orgArray = inlt()\r\n\r\n set1 = []\r\n set2 = []\r\n set3 = []\r\n\r\n num_neg = 0\r\n num_pos = 0\r\n\r\n for num in orgArray:\r\n if num < 0 :\r\n num_neg += 1\r\n elif num > 0:\r\n num_pos += 1\r\n \r\n if num_pos == 0:\r\n required_neg_in_set2 = 2\r\n else:\r\n required_neg_in_set2 = 0\r\n\r\n required_neg_in_set1 = 1 \r\n\r\n for num in orgArray:\r\n if num < 0 :\r\n if required_neg_in_set1 != 0:\r\n set1.append(num)\r\n required_neg_in_set1 -= 1\r\n\r\n elif required_neg_in_set2 != 0: \r\n set2.append(num)\r\n required_neg_in_set2 -= 1 \r\n\r\n else:\r\n set3.append(num) \r\n\r\n elif num > 0:\r\n set2.append(num)\r\n else:\r\n set3.append(num)\r\n\r\n outputStr = ''\r\n\r\n outputStr += str(len(set1)) + ' '\r\n for num in set1:\r\n outputStr += str(num) + ' '\r\n outputStr += '\\n'\r\n\r\n outputStr += str(len(set2)) + ' '\r\n for num in set2:\r\n outputStr += str(num) + ' '\r\n outputStr += '\\n'\r\n\r\n outputStr += str(len(set3)) + ' '\r\n for num in set3: \r\n outputStr += str(num) + ' ' \r\n outputStr += '\\n'\r\n\r\n outputStr = outputStr.strip()\r\n print(outputStr)\r\n return \r\n \r\nArray()", "\r\n\r\ndef main():\r\n n = int(input())\r\n arr = sorted(list(map(int,input().split())))\r\n a = []\r\n b = []\r\n c = []\r\n v = sorted([i for i in arr if i < 0])\r\n a.append(v[-1])\r\n del v[-1]\r\n ind = 0\r\n while ind <= len(v) - 1:\r\n if ind <= len(v) - 2:\r\n b.append(v[ind])\r\n b.append(v[ind + 1])\r\n ind += 2\r\n else:\r\n c.append(v[ind])\r\n ind += 1\r\n\r\n count = 0\r\n\r\n for i in arr:\r\n if i == 0:\r\n c.append(i)\r\n elif i > 0:\r\n b.append(i)\r\n print(len(a),' '.join(map(str,a)))\r\n print(len(b), ' '.join(map(str, b)))\r\n print(len(c), ' '.join(map(str, c)))\r\n\r\n\r\n\r\nmain()", "from sys import stdin; inp = stdin.readline\r\nfrom math import dist, ceil, floor, sqrt, log\r\ndef IA(): return list(map(int, inp().split()))\r\ndef FA(): return list(map(float, inp().split()))\r\ndef SA(): return inp().split()\r\ndef I(): return int(inp())\r\ndef F(): return float(inp())\r\ndef S(): return inp()\r\n\r\ndef main():\r\n n = I() # 3-100\r\n a = IA()\r\n ne = []\r\n po = []\r\n ze = []\r\n for n in a:\r\n if not ne and n < 0:\r\n ne.append(n)\r\n elif not po and n > 0:\r\n po.append(n)\r\n else:\r\n ze.append(n)\r\n if not po:\r\n ze.sort(reverse=True)\r\n for i in range(2):\r\n x = ze.pop()\r\n po.append(x)\r\n \r\n print(len(ne), *ne)\r\n print(len(po), *po)\r\n print(len(ze), *ze)\r\n \r\n\r\nif __name__ == '__main__':\r\n main()", "n = int(input())\nnums = list(map(int, input().split()))\nnums.sort()\n\nstart = 1\nif nums[-1] == 0:\n print(1, nums[0])\n print(2, nums[1], nums[2])\n print(n - 3, ' '.join(map(str, nums[3:])))\nelse:\n print(1, nums[0])\n print(1, nums[-1])\n print(n - 2, ' '.join(map(str, nums[1:-1])))\n", "s= int(input())\r\nt=input()\r\ni=t.split(\" \")\r\ninpu=[int(ko) for ko in i]\r\npos=[]\r\nneg=[]\r\nzero=[]\r\nfor q in inpu:\r\n if q==0:\r\n zero.append(q)\r\n elif(q<0):\r\n neg.append(q)\r\n else:\r\n pos.append(q)\r\n\r\nif(len(pos)==0):\r\n x=neg.pop()\r\n pos.append(x)\r\n x=neg.pop()\r\n pos.append(x)\r\nif(len(neg)%2==0):\r\n x=neg.pop()\r\n zero.append(x)\r\nans=str(len(neg))+ \" \"+\" \".join(str(n) for n in neg)\r\nprint(ans)\r\nans=str(len(pos))+ \" \"+\" \".join(str(n) for n in pos)\r\nprint(ans)\r\n\r\nans=str(len(zero))+ \" \"+\" \".join(str(n) for n in zero)\r\nprint(ans)", "list1= [] \r\nlist2= [] \r\nlist3= []\r\nn =int(input())\r\nar = [int(i) for i in input().split()]\r\nneg = [int(i) for i in ar if i<0]\r\n\r\nif len(neg)%2: \r\n list1.append(neg[0])\r\n ar.remove(neg[0])\r\n for i in ar: \r\n if i==0: \r\n list3.append(i)\r\n else:\r\n list2.append(i)\r\n \r\nif len(neg)%2==0: \r\n list1.append(neg[0])\r\n ar.remove(neg[0])\r\n neg.pop(0)\r\n for i in ar: \r\n if i==0 or (i<0 and len(neg)%2!=0 and bool(neg)): \r\n list3.append(i)\r\n if i!=0:\r\n neg.remove(i)\r\n else:\r\n list2.append(i)\r\nprint(len(list1),*list1)\r\nprint(len(list2),*list2)\r\nprint(len(list3),*list3)", "n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nlp = list()\r\nln = list()\r\nlz = list()\r\n\r\nfor i in a:\r\n if i < 0: ln.append(i)\r\n elif i > 0: lp.append(i)\r\n else: lz.append(i)\r\nif len(ln) % 2 == 0:\r\n x = ln.pop()\r\n lz.append(x)\r\nif len(lp) == 0:\r\n lp.extend(ln[0:2])\r\n del ln[0:2]\r\n\r\nprint(len(ln),end=\" \")\r\nprint(*ln)\r\nprint(len(lp),end=\" \")\r\nprint(*lp)\r\nprint(len(lz),end=\" \")\r\nprint(*lz)\r\n ", "\nn = int(input())\nlist = list(map(int, input().split()))\npositive, negative, zero = [], [], []\nfor ele in list:\n if ele > 0:\n positive.append(ele)\n elif ele < 0:\n negative.append(ele)\n else:\n zero.append(ele)\nif len(negative) % 2 == 0:\n zero.append(negative[-1])\n negative.pop()\nif len(positive) == 0:\n positive.append(negative[-1])\n negative.pop()\n positive.append(negative[-1])\n negative.pop()\nprint(len(negative), *negative)\nprint(len(positive), *positive)\nprint(len(zero), *zero)\n \t \t\t \t \t \t\t\t\t \t \t\t \t", "n=int(input())\narr=[int(i) for i in input().split()]\narr.sort()\nprint(1,arr[0])\nif arr[-1] > 0:\n print(1,arr[-1])\n print(n-2,*arr[1:-1])\nelse :\n print(2,arr[1],arr[2])\n print(n-3,*arr[3:])\n \t\t \t\t\t \t\t \t \t \t \t\t\t", "n = int(input())\nv = list(map(int, input().split()))\n\npos, neg, z = [[], [], []]\nfor el in v:\n if el < 0:\n neg.append(el)\n elif el > 0:\n pos.append(el)\n else:\n z.append(el)\n\n\nif pos == []:\n pos.append(neg[0])\n neg.pop(0)\n pos.append(neg[0])\n neg.pop(0)\n\nif len(neg) % 2 == 0:\n z.append(neg[0])\n neg.pop(0)\n\nprint(len(neg), end=\" \")\nprint(*neg)\nprint(len(pos), end=\" \")\nprint(*pos)\nprint(len(z), end=\" \")\nprint(*z)\n", "n = input()\r\n# arr = [int(x) for x in input().split()]\r\narr = [int(x) for x in input().split()]\r\nneg = []\r\npos = []\r\nzero = []\r\nfor i in arr:\r\n if i<0:\r\n neg.append(i)\r\n if i>0:\r\n pos.append(i)\r\n if i==0:\r\n zero.append(i)\r\n\r\nif len(pos)==0:\r\n for i in range(2):\r\n pos.append(neg[-1])\r\n neg.pop()\r\nif len(neg)%2==0:\r\n zero.append(neg[-1])\r\n neg.pop()\r\nprint(len(neg),end = \" \")\r\nfor i in neg:\r\n print(i, end = \" \")\r\nprint()\r\n\r\nprint(len(pos),end = \" \")\r\nfor i in pos:\r\n print(i, end = \" \")\r\nprint()\r\n\r\nprint(len(zero),end = \" \")\r\nfor i in zero:\r\n print(i, end=\" \")", "n = int(input())\nlista = [int(x) for x in input().split()]\nneg, pos, zero = [], [], []\nfor elem in lista:\n if elem == 0:\n zero.append(elem)\n elif elem < 0:\n neg.append(elem)\n else:\n pos.append(elem)\nif len(neg) % 2 == 0:\n zero.append(neg[-1])\n neg.pop()\nif pos == []:\n pos += neg[-2:]\n neg.pop()\n neg.pop()\n\nprint(len(neg), end=\" \")\nprint(*neg)\nprint(len(pos), end=\" \")\nprint(*pos)\nprint(len(zero), end=\" \")\nprint(*zero)\n\t \t\t \t\t \t\t\t \t \t\t \t\t \t \t\t", "n=int(input())\r\nl=list(map(int,input().split()))\r\nlp,ln,lz=[],[],[]\r\nfor i in l:\r\n if i==0:\r\n lz.append(i)\r\n elif i<0:\r\n ln.append(i)\r\n else:\r\n lp.append(i)\r\nif len(lp)>=1:\r\n print(1,ln[0])\r\n print(1,lp[0])\r\n print(n-2,end=\" \")\r\n l=ln[1:]+lp[1:]+lz\r\n for i in l:\r\n print(i,end=\" \")\r\nelse:\r\n print(1,ln[0])\r\n print(2,ln[1],ln[2])\r\n print(n-3,end=\" \")\r\n l=ln[3:]+lz\r\n for i in l:\r\n print(i,end=\" \")", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = []\r\nc = []\r\nd = []\r\ncount = 0\r\nfor i in range(n):\r\n if(a[i] < 0):\r\n b.append(a[i])\r\n elif(a[i] > 0):\r\n c.append(a[i])\r\n else:\r\n d.append(a[i])\r\nj=len(b)\r\nk=len(c)\r\nm=len(d)\r\nif(j % 2 == 0):\r\n d.append(b[j - 1])\r\n b.remove(b[j - 1])\r\nj=len(b)\r\nk=len(c)\r\nm=len(d)\r\nif(k == 0):\r\n c.append(b[j - 1])\r\n b.remove(b[j - 1])\r\n c.append(b[j - 2])\r\n b.remove(b[j - 2])\r\nj=len(b)\r\nk=len(c)\r\nm=len(d)\r\nprint(j,end=\" \")\r\nfor i1 in range(j):\r\n if(i1 == j - 1):\r\n print(b[i1])\r\n else:\r\n print(b[i1],end=\" \")\r\nprint(k,end=\" \")\r\nfor i2 in range(k):\r\n if(i2 == k - 1):\r\n print(c[i2])\r\n else:\r\n print(c[i2],end=\" \")\r\nprint(m,end=\" \")\r\nfor i3 in range(m):\r\n if(i3 == m - 1):\r\n print(d[i3])\r\n else:\r\n print(d[i3],end=\" \")", "n = int(input())\r\n\r\narr = [int(x) for x in input().split()]\r\n\r\nzero = []\r\nzero.append(0)\r\npos = []\r\nneg = []\r\n\r\nfor i in arr:\r\n\tif i < 0:\r\n\t\tneg.append(i)\r\n\telif i > 0:\r\n\t\tpos.append(i)\r\n\r\n\r\nif len(neg)%2 == 0:\r\n\tzero.append(neg.pop())\r\n\r\n\r\nif len(pos) == 0:\r\n\tpos.append(neg.pop())\r\n\tpos.append(neg.pop())\r\n\r\n\r\nprint(len(neg),*neg)\r\nprint(len(pos),*pos)\r\nprint(len(zero),*zero)", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nneg = list(filter(lambda x: x<0, a))\r\npos = list(filter(lambda x: x>0, a))\r\nzero = list(filter(lambda x: x == 0, a))\r\nif(len(pos) == 0):\r\n pos.append(neg[0])\r\n neg.pop(0)\r\n pos.append(neg[0])\r\n neg.pop(0)\r\nif(len(neg)%2 == 0):\r\n zero.append(neg[0])\r\n neg.pop(0)\r\nprint(len(neg), end = \" \")\r\nfor i in neg:\r\n print(i, end = \" \")\r\nprint()\r\nprint(len(pos), end = \" \")\r\nfor i in pos:\r\n print(i, end = \" \")\r\nprint()\r\nprint(len(zero), end = \" \")\r\nfor i in zero:\r\n print(i, end = \" \")\r\nprint()", "n = int(input())\narr = list(map(int, input().split()))\n\nneg = []\npos = []\nzero = []\ngen = []\nfor i in arr:\n if i < 0:\n neg.append(i)\n if i > 0:\n pos.append(i)\n if i == 0:\n zero.append(i)\n\ngen.append(neg)\ngen.append(pos)\ngen.append(zero)\n\n\nif len(neg) % 2 == 0:\n zero.append(neg.pop())\nif len(pos) == 0:\n pos.append(neg.pop())\n pos.append(neg.pop())\n\n\nfor i in gen:\n print(len(i), *i)\n \t\t\t \t \t \t\t \t \t\t\t \t\t\t \t \t\t \t", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\na = set()\r\nb = set()\r\nc = set()\r\nfor i in w:\r\n if i < 0:\r\n a.add(i)\r\n elif i > 0:\r\n b.add(i)\r\n else:\r\n c.add(i)\r\nif len(b) == 0:\r\n b.add(a.pop())\r\n b.add(a.pop())\r\nif not len(a) & 1:\r\n c.add(a.pop())\r\nfor i in [a,b,c]:\r\n print(len(i), ' '.join(map(str, i)))", "n = int(input())\r\narr = list(map(int , input().split()))\r\nneg = [i for i in arr if i<0]\r\nzero = [0]*arr.count(0)\r\npos = [i for i in arr if i>0]\r\nif len(pos)==0:\r\n pos.append(neg[0])\r\n pos.append(neg[1])\r\n neg.remove(neg[0])\r\n neg.remove(neg[0])\r\nif len(neg)%2==0:\r\n zero.append(neg[0])\r\n neg.remove(neg[0])\r\nprint(len(neg) , *neg)\r\nprint(len(pos) , *pos)\r\nprint(len(zero), *zero)", "n=int(input())\r\nlist1=list(map(int,input().split()))\r\nl1=[]\r\nl2=[]\r\nl3=[]\r\nfor i in range(n):\r\n if(list1[i]>0):\r\n l2.append(list1[i])\r\n elif(list1[i]==0):\r\n l3.append(list1[i])\r\n else:\r\n l1.append(list1[i])\r\nif(len(l2)==0):\r\n l2.append(l1.pop())\r\n l2.append(l1.pop())\r\nif(len(l1)%2==0):\r\n l3.append(l1.pop())\r\nprint(len(l1),*l1)\r\nprint(len(l2),*l2)\r\nprint(len(l3),*l3)\r\n", "n=int(input())\r\na=[int(i) for i in input().split()]\r\ncount=0\r\na.sort()\r\nans1=[]\r\nans2=[]\r\nans3=[]\r\ncountp=0\r\nfor i in range(0,n):\r\n if a[i]<0:\r\n count+=1\r\n elif a[i]>0:\r\n countp+=1\r\nj=0\r\nfor i in range(0,n):\r\n if i==0:\r\n ans1.append(a[i])\r\n elif countp==0 and j<2:\r\n j+=1\r\n ans2.append(a[i])\r\n elif len(ans2)==0 and a[i]>0:\r\n ans2.append(a[i])\r\n else:\r\n ans3.append(a[i])\r\nprint(len(ans1),*ans1)\r\nprint(len(ans2),*ans2)\r\nprint(len(ans3),*ans3)", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = []\r\nc = []\r\nd = []\r\n\r\nfor x in a:\r\n if x < 0: b.append(x)\r\n elif x > 0: c.append(x)\r\n else: d.append(x)\r\n\r\nif len(c) == 0:\r\n c.append(b[-1])\r\n b.pop()\r\n c.append(b[-1])\r\n b.pop()\r\n\r\nif len(b) % 2 == 0:\r\n d.append(b[-1])\r\n b.pop()\r\n\r\nprint(len(b), end=' ')\r\nfor x in b:\r\n print(x, end=' ')\r\nprint()\r\n\r\nprint(len(c), end=' ')\r\nfor x in c:\r\n print(x, end=' ')\r\nprint()\r\n\r\nprint(len(d), end=' ')\r\nfor x in d:\r\n print(x, end=' ')\r\nprint()", "import sys \r\n\r\ninput = lambda: sys.stdin.readline().strip()\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\npos, neg, zero = [], [], []\r\n\r\nfor x in a:\r\n if x == 0: zero.append(x)\r\n elif x > 0: pos.append(x)\r\n else: neg.append(x)\r\n\r\nif not pos:\r\n pos.append(neg.pop())\r\n pos.append(neg.pop())\r\n\r\nif len(neg) & 1 == 0:\r\n zero.append(neg.pop())\r\n\r\nprint(len(neg), *neg)\r\nprint(len(pos), *pos)\r\nprint(len(zero), *zero)\r\n", "\r\nn = int(input())\r\narr = list(map(int,input().split()))\r\n\r\npositive = []\r\nnegetive = []\r\nzero = []\r\n\r\nfor x in arr:\r\n if x > 0:\r\n positive.append(x)\r\n elif x < 0:\r\n negetive.append(x)\r\n else:\r\n zero.append(x)\r\n\r\nif len(positive) == 0:\r\n positive.append(negetive[0])\r\n negetive.pop(0)\r\n positive.append(negetive[0])\r\n negetive.pop(0)\r\n\r\nif len(negetive) % 2 == 0:\r\n zero.append(negetive[0])\r\n negetive.pop(0)\r\n\r\nprint(len(negetive), end=\" \")\r\nfor x in negetive:\r\n print(x, end=\" \")\r\n\r\nprint(\"\")\r\n\r\nprint(len(positive), end=\" \")\r\nfor x in positive:\r\n print(x, end=\" \")\r\n\r\nprint(\"\")\r\n\r\nprint(len(zero), end=\" \")\r\nfor x in zero:\r\n print(x, end=\" \")\r\n\r\nprint(\"\")", "size = int(input().strip())\r\narr = list(map(int, input().strip().split()))\r\nneg = []\r\npos = []\r\nzero = []\r\nfor i in arr:\r\n if i < 0 and not len(neg):\r\n neg.append(str(i))\r\n elif i == 0 or i < 0:\r\n zero.append(str(i))\r\n else:\r\n pos.append(str(i))\r\nif len(pos) == 0:\r\n idx = 0\r\n while len(pos) < 2:\r\n if int(zero[idx]):\r\n pos.append(zero[idx])\r\n zero.pop(idx)\r\n idx -= 1\r\n idx += 1\r\nprint(len(neg), ' '.join(neg))\r\nprint(len(pos), ' '.join(pos))\r\nprint(len(zero), ' '.join(zero))\r\n", "n = int(input())\nnums = [int(x) for x in input().split()]\n\npos_num, neg_num, zero = [], [], []\n\nfor num in nums:\n if num > 0:\n pos_num.append(num)\n elif num < 0:\n neg_num.append(num)\n else:\n zero.append(num)\nif len(pos_num) == 0:\n pos_num.append(neg_num.pop(0))\n pos_num.append(neg_num.pop(0))\nif len(neg_num) % 2 == 0:\n zero.append(neg_num.pop(0))\nprint(len(neg_num), end=' ')\nprint(*neg_num)\nprint(len(pos_num), end = ' ')\nprint(*pos_num)\nprint(len(zero), end = ' ')\nprint(*zero)", "def printer(a):\r\n print(len(a), end = ' ')\r\n for i in a:\r\n print(i, end = ' ')\r\n print()\r\n\r\nimport math\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\na0 = []\r\nap = []\r\nan = []\r\n\r\nfor i in a:\r\n if i == 0:\r\n a0.append(i)\r\n elif i > 0:\r\n ap.append(i)\r\n else:\r\n an.append(i)\r\n \r\na0 = list(set(a0))\r\nap = list(set(ap))\r\nan = list(set(an))\r\n\r\nif len(ap) == 0:\r\n ap.append(an.pop())\r\n ap.append(an.pop())\r\n \r\nif len(an) % 2 == 0:\r\n a0.append(an.pop())\r\n \r\nprinter(an)\r\nprinter(ap)\r\nprinter(a0)\r\n", "def solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n n = [i for i in a if (i < 0)]\r\n p = [i for i in a if (i > 0)]\r\n z = [i for i in a if (not i)]\r\n\r\n n1,n2, n3 = [], p, z\r\n h1, h2, r = 0, 0, 0\r\n if (len(n)%2 == 0):\r\n z.append(n.pop())\r\n \r\n h1, h2 = len(n)//2, len(n)//2+1\r\n if h1%2 == 0:\r\n h1, h2 = h2, h1\r\n \r\n while h2:\r\n h2 -= 1\r\n p.append(n.pop())\r\n\r\n\r\n print(len(n), *n)\r\n print(len(p), *p)\r\n print(len(z), *z)\r\n\r\n\r\nt = 1\r\nfor _ in range(t):\r\n solve()", "n, A = int(input()), sorted(map(int, input().split()))\r\n \r\nprint(1, A[0])\r\n \r\nif A[-1]:\r\n print(1, A[-1])\r\n print(n - 2, *A[1:-1])\r\nelse:\r\n print(2, *A[1:3])\r\n print(n - 3, *A[3:])", "n = int(input())\r\narr = sorted(map(int, input().split()))\r\nprint(1, arr[0])\r\nif arr[-1] <= 0:\r\n print(2, arr[1], arr[2])\r\n print(n-3, *arr[3:])\r\nelse:\r\n print(1, arr[-1])\r\n print(n-2, *arr[1:-1])", "n = int(input())\nnumeros = list(map(int, input().split()))\n\nneg = []\npos = []\nzero = []\n\nfor x in numeros:\n\tif x < 0:\n\t\tneg.append(x)\n\telif x > 0:\n\t\tpos.append(x)\n\telse:\n\t\tzero.append(x)\n\nif not len(neg)&1:\n\tzero.append(neg.pop())\n\nif len(pos) == 0:\n\tpos.append(neg.pop())\n\tpos.append(neg.pop())\n\nprint(len(neg), \" \".join(list(map(str, neg))))\nprint(len(pos), \" \".join(list(map(str, pos))))\nprint(len(zero), \" \".join(list(map(str, zero))))\n\t \t\t \t \t\t\t\t\t \t \t \t\t", "def pas(n):\r\n print(id(n))\r\n\r\nnegative, positive, equal = [],[],[]\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nfor num in lst:\r\n if num < 0: negative.append(num)\r\n elif num == 0: equal.append(num)\r\n else: positive.append(num)\r\n\r\nif len(positive) == 0:\r\n positive.append(negative[0])\r\n positive.append(negative[1])\r\n negative.pop(0)\r\n negative.pop(0)\r\nif not(len(negative) % 2):\r\n equal.append(negative[0])\r\n negative.pop(0)\r\n\r\nprint(len(negative), end = ' ')\r\nfor num in negative: print(num, end = ' ')\r\nprint()\r\nprint(len(positive), end = ' ')\r\nfor num in positive: print(num, end = ' ')\r\nprint()\r\nprint(len(equal), end = ' ')\r\nfor num in equal: print(num, end = ' ')\r\n", "input()\r\narr = [int(i) for i in input().split()]\r\nn, p, o = set(), set(), set()\r\n\r\nfor a in arr:\r\n if a > 0 and not p:\r\n p.add(a)\r\n elif a < 0 and not n:\r\n n.add(a)\r\n else:\r\n o.add(a)\r\n\r\nif not p:\r\n for _ in range(2):\r\n m = min(o)\r\n p.add(m)\r\n o.remove(m)\r\n\r\nprint(len(n), *n)\r\nprint(len(p), *p)\r\nprint(len(o), *o)", "def find_zero_index(array):\r\n for i in range(len(array)):\r\n if numbers[i] == 0:\r\n return i\r\n\r\nn = int(input())\r\nuser_input = input().split()\r\nnumbers = list(map(int, user_input))\r\nnumbers.sort()\r\npositive = []\r\nnegative = []\r\nzero = []\r\na = find_zero_index(numbers)\r\n\r\nif a == len(numbers) - 1 :\r\n positive = numbers[a-2:a]\r\n negative = [numbers[a-3]]\r\n zero = numbers[:a-3]\r\n zero.append(numbers[a])\r\nelse:\r\n positive = numbers[a + 1:]\r\n negative = [numbers[a-1]]\r\n zero = numbers[:a-1]\r\n zero.append(numbers[a])\r\n\r\n\r\n\r\n\r\nprint(len(negative), *negative)\r\nprint(len(positive), *positive)\r\nprint(len(zero), *zero)\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nnArr = list(filter(lambda x: x < 0, arr))\r\npArr = list(filter(lambda x: x > 0, arr))\r\nzArr = list(filter(lambda x: x == 0, arr))\r\n\r\nif len(nArr) % 2 == 0:\r\n val = nArr.pop()\r\n zArr.append(val)\r\nif len(pArr) == 0:\r\n pArr += nArr[:2]\r\n nArr = nArr[2:]\r\n\r\nprint(f\"{len(nArr)} {' '.join(map(str, nArr))}\")\r\nprint(f\"{len(pArr)} {' '.join(map(str, pArr))}\")\r\nprint(f\"{len(zArr)} {' '.join(map(str, zArr))}\")\r\n", "#A. Array\r\nn = int(input())\r\na,b,c =[],[],[]\r\nl = list(map(int,input().split()))\r\nfor i in l:\r\n if i<0:\r\n a.append(i)\r\n elif i>0:\r\n b.append(i)\r\n else:\r\n c.append(i)\r\n\r\nif len(b)==0 and len(a)>2:\r\n b.append(a.pop())\r\n b.append(a.pop()) \r\nif len(a)%2==0:\r\n c.append(a.pop()) \r\nprint(len(a),*a)\r\nprint(len(b),*b)\r\nprint(len(c),*c)", "# A. Array\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ndef product(a):\r\n p=1\r\n for i in a:\r\n p*=i\r\n return p\r\n\r\na.sort()\r\na1=[]\r\na1.append(a[0])\r\na3=[0]\r\na2=a[1:]\r\na2.remove(0)\r\nif product(a2)>0:\r\n print(1,*a1)\r\n print(n-2,*a2)\r\n print(1,*a3)\r\nelse:\r\n a3.append(a2[0])\r\n a2.pop(0)\r\n print(1,*a1)\r\n print(n-3,*a2)\r\n print(2,*a3)", "n=int(input())\r\n\r\na=list(map(int,input().split()))\r\n\r\naa=[]\r\nbb=[]\r\ncc=[]\r\n\r\nfor i in a:\r\n if i<0:\r\n aa.append(i)\r\n elif i>0:\r\n bb.append(i)\r\n else:\r\n cc.append(i)\r\nl=[]\r\ng=[]\r\nz=[]\r\n\r\nl.append(aa[0])\r\nminus=0\r\nif len(bb)==0:\r\n if (len(aa)-1)%2==0:\r\n g=aa[1:]\r\n minus=len(g)\r\n else:\r\n g=aa[1:len(aa)-1]\r\n minus=len(g)\r\nelse:\r\n g=bb\r\n\r\nif len(aa)-(1+minus)==0:\r\n z=[0]\r\nelse:\r\n z=cc+aa[(1+minus):]\r\nans=\"\"\r\nfor i in range(len(l)):\r\n if i==0:\r\n ans+=str(len(l))+\" \"\r\n ans+=str(l[i])+\" \"\r\nans+=\"\\n\"\r\nfor i in range(len(g)):\r\n if i==0:\r\n ans+=str(len(g))+\" \"\r\n ans+=str(g[i])+\" \"\r\nans+=\"\\n\"\r\nfor i in range(len(z)):\r\n if i==0:\r\n ans+=str(len(z))+\" \"\r\n ans+=str(z[i])+\" \"\r\nprint(ans)", "n = int(input())\nnegative = []\npostive = []\nzero = []\ni = input()\ni = i.split()\ni = [int(x) for x in i]\n\nfor x in i:\n if x < 0: \n negative.append(x)\n if x > 0:\n postive.append(x)\n if x == 0:\n zero.append(x)\n\nif len(postive) == 0:\n postive.append(negative[0])\n negative.pop(0)\n postive.append(negative[1])\n negative.pop(1)\nif len(negative) % 2 == 0:\n zero.append(negative[0])\n negative.pop(0)\n\nprint(len(negative), end=\" \")\nfor i in negative:\n print(i,end=\" \")\nprint(\"\")\nprint(len(postive), end=\" \")\nfor i in postive:\n print(i,end=\" \")\nprint(\"\")\nprint(len(zero), end=\" \")\nfor i in zero:\n print(i,end=\" \")\nprint(\"\")\n\n \t\t\t\t \t \t \t \t \t \t\t \t \t\t", "\nn = int(input())\nlst = list(map(int, input().split()))\nlst.sort()\n\nneg, pos, zero = [], [], []\nneg.append(lst[0])\ni = 1\nwhile i < len(lst):\n if lst[i] < 0:\n if lst[i + 1] < 0:\n pos.append(lst[i])\n pos.append(lst[i + 1])\n i += 1\n else:\n zero.append(lst[i])\n elif lst[i] > 0:\n pos.append(lst[i])\n else:\n zero.append(lst[i])\n i += 1\n\nprint(len(neg), *neg)\nprint(len(pos), *pos)\nprint(len(zero), *zero)\n\n\n \t\t\t\t \t\t \t\t \t \t\t \t\t \t\t \t \t \t", "n=int(input())\r\nall=list(map(int,input().split()))\r\npos=[]\r\nneg=[]\r\ndef pprint(x):\r\n print(len(x),end=' ')\r\n for i,j in enumerate(x):\r\n if i!=len(x)-1:\r\n print(j,end=' ')\r\n else:\r\n print(j)\r\nfor i in all[:]:\r\n if i<0:\r\n neg.append(i)\r\n all.remove(i)\r\n break\r\nfor i in all[:]:\r\n if i>0:\r\n pos.append(i)\r\n all.remove(i)\r\n break\r\nif len(pos) == 0:\r\n c=0\r\n for i in all[:]:\r\n if i<0:\r\n pos.append(i)\r\n all.remove(i)\r\n c+=1\r\n if c==2:\r\n break\r\npprint(neg)\r\npprint(pos)\r\npprint(all)\r\n", "input()\r\na = list(map(int, input().split()))\r\ns = [[], [], []]\r\nfor i in a:\r\n if i < 0:\r\n s[0] += [str(i)]\r\n elif i > 0:\r\n s[1] += [str(i)]\r\n else:\r\n s[2] += [str(i)]\r\nif len(s[1]) == 0:\r\n s[1].extend(s[0][:2])\r\n s[0] = s[0][2:]\r\nif len(s[0]) % 2 == 0:\r\n s[2].append(s[0][0])\r\n s[0] = s[0][1:]\r\nfor l in s:\r\n print(len(l), ' '.join(l))", "def divide_array(n, arr):\r\n negatives = []\r\n positives = []\r\n zeros = []\r\n\r\n for num in arr:\r\n if num < 0:\r\n negatives.append(num)\r\n elif num > 0:\r\n positives.append(num)\r\n else:\r\n zeros.append(num)\r\n\r\n if len(positives) == 0:\r\n positives.append(negatives.pop())\r\n positives.append(negatives.pop())\r\n\r\n if len(negatives) % 2 == 0:\r\n zeros.append(negatives.pop())\r\n\r\n \r\n print(len(negatives), ' '.join(map(str, negatives)))\r\n print(len(positives), ' '.join(map(str, positives)))\r\n print(len(zeros), ' '.join(map(str, zeros)))\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\n\r\ndivide_array(n, arr)\r\n", "n=int(input())\r\nl=list(map(int, input().split()))\r\nb={\"o\":0,\"p\":0,\"z\":0}\r\no=list()\r\np=list()\r\nz=list()\r\nfor i in l:\r\n if i<0:\r\n b[\"o\"]+=1\r\n o.append(i)\r\n if i>0:\r\n b[\"p\"]+=1\r\n p.append(i)\r\n if i==0:\r\n b[\"z\"]+=1\r\n z.append(i)\r\n\r\nprint(1,o[0])\r\n\r\nif len(p)>0:\r\n print(1, p[0])\r\nelse:\r\n print(2, o[1], o[2])\r\n\r\nif len(p)>0:\r\n z.extend(o[1:len(o)])\r\n z.extend(p[1:len(p)])\r\nelse:\r\n z.extend(o[3:len(o)])\r\n\r\nprint(len(z), *z)", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\npos = -1\r\nneg1 = -1\r\nneg2 = -1\r\nneg3 = -1\r\n\r\nfor i in range(len(a)):\r\n if a[i] > 0:\r\n pos = a[i]\r\n elif a[i] < 0:\r\n if neg1 == -1:\r\n neg1 = a[i]\r\n elif neg2 == -1:\r\n neg2 = a[i]\r\n else:\r\n neg3 = a[i]\r\nif pos != -1:\r\n print(1, neg1)\r\n print(1, pos)\r\n print(n - 2, end = ' ')\r\n for i in range(n):\r\n if a[i] != neg1 and a[i] != pos:\r\n print(a[i], end = ' ')\r\nelse:\r\n print(1, neg3)\r\n print(2, neg1, neg2)\r\n print(n - 3, end = ' ')\r\n for i in range(n):\r\n if a[i] not in [neg1, neg2, neg3]:\r\n print(a[i], end = ' ')\r\n", "t = int(input())\r\n\r\narr = list(map(int, input().split()))\r\n\r\nless = []\r\ngreat = []\r\nzero = []\r\n\r\nfor i in range(t):\r\n if(arr[i] == 0):\r\n zero.append(0)\r\n\r\n else:\r\n if(arr[i] < 0):\r\n if(len(less) == 0):\r\n less.append(arr[i])\r\n else:\r\n great.append(arr[i])\r\n\r\n else:\r\n great.append(arr[i])\r\n\r\npos = -1\r\ncount = 0\r\nfor i in range(len(great)):\r\n if(great[i] < 0):\r\n pos = i \r\n count += 1\r\n\r\nif(count % 2 == 1):\r\n x = great[pos]\r\n del(great[pos])\r\n zero.append(x)\r\n\r\nprint(len(less), *less)\r\nprint(len(great), *great)\r\nprint(len(zero), *zero)\r\n\r\n", "a=int(input())\narr=[int(arr) for arr in input().split()]\narr.sort()\ns1=[]\ns2=[]\ns3=[]\ns1.append(arr.pop(0))\nfor i in range(arr.count(0)):\n arr.remove(0)\n s3.append(0)\nif(arr[len(arr)-1]>0):\n s2.append(arr.pop())\nelse:\n s2.append(arr.pop())\n s2.append(arr.pop())\n\ns3=s3+arr\nprint(len(s1),*s1)\nprint(len(s2),*s2)\nprint(len(s3),*s3)\n \t \t \t \t\t\t\t \t\t\t\t \t \t \t\t", "n = int(input())\nneg = []\npos = []\nzero = []\na = list(map(int, input().split()))\nfor elem in a:\n if elem < 0:\n neg.append(elem)\n elif elem > 0:\n pos.append(elem)\n else:\n zero.append(elem)\nif len(neg)%2 == 0:\n zero.append(neg.pop())\nif len(pos) == 0:\n pos.append(neg.pop())\n pos.append(neg.pop())\nprint(len(neg),end=' ')\nprint(*neg)\nprint(len(pos),end=' ')\nprint(*pos)\nprint(len(zero),end=' ')\nprint(*zero)\n\t\t \t \t \t \t\t\t\t\t \t\t \t \t\t\t\t\t \t\t\t", "length = int(input())\r\narr = list(map(int, input().split()))\r\narr1 = []\r\narr2 = []\r\narr3 = []\r\narrTemp = []\r\n\r\nneg_count = 0\r\npos_count = 0\r\n\r\nfor element in arr:\r\n if element > 0:\r\n pos_count += 1\r\n arr2.append(element)\r\n elif element < 0:\r\n neg_count += 1\r\n arrTemp.append(element)\r\n else:\r\n arr3.append(element)\r\n\r\nif neg_count%2 == 0 and pos_count == 0:\r\n for i in range(len(arrTemp)):\r\n if i == 0 or i == 1:\r\n arr2.append(arrTemp[i])\r\n elif i == 2:\r\n arr3.append(arrTemp[i])\r\n else:\r\n arr1.append(arrTemp[i])\r\n\r\nelif neg_count%2 == 0 and pos_count != 0:\r\n for i in range(len(arrTemp)):\r\n if i == 0:\r\n arr3.append(arrTemp[i])\r\n else:\r\n arr1.append(arrTemp[i])\r\n\r\nelif neg_count%2 == 1 and pos_count == 0:\r\n for i in range(len(arrTemp)):\r\n if i == 0 or i == 1:\r\n arr2.append(arrTemp[i])\r\n else:\r\n arr1.append(arrTemp[i])\r\n\r\nelse:\r\n arr1 = arrTemp\r\n\r\ndef printArr(arr):\r\n i = 0\r\n print(len(arr), end = \" \")\r\n for i in range(len(arr)):\r\n if i < (len(arr) - 1):\r\n print(arr[i], end = \" \")\r\n else:\r\n print(arr[i])\r\n\r\nprintArr(arr1)\r\nprintArr(arr2)\r\nprintArr(arr3)", "n = int(input())\r\n\r\na = list(map(int, input().split()))[:n]\r\n\r\nzeroSet = []\r\nnegativeSet = []\r\npositiveSet = []\r\n\r\nfor i in range(n):\r\n if(a[i] < 0):\r\n negativeSet.append(a[i])\r\n elif(a[i] == 0):\r\n zeroSet.append(a[i])\r\n else:\r\n positiveSet.append(a[i])\r\n\r\nlengthPositive = len(positiveSet)\r\nlengthNegative = len(negativeSet)\r\n\r\nif(lengthPositive == 0):\r\n positiveSet = negativeSet[-2:]\r\n negativeSet = negativeSet[0:lengthNegative - 2]\r\n\r\nif(len(negativeSet) % 2 == 0):\r\n lastNegative = negativeSet.pop(-1)\r\n zeroSet.append(lastNegative)\r\n\r\n\r\ndef printResult(result):\r\n length = len(result)\r\n print(length, *result)\r\n\r\n\r\nprintResult(negativeSet)\r\nprintResult(positiveSet)\r\nprintResult(zeroSet)\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\na,b=[],[]\r\ns=1\r\nfor i in l:\r\n if(i<0):\r\n a.append(i)\r\n elif(i>0):\r\n b.append(i)\r\nprint('1',a[0])\r\na.pop(0)\r\nif(len(b)==0):\r\n print('2',end=\" \")\r\n print(a[0],end=\" \")\r\n print(a[1])\r\n s+=2\r\n a.pop(0)\r\n a.pop(0)\r\nelse:\r\n print('1',b[0])\r\n s+=1\r\n b.pop(0)\r\nprint(n-s,end=\" \")\r\nprint('0',end=\" \")\r\nprint(*a,end=\" \")\r\nprint(*b)\r\n ", "n = int(input())\r\n\r\nnum_list = list(map(int, input().split()))\r\n\r\na = list(filter(lambda x: x < 0, num_list))\r\nb = list(filter(lambda x: x > 0, num_list))\r\nc = list(filter(lambda x: x == 0, num_list))\r\n\r\nif len(a) % 2 == 0:\r\n c.append(a.pop(0))\r\n\r\nif len(b) == 0:\r\n if len(c) > 2:\r\n b.append(c.pop(-1))\r\n b.append(c.pop(-1))\r\n elif len(a) > 2:\r\n b.append(a.pop(-1))\r\n b.append(a.pop(-1))\r\n else:\r\n b.append(a.pop(-1))\r\n b.append(c.pop(-1))\r\n\r\nprint(len(a), *a)\r\nprint(len(b), *b)\r\nprint(len(c), *c)\r\n", "n = int(input())\r\na = sorted(map(int, input().split()))\r\nprint(1, a[0])\r\nif a[-1] <= 0:\r\n print(2, a[1], a[2])\r\n print(n-3, *a[3:])\r\nelse:\r\n print(1, a[-1])\r\n print(n-2, *a[1:-1])", "# -*- coding: utf-8 -*-\n\"\"\"Untitled60.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1_5zBpQX0AmGklJanmyzNjYDfVnhJxgIK\n\"\"\"\n\nn=int(input())\nl1=list(map(int,input().split()))\na=[]\nb=[]\nc=[]\nfor x in l1:\n if x<0:\n a.append(x)\n elif x>0:\n b.append(x)\n else:\n c.append(x)\nif len(a)%2==0:\n d=a.pop()\n c.append(d)\nif len(b)==0:\n b.append(a.pop())\n b.append(a.pop())\nprint(str(len(a)),end=\" \")\nfor x in a:\n print(x,end=\" \")\nprint()\nprint(str(len(b)),end=\" \")\nfor x in b:\n print(x,end=\" \")\n\nprint()\nprint(str(len(c)),end=\" \")\nfor x in c:\n print(x,end=\" \")", "def _input():\r\n return map(int, input().split())\r\n\r\nt = _input()\r\nlst = sorted(list(_input()))\r\n\r\nx = lst.index(0)\r\n\r\nprint(1, lst[x-1]); lst.pop(x-1)\r\nx = lst.index(0)\r\n#print(\"x=\", x)\r\nif x < 2:\r\n print(1, lst[x+1]); lst.pop(x+1)\r\nelse:\r\n print(2, lst[x-1], lst[x-2]) \r\n lst.pop(x-1); lst.pop(x-2)\r\n\r\nprint(len(lst), end = ' ')\r\nfor i in lst:\r\n print(i, end = ' ')\r\n\r\n\r\n\r\n", "n = int(input())\na = list(map(int, input().split()))\nneg = []\nfor i in a:\n if i < 0:\n neg.append(i)\nn1 = []\nn2 = []\nn3 = []\nif len(neg) % 2 > 0 and len(a) - len(neg) > 1:\n n1.extend(neg)\n n3.append(0)\n for i in a:\n if i > 0:\n n2.append(i)\nelif len(neg) % 2 > 0 and len(a) - len(neg) == 1:\n n2.extend(neg)\n n2.pop()\n n1.append(neg[-1])\n n3.append(0)\nelif len(neg) % 2 == 0 and len(a) - len(neg) > 1:\n n1.extend(neg)\n n1.pop()\n n3.append(0)\n n3.append(neg[-1])\n for i in a:\n if i > 0:\n n2.append(i)\nelif len(neg) % 2 == 0 and len(a) - len(neg) == 1:\n n1.append(neg[0])\n n2.extend(neg[1:-1])\n n3.append(0)\n n3.append(neg[-1])\n\nprint(len(n1), *n1)\nprint(len(n2), *n2)\nprint(len(n3), *n3)\n\n \t \t \t\t\t\t \t\t\t\t\t \t \t\t\t\t \t", "n = int(input())\n\narray = list(map(int, input().split()))\n\nnegative_numbers = []\npositive_numbers = []\nzero_numbers = []\n\nfor number in array:\n if number < 0:\n negative_numbers.append(number)\n elif number > 0:\n positive_numbers.append(number)\n else:\n zero_numbers.append(number)\n\nif len(negative_numbers) % 2 == 0:\n zero_numbers.append(negative_numbers[-1])\n negative_numbers.pop()\n\nif len(positive_numbers) == 0:\n positive_numbers.append(negative_numbers[0])\n positive_numbers.append(negative_numbers[1])\n negative_numbers.pop(0)\n negative_numbers.pop(0)\n\nnegative_set = \" \".join(map(str,negative_numbers))\npositive_set = \" \".join(map(str,positive_numbers))\nzero_set = \" \".join(map(str,zero_numbers))\n\nprint(\"{} {}\".format(len(negative_numbers), negative_set))\nprint(\"{} {}\".format(len(positive_numbers), positive_set))\nprint(\"{} {}\".format(len(zero_numbers), zero_set))", "n=int(input())\r\nlst=list(map(int,input().split()))\r\na=[]\r\nb=[]\r\nc=[]\r\nlst.sort()\r\nflag1=0\r\nfor i in range(n):\r\n if(lst[i]<0 and flag1==0):\r\n a.append(lst[i])\r\n flag1=1\r\n elif(lst[i]>0):\r\n b.append(lst[i])\r\n else:\r\n c.append(lst[i])\r\nif(len(b)==0):\r\n b.append(c[0])\r\n b.append(c[1])\r\n c.pop(0)\r\n c.pop(0)\r\nprint(len(a),*a)\r\nprint(len(b),*b)\r\nprint(len(c),*c)", "\nn = input()\nn = int(n)\n\nlist = input().split()\nlist = [int(x) for x in list]\n\nnegative = []\npositive = []\nzero = []\n\nfor i in range(n):\n if list[i] < 0 :\n negative.append(list[i])\n\n elif list[i] > 0:\n positive.append(list[i])\n\n elif list[i] == 0:\n zero.append(list[i])\n\nif len(positive) == 0 and len(negative) > 2:\n positive.append(negative.pop())\n positive.append(negative.pop())\n\nif len(negative) % 2 == 0:\n zero.append(negative.pop())\n\nprint(len(negative) , *negative)\nprint(len(positive) , *positive)\nprint(len(zero) , *zero)\n\n\n# Time Complexity : O(n)\n\n\t \t \t \t\t \t \t \t\t\t \t \t \t\t", "(input())\r\na=sorted(map(int,input().split()))\r\n#print(a)\r\nb=[a.pop(0)]\r\n#print(b)\r\nc=a[-1]>0 and [a.pop()] or [a.pop(0),a.pop(0)]\r\n#print(c)\r\nfor l in b,c,a:\r\n print(len(l),*l)", "n = int(input())\r\n\r\na = [int(i) for i in input().split()]\r\n\r\nis_zero = []\r\ngreater_zero = []\r\nless_zero = []\r\n\r\nfor v in a:\r\n if v < 0:\r\n less_zero.append(v)\r\n elif v > 0:\r\n greater_zero.append(v)\r\n else:\r\n is_zero.append(v)\r\n\r\nif len(greater_zero) == 0:\r\n greater_zero.append(less_zero[0])\r\n greater_zero.append(less_zero[1])\r\n less_zero = less_zero[2:]\r\n\r\nif len(less_zero) % 2 == 0 and len(less_zero) > 1:\r\n is_zero.append(less_zero[0])\r\n less_zero = less_zero[1:]\r\n\r\nprint(len(less_zero), *less_zero, sep = \" \")\r\nprint(len(greater_zero), *greater_zero, sep = \" \")\r\nprint(len(is_zero), *is_zero, sep = \" \")\r\n\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\na1,a2,a3=[],[],[]\r\nfor i in a:\r\n if i<0:a1.append(i)\r\n elif i>0:a2.append(i)\r\n else:a3.append(i)\r\nif not len(a1)&1:\r\n a3.append(a1.pop())\r\nif len(a2)==0:\r\n a2.append(a1.pop())\r\n a2.append(a1.pop())\r\nprint(len(a1),*a1)\r\nprint(len(a2),*a2)\r\nprint(len(a3),*a3)", "\r\nn = int(input())\r\na = list(map(lambda x: int(x), input().split(' ')))\r\n\r\nneg = []\r\npos = []\r\nzer = []\r\n\r\nfor i in a:\r\n if i == 0:\r\n zer.append(i);\r\n elif i > 0:\r\n pos.append(i)\r\n elif len(neg) != 0:\r\n zer.append(i)\r\n else:\r\n neg.append(i)\r\n \r\nif len(pos) == 0:\r\n while len(pos) != 2:\r\n t = zer.pop()\r\n if t == 0:\r\n zer.insert(0, 0)\r\n else:\r\n pos.append(t)\r\n \r\n \r\n\r\nprint(len(neg), \" \".join(map(str, neg)))\r\nprint(len(pos), \" \".join(map(str, pos)))\r\nprint(len(zer), \" \".join(map(str, zer)))", "n=int(input())\r\na=list(map(int,input().split()))\r\nb=[]\r\nk=0\r\nk1=0\r\nfor i in range(0,n):\r\n if(a[i]==0):\r\n b.append(a[i])\r\n elif(a[i]>0):\r\n if(k==0):\r\n k=a[i]\r\n else:\r\n b.append(a[i])\r\n elif(a[i]<0):\r\n if(k1==0):\r\n k1=a[i]\r\n else:\r\n b.append(a[i])\r\nprint(1,k1)\r\nf=0\r\nif(k==0):\r\n c=[]\r\n for i in range(0,n):\r\n if(b[i]<0):\r\n c.append(b[i])\r\n b[i]='@'\r\n f=f+1\r\n if(len(c)==2):\r\n break\r\n print(2)\r\n for i in range(0,2):\r\n print(c[i])\r\nelse:\r\n print(1,k)\r\nprint(len(b)-f)\r\nfor i in range(0,len(b)):\r\n if(b[i]!='@'):\r\n print(b[i])", "n = int(input())\r\nlis = list(map(int,input().split()))\r\n\r\nlis1 = []\r\nlis2 = []\r\nlis3 = []\r\n\r\n\r\nfor el in lis:\r\n if el == 0:\r\n lis3.append(el)\r\n elif el<0:\r\n lis1.append(el)\r\n else:\r\n lis2.append(el)\r\n \r\nif len(lis2) == 0:\r\n if len(lis1)%2!=0:\r\n lis2.append(lis1.pop())\r\n lis2.append(lis1.pop())\r\n else:\r\n lis2.append(lis1.pop())\r\n lis2.append(lis1.pop())\r\n lis3.append(lis1.pop())\r\n\r\nif len(lis1)%2 == 0:\r\n lis3.append(lis1.pop())\r\n \r\n\r\nlis1.insert(0,len(lis1))\r\nlis2.insert(0,len(lis2))\r\nlis3.insert(0,len(lis3))\r\n\r\n\r\nprint(*lis1, sep=' ')\r\nprint(*lis2, sep=' ')\r\nprint(*lis3, sep=' ')" ]
{"inputs": ["3\n-1 2 0", "4\n-1 -2 -3 0", "5\n-1 -2 1 2 0", "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82", "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46", "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38", "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37", "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61", "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66", "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82", "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22", "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41", "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935", "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952", "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0", "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0", "5\n-1 -2 -3 -4 0", "3\n-101 101 0", "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000", "4\n0 -1 -2 -3"], "outputs": ["1 -1\n1 2\n1 0", "1 -1\n2 -3 -2\n1 0", "1 -1\n2 1 2\n2 0 -2", "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0", "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0", "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0", "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37", "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61", "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0", "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0", "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20", "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0", "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0", "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961", "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673", "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182", "1 -1\n2 -4 -3\n2 0 -2", "1 -101\n1 101\n1 0", "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000", "1 -1\n2 -3 -2\n1 0"]}
UNKNOWN
PYTHON3
CODEFORCES
248
1e526c78e232fa1191bd872a5767a30a
Maximum Control (easy)
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect some of them. The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel. How much work is there left to be done: that is, how many remote planets are there? The first line of the input contains an integer *N* (2<=≤<=*N*<=≤<=1000) – the number of planets in the galaxy. The next *N*<=-<=1 lines describe the hyperspace tunnels between the planets. Each of the *N*<=-<=1 lines contains two space-separated integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*N*) indicating that there is a bidirectional hyperspace tunnel between the planets *u* and *v*. It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets. A single integer denoting the number of remote planets. Sample Input 5 4 1 4 2 1 3 1 5 4 1 2 4 3 1 4 Sample Output 3 2
[ "n = int(input())\r\ncounter = 0\r\na = [[0 for j in range(n)] for i in range(n)]\r\nfor i in range(n - 1):\r\n i, j = map(int, input().split())\r\n a[i - 1][j - 1] = 1\r\n a[j - 1][i - 1] = 1\r\n\r\nfor element in a:\r\n if element.count(1) == 1:\r\n counter += 1\r\n\r\nprint(counter)", "import sys\r\nimport math\r\nimport bisect\r\n\r\ndef main():\r\n n = int(input())\r\n A = [0] * n\r\n for i in range(n - 1):\r\n a, b = map(int, input().split())\r\n A[a-1] += 1\r\n A[b-1] += 1\r\n ans = 0\r\n for i in range(n):\r\n if A[i] == 1:\r\n ans += 1\r\n print(ans)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "N = int(input())\r\ndeg = [0] * N\r\nfor i in range(N - 1):\r\n a, b = map(int, input().split())\r\n deg[a - 1] += 1\r\n deg[b - 1] += 1\r\n\r\nnum = 0\r\nfor i in range(N):\r\n if deg[i] == 1:\r\n num += 1\r\n\r\nprint(num)\r\n", "n = int(input())\r\n\r\nlis1 = list()\r\nlis2 = list()\r\nans = 0\r\n\r\nfor i in range(n-1):\r\n x, y = input(\"\").split()\r\n lis1.append(x)\r\n lis2.append(y)\r\n\r\nfor i in range(len(lis1)):\r\n if lis1.count(lis1[i]) == 1 and lis1[i] not in lis2:\r\n ans += 1\r\n if lis2.count(lis2[i]) == 1 and lis2[i] not in lis1:\r\n ans += 1\r\n \r\nprint(ans)", "n = int(input())\na = set()\nb = set()\nfor _ in range(n-1):\n c1,c2 = map(int,input().split())\n for c in [c1,c2]:\n if c in b:\n pass\n else:\n if c in a:\n b.add(c)\n a.remove(c)\n else:\n a.add(c)\nprint(len(a))\n", "t=int(input())\r\nli=[]\r\ncount=0\r\nfor i in range(t-1):\r\n\tl,r=map(int,input().split())\r\n\tli.append(r)\r\n\tli.append(l)\r\nfor i in li:\r\n\tif li.count(i)==1:\r\n\t\tcount+=1\r\nprint(count)", "N = int(input())\r\npairs = [tuple(map(int, input().split())) for i in range(N - 1)]\r\n\r\ngraph = {i: list() for i in range(1, N + 1)}\r\n\r\nfor el in pairs:\r\n x, y = el\r\n\r\n graph[x].append(y)\r\n graph[y].append(x)\r\n\r\nprint(sum(1 for i in range(1, N + 1) if len(graph[i]) == 1))\r\n", "n=int(input())\r\n\r\na=[0]*(n+1)\r\nfor i in range(n-1):\r\n u,v=map(int,input().split())\r\n a[u]+=1\r\n a[v]+=1\r\n\r\ncnt=0\r\nfor i in range(1,n+1):\r\n if a[i]==1:\r\n cnt+=1\r\n\r\nprint(cnt)", "# -*- coding: utf - 8 -*-\r\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\r\n| author: mr.math - Hakimov Rahimjon |\r\n| e-mail: [email protected] |\r\n| created: 14.04.2018 16:50 |\r\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\r\n# inp = open(\"input.txt\", \"r\"); input = inp.readline; out = open(\"output.txt\", \"w\"); print = out.write\r\nTN = 1\r\n\r\n\r\n# ===========================================\r\n\r\n\r\ndef solution():\r\n n = int(input())\r\n l = [[0 for j in range(n)] for i in range(n)]\r\n ans = 0\r\n for i in range(n-1):\r\n u, v = map(int, input().split())\r\n l[u-1][v-1] = 1\r\n l[v-1][u-1] = 1\r\n for i in l:\r\n if i.count(1) == 1: ans+=1\r\n print(ans)\r\n\r\n\r\n# ===========================================\r\nwhile TN != 0:\r\n solution()\r\n TN -= 1\r\n# ===========================================\r\n# inp.close()\r\n# out.close()\r\n", "\r\nnum_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\nn = int(input())\r\n\r\nE = [0] * n\r\n\r\nfor i in range(n - 1):\r\n u, v = map(int, input().split())\r\n E[u-1] += 1\r\n E[v-1] += 1\r\n\r\nprint(E.count(1))", "from collections import defaultdict\r\n\r\nd = defaultdict(int)\r\n\r\nfor _ in range(int(input())-1):\r\n u, v = input().split()\r\n d[u] += 1\r\n d[v] += 1\r\n\r\nprint(sum(n==1 for n in d.values()))", "n=int(input())\r\narr=[]\r\nfor _ in range(n):\r\n arr.append(0)\r\nfor _ in range(n-1):\r\n a,b=map(int,input().split())\r\n arr[a-1]+=1 \r\n arr[b-1]+=1 \r\nprint(arr.count(1))\r\n ", "t=int(input())\r\ndic1={}\r\ndic2={}\r\nremotes=[False]*t\r\nfor i in range(t-1):\r\n a,b=input().split()\r\n k=dic1.get(a,-1)\r\n if k==-1:\r\n dic1[a]=list()\r\n dic1[a].extend([b])\r\n k=dic2.get(b,-1)\r\n if k==-1:\r\n dic2[b]=list()\r\n dic2[b].extend([a])\r\nfor i in range(1,t+1):\r\n res=0\r\n if str(i) in dic1:\r\n if len(dic1[str(i)])>1:\r\n res=1\r\n elif str(i) in dic2 and len(dic1[str(i)])+len(dic2[str(i)])>1:\r\n res=1\r\n if str(i) in dic2:\r\n if len(dic2[str(i)])>1:\r\n res=1\r\n elif str(i) in dic1 and len(dic1[str(i)])+len(dic2[str(i)])>1:\r\n res=1\r\n remotes[i-1]=res\r\nprint(remotes.count(0))\r\n\r\n", "n = int(input())\r\nl = [2 for i in range(n)]\r\nfor i in range(n - 1):\r\n\tu, v = map(int, input().split())\r\n\tl[u - 1] -= 1\r\n\tl[v - 1] -= 1\r\n\r\nprint(l.count(1))", "def solve(l1,l2):\r\n ans = 0\r\n M = {}\r\n for i in range(len(l1)):\r\n if l1[i] in M:\r\n M[l1[i]] += 1\r\n else:\r\n M[l1[i]] = 1\r\n\r\n \r\n for i in range(len(l2)):\r\n if l2[i] in M:\r\n M[l2[i]] += 1\r\n else:\r\n M[l2[i]] = 1\r\n\r\n for i in M:\r\n if M[i] < 2:\r\n ans += 1\r\n\r\n print(ans)\r\n\r\nn = int(input())\r\nl1 = []\r\nl2 = []\r\nwhile (n-1):\r\n input_string = input()\r\n l = input_string.split()\r\n l1.append(l[0])\r\n l2.append(l[1])\r\n n -= 1\r\nsolve(l1,l2)", "\r\ndef main_function():\r\n n = int(input())\r\n hash = [0 for i in range(n + 1)]\r\n for i in range(n - 1):\r\n a, b = [int(i) for i in input().split(\" \")]\r\n hash[a] += 1\r\n hash[b] += 1\r\n counter = 0\r\n for i in hash:\r\n if i == 1:\r\n counter += 1\r\n print(counter)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()\r\n", "from collections import defaultdict\n\nn = int(input())\nm = defaultdict(int)\n\nfor i in range(n-1):\n\ta, b = map(int, input().split(\" \"))\n\tm[a] += 1\n\tm[b] += 1\n\nr = 0\nfor i in range(1, n + 1):\n\tif m[i] == 1:\n\t\tr += 1\n\nprint(r)\t\n", "cnt = {}\r\nfor _ in range(int(input())-1):\r\n a,b = map(int,input().split())\r\n #print(a,b)\r\n if a not in cnt:\r\n cnt[a] = 1\r\n else:\r\n cnt[a] += 1\r\n if b not in cnt:\r\n cnt[b] = 1\r\n else:\r\n cnt[b] += 1\r\n\r\ncount = 0\r\nfor k,v in cnt.items():\r\n if v == 1:\r\n count += 1\r\n\r\nprint(count)", "n = int(input())\nlst = []\np = []\nfor i in range(n-1):\n lst.append(list(map(int, input().split())))\n p.append(lst[i][0])\n p.append(lst[i][1])\ncount = 0\nfor i in range(len(p)):\n if p.count(p[i]) == 1:\n count += 1\nprint(count)\n", "import sys, bisect\r\n\r\nn = int(sys.stdin.readline())\r\ndeg = [0] * (n + 1)\r\nfor _ in range(n - 1):\r\n a, b = map(int, sys.stdin.readline().split())\r\n deg[a] += 1\r\n deg[b] += 1\r\nans = 0\r\nfor i in deg:\r\n if i == 1:\r\n ans += 1\r\nprint(ans)\r\n", "n=int(input())\r\na=[]\r\ncnt=0\r\nfor i in range(n-1):\r\n a+=input().split()\r\nfor i in range(1,n+1):\r\n if a.count(str(i))==1:\r\n cnt+=1\r\nprint(cnt)", "graph, num = {}, 0\r\nn = int(input())\r\nfor i in range(n-1):\r\n a, b = [int(i) for i in input().split()]\r\n if a not in graph: graph[a] = []\r\n graph[a].extend([b])\r\n if b not in graph: graph[b] = []\r\n graph[b].extend([a])\r\n \r\nfor key in graph:\r\n if len(graph[key]) == 1: num += 1\r\n\r\nprint(num)", "N = int(input())\r\nCheck = [0] * N\r\nfor i in range(N - 1):\r\n X = list(map(int, input().split()))\r\n Check[X[0] - 1], Check[X[1] - 1], = Check[X[0] - 1] + 1, Check[X[1] - 1] + 1\r\nprint(Check.count(1))\r\n", "n=int(input())\r\nls=[]\r\nfor i in range(n-1):\r\n p,q=map(int,input().split())\r\n ls.append(p)\r\n ls.append(q)\r\ns=0\r\nfor i in ls:\r\n if ls.count(i)==1:\r\n s+=1\r\nprint(s)", "n = int(input())\nd = {}\nfor i in range(n - 1):\n u, v = map(int, input().split())\n if u not in d:\n d[u] = 1\n else:\n d[u] += 1\n if v not in d:\n d[v] = 1\n else:\n d[v] += 1\nans = 0\nfor i in range(1, n + 1):\n if d[i] == 1:\n ans += 1\nprint(ans)", "import sys\nfrom itertools import accumulate\n\namt = int(input())\n\ndct = {i:0 for i in range(1, amt + 1)}\nfor i in range(amt - 1):\n\tx, y = [int(i) for i in input().split()]\n\tdct[x] += 1\n\tdct[y] += 1\nans = 0\nfor i in dct:\n\tif dct[i] == 1:\n\t\tans += 1\nprint(ans)\n", "N=int(input())\r\na=[0 for i in range(N)]\r\nfor i in range(N-1):\r\n u,v=map(int,input().split())\r\n a[u-1]+=1\r\n a[v-1]+=1\r\ncount=0 \r\nfor j in range(N):\r\n if(a[j]==1):\r\n count+=1\r\nprint(count) ", "n = int(input())\r\nd = {}\r\nfor i in range(n-1):\r\n s,t = map(int,input().split())\r\n if s in d:\r\n d[s].append(t)\r\n else:\r\n d[s] = [t]\r\n if t in d:\r\n d[t].append(s)\r\n else:\r\n d[t] = [s]\r\ntotal = 0\r\nfor j in d.keys():\r\n if len(d[j])==1:\r\n total += 1\r\nprint(total)", "import sys\r\n\r\nn = int(sys.stdin.readline())\r\n\r\nconn = []\r\nfor i in range(n-1):\r\n inp = sys.stdin.readline()\r\n a,b = [int(elem) for elem in inp.split()]\r\n conn.append(a)\r\n conn.append(b)\r\n\r\nremote=0\r\n\r\nfor i in range(1,n+1):\r\n if conn.count(i)==1:\r\n remote+=1\r\n\r\nsys.stdout.write(str(remote))", "n = int(input())\r\nm = [0 for i in range(n)]\r\nfor i in range(n - 1):\r\n u, v = map(int, input().split())\r\n m[u - 1] += 1\r\n m[v - 1] += 1\r\nprint(m.count(1))\r\n", "n=int(input())\r\nw=[]\r\nk=0\r\nfor i in range(n-1):\r\n u,v=map(int,input().split())\r\n w.append(u)\r\n w.append(v)\r\ns=list(set(w))\r\nfor i in s:\r\n if w.count(i)==1:\r\n k+=1\r\n \r\nprint(k)\r\n", "n=int(input())\r\narr=[]\r\nfor i in range(0,n-1):\r\n li=list(map(int,input().split()))\r\n u=li[0]\r\n v=li[1]\r\n arr.append(u)\r\n arr.append(v)\r\ncnt=0\r\nfor i in arr:\r\n if arr.count(i)==1:\r\n cnt+=1\r\nprint(cnt)", "n = int(input())\r\nli = [0] * n\r\n\r\nfor x in range(0,n-1):\r\n line = (input().split())\r\n for x in line:\r\n li[int(x)-1] += 1\r\n\r\nprint(li.count(1))", "def fun(ls):\r\n dct = {}\r\n count = 0\r\n for i in ls:\r\n f, s = i\r\n if(f in dct):\r\n dct[f] = dct.get(f) + 1\r\n else:\r\n dct[f] = 1\r\n if(s in dct):\r\n dct[s] = dct.get(s) + 1\r\n else:\r\n dct[s] = 1\r\n for key, value in dct.items():\r\n if value < 2:\r\n count += 1\r\n print(count)\r\n\r\n\r\nT = int(input())\r\nls = []\r\nfor i in range(T-1):\r\n lt = list(map(int, input().split()))\r\n ls.append(lt)\r\nfun(ls)\r\n", "n = int(input())\nc = {}\n\nfor i in range(n-1):\n\tt = list(map(int, input().split()))\n\ttry:\n\t\tc[t[0]] += 1\n\t\tif c[t[0]] == 1:\n\t\t\tc.pop(t[0])\n\texcept:\n\t\tc[t[0]] = 1\n\n\ttry:\n\t\tc[t[1]] += 1\n\t\tif c[t[1]] == 1:\n\t\t\tc.pop(t[0])\n\texcept:\n\t\tc[t[1]] = 1\n\nt = 0\nfor i in c:\n\tif c[i] == 1:\n\t\tt += 1\n\nprint(t)\n\n\n", "from collections import deque, defaultdict, Counter\r\nfrom itertools import product, groupby, permutations, combinations\r\nfrom math import gcd, floor, inf, log2, sqrt, log10\r\nfrom bisect import bisect_right, bisect_left\r\nfrom statistics import mode\r\nfrom string import ascii_uppercase\r\n\r\ncases = int(input())\r\nans = [0] * (cases+1)\r\n# print(ans)\r\nfor _ in range(cases-1):\r\n a, b = map(int, input().split())\r\n ans[a] += 1\r\n ans[b] += 1\r\n\r\nprint(ans.count(1))\r\n", "n = int(input())\r\nmx = \"\"\r\nfor i in range(n-1):\r\n m = input().strip()\r\n mx = mx + m + \" \"\r\nmx = list(map(int,mx.split()))\r\ncount = 0\r\nfor i in range(n):\r\n if mx.count(i+1) == 1:\r\n count += 1\r\nprint(count)", "n = int(input())\r\ngraph = [[] for _ in range(n)]\r\nfor _ in range(n - 1):\r\n (u, v) = [(int(r) - 1) for r in input().split()]\r\n graph[u].append(v)\r\n graph[v].append(u)\r\nans = 0\r\nfor adj in graph:\r\n if len(adj) == 1:\r\n ans += 1\r\nprint(ans)\r\n", "number_of_planets = int(input())\n\nplanets = []\n\nfor i in range(number_of_planets - 1):\n bidirectional_hyperspace_tunnel = list(map(int, input().split(' ')))\n planets.append(bidirectional_hyperspace_tunnel[0])\n planets.append(bidirectional_hyperspace_tunnel[1])\n\nremote_planets = []\n\nfor planet in planets:\n if planets.count(planet) == 1:\n remote_planets.append(planet)\n\nprint(len(remote_planets))\n\n", "n = []\r\na = 0\r\nfor _ in range(int(input()) - 1):\r\n s = list(map(int,input().split()))\r\n for x in s:\r\n n.append(x)\r\nfor x in n:\r\n if n.count(x) == 1: a+= 1\r\nprint(a)\r\n", "n = int(input())\r\ndic = {}\r\nfor i in range(1, n+1):\r\n dic.update({i:0})\r\nfor i in range(n-1):\r\n s = input().split()\r\n dic[int(s[0])]+=1\r\n dic[int(s[1])]+=1\r\n\r\ncount = 0 \r\nfor x in dic.keys():\r\n if dic[x]==1:\r\n count+=1\r\n \r\nprint(count)", "n = int(input())\r\nmyList = []\r\nfor k in range(0, n):\r\n myList.append(0)\r\ncounter = 0\r\nfor i in range(0, n - 1):\r\n a, b = map(int, input().split())\r\n myList[a - 1] += 1\r\n myList[b - 1] += 1\r\nfor j in range(0, len(myList)):\r\n if myList[j] == 1:\r\n counter += 1\r\nprint(counter)\r\n", "N = int(input())\r\n\r\nplanets = []\r\n\r\nans = 0\r\n\r\nfor i in range(N - 1):\r\n\r\n\ttunnel = [int(x) for x in input().split()]\r\n\r\n\tplanets.append(tunnel[0])\r\n\r\n\tplanets.append(tunnel[1])\r\n\r\nplanets.sort()\r\n\r\nfor i in range(len(planets)):\r\n\r\n\tif i == 0:\r\n\r\n\t\tif planets[i] != planets[i + 1]:\r\n\r\n\t\t\tans += 1\r\n\r\n\telif i == len(planets) - 1:\r\n\r\n\t\tif planets[i] != planets[i - 1]:\r\n\r\n\t\t\tans += 1\r\n\r\n\telse:\r\n\r\n\t\tif planets[i] != planets[i + 1] and planets[i] != planets[i - 1]:\r\n\r\n\t\t\tans += 1\r\n\r\nprint(ans)", "a=[]\r\nb=int(input())\r\ne=0\r\nfor i in range(b-1):\r\n d,c=list(map(int,input().split()))\r\n a.append(d)\r\n a.append(c)\r\nfor i in range(1,b+1):\r\n\r\n if a.count(i)==1:\r\n e+=1\r\nprint(e)\r\n\r\n\r\n\r\n", "n = int(input())\r\ns = [0 for i in range(n)]\r\n\r\nfor i in range(n-1):\r\n\tu,v = map(int,input().split())\r\n\ts[u-1]+=1\r\n\ts[v-1]+=1\r\n\r\nprint(s.count(1))", "n=int(input())\r\nl=[]\r\nans=0\r\nfor i in range(n-1):\r\n u,v=list(map(int,input().split()))\r\n l.append(u)\r\n l.append(v)\r\nfor i in range(1,n+1):\r\n if l.count(i)==1:\r\n ans=ans+1\r\nprint(ans)\r\n\r\n", "n=int(input())\r\ngraph=[[] for i in range(n)]\r\nfor i in range(n-1):\r\n\tx,y=map(int,input().split())\r\n\tgraph[x-1].append(y)\r\n\tgraph[y-1].append(x)\r\nc=0\r\nfor i in range(n):\r\n\tif len(graph[i])==1:\r\n\t\tc+=1\r\nprint(c)", "#author : SanskarxRawat\r\nfrom collections import Counter\r\nn=int(input())\r\ns={}\r\nfor i in range(n-1):\r\n u,v=map(int,input().strip().split())\r\n s[u]=s.get(u,0)+1\r\n s[v]=s.get(v,0)+1\r\nprint(Counter(s.values())[1])", "import sys\r\nimport math\r\n\r\n#to read string\r\nget_string = lambda: sys.stdin.readline().strip()\r\n#to read list of integers\r\nget_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )\r\n#to read integers\r\nget_int = lambda: int(sys.stdin.readline())\r\n#to print fast\r\npt = lambda x: sys.stdout.write(str(x)+'\\n')\r\n\r\n#--------------------------------WhiteHat010--------------------------------------#\r\nn = get_int()\r\nd = {}\r\nfor i in range(1,n+1):\r\n d[i] = 0\r\n\r\nfor i in range(n-1):\r\n a,b = get_int_list()\r\n d[a] += 1\r\n d[b] += 1\r\ncount = 0\r\nfor i,v in d.items():\r\n if v == 1:\r\n count += 1\r\nprint(count)", "p=int(input())\r\na=[]\r\nx=0\r\nfor i in range(p-1):\r\n a+=input().split()\r\nfor i in range(p):\r\n if a.count(str(i+1))==1:\r\n x+=1\r\nprint(x)\r\n", "n=int(input())\r\na=[0]*n\r\nfor i in range(n-1):\r\n a1,a2=[int(x) for x in input().split()]\r\n a[a1-1]+=1\r\n a[a2-1]+=1\r\nres=0\r\nfor i in a:\r\n if i==1:\r\n res+=1\r\nprint(res)", "n = int(input())\r\n\r\nhashMap = {}\r\nfor _ in range(n-1):\r\n u, v = map(int, input().split())\r\n\r\n if u not in hashMap:\r\n hashMap[u] = 1\r\n else:\r\n hashMap[u] += 1\r\n\r\n if v not in hashMap:\r\n hashMap[v] = 1\r\n else:\r\n hashMap[v] += 1\r\n\r\nres = 0\r\nfor i in hashMap:\r\n if hashMap[i] == 1:\r\n res += 1\r\n\r\nprint(res)", "N = int(input())\r\na = [0] * N\r\nfor _ in range(N-1):\r\n u, v = list(map(int, input().split()))\r\n a[u-1] += 1\r\n a[v-1] += 1\r\nprint(a.count(1))", "from sys import stdin,stdout\r\nfrom math import ceil\r\nst=lambda:list(stdin.readline().strip())\r\nli=lambda:list(map(int,stdin.readline().split()))\r\nmp=lambda:map(int,stdin.readline().split())\r\ninp=lambda:int(stdin.readline())\r\npr=lambda n: stdout.write(str(n)+\"\\n\")\r\n\r\nmod=1000000007\r\n\r\ndef solve():\r\n n=inp()\r\n ans=0\r\n d={}\r\n for i in range(n-1):\r\n a,b=mp()\r\n d[a]=d.get(a,[])+[b]\r\n d[b]=d.get(b,[])+[a]\r\n #pr(d)\r\n for i in d:\r\n if len(d[i])==1:\r\n ans+=1\r\n pr(ans)\r\n \r\nfor _ in range(1):\r\n solve()\r\n", "n = int(input())\r\n\r\nE = [0] * n\r\n\r\nfor i in range(n - 1):\r\n u, v = map(int, input().split())\r\n E[u-1] += 1\r\n E[v-1] += 1\r\n\r\nprint(E.count(1))", "n = int(input())\r\nl=[]\r\nwhile(n!=1):\r\n a,m = map(int,input().split())\r\n l.append(a)\r\n l.append(m)\r\n n-=1\r\nc=0\r\nfor i in range(len(l)):\r\n if(l.count(l[i])<=1):\r\n c+=1\r\nprint(c)\r\n", "N = int(input())\r\nCheck = [0] * N\r\nfor i in range(N - 1):\r\n X = list(map(int, input().split()))\r\n Check[X[0] - 1], Check[X[1] - 1], = Check[X[0] - 1] + 1, Check[X[1] - 1] + 1\r\nprint(Check.count(1))\r\n\r\n# UB_CodeForces\r\n# Advice: Falling down is an accident, staying down is a choice\r\n# Location: A Few days in Mashhad\r\n# Caption: Before going to a family house\r\n# CodeNumber: 675\r\n", "N = int(input())\nsrc = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]\nes = [[] for i in range(N)]\nfor a,b in src:\n es[a].append(b)\n es[b].append(a)\nans = 0\nfor e in es:\n if len(e) == 1:\n ans += 1\nprint(ans)\n", "n=int(input())\r\nd={}\r\nfor i in range (1,n):\r\n x,y=map(int,input().split())\r\n if x in d:\r\n d[x].append(y)\r\n else:\r\n d[x]=[y]\r\n if y in d:\r\n d[y].append(x)\r\n else:\r\n d[y] = [x]\r\n# print(d)\r\nc=0\r\nfor i in d:\r\n if len(d[i])==1:\r\n c+=1\r\nprint(c)", "n = int(input())\ncons = []\nfor i in range(n-1):\n cons+=[int(x) for x in input().split()]\ncnt = 0\nfor i in range(1,n+1):\n if(cons.count(i)==1):\n cnt += 1\nprint(cnt)\n", "n=int(input())\r\nk=n-1\r\nar=[]\r\nfor x in range(n):\r\n ar.append(0)\r\nwhile k>0:\r\n z,v=map(int,input().split())\r\n ar[z-1]+=1 \r\n ar[v-1]+=1\r\n k-=1\r\nm=0\r\nfor x in range(n):\r\n if ar[x]==1:\r\n m+=1 \r\nprint(m)\r\n ", "def solve():\r\n\tn = int(input())\r\n\tmp = {}\r\n\tfor i in range(n-1):\r\n\t\tu, v = map(int, input().split())\r\n\t\tif u in mp:\r\n\t\t\tmp[u].append(v)\r\n\t\telse:\r\n\t\t\tmp[u] = [v]\r\n\t\tif v in mp:\r\n\t\t\tmp[v].append(u)\r\n\t\telse:\r\n\t\t\tmp[v] = [u]\r\n\tcnt = 0\r\n\tfor i in mp.keys():\r\n\t\tif len(mp[i]) == 1:\r\n\t\t\tcnt += 1\r\n\treturn cnt\r\n\r\nprint(solve())", "memo = [0] * 1001\r\n\r\nfor _ in range(int(input()) - 1):\r\n u, v = map(int, input().split())\r\n memo[u] += 1\r\n memo[v] += 1\r\n\r\nprint(len([i for i in memo if i == 1]))", "n = int(input()) - 1\r\na = ''\r\nfor i in range(n):\r\n uv = input().split()\r\n u = int(uv[0])\r\n v = int(uv[1])\r\n a += str(u) + ' ' + str(v) + ' '\r\na = sorted([int(i) for i in a.split()])\r\ni = 0\r\nk = 0\r\nfor i in range(2*n):\r\n if i == 0 and a[0] != a[1]:\r\n k += 1\r\n elif i == 2*n - 1 and a[2*n-2] != a[2*n-1]:\r\n k += 1\r\n elif 0 < i < 2*n - 1 and a[i] != a[i-1] and a[i] != a[i+1]:\r\n k += 1\r\nprint(k)\r\n", "n = int(input())\r\nd = [0] * (n + 1)\r\nfor _ in range(n - 1):\r\n x, y = map(int, input().split())\r\n d[x] += 1\r\n d[y] += 1\r\nprint(d.count(1))\r\n", "x=int(input())\r\na=[]\r\nb=[]\r\nnum=[]\r\nans=0\r\nfor i in range(x-1):\r\n inp=list(map(int,input().split()))\r\n a.append(inp)\r\n b.append(i+1)\r\nb.append(x)\r\nfor i in b:\r\n temp=sum(x.count(i) for x in a)\r\n num.append(temp)\r\nfor i in num:\r\n if i==1:\r\n ans+=1\r\nprint(ans)\r\n\r\n\r\n", "a=int(input())\r\ns=[]\r\nm=0\r\nfor i in range(a-1):\r\n b,c=map(int,input().split())\r\n s=s+[b]+[c]\r\nfor i in range(len(s)):\r\n if s.count(s[i])==1:\r\n m=m+1\r\nprint(m)\r\n \r\n \r\n", "n = int(input())\r\n\r\nli = list([[0]*n])\r\nli = li[0]\r\n\r\ncount = n\r\nfor i in range(n-1):\r\n a, b = map(int, input().split())\r\n if li[a-1] == 0:\r\n li[a-1] = b\r\n elif li[a-1] == -1:\r\n li[a-1] = li[a-1]\r\n else:\r\n count -= 1\r\n li[a-1] = -1\r\n if li[b-1] == 0:\r\n li[b-1] = a\r\n elif li[b-1] == -1:\r\n li[b-1] = li[b-1]\r\n else:\r\n count -= 1\r\n li[b-1] = -1\r\n\r\nprint(count)\r\n", "\"\"\"\nhttps://codeforces.com/problemset/problem/958/B1\n\"\"\"\nplanets = int(input())\nlinks = dict()\nfor _ in range(planets - 1):\n a, b = [x for x in input().split()]\n links.setdefault(a, []).append(b)\n links.setdefault(b, []).append(a)\ncompte=0\nfor v in links.values():\n if len(v)==1:\n compte+=1\nprint(compte) \n", "n = int(input())\r\ntun = {}\r\nfor i in range(n):\r\n tun[i+1] = 0\r\nfor i in range(n-1):\r\n u,v = map(int,input().split())\r\n tun[u] += 1\r\n tun[v] += 1\r\nans = 0\r\nfor i in range(1,n+1):\r\n if tun[i] == 1:\r\n ans += 1\r\nprint(ans)", "N = int(input())\ncnt = [0] * N\nfor n in range(N - 1):\n u, v = map(int, input().split())\n cnt[u - 1] += 1\n cnt[v - 1] += 1\n\nprint(sum(x == 1 for x in cnt))\n", "n = int(input().strip())\ngraph = [[] for i in range(n)]\nfor _ in range(n-1):\n a, b = map(int, input().split())\n graph[a-1].append(b-1)\n graph[b-1].append(a-1)\ncount = 0\nfor g in graph:\n if len(g) < 2:\n count += 1\nprint(count)", "# from dust i have come dust i will be\n\nn=int(input())\n\na=[0]*(n+1)\nfor i in range(n-1):\n u,v=map(int,input().split())\n a[u]+=1\n a[v]+=1\n\ncnt=0\nfor i in range(1,n+1):\n if a[i]==1:\n cnt+=1\n\nprint(cnt)\n \t \t \t \t \t\t\t\t \t \t \t \t", "n = int(input())\r\n\r\nlst = []\r\n\r\nfor x in range(n-1):\r\n a, b = input().split()\r\n lst.append(a)\r\n lst.append(b)\r\n\r\ncnt = 0\r\nfor bruh in lst:\r\n if lst.count(bruh) == 1:\r\n cnt += 1\r\n\r\nprint(cnt)", "from collections import Counter\r\nn=int(input())\r\nl1=[]\r\nwhile True:\r\n\ttry:\r\n\t\tl=input().split()\r\n\t\tfor i in l:\r\n\t\t\tl1.append(i)\r\n\texcept:break\r\na=Counter(l1)\r\nz=list(a.values())\r\nprint(z.count(1))", "n = int(input())\r\na = []\r\ns = 0\r\nfor i in range(n):\r\n a.append(0)\r\nfor i in range(n-1):\r\n u,v = map(int, input().split())\r\n a[u-1]+=1\r\n a[v-1]+=1\r\nfor i in range(n):\r\n if a[i]==1:\r\n s+=1\r\nprint(s)\r\n", "n = int(input())\n\nq = [0] * n\n\nfor i in range(n - 1):\n u, v = map(int, input().split())\n\n q[u - 1] += 1\n q[v - 1] += 1\n\nprint(q.count(1))\n", "from collections import defaultdict\r\nn = int(input())\r\nd = defaultdict(list)\r\nfor i in range(n-1):\r\n\ta,b = map(int,input().split())\r\n\td[a].append(b)\r\n\td[b].append(a)\r\nt = 0\r\nfor i in d:\r\n\tif len(d[i]) == 1:\r\n\t\tt = t + 1\r\nprint(t)", "n=int(input())\r\nd=dict()\r\nfor i in range(n-1):\r\n a,b=map(int,input().split())\r\n if a in d:\r\n d[a]+=1\r\n else:\r\n d[a]=1\r\n if b in d:\r\n d[b]+=1\r\n else: d[b]=1\r\nans=0\r\nfor i in d:\r\n if d[i]==1:\r\n ans+=1\r\nprint(ans)\r\n", "from collections import Counter\n\nN = int(input())\ncount = [0]*N\n\nfor i in range(N - 1):\n a,b = input().split()\n count[int(a) - 1] += 1\n count[int(b) - 1] += 1\n\ncount2 = 0\nfor i in range(N):\n if count[i] < 2:\n count2 += 1\n\nprint(count2)", "n = int(input())\r\ngraph = {i: [] for i in range(1, n+1)}\r\nfor _ in range(n-1):\r\n a, b = map(int, input().split())\r\n graph[a].append(b)\r\n graph[b].append(a)\r\nr = 0\r\nfor i in range(1, n+1):\r\n r += (len(graph[i]) == 1)\r\nprint(r)", "n=int(input())\r\nlista=[]\r\nlistb=[]\r\nfor i in range(n-1):\r\n a,b=map(int,input().split())\r\n lista.append(a)\r\n listb.append(b)\r\nlistf=[]\r\nseta=set(lista)\r\nsetb=set(listb)\r\nfor i in seta:\r\n if lista.count(i)==1 and listb.count(i)==0:\r\n listf.append(i)\r\nfor j in setb:\r\n if j not in listf:\r\n if listb.count(j)==1 and lista.count(j)==0:\r\n listf.append(j)\r\nprint(len(listf))\r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ", "__author__ = 'Esfandiar'\nn = int(input())\ng = [[] for i in range(n)]\nfor i in range(n-1):\n u,v = map(int,input().split())\n g[u-1].append(v-1)\n g[v-1].append(u-1)\nprint(sum([len(g[i])==1 for i in range(n)]))", "n = int(input())\r\nl = []\r\nfor i in range(n-1):\r\n\tu , v = map(int,input().split())\r\n\tl.append(u)\r\n\tl.append(v)\r\nsetl = set(l)\r\ncount1 = 0\r\nfor j in setl:\r\n\tif l.count(j)==1:\r\n\t\tcount1 += 1\r\nprint(count1)\t\t", "n=int(input())\r\na,d,f=[],0,0\r\nfor i in range(n-1):\r\n k,l=map(int,input().split())\r\n a.append(k)\r\n a.append(l)\r\nfor i in range(len(a)):\r\n d=0\r\n for j in range(len(a)):\r\n if i!=j and a[i]==a[j]:d=d+1\r\n if d==0:f=f+1\r\nprint(f)\r\n", "\r\n\r\n\r\nt=[]\r\nfor k in range(int(input())-1):\r\n a,b = map(int,input().split())\r\n t.append(a)\r\n t.append(b)\r\n\r\n\r\n\r\n\r\ny = set(t)\r\np=0\r\n\r\nfor i in y:\r\n if t.count(i)==1:\r\n p+=1\r\n\r\nprint(p)\r\n", "n = int(input())\r\nu_list = []\r\nv_list = []\r\nfor i in range(n-1):\r\n u, v = map(int, input().split())\r\n u_list.append(u)\r\n v_list.append(v)\r\nh = 0\r\nfor k in range(n-1):\r\n if ((u_list.count(u_list[k]) == 1) and u_list[k] not in v_list) or (v_list.count(v_list[k]) == 1 and v_list[k] not in u_list):\r\n h += 1\r\nprint(h)", "n=int(input())\r\nk=[]\r\nfor i in range(n-1):\r\n a,b=map(int,input().split())\r\n k.append(a)\r\n k.append(b)\r\nans=0\r\nfor i in k:\r\n if k.count(i)==1:\r\n ans+=1\r\nprint(ans)", "n = int(input())\r\nd = {}\r\nfor i in range(n-1):\r\n\tx,y = map(int,input().split())\r\n\tif x in d:\r\n\t\td[x] +=1\r\n\telse:\r\n\t\td[x] = 1\r\n\tif y in d:\r\n\t\td[y] +=1 \r\n\telse:\r\n\t\td[y] = 1\r\nans = 0\r\nfor i in d.keys():\r\n\tif d[i] == 1:\r\n\t\tans+=1\r\nprint(ans)", "n = int(input())\r\n\r\nl = []\r\ns = 0\r\n\r\nfor i in range(n - 1):\r\n\tu, v = map(int, input().split())\r\n\tl.append(u)\r\n\tl.append(v)\r\n\t\r\nfor i in l:\r\n\tif l.count(i) == 1:\r\n\t\ts += 1\r\n\t\t\r\nprint(s)", "resole = []\r\nresult = 0\r\nfor i in range(int(input()) - 1):\r\n resole.extend(list(map(lambda x: int(x), input().split(' '))))\r\n\r\nresole.sort()\r\n\r\nfor i in range(1, len(resole) - 1):\r\n if not resole[i + 1] == resole[i] and not resole[i - 1] == resole[i]:\r\n result += 1\r\n\r\nif not resole[len(resole) - 1] == resole[len(resole) - 2]:\r\n result += 1\r\n\r\nif not resole[0] == resole[1]:\r\n result += 1\r\n\r\nprint(result)\r\n", "from collections import Counter\n\nn = int(input())\ncnt = Counter()\nfor _ in range(n - 1):\n a, b = (int(i) for i in input().split())\n cnt[a] += 1\n cnt[b] += 1\nres = sum(v == 1 for v in cnt.values())\nprint(res)\n", "n=int(input())\r\npairs=[]\r\nremote=[]\r\nfor i in range(n-1):\r\n n,k=list(map(int,input().split()))\r\n pairs.append(n)\r\n pairs.append(k)\r\nfor i in pairs:\r\n if pairs.count(i)==1:\r\n remote.append(i)\r\nprint(len(remote)) \r\n", "n=int(input())\r\nl=[0]*(n)\r\n\r\nfor _ in range(n-1):\r\n a,b=list(map(int,input().split()))\r\n l[a-1]+=1\r\n l[b-1]+=1\r\n \r\nprint(l.count(1))", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn = int(input())\r\nd = [0]*n\r\nfor _ in range(n-1):\r\n a, b = map(int, input().split())\r\n d[a-1] += 1\r\n d[b-1] += 1\r\nc = 0\r\nfor i in d:\r\n if i < 2:\r\n c += 1\r\nprint(c)\r\n", "N=int(input())\r\nM=[]\r\nr=0\r\nfor k in range(N):\r\n M.append(0)\r\nfor k in range(N-1):\r\n a,b=input().split()\r\n M[int(a)-1]+=1\r\n M[int(b)-1]+=1\r\nfor k in range(N):\r\n if M[k]==1:\r\n r+=1\r\nprint(r)\r\n", "if __name__ == '__main__':\r\n P = lambda: map(int, input().split())\r\n N = lambda: int(input())\r\n\r\n n = N()\r\n a = [0]*n\r\n\r\n while n > 1:\r\n u, v = P()\r\n a[u - 1] += 1\r\n a[v - 1] += 1\r\n n -= 1\r\n print(len([i for i in range(len(a)) if a[i] < 2]))", "from collections import Counter\nn = int(input())\nC = Counter()\nfor _ in range(n - 1):\n C.update(map(int, input().split()))\nprint(sum(1 for a, b in C.items() if b == 1)) \n", "n = int(input())\r\nk = []\r\nz = 0\r\n#p = [i for i in range(1,n+1)]\r\nfor i in range(n-1):\r\n a, b = map(int, input().split())\r\n k.append(a)\r\n k.append(b)\r\nfor i in range(1,n+1):\r\n if k.count(i) <= 1:\r\n z += 1\r\nprint(z)\r\n", "n = int(input())\n\ncounterArray = [0] *n\n\n\nfor _ in range(n-1):\n s, g = map(int, input().split())\n\n counterArray[s-1]+=1\n counterArray[g-1]+=1\n\nres = 0\n\nfor i in counterArray:\n if i ==1: res+=1\n\n\nprint(res)\n\n", "n = int(input())\r\nd = {}\r\nfor i in range(n - 1):\r\n u, v = map(int, input().split())\r\n d[u] = d.get(u, 0) + 1\r\n d[v] = d.get(v, 0) + 1\r\ncnt = 0\r\nfor i in d.keys():\r\n if d[i] == 1:\r\n cnt += 1\r\nprint(cnt)", "a = int(input())\r\nl = []\r\none =[]\r\nfor i in range(a-1):\r\n p = list(int(x) for x in input().split())\r\n for i in p:\r\n l.append(i)\r\nfor i in set(l):\r\n one.append(l.count(i))\r\nprint(one.count(1))", "n = int(input())\r\ncount = {}\r\nfor _ in range(n - 1):\r\n u, v = map(int, input().split())\r\n count[u] = count.get(u, 0) + 1\r\n count[v] = count.get(v, 0) + 1\r\nans = sum([1 for x in count.values() if x == 1])\r\nprint(ans)", "import sys\r\ndef get_int(): return int(sys.stdin.readline())\r\ndef get_string(): return sys.stdin.readline().strip()\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split(\" \"))\r\ndef get_array(): return [int(x) for x in sys.stdin.readline().strip().split(\" \")]\r\n\r\n\r\ndef solution(n, arr):\r\n d = {}\r\n for i in range(n-1):\r\n p1, p2 = arr[i]\r\n if d.get(str(p1), 0) == 0:\r\n d[str(p1)] = 1\r\n else:\r\n d[str(p1)] += 1\r\n\r\n if d.get(str(p2), 0) == 0:\r\n d[str(p2)] = 1\r\n else:\r\n d[str(p2)] += 1\r\n\r\n ans = 0\r\n for i in d.keys():\r\n if d[i] == 1:\r\n ans += 1\r\n\r\n return ans\r\n\r\nn = get_int()\r\narr = [get_array() for _ in range(n-1)]\r\nprint(solution(n, arr)) \r\n\r\n\r\n" ]
{"inputs": ["5\n4 1\n4 2\n1 3\n1 5", "4\n1 2\n4 3\n1 4", "10\n4 3\n2 6\n10 1\n5 7\n5 8\n10 6\n5 9\n9 3\n2 9"], "outputs": ["3", "2", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
104
1e55fccee6224084c321804a4e02e995
Forecast
The Department of economic development of IT City created a model of city development till year 2100. To prepare report about growth perspectives it is required to get growth estimates from the model. To get the growth estimates it is required to solve a quadratic equation. Since the Department of economic development of IT City creates realistic models only, that quadratic equation has a solution, moreover there are exactly two different real roots. The greater of these roots corresponds to the optimistic scenario, the smaller one corresponds to the pessimistic one. Help to get these estimates, first the optimistic, then the pessimistic one. The only line of the input contains three integers *a*,<=*b*,<=*c* (<=-<=1000<=≤<=*a*,<=*b*,<=*c*<=≤<=1000) — the coefficients of *ax*2<=+<=*bx*<=+<=*c*<==<=0 equation. In the first line output the greater of the equation roots, in the second line output the smaller one. Absolute or relative error should not be greater than 10<=-<=6. Sample Input 1 30 200 Sample Output -10.000000000000000 -20.000000000000000
[ "a,b,c = map(int,input().split())\r\nif a < 0:\r\n a,b,c = -a,-b,-c\r\nprint((-b+(b*b-4*a*c)**0.5)/(2*a),(-b-(b*b-4*a*c)**0.5)/(2*a))", "a, b, c = map(int, input().split())\r\nf = lambda x : a * x ** 2 + b * x + c\r\nxv = -b / (2 * a)\r\nl1 = -1e12\r\nr1 = xv\r\nwhile (r1 - l1 > 1e-6):\r\n mid1 = (r1 + l1) / 2\r\n if (f(mid1) * f(r1) <= 0):\r\n l1 = mid1\r\n else:\r\n r1 = mid1\r\nr2 = 1e12\r\nl2 = xv\r\nwhile (r2 - l2 > 1e-6):\r\n mid2 = (r2 + l2) / 2\r\n if (f(mid2) * f(r2) <= 0):\r\n l2 = mid2\r\n else:\r\n r2 = mid2\r\nprint(l2, l1)", "a,b,c=map(int,input().split(' '))\r\nd=-b+(b**2-4*a*c)**0.5\r\ne=-b-(b**2-4*a*c)**0.5\r\nd/=(2*a)\r\ne/=(2*a)\r\nif d>e:\r\n print(d)\r\n print(e)\r\nelse:\r\n print(e)\r\n print(d)", "import math\na, b, c = map(int, input().split())\n\nx1 = (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)\nx2 = (-b - math.sqrt(b**2 - 4*a*c)) / (2*a)\n\nif x1 > x2:\n print(x1)\n print(x2)\nelse:\n print(x2)\n print(x1)\n \t\t \t\t\t\t \t \t\t \t \t\t \t\t\t \t", "a, b, c = map(int, input().split())\r\nd = (b ** 2 - 4 * a * c) ** 0.5\r\nx1 = (-b + d) / (2 * a)\r\nx2 = (-b - d) / (2 * a)\r\nprint(max(x1, x2), min(x1, x2), sep='\\n')\r\n", "a,b,c=map(int,input().split());b/=2*a;d=(b*b-c/a)**0.5;print(d-b,-b-d)", "a, b, c = map(int, input().split())\r\nb /= 2 * a\r\nd = (b * b - c / a) ** 0.5\r\nprint(d - b, - b - d)\r\n", "import math\r\n\r\na, b, c = map(int, input().split())\r\nx, y = (-b + math.sqrt(b ** 2 - 4 * a * c)) / (2 * a), (-b - math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)\r\nx, y = max(x, y), min(x, y)\r\nprint(\"{0:.12f}\".format(x), \"{0:.12f}\".format(y), sep='\\n')", "from math import sqrt\r\n\r\n\r\na, b, c = map(int, input().split())\r\n# -b +- root(b2 - 4ac) / 2a\r\nans1 = (-b + sqrt(b*b-4*a*c))/(2*a)\r\nans2 = (-b - sqrt(b*b-4*a*c))/(2*a)\r\nprint(\"%.15f\"%max(ans1,ans2))\r\nprint(\"%.15f\"%min(ans1,ans2))", "# /**\r\n# * author: brownfox2k6\r\n# * created: 16/08/2023 15:14:32 Hanoi, Vietnam\r\n# **/\r\n\r\na, b, c = map(int, input().split())\r\n\r\nx = (b**2 - 4*a*c) ** 0.5\r\nroots = [(-b+x)/(2*a), (-b-x)/(2*a)]\r\nroots.sort(reverse=True)\r\nprint(*roots, sep='\\n')" ]
{"inputs": ["1 30 200", "1 1 -1", "-1 1 1", "1000 1 -1", "-1 1000 1", "1000 1000 -999", "633 304 -186", "-181 -227 368", "-779 -814 321", "1 1 0", "1 0 -9"], "outputs": ["-10.000000000000000\n-20.000000000000000", "0.618033988749895\n-1.618033988749895", "1.618033988749895\n-0.618033988749895", "0.031126729201737\n-0.032126729201737", "1000.000999999000000\n-0.000999999000002", "0.617586685675881\n-1.617586685675881", "0.352747585783570\n-0.833000350396524", "0.930608581348335\n-2.184752227757175", "0.305204386055057\n-1.350133782717445", "0.000000000000000\n-1.000000000000000", "3.000000000000000\n-3.000000000000000"]}
UNKNOWN
PYTHON3
CODEFORCES
10
1e5d848978933dde5b192f0f60219f6d
Credit Card
Recenlty Luba got a credit card and started to use it. Let's consider *n* consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of *i*-th day a transaction *a**i* occurs. If *a**i*<=&gt;<=0, then *a**i* bourles are deposited to Luba's account. If *a**i*<=&lt;<=0, then *a**i* bourles are withdrawn. And if *a**i*<==<=0, then the amount of money on Luba's account is checked. In the morning of any of *n* days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed *d*. It can happen that the amount of money goes greater than *d* by some transaction in the evening. In this case answer will be «-1». Luba must not exceed this limit, and also she wants that every day her account is checked (the days when *a**i*<==<=0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her! The first line contains two integers *n*, *d* (1<=≤<=*n*<=≤<=105, 1<=≤<=*d*<=≤<=109) —the number of days and the money limitation. The second line contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (<=-<=104<=≤<=*a**i*<=≤<=104), where *a**i* represents the transaction in *i*-th day. Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money. Sample Input 5 10 -1 5 0 -5 3 3 4 -10 0 20 5 10 -5 0 10 -11 0 Sample Output 0 -1 2
[ "def main():\r\n n, d = map(int, input().split())\r\n a = list(map(int, input().split()))\r\n ans = 0\r\n cur = 0\r\n balance = 0\r\n lows = [0] * n\r\n rigs = [0] * n\r\n for i in range(n):\r\n balance += a[i]\r\n if a[i] == 0:\r\n lows[i] = -balance\r\n rigs[i] = d - balance\r\n for i in range(1, n):\r\n lows[i] = max(lows[i], lows[i - 1])\r\n for i in range(n - 2, -1, -1):\r\n rigs[i] = min(rigs[i], rigs[i + 1])\r\n for i in range(n):\r\n if lows[i] > rigs[i]:\r\n print(\"-1\")\r\n return\r\n if cur < lows[i]:\r\n cur = rigs[i]\r\n ans += 1\r\n print(ans)\r\nif __name__ == \"__main__\":\r\n main()# 1692038411.5287888", "n, d = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nl, u = 0, 0\r\nans = 0\r\nfor a in A:\r\n if a == 0:\r\n if u < 0:\r\n l = 0\r\n u = d\r\n ans += 1\r\n l = max(0, l)\r\n else:\r\n u = min(d, u+a)\r\n l += a\r\n if l > d:\r\n print(-1)\r\n exit()\r\nprint(ans)\r\n", "n, d = map(int, input().split())\na = [0] + list(map(int, input().split()))\nb = [0] * (n + 2)\nb[n] = a[n]\nnow = a[n]\nfor i in range(n - 1 , 0 , -1):\n now = a[i] + max(now, 0)\n b[i] = now\nnow = 0\nres = 0\nfor i in range(1 , n + 1):\n if a[i] == 0:\n if now < 0:\n res += 1\n now = min(d, max(0, d - b[i + 1]))\n else:\n now += a[i]\n if now > d:\n res = -1\n break\nprint(res)\n\n\n \t \t \t\t \t\t\t\t \t \t\t \t \t\t\n\t \t\t \t\t\t \t \t \t \t\t \t\t\t \t\t", "H,L,t=0,0,0\r\nn,d=map(int,input().split())\r\nfor i in map(int,input().split()):\r\n if i==0:\r\n if H<0:H=d;t+=1\r\n L=max(L,0)\r\n L+=i\r\n H=min(d,H+i)\r\n if L>d:exit(print(-1))\r\nprint(t)" ]
{"inputs": ["5 10\n-1 5 0 -5 3", "3 4\n-10 0 20", "5 10\n-5 0 10 -11 0", "5 13756\n-2 -9 -10 0 10", "20 23036\n-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1", "12 82016\n1 -2 -1 -1 -2 -1 0 -2 -1 1 -2 2", "7 8555\n-2 -3 -2 3 0 -2 0", "16 76798\n-1 11 -7 -4 0 -11 -12 3 0 -7 6 -4 8 6 5 -10", "20 23079\n0 1 1 -1 1 0 -1 -1 0 0 1 -1 1 1 1 0 0 1 0 1", "19 49926\n-2 0 2 0 0 -2 2 -1 -1 0 0 0 1 0 1 1 -2 2 2", "19 78701\n1 0 -1 0 -1 -1 0 1 0 -1 1 1 -1 1 0 0 -1 0 0", "10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2", "9 13\n6 14 19 5 -5 6 -10 20 8", "8 11\n12 -12 -9 3 -22 -21 1 3", "8 26\n-4 9 -14 -11 0 7 23 -15", "5 10\n-8 -24 0 -22 12", "10 23\n9 7 14 16 -13 -22 24 -3 -12 14", "8 9\n6 -1 5 -5 -8 -7 -8 -7", "3 14\n12 12 -8", "9 9\n-3 2 0 -2 -7 -1 0 5 3", "4 100\n-100 0 -50 100", "9 5\n-2 0 3 -4 0 4 -3 -2 0", "7 4\n-6 0 2 -3 0 4 0", "6 2\n-2 3 0 -2 0 0", "1 1\n2", "5 4\n-1 0 -3 0 3", "7 3\n1 -3 0 3 -1 0 2", "4 4\n2 2 0 1", "6 1\n-3 0 0 0 -2 3", "1 1\n1", "2 3\n2 0", "5 4\n-1 0 0 1 -1", "6 4\n-1 0 2 -4 0 5"], "outputs": ["0", "-1", "2", "1", "1", "1", "1", "1", "0", "1", "1", "1", "-1", "-1", "-1", "1", "-1", "-1", "-1", "2", "1", "1", "1", "1", "-1", "1", "-1", "-1", "1", "0", "0", "1", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
4
1e69e3da1ef219365379e87e1145a53c
Crosses
There is a board with a grid consisting of *n* rows and *m* columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number *i* and column number *j* as (*i*,<=*j*). A group of six numbers (*a*,<=*b*,<=*c*,<=*d*,<=*x*0,<=*y*0), where 0<=≤<=*a*,<=*b*,<=*c*,<=*d*, is a cross, and there is a set of cells that are assigned to it. Cell (*x*,<=*y*) belongs to this set if at least one of two conditions are fulfilled: - |*x*0<=-<=*x*|<=≤<=*a* and |*y*0<=-<=*y*|<=≤<=*b* - |*x*0<=-<=*x*|<=≤<=*c* and |*y*0<=-<=*y*|<=≤<=*d* Your task is to find the number of different groups of six numbers, (*a*,<=*b*,<=*c*,<=*d*,<=*x*0,<=*y*0) that determine the crosses of an area equal to *s*, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (*x*,<=*y*) of the cross 1<=≤<=*x*<=≤<=*n*; 1<=≤<=*y*<=≤<=*m* holds). The area of the cross is the number of cells it has. Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points. The input consists of a single line containing three integers *n*, *m* and *s* (1<=≤<=*n*,<=*m*<=≤<=500, 1<=≤<=*s*<=≤<=*n*·*m*). The integers are separated by a space. Print a single integer — the number of distinct groups of six integers that denote crosses with area *s* and that are fully placed on the *n*<=×<=*m* grid. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Sample Input 2 2 1 3 4 5 Sample Output 4 4
[ "from sys import stdin\r\ndef read(): return map(int, stdin.readline().split())\r\n\r\n\r\ndef ways(h,w,area):\r\n if area == h*w:\r\n return 2 * ( (h+1)//2 * (w+1)//2 ) - 1\r\n if area > h*w: return 0\r\n if area < h+w-1: return 0\r\n \r\n area = h*w - area\r\n if area % 4 != 0: return 0\r\n area //= 4\r\n \r\n ans = 0\r\n h //= 2\r\n w //= 2\r\n for a in range(1,h+1):\r\n if area%a == 0 and area//a <= w:\r\n ans += 1\r\n return ans*2\r\n \r\nn, m, s = read()\r\nans = 0\r\nfor h in range(1,n+1,2):\r\n for w in range(1,m+1,2):\r\n ans += ways(h,w,s) * (n-h+1) * (m-w+1)\r\nprint(ans)\r\n" ]
{"inputs": ["2 2 1", "3 4 5", "2 2 3", "5 1 3", "9 7 55", "5 10 25", "20 12 101", "21 10 155", "49 7 105", "74 99 5057", "9 10 5", "10 14 47", "6 14 23", "27 9 57", "20 17 319", "2 20 37", "10 4 33", "30 8 53", "48 76 2921", "2 78 117", "2 55 9", "56 54 2639", "72 65 2843", "32 71 297", "48 81 2573", "1 1 1", "100 100 5", "100 100 19", "20 20 8", "30 90 29", "100 100 199", "100 100 3421", "2 1 1", "1 2 1", "1 2 2", "2 1 2", "500 500 1", "500 499 3", "499 500 5", "499 499 5", "499 498 7", "500 500 9", "500 498 11", "498 500 13", "497 498 45", "500 499 93", "500 500 250000", "500 500 9999", "500 500 9997", "500 500 9001", "3 3 5", "500 500 249999", "500 500 249998", "500 500 249997", "500 500 249995", "500 500 249993", "500 500 6913", "500 500 4755", "500 500 2639", "500 500 2431", "500 500 11025"], "outputs": ["4", "4", "0", "9", "4", "102", "424", "36", "14229", "20000", "632", "256", "112", "3435", "4", "0", "0", "896", "1288", "0", "846", "392", "25704", "507408", "9380", "1", "115208", "550416", "0", "145304", "1788896", "723136", "2", "2", "0", "0", "250000", "1491006", "2970032", "2964068", "4419230", "7640108", "8304516", "9728792", "74632432", "143189600", "0", "4540761776", "1380438648", "1254836160", "2", "0", "0", "0", "0", "0", "2147074656", "2145363424", "2141188528", "2137019440", "10736521384"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1e6b1ebdeec5065319d5165cebc63f4d
Robbers' watch
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in *n* hours, and each hour in *m* minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to *n*<=-<=1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to *m*<=-<=1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation. Note that to display number 0 section of the watches is required to have at least one place. Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number. The first line of the input contains two integers, given in the decimal notation, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of hours in one day and the number of minutes in one hour, respectively. Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct. Sample Input 2 3 8 2 Sample Output 4 5
[ "def D(n):\r\n\tx,r=n-1,1\r\n\twhile x>=7:\r\n\t\tx//=7\r\n\t\tr+=1\r\n\treturn r\r\ndef H(n,l):\r\n\tx,r=n,\"\"\r\n\tif x==0:r+='0'\r\n\twhile x:\r\n\t\tr+=chr(ord('0')+x%7)\r\n\t\tx//=7\r\n\tr+='0'*(l-len(r))\r\n\treturn r\r\na,b=map(int,input().split())\r\nla=D(a)\r\nlb=D(b)\r\nV=[0]*99\r\nr=0\r\ndef F(deep,wa,wb):\r\n\tglobal r\r\n\tif wa>=a or wb>=b:return\r\n\tif deep==la+lb:\r\n\t\tr+=1\r\n\t\treturn\r\n\ti=-1\r\n\twhile i<6:\r\n\t\ti+=1\r\n\t\tif V[i]:continue\r\n\t\tV[i]=1\r\n\t\tif deep>=la:\r\n\t\t\tF(deep+1,wa,wb+i*(7**(lb-1-(deep-la))))\r\n\t\telse:\r\n\t\t\tF(deep+1,wa+i*(7**(la-1-deep)),wb)\r\n\t\tV[i]=0\r\nif la+lb<8:F(0,0,0)\r\nprint(r)\r\n", "from itertools import permutations\r\n\r\ndef find_power(n):\r\n res = 1\r\n n = n // 7\r\n while n > 0:\r\n n //= 7\r\n res +=1\r\n return res\r\n\r\na, b = list(int(x) for x in input().split())\r\nx = find_power(a-1)\r\ny = find_power(b-1)\r\nres = 0\r\nif x + y > 7:\r\n print(0)\r\n exit()\r\nfor i in permutations('0123456', x + y):\r\n s = ''.join(list(i))\r\n p, q = int(s[:x], 7), int(s[x:], 7)\r\n if p <= a-1 and q <= b-1:\r\n res += 1\r\nprint(res)\r\n", "from itertools import *\r\ndef f(x):\r\n x -= 1\r\n ret = 0\r\n if x == 0:\r\n ret = 1\r\n else:\r\n while x != 0:\r\n ret += 1\r\n x //= 7\r\n return ret\r\n\r\ndef g(d):\r\n ret = 0\r\n for v in d:\r\n ret = ret * 7 + v\r\n return ret\r\n\r\n\r\n\r\nn, m = map(int, input().split())\r\na = f(n)\r\nb = f(m)\r\nif a + b > 7:\r\n print(0)\r\nelse:\r\n ans = 0\r\n for p in permutations(range(7), a + b):\r\n if g(p[:a]) < n and g(p[a:]) < m:\r\n ans += 1\r\n print(ans)\r\n\r\n\r\n", "from itertools import permutations\nfrom math import ceil, log\n\nn, m = t = list(map(int, input().split()))\nl, _ = t = [ceil(log(x, 7.)) if x > 1 else 1 for x in t]\nprint(sum(int(s[:l], 7) < n and int(s[l:], 7) < m for s in map(''.join, permutations(\"0123456\", sum(t)))))\n", "from collections import Counter\r\n\r\ndef getd(n):\r\n v = 1\r\n while n > 7 ** v:\r\n v += 1\r\n return v\r\n\r\ndef getb(n, d):\r\n v = 0\r\n for i in range(d):\r\n b = 1 << (n % 7)\r\n if v & b:\r\n return 0\r\n v |= b\r\n n //= 7\r\n return v\r\n\r\ndef getc(n, d):\r\n c = Counter()\r\n for i in range(n):\r\n cb = getb(i, d)\r\n if cb:\r\n c[cb] += 1\r\n return c\r\n\r\nx, y = map(int, input().split())\r\nxd, yd = getd(x), getd(y)\r\nif xd + yd > 7:\r\n print(0)\r\n exit()\r\nxc, yc, v = getc(x, xd), getc(y, yd), 0\r\nfor xi in xc:\r\n for yi in yc:\r\n if xi & yi == 0:\r\n v += xc[xi] * yc[yi]\r\nprint(v)", "from itertools import permutations\r\nfrom math import ceil, log\r\n\r\nnn, m = t = list(map(int, input().split()))\r\nl, _ = t = [ceil(log(x, 7.)) if x > 1 else 1 for x in t]\r\nprint(sum(int(s[:l], 7) < nn and int(s[l:], 7) < m for s in map(''.join, permutations(\"0123456\", sum(t)))))\r\n", "# Author: Akash Kumar\r\n\r\nfrom itertools import permutations\r\n\r\nbase = 7\r\ndef log(x, base):\r\n r = (x==0)\r\n while x != 0:\r\n r += 1\r\n x //= base\r\n return r\r\n\r\n# Input\r\nn ,m = map(int,input().split())\r\n\r\nln = log(n-1, base)\r\nlm = log(m-1, base)\r\n\r\nres = 0\r\nfor i in permutations('0123456', ln+lm):\r\n i = ''.join(i)\r\n res += int(i[:ln], base) < n and int(i[ln:], base) < m\r\n\r\nprint(res)", "from itertools import permutations\r\nn, m = map(int, input().split())\r\nt1 = 1; t2 = 1;\r\nwhile 7 ** t1 < n: t1 += 1\r\nwhile 7 ** t2 < m: t2 += 1\r\ncount = 0\r\n\r\nfor perm in permutations(list('0123456'), t1 + t2):\r\n a = int(''.join(perm[:t1]), 7)\r\n b = int(''.join(perm[t1:t1 + t2]), 7)\r\n if a < n and b < m:\r\n count += 1\r\nprint(count)", "from itertools import permutations as p\r\n\r\n\r\ndef length_base_7(ele, arr):\r\n if not ele:\r\n arr.append(0)\r\n return 1\r\n length = 0\r\n while ele:\r\n arr.append(ele % 7)\r\n ele //= 7\r\n length += 1\r\n return length\r\n\r\n\r\nn, m = map(int, input().split())\r\nn -= 1\r\nm -= 1\r\n\r\nn_base7, m_base7 = [], []\r\nn_length, m_length = length_base_7(n, n_base7), length_base_7(m, m_base7)\r\n\r\nn_base7, m_base7 = n_base7[::-1], m_base7[::-1]\r\n\r\ncombination_number = {0, 1, 2, 3, 4, 5, 6}\r\nres = 0\r\nfor i in p(combination_number, n_length):\r\n if list(i) <= n_base7:\r\n for j in p(combination_number - set(i), m_length):\r\n if list(j) <= m_base7:\r\n res += 1\r\n\r\nprint(res)\r\n", "BASE = 7\r\n\r\ndef itov(x):\r\n if x == 0: return [0]\r\n digits = []\r\n while x > 0:\r\n digits.append(x % BASE)\r\n x //= BASE\r\n digits.reverse()\r\n return digits\r\n\r\ndef dfs(pos=0,minute=False,smaller=False):\r\n max_val = max_minute if minute else max_hour\r\n if pos>=len(max_val):\r\n return 1 if minute else dfs(0,True)\r\n ans = 0\r\n for d in range(BASE):\r\n valid = smaller or d<=max_val[pos]\r\n small = smaller or d< max_val[pos]\r\n if free[d] and valid:\r\n free[d]=False\r\n ans += dfs(pos+1,minute,small)\r\n free[d]=True\r\n return ans\r\n\r\nn, m = map(int, input().split())\r\nn -= 1\r\nm -= 1\r\nfree = [True] * BASE\r\nmax_hour = itov(n)\r\nmax_minute = itov(m)\r\nprint(dfs())\r\n", "from itertools import permutations\n\nn, m = map(int, input().split())\n\ndef S(x):\n if x == 0:\n return 1\n res = 0\n while x > 0:\n x //= 7\n res += 1\n return res\n\n\na, b = S(n - 1), S(m - 1)\n\nif a + b > 7:\n print(0)\n exit()\n\nD = list(range(7))\n\nres = 0\n\nfor v in permutations(D, a):\n\n x = 0\n for i in range(a):\n x = 7 * x + v[i]\n\n if x >= n:\n continue\n\n R = [d for d in D if d not in v]\n\n for u in permutations(R, b):\n y = 0\n for i in range(b):\n y = 7 * y + u[i]\n\n res += y < m\n\nprint(res)\n", "BASE = 7\r\n\r\ndef itov(x):\r\n digits = []\r\n if x == 0:\r\n digits.append(0)\r\n while x > 0:\r\n digits.append(x % BASE)\r\n x //= BASE\r\n digits.reverse()\r\n return digits\r\n\r\ndef gen(pos = 0, minute = False, smaller = False):\r\n max_val = max_minute if minute else max_hour\r\n if pos >= len(max_val):\r\n if minute:\r\n return 1\r\n else:\r\n return gen(0, True)\r\n else:\r\n ans = 0\r\n for digit in range(BASE):\r\n if not used[digit] and (smaller or digit <= max_val[pos]):\r\n used[digit] = True\r\n ans += gen(pos + 1, minute, smaller or digit < max_val[pos])\r\n used[digit] = False\r\n return ans\r\n\r\nn, m = map(int, input().split())\r\nn -= 1\r\nm -= 1\r\nused = [False] * BASE\r\nmax_hour = itov(n)\r\nmax_minute = itov(m)\r\nprint(gen())", "from itertools import *\nfrom math import *\nn, m = map(int, input().split())\nx, y = (max(1, ceil(log(k, 7))) for k in [n, m])\np = [''.join(t) for t in permutations('0123456', x + y)]\nprint(0 if x + y > 7 else sum(int(t[:x], 7) < n and int(t[x:], 7) < m for t in p))", "import math\n\ndef digits(x, k):\n d = [False] * 7\n for i in range(k):\n if d[x%7]:\n return False\n d[x%7] = True\n x //= 7\n return True\n \ndef solve(n, m):\n if n*m > 7**7:\n return 0\n k1 = math.ceil(math.log(n, 7)) if n > 1 else 1\n k2 = math.ceil(math.log(m, 7)) if m > 1 else 1\n s = 0\n for i in range(n):\n for j in range(m):\n s += digits(i * 7 ** k2 + j, k1 + k2)\n return s\n\n\nn, m = map(int, input().split())\nprint(solve(n, m))\n" ]
{"inputs": ["2 3", "8 2", "1 1", "1 2", "8 8", "50 50", "344 344", "282475250 282475250", "8 282475250", "1000000000 1000000000", "16808 7", "2402 50", "343 2401", "1582 301", "421414245 4768815", "2401 343", "2 1", "282475250 8", "8 7", "50 7", "16808 8", "2402 49", "123 123", "123 456", "1 9", "1 10", "50 67", "7 117649", "2400 342", "2400 227", "117648 5", "16808 41", "3 16808", "823542 3", "3 823544", "117650 5", "50 50", "50 3", "2402 343"], "outputs": ["4", "5", "0", "1", "0", "0", "0", "0", "0", "0", "720", "0", "5040", "2874", "0", "5040", "1", "0", "35", "120", "0", "720", "360", "150", "0", "1", "6", "5040", "5040", "3360", "3600", "0", "240", "0", "0", "0", "0", "40", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
14
1e74392cb55352ace00ff81a62ba0aa3
Calculating Function
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Print *f*(*n*) in a single line. Sample Input 4 5 Sample Output 2 -3
[ "S0l=int(input())\r\nif S0l%2==0:\r\n print(S0l//2)\r\nelse:\r\n print(S0l//2-S0l)", "y = int(input())\r\nprint(y//2-y * (y%2))", "n = int(input())\r\nif n%2 != 0:\r\n val = -(n + 1) / 2\r\nelse:\r\n val = n/2\r\nprint(int(val))", "f=int(input())\r\nprint(f//2-f*(f%2))", "n: int = int(input())\r\n\r\nans = (n // 2) - [0, n][n % 2]\r\n\r\nprint(ans)", "import math\r\nn=int(input())\r\nif (n%2 ==0):\r\n ans = n/2\r\nif (n%2 == 1):\r\n ans = math.floor(-n/2)\r\nprint(int(ans))", "n = int(input())\r\nif n&1:\r\n print(-(n+1)//2)\r\nelse:\r\n print(n//2)\r\n", "n=int(input())\r\nk=n//2\r\nif n%2==1:\r\n k=(n+1)//2\r\n print(-k)\r\nelse:\r\n print(k)\r\n\r\n ", "n = int(input())\r\ns = 0 \r\nif n%2 == 0:\r\n s = n//2\r\nelse:\r\n s = n // 2 + 1 \r\n s = -s \r\nprint(s)", "N = int(input())\r\nif N%2 == 0:Ans = N//2\r\nelse:Ans = -(N//2 + 1)\r\nprint(Ans)", "# import sys \n# sys.stdin = open(\"/Users/swasti/Desktop/coding/cp/codeforces/input.txt\", \"r\")\n# sys.stdout = open(\"/Users/swasti/Desktop/coding/cp/codeforces/output.txt\", \"w\")\n\nn = int(input())\nif n%2==0:\n print( n//2)\nelse:\n prev = (n-1)//2\n print(prev-n)\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Sep 22 16:46:00 2023\r\n\r\n@author: 2300011413\r\n\"\"\"\r\n\r\nn=int(input())\r\nif n%2==0:\r\n print(n//2)\r\nelse:\r\n print((n-1)//2-n)", "n = int(input())\r\ntotal = 0\r\n\r\nif n%2==0:\r\n total = n//2\r\nelse:\r\n total = ((n+1)//2)* (-1)\r\n\r\nprint(total)", "N = int(input())\r\nif(N%2==0):\r\n print(N//2)\r\nelse:\r\n print((N//2)-N)", "\"\"\"\r\n@auther:Abdallah_Gaber \r\n\"\"\"\r\n\r\nn = int(input())\r\nif n %2 == 0:\r\n print(int(n/2))\r\nelse:\r\n print(int(n/2)-n)\r\n\r\n", "n = int(input(\"\"))\r\n\r\nif n%2 == 0:\r\n result = (n//2)\r\n print(result)\r\n\r\nelif n%2 != 0:\r\n result = (n//2)-n\r\n print(result)", "def solve(n):\r\n # return sum(-i if i % 2 == 1 else i for i in range(1, n+1))\r\n if n % 2 == 0:\r\n # If n is even, the result is n/2.\r\n result = n // 2\r\n else:\r\n # If n is odd, the result is -(n+1)//2.\r\n result = -((n + 1) // 2)\r\n return result\r\n \r\n\r\n\r\n\r\ndef main():\r\n\r\n n = int(input().strip()) # int values\r\n print(solve(n))\r\n\r\nif __name__ == \"__main__\":\r\n main()", "number=int(input())\nif number%2==1:\n print(-1*(number+1)//2)\nelse:\n print(number//2)\n \t\t\t \t\t \t \t\t \t\t \t\t \t", "n = int(input())\r\n\r\neven = n//2\r\nif n%2 != 0:\r\n odd = n//2 + 1\r\nelse:\r\n odd = n//2\r\nsum = (even**2+even) - (odd**2) \r\n\r\nprint(sum)", "n = int(input())\r\n\r\n# If n is even, f(n) = n/2\r\n# If n is odd, f(n) = -((n + 1) // 2)\r\nif n % 2 == 0:\r\n result = n // 2\r\nelse:\r\n result = -((n + 1) // 2)\r\n\r\nprint(result)\r\n", "n=int(input())\r\nif(n%2==0):\r\n output=((n//2)*((n//2)+1))-((n//2)**2)\r\nelse:\r\n output=(((n**2)-1)//4)-(((n+1)//2)**2)\r\nprint(output)", "n=int(input())\r\nif n%2==0:\r\n result=n//2\r\nelse:\r\n result=-((n+1)//2)\r\nprint(result)", "number_repetition = int(input())\r\nif number_repetition % 2 == 0: print(number_repetition // 2)\r\nelse: print(number_repetition // 2 - number_repetition)", "n=int(input())\r\nif n%2==0:\r\n b=n//2\r\n a=n//2\r\nelse:\r\n b=n//2+1\r\n a=n//2\r\neven_sum=a*(a+1)\r\nodd_sum=b**2\r\nprint(even_sum-odd_sum)", "a = int(input())\r\nif a % 2 != 0:\r\n u = -1*(a // 2 + 1)\r\nelse:\r\n u = a // 2\r\nprint(u)", "n=int(input())\nif n%2==0:\n print(int(n/2))\nelse :\n print(int(n//2 - n))\n\n\n\n\n# -1 + 2 = 1\n# -1 + 2 + -3 + 4 = 2\n# -1 + 2 + -3 + 4 + -5 + 6 = 3\n# ceil(0.000000000001)=1\n# 0.1=1\n# -1 = -1\n# -1 + 2 + -3 =-2\n# -1 + 2 + -3 + 4 + -5 =-3\n#\n# even n/2\n# odd -(n//2)\n\n\n\n \t \t\t\t \t\t\t \t\t \t\t \t\t\t\t\t \t\t", "def CalculatingFunction():\r\n currentInteger = int(input())\r\n answer = 0\r\n #Number Even\r\n if (currentInteger % 2 == 0):\r\n answer += int(currentInteger/2)\r\n else:\r\n answer -= (int(currentInteger/2) + 1)\r\n print(answer)\r\nCalculatingFunction()", "n = int(input())\r\ne = n // 2\r\no = n - e\r\nprint(e * (e + 1) - o * o)\r\n", "# Решение задач проекта CODEFORSES, Задача 486A\r\n#\r\n# (C) 2023 Артур Ще, Москва, Россия\r\n# Released under GNU Public License (GPL)\r\n# email [email protected]\r\n# -----------------------------------------------------------\r\n\r\n'''\r\nA. Подсчёт функции\r\nограничение по времени на тест1 секунда\r\nограничение по памяти на тест256 мегабайт\r\nвводстандартный ввод\r\nвыводстандартный вывод\r\nДля положительного целого числа n определим функцию f:\r\n\r\nf(n) =  - 1 + 2 - 3 + .. + ( - 1)^n*n\r\n\r\nВаша задача — посчитать f(n) для данного целого числа n.\r\n\r\nВходные данные\r\nВ единственной строке записано положительное целое число n (1 ≤ n ≤ 10^15).\r\n\r\nВыходные данные\r\nВыведите f(n) в единственной строке\r\n'''\r\n\r\nfrom datetime import datetime\r\nimport time\r\nstart_time = datetime.now()\r\nimport functools\r\nfrom itertools import *\r\nfrom collections import Counter\r\nimport random\r\nimport math\r\n\r\na1=int(input())\r\nans = (a1 + 1)//2\r\nif a1%2 ==1: ans =ans * (-1)\r\nprint(ans)", "n = int(input())\r\n\r\nif n % 2 == 0: value = n/2\r\nelse: value = -1*((n+1)/2)\r\n\r\nprint(int(value))", "n=int(input())\r\nif n%2==0:\r\n k=n//2\r\nelse:\r\n k=((n-1)//2)-n\r\nprint(k)", "n = int(input())\r\ns = n // 2\r\nif n % 2 == 1:\r\n s -= n\r\nprint(s)", "def f(n):\r\n sum = 0\r\n if (n % 2):\r\n sum -= (int((n + 1) / 2))\r\n else:\r\n sum += (int(n / 2))\r\n print(sum)\r\nf(int(input())) ", "n = int(input())\r\nif (n%2==0):\r\n print(int(n/2))\r\nelse:\r\n n=int(((n+1)/2)-(n+1))\r\n print(n)\r\n", "n=int(input())\r\nprint((n//2)-n*(n%2))", "n = int(input())\nif n%2 ==0:\n print(int(n/2))\nelse:\n print(n//2-n)\n", "def calculate(n):\r\n if n%2==0:\r\n return n//2\r\n else:\r\n return -((n+1)//2)\r\nn=int(input())\r\nprint(calculate(n))", "n = int(input())\r\nprint(n // 2 - n if n % 2 else n // 2)", "first = int(input())\r\n\r\nif first % 2 == 0:\r\n print(int(first / 2))\r\nelse:\r\n print(int(-(first + 1) / 2))\r\n\r\n", "n = int(input())\r\nc = 0\r\n\r\nif n%2 == 0:\r\n c = n/2\r\nelse:\r\n c = (n//2) - n\r\n\r\nprint(int(c))", "san = int(input())\r\nif san%2==0:\r\n print(san//2)\r\nelse: print(-1*(san//2+1))", "n=int(input())\r\nif n%2:print(n//2-n)\r\nelse:print(n//2)", "def fg():\r\n return int(input())\r\ndef fgh():\r\n return[int(xx) for xx in input().split()]\r\ndef fgt():\r\n return map(int,input().split())\r\ndef fgs():\r\n return input()\r\nn=fg()\r\nif n%2==0:\r\n print(n//2)\r\n exit(0)\r\nprint(-((n+1)//2))", "num=int(input())\r\nres=1\r\nif num % 2 == 0:\r\n res = num / 2\r\nelse:\r\n res = -(num+1) / 2\r\n\r\nprint(int(res))", "import math as m\r\nf = int(input())\r\nif f%2==0:\r\n print(f//2)\r\nelse:\r\n print(-1*(m.ceil(f/2))) ", "n=int(input())\r\nans=0\r\nif n%2==0:\r\n ans=n//2\r\nelse:\r\n ans=-((n+1)//2)\r\nprint(ans)", "n = int(input())\nf = 0\nif n % 2 == 0:\n f = n // 2\nelse:\n f = (-n-1)//2\nprint(f)", "n = int(input())\r\nif n%2==0 or n==2:\r\n print(n//2)\r\nelse:\r\n print((n+1)//-2)", "n = int(input())\r\nk = n//2 + n%2\r\nk = 2*k**2\r\nn = (n*(n+1))//2\r\nprint(n-k)", "n = int(input())\r\n\r\nx = n//2\r\ny = x if n%2 == 0 else x+1\r\n\r\nf = x*(x+1) - y**2\r\nprint(f)\r\n ", "# ██████╗\r\n# ███ ███═█████╗\r\n# ████████╗ ██████╗ ████████╗ ████ █████ ████╗\r\n# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║\r\n# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝\r\n# ██╔═══╝ ██║ ██╗ ██╔═══╝ ███ ███╔══╝\r\n# ████████╗ ╚██████╔╝ ████████╗ ███ ██╔═╝\r\n# ╚═══════╝ ╚═════╝ ╚═══════╝ ███╔══╝\r\n# Legends ╚══╝\r\n\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nsum_odd = 0\r\nsum_even = 0\r\nif n & 1:\r\n sum_odd = -(((n + 1) // 2) ** 2)\r\n sum_even = (n // 2) ** 2 + n // 2\r\nelse:\r\n sum_odd = -((n // 2) ** 2)\r\n sum_even = (n // 2) ** 2 + n // 2\r\nprint(sum_odd + sum_even)\r\n", "def calculating_function(n):\n \n if (n % 2) == 0:\n print(n // 2)\n else:\n print(-((n // 2) + 1))\n\ncalculating_function(int(input()))\n\t \t \t \t \t \t\t \t \t\t \t\t", "import math\r\n\r\nn = int(input())\r\n\r\nresult = (-1) ** n * math.ceil(n / 2)\r\n\r\nprint(result)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Oct 27 11:06:08 2023\r\n\r\n@author: 10\r\n\"\"\"\r\n\r\nn=int(input())\r\nif n&1:\r\n print((n-1)//2-n)\r\nelse:\r\n print(n//2)", "n = int(input())\nresult = 0\njuft = 0\ntoq = 0\n\n# if n%2 == 0:\n# n /= 2\n# juft = (n/2)*(2*2+(n-1)*2)\n# toq = -1*((n/2)*(2*1+(n-1)*2))\n# result = juft + toq\n# print(int(result))\n# else:\n# nj = ((n-1)/2)\n# nt = nj+1\n# juft = (nj/2)*(2*2+(nj-1)*2)\n# toq = -1*((nt/2)*(2*1+(nt-1)*2))\n# result = juft + toq\n# print(int(result))\n\nif n % 2 == 0:\n if n>2:\n print(int(n/2))\n elif n==2:\n print(1)\n else:\n print(-1)\nelse:\n if n>2:\n result = (-1)*(int((n+1)/2))\n print(result)\n elif n == 2:\n print(1)\n else:\n print(-1) \n", "n = int(input())\r\nv = n // 2\r\nif n % 2 == 0:\r\n print(v)\r\nelse:\r\n print(v-n)\r\n", "n = int(input())\r\nans = 0\r\nif n % 2==0:\r\n ans = n/2\r\nelse:\r\n ans = -(n+1)/2\r\nprint(int(ans))", "f = int(input())\r\ns = f-1\r\nif f%2 == 0:\r\n print(int(f/2))\r\n\r\nelse:\r\n print(int(s/2-f))", "n=int(input())\r\nans=(n+1)//2\r\nif n%2 !=0:\r\n ans=(-ans)\r\nprint(ans)", "x = int(input())\r\nprint(int(x/2) if x % 2 == 0 else -int(x/2 + .5))", "n = int(input())\r\nif n%2 == 0:\r\n print(int(n/2))\r\nelif n%2 == 1:\r\n print(int(((-1)*(n+1))/2))", "n=int(input())\r\nif n%2==0: print(int(n/2))\r\nelse: print(int(-(n+1)/2))", "n = int(input())\r\nimport math\r\n\r\n\r\nif n%2 == 0:\r\n sum = math.floor(n/2)\r\n\r\nelse:\r\n ans = math.floor(n/2)\r\n sum = ans + ((-1)**n) * n\r\n \r\nprint(sum)", "t=int(input())\r\nif t%2==0:\r\n res=t//2\r\nelse:\r\n res=-((t+1)//2)\r\nprint(res)", "n = int(input())\r\nprint((n//2+n%2)*(-1 if n%2==1 else 1))\r\n", "a=int(input())\r\nb=0\r\nif a%2==0:\r\n b=a//2\r\nelse:\r\n b=-(a+1)//2\r\nprint(b)", "a=int(input())\r\nd=0\r\nif a%2==0:\r\n print(a//2)\r\nelse:\r\n d-=(a//2)+1\r\n print(d)", "number = int(input())\r\ntotal = 0\r\n\r\nif number % 2 == 0:\r\n total = number / 2\r\nelse:\r\n total = int(-1 * ((number / 2)+ 1))\r\nprint(int(total))\r\n", "n = int(input())\r\n\r\nif n%2 == 0:\r\n fn = n/2\r\nelse:\r\n fn = (n-1)/2-n\r\nprint(\"{:.0f}\".format(fn))", "t=int(input())\r\nif t%2==0:\r\n t=t//2\r\n print((t*(t+1))-(t**2))\r\nelse:\r\n t=t//2\r\n print((t*(t+1))-((t+1)**2))", "integer = int(input())\r\n\r\nif integer % 2 == 0:\r\n print(int(integer / 2))\r\nelse:\r\n print((integer // 2 + 1) * -1)", "y=int(input())\r\nprint((y//2+y%2)*(-1)**y)", "import math\r\nn=int(input())\r\nif n%2==0: f=math.ceil(n/2)\r\nelse: f=0-math.ceil(n/2)\r\nprint(f)", "n = int(input())\r\nans = ((n + 1) // 2) * (-1 if n & 1 else 1)\r\nprint(ans)", "n = int(input())\r\nn = n / 2 + (0 if n % 2 == 0 else -n-1)\r\nprint(int(n))", "import math\r\nn = int(input())\r\nif(n%2==0):\r\n print(int(n/2))\r\nelse:\r\n c = math.floor(-(n/2))\r\n a=int(c)\r\n print(a)", "n=int(input())\r\nif n%2==0:\r\n a=n//2\r\nelse:\r\n a=-(n//2+1)\r\nprint(a)", "# Calculating Function Difficulty:800\r\nn = int(input())\r\nif n % 2 == 0:\r\n f = n/2\r\nelse:\r\n f = (n-1)/2 - n\r\nprint(int(f))\r\n", "n = int(input())\r\nif n%2 == 0:\r\n sum = n//2\r\nelse:\r\n sum = -((n//2)+1)\r\nprint(sum)", "import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\n\nd_even = 2\nd_odd = -2\n\na_even = 2\na_odd = -1\n\nif n % 2 == 0:\n times = n // 2\n even_sum = times * (a_even + (d_even * (times - 1) // 2))\n odd_sum = times * (a_odd + (d_odd * (times - 1) // 2))\n\n result = even_sum + odd_sum\n sys.stdout.write(f\"{result}\")\n\nelse:\n even_times = n // 2\n odd_times = even_times + 1\n\n even_sum = even_times * (a_even + (d_even * (even_times - 1) // 2))\n odd_sum = odd_times * (a_odd + (d_odd * (odd_times - 1) // 2))\n result = even_sum + odd_sum\n\n sys.stdout.write(f\"{result}\")\n", "n = int(input())\r\nresult = (-1)**n * (n+1)//2\r\nprint(result)", "n=int(input())\r\nprint(-((-1)**(n-1)*(2*n+1)+1)//4)\n# Sat Oct 21 2023 18:56:56 GMT+0300 (Moscow Standard Time)\n", "a = int(input())\r\nif a % 2 == 0:\r\n print(int(a/2))\r\nelse:\r\n print(int((a+1)/(-2)))\r\n", "n=int(input())\r\nsum=0\r\nt=n*(n+1)//2\r\nif(n%2==0):\r\n o=n//2\r\n \r\n print(t-2*(o**2))\r\nelse:\r\n o=(n//2)+1\r\n print(t-2*(o**2))\r\n \r\n ", "a=int(input())\r\nif a%2==0:print(a//2)\r\nelse:print('-'+str(a//2+1))\r\n", "a = int(input())\r\nif a%2==0:\r\n print(a//2)\r\nelse:\r\n print(a//2-a)\n# Sat Oct 21 2023 19:29:20 GMT+0300 (Moscow Standard Time)\n", "import math\r\nn = int(input())\r\nif n % 2 == 0:\r\n print(n//2)\r\nelse:\r\n print((math.ceil(n/2))*(-1))", "def function(n):\r\n if n % 2 == 0:\r\n return n//2\r\n else:\r\n return n//2 - n\r\nprint(str(function(int(input()))))", "import math\n\nn=int(input())\nif n%2==0:\n print(n//2)\nelse:\n print(-1*math.ceil(n/2))\n\n\n \t\t\t \t\t \t \t \t\t \t\t\t\t \t\t\t\t\t\t", "num = int(input())\r\n\r\nif num % 2 == 0:\r\n print(int(num/2))\r\nelse: \r\n print(int(-(num+1)/2))", "def solve():\r\n n = int(input())\r\n if n%2 == 0:\r\n odd = n//2\r\n even = n//2\r\n else:\r\n odd = (n//2)+1\r\n even = (n//2)\r\n return (even**2+even) - odd**2\r\nprint(solve())\r\n", "n=int(input(\"\"))\r\nc=0\r\nif n%2==0:\r\n print(int(n/2))\r\nelse:\r\n print(-((n//2)+1))\r\n", "import math\nn = int(input())\nif n %2==0:\n print(n//2)\nelse:\n print(-1*math.ceil(n/2))\n \t\t \t\t \t\t \t \t\t\t \t\t\t\t \t \t", "x = int(input())\r\n\r\nq, r = x // 2, x % 2\r\n\r\nif r:\r\n print(-q - r)\r\nelse:\r\n print(q)", "from sys import stdin, stdout\r\n#from bisect import bisect_left, bisect_right\r\n#from collections import Counter, deque\r\n#from queue import Queue\r\n#import heapq\r\n#import math\r\n#from itertools import permutations, combinations, islice\r\n\r\ndef input():\r\n return stdin.readline().strip()\r\n\r\ndef solve():\r\n n = int(input())\r\n if n%2 == 0:\r\n return f\"{n//2}\"\r\n else:\r\n return f\"{-n + n//2}\"\r\n\r\nstdout.write(solve())", "n = int(input())\r\nprint(n // 2 - (n % 2) * n)", "x = int(input())\r\nif x%2==0:\r\n print (x//2)\r\nelse:\r\n print (-(x//2+1))", "n = int(input())\nfn = (-1)**n*(n+1)/2\nprint(int(fn))", "theResult=int(input())\r\n\r\nif theResult%2==0:\r\n print(theResult//2)\r\n\r\nelse:\r\n print(-((theResult+1)//2))\r\n", "n = int(input())\r\ns = 0\r\ne = (int(n/2)*(int(n/2)+1))\r\no = int(n/2)*int(n/2) if n%2==0 else int((n+1)/2)*int((n+1)/2)\r\ns = e - o\r\nprint(s)\r\n", "fn = int(input())\r\nsum = 0\r\n\r\nif fn % 2 == 0:\r\n sum = fn / 2\r\nelse:\r\n sum = ((fn + 1) /2 * (-1))\r\nprint(int(sum))", "def func(n):\r\n ans=n//2\r\n if n%2==0:\r\n return ans\r\n else:\r\n return -(ans+1)\r\nn=int(input())\r\nprint(func(n))", "from sys import stdin\r\ninput = stdin.readline\r\nn = int(input())\r\nif n & 1 == 1:\r\n print(-((n+1)//2))\r\nelse:\r\n print(n//2)\r\n", "a=int(input())\r\nimport math\r\nd=math.ceil(a/2)\r\nif a%2==0:\r\n print(a//2)\r\nelse:\r\n print(-d)", "n = int(input())\r\n\r\nif n % 2 != 0:\r\n res = - (n + 1) / 2\r\nelse:\r\n res = - n / 2 + n\r\n\r\nprint(int(res))\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Sep 7 10:40:54 2023\r\n\r\n@author: Lenovo\r\n\"\"\"\r\n\r\nn=int(input())\r\nf=0\r\nif n%2==0:\r\n f+=n//2\r\nelse:\r\n f=f+n//2-n\r\nprint(f)", "# https://codeforces.com/problemset/problem/486/A\r\nimport math\r\n\r\nn = int(input())\r\n\r\nif n % 2 == 0:\r\n print(n//2)\r\nelse:\r\n print(-((n+1)//2))\r\n", "s = int(input())\r\nif s % 2 == 0:\r\n f = s / 2\r\nelse:\r\n f = (s + 1) * (-1) / 2\r\nprint(int(f))", "import math\r\n\r\nx=int(input())\r\nif(x%2==0):\r\n print(x//2)\r\nelse:\r\n b=math.ceil(-x//2)\r\n print(b)", "from collections import Counter\r\nN = int(input())\r\nq = N // 2\r\nif q * 2 != N:\r\n q += 1\r\nprint(-q if N % 2 == 1 else q)\r\n", "n=int(input())\r\nif n%2==0:\r\n r=n // 2\r\nelse:\r\n r=-((n+1)//2)\r\nprint(r)\r\n", "\r\ndef function(n):\r\n if n % 2 == 0:\r\n return n // 2\r\n else:\r\n return -(n//2 + 1)\r\n\r\nprint(function(int(input())))", "def fun(x):\r\n if(int(x)%2==0):\r\n c=int(x)/2\r\n else:\r\n c=int(int(x)/2)-int(x)\r\n print(int(c))\r\n\r\ns = input()\r\nfun(s)\r\n", "import math\r\nn = int(input()) \r\nres = (-1)**n * math.ceil(n / 2)\r\nprint(res)", "n = int(input())\r\nif n%2: print((n-1)//2-n)\r\nelse: print(n//2)", "n=int(input())\n\nprint (int(n//2-n*(n%2)))\n \t \t\t \t\t\t \t \t\t\t \t \t\t\t \t", "n = int(input())\r\ns = 0\r\nif n % 2 == 0:\r\n s = n // 2\r\nelse:\r\n s = n // 2 - n\r\nprint(s)\r\n", "import sys\r\ndef I(): return int(sys.stdin.readline().rstrip())\r\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\r\ndef MI(): return map(int, sys.stdin.readline().rstrip().split())\r\ndef SI(): return sys.stdin.readline().rstrip()\r\n\r\n\r\ndef main():\r\n n = I()\r\n if n % 2 == 0:\r\n print(n//2)\r\n else:\r\n print(((n-1)//2) - n)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\r\nans = (n // 2 + n % 2) * (-1)**n\r\nprint(ans)", "n=int(input())\r\nif n%2==0:\r\n r=n//2\r\nelse:\r\n r=-(n+1)//2\r\nprint(r)", "# https://codeforces.com/problemset/problem/486/A\r\n\r\ndef code(n):\r\n\r\n result = n//2 if (n % 2 == 0) else -(n+1)//2\r\n return result\r\n\r\n\r\nn = int(input())\r\nresult = code(n)\r\nprint(result)\r\n\r\n", "T=int(input())\r\nif T%2==0:\r\n T=T//2\r\n print((T*(T+1))-(T**2))\r\nelse:\r\n T=T//2\r\n print((T*(T+1))-((T+1)**2))", "n = int(input())\r\nif n%2 == 0:\r\n print(n//2)\r\nelse:\r\n m = (n//2)\r\n print((m*(m+1)) - (m+1)**2)", "n = int(input())\r\nresult = (-1) ** n * ((n + 1) // 2)\r\nprint(result)\r\n", "n = int(input())\nif n%2==0:\n print(n//2)\nelse :print(-(n//2+1))\n\t \t\t\t \t \t\t \t \t \t\t\t\t \t\t\t\t", "n = int(input())\r\n\r\nif n % 2 == 0 :\r\n print(int(n/2))\r\nelse:\r\n print(-(int((n/2+1))))\r\n", "n1 = int(input()) \r\n\r\nif n1 % 2 == 0:\r\n \r\n result = n1 // 2\r\nelse:\r\n \r\n result = -(n1 + 1) // 2\r\n\r\nprint(result)\r\n", "a=int(input())\r\nb=a//2\r\nif a%2==0:\r\n\tprint (b)\r\nelse:\r\n\tprint (-(b+1))", "num = int(input())\r\nif num % 2 == 0:\r\n func = num // 2\r\nelse:\r\n func = -(num + 1) // 2\r\nprint(func)\r\n", "def solve():\r\n x = int(input())\r\n print(x//2 if x % 2 == 0 else -((x+1)//2))\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nwhile t:\r\n solve()\r\n t -= 1\r\n", "import math\r\nn = int(input())\r\nif n % 2 == 0:\r\n print(int(n/2))\r\nelse:\r\n print(-1*math.ceil(n/2))", "\r\n\r\nn=int(input())\r\nx=0\r\nif n%2==0:\r\n x+=n/2\r\nelse:\r\n x-=(n/2)+1\r\nprint(int(x))", "g=int(input())\r\nif(g%2==0):\r\n answer=(int)(g/2)\r\nelse:\r\n answer= (int)(-(g+1)/2)\r\nprint(answer)", "n=int(input());\r\nprint(n//2-n%2*n)", "n = int(input())\r\n\r\n# Get number of even and odd numbers\r\nx = n//2\r\ny = x if n%2 == 0 else x+1\r\n\r\n# Calculate function\r\nf = x*(x+1) - y**2\r\nprint(f)\r\n ", "n=int(input())\r\nprint(n//2 if n%2==0 else (n//2+n%2)*(-1))", "n = int(input())\n\nif(n % 2 == 0):\n a = n // 2\n even = a * (1 + a)\n odd = a ** 2\nelse:\n a = n // 2\n odd = (a + 1) ** 2\n even = a * (1 + a)\n \nprint(even - odd)\n \t \t \t\t\t \t\t\t\t \t \t\t\t\t\t\t\t\t", "n = int(input())\nans = 0\n\nif n % 2 == 0:\n print(int(n / 2))\nelse:\n print(int(-((n // 2) + 1)))", "n=int(input())\r\nif ((n%2)==0):\r\n print(int(n/2))\r\nelse:\r\n print(int((-1)*((n+1)/2)))", "# 486A - Calculating Function\r\n# https://codeforces.com/problemset/problem/486/A\r\n\r\n# Inputs:\r\n# 1) Número (N)\r\nn = int(input())\r\n\r\n# Resultado de la función\r\nresultado = 0\r\n\r\n# Realiza la función\r\nif(n % 2 == 0):\r\n print(n // 2)\r\nelse:\r\n print(-((n+1)//2))\r\n\r\n# for i in range(0,n+1):\r\n# resultado = resultado + (i * ((-1) ** i))\r\n\r\n# Imprime el resultado\r\n# print(resultado)", "num=int(input())\r\nif num%2==0:\r\n print(num//2)\r\nelse:\r\n print(-((num+1)//2))\r\n \r\n \r\n", "n = int(input())\r\n\r\n# Calculate f(n) based on whether n is even or odd\r\nif n % 2 == 0:\r\n # If n is even, f(n) is half of n\r\n result = n // 2\r\nelse:\r\n # If n is odd, f(n) is -(n+1)//2\r\n result = -(n + 1) // 2\r\n\r\nprint(result)\r\n", "import math\r\nn1=int(input())\r\nif n1%2==0:\r\n print(n1//2)\r\nelse:\r\n print(0-math.ceil(n1/2))", "net=int(input());print((-1)**net*net//2)", "n=int(input())\r\nif n%2==0:\r\n on=n//2\r\n so=-(on**2)\r\n se=on*(on+1)\r\n print(se+so)\r\nelse:\r\n on=(n//2)+1\r\n en=(n//2)\r\n so=-(on**2)\r\n se=en*(en+1)\r\n print(se+so)\r\n \r\n", "n = int(input())\r\nprint(((n+1)//2)*(-1)**(n%2))", "s=int(input())\r\nif(s%2==0):\r\n p=(int)(s/2)\r\nelse:\r\n p= (int)(-(s+1)/2)\r\nprint(p)", "n = int(input())\nresult = ((-1) ** n) * ((n + 1) // 2)\nprint(result)\n \t\t \t\t \t \t\t \t \t\t\t\t \t\t", "n=int(input())\r\nans=(n+1)//2\r\nif n%2 !=0:\r\n\tans=ans*-1\r\nprint(ans)", "num = int(input())\r\ntotal = 0\r\nif num % 2 != 0:\r\n total = (num - 1) / 2 - num\r\nelse:\r\n total = num / 2\r\nprint(int(total))\r\n", "a = int(input())\r\nif a % 2 == 0:\r\n print(a // 2)\r\nelse:\r\n print(-(a // 2 + 1))", "# m=int(input())\r\n# d=0\r\n# for i in range(1,m+1):\r\n# c=(-1)**i*i\r\n# d=d+c\r\n# print(d)\r\n\r\nm=int(input())\r\nif m%2==0:\r\n print(m//2)\r\nelse:\r\n print(-((m+1)//2))", "def calc():\r\n n = int(input())\r\n return n//2-n%2*n\r\nprint(calc())\r\n", "n=int(input())\r\nprint((n//2)-n%2*n)", "def main():\r\n n =int(input())\r\n if n%2==0:\r\n print(int(n/2))\r\n\r\n else:\r\n print(-int((n+1)/2))\r\n\r\n\r\nmain()", "def calculate_f(n):\r\n return n // 2 if n % 2 == 0 else -(n + 1) // 2\r\nn = int(input())\r\nresult = calculate_f(n)\r\nprint(result)", "t= int(input())\r\n\r\nif t % 2 == 0:\r\n res = t // 2\r\nelse:\r\n res = -(t // 2 + 1)\r\n \r\nprint(res)", "n = int(input())\r\ndef ff(n):\r\n if n%2==0:\r\n return n//2\r\n else:\r\n return -(n//2+1)\r\nprint(ff(n))", "# Calculating Function\r\nn = int(input())\r\nsum = 0\r\n\r\nif n % 2 != 0:\r\n suma_impares = ((n + 1) // 2) ** 2\r\n n -= 1\r\n suma_pares = (n // 2) * ((n // 2) + 1)\r\nelse:\r\n suma_pares = (n // 2) * ((n // 2) + 1)\r\n n -= 1\r\n suma_impares = ((n + 1) // 2) ** 2\r\n\r\nsum = suma_pares - suma_impares\r\nprint(sum)", "import math\r\na = int(input())\r\n\r\nif a % 2 == 0:\r\n s = a / 2\r\nelse:\r\n s = math.floor(a/2)-a\r\nprint(int(s))\r\n", "def f(n):\r\n # return sum((-1)**i * i for i in range(1, n+1))\r\n\r\n return (2 * (-1)**n * n + (-1)**n - 1) // 4\r\n\r\nresult = f(int(input()))\r\nprint(result)", "import math\r\nn=int(input())\r\nx=n//2*((n//2)+1)-math.ceil(n/2)**2\r\nprint(x)", "import math\r\nn = int(input())\r\n\r\nansw = math.ceil(n / 2)\r\nif n % 2 == 0:\r\n print(answ)\r\nelse:\r\n print(-answ) ", "q=int(input())\r\nprint(q//2-q%2*q)", "a = int(input())\r\nif a % 2 == 1:\r\n print(-1 * (a // 2 + a % 2))\r\nelse:\r\n print(a // 2 + a % 2)\r\n", "from math import *\r\nn = int(input())\r\nn1 = ceil((n*1.0)/2)\r\nif n%2==0 :\r\n print(n//2)\r\nelse :\r\n print(-n1)\r\n", "n=int(input())\r\nesum=n//2*(n//2+1)\r\nosum=n*(n+1)//2-esum\r\nprint(-osum+esum)", "n=int(input())\r\nif n%2!=0:\r\n n=n//2\r\n n=-n-1\r\n print(n)\r\nelse:\r\n print(n//2)", "n = int(input()) \r\n\r\nif n % 2 == 0:\r\n r = n // 2\r\nelse:\r\n r = -(n + 1) // 2\r\n\r\nprint(r)\r\n", "n=int(input())\r\nif n%2==0:\r\n s=n//2\r\nelse:\r\n s=-(n+1)//2\r\nprint(s)", "n=int(input())\r\nans=0\r\nif n%2==0: #для n-чётного\r\n ans+=((n+2)*n)//4\r\n ans-=(n**2)//4\r\nelse: #для n-нечетного\r\n ans-=((n+1)*((n//2)+1))//2\r\n ans+=((n+1)*(n//2))//2\r\nprint(ans)", "# URL: https://codeforces.com/problemset/problem/486/A\n\nn = int(input())\nans = (n + 1) // 2\nif n % 2 == 1:\n ans *= -1\nprint(ans)\n", "a = int(input())\r\nif a % 2:\r\n print(a // 2 * (-1) - 1)\r\nelse:\r\n print(a // 2)\r\n", "n=int(input())\r\ncount=0\r\nif n%2!=0:\r\n count-=(n-n//2)\r\nelse:\r\n count+=n//2\r\nprint(count)\r\n", "i=int(input())\r\nif i%2==0:\r\n print(i//2)\r\nelif i%2==1:\r\n print((i//2)-i)\r\n", "import math\r\nnum = int(input())\r\nres = 0\r\nif num%2 == 0:\r\n res = round(num/2)\r\nelse:\r\n res = -num//2 \r\n \r\n\r\nprint(res)", "n = int(input())\r\nk = 0\r\nif n%2==0:\r\n print(int(n/2))\r\nelse: print(int(-1*(n+1)/2))", "import math\r\na=int(input())\r\nc=0\r\nif a%2==0:\r\n print(a//2)\r\nelse:\r\n print(-(math.ceil(a/2)))\r\n", "import math\r\nn = int(input())\r\npairs = math.ceil(n / 2) * -1\r\nif n % 2 == 0 :\r\n pairs += n\r\nprint(pairs)", "num=int(input())\r\nif num%2==0:\r\n print(int(num/2))\r\nelse:\r\n print(int(((num+1)/2)*(-1)))", "w=int(input());print(w//2-w%2*w)", "n=int(input())\r\ns1=n*(n+1)//2\r\nif n%2==0:\r\n s2=(n//2)*(n//2)\r\nelse:\r\n s2=((n//2)+1)*((n//2)+1)\r\n\r\nprint(s1-2*s2) ", "n = int(input())\r\nx = n % 2\r\nif x == 0:\r\n print(int(n/2))\r\nelse:\r\n print(int((n+1)/(-2)))", "n = int(input())\r\nb = (-1) ** n * n\r\nif b % 2 != 0:\r\n print(((b + 1) // 2) - 1)\r\nelse:\r\n print(b // 2)", "N=input()\nN=int(N)\nif N %2==0:\n print(int(N/2))\nelse:\n print(int((N+1)/2*(-1)))\n\t \t \t\t \t\t\t \t \t \t \t", "import math\r\nn=int(input())\r\nres=(-1)**n*math.ceil(n/2)\r\nprint(res)", "z=int(input());print(z//2-z%2*z)\r\n", "n=int(input())\r\nc=n//2+1\r\nif n%2!=0:\r\n last=(n-1)//2\r\n print(last*(last+1)-c**2)\r\nelse:\r\n c-=1\r\n last=n//2\r\n print(last*(last+1)-c**2)", "n = int(input())\r\nif (n % 2 == 0):\r\n print(int(n/2))\r\nelse:\r\n prev = (n - 1) / 2\r\n print(int(prev - n))", "a=int(input());print(a//2 if a%2==0 else a//2-a)", "n = int(input())\r\nresult = n // 2 if n % 2 == 0 else -((n + 1) // 2)\r\nprint(result)\r\n", "n=int(input())\r\nsumm=0\r\nif n%2==0:\r\n summ=n//2\r\nelse:\r\n summ=-1*((n+1)//2)\r\nprint(summ)", "n = int(input())\r\neven = (n//2)*(n//2+1);\r\nodd = (n*(n+1)//2)-even;\r\nprint(even-odd);", "def solve(n):\r\n if n % 2 == 0:\r\n return n // 2\r\n return -((n+1)//2)\r\nprint(solve(int(input())))\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Sep 14 10:44:15 2023\r\n\r\n@author: Zinc\r\n\"\"\"\r\ns = 0\r\nn = int(input())\r\nprint(n//2-n%2*n)", "N=int(input())\r\nif N%2==0:\r\n\tprint(N//2)\r\nelse:\r\n\tprint(-(N+1)//2)", "N = int(input())\r\nif N % 2 == 0:\r\n print(int(N/2))\r\nelse:\r\n print(\"-\" + str(N//2+1))", "def calculate_f(n):\r\n if n%2==0:\r\n return n//2\r\n else:\r\n return -(n+1)//2\r\n \r\nn=int(input())\r\nresult=calculate_f(n)\r\nprint(result)", "def func(n :int) -> int:\r\n return n // 2 - (n if n % 2 == 1 else 0)\r\n\r\n\r\nprint(func(int(input())))", "m = int(input())\r\n\r\nif m % 2 == 0:\r\n result = m // 2\r\nelse:\r\n result = -(m // 2 + 1)\r\n\r\nprint(result)\r\n", "import sys\r\ninput=sys.stdin.readline\r\na=int(input())\r\nif a%2==1:\r\n print(-(a*(a+1)//2)//a)\r\nelse:\r\n print((a*(a+1)//2)//a)", "n = int(input())\nprint(int((n + 1 )/2) * -1 if n % 2 else int(n/2))", "n = int(input())\r\nsum = 0\r\n\r\nif n % 2 == 0:\r\n sum += n//2\r\nelse:\r\n sum += -((n//2)+1)\r\nprint(sum)", "n = int(input())\r\nif n%2==1:\r\n print(n//2+(-1)**n*n)\r\nelse:\r\n print(n//2)\r\n", "a = int(input())\r\nif a % 2 == 1:\r\n sum = -((a + 1) // 2)\r\nelse:\r\n sum = a // 2\r\n\r\nprint(sum)\r\n", "n = input()\r\nint_n = int(n)\r\nx = int_n//2\r\ny = x if int_n%2 == 0 else x+1\r\n\r\nf = x*(x+1) - y**2\r\nprint(f)", "n=int(input())\r\nif(n%2 == 0):\r\n print(int(n/2))\r\nelse:\r\n print(int((n + 1) / 2) * (-1))\r\n\r\n\r\n", "n = int(input())\r\n\r\nif n % 2 == 0:\r\n y = n/2\r\nelse:\r\n y = (n-1)/2 - n\r\nprint(int(y))", "def main():\r\n n = int(input())\r\n result = calculate_result(n)\r\n print(result)\r\ndef calculate_result(n):\r\n x = n % 2\r\n if x == 0:\r\n return int(n / 2)\r\n else:\r\n return int((n + 1) / (-2))\r\nmain()", "import math\r\nn=int(input())\r\nz=(n//2)*((n//2)+1)\r\ny=(((n+1)//2)*((((n+1)//2))+1))-((n+1)//2)\r\nm=y*-1\r\nprint(m+z)\r\n\r\n", "a=int(input())\r\nif a%2==0:\r\n b=a/2\r\nelse:\r\n b=(a*(-1)-1)/2\r\nprint(int(b))", "x=int(input())\r\nif x%2==0:\r\n print(int(x/2))\r\nelse:\r\n x+=1\r\n print(int(-(x/2)))", "n=int(input())\r\nif n%2!=0:\r\n x=(n+1)/2\r\n y=(-1)*x\r\nelse:\r\n y=n/2\r\n\r\nz=int(y)\r\nprint(z)", "n = int(input()) # Input n\n\nif n % 2 == 0:\n result = n // 2\nelse:\n result = (n - 1) // 2 - n\n\nprint(result)", "N = int(input())\r\nif N % 2 == 0:\r\n print(N // 2)\r\nelse:\r\n print(-(N + 1) // 2)", "range_ = int(input())\nsum = 0\n\nslice = int(range_ / 2)\nsum = slice * (slice + 1)\n\nif range_ % 2 == 0:\n sum -= slice * slice\nelse:\n sum -= (slice + 1) * (slice + 1)\n\nprint(sum)\n", "def Calculating_Function(number):\r\n if number % 2 == 0:\r\n return number // 2\r\n else:\r\n return -((number+1) // 2)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n number = int(input())\r\n print(Calculating_Function(number))", "n = int(input())\r\nif n % 2 == 0:\r\n s = (n+1) // 2\r\nelse:\r\n s = -((n+1) // 2)\r\nprint(s)", "n = int(input())\r\nif n % 2:\r\n res = n // 2 - n\r\nelse:\r\n res = n // 2\r\nprint(res)", "from sys import stdin\ninput = stdin.readline\n\n\nif __name__ == \"__main__\":\n n = int(input())\n x = n % 2 != 0\n n += x\n print(f\"{['', '-'][x]}{n//2}\")\n\n \t \t \t \t \t\t \t \t\t \t \t\t", "k=int(input())\r\nif k%2==0:\r\n print(k//2)\r\nelse:\r\n print((k+1)//2-k-1)\r\n", "x = int(input())\r\nif x % 2 == 1:\r\n print(int((x-1)/2-x))\r\nelse:\r\n print(int(x/2))", "n = int(input())\r\nans = (n + 1)// 2\r\nif n%2 != 0:\r\n ans = -ans\r\nprint(ans)", "import math\r\n\r\ndef calc_func(number):\r\n\tif number % 2 != 0:\r\n\t\treturn math.ceil(number/2) * -1\r\n\telse:\r\n\t\treturn int(number/2)\r\n\r\nprint(calc_func(int(input())))", "n = int(input())\r\nsum=n//2\r\nif n%2==1:\r\n sum=-sum-1\r\nprint(sum)", "# import sys \n# sys.stdin = open(\"/Users/swasti/Desktop/coding/cp/codeforces/input.txt\", \"r\")\n# sys.stdout = open(\"/Users/swasti/Desktop/coding/cp/codeforces/output.txt\", \"w\")\n\n\ndef solve(n):\n if n%2==0:\n return n//2\n else:\n prev = (n-1)//2\n return prev-n\nif __name__ == \"__main__\":\n n = int(input())\n print (solve(n))", "nj=int(input())\r\nif nj%2==0:\r\n print(nj//2)\r\nelse:\r\n print(-((nj+1)//2))", "n = int(input())\r\nanswer = 0\r\n\r\n\r\nif (n%2 ==0):\r\n answer = (-1*pow(n//2,2)) + ((n//2)*(n//2+1))\r\nelse:\r\n answer = (-1*pow((n+1)//2,2)) + (((n-1)//2)*((n-1)//2+1))\r\n\r\nprint(int(answer))", "def cal(n):\r\n if n % 2 == 0:\r\n return n//2\r\n else:\r\n return -(n+1)// 2\r\nn = int(input())\r\nres = cal(n)\r\nprint(res)\r\n", "a=int(input())\r\nif a%2==0:\r\n a=a//2\r\n print((a*(a+1))-(a**2))\r\nelse:\r\n a=a//2\r\n print((a*(a+1))-((a+1)**2))", "n = int(input())\n\nodd_numbers = ((n//2) + (n % 2))**2\neven_numbers = (n//2)*((n//2) + 1)\n\nprint(even_numbers - odd_numbers)", "x=int(input())\r\nif x%2==0:\r\n print(x//2)\r\nelse:\r\n print((x//2)-x)", "# Read the input integer n\r\nn = int(input())\r\n\r\n# Calculate f(n)\r\nresult = (-1) ** n * ((n + 1) // 2)\r\n\r\n# Output the result\r\nprint(result)\r\n", "n = int(input()) # Read the input integer n\r\nresult = 0\r\n\r\nif n % 2 == 0:\r\n # If n is even, the result is n / 2\r\n result = n // 2\r\nelse:\r\n # If n is odd, the result is -((n + 1) // 2)\r\n result = -((n + 1) // 2)\r\n\r\nprint(result) # Print the result\r\n", "n = int (input())\nif n % 2 :\n print (int ((n//2) - n))\nelse :\n print (int (n/2))\n\t\t \t\t \t \t \t \t\t \t\t\t \t\t\t\t \t", "num =int(input())\nsum=0\nif num%2==0: print(num//2)\nelse :print((-num//2))\n\n \t\t \t \t\t\t \t \t\t \t \t\t \t\t", "def Calculate(n):\n if n % 2 == 0: # even\n return int(n / 2)\n else:\n return int(-1*((n+1)/2))\n\n\n\n\nif __name__ == '__main__':\n n = int(input())\n print(Calculate(n))\n \t\t\t\t\t \t \t\t\t\t\t\t\t\t \t \t \t \t\t\t", "j = int(input())\r\n \r\nif j % 2 == 0 :\r\n print(int(j/2))\r\nelse:\r\n print(-(int((j//2+1))))\r\n", "n = int(input())\r\nresult=0\r\nif n%2==0:\r\n print(n//2)\r\nelse:\r\n result = -(n+1)//2\r\n print(result)", "from math import *\r\nn=int(input())\r\nif (n % 2) == 0:\r\n print(n//2)\r\nelse:\r\n j=(-n)//2\r\n print(j)", "def calculate_f(n):\r\n if n % 2 == 0:\r\n return n // 2\r\n else:\r\n return -(n // 2) - 1 if n % 2 == 1 else n // 2\r\n\r\n# Input\r\nn = int(input())\r\n\r\n# Output\r\nprint(calculate_f(n))\r\n", "x= int(input())\r\n\r\nif x % 2 == 0:\r\n r = x // 2\r\nelse:\r\n r = -((x // 2) + 1)\r\n\r\nprint(r)\r\n", "n=int(input())\nif n%2==0:\n print(int(n/2))\nelse:\n print(int((n/2+0.5)*-1))", "n =int(input())\r\nans =(n+1)//2\r\nif n%2 !=0:\r\n ans = -ans\r\n\r\nprint(ans)\r\n ", "n = int(input())\r\nif n % 2 == 1:\r\n s1 = ((1 + n) *((n + 1) // 2)) // 2\r\n s2 = ((1 + n) * (n // 2)) // 2\r\nelse:\r\n s1 = (n *(n // 2)) // 2\r\n s2 = ((2 + n) * (n // 2)) // 2\r\nprint(s2 - s1)\r\n \r\n", "n=int(input())\r\nx=(n*(n+1))//2\r\ny=int(n/2)\r\nz=0\r\nif n%2==1:\r\n z=(y**2)+n\r\nelif n%2==0:\r\n z=y**2\r\nprint(x-2*z)\r\n", "x=int(input())\r\nprint(x//2-x%2*x)", "def f(x):\r\n k1 = x // 2\r\n k2 = (x + 1) // 2\r\n k3 = k1 * (k1 + 1)\r\n k4 = k2 * k2\r\n return k3 - k4\r\n\r\n\r\nn = int(input())\r\nprint(f(n))", "n=int(input())\r\nif n%2==0:\r\n a=(n//2)\r\nelse:\r\n a=-1-(n//2)\r\nprint(a)", "n=int(input())\r\nif n%2==0:\r\n s = (2+n)*(n)//4\r\n s1 = (-1)*n*n//4\r\nelse:\r\n s1=(-1)*(1+n)*(n//2+1)//2\r\n s = (1+n)*(n//2)//2\r\nprint(s+s1)", "n = int(input())\r\n \r\nif n % 2 == 0:\r\n print(int(n / 2))\r\nelse:\r\n k = n - 1\r\n k = int(k / 2)\r\n print(int(k - n))\r\n \t \t \t", "a = int(input())\r\nif a%2 == 0:\r\n print(a//2)\r\nelse:\r\n print(-(a//2+1))", "g=int(input())\r\nprint(-(g//2+1) if g%2==1 else g//2)", "n=int(input())\r\nprint(int((n/2 if(n%2==0)else (n-1)/2-n)))", "a=int(input())\r\nprint(a//2-a%2*a)", "n=int(input())\r\nb=(n//2)*((n//2)+1)- (((n-1)//2)+1)**2\r\nprint(b)\r\n", "n=int(input())\r\nk=n//2\r\nif n%2==0:\r\n print(k)\r\nelse:\r\n print(-(k+1))\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Oct 2 17:30:20 2023\r\n\r\n@author: 25419\r\n\"\"\"\r\n\r\nn=int(input())\r\nif n%2==0:\r\n print(n//2)\r\nelse:print(-n//2)", "num = int(input())\r\nif num % 2 == 0 and num > 0:\r\n print(num//2)\r\nelif num % 2 == 1 and num > 0:\r\n print(-(num//2) - 1)", "n=input()\r\nif int(n)%2==0:\r\n print(int(int(n)/2))\r\nelse:\r\n print(int(int(int(n)+1)/(-2)))", "n=int(input())\r\nif n%2==0:\r\n print(n//2)\r\nelse:\r\n c=n-(n//2)\r\n print(-c)\r\n#####################\r\n# def main():\r\n# from sys import stdin,stdout\r\n# from math import ceil\r\n# n=int(stdin.readline())\r\n# result=ceil(n/2)\r\n# n//=2\r\n# stdout.write(str(n*(n+1)-result*result))\r\n# if __name__=='__main__':\r\n# main()\r\n#####################\r\n# n=int(input())\r\n# i,j,ans=-1,2,0\r\n# while True:\r\n# z=i+j\r\n# i-=2\r\n# j+=2\r\n# z+=1\r\n# if j == n:\r\n# ans+=z\r\n# break\r\n# if abs(i) == n:\r\n# ans+=z\r\n# ans+=i\r\n# break\r\n# print(ans)\r\n", "a = int(input())\r\nprint((-a//2) * (1 if a%2 else -1))", "a=int(input())\r\nif a%2==0:\r\n print(int(a/2))\r\nelse:\r\n print(-((a//2)+1))", "# -*- coding: utf-8 -*-\n\"\"\"Calculating Function.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1NzkS-ILNK1ukdPywhFmWqiP6lQ-WO8n-\n\"\"\"\n\nn = int(input())\nif n%2==0:\n sum_impares = ((n-1)//2 + 1)**2\n sum_pares = (n//2+1)*(n//2)\nelse:\n sum_impares = ((n)//2 + 1)**2\n sum_pares = ((n-1)//2+1)*((n-1)//2)\n\nprint(int(sum_pares-sum_impares))", "n = int(input())\nif n % 2 == 1:\n print(n//2-n)\nelse:\n print(n//2)", "np = int(input())\r\n\r\n\r\nif np % 2 == 0:\r\n result = np // 2\r\nelse:\r\n result = -(np + 1) // 2\r\n\r\n\r\nprint(result)\r\n", "n = int(input()) \r\nif n% 2==0:\r\n result=n//2\r\nelse:\r\n result=-((n+1)//2)\r\nprint(result) \r\n", "import math\nn = int(input())\n\nif n % 2 == 0:\n print(int(n/2))\nelse:\n print(int((math.ceil(n/2))* -1))", "import sys\r\n\r\nn = int(sys.stdin.readline().split()[0])\r\n\r\nif n % 2 == 0:\r\n print(int(n / 2))\r\nelse:\r\n print(int(-(n+1) / 2))", "\r\nn = int(input().strip())\r\nr = 0\r\n\r\nif n%2 == 0: r = n//2\r\nelse: r = -(n+1)//2\r\nprint(r)\r\n", "n = int(input())\r\nk = -1\r\nf = 0\r\nif (n%2!=0):\r\n f = int((n-1)/2) - n\r\nelse:\r\n f = int(n/2)\r\nprint(f)", "n = int(input())\r\nf = 0\r\nif n % 2:\r\n print(int(n/2*-1-1))\r\nelse:\r\n print(int(n/2))\r\n\r\n\r\n", "n=float(input())\r\nif n%2==0:\r\n print(int(n/2))\r\nelse:\r\n print(int((-n)//2))", "x = int(input())\r\n\r\nif x%2==0:\r\n even = ((x//2)+1)*(x//2)\r\n odd = pow(x//2,2)\r\n print(even-odd)\r\nelse:\r\n even = ((x // 2) + 1) * (x // 2)\r\n odd = pow((x // 2)+1, 2)\r\n print(even - odd)\r\n", "num = int(input())\r\n\r\nprint(num//2 if num%2==0 else -1*(num//2+1))", "n = int(input())\r\n\r\n# Calculate the sum for even terms\r\nsum_e = (n // 2) * ((n // 2) + 1)\r\n\r\n# Calculate the sum for odd terms\r\nsum_o = (n * (n + 1)) // 2 - sum_e\r\n\r\n# Calculate the final result using integer arithmetic\r\nresult = sum_e - sum_o\r\n\r\nprint(result)\r\n", "def main():\n n = int(input())\n if(n%2==0):\n print(n//2)\n else:\n print(-(n+1)//2)\n\n\nif __name__ == '__main__':\n main()", "import math\r\n\r\nn = int(input())\r\n\r\nif n%2==0:\r\n result = math.ceil(n/2)\r\nelse:\r\n result = -math.ceil(n/2)\r\n\r\nprint(result)\r\n", "number=int(input())\r\nif number%2==0:\r\n print(number//2)\r\nelse:\r\n print(-((number+1)//2))", "x=int(input())\r\nif x%2==0:\r\n print(x//2)\r\nelif x%2==1:\r\n ans=(-(x+1)//2)\r\n print(ans)", "n = int(input())\r\nprint(n//2 - (n if n % 2 == 1 else 0))", "non=int(input());\r\nprint(non//2-non%2*non)", "n=int(input())\r\nans=(n+1)//2\r\nif n % 2 != 0:\r\n\tans=-ans\r\nprint(ans)\t", "n = int(input())\r\n\r\nx = n%2\r\n\r\nif x==0:\r\n print(int(n/2))\r\nelse:\r\n print(int((n+1)/(-2)))", "n = int(input())\r\nif n % 2:\r\n print(-1*(n//2+n%2))\r\nelse:\r\n print(n//2)", "n = int(input())\r\nans = (n+1)//2\r\nif n%2 !=0:\r\n\tans = -ans\r\nprint(ans)", "import math\r\nn = input()\r\nn = int(n)\r\nans = 0\r\n\r\nif n % 2 == 0:\r\n ans = math.ceil(n / 2)\r\nelse :\r\n ans = -math.ceil(n / 2)\r\n\r\nprint(ans)\r\n\r\n# Time Complexity : O(1)\r\n", "import math\r\n\r\nn = int(input())\r\nans = math.ceil(n/2)\r\nif n & 1 == 1:\r\n print(-ans)\r\nelse:\r\n print(ans)", "n = int(input())\r\n\r\nif n % 2 == 0:\r\n # When n is even, f(n) is equal to n/2\r\n result = n // 2\r\nelse:\r\n # When n is odd, f(n) is equal to -(n+1)/2\r\n result = -((n + 1) // 2)\r\n\r\nprint(result)\r\n", "n = int(input(\"\"))\r\ntotal = 0\r\nif n % 2 == 0:\r\n total = n // 2\r\nelse:\r\n total = n //2 - n\r\nprint(int(total))", "number = int(input())\r\nif number % 2 != 0:\r\n total = (number + 1) / -2\r\nelif number % 2 == 0:\r\n total = number / 2\r\nprint(int(total))", "n = int(input())\r\nif n%2==0:\r\n\tfunction = (n//2)\r\nelse:\r\n\tfunction = -((n+1)//2)\r\nprint(function)", "n = int(input())\r\n\r\nans = n//2 - n*int(n%2 != 0)\r\n\r\nprint(ans)", "def calculate_f(n):\r\n # If n is even, the sum is n/2, and if n is odd, the sum is -(n+1)/2.\r\n if n % 2 == 0:\r\n return n // 2\r\n else:\r\n return -((n + 1) // 2)\r\n\r\n# Read the input value of n\r\nn = int(input())\r\n# Calculate and print f(n)\r\nresult = calculate_f(n)\r\nprint(result)\r\n", "x = int(input())\r\nif x%2 == 0:\r\n print(x//2)\r\nelse:\r\n print(x//2 * (-1) -1)", "def f(n):\r\n if n%2 ==0:\r\n return n//2\r\n else:\r\n return -((n+1)//2)\r\nprint(f(int(input())))", "n=int(input())\r\n# even=n*(n+1)\r\n# odd=n*n\r\nif n%2==0 :\r\n n=n//2\r\n even=n*(n+1)\r\n odd=n*n\r\n print(even-odd)\r\nelse:\r\n odd=(n//2)+1\r\n even=n//2\r\n even=even*(even+1)\r\n odd=odd*odd\r\n \r\n print(even-odd)", "def f(n):\r\n if n%2==0:\r\n return n//2\r\n else:\r\n return -(n//2+1)\r\na = int(input())\r\nprint(f(a))\r\n", "n=int(input());print(n//2-n*(n%2))", "n=int(input())\r\nif n%2 == 0:\r\n a=n//2\r\nelse:\r\n a=((n+1)//2)*(-1)\r\nprint(a)", "def f(n):\r\n x = n // 2\r\n if n % 2 != 0:\r\n x -= n\r\n return x\r\n\r\nprint(f(int(input())))", "n = int(input())\r\nprint(-(n+1)//2 if n%2!=0 else n//2)", "n = int(input())\r\n\r\nif n%2 == 0 :\r\n r = (n//2)*1\r\nelse :\r\n r = ((n//2)+1)*-1\r\n \r\nprint(r)", "n = int(input())\r\nprint(n//2 if n%2==0 else -n//2)", "'''\r\n==TEST CASE==\r\nInput:\r\n4\r\n\r\nOutput:\r\n2\r\n'''\r\nn=int(input())\r\n\r\nif n%2==0:\r\n print(int(n/2))\r\nelse:\r\n print(int(((n-1)/2)-n))\r\n", "N=int(input())\r\nif N%2==0:\r\n print(N//2)\r\nelse:\r\n print(-1*(N+1)//2)", "num = int(input())\r\nif num %2 == 0:\r\n print(num // 2)\r\nelse:\r\n print(num // 2 - num) ", "r = int(input())\r\n\r\nif r % 2:\r\n print(-(r // 2 + 1))\r\nelse:\r\n print(r // 2)\r\n", "n = int(input())\r\nc = n%2\r\n\r\nif c==1:\r\n c=-(n//2+1)\r\nelse:\r\n c=n//2\r\nprint(c)", "l = int(input())\r\ntotal = 0\r\ndef f(l):\r\n if l % 2 == 0:\r\n total = int(l/2)\r\n else:\r\n total = int(((l + 1)/2) * -1)\r\n print(total)\r\nf(l)\r\n\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Sep 6 15:24:38 2023\r\n\r\n@author: HyFlu\r\n\"\"\"\r\n\r\nx=int(input())\r\nfx=0\r\nif x%2==1:\r\n fx=-(x+1)//2\r\nelse:\r\n fx=x//2\r\nprint(fx)", "x = int(input())\r\na = 0\r\nif x%2 != 0:\r\n a = -(x//2+1)\r\nelse:\r\n a = x//2\r\nprint(a)", "n =input()\nn =int(n)\nif (n %2==0):\n print(n//2)\nelse :\n print(-(n+1)//2)\n\t\t\t\t \t \t \t \t\t\t\t \t\t \t \t\t \t\t", "a = int(input())\r\n\r\nif a % 2 == 0:\r\n r = a // 2\r\nelse:\r\n r = -(a + 1) // 2\r\n\r\nprint(r)", "def foncution(n):\r\n if n % 2 == 0: \r\n x = int(n / 2)\r\n return (x * (x+1)) - (x ** 2)\r\n else:\r\n x = int((n-1)/2)\r\n y = int((n+1)/2)\r\n return (x * (x+1)) - (y ** 2)\r\n \r\nn = int(input())\r\n\r\nprint(foncution(n))", "n = int(input())\r\nprint((1, -1)[n % 2] * (n+1)//2)\r\n", "import math\r\n\r\nn = int(input())\r\nif n / 2 == math.ceil(n / 2):\r\n print(math.ceil(n / 2))\r\nelse:\r\n print(-math.ceil(n / 2))", "def caluclate(n):\r\n if n % 2 == 0:\r\n res = n // 2\r\n else:\r\n res = (n // 2 + 1)* -1\r\n print(res)\r\n \r\nnum = int(input().strip())\r\ncaluclate(num)", "n=int(input())\r\nn2=n\r\nn=n//2\r\neven=n*(n+1)\r\nif(n2&1): \r\n odd= (n+1)*(n+1)\r\nelse:\r\n odd=n*n\r\n\r\nprint(even-odd)", "number = int(input())\r\nc = 0\r\nif number % 2 == 0:\r\n print(number//2)\r\nelse:\r\n print((number-1)//2-number)", "n=int(input())\r\nif n%2==0:\r\n a=n//2\r\nelse:\r\n a=-(n+1)//2\r\nprint(a)", "def f(n):\r\n if n % 2 == 0:\r\n return n//2\r\n a = n//2\r\n b = n - a\r\n return -(b**2) + a**2+a\r\nprint(f(int(input())))\r\n", "n= int(input())\nif n % 2 == 0:\n print(n // 2)\nelse:\n print((n -1)// 2 - n)\n\t\t \t \t \t\t \t \t \t\t\t\t\t\t", "n = int(input())\r\n\r\nif n%2 == 0:\r\n r = n//2\r\nelse :\r\n r = -(n+1)//2\r\n \r\nprint(r)\r\n", "n= int(input())\r\n# ans = 0 \r\n# for i in range (1,n+1): \r\nif n %2 == 0:\r\n\tprint(int(n/2))\r\nelse:\r\n\tprint(-(int(n/2+1)))\r\n ", "n = int(input())\n\nif n % 2 == 0:\n\tsumn = n // 2\nelse:\n\tsumn = n // 2 - n\n\nprint(sumn)", "def solve(n):\r\n if(n%2==0):\r\n return int(n/2)\r\n else:\r\n prev = (n-1)/2\r\n return int(prev-n)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n print(solve(n))", "n=int(input())\r\nans=n//2\r\nif n%2!=0:\r\n print(-(ans+1))\r\nelse:\r\n print(ans)", "n=int(input())\r\nif not n&1:\r\n n//=2\r\n plus=n*(n+1)\r\n minus=n*n \r\n print(plus-minus)\r\nelse:\r\n n-= 1 \r\n n//=2\r\n plus=(n)*(n+1)\r\n n+=1 \r\n minus=n*n \r\n print(plus-minus)\r\n ", "# f(n) = -1 +2 -3 ... + (-n)^n * n\r\n\r\n# f(1) = -1 -- f(2) = 1\r\n# f(3) = -2 -- f(4) = 2\r\n# f(5) = -3 -- f(6) = 3\r\n# f(7) = -4 -- f(8) = 4\r\n# f(9) = -5 -- f(10) = 5\r\n# if n is odd it's ((n+1)/2) * -1\r\n# if n is 1 it's -1.\r\n# if n is even it's n/2.\r\n\r\n# I've been thinking about this problem for a few days and now I see the pattern. \r\n\r\nvalueOfN = int(input())\r\n\r\nif valueOfN % 2 == 0:\r\n output = valueOfN // 2\r\nelse:\r\n output = ((valueOfN + 1) // 2) * (-1)\r\n\r\nprint(output)", "# 1 second = 10^7 steps\nn = int(input())\nif n %2 == 0:\n print(int(n/2))\nelse:\n print(int((n-1)/2)-n)\n \t \t \t \t \t \t\t\t \t\t\t\t \t\t", "import math\r\nn = int(input())\r\nif n % 2 == 0:\r\n print(n // 2)\r\nelse:\r\n print(math.floor(-n / 2))", "n=int(input())\r\nif n%2==0:\r\n print(int(n/2))\r\nelse:\r\n print(int(-1*(n+1)/2))", "i = int(input())\r\n \r\nif i % 2 == 0 :\r\n print(int(i/2))\r\nelse:\r\n print(-(int((i/2+1))))", "n=int(input())\r\nif(n%2==0):\r\n p=(int)(n/2)\r\nelse:\r\n p= (int)(-(n+1)/2)\r\nprint(p)", "N = int(input())\r\na = -1\r\nif N % 2 == 0:\r\n a += 1 + N\r\nelse:\r\n a -= N\r\nprint(a // 2)\r\n", "x = int(input())\r\nif x % 2 == 0:\r\n print(x // 2)\r\nelse:\r\n print(-1 * ((x + 1) // 2))\r\n", "n = int(input())\r\nans = (n+1)//2\r\nif n % 2 == 1:\r\n print(-ans)\r\nelse:\r\n print(ans)\r\n ", "z=int(input())\r\nf=0\r\nif z&1==1:\r\n z+=1 \r\n z=-(z//2)\r\nelse:\r\n z=z//2\r\nprint(z)", "n=int(input())\r\nif n%2==0:\r\n a=n//2\r\n even=a*(1+a)\r\n odd=a**2\r\nelse:\r\n a=n//2\r\n odd=(a+1)**2\r\n even=(a)*(1+a)\r\nprint(even-odd)", "n = int(input())\r\nprint(n // 2 if n % 2 == 0 else -(n // 2 + 1))", "n = int(input())\r\nif n % 2 == 0:\r\n fn = n //2\r\nelse:\r\n fn = -((n+1) // 2)\r\nprint(fn)", "import math\r\nn=int(input())\r\nif (n % 2 == 0) :\r\n\tprint(int(n / 2))\r\nelse :\r\n\tprint(int(-1 * math.ceil(n / 2)))\r\n", "#calculating a function\r\n\r\nn=int(input())\r\n\r\nif n%2==0:\r\n result=n//2\r\nelse:\r\n result=((n-1)//2)-n\r\n\r\nprint(result)", "import math\r\n\r\nn = int(input())\r\nnum_list = []\r\nif n % 2 == 0:\r\n total = n/2\r\nelse:\r\n total = math.ceil(-n/2)-1\r\n\r\nprint(int(total))\r\n\r\n\r\n", "n = int(input())\r\nresult = 0\r\nif n%2==0:\r\n result = int(n/2)\r\nelse:\r\n result = int((n/2) + 0.5)*-1\r\nprint(f\"{round(result)}\")", "x=int(input())\r\nif x%2==1:x=-(x//2)-1\r\nelse:x//=2\r\nprint(x)", "n=int(input())\nif(n%2):\n print(int(-((n+1)/2)))\nelse:\n print(int(n/2))\n\t \t\t\t\t \t\t\t\t\t \t \t\t\t\t \t \t\t \t", "n = int(input())\r\nif n % 2 == 0:\r\n print((-1 + (n-1)//2*-1) + n)\r\nelse:\r\n print((-1 + (n-1)//2*-1))", "n = int(input())\r\nsumar = 0\r\nk_chet = 2\r\nk_nechet = -1\r\nif n%2==0:\r\n print (1*n//2)\r\nelse:\r\n print (1*n//2 + (-1 + (-2*(n//2))))\r\n", "n = int(float(input())) # Convert float input to integer\r\n\r\nif n % 2 == 0:\r\n result = n // 2 # n is even, so the result is n/2\r\nelse:\r\n result = -(n // 2 + 1) # n is odd, so the result is -(n/2 + 1)\r\n\r\nprint(result)\r\n", "n=int(input())\r\nif n%2==0:\r\n fn=n//2\r\nelse:\r\n fn=-(n//2+1)\r\nprint(fn)", "n = int(input())\r\nprint(n//2 - n % 2*n)", "# Calculating Function\r\nn = int(input())\r\nresultado = ((n + 1) / 2).__floor__() if n % 2 == 0 else (-n / 2).__floor__()\r\nprint(resultado)", "d=int(input())\r\nif(d%2==0):\r\n ans=(int)(d/2)\r\nelse:\r\n ans= (int)(-(d+1)/2)\r\nprint(ans)", "n=int(input())\r\nif(n%2!=0):\r\n s=-((n+1)//2)\r\nelse:\r\n s=(n//2)\r\nprint(s)", "def calculate_f(n):\r\n if n % 4 == 0 or n % 4 == 2:\r\n return n // 2\r\n else:\r\n return n // 2 - n\r\n\r\n# Read input\r\nn = int(input())\r\n\r\n# Calculate and print the result\r\nresult = calculate_f(n)\r\nprint(result)\r\n", "n=int(input())\r\nx=n\r\nif(n%2==0):\r\n n=n//2\r\n res=((n)*(2+x))//2\r\n res1=((n)*(x))//2\r\n print(res-res1)\r\nelse:\r\n n=n//2\r\n res=((n)*(x+1))//2\r\n res1=((n+1)*(1+x))//2\r\n print(res-res1)", "b = int(input())\r\ns = ((-1)**(b%2))*((b+1)//2)\r\nprint(s)", "n=int(input())\r\nif n%2==0:print(n//2)\r\nelse:print('-'+str((n-n//2)))", "if __name__ == \"__main__\":\r\n num = int(input())\r\n if num % 2 == 0:\r\n print(int(num/2))\r\n else:\r\n print((int((num-1)/2 + 1) * -1))", "n = int(input())\r\nif n % 2==0:\r\n count = n//2\r\nelse:\r\n count = (n+1)//-2\r\nprint(count)\r\n", "# Function to calculate f(n)\r\ndef calculate_f(n):\r\n if n % 2 == 0:\r\n # If n is even, f(n) is n/2\r\n return n // 2\r\n else:\r\n # If n is odd, f(n) is -(n+1)//2\r\n return -((n + 1) // 2)\r\n\r\n# Input\r\nn = int(input())\r\n\r\n# Calculate and print f(n)\r\nresult = calculate_f(n)\r\nprint(result)\r\n", "k = int(input())\r\nif k % 2 == 0:\r\n result = k // 2\r\nelse:\r\n result = -((k + 1) // 2)\r\nprint(result)", "from math import ceil\r\n\r\n\r\ndef function(n):\r\n if n % 2 == 0:\r\n return n//2\r\n return -ceil(n / 2)\r\n\r\n\r\nb = int(input())\r\nprint(function(b))\r\n", "n=int(input())\r\nout=0\r\nif(n%2==0):\r\n out=n//2\r\nelse:\r\n out=(n+1)//2 *(-1)\r\nprint(out)", "n = int(input())\n\nif (n%2 == 1):\n num_positive_terms = ((n+1) // 2) -1\n num_negative_terms = n - num_positive_terms\nelse: \n num_positive_terms = (n+1) // 2\n num_negative_terms = n - num_positive_terms\n \n\nsum_positive = num_positive_terms + (num_positive_terms * num_positive_terms)\nsum_negative = (num_negative_terms * num_negative_terms)\n\n\nresult = sum_positive - sum_negative\n\nprint(result)\n\n \t \t\t \t\t\t \t\t\t \t \t\t \t", "def main():\r\n from sys import stdin,stdout\r\n from math import ceil\r\n n=int(stdin.readline())\r\n result=ceil(n/2)\r\n n//=2\r\n stdout.write(str(n*(n+1)-result*result))\r\nif __name__=='__main__':\r\n main()", "#initializes number and x\r\nnumber = int(input())\r\n\r\n#performs function described in problem\r\nx = ((-1)**(number) * (number)) // 2\r\nprint(x)\r\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Sep 13 22:54:21 2023\n\n@author: huangxiaoyuan\n\"\"\"\n\ndef f(k):\n if k%2==0:\n return int(k/2)\n else: \n return int(-(k+1)/2)\n \nn=int(input())\nif 1<=n<=10**15:\n print(f(n))", "def calculatatingFunction():\r\n n = int(input())\r\n if n % 2 == 0 : print(int(n/2))\r\n else:\r\n sum = int(-1*(n+1)*0.5)\r\n print(sum)\r\n\r\ncalculatatingFunction()" ]
{"inputs": ["4", "5", "1000000000", "1000000001", "1000000000000000", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "208170109961052", "46017661651072", "4018154546667", "288565475053", "3052460231", "29906716", "87897701693326", "8240", "577935", "62", "1", "2", "9999999999999", "1000000000000", "99999999999999", "999999999999999", "42191359342", "100000000000000", "145645214654154", "4294967296", "3037000499", "10000000000001", "100000017040846", "98979894985999"], "outputs": ["2", "-3", "500000000", "-500000001", "500000000000000", "50", "-51", "51", "-52", "52", "-53", "53", "-54", "54", "-55", "104085054980526", "23008830825536", "-2009077273334", "-144282737527", "-1526230116", "14953358", "43948850846663", "4120", "-288968", "31", "-1", "1", "-5000000000000", "500000000000", "-50000000000000", "-500000000000000", "21095679671", "50000000000000", "72822607327077", "2147483648", "-1518500250", "-5000000000001", "50000008520423", "-49489947493000"]}
UNKNOWN
PYTHON3
CODEFORCES
371
1ebe3a50c08a441116f53867534813de
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days. Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Sample Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler icm codeforces 1 codeforces technex Sample Output ross rachel joey rachel joey phoebe joey monica joey chandler icm codeforces icm technex
[ "\ns = ' '+input()+' '\nn = int(input())\nprint(s[1:-1])\nfor i in range(n):\n l,r = input().split()\n s = s.replace(' '+l+' ',' '+r+' ')\n print(s[1:-1])\n", "n,m= input().split()\r\nprint(n,m)\r\nnum = int(input())\r\nfor i in range(num):\r\n\ta,b=input().split()\r\n\tif(a==n):\r\n\t\tprint(b,m)\r\n\t\tn=b\r\n\telse:\r\n\t\tprint(b,n)\r\n\t\tm=b\r\n\t", "x, y = input().split()\r\nprint(x, y)\r\nfor _ in range(int(input())):\r\n a, b = input().split()\r\n if x == a:\r\n x = b\r\n elif y == a:\r\n y = b\r\n print(x, y)", "initial = input().split()\r\nq = int(input())\r\n \r\nvct = []\r\np = q\r\nwhile p > 0:\r\n s, t = input().split()\r\n vct.append([s, t])\r\n p -= 1\r\n \r\nanswer = initial[0] + \" \" + initial[1]\r\n \r\nfor i in range(len(vct)):\r\n if initial[0] == vct[i][0]:\r\n initial[0] = vct[i][1]\r\n answer += \"\\n\" + initial[0] + \" \" + initial[1]\r\n elif initial[1] == vct[i][0]:\r\n initial[1] = vct[i][1]\r\n answer += \"\\n\" + initial[0] + \" \" + initial[1]\r\n \r\nprint(answer)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Feb 11 17:42:31 2018\r\n\r\n@author: arjun\r\n\"\"\"\r\n\r\nf1,f2 = list(map(str,input().split()))\r\nprint(f1,f2)\r\nn = int(input())\r\nfor _ in range(n):\r\n dead,replace = list(map(str,input().split()))\r\n if(dead==f1):\r\n f1 = replace\r\n else:\r\n f2 = replace\r\n print(f1,f2)", "from sys import stdin\r\n\r\nrd = stdin.readline\r\n\r\nname1, name2 = rd().split()\r\nn = int(rd())\r\n\r\nprint(name1, name2)\r\n\r\nfor _ in range(n):\r\n\r\n mur, rep = rd().split()\r\n\r\n if name1 == mur: name1 = rep\r\n else: name2 = rep\r\n\r\n print(name1, name2)\r\n", "if __name__ == \"__main__\":\n vic1, vic2 = input().strip().split()\n n = int(input())\n for i in range(n):\n print(vic1, vic2)\n ded, rep = input().strip().split()\n if ded == vic1: vic1 = rep\n else: vic2 = rep\n print(vic1, vic2)\n", "l1=input().split()\r\n\r\nn=int(input())\r\n\r\nfor i in range(n):\r\n #print(l1)\r\n\r\n for name in l1:\r\n print(name,\" \",end=\"\")\r\n\r\n l2=input().split()\r\n\r\n if l2[0]==l1[0]:\r\n l1[0]=l2[1]\r\n else:\r\n l1[1]=l2[1]\r\n\r\n print()\r\n\r\n\r\n\r\nfor name in l1:\r\n print(name,\" \", end=\"\")\r\nprint()\r\n\r\n\r\n", "victims = input().split()\r\nn = int(input())\r\nprint(*victims)\r\nfor i in range(n):\r\n killed, victim = input().split()\r\n victims.remove(killed)\r\n victims.append(victim)\r\n print(*victims)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "l=input().split()\r\nprint(*l)\r\nn=int(input())\r\nfor i in range(n):\r\n m,n=input().split()\r\n l[l.index(m)]=n\r\n print(*l)", "s1,s2=input().split()\r\nn=int(input())\r\ni=0\r\nwhile i<n:\r\n a,b=input().split()\r\n print(s1,s2)\r\n if s1==a:\r\n s1=b\r\n else:\r\n s2=b\r\n i=i+1\r\nprint(s1,s2)", "l=list(input().split())\r\nn=int(input())\r\nprint(l[0]+\" \"+l[1])\r\nfor i in range(n):\r\n a,b=input().split()\r\n if(l[0]==a):\r\n l[0]=b\r\n else:\r\n l[1]=b\r\n print(l[0]+\" \"+l[1])", "import math\r\n\r\n\r\ndef main_function():\r\n output_list = []\r\n first_pair = [i for i in input().split(\" \")]\r\n output_list.append(first_pair)\r\n for i in range(int(input())):\r\n pair = [i for i in input().split(\" \")]\r\n korea = output_list[-1].copy()\r\n for i in range(2):\r\n if korea[i] == pair[0]:\r\n korea[i] = pair[1]\r\n output_list.append(korea)\r\n return \"\\n\".join([i[0] + \" \" + i[1] for i in output_list])\r\n\r\n\r\nprint(main_function())", "s = input()\r\n \r\nn = int(input())\r\n \r\nprint(s)\r\n \r\ns = s.split()\r\n \r\nfor _ in range(n):\r\n\ta = input().split()\r\n \r\n\ts.remove(a[0])\r\n\ts.append(a[1])\r\n\t\r\n \r\n\tprint(s[0],s[1])", "a = list(input().split())\r\nn = int(input())\r\nprint(a[0], a[1])\r\nfor _ in range(n):\r\n a1, a2 = input().split()\r\n if a1 == a[0]:\r\n a[0] = a2\r\n if a1 == a[1]:\r\n a[1] = a2\r\n print(a[0], a[1])", "import sys\r\np=[]\r\nj = sys.stdin.readline().strip().split()\r\np.append(' '.join(j))\r\nfor _ in range(int(sys.stdin.readline().strip())):\r\n c = sys.stdin.readline().strip().split()\r\n s = []\r\n for i in c:\r\n if i not in c or i not in j:\r\n s.append(i)\r\n for i in j:\r\n if i not in c or i not in j:\r\n s.append(i)\r\n p.append(' '.join(s))\r\n j = s\r\nprint(*p,sep=\"\\n\")", "from sys import *\r\nfrom math import *\r\nb=list(input().split())\r\nn=int(input())\r\nm=[]\r\nfor i in range(n):\r\n a=list(input().split())\r\n m.append(a)\r\nprint(*b)\r\nfor i in range(n):\r\n if m[i][0]==b[0]:\r\n b[0]=m[i][1]\r\n else:\r\n b[1]=m[i][1]\r\n print(*b)", "#I = lambda: [int(i) for i in input().split()]\r\n#import io, os, sys\r\n#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline\r\n\r\n\r\n# n = int(input())\r\n# l1 = list(map(int,input().split()))\r\n# n,x = map(int,input().split())\r\n# s = input()\r\n# mod = 1000000007\r\n# print(\"Case #\"+str(_+1)+\":\",)\r\nfrom collections import defaultdict\r\nimport bisect\r\nimport sys\r\n\r\n\r\ns,t = map(str, input().split())\r\nn = int(input())\r\nprint(s,t)\r\nfor i in range(n):\r\n a,b = map(str, input().split())\r\n if s==a:\r\n print(b,t)\r\n s=b\r\n elif s==b:\r\n print(a,t)\r\n s=a\r\n elif t == b:\r\n print(a, s)\r\n t = a\r\n else:\r\n print(b,s)\r\n t=b\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "a, b = input().split()\r\nn = int(input())\r\nprint(a, b)\r\nfor i in range(n):\r\n\tkill, ptn = input().split()\r\n\tif (kill == a):\r\n\t\ta = ptn\r\n\telse:\r\n\t\tb = ptn\r\n\tprint(a, b)", "l=input().split()\r\nprint(*l)\r\nfor i in range(int(input())):\r\n s,t=input().split()\r\n l[l.index(s)]=t\r\n print(*l)", "(a, b) = input().split()\r\n\r\nn = int(input())\r\n\r\nprint(a, b)\r\nfor i in range(n):\r\n (a1, a2) = input().split()\r\n if a == a1:\r\n a = a2\r\n elif b == a1:\r\n b = a2\r\n elif a == a2:\r\n a = a1\r\n elif b == a2:\r\n b = a1 \r\n print(a, b)", "import math as mt \nimport sys,string,bisect\ninput=sys.stdin.readline\nfrom collections import deque,defaultdict\nL=lambda : list(map(int,input().split()))\nLs=lambda : list(input().split())\nM=lambda : map(int,input().split())\nI=lambda :int(input())\na,b=input().split()\nprint(a,b)\nn=I()\nfor i in range(n):\n k=input().split()\n if(a==k[0]):\n a=k[1]\n else:\n b=k[1]\n print(a,b)\n", "l=list(map(str,input().split()))\r\nm=[]\r\n\r\nm.append(l)\r\nn=int(input())\r\nfor i in range(n):\r\n\ts=list(map(str,input().split()))\r\n\tm.append(s)\r\nz=[]\r\nfor i in range(n+1):\r\n\tfor j in range(2):\r\n\t\tif m[i][j] not in z:\r\n\t\t\tz.append(m[i][j])\r\n\t\t\tif len(z)==2:\r\n\t\t\t\tprint(\" \".join(z))\r\n\t\telif m[i][j] in z:\r\n\t\t\tz.remove(m[i][j])", "a,b = input().split()\r\nprint(a , b)\r\nfor i in range(int(input())):\r\n x , y = input().split()\r\n if a == x :\r\n a = y\r\n else :\r\n b = y\r\n print(a , b)", "S = set(input().split())\r\nfor x in S:\r\n print(x, end= ' ') \r\nprint()\r\nfor i in range(int(input())):\r\n a,b=input().split()\r\n S.remove(a)\r\n S.add(b)\r\n \r\n for x in S:\r\n print(x, end= ' ') \r\n print()", "\r\nR = lambda:map(int,input().split())\r\n\r\narr = input().split()\r\nprint(*arr)\r\nn, = R()\r\nfor i in range(n):\r\n x, y = input().split()\r\n arr[arr.index(x)] = y\r\n print(*arr)\r\n ", "s=input()\r\nl=[]\r\nl.append(s)\r\ns=s.split()\r\nfor i in range(int(input())):\r\n\ta,b=input().split()\r\n\ts[s.index(a)]=b\r\n\tl.append(\" \".join(s))\r\nprint(*l,sep=\"\\n\")", "a, b = input().split()\r\nans = []\r\nans.append(a + \" \" + b)\r\nn = int(input())\r\nfor _ in range(n):\r\n p, q = input().split()\r\n if a in [p, q]:\r\n if a == p:\r\n a = q\r\n else:\r\n b = p\r\n else:\r\n if b == p:\r\n b = q\r\n else:\r\n b = p\r\n ans.append(a + \" \" + b)\r\nprint(*ans, sep = '\\n')", "Initial = list(input().split())\r\nn = int(input())\r\nprint(*Initial, sep=\" \")\r\nfor i in range(n):\r\n X = list(input().split())\r\n Initial[Initial.index(X[0])] = X[1]\r\n print(*Initial, sep=\" \")\r\n", "#-------------Program--------------\r\n#----Kuzlyaev-Nikita-Codeforces----\r\n#-------------Training-------------\r\n#----------------------------------\r\n\r\nn1,n2=map(str,input().split())\r\nn=int(input())\r\nfor i in range(n):\r\n v,f=map(str,input().split())\r\n print(n1,n2)\r\n if v==n1:\r\n n1=f\r\n else:\r\n n2=f\r\nprint(n1,n2)", "a,b=input().split()\r\nn=int(input())\r\nprint(a,b)\r\nfor i in range(n):\r\n\tc,d=input().split()\r\n\tif a==c:\r\n\t\ta=d\r\n\telif b==c:\r\n\t\tb=d\r\n\tprint(a,b)", "a , b = input().split()\r\nn = int(input())\r\nprint(a , b)\r\nfor i in range(n):\r\n x , y = input().split()\r\n if(x == a):\r\n a = y\r\n else:\r\n b = y\r\n print(a , b)", "initial = input().split(\" \")\r\nprint(initial[0] + \" \" + initial[1])\r\nnumCases = int(input())\r\nfor _ in range(numCases):\r\n \r\n names = input().split(\" \")\r\n if initial[0] == names[0]:\r\n initial[0] = names[1]\r\n else:\r\n initial[1] = names[1]\r\n print(initial[0] + \" \" + initial[1])\r\n", "a,b=input().split()\r\nprint(a,b)\r\nn=int(input())\r\nfor i in range(n):\r\n c,d=input().split()\r\n if c==a:\r\n print(d,b)\r\n a=d\r\n else:\r\n print(d,a)\r\n b=d", "today = input().split()\nn = int(input())\nfor name in range(n):\n kill = input().split()\n print(' '.join(today))\n today[today.index(kill[0])] = kill[1]\nprint(' '.join(today))\n", "e = input().split()\nprint(*e)\nn = int(input())\nfor x in range(n):\n x=input().split()\n e[e.index(x[0])]=x[1]\n print(*e)\n\n\n\n# Made By Mostafa_Khaled", "a,b=input().split()\r\nn=int(input())\r\nprint(a,b)\r\nfor i in range(n):\r\n c,d=input().split()\r\n if c==a: a=d\r\n else: b=d\r\n print(a,b)", "a, b = map(str, input().split())\r\nq = int(input())\r\nprint(a, b)\r\nfor i in range(q):\r\n x, y = map(str, input().split())\r\n if a == x:\r\n a = y\r\n else:\r\n b = y\r\n print(a, b)", "p1, p2 = input().split()\nn = int(input())\n\nprint(p1, p2)\nfor i in range(n):\n vic, new = input().split()\n if p1 == vic:\n p1 = new\n else:\n p2 = new\n print(p1, p2)\n \t\t\t \t \t \t\t \t \t\t\t\t \t\t\t \t", "def serial_killer(first_pair, rest_pair):\r\n prev = first_pair.split()\r\n print(\"%s %s\" % (prev[0], prev[1]))\r\n for each in rest_pair:\r\n curr = each.split()\r\n if curr[0] == prev[0]:\r\n prev = [prev[1], curr[1]]\r\n else:\r\n prev = [prev[0], curr[1]]\r\n print(\"%s %s\" % (prev[0], curr[1]))\r\n\r\n\r\ndef main():\r\n names = input()\r\n name_pair = []\r\n for _ in range(int(input())):\r\n name_pair.append(input())\r\n serial_killer(names, name_pair)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "a,b=map(str,input().split())\r\nn=int(input())\r\nl=[]\r\nl.append(a+\" \"+b)\r\nfor i in range(n):\r\n c,d=map(str,input().split())\r\n if c==a:\r\n l.append(d+\" \"+b)\r\n a=d\r\n if c==b:\r\n l.append(a+\" \"+d)\r\n b=d\r\nfor i in l:\r\n print(i)\r\n", "victim1, victim2 = input().split()\r\nprint(victim1, victim2)\r\nfor _ in range(int(input())):\r\n\tmudered, next = input().split()\r\n\tif mudered == victim1:\r\n\t\tvictim1 = next\r\n\telse:\r\n\t\tvictim2 = next\r\n\tprint(victim1, victim2)\r\n", "a,b=input().split()\r\nprint(a,b)\r\nfor x in range(int(input())):\r\n\tc,d=input().split()\r\n\tif a==c:\r\n\t\ta=d\r\n\t\tprint(a,b)\r\n\telse:\r\n\t\tb=d\r\n\t\tprint(a,b)", "a,b=map(str, input().split(\" \"))\r\nn=int(input())\r\nprint(a,b)\r\nwhile(n):\r\n c,d=map(str, input().split(\" \"))\r\n if(c==a):\r\n a=d\r\n print(a,b)\r\n if(c==b):\r\n b=d\r\n print(a,b)\r\n n-=1", "a,b=input().split()\r\nn=int(input())\r\nfor i in range(n):\r\n\tp,q=input().split()\r\n\tprint(a,b)\r\n\tif p==a:\r\n\t\ta=q\r\n\telif b==p:\r\n\t\tb=q\r\n\tif i==n-1:\r\n\t\tprint(a,b)", "s = input().split()\r\nprint(' '.join(s))\r\nn = int(input())\r\nfor i in range(n):\r\n n1, n2 = input().split()\r\n s[s.index(n1)] = n2\r\n print(' '.join(s))", "a,b=input().split()\r\nprint(a,b)\r\nfor i in range(int(input())):\r\n c,d=input().split()\r\n if(c==a):\r\n x=d\r\n y=b\r\n print(x,y)\r\n else:\r\n x=a\r\n y=d\r\n print(x,y)\r\n a=x\r\n b=y\r\n \r\n \r\n \r\n", "init = set(input().split())\r\nn = int(input())\r\n\r\nfor x in init:\r\n print(x, end = ' ')\r\nprint()\r\n\r\nfor _ in range(n):\r\n new = set(input().split())\r\n dead = init&new\r\n init = init | new\r\n init = init - dead\r\n for x in init:\r\n print(x, end = ' ')\r\n print()\r\n", "'''k, n, w = map(int, input().split())\r\nx = w*(w+1)/2 * k\r\ny = x-n\r\nif y>=0:\r\n print(int(y))\r\nelse:\r\n print(int(0))'''\r\nx, y = input().split()\r\nn = int(input())\r\n#print(x,y,n)\r\nm =[]\r\nr = []\r\nfor i in range(n):\r\n #print(i)\r\n a, b = input().split()\r\n m.append(a)\r\n r.append(b)\r\n #[i], r[i] = input().split()\r\nprint(x, y)\r\nfor i in range(n):\r\n if x == m[i]:\r\n print(r[i], y)\r\n x = r[i]\r\n else:\r\n print(x, r[i])\r\n y = r[i]\r\n#print(m,r)\r\n\r\n", "initial = input().split()\r\nn = int(input())\r\n\r\nvictims = []\r\nm = n\r\nwhile m > 0:\r\n s, t = input().split()\r\n victims.append([s, t])\r\n m -= 1\r\n\r\nanswer = initial[0] + \" \" + initial[1]\r\n\r\nfor i in range(len(victims)):\r\n if initial[0] == victims[i][0]:\r\n initial[0] = victims[i][1]\r\n answer += \"\\n\" + initial[0] + \" \" + initial[1]\r\n elif initial[1] == victims[i][0]:\r\n initial[1] = victims[i][1]\r\n answer += \"\\n\" + initial[0] + \" \" + initial[1]\r\n\r\nprint(answer)", "start = input()\r\nn = int(input())\r\n\r\nd = []\r\nfor i in range(n):\r\n r = input()\r\n d.append(r)\r\n#print(d)\r\n\r\nz = start\r\nm = [z]\r\nfor i in range(n) :\r\n y = m[i]\r\n for u in range(len(y)):\r\n if y[u] == \" \" :\r\n a = u\r\n # print(z)\r\n b = y[:a]\r\n c = y[a + 1:]\r\n # print(b)\r\n # print(c)\r\n\r\n e = d[i]\r\n for j in range(len(e)):\r\n if e[j] == \" \" :\r\n f = j\r\n g = e[:f]\r\n h = e[f+1:]\r\n #print(g)\r\n #print(h)\r\n if b == g :\r\n k = h + \" \" + c\r\n m.append(k)\r\n #z = k\r\n# print(z)\r\n elif c == g :\r\n l = b + \" \" + h\r\n m.append(l)\r\n #z = l\r\n# print(z)\r\n#print(z)\r\n#print(start)\r\nfor q in range(len(m)):\r\n print(m[q])\r\n", "# from scipy.special import comb,perm\n# import math\n# x=1-2*(0.1587)\n# for i in range(1,10):\n# print(1-(1-x)**i)\n\na,b=input().split()\nn=int(input())\nprint(a,b)\nfor i in range(n):\n nex1,nex2=input().split()\n if a==nex1:\n a=nex2\n elif b==nex1:\n b=nex2\n print(a,b)\n\n\n\t\t\t\t \t\t\t \t\t \t \t \t \t\t \t\t\t\t", "a, b = map(str,input().split())\r\nn = int(input())\r\nfor i in range (n+1):\r\n if i == 0:\r\n print(a,b)\r\n else:\r\n delete, replace = map(str, input().split())\r\n if delete == a:\r\n print(replace,b)\r\n a,b = replace, b\r\n else:\r\n print(a,replace)\r\n a, b = a, replace", "a,b=input().split()\r\nn=input()\r\nn=int(n)\r\nprint(a+\" \"+b)\r\nfor i in range(n):\r\n c,d=input().split()\r\n if(c==a):\r\n print(b+\" \"+d)\r\n a=b\r\n b=d\r\n elif(c==b):\r\n print(a+\" \"+d)\r\n a=a\r\n b=d\r\n\r\n \r\n", "s = input().split()\r\nprint(*s)\r\nn = int(input())\r\nfor i in range(n):\r\n a,b = map(lambda x:x,input().split())\r\n if a in s:\r\n s.pop(s.index(a))\r\n s.append(b)\r\n else:\r\n s.pop(s.index(b))\r\n s.append(a)\r\n print(*s)", "text = input().split()\r\nprint(*text)\r\nfor i in range(int(input())):\r\n a, b = input().split()\r\n\r\n text.remove(a)\r\n\r\n text.append(b)\r\n print(*text)", "def main():\n pv1, pv2 = input().split()\n days = int(input())\n \n print(pv1, pv2)\n for i in range(days):\n c, d = input().split()\n if pv1 == c:\n pv1 = d\n elif pv2 == c:\n pv2 = d\n print(pv1, pv2)\n\n\nmain()\n\n", "names={}\r\nnames=set()\r\n\r\n[a,b] = input().split()\r\nprint(a,b)\r\nnames.add(a)\r\nnames.add(b)\r\n\r\nnum = int(input())\r\n\r\nwhile num!=0:\r\n [a,b] = input().split()\r\n names.remove(a)\r\n names.add(b)\r\n for i in names:\r\n print(i,end=' ')\r\n print()\r\n num-=1", "s=set(input().split())\r\nn=int(input())\r\nprint(*s)\r\nfor i in range(n):\r\n a,b=input().split()\r\n s^={a}\r\n s.add(b)\r\n print(*s)\r\n \r\n \r\n", "v = input().split()\nprint(*v)\nfor _ in range(0, int(input())):\n i = input().split()\n if v[0] == i[0]:\n v[0] = i[1]\n else:\n v[1] = i[1]\n print(*v)\n", "name1, name2 = input().split()\r\nn = int(input())\r\nprint(name1, name2)\r\nfor i in range(n):\r\n victim, new_name = input().split()\r\n if name1 == victim:\r\n name1 = new_name\r\n else:\r\n name2 = new_name\r\n print(name1, name2)\r\n", "def main():\r\n pair = input().split()\r\n t = int(input())\r\n print(pair[0], pair[1])\r\n for _ in range(t):\r\n n1, n2 = input().split()\r\n if pair[0] == n1:\r\n pair = (n2, pair[1])\r\n else:\r\n pair = (pair[0], n2)\r\n print(pair[0], pair[1])\r\n\r\n\r\nmain()\r\n", "a, b = map(str, input().split())\r\nprint(a, b)\r\nfor i in range(int(input())):\r\n c, d = map(str, input().split())\r\n if a == c:\r\n a = d\r\n else:\r\n b = d\r\n print(a, b)", "a = input().split()\nx = int(input())\nprint(' '.join(a))\nfor i in range(x):\n x = input().split()\n a[a.index(x[0])] = x[1]\n print(' '.join(a))", "a = list(map(str, input().split()))\r\nn = int(input())\r\nprint(*a)\r\nfor i in range(n):\r\n died, replaced = map(str, input().split())\r\n if a[0] == died:\r\n a[0] = replaced\r\n else:\r\n a[1] = replaced\r\n print(*a)", "day1=list(map(str,input().split()))\r\nn=int(input())\r\nl=[]\r\nfor i in range(n):\r\n e=list(map(str,input().split()))\r\n l.append(e)\r\nprint(day1[0],day1[1])\r\nans=[]\r\nans.append(day1)\r\nfor i in range(n):\r\n for e in ans[-1]:\r\n if(l[0][0] != e):\r\n a=e\r\n b=l[0][1]\r\n ans.append([a,b])\r\n l=l[1:]\r\n print(a,b)\r\n", "def printlist(a):\r\n print(\" \".join(a))\r\n\r\na = input().split()\r\nprintlist(a)\r\n\r\nn=int(input())\r\n\r\nfor _ in range(n):\r\n x,y = map(str, input().split())\r\n i = a.index(x)\r\n a[i] = y\r\n printlist(a)\r\n", "inp = input().split(\" \")\r\nnam = []\r\nnam.append(inp[0])\r\nnam.append(inp[1])\r\nfinal = []\r\nfinal.append(nam)\r\nn = int(input())\r\nfor i in range(n):\r\n name = final[-1].copy()\r\n k = input().split(\" \")\r\n if name[0] == k[0]:\r\n name[0] = k[1]\r\n else:\r\n name[1] = k[1]\r\n \r\n final.append(name)\r\nfor i in final:\r\n print(*i)\r\n\r\n", "name1,name2=input().split()\r\nt=int(input())\r\nprint(name1,name2)\r\nfor x in range(t):\r\n killed,new=input().split()\r\n if killed==name1:\r\n name1=new\r\n else:\r\n name2=new\r\n print(name1,name2)\r\n", "names = set(input().split(' '))\r\nprint(' '.join(names))\r\nn = int(input())\r\nfor i in range(n):\r\n a,b = input().split(' ')\r\n if a in names:\r\n names.remove(a)\r\n names.add(b)\r\n else:\r\n names.remove(b)\r\n names.add(a)\r\n print(' '.join(names))\r\n", "import sys\n\nrl = lambda: sys.stdin.readline()\nvictims = rl().strip().split(' ')\n\n\ndef print_list():\n print('{} {}'.format(victims[0], victims[1]))\n\nprint_list()\n\nnum_line = int(rl())\nfor _ in range(num_line):\n victim, subst = rl().strip().split(' ')\n if victims[0] == victim:\n victims[0] = subst\n else:\n victims[1] = subst\n print_list()\n", "s = input().split()\r\nprint(*s)\r\nfor i in range(int(input())):\r\n a,b = input().split()\r\n s[s.index(a)] = b\r\n print(*s)", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main():\r\n a,b=input().split()\r\n print(a,b)\r\n n=int(input())\r\n for i in range(n):\r\n c,d=input().split()\r\n if c==a:\r\n a=d\r\n else:\r\n b=d\r\n print(a,b)\r\n\r\n\r\n\r\n\r\nfor _ in range(1):\r\n main()\r\n", "n = input().split()\r\nt = int(input())\r\n\r\nprint(n[0], n[1])\r\nfor i in range(t):\r\n f = input().split()\r\n n[n.index(f[0])] = f[1]\r\n print(n[0], n[1])", "s = list(input().split())\r\nprint(s[0],s[1])\r\nn= int(input())\r\nfor i in range(n):\r\n a,b = input().split()\r\n s.remove(a)\r\n s.append(b)\r\n print(s[0],s[1])", "def solve(a,b,v):\r\n ans=[]\r\n for i in range(len(v)):\r\n ans.append([a,b])\r\n p1,p2=v[i][0],v[i][1]\r\n if p1==a:\r\n a=p2\r\n else:\r\n b=p2\r\n ans.append([a,b])\r\n s=\"\"\r\n for i in ans:\r\n s+=i[0] + \" \" + i[1]+\"\\n\"\r\n return s\r\n\r\na1,b1=input().split()\r\nn=int(input())\r\nv=[]\r\nfor i in range(n):\r\n a,b=input().split()\r\n v.append([a,b])\r\nprint(solve(a1,b1,v))\r\n", "a,b=map(str,input().split())\r\nn=int(input())\r\nfor i in range(n+1):\r\n print(a,b)\r\n if i==n:\r\n break\r\n c,d=map(str,input().split())\r\n if c==a:\r\n a=d\r\n else:\r\n b=d\r\n\r\n ", "p1,p2=map(str, input().split(\" \"))\r\nn=int(input())\r\nprint(p1,p2)\r\nwhile(n):\r\n v1,v2=map(str, input().split(\" \"))\r\n if(v1==p1):\r\n p1=v2\r\n print(p1,p2)\r\n if(v1==p2):\r\n p2=v2\r\n print(p1,p2)\r\n n-=1", "inp1 = input().split()\r\nprint(\" \".join(inp1))\r\nn = int(input())\r\nfor i in range(0,n):\r\n lst = []\r\n inp2 = input().split()\r\n for j in range(0,2):\r\n if inp1[j] == inp2[0]:\r\n inp1[j] = inp2[1]\r\n ans = \" \".join(inp1)\r\n print(ans)", "vic1,vic2=map(str,input().split())\r\nn=int(input())\r\nprint(vic1,vic2)\r\nfor i in range(n):\r\n\tstr1,str2=map(str,input().split())\r\n\tif str1==vic1:\r\n\t\tvic1=str2\r\n\tif str1==vic2:\r\n\t\tvic2=str2\r\n\tprint(vic1,vic2)", "import sys\n\na, b = input().split()\nprint(a, b)\nx, y = a, b\n\nn = int(input())\nfor i in range(n):\n a, b = input().split()\n if a == x or a == y:\n if a == x:\n x = b\n else:\n y = b\n else:\n if b == x:\n x = a\n else:\n y = b\n\n print(x, y)\n", "st=input().split()\r\nn=int(input())\r\nl=[st]\r\ne=st\r\nfor i in range(n):\r\n o=input().split()\r\n e=set(e)-{o[0]}\r\n e.add(o[1])\r\n l.append(list(e))\r\nfor i in l:\r\n print(' '.join(i))\r\n", "l = list(map(str,input().split()))\r\nn = int(input())\r\nfor i in l:\r\n print(i, end = \" \")\r\nprint(\"\")\r\nfor i in range(n):\r\n ll = list(map(str,input().split()))\r\n \r\n if(l[0] == ll[0]):\r\n l[0] = ll[1]\r\n else:\r\n l[1] = ll[1]\r\n \r\n for j in l:\r\n print(j, end = \" \")\r\n print('')\r\n", "s1,s2=input().split()\r\nn=int(input())\r\nprint(s1,s2)\r\nwhile n>0:\r\n n-=1\r\n a,b=input().split()\r\n if a==s1:\r\n s1=b\r\n else :\r\n s2=b\r\n print(s1,s2)", "a,b = input().split()\r\nprint(a,b)\r\nn = int(input())\r\nfor _ in range(n):\r\n s1,s2 = input().split()\r\n if a==s1:\r\n a = s2\r\n else:\r\n b = s2\r\n print(a,b)", "a,b=input().split()\r\nn=int(input())\r\nl=[]\r\nh=[]\r\nh.append([a,b])\r\nfor i in range(n):\r\n l.append(input().split())\r\n \r\nfor i in range(n):\r\n if h[i][0]==l[i][0]:\r\n h.append([l[i][1],h[i][1]])\r\n\r\n elif h[i][1]==l[i][0]:\r\n h.append ([h[i][0],l[i][1]])\r\nfor i in range(len(h)):\r\n for j in range(2):\r\n print(h[i][j],end=' ')\r\n print()", "s=input().split(); print(*s)#Gym\nfor _ in \" \"*int (input()):t,l=input().split();s[s.index(t)]=l;print(*s)\n#Serial killer\n \t \t\t\t \t\t \t \t\t \t \t\t\t\t \t", "n1, n2 = input().split()\r\nd = int(input())\r\n\r\nprint(n1, n2)\r\n\r\nfor i in range(d):\r\n a, b = input().split()\r\n if a == n1 :\r\n n1 = b\r\n else :\r\n n2 = b\r\n \r\n print(n1, n2)", "r = lambda: input().split()\r\na,b = r()\r\nn = int(input())\r\n\r\nprint(a,b)\r\nfor _ in range(n):\r\n x,y = r()\r\n a = (a,y)[a==x]\r\n b = (b,y)[b==x]\r\n print (a,b)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nw = set(input().split())\r\nprint(*w)\r\nfor _ in range(int(input())):\r\n s = input().split()\r\n w = set(s) ^ w\r\n print(*w)\r\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nu = input().rstrip().decode().split()\r\nans = [\" \".join(u)]\r\nn = int(input())\r\nfor _ in range(n):\r\n v = input().rstrip().decode().split()\r\n f = 0\r\n for i in range(2):\r\n if f:\r\n break\r\n for j in range(2):\r\n if u[i] == v[j]:\r\n v[j] = u[i ^ 1]\r\n f = 1\r\n break\r\n u = v\r\n ans.append(\" \".join(u))\r\nsys.stdout.write(\"\\n\".join(ans))", "arr = input().split()\r\n\r\nn = int(input())\r\n\r\nfor i in range(n):\r\n print(*arr)\r\n x , y = input().split()\r\n if(arr[0] == x): arr[0] = y\r\n else: arr[1] = y\r\n\r\nprint(*arr)\r\n\r\n", "# The same file will be used throughout Problem Set by saving after writing different codes\r\ndef printlist(arr):\r\n print(\" \".join(arr));\r\n\r\ndef replaceName(arr, og_name, new_name):\r\n if arr[0] == og_name:\r\n arr[0] = new_name;\r\n else:\r\n arr[1] = new_name;\r\n return arr;\r\n\r\nnames = list(map(str, input().split()));\r\nprintlist(names);\r\nfor _ in range(int(input())):\r\n ogname, newname = map(str, input().split());\r\n if names[0] == ogname:\r\n names[0] = newname;\r\n else:\r\n names[1] = newname;\r\n printlist(names);\r\n ", "##n = int(input())\r\n##a = list(map(int, input().split()))\r\n##print(' '.join(map(str, res)))\r\n\r\n[a, b] = list(map(str, input().split()))\r\nn = int(input())\r\nprint(' '.join(map(str, [a, b])))\r\nfor i in range(n):\r\n [x, y] = list(map(str, input().split()))\r\n if x == a:\r\n a = y\r\n else:\r\n b = y\r\n print(' '.join(map(str, [a, b])))", "a,b=input().split()\r\nn=int(input())\r\nprint(a+\" \"+b)\r\n\r\nfor i in range(n):\r\n c,d=input().split()\r\n if a==c:\r\n a=d\r\n else:\r\n b=d\r\n \r\n print(a+\" \"+b)", "v1,v2 =map(str, input().split())\r\nn = int(input())\r\nx=[]\r\nx.append(v1)\r\nx.append(v2)\r\nprint(*x)\r\nfor i in range(n):\r\n v11,v12 = map(str,input().split())\r\n x.remove(v11)\r\n x.append(v12)\r\n print(*x)\r\n \r\n", "a,b=input().split()\nfor _ in range(int(input())):\n print(a,b)\n c,d=input().split()\n if c==a:\n a=d\n else:b=d\nprint(a,b)", "s = input().split()\r\nlis = []\r\nlis.append(\" \".join(s))\r\nn = int(input())\r\nfor i in range(n):\r\n m, n = input().split()\r\n s[s.index(m)] = n\r\n lis.append(\" \".join(s))\r\nfor i in lis:\r\n print(i)", "import itertools\r\n\r\n\r\ndef main():\r\n a, b = [v.strip() for v in input().split()]\r\n names = {a,b}\r\n n = int(input())\r\n print(\" \".join(list(names)))\r\n for i in range(n):\r\n na, nb = [v.strip() for v in input().split()]\r\n names.remove(na)\r\n names.add(nb)\r\n print(\" \".join(list(names)))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "l = input().split()\r\nn = int(input())\r\nprint(*l)\r\nfor i in range(n):\r\n t = input().split()\r\n l.remove(t[0])\r\n l.append(t[1])\r\n print(*l)", "a,b = list(input().split())\r\nn = int(input())\r\n\r\nprint(a, b)\r\n\r\nfor i in range(n):\r\n c,d = list(input().split())\r\n \r\n if a==c:\r\n a=d\r\n elif b==c:\r\n b=d\r\n \r\n print(a,b)", "x = input()\np = x.split()\na = int(input())\n\narray = []\nfor i in range(a):\n y = input()\n z = y.split()\n m = z[0]\n n = z[1]\n t = p.index(m)\n p[t] = n\n array.append(p[0])\n array.append(p[1])\n\nprint(x)\nfor i in range(0, (a*2), 2):\n print(array[i] + \" \" + array[i+1])\n\n\n\n \t \t \t \t\t \t\t\t \t \t\t\t\t \t\t\t \t\t", "name1,name2=input().split()\r\nn=int(input())\r\nprint(name1,name2)\r\nwhile(n>0):\r\n p,q=input().split()\r\n if(p==name1):\r\n name1=q\r\n print(name1,name2)\r\n n=n-1\r\n continue\r\n if(p==name2):\r\n name2=q\r\n print(name1,name2)\r\n n=n-1\r\n continue\r\n if(q==name1):\r\n name1=p\r\n print(name1,name2)\r\n n=n-1\r\n continue\r\n if(q==name2):\r\n name2=p\r\n print(name1,name2)\r\n n=n-1\r\n continue\r\n \r\n\r\n ", "\r\ndef main():\r\n s1, s2 = input().split()\r\n n = int(input())\r\n print(s1, s2)\r\n\r\n while n > 0:\r\n k1, k2 = input().split()\r\n if k1 == s1:\r\n s1 = k2\r\n else:\r\n s2 = k2\r\n n -= 1\r\n print(s1, s2)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "a=[s for s in input().split()]\r\nn=int(input())\r\nfor i in range(n):\r\n print(' '.join(j for j in a))\r\n x, y = [s for s in input().split()]\r\n if a[0]==x:\r\n a[0]=y\r\n else:\r\n a[1]=y\r\nprint(' '.join(j for j in a))", "a,b=input().split()\r\nn=int(input())\r\nprint(a,b)\r\ns=[a,b]\r\nfor i in range(n):\r\n\tx,y=input().split()\r\n\ts.remove(x)\r\n\ts.append(y)\r\n\tprint(*s)", "a, b = [i for i in input().split()]\r\nn = int(input())\r\nr = [[a, b]]\r\nfor j in range(n):\r\n c, d = [z for z in input().split()]\r\n if c == a:\r\n a = d\r\n else:\r\n b = d\r\n r.append([a, b])\r\nfor elem in r:\r\n print(*elem)\r\n", "people = input().split()\n\nn = int(input())\n\nprint(' '.join(people))\nfor i in range(n):\n p1, p2 = input().split()\n people[people.index(p1)] = p2\n print(' '.join(people))\n\n\n \t \t\t \t\t\t \t \t \t\t\t\t \t \t", "final = input().split(\" \")\nnum = int(input())\ndata = []\n\nfor hih in range(num):\n data.append(input().split(\" \"))\n\nprint(*final, sep=\" \")\nfor hih in data:\n final.remove(hih[0])\n final.append(hih[1])\n print(*final, sep=\" \")\n\n", "ipv1,ipv2=map(str,input().split())\r\nn=int(input())\r\nclist=[]\r\nfor i in range(0,n):\r\n listi=list(map(str,input().split()))\r\n clist.append(listi)\r\n \r\n\r\nlisti=[ipv1,ipv2]\r\nprint(*listi)\r\nfor i in range(0,n):\r\n listi.remove(clist[i][0])\r\n listi.insert(1,clist[i][1])\r\n print((*listi))", "a = input().split()\r\nx = int(input())\r\ns = [input().split() for i in range(x)]\r\nprint(a[0],a[1])\r\nt = a[0]\r\nt1 = a[1]\r\nfor i in range(x):\r\n\tif s[i][0] == t:\r\n\t\tprint(t1,s[i][1])\r\n\t\tt = t1\r\n\t\tt1 = s[i][1]\r\n\telif s[i][0] == t1:\r\n\t\tprint(t,s[i][1])\r\n\t\tt1 = s[i][1]", "x1, x2 = input().split()\nn = int(input())\nprint(x1,x2)\nfor i in range(n):\n\ty1,y2 = input().split()\n\tif(x1 == y1):\n\t\tx1 = y2\n\tif(x2 == y1):\n\t\tx2 = y2\n\tprint(x1,x2)", "s = input().split()\r\nn = int(input())\r\nkilled = [0]*n\r\nfor i in range(n):\r\n killed[i] = input().split()\r\nprint(s[0], s[1])\r\nfor i in range(n):\r\n if killed[i][0] == s[0]:\r\n s[0] = killed[i][1]\r\n else:\r\n s[1] = killed[i][1]\r\n print(s[0],s[1])", "s = list(input().split())\r\nprint(*s)\r\ncases = int(input())\r\nwhile cases:\r\n cases -= 1\r\n names = list(input().split())\r\n ind = s.index(names[0])\r\n s[ind] = names[1]\r\n print(*s)\r\n", "s=[x for x in input().split()]\r\nprint(s[0],s[1])\r\nn=int(input())\r\nfor i in range(n):\r\n a=[x for x in input().split()]\r\n if s[0] in a:\r\n if a[0]==s[0]:\r\n s.remove(s[0])\r\n s.append(a[1])\r\n else:\r\n s.remove(s[0])\r\n s.append(a[0])\r\n else:\r\n if a[0]==s[1]:\r\n s.remove(s[1])\r\n s.append(a[1])\r\n else:\r\n s.remove(s[1])\r\n s.append(a[0])\r\n print(s[0],s[1])", "def solve():\r\n killed=list(input().split());n=int(input());a=[list(input().split()) for i in range(n)]\r\n print(*killed)\r\n for i in a:\r\n if i[0]==killed[0]:killed[0]=i[1]\r\n else:killed[1]=i[1]\r\n print(*killed)\r\nsolve()", "b,c = input().split()\r\na = int(input())\r\nitems =[[b,c]]\r\n\r\nfor i in range(1,a+1):\r\n d,e = input().split()\r\n if d == items[i-1][0]:\r\n items += [[e,items[i-1][1]]]\r\n else:\r\n items += [[items[i-1][0],e]]\r\n \r\nfor x in range(len(items)):\r\n print (items[x][0] + \" \" + items[x][1])", "first_couple = input().split()\r\nprint(' '.join(first_couple))\r\n\r\nfor _ in range(int(input())):\r\n replace_people = input().split()\r\n index_couple = first_couple.index(replace_people[0])\r\n first_couple[first_couple.index(replace_people[0])] = replace_people[1]\r\n print(' '.join(first_couple))\r\n", "a,b=input().strip().split()[:2]\r\nn=int(input())\r\nprint(a,b)\r\nfor x in range(n):\r\n\tc,d=input().strip().split()[:2]\r\n\tif c==a:\r\n\t\tprint(d,b)\r\n\t\ta=d\r\n\telse:\r\n\t\tb=d\r\n\t\tprint(a,b)", "lst = []\r\nduo = input().split()\r\nn = int(input())\r\nfor _ in range(n):\r\n lst.append(input().split())\r\nres = [\" \".join(duo)]\r\nfor i in range(n):\r\n duo.remove(lst[i][0])\r\n duo.append(lst[i][1])\r\n res.append(\" \".join(duo))\r\nprint(\"\\n\".join(res))", "string = input()\r\npairs = [string]\r\nnames = string.split()\r\nn = int(input())\r\nfor x in range(n):\r\n string = input()\r\n temp = string.split()\r\n names.remove(temp[0])\r\n names.append(temp[1])\r\n pairs.append(\" \".join(names))\r\nfor x in pairs:\r\n print(x)", "s = input().split()\r\nfor i in range(int(input())):\r\n\tprint(s[0], s[1])\r\n\ts1 = input().split()\r\n\ts[s.index(s1[0])] = s1[1]\r\n\r\nprint(s[0], s[1])\r\n", "def main():\r\n a, b = input().split()\r\n n = int(input())\r\n print(a, b)\r\n for _ in range(n):\r\n x, y = input().split()\r\n if x == a:\r\n a = y\r\n else:\r\n b = y\r\n print(a, b)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "victims = set(input().split())\r\nprint(*victims)\r\n\r\nfor _ in range(int(input())):\r\n casualty, new_victim = input().split()\r\n victims.discard(casualty)\r\n victims.add(new_victim)\r\n print(*victims)", "a,b = map(str,input().split())\r\nn = int(input())\r\nprint(a,b)\r\nfor _ in range(n):\r\n c,d = map(str,input().split())\r\n if c==a:\r\n a=d\r\n else:\r\n b=d\r\n print(a,b)", "def solution(f,s,k,r):\r\n res =[0]*(n+1)\r\n res[0] = f +\" \" +s\r\n for i in range(1,n+1):\r\n if k[i-1] == res[i-1].split()[0] :\r\n res[i] = res[i-1].split()[1] + \" \"+ r[i-1]\r\n else:\r\n res[i] = res[i-1].split()[0]+ \" \"+ r[i-1]\r\n return res\r\nif __name__ == \"__main__\":\r\n f,s = input().split()\r\n n = int(input())\r\n k=[0]*n\r\n r= [0]*n\r\n for i in range(n):\r\n k[i],r[i] =input().split()\r\nfor ans in solution(f,s,k,r) :\r\n print(ans)", "victims = list(input().split(\" \"))\r\nn = int(input())\r\nprint(victims[0]+\" \"+victims[1])\r\nfor i in range(n):\r\n temp = list(input().split(\" \"))\r\n victims = [temp[1] if x==temp[0] else x for x in victims]\r\n print(victims[0]+\" \"+victims[1])", "init_victims = list(map(str, input().split()))\r\nnext_victims = []\r\ncurrent_victims = init_victims\r\nt = int(input())\r\nfor x in range(t):\r\n next_victims += list(map(str, input().split()))\r\nprint(' '.join(init_victims))\r\nwhile t != 0:\r\n current_victims.remove(next_victims.pop(0))\r\n current_victims.append(next_victims.pop(0))\r\n print(' '.join(current_victims))\r\n t -= 1\r\n", "a = input().split()\nprint(*a)\nfor i in range(int(input())):\n b = input().split()\n a[a.index(b[0])] = b[1]\n print(*a)", "ls = list(map(str, input().split()))\r\nn = int(input())\r\nprint(*ls)\r\nfor _ in range(n):\r\n tmp = list(map(str, input().split()))\r\n ls.remove(tmp[0])\r\n ls.append(tmp[1])\r\n print(*ls)\r\n", "a,b=map(str,input().split())\r\nn=int(input())\r\nmurdered=[]\r\nreplaced=[]\r\nfor i in range(n):\r\n m,s=map(str,input().split())\r\n murdered.append(m)\r\n replaced.append(s)\r\nl1=[a,b]\r\nprint(\" \".join(l1))\r\nfor i in range(n):\r\n if murdered[i]==l1[0]:\r\n l1.remove(l1[0])\r\n l1.append(replaced[i])\r\n print(\" \".join(l1))\r\n elif murdered[i]==l1[1]:\r\n l1.remove(l1[1])\r\n l1.append(replaced[i])\r\n print(\" \".join(l1))", "def solution():\r\n candidates = set(input().split())\r\n days = int(input())\r\n\r\n print(*candidates)\r\n\r\n for day in range(days):\r\n candidates ^= set(input().split())\r\n print(*candidates)\r\n\r\n\r\ndef main():\r\n solution()\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "a=input().split()\r\nprint(*a)\r\nfor i in range(int(input())):\r\n c,d = input().split()\r\n a[a.index(c)]=d\r\n print(*a)", "name1, name2 = input().lower().split(' ')\nprint(name1+\" \"+name2)\nn = int(input())\ni = 0\nwhile i < n:\n victim1, victim2 = input().lower().split(' ')\n if name1 == victim1:\n name1 = victim2\n elif name2 == victim1:\n name2 = victim2\n print(name1+\" \"+name2)\n i+=1\n# ross rachel\n# 4\n# ross joey\n# rachel phoebe\n# phoebe monica\n# monica chandler\n\n# icm codeforces\n# 1\n# codeforces technex\n", "start=input().split()\r\nprint(*start)\r\nnum=int(input())\r\nfor _ in range(num):\r\n s,c=input().split()\r\n start[start.index(s)]=c\r\n print(*start)\r\n\r\n\r\n", "def main():\r\n a = input().split()\r\n print(*a)\r\n for i in range(int(input())):\r\n b, c = input().split()\r\n a[a.index(b)] = c\r\n print(*a)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "def main():\n state = dict.fromkeys(input().split())\n print(' '.join(list(state.keys())))\n\n for _ in range(int(input())):\n next_choices = input().split()\n del state[next_choices[0]]\n state[next_choices[1]] = 0\n print(' '.join(list(state.keys())))\n\n\nif __name__ == '__main__':\n main()\n", "if __name__ == '__main__':\r\n f, s = input().split(' ')\r\n print(f + ' ' + s)\r\n n = int(input())\r\n for i in range(n):\r\n ft, st = input().split(' ')\r\n if f == ft:\r\n f = st\r\n else:\r\n s = st\r\n print(f + ' ' + s)", "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-22 23:09:57\nLastEditTime: 2021-11-22 23:14:48\nDescription: A Serial Killer\nFilePath: CF776A.py\n'''\n\n\ndef func():\n lst = input().strip().split()\n n = int(input())\n print(\" \".join(lst))\n for _ in range(n):\n old, new = input().strip().split()\n lst.remove(old)\n lst.append(new)\n print(\" \".join(lst))\n\n\nif __name__ == '__main__':\n func()\n", "v1,v2 = list(input().split())\r\nn = int(input())\r\nprint(v1,v2)\r\nfor i in range(n):\r\n\tvictim_replaced, victim_new = list(input().split())\r\n\tprint(victim_new,end=' ')\r\n\tif(v1 == victim_replaced):\r\n\t\tv1 = victim_new\r\n\t\tprint(v2)\r\n\telse:\r\n\t\tv2 = victim_new\r\n\t\tprint(v1)", "a,b=map(str,input().split())\r\nprint(a,b)\r\nn=int(input())\r\nfor i in range(n):\r\n h,k=map(str,input().split())\r\n if(h==a):\r\n a=k\r\n else:\r\n b=k\r\n print(a,b)", "poten_vi_1,poten_vi_2=input().split()\r\nn=int(input())\r\ncurr_vi_1,curr_vi_2=poten_vi_1,poten_vi_2\r\nprint(curr_vi_1,curr_vi_2)\r\nfor _ in range(n):\r\n muder_person,new_postion=input().split()\r\n if curr_vi_1==muder_person:\r\n curr_vi_1=new_postion\r\n else:\r\n curr_vi_2=new_postion\r\n print(curr_vi_1,curr_vi_2)", "\r\n\r\nx , y = input().split()\r\nn = int(input())\r\nprint(x , y)\r\nfor i in range(n):\r\n z , z1 = input().split()\r\n if(x == z):\r\n x = z1\r\n else:\r\n y = z1\r\n print(x , y)\r\n \r\n", "import math\ndef solve(arr1,arr2):\n print(*arr1)\n temp1= arr1[0]\n temp2 = arr1[1]\n for i in arr2:\n if i[0] == temp1:\n temp1 = i[1]\n else:\n temp2 = i[1]\n print(temp1,temp2)\n \n\n \ndef main():\n #arr1 =list(map(int,input().split(' ')))\n arr1 =input().split(' ')\n arr2 = []\n n = int(input())\n for j in range(n):\n i = input().split(' ')\n # i = input().split(' ')\n #i = int(''.join(input().split(' ')))\n arr2.append(i)\n solve(arr1,arr2)\n\nmain()", "p1, p2 = input().split(\" \")\r\n\r\nprint(p1, p2)\r\n\r\nn = int(input())\r\n\r\nfor i in range(n):\r\n morreu, trocou = input().split(\" \")\r\n if morreu == p1:\r\n p1 = trocou\r\n print(p1, p2)\r\n else:\r\n p2 = trocou\r\n print(p1, p2)", "a = [i for i in input().split()]\r\nn = int(input())\r\nprint(*a)\r\nfor j in range(n):\r\n b = [i for i in input().split()]\r\n if b[0] == a[0]:\r\n a[0] = b[1]\r\n else:\r\n a[1] = b[1]\r\n print(*a)", "potential1, potential2 = input().split()\r\nn = int(input())\r\nprint(potential1, potential2)\r\nfor i in range(n):\r\n killed, newPotential = input().split()\r\n if killed == potential1:\r\n potential1 = newPotential\r\n else:\r\n potential2 = newPotential\r\n print(potential1, potential2)", "n1,n2 = input().split(\" \")\r\nn = int(input())\r\nl = [[n1,n2]]\r\nfor i in range(n):\r\n m1,m2 = input().split(\" \")\r\n if(m1==n1):\r\n l.append([m2,n2])\r\n n1 = m2[:]\r\n n2 = n2[:]\r\n elif(m1==n2):\r\n l.append([n1,m2])\r\n n1 = n1[:]\r\n n2 = m2[:]\r\nfor i in l:\r\n print(*i)\r\n\r\n \r\n \r\n", "# import sys \r\n# sys.stdin=open(\"input1.in\",\"r\")\r\n# sys.stdout=open(\"output2.out\",\"w\")\r\nX,Y=input().split()\r\nprint(X,Y)\r\nN=int(input())\r\nfor i in range(N):\r\n\tZ,M=input().split()\r\n\tif X==Z:\r\n\t\tX=M\r\n\telse:\r\n\t\tY=M\r\n\tprint(X,Y)\r\n\r\n", "str1, str2 = map(str, input().split())\r\nn = int(input())\r\ndict1 = {}\r\nfor x in range(n):\r\n str3, str4 = map(str, input().split())\r\n dict1[str3] = str4\r\nprint(str1, str2)\r\nfor key, values in dict1.items():\r\n if (key == str1):\r\n str1 = values\r\n print(str1, str2)\r\n else:\r\n str2 = values\r\n print(str1, str2)\r\n", "l=list(map(str,input().split()))\r\nprint(*l)\r\nn=int(input())\r\nfor i in range(n):\r\n\ta,b=map(str,input().split())\r\n\t# print(*l)\r\n\tl.remove(a)\r\n\tl.append(b)\r\n\tprint(*l)", "op1,op2=[x for x in input().split(\" \")]\r\nprint(op1,op2)\r\nn=int(input())\r\nwhile n:\r\n n-=1\r\n x,y=[x for x in input().split(\" \")]\r\n if x==op1: op1=y\r\n elif x==op2: op2=y\r\n print(op1,op2)", "def solve():\r\n p1,p2=input().split()\r\n\r\n n=int(input())\r\n\r\n print(p1,p2)\r\n\r\n for i in range(n):\r\n s1,s2=input().split()\r\n if s1==p1:\r\n print(p2,s2)\r\n p1=p2\r\n p2=s2\r\n if s1==p2:\r\n print(p1,s2)\r\n p2=s2\r\n\r\n\r\nsolve()\r\n\r\n", "ls=list(map(str,input().rstrip().split()))\r\nn=int(input())\r\nprint(ls[0],ls[1])\r\nfor i in range(n):\r\n lsd=list(map(str,input().rstrip().split()))\r\n if(lsd[0]==ls[0]):\r\n ls[0]=lsd[1]\r\n else:\r\n ls[1]=lsd[1]\r\n print(ls[0],ls[1])", "victims=[x for x in input().split()]\r\npotentialVictims={}\r\npotentialVictims[victims[0]] = True\r\npotentialVictims[victims[1]] = True \r\nfor i in range(int(input())):\r\n murdered, added = [i for i in input().split()]\r\n print(*list(potentialVictims.keys()))\r\n del potentialVictims[murdered]\r\n potentialVictims[added] = True\r\n\r\nprint(*list(potentialVictims.keys()))\r\n", "person = input().split()\r\nprint(*person)\r\nfor i in range(int(input())):\r\n a, b = input().split()\r\n person.remove(a)\r\n person.append(b)\r\n print(*person)\r\n", "l=[]\r\ntemp=[]\r\nt=list(map(str,input().split()))\r\nn=int(input())\r\nprint(*t)\r\nfor _ in range(n):\r\n a,b=map(str,input().split())\r\n if a not in t:\r\n if(b==t[0]):\r\n t[0]=a\r\n print(*t)\r\n else:\r\n t[1]=a\r\n print(*t)\r\n else:\r\n if(a==t[0]):\r\n t[0]=b\r\n print(*t)\r\n else:\r\n t[1]=b\r\n print(*t)\r\n\r\n", "s=input()\r\na=s.split(\" \")\r\nprint(*a)\r\nfor i in range(int(input())):\r\n x=input()\r\n b=x.split(\" \")\r\n if(a[0]==b[0]):\r\n a[0]=b[1]\r\n elif(a[1]==b[0]):\r\n a[1]=b[1]\r\n print(*a)\r\n", "people = [x for x in input().split()]\r\ndays = int(input())\r\nfor o in range(days):\r\n print(people[0] + \" \" + people[1])\r\n inp = [x for x in input().split()]\r\n if people[0] == inp[0]:\r\n people[0] = inp[1]\r\n else:\r\n people[1] = inp[1]\r\nprint(people[0] + \" \" + people[1])", "s=list(input().split())\r\nprint(s[0],s[1])\r\nn=int(input())\r\nfor i in range (n):\r\n\ta,b=input().split()\r\n\ts.remove(a)\r\n\ts.append(b)\r\n\tprint(s[0],s[1])", "m = set([i for i in input().split()])\nn = int(input())\nl = [set([i for i in input().split()]) for i in range(n)]\nprint(*m)\nfor i in l:\n\tm ^= i\n\tprint(*m)\n\n\n", "c,d=input().split()\r\nn=int(input())\r\nz=[]\r\nprint(c,d)\r\nfor i in range(n):\r\n a,b=input().split()\r\n x=\"\"\r\n if c==a:\r\n x=b\r\n c=x\r\n print(x,d)\r\n elif d==a:\r\n x=b\r\n d=x\r\n print(c,x)\r\n ", "v1,v2 = map(str, input().split())\r\ndays = int(input())\r\nvictims = [[v1,v2]]\r\n\r\nwhile days>0:\r\n killed, new = map(str, input().split())\r\n if killed == v1:\r\n v1 = new\r\n else:\r\n v2 = new\r\n victims.append([v1,v2])\r\n\r\n days-=1\r\n\r\n\r\nfor i in victims:\r\n print(' '.join(i))", "s1, s2 = input().split()\nn = int(input())\nfor i in range(n):\n print(s1, s2)\n t1, t2 = input().split()\n if s1 == t1:\n s1 = t2\n elif s1 == t2:\n s1 = t1\n elif s2 == t1:\n s2 = t2\n else:\n s2 = t1\nprint(s1, s2)\n", "surv = input().split()\r\nn = int(input())\r\nprint(\" \".join(surv))\r\nfor i in range(n):\r\n a,b = input().split()\r\n if a in surv:\r\n surv.remove(a)\r\n surv.append(b)\r\n \r\n print(\" \".join(surv))", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\npv = set(input().split())\r\nprint(*pv)\r\n\r\nfor _ in range(int(input())):\r\n a, b = input().split()\r\n pv.remove(a)\r\n pv.add(b)\r\n print(*pv)\r\n", "lst = input().split()\r\nprint(\" \".join(lst))\r\n\r\nfor i in range(int(input())):\r\n kill, ext = input().split()\r\n lst[lst.index(kill)] = ext\r\n print(\" \".join(lst))", "x=list(input().split())\r\nprint(*x)\r\nfor i in range(int(input())):\r\n c,d=input().split()\r\n x.remove(c)\r\n x.append(d)\r\n print(*x)", "vic1, vic2 = map(str, input().split())\r\nprint(vic1, vic2)\r\nfor i in range(int(input())):\r\n mur, replace = map(str, input().split())\r\n if(vic1 == mur):\r\n vic1 = replace\r\n else:\r\n vic2 = replace\r\n print(vic1, vic2)\r\n", "k1, k2 = map(str, input().split())\r\nn = int(input())\r\n\r\nfor i in range(0, n):\r\n x, y = map(str, input().split())\r\n if i == 0:\r\n print(k1, k2)\r\n if k1 == x:\r\n k1 = y\r\n elif k2 == x:\r\n k2 = y\r\n\r\n print(k1, k2)\r\n", "'''input\r\nross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n'''\r\nkill,replace=list(input().strip().split(' '))\r\nprint(kill,replace)\r\nn=int(input())\r\nfor i in range(n):\r\n\tp1,p2=list(input().strip().split(' '))\r\n\tif kill==p1:\r\n\t\tkill=replace\r\n\t\treplace=p2\r\n\telse:\r\n\t\treplace=kill\r\n\t\tkill=p2\r\n\tprint(kill,replace)", "start = input().split()\r\nn = int(input())\r\n\r\nv = []\r\nm = n\r\nwhile m > 0:\r\n s, t = input().split()\r\n v.append([s, t])\r\n m -= 1\r\n\r\nanswer = start[0] + \" \" + start[1]\r\n\r\nfor i in range(len(v)):\r\n if start[0] == v[i][0]:\r\n start[0] = v[i][1]\r\n answer += \"\\n\" + start[0] + \" \" + start[1]\r\n elif start[1] == v[i][0]:\r\n start[1] = v[i][1]\r\n answer += \"\\n\" + start[0] + \" \" + start[1]\r\n\r\nprint(answer)", "s1,s2 = input().split()\r\n\r\nn = int(input())\r\nfor i in range(n):\r\n print(s1,s2)\r\n s,c = input().split()\r\n if s == s1:\r\n s1 = c\r\n else:\r\n s2 = c\r\nprint(s1,s2)\r\n", "days = input().split()\r\nn = int(input())\r\nfor i in range(0,2*n,2):\r\n cur_day_f, cur_day_s = input().split()\r\n days.append(cur_day_s)\r\n if cur_day_f == days[i]:\r\n days.append(days[i+1])\r\n else:\r\n days.append(days[i])\r\nfor i in range(0,(2*n)+2,2):\r\n print(days[i],days[i+1]) ", "first, second = input().split()\r\n\r\nn = int(input())\r\nprint(first, second)\r\nfor i in range(n):\r\n corp, alive = input().split()\r\n if corp == first:\r\n first = alive\r\n else:\r\n second = alive\r\n print(first, second)", "a = input().split()\nprint(*a)\nn = int(input())\n#n, m = map(int, input().split())\n#s = input()\n#c = list(map(int, input().split()))\nfor i in range(n):\n s = input().split()\n a[a.index(s[0])] = s[1]\n print(*a)\n ", "S = input().split()\nN = int(input())\nfor i in range(N):\n print(\" \".join(S))\n s1, s2 = input().split()\n if s1 == S[0]:\n S[0] = s2\n elif s1 == S[1]:\n S[1] = s2\nprint(\" \".join(S))\n", "lst = list(map(str, input().split()))\r\nprint(*lst)\r\nfor u in range(int(input())):\r\n a, b = map(str, input().split())\r\n if a == lst[0]: lst[0] = b\r\n else: lst[1] = b\r\n print(*lst)", "l=[str(i) for i in input().split()]\r\nn=int(input())\r\nprint(*l)\r\nfor i in range(n):\r\n a=[str(i) for i in input().split()]\r\n if(a[0]==l[0]):\r\n l[0]=a[1]\r\n else:\r\n l[1]=a[1]\r\n print(*l)", "name_one,name_two = input().split()\r\nprint (name_one, name_two)\r\n\r\nt = int(input())\r\n\r\nfor i in range (t):\r\n name_three, name_four = input().split()\r\n \r\n if name_one == name_three :\r\n name_one = name_four\r\n elif name_one == name_four:\r\n name_one = name_three\r\n elif name_two == name_three :\r\n name_two = name_four\r\n else:\r\n name_two = name_three\r\n \r\n print (name_one, name_two)", "def solve():\n new_names = next(name_gen)\n solution = (names | new_names) - (new_names & names)\n print_names(solution)\n return solution\n\n\ndef read_names():\n while True: yield set(input().split())\n\n\ndef print_names(names):\n print(' '.join(names))\n\n\ndef main():\n global name_gen, names, n\n name_gen = read_names()\n\n names = next(name_gen)\n print_names(names)\n\n n = int(input()) \n for _ in range(n):\n names = solve()\n\nmain()\n", "s1, s2 = input().split()\r\n\r\nn = int(input())\r\nfor i in range(n):\r\n print(s1, s2)\r\n killed, new = input().split()\r\n if s1 == killed:\r\n s1 = new\r\n else:\r\n s2 = new\r\n \r\nprint(s1, s2)", "name1, name2 = input().split()\r\ni = int(input())\r\nc = 0\r\nwhile c < i and 0 <= i <= 1000:\r\n print(name1, name2)\r\n name3, name4 = input().split()\r\n if name1 == name3 or name1 == name4:\r\n name1 = name4\r\n if name2 == name4 or name2 == name3:\r\n name2 = name4\r\n c += 1\r\n if c >= i:\r\n print(name1, name2)\r\n", "x=str(input(\"\"))\r\narr1=[]\r\narr1=x.split()\r\narr3=x.split()\r\ny=int(input(\"\"))\r\nfor i in range(y):\r\n z=str(input(\"\"))\r\n x1=[]\r\n x1=z.split()\r\n ind=arr1.index(x1[0]) #0\r\n arr1.remove(x1[0])\r\n arr1.insert(ind,x1[1])\r\n arr3=arr3+arr1\r\nfor k in range(0,2*(y+1),2):\r\n print(arr3[k],arr3[k+1])", "c = input().split()\r\n\r\nn = int(input())\r\na = []\r\nb = []\r\nfor i in range(n):\r\n tested, new = input().split()\r\n a.append(tested)\r\n b.append(new)\r\n\r\nfor i in range(n + 1):\r\n print(*reversed(c))\r\n\r\n if i < n:\r\n c.remove(a[i])\r\n c.append(b[i])\r\n\r\n", "x, y = input(\"\").split()\np, q = x,y\nl = []\nn = int(input())\nfor i in range(n):\n a, b = input(\"\").split()\n if x == a:\n l.append(b)\n x = b\n l.append(y)\n elif y == a:\n l.append(x)\n y = b\n l.append(y)\nprint(f\"{p} {q}\")\nfor i in range(0,len(l),2):\n print(f\"{l[i]} {l[i+1]}\")\n\n", "a,b=input().split()\r\nprint(a,b)\r\nfor _ in range(int(input())):\r\n x,y=input().split()\r\n if(x==a):\r\n a=y\r\n else:\r\n b=y\r\n print(a,b)", "a,b=input().split(' ')\r\nprint(a+' '+b)\r\nn=int(input())\r\nfor i in range(n):\r\n\tc,d=input().split(' ')\r\n\tif c==a:\r\n\t\ta=d\r\n\telse:\r\n\t\tb=d\r\n\tprint(a+' '+b)", "# get first two victims and number of days\r\nv1, v2 = [x for x in input().split(' ')]\r\nn = int(input())\r\n\r\nprint(v1 + ' ' + v2)\r\n\r\nfor i in range(n):\r\n murd, repl = [x for x in input().split(' ')]\r\n if v1 == murd:\r\n v1 = repl\r\n else:\r\n v2 = repl\r\n print(v1 + ' ' + v2)\r\n", "l=list(input().split());print(*l)\r\nfor _ in range(int(input())):m,n=input().split();l[l.index(m)]=n;print(*l)", "n,m=map(str,input().split());s,k=n,m;print(s,k)\r\nfor i in range(int(input())):\r\n q,w=map(str,input().split())\r\n if s==q:s=w;print(s,k)\r\n else:k=w;print(s,k)\r\n", "v = input().split(' ')\r\nprint(* v)\r\nn = int(input())\r\nfor i in range(n):\r\n w = input().split(' ')\r\n v.remove(w[0])\r\n v.append(w[1])\r\n print(*v)", "f , k = map(str , input() .split())\r\nn = int(input())\r\nprint(f,k)\r\nt1 = f\r\nt2 = k\r\nfor i in range (n):\r\n v1,v2 = map(str , input() .split())\r\n if v1 == t1:\r\n print(v2,t2)\r\n t1 = v2\r\n t2 = t2\r\n else:\r\n print(t1,v2)\r\n t1 = t1\r\n t2 = v2", "class CodeforcesTask776ASolution:\n def __init__(self):\n self.result = ''\n self.pair = []\n self.n = 0\n self.murder_replace = []\n\n def read_input(self):\n self.pair = input().split(\" \")\n self.n = int(input())\n for _ in range(self.n):\n self.murder_replace.append(input().split(\" \"))\n\n def process_task(self):\n res = []\n to_choose = set(self.pair)\n for day in self.murder_replace:\n res.append(\" \".join(to_choose))\n to_choose.remove(day[0])\n to_choose.add(day[1])\n res.append(\" \".join(to_choose))\n self.result = \"\\n\".join(res)\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask776ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "line = [x for x in input().split()]\n\nf1, f2 = line[0], line[1]\n\nn = int(input())\n\nfor i in range(n):\n print(f1, f2)\n line = [x for x in input().split()]\n f3, f4 = line[0], line[1]\n if f1 == f3:\n f1 = f4\n else:\n f2 = f4\nprint(f1, f2)\n", "v=list(map(str,input().split()))\r\nn=int(input())\r\nprint(*v)\r\nfor i in range(n):\r\n v1,v2=map(str,input().split())\r\n if v1 in v:\r\n v.remove(v1)\r\n v.append(v2)\r\n print(*v)", "a, b = input().split() # initial list of victims\r\n\r\nn = int(input()) # num of days\r\n\r\nprint(a, b)\r\n\r\nfor _ in range(n):\r\n dead, replacement = input().split()\r\n\r\n if a == dead:\r\n a = replacement\r\n else:\r\n b = replacement\r\n\r\n print(a, b)\r\n", "s = list(map(str, input().split()))\r\nprint(*s)\r\nfor cas in range(int(input())):\r\n t = list(map(str, input().split()))\r\n if s[0] == t[0]:\r\n s[0] = t[1]\r\n elif s[0] == t[1]:\r\n s[0] = t[0]\r\n elif s[1] == t[0]:\r\n s[1] = t[1]\r\n else:\r\n s[1] = t[0]\r\n print(*s)", "init = input()\r\nprint(init)\r\ninit = init.split()\r\nt = int(input())\r\nfor x in range(t):\r\n \r\n init+=input().split()\r\n for y in init:\r\n if init.count(y)==2:\r\n init.remove(y)\r\n init.remove(y)\r\n print(*init)", "\r\nl = list(input().split())\r\nprint(*l , sep = ' ')\r\nn = int(input())\r\nfor _ in range(n):\r\n\t\r\n\tli = list(input().split())\r\n\t\r\n\tind = l.index(li[0])\r\n\tl[ind] = li[1]\r\n\tprint(*l , sep = ' ')\r\n\r\n\r\n", "s, t = map(str, input().split())\r\nl = [s, t]\r\nn = int(input())\r\nfor i in range(n):\r\n print(*l)\r\n s, t = map(str, input().split())\r\n if s == l[0]:\r\n l[0] = t\r\n else:\r\n l[1] = t\r\nprint(*l)\r\n", "# import sys\r\n# sys.stdin=open(\"input.in\",\"r\")\r\na,b=input().split()\r\nprint(a,b)\r\nfor i in range(int(input())):\r\n\tc,d=input().split()\r\n\tif a==c:\r\n\t\ta=d\r\n\telif b==c:\r\n\t\tb=d\r\n\tprint(a,b)", "# n = input()\n\n# s = list(set(n))\n\n# if len(s)>2:\n# return ('NO')\n\n# def f(arr1,arr2):\n \n\nword = input().split()\n\nn = int(input())\n\nprint(\" \".join(word))\nfor i in range(n):\n arr = input().split()\n\n word[word.index(arr[0])] = arr[1]\n\n print(\" \".join(word))\n", "# LUOGU_RID: 101649152\na = input().split()\r\nprint(*a)\r\nfor _ in ' ' * int(input()):\r\n b, c = input().split()\r\n a[a.index(b)] = c\r\n print(*a)", "s=input().split()\r\nprint(*s)\r\nfor i in range(int(input())):\r\n\tx,y=input().split()\r\n\ts[s.index(x)]=y\r\n\tprint(*s)", "s1,s2=input().split()\r\nn=int(input())\r\nprint(s1,s2)\r\nfor i in range(n):\r\n s3,s4=input().split()\r\n if s3==s1:\r\n s1=s2\r\n s2=s4\r\n print(s1,s2)", "a, b = input().split()\r\nfor _ in range(int(input())):\r\n print(a, b)\r\n c, d = input().split()\r\n if c == a:\r\n a = d\r\n else:\r\n b = d\r\nprint(a, b)\r\n", "victims = input().split()\r\nprint(victims[0], victims[1])\r\ncases = int(input())\r\nfor _ in range(cases):\r\n killed, rep = input().split()\r\n if victims[0] == killed:\r\n victims[0] = rep\r\n else:\r\n victims[1] = rep\r\n print(victims[0], victims[1])", "l=list(map(str,input().split()))\r\nn=int(input())\r\np=[]\r\nfor i in range(n):\r\n t=list(map(str,input().split()))\r\n p.append(t)\r\n\r\nt=[]\r\nt.append(l)\r\nfor i in range(n):\r\n if t[len(t)-1][0]==p[i][0]:\r\n a=p[i][1]\r\n t.append([a,t[len(t)-1][1]])\r\n elif t[len(t)-1][1]==p[i][0]:\r\n b=p[i][1]\r\n t.append([t[len(t)-1][0],b])\r\nfor i in t:\r\n for k in i:\r\n print(k,end=\" \")\r\n print()\r\n ", "names=input()\r\nlist=names.split()\r\na=list[0]\r\nb=list[1]\r\nn=int(input())\r\nprint(a+\" \"+b)\r\nfor i in range(0,n):\r\n names=input()\r\n list=names.split()\r\n if a==list[0]:\r\n a=list[1]\r\n elif b==list[0]:\r\n b=list[1]\r\n print(a+\" \"+b)", "s = input().split()\r\nn = int(input())\r\nprint(*s)\r\nfor i in range(n):\r\n\tk = input().split()\r\n\ts[s.index(k[0])]=k[1]\r\n\tprint(*s)", "ans = input().split()\r\nn = int(input())\r\nprint(*ans)\r\nfor _ in range(n):\r\n names = input().split()\r\n for i in range(2):\r\n if ans[i] == names[0]:\r\n ans[i] = names[1]\r\n print(*ans)", "m, n = map(str, input().split())\r\nm, n = m.lower(), n.lower()\r\n\r\ndef serial_killer(x, y):\r\n global m, n\r\n if x == m:\r\n m = y\r\n print(str(m) + ' ' + str(n))\r\n if x == n:\r\n n = y\r\n print(str(m) + ' ' + str(n))\r\n \r\n \r\np = int(input())\r\nprint(str(m) + ' ' + str(n))\r\nfor _ in range(p):\r\n x, y = map(str, input().split())\r\n x, y = x.lower(), y.lower()\r\n serial_killer(x, y)", "one, other = [ str(x) for x in input().split()]\r\n\r\nmurders = int(input())\r\n\r\nfor i in range(murders):\r\n killed, replaced_by = [ str(x) for x in input().split()]\r\n\r\n print(f'{one} {other}')\r\n if( killed == one):\r\n one = replaced_by\r\n else:\r\n other = replaced_by\r\nprint(f'{one} {other}')\r\n", "initial = input().split()\nn = int(input())\n\nvictims = []\n\nm = n\n\nwhile m>0:\n s,t = input().split()\n victims.append([s,t])\n m-=1\n\nanswer = initial[0]+\" \"+initial[1]\n\nfor i in range(len(victims)):\n if initial[0]==victims[i][0]:\n initial[0] = victims[i][1]\n answer+=\"\\n\"+initial[0]+\" \"+initial[1]\n elif initial[1]==victims[i][0]:\n initial[1] = victims[i][1]\n answer+=\"\\n\"+initial[0]+\" \"+initial[1]\n\nprint(answer)\n\n \t\t \t \t\t\t\t\t \t\t\t \t\t \t\t \t", "a, b = input().split()\r\n\r\nn = int(input())\r\n\r\nfor i in range(n):\r\n print(a, b)\r\n k, r = input().split()\r\n if a == k:\r\n a = r\r\n else:\r\n b = r\r\nprint(a, b)\r\n", "a,b = input().split()\r\nn = int(input())\r\nfor i in range(n):\r\n print(a,b)\r\n c,d = input().split()\r\n if a==c:\r\n a = d\r\n elif b==c:\r\n b = d\r\nprint(a,b)\r\n", "p1,p2 = input().split()\nprint(p1,p2)\ntmp={1:p1,2:p2}\nfor i in range(int(input())):\n m,r = input().split()\n if tmp[1]==m:\n tmp[1]=r\n print(tmp[1],tmp[2])\n else:\n tmp[2]=r\n print(tmp[1],tmp[2])\n", "names = list(map(str, input().split()))\r\nn = int(input())\r\nprint(*names)\r\nfor i in range(n):\r\n s1, s2 = map(str, input().split())\r\n if names[0] == s1:\r\n names[0] = s2\r\n else:\r\n names[1] = s2\r\n print(*names)\r\n", "nomes = input().split()\r\nprint(\" \".join(nomes))\r\nn = int(input())\r\nfor i in range(n):\r\n nl = input().split()\r\n nomes[nomes.index(nl[0])] = nl[1]\r\n print(\" \".join(nomes))\r\n", "a,b=input().split()\nfor _ in range(int(input())):\n\tprint(a,b)\n\tc,d=input().split()\n\tif a==c:\n\t\ta=d\n\telse:\n\t\tb=d\nprint(a,b)\n \t\t \t\t \t \t\t\t \t \t \t \t\t \t \t", "a,b=map(str,input().split())\r\nn=int(input())\r\nprint(a,b)\r\nfor i in range(n):\r\n c,d=map(str,input().split())\r\n if a==c :\r\n a=d\r\n else:\r\n b=d\r\n print(a,b)", "# https://codeforces.com/problemset/problem/776/A\n# 900\n\niv = input().split()\nn = int(input())\n\nprint(\" \".join(iv))\nfor _ in range(n):\n k, r = input().split()\n iv.remove(k)\n iv.append(r)\n print(\" \".join(iv))\n", "def solve(names, new_names):\n solution = (names | new_names) - (new_names & names)\n return solution\n\n\ndef read_names():\n while True: yield set(input().split())\n\n\ndef print_names(names):\n print(' '.join(names))\n\n\ndef main():\n namesg = read_names()\n\n names = next(namesg)\n print_names(names)\n\n n = int(input()) \n for _ in range(n):\n new_names = next(namesg)\n names = solve(names, new_names)\n print_names(names)\n\n\nmain()\n", "name1, name2 = input().split()\r\nnum = int(input())\r\nlst = [name1, name2]\r\nprint(*lst)\r\nfor i in range(num):\r\n temp1, temp2 = input().split()\r\n pos = lst.index(temp1)\r\n lst[pos] = temp2\r\n print(*lst)\r\n\r\n\r\n", "# python master kru ya c++ pe shift ho jaau?\r\ns=str(input())\r\nsp=s.split()\r\nt=int(input())\r\nstore=s+\"\\n\"\r\nfor i in range(t):\r\n s1=str(input())\r\n s2=s1.split()\r\n isp=sp.index(s2[0])\r\n sp[isp]=s2[1]\r\n s=\" \".join(sp)\r\n store+=s+\"\\n\"\r\nprint(store,end=\"\")", "a={*input().split()}\r\nprint(*a)\r\nfor _ in[0]*int(input()):\r\n b,c=input().split()\r\n a=a-{b}|{c}\r\n print(*a)", "R = lambda:[x for x in input().split()]\r\none, two = R()\r\nprint(one, two)\r\nn = int(input())\r\nfor _ in range(n):\r\n aone, atwo = R()\r\n if one == aone: one = atwo\r\n if two == aone: two = atwo\r\n print(one, two)", "n = list(input().split(\" \"))\nnum = int(input())\nfirst = f'{n[0]} {n[1]}'\nanslist =[first]\nfor _ in range(num):\n\tnewstring = list(input().split(\" \"))\n\tif(newstring[0] in n):\n\t\tif(newstring[0] == n[0]):\n\t\t\tn[0]=newstring[1]\n\t\telse:\n\t\t\tn[1]=newstring[1]\n\tanslist.append(f'{n[0]} {n[1]}')\n\t\nfor i in anslist:\n\tprint(i)\n\n \t\t \t \t\t\t\t \t \t\t \t \t\t\t\t", "nome1, nome2 = input().split()\nprint(nome1, nome2)\nfor i in range(int(input())):\n assassinado, substituto = input().split()\n if assassinado == nome1:\n nome1 = substituto\n else:\n nome2 = substituto\n print(nome1, nome2)", "a, b = map(str, input().split())\r\nprint(a, b, sep=' ')\r\nn = int(input())\r\nfor i in range(n):\r\n c, d = map(str, input().split())\r\n if c == a:\r\n a = d\r\n if c == b:\r\n b = d\r\n print(a, b, sep=' ')\r\n\r\n # CodeForcesian\r\n# ♥\r\n# زبل\r\n", "pair = list(map(str, input().split()))\r\nn = int(input())\r\nprevPair = pair\r\nprint(*prevPair, sep=\" \")\r\n\r\nwhile n > 0:\r\n pair = list(map(str, input().split()))\r\n prevPair[prevPair.index(pair[0])] = pair[1]\r\n print(*prevPair, sep=\" \")\r\n n -= 1", "a, b = input().split(' ')\nn = int(input())\nprint(a, b)\nfor i in range(n):\n c, d = input().split(' ')\n if c == a:\n a = d\n else:\n b = d\n print(a, b)\n", "a, b = map(str, input().split())\r\nn = int(input())\r\nlst = [a, b]\r\nlst_output = [a, b]\r\n\r\nfor i in range(n):\r\n c, d = map(str, input().split())\r\n lst.append(c)\r\n lst.append(d)\r\n\r\ndef all_index(lst1, word):\r\n all_index1 = []\r\n for k in range(len(lst1)):\r\n if lst1[k] == word:\r\n all_index1.append(k)\r\n\r\n return all_index1\r\n\r\nfor i in range(2, len(lst), 2):\r\n lst_idx = all_index(lst_output, f\"{lst[i]}\")\r\n\r\n for w in range(len(lst_idx)):\r\n if lst_idx[w] == i-2:\r\n lst_output += [lst[i+1], lst_output[i-1]]\r\n\r\n elif lst_idx[w] == i-1:\r\n lst_output += [lst_output[i-2], lst[i+1]]\r\n\r\nfor z in range(0, len(lst_output), 2):\r\n print(lst_output[z], end=\" \"), print(lst_output[z+1])", "import sys \r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(A):\r\n n = len(A)\r\n answer = [A[0]]\r\n for i in range(1, n):\r\n a1, b1 = answer[-1]\r\n a2, b2 = A[i]\r\n if a1==a2:\r\n answer.append([b1, b2])\r\n elif a1==b2:\r\n answer.append([a2, b1])\r\n elif b1==a2:\r\n answer.append([a1, b2])\r\n elif b1==b2:\r\n answer.append([a1,a2])\r\n for a, b in answer:\r\n sys.stdout.write(f\"{a} {b}\\n\")\r\n \r\na, b = input().decode().strip().split()\r\nn = int(input())\r\nA = [[a, b]]\r\nfor i in range(n):\r\n a, b = input().decode().strip().split()\r\n A.append([a, b])\r\nprocess(A)", "a,b = input().split()\r\nprint(a,b)\r\nfor _ in range(int(input())):\r\n c,d = input().split()\r\n if a == c:\r\n a = d\r\n print(a,b)\r\n elif b == c:\r\n b = d\r\n print(a,b)\r\n\r\n\r\n", "str1,str2 = map(str,input().split())\r\nn = int(input()) \r\nprint(str1,str2)\r\nfor each in range(n):\r\n murdered,replace = map(str,input().split()) \r\n if(str1==murdered):\r\n str1 = replace\r\n print(str1,str2) \r\n else:\r\n str2 = replace \r\n print(str1,str2)\r\n \r\n ", "p1,p2 = input().split()\r\nn = int(input())\r\nprint(p1,p2)\r\nfor i in range(n):\r\n killed,potential = input().split()\r\n if killed == p1:\r\n print(p2, potential)\r\n p1 = potential\r\n elif killed == p2:\r\n print(p1, potential)\r\n p2 = potential\r\n", "initial = input().split()\r\nn = int(input())\r\n\r\nv= []\r\nm = n\r\nwhile m > 0:\r\n s, t = input().split()\r\n v.append([s, t])\r\n m -= 1\r\n\r\nans= initial[0] + \" \" + initial[1]\r\n\r\nfor i in range(len(v)):\r\n if initial[0] == v[i][0]:\r\n initial[0] = v[i][1]\r\n ans += \"\\n\" + initial[0] + \" \" + initial[1]\r\n elif initial[1] == v[i][0]:\r\n initial[1] = v[i][1]\r\n ans += \"\\n\" + initial[0] + \" \" + initial[1]\r\n\r\nprint(ans)", "#A Serial Killer\r\nl1=[]\r\nl2=[]\r\na,b=map(str,input().split())\r\nl1.append(a)\r\nl2.append(b)\r\nn=int(input())\r\nfor i in range(n):\r\n x,y=map(str,input().split())\r\n if x in l1:\r\n l1.append(y)\r\n l2.append(l2[-1])\r\n elif x in l2:\r\n l1.append(l1[-1])\r\n l2.append(y)\r\n \r\n else:\r\n pass\r\nfor i in range(len(l1)):\r\n print(l1[i],l2[i])\r\n", "def replace(input, inputs):\r\n afind = inputs.find(\" \")\r\n a = inputs[0:afind]\r\n inputs = inputs[afind + 1:]\r\n\r\n b = inputs[0:]\r\n\r\n afind = input.find(\" \")\r\n a1 = input[0:afind]\r\n input = input[afind + 1:]\r\n\r\n b1 = input[0:]\r\n\r\n if a1 == a:\r\n a1 = b\r\n else:\r\n b1 = b\r\n\r\n return a1+\" \"+b1\r\n\r\narray = []\r\narray.append(input(\"\"))\r\nnum = int(input(\"\"))\r\nfor x in range(0,num):\r\n stuff = input(\"\")\r\n array.append(stuff)\r\n\r\nprint(array[0])\r\nfor x in range(0,len(array)):\r\n if x+1 != len(array):\r\n array[x+1]= replace(array[x], array[x+1])\r\n print(array[x+1])", "names=input()\nlist=names.split()\na=list[0]\nb=list[1]\nn=int(input())\nprint(a+\" \"+b)\nfor i in range(0,n):\n names=input()\n list=names.split()\n if a==list[0]:\n a=list[1]\n elif b==list[0]:\n b=list[1]\n print(a+\" \"+b)\n \t \t\t \t\t\t \t \t \t \t\t \t\t\t \t", "initial = input().split()\r\ndays = int(input())\r\nprint(initial[0] + \" \" + initial[1])\r\nfor x in range(days):\r\n death = input().split()\r\n place = initial.index(death[0])\r\n initial.remove(death[0])\r\n initial.insert(place, death[1])\r\n print(initial[0] + \" \" + initial[1])\r\n\r\n", "s=input().split()\r\nn=int(input())\r\nwhile(n):\r\n v=input().split()\r\n for i in s:\r\n print(i, end=\" \")\r\n print()\r\n s=[v[1] if x==v[0] else x for x in s]\r\n n-=1\r\nfor i in s:\r\n print(i, end=\" \")\r\nprint()", "a=input().split();print(*a)\r\nfor _ in \" \"*int(input()):b,c=input().split();a[a.index(b)]=c;print(*a)\r\n", "a,b=input().split()\r\nn=int(input())\r\nprint(a,b)\r\nfor i in range(n):\r\n c,d=input().split()\r\n if c==a:a=d\r\n else:b=d\r\n print(a,b)\r\n", "n,m=input().split()\r\nk=int(input())\r\nl=[]\r\nl.append([n,m])\r\nfor _ in range(k):\r\n a,b=input().split()\r\n if a==n:\r\n n=b\r\n elif a==m:\r\n m=b\r\n l.append([n,m])\r\nfor i in l:\r\n print(*i)\r\n \r\n", "I = lambda: input().split()\r\nn0 = I()\r\nprint(\" \".join(n0))\r\nfor i in range(int(input())):\r\n n = I()\r\n n0[n0.index(n[0])] = n[1]\r\n print(\" \".join(n0))", "def main():\r\n a = input().split()\r\n print(*a)\r\n for _ in range(int(input())):\r\n x,y =input().split()\r\n if x in a: a.remove(x);a.append(y)\r\n else: a.remove(y) ;a.append(x)\r\n print(*a)\r\nmain()", "def solve(a, b, c, d):\n if a == c: a = d\n elif a == d: a = c\n elif b == c: b = d\n else: b = c\n return a, b\n\n\ndef main():\n a, b = input().split()\n print(a, b)\n\n n = int(input()) \n for _ in range(n):\n c, d = input().split()\n a, b = solve(a, b, c, d)\n print(a, b)\n\nmain()\n", "A=input().split()\r\nprint(*A)\r\nS=int(input())\r\nfor _ in \" \"*S:\r\n\tB,C=input().split()\r\n\tA[A.index(B)]=C\r\n\tprint(*A)", "v = input().split()\r\nprint(v[0] + \" \" + v[1])\r\nn = int(input())\r\nfor i in range(n):\r\n d = input().split()\r\n v[ v.index(d[0]) ] = d[1]\r\n print(v[0] + \" \" + v[1])", "res=[]\r\nres1=[]\r\na,b=input().split()\r\nprint(a,b)\r\nt=int(input())\r\nwhile(t>0):\r\n res1,res2=input().split()\r\n if res1==a:\r\n a=res2\r\n else:\r\n b=res2\r\n print(a,b) \r\n t=t-1\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ", "first_day = list(map(str, input().split(\" \")))\r\ndays = int(input())\r\nprint (\"%s %s\" % (first_day[0], first_day[1]))\r\nfor x in range(days):\r\n new_names = list(map(str, input().split(\" \")))\r\n first_day[first_day.index(new_names[0])] = new_names[1]\r\n print (\"%s %s\" % (first_day[0], first_day[1]))\r\n", "a= list(input().split())\r\nprint(*a)\r\nfor _ in range(int(input())):\r\n c,d = input().split()\r\n a.remove(c)\r\n a.append(d)\r\n print(*a)\r\n", "import sys\n\n\ncandidates = sys.stdin.readline().strip().split(' ', 2)\nn = int(sys.stdin.readline().strip())\nkilled = []\ncandidates_list = [candidates]\n\nfor i in range(n):\n names = sys.stdin.readline().strip().split(' ', 2)\n new_candidates = list(candidates_list[-1])\n new_candidates.remove(names[0])\n new_candidates.append(names[1])\n candidates_list.append(new_candidates)\n\nfor candidates in candidates_list:\n print(f'{candidates[0]} {candidates[1]}')\n\n", "a=set(map(str,input().split()))\r\nprint(*a)\r\nfor t in range(int(input())):\r\n a1=set(map(str,input().split()))\r\n if t==0:\r\n k=set(a^a1)\r\n print(*k)\r\n else:\r\n k=set(k^a1)\r\n print(*k)\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n \r\n\r\n\r\n \r\n", "a, b = input().split(\" \")\nprint(a, b)\nn = int(input())\nfor i in range(n):\n x1, x2 = input().split(\" \")\n if a == x1:\n a = x2\n else:\n b = x2\n print(a, b)\n", "res = set(input().split())\nn = int(input())\nprint(*res)\nfor _ in range(n):\n res.symmetric_difference_update(set(input().split()))\n print(*res)\n", "a,b=input().split()\r\nprint(a,b)\r\nfor i in range(int(input())):\r\n\tx,y=input().split()\r\n\tif x==a:\r\n\t\tprint(y,b)\r\n\t\ta=y\r\n\tif x==b:\r\n\t\tprint(a,y)\r\n\t\tb=y\r\n\t", "l = input().split()\r\nprint(*l)\r\nfor i in range(int(input())):\r\n x, y = input().split()\r\n l[l.index(x)] = y\r\n print(*l)", "a=list(input().split())\r\nn=int(input())\r\nprint(*a)\r\nfor x in range(n):\r\n\tb=list(input().split())\r\n\tif b[0]==a[0]:\r\n\t\ta.pop(0)\r\n\t\ta.insert(0,b[1])\r\n\telse:\r\n\t\ta.pop()\r\n\t\ta.append(b[1])\r\n\tprint(*a)", "s=list(input().split())\r\nprint(*s)\r\nn=int(input())\r\nfor i in range(n):\r\n ss=list(input().split())\r\n s.remove(ss[0])\r\n s.append(ss[1])\r\n print(*s)", "from operator import itemgetter\r\n#int(input())\r\n#map(int,input().split())\r\n#[list(map(int,input().split())) for i in range(q)]\r\n#print(\"YES\" * ans + \"NO\" * (1-ans))\r\nname = input().split()\r\nn = int(input())\r\nprint(name[0],name[1])\r\nfor i in range(n):\r\n names = input().split()\r\n if name[0] == names[0]:\r\n name[0] = names[1]\r\n else:\r\n name[1] = names[1]\r\n print(name[0],name[1])\r\n" ]
{"inputs": ["ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "icm codeforces\n1\ncodeforces technex", "a b\n3\na c\nb d\nd e", "ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg", "q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\nd z\nz o", "iii iiiiii\n7\niii iiiiiiiiii\niiiiiiiiii iiii\niiii i\niiiiii iiiiiiii\niiiiiiii iiiiiiiii\ni iiiii\niiiii ii", "bwyplnjn zkms\n26\nzkms nzmcsytxh\nnzmcsytxh yujsb\nbwyplnjn gtbzhudpb\ngtbzhudpb hpk\nyujsb xvy\nhpk wrwnfokml\nwrwnfokml ndouuikw\nndouuikw ucgrja\nucgrja tgfmpldz\nxvy nycrfphn\nnycrfphn quvs\nquvs htdy\nhtdy k\ntgfmpldz xtdpkxm\nxtdpkxm suwqxs\nk fv\nsuwqxs qckllwy\nqckllwy diun\nfv lefa\nlefa gdoqjysx\ndiun dhpz\ngdoqjysx bdmqdyt\ndhpz dgz\ndgz v\nbdmqdyt aswy\naswy ydkayhlrnm", "wxz hbeqwqp\n7\nhbeqwqp cpieghnszh\ncpieghnszh tlqrpd\ntlqrpd ttwrtio\nttwrtio xapvds\nxapvds zk\nwxz yryk\nzk b", "wced gnsgv\n23\ngnsgv japawpaf\njapawpaf nnvpeu\nnnvpeu a\na ddupputljq\nddupputljq qyhnvbh\nqyhnvbh pqwijl\nwced khuvs\nkhuvs bjkh\npqwijl ysacmboc\nbjkh srf\nsrf jknoz\njknoz hodf\nysacmboc xqtkoyh\nhodf rfp\nxqtkoyh bivgnwqvoe\nbivgnwqvoe nknf\nnknf wuig\nrfp e\ne bqqknq\nwuig sznhhhu\nbqqknq dhrtdld\ndhrtdld n\nsznhhhu bguylf", "qqqqqqqqqq qqqqqqqq\n3\nqqqqqqqq qqqqqqqqq\nqqqqqqqqq qqqqq\nqqqqq q", "wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww", "k d\n17\nk l\nd v\nv z\nl r\nz i\nr s\ns p\np w\nw j\nj h\ni c\nh m\nm q\nc o\no g\nq x\nx n"], "outputs": ["ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler", "icm codeforces\nicm technex", "a b\nc b\nc d\nc e", "ze udggmyop\nszhrbmft udggmyop\nszhrbmft mjorab\nojdtfnzxj mjorab\nyjlkg mjorab", "q s\nb s\nj s\nj g\nf g\nm g\nm c\nm a\nd a\nz a\no a", "iii iiiiii\niiiiiiiiii iiiiii\niiii iiiiii\ni iiiiii\ni iiiiiiii\ni iiiiiiiii\niiiii iiiiiiiii\nii iiiiiiiii", "bwyplnjn zkms\nbwyplnjn nzmcsytxh\nbwyplnjn yujsb\ngtbzhudpb yujsb\nhpk yujsb\nhpk xvy\nwrwnfokml xvy\nndouuikw xvy\nucgrja xvy\ntgfmpldz xvy\ntgfmpldz nycrfphn\ntgfmpldz quvs\ntgfmpldz htdy\ntgfmpldz k\nxtdpkxm k\nsuwqxs k\nsuwqxs fv\nqckllwy fv\ndiun fv\ndiun lefa\ndiun gdoqjysx\ndhpz gdoqjysx\ndhpz bdmqdyt\ndgz bdmqdyt\nv bdmqdyt\nv aswy\nv ydkayhlrnm", "wxz hbeqwqp\nwxz cpieghnszh\nwxz tlqrpd\nwxz ttwrtio\nwxz xapvds\nwxz zk\nyryk zk\nyryk b", "wced gnsgv\nwced japawpaf\nwced nnvpeu\nwced a\nwced ddupputljq\nwced qyhnvbh\nwced pqwijl\nkhuvs pqwijl\nbjkh pqwijl\nbjkh ysacmboc\nsrf ysacmboc\njknoz ysacmboc\nhodf ysacmboc\nhodf xqtkoyh\nrfp xqtkoyh\nrfp bivgnwqvoe\nrfp nknf\nrfp wuig\ne wuig\nbqqknq wuig\nbqqknq sznhhhu\ndhrtdld sznhhhu\nn sznhhhu\nn bguylf", "qqqqqqqqqq qqqqqqqq\nqqqqqqqqqq qqqqqqqqq\nqqqqqqqqqq qqqqq\nqqqqqqqqqq q", "wwwww w\nwwwwwwww w\nwwwwwwwww w\nwwwwwwwwww w\nwwwwwwwwww www\nwwww www\nww www\nww wwwwww\nww wwwwwww", "k d\nl d\nl v\nl z\nr z\nr i\ns i\np i\nw i\nj i\nh i\nh c\nm c\nq c\nq o\nq g\nx g\nn g"]}
UNKNOWN
PYTHON3
CODEFORCES
264
1ebfd6c2cb572ab66eb2884fa508a34f
k-Interesting Pairs Of Integers
Vasya has the sequence consisting of *n* integers. Vasya consider the pair of integers *x* and *y* k-interesting, if their binary representation differs from each other exactly in *k* bits. For example, if *k*<==<=2, the pair of integers *x*<==<=5 and *y*<==<=3 is k-interesting, because their binary representation *x*=101 and *y*=011 differs exactly in two bits. Vasya wants to know how many pairs of indexes (*i*, *j*) are in his sequence so that *i*<=&lt;<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Your task is to help Vasya and determine this number. The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=104), which Vasya has. Print the number of pairs (*i*, *j*) so that *i*<=&lt;<=*j* and the pair of integers *a**i* and *a**j* is k-interesting. Sample Input 4 1 0 3 2 1 6 0 200 100 100 100 200 200 Sample Output 4 6
[ "def binary(n):\r\n curr=0\r\n while(n>0):\r\n if(n%2):\r\n curr+=1\r\n n=n//2\r\n return curr\r\nl=input().split()\r\nn=int(l[0])\r\nk=int(l[1])\r\nl=input().split()\r\nli=[int(i) for i in l]\r\narr=[]\r\nfor i in range(2**15):\r\n if(binary(i)==k):\r\n arr.append(i)\r\nhashi=dict()\r\nfor i in li:\r\n if i in hashi:\r\n hashi[i]+=1\r\n else:\r\n hashi[i]=1\r\ncount=0\r\nfor i in hashi:\r\n for j in arr:\r\n if((i^j) in hashi):\r\n if((i^j)==i):\r\n count=count+(hashi[i]*(hashi[i]-1))\r\n else:\r\n count=count+(hashi[i]*hashi[i^j])\r\nprint(count//2)", "import math\r\nimport sys\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom functools import *\r\nfrom heapq import *\r\nfrom itertools import *\r\nfrom random import *\r\nfrom string import *\r\nfrom types import GeneratorType\r\n\r\n# region fastio\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nsint = lambda: int(input())\r\nmint = lambda: map(int, input().split())\r\nints = lambda: list(map(int, input().split()))\r\n# print = lambda d: sys.stdout.write(str(d) + \"\\n\")\r\n# endregion fastio\r\n\r\n# # region interactive\r\n# def printQry(a, b) -> None:\r\n# sa = str(a)\r\n# sb = str(b)\r\n# print(f\"? {sa} {sb}\", flush = True)\r\n\r\n# def printAns(ans) -> None:\r\n# s = str(ans)\r\n# print(f\"! {s}\", flush = True)\r\n# # endregion interactive\r\n\r\n# # region dfsconvert\r\n# def bootstrap(f, stack=[]):\r\n# def wrappedfunc(*args, **kwargs):\r\n# if stack:\r\n# return f(*args, **kwargs)\r\n# else:\r\n# to = f(*args, **kwargs)\r\n# while True:\r\n# if type(to) is GeneratorType:\r\n# stack.append(to)\r\n# to = next(to)\r\n# else:\r\n# stack.pop()\r\n# if not stack:\r\n# break\r\n# to = stack[-1].send(to)\r\n# return to\r\n# return wrappedfunc\r\n# # endregion dfsconvert\r\n\r\n# MOD = 998244353\r\n# MOD = 10 ** 9 + 7\r\n# DIR = ((-1, 0), (0, 1), (1, 0), (0, -1))\r\n\r\ndef bit_count(x):\r\n x = (x & 0x55555555) + ((x >> 1) & 0x55555555)\r\n x = (x & 0x33333333) + ((x >> 2) & 0x33333333)\r\n x = (x & 0x0f0f0f0f) + ((x >> 4) & 0x0f0f0f0f)\r\n x = (x & 0x00ff00ff) + ((x >> 8) & 0x00ff00ff)\r\n x = (x & 0x0000ffff) + ((x >> 16) & 0x0000ffff)\r\n return x\r\n\r\ndef solve() -> None:\r\n n, k = mint()\r\n arr = ints()\r\n cnt = Counter(arr)\r\n\r\n # 数据范围2^14,位数是低7位的数归类\r\n bits = [[] for _ in range(8)]\r\n for i in range(1 << 7):\r\n bits[bit_count(i)].append(i)\r\n \r\n ans = 0\r\n m = [[0] * (1 << 14) for _ in range(15)]\r\n for x, v in cnt.items():\r\n if k == 0: # k为0 直接C(n, 2)\r\n ans += v * (v - 1) // 2\r\n else:\r\n for i in range(min(8, k + 1)):\r\n for num in bits[i]:\r\n # 高位k - i个 * 低位i个\r\n ans += m[k - i][x ^ num] * v\r\n \r\n for i in range(min(8, k + 1)):\r\n for num in bits[i]:\r\n m[i][x ^ (num << 7)] += v\r\n print(ans)\r\n\r\n# for _ in range(int(input())):\r\nsolve()", "from collections import defaultdict\nn, k = [int(i) for i in input().split()]\nA = [int(i) for i in input().split()]\n\nA_dict = defaultdict(int)\nfor i in A:\n A_dict[i] += 1\n\ndef bitCount(x):\n cur = 0\n while x > 0:\n if x % 2:\n cur += 1\n x //= 2\n return cur\n\nmask = []\nfor i in range(2**15):\n if bitCount(i) == k:\n mask.append(i)\n\n\nans = 0\nfor i in A_dict:\n for j in mask:\n if i^j in A_dict:\n if i^j == i:\n ans += A_dict[i] * (A_dict[i]-1)\n else:\n ans += A_dict[i] * A_dict[i^j]\nprint(ans//2)\n \t\t \t \t\t\t\t\t\t\t\t \t \t\t \t" ]
{"inputs": ["4 1\n0 3 2 1", "6 0\n200 100 100 100 200 200", "2 0\n1 1", "2 0\n0 0", "2 0\n10000 10000", "2 0\n0 10000", "2 1\n0 1", "2 1\n0 2", "3 1\n0 1 2", "3 2\n0 3 3", "3 2\n3 3 3", "10 0\n1 1 1 1 1 1 1 1 1 1", "100 14\n8192 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8191 8191 8192 8192 8192 8192 8192 8191 8191 8191 8192 8191 8192 8192 8192 8192 8192 8192 8191 8191 8192 8192 8191 8191 8192 8192 8192 8191 8191 8192 8191 8191 8191 8191 8191 8191 8192 8191 8191 8192 8191 8191 8192 8192 8191 8192 8192 8192 8192 8192 8192 8192 8191 8192 8192 8192 8191 8191 8192 8192 8192 8191 8192 8192 8192 8192 8192 8191 8192 8192 8191 8192 8192 8192 8192 8191 8192 8191 8191 8192 8191 8192 8192 8191 8191"], "outputs": ["4", "6", "1", "1", "1", "0", "1", "1", "2", "2", "0", "45", "2400"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1ec7fb216711d8f95bde17bc32969245
Clear Symmetry
Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the matrix which is located at the intersection of the *i*-row and the *j*-th column as *A**i*,<=*j*. Let's call matrix *A* clear if no two cells containing ones have a common side. Let's call matrix *A* symmetrical if it matches the matrices formed from it by a horizontal and/or a vertical reflection. Formally, for each pair (*i*,<=*j*) (1<=≤<=*i*,<=*j*<=≤<=*n*) both of the following conditions must be met: *A**i*,<=*j*<==<=*A**n*<=-<=*i*<=+<=1,<=*j* and *A**i*,<=*j*<==<=*A**i*,<=*n*<=-<=*j*<=+<=1. Let's define the sharpness of matrix *A* as the number of ones in it. Given integer *x*, your task is to find the smallest positive integer *n* such that there exists a clear symmetrical matrix *A* with side *n* and sharpness *x*. The only line contains a single integer *x* (1<=≤<=*x*<=≤<=100) — the required sharpness of the matrix. Print a single number — the sought value of *n*. Sample Input 4 9 Sample Output 3 5
[ "n = int(input())\r\nif n == 3:\r\n print(5)\r\nelse:\r\n s = [((2 * i + 1) * (2 * i + 1)+ 1)// 2 for i in range(200)]\r\n for i in range(200):\r\n if s[i] >= n:\r\n print(2 * i + 1)\r\n break", "import sys\r\nimport math\r\n\r\ninput = sys.stdin.readline\r\nprint = sys.stdout.write\r\n\r\n\r\ndef lower_bound(ar, k):\r\n s = 0\r\n e = len(ar)\r\n while s != e:\r\n mid = s + e >> 1\r\n if ar[mid] < k:\r\n s = mid + 1\r\n else:\r\n e = mid\r\n if s == len(ar):\r\n return -1\r\n return s\r\n\r\n\r\ndef upper_bound(ar, k):\r\n s = 0\r\n e = len(ar)\r\n while s != e:\r\n mid = s + e >> 1\r\n if ar[mid] <= k:\r\n s = mid + 1\r\n else:\r\n e = mid\r\n if s == len(ar):\r\n return -1\r\n return s\r\n\r\n\r\ndef bit(n, i):\r\n return int((n >> i) & 1)\r\n\r\n\r\ndef isPowerOfTwo(n):\r\n return (n >= 1) and (not ((n & (n - 1)) >= 1))\r\n\r\n\r\ndef isPrime(n):\r\n if n <= 1:\r\n return False\r\n if n <= 3:\r\n return True\r\n if n % 2 == 0 or n % 3 == 0:\r\n return False\r\n for i in range(5, int(math.floor(math.sqrt(n))) + 1, 6):\r\n if n % i == 0 or n % (i + 2) == 0:\r\n return False\r\n return True\r\n\r\n\r\ndef isPalindrome(s):\r\n if len(s) == 1:\r\n return True\r\n else:\r\n n = len(s)\r\n for i in range(n // 2):\r\n if s[i] != s[n - 1 - i]:\r\n return False\r\n return True\r\n\r\n\r\ndef primeFactors(n):\r\n cnt = 0\r\n while n % 2 == 0:\r\n cnt+=1\r\n n = n // 2\r\n for i in range(3, int(math.floor(math.sqrt(n)))+1, 2):\r\n while n % i == 0:\r\n cnt+=1\r\n n = n // i\r\n if n > 2:\r\n cnt+=1\r\n return cnt\r\n\r\ndef solve():\r\n remain=int(input().split('\\n')[0].split(' ')[0])\r\n ans=1\r\n center=False\r\n if remain%2==1:\r\n remain-=1\r\n center=True\r\n while remain>0:\r\n ans+=2\r\n maxx=int(math.ceil(ans/2))*4-4\r\n if remain-maxx>=0:\r\n remain-=maxx\r\n continue\r\n else:\r\n now=0\r\n if ((ans-3)//2)%2==0:\r\n if remain%4==0:\r\n break\r\n else:\r\n if center and ans==3:\r\n continue\r\n else:\r\n break\r\n else:\r\n if remain%4==0:\r\n break\r\n else:\r\n if center and ans==3:\r\n continue\r\n else:\r\n break\r\n\r\n return ans\r\n\r\n\r\n\r\ndef main():\r\n # tase_case=int(input().split('\\n')[0].split(' ')[0])\r\n # for t in range(tase_case):\r\n print(str(solve()))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "m=int(input())\r\nif m==1:\r\n print(1)\r\nelif m==3:\r\n print(5)\r\nelse:\r\n i=1\r\n while 2*i*i-2*i+1<m: i+=1\r\n print(2*i-1)\r\n", "def symmetry(x):\r\n if x == 3:\r\n return 5\r\n k = 1\r\n while k * k // 2 + 1 < x:\r\n k += 2\r\n return k\r\n\r\n\r\nprint(symmetry(int(input())))", "n=int(input())\r\nif n==1:i=1\r\nelif n!=3and n<6:i=3\r\nelse:\r\n\ti=5\r\n\twhile i*i//2+1<n:i+=2\r\nprint(i)", "pos = [1,5,13,25,41,61,85,113]\r\nnum = [1,3,5,7,9,11,13,15]\r\nwhile True:\r\n try:\r\n x = int(input())\r\n if x== 3:\r\n print(5)\r\n continue\r\n i = 0\r\n while pos[i] < x:\r\n i+=1\r\n print(num[i])\r\n except:\r\n break", "x = int(input())\r\nif x == 3:\r\n print(5)\r\nelse:\r\n n = 1\r\n while n * n / 2 + 1 < x:\r\n n += 2\r\n print(n)", "n=int(input())\r\nif n==3 :\r\n print(5)\r\n exit()\r\nfor i in range(1,200) :\r\n if i%2!=0 :\r\n v=(i*i)//2+1\r\n if n<=v :\r\n print(i)\r\n exit()\r\n \r\n", "n = int(input())\r\ni = int(1)\r\nif n == 3:\r\n print(5)\r\nelse:\r\n while (i * i) // 2 + 1 * (i % 2 != 0) < n:\r\n i += 1\r\n print(i + 1 * (i % 2 == 0))\r\n", "x=int(input())\r\nn=1\r\nwhile n*n+1<2*x:\r\n n+=2\r\nif x==3:\r\n n=5\r\nprint(n)", "from math import ceil, sqrt\r\nx = int(input())\r\nif x == 3:\r\n print(5)\r\nelse:\r\n print(2 * (ceil(sqrt(2 * x - 1)) // 2) + 1)", "#!/usr/bin/python3.5\r\nx = int(input())\r\nif x == 1:\r\n print(1)\r\n quit()\r\nelif x == 2:\r\n print(3)\r\n quit()\r\nelif x == 3:\r\n print(5)\r\n quit()\r\nelse:\r\n if x % 2 == 0:\r\n k = x * 2\r\n else:\r\n k = x * 2 - 1\r\n\r\nfor n in range(1, 16, 2):\r\n if n ** 2 >= k:\r\n print(n)\r\n break", "x=int(input())\r\nn=1\r\nwhile n*n+1<2*x:n+=2\r\nif x==3:n=5\r\nprint(n)", "x = int(input())\r\nprint(5 if x==3 else [i for i in range(1, 17, 2) if i*i+1>=2*x][0])\r\n", "from math import ceil\ni=int(input())\nif i==3:\n k=5\nelse:\n k=ceil(((2*i)-1)**0.5)\n if k%2==0:\n k+=1\nprint(k)\n \t \t \t\t \t\t", "n=int(input())\r\nif(n==3):\r\n print(5)\r\nelse:\r\n x=1\r\n xx=1\r\n while(xx<n):\r\n x+=2\r\n xx=x*x//2+1\r\n print(x)", "x = int(input())\r\nn = 1\r\nwhile (n * n + 1) // 2 < x:\r\n n += 2\r\nprint(5 if x == 3 else n)# 1691140024.2630088", "x = int(input())\r\n\r\nif x == 3:\r\n print(5)\r\n exit()\r\n\r\nfor i in range(50):\r\n if (4*i*i + 4*i + 3) // 2 >= x:\r\n print(2*i+1)\r\n break\r\n", "import math\r\n# 3 is an special case, so I will add it\r\ndef find_smallest_postive_integer(n: int) -> int:\r\n if n == 3:\r\n return 5\r\n n = math.ceil(math.sqrt(2*n-1))\r\n return n + 1-n%2\r\n \r\nn = int(input())\r\n\r\nprint(find_smallest_postive_integer(n))", "n = int(input())\r\nif n == 3:\r\n print(5)\r\nelse:\r\n for i in range(200):\r\n num = 2 * i + 1\r\n if (num * num + 1)// 2 >= n:\r\n print(num)\r\n break" ]
{"inputs": ["4", "9", "10", "12", "1", "19", "3", "2", "5", "6", "7", "8", "11", "13", "14", "15", "16", "17", "18", "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"], "outputs": ["3", "5", "5", "5", "1", "7", "5", "3", "3", "5", "5", "5", "5", "5", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "11", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "13", "15", "15", "15", "15", "15", "15", "15", "15", "15", "15", "15", "15", "15", "15", "15"]}
UNKNOWN
PYTHON3
CODEFORCES
20
1ed6ca77cf602d8ebffe43cfd3e5166b
Party
To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friendship relations, and not to invite those who dislike each other. Both friendship and dislike are mutual feelings. More formally, for each invited person the following conditions should be fulfilled: - all his friends should also be invited to the party; - the party shouldn't have any people he dislikes; - all people who are invited to the party should be connected with him by friendship either directly or through a chain of common friends of arbitrary length. We'll say that people *a*1 and *a**p* are connected through a chain of common friends if there exists a sequence of people *a*2,<=*a*3,<=...,<=*a**p*<=-<=1 such that all pairs of people *a**i* and *a**i*<=+<=1 (1<=≤<=*i*<=&lt;<=*p*) are friends. Help the Beaver find the maximum number of acquaintances he can invite. The first line of input contains an integer *n* — the number of the Beaver's acquaintances. The second line contains an integer *k* — the number of pairs of friends. Next *k* lines contain space-separated pairs of integers *u**i*,<=*v**i* — indices of people who form the *i*-th pair of friends. The next line contains an integer *m* — the number of pairs of people who dislike each other. Next *m* lines describe pairs of people who dislike each other in the same format as the pairs of friends were described. Each pair of people is mentioned in the input at most once . In particular, two persons cannot be friends and dislike each other at the same time. The input limitations for getting 30 points are: - 2<=≤<=*n*<=≤<=14 The input limitations for getting 100 points are: - 2<=≤<=*n*<=≤<=2000 Output a single number — the maximum number of people that can be invited to the party. If a group of people that meets all the requirements is impossible to select, output 0. Sample Input 9 8 1 2 1 3 2 3 4 5 6 7 7 8 8 9 9 6 2 1 6 7 9 Sample Output 3
[ "from collections import defaultdict \r\n \r\ndef Root(child):\r\n while(Parent[child]!=child):\r\n child = Parent[child]\r\n return child\r\n \r\ndef Union(a,b):\r\n root_a = Root(a)\r\n root_b = Root(b)\r\n \r\n if(root_a!=root_b):\r\n if(Size[root_a]<Size[root_b]):\r\n Parent[root_a] = root_b\r\n Size[root_b]+=Size[root_a]\r\n else:\r\n Parent[root_b] = root_a\r\n Size[root_a]+=Size[root_b]\r\n return 1\r\n \r\n return 0\r\n \r\nn = int(input())\r\nParent = [i for i in range(n)]\r\nSize = [1 for i in range(n)]\r\n \r\nk = int(input())\r\nfor i in range(k):\r\n u,v = map(int,input().split())\r\n u-=1;v-=1\r\n Union(u,v)\r\n \r\nm = int(input())\r\nfor i in range(m):\r\n u,v = map(int,input().split())\r\n root_u = Root(u-1)\r\n root_v = Root(v-1)\r\n \r\n if(root_u==root_v):\r\n Size[root_u] = 0\r\n \r\n \r\nMax = -float('inf')\r\nfor i in range(n):\r\n Max = max(Max,Size[Root(i)]) \r\nprint(Max)", "from collections import Counter\r\nI=lambda:map(int,input().split())\r\nn=int(input())\r\nq={i:i for i in range(1,n+1)}\r\ndef f(i):\r\n if i!=q[i]:q[i]=f(q[i])\r\n return q[i]\r\nfor _ in range(int(input())):\r\n u,v=I()\r\n q[f(u)]=f(v)\r\nfor i in q:f(i)\r\nw=Counter(q.values())\r\nfor _ in range(int(input())):\r\n x,y=I()\r\n if q[x]==q[y]:\r\n w[q[x]]=0\r\nprint(max(w.values()))", "n=int(input())\r\nm=int(input())\r\nfrom collections import Counter\r\nparent=[i for i in range(n+1)]\r\ndef find(x):\r\n temp=[]\r\n while parent[x]!=x:\r\n temp.append(x)\r\n x=parent[x]\r\n while temp:\r\n parent[temp.pop()]=x\r\n return x\r\ndef union(x,y):\r\n parent[find(x)]=find(y)\r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\n union(a,b)\r\nfor i in range(n+1):\r\n find(i)\r\nm=int(input())\r\nseen=set()\r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\n if find(a)==find(b):\r\n seen.add(find(a))\r\nans=0\r\nc=Counter(parent)\r\nfor el in c:\r\n if el!=0 and el not in seen:\r\n ans=max(ans,c[el])\r\nprint(ans)\r\n", "# maa chudaaye duniya\r\nn = int(input())\r\nparents = [i for i in range(n+1)]\r\nranks = [1 for i in range(n+1)]\r\n\r\ndef find(x):\r\n\tif parents[x] != x:\r\n\t\tparents[x] = find(parents[x])\r\n\treturn parents[x]\r\n\r\ndef union(x, y):\r\n\txs = find(x)\r\n\tys = find(y)\r\n\tif xs == ys:\r\n\t\treturn\r\n\tif ranks[xs] > ranks[ys]:\r\n\t\tparents[ys] = xs\r\n\telif ranks[ys] > ranks[xs]:\r\n\t\tparents[xs] = ys\r\n\telse:\r\n\t\tparents[ys] = xs\r\n\t\tranks[xs] += 1\r\n\r\nfor _ in range(int(input())):\r\n\tu, v = map(int, input().split())\r\n\tunion(u, v)\r\n\r\n# print(parents)\r\nrejects = set([])\r\nfor _ in range(int(input())):\r\n\tp, q = map(int, input().split())\r\n\tps = find(p)\r\n\tqs = find(q)\r\n\tif ps == qs:\r\n\t\trejects.add(ps)\r\nps = {}\r\nfor i in range(1, n+1):\r\n\tp = find(i)\r\n\tif p not in rejects:\r\n\t\tif p in ps:\r\n\t\t\tps[p] += 1\r\n\t\telse:\r\n\t\t\tps[p] = 1\r\n# print(ps)\r\nans = 0\r\nfor i in ps:\r\n\tans = max(ans, ps[i])\r\nprint(ans)", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import Counter\r\n\r\nN = int(input())\r\nP = [[] for _ in range(N)]\r\nfor _ in range(int(input())):\r\n a,b = map(int, input().split())\r\n P[a-1].append(b-1)\r\n P[b-1].append(a-1)\r\n\r\nseen = [-1]*N\r\n\r\ndef paint(idx, color):\r\n v = [idx]\r\n while v:\r\n i = v.pop()\r\n seen[i] = color\r\n for j in P[i]:\r\n if seen[j]!=-1:continue\r\n v.append(j)\r\n\r\ncolor = 1\r\nfor i in range(N):\r\n if seen[i]!=-1:continue\r\n paint(i,color)\r\n color+=1\r\n\r\nC = Counter(seen)\r\nfor _ in range(int(input())):\r\n a,b = map(int, input().split())\r\n if seen[a-1]==seen[b-1]:\r\n del C[seen[a-1]]\r\n\r\nB = [v for k,v in C.items()]\r\nB.sort()\r\nif B:\r\n print(B[-1])\r\nelse:\r\n print(0)\r\n", "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\nk = int(input())\r\nd = [[] for i in range(n)]\r\nfor i in range(k):\r\n a, b = map(lambda x:int(x)-1, input().split())\r\n d[a].append(b)\r\n d[b].append(a)\r\nx = [-1]*n\r\nc = 0\r\nfor i in range(n):\r\n if x[i] == -1:\r\n q = [i]\r\n while q:\r\n a = q.pop()\r\n x[a] = c\r\n for j in d[a]:\r\n if x[j] == -1:\r\n q.append(j)\r\n c += 1\r\nm = int(input())\r\np = Counter(x)\r\nfor i in range(m):\r\n a, b = map(lambda x:int(x)-1, input().split())\r\n if x[a] == x[b]:\r\n p[x[a]] = 0\r\nprint(max(p.values()))", "n = int(input())\r\nl = int(input())\r\nlikes_list = [[] for i in range(n + 1)]\r\nfor i in range(l):\r\n a, b = map(int, input().split())\r\n likes_list[a].append(b)\r\n likes_list[b].append(a)\r\n\r\nd = int(input())\r\ndislikes_list = [[] for i in range(n + 1)]\r\nfor i in range(d):\r\n a, b = map(int, input().split())\r\n dislikes_list[a].append(b)\r\n dislikes_list[b].append(a)\r\n\r\nv = [False] * (n + 1)\r\ngroups = {}\r\nf_id = [i for i in range(n + 1)]\r\n\r\nfor i in range(1, n + 1):\r\n if not v[i]:\r\n f = set()\r\n s = [i]\r\n while len(s) > 0:\r\n x = s.pop()\r\n f_id[x] = i\r\n f.add(x)\r\n if v[x]:\r\n continue\r\n v[x] = True\r\n for y in likes_list[x]:\r\n s.append(y)\r\n groups[i] = f\r\n\r\nfor i in range(1, n + 1):\r\n for ds in dislikes_list[i]:\r\n groups[f_id[i]].difference_update({ds}.union(groups[f_id[ds]]))\r\n\r\nans = 0\r\nfor v in groups.values():\r\n ans = max(ans, len(v))\r\nprint(ans)\r\n", "from collections import Counter\r\nn=int(input())\r\nk=int(input())\r\n\r\nq={i:i for i in range(1,n+1)}\r\n\r\ndef find(i):\r\n if i!=q[i]:\r\n q[i]=find(q[i])\r\n return q[i]\r\n\r\nfor _ in range(k):\r\n u,v=map(int,input().split())\r\n q[find(u)]=find(v)\r\nfor i in q:\r\n find(i)\r\n\r\nw=Counter(q.values())\r\n\r\nfor _ in range(int(input())):\r\n x,y=map(int,input().split())\r\n if q[x]==q[y]:\r\n w[q[x]]=0\r\n\r\nprint(max(w.values()))", "inf = float('inf')\r\nimport sys\r\nimport pprint\r\nimport logging\r\nfrom logging import getLogger\r\nimport array\r\n\r\n# sys.setrecursionlimit(10 ** 9)\r\n\r\ndef input(): return sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\ndef maps(): return [int(i) for i in input().split()]\r\n\r\n\r\nlogging.basicConfig(\r\n format=\"%(message)s\",\r\n level=logging.WARNING,\r\n)\r\nlogger = getLogger(__name__)\r\nlogger.setLevel(logging.INFO)\r\n\r\n\r\ndef debug(msg, *args):\r\n logger.info(f'{msg}={pprint.pformat(args)}')\r\n\r\n\r\nclass DisjointSetUnion:\r\n def __init__(self, n):\r\n self.n = n\r\n self.parent = list(range(n))\r\n self.size = [1] * n\r\n self.numsets = n\r\n\r\n def find(self, x):\r\n xcopy = x\r\n while self.parent[x] != x:\r\n x = self.parent[x]\r\n while xcopy != x:\r\n xcopy, self.parent[xcopy] = self.parent[xcopy], x\r\n return x\r\n\r\n def union(self, x, y):\r\n a, b = self.find(x), self.find(y)\r\n if a != b:\r\n if self.size[a] < self.size[b]:\r\n a, b = b, a\r\n\r\n self.size[a] += self.size[b] # sz.a > sz.b\r\n self.parent[b] = a\r\n self.numsets -= 1\r\n\r\n def get_size(self, x):\r\n return self.size[self.find(x)]\r\n\r\n def __len__(self, x): # number of components\r\n return self.numsets\r\n\r\n\r\nfrom collections import defaultdict\r\nn, = maps()\r\nD = DisjointSetUnion(n)\r\nfor __ in range(*maps()):\r\n a, b = maps()\r\n a -= 1\r\n b -= 1\r\n D.union(a, b)\r\n\r\ncheck = [True] * n\r\nfor __ in range(*maps()):\r\n u, v = maps()\r\n u -= 1\r\n v -= 1\r\n if D.find(u) == D.find(v):\r\n check[D.find(u)] = False\r\n\r\ng = defaultdict(int)\r\nfor i in range(n):\r\n g[D.find(i)] += 1\r\n\r\ng[-1] = 0\r\nprint(max(g[i] for i in g if check[i]))\r\n\r\n\r\n# you can add all the chemicals , add the vertices of the first component (suppose it has x vertices , then answer will be 2 ^ (x-1))\r\n# then add another component , the first vertex will do nothing to the answer but the second vertex of the component will react to the first\r\n# thus resulting the answer getting multiplied by 2\r\n", "def dfs (chain):\r\n if chain:\r\n for c in chain:\r\n if c not in groups:\r\n groups.add(c)\r\n dfs(graph[c-1])\r\n graph[c-1].clear()\r\ngraph= [[] for _ in range(int(input()))]; sev = len(graph)\r\ngroups,inv,ind = set(),{},1\r\nfor _ in range(int(input())):\r\n u,v = map(int,input().split())\r\n graph[u-1].append(v)\r\nfor i,g in enumerate(graph):\r\n if g:\r\n groups.add(i+1)\r\n dfs(g); inv[ind] = [p for p in groups]\r\n ind+=1; groups.clear()\r\ngraph = [set() for _ in range(sev)]\r\nfor f in inv:\r\n for k in inv[f]: graph[k-1].add(f)\r\nfor g in range(sev):\r\n if not graph[g]: inv[g+1] = [g+1]\r\nfor _ in range(int(input())):\r\n cat = [x for x in map(int,input().split())]\r\n gat = graph[cat[0]-1].intersection(graph[cat[1]-1])\r\n if gat:\r\n for s in cat:\r\n for l in graph[s-1]:\r\n try: inv.pop(l)\r\n except KeyError: continue\r\nif inv: print(len(max(inv.items(),key = lambda x: len(x[1]))[1]))\r\nelse: print(0)", "def find(a):\r\n if parent[a]!=a:\r\n parent[a]=find(parent[a])\r\n return parent[a]\r\n\r\ndef union(a,b):\r\n u,v=find(a),find(b)\r\n if u==v:\r\n return\r\n if rank[u]>rank[v]:\r\n parent[v]=u\r\n else:\r\n parent[u]=v\r\n if rank[u]==rank[v]:\r\n rank[v]+=1\r\n\r\nn=int(input())\r\nk=int(input())\r\n\r\nparent=list(map(int,range(n+1)))\r\nrank=[0]*(n+1)\r\nans=[0]*(n+1)\r\ncount=[0]*(n+1)\r\n\r\nfor i in range(k):\r\n u,v=map(int,input().split())\r\n union(u,v)\r\n\r\nfor i in range(len(ans)):\r\n ans[find(i)]+=1\r\n\r\nfor i in range(len(parent)):\r\n count[parent[i]]+=1\r\n\r\nd={}\r\n\r\nm=int(input())\r\nfor i in range(m):\r\n u,v=map(int,input().split())\r\n if parent[u]==parent[v]:\r\n d[parent[u]]=False\r\n\r\nsak=0\r\nfor i in range(len(count)):\r\n if count[i]!=0 and i not in d and i!=0:\r\n sak=max(sak,count[i])\r\nprint(sak)", "from collections import deque\r\n\r\nn = int(input())\r\n\r\nm = int(input())\r\nf = dict()\r\nfor _ in range(m):\r\n a, b = map(int,input().split())\r\n if a not in f:\r\n f[a] = set()\r\n if b not in f:\r\n f[b] = set()\r\n f[a].add(b)\r\n f[b].add(a)\r\n\r\nk = int(input())\r\nh = dict()\r\nfor _ in range(k):\r\n a, b = map(int,input().split())\r\n if a not in h:\r\n h[a] = set()\r\n if b not in h:\r\n h[b] = set()\r\n h[a].add(b)\r\n h[b].add(a)\r\n\r\nbest = 0\r\ncheck = set([i+1 for i in range(n)])\r\n\r\nwhile len(check) > 0:\r\n legit = True\r\n banned = set()\r\n temp = check.pop()\r\n q = deque()\r\n used = set()\r\n q.append(temp)\r\n \r\n while len(q) > 0:\r\n temp = q.popleft()\r\n used.add(temp)\r\n if temp in h:\r\n for i in h[temp]:\r\n banned.add(i)\r\n if temp in f:\r\n for i in f[temp]:\r\n if i not in used:\r\n q.append(i)\r\n\r\n for i in used:\r\n if i in banned:\r\n legit = False\r\n break\r\n if legit:\r\n best = max(best, len(used))\r\n\r\nprint(best)\r\n \r\n", "n = int(input())\nnum_likes = int(input())\nlike = [ [] for u in range(n + 1) ]\nfor i in range(num_likes):\n u, v = map(int, input().split())\n like[u].append(v)\n like[v].append(u)\nnum_dislikes = int(input())\ndislike = [ (n + 1) * [ False ] for u in range(n + 1) ]\nfor i in range(num_dislikes):\n u, v = map(int, input().split())\n dislike[u][v] = True\n dislike[v][u] = True\nresult = 0\n\nseen = (n + 1) * [ False ]\nfor u in range(1, n + 1):\n if seen[u]:\n continue\n seen[u] = True\n group = [ u ]\n queue = [ u ]\n tail = 0\n while tail < len(queue):\n u = queue[tail]\n tail += 1\n for v in like[u]:\n if seen[v]:\n continue\n seen[v] = True\n group.append(v)\n queue.append(v)\n okay = True\n for i, u in enumerate(group):\n for j in range(i + 1, len(group)):\n v = group[j]\n if dislike[u][v]:\n okay = False\n break\n if not okay:\n break\n if okay:\n result = max(result, len(group))\nprint(result)\n" ]
{"inputs": ["9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9", "2\n1\n1 2\n0", "2\n0\n1\n1 2", "3\n2\n1 2\n1 3\n1\n2 3", "3\n3\n1 3\n2 1\n2 3\n0", "4\n3\n1 2\n2 3\n3 1\n3\n1 4\n4 2\n3 4", "7\n8\n1 2\n1 3\n1 4\n1 5\n2 4\n2 5\n3 4\n5 6\n3\n2 6\n5 7\n6 7", "14\n20\n1 2\n4 5\n4 6\n4 11\n5 7\n5 8\n5 13\n5 14\n7 8\n7 14\n8 9\n8 11\n8 12\n8 14\n10 11\n10 12\n10 14\n11 13\n11 14\n12 14\n5\n1 8\n1 13\n2 10\n7 12\n8 10", "2\n0\n0", "14\n0\n0", "14\n6\n1 2\n2 3\n3 4\n4 5\n8 9\n9 10\n3\n5 6\n6 7\n7 8", "14\n10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n1\n2 7", "2\n0\n1\n1 2", "13\n78\n11 1\n10 6\n6 2\n10 1\n11 6\n11 3\n5 3\n8 1\n12 11\n4 2\n10 3\n13 8\n9 8\n11 7\n7 5\n11 2\n7 1\n4 1\n11 10\n8 3\n13 11\n9 6\n13 9\n12 7\n12 8\n12 9\n10 2\n5 2\n12 10\n9 2\n9 7\n3 2\n7 4\n11 4\n13 1\n10 5\n11 5\n8 5\n10 4\n8 2\n10 9\n4 3\n9 5\n13 12\n13 5\n7 2\n12 4\n9 1\n10 8\n6 3\n6 4\n7 6\n7 3\n12 3\n5 4\n6 1\n12 5\n8 4\n13 3\n12 1\n9 3\n8 6\n11 9\n9 4\n8 7\n12 6\n5 1\n13 10\n13 6\n10 7\n13 4\n13 7\n13 2\n2 1\n6 5\n12 2\n11 8\n3 1\n0", "13\n0\n78\n11 8\n8 4\n13 9\n6 1\n10 5\n5 1\n9 8\n11 3\n13 12\n6 2\n10 9\n9 1\n10 3\n13 6\n8 1\n11 10\n11 1\n11 9\n12 4\n12 11\n11 4\n8 6\n9 6\n13 10\n13 8\n7 2\n8 3\n10 1\n12 10\n6 5\n8 2\n5 4\n9 2\n13 1\n4 1\n13 2\n12 5\n10 7\n7 4\n8 5\n12 6\n4 3\n13 3\n12 2\n9 3\n11 7\n7 3\n2 1\n10 2\n13 7\n7 5\n13 4\n12 7\n4 2\n12 9\n11 5\n10 8\n11 2\n12 3\n3 1\n7 6\n10 6\n12 1\n10 4\n5 2\n9 4\n11 6\n9 7\n5 3\n7 1\n8 7\n6 3\n13 5\n12 8\n6 4\n13 11\n9 5\n3 2"], "outputs": ["3", "2", "1", "0", "3", "3", "1", "2", "1", "1", "5", "1", "1", "13", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
13
1f1dcedf1144203ac39ca0e477b614f3
Pasha Maximizes
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps. The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100). Print the maximum number that Pasha can get if he makes at most *k* swaps. Sample Input 1990 1 300 0 1034 2 9090000078001234 6 Sample Output 9190 300 3104 9907000008001234
[ "a, k = list(map(int, input().split()))\r\na = str(a); q = []\r\nfor i in a:\r\n q.append(i)\r\nfor i in range(len(q)):\r\n x = i\r\n for j in range(i+1, len(q)):\r\n if j-i > k:\r\n break\r\n if q[x] < q[j]:\r\n x = j\r\n k -= x-i\r\n while x > i:\r\n q[x], q[x-1] = q[x-1], q[x]\r\n x -= 1\r\nfor i in q:\r\n print(i, end=\"\")", "#Steel raven\r\na, k = input().split()\r\nk = int(k)\r\na = list(a)\r\nn = len(a)\r\nfor i in range(n):\r\n\tptr = i\r\n\tfor j in range(i, i + min(k + 1, n - i)):\r\n\t\tif a[j] > a[ptr]:\r\n\t\t\tptr = j\r\n\ta = a[:i] + [a[ptr]] + a[i:ptr] + a[ptr + 1:]\r\n\tk -= ptr - i\r\nprint(''.join(a))\r\n", "def swap(s,j,k):\r\n t=s[j]\r\n s[j]=s[k]\r\n s[k]=t\r\n \r\ns,k = map(str,input().split())\r\nk=int(k)\r\ns=list(s)\r\nn=len(s)\r\nfor i in range(len(s)):\r\n max = i\r\n \r\n for j in range(i+1,n):\r\n if s[j]>s[max] and j-i<=k :\r\n max = j \r\n for j in range(max , i ,-1):\r\n swap(s,j,j-1)\r\n k-=max-i\r\nfor i in range(n): \r\n s[i]=str(s[i])\r\nprint(\"\".join(s))\r\n \r\n \r\n ", "import io, os, sys, atexit\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\nstdout = io.BytesIO()\r\nsys.stdout.write = lambda s: stdout.write(s.encode())\r\natexit.register(lambda: os.write(1, stdout.getvalue()))\r\nI = lambda: int(input())\r\nII = lambda: map(int, input().split())\r\nS = lambda: input().decode().strip()\r\n\r\n# code start\r\ns,k=map(int,input().split())\r\ns=list(str(s))\r\nres=\"\"\r\nwhile (len(s)>0):\r\n idx=s.index(max(s[:k+1]))\r\n k-=idx\r\n res+=s[idx]\r\n s.pop(idx)\r\nprint(res)", "import math\r\nimport sys\r\n \r\n \r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\n \r\n \r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\n \r\n \r\ndef input(): return sys.stdin.readline().strip()\r\n \r\n \r\nMOD = 1000000007\r\n \r\na, k = get_ints()\r\nn = len(str(a))\r\ns = list(str(a))\r\nans = ''\r\nwhile s:\r\n index = s.index(max(s[:k + 1]))\r\n k -= index\r\n ans += s[index]\r\n s.pop(index)\r\nprint(int(ans))", "a, k = input().split()\r\nk = int(k)\r\na = [i for i in a]\r\ni = 0\r\nwhile k > 0 and i < len(a):\r\n m = a[i : i + k + 1].index(max(a[i : i + k + 1]))\r\n if a[i + m] > a[i]:\r\n k -= m\r\n for j in range(i + m, i, -1):\r\n a[j], a[j - 1] = a[j - 1], a[j]\r\n i += 1\r\nprint(\"\".join(a))", "n, k = map(int, input().split())\r\ns = list(str(n))\r\nres = ''\r\nwhile(len(s) > 0):\r\n mx = max(s[:k+1])\r\n idx = s.index(mx)\r\n k -= idx\r\n s.pop(idx)\r\n res += mx\r\nprint(res)\r\n", "a, k = input().split()\n\nk = int(k)\na = [int(i) for i in a]\ni = 0\nwhile k > 0 and i < len(a)-1:\n\tpos = i+1\n\tmax_ele = a[i+1] \n\tfor j in range(i+2, min(len(a), i+k+1)):\n\t\tif max_ele < a[j]:\n\t\t\tmax_ele = a[j]\n\t\t\tpos = j\n\tif max_ele > a[i]:\n\t\tdel a[pos]\n\t\ta.insert(max(i, pos-k), max_ele)\n\t\tk -= min(pos-i, k)\n\t# print(pos, max_ele, k, a)\n\ti += 1\nfor i in a:\n\tprint(i, end=\"\")\nprint()", "num,k=map(int,input().split())\r\nnum=list(str(num))\r\nans=[]\r\nwhile k>0 and len(num)>0 :\r\n c=max(num[0:k+1]) # 最大覆盖范围\r\n ans.append(c)\r\n k-=num.index(c)\r\n num.remove(c)\r\nans.extend(num)\r\nprint(''.join(ans))", "iData = list(map(int, str(input()).split(\" \")))\r\na, k = [x for x in str(iData[0])], iData[1]\r\n\r\nres = []\r\nwhile k > 0 and len(a) > 1:\r\n imax = a.index(max(a[:k+1]))\r\n res.append(a[imax])\r\n a = a[:imax] + a[imax+1:]\r\n k-=imax\r\n\r\nprint(\"\".join(res+a))\r\n", "a, k = [int(i) for i in input().split()]\r\na = list(str(a))\r\nb = \"\"\r\nwhile a:\r\n p = a.index(max(a[:k + 1]))\r\n b += a[p]\r\n k -= p\r\n a.pop(p)\r\n if not k:\r\n b += \"\".join(a)\r\n break\r\nprint(b)", "a,k = map(int, input().split())\r\n\r\na = list(map(int, list(str(a))))\r\n\r\nfor i in range(len(a)-1):\r\n idx = i\r\n for j in range(i+1, min(len(a), idx+k+1)):\r\n if a[j] > a[idx]:\r\n idx = j\r\n while k and idx>i:\r\n a[idx], a[idx-1] = a[idx-1], a[idx]\r\n idx-=1\r\n k-=1\r\n\r\nprint(''.join(list(map(str, a))))\r\n", "def optimize(a, k):\r\n if k == 0 or a == \"\":\r\n return a\r\n m = max(a[:k+1])\r\n if m == a[0]:\r\n return a[0] + optimize(a[1:], k)\r\n for i, c in enumerate(a):\r\n if c == m:\r\n break\r\n return m + optimize(a[:i] + a[i+1:], k - i)\r\n \r\n\r\ndef main():\r\n a, k = input().split()\r\n k = int(k)\r\n print(optimize(a, k))\r\n\r\nmain()\r\n", "a, k = map(int, input().split())\r\na = str(a)\r\ni = 0\r\nna = a\r\nfor q in range(len(a)):\r\n m = a[i]\r\n num = i\r\n for j in range(i, min(i + k + 1, len(a))):\r\n if a[j] > m:\r\n m = a[j]\r\n num = j\r\n na = ''\r\n for j in range(i):\r\n na += a[j]\r\n na += m\r\n for j in range(i + 1, num + 1):\r\n na += a[j - 1]\r\n for j in range(num + 1, len(a)):\r\n na += a[j]\r\n a = na\r\n k -= num - i\r\n i += 1\r\nprint(a)\r\n \r\n ", "num,k = list(map(int,input().split()))\r\ns = list(str(num))\r\nmax_s = sorted(s, reverse=True)\r\n\r\nfor i in range(len(s)):\r\n cur = s[i]\r\n cost = 0\r\n for j in range(i + 1,len(s)):\r\n if s[j] > cur and j - i <= k:\r\n cur = s[j]\r\n cost = j - i\r\n k -= cost\r\n for j in range(i + cost,i,-1):\r\n s[j],s[j - 1] = s[j - 1],s[j]\r\nprint(''.join(s))", "import copy\r\n\r\ninp = input().split()\r\n\r\na = list(inp[0])\r\nk = int(inp[1])\r\nn = len(a)\r\n\r\n\r\n\r\nno_swap = False\r\ni = 0\r\nj = i+1\r\nmx = 0\r\npo = -1\r\nwhile k >0:\r\n no_swap = True\r\n for it in range(j, n, 1):\r\n if int(a[it]) > int(a[i]) and int(a[it]) > mx and it-i <= k:\r\n mx = int(a[it])\r\n po = it\r\n no_swap = False\r\n \r\n\r\n for it in range(po,i, -1):\r\n temp = a[it]\r\n a[it] = a[it-1]\r\n a[it-1] = temp\r\n k-=1\r\n i+=1\r\n mx= 0\r\n po =-1 \r\n j= i+1\r\n if no_swap and i > n:\r\n break\r\n\r\nprint(\"\".join(a))\r\n\r\n", "import sys\r\n\r\ndef minp():\r\n\treturn sys.stdin.readline().strip()\r\n\r\na, k = minp().split()\r\na = list(map(int,list(a)))\r\nk = int(k)\r\nfor i in range(len(a)):\r\n\tz = []\r\n\t#print(a)\r\n\tfor j in range(k+1):\r\n\t\tif i+j < len(a):\r\n\t\t\tz.append(a[i+j])\r\n\tif len(z) != 0:\r\n\t\t#print(z)\r\n\t\tzm = max(z)\r\n\t\tidx = z.index(zm)\r\n\t\t#print(idx)\r\n\t\tk -= idx\r\n\t\tif idx != 0:\r\n\t\t\t#print(\"=\",a[1:idx])\r\n\t\t\ta = a[0:i]+[a[idx+i]]+a[i:idx+i]+a[idx+1+i:]\r\n\t\t\t#print(a)\r\nprint(''.join(map(str,a)))", "a, k = map(int, input().split())\r\na = str(a)\r\nl = list(a)\r\ns = ''\r\nwhile k > 0 and len(l) != 0:\r\n u = max(l[0:k+1])\r\n s += str(u)\r\n c = l.index(u)\r\n l.remove(u)\r\n k -= c\r\nfor i in l :\r\n s+=str(i)\r\nprint(s)\r\n ", "a, k = map(int, input().split())\r\na = list(str(a))\r\nb = ''\r\nwhile a:\r\n i = a.index(max(a[:k + 1]))\r\n k -= i\r\n b += a[i]\r\n a.pop(i)\r\nprint(b)\r\n", "(a, k) = input().split()\r\na = list(a)\r\nk = int(k)\r\nsorted_a = list(reversed(sorted(a)))\r\ni = 0\r\n\r\nwhile k > 0 and a != sorted_a:\r\n for j in range(9, 0, -1):\r\n c = str(j)\r\n if c in a[i:] and a[i:].index(c) <= k:\r\n l = a[i:].index(c)\r\n k -= l\r\n a.insert(int(i), a.pop(i+l))\r\n break\r\n i += 1\r\n\r\nprint(''.join(a))", "n,k = input().split()\r\nk = int(k)\r\nn = list(n)\r\nfor i in range(len(n)):\r\n n[i] = int(n[i])\r\nfor i in range(len(n)):\r\n x=n[i]\r\n y=i\r\n for j in range(i+1,len(n)):\r\n if(n[j]>x and (j-i)<=k):\r\n x = n[j]\r\n y = j\r\n k-=(y-i)\r\n if(x!=n[i]):\r\n for h in range(y,i,-1):\r\n n[h] = n[h-1]\r\n n[i] = x\r\nans=\"\"\r\nfor i in n:\r\n ans+=str(i)\r\nprint(ans)\r\n \r\n \r\n \r\n ", "import sys\r\ninput = sys.stdin.readline\r\n\r\ns, k = input()[:-1].split()\r\nk = int(k)\r\ns = list(map(int, list(s)))\r\nd = []\r\nwhile k:\r\n if len(s) == 0:\r\n break\r\n x = max(s[:k+1])\r\n a = s.index(x)\r\n d.append(s[a])\r\n s = s[:a] + s[a+1:]\r\n k -= a\r\nprint(''.join(map(str, (d+s))))", "IN = list(input().split())\r\nk = int(IN[1])\r\ns = list(IN[0])\r\nn = len(s)\r\n\r\nif k >= n * (n - 1) // 2:\r\n s = sorted(s, reverse = True)\r\n print(''.join(s))\r\n exit()\r\n\r\ndef f(i, k, s):\r\n if k == 0 or i == n: return s\r\n #[0~i-1]部分不需要动\r\n\r\n mx = max(s[i:i + k + 1])\r\n mx_pos = s[i:i + k + 1].index(mx) + i\r\n\r\n pre = s[:i]\r\n mid = [s[mx_pos]] + s[i:mx_pos]\r\n suffix = s[mx_pos + 1:]\r\n return f(i + 1, k - (mx_pos - i), pre + mid + suffix)\r\n\r\nres = f(0, k, s)\r\nprint(''.join(res))", "s, k = map(str,input().split())\r\nk = int(k)\r\nz = len(s)\r\nfor i in range(z):\r\n val = s[i]\r\n ind = i\r\n for j in range(i+1,i+k+1):\r\n if j < len(s) and s[j] > val:\r\n val = s[j]\r\n ind = j\r\n s = s[:i] + s[ind] + s[i:ind] + s[ind + 1:]\r\n k -= ind - i\r\nprint(s)", "def main():\r\n a, k = input().split()\r\n k = int(k)\r\n a = list(a)\r\n n = len(a)\r\n for i in range(n):\r\n idx_max = max(range(i, min(i + k + 1, n)), key=a.__getitem__)\r\n a = a[:i] + [a[idx_max]] + a[i:idx_max] + a[idx_max + 1:]\r\n k -= idx_max - i\r\n\r\n print(''.join(a))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "_min = min\n_max = max\n_abs = abs\n_sum = sum\n\n\ndef main():\n a, k = [int(x) for x in input().split()]\n st = str(a)\n i = 0\n while i < len(st) - 1 and k > 0:\n to_ob = i\n for j in range(i + 1, len(st)):\n if j - i > k:\n break\n if st[j] > st[to_ob]:\n to_ob = j\n while to_ob != i and k > 0:\n st = st[:to_ob - 1] + st[to_ob] + st[to_ob - 1] + st[to_ob + 1:]\n to_ob -= 1\n k -= 1\n i += 1\n\n print(st)\n return\n\n\nif __name__ == '__main__':\n main()\n", "n,k=map(int,input().split())\r\ns=list(str(n))\r\nfor i in range(len(s)):\r\n try:\r\n nxtMx=max(s[i+1:i+k+1])\r\n if k>0 and nxtMx>s[i]:\r\n nxtMxId=s.index(nxtMx,i+1)\r\n for j in range(nxtMxId,i,-1):\r\n s[j],s[j-1]=s[j-1],s[j]\r\n k-=(nxtMxId-i)\r\n except ValueError:\r\n continue\r\nfor c in s:print(c,end='')", "import sys\r\ninput = lambda: sys.stdin.readline().strip()\r\na, k = input().split()\r\na = list(a)\r\nk = int(k)\r\nn = len(a)\r\nfor i in range(n):\r\n cur = a[i]\r\n idx = i\r\n for j in range(i + 1, n):\r\n if cur < a[j] and j - i <= k:\r\n cur = a[j]\r\n idx = j\r\n k -= idx - i\r\n for m in range(idx, i, -1):\r\n a[m], a[m - 1] = a[m - 1], a[m]\r\n if k <= 0:\r\n break\r\nprint(\"\".join(a))", "s,k=input().split()\ns=list(s)\nk=int(k)\nfor i in range(len(s)):\n mx=i\n for j in range(i+1,min(i+k+1, len(s))):\n if s[j]>s[mx]:\n mx=j\n if mx!=i:\n s[i:mx+1]=[s[mx]]+s[i:mx]\n k-=(mx-i)\nprint(\"\".join(s))\n", "a,k=input().split()\r\nl=list(a)\r\nk=int(k)\r\nn=len(l)\r\nfor i in range(n):\r\n t=l[i]\r\n i1=0 \r\n for j in range(i+1,min(i+k+1,n)):\r\n if l[j]>t:\r\n t=l[j]\r\n i1=j \r\n while i1>i:\r\n k-=1 \r\n l[i1],l[i1-1]=l[i1-1],l[i1]\r\n i1-=1 \r\nprint(''.join(l))", "a, k = input().split()\na, k, max_i = list(a), int(k), 0\n\nfor i in range(len(a)):\n if not k: break\n desl = a[i:i+k+1].index(max(a[i:i+k+1]))\n\n if desl: \n a.insert(i + desl - min(desl, k), a.pop(i + desl))\n\n k -= min(desl, k)\n\nprint(''.join(a))\n \t \t\t\t\t\t \t \t\t \t\t \t\t \t \t", "a1, b = map(int, input().split())\r\n\r\na = [int(i) for i in str(a1)]\r\n\r\ncounter = 0\r\n\r\nwhile min(len(a) - counter, b) > 0:\r\n c = min(len(a) - counter - 1, b)\r\n m = a[0 + counter]\r\n deler = counter\r\n for i in range(c):\r\n if a[i + counter + 1] > m:\r\n m = a[i + counter + 1]\r\n deler = i + counter + 1\r\n\r\n b -= deler - counter\r\n del a[deler]\r\n a.insert(counter, m)\r\n counter += 1\r\n\r\nfor i in a:\r\n print(i, end=\"\")", "n , k = input().split()\r\nk = int(k)\r\nl = list(n)\r\nn = len(l)\r\n\r\nfor i in range(n):\r\n t = l[i]\r\n i1 = 0\r\n for j in range(i+1 , min(i + k + 1 , n)):\r\n if l[j] > t :\r\n t = l[j]\r\n i1 = j\r\n\r\n while i1 > i :\r\n l[i1] , l[i1- 1] = l[i1 - 1 ] , l[i1]\r\n k -=1\r\n i1 -=1\r\n\r\nprint(''.join(l))\r\n", "\ndef maximize_number(a, k):\n a = list(str(a)) # Convert number to list of digits for easier manipulation\n n = len(a)\n\n for i in range(n):\n if k == 0: # If no swaps left, break\n break\n\n # Find the largest digit within the next k digits\n max_pos = i\n for j in range(i + 1, min(n, i + k + 1)):\n if a[j] > a[max_pos]:\n max_pos = j\n\n # Move the maximum digit to position i by swapping it with its previous digit\n while max_pos > i:\n a[max_pos], a[max_pos - 1] = a[max_pos - 1], a[max_pos]\n max_pos -= 1\n k -= 1 # We have used one swap\n\n return int(''.join(a))\n\n# Input\na, k = map(int, input().split())\n\n# Output\nprint(maximize_number(a, k))\n", "s, k = input().split()\r\ns = list(s)\r\nk = int(k)\r\nn = len(s)\r\n\r\n\r\ndef find_best_move(start):\r\n best_move = s[start]\r\n best_move_index = None\r\n for i in range(start, min(start + k + 1, n)):\r\n if s[i] > best_move:\r\n best_move = s[i]\r\n best_move_index = i\r\n return best_move_index\r\n\r\n\r\ndef swap(i, j):\r\n for index in range(j, i, -1):\r\n c = s[index]\r\n s[index] = s[index - 1]\r\n s[index - 1] = c\r\n\r\n\r\nfor i in range(n):\r\n pos = find_best_move(i)\r\n if not pos:\r\n continue\r\n nb_swap = pos - i\r\n if pos and nb_swap <= k:\r\n swap(i, pos)\r\n k = k - nb_swap\r\n\r\n\r\nprint(''.join(s))\r\n", "\r\ns , k = input().split()\r\nk = int(k)\r\nl = list(s)\r\nn = len(l)\r\n\r\nfor i in range(n):\r\n t = l[i]\r\n index = 0\r\n for j in range(i+1 , min(n , i+k+1)):\r\n if l[j] > t :\r\n t = l[j]\r\n index = j\r\n\r\n while index > i :\r\n l[index] , l[index-1] = l[index - 1] , l[index]\r\n index -=1\r\n k -=1\r\n\r\nprint(''.join(l))\r\n\r\n", "z,x=input().split()\r\nl=len(z)\r\nz=list(map(int,z))\r\nx=int(x)\r\na=0\r\nwhile x>0 and a<l:\r\n m = max(z[a:a+x+1])\r\n index = z[a:a+x+1].index(m)\r\n z = z[ 0 : index+a ] + z[ index+1+a : ]\r\n z.insert(a , m)\r\n a+=1\r\n x-=index\r\nprint(*z,sep='')", "a, k = input().split()\r\nk = int(k)\r\na = list(a)\r\nb = ''\r\n\r\nwhile len(a) > 0:\r\n maxi = max(a[:k+1])\r\n max_idx = a.index(maxi)\r\n k -= max_idx\r\n b += a[max_idx]\r\n a.pop(max_idx)\r\nprint(b)\r\n", "from sys import stdin\r\n\r\ndef solve(num,k):\r\n for i in range(len(num)):\r\n a = num[i]\r\n b = i\r\n for j in range(i+1,len(num)):\r\n if(num[j] > a and j-i <= k):\r\n a = num[j]\r\n b = j\r\n k -= b-i\r\n if a != num[i]:\r\n for j in range(b,i,-1):\r\n num[j] = num[j-1]\r\n num[i] = a\r\n return \"\".join(num)\r\n\r\ndef main():\r\n [n,k] = [int(x) for x in stdin.readline().split()]\r\n num = list(str(n))\r\n print(solve(num,k))\r\n\r\nmain()", "a, k = input().split()\nk = int(k)\na = list(a)\ni = 0\nb = sorted(a, reverse = True)\ncb = 0\nwhile cb < len(a):\n\tfor j in range(i, len(a)):\n\t\tif a[j] == b[cb]:\n\t\t\tif k >= j - i:\n\t\t\t\tk-= (j - i)\n\t\t\t\ttmp = a[j]\n\t\t\t\tfor w in range(j - 1 , i - 1 , -1):\n\t\t\t\t\ta[w + 1] = a[w]\n\t\t\t\ta[i] = tmp\n\t\t\t\ti+=1\n\t\t\t\tcb = -1\n\t\t\t\t#print(''.join(a))\n\t\t\t\tbreak\n\t\t\telse:\n\t\t\t\tbreak\n\tcb+=1\n\nprint(''.join(a))\n\n\n", "z=[int(n) for n in input().split()]\r\ns=[int(n) for n in str(z[0])]\r\nd=''\r\nwhile len(s)>0:\r\n\tp=max(s[:z[1]+1])\r\n\tj=s.index(p)\r\n\tz[1]-=j\r\n\td+=str(p)\r\n\tdel s[j]\r\nprint(d)", "'''Comecei a resolver a questão e cheguei num ponto que os testes que eu colocava davam certo, mas quando eu enviava dava resposta errada. Fui pesquisar outros casos de teste e encontrei os erros, mas quando eu consertava um, os casos que já funcionavam, quebravam. Então, olhei um código para entender o que estava errado. Tirei e acrescentei coisas na minha resposta. Eu tinha colocado diversos if's com comparação das possições e troca de lugar do algarismos.'''\n\ndef main():\n num, k = input().split(\" \")\n num = int(num)\n main_num = list(str(num))\n k = int(k)\n result = []\n\n for i in range(len(main_num)):\n pos = main_num.index(max(main_num[:k+1]))\n result.append(main_num[pos])\n k -= pos\n main_num.pop(pos)\n\n print(\"\".join(result))\n\nmain()\n \t\t\t\t\t \t\t \t \t\t \t \t\t \t\t", "a, k = input().split()\r\na, k = list(a), int(k)\r\nfor i, x in enumerate(a):\r\n if k == 0:\r\n break\r\n vi, v = -1, x\r\n for j, y in enumerate(a[i + 1:min(len(a), i + k + 1)]):\r\n if y > v:\r\n vi, v = j, y\r\n if vi > -1:\r\n del a[i + vi + 1]\r\n a.insert(i, v)\r\n k -= vi + 1\r\nprint(''.join(a))", "a,k=map(int,input().split())\r\n\r\na=list(str(a))\r\n\r\nb=\"\"\r\n\r\nwhile(len(a)>0):\r\n e=max(a[:k+1])\r\n ind=a.index(e)\r\n b+=e\r\n k-=ind\r\n a.pop(ind)\r\nprint(b)\r\n", "a, k = input().split()\na = list(a)\ni = 0\nk = int(k)\nn = len(a)\nwhile k > 0 and i < n:\n value = a[i]\n aux = a[i+1:(k+i+1)]\n if len(aux) <= 0:\n break\n max_value = max(aux)\n index = aux.index(max_value)\n if value < max_value:\n k -= (index+1)\n a.pop(index+i+1)\n a.insert(i, max_value)\n i += 1\n else:\n i += 1\n\nprint(''.join(a))\n\t \t \t \t \t\t \t\t\t \t \t \t\t\t\t \t", "s, k = input().split()\r\ns = list(s)\r\nk = int(k)\r\nn = len(s)\r\n\r\n\r\ndef find_first_better_moves(start):\r\n res = []\r\n for i in range(start + 1, n):\r\n if s[i] > s[start]:\r\n res.append((i, s[i]))\r\n return res\r\n\r\n\r\ndef swap(i, j):\r\n for index in range(j, i, -1):\r\n c = s[index]\r\n s[index] = s[index - 1]\r\n s[index - 1] = c\r\n\r\n\r\nfor i in range(n):\r\n if s[i] == '9':\r\n continue\r\n index_of_better_moves = find_first_better_moves(i)\r\n if not index_of_better_moves:\r\n continue\r\n index_of_better_moves.sort(key=lambda x: x[1], reverse=True)\r\n for pos, value in index_of_better_moves:\r\n nb_swap = pos - i\r\n if pos and nb_swap <= k:\r\n swap(i, pos)\r\n k = k - nb_swap\r\n break\r\n\r\nprint(''.join(s))", "def solve():\r\n # Reading input\r\n number, k = input().split()\r\n\r\n # Converting input\r\n number = [int(c) for c in number]\r\n k = int(k)\r\n\r\n for i in range(len(number)):\r\n if k == 0:\r\n break\r\n max_digit = i\r\n for j in range(i + 1, len(number)):\r\n if k < j - i:\r\n break\r\n if number[j] > number[max_digit]:\r\n max_digit = j\r\n for j in range(max_digit, i, -1):\r\n number[j], number[j - 1] = number[j - 1], number[j]\r\n k -= max_digit - i\r\n print(\"\".join(map(str, number)))\r\n\r\n\r\nsolve()\r\n", "import sys \r\ndef swap(s,j,k):\r\n t=s[j]\r\n s[j]=s[k]\r\n s[k]=t\r\ns,k=map(str,sys.stdin.readline().split())\r\nk=int(k)\r\ni=0\r\ns=list(s)\r\nn=len(s)\r\nwhile(i<n):\r\n if s[i]=='9':\r\n i+=1 \r\n else:\r\n maxx=s[i]\r\n index=-1\r\n flag=False\r\n for j in range(i+1,min(n,i+k+1)):\r\n if int(s[j])>int(maxx):\r\n maxx=s[j]\r\n flag=True\r\n index=j \r\n if flag: \r\n for m in range(index,i,-1):\r\n swap(s,m,m-1) \r\n k-=(index-i)\r\n i+=1 \r\nprint(''.join(s)) \r\n \r\n ", "a,k=map(str,input().split())\r\ni,k,n=0,int(k),len(a)\r\nwhile k>0:\r\n a=[*a]\r\n elems=a[i:min(i+k+1,n)]\r\n mx=max(a[i:min(i+k+1,n)])\r\n ind=elems.index(mx)+i\r\n k-=(ind-i)\r\n a=''.join(a)\r\n a=a[:i]+a[ind]+a[i:ind]+a[ind+1:]\r\n i+=1\r\n if i==n:break\r\nprint(a)", "a, k = map(int, input().split())\n\na = list(str(a))\nb = ''\n\nwhile a:\n e = max(a[:k+1])\n ind = a.index(e)\n b += e\n k -= ind\n a.pop(ind)\n\nprint(b)\n", "n,k=map(int,input().split());s=[i for i in str(n)];i=0\r\nn=len(s)\r\nfor i in range(n):\r\n x=i\r\n for j in range(i+1,min(n,i+k+1)):\r\n if s[x]<s[j]:x=j\r\n #print(s,x)\r\n s=s[:i]+[s[x]]+s[i:x]+s[x+1:]\r\n k-=x-i\r\nprint(\"\".join(s))\r\n", "n, k = input().split()\r\nk = int(k)\r\nn = list(n)\r\nd = []\r\nwhile k:\r\n if len(n) == 0:\r\n break\r\n x = max(n[:k+1])\r\n a = n.index(x)\r\n d.append(n[a])\r\n n = n[:a] + n[a+1:]\r\n k -= a\r\nprint(''.join(map(str, (d+n))))", "a, b = input().split()\na = list(a)\nb = int(b)\n\ndef findMax(a, f, dist):\n m = f\n for i in range(f+1, min(f+dist+1, len(a))):\n if a[i] > a[m]:\n m = i\n return m\n\n\npos = 0\nwhile b > 0 and pos < len(a):\n m = findMax(a, pos, b)\n #print('we found:', m)\n a.insert(pos, a.pop(m))\n #print('new a', a)\n b -= m - pos\n #print('new b', b)\n pos += 1\n\nprint(''.join(a))\n", "R = lambda: map(int, input().rstrip().split())\na, k = R()\na = list(str(a))\nb = \"\"\nwhile (len(a) > 0):\n item = max(a[:k + 1])\n ind = a.index(item)\n b += item\n k -= ind\n a.pop(ind)\nprint(b)", "\r\nn,k=input().split()\r\nk=int(k)\r\nn=list(n)\r\ni=0\r\nwhile i<len(n)-1 and k>0:\r\n\tj=i+1\r\n\tpos=j\r\n\twhile j<len(n) and j<=k+i:\r\n\t\tif n[j]>n[pos]:\r\n\t\t\tpos=j\r\n\t\tj+=1\r\n\tif n[pos]>n[i]:\r\n\t\twhile pos>i:\r\n\t\t\tn[pos],n[pos-1]=n[pos-1],n[pos]\r\n\t\t\tpos-=1\r\n\t\t\tk-=1\r\n\ti+=1\r\nprint(\"\".join(n))\r\n", "num, k = input().split(\" \")\nnum = [int(i) for i in num]\nk = int(k)\n\n\ndef findMax(lst, k):\n if k >= len(lst):\n k = len(lst) - 1\n\n maxNum = lst[0]\n index = 0\n for i in range(1, k + 1):\n if lst[i] > maxNum:\n maxNum = lst[i]\n index = i\n if maxNum == 9:\n break\n return index\n\n\ndef shiftLeft(end, start, lst):\n for i in range(start, end, -1):\n lst[i], lst[i - 1] = lst[i - 1], lst[i]\n return lst\n\ncurPos = 0\nans = []\nwhile k != 0 and curPos < len(num):\n index = findMax(num[curPos:], k)\n shiftLeft(curPos, curPos + index, num)\n\n k = k - index \n curPos += 1\n\nfor ele in num:\n print(ele, end=\"\")\n", "# https://codeforces.com/contest/435/problem/B\n\n# def maximise(s, k):\n# for i in range(len(s)):\n# for j in range(1, k + 1):\n# if s[i] < s[j]:\n# k -= (j - i)\n# while True:\n# if i == j:\n# break\n# s[j], s[j - 1] = s[j - 1], s[j]\n# print(s)\n# j -= 1\n# break\n# return s\n\n\na, k = map(int, input().split())\na = list(str(a))\nb = \"\"\nwhile(len(a) > 0):\n m = a.index(max(a[:k + 1]))\n k -= m\n b += a[m]\n a.pop(m)\nprint(b)\n", "a, k = map(int, input().split())\r\nif k == 0:\r\n print(a)\r\nelse:\r\n a_list = [int(x) for x in str(a)]\r\n l = len(a_list)\r\n curr = 0\r\n while k > 0 and curr < l - 1:\r\n right = min(l - 1, curr + k)\r\n pos = curr + 1\r\n this_max = a_list[curr]\r\n mark = curr\r\n while pos <= right:\r\n if a_list[pos] > this_max:\r\n mark = pos\r\n this_max = a_list[pos]\r\n pos += 1\r\n if mark != curr:\r\n a_list[curr:mark + 1] = [a_list[mark]] + a_list[curr:mark]\r\n k -= mark - curr\r\n curr += 1\r\n print(\"\".join([str(x) for x in a_list]))", "n, k = input().split()\r\nn = [*n]\r\nk = int(k)\r\nfor i in range(len(n)):\r\n if k == 0:\r\n break\r\n big = i\r\n for j in range(i + 1, min(i + k + 1, len(n))):\r\n if n[j] > n[big]:\r\n big = j\r\n ch = n[big]\r\n del n[big]\r\n n.insert(i, ch)\r\n k -= big - i\r\nprint(*n, sep = '')\r\n", "n, k = [int(c) for c in input().split()]\r\n\r\nar = []\r\n\r\nwhile n != 0:\r\n ar.append(n % 10)\r\n n = n // 10\r\n\r\nar.reverse()\r\n\r\ni = 0\r\n\r\nwhile k > 0 and i < len(ar):\r\n m_val = max(ar[i:i + k + 1])\r\n pos = i\r\n\r\n while ar[pos] != m_val:\r\n pos += 1\r\n\r\n while pos != i:\r\n ar[pos], ar[pos - 1] = ar[pos - 1], ar[pos]\r\n pos -= 1\r\n k -= 1\r\n\r\n i += 1\r\n\r\n\r\nprint(''.join(map(str,ar)))", "s = input()\r\ns, n = s.split()\r\nn = int(n)\r\ns = list(s)\r\n\r\nindex = 0\r\nwhile n > 0:\r\n Max = int(s[index])\r\n pos = index\r\n for i in range(index, min(index + n + 1, len(s))):\r\n if int(s[i]) > Max:\r\n pos = i\r\n Max = int(s[i])\r\n for i in range(min(pos - index, n)):\r\n s[pos], s[pos - 1] = s[pos - 1], s[pos]\r\n pos -= 1\r\n n -= 1\r\n index += 1\r\n if index == len(s):\r\n break\r\nfor i in s:\r\n print(i, end = \"\")\r\nprint()\r\n", "l = input().split()\nk = int(l[1])\ns = list(l[0])\nn = len(s)\n\nfor i in range(n):\n if k <= 0:\n break\n index = i\n for j in range(i+1, min(k+i, n-1)+1):\n if s[j] > s[index]:\n index = j\n for j in range(index, i, -1):\n s[j], s[j-1] = s[j-1], s[j]\n k -= 1\n\nprint(''.join(s))\n\n", "def solve():\r\n n, k = map(int, input().split())\r\n s = str(n)\r\n ws = list(s)\r\n while k:\r\n hm = dict()\r\n for i in range(len(ws)):\r\n if int(ws[i]) in hm:continue\r\n j = i\r\n while j - 1 >= 0 and ws[j - 1] < ws[i] and i - j + 1 <= k:\r\n j -= 1\r\n if j != i:\r\n hm[int(ws[i])] = [j, i]\r\n l = r = 1 << 60\r\n for i in range(10):\r\n if i not in hm:continue\r\n if hm[i][0] <= l:\r\n l = hm[i][0]\r\n r = hm[i][1]\r\n if l == r:\r\n break \r\n for i in range(r, l, -1):\r\n ws[i], ws[i - 1] = ws[i - 1], ws[i]\r\n k -= r - l \r\n print(\"\".join(ws))\r\n \r\nsolve()\r\n ", "\r\nif __name__ == \"__main__\":\r\n a, k = map(int, input().split())\r\n a = list(str(a))\r\n\r\n maxv = -1\r\n pos = -1\r\n i = 0\r\n while i < len(a) and k > 0:\r\n st = i\r\n while i < len(a) and i - st <= k:\r\n if int(a[i]) > maxv:\r\n maxv = int(a[i])\r\n pos = i \r\n i += 1\r\n \r\n for j in range(pos-1, st-1, -1):\r\n a[j+1] = a[j]\r\n \r\n a[st] = maxv \r\n k -= pos - st \r\n maxv = -1\r\n pos = -1\r\n i = st + 1\r\n \r\n res = 0\r\n for x in a:\r\n res = res * 10 + int(x)\r\n print(res)\r\n\r\n", "def main():\r\n ts, tn = input().split()\r\n k = int(tn)\r\n s = list(ts)\r\n for i in range(len(s)):\r\n if s[i] == '9':\r\n continue\r\n curr = i\r\n for j in range(i + 1, len(s)):\r\n if s[j] > s[curr] and j - i <= k:\r\n curr = j\r\n if curr == i:\r\n continue\r\n else:\r\n tmp = s[curr]\r\n for j in range(curr, i, -1):\r\n s[j] = s[j - 1]\r\n s[i] = tmp\r\n k -= (curr - i)\r\n print(''.join(s))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "\r\nif __name__ == \"__main__\":\r\n s, k = input().split(\" \")\r\n s = list(map(str, s))\r\n k = int(k)\r\n i = 0\r\n while i < len(s) and k > 0:\r\n swap = i\r\n j = i + 1\r\n while j < len(s) and j <= i + k:\r\n if s[j] > s[swap]:\r\n swap = j\r\n j += 1\r\n while swap > i:\r\n s[swap], s[swap - 1] = s[swap - 1], s[swap]\r\n k -= 1\r\n swap -= 1\r\n i += 1\r\n print(\"\".join(s))\r\n", "import os\nimport copy\n \nn,k=map(str,input().split())\nn=list(n)\nfor x in n:\n\tx=int(x)\nk=int(k)\ni=0\n#print(n,k)\nwhile k>0 and i<len(n)-1:\n\tarr=n[i+1:i+1+k]\n\td=max(arr)\n\tpos=arr.index(d)\n\tif d>n[i]:\n\t\tfor j in range(i+pos+1,i,-1):\n\t\t\tn[j]=n[j-1]\n\t\tn[i]=d\n\t\tk-=pos+1\n\ti+=1\nfor x in n:\n\tprint(x,end='')\n \n\t \t\t\t\t\t \t\t\t \t\t\t\t \t \t\t \t\t", "from sys import stdin, stdout\r\n\r\ndef main():\r\n\r\n def getMaxIndex(s):\r\n maxim = 0\r\n maxid = 0\r\n for i in range(len(s)):\r\n if ord(s[i]) > maxim:\r\n maxim = ord(s[i])\r\n maxid = i\r\n return maxid\r\n\r\n num, k = stdin.readline().split()\r\n k = int(k)\r\n\r\n pointer = 0\r\n while k and pointer < len(num):\r\n index = pointer + getMaxIndex(num[pointer:pointer+min(len(num),k+1)])\r\n num = num[:pointer] + num[index] + num[pointer:index] + num[index+1:]\r\n k -= (index - pointer)\r\n pointer+=1\r\n \r\n stdout.write(num+'\\n')\r\n\r\nif __name__ == '__main__':\r\n main()", "a, k = input().split()\r\nk = int(k)\r\na = list(a)\r\nmy_position = 0\r\nwhile my_position != len(a):\r\n mx = max(a[my_position:my_position + k + 1])\r\n ind = a.index(mx, my_position, my_position + k + 1)\r\n if k <= 0:\r\n break\r\n if a[ind] == a[my_position]:\r\n my_position += 1\r\n continue\r\n a.pop(ind)\r\n a.insert(my_position, mx)\r\n k = k - ind + my_position\r\n my_position += 1\r\nfor i in a:\r\n print(i, end='')\r\n\r\n", "# LUOGU_RID: 112593860\nimport sys\r\n\r\nclass Fenwick:\r\n def __init__(self,n:int):\r\n self.n=n\r\n self.tr=[0]*(n+10)\r\n\r\n def lowbit(self,x:int)->int:\r\n return x&(-x)\r\n\r\n def add(self,x:int,val:int):\r\n i=x\r\n while i<=self.n:\r\n self.tr[i]+=val\r\n i+=self.lowbit(i)\r\n return\r\n\r\n def get(self,x:int):\r\n i=x\r\n res=0\r\n while i>0:\r\n res+=self.tr[i]\r\n i-=self.lowbit(i)\r\n return res\r\n\r\n def query(self,l,r):\r\n return self.get(r)-self.get(l-1)\r\n\r\npos=[[] for i in range(10)]\r\na,k=list(map(int,sys.stdin.readline().strip().split()))\r\na=list(str(a))\r\nn=len(a)\r\na=['$']+a\r\nfor i in range(1,n+1):\r\n pos[int(a[i])].append(i)\r\nfor i in range(10):\r\n pos[i].sort(key=lambda x:-x)\r\n\r\ncnt=Fenwick(20)\r\nans=[]\r\nfor i in range(1,n+1):\r\n for j in range(9,-1,-1):\r\n if len(pos[j])>0:\r\n behind=cnt.query(pos[j][-1]+1,n)\r\n dist=pos[j][-1]-i+behind\r\n if k>=dist:\r\n k-=dist\r\n cnt.add(pos[j][-1],1)\r\n ans.append(j)\r\n pos[j].pop()\r\n break\r\n\r\nfor x in ans:\r\n print(x,end='')\r\n", "from collections import defaultdict\nfrom sys import stdin, stdout\nrd = lambda: list(map(int, stdin.readline().split()))\nrds = lambda: stdin.readline().rstrip()\nii = lambda: int(stdin.readline())\nINF = 1 << 62\nmod = 10**9 + 7\n\ns, k = rds().split(' ')\n\ns = [int(c) for c in s]\nk = int(k)\n\n\ni = 0\nwhile k and i < len(s):\n # for each i find j j <= i+k\n max_i = -1\n max_val = s[i]\n for j in range(1, k+1):\n if i+j >= len(s):\n break\n if s[i+j] > max_val:\n max_val = s[i+j]\n max_i = i + j\n\n if max_val == 9:\n break\n\n # hop max_i to i\n if max_i != -1:\n for l in range(max_i, i, -1):\n s[l], s[l-1] = s[l-1], s[l]\n\n k -= max_i - i\n\n i += 1\n\nstdout.write(''.join(map(str, s)))\n#stdout.write(f'{res}')\n\n", "arr=list(input().split())\ns = list(arr[0])\nk = int(arr[1])\nans = []\n\nwhile s:\n x = s.index(max(s[:k+1]))\n ans.append(s[x])\n s.pop(x)\n k-=x\nprint(''.join(ans))\n", "import os\r\nimport copy\r\n\r\nn,k=map(str,input().split())\r\nn=list(n)\r\nfor x in n:\r\n\tx=int(x)\r\nk=int(k)\r\ni=0\r\n#print(n,k)\r\nwhile k>0 and i<len(n)-1:\r\n\tarr=n[i+1:i+1+k]\r\n\td=max(arr)\r\n\tpos=arr.index(d)\r\n\tif d>n[i]:\r\n\t\tfor j in range(i+pos+1,i,-1):\r\n\t\t\tn[j]=n[j-1]\r\n\t\tn[i]=d\r\n\t\tk-=pos+1\r\n\ti+=1\r\nfor x in n:\r\n\tprint(x,end='')\r\n\r\n\r\n", "a, k = map(int, input().split())\r\na = list(str(a))\r\nb = ''\r\nwhile(a):\r\n\tidx = a.index(max(a[:k+1]))\r\n\tk -= idx \r\n\tb += a[idx]\r\n\ta.pop(idx)\r\nprint(b)\r\n", "import random\r\nimport sys\r\nfrom math import gcd, lcm, sqrt, isqrt, perm\r\nfrom collections import Counter, defaultdict, deque\r\nfrom functools import lru_cache, reduce, cmp_to_key\r\nfrom itertools import accumulate, combinations, permutations\r\nfrom heapq import nsmallest, nlargest, heappushpop, heapify, heappop, heappush\r\nfrom copy import deepcopy\r\nfrom bisect import bisect_left, bisect_right\r\nfrom string import ascii_lowercase, ascii_uppercase\r\ninf = float('inf')\r\nMOD = 10**9+7\r\ninput = lambda: sys.stdin.readline().strip()\r\nI = lambda: input()\r\nII = lambda: int(input())\r\nMII = lambda: map(int, input().split())\r\nLI = lambda: list(input().split())\r\nLII = lambda: list(map(int, input().split()))\r\nGMI = lambda: map(lambda x: int(x) - 1, input().split())\r\nLGMI = lambda: list(map(lambda x: int(x) - 1, input().split()))\r\n\r\ndef solve():\r\n s, k = input().split()\r\n s = list(s)\r\n k = int(k)\r\n n = len(s)\r\n for i in range(n):\r\n pos = i\r\n for j in range(i+1, min(n, i+k+1)):\r\n if s[j] > s[pos]:\r\n pos = j\r\n for j in range(pos, i, -1):\r\n s[j], s[j-1] = s[j-1], s[j]\r\n k -= pos-i\r\n if k == 0:\r\n break\r\n print(''.join(s))\r\n return\r\n\r\nsolve()\r\n", "from functools import lru_cache\r\n\r\ns, k = map(int, input().split())\r\na = list(str(s))\r\nb = \"\"\r\nwhile len(a) > 0:\r\n m = a.index(max(a[:k + 1]))\r\n k -= m\r\n b += a[m]\r\n a.pop(m)\r\nprint(b)\r\n", "s,k=map(int,input().split())\r\nls=[]\r\nfor i in str(s):\r\n ls.append(i)\r\nfor i in range(len(ls)):\r\n temp=i\r\n for j in range(i,len(ls)):\r\n if k<j-i:\r\n continue\r\n if ls[temp]<ls[j]:\r\n temp=j\r\n k-=temp-i\r\n l=temp\r\n while l>i:\r\n ls[l],ls[l-1]=ls[l-1],ls[l]\r\n l-=1\r\nans='' \r\nfor i in ls:\r\n ans+=i\r\nprint(ans)", "a,k=map(int,input().split())\r\na=list(str(a))\r\nb=\"\"\r\nwhile(len(a)>0):\r\n\tm=a.index(max(a[:k+1]))\r\n\tk-=m\r\n\tb+=a[m]\r\n\ta.pop(m)\r\nprint(b)\r\n", "n , k = input().split()\r\nk = int(k)\r\nl = list(n)\r\nm = len(l)\r\nfor i in range(m):\r\n t =l[i]\r\n index = 0\r\n for j in range(i+1 , min(i + k +1 , m)):\r\n if l[j] > t :\r\n t = l[j]\r\n index = j\r\n\r\n while index > i :\r\n l[index] , l[index - 1] = l[index-1] , l[index]\r\n k-=1\r\n index -=1\r\n\r\nprint(''.join(l))", "a, k = [i for i in input().split()]\r\nk = int(k)\r\na = list(a)\r\na = [int(i) for i in a] + [-1]\r\ncount = 1\r\nwhile k > 0 and count < len(a):\r\n _max = max(a[count:min(len(a), k + count)])\r\n ind = a[count:min(len(a), k + count)].index(_max) + count\r\n if _max > a[count - 1]:\r\n k = k - ind + count - 1\r\n a.pop(ind)\r\n a.insert(count - 1, _max)\r\n count +=1\r\nprint(*a[:-1], sep='')\r\n\r\n", "import sys\r\nfrom collections import defaultdict\r\n\r\ndef perform_swaps(j, i, values):\r\n for x in range(j, i , -1):\r\n values[x], values[x - 1] = values[x - 1], values[x]\r\n\r\ndef main() -> None:\r\n read = sys.stdin.readline\r\n values, k = read().split()\r\n k: int = int(k)\r\n values: list[int] = [int(c) for c in values.strip()]\r\n next_insertion = 0\r\n while next_insertion < len(values):\r\n # Find the range we are considering\r\n max_value = -1\r\n max_value_idx = -1\r\n for j in range(next_insertion + 1, min(next_insertion + k + 1, len(values))):\r\n if values[j] > max_value:\r\n max_value = values[j]\r\n max_value_idx = j\r\n if max_value > 0 and max_value > values[next_insertion]:\r\n # Do a swap\r\n cost = max_value_idx - next_insertion\r\n k -= cost\r\n perform_swaps(max_value_idx, next_insertion, values)\r\n next_insertion += 1\r\n\r\n\r\n print(''.join((str(c) for c in values)))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n# For the other", "n,k=input().split()\r\nk=int(k)\r\nl=list(n)\r\nu=len(l)\r\nd='0'\r\ni=0\r\nwhile k>0 and i<u-1:\r\n\tc=i+k\r\n\tif c>u:\r\n\t\tc=u\r\n\td=max(l[i+1:c+1])\r\n\tif d>l[i]:\r\n\t\tj=False\r\n\t\tp=i+1\r\n\t\twhile not j:\r\n\t\t\tif l[p]==d: j=p\r\n\t\t\telse:p+=1\r\n\t\t\t\r\n\t\tfor h in range(j,i,-1):\r\n\t\t\tl[h],l[h-1]=l[h-1],l[h]\r\n\t\t\tk-=1\r\n\t\ti=0\r\n\telse:\r\n\t\ti+=1\r\nx=''\r\nfor i in l:\r\n\tx=x+str(i)\r\nprint(x)", "if __name__ == \"__main__\":\r\n s, k = map(int, input().split())\r\n s = list(str(s))\r\n ans = \"\"\r\n while len(s) > 0:\r\n m = s.index(max(s[:k+1]))\r\n k -= m\r\n ans += s[m]\r\n s.pop(m)\r\n print(ans)", "s, k = input().split()\r\ns = list(s)\r\nk = int(k)\r\n\r\nfor i in range(len(s)-1):\r\n if k == 0: break\r\n if s[i] == '9':\r\n continue\r\n\r\n j = idx = i\r\n max_ = s[i]\r\n while j-i <= k and j < len(s):\r\n if max_ < s[j]:\r\n max_ = s[j]\r\n idx = j\r\n j += 1\r\n\r\n mid = s[i:idx]\r\n s = s[:i] + [s[idx]] + mid + s[idx+1:]\r\n k -= idx-i\r\n\r\nprint(\"\".join(s))", "import sys\r\ninput = sys.stdin.readline\r\nread_tuple = lambda _type: map(_type, input().split(' '))\r\n\r\n\r\ndef solve():\r\n a, k = input().split(' ')\r\n a, n, k, i = list(a), len(a), int(k), 0\r\n while k and i < n:\r\n current = a[i]\r\n greater_than_current = {}\r\n for j, elem in enumerate(a[i:]):\r\n if elem > current and j <= k and elem not in greater_than_current:\r\n greater_than_current[elem] = j\r\n if greater_than_current:\r\n _max = max(greater_than_current)\r\n a.pop(i + greater_than_current[_max])\r\n a.insert(i, _max)\r\n k -= greater_than_current[_max]\r\n i += 1\r\n print(''.join(a))\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n solve()", "number,swaps=input().split() ; swaps=int(swaps); number=list(number) ; start=0 ; lenth=len(number)\r\nwhile swaps>0 and start<lenth-1:\r\n maxi=max(number[start:start+swaps+1])\r\n ind=number[start:].index(maxi)\r\n x=number.pop(start+ind) ; number.insert(start, x)\r\n swaps-=ind\r\n start+=1\r\nprint(\"\".join(number))\r\n ", "l = input().split()\r\na = list(map(int, l[0]))\r\nk = int(l[1])\r\nn = len(a)\r\ndef rshift(a, l, r):\r\n t = a[r]\r\n for i in range(r, l, -1):\r\n a[i] = a[i - 1]\r\n a[l] = t\r\nfor i in range(n - 1):\r\n if k == 0:\r\n break\r\n j = min(n - 1, i + k)\r\n m = max(a[i + 1:j + 1])\r\n if m > a[i]:\r\n x = i + a[i + 1:j + 1].index(m) + 1\r\n rshift(a, i, x)\r\n k -= x - i\r\nprint(''.join(map(str, a)))", "import os\r\nimport sys\r\nimport math\r\nimport heapq\r\nfrom decimal import *\r\nfrom io import BytesIO, IOBase\r\nfrom collections import defaultdict, deque\r\n\r\ndef r():\r\n return int(input())\r\ndef rm():\r\n return map(int,input().split())\r\ndef rl():\r\n return list(map(int,input().split()))\r\n\r\ns, k = map(str,input().split())\r\nk = int(k)\r\ns = [int(s[i]) for i in range(len(s))]\r\nn = len(s)\r\npnt=0\r\nwhile k!=0 and pnt<n-1:\r\n maxi = max(s[pnt+1:min(k+pnt+1,len(s))])\r\n if maxi<=s[pnt]:\r\n pnt+=1\r\n else:\r\n found=False\r\n for i in range(pnt+1,min(k+pnt+1,n)):\r\n if s[i]==maxi:\r\n found=True\r\n break\r\n if found:\r\n k-=(i-pnt)\r\n s = s[:pnt] + [s[i]] + s[pnt:i] + s[i+1:]\r\n pnt+=1\r\nprint(*s,sep='')\r\n", "n, k = [int(i) for i in input().split()]\r\ns = list(str(n))\r\nresult = ''\r\nwhile len(s) > 0:\r\n mx = max(s[:k + 1])\r\n ind = s.index(mx)\r\n k -= ind\r\n s.pop(ind)\r\n result += mx\r\nprint(result)\r\n", "inp, k = map(int, input().split())\r\n\r\ninp = list(repr(inp))\r\nans = []\r\n\r\nwhile len(inp) != 0:\r\n tmp = max(inp[:k + 1])\r\n pos = inp.index(tmp)\r\n k -= pos\r\n ans.append(tmp)\r\n inp.pop(pos)\r\n\r\nprint(''.join(ans))\r\n" ]
{"inputs": ["1990 1", "300 0", "1034 2", "9090000078001234 6", "1234 3", "5 100", "1234 5", "1234 6", "9022 2", "66838 4", "39940894417248510 10", "5314 4", "1026 9", "4529 8", "83811284 3", "92153348 6", "5846059 3", "521325125110071928 4", "39940894417248510 10", "77172428736634377 29", "337775999910796051 37", "116995340392134308 27", "10120921290110921 20", "929201010190831892 30", "111111111111111119 8", "219810011901120912 100", "191919191919119911 100", "801211288881101019 22", "619911311932347059 3", "620737553540689123 2", "621563797296514835 3", "915277434701161 9", "15603712376708 28", "784069392990841 0", "787464780004 2", "74604713975 29", "901000000954321789 5", "901000000954321789 10", "901000000954321789 28", "901000000954321789 40", "901000000954321789 70", "1234567891234567 99", "123456789123456789 100", "12345670123456789 100", "12 100", "11223344556677889 47"], "outputs": ["9190", "300", "3104", "9907000008001234", "4123", "5", "4312", "4321", "9220", "86863", "99984304417248510", "5431", "6210", "9542", "88321184", "98215334", "8654059", "552132125110071928", "99984304417248510", "87777764122363437", "999997733751076051", "999654331120134308", "99221010120110921", "999928201010103182", "111111111911111111", "999822211111110000", "999999991111111111", "982111028888110101", "969111311932347059", "672037553540689123", "662153797296514835", "977541234701161", "87761503123670", "784069392990841", "877644780004", "97776544310", "910009000054321789", "991000000504321789", "999100050000432178", "999810000050043217", "999875410000300021", "9877665544332211", "998877665544213123", "98776655443322101", "21", "98821213344556677"]}
UNKNOWN
PYTHON3
CODEFORCES
90
1f4cbe261ba5bc12af16f0c6bfe7bd72
Load Testing
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last *n* minutes and in the *i*-th minute friends will send *a**i* requests. Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load. Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable. For example, if the load is described with one of the arrays [1, 2, 8, 4, 3], [1, 3, 5] or [10], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays [1, 2, 2, 1], [2, 1, 2] or [10, 10], then such load does not satisfy Polycarp. Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from 1 to *n*. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the duration of the load testing. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of requests from friends in the *i*-th minute of the load testing. Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards. Sample Input 5 1 4 3 2 5 5 1 2 2 2 1 7 10 20 40 50 70 90 30 Sample Output 6 1 0
[ "s, l, r = 0, 0, int(input()) - 1\r\nt = list(map(int, input().split()))\r\nwhile 1:\r\n while l < r and t[l] < t[l + 1]: l += 1\r\n while l < r and t[r] < t[r - 1]: r -= 1\r\n if l == r: break\r\n if t[l] < t[r]:\r\n s += t[l] - t[l + 1] + 1\r\n t[l + 1] = t[l] + 1\r\n else:\r\n s += t[r] - t[r - 1] + 1\r\n t[r - 1] = t[r] + 1\r\nprint(s)", "n = int(input())\r\np = list(map(int, input().split()))\r\na = [0] * n\r\nt = s = f = 0\r\nfor i in range(n):\r\n if p[i] <= t: a[i] = t - p[i] + 1\r\n t = max(p[i], t+1)\r\nfor i in range(n-1, 0, -1):\r\n if p[i] <= s: a[i] = min(s - p[i] + 1, a[i])\r\n else: a[i] = 0\r\n s = max(p[i], s + 1)\r\nfor i in range(n):\r\n\tp[i] += a[i]\r\n\tf |= i > 1 and p[i] == p[i-1]\r\nprint(sum(a[:]) + f)\r\n", "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\nd = [w[0]]\r\ne = [w[-1]]\r\nfor i in w[1:]:\r\n d.append(max(d[-1]+1, i))\r\nfor i in w[:-1][::-1]:\r\n e.append(max(e[-1]+1, i))\r\ne = e[::-1]\r\nc = 10**18\r\nf = -1\r\nfor i in range(n):\r\n a = max(d[i], e[i])\r\n b = (2*a-i)*(i+1) + (2*a-(n-i-1))*(n-i)\r\n if b//2 < c:\r\n f = i\r\n c = b//2\r\n\r\nc = 0\r\nfor i in range(1, f+1):\r\n a = max(w[i-1]+1, w[i])\r\n c += a - w[i]\r\n w[i] = a\r\nfor i in range(n-2, f-1, -1):\r\n a = max(w[i+1]+1, w[i])\r\n c += a - w[i]\r\n w[i] = a\r\nprint(c)", "n=int(input())\r\np=list(map(int,input().split()))\r\na=[0]*n\r\nt=s=f=0\r\nfor i in range(n):\r\n if p[i]<=t:a[i]=t-p[i]+1\r\n t=max(p[i],t+1)\r\nfor i in range(n-1,0,-1):\r\n if p[i] <= s: a[i] = min(s - p[i] + 1,a[i])\r\n else:a[i]=0\r\n s = max(p[i], s + 1)\r\nfor i in range(n):p[i]+=a[i];f|=i>1and p[i]==p[i-1]\r\nprint(sum(a[:])+f)", "n = int(input())\r\narr = list(map(int, input().split()))\r\nforward = arr[:]\r\ncnt = arr[0] + 1\r\nfor i in range(1, n):\r\n forward[i] = max(cnt, arr[i])\r\n cnt = max(cnt, arr[i]) + 1\r\n\r\nbackward = arr[:]\r\ncnt = arr[n - 1] + 1\r\nfor i in range(n - 2, -1, -1):\r\n backward[i] = max(cnt, arr[i])\r\n cnt = max(cnt, arr[i]) + 1\r\nans = 0\r\nfor i in range(n):\r\n if forward[i] < backward[i]:\r\n ans += forward[i] - arr[i]\r\n else:\r\n if abs(backward[i] - forward[i]) == 1:\r\n ans += 1\r\n ans += backward[i] - arr[i]\r\nprint(ans)\r\n", "import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nN = int(input())\nA = list(map(int,input().split()))\nR,L = A[:],A[:]\nr,l = [0,0],[0,0]\nfor i in range(N-2,-1,-1):\n if R[i]<=R[i+1]:\n r.append(r[-1]+((R[i+1]+1)-R[i]))\n R[i] = R[i+1]+1\n else:\n r.append(r[-1])\nr.pop()\nr = r[::-1]\n\nfor i in range(1,N):\n if L[i]<=L[i-1]:\n l.append(l[-1]+((L[i-1]+1)-L[i]))\n L[i] = L[i-1]+1\n else:\n l.append(l[-1])\nl.pop()\n# print(L,R,l,r)\nans = float('inf')\n\nfor i in range(N):\n ans = min(ans,(max(R[i],L[i])-A[i])+r[i]+l[i])\nprint(ans)", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nstarts = [0 for _ in range(n)]\r\nends = [0 for _ in range(n)]\r\n\r\nstarts[0] = arr[0]\r\nends[-1] = arr[-1]\r\n\r\nfor i in range(1, n):\r\n starts[i] = max(arr[i], starts[i - 1] + 1)\r\n ends[-i - 1] = max(arr[-i - 1], ends[-i] + 1)\r\n\r\nsts = starts[:]\r\neds = ends[:]\r\n\r\nfor i in range(n):\r\n starts[i] -= arr[i]\r\n ends[-i - 1] -= arr[-i - 1]\r\n\r\nfor i in range(1, n):\r\n starts[i] += starts[i - 1]\r\n ends[-i - 1] += ends[-i]\r\n\r\nbst = 10**30\r\n\r\nfor i in range(n):\r\n score = max(sts[i], eds[i]) - arr[i]\r\n \r\n if i > 0:\r\n score += starts[i - 1]\r\n if i < n - 1:\r\n score += ends[i + 1]\r\n \r\n bst = min(bst, score)\r\n\r\nprint(bst)", "n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nlp,rp = [0 for i in range(n)],[0 for i in range(n)]\r\nlnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)]\r\nmx = a[0]\r\nfor i in range(1,n):\r\n if a[i] > mx:\r\n mx = a[i]\r\n lp[i] = lp[i-1]\r\n else:\r\n mx += 1\r\n lp[i] = lp[i-1] + mx - a[i]\r\n lnr[i] = mx\r\n\r\nmx = a[-1]\r\nfor i in range(n-2,-1,-1):\r\n if a[i] > mx:\r\n mx = a[i]\r\n rp[i] = rp[i+1]\r\n else:\r\n mx += 1\r\n rp[i] = rp[i+1] + mx - a[i]\r\n rnr[i] = mx\r\n \r\nans = min(rp[0], lp[-1])\r\nfor i in range(1,n-1):\r\n ca = lp[i-1] + rp[i+1]\r\n if max(lnr[i-1], rnr[i+1]) + 1 > a[i]:\r\n ca += max(lnr[i-1], rnr[i+1]) + 1 - a[i]\r\n ans = min(ans, ca)\r\nprint(ans)" ]
{"inputs": ["5\n1 4 3 2 5", "5\n1 2 2 2 1", "7\n10 20 40 50 70 90 30", "1\n1", "2\n1 15", "4\n36 54 55 9", "5\n984181411 215198610 969039668 60631313 85746445", "10\n12528139 986722043 1595702 997595062 997565216 997677838 999394520 999593240 772077 998195916", "100\n9997 9615 4045 2846 7656 2941 2233 9214 837 2369 5832 578 6146 8773 164 7303 3260 8684 2511 6608 9061 9224 7263 7279 1361 1823 8075 5946 2236 6529 6783 7494 510 1217 1135 8745 6517 182 8180 2675 6827 6091 2730 897 1254 471 1990 1806 1706 2571 8355 5542 5536 1527 886 2093 1532 4868 2348 7387 5218 3181 3140 3237 4084 9026 504 6460 9256 6305 8827 840 2315 5763 8263 5068 7316 9033 7552 9939 8659 6394 4566 3595 2947 2434 1790 2673 6291 6736 8549 4102 953 8396 8985 1053 5906 6579 5854 6805"], "outputs": ["6", "1", "0", "0", "0", "0", "778956192", "1982580029", "478217"]}
UNKNOWN
PYTHON3
CODEFORCES
8
1f4e69ed4131031462be5f829f047a10
Sonya and Exhibition
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions should contain exactly one flower: a rose or a lily. She knows that exactly $m$ people will visit this exhibition. The $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. The girl knows that each segment has its own beauty that is equal to the product of the number of roses and the number of lilies. Sonya wants her exhibition to be liked by a lot of people. That is why she wants to put the flowers in such way that the sum of beauties of all segments would be maximum possible. The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively. Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any. Sample Input 5 3 1 3 2 4 2 5 6 3 5 6 1 4 4 6 Sample Output 01100110010
[ "def scanf(t=int):\r\n return list(map(t, input().split()))\r\nn, m = scanf()\r\ns = '01' * (n//2) + '0' * (n % 2)\r\nprint(s)", "# import atexit\r\n# import io\r\n# import sys\r\n#\r\n# _INPUT_LINES = sys.stdin.read().splitlines()\r\n# input = iter(_INPUT_LINES).__next__\r\n# _OUTPUT_BUFFER = io.StringIO()\r\n# sys.stdout = _OUTPUT_BUFFER\r\n#\r\n#\r\n# @atexit.register\r\n# def write():\r\n# sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())\r\n\r\nn, m = map(int, input().split())\r\n\r\nans = \"10\" * (n // 2)\r\n\r\nif (n & 1) == 1:\r\n ans += \"1\"\r\n\r\nprint(ans)\r\n", "n,m=map(int,input().split())\r\nprint('10'*(n//2)+('1' if n%2 else ''))", "import sys\nimport os\nn,m=list(map(int,input().split()))\nwhile m:\n\ta,b=list(map(int,input().split()))\n\tm-=1\nfor i in range(n):\n\tif i%2==0:\n\t\tprint(\"0\",end=\"\")\n\telse:\n\t\tprint(\"1\",end=\"\")\nprint(\"\")\n\n", "n,m = map(int,input().split())\r\nfor i in range(m):\r\n l,r = map(int,input().split())\r\ns=\"\"\r\nif(n%2==0):\r\n s=\"01\"*(n//2)\r\nelse:\r\n s=\"01\"*(n//2)+\"0\"\r\nprint(s)\r\n\r\n", "# import sys\r\n# sys.stdin=open('F:\\\\C\\\\Script\\\\input.txt','r')\r\n# sys.stdout=open('F:\\\\C\\\\Script\\\\output.txt','w')\r\n# sys.stdout.flush()\r\n\r\ndef I():\r\n\treturn [int(i) for i in input().split()]\r\n\r\nn , m = I()\r\nfor i in range(m):\r\n\tl , r = I()\r\nprint ('10'*(n//2)+n%2*'1')\r\n\r\n", "n, m = [int(i) for i in input().split()]\r\nfor i in range(n):\r\n print(i%2, end = \"\")\r\nprint()\r\n", "n,m = list(map(int, input().split(' ')))\r\nfor i in range(m):\r\n l , r = list(map(int, input().split(' ')))\r\n\r\ns = ''\r\nfor i in range(n):\r\n if(i%2 == 0):\r\n s = s + '0'\r\n else:\r\n s = s + '1'\r\nprint(s)\r\n", "a=[int(q) for q in input().strip().split()]\r\nb=[]\r\nfor k in range(a[1]):\r\n t=input()\r\nfor k in range(int(a[0]/2)):\r\n b.append('10')\r\nif int(a[0])%2==1:\r\n b.append('1')\r\nprint(''.join(b))", "def main():\n n, m = map(int, input().strip().split())\n for _ in range(m):\n a, b = map(int, input().strip().split())\n \n output = [i % 2 for i in range(n)]\n print(''.join(map(str, output)))\n\nif __name__ == '__main__':\n main()\n\t \t \t\t\t\t\t \t\t \t\t\t\t\t \t \t\t \t \t", "import math as ma\r\nfrom sys import exit\r\nfrom decimal import Decimal as dec\r\ndef li():\r\n\treturn list(map(int , input().split()))\r\ndef num():\r\n\treturn map(int , input().split())\r\ndef nu():\r\n\treturn int(input())\r\n\r\nn,m=num()\r\ns=\"\"\r\nfor i in range(n//2):\r\n\ts+=\"10\"\r\nif(n%2==1):\r\n\ts+=\"1\"\r\nprint(s)", "n,m=[int(c) for c in input().split()]\r\nfor x in range(m):\r\n c=input()\r\nfor c in range(int(n/2)):\r\n print(\"01\",end=\"\")\r\nif n%2==1:\r\n print(\"0\")", "n, d = map(int, input().split())\r\nprint('10' * (n // 2), end='')\r\nif(n % 2):\r\n print(1)", "n,m=[int(i) for i in input().split()]\r\ng=[]\r\nfor i in range(m):\r\n g.append(input().split())\r\n \r\nfor i in range(n): \r\n if i%2==0:\r\n print(\"1\",end=\"\")\r\n else:\r\n print(\"0\",end=\"\")\r\nprint()", "n, m = [int(i) for i in input().split()]\r\nfor j in range(m):\r\n l, r = [int(x) for x in input().split()]\r\ns = ''\r\nfor y in range(n):\r\n s += str(y % 2)\r\nprint(s)\r\n", "f, v = map(int, input().split())\r\n\r\nfor i in range(v):\r\n l, r = map(int, input().split())\r\n\r\nfor j in range(f):\r\n if j%2 == 0:\r\n print(1, end='')\r\n else:\r\n print(0, end='')\r\nprint()", "n, _ = map(int, input().split())\nprint(('01' * n)[:n])\n", "n,p=map(int, input().split())\r\nfor i in range(p):\r\n\ta,b=map(int, input().split())\r\n\r\nfor i in range(n):\r\n\tif i%2==0:\r\n\t\tprint('0',end='')\r\n\telse:\r\n\t\tprint('1',end='')\r\n", "# your code goes here\r\nn ,m = map(int,input().split())\r\nlist_pos = []\r\nfor i in range(m):\r\n\tl,r = map(int,input().split())\r\n\tlr = []\r\n\tlr.append(l)\r\n\tlr.append(r)\r\n\tlist_pos.append(lr)\r\n\r\nflag = 0\r\np_str = ''\r\nfor i in range(n):\r\n\tif flag == 0:\r\n\t\tp_str = p_str +'0'\r\n\t\tflag = 1\r\n\telif flag == 1:\r\n\t\tp_str = p_str + '1'\r\n\t\tflag = 0\r\n\r\nprint(p_str)\r\n\t\t\r\n", "n,k=map(int,input().split())\r\narr=[]\r\nfor i in range(k):\r\n x,y=map(int,input().split())\r\n arr.append([x,y])\r\narr1=[0]*n\r\nfor i in range(n):\r\n if(i%2==0):\r\n arr1[i]=0\r\n else:\r\n arr1[i]=1\r\n\"\"\"for i in range(k):\r\n for j in range(arr[i][0]-1,arr[i][1]):\r\n if(j==0):\r\n arr1[j]=0\r\n else:\r\n if(arr[j-1]!=arr[j]):\r\n if(arr1[j-1]==1):\r\n arr1[j]=0\r\n else:\r\n arr1[j]=1\"\"\"\r\ns=''\r\nfor i in arr1:\r\n s+=str(i)\r\nprint(s)\r\n\r\n", "n, m = map(int,input().split())\r\nans = [str(i%2) for i in range(n)]\r\nprint(\"\".join(ans))", "R=lambda:map(int,input().split())\nn,m=R()\nprint(((n+1)//2*'01')[:n])", "n,m = map(int,input().split())\r\nfor _ in range(m):\r\n x,y = map(int,input().split())\r\n\r\ncnt = 0\r\nans = []\r\nfor i in range(n):\r\n if cnt%2 == 0:\r\n ans.append(\"0\")\r\n\r\n else:\r\n ans.append(\"1\")\r\n\r\n cnt += 1\r\n\r\nprint(\"\".join(ans))", "n, m = map(int, input().split(' '))\r\nl = []\r\nr = []\r\nfor i in range(m):\r\n l_i, r_i = map(int, input().split(' '))\r\n l.append(l_i)\r\n r.append(r_i)\r\ns = ''\r\nfor i in range(n):\r\n if i % 2==0:\r\n s += '0'\r\n else:\r\n s += '1'\r\nprint(s)", "n,m = [int(i) for i in input().split()]\r\np = []\r\nfor i in range(m):\r\n ii,jj = [int(i) for i in input().split()]\r\n p += [[ii,jj]]\r\n\r\ns = \"\"\r\nfor i in range(n):\r\n if i % 2 == 0:\r\n s += \"1\"\r\n else:\r\n s += \"0\"\r\n \r\nprint(s)\r\n", "n, m =[int(x) for x in input().split()]\r\nz= '01'*500\r\nz=z[:n]\r\nprint(z)", "def input_int():\r\n return list(map(int, input().split()))\r\n\r\n\r\nn, m = input_int()\r\nfor _ in range(m):\r\n a, b = input_int()\r\n\r\nc = ['1', '0']\r\ns = ''\r\nfor i in range(n):\r\n s = s + c[i%2]\r\n\r\nprint(s)\r\n\r\n", "# \r\nimport collections\r\nfrom functools import cmp_to_key\r\n#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )\r\nimport math\r\nimport sys\r\ndef getIntList():\r\n return list(map(int, input().split())) \r\n\r\nimport bisect \r\ntry :\r\n import numpy\r\n dprint = print\r\n dprint('debug mode')\r\nexcept ModuleNotFoundError:\r\n def dprint(*args, **kwargs):\r\n pass\r\ndef makePair(z):\r\n return [(z[i], z[i+1]) for i in range(0,len(z),2) ]\r\ndef memo(func): \r\n cache={} \r\n def wrap(*args): \r\n if args not in cache: \r\n cache[args]=func(*args) \r\n return cache[args] \r\n return wrap\r\n\r\n@memo\r\ndef comb (n,k):\r\n if k==0: return 1\r\n if n==k: return 1\r\n return comb(n-1,k-1) + comb(n-1,k)\r\n\r\nn,m = getIntList()\r\n\r\nfor x in range(n):\r\n print(x%2,end = '')\r\n\r\nprint()\r\n\r\n", "n = int(input().split()[0])\r\nl = input()\r\nprint('10' * (n // 2) + '1' * (n % 2))", "n,k=map(int,input().split())\r\nfor i in range(k):\r\n l,r=map(int,input().split())\r\nl1=[0]\r\nfor i in range(1,n):\r\n if(l1[i-1]==0):\r\n l1.append(1)\r\n else:\r\n l1.append(0)\r\nfor i in l1:\r\n print(i,end=\"\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input().split()[0])\r\nout = ''\r\nfor i in range(n):\r\n out += str(i % 2)\r\nprint(out)", "a,b=map(int,input().split())\nl=[]\nfor i in range(b):\n m,n=map(int,input().split())\n l.append([m,n])\ns=\"\"\nfor i in range(a):\n if(i%2==0):\n s+=\"1\"\n else:\n s+=\"0\"\nprint(s)\n", "n, m = map(int, input().split())\r\nq = ''\r\nfor i in range(m):\r\n x, y = map(int, input().split())\r\nfor i in range(n):\r\n q = q + str(1 - (i % 2))\r\nprint(q)", "n,m=map(int,input().split())\r\nl=[]\r\nr=[]\r\nfor i in range(m):\r\n a,b=map(int,input().split());\r\n l.append(a);\r\n r.append(b);\r\nans1='10'*n;\r\nprint(ans1[0:n])\r\n ", "n, m = map(int,input().split())\r\ns=\"\"\r\nf=0\r\nfor i in range(n):\r\n s=s+str(f)\r\n if f==0:\r\n f=1\r\n else:\r\n f=0\r\nprint(s) \r\n \r\n ", "def readList(converter = str):\r\n return [converter(x) for x in input().strip().split()]\r\n\r\nn,m = readList(int)\r\n\r\nprint('10'*(n//2) + ('1' if n%2 == 1 else ''))", "n, _ = map(int, input().split())\r\n\r\ns = \"01\"\r\nwhile len(s) < n:\r\n s = s + s\r\n\r\nprint(s[:n])", "# def solve():\n# \tsol = [-1] * n\n# \twhile visitos:\n# \t\tcur = visitos.pop()\n# \t\tfor i in range(cur[0])\n\n\nn, m = [int(x) for x in input().split(' ')]\nvisitos = []\nfor i in range(m):\n\tvisitos.append([int(x) for x in input().split(' ')])\n\n# visitos.sort(key=lambda x:(x[1] - x[0]))\nsol = \"\"\nfor i in range(n):\n\tsol += str(i%2)\n\nprint(sol)\n", "'''\n# 07.08.2021\n#\n# CF 495 B\n'''\n\nn, m = map (int, input ().split ())\n\nfor i in range (m) :\n l,r = map (int, input ().split ())\n\ns = ['0']*n\nfor i in range (0, n, 2) :\n s [i] = '1'\n\nfor i in range (n) :\n print (s [i], end='')\n", "n, m = [int(x) for x in input().split()]\r\nfor _ in range(m): input()\r\nprint(\"01\" * (int(n/2)) + (\"0\" if (n % 2 != 0) else \"\"))\r\n", "n, m = map(int, input().split())\nx = [0]\nfor i in range(n - 1):\n x.append(1 - x[-1])\nprint(''.join(map(str, x)))\n", "n,m=map(int,input().split())\r\nfor i in range(1,m+1):\r\n\ta,b=map(int,input().split())\r\nfor i in range(1,n+1):\r\n\tif(i%2==1):\r\n\t\tprint(1,end='');\r\n\telse:\r\n\t\tprint(0,end='');\r\n", "n, m = map(int, input().split())\r\n\r\n \r\ns = \"\".join(['0' if i%2 == 0 else '1' for i in range(n)])\r\n\r\nfor i in range(m):\r\n l, r = map(int, input().split())\r\n # print(s[l-1:r].count('1') * s[l-1:r].count('0'))\r\n \r\nprint(s)", "n,m=[int(x) for x in input().split()]\r\na=[]\r\nfor ii in range(m):\r\n a.append([int(x) for x in input().split()])\r\n\r\n\r\n\r\nfor i in range(n):\r\n print(i&1,end='')\r\nprint()\r\n \r\n \r\n \r\n \r\n \r\n \r\n", "#import sys\r\nf,v = map(int,input().split())\r\n#ans = 0\r\nfor i in range(v):\r\n l,r = map(int,input().split())\r\n \"\"\"if (r-l) % 2 != 0:\r\n ans += pow((r-l+1)//2,2)\r\n else:\r\n t = (r-l)//2\r\n ans += t*(t+1)\"\"\"\r\nprint('01'*(f//2),end = '')\r\nif f%2 !=0:\r\n print(0)\r\n", "n, _ = map(int, input().split())\ns = '01' * (n // 2) + ('0' if n % 2 == 1 else '')\nprint(s)", "a=list(map(int,input().split()))\r\nn=a[0]\r\nm=a[1]\r\n\r\nk=[]\r\nfor i in range(m):\r\n k.append(list(map(int,input().split()))) \r\n\r\ns=''\r\nfor i in range(n):\r\n if(i%2==0):\r\n s+='1'\r\n else:\r\n s+='0'\r\n\r\nprint(s)", "n, k = list(map(int, input().split()))\r\nfor _ in range(k):\r\n input()\r\n \r\nprint(('10'*n)[:n])", "n,m=map(int,input().split())\r\nprint('01'*(n//2)+('0' if n%2 else ''))", "n, m = [int(i) for i in input().split()]\n\nif n % 2 == 0:\n print('10' * (n // 2))\nelse:\n print('10' * (n // 2) + '1')", "n,m=map(int,input().split())\r\nfor i in range(m):\r\n l,r=map(int,input().split())\r\nans=\"\"\r\nfor i in range(n):\r\n if i%2:\r\n ans+='0'\r\n else:\r\n ans+='1'\r\nprint(ans)\r\n", "n,m=map(int,input().split())\r\nprint (((n//2)*\"01\"),end=\"\")\r\nif n%2==1:\r\n print('0')\r\n", "n, m = map(int, input().split())\r\nfor i in range(m):\r\n input()\r\n\r\nc = 0\r\n\r\nfor i in range(n):\r\n print(c, end='')\r\n c ^= 1", "arr=list(map(int, input().rstrip().split()))\r\nn=arr[0]\r\nm=arr[1]\r\narr=[]\r\nfor i in range(m):\r\n\tbrr=[]\r\n\tcrr=list(map(int, input().rstrip().split()))\r\n\tb=crr[1]\r\n\ta=crr[0]\r\n\tbrr.append(b-a)\r\n\tbrr.extend(crr)\r\n\tarr.append(brr)\r\ns=\"\"\r\nfor i in range(n):\r\n\tif(i%2==0):\r\n\t\ts+='1'\r\n\telse:\r\n\t\ts+='0'\r\nprint(s)\r\n", "n,b = [int(i) for i in input().split()]\r\nfor i in range (b):\r\n a,c = [int(i) for i in input().split()]\r\ns = '01'*501\r\nprint(s[0:n])\r\n", "n,m=input().split()\r\nn=int(n)\r\nm=int(m)\r\nfor i in range(m):\r\n a,b=input().split()\r\nfor i in range(n):\r\n print(i%2,end='')", "n, m = map(int, input().split())\r\nwhile m:\r\n l, r = map(int, input().split())\r\n m -= 1\r\ns = \"01\"*(n//2)\r\nif n % 2 == 0:\r\n print(s)\r\nelse:\r\n print(s + \"0\")\r\n", "lista = list(map(int, input().split()))\r\n\t\r\nn = lista[0]\r\nm = lista[1]\r\nA = \"\"\r\n\r\nfor i in range(m):\r\n\tlistaa = list(map(int, input().split()))\r\n\r\nfor k in range(n):\r\n\tif k%2 == 0:\r\n\t\tA = A + \"0\"\r\n\telse:\r\n\t\tA = A + \"1\"\r\n\r\nprint(A)", "n,k=map(int,input().split())\r\na=[0]*k\r\nb=[0]*k\r\nfor i in range (k):\r\n x,y=map(int,input().split())\r\n a[i]=x\r\n b[i]=y\r\n\r\nfor i in range (n//2):\r\n print(\"0\",end=\"\")\r\n print(\"1\",end=\"\")\r\n\r\nif(n%2==1):\r\n print(\"0\")\r\n\r\nelse:\r\n print()\r\n\r\n \r\n \r\n", "import sys\r\n\r\nif __name__ == \"__main__\":\r\n n, m = (int(x) for x in sys.stdin.readline().split())\r\n \r\n for i in range(0, n):\r\n sys.stdout.write(str(i & 1))\r\n", "# Link: http://codeforces.com/contest/1004/problem/B\n# py3\n\nfrom __future__ import print_function\nimport sys\nimport math\nimport os.path\nimport random\nfrom copy import deepcopy\nfrom functools import reduce\n\n\nfrom collections import Counter, ChainMap, defaultdict\nfrom itertools import cycle, chain\nfrom queue import Queue, PriorityQueue\nfrom heapq import heappush, heappop, heappushpop, heapify, heapreplace, nlargest, nsmallest\nimport bisect\n\nfrom statistics import mean, mode, median, median_low, median_high\n\n\n# CONFIG\nsys.setrecursionlimit(10**9)\n\n# LOG \ndef log(*args, **kwargs):\n print(*args, file=sys.stderr, **kwargs)\n\n\n# INPUT\ndef ni():\n return map(int, input().split())\n\n\ndef nio(offset):\n return map(lambda x: int(x) + offset, input().split())\n\n\ndef nia():\n return list(map(int, input().split()))\n\n\n# CONVERT\ndef toString(aList, sep=\" \"):\n return sep.join(str(x) for x in aList)\n\n\ndef toMapInvertIndex(aList):\n return {k: v for v, k in enumerate(aList)}\n\n\n# SORT\ndef sortId(arr):\n return sorted(range(arr), key=lambda k: arr[k])\n\n\n# MAIN\n\nn, m = ni()\n\nprint((\"01\"*((n+1)//2))[:n])", "import sys\r\nimport os\r\n\r\ndef sonyaAndExhibition(n, m, visitors):\r\n return ('01' * n)[:n]\r\n\r\ndef main():\r\n n, m = (int(x) for x in input().split())\r\n visitors = []\r\n for i in range(m):\r\n l, r = (int(x) for x in input().split())\r\n visitors.append((l, r))\r\n print(sonyaAndExhibition(n, m, visitors))\r\n\r\nif __name__ == '__main__':\r\n main()", "n, m = input().split(\" \")\r\nn = int(n)\r\nm = int(m)\r\nfor i in range(m):\r\n\tinp = input()\r\n\r\nif n%2==0:\r\n\tans = \"01\"*(n//2)\r\nelse:\r\n\tans = \"01\"*((n-1)//2)+\"0\"\r\n\r\nprint(ans)", "[n,v] = [int(i) for i in input().split()]\r\n\r\n# vis_pos = []\r\n# for i in range(v):\r\n# in_tup = tuple(int(j) for j in input().split())\r\n# vis_pos.append([in_tup,len(in_tup)])\r\n\r\n# a.sort(vis_pos,key = lambda x : x[1], reverse=1)\r\n\r\n# flo_pos = [-1]*n\r\n\r\n# for p in a:\r\n# str_len = p[1]\r\n# flo_pos[p[0][0]:p[0][1]+1] = \r\n\r\nout_str = \"10\"*(n//2) + \"1\"*(n - 2*(n//2))\r\n\r\nprint(out_str)\r\n\r\n\r\n", "a=int(input().split()[0])\r\nprint(\"10\"*(a//2)+'1'*(a%2))", "if __name__==\"__main__\":\r\n n,m=map(int,input().split())\r\n s=\"\"\r\n for i in range(n):\r\n if i%2==0:\r\n s+='0'\r\n else:\r\n s+='1'\r\n print(s)", "n, m = [int(x) for x in input().split()]\nprint(''.join(str(i % 2) for i in range(n)))\n", "n,m=map(int,input().split())\r\nl=list()\r\nr=list()\r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\nfor i in range(n):\r\n if(i%2==0):\r\n print(0,end='')\r\n else:\r\n print(1,end='')\r\n", "# ANSHUL GAUTAM\n# IIIT-D\n\nfrom math import *\nfrom string import *\nfrom itertools import *\n\nN,M = map(int, input().split())\nfor m in range(M):\n\tl,r = map(int, input().split())\n\nif(N&1 == 0):\n\tx = \"10\"*(N//2)\n\tprint(x)\nelse:\n\tx = \"10\"*(N//2)\n\tx += \"1\"\n\tprint(x)", "n, m = map(int, input().split())\r\nu = []\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n u.append((a, b))\r\nans = ''\r\nfor i in range(n):\r\n k = i % 2\r\n ans += str(k)\r\nprint(ans)\r\n", "[n, m] = [int(x) for x in input().split()]\r\ns = \"01\"*(n//2)\r\nif n&1:\r\n s += \"0\"\r\nfor che in range(m):\r\n [l, r] = [int(x) for x in input().split()]\r\nprint(s)", "# Link: http://codeforces.com/contest/1004/problem/B\n# py3\n\n# INPUT\ndef ni():\n return map(int, input().split())\n\n\n\n\n# CONVERT\ndef toString(aList, sep=\" \"):\n return sep.join(str(x) for x in aList)\n\n\ndef toMapInvertIndex(aList):\n return {k: v for v, k in enumerate(aList)}\n\n\n# SORT\ndef sortId(arr):\n return sorted(range(arr), key=lambda k: arr[k])\n\n\n# MAIN\n\nn, m = ni()\n\nprint((\"01\"*((n+1)//2))[:n])", "n = int(input().split()[0])\r\nprint(\"01\"*(n>>1) + \"0\"*(n&1))", "import functools\r\nimport time\r\n\r\ndef timer(func):\r\n @functools.wraps(func)\r\n def wrapper(*args, **kwargs):\r\n stime = time.perf_counter()\r\n res = func(*args, **kwargs)\r\n elapsed = time.perf_counter() - stime\r\n print(f\"{func.__name__} in {elapsed:.4f} secs\")\r\n return res\r\n return wrapper\r\n\r\nclass solver:\r\n def __init__(self):\r\n n, m = map(int, input().strip().split())\r\n segs = list()\r\n for i in range(m):\r\n segs.append(list(map(int, input().strip().split())))\r\n \r\n def calc(s, segs):\r\n res = 0\r\n for x in segs:\r\n ones = sum(s[x[0]:x[1] + 1])\r\n res += ones * (x[1] - x[0] + 1 - ones)\r\n return res\r\n\r\n s1 = [0 for i in range(n)]\r\n s2 = [1 for i in range(n)]\r\n for i in range(n):\r\n if i % 2 == 0:\r\n s1[i] = 1\r\n s2[i] = 0\r\n\r\n ans = s1 if calc(s1, segs) > calc(s2, segs) else s2\r\n print(''.join(map(str, ans)))\r\n \r\nsolver()", "n, m = [int(el) for el in input().split()]\r\nfor i in range(m):\r\n l, r = [int(el) for el in input().split()]\r\ns = '01' * (n//2)\r\nif n % 2 == 1:\r\n s += '0'\r\nprint(s)\r\n", "n , m = [int(c) for c in input().split()]\r\ns1, s2 = [], []\r\n\r\nfor i in range(n):\r\n s2.append(i&1)\r\n s1.append((i+1)&1)\r\nb1 = 0\r\nb2 = 0\r\nfor i in range(m):\r\n l, r = [int(c) for c in input().split()]\r\n b1 += s1[l-1:r].count(1)*s1[l-1:r].count(0)\r\n b2 += s2[l-1:r].count(1)*s2[l-1:r].count(0)\r\nif b1>b2:\r\n print(*s1,sep='')\r\nelse:\r\n print(*s2,sep='')\r\n\r\n \r\n", "n, m = map(int, input().split())\r\n\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n\r\nprint(\"\".join(str(1 - (idx % 2)) for idx in range(n)))", "n,m=map(int,input().split())\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\narr=[]\r\nfor i in range(n):\r\n if i%2==0:\r\n arr.append(0)\r\n else:\r\n arr.append(1)\r\nprint(*arr,sep=\"\")", "def solve(n, m, lr):\r\n s = ''\r\n for i in range(n):\r\n if i % 2 == 0:\r\n s += '0'\r\n else:\r\n s += '1'\r\n return s \r\n\r\n\r\nnm = [int(x) for x in input().split()]\r\nlr = []\r\nfor _ in range(nm[1]):\r\n l = [int(x) for x in input().split()]\r\n lr.append(l)\r\nprint(solve(nm[0], nm[1], lr))", "n,m=map(int,input().split())\r\nli=['0']*(n+1)\r\nmc=(n//2)\r\nfor i in range(m):\r\n l,r=map(int,input().split())\r\nfor i in range(2,n+1,2):\r\n li[i]='1'\r\ns=''.join(li)\r\nprint(s[1:])\r\n \r\n \r\n ", "'''\r\n Author : thekushalghosh\r\n Team : CodeDiggers\r\n'''\r\nn,m = [int(x) for x in input().split()]\r\nfor i in range(m): input()\r\nprint(\"01\" * (int(n/2)) + (\"0\" if (n % 2 != 0) else \"\"))", "n,m=map(int,input().split())\r\nfor i in range(n):print(i%2,end='')", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\nprint(('01'*n)[:n])\r\n", "n,m=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n if i%2==0:\r\n a.append('1')\r\n else:\r\n a.append('0')\r\nprint(''.join(a))", "n, m = (int(x) for x in input().split())\r\nfor i in range(m):\r\n l, r = (int(x) for x in input().split())\r\n\r\nflag = True\r\nfor i in range(n):\r\n if flag:\r\n print(0,end=\"\")\r\n flag = False\r\n else:\r\n print(1,end=\"\")\r\n flag = True", "flowers, people = list(map(int, input().split(\" \")))\r\nfor _ in range(people): input()\r\nprint(\"10\" * int(flowers / 2) + \"1\" * (flowers % 2))", "def I(): return(list(map(int,input().split())))\nn,m=I()\nfor i in range(m):\n\tinput()\ns=\"\"\nfor i in range(n):s+=\"1\" if i%2 else \"0\"\nprint(s)", "# Link: http://codeforces.com/contest/1004/problem/B\n# py3\n\nfrom __future__ import print_function\nimport sys\nimport math\nimport os.path\nimport random\nfrom copy import deepcopy\nfrom functools import reduce\n\n\nfrom collections import Counter, ChainMap, defaultdict\nfrom itertools import cycle, chain\nfrom queue import Queue, PriorityQueue\nfrom heapq import heappush, heappop, heappushpop, heapify, heapreplace, nlargest, nsmallest\nimport bisect\n\nfrom statistics import mean, mode, median, median_low, median_high\n\n\n# CONFIG\nsys.setrecursionlimit(10**9)\n\n# LOG \ndef log(*args, **kwargs):\n print(*args, file=sys.stderr, **kwargs)\n\n\n# INPUT\ndef ni():\n return map(int, input().split())\n\n\ndef nio(offset):\n return map(lambda x: int(x) + offset, input().split())\n\n\ndef nia():\n return list(map(int, input().split()))\n\n\n# CONVERT\ndef toString(aList, sep=\" \"):\n return sep.join(str(x) for x in aList)\n\n\ndef toMapInvertIndex(aList):\n return {k: v for v, k in enumerate(aList)}\n\n\n# SORT\ndef sortId(arr):\n return sorted(range(arr), key=lambda k: arr[k])\n\n\n# MAIN\n\nn, m = ni()\n# l = [0] * m\n# r = [0] * m\n\n# for i in range(m):\n# l[i], r[i] = ni()\n\n# log(l,r)\n\ns1 = [i % 2 for i in range(n)]\n# s2 = [1 - (i % 2) for i in range(n)]\n\n# c10 = [0] * n\n# c11 = [0] * n\n# c20 = [0] * n\n# c21 = [0] * n\n\n# log(s1,s2)\n\n# c10[0] = 1\n# c21[0] = 1\n\n# for i in range(1, n):\n# if s1[i] == 0:\n# c1\n\n# r1 = r2 = -1\n\nprint(toString(s1,\"\"))", "import sys,math\r\nn,m=map(int,sys.stdin.readline().split())\r\nfor i in range(m):\r\n x,y=map(int,sys.stdin.readline().split())\r\nfor i in range(n):\r\n if i%2==0:\r\n print(\"1\",end=\"\")\r\n else:\r\n print(\"0\",end=\"\")\r\n \r\n", "def main():\n n, m = map(int, input().split())\n print(''.join('01'[i & 1] for i in range(n)))\n\n\nif __name__ == '__main__':\n main()\n", "from sys import stdin\r\n\r\nall_in = stdin.read().splitlines()\r\n\r\nn, m = map(int, all_in[0].split())\r\npos = [tuple(map(int, el.split())) for el in all_in[1:]]\r\n\r\nans = list()\r\nfor i in range(1, n + 1):\r\n ans.append(i % 2)\r\n\r\nprint(''.join(map(str, ans)))\r\n", "n,m=map(int,input().split())\r\nfor _ in range(m):\r\n\ta=input()\r\ns=\"\"\r\nfor i in range(n//2):\r\n\ts+=\"10\"\r\nif n%2==1:\r\n\ts+=\"1\"\r\nelse:\r\n\tpass\r\nprint(s)", "from collections import Counter,defaultdict,deque\r\n#alph = 'abcdefghijklmnopqrstuvwxyz'\r\n#from math import factorial as fact\r\n#import math\r\n\r\n#tt = 1#int(input())\r\n#total=0\r\n#n = int(input())\r\n#n,m,k = [int(x) for x in input().split()]\r\n#n = int(input())\r\n\r\n\r\n \r\nn,m = [int(x) for x in input().split()]\r\nfor i in range(m):\r\n a = input()\r\nprint('01'*(n//2)+'0'*(n%2==1))\r\n", "read = lambda: map(int, input().split())\nn, m = read()\nfor i in range(m): read()\nprint( (n//2)*\"01\" + ((n%2)*'0'))\n", "n,m=map(int,input().split())\r\nfor hmm in range(m):\r\n hmmm=input()\r\nprint('10'*(n//2) + '1'*(n%2))", "x,y = map(int,input().split())\r\n\r\nfor i in range(x):\r\n print(i%2,end='')", "#!/usr/bin/env python3\n\nn, m = [int(i) for i in input().split()]\nfor i in range(m):\n a, b = map(int, input().split())\nflag = 1\nfor i in range(n):\n if flag == 1:\n print(1, end = '')\n flag = 0\n else:\n print(0, end = '')\n flag = 1\n\n", "# @Chukamin ZZU_TRAIN\n\ndef main():\n n, m = map(int, input().split())\n if n & 1 == 0:\n print('01' * (n >> 1))\n else:\n print('01' * (n >> 1) + '0')\n\nif __name__ == '__main__':\n main()\n\t \t\t\t\t\t\t \t\t\t \t\t\t\t\t\t \t\t\t", "n,m = map(int, input().split())\r\nfor i in range(m):\r\n u,v = map(int, input().split())\r\n a = []\r\nfor i in range(n):\r\n if i% 2 == 0:\r\n a.append('0')\r\n else:\r\n a.append('1')\r\nfor i in a:\r\n print(i,end = '')", "n,m=input().split()\r\nn=int(n)\r\nm=int(m)\r\nfor xx in range(m):\r\n l,r=input().split()\r\nans=''\r\nflag=0\r\nfor i in range(n):\r\n if flag==0:\r\n ans+='1'\r\n flag=1\r\n else:\r\n ans+='0'\r\n flag=0\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n\r\n", "m,n=map(int,input().split())\r\nfor i in range(n):\r\n a=input().split()\r\nz='10'*m\r\nprint(z[:m])", "a=input().split()\r\nn=int(a[0])\r\nm=int(a[1])\r\nflag = False\r\nfor i in range(m):\r\n b=input()\r\nfor i in range(n):\r\n if flag:\r\n print(1,end='')\r\n flag=False\r\n else:\r\n print(0,end='')\r\n flag=True\r\n\r\n \r\n", "n, m = map(int, input().split())\r\nl = [list(map(int, input().split())) for i in range(m)]\r\nans = '01' * (n // 2) + '0' * (n % 2)\r\nprint(ans)", "import math\r\nfrom decimal import Decimal\r\nimport heapq\r\ndef na():\r\n\tn = int(input())\r\n\tb = [int(x) for x in input().split()]\r\n\treturn n,b\r\n \r\n \r\ndef nab():\r\n\tn = int(input())\r\n\tb = [int(x) for x in input().split()]\r\n\tc = [int(x) for x in input().split()]\r\n\treturn n,b,c\r\n \r\n \r\ndef dv():\r\n\tn, m = map(int, input().split())\r\n\treturn n,m\r\n \r\n \r\ndef dva():\r\n\tn, m = map(int, input().split())\r\n\ta = [int(x) for x in input().split()]\r\n\tb = [int(x) for x in input().split()]\r\n\treturn n,m,b\r\n \r\n \r\ndef eratosthenes(n): \r\n\tsieve = list(range(n + 1))\r\n\tfor i in sieve:\r\n\t\tif i > 1:\r\n\t\t\tfor j in range(i + i, len(sieve), i):\r\n\t\t\t\tsieve[j] = 0\r\n\treturn sorted(set(sieve))\r\n \r\n \r\n \r\ndef nm():\r\n\tn = int(input())\r\n\tb = [int(x) for x in input().split()]\r\n\tm = int(input())\r\n\tc = [int(x) for x in input().split()]\r\n\treturn n,b,m,c\r\n \r\n \r\ndef dvs():\r\n\tn = int(input())\r\n\tm = int(input())\r\n\treturn n, m \r\n\r\n\r\nn, m = map(int, input().split())\r\nfor i in range(m):\r\n\ts = input()\r\na = [0, 1]\r\nfor i in range(n):\r\n\tprint(a[i % 2], end = '')\r\n", "def main():\n [n,m] = list(map(int, input().split(\" \")))\n map(input, range(m))\n output = \"0\"\n while len(output)<n:\n if output.endswith(\"0\"):\n output += \"1\"\n elif output.endswith(\"1\"):\n output += \"0\"\n print(output)\n\nmain()\n\n", "n,m = map(int, input().split())\r\nfor i in range(m):\r\n s = input()\r\nans = []\r\nfor i in range(n):\r\n if i % 2 == 0:\r\n ans.append('0')\r\n else:\r\n ans.append('1')\r\nprint(\"\".join(ans))", "n,m = map(int, input().split())\r\nwhile(m>0):\r\n i,j = map(int, input().split())\r\n m=m-1\r\ns=\"\"\r\nif(n%2==0):\r\n n=n/2\r\n while(n>0):\r\n s=s+\"10\"\r\n n=n-1\r\nelse:\r\n n=(n/2)-1\r\n while(n>0):\r\n s=s+\"10\"\r\n n=n-1\r\n s=s+\"1\"\r\nprint(s)", "n, m = (int(x) for x in input().split())\r\nfor i in range(m):\r\n l, r = (int(x) for x in input().split())\r\n\r\nprint(''.join(['1' if i % 2 == 0 else '0' for i in range(n)]))\r\n", "td=list(map(int,input().split()))\r\nt=td[0]\r\nd=td[1]\r\nl=[]\r\nfor i in range(1,t+1):\r\n if(i%2==0):\r\n l.append(\"1\")\r\n else:\r\n l.append(\"0\")\r\nfor i in l:\r\n print(i,end='')", "n, m = map(int, input().split())\r\nfor i in range(m):\r\n input()\r\n\r\nif n % 2 == 0:\r\n print('01' * (n//2))\r\nelse:\r\n print('01'*(n//2) + str(0))", "print((lambda n: ('01'*n)[:n])(int(input().split()[0])))", "import sys, heapq\r\n\r\nn, m = map(int, sys.stdin.readline().split())\r\nfor _ in range(m):\r\n a, b = map(int, sys.stdin.readline().split())\r\nans = [0] * n\r\nfor i in range(1, n, 2):\r\n ans[i] = 1\r\nprint(''.join(map(str, ans)))\r\n", "n, m = list(map(int, input().split()))\nb = True\nfor i in range(n):\n\tif b == True:\n\t\tprint(1, end = '')\n\t\tb = False\n\telse:\n\t\tprint(0, end = '')\n\t\tb = True\n", "def solve():\r\n n, m = map(int, input().split())\r\n fb = [\"0\"]*n\r\n for i in range(m):\r\n l, r = map(int, input().split())\r\n l -= 1\r\n r -= 1\r\n temp = r - l + 1\r\n roses = temp // 2\r\n # x = fb[l: r+1]\r\n # x = fb[l: r+1].count(1)\r\n # print(\"original x\", x)\r\n # print(\"original rose\", roses)\r\n # roses -= x\r\n # print(\"new r\", roses)\r\n while l < r+1 and roses > 0:\r\n if l % 2 == 0:\r\n fb[l] = \"1\"\r\n l += 2\r\n roses -= 1\r\n else:\r\n l += 1\r\n # print(\"temp fb is\", fb)\r\n return \"\".join(fb)\r\n\r\n\r\nt = 1\r\nwhile t != 0:\r\n res = solve()\r\n print(res)\r\n t -= 1\r\n", "n, m = list(map(int,input().split()))\r\nprint(('01'*(n+1//2))[:n])", "n1,m1=input().split(\" \")\r\nn=int(n1)\r\nm=int(m1)\r\nl=[0]*m\r\nr=[0]*m\r\nfor i in range(m):\r\n l[i],r[i]=input().split(\" \")\r\nfor i in range(n):\r\n if i%2==0:\r\n print(0,end='')\r\n else :\r\n print(1,end='')", "n, p = map(int, input().split())\nfor i in range(p):\n a, b = map(int, input().split())\ns=''\nfor i in range(n):\n if i%2 == 0:\n s+= '0'\n else:\n s+='1'\nprint(s)\n", "n, m = map(int, input().strip().split())\nfor i in range(m):\n _, _ = map(int, input().strip().split())\nfor i in range(n):\n if i % 2 == 0:\n print(0, end='')\n else:\n print(1, end='')", "n,m=map(int,input().split())\r\nfor i in range(m):\r\n\ta,b=map(int,input().split())\r\nfor i in range(n):\r\n\tprint(i&1,end=\"\")\r\nprint()", "n, m = input().split()\r\nn, m = int(n), int(m)\r\n[input() for i in range(m)]\r\nprint('01'*(n//2) + ('0' if n%2 == 1 else ''))\r\n", "print(''.join(str(i % 2) for i in range(int(input().split()[0]))))", "n,m = map(int,input().split())\r\nfor i in range(m):input()\r\nprint('10'*(n//2)+'1'*(n%2))\r\n", "from math import *\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef main():\r\n\r\n\r\n\r\n\tn, m = [int(x) for x in input().split(' ')]\r\n\r\n\tfor i in range(n):\r\n\t\tprint(1 if i%2 == 0 else 0, end='')\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()\r\n", "n,m=map(int,input().split())\r\nl=[]\r\nfor i in range(m):\r\n a,b=map(int,input().split())\r\n l+=[(a,b)]\r\ns=\"\"\r\nfor i in range(n):\r\n if i%2==0:\r\n s+=\"1\"\r\n else:\r\n s+=\"0\"\r\nprint(s)", "n, m = list(map(int, input().split()))\npairs = []\nfor i in range(m):\n l, r = list(map(int, input().split()))\n pairs.append((l, r))\nr = True\nfor i in range(n):\n print(\"1\" if r else \"0\", end='')\n r = not r\n", "if __name__ == '__main__':\n n, m = [int(i) for i in input().strip().split()]\n flowers = [0] * n\n visitors = []\n for _ in range(m):\n l, r = [int(i) for i in input().strip().split()]\n visitors.append((l - 1, r - 1))\n for i in range(1, n, 2):\n flowers[i] = 1\n print(''.join(map(str, flowers)))\n", "n,k = map(int,input().split())\r\nfor i in range(k):\r\n q = input()\r\n \r\nprint(''.join(str(i%2) for i in range(n)))", "n, m = map(int, input().split())\r\ns = '10' * (n // 2)\r\nif n & 1:\r\n s += '1'\r\nprint(s)", "n,m = map(int,input().split())\r\nfor i in range(m):\r\n input()\r\nprint(n // 2 * \"01\" + \"0\" * (n % 2))", "n,m = map(int, input().split())\r\nfor i in range(m):\r\n input()\r\nstr = \"\"\r\nfor i in range(n):\r\n if i%2:\r\n str+=\"1\"\r\n else:\r\n str+=\"0\"\r\nprint(str)\r\n", "n, m = map(int, input().split())\r\nfor i in range(m):\r\n q, w = map(int, input().split())\r\nq = 0\r\nans = ''\r\nfor i in range(n):\r\n ans += str(q)\r\n q = (q + 1) % 2\r\nprint(ans)\r\n", "n,m = map(int,input().split(' '))\r\nst=''\r\nfor i in range(n):\r\n\tif i%2==0:\r\n\t\tst+='1'\r\n\telse:\r\n\t\tst+='0'\r\nprint(st)", "n, m = map(int, input().split())\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\nstring = []\r\nfor i in range(n):\r\n string.append(str(i % 2))\r\nprint(''.join(string))\r\n", "print(*[x%2 for x in range(int(input().split()[0]))],sep='')\n", "n, _ = map(int, input().split())\r\n\r\nfor i in range(n):\r\n print('10'[i % 2], end='')\r\n", "from sys import stdin,stdout\r\nn, m = map(int,stdin.readline().split())\r\nans = [i%2 for i in range(n)]\r\nfor i in range(n):\r\n print(ans[i],end='')", "import sys\r\n\r\nn = (input().split())\r\nnumber_of_flowers = int(n[0])\r\nvisitors = int(n[1])\r\n\r\nfor i in range(visitors):\r\n coords = input().split()\r\n left = int(coords[0])\r\n right = int(coords[1])\r\n\r\nfor j in range(number_of_flowers):\r\n print(j%2, end='')", "n,m = map(int,input().split())\r\nfor i in range(0,n):\r\n if i % 2 > 0:\r\n print(1,end = '')\r\n else :\r\n print(0,end = '')\r\n \r\n", "arr = list(map(int, input().split()))\r\nn=arr[0]\r\nm=arr[1]\r\nfor i in range(m):\r\n s=input()\r\nc=1\r\ns=0\r\nfor i in range(n):\r\n if(i%2!=0):\r\n s+=c\r\n c*=10\r\nif(n%2!=0):\r\n s*=10\r\n s+=1\r\nprint(s)", "n,m = map(int, input().split())\nasn = list()\nfor i in range(n):\n asn.append('0' if i%2==0 else '1')\nprint(str(''.join(asn)))", "n,m=map(int,input().split())\r\ns=\"01\"*n\r\nprint(s[:n])\r\n", "n,m=list(map(int,input().split()))\r\na=1\r\nfor i in range(n):\r\n\tif a==1:\r\n\t\tprint('0',end='')\r\n\telse:\r\n\t\tprint('1',end='')\r\n\ta*=-1", "n , m = map(int,input().split())\r\nls = list()\r\nfor i in range(m):\r\n p = list(map(int,input().split()))\r\n ls.append(p)\r\nfor i in range(n):\r\n if(i%2):print(0,end=\"\")\r\n else:print(1,end=\"\")\r\n", "def i_ints():\r\n return map(int, input().split())\r\n\r\n\r\nn, m = i_ints()\r\nprint((\"01\"*n)[:n])\r\n", "n, m = map(int, input().split())\nque = []\nfor _ in range(m):\n\tque.append(list(map(int, input().split())))\nk = ''\nc = 0\nfor i in range(n):\n\tc ^= 1\n\tk += str(c)\nprint(k)\n", "n,m = [int(x) for x in input().split()]\r\nfor _ in range(m):\r\n x = input()\r\n\r\nif n % 2 == 0:\r\n print('01'*(n//2))\r\nelse:\r\n print('01'*(n//2)+'0')", "n,q=map(int,input().split())\r\ns='10'*n\r\nprint(s[:n])", "# your code goes here\r\na = input()\r\na = a.split(' ')\r\n\r\nfor i in range(int(a[1])):\r\n\ti = input()\r\n\r\nans = ''\r\n\r\nfor k in range(int(a[0])):\r\n\tif k % 2 == 0:\r\n\t\tans += '0'\r\n\telse:\r\n\t\tans += '1'\r\nprint(ans)", "n, m = (int(x) for x in input().split())\nfor a in range(m):\n input()\nans = '01' * n\nans = ans[:n]\nprint(ans)\n", "n,m=map(int,input().split())\r\ns=\"\"\r\nfor i in range(m):\r\n x,y=map(int,input().split()) \r\nn1=n//2\r\ns=\"10\"*n1\r\nif n%2!=0:\r\n s+=\"1\"\r\nprint(s)\r\n", "import sys, threading, bisect, math, copy, itertools\r\n\r\nfrom heapq import heappush, heappop, heapify\r\nfrom functools import cmp_to_key as ctk, lru_cache\r\nfrom collections import defaultdict, deque, Counter\r\n\r\nreadline = sys.stdin.readline\r\nread = lambda : list(map(int, readline().split()))\r\nreadstr = lambda : readline().rstrip()\r\n\r\n# dfv 只能为基本数据类型\r\nalloc = lambda dfv, *s: len(s) != 1 and [alloc(dfv, *s[1:]) for _ in range(int(s[0]))] or [dfv] * int(s[0])\r\nshow = lambda arr: print(\" \".join(map(str, arr)))\r\n\r\n\r\ndef main():\r\n INF = float('inf')\r\n MOD = 10 ** 9 + 7\r\n # dfd = defaultdict(int)\r\n # dq = deque()\r\n N = 10 ** 5 + 10\r\n n, m = read()\r\n for _ in range(m):\r\n a, b = read()\r\n res = '01' * n\r\n print(res[:n])\r\n\r\n\r\n\r\nmain()\r\n\r\n# threading.stack_size((10 ** 8))\r\n# t = threading.Thread(target=main)\r\n# t.start()\r\n# t.join()", "n,m=map(int,input().split())\r\nfor i in range(m):\r\n l,r=map(int,input().split())\r\nif n%2==0:\r\n print('10'*(n//2))\r\nelse:\r\n print('10'*((n-1)//2)+'1')", "n,v = map(int, input().split())\nvisitors = []\nfor i in range(v):\n l,r = map(int, input().split())\n visitors.append([r-l+1,l,r])\n\ndist = []\n\nfor i in range(n):\n if i%2:\n dist.append(\"0\")\n else:\n dist.append(\"1\")\n\nprint(\"\".join(dist))\n", "n, m = map(int, input().split())\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n\r\nans = [int(i % 2 == 0) for i in range(n)]\r\nprint(\"\".join(map(str, ans)))", "n,m=map(int,input().split())\r\ns=\"\"\r\nfor i in range (m):\r\n l1=list(map(int,input().split()))\r\nfor i in range(n):\r\n if(i%2==0):\r\n s+=\"0\"\r\n else:\r\n s+=\"1\"\r\nprint(s)", "n,d=map(int,input().split())\r\nfor i in range(d):\r\n a,b=map(int,input().split())\r\nprint('10'*(n//2)+'1'*(n%2))\r\n", "n,m = map(int,input().split())\r\nfor _ in range(m):\r\n l,r = map(int,input().split())\r\ns =''\r\nif(n%2):\r\n s+='01'*(n//2)+'0'\r\nelse:\r\n s+='01'*(n//2)\r\nprint(s)\r\n", "n, m = map(int, input().split())\nresult = ''\nfor i in range(n):\n if i % 2 == 0:\n result += '0'\n else:\n result += '1'\n \nprint(result)", "n,m=map(int,input().split())\r\narr=[\"01\" for _ in range(n//2)]\r\nif n%2==1:\r\n arr.append(\"0\")\r\nprint(\"\".join(arr))\r\n", "n, m = map(int, input().split())\nfor i in range(0, n):\n if i % 2 > 0:\n print('1', end = '')\n else:\n print('0', end = '')", "n , m = map(int, input().split())\r\nprint(\"10\" * (n // 2) + \"1\" * (n % 2))", "print(('01'*500)[:int(input().split()[0])])\r\n", "n, m = map(int, input().split())\r\nfor _ in range(m):\r\n input()\r\nif n == 1:\r\n print('0')\r\nelif n % 2 == 0:\r\n print('01' * (n // 2))\r\nelif n % 2 == 1:\r\n print('01' * (n // 2) + '0')\r\n", "from collections import defaultdict,Counter,deque\nimport math\nimport bisect\nfrom itertools import accumulate, product\nfrom math import ceil, log,gcd\nfrom functools import lru_cache\nfrom sys import stdin, stdout\nimport time\nimport atexit\nimport io\nimport sys\nimport string\nimport heapq\nimport copy\nimport random\nimport bisect\n \ndef primes(n):\n if n<=2:\n return []\n sieve=[True]*(n+1)\n for x in range(3,int(n**0.5)+1,2):\n for y in range(3,(n//x)+1,2):\n sieve[(x*y)]=False\n \n return [2]+[i for i in range(3,n,2) if sieve[i]]\n \n \n \ndef write(*args, **kwargs):\n sep = kwargs.get('sep', ' ')\n end = kwargs.get('end', '\\n')\n stdout.write(sep.join(str(a) for a in args) + end)\n \ndef read():\n return stdin.readline().rstrip()\n \n \ndef primes_rwh(n):\n \"\"\" Returns a list of primes < n \"\"\"\n sieve = [True] * n\n for i in range(3,int(n**0.5)+1,2):\n if sieve[i]:\n sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)\n return [2] + [i for i in range(3,n,2) if sieve[i]]\n \n \ndef prime_factors(n):\n i = 2\n factors = []\n d = defaultdict(lambda:0)\n for i in primes_rwh(int(n**0.5+1)):\n while n % i == 0:\n n //= i\n factors.append(i)\n d[i]+=1\n if n > 1:\n factors.append(n)\n d[n]+=1\n return factors,d\n \n \n \ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n \ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n \ndef lcm(x, y):\n lcm = (x*y)//math.gcd(x,y)\n return lcm \n \n \n# def bitsoncount(i):\n# assert 0 <= i < 0x100000000\n# i = i - ((i >> 1) & 0x55555555)\n# i = (i & 0x33333333) + ((i >> 2) & 0x33333333)\n# return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 \ndef bitsoncount(x): \n b=0\n while(x > 0):\n x &= x - 1 \n b+=1\n return b\ndef prime_factors_s(n):\n i = 2\n factors =set()\n d = defaultdict(lambda:0)\n for i in primes_rwh(int(n**0.5+1)):\n while n % i == 0:\n n //= i\n factors.add(i)\n if n > 1:\n factors.add(n)\n return factors\n \nfrom bisect import bisect_right \n \n \ndef pollard_rho(n):\n \"\"\"returns a random factor of n\"\"\"\n if n & 1 == 0:\n return 2\n if n % 3 == 0:\n return 3\n \n s = ((n - 1) & (1 - n)).bit_length() - 1\n d = n >> s\n for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:\n p = pow(a, d, n)\n if p == 1 or p == n - 1 or a % n == 0:\n continue\n for _ in range(s):\n prev = p\n p = (p * p) % n\n if p == 1:\n return math.gcd(prev - 1, n)\n if p == n - 1:\n break\n else:\n for i in range(2, n):\n x, y = i, (i * i + 1) % n\n f = math.gcd(abs(x - y), n)\n while f == 1:\n x, y = (x * x + 1) % n, (y * y + 1) % n\n y = (y * y + 1) % n\n f = math.gcd(abs(x - y), n)\n if f != n:\n return f\n return n \n \ndef memodict(f):\n \"\"\"memoization decorator for a function taking a single argument\"\"\"\n class memodict(dict):\n def __missing__(self, key):\n ret = self[key] = f(key)\n return ret\n \n return memodict().__getitem__\n \n@memodict\ndef prime_factors_r(n):\n \"\"\"returns a Counter of the prime factorization of n\"\"\"\n if n <= 1:\n return Counter()\n f = pollard_rho(n)\n return Counter([n]) if f == n else prime_factors_r(f) + prime_factors_r(n // f)\n \ndef multiply(a, b):\n \n # Creating an auxiliary matrix\n # to store elements of the\n # multiplication matrix\n mul = [[0 for x in range(2)]\n for y in range(2)];\n for i in range(2):\n for j in range(2):\n for k in range(2):\n mul[i][j] += a[i][k] * b[k][j];\n mul[i][j] %= (10**9+7 ) \n return mul\n \n \ndef power(F, n):\n # print(n)\n # Multiply it with initial values i.e\n # with F(0) = 0, F(1) = 1, F(2) = 1\n if (n == 1):\n return F\n \n F_ = power(F, int(n // 2));\n \n F_ = multiply(F_, F_);\n \n if (n % 2 != 0):\n F_ = multiply(F_, F);\n \n # Multiply it with initial values i.e\n # with F(0) = 0, F(1) = 1, F(2) = 1\n return F_ ;\n \n \nfrom bisect import bisect_left as lower_bound\nfrom bisect import bisect_right as upper_bound\n \n \nclass FenwickTree:\n def __init__(self, x):\n bit = self.bit = list(x)\n size = self.size = len(bit)\n for i in range(size):\n j = i | (i + 1)\n if j < size:\n bit[j] += bit[i]\n \n def update(self, idx, x):\n \"\"\"updates bit[idx] += x\"\"\"\n while idx < self.size:\n self.bit[idx] += x\n idx |= idx + 1\n \n def __call__(self, end):\n \"\"\"calc sum(bit[:end])\"\"\"\n x = 0\n while end:\n x += self.bit[end - 1]\n end &= end - 1\n return x\n \n def find_kth(self, k):\n \"\"\"Find largest idx such that sum(bit[:idx]) <= k\"\"\"\n idx = -1\n for d in reversed(range(self.size.bit_length())):\n right_idx = idx + (1 << d)\n if right_idx < self.size and self.bit[right_idx] <= k:\n idx = right_idx\n k -= self.bit[idx]\n return idx + 1, k\n \n \nclass SortedList:\n block_size = 700\n \n def __init__(self, iterable=()):\n self.macro = []\n self.micros = [[]]\n self.micro_size = [0]\n self.fenwick = FenwickTree([0])\n self.size = 0\n for item in iterable:\n self.insert(item)\n \n def insert(self, x):\n i = lower_bound(self.macro, x)\n j = upper_bound(self.micros[i], x)\n self.micros[i].insert(j, x)\n self.size += 1\n self.micro_size[i] += 1\n self.fenwick.update(i, 1)\n if len(self.micros[i]) >= self.block_size:\n self.micros[i:i + 1] = self.micros[i][:self.block_size >> 1], self.micros[i][self.block_size >> 1:]\n self.micro_size[i:i + 1] = self.block_size >> 1, self.block_size >> 1\n self.fenwick = FenwickTree(self.micro_size)\n self.macro.insert(i, self.micros[i + 1][0])\n \n def pop(self, k=-1):\n i, j = self._find_kth(k)\n self.size -= 1\n self.micro_size[i] -= 1\n self.fenwick.update(i, -1)\n return self.micros[i].pop(j)\n \n def __getitem__(self, k):\n i, j = self._find_kth(k)\n return self.micros[i][j]\n \n def count(self, x):\n return self.upper_bound(x) - self.lower_bound(x)\n \n def __contains__(self, x):\n return self.count(x) > 0\n \n def lower_bound(self, x):\n i = lower_bound(self.macro, x)\n return self.fenwick(i) + lower_bound(self.micros[i], x)\n \n def upper_bound(self, x):\n i = upper_bound(self.macro, x)\n return self.fenwick(i) + upper_bound(self.micros[i], x)\n \n def _find_kth(self, k):\n return self.fenwick.find_kth(k + self.size if k < 0 else k)\n \n def __len__(self):\n return self.size\n \n def __iter__(self):\n return (x for micro in self.micros for x in micro)\n \n def __repr__(self):\n return str(list(self))\ndef calc_primes(n):\n return [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\n 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,\n 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,\n 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,\n 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,\n 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659,\n 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,\n 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,\n 947, 953, 967, 971, 977, 983, 991, 997]\np = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,\n 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,\n 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,\n 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,\n 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541,\n 547 ]\n \n@lru_cache(None)\ndef factorize(n):\n factorization = set()\n for d in p:\n if d * d > n:\n break\n while n % d == 0:\n factorization.add(d)\n n //= d\n if n > 1:\n factorization.add(n)\n return sorted(factorization)\n \n \n@lru_cache(None)\ndef factorize_full(n):\n factorization = set()\n for d in p:\n if d * d > n:\n break\n c = 1\n while n % d == 0:\n factorization.add(d**c)\n n //= d\n c+=1\n if n > 1:\n factorization.add(n)\n return sorted(factorization)\n \ndef z(s):\n n = len(s)\n ret = [0] * n\n l = 1\n ll = 0\n r = 0\n while l < len(s):\n # print(l,ll,r,ret)\n if l < r:\n ret[l] = min(ret[l-ll],r-l)\n \n i = ret[l]\n # print(l,s[l:],i) \n while l+i < len(s) and s[i] == s[l+i]:\n ret[l] +=1\n \n i +=1\n if ret[l] >0:\n if l+i-1 > r:\n ll = l\n r = max(r,l+i-1) \n l+=1\n return ret\n \n# def primes(n):\n# if n<=2:\n# return []\n# sieve=[set() for i in range(n+1)]\n# for x in p:\n# for y in range(1,(n//x)+1,1):\n# sieve[(x*y)].add(x)\n# # sieve[(x*y)].add(n//x)\n# return [*map(list,sieve)]\n \ndef powm(x, n, m):\n if (n ==0):\n return 1\n elif (n==1):\n return x%m\n \n t = powm(x,n//2,m)\n t = t * t\n \n if (n%2==1):\n t *= x\n \n t%=m\n if (t <0):\n t +=m\n return t\n \n \n \ndef z(s):\n n = len(s)\n ret = [0] * n\n l = 1\n ll = 0\n r = 0\n while l < len(s):\n # print(l,ll,r,ret)\n if l < r:\n ret[l] = min(ret[l-ll],r-l)\n \n i = ret[l]\n # print(l,s[l:],i) \n while l+i < len(s) and s[i] == s[l+i]:\n ret[l] +=1\n \n i +=1\n if ret[l] >0:\n if l+i-1 > r:\n ll = l\n r = max(r,l+i-1) \n l+=1\n return ret\n \nimport random as rd\nclass SET():\n def init(self):\n self.R = rd.randint(1<<30, 1<<60)\n self.S = set()\n \n def IN(self,x):\n if x^self.R in self.S:\n return True\n else:\n return False\n \n def add(self, x):\n self.S.add(self.R^x)\n \n def erase(self,x):\n if self.IN(x):\n self.S.remove(self.R^x)\n \n# total = int(read())\n# n,k = [*map(int, read().split(' '))]\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n \ndef modinv(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n raise Exception('modular inverse does not exist')\n else:\n return x % m\n \nfrom hashlib import sha256\n \n#Li Chao\nclass Node:\n def __init__(self):\n self.k=10**18\n self.t = 10**18\n self.L, self.R=-10,10**7\n self.left = None\n self.right = None\n \ndef UpdateHelper(curr, k_new, t_new):\n f = lambda x,k,t: k*x+t\n \n \n print(k_new,t_new,curr.L,curr.R)\n m = curr.L + (curr.R-curr.L) // 2+1\n # print(curr.L,curr.R, m)\n lef = f(curr.L,curr.k,curr.t) > f(curr.L,k_new,t_new)\n mid = f(m,curr.k,curr.t) > f(m,k_new,t_new)\n print(lef,mid)\n if mid :\n tmp = k_new, t_new\n k_new, t_new = curr.k,curr.t\n curr.k,curr.t = tmp\n \n if curr.R == curr.L:\n return \n \n # If the index is in the left subtree\n if (lef != mid) :\n print('go left')\n # Create a new node if the left\n # subtree is None\n if (curr.left == None):\n curr.left = Node()\n curr.left.L = curr.L\n curr.left.R = m-1\n curr.left.k = k_new\n curr.left.t = t_new\n \n \n \n # Recursively call the function\n # for the left subtree\n else:\n # print(curr.left.L, curr.left.R)\n UpdateHelper(curr.left, k_new, t_new)\n \n \n # If the index is in the right subtree\n else :\n print('go right')\n # Create a new node if the right\n # subtree is None\n if (curr.right == None):\n curr.right = Node()\n curr.right.L = m\n curr.right.R = curr.R\n curr.right.k = k_new\n curr.right.t = t_new\n \n \n # Recursively call the function\n # for the right subtree\n else:\n # print(curr.right.L, curr.right.R)\n UpdateHelper(curr.right, k_new, t_new)\n \n \n return\n \n \n# Function to find the sum of the\n# values given by the range\ndef queryHelper(curr, x):\n \n # Return 0 if the root is None\n if (curr == None):\n return 10**18\n \n m = curr.L + (curr.R-curr.L) // 2+1\n if curr.R == curr.L:\n return curr.k*x + curr.t\n elif (x < m):\n return min(curr.k*x + curr.t, queryHelper(curr.left,x))\n else:\n return min(curr.k*x + curr.t, queryHelper(curr.right,x))\n \n \ndef pow( x, n, m):\n if (n ==0):\n return 1;\n elif (n==1):\n return x%m;\n \n t = pow(x,n//2,m);\n t = t * t;\n \n if (n%2==1):\n t *= x;\n \n t%=m;\n if (t <0):\n t +=m;\n return t;\nimport itertools\nfrom functools import reduce\n \ndef factors(n): \n return set(reduce(list.__add__, \n ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))\n \n# n,x = [*map(int, read().split(' '))]\n \n# s = [*map(int, read().split(' '))]\n# f = [*map(int, read().split(' '))]\n \n \n \n# a = [0, 1, 19, 271, 3439, 40951, 468559, 5217031, 56953279, 612579511, 6513215599, 68618940391, 717570463519, 7458134171671, 77123207545039, 794108867905351, 8146979811148159, 83322818300333431, 849905364703000879, 8649148282327007911, 87842334540943071199]\n \n# def c4(n):\n# if (n < 4):\n# return 0\n# d = int(math.log10(n))\n# p = math.ceil(10**d)\n# msb = n // p\n# if (msb == 4):\n# return (msb) * a[d] + (n % p) + 1\n# if (msb > 4):\n# return ((msb - 1) * a[d] + p +\n# c4(n % p))\n# return (msb) * a[d] + c4(n % p)\n \n \n \n# def f(x):\n# return x - c4(x)\n \n# \n \n \n# total = int(read())\n# total = 10000\ntotal = 1\n \n# mod = 998244353\nmod = 1000000007\n# pow2 = [1]\n \n# for i in range(1,10**7+10):\n# pow2.append((pow2[-1]*2)%mod )\n \n# pow3 = [1]\n \n# for i in range(1,10**7+10):\n# pow3.append((pow3[-1]*3)%mod )\n \n# pow4m = [1]\n \n# mlt = pow(4, mod-2,mod)\n \n# for i in range(1,10**7+10):\n# pow4m.append((pow4m[-1]*mlt)%mod )\n \n# pow34 = [1]\n \n# mlt = (3*pow(4, mod-2,mod))%mod\n \n# for i in range(1,10**7+10):\n# pow34.append((pow34[-1]*mlt)%mod )\n \n \n \n \nfor _ in range(total):\n # n = int(read())\n # n = 8\n # s = read()\n \n n,m = [*map(int, read().split(' '))]\n \n for i in range(m):\n s = read()\n \n ret = '01'*n\n print(ret[:n]) \n \n \n \n ", "n, m = [int(x) for x in input().strip().split()]\r\nprint(''.join('01' for _ in range(n//2 + 1))[:n])\r\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\nfor _ in range(m):\r\n input()\r\nans = [i % 2 for i in range(n)]\r\nsys.stdout.write(\"\".join(map(str, ans)))", "n, m = map(int, input().split())\r\na = '01'*(n//2)\r\nif n % 2:\r\n a = a+'0'\r\nprint(a)", "n,m=map(int,input().split())\r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\nprint('01'*(n//2)+'0'*(n%2))\r\n", "print((1000 * '01')[:int(input().split()[0])])\r\n", "n,m = input().split()\r\nout = \"\"\r\nfor i in range(int(m)):\r\n input()\r\nfor i in range(int(n)):\r\n if(i%2==0):\r\n out+=\"0\"\r\n else:\r\n out+=\"1\"\r\nprint(out)", "print(('01'*99999)[:int(input().split()[0])])", "n,m=list(map(int,input().split()))\r\nfor i in range(m):\r\n input()\r\nfor i in range(n):\r\n if i%2==0:\r\n print(\"0\",end=\"\")\r\n else:\r\n print(\"1\",end=\"\")", "\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef MAP2():return map(float,input().split())\r\ndef LIST(): return list(map(int, input().split()))\r\ndef STRING(): return input()\r\nimport string\r\nimport sys\r\nfrom heapq import heappop , heappush\r\nfrom bisect import *\r\nfrom collections import deque , Counter , defaultdict\r\nfrom math import *\r\nfrom itertools import permutations , accumulate\r\ndx = [-1 , 1 , 0 , 0 ]\r\ndy = [0 , 0 , 1 , - 1]\r\n#visited = [[False for i in range(m)] for j in range(n)]\r\n#sys.stdin = open(r'input.txt' , 'r')\r\n#sys.stdout = open(r'output.txt' , 'w')\r\n#for tt in range(INT()):\r\n\r\n#Code\r\n\r\nn , m = MAP()\r\nfor i in range(m):\r\n l , r = MAP()\r\n\r\nt = ''\r\nf = 0\r\nfor i in range(n):\r\n if f == 0 :\r\n t+=str(f)\r\n f = 1\r\n else:\r\n t += str(f)\r\n f = 0\r\n\r\nprint(t)\r\n\r\n\r\n\r\n\r\n", "n,k = map(int,input().split(' '))\r\na = []\r\n\r\nfor i in range(0,k):\r\n x,y = map(int,input().split(' '))\r\n a.append([x,y])\r\n\r\nif n%2==0:\r\n print('01'*(n//2))\r\nelse:\r\n print('01'*(n//2)+'0')\r\n", "n,m=map(int,input().split())\r\nfor k in range(m):\r\n l,r=map(int,input().split())\r\nprint('10'*(n//2) + '1'*(n%2))\r\n", "n, d = map(int, input().split())\nprint (''.join([chr(ord('0') + i % 2) for i in range(n)]))\n", "n,k=input().split()\r\nn=int(n)\r\nstrn=\"\"\r\nfor i in range(0,n):\r\n if(i%2==0):\r\n strn+=\"1\"\r\n else:\r\n strn+=\"0\"\r\nprint(strn)", "def main():\r\n #string input()\r\n #strList input().split()\r\n #integer int(input())\r\n #intList list(map(int, input().split()))\r\n # str = \"\"\r\n n, m = map(int, input().split())\r\n audience = []\r\n for i in range(m):\r\n audience.append(tuple(map(int, input().split())))\r\n print(\"10\" * (n // 2) + \"1\" * (n % 2))\r\n # audience.sort(key = lambda a: (a[0], a[1]))\r\n return 0\r\nmain()\r\n", "inp = [int(i)for i in input().split()]\r\nn, m = inp\r\n\r\nfor i in range(m):\r\n a = input()\r\n\r\nprint(('01'*(n//2+1))[:n])", "n, d = map(int, input().split())\r\n\r\nprint(''.join(str(i % 2) for i in range(n)))\r\n", "n,k=[int(x) for x in input().split()]\nfor i in range(k):\n a=input()\n\na='0'\ns=''\nfor i in range(n):\n s+=a\n if a=='0':\n a='1'\n else:\n a='0'\n\nprint(s)\n", "f,n=[int(x) for x in input().split(' ')]\nls={}\nrs={}\nfor i in range(n):\n l, r = [int(x) for x in input().split(' ')]\n ls[i]=l\n rs[i]=r\ns=\"\"\nfor i in range(f):\n s+=str(i%2)\nprint(s)\n\n\n", "n, nSegs = map(int, input().split())\r\nsegs = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(nSegs)]\r\n\r\nret = '01' * (n // 2) + '0' * (n & 1)\r\nprint(ret)", "n,k=map(int,input().split())\r\nr=''\r\nfor i in range(k):\r\n l=list(map(int,input().split()))\r\nfor i in range(n):\r\n if(i%2==1):\r\n r=r+'1'\r\n else:\r\n r=r+'0'\r\nprint(r)\r\n", "n,d = map(int,input().split())\r\narr = []\r\nfor i in range(d):\r\n\tarr.append(list(map(int,input().split())))\r\ns = \"\"\r\nfor i in range(n):\r\n\tif i % 2 == 0:\r\n\t\ts = s + \"0\"\r\n\telse:\r\n\t\ts = s + \"1\"\r\nprint(s)", "n1=input()\r\nn1=n1.split()\r\nn=int(n1[0])\r\nm=int(n1[1])\r\nfor i in range(m):\r\n a=input()\r\na=\"\"\r\nfor i in range(n):\r\n if i%2==1:\r\n a+=\"0\"\r\n else:\r\n a+=\"1\"\r\nprint(a)\r\n", "n, m = map(int, input().split())\r\nclients = []\r\nfor i in range(m):\r\n temp_l = list(map(int, input().split()))\r\n clients.append(temp_l)\r\nprint('10' * (n // 2), end='')\r\nif n % 2 == 1:\r\n print('1')\r\n", "a, b = map(int, input().split())\r\nq, r = divmod(a, 2)\r\nprint('01'*q + '0'*r)\r\n", "input1 = input()\nn = int(input1.split()[0])\nm = int(input1.split()[1])\nfor i in range(m):\n\tinput2 = input()\nstr = \"\"\nfor i in range(n):\n\tif(i%2 == 0):\n\t\tstr = str+\"0\"\n\telse:\n\t\tstr = str+\"1\"\nprint(str)", "def calc(l):\r\n res = 0\r\n \r\n for li, ri in lr:\r\n zero, one = 0, 0\r\n \r\n for i in range(li-1, ri):\r\n if l[i]==0:\r\n zero += 1\r\n else:\r\n one += 1\r\n \r\n res += zero*one\r\n \r\n return res\r\n\r\nn, m = map(int, input().split())\r\nlr = [tuple(map(int, input().split())) for _ in range(m)]\r\nl1, l2 = [], []\r\n\r\nfor i in range(n):\r\n if i%2==0:\r\n l1.append(0)\r\n l2.append(1)\r\n else:\r\n l1.append(1)\r\n l2.append(0)\r\n\r\nv1, v2 = calc(l1), calc(l2)\r\n\r\nif v1>v2:\r\n print(''.join(map(str, l1)))\r\nelse:\r\n print(''.join(map(str, l2)))", "def calc(s):\n presum = [0]\n for ch in s:\n presum.append(presum[-1])\n if ch == '1':\n presum[-1] += 1\n ans = 0\n for (l,r) in points:\n ans += ((r-l+1) - (presum[r] - presum[l-1])) * (presum[r] - presum[l-1])\n return ans\n\n\nn, m = list(map(int, input().split()))\npoints = []\nfor _ in range(m):\n points.append(list(map(int, input().split())))\n\nans1 = \"10\" * (n//2)\nans2 = \"01\" * (n//2)\nif n%2:\n ans1 += '1'\n ans2 += '0'\n\nprint(ans1 if calc(ans1) > calc(ans2) else ans2)\n", "from operator import itemgetter\r\n\r\ndef main():\r\n n,m=map(int,input().split( ))\r\n a=[]\r\n for _ in range(m):\r\n x,y=map(int,input().split( ))\r\n x-=1;y-=1\r\n a.append((x,y))\r\n a=sorted(a,key=itemgetter(0,1))\r\n\r\n ans=[-1]*n\r\n for l,r in a:\r\n\r\n if ans[l]==-1:\r\n \r\n flag=1\r\n\r\n for i in range(l,r+1):\r\n if flag:\r\n ans[i]=1\r\n else:\r\n ans[i]=0\r\n flag^=1\r\n else:\r\n\r\n flag=1\r\n x=ans[l]\r\n for i in range(l,r+1):\r\n\r\n if flag:\r\n ans[i]=x\r\n else:\r\n ans[i]=x^1\r\n flag^=1\r\n for i in range(n):\r\n if ans[i]==-1:\r\n ans[i]=0\r\n\r\n ans=map(str,ans)\r\n print(''.join(ans))\r\nmain()", "n, m = list(map(int, input().split(\" \")))\nl, r = [], []\nfor i in range(0, m):\n l1, r1 = list(map(int, input().split(\" \")))\n l.append(l1)\n r.append(r1)\n\nt = True\nfor i in range(0, n):\n if t:\n print(1, end=\"\")\n t = False\n else:\n print(0, end=\"\")\n t = True\n\n\n\n", "n, m = input().split(\" \")\r\nn = int(n)\r\nm = int(m)\r\nfor i in range(m):\r\n input()\r\nst = \"\"\r\nfor i in range(n):\r\n if i % 2 == 0:\r\n st += \"1\"\r\n else:\r\n st += \"0\"\r\nprint(st)", "import math\r\nn,k=map(int,input().split())\r\nans=0\r\nfor i in range(1,n+1):\r\n if (i%2==1):\r\n print(\"1\",end=\"\")\r\n else:\r\n print(\"0\",end=\"\")", "n, m = map(int, input().split())\r\nfor _ in range(m):\r\n l, r = map(int, input().split())\r\n\r\nans = []\r\nx = [\"0\", \"1\"]\r\nfor i in range(n):\r\n ans.append(x[i % 2])\r\nprint(\"\".join(ans))", "mod = 1000000007\r\nMOD = 998244353\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nit = lambda : tuple(map(int, input().split()))\r\nls = lambda : list(input())\r\ns='01'*10**3\r\nn, k = f()\r\nl=[]\r\nfor i in range(k):\r\n l.append(il())\r\nprint(s[:n])", "import math\r\nn,k=map(int,input().split())\r\nfor _ in range(k):\r\n l,r=map(int,input().split())\r\nfor i in range(1,n+1):\r\n if i%2==0:\r\n print('0',end='')\r\n else:\r\n print('1',end='')\r\nprint()\r\n\r\n", "n, d = map(int, input().split())\nfor i in range(n):\n if (i % 2 == 0): print(0, end = '')\n else: print(1, end = '')", "n, m = map(int, input().split())\r\nans = [\"0\"] * n\r\nfor i in range(1, n, 2):\r\n ans[i] = \"1\"\r\nprint(\"\".join(ans))", "n, m = map(int, input().split())\nprint(\"01\" * (n // 2) + \"0\" * (n % 2))", "a = list(input().split(' '))\r\nn, m = int(a[0]), int(a[1])\r\nres = list(-1 for x in range(n))\r\nfor i in range(n):\r\n print(i%2, sep = '', end = '')\r\n\r\n##for _ in range(m):\r\n## a = list(input().split(' '))\r\n## l, r = int(a[0]), int(a[1])\r\n## l -= 1\r\n## r -= 1\r\n## ind = -1\r\n## for i in range(l, r+1):\r\n## print(i)\r\n## if res[i] != -1:\r\n## ind = i\r\n## print('this is ind')\r\n## print(ind)\r\n## if ind > 0:\r\n## print('hello' + str(ind))\r\n## if ind < n-1:\r\n## print(res[ind])\r\n## if res[ind + 1] >= 0:\r\n## for i in range(ind, l-1, -1):\r\n## res[i] = 1 - res[i+1]\r\n## elif ind > 0:\r\n## if res[ind - 1] >= 0:\r\n## for i in range(ind, r+1):\r\n## res[i] = 1 - res[i-1]\r\n## else:\r\n## res[l] = 0\r\n## for i in range(l+1, r+1):\r\n## res[i] = 1 - res[i-1]\r\n## print('this is res')\r\n## print(res)\r\n##for i in range(n):\r\n## print(res[i], sep='', end='')\r\n \r\n \r\n" ]
{"inputs": ["5 3\n1 3\n2 4\n2 5", "6 3\n5 6\n1 4\n4 6", "10 4\n3 3\n1 6\n9 9\n10 10", "1 1\n1 1", "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999", "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23 74\n647 702\n930 986\n926 983\n769 822\n508 558", "1000 10\n138 238\n160 260\n716 816\n504 604\n98 198\n26 126\n114 214\n217 317\n121 221\n489 589", "1000 5\n167 296\n613 753\n650 769\n298 439\n71 209", "1000 5\n349 415\n714 773\n125 179\n1 80\n148 242", "914 10\n587 646\n770 843\n825 875\n439 485\n465 521\n330 387\n405 480\n477 521\n336 376\n715 771", "571 10\n13 94\n450 510\n230 293\n302 375\n304 354\n421 504\n24 87\n122 181\n221 296\n257 307", "6 2\n1 6\n1 4", "2 1\n1 2"], "outputs": ["01010", "010101", "0101010101", "0", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...", "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...", "010101", "01"]}
UNKNOWN
PYTHON3
CODEFORCES
202
1f5631011a2485df36b8c0ae1a556024
Peculiar apple-tree
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=&lt;<=*i*. Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time. Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest. First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000)  — number of inflorescences. Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down. Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. Sample Input 3 1 1 5 1 2 2 2 18 1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4 Sample Output 1 3 4
[ "n = int(input())\r\na = [int(e) for e in input().split()]\r\nd = {1:0}\r\nfor k, v in enumerate(a):\r\n d[k+2] = d[v] + 1\r\nd2 = {}\r\nfor k, v in d.items():\r\n d2[v] = d2.get(v,0) + 1\r\ns = sum([v%2 for v in d2.values()])\r\nprint(s)", "def f(x):\r\n return int(x) - 1\r\n\r\n\r\nn = int(input())\r\np = [0] + list(map(f, input().split()))\r\ndst = [0] * n\r\nfor i in range(1, n):\r\n dst[i] = dst[p[i]] + 1\r\ncnt = [0] * (n + 1)\r\nfor i in range(1, n):\r\n cnt[dst[i]] ^= 1\r\nprint(sum(cnt) + 1)\r\n", "from collections import defaultdict\r\nfrom queue import Queue\r\nn=int(input())\r\nt=defaultdict(list)\r\np=list(map(int,input().split()))\r\nfor i in range(2,n+1):\r\n t[p[i-2]].append(i)\r\nq=Queue()\r\na=1\r\nq.put(1)\r\nwhile not q.empty():\r\n n=q.qsize()\r\n ap=0\r\n for i in range(n):\r\n u=q.get()\r\n for v in t[u]:\r\n q.put(v)\r\n ap^=1\r\n a+=ap\r\nprint(a)\r\n\r\n ", "n = int(input())\r\np = list(map(int, input().split()))\r\nlvl = [0] * n\r\ncnt = {0: 1}\r\nfor v in range(n - 1):\r\n lvl[v + 1] = lvl[p[v] - 1] + 1\r\n if lvl[v + 1] in cnt:\r\n cnt[lvl[v + 1]] += 1\r\n else:\r\n cnt[lvl[v + 1]] = 1\r\nprint(sum(map(lambda x: x % 2, cnt.values())))", "n=int(input())\r\na=[0]+[1]*n\r\np = list(map(int,input().split()))\r\nnei=[[] for i in range(n+1)]\r\nnei[0]=[1]\r\nfor i,e in enumerate(p):\r\n nei[e]+=[i+2]\r\nd=[-1]*(n+1)\r\n\r\nvert=[0]\r\nindex=0\r\nwhile index<=n:\r\n v=vert[index]\r\n for nnn in nei[v]:\r\n d[nnn]=d[v]+1\r\n vert.append(nnn)\r\n index+=1\r\nfrom collections import Counter\r\ncc=Counter(d)\r\ns=0\r\nfor i,e in cc.items():\r\n s+=e%2\r\nprint(s-1)\r\n", "# python3\n\n\ndef main():\n n = int(input())\n parent = tuple(int(x) - 1 for x in input().split())\n\n depth = [0]\n for v in range(n - 1):\n depth.append(depth[parent[v]] + 1)\n\n parity = [0] * n\n for d in depth:\n parity[d] ^= 1\n\n print(sum(parity))\n\n\nmain()\n", "\r\nclass Node: \r\n def __init__(self, id):\r\n self.id = id\r\n self.parent = -1\r\n self.children = set()\r\n self.apples = 1\r\n\r\nnodes = dict()\r\n\r\nnb_nodes = int(input())\r\nfor i in range(nb_nodes): \r\n nodes[i+1] = Node(i+1)\r\n\r\nparents = [int(i) for i in input().split(\" \")]\r\n\r\nbase = 2\r\nfor p in parents: \r\n nodes[base].parent = p\r\n nodes[p].children.add(base)\r\n base += 1\r\n\r\n#for n in nodes.values(): \r\n# print(\"%d -> %s\" % (n.id, n.children))\r\n \r\nrecolt = 0\r\ntodo = { 1 }\r\nwhile len(todo) > 0: \r\n recolt += len(todo) % 2\r\n next = set()\r\n for t in todo: \r\n next |= nodes[t].children\r\n todo = next\r\n \r\nprint(recolt)", "from collections import Counter\r\n\r\nn = int(input())\r\nlevels = [0] * n\r\nlevels[0] = 1\r\nflow = list(map(int, input().split()))\r\nfor i in range(1, n):\r\n levels[i] = levels[flow[i - 1] - 1] + 1\r\napples = 0\r\nfor v in dict(Counter(levels)).values():\r\n apples += v % 2\r\nprint(apples)\r\n", "from collections import Counter\r\n\r\ntree = []\r\n\r\n\r\nclass Node:\r\n def __init__(self, num=None):\r\n self.length = 0 if num is None else tree[num-1].length + 1\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n global tree\r\n tree = [Node()]\r\n\r\n for x in input().split():\r\n tree.append(Node(int(x)))\r\n\r\n print(sum([value & 1 for key, value in Counter([x.length for x in tree]).items()]))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n, lens, ans, cnt, me = int(input()) , [0] * (10 ** 5), 1, [0] * (10 ** 5), 1\r\nfor i in [(int(i) - 1) for i in input().split()]:\r\n\tlens[me], ans, cnt[lens[i] + 1], me = lens[i] + 1, ans - 2 * cnt[lens[i] + 1] + 1, cnt[lens[i] + 1] ^ 1, me + 1\r\nprint(ans)", "n = int(input())\r\np = [-1, 0] + list(map(int, input().split()))\r\nh = [0] * (n+1)\r\ncnt = [1] + [0] * n\r\nfor i in range(2, n+1):\r\n h[i] = h[p[i]] + 1\r\n cnt[h[i]] += 1\r\nres = 0\r\nfor i in range(max(h)+1):\r\n if cnt[i] % 2 == 1:\r\n res += 1\r\nprint(res)", "from collections import deque\r\nn = int(input())\r\ngraph = [[] for i in range(n)]\r\ndist = [0] * n\r\nused = [0] * n\r\nused[0] = 1\r\nnum = list(map(int, input().split()))\r\nfor i in range(n - 1):\r\n graph[num[i] - 1].append(i + 1)\r\n graph[i + 1].append(num[i] - 1)\r\nq = deque()\r\nq.append(0)\r\nsmth = [0] * n\r\nwhile len(q):\r\n v = q.popleft()\r\n for i in range(len(graph[v])):\r\n if not used[graph[v][i]]:\r\n q.append(graph[v][i])\r\n dist[graph[v][i]] = dist[v] + 1\r\n used[graph[v][i]] = 1\r\nans = 1\r\nfor i in range(1, n):\r\n smth[dist[i]] += 1\r\nfor i in range(len(smth)):\r\n ans += smth[i] % 2\r\nprint(ans)", "n = int(input())\r\npi = list(map(int, input().split()))\r\n\r\nar = [0] * n\r\nar2 = [0] * n\r\nar2[0] = 1\r\n\r\nfor i in range(n-1):\r\n temp = ar[pi[i]-1] + 1\r\n ar[i+1] = temp\r\n ar2[temp] += 1\r\n\r\nans = 0\r\nfor i in range(n):\r\n if ar2[i] % 2 == 1:\r\n ans += 1\r\nprint(ans)\r\n", "import sys\r\nn = int(sys.stdin.readline())\r\nmas = list(map(int,sys.stdin.readline().split()))\r\notv = [0]*(n)\r\nfor i in range(1,n):\r\n otv[i]=otv[mas[i-1]-1]+1\r\ncount=0\r\notv.sort()\r\nstart=0\r\nans=0\r\n#print(*otv)\r\nfor i in range(n):\r\n if otv[i]==start:\r\n count+=1\r\n else:\r\n #print(count)\r\n ans+=count%2\r\n start=otv[i]\r\n count=1\r\nprint(ans+count%2)\r\n", "import collections\nn = int(input())\na = list(map(int, input().split()))\n\nto = {}\nfor i, node in enumerate(a):\n to[i+2] = node\n\nlayers = collections.defaultdict(list)\nfor k, v in to.items():\n layers[v].append(k)\n\nqueue = [1]\nans = 0\nwhile queue:\n ans += len(queue)%2\n n = len(queue)\n for _ in range(n):\n node = queue.pop(0)\n if node in layers:\n queue.extend(layers[node])\n\nprint(ans)", "n = int(input())\r\np = [-1, 0] + [int(x) for x in input().split()]\r\nh = [0] * (n+1)\r\ncount = [0] * n\r\ncount[0] = 1\r\nmax_h = 0\r\nfor i in range(2, n+1):\r\n h[i] = h[p[i]]+1\r\n count[h[i]]+=1\r\n max_h = max(max_h,h[i])\r\nans = 0\r\nfor i in range(max_h+1):\r\n ans += count[i]%2\r\nprint(ans)", "from sys import setrecursionlimit\r\n\r\na = int(input())\r\n\r\nsetrecursionlimit(200000)\r\n\r\nh = [[] for i in range(a)]\r\ns = list(map(int, input().split()))\r\nfor i in range(a - 1):\r\n h[s[i] - 1].append(i + 1)\r\n\r\nmetka = [False for i in range(a)]\r\ndat = [0 for i in range(a)]\r\ndis = [0 for i in range(a)]\r\n\r\n\r\ndef dfs(x):\r\n stack = []\r\n stack.append(x)\r\n while stack:\r\n x = stack.pop(-1)\r\n dat[dis[x]] += 1\r\n metka[x] = True\r\n for i in h[x]:\r\n if not metka[i]:\r\n stack.append(i)\r\n dis[i] = dis[x] + 1\r\n\r\n\r\ndfs(0)\r\n\r\nprint(sum(map(lambda x: x % 2, dat)))\r\n", "n = int(input())\n\npar = [None] + [int(i) - 1 for i in input().split()]\nchildren = [[] for _ in range(n)]\nfor child in range(1, n):\n children[par[child]].append(child)\n\ncount = 0\nnodesAtCurrLevel = [0]\n\nwhile nodesAtCurrLevel:\n count += len(nodesAtCurrLevel) % 2\n \n nodesAtNextLevel = []\n for node in nodesAtCurrLevel:\n nodesAtNextLevel += children[node]\n \n nodesAtCurrLevel = nodesAtNextLevel\n\nprint(count)", "import collections\r\nfrom functools import partial\r\n\r\n\r\nn = int(input())\r\nparents = [0]\r\nparents.extend(int(i) - 1 for i in input().split())\r\nchildren = [set() for _ in range(n)]\r\n\r\nfor index, parent in enumerate(parents):\r\n if index > 0:\r\n children[parent].add(index)\r\n\r\n\r\ndepth = [set() for _ in range(n)]\r\n\r\n\r\ndef discover(index: int, depth_stat: int = 0) -> None:\r\n depth[depth_stat].add(index)\r\n for child in children[index]:\r\n queue.append(partial(discover, child, depth_stat + 1))\r\n\r\n\r\nqueue = collections.deque([partial(discover, 0)])\r\nwhile queue:\r\n func = queue.popleft()\r\n func()\r\n\r\n\r\nresult = 0\r\nfor children in depth:\r\n result += len(children) % 2\r\n\r\n\r\nprint(result)\r\n", "#!/usr/bin/env python3\n\nimport sys\n\nn = int(sys.stdin.readline().strip())\npis = list(map(int, sys.stdin.readline().strip().split()))\n\nlevels = [0 for _ in range(len(pis) + 1)]\nlevel_counts = [1]\nmax_level = 0\n\nfor i, pi1 in zip(range(1, len(pis) + 1), pis):\n\tpi = pi1 - 1 # 0-index\n\tlvl = levels[pi] + 1\n\tif lvl > max_level:\n\t\tlevel_counts.append(0)\n\t\tmax_level += 1\n\tlevels[i] = lvl\n\tlevel_counts[lvl] += 1\n\nharvest = sum(c % 2 for c in level_counts)\n\nprint (harvest)\n", "from collections import defaultdict\r\nn = int(input())\r\na = list(map(int, input().split()))\r\na.insert(0, -1)\r\na.insert(0, -1)\r\n\r\ncnt = {}\r\n\r\n\r\ndef find(k):\r\n if k == 1:\r\n return 1\r\n if k in cnt.keys():\r\n return cnt[k]\r\n else:\r\n cnt[k] = find(a[k]) + 1\r\n return cnt[k]\r\n\r\n\r\nfor i in range(2, n + 1):\r\n find(i)\r\ndic = defaultdict(int)\r\nfor k, v in cnt.items():\r\n dic[v] ^= 1\r\nprint(sum(dic.values()) + 1)", "n = int(input())\nP = list(map(int, input().split()))\nP = [p-1 for p in P]\ng = [[] for i in range(n)]\nfor i, p in enumerate(P):\n g[p].append(i+1)\n\nfrom collections import deque\nq = deque([])\nq.append(0)\ndepth = [-1]*n\ndepth[0] = 0\nwhile q:\n v = q.popleft()\n for u in g[v]:\n q.append(u)\n depth[u] = depth[v]+1\n\nfrom collections import Counter\nC = Counter(depth)\nans = 0\nfor k, v in C.items():\n ans += v%2\nprint(ans)\n", "from functools import reduce\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nd = [0 for i in range(n)]\r\nfor i, j in enumerate(a):\r\n k = j - 1\r\n d[i + 1] = d[k] + 1\r\nM = [0 for i in range(max(d) + 1)]\r\nans = 0\r\nfor i in d:\r\n M[i] += 1\r\nprint(reduce(lambda x, y: x + (y % 2), M))", "n = int(input().strip())\ncount = [0]*n\nparams = [-1, 0]+list(map(int, input().split()))\ni = 2\nlayer = [0]*(n+1)\nnodes_in_layer = {}\nwhile i <= n:\n layer[i] = layer[params[i]] + 1\n count[params[i]] += 1\n if nodes_in_layer.get(layer[i]) is None:\n nodes_in_layer.setdefault(layer[i], 1)\n else:\n nodes_in_layer[layer[i]] += 1\n i += 1\nmax_layer = max(layer)\nresult = 1\nfor i in range(1, max_layer+1):\n result += nodes_in_layer[i] % 2\n\nprint(result)\n", "import sys, math\n\n#f = open('input/input_2', 'r')\nf = sys.stdin\n\nN = int(f.readline())\npl = list(map(int, f.readline().split()))\n\ne = [[] for _ in range(N+1)]\nlv = [0] * (N+1)\nfor i, p in enumerate(pl):\n e[p].append(i+2)\n\nc = [0] * (N+1)\n\nfor i in range(1, N+1):\n c[lv[i]] = 1 - c[lv[i]]\n for j in e[i]:\n lv[j] = lv[i]+1\n\nprint(sum(c))\n", "from collections import Counter\r\n\r\nn = int(input())\r\np = list(map(int, input().split()))\r\n\r\nco = [1]\r\n\r\nfor i in range(n - 1):\r\n co.append(co[p[i] - 1] + 1)\r\n\r\nans = 0\r\n\r\nfor v in Counter(co).values():\r\n ans += v % 2\r\n\r\nprint(ans)\r\n", "from collections import deque\n\nn = int(input())\nparents = [0, 0] + [int(x) for x in input().split()]\nchildren = [set([]) for _ in range(n + 1)]\nfor i, p in enumerate(parents):\n children[p].add(i)\n\nq = deque([(0, 1)])\nlevels = [0 for _ in range(n + 1)]\nmaxLevel = 0\nwhile len(q) > 0:\n level, node = q.popleft()\n levels[node] = level\n maxLevel = max(maxLevel, level)\n for i in children[node]:\n q.append((level + 1, i))\n\nlevels2 = [0 for _ in range(maxLevel + 1)]\nfor i in levels[1:]:\n levels2[i] += 1\n\nprint(sum([i % 2 for i in levels2]))", "n=int(input())\n\n\n\n\n\na=list(map(int,input().split()))\n\ndp=[0,]\n\ncount=[0 for i in range(n)]\n\ncount[0]+=1\n\nfor i in range(n-1):\n\n dp.append(dp[a[i]-1]+1)\n\n count[dp[-1]]+=1\n\nans=0\n\nfor i in range(n):\n\n ans+=count[i]%2\n\nprint(ans)\n\n\n\n# Made By Mostafa_Khaled", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef f(n, w):\r\n d = [0 for i in range(n+1)]\r\n d[1] = 0\r\n for i in range(2, n+1):\r\n x = w[i-2]\r\n d[i] = d[x] + 1\r\n s = dict()\r\n for i in range(1, n+1):\r\n x = d[i]\r\n if x not in s:\r\n s[x] = 0\r\n s[x] = (s[x] + 1) % 2\r\n return sum(s.values())\r\n\r\n\r\nn = int(input())\r\nx = [0]*n\r\nw = list(map(int, input().split()))\r\nprint(f(n, w))\r\n", "# 930A\nimport collections\ndef do():\n n = int(input())\n nums = [0] + [int(c)-1 for c in input().split(\" \")]\n g = collections.defaultdict(list)\n for i, j in enumerate(nums):\n if i != j:\n g[j].append(i) # children\n cur = [0]\n res = 0\n while cur:\n res += len(cur) % 2\n next = []\n for c in cur:\n for nei in g[c]:\n next.append(nei)\n cur = next\n return res\n\nprint(do())", "def bfs(d,n):\r\n queue = [[1,0]]\r\n res = 0\r\n mark = {i:False for i in range(1,n+1)}\r\n mark[1]=True\r\n res = [0 for i in range(n)]\r\n while queue:\r\n q = queue.pop(0)\r\n x,level = q[0],q[1]\r\n lev = level+1\r\n res[level]=(res[level]+1)%2\r\n for i,y in enumerate(d[x]):\r\n if mark[y]==False:\r\n mark[y]=True\r\n queue.append([y,lev])\r\n print(sum(res))\r\nn = int(input())\r\nlst = list(map(int,input().split()))\r\nd = {1:[]}\r\nfor i,x in enumerate(lst):\r\n d[x].append(i+2)\r\n d[i+2]=[]\r\nbfs(d,n)", "n = int(input())\np = list(map(int, input().split()))\n\nx = []\n\nfor i in range(n):\n x.append(list())\n\nfor idx, pi in enumerate(p, 1):\n x[pi-1].append(idx)\n\nlc = [0 for i in range(n)]\n\nstack_vertex = [0]\nstack_level = [0]\n\n\ndef dfs():\n while len(stack_vertex) > 0:\n vertex = stack_vertex.pop()\n level = stack_level.pop()\n\n lc[level] += len(x[vertex])\n\n for v in x[vertex]:\n stack_vertex.append(v)\n stack_level.append(level + 1)\n\n\ndfs()\n\nresp = 1\nfor count in lc:\n if count % 2 != 0:\n resp += 1\n\nprint(resp)\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\ndepths = [0]\r\ntime = {}\r\nfor i in range(n-1):\r\n cur_depth = depths[arr[i]-1] + 1\r\n depths.append(cur_depth)\r\n if cur_depth not in time:\r\n time[cur_depth] = 0\r\n time[cur_depth] += 1\r\nans = 1\r\nfor i in time:\r\n ans += time[i]%2\r\nprint(ans)\r\n", "import sys\r\nimport threading\r\nfrom collections import defaultdict,deque\r\n \r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nadj=defaultdict(list)\r\nfor i,j in enumerate(arr):\r\n adj[j].append(i+2)\r\n#print(adj)\r\ndef fun():\r\n ans=0\r\n q=deque([None,1])\r\n while(len(q)>1):\r\n x=q.popleft()\r\n if x:\r\n if adj.get(x,None):\r\n for ch in adj[x]:\r\n q.append(ch)\r\n else:\r\n if len(q)&1:\r\n ans+=1\r\n q.append(x)\r\n return ans\r\n \r\ndef main():\r\n # print()\r\n print(fun())\r\nif __name__==\"__main__\":\r\n sys.setrecursionlimit(10**6)\r\n threading.stack_size(10**8)\r\n t = threading.Thread(target=main)\r\n t.start()\r\n t.join() ", "n = int(input())\ns = [int(x) - 1 for x in input().split()]\ngraph = []\nfor i in range(n):\n graph.append(set())\nfor i in range(n - 1):\n graph[i + 1].add(s[i])\n graph[s[i]].add(i + 1)\nq = [0]\ndist = [1000000] * n\ndist[0] = 0\nused = [False] * n\nused[0] = True\nwhile q != []:\n parent = q.pop()\n for child in graph[parent]:\n if not used[child]:\n dist[child] = dist[parent] + 1\n q.append(child)\n used[child] = True\ndct = {}\nfor i in range(n):\n if dist[i] in dct:\n dct[dist[i]] += 1\n dct[dist[i]] %= 2\n else:\n dct[dist[i]] = 1\ncount = 0\nfor i in dct:\n count += dct[i]\nprint(count)", "import sys\r\ninput=sys.stdin.readline\r\nfrom collections import deque,defaultdict\r\nn=int(input())\r\np=list(map(int,input().strip().split()))\r\ng=defaultdict(set)\r\n\r\nfor i in range(n-1):\r\n g[p[i]].add(i+2)\r\n g[i+2].add(p[i])\r\n#print(g)\r\nvisited={1}\r\nq=deque([[1]])\r\nans=1\r\nwhile q:\r\n f=q.popleft()\r\n l=[]\r\n for node in f:\r\n for nbr in g[node]:\r\n if nbr not in visited:\r\n l.append(nbr)\r\n visited.add(nbr)\r\n ans+=len(l)%2\r\n if len(l)==0:\r\n break\r\n q.append(l)\r\nprint(ans)", "n = int(input())\r\nparent = tuple(int(x) - 1 for x in input().split())\r\n \r\ndepth = [0]\r\nfor v in range(n - 1):\r\n depth.append(depth[parent[v]] + 1)\r\n \r\n# parity = [0] * n\r\n# for d in depth:\r\n# parity[d] ^= 1\r\n\r\nfreq = {}\r\n\r\nfor d in depth:\r\n if d in freq:\r\n freq[d] += 1\r\n else:\r\n freq[d] = 1\r\n\r\nres = 0\r\nfor d in freq:\r\n res+= freq[d]%2\r\nprint(res)\r\n \r\n# print(sum(parity))", "import sys\r\nimport bisect\r\n# from collections import deque\r\n\r\nRi = lambda : [int(x) for x in sys.stdin.readline().split()]\r\nri = lambda : sys.stdin.readline().strip()\r\n \r\ndef input(): return sys.stdin.readline().strip()\r\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\r\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\r\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\r\ndef ceil(x, y=1): return int(-(-x // y))\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\r\ndef Yes(): print('Yes')\r\ndef No(): print('No')\r\ndef YES(): print('YES')\r\ndef NO(): print('NO')\r\nINF = 10 ** 30 \r\nMOD = 998244353\r\n\r\nn = int(ri())\r\na = Ri()\r\n\r\ndic = {}\r\nfor i in range(len(a)):\r\n if a[i] == 1:\r\n dic[i+2] = 1\r\n else:\r\n time = dic[a[i]]\r\n dic[i+2] = time+1\r\ncnt = 0\r\ntime = {}\r\nfor i in dic:\r\n if dic[i] in time:\r\n time[dic[i]]+=1\r\n else:\r\n time[dic[i]] = 1\r\n \r\nfor i in time:\r\n cnt +=(time[i]%2)\r\nprint(cnt+1)", "def find_apples(edges):\r\n from collections import deque, defaultdict\r\n level_mp = defaultdict(int)\r\n queue = deque([(1, 0, 0)])\r\n while queue:\r\n node, par, level = queue.popleft()\r\n level_mp[level] += 1\r\n for ch in edges.get(node, []):\r\n if ch != par:\r\n queue.append((ch, node, level+1))\r\n total_apple = 0\r\n for apple in level_mp.values():\r\n total_apple += (apple%2)\r\n return total_apple\r\n \r\ndef main():\r\n from collections import defaultdict\r\n # n, flower, bee = list(map(int, input().split()))\r\n n = int(input())\r\n infloresence = list(map(int, input().split()))\r\n edges = defaultdict(list)\r\n for i in range(n-1):\r\n x = i + 2\r\n y = infloresence[i]\r\n edges[x].append(y)\r\n edges[y].append(x)\r\n print(find_apples(edges))\r\n\r\nif __name__==\"__main__\":\r\n import sys\r\n import threading\r\n sys.setrecursionlimit(10**6)\r\n threading.stack_size(10**8)\r\n t = threading.Thread(target=main)\r\n t.start()\r\n t.join() ", "n = int(input())\r\nans = 1\r\n\r\nA = list(map(int, input().split()))\r\nh = [0 for i in range(n+1)]\r\nB = [0 for i in range(n+1)]\r\n\r\nfor i in range(n-1):\r\n h[i+2] = h[A[i]] + 1\r\n B[h[i+2]] += 1\r\n \r\n \r\nfor x in B:\r\n if x % 2 != 0:\r\n ans += 1\r\n \r\nprint(ans)\r\n", "tree = []\r\n\r\n\r\nclass Node:\r\n def __init__(self, num):\r\n self.parent = num - 1\r\n self.length = 0\r\n\r\n def add_to_tree(self):\r\n if self.parent < 0:\r\n return\r\n self.length = tree[self.parent].length + 1\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n global tree\r\n tree = [Node(0)] + [Node(int(x)) for x in input().split()]\r\n\r\n for i in tree:\r\n i.add_to_tree()\r\n\r\n amount = [0] * n\r\n for i in [x.length for x in tree]:\r\n amount[i] += 1\r\n\r\n print(sum([x & 1 for x in amount]))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\nle=[0]*(n+1)\r\nle[1]=1\r\nl=[int(x) for x in input().split()]\r\nfor i in range(len(l)):\r\n le[i+2]=le[l[i]]+1 \r\nf=[0]*(n+1)\r\n#print(le)\r\nfor ele in le:\r\n f[ele]+=1 \r\nans=0\r\n#print(f)\r\nfor ele in f:\r\n if ele%2==1:\r\n ans+=1 \r\nprint(ans-1)", "from collections import deque\r\nn = int(input())\r\ndist = [-1] * n\r\ncnt = [1] + [0] * (n - 1)\r\nsl = [[] for i in range(n)]\r\na = [int(x) - 1 for x in input().split()]\r\nfor i in range(n - 1):\r\n\tsl[a[i]] += [i + 1]\r\nqueue = deque()\r\nqueue.append(0)\r\ndist[0] = 0\r\nwhile queue:\r\n\tv = queue.popleft()\r\n\tfor u in sl[v]:\r\n\t\tif dist[u] == -1:\r\n\t\t\tdist[u] = dist[v] + 1\r\n\t\t\tcnt[dist[u]] += 1\r\n\t\t\tqueue.append(u)\r\nans = 0\r\nfor i in cnt:\r\n\tans += i % 2\r\nprint(ans)", "import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef process(n, A):\r\n depth = [0 for i in range(n+1)]\r\n depth[1] = 0\r\n for i in range(2, n+1):\r\n pi = A[i-2]\r\n depth[i] = depth[pi]+1\r\n d = {}\r\n for i in range(1, n+1):\r\n x = depth[i]\r\n if x not in d:\r\n d[x] = 0\r\n d[x] = (d[x]+1) % 2\r\n return sum(d.values())\r\n\r\nn = int(input())\r\nA = [int(x) for x in input().split()]\r\nprint(process(n, A))\r\n ", "import sys\r\n\r\nsys.setrecursionlimit(10**5 + 10)\r\nclass Tree:\r\n def __init__(self):\r\n n = Node()\r\n n.oddity = [False]*(10**5 + 1)\r\n n.oddity[0] = True\r\n self.nodes = [n]\r\n\r\n def add(self, parent):\r\n parent = parent - 1\r\n n = Node()\r\n self.nodes[parent].add_child(n)\r\n self.nodes.append(n)\r\n self.nodes[0].oddity[n.height] = not self.nodes[0].oddity[n.height]\r\n\r\nclass Node:\r\n def __init__(self):\r\n #self.childs = []\r\n self.parent = None\r\n self.oddity = None\r\n self.height = 0\r\n\r\n def add_child(self, n):\r\n #self.childs.append(n)\r\n n.parent = self\r\n n.height = self.height + 1\r\n\r\n\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nt = Tree()\r\n\r\nfor l in a:\r\n t.add(l)\r\n\r\n\r\nprint(sum(t.nodes[0].oddity))", "import sys\r\nfrom math import sqrt, gcd, ceil, log\r\n# from bisect import bisect, bisect_left\r\nfrom collections import defaultdict, Counter, deque\r\n# from heapq import heapify, heappush, heappop\r\ninput = sys.stdin.readline\r\nread = lambda: list(map(int, input().strip().split()))\r\n\r\nsys.setrecursionlimit(10**6)\r\n\r\n\r\ndef main():\r\n\tn = int(input()); par = read()\r\n\tadj = defaultdict(list)\r\n\tfor i in range(n-1):\r\n\t\tadj[par[i]].append(i+2)\r\n\t# print(adj)\r\n\tlvl = [1]\r\n\tans = 0\r\n\twhile lvl:\r\n\t\tans += len(lvl)%2\r\n\t\tlvl = [j for i in lvl for j in adj[i]]\r\n\tprint(ans)\r\n\r\n\r\n\t\t\t\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()", "import threading\n\nimport sys\n\nthreading.stack_size(2 ** 26)\nsys.setrecursionlimit(10 ** 9)\n\nn = int(input())\ngraph = [[] for i in range(n)]\nprev = list(map(int, input().split()))\ns = [0] * n\n\n\ndef dfs(v, level):\n for u in graph[v]:\n dfs(u, level + 1)\n s[level] += 1\n\n\ndef main():\n ans = 0\n for i in range(n - 1):\n graph[prev[i] - 1].append(i + 1)\n dfs(0, 0)\n for i in s:\n if i % 2 != 0:\n ans += 1\n print(ans)\n\n\ntread = threading.Thread(target=main)\ntread.start()\n", "import sys\r\n\r\nTEST_MODE = False\r\n\r\n\r\ndef test_mode(filename):\r\n def inner(fun):\r\n def wrapper(*args, **kwargs):\r\n with open(filename) as file:\r\n temporary = sys.stdin\r\n sys.stdin = file\r\n fun(*args, **kwargs)\r\n sys.stdin = temporary\r\n\r\n global TEST_MODE\r\n if not TEST_MODE:\r\n return fun\r\n return wrapper\r\n return inner\r\n\r\n\r\nclass Node:\r\n def __init__(self, label, successor=None):\r\n self.label = label\r\n self.distance = 0\r\n self.successor = successor\r\n\r\n def __repr__(self):\r\n return str(self.label)\r\n\r\n\r\ndef dfs(nodes):\r\n for node in nodes[2:]:\r\n node.distance = node.successor.distance + 1\r\n\r\n\r\n@test_mode(\"test.txt\")\r\ndef main():\r\n n = int(input())\r\n tab = [int(x) for x in input().split()]\r\n nodes = [None, Node(1)]\r\n for i in range(n-1):\r\n nodes.append(Node(i+2, nodes[tab[i]]))\r\n dfs(nodes)\r\n distances = n*[0]\r\n distances[0] = 1\r\n for node in nodes[2:]:\r\n distances[node.distance] ^= 1\r\n print(sum(distances))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\ndp = dict()\ncnt = dict()\ndp[1] = 1\ncnt[1] = 1\np = list(map(int, input().split()))\nfor i in range(0, n-1):\n\tdp[i+2] = dp[p[i]]+1\n\tif dp[i+2] in cnt:\n\t\tcnt[dp[i+2]]+=1\n\telse:\n\t\tcnt[dp[i+2]] = 1\nans = 0\nfor k, v in cnt.items():\n\tif v%2 == 1:\n\t\tans+=1\nprint(ans)\n", "import sys\nimport itertools as it\nimport math\n\nn = int(sys.stdin.readline())\np = list(map(int, sys.stdin.readline().split()))\n\n\n\nlevel = dict()\nlevel[1] = 1\n\nfor k in range(len(p)):\n level[k+2] = level[p[k]]+1\n\nlevel_cnt = dict()\nfor v in level.values():\n level_cnt.setdefault(v,0)\n level_cnt[v]+=1\n\nr = sum(map(lambda e: e%2, level_cnt.values()))\n\nprint(r)", "import sys\nfrom collections import defaultdict\nfrom collections import deque\ninput = sys.stdin.readline\n \n\ndef solve(parents, n):\n childs = defaultdict(list)\n \n for i in range(n-1):\n childs[parents[i]].append(i+1)\n \n root = 0\n nodes = [root]\n cnt = 0\n\n while nodes:\n cnt += len(nodes) % 2\n temp_nodes = []\n for node in nodes:\n for child in childs[node]:\n temp_nodes.append(child)\n nodes = temp_nodes\n return cnt \n \nif __name__ == \"__main__\":\n n = int(input())\n parents = [int(el)-1 for el in input().split()]\n print(solve(parents, n))\n\n", "SZ = 100010\r\ng = [[] for i in range(SZ)]\r\nh = [0] * SZ\r\nd = [0] * SZ\r\nn = int(input())\r\np = [int(i) for i in input().split()]\r\nfor i in range(len(p)):\r\n g[p[i]].append(i + 2)\r\n \r\ns = [1]\r\nd[1] = 0\r\nwhile len(s):\r\n v = s[-1]\r\n s.pop()\r\n for u in g[v]:\r\n d[u] = d[v] + 1\r\n s.append(u)\r\n h[d[v]] += 1\r\n \r\nsm = 0\r\nfor i in range(SZ):\r\n sm += h[i] % 2\r\nprint(sm)\r\n \r\n", "n = int(input())\nP = [0, 0] + list(map(int, input().split()))\ndeep = [0] * (n + 1)\nsons = []\nfor _ in range(n + 1):\n sons.append(set())\nfor i in range(2, n + 1):\n sons[P[i]].add(i)\ncnt = 1\ns1 = {1}\ns2 = set()\nwhile s1:\n for v in s1:\n for u in sons[v]:\n s2.add(u)\n deep[u] = cnt\n s1 = s2\n s2 = set()\n cnt += 1\nJ = dict()\nans = 0\nfor i in deep:\n if i not in J:\n J[i] = 0\n J[i] += 1\nfor a in J:\n ans += J[a] % 2\nprint(ans + 1)", "n=int(input())\r\na=[*map(int,input().split())]\r\nq={}\r\nfor i in range(1,n+1):\r\n q[i]=0\r\nfor i in range(n-1):\r\n q[i+2]=q[a[i]]+1\r\nz={}\r\nfor i in q.values():\r\n z[i]=z.get(i,0)+1\r\nprint(sum(z[i]%2 for i in z))", "n=int(input())\r\nm=[0]+[0]+list(map(int,input().split()))\r\np=[[] for i in range(n+1)]\r\nfor i in range(2,n+1):\r\n p[m[i]]+=[i]\r\ndef wide():\r\n stack=[]\r\n addto=[1]\r\n ans=0\r\n while addto:\r\n stack,addto=addto,[]\r\n if len(stack)%2:\r\n ans+=1\r\n while stack:\r\n addto.extend(p[stack.pop()])\r\n print(ans)\r\nwide()", "n = int(input())\r\np = list(map(int, input().split(\" \")))\r\n\r\nadj_list = {i: [] for i in range(1, n + 1)}\r\nfor i in range(len(p)):\r\n adj_list[p[i]].append(i + 2)\r\n\r\ndep = [0] * (n + 1)\r\ns = [(1, 1)]\r\nwhile len(s) > 0:\r\n x, d = s.pop()\r\n dep[d] += 1\r\n for i in adj_list[x]:\r\n s.append((i, d + 1))\r\n\r\nprint(sum(i % 2 for i in dep))", "n = int(input())\r\nc = [0] * 1000003\r\nc[0] = 1\r\nans = 0\r\na = [0] * 1000003\r\nd = [0] * 1000003\r\nsequence = list(map(int, input().split()))\r\nfor i in range(2, n + 1):\r\n a[i] = sequence[i - 2] \r\n d[i] = d[a[i]] + 1\r\n c[d[i]] += 1\r\nfor i in range(1000001):\r\n if c[i] % 2 != 0:\r\n ans += 1\r\nprint(ans)# 1698174944.4217854", "import sys\n\nn = int(input())\nb = list(map(int, sys.stdin.readline().split()))\nx = [[] for _ in range(n + 1)]\nfor i, bi in enumerate(b):\n x[bi].append(i + 2)\n\nq = []\nd = [0, ] * n\nh = 0\n\nq.append((1, 0))\nd[0] += 1\n\nwhile h < len(q):\n e = q[h]\n h += 1\n\n for xi in x[e[0]]:\n q.append((xi, e[1] + 1))\n d[e[1] + 1] = (d[e[1] + 1] + 1) % 2\n\nprint(sum(d))\n", "from collections import deque, Counter\r\nn=int(input())\r\nw=[int(k) for k in input().split()]\r\nzeta=[0 for j in range(n+1)]\r\nq={}\r\nfor j in range(n-1):\r\n if w[j] in q:\r\n q[w[j]].append(j+2)\r\n else:\r\n q[w[j]]=[j+2]\r\nres=0\r\n#print(q)\r\nnew=deque([1])\r\nwhile new:\r\n x=new.pop()\r\n if x in q:\r\n for j in q[x]:\r\n zeta[j]=zeta[x]+1\r\n new.appendleft(j)\r\nc=Counter(zeta)\r\nfor j in c.keys():\r\n if j!=0:\r\n res+=c[j]%2\r\nprint(res+1)\r\n#print(zeta)", "n = int(input())\n*p, = map(int, input().split())\n\nroot_lens = [0] * n\nfor i in range(n - 1):\n root_lens[i + 1] = root_lens[p[i] - 1] + 1\n\ndict_lens = {}\nfor i in range(n):\n dict_lens.setdefault(root_lens[i], 0)\n dict_lens[root_lens[i]] += 1\n\nprint(sum(v % 2 for v in dict_lens.values()))\n# Thu Jan 07 2021 09:19:48 GMT+0300 (Москва, стандартное время)\n" ]
{"inputs": ["3\n1 1", "5\n1 2 2 2", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4", "2\n1", "3\n1 2", "20\n1 1 1 1 1 4 1 2 4 1 2 1 7 1 2 2 9 7 1", "20\n1 2 1 2 2 1 2 4 1 6 2 2 4 3 2 6 2 5 9", "20\n1 1 1 4 2 4 3 1 2 8 3 2 11 13 15 1 12 13 12", "20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 15", "20\n1 2 3 4 5 6 7 8 9 6 11 12 12 7 13 15 16 11 13", "10\n1 1 1 2 1 3 4 2 1", "30\n1 1 1 2 1 2 1 1 2 1 1 1 2 2 4 3 6 2 3 5 3 4 11 5 3 3 4 7 6", "40\n1 1 1 1 1 1 1 1 1 3 4 3 3 1 3 6 7 4 5 2 4 3 9 1 4 2 5 3 5 9 5 9 10 12 3 7 2 11 1", "50\n1 1 1 1 1 2 3 3 2 1 1 2 3 1 3 1 5 6 4 1 1 2 1 2 1 10 17 2 2 4 12 9 6 6 5 13 1 3 2 8 25 3 22 1 10 13 6 3 2", "10\n1 1 1 1 2 1 3 4 3", "30\n1 2 1 1 1 2 1 4 2 3 9 2 3 2 1 1 4 3 12 4 8 8 3 7 9 1 9 19 1", "40\n1 1 1 2 3 1 2 1 3 7 1 3 4 3 2 3 4 1 2 2 4 1 7 4 1 3 2 1 4 5 3 10 14 11 10 13 8 7 4", "50\n1 2 1 1 1 3 1 3 1 5 3 2 7 3 6 6 3 1 4 2 3 10 8 9 1 4 5 2 8 6 12 9 7 5 7 19 3 15 10 4 12 4 19 5 16 5 3 13 5", "10\n1 1 1 2 3 2 1 2 3", "30\n1 1 1 1 2 1 4 4 2 3 2 1 1 1 1 3 1 1 3 2 3 5 1 2 9 16 2 4 3", "40\n1 1 1 2 1 2 1 2 4 8 1 7 1 6 2 8 2 12 4 11 5 5 15 3 12 11 22 11 13 13 24 6 10 15 3 6 7 1 2", "50\n1 1 1 1 3 4 1 2 3 5 1 2 1 5 1 10 4 11 1 8 8 4 4 12 5 3 4 1 1 2 5 13 13 2 2 10 12 3 19 14 1 1 15 3 23 21 12 3 14", "10\n1 1 1 1 2 4 1 1 3", "30\n1 1 1 1 3 3 2 3 7 4 1 2 4 6 2 8 1 2 13 7 5 15 3 3 8 4 4 18 3", "40\n1 1 1 2 2 1 1 4 6 4 7 7 7 4 4 8 10 7 5 1 5 13 7 8 2 11 18 2 1 20 7 3 12 16 2 22 4 22 14", "50\n1 1 1 2 2 1 3 5 3 1 9 4 4 2 12 15 3 13 8 8 4 13 20 17 19 2 4 3 9 5 17 9 17 1 5 7 6 5 20 11 31 33 32 20 6 25 1 2 6", "10\n1 1 1 3 3 5 6 8 3", "30\n1 2 2 1 5 5 5 1 7 4 10 2 4 11 2 3 10 10 7 13 12 4 10 3 22 25 8 1 1", "40\n1 2 2 2 2 4 2 2 6 9 3 9 9 9 3 5 7 7 2 17 4 4 8 8 25 18 12 27 8 19 26 15 33 26 33 9 24 4 27", "50\n1 1 3 3 4 5 5 2 4 3 9 9 1 5 5 7 5 5 16 1 18 3 6 5 6 13 26 12 23 20 17 21 9 17 19 34 12 24 11 9 32 10 40 42 7 40 11 25 3", "10\n1 2 1 2 5 5 6 6 6", "30\n1 1 3 3 5 6 7 5 7 6 5 4 8 6 10 12 14 9 15 20 6 21 14 24 17 23 23 18 8", "40\n1 2 2 3 1 2 5 6 4 8 11 12 9 5 12 7 4 16 16 15 6 22 17 24 10 8 22 4 27 9 19 23 16 18 28 22 5 35 19", "50\n1 2 3 4 5 5 5 7 1 2 11 5 7 11 11 11 15 3 17 10 6 18 14 14 24 11 10 7 17 18 8 7 19 18 31 27 21 30 34 32 27 39 38 22 32 23 31 48 25", "10\n1 2 2 4 5 5 6 4 7", "30\n1 2 3 3 5 6 3 8 9 10 10 10 11 7 8 8 15 16 13 13 19 12 15 18 18 24 27 25 10", "40\n1 2 3 4 5 6 6 8 7 10 11 3 12 11 15 12 17 15 10 20 16 20 12 20 15 21 20 26 29 23 29 30 23 24 35 33 25 32 36", "50\n1 2 2 2 5 6 7 7 9 10 7 4 5 4 15 15 16 17 10 19 18 16 15 24 20 8 27 16 19 24 23 32 17 23 29 18 35 35 38 35 39 41 42 38 19 46 38 28 29", "10\n1 2 3 4 5 5 5 7 9", "30\n1 2 3 4 5 6 5 3 6 7 8 11 12 13 15 15 13 13 19 10 14 10 15 23 21 9 27 22 28", "40\n1 2 2 3 3 6 5 5 9 7 8 11 13 7 10 10 16 14 18 20 11 19 23 18 20 21 25 16 29 25 27 31 26 34 33 23 36 33 32", "50\n1 2 2 4 5 5 7 6 9 10 11 12 13 7 14 15 14 17 10 14 9 21 23 23 19 26 19 25 11 24 22 27 26 34 35 30 37 31 38 32 40 32 42 44 37 21 40 40 48", "10\n1 2 3 4 3 6 6 6 7", "30\n1 2 2 4 5 6 5 7 9 6 4 12 7 14 12 12 15 17 13 12 8 20 21 15 17 24 21 19 16", "40\n1 2 3 4 4 6 6 4 9 9 10 12 10 12 12 16 8 13 18 14 17 20 21 23 25 22 25 26 29 26 27 27 33 31 33 34 36 29 34", "50\n1 2 3 3 4 3 6 7 8 10 11 10 12 11 11 14 13 8 17 20 21 19 15 18 21 18 17 23 25 28 25 27 29 32 32 34 37 29 30 39 41 35 24 41 37 36 41 35 43", "99\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", "99\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "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"], "outputs": ["1", "3", "4", "2", "3", "2", "2", "4", "4", "8", "2", "4", "2", "4", "2", "2", "2", "2", "2", "2", "2", "4", "2", "2", "4", "4", "4", "6", "4", "6", "2", "2", "4", "2", "2", "6", "8", "6", "8", "4", "6", "10", "4", "4", "10", "10", "1", "99", "2", "100"]}
UNKNOWN
PYTHON3
CODEFORCES
60
1f5ecc480ea7750a08db8a7787697704
Cupboards
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*. The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces. In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. Sample Input 5 0 1 1 0 0 1 1 1 0 1 Sample Output 3
[ "n = int(input())\r\ncountofopenleft = 0\r\ncountofopenright = 0\r\nfor _ in range(n):\r\n l,r = input().split()\r\n if l=='1':\r\n countofopenleft +=1\r\n if r=='1':\r\n countofopenright+=1\r\n\r\ncountofcloseleft = n- countofopenleft\r\ncountofcloseright = n - countofopenright\r\ntotalmoves = min(countofcloseleft,countofopenleft)+min(countofopenright, countofcloseright)\r\nprint(totalmoves)\r\n ", "n=int(input())\r\nu=v=0\r\nfor i in range(n):\r\n a,b =map(int, input().split())\r\n u+=a\r\n v+=b\r\nx=min(u,n-u)\r\ny=min(v,n-v)\r\nprint(x+y)\r\n\r\n", "t=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(t):\r\n l1,r1=list(map(int, input().split()))\r\n l.append(l1)\r\n r.append(r1)\r\nl0=l.count(0)\r\nl1=l.count(1)\r\nr0=r.count(0)\r\nr1=r.count(1)\r\nprint(min(l0,l1)+min(r0,r1))", "n = int(input())\r\nlefto=0\r\nrighto=0\r\ns=0\r\nfor i in range(0,n):\r\n inputs = [(num) for num in input().split()]\r\n if(inputs[0]==\"1\"):\r\n lefto+=1\r\n if(inputs[1]==\"1\"):\r\n righto+=1\r\nif(lefto>int(n/2)):\r\n s+=n-lefto\r\nelse:\r\n s+=lefto\r\nif(righto>int(n/2)):\r\n s+=n-righto\r\nelse:\r\n s+=righto\r\nprint(s)\r\n", "t=input()\r\nl=''\r\nr=''\r\nfor i in range(0,int(t)):\r\n c=input()\r\n x,y=c.split(' ')\r\n l+=x\r\n r+=y\r\nli=(l.count('0'),l.count('1'),r.count('0'),r.count('1'))\r\nli=sorted(li)\r\nprint(li[0]+li[1])", "n = int(input())\r\nleft_doors_opened = right_doors_opened = 0\r\n\r\nfor _ in range(n):\r\n l, r = input().split()\r\n if l == '1':\r\n left_doors_opened += 1\r\n if r == '1':\r\n right_doors_opened += 1\r\n\r\nprint(min(left_doors_opened, n - left_doors_opened) + min(right_doors_opened, n - right_doors_opened))\r\n", "nb_cabs = int(input())\r\nl, r = 0, 0\r\nfor _ in range(nb_cabs):\r\n a, b = [int(x) for x in input().split()]\r\n l+= a\r\n r+= b\r\nprint(min(l, nb_cabs-l) + min(r, nb_cabs-r))\r\n", "n=int(input())\r\na,b,c,d=0,0,0,0\r\nfor i in range( n):\r\n e,f=map(int,input().split())\r\n if e==0:\r\n a+=1\r\n else:\r\n b+=1\r\n if f==0:\r\n c+=1\r\n else:\r\n d+=1\r\nprint(min(a,b)+min(c,d))", "n = int(input())\nl = []\nr = []\nfor i in range(n):\n a = list(map(int, input().rstrip().split()))\n l += [a[0]]\n r += [a[1]]\nprint(min(l.count(0), l.count(1)) + min(r.count(0), r.count(1)))\n", "n = int(input())\r\ncountl0,countl1 = 0,0\r\ncountr0,countr1 = 0,0\r\nfor i in range(n):\r\n l,r = map(int, input().split())\r\n if l==0:\r\n countl0 += 1\r\n else:\r\n countl1 += 1\r\n if r==0:\r\n countr0 += 1\r\n else:\r\n countr1 += 1\r\nprint(min(countr1,countr0) + min(countl0,countl1))", "n = int(input())\r\nl_cnt = 0\r\nr_cnt = 0\r\nfor _ in range(n):\r\n counts = list(map(int, input().split()))\r\n l_cnt += counts[0]\r\n r_cnt += counts[1]\r\n\r\ntotal = min(l_cnt, n - l_cnt) + min(r_cnt, n - r_cnt)\r\nprint(total)\r\n", "t = int(input())\r\nleft = 0\r\nright = 0\r\nans = 0\r\nfor i in range(t):\r\n l, r = map(int, input().split())\r\n left += l\r\n right += r\r\n \r\nans += min(t-left, left-0)\r\nans += min(t-right, right)\r\nprint(ans)\r\n", "n = int(input())\r\nleftOpen, rightOpen = 0, 0\r\nfor i in range(n):\r\n left, right = [int(x) for x in input().split()]\r\n if left == 0:\r\n leftOpen += 1\r\n if right == 0:\r\n rightOpen += 1\r\n\r\nres = min(leftOpen, n - leftOpen) + min(rightOpen, n - rightOpen)\r\nprint(res)", "n=int(input())\r\na,b=zip(*(input().split() for _ in ' '*n))\r\nprint(min(a.count('1'),a.count('0')) + min(b.count('0'),b.count('1')))", "n=int(input())\r\na=[]\r\nb=[]\r\nc=0\r\nma=0\r\nmb=0\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n a.append(x)\r\n b.append(y)\r\nfor i in range(n):\r\n ma+=a[i]\r\n mb+=b[i]\r\n\r\n\r\nif (n-ma) < ma:\r\n c += (n-ma)\r\nelse:\r\n c += ma\r\nif(n-mb) < mb:\r\n c += (n-mb)\r\nelse:\r\n c += mb\r\n\r\nprint(c)\r\n", "n = int(input())\nlo, lc, ro, rc = (0, 0, 0, 0)\nwhile n:\n n -= 1\n l, r = map(int, input().split())\n if l:\n lo += 1\n else:\n lc += 1\n if r:\n ro += 1\n else:\n rc +=1\n \nprint(min(rc, ro) + min(lc, lo))\n", "# n = int(input())\r\n# cnt = 0\r\n# for _ in range(n):\r\n# arr = list(map(int,input().split()))\r\nn = int(input())\r\na = 0\r\nb = 0\r\nfor _ in range(n):\r\n l,r = list(map(int,input().split()))\r\n a += l\r\n b += r\r\nprint(min(a,n-a)+min(b,n-b))\r\n", "n=int(input())\r\nlCup=[]\r\nrCup=[]\r\nopen=0\r\nclosed=0\r\nleft=0\r\nright=0\r\nwhile n:\r\n l,*r=input().split(' ')\r\n lCup.append(int(l))\r\n rCup.append(int(*r))\r\n n-=1\r\nfor i in lCup:\r\n if i==0:\r\n closed+=1\r\n else:\r\n open+=1\r\nleft = min(closed, open)\r\nclosed=0\r\nopen=0\r\nfor x in rCup:\r\n if x==0:\r\n closed+=1\r\n else:\r\n open+=1\r\nright = min(closed, open)\r\nprint(left+right)\r\n", "n=int(input())\r\nl1=[]\r\nl2=[n]\r\nfor i in range(n):\r\n a,b=map(int,input().split(\" \"))\r\n l1.append(a)\r\n l2.append(b)\r\nprint(min(l1.count(0),l1.count(1))+min(l2.count(0),l2.count(1)))", "def cupboards(N, arr):\r\n l0,l1 = 0, 0\r\n r0,r1 = 0, 0\r\n \r\n for i in arr:\r\n if i[0] == 0:\r\n l0 += 1\r\n else:\r\n l1 += 1\r\n \r\n if i[1] == 0:\r\n r0 += 1\r\n else:\r\n r1 += 1\r\n \r\n left = N-l0 if l0>l1 else N-l1\r\n right = N-r0 if r0>r1 else N-r1\r\n ans = left + right\r\n \r\n return ans\r\n\r\nif __name__ == \"__main__\":\r\n N = int(input())\r\n arr = []\r\n \r\n for _ in range(N):\r\n li = list(map(int, input().split()))\r\n arr.append(li)\r\n \r\n ans = cupboards(N, arr)\r\n print(ans)", "n=int(input())\r\nl=[0]*n\r\nr=[0]*n\r\nfor i in range(n):\r\n l[i],r[i]=map(int,input().split())\r\nlc=l.count(0)\r\nrc=r.count(0)\r\nlc=min(lc,n-lc)\r\nrc=min(rc,n-rc)\r\nprint(lc+rc)", "n = int(input())\r\nlzero = lone = rzero = rone = 0\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n\r\n if a == 0:\r\n lzero = lzero + 1\r\n if a == 1:\r\n lone += 1\r\n if b == 0:\r\n rzero += 1\r\n if b == 1:\r\n rone += 1\r\n\r\nprint(min(rone, rzero) + min(lzero, lone))\r\n\r\n", "t=int(input())\r\na,b,c,d=0,0,0,0\r\nfor i in range(t):\r\n l,r=map(int,input().split())\r\n if l==0:\r\n a+=1\r\n else:\r\n b+=1\r\n if r==0:\r\n c+=1\r\n else:\r\n d+=1\r\n if a>b:\r\n m=b\r\n else:\r\n m=a\r\n if c>d:\r\n n=d\r\n else:\r\n n=c\r\nprint(m+n)", "a, ans = [], 0\r\nfor i in range(int(input())):\r\n a.extend(input().split())\r\nprint(min(a[::2].count('0'), a[::2].count('1')) + min(a[1::2].count('0'), a[1::2].count('1')))", "n = int(input())\r\nl = list()\r\nr = list()\r\n\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n l.append(a)\r\n r.append(b)\r\n\r\nres = min(l.count(1), l.count(0)) + min(r.count(1), r.count(0))\r\n\r\nprint(res)\r\n", "n = int(input())\r\nleft = []\r\nright = []\r\nfor i in range(n):\r\n l, r = [int(i) for i in input().split()]\r\n left.append(l)\r\n right.append(r)\r\nres = left.count(0) if left.count(0) < left.count(1) else left.count(1)\r\nres += right.count(0) if right.count(0) < right.count(1) else right.count(1)\r\nprint(res)", "n=int(input())\r\nx=y=0\r\nfor i in range(n):\r\n li,ri=map(int,input().split())\r\n x+=li\r\n y+=ri\r\nprint(min(x,n-x)+min(y,n-y))\r\n", "import sys\r\nimport math\r\n\r\n#to read string\r\nget_string = lambda: sys.stdin.readline().strip()\r\n#to read list of integers\r\nget_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )\r\n#to read non spaced string and elements are integers to list of int\r\nget_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))\r\n#to read non spaced string and elements are character to list of character\r\nget_charList_from_str = lambda: list(sys.stdin.readline().strip())\r\n#get word sepetared list of character\r\nget_char_list = lambda: sys.stdin.readline().strip().split() \r\n#to read integers\r\nget_int = lambda: int(sys.stdin.readline())\r\n#to print faster\r\npt = lambda x: sys.stdout.write(str(x))\r\n\r\n#--------------------------------WhiteHat010--------------------------------#\r\nn = get_int()\r\nleft = [1]*n\r\nright = [1]*n\r\nfor i in range(n):\r\n left[i],right[i] = get_int_list()\r\nl = min( left.count(0), left.count(1) )\r\nr = min( right.count(0), right.count(1) )\r\nprint(l+r)", "left,right = [],[]\r\nfor i in range(int(input())):\r\n l,r = input().split()\r\n left.append(l)\r\n right.append(r) \r\nprint(min(left.count('1'),left.count('0'))+min(right.count('1'),right.count('0')))\r\n ", "a=int(input())\r\nsayacm=0\r\nsayacn=0\r\nhamle=0\r\nfor i in range(a):\r\n m,n=input().split()\r\n if m == \"0\":\r\n sayacm=sayacm+1\r\n if n == \"0\":\r\n sayacn=sayacn+1\r\nif sayacm>=(a/2):\r\n hamle = hamle+(a-sayacm)\r\nif sayacm<(a/2):\r\n hamle = hamle +(sayacm)\r\nif sayacn>=(a/2):\r\n hamle = hamle+(a-sayacn)\r\nif sayacn<(a/2):\r\n hamle = hamle +(sayacn)\r\nprint(hamle)", "n = int(input())\r\nc = 0\r\nleft = []\r\nright = []\r\nfor i in range(n):\r\n arr = list(map(int, input().rstrip().split()))\r\n left.append(arr[0])\r\n right.append(arr[1])\r\n\r\n\r\ndef solve(l, r):\r\n t = 0\r\n if l.count(0) < l.count(1):\r\n t += l.count(0)\r\n\r\n else:\r\n t += l.count(1)\r\n\r\n if r.count(0) < r.count(1):\r\n t += r.count(0)\r\n\r\n else:\r\n t += r.count(1)\r\n print(t)\r\n\r\n\r\nsolve(left, right)\r\n", "n=int(input())\r\narr=[]\r\nfor _ in range(n):\r\n\tarr.append(list(map(int,input().split())))\r\nlz=0\r\nrz=0\r\nfor i in range(n):\r\n\tif(arr[i][0]==0):\r\n\t\tlz=lz+1\r\n\tif(arr[i][1]==0):\r\n\t\trz=rz+1\r\nprint(min(lz,n-lz)+min(rz,n-rz))\r\n", "n = int(input())\r\n\r\nleft = []\r\nright = []\r\nl_zeros = 0\r\nl_ones = 0\r\nr_zeros = 0\r\nr_ones = 0\r\n\r\nfor i in range(n):\r\n entry = input()\r\n left.append(entry[0])\r\n right.append(entry[2])\r\n\r\nfor elem in left:\r\n if elem == '0':\r\n l_zeros += 1\r\n else:\r\n l_ones += 1\r\n\r\nfor elem in right:\r\n if elem == '0':\r\n r_zeros += 1\r\n else:\r\n r_ones += 1\r\n \r\nseconds = 0\r\nif l_zeros != n or l_ones != n:\r\n if l_zeros < l_ones:\r\n \tseconds += l_zeros\r\n else:\r\n \tseconds += l_ones\r\n\r\nif r_zeros != n or r_ones != n:\r\n if r_zeros < r_ones:\r\n \tseconds += r_zeros\r\n else:\r\n \tseconds += r_ones\r\n\r\nprint(seconds) ", "n = int(input())\r\nlt,rt=[],[]\r\nfor _ in range(n):\r\n l,r = map(int,input().split())\r\n lt.append(l)\r\n rt.append(r)\r\n\r\nltc = lt.count(1)\r\nrtc = rt.count(1)\r\nres=0\r\n\r\nres = min(ltc,n-ltc)\r\nres+=min(rtc,n-rtc)\r\nprint(res)\r\n \r\n", "n=int(input())\r\nc=[]\r\nd=[]\r\nfor x in range(0,n):\r\n a,b=map(int,input().split(\" \"))\r\n c.append(a)\r\n d.append(b)\r\ne=0\r\nf=0\r\nif c.count(1)>=c.count(0):\r\n e=c.count(0)\r\nelse:\r\n e=c.count(1)\r\nif d.count(1)>=d.count(0):\r\n f=d.count(0)\r\nelse:\r\n f=d.count(1)\r\nprint(e+f)", "n = int(input())\nleft = {0:0, 1:0}\nright = {0:0, 1:0}\nfor i in range(n):\n arr = input().split(' ')\n if int(arr[0]) == 0:\n left[0]+=1\n else:\n left[1]+=1\n if int(arr[1]) == 0:\n right[0]+=1\n else:\n right[1]+=1\nres = min(left[0],left[1])+min(right[0],right[1])\nprint(res)\n ", "n = int(input())\r\nl, r = [0, 0], [0, 0]\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n l[x] += 1\r\n r[y] += 1\r\nprint(min(l) + min(r))", "def fn(l):\r\n if l.count(0)>l.count(1):\r\n return l.count(1)\r\n else:\r\n return l.count(0)\r\n \r\nn=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n a,b=input().split()\r\n l.append(int(a))\r\n r.append(int(b))\r\nc=0\r\nc+=fn(l)\r\nc+=fn(r)\r\nprint(c)", "x=y=0\r\nn=int(input())\r\nexec(\"a,b=map(int,input().split());x+=a;y+=b;\"*n)\r\nprint(min(n-x,x)+min(n-y,y))", "right = {0: 0, 1: 0}\r\nleft = {0: 0, 1: 0}\r\nNumberOftest = int(input())\r\n\r\nfor i in range(NumberOftest):\r\n l, r = map(int, input().split())\r\n\r\n left[l] += 1\r\n right[r] += 1\r\ncount = 0\r\n\r\nif right[0] >= right[1]:\r\n count += right[1]\r\nelse:\r\n count += right[0]\r\n\r\nif left[0] >= left[1]:\r\n count += left[1]\r\nelse:\r\n count += left[0]\r\nprint(count)\r\n\r\n", "l = []\r\nr = []\r\nfor _ in range(int(input())):\r\n a, b = input().split()\r\n l.append(a)\r\n r.append(b)\r\n\r\nl = min(l.count('0'), l.count('1'))\r\nr = min(r.count('0'), r.count('1'))\r\n\r\nprint(l + r)", "n = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n\ta,b = map(int, input().split())\r\n\tl.append(a)\r\n\tr.append(b)\r\n \r\nx = min(l.count(0),l.count(1))\r\ny = min(r.count(0),r.count(1))\r\n \r\nprint(x+y)", "n = int(input())\r\nldoors = {'0':0, '1':0}\r\nrdoors = {'0':0, '1':0}\r\n\r\n\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n ldoors[str(a)]+=1\r\n rdoors[str(b)]+=1\r\n \r\nprint(min(ldoors.values())+min(rdoors.values()))", "n=int(input())\r\nl=[0]*2\r\nr=[0]*2\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n l[x]+=1\r\n r[y]+=1\r\nprint(min(l)+min(r))", "n = int(input())\nleft = [0, 0]\nright = [0, 0]\n\nfor i in range(n):\n a, b = input().split()\n a = int(a)\n b = int(b)\n left[a] += 1\n right[b] += 1\n\nl = min(left[0], left[1])\nr = min(right[0], right[1])\n\nprint(l + r)\n \t \t \t \t\t\t \t \t\t \t\t\t\t", "left_open = 0\r\nleft_closed = 0\r\nright_open = 0\r\nright_closed = 0\r\n\r\nfor _ in range(int(input())):\r\n left, right = map(int,input().split())\r\n if left == 0:\r\n left_closed += 1\r\n else:\r\n left_open += 1\r\n if right == 0:\r\n right_closed += 1\r\n else:\r\n right_open += 1\r\n\r\nprint(min(left_open,left_closed) + min(right_open,right_closed))\r\n", "n = int(input())\nloff, lon, roff, ron = 0, 0, 0, 0\nfor _ in range(n):\n l, r = map(int, input().split())\n if l == 0: loff += 1\n if l == 1: lon += 1\n if r == 0: roff += 1\n if r == 1: ron += 1\nprint(min(loff, lon) + min(roff, ron))\n \t \t\t\t \t\t \t\t\t\t\t\t \t\t \t", "n = int(input())\n\ndoors = []\n\nfor i in range(n):\n l,r = map(int,input().split())\n doors.append((l,r))\n\n left0,left1,right0,right1 = 0,0,0,0\n\nfor i in range(n):\n if doors[i][0] == 0:\n left0 += 1\n else:\n left1 += 1\n\n if doors[i][1] == 0:\n right0 += 1\n else:\n right1 += 1 \n\n\nprint( min(left0,left1)+min(right0,right1) )\n\n", "n = int(input())\r\n\r\nleft = []\r\nright = []\r\n\r\nsecs = 0\r\n\r\nfor i in range(0,n):\r\n arr = a,b = [int(x) for x in input().split()]\r\n left.append(a)\r\n right.append(b)\r\n\r\nl_one = left.count(1)\r\nl_zero = left.count(0)\r\nr_one = right.count(1)\r\nr_zero = right.count(0)\r\n\r\nln = len(left)\r\n\r\nsecs += ln - max(l_one,l_zero)\r\nsecs += ln - max(r_one,r_zero)\r\n\r\nprint(secs)", "n = int(input())\nx0 = 0\nx1 = 0\ny0 = 0\ny1 = 0\nfor i in range(n):\n x, y = map(int, input().split())\n if x == 0:\n x0 += 1\n else:\n x1 += 1\n\n if y == 0:\n y0 += 1\n else:\n y1 += 1\n\nprint(min(x0, x1)+min(y0, y1))\n", "n=int(input())\r\ncount01=0\r\ncount10=0\r\ncount11=0\r\ncount00=0\r\nfor _ in range(n):\r\n l,r=map(int,input().split())\r\n if l==0 and r==1:\r\n count01+=1\r\n elif l==1 and r==0:\r\n count10+=1\r\n elif l==1 and r==1:\r\n count11+=1\r\n elif l==0 and r==0:\r\n count00+=1\r\n\r\nprint(min(count10*2+count11+count00,count01*2+count11+count00,count10+count01+count11*2,count10+count01+count00*2))\r\n\r\n\r\n", "n=int(input())\r\narr = []\r\nldc = 0\r\nldo = 0\r\nrdc = 0\r\nrdo = 0\r\nfor i in range(n):\r\n el = [int(x) for x in input().split()]\r\n if(el[0]==0): ldc += 1\r\n else: ldo += 1\r\n \r\n if(el[1]==0): rdc += 1\r\n else: rdo += 1\r\n \r\n # arr.append(el)\r\nminl=ldc\r\nminr=rdc\r\nif(ldc >= ldo):\r\n minl=ldo\r\nif(rdc >= rdo):\r\n minr=rdo\r\nprint(minl+minr)", "t = int(input())\r\nl = [0,0]\r\nr = [0,0]\r\nwhile(t>0):\r\n temp = input().split()\r\n if temp[0] == '0':\r\n l[0] += 1\r\n else:\r\n l[1] +=1\r\n \r\n if temp[1] == '0':\r\n r[0] += 1\r\n else:\r\n r[1] +=1\r\n t-=1\r\n \r\nprint(min(l)+min(r))\r\n ", "t=int(input())\r\nl,r=[],[]\r\nfor _ in range(t):\r\n x,y=map(int,input().split())\r\n l.append(x)\r\n r.append(y)\r\na=min(l.count(0),l.count(1))\r\nb=min(r.count(0),r.count(1))\r\nprint(a+b)", "n = int(input())\r\nleft = 0\r\nright = 0\r\nfor i in range(n):\r\n cupboard = input().split()\r\n left += int(cupboard[0])\r\n right += int(cupboard[1])\r\n\r\nprint(min(n-left, left) + min(n-right, right))\r\n", "n=int(input())\nw=x=y=z=0\nfor i in range(n):\n\ta,b=map(int, input().split())\n\tif a==0: w+=1\n\tif a==1: x+=1\n\tif b==0: y+=1\n\tif b==1: z+=1\n\tp=min(w,x)\n\tp+=min(y,z)\nprint(p)", "x = int(input())\r\ncnt1, cnt2 = 0, 0\r\nfor _ in range(x):\r\n a, b = map(int, input().split())\r\n cnt1 += a == 1\r\n cnt2 += b == 1\r\nprint(min(cnt1, x-cnt1)+min(cnt2, x-cnt2))", "n=int(input())\r\nc1=c2=0\r\nfor i in range(n):\r\n a,b =map(int, input().split())\r\n c1+=a\r\n c2+=b\r\nm=min(c1,n-c1)\r\nM=min(c2,n-c2)\r\nprint(m+M)\r\n\r\n", "N = int(input())\r\nleft = []\r\nright = []\r\nfor i in range(N):\r\n l , r = map(int , input().split(' '))\r\n left.append(l)\r\n right.append(r)\r\nreq =min(left.count(1),left.count(0)) +min(right.count(1) ,right.count(0))\r\nprint(req)", "n=int(input())\r\nl=[]\r\nfor i in range(0,n):\r\n l.append([int(i) for i in input().split()])\r\n# print(l)\r\nscol=list(zip(*l))\r\ns=0\r\nif scol[0].count(1)>scol[0].count(0):\r\n s=s+scol[0].count(0)\r\nelse:\r\n s=s+scol[0].count(1)\r\nif scol[1].count(1)>scol[1].count(0):\r\n s=s+scol[1].count(0)\r\nelse:\r\n s=s+scol[1].count(1)\r\nprint(s)", "n = int(input())\r\n\r\ncount_left = 0\r\ncount_right = 0\r\n\r\nfor _ in range(0, n):\r\n l, r = map(int, input().split())\r\n count_left += l\r\n count_right += r\r\n\r\nt = (n - count_left if count_left > n / 2 else count_left)\r\nt += (n - count_right if count_right > n / 2 else count_right)\r\nprint(t)", "n = int(input())\r\ncountL = [0,0]\r\ncountR = [0,0]\r\nfor i in range(n):\r\n a = input().split(' ')\r\n if a[0] == '0':\r\n countL[0] += 1\r\n else:\r\n countL[1] += 1\r\n if a[1] == '0':\r\n countR[0] += 1\r\n else:\r\n countR[1] += 1\r\nprint(min(countL) + min(countR))\r\n", "n=int(input())\r\na=[]\r\nfor _ in range(n):\r\n a.append(list(map(int,input().split())))\r\nx,y,p,q=0,0,0,0\r\nfor i in range(n):\r\n if a[i][0]==1:\r\n x+=1\r\n else:\r\n y+=1\r\n if a[i][1]==1:\r\n p+=1\r\n else:\r\n q+=1\r\nprint(min(p,q)+min(x,y))", "n = int(input())\r\nl_door = ''\r\nr_door = ''\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n l_door += str(l)\r\n r_door += str(r)\r\n\r\nprint((len(l_door) - max(l_door.count(\"1\"), l_door.count(\"0\"))) +\r\n (len(r_door) - max(r_door.count(\"1\"), r_door.count(\"0\"))))\r\n", "n=int(input())\r\na=b=0\r\nfor i in range(n):\r\n x,y =map(int, input().split())\r\n a+=x\r\n b+=y\r\nm=min(a,n-a)\r\nM=min(b,n-b)\r\nprint(m+M)\r\n\r\n", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nf = 0\r\ns = 0\r\n\r\nn = int(input())\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n f += a\r\n s += b\r\n\r\nprint(min(f, n - f) + min(s, n - s))", "n = int(input())\r\nleft = 0\r\nright = 0\r\nfor _ in range(n):\r\n l,r = map(int,input().split())\r\n left+=l\r\n right+=r\r\nprint(min(left,n-left)+min(right,n-right))\r\n", "n = int(input())\r\nld,rd = 0,0\r\nm = n\r\nwhile m:\r\n l,r = map(int, input().split())\r\n ld+=l\r\n rd+=r\r\n m-=1\r\nt = min(ld,abs(n-ld))+min(rd, abs(n-rd))\r\nprint(t)", "n=int(input())\r\nl=r=0\r\nfor _ in range(n):\r\n x,y=map(int,input().split())\r\n l+=x\r\n r+=y\r\nans=min(n-l,l)\r\nans+=min(n-r,r)\r\nprint(ans)", "n=int(input())\r\nla=[]\r\nlb=[]\r\nfor _ in range(n):\r\n a,b=map(int,input().split())\r\n la.append(a)\r\n lb.append(b)\r\nprint(min(la.count(1),la.count(0))+min(lb.count(1),lb.count(0)))", "n=int(input())\r\nl1_l=[]\r\nl1_r=[]\r\ni=1\r\nwhile i<=n:\r\n l2=[int(j) for j in input().split()]\r\n l1_l.append(l2[0])\r\n l1_r.append(l2[-1])\r\n i+=1\r\nao=l1_l.count(0)\r\nal=l1_l.count(1)\r\nbo=l1_r.count(0)\r\nbl=l1_r.count(1)\r\nprint(min(ao,al)+min(bo,bl))", "def solve():\n\tn = int(input())\n\t\n\tdoors = []\n\tl = 0\n\tr = 0\n\tt = 0\n\t\n\tfor i in range(n):\n\t\tdoors.append(list(map(int, input().split())))\n\t\t\n\tfor cb in doors:\n\t\tl += cb[0]\n\t\tr += cb[1]\n\t\t\n\tif l > (n / 2):\n\t\tfor cb in doors:\n\t\t\tif cb[0] == 0:\n\t\t\t\tt += 1\n\telse:\n\t\tfor cb in doors:\n\t\t\tif cb[0] == 1:\n\t\t\t\tt += 1\n\t\t\t\t\n\tif r > (n / 2):\n\t\tfor cb in doors:\n\t\t\tif cb[1] == 0:\n\t\t\t\tt += 1\n\telse:\n\t\tfor cb in doors:\n\t\t\tif cb[1] == 1:\n\t\t\t\tt += 1\n\t\n\tprint(t)\n\nif __name__ == '__main__':\n\tsolve()\n", "n=int(input())\r\na=[]\r\nleft=0 ##coutning number of 0\r\nright=0 ## coutning number of 0 in right\r\nfor i in range(n) :\r\n l,r=map(int,input().split())\r\n a.append([l,r])\r\n if l==0 :\r\n left+=1\r\n if r==0:\r\n right+=1\r\nresult=0 \r\nif left>n/2 :\r\n result+=n-left\r\nelse :\r\n result+=left\r\nif right>n/2:\r\n result+=n-right\r\nelse :\r\n result+=right\r\nprint (result)\r\n \r\n ", "import math\ndef solve(arr):\n count_0_l = 0\n count_1_l = 0\n count_0_r = 0\n count_1_r = 0\n for i in arr:\n if i[0] == 0:\n count_0_l+= 1\n else :\n count_1_l+=1\n if i[1] == 0:\n count_0_r+=1\n else:\n count_1_r+=1\n return min(count_0_l,count_1_l)+min(count_0_r,count_1_r)\n \n\ndef main():\n #arr =list(map(int,input().split(' ')))\n n = int(input())\n arr = []\n for j in range(n):\n i = list(map(int,input().split(' ')))\n # i = input().split(' ')\n #i = int(''.join(input().split(' ')))\n arr.append(i)\n print(solve(arr))\n\nmain()", "x=int(input())\r\na=[]\r\nb=[]\r\nn=0\r\nfor i in range(x):\r\n y=input()\r\n c=y[0]\r\n a.append(c)\r\n d=y[2]\r\n b.append(d)\r\np=0\r\nq=0\r\nfor i in a:\r\n if i==\"1\":\r\n p=p+1\r\n else:\r\n q=q+1\r\nif p>=q:\r\n n=n+q\r\nelse:\r\n n=n+p\r\np=0\r\nq=0\r\nfor i in b:\r\n if i==\"1\":\r\n p=p+1\r\n else:\r\n q=q+1\r\nif p>=q:\r\n n=n+q\r\nelse:\r\n n=n+p\r\nprint(n)", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor _ in range(n):\r\n a,b=[int(i) for i in input().split()]\r\n l.append(a)\r\n r.append(b)\r\nprint(min(l.count(0),l.count(1))+min(r.count(0),r.count(1)))", "from math import ceil,gcd,factorial\r\nimport queue\r\nimport re\r\nfrom collections import Counter,deque\r\nfrom sys import stdin,stdout\r\nfrom bisect import bisect,insort\r\ndef binpow(a,b,m):\r\n r=1\r\n while(b>0):\r\n if(b&1):\r\n r=(r*a)%m\r\n a=(a*a)%m\r\n b>>=1\r\n return b\r\ndef lcm(a,b):\r\n return (a//gcd(a,b))*b\r\n#gcd(a,b)=ax+by and \r\ndef gcdExtended(a, b): \r\n if(a==0): \r\n return b,0,1\r\n g,x1,y1=gcdExtended(b%a,a) \r\n x = y1 - (b//a) * x1 \r\n y = x1 \r\n return g, x, y\r\ndef dfs(graph,n,v):\r\n v[n]=1\r\n a=[n] \r\n b=[]\r\n l=1\r\n while(a!=[]):\r\n k=a.pop()\r\n b.append(k)\r\n for i in graph[k]:\r\n if(v[i]==0):\r\n v[i]=1\r\n a.append(i)\r\ndef bfs(graph,s,n,dest):\r\n v=[0]*n\r\n d=[0]*n\r\n v[s]=1\r\n q=queue.Queue()\r\n q.put(s)\r\n #p=[0]*n\r\n #p[s]=-1\r\n while(not q.empty()):\r\n l=q.get()\r\n for j in graph[l]:\r\n if(v[j]==0):\r\n v[j]=1\r\n q.put(j)\r\n d[j]=d[l]+1\r\n #p[j]=l\r\n path=[]\r\n x=dest#given\r\n while(x!=-1):\r\n path.append(x)\r\n x=p[x]\r\n path.reverse()\r\n return d\r\nc1=c2=c3=c4=0\r\nn=int(input())\r\nfor i in range(n):\r\n#n=int(input())\r\n #a=list(map(int,input().split()))\r\n a,b=map(int,input().split())\r\n if(a==0):\r\n c1+=1\r\n else:\r\n c2+=1\r\n if(b==0):\r\n c3+=1\r\n else:\r\n c4+=1\r\ns=min(c1,c2)\r\ns+=min(c3,c4)\r\nprint(s)\r\n\r\n \r\n\r\n", "l=0\r\nr=0\r\nn=int(input())\r\nfor _ in range(n):\r\n l1,r1=map(int, input().split())\r\n l+=l1\r\n r+=r1\r\nprint(min(l,n-l)+min(r,n-r))\r\n \r\n\r\n \r\n\r\n \r\n", "n=int(input())\r\n\r\narr=[]\r\nfor i in range(n):\r\n arr.append(list(map(int,input().split())))\r\nz0,z1,o1,o0=0,0,0,0 \r\nfor i in range(n): \r\n if(arr[i][0]==0):\r\n z0=z0+1\r\n else:\r\n o0=o0+1\r\n\r\nfor i in range(n):\r\n if(arr[i][1]==0):\r\n z1=z1+1\r\n else:\r\n o1=o1+1\r\n \r\nif(z0>o0):\r\n s=o0\r\nelse:\r\n s=z0\r\n \r\nif(z1>o1):\r\n t=o1\r\nelse:\r\n t=z1\r\n\r\nprint(s+t)\r\n ", "\r\nn = int(input())\r\na = []\r\nb = []\r\nz = 0\r\nfor i in range(n):\r\n x,y = map(int, input().split(\" \"))\r\n a.append(x)\r\n b.append(y)\r\n\r\na1,b1 = a.count(1),b.count(1)\r\n\r\nif a1<n-a1:\r\n z += a1\r\nelse:\r\n z += n-a1\r\nif b1<n-b1:\r\n z += b1\r\nelse:\r\n z += n-b1\r\n\r\n\r\nprint(z)", "import sys\r\n\r\ncupboards = int(input())\r\ndoors = []\r\ns = [line.rstrip('\\n') for line in sys.stdin.readlines()]\r\nfor item in s:\r\n item = doors.append(item.split())\r\n\r\nleft = 0\r\nright = 0\r\nfor door in doors:\r\n left += int(door[0])\r\n right += int(door[1])\r\n\r\ncombination_1 = left + right\r\ncombination_2 = 2 * cupboards - left - right\r\ncombination_3 = left + cupboards - right\r\ncombination_4 = right + cupboards - left\r\nchanges_to_make = min(combination_1, combination_2, combination_3, combination_4)\r\n\r\nprint(changes_to_make)", "n = int(input())\r\nright_open, right_close, left_open, left_close = 0, 0, 0, 0\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n if l == 1:\r\n left_open += 1\r\n if l == 0:\r\n left_close += 1\r\n if r == 1:\r\n right_open += 1\r\n if r == 0:\r\n right_close += 1\r\nprint(min(right_close, right_open) + min(left_close, left_open))", "n = int(input());\r\n\r\ncountl = {0: 0, 1: 0}\r\ncountr = {0: 0, 1: 0}\r\n\r\nfor i in range(n):\r\n\tl, r = tuple(map(int, input().split(\" \")));\r\n\r\n\tcountl[l] += 1\r\n\tcountr[r] += 1\r\n\r\nprint(min(countl[0], countl[1]) + min(countr[0], countr[1]))\r\n", "n = int(input())\na = b = 0\nfor i in range(n):\n x, y = map(int, input().split())\n a += x;\n b += y;\nprint(min(a, n-a) + min(b, n-b))\n\n", "n=int(input())\r\na,b=0,0\r\nfor _ in range(n):\r\n l,r=map(int,input().split())\r\n a+=l\r\n b+=r\r\n\r\nprint(min(a,n-a)+min(b,n-b))", "n = int(input())\r\n\r\nleft_open = 0\r\nleft_closed = 0\r\nright_open = 0\r\nright_closed = 0\r\n\r\nfor _ in range(n):\r\n li, ri = map(int, input().split())\r\n \r\n if li == 1:\r\n left_open += 1\r\n else:\r\n left_closed += 1\r\n \r\n if ri == 1:\r\n right_open += 1\r\n else:\r\n right_closed += 1\r\n \r\ntime_left = min(left_open, left_closed)\r\n\r\ntime_right = min(right_open, right_closed)\r\n\r\ntotal_time = time_left + time_right\r\n\r\nprint(total_time)", "n = int(input())\r\ndoors= []\r\nlzeros, lones, rzeros, rones = 0, 0, 0, 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n doors.append([l, r])\r\nt = 0\r\nfor x in doors:\r\n if x[0] == 0:\r\n lzeros +=1\r\n if x[1] == 0:\r\n rzeros +=1\r\n if x[0] == 1:\r\n lones +=1\r\n if x[1] == 1:\r\n rones +=1\r\n\r\nfor x in doors:\r\n if lzeros >= lones:\r\n if x[0] == 1:\r\n x[0] = 0\r\n t += 1\r\n if lones > lzeros:\r\n if x[0] == 0:\r\n x[0] = 1\r\n t += 1\r\n if rones >= rzeros:\r\n if x[1] == 0:\r\n x[1] = 1\r\n t+=1\r\n if rzeros > rones :\r\n if x[1] == 1:\r\n x[1] = 0\r\n t += 1\r\n\r\n\r\nprint(t)\r\n", "a, b = [], []\r\nfor i in range(int(input())):\r\n i, j = map(int, input().split())\r\n a.append(i)\r\n b.append(j)\r\nprint(min(a.count(0), a.count(1)) + min(b.count(0), b.count(1)))\r\n", "n = int(input())\nsl = 0\nsr = 0 \nfor _ in range(n):\n l, r = [int(x) for x in input().split()]\n sl+=l\n sr+=r\nml = min(sl, n-sl)\nmr = min(sr, n-sr)\nprint(ml+mr)\n\t \t\t \t\t \t\t\t\t \t \t\t\t \t \t\t\t\t", "n= int(input())\r\nc1=c2=0\r\nt=0\r\nfor i in range(n):\r\n x,y= [int(x) for x in input().split()]\r\n if x==1:\r\n c1+=1\r\n if y==1:\r\n c2+=1\r\nif c1<=n//2:\r\n t+=c1\r\nelse:\r\n t+=(n-c1)\r\nif c2<=n//2:\r\n t+=c2\r\nelse:\r\n t+=(n-c2)\r\n \r\nprint(t)", "def calculate_minimum_time(n, left_doors, right_doors):\r\n min_left_open = left_doors.count('1')\r\n min_left_closed = n - min_left_open\r\n min_right_open = right_doors.count('1')\r\n min_right_closed = n - min_right_open\r\n\r\n min_time = min(min_left_open, min_left_closed) + min(min_right_open, min_right_closed)\r\n return min_time\r\nn = int(input())\r\nleft_doors = \"\"\r\nright_doors = \"\"\r\nfor i in range(n):\r\n l,r=input().split()\r\n left_doors+=l\r\n right_doors+=r\r\nresult = calculate_minimum_time(n, left_doors, right_doors)\r\nprint(result)", "x = int(input())\r\nl ,l1= [], []\r\ncnt_a, cnt_b =0, 0\r\nfor i in range(x):\r\n a,b = map(int,input().split())\r\n if a == 1:\r\n cnt_a += 1\r\n if b == 1:\r\n cnt_b += 1\r\n l.append(a)\r\n l1.append(b)\r\nt = 0\r\nif cnt_a >= (x+1)//2:\r\n t += x - cnt_a\r\nelse:\r\n t += cnt_a\r\n\r\nif cnt_b >= (x+1)//2:\r\n t += x - cnt_b\r\nelse:\r\n t += cnt_b\r\nprint(t)\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\nans = 0\r\nleft_open = 0\r\nleft_close = 0\r\nright_open = 0\r\nright_close = 0\r\nfor i in range(n):\r\n l_i,r_i = map(int,input().split())\r\n\r\n if l_i == 1:\r\n left_open+=1\r\n else:\r\n left_close+=1\r\n\r\n if r_i == 1:\r\n right_open+=1\r\n else:\r\n right_close+=1\r\nif left_open<=left_close:\r\n ans+=left_open\r\nelse:\r\n ans+=left_close\r\nif right_open<=right_close:\r\n ans+=right_open\r\nelse:\r\n ans+=right_close\r\n\r\nprint(ans)", "n = int(input())\r\n\r\nl, r = [], []\r\n\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n\r\n l.append(x)\r\n r.append(y)\r\n\r\nl0 = l.count(0)\r\n\r\nans = min(l0, n - l0)\r\nr0 = r.count(0)\r\nans += min(r0, n - r0)\r\nprint(ans)\r\n", "n = int(input())\r\nlcount = 0\r\nrcount = 0\r\nfor i in range(n):\r\n a = list(map(int, input().split()))\r\n if a[0] == 0:\r\n lcount += 1\r\n if a[1] == 0:\r\n rcount += 1\r\nif lcount > n/2:\r\n lcount = n-lcount\r\nif rcount > n/2:\r\n rcount = n-rcount\r\nprint(lcount + rcount)\r\n", "from operator import itemgetter\r\n#int(input())\r\n#map(int,input().split())\r\n#[list(map(int,input().split())) for i in range(q)]\r\n#print(\"YES\" * ans + \"NO\" * (1-ans))\r\nn = int(input())\r\nnum = 0\r\nnum2 = 0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n num += l\r\n num2 += r\r\nprint(min(num,n - num) + min(num2, n - num2))\r\n", "from collections import Counter\r\nn=int(input())\r\nl=[]\r\nr=[]\r\nfor _ in range(n):\r\n x,y=map(int,input().split())\r\n l.append(x)\r\n r.append(y)\r\nres=0\r\nlc=Counter(l)\r\nrc=Counter(r)\r\n# left doors\r\nif lc[0]<=lc[1]:\r\n res+=lc[0]\r\nelse:\r\n res+=lc[1]\r\n\r\nif rc[0]<=rc[1]:\r\n res+=rc[0]\r\nelse:\r\n res+=rc[1]\r\nprint(res)", "n = int(input())\ncupboards = []\nleft = 0\nright = 0\nt = 0\n\nfor cupboard in range(1, n+1):\n l, r = input().split(' ')\n list = [l, r]\n cupboards.append(list)\n\nfor value in cupboards:\n left = left + int(value[0])\n right = right + int(value[1])\n\nif n - left > left:\n for item in cupboards:\n if int(item[0]) != 0:\n item[0] = 0\n t = t + 1\nelse:\n for item in cupboards:\n if int(item[0]) != 1:\n item[0] = 1\n t = t + 1\n\nif n - right > right:\n for item in cupboards:\n if int(item[1]) != 0:\n item[1] = 0\n t = t + 1\nelse:\n for item in cupboards:\n if int(item[1]) != 1:\n item[1] = 1\n t = t + 1\n\nprint(t)\n \t \t \t\t\t\t \t\t \t\t", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(0,n):\r\n x,y=map(int,input().split())\r\n l.append(x)\r\n r.append(y)\r\na=l.count(0)\r\nb=l.count(1)\r\nc=r.count(0)\r\nd=r.count(1)\r\nans=0\r\nif a>=b:\r\n if c>=d:ans=b+d\r\n else:ans=c+b\r\nelif b>a:\r\n if c>=d:ans=a+d\r\n else:ans=a+c\r\nprint(ans) \r\n ", "testcases=int(input())\r\nleft=[]\r\nright=[]\r\ncount0=0\r\ncount1=0\r\ntime1=0\r\nmain=0\r\n\r\nfor i in range(testcases):\r\n x=list(map(int,input().split()))\r\n left.append(x[0])\r\n right.append(x[1])\r\n\r\nfor i in range(len(left)):\r\n if left[i]==0:\r\n count0+=1\r\n else:\r\n count1+=1\r\nif count0>count1:\r\n time1+=count1\r\n main+=count1\r\nelse:\r\n time1+=count0\r\n main+=count0\r\n# print(main)\r\n\r\ncount0=0\r\ncount1=0\r\ntime1=0\r\n\r\nfor i in range(len(right)):\r\n if right[i]==0:\r\n count0+=1\r\n else:\r\n count1+=1\r\nif count0>count1:\r\n time1+=count1\r\n main+=time1\r\nelse:\r\n time1+=count0\r\n main+=time1\r\nprint(main)\r\n", "matrix = []\nn = int(input())\n# For user input\nfor i in range(n):\n a = list(map(int, input().split()))\n matrix.append(a)\n\nresult = []\nfor i in range(2):\n result.append(sum([row[i] for row in matrix]))\n\nprint(min(result[0], n-result[0]) + min(result[1], n - result[1]))\n", "n=int(input())\r\na=[]\r\nb=[]\r\nflag=0\r\nfor i in range(n):\r\n p,q=[int(x) for x in input().split()]\r\n a.append(p)\r\n b.append(q)\r\n \r\n \r\nzeroa=a.count(0)\r\nzerob=b.count(0)\r\nonea=a.count(1)\r\noneb=b.count(1)\r\n\r\ncount=0\r\nif(zeroa<=onea):\r\n count+=zeroa\r\nelse:\r\n count+=onea\r\n\r\nif(zerob<=oneb):\r\n count+=zerob\r\nelse:\r\n count+=oneb\r\nprint(count)", "n=int(input())\r\ni=0\r\ns=0\r\nt=0\r\n\r\nwhile i<n :\r\n list2= list(map(int,input().split()))\r\n j=int(list2[0])\r\n k=int(list2[1])\r\n i=i+1\r\n if j==1:\r\n s=s+1\r\n if k==1:\r\n t=t+1\r\n\r\n\r\nu=n-s\r\nv=n-t\r\nif u>s:\r\n f1=s\r\nelse:\r\n f1=u\r\n \r\nif v>t:\r\n f2=t\r\nelse:\r\n f2=v\r\n \r\nprint(f1+f2)", "n=int(input())\nlist1=[]\nlist2=[]\nfor i in range(n):\n\tx,y=map(int,input().split())\n\tlist1.append(x)\n\tlist2.append(y)\ncount1=list1.count(0)\ncount2=list1.count(1)\nresult1=0\nif count1 >= count2:\n\tresult1=count2\nelse:\n\tresult1=count1\ncount3=list2.count(0)\ncount4=list2.count(1)\nresult2=0\nif count3 >= count4:\n\tresult2=count4\nelse:\n\tresult2=count3\nprint(result1+result2)\n", "n=int(input())\r\na=[0]*n;b=[0]*n\r\nfor i in range(0,n):\r\n a[i],b[i]=input().split()\r\n \r\nprint(min([a.count('0'),a.count('1')]) +min([b.count('0'),b.count('1')]))", "a = int(input())\r\nl = []\r\nr = []\r\nl0,r0,l1,r1 = 0,0,0,0\r\ncount = 0\r\nfor i in range(a):\r\n m,n = map(int,input().split())\r\n l.append(m)\r\n r.append(n)\r\n\r\nfor j in l:\r\n if j==0:\r\n l0 += 1\r\n elif j==1:\r\n l1 += 1\r\nif l1>l0:\r\n count += l0\r\nelse:\r\n count += l1\r\n\r\nfor k in r:\r\n if k==0:\r\n r0 += 1\r\n elif k==1:\r\n r1 += 1\r\nif r1>r0:\r\n count += r0\r\nelse:\r\n count += r1\r\n\r\nprint(count)", "amo = int(input())\r\nlo = 0\r\nlc = 0\r\nro = 0\r\nrc = 0\r\nsec = 0\r\nfor i in range(amo):\r\n l, r = input().split()\r\n if l == '1':\r\n lo += 1\r\n else :\r\n lc += 1\r\n if r == '1':\r\n ro += 1\r\n else :\r\n rc += 1\r\nif lo > lc:\r\n sec += lc\r\nelse :\r\n sec += lo\r\nif ro > rc:\r\n sec += rc\r\nelse :\r\n sec += ro\r\nprint(sec)", "import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n# def LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\ndef main():\n n=I()\n a=[]\n b=[]\n\n for _ in range(n):\n c,d=LI()\n a.append(c)\n b.append(d)\n\n # 0 0\n ansA=0\n for i in range(n):\n c=a[i]\n d=b[i]\n\n if c!=0:\n ansA+=1\n if d!=0:\n ansA+=1\n\n # 0 1\n ansB=0\n for i in range(n):\n c=a[i]\n d=b[i]\n\n if c!=0:\n ansB+=1\n if d!=1:\n ansB+=1\n\n # 1 0\n ansC=0\n for i in range(n):\n c=a[i]\n d=b[i]\n\n if c!=1:\n ansC+=1\n if d!=0:\n ansC+=1\n\n # 1 1\n ansD=0\n for i in range(n):\n c=a[i]\n d=b[i]\n\n if c!=1:\n ansD+=1\n if d!=1:\n ansD+=1\n\n return min(ansA,ansB,ansC,ansD)\n\n# main()\nprint(main())\n", "\r\n\r\n\r\n\r\n\r\nn = int(input())\r\nl0,l1,r0,r1=0,0,0,0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n if l==0 :\r\n l0+=1\r\n else:\r\n l1+=1\r\n \r\n if r==0 :\r\n r0+=1\r\n else:\r\n r1+=1\r\n\r\nt = (n-max(l0,l1))+(n-max(r0,r1))\r\nprint(t)\r\n \r\n\r\n\r\n\r\n \r\n", "n = int(input())\r\nro = 0\r\nrc = 0\r\nlo = 0\r\nlc = 0\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n if a == 0:\r\n lo += 1\r\n else:\r\n lc += 1\r\n if b == 0:\r\n ro += 1\r\n else:\r\n rc += 1\r\nprint(min(lo+ro, lo+rc, lc+ro, lc+rc))", "\r\nl0=0 \r\nl1=0 \r\nr0=0 \r\nr1=0\r\nt=int(input())\r\nfor i in range(t):\r\n s=input().split()\r\n c1=int(s[0])\r\n c2=int(s[1])\r\n if c1==0:\r\n l0+=1 \r\n if c1==1:\r\n l1+=1 \r\n if c2==0:\r\n r0+=1 \r\n if c2==1:\r\n r1+=1 \r\nprint(min(l0,l1)+min(r0,r1))\r\n ", "n = int(input())\r\nkas = 0\r\nA,B,ans = 0,0,0\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n A += a\r\n B += b\r\n kas += 1\r\nmn = min(A,kas-A)\r\nmx = min(B,kas-B)\r\nans = mn+mx\r\nprint(ans)\r\n", "n = int(input())\r\nli_l, li_r = [], []\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n li_l.append(l)\r\n li_r.append(r)\r\n\r\ncount1_l = li_l.count(1)\r\ncount1_r = li_r.count(1)\r\n\r\ncount2_l = li_l.count(0)\r\ncount2_r = li_r.count(0)\r\n\r\nprint(min(count1_r, count2_r)+min(count1_l, count2_l))\r\n ", "n = int(input())\r\n\r\nleft = []\r\nright = []\r\n\r\nl_count_0 = 0\r\nl_count_1 = 0\r\n\r\nr_count_0 = 0\r\nr_count_1 = 0\r\n\r\nfor i in range(n):\r\n l, r = input().strip().split()\r\n left.append(l)\r\n right.append(r)\r\n\r\n if l == '1':\r\n l_count_1 += 1\r\n else:\r\n l_count_0 += 1\r\n \r\n if r == '1':\r\n r_count_1 += 1\r\n else:\r\n r_count_0 += 1\r\n\r\nif l_count_0 > l_count_1:\r\n left_time = len(left)-l_count_0\r\nelse:\r\n left_time = len(left)-l_count_1\r\n\r\nif r_count_0 > r_count_1:\r\n right_time = len(left)-r_count_0\r\nelse:\r\n right_time = len(left)-r_count_1\r\n\r\nprint(left_time + right_time)", "n = int(input())\nl_count0 = 0\nl_count1 = 0\nr_count0 = 0\nr_count1 = 0\nfor x in range(n):\n [l,r] = map(int, input().split())\n if l:\n l_count1 += 1\n else:\n l_count0 += 1\n if r:\n r_count1 += 1\n else:\n r_count0 += 1\n\nprint(min(l_count0,l_count1) + min(r_count0, r_count1))\n \n ", "n=int(input())\r\nl,r=0,0\r\nfor i in range(n):\r\n\ta,b=input().split()\r\n\ta,b=int(a),int(b)\r\n\tl+=a\r\n\tr+=b\r\nprint(min(l,n-l)+min(r,n-r))", "def cupboard(n, l, r):\r\n lcount = l.count(1)\r\n rcount = r.count(1)\r\n li = min(lcount, n-lcount)\r\n ri = min(rcount, n-rcount)\r\n\r\n return li+ri\r\n \r\nn = int(input())\r\nlarr = []\r\nrarr = []\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n larr.append(l)\r\n rarr.append(r)\r\nprint(cupboard(n, larr, rarr))", "n = int(input())\nminz = 0\nmind = 0\n\nfor i in range (n) : \n l , r = map(int,input().split())\n\n if (l == 1) : \n minz+=1\n if (r == 1) :\n mind+=1\n\n\nans = min (minz, n - minz) + min (mind, n - mind)\n\nprint(ans)\n\n", "n=int(input())\r\nresult=[]\r\nresult2=[]\r\nfor i in range(n):\r\n d=input()\r\n alist=[int(f) for f in d.split()]\r\n result.append(alist[0])\r\n result2.append(alist[1])\r\nm=min(result.count(0),result.count(1))\r\nn=min(result2.count(0),result2.count(1))\r\nprint(m+n)", "from collections import Counter\r\ns1=''\r\ns2=''\r\nfor _ in range(int(input())):\r\n l,r=map(int,input().split())\r\n s1+=str(l)\r\n s2+=str(r)\r\nc1=Counter(s1)\r\nc2=Counter(s2)\r\nx=min(c1['0'],c1['1'])\r\ny=min(c2['0'],c2['1'])\r\nprint(x+y)", "n = int(input())\r\nleft_open = 0\r\nright_open = 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n left_open += l\r\n right_open += r\r\ncase1 = min(left_open, n - left_open) + min(right_open, n - right_open)\r\ncase2 = min(left_open, n - left_open) + min(right_open, n - right_open) + abs(left_open - right_open)\r\nprint(min(case1, case2))\r\n", "t = int(input())\r\na = []\r\nb = []\r\nfor _ in range(t):\r\n l,r = map(int,input().split())\r\n a.append(l)\r\n b.append(r)\r\nprint(min(a.count(0),a.count(1))+min(b.count(0),b.count(1)))\r\n", "sl=0\r\nsr=0\r\nn=int(input())\r\nfor i in range(n):\r\n a = list(map(int, input().split()))\r\n sl+=a[0]\r\n sr+=a[1]\r\nprint(min(sl,n-sl)+min(sr,n-sr))", "a=int(input())\r\nb={0:0,1:0}\r\nc={0:0,1:0}\r\nfor i in range(a):\r\n a=list(map(int,input().split()))\r\n b[a[0]]=b[a[0]]+1\r\n c[a[1]]=c[a[1]]+1\r\nans=0\r\nans=ans+min(b[0],b[1])+min(c[0],c[1])\r\nprint(ans)", "def ii(): return int(input())\r\ndef mi(): return map(int, input().split())\r\ndef li(): return list(map(int, input().split()))\r\n\r\n\r\nt = 1\r\n\r\nfor _ in range(t):\r\n n = ii()\r\n\r\n left = 0\r\n right = 0\r\n for i in range(n):\r\n l, r = mi()\r\n left += l\r\n right += r\r\n\r\n print(min(left, n - left) + min(right, n - right))\r\n", "def alag(l,r):\r\n zero = 0\r\n one = 0\r\n for i in l:\r\n if i == 0:\r\n zero = zero + 1\r\n else:\r\n one = one + 1\r\n\r\n zeroz = 0\r\n onez = 0\r\n for i in r:\r\n if i==0:\r\n zeroz = zeroz + 1\r\n else:\r\n onez = onez + 1\r\n\r\n if zero >= one:\r\n ans = one + onez\r\n else:\r\n ans = zero + zeroz\r\n\r\n return ans\r\ndef same(l,r):\r\n zero = 0\r\n one = 0\r\n for i in l:\r\n if i == 0:\r\n zero = zero + 1\r\n else:\r\n one = one + 1\r\n\r\n zeroz = 0\r\n onez = 0\r\n for i in r:\r\n if i==0:\r\n zeroz = zeroz + 1\r\n else:\r\n onez = onez + 1\r\n\r\n if zero + zeroz >= one + onez:\r\n return (one+onez)\r\n else:\r\n return(zero+zeroz)\r\ndef alagalag(l,r):\r\n zero = 0\r\n one = 0\r\n for i in l:\r\n if i == 0:\r\n zero = zero + 1\r\n else:\r\n one = one + 1\r\n\r\n zeroz = 0\r\n onez = 0\r\n for i in r:\r\n if i==0:\r\n zeroz = zeroz + 1\r\n else:\r\n onez = onez + 1\r\n\r\n if one >= zero:\r\n ans = zero\r\n else:\r\n ans = one\r\n\r\n if onez >=zeroz:\r\n ans = ans + zeroz\r\n else:\r\n ans = ans + onez\r\n\r\n return ans\r\nn = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n m,n = map(int,input().split())\r\n l.insert(i,m)\r\n r.insert(i,n)\r\n\r\nalag1 = alag(l,r)\r\nsame1 = same(l,r)\r\nalag2 = alagalag(l,r)\r\nif alag1>same1:\r\n if alag2>same1:\r\n print(same1)\r\n else:\r\n print(alag2)\r\nelse:\r\n if alag1 > alag2:\r\n print(alag2)\r\n else:\r\n print(alag1)\r\n", "from sys import *\n'''sys.stdin = open('input.txt', 'r') \nsys.stdout = open('output.txt', 'w') '''\nfrom collections import defaultdict as dd\nfrom math import *\nfrom bisect import *\n#sys.setrecursionlimit(10 ** 8)\ndef sinp():\n return input()\ndef inp():\n return int(sinp())\ndef minp():\n return map(int, sinp().split())\ndef linp():\n return list(minp())\ndef strl():\n return list(sinp())\ndef pr(x):\n print(x)\nmod = int(1e9+7)\nn = inp()\nd_l = dd(int)\nd_r = dd(int)\nfor i in range(n):\n l, r = minp()\n d_l[l] += 1\n d_r[r] += 1\npr(min(d_l[0], d_l[1]) + min(d_r[0], d_r[1]))", "\r\none=zero=O=Z=0\r\nfor i in range(int(input())):\r\n left,right=map(int,input().split())\r\n if left==1:\r\n one+=1\r\n else:\r\n zero+=1\r\n if right==1:\r\n O+=1\r\n else:\r\n Z+=1\r\nans=min(one,zero)+min(O,Z)\r\nprint(ans)\r\n", "def solve():\r\n n = int(input())\r\n tempList = []\r\n mainList= []\r\n for i in range(n):\r\n tempList += map(int, input().split(' '))\r\n mainList.append(tempList)\r\n tempList = []\r\n\r\n totalLeftZeroes = 0\r\n totalRightZeroes = 0\r\n for i in mainList:\r\n if i[0] == 0:\r\n totalLeftZeroes += 1\r\n if i[1] == 0:\r\n totalRightZeroes += 1\r\n\r\n totalLeftOnes = n - totalLeftZeroes\r\n totalRightOnes = n - totalRightZeroes\r\n\r\n print(min(totalLeftZeroes, totalLeftOnes) + min(totalRightZeroes, totalRightOnes))\r\nsolve()", "right=[]\r\nleft=[]\r\nfor _ in range(int(input())):\r\n r,l=map(int,input().split())\r\n right.append(r)\r\n left.append(l)\r\nn1=min(right.count(0),right.count(1))\r\nn2=min(left.count(0),left.count(1))\r\nprint(n1+n2)", "n = int(input())\r\nopen = 1\r\nclosed = 0\r\nleft_open, left_closed, right_open, right_closed = 0,0,0,0\r\nfor i in range(n):\r\n left, right = [int(x) for x in input().split()]\r\n\r\n left_open += (left==open)\r\n left_closed += (left==closed)\r\n\r\n right_open += (right==open)\r\n right_closed += (right==closed)\r\n\r\nmin_left = min(left_open, left_closed)\r\nmin_right = min(right_open, right_closed)\r\n\r\nprint(min_left+min_right)", "m = int(input())\nwindows = []\nlwo = 0\nlwz = 0\nrwo = 0\nrwz = 0\nfor i in range(0,m):\n sw = input()\n windows.append(sw.split())\nfor i in range(0,m):\n if(windows[i][0] == '1'):\n lwo += 1\n else:\n lwz += 1\n if(windows[i][1] == '1'):\n rwo += 1\n else:\n rwz += 1\nprint(min(lwo,lwz) + min(rwo,rwz))\n", "li = [ list(map(int,input().split())) for i in range(int(input())) ]\r\nz = list(zip(*li))\r\nres = 0\r\nfor v in z:\r\n if v.count(0) > v.count(1):\r\n res+=v.count(1)\r\n else:\r\n res+=v.count(0)\r\nprint(res)", "n=int(input())\r\np=[]\r\nfor i in range(n):\r\n p.append(input().split())\r\nl0=0\r\nl1=0\r\nr0=0\r\nr1=0\r\nfor i in range(n):\r\n l0+=p[i][0].count('0')\r\n l1+=p[i][0].count('1')\r\n r0+=p[i][1].count('0')\r\n r1+=p[i][1].count('1')\r\nprint(min(l0,l1)+min(r0,r1))", "n=int(input())\r\nt=0\r\na=[]\r\nb=[]\r\nfor i in range(n):\r\n p=list(map(str, input().split()))\r\n a.append(p[0])\r\n b.append(p[1])\r\nprint(min(a.count('0'), a.count('1'))+min(b.count('0'), b.count('1'))) ", "def CupBoards(ll,rl):\r\n t=0\r\n oc=0;zc=0\r\n oc=ll.count(0)\r\n zc=ll.count(1)\r\n if oc<zc:\r\n t+=oc\r\n else:\r\n t+=zc\r\n oc=rl.count(0)\r\n zc=rl.count(1)\r\n if oc<zc:\r\n t+=oc\r\n else:\r\n t+=zc\r\n return t\r\n \r\n\r\nn=int(input())\r\nll=[];rl=[]\r\nfor i in range(n):\r\n a=[]\r\n a=list(map(int,input().split()))\r\n ll.append(a[0])\r\n rl.append(a[1])\r\nprint(CupBoards(ll,rl))\r\n \r\n", "n=int(input())\r\nl=\"\"\r\nr=\"\"\r\nfor i in range(n):\r\n a,b =map(str,input().split())\r\n l+=a\r\n r+=b\r\nlc=l.count('1')\r\nrc=r.count('1')\r\ncount=0\r\nif rc>n//2:\r\n count+=(n-rc)\r\nelse:\r\n count+=rc\r\nif lc>n//2:\r\n count+=(n-lc)\r\nelse:\r\n count+=lc\r\nprint(count)", "n = int(input())\ncupboards = []\nl,r = 0,0\nfor _ in range(n):\n ll, rr = (map(int,input().split()))\n l+=ll\n r+=rr\nsecs = 0\nif l>n//2:\n secs+=n-l\nelse:\n secs+=l\nif r>n//2:\n secs+=n-r\nelse:\n secs+=r\nprint(secs)", "l0 = l1 = r0 = r1 = 0\r\nfor _ in range(int(input())):\r\n s = input().split()\r\n if s[0] == '0': l0 += 1\r\n else: l1 += 1\r\n if s[1] == '0': r0 += 1\r\n else: r1 += 1\r\nprint(min(l0, l1)+min(r0, r1))\r\n", "n = int(input())\r\nlcro = lorc = lcrc = loro = 0\r\nfor i in range(n):\r\n l,r = input().split()\r\n if l=='1':\r\n lcro += 1\r\n lcrc += 1\r\n else:\r\n lorc += 1\r\n loro += 1\r\n if r=='1':\r\n lorc += 1\r\n lcrc += 1\r\n else:\r\n lcro += 1\r\n loro += 1\r\nprint(min(lcro,lorc,lcrc,loro))", "n=int(input())\r\nL,R=0,0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n if l==1:\r\n L+=1\r\n if r==1:\r\n R+=1\r\n\r\nprint(min(R,n-R)+ min(L,n-L))\r\n\r\n\r\n\r\n ", "c1 = 0\r\nc2 = 0\r\nn = int(input())\r\n\r\nfor _ in range(n):\r\n l , r = map(int,input().split())\r\n c1 +=l\r\n c2 += r\r\n\r\nprint(min(c1 , n - c1) + min(c2 , n - c2))\r\n\r\n\r\n\r\n\r\n\r\n", "def check(mass):\r\n if mass.count(1) > mass.count(0):\r\n return 0\r\n return 1\r\n\r\nn = int(input())\r\nleft = []\r\nright = []\r\nfor _ in range(n):\r\n l, r = input().split()\r\n left.append(int(l))\r\n right.append(int(r))\r\nl_m = check(left)\r\nr_m = check(right)\r\nans = left.count(l_m) + right.count(r_m)\r\nprint(ans)", "query=int(input())\r\nl1=0;l0=0;r1=0;r0=0\r\n\r\nfor _ in range(query):\r\n\tl, r=map(int, input().split())\r\n\tif l==1:\r\n\t\tl1+=1\r\n\t\tif r==1:\r\n\t\t\tr1+=1\r\n\t\telse:\r\n\t\t\tr0+=1\r\n\telse:\r\n\t\tl0+=1\r\n\t\tif r==1:\r\n\t\t\tr1+=1\r\n\t\telse:\r\n\t\t\tr0+=1\r\nlm=min(l0,l1);rm=min(r0,r1)\r\nprint(lm+rm)", "n = int(input())\r\nleft_doors = []\r\nright_doors = []\r\n\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n left_doors.append(l)\r\n right_doors.append(r)\r\n\r\n# Count the number of doors that need to be flipped\r\nflips = min(sum(left_doors), n - sum(left_doors)) + min(sum(right_doors), n - sum(right_doors))\r\n\r\nprint(flips)\r\n", "n = int(input())\r\nm = []\r\nl = 0\r\nr = 0\r\ns = 0\r\nfor i in range(n):\r\n a = list(map(int,input().split()))\r\n if a[0] == 1:\r\n l += 1\r\n if a[1] == 1:\r\n r += 1\r\nif l > n/2:\r\n s += (n-l)\r\nelse:\r\n s += l\r\nif r > n/2:\r\n s += (n-r)\r\nelse:\r\n s += r\r\nprint(s)", "n=int(input())\r\nleft_open,left_close,right_open,right_close=0,0,0,0\r\nfor i in range(n):\r\n l,r=map(int, input().split())\r\n left_open+=l\r\n left_close+=1-l\r\n right_open+=r\r\n right_close+=1-r\r\n \r\nleft=min(left_open,left_close)\r\nright=min(right_open,right_close)\r\nprint(left+right)", "n = int(input())\r\nl = 0\r\nr = 0\r\nfor i in range(n):\r\n a, b = input().split()\r\n a = int(a)\r\n b = int(b)\r\n if a == 1:\r\n l += 1\r\n if b == 1:\r\n r += 1\r\n\r\nprint(min(l, n-l) + min(r, n - r))", "a, b, c ,d = 0, 0,0,0\nfor i in range(int(input())):\n l, r= list(map(int, input().split()))\n if (l == 0):\n a += 1\n if (l == 1):\n b += 1\n if (r == 0):\n c += 1\n if (r == 1):\n d += 1\nprint(min(a,b) + min(c,d))\n", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n l,r=(int(j) for j in input().split())\r\n left.append(l)\r\n right.append(r)\r\nl_close=left.count(0)\r\nl_open=left.count(1)\r\nr_close=right.count(0)\r\nr_open=right.count(1)\r\nvalue=min(l_close,l_open)+min(r_close,r_open)\r\nprint(value)\r\n", "t=int(input())\r\nopen1=1 \r\nclosed=0\r\nlo=0\r\nlc=0\r\nro=0\r\nrc=0\r\nfor i in range(t):\r\n a,b=map(int,input().split())\r\n if(a==open1):\r\n lo+=1\r\n if(a==closed):\r\n lc+=1 \r\n if(b==open1):\r\n ro+=1 \r\n if(b==closed):\r\n rc+=1 \r\nk=min(lo,lc)\r\nk1=min(ro,rc)\r\nprint(k+k1)", "n = int(input())\r\nleft, right = [], []\r\nfor x in range(n):\r\n string = input()\r\n numbers = string.split()\r\n left.append(int(numbers[0]))\r\n right.append(int(numbers[1]))\r\na, b = left.count(0), right.count(0)\r\nprint(min(a, n - a) + min(b, n - b))", "n = int(input())\r\n\r\nd = []\r\nd += [input().split() for i in range(n)]\r\n\r\nld,rd = [i[0] for i in d],[i[1] for i in d]\r\n\r\nif ld.count('1') > ld.count('0'):\r\n t = ld.count('0')\r\nelse:\r\n t = ld.count('1')\r\n\r\nif rd.count('1') > rd.count('0'):\r\n t += rd.count('0')\r\nelse:\r\n t+= rd.count('1')\r\n\r\nprint(t)", "n = int(input())\r\nl = r = 0\r\n\r\nfor i in range(n):\r\n a,b = map(int, input().split())\r\n l += a\r\n r += b\r\n\r\nans = min(n-l,l) + min(n-r,r)\r\nprint(ans)\r\n", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n l1,r1=map(int,input().split())\r\n l.append(l1)\r\n r.append(r1)\r\nprint(min(l.count(0),l.count(1))+min(r.count(0),r.count(1)))", "n=int(input())\r\nl=list()\r\nr=list()\r\nwhile n>0:\r\n x,y=input().split()\r\n x=int(x)\r\n y=int(y)\r\n l.append(x)\r\n r.append(y)\r\n n=n-1\r\nprint(min(l.count(0),l.count(1))+min(r.count(0),r.count(1)))", "n =int(input())\r\n\r\nleft_open = 0\r\nright_open = 0\r\nfor _ in range(n):\r\n (left, right) = map(int, input().split())\r\n if left == 1:\r\n left_open += 1\r\n\r\n if right == 1:\r\n right_open += 1\r\n\r\n\r\nmin_left = min(left_open, n-left_open)\r\nmin_right = min(right_open, n-right_open)\r\nprint(min_left+min_right)\r\n\r\n", "n=int(input())\r\nl,r=0,0\r\nfor _ in range(n):\r\n x,y=map(int,input().split())\r\n if x==1:\r\n l+=1\r\n if y==1:\r\n r+=1\r\nprint(min(n-l,l)+min(n-r,r))\r\n \r\n", "num = int(input())\nleft,right = [],[]\ntime = 0\n\nfor i in range(num):\n l = input().split()\n left.append(int(l[0]))\n right.append(int(l[1]))\n\nleft_0 = left.count(0)\nleft_1 = left.count(1)\nright_0 = right.count(0)\nright_1 = right.count(1)\n\nif left_0 > left_1:\n time += left_1\nelse: \n time += left_0\n\nif right_0 > right_1:\n time += right_1\nelse:\n time += right_0\n\nprint(time)", "n=int(input())\r\ns=0\r\nx=0\r\n\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n s=s+l\r\n x=x+r\r\n \r\nif s>n//2:\r\n s=n-s\r\nelse:\r\n s=s\r\n \r\nif x>n//2:\r\n x=n-x\r\nelse:\r\n x=x \r\n \r\nprint(s+x)", "n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n l1=list(map(int,input().split()))\r\n l.append(l1)\r\nclz=0\r\nclo=0\r\ncrz=0\r\ncro=0\r\nfor i in range(n):\r\n if l[i][0]==0:\r\n clz+=1\r\n elif l[i][0]==1:\r\n clo+=1\r\n \r\nfor i in range(n):\r\n if l[i][1]==0:\r\n crz+=1\r\n elif l[i][1]==1:\r\n cro+=1\r\n \r\nc=0\r\nif clz>clo:\r\n c+=clo\r\n \r\nif clo>clz:\r\n c+=clz\r\n\r\nif clo==clz:\r\n c+=clo\r\n \r\nif crz>cro:\r\n c+=cro\r\n \r\nif cro>crz:\r\n c+=crz\r\n\r\nif cro==crz:\r\n c+=cro\r\nprint(c) ", "n = int(input())\r\nleft = []\r\nright = []\r\nfor _ in range(n):\r\n i,j = map(int, input().split())\r\n left.append(i)\r\n right.append(j)\r\nans = 0\r\nif left.count(0) == 0:\r\n pass\r\nelif left.count(0) > left.count(1):\r\n ans += left.count(1)\r\nelse:\r\n ans += left.count(0)\r\n\r\nif right.count(0) == 0:\r\n pass\r\nelif right.count(0) > right.count(1):\r\n ans += right.count(1)\r\nelse:\r\n ans += right.count(0)\r\n\r\nprint(ans)", "import sys\n\nn = int(input())\n\nlft, rt = 0, 0\n\nfor line in sys.stdin:\n l, r = line.split()\n if l == '1':\n lft += 1\n if r == '1':\n rt += 1\n\nans = 0\n\nif lft > n//2:\n ans += n - lft\nelse:\n ans += lft\nif rt > n//2:\n ans += n - rt\nelse:\n ans += rt\n\nprint(ans)\n", "n=int(input())\r\ndoors=list()\r\nfor i in range(n):\r\n door=[int(x) for x in input().split()]\r\n doors.append(door)\r\nfreq={'l':{0:0,1:0},'r':{0:0,1:0}}\r\nfor i in range(n):\r\n if(doors[i][0]==0):\r\n freq['l'][0]+=1\r\n else:\r\n freq['l'][1]+=1\r\n if(doors[i][1]==0):\r\n freq['r'][0]+=1\r\n else:\r\n freq['r'][1]+=1\r\ncnt=0\r\nif(freq['l'][0]>freq['l'][1]):\r\n cnt+=freq['l'][1]\r\nelse:\r\n cnt+=freq['l'][0]\r\nif(freq['r'][0]>freq['r'][1]):\r\n cnt+=freq['r'][1]\r\nelse:\r\n cnt+=freq['r'][0]\r\nprint(cnt)\r\n", "aL, aR = [], []\r\nn = int(input())\r\nfor _ in range(n):\r\n L, R = input().split()\r\n aL.append(L)\r\n aR.append(R)\r\nlC, rC = aL.count(\"0\"), aR.count(\"0\")\r\nprint(min(lC, n-lC) + min(rC, n-rC))", "f=lambda:map(int,input().split())\r\nn=int(input())\r\nl,r=zip(*(input().split() for i in range(n)))\r\nprint(2*n-(max(l.count('0'),l.count('1'))+max(r.count('0'),r.count('1'))))", "n = int(input())\r\nt = list()\r\np = list()\r\nsoT = 0\r\nsoP = 0\r\nfor i in range(0,n):\r\n h = list(map(int, input().split(\" \")))\r\n t.append(h[0])\r\n p.append(h[1])\r\nsetT = set(t)\r\nsetP = set(p)\r\nif(len(setP) == 1 and len(setT) == 1):\r\n print(0)\r\nelif(t.count(1) == p.count(1) or t.count(0) == p.count(0)):\r\n print((n - t.count(1)) * 2)\r\nelif(t.count(1) == n):\r\n print(n - p.count(1))\r\nelif(t.count(0) == n):\r\n print(n - p.count(0))\r\nelif(p.count(1) == n):\r\n print(n - t.count(1))\r\nelif(p.count(0) == n):\r\n print(n - t.count(0))\r\nelif(t.count(1) > p.count(1)):\r\n soT = n - t.count(1)\r\n soP = n - p.count(0)\r\n print(soT + soP)\r\nelse:\r\n soT = n - t.count(0)\r\n soP = n - p.count(1)\r\n print(soT + soP)", "def door_open_close(cupboards):\r\n total = 0\r\n if sum(cupboards) > n/2:\r\n total += n - sum(cupboards)\r\n else:\r\n total += sum(cupboards)\r\n\r\n return total\r\n\r\n\r\nleft, right = [], []\r\nn = int(input())\r\nfor _ in range(n):\r\n l, r = map(int,input().split(' '))\r\n left.append(l)\r\n right.append(r)\r\n\r\nprint(door_open_close(left) + door_open_close(right))", "n = int(input())\r\nleft_open =0\r\nright_open = 0\r\nfor i in range(n):\r\n li,ri = map (int,input().split())\r\n left_open+=li\r\n right_open+=ri\r\n\r\nmin_time = min(left_open,n-left_open) + min(right_open,n-right_open)\r\n\r\nprint(min_time)\r\n", "n1 = int(input())\r\nlist1 = []\r\nleft = 0\r\nright = 0\r\nfor i in range(n1):\r\n x = input().split()\r\n temp = []\r\n for j in x:\r\n temp.append(int(j))\r\n left += temp[0]\r\n right += temp[1]\r\n\r\ncount = 0 \r\nif n1 - left> left - 0:\r\n count += left\r\nelif left > n1 - left:\r\n count+= n1 - left\r\nelse:\r\n count += left\r\n\r\nif n1 - right> right - 0:\r\n count += right\r\nelif right > n1 - right:\r\n count+= n1 - right\r\nelse:\r\n count += right\r\n\r\nprint(count)\r\n \r\n \r\n", "n = int(input())\r\nl1 = []\r\nl2 = []\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n l1.append(x)\r\n l2.append(y)\r\n\r\na = l1.count(1)\r\nb = l2.count(1)\r\n\r\nprint(min(n-a,a)+min(n-b,b))\r\n", "n = int(input())\r\n \r\na=0\r\nb=0\r\n \r\nfor i in range(n):\r\n\tx, y = input().split()\r\n\tx = int(x)\r\n\ty = int(y)\r\n\tif x==0:\r\n\t\ta = a + 1\r\n\tif y==0:\r\n\t\tb = b + 1\r\n \r\nprint(min(a,n-a)+min(b,n-b))", "#\r\n\r\n\r\ndef single_integer():\r\n return int(input())\r\n\r\n\r\ndef multi_integer():\r\n return map(int, input().split())\r\n\r\n\r\ndef string():\r\n return input()\r\n\r\n\r\ndef multi_string():\r\n return input().split()\r\n\r\n\r\nn = single_integer()\r\nl_open = 0\r\nl_close = 0\r\nr_open = 0\r\nr_close = 0\r\n\r\nfor i in range(n):\r\n l, r = multi_string()\r\n if l == \"1\":\r\n l_open += 1\r\n else:\r\n l_close += 1\r\n\r\n if r == \"1\":\r\n r_open += 1\r\n else:\r\n r_close += 1\r\n\r\nprint(min(l_open, l_close) + min(r_open, r_close))\r\n", "# In this task, you can consider independently all left cabinet doors and, similarly, all right ones. Obviously, in order to bring all the left cabinet doors to the same position, you need to determine which of the two states (\"left door open\" or \"left door closed\") occurs more often. All left doors that are in a different state need to be brought to this. The same should be done with the right doors. If you carefully count in this case the number of operations for changing the state of the door, then this will be the answer.\n\n# One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.\n\n# Karlsson's gaze immediately fell on n wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find.\n\n# And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open.\n\n# Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds t, in which he is able to bring all the cupboard doors in the required position.\n\n# Your task is to write a program that will determine the required number of seconds t.\n\nn = int(input())\nleft_dict = {'0': 0, '1':0}\nright_dict = {'0':0, '1':0}\nfor _ in range(n):\n l, r = map(str, input().split())\n left_dict[l]+=1\n right_dict[r]+=1\ncount =0\nkey_l = max(left_dict, key = left_dict.get)\nkey_r = max(right_dict, key = right_dict.get)\n# print(key_l, key_r)\ncount+= (n-left_dict[key_l]) + (n-right_dict[key_r])\nprint(count)\n\n\n\n", "n = int(input())\r\nopenl = 0\r\nclosel = 0\r\nopenr = 0\r\ncloser = 0\r\n\r\nfor i in range(n):\r\n door = list(map(int, input().split()))\r\n if door[0] == 1:\r\n openl += 1\r\n elif door[0] == 0:\r\n closel += 1\r\n\r\n if door[1] == 1:\r\n openr += 1\r\n elif door[1] == 0:\r\n closer += 1\r\n\r\nright = [openr, closer]\r\nleft = [openl, closel]\r\n\r\nprint(min(right) + min(left))", "n=int(input())\r\na=[]\r\nb=[]\r\nfor i in range(0,n):\r\n c=list(map(int,input().split()))\r\n a.append(c[0])\r\n b.append(c[1])\r\np=a.count(0)\r\nq=a.count(1)\r\nk=min(p,q)\r\np=b.count(0)\r\nq=b.count(1)\r\nl=min(p,q) \r\nprint(k+l)\r\n", "def mini(list):\r\n a = list.count(1)\r\n b = list.count(0)\r\n \r\n if a > b:\r\n return b\r\n else:\r\n return a\r\n\r\nn = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n a,b = map(int, input().split())\r\n l.append(a)\r\n r.append(b)\r\n\r\nr1 = mini(l)\r\nr2 = mini(r)\r\n\r\n\r\nprint(r1+r2)", "N=int(input())\nx=0\ny=0\nfor i in range(N):\n a,b=map(int,input().split(\" \",1))\n if a==0:\n x=x+1\n if b==0:\n y=y+1\nx=min(N-x,x)\ny=min(N-y,y)\nprint(x+y)\n\t\t\t \t \t\t\t \t\t\t\t \t \t\t\t\t\t\t \t\t", "v1, v2 = 0, 0\nl, r = [], []\n\nfor i in range(int(input())):\n n = [int(_) for _ in input().split()]\n\n l.append(n[0])\n r.append(n[1])\n\nv1 = l.count(0)\nv2 = l.count(1)\nv3 = r.count(0)\nv4 = r.count(1)\n\nprint(min(v1, v2) + min(v3, v4))\n", "n = int(input())\r\nll = list()\r\nrr = list()\r\nans = 0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n ll.append(l)\r\n rr.append(r)\r\nl0 = ll.count(0)\r\nl1 = ll.count(1)\r\nr0 = rr.count(0)\r\nr1 = rr.count(1)\r\nif l0 > l1: ans+=l1\r\nelse: ans+=l0\r\n\r\nif r0 > r1: ans+=r1\r\nelse: ans+=r0\r\n\r\nprint(ans)\r\n ", "import sys\r\n\r\nn = int(input())\r\ncntl0, cntl1, cntr0, cntr1 = 0, 0, 0, 0\r\nfor i in range(n):\r\n l, r = (int(el) for el in input().split())\r\n if l == 0:\r\n cntl0 += 1\r\n else:\r\n cntl1 += 1\r\n if r == 0:\r\n cntr0 += 1\r\n else:\r\n cntr1 += 1\r\n \r\nprint(min(cntl0, cntl1) + min(cntr0, cntr1))\r\n \r\n'''6\r\n2 1 4 3 6 5\r\n''' \r\n\r\n\r\n", "z,o,s = 0,0,0\r\n\r\na = [list(map(int,input().split())) for i in range(int(input()))]\r\nfor i in range(len(a)):\r\n if a[i][0] == 1:o+=1\r\n else: z+=1\r\ns+= min(z,o)\r\nz,o = 0,0\r\n\r\nfor i in range(len(a)):\r\n if a[i][1] == 1:o+=1\r\n else: z+=1\r\ns+= min(z,o)\r\nprint(s)", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n z=str(x)+str(y)\r\n a.append(z)\r\nv=[\"zo\",\"oo\",\"oz\",\"zz\"]\r\no=[]\r\nfor k in v:\r\n if k==\"zo\":\r\n c=\"01\"\r\n elif k==\"oo\":\r\n c=\"11\"\r\n elif k==\"oz\":\r\n c=\"10\"\r\n else:\r\n c=\"00\"\r\n s=0\r\n for i in range(n):\r\n s=s+abs(int(c[0])-int(a[i][0]))+abs(int(c[1])-int(a[i][1]))\r\n o.append(s)\r\nprint(min(o))", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n a=input().split()\r\n left.append(a[0])\r\n right.append(a[1])\r\nleft1=left.count(\"0\")\r\nleft0=left.count(\"1\")\r\nright1=right.count(\"1\")\r\nright0=right.count(\"0\")\r\nfinal=0\r\nif left1<=left0:\r\n final+=left1\r\nelse:\r\n final+=left0\r\nif right1<=right0:\r\n final+=right1\r\nelse:\r\n final+=right0\r\nprint(final)", "n = int(input())\r\nleft = 0\r\nright = 0\r\nboth = 0\r\n\r\ndata = []\r\nfor i in range(n):\r\n data.append(list(map(int, input().split())))\r\n'''\r\noptions:\r\neverything left, everything right, everything open, everything closed\r\n'''\r\n\r\ndef time(goal, curr):\r\n ans = 0\r\n if(goal[0] != curr[0]):\r\n ans += 1\r\n if(goal[1] != curr[1]):\r\n ans += 1\r\n return ans\r\n\r\ndef sim(goal):\r\n global data\r\n ans = 0\r\n for i in data:\r\n ans += time(goal, i)\r\n return ans\r\n'''\r\n[0,0] -> both closed\r\n[0,1] -> right open\r\n[1,0] -> left open\r\n[1,1] -> both open\r\n'''\r\n\r\nv1 = sim([0,0])\r\nv2 = sim([0,1])\r\nv3 = sim([1,0])\r\nv4 = sim([1,1])\r\n\r\nprint(min([v1,v2,v3,v4]))", "n=int(input())\r\nl=[]\r\no,c,o1,c1,count=0,0,0,0,0\r\nfor i in range(n):\r\n\tl2=list(map(int,input().split()))\r\n\tl.append(l2)\r\nfor i in range(n):\r\n\tif l[i][0]==0:\r\n\t\to+=1\r\n\telse:\r\n\t\tc+=1\r\nfor i in range(n):\r\n\tif l[i][1]==0:\r\n\t\to1+=1\r\n\telse:\r\n\t\tc1+=1\r\nif c<=o:\r\n\tcount+=c\r\nelse:\r\n\tcount+=o\r\nif c1<=o1:\r\n\tcount+=c1\r\nelse:\r\n\tcount+=o1\r\nprint(count)", "\r\nn = int(input())\r\nlef = []\r\nrig = []\r\nfor _ in range(n):\r\n\ta, b = map(int, input().split())\r\n\tlef.append(a)\r\n\trig.append(b)\r\n\r\nt = 0\r\nt += min(lef.count(0), lef.count(1))\r\nt += min(rig.count(0), rig.count(1))\r\nprint(t)\r\n", "n=int(input())\r\nu=[]\r\nv=[]\r\nfor i in range(n):\r\n l,m=map(int,input().split())\r\n u.append(l)\r\n v.append(m)\r\ncnt=0\r\ncnt1=0\r\ncnt2=0\r\ncnt3=0\r\nsum=0\r\nfor i in u:\r\n if i==0:\r\n cnt+=1\r\n else:\r\n cnt1+=1\r\nsum=min(cnt,cnt1)\r\nfor i in v:\r\n if i==0:\r\n cnt2+=1\r\n else:\r\n cnt3+=1\r\nc=sum+min(cnt2,cnt3)\r\nprint(c)", "n = int(input())\r\n\r\nL, R = 0, 0\r\nfor _ in range(n):\r\n\r\n (l, r) = (int(i) for i in input().split(' '))\r\n L+=l\r\n R+=r\r\n\r\nprint(min(n-R, R) + min(n-L, L))", "n = int(input())\r\nleft = right = ''\r\nfor i in range(n):\r\n a = list(map(str, input().split()))\r\n left += a[0]\r\n right += a[1]\r\nif(left.count('1') < left.count('0')):\r\n if(right.count('1') < right.count('0')):\r\n print(right.count('1') + left.count('1'))\r\n else:\r\n print(left.count('1') + right.count('0'))\r\nelse:\r\n if (right.count('1') < right.count('0')):\r\n print(right.count('1') + left.count('0'))\r\n else:\r\n print(left.count('0') + right.count('0'))", "n = int(input())\r\na = []\r\nb = []\r\nfor i in range(n):\r\n c, d = map(int, input().split())\r\n a.append(c)\r\n b.append(d)\r\nprint(min(n - sum(a), sum(a)) + min(n - sum(b), sum(b)))", "c,d=[],[];z=lambda x,y:x.count(y)\r\nfor i in range(int(input())):a,b=map(int,input().split());c+=[a];d+=[b]\r\nprint(min(z(c,0),z(c,1))+min(z(d,1),z(d,0)))", "# import sys\r\n# sys.stdout = open('DSA/Stacks/output.txt', 'w')\r\n# sys.stdin = open('DSA/Stacks/input.txt', 'r')\r\n\r\nn=int(input())\r\nl,r=0,0\r\nfor _ in range(n):\r\n\ta,b=map(int,input().split())\r\n\tl+=a\r\n\tr+=b\r\nprint(min(l,n-l)+min(r,n-r))", "n=int(input())\r\na=[]\r\nb=[]\r\nc=[]\r\nfor i in range(n):\r\n a=a+list(map(int,input().split()))\r\nfor j in range(2*n):\r\n if j%2==0:\r\n b.append(a[j])\r\n else:\r\n c.append(a[j])\r\nx=b.count(0)\r\ny=b.count(1)\r\nz=c.count(1)\r\nw=c.count(0)\r\nprint(min(x,y)+min(z,w))\r\n", "n=int(input())\r\nl1=[]\r\nl2=[]\r\ns=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n l1.append(a)\r\n l2.append(b)\r\nif l1.count(1)>l1.count(0):\r\n s+=l1.count(0)\r\nelse:\r\n s+=l1.count(1)\r\nif l2.count(1)>l2.count(0):\r\n s+=l2.count(0)\r\nelse:\r\n s+=l2.count(1)\r\nprint(s)\r\n \r\n \r\n", "cupboards_l = []\r\ncupboards_r = []\r\n\r\nfor i in range(int(input())):\r\n cupboards = input().split()\r\n cupboards_l.append(cupboards[0])\r\n cupboards_r.append(cupboards[1])\r\n\r\nseconds = 0\r\n\r\nif cupboards_l.count(\"0\") > cupboards_l.count(\"1\"):\r\n seconds += cupboards_l.count(\"1\")\r\nelse:\r\n seconds += cupboards_l.count(\"0\")\r\n\r\n\r\nif cupboards_r.count(\"0\") > cupboards_r.count(\"1\"):\r\n seconds += cupboards_r.count(\"1\")\r\nelse:\r\n seconds += cupboards_r.count(\"0\")\r\n\r\nprint(seconds)\r\n", "sum1=0\r\nsum2=0\r\nn=int(input())\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n sum1=a[0]+sum1\r\n sum2=a[1]+sum2\r\nprint(min(sum1,n-sum1)+min(sum2,n-sum2))\r\n", "if __name__== \"__main__\":\r\n T=int(input())\r\n l=[]\r\n r=[]\r\n for i in range(T):\r\n lst=input()\r\n lst=lst.split(\" \")\r\n l.append(lst[0])\r\n r.append(lst[1])\r\n ans=min([l.count(\"0\"),l.count(\"1\")])+min([r.count(\"0\"),r.count(\"1\")])\r\n print(ans)", "n = int(input())\r\nopen_left_scenario = 0\r\nopen_right_scenario = 0\r\nopen_all = 0\r\nclose_all = 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n if l == 0:\r\n open_left_scenario += 1\r\n close_all += 1\r\n else:\r\n open_right_scenario += 1\r\n open_all += 1\r\n if r == 0:\r\n open_right_scenario += 1\r\n close_all += 1\r\n else:\r\n open_left_scenario += 1\r\n open_all += 1\r\nprint(min(open_left_scenario, open_right_scenario, open_all, close_all))\r\n\r\n", "# n = int(input())\n# tn = [int(i) for i in input().split()]\n#\n# def f():\n# pass\n#\n# l = 0\n# r = n\n#\n# while l < r:\n# pass\n\n\nn = int(input())\nlm0 = lm1 = rm0 = rm1 = 0\n\nfor j in range(n):\n a = [int(i) for i in input().split()]\n\n if a[0] == 1: lm1 += 1\n elif a[0] == 0: lm0 += 1\n \n if a[1] == 1: rm1 += 1\n elif a[1] == 0: rm0 += 1\n\nprint(n - max(lm0, lm1) + n - max(rm0, rm1))\n", "x, y = [], []\r\nfor _ in range(int(input())):\r\n t = list(map(int, input().split()))\r\n x.append(t[0])\r\n y.append(t[1])\r\nprint(min(x.count(1), x.count(0)) + min(y.count(1), y.count(0)))", "n = int(input())\r\na = []\r\nb = []\r\nfor _ in range (n) :\r\n l , r = list(map(int,input().split()))\r\n a.append(l)\r\n b.append(r)\r\ncount1 = 0\r\ncount0 = 0\r\ncount11 = 0\r\ncount00 = 0\r\nfor i in a :\r\n if i == 0 :\r\n count0 += 1\r\n if i == 1 :\r\n count1 += 1\r\nfor i in b :\r\n if i == 0 :\r\n count00 += 1\r\n if i == 1 :\r\n count11 += 1\r\nM = min(count1 , count0)\r\nm = min(count00 , count11)\r\nprint(M + m)", "n = int(input())\r\nleft = 0\r\nright = 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n left += l\r\n right += r\r\nresult = min(left, n - left) + min(right, n - right)\r\nprint(result)\r\n", "from itertools import product\r\nfrom math import ceil\r\n\r\ndef binary_table(string_with_all_characters, length_to_make):\r\n return [''.join(x) for x in product(string_with_all_characters, repeat=length_to_make)]\r\n\r\n\r\ndef all_possible_substrings(string):\r\n return [string[i: j] for i in range(len(string)) for j in range(i + 1, len(string) + 1)]\r\n\r\n\r\ndef number_of_substrings(length):\r\n return int(length * (length + 1) / 2)\r\n\r\n\r\ndef is_prime(num):\r\n for i in range(2, num):\r\n if num / i == int(num / i) and num != i:\r\n return False\r\n\r\n return True\r\n\r\n\r\n\"\"\"for enumeration in range(int(input())):\r\n\"\"\"\r\nll = []\r\npp = []\r\nfor i in range(int(input())):\r\n l, p = map(int, input().split())\r\n ll.append(l)\r\n pp.append(p)\r\n\r\n\r\nprint(min([ll.count(0), ll.count(1)]) + min([pp.count(0), pp.count(1)]))", "t = int(input())\r\nl = [];r=[]\r\nfor i in range (t):\r\n d = [int(i) for i in input().split()]\r\n l.insert(0,d[0]); r.insert(0,d[1])\r\nsl = sum(l); sr = sum(r)\r\nif sl>t//2:\r\n sl = t-sl\r\nif sr>t//2:\r\n sr = t-sr\r\nprint(sl+sr) \r\n", "\r\nn = int(input())\r\nL, R = [], []\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n L.append(l)\r\n R.append(r)\r\nprint(min(L.count(0), L.count(1)) + min(R.count(0), R.count(1)))\r\n\r\n# CodeForcesian\r\n# ♥\r\n# تو نمیتونی کتابی رو باز کنی و از اون چیزی یاد نگیری\r\n", "import sys\r\n# cook your dish here\r\n\r\nn = int(sys.stdin.readline())\r\nleft, right = 0, 0\r\nfor i in range(n):\r\n l = list(map(int, sys.stdin.readline().split()))\r\n left += l[0]\r\n right += l[1]\r\n\r\nx = min(left, n-left)\r\ny = min(right, n-right)\r\n\r\nprint(x+y)\r\n", "n,m=0,0\r\nx=int(input())\r\nfor i in range(x):\r\n\ta,b=map(int,input().split())\r\n\tn+=a\r\n\tm+=b\r\nprint(min(n,x-n)+min(m,x-m))\r\n", "y=0\r\nl=[]\r\nr=[]\r\nn=int(input())\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\nif l.count(0)>=l.count(1):\r\n y+=l.count(1)\r\nelif l.count(0)<=l.count(1):\r\n y+=l.count(0)\r\nif r.count(0)>=r.count(1):\r\n y+=r.count(1)\r\nelif r.count(0)<=r.count(1):\r\n y+=r.count(0)\r\nprint(y)", "n=int(input())\r\np=[]\r\nq=[]\r\nfor i in range(n):\r\n\ts,t=map(int,input().split())\r\n\tp.append(s)\r\n\tq.append(t)\r\na=p.count(0)\r\nb=p.count(1)\r\nc=q.count(0)\r\nd=q.count(1)\r\nprint(min(a,b)+min(c,d))", "n = int(input())\nleft_open = 0\nright_open = 0\nfor _ in range(n):\n l, r = input().split()\n if l == \"1\":\n left_open += 1\n if r == \"1\":\n right_open += 1\ntime_cl = left_open\ntime_ol = n - left_open\ntime_cr = right_open\ntime_or = n - right_open\ntime = 0\nif time_cl > time_ol:\n time += time_ol\nelse:\n time += time_cl\nif time_cr > time_or:\n time += time_or\nelse:\n time += time_cr\nprint(time)", "n = int(input())\r\nxo = 0\r\nxc = 0\r\nyo = 0\r\nyc = 0\r\nfor i in range(n):\r\n t = input().split(' ')\r\n left = int(t[0])\r\n right = int(t[1])\r\n if left: xo+=1\r\n else: xc +=1\r\n if right: yo+=1\r\n else: yc+=1\r\n\r\nprint(str(min(yo,yc)+min(xo,xc)))", "n = int(input())\r\nsumA0, sumA1 = 0, 0\r\nsumB0, sumB1 = 0, 0\r\nfor i in range(n):\r\n x, y = map(int,input().split())\r\n if x == 0: sumA0 += 1\r\n else: sumA1 += 1\r\n if y == 0: sumB0 += 1\r\n else: sumB1 += 1\r\nprint(min(sumA0, sumA1) + min(sumB0, sumB1))\r\n", "k = int(input())\r\nl1 = []\r\nr1 = []\r\nt = 0\r\no = 0\r\nfor i in range(k):\r\n l, r = map(int, input().split())\r\n l1.append(l)\r\n r1.append(r)\r\nl1o=0\r\nl1l=0\r\nfor i in range(len(l1)):\r\n if l1[i]==0:\r\n l1o += 1\r\n else:\r\n l1l += 1\r\nif l1o>l1l:\r\n t+=l1l\r\n o += 1\r\nelse:\r\n t += l1o\r\nr1o=0\r\nr1l=0\r\nfor i in range(len(r1)):\r\n if r1[i]==0:\r\n r1o += 1\r\n else:\r\n r1l += 1\r\nif r1o>r1l:\r\n t+=r1l\r\nelse:\r\n t += r1o\r\nprint(t)", "n=int(input())\r\na=0\r\nb=0\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n a+=x\r\n b+=y\r\nprint (min(n-a,a) + min (n-b,b))", "# import os\r\n\r\nn = int(input())\r\n\r\ncupboard = []\r\nfor _ in range(n):\r\n cupboard.append(list(map(int,input().split())))\r\n\r\ncount_left_0 = 0\r\ncount_left_1 = 0\r\ncount_right_0 = 0\r\ncount_right_1 = 0\r\nfor left, right in cupboard:\r\n if left == 1:\r\n count_left_1 += 1\r\n else:\r\n count_left_0 += 1\r\n if right == 1:\r\n count_right_1 += 1\r\n else:\r\n count_right_0 += 1\r\n\r\na = count_left_0 if count_left_0 < count_left_1 else count_left_1\r\nb = count_right_0 if count_right_0 < count_right_1 else count_right_1\r\n \r\nprint(a+b)\r\n\r\n\r\n# proper: (numerator/denominator)\r\n# irreducible: (numerator & denominator => coprime)\r\n\r\n", "n=int(input())\r\ncnt1=cnt2=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n cnt1+=a\r\n cnt2+=b\r\nprint(min(cnt1,n-cnt1)+min(cnt2,n-cnt2))", "\r\nn = int(input())\r\nk = n\r\n\r\nleft_open = 0\r\nright_open = 0\r\n\r\n\r\nwhile k:\r\n\r\n l, r = list(map(int, input().split()))\r\n\r\n left_open += l\r\n right_open += r\r\n\r\n k -= 1\r\n\r\nprint(min(n-left_open, left_open) + min(n-right_open, right_open))\r\n\r\n", "l0 = 0\r\nl1 = 0\r\nr0 = 0\r\nr1 = 0\r\nfor m in range(int(input())):\r\n\tlr = list(map(int, input().split()))\r\n\tif lr[0] == 0:\r\n\t\tl0 += 1\r\n\telse:\r\n\t\tl1 += 1\r\n\tif lr[1] == 0:\r\n\t\tr0 += 1\r\n\telse:\r\n\t\tr1 += 1\r\nprint(min(l0, l1) + min(r0, r1))", "n = int(input())\r\nl, r = [], []\r\nfor i in range(n):\r\n\ttemp = list(map(int, input().split()))\r\n\tl.append(temp[0])\r\n\tr.append(temp[1])\r\n\r\nlcount = 0\r\nfor i in l:\r\n\tif i == 0:\r\n\t\tlcount += 1\r\nrcount = 0\r\nfor i in r:\r\n\tif i == 0:\r\n\t\trcount += 1\r\n\t\r\nt = 0\r\nif lcount < n / 2:\r\n\tt += lcount\r\nelse:\r\n\tt += n - lcount\r\nif rcount < n / 2:\r\n\tt += rcount\r\nelse:\r\n\tt += n - rcount\r\n\r\nprint(t)\r\n", "from collections import Counter\r\n\r\n\r\nn = int(input())\r\nleft = []\r\nright = []\r\ncount = 0\r\nfor _ in range(n):\r\n m = input().split()\r\n left.append(int(m[0]))\r\n right.append((m[-1]))\r\nleft = Counter(left).values()\r\nright = Counter(right).values()\r\nif len(left) == 1 and len(right) == 1:\r\n print(0)\r\nelif len(left) == 1:\r\n print(min(right))\r\nelif len(right) == 1:\r\n print(min(left))\r\nelse:\r\n print(min(left)+min(right))", "t = int(input())\r\nlo = 0\r\nle = 0\r\nro = 0\r\nre = 0\r\nfor i in range(t) :\r\n l,r = map(int,input().split())\r\n if l==0 :\r\n lo += 1\r\n if l==1 :\r\n le += 1\r\n if r==0 :\r\n ro += 1\r\n if r==1 :\r\n re += 1\r\nprint(min(lo,le)+min(ro,re))", "n = int(input())\r\na,b = [],[]\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n a.append(x)\r\n b.append(y)\r\n\r\nprint(min(a.count(0),a.count(1))+min(b.count(0),b.count(1)))", "n = int(input())\r\np = []\r\nl = []\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n p.append(a)\r\n l.append(b)\r\nprint(min(p.count(1),p.count(0)) + min(l.count(1),l.count(0)))", "def minsayısı(liste):\r\n sıfırsayısı = 0\r\n birsayısı = 0\r\n for i in liste:\r\n if i==0:\r\n sıfırsayısı +=1\r\n else:\r\n birsayısı += 1\r\n if birsayısı > sıfırsayısı:\r\n return sıfırsayısı\r\n else:\r\n return birsayısı\r\nuzunluk = int(input())\r\nsağlist =[]\r\nsollist =[]\r\nfor i in range(uzunluk):\r\n sol,sağ = map(int,input().split())\r\n sollist.append(sol)\r\n sağlist.append(sağ)\r\nprint(minsayısı(sollist)+minsayısı(sağlist))", "# l = [list(map(int,input().split())) for i in range(3)]\r\n# l1 = [[1,1,1],[1,1,1],[1,1,1]]\r\n# for i in range(3):\r\n# for j in range(3):\r\n# l[i][j]%=2\r\n# for i in range(3):\r\n# for j in range(3):\r\n# if l[i][j] == 1:\r\n# for y in range(0,3):\r\n# if l1[y][j] == 1:\r\n# l1[y][j] = 0\r\n# else:\r\n# l1[y][j] = 1\r\n# print('y')\r\n# for _ in range(3):\r\n# print(l1[_])\r\n# for x in range(0,3):\r\n# # print(x,j)\r\n# if x == j:\r\n# continue\r\n# else:\r\n# if l1[i][x] == 1:\r\n# l1[i][x] = 0\r\n# else:\r\n# l1[i][x] = 1\r\n# print('x')\r\n# for _ in range(3):\r\n# print(l1[_])\r\n# for i in range(3):\r\n# print(l1[i])\r\n\r\n\r\nn = int(input())\r\na1 = []\r\nb1 = []\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n a1.append(a)\r\n b1.append(b)\r\nfrom collections import Counter\r\na2 = Counter(a1)\r\nb2 = Counter(b1)\r\nc = 0\r\nif a2[0] == max(a2.values()):\r\n c+=n-a2[0]\r\nelse:\r\n c+=n-a2[1]\r\nif b2[0] == max(b2.values()):\r\n c+=n-b2[0]\r\nelse:\r\n c+=n-b2[1]\r\nprint(c)\r\n", "n = int(input())\r\nl = []\r\nr = []\r\nfor _ in range(n):\r\n li, ri = map(int, input().split())\r\n l.append(li)\r\n r.append(ri)\r\nprint(min([l.count(0), l.count(1)])+min([r.count(0), r.count(1)]))", "x_0 = 0\r\ny_0 = 0\r\nx_1 = 0\r\ny_1 = 0\r\ncount=0\r\nfor _ in range(int(input())):\r\n x,y = map(int,input().split())\r\n if x==0:\r\n x_0 += 1\r\n elif x == 1:\r\n x_1 += 1\r\n if y==0:\r\n y_0 += 1\r\n elif y == 1:\r\n y_1 += 1\r\n \r\nif x_0>x_1:\r\n count+=x_1\r\nelif x_0<=x_1:\r\n count+=x_0\r\nif y_0>y_1:\r\n count+=y_1\r\nelif y_0<=y_1:\r\n count+=y_0\r\nprint(count)\r\n", "n = int(input())\r\nleft = ''\r\nright = ''\r\nfor i in range(n):\r\n pair = input().split(' ')\r\n left += pair[0]\r\n right += pair[1]\r\nprint(min(left.count('0'), left.count('1')) + min(right.count('0'), right.count('1')))", "n = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\na = sum(l) if sum(l) < (len(l) - sum(l)) else (len(l) - sum(l))\r\nb = sum(r) if sum(r) < (len(r) - sum(r)) else (len(r) - sum(r))\r\nprint(a+b)", "n = int(input())\r\nleft = 0\r\nright = 0\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n left += a\r\n right += b\r\nprint(min(left, n-left) + min(right, n-right))", "import sys\r\nfrom os import path\r\n\r\nif (path.exists(\"C:/Users/hp/PycharmProjects/CODEFORCES/input.txt\")):\r\n sys.stdin = open(\"C:/Users/hp/PycharmProjects/CODEFORCES/input.txt\", \"r\")\r\n sys.stdout = open(\"C:/Users/hp/PycharmProjects/CODEFORCES/output.txt\", \"w\")\r\n\r\nn=int(input())\r\nlo=0\r\nlc=0\r\nro=0\r\nrc=0\r\n\r\nfor i in range(n):\r\n l,r=map(int,input().split(\" \"))\r\n if(l==0):\r\n lo=lo+1\r\n else:\r\n lc=lc+1\r\n if(r==0):\r\n ro=ro+1\r\n else:\r\n rc=rc+1\r\n\r\nprint(min(lc,lo)+min(rc,ro))\r\n\r\n\r\n", "x=int(input())\r\n\r\nlist=[]\r\nfor i in range(x):\r\n temp=input()\r\n list.append(temp)\r\n # temp.split(\" \")\r\n\r\nleftopen=0\r\nleftclose=0\r\nrightopen=0\r\nrightclose=0\r\n#step2: iterate through every door\r\nfor i in range(len(list)):\r\n x=list[i].split(\" \")\r\n #left close\r\n if x[0]==\"0\":\r\n leftclose+=1\r\n #left open\r\n if x[0]==\"1\":\r\n leftopen+=1\r\n #right open\r\n if x[1]==\"1\":\r\n rightopen+=1\r\n\r\n #right close\r\n if x[1]=='0':\r\n rightclose+=1\r\n\r\n# print(leftopen,leftclose,rightopen,rightclose)\r\ntemp=0\r\nif leftopen>leftclose:\r\n temp+=leftclose\r\n if rightopen>rightclose:\r\n temp+=rightclose\r\n else:\r\n temp+=rightopen\r\nelse:\r\n temp+=leftopen\r\n if rightopen>rightclose:\r\n temp+=rightclose\r\n else:\r\n temp+=rightopen\r\n\r\nprint(temp)\r\n", "l, r = [], []\r\nt = 0\r\n\r\nfor x in range(int(input())):\r\n a, b = map(int, input().split())\r\n l.append(a)\r\n r.append(b)\r\n\r\nif r.count(1) > r.count(0):\r\n t += r.count(0)\r\nelse:\r\n t += r.count(1)\r\n\r\nif l.count(1) > l.count(0):\r\n t += l.count(0)\r\nelse:\r\n t += l.count(1) \r\n\r\nprint(t)", "a=0\r\nb=0\r\nn=int(input())\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n a=a+l\r\n b=b+r\r\nprint(min(a,n-a)+min(b,n-b))", "n=int(input())\nl=[]\nr=[]\nl+=[0]*n\nr+=[0]*n\nc=0\nfor i in range(n): \n l[i],r[i]=map(int,input().split())\nif l.count(0)<l.count(1):\n c+=l.count(0)\nelse:\n c+=l.count(1)\nif r.count(0)<r.count(1):\n c+=r.count(0)\nelse:\n c+=r.count(1)\nprint(c)", "n=int(input())\r\nlist1=[]\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n list1.append([l,r])\r\n\r\ncount1=0\r\ncount2=0\r\nfor i in range(len(list1)):\r\n if list1[i][0]==0:\r\n count1=count1+1\r\n if list1[i][1]==0:\r\n count2=count2+1\r\ncount2a=n-count2\r\ncount1a=n-count1\r\n\r\ncount=0\r\nif count1a<count1:\r\n count=count+count1a\r\nif count1a>count1:\r\n count=count+count1\r\nif count1a==count1:\r\n count=count+count1\r\nif count2a<count2:\r\n count=count+count2a\r\nif count2a>count2:\r\n count=count+count2\r\nif count2a==count2:\r\n count=count+count2\r\nprint(count)", "x = int(input())\n\nlefto = 0\nrighto = 0\nfor i in range(x):\n j = list(input().split())\n if j[0] == '1':\n lefto += 1\n if j[1] == '1':\n righto += 1\n \ntotal = 0\nif lefto>(x-lefto):\n total += x-lefto\nelse:\n total += lefto\n\nif righto>(x-righto):\n total += x-righto\nelse:\n total += righto\n \nprint(f\"{total}\")\n ", "a1, a2 = [], []\r\nfor _ in range(int(input())):\r\n a = list(map(int, input().split(' ')))\r\n a1.append(a[0])\r\n a2.append(a[1])\r\nprint(min(a1.count(0), a1.count(1)) + min(a2.count(0), a2.count(1)))", "# arr = []\n# arr= list(map(int , (input().strip().split(' '))))\nn = int(input(\"\"))\n\nl = 0 \nr = 0\nfor i in range(0,n):\n arr= list(map(int , (input().strip().split(' '))))\n l +=arr[0]\n r += arr[1]\n\ntime =0 \nif(l>n-l):\n time+=(n-l)\nelse :\n time+= l\n\nif(r>n-r):\n time+=(n-r)\nelse :\n time+= r\n\nprint(time)", "n = int(input())\nl, r = 0, 0\nfor _ in range(n):\n left, right = map(int, input().split())\n l += left\n r += right\ncount = min(l, n - l) + min(r, n - r)\nprint(count)\n", "a = int(input())\r\nx = 0\r\nc = 0\r\nr = 0\r\ne = 0\r\nfor i in range(0, a):\r\n d, b = map(int, input().split())\r\n if d == 1:\r\n x += 1\r\n else:\r\n c += 1\r\n if b == 1:\r\n r += 1\r\n else:\r\n e += 1\r\nprint(min(x, c) + min(r, e))\r\n", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n x,y=input().split()\r\n l.append(int(x))\r\n r.append(int(y))\r\nz1=l.count(0)\r\no1=l.count(1)\r\nz2=r.count(0)\r\no2=r.count(1)\r\nres=0\r\nif(z1<o1):\r\n res+=z1\r\nelse:\r\n res+=o1\r\nif(z2<o2):\r\n res+=z2\r\nelse:\r\n res+=o2\r\nprint(res)", "n = int(input())\r\nlcountz = lcounto = rcountz = rcounto = 0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n if(l==0):\r\n lcountz += 1\r\n else:\r\n lcounto += 1\r\n if(r==0):\r\n rcountz += 1\r\n else:\r\n rcounto += 1\r\n\r\nif(lcountz<lcounto):\r\n ans = lcountz\r\nelse:\r\n ans = lcounto\r\n\r\nif(rcountz < rcounto):\r\n ans += rcountz\r\nelse:\r\n ans += rcounto\r\n\r\nprint(ans)\r\n", "n = int(input())\r\nleftOpen, righOpen = 0, 0\r\nfor _ in range(n):\r\n l, r = input().split()\r\n if l == '0':\r\n leftOpen += 1\r\n if r == '0':\r\n righOpen += 1\r\nprint(min(n - leftOpen, leftOpen) + min(n - righOpen, righOpen))", "x = int(input())\nleft = 0\nright = 0\nfor i in range(x):\n a,b = map(int,input().split())\n left += a\n right += b\n\nprint(min(right,x-right) + min(left,x - left))", "n =int(input())\r\nl = []\r\nr = []\r\nt = 0\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n l.append(x)\r\n r.append(y)\r\nif l.count(1)>l.count(0):\r\n t = t+l.count(0)\r\nelse:\r\n t = t+l.count(1)\r\nif r.count(1)>r.count(0):\r\n t= t+r.count(0)\r\nelse:\r\n t = t+r.count(1)\r\nprint(t)\r\n \r\n", "\r\n\r\ndef calc(cp):\r\n OPEN = 1\r\n CLOSED = 0\r\n N = len(cp)\r\n lo, ro = 0,0\r\n for l,r in cp:\r\n if l == OPEN:\r\n lo += 1\r\n if r == OPEN:\r\n ro += 1\r\n\r\n l = min(lo, N-lo)\r\n r = min(ro, N-ro)\r\n\r\n return l+r\r\n\r\n\r\n# get inputs\r\nn = int(input())\r\ncp = []\r\nfor _ in range(n):\r\n cp.append(list(map(int, input().split())))\r\nprint(calc(cp))\r\n\r\n\r\n\r\n\r\n", "x=y=0\r\nn=int(input())\r\nfor _ in[0]*n:a,b=map(int,input().split());x+=a;y+=b\r\nprint(min(n-x,x)+min(n-y,y))", "n = int(input())\r\nlo, ro = 0, 0\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n lo += l\r\n ro += r\r\n\r\nt = min(lo, n-lo) + min(ro, n-ro)\r\n\r\nprint(t)", "l, r =0,0\r\nn=int(input())\r\nfor i in range(n):\r\n x,y= map(int,input().split())\r\n if x == 1: l+=1\r\n if y==1:r+=1\r\n\r\nprint(min(l, n-l) + min(r, n-r)) ", "n = int(input())\r\nt = 0\r\nright_list = []\r\nleft_list = []\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n left_list.append(l)\r\n right_list.append(r)\r\nif left_list.count(0) > left_list.count(1):\r\n t += left_list.count(1)\r\nelse:\r\n t += left_list.count(0)\r\nif right_list.count(0) > right_list.count(1):\r\n t += right_list.count(1)\r\nelse:\r\n t += right_list.count(0)\r\nprint(t)\r\n", "n = int(input())\r\na, b = 0, 0\r\nfor i in range(n):\r\n u, v = map(int, input().split())\r\n a, b = a + u, b + v\r\nprint(min(a, n - a) + min(b, n - b))\r\n\r\n# i am from jasnah", "n = int(input().strip())\nl, r = 0, 0\nfor i in range(n):\n\tld, rd = tuple(map(int, input().strip().split()))\n\tif ld:\n\t\tl += 1\n\tif rd:\n\t\tr += 1\nprint(min(l, n - l) + min(r, n - r))\n", "from collections import Counter\r\nn=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n l1,r1=map(int,input().split(\" \"))\r\n l.append(l1)\r\n r.append(r1)\r\nld=Counter(l)\r\nlr=Counter(r)\r\n\r\nmax_ld=max(list(ld.values()))\r\nmax_lr=max(list(lr.values()))\r\nsum=(len(l)-max_ld)+(len(r)-max_lr)\r\nprint(sum)\r\n", "num = int(input())\r\nleft_count =0\r\nright_count =0\r\nfor _ in range(num):\r\n leftval,rightval = map(int,input().split())\r\n \r\n if leftval ==1:\r\n left_count += 1\r\n if rightval == 1:\r\n right_count += 1\r\nprint(\r\n min(num-left_count,left_count)+\r\n min(num-right_count,right_count))", "import sys\r\nimport math\r\nfrom collections import Counter\r\n# n = int(input())\r\n# a = list(map(int, input().split()))\r\n\r\nn = int(input())\r\na = list(list(map(int, input().split())) for i in range(n))\r\nl = list(u[0] for u in a)\r\nr = list(u[1] for u in a)\r\nl0 = l.count(0)\r\nr0 = r.count(0)\r\nprint(min(l0, n - l0) + min(r0, n - r0))\r\n\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n", "import sys\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_str(): return sys.stdin.readline().strip()\r\ndef get_int(): return int(sys.stdin.readline().strip())\r\ndef fast_print(*args, **kwargs):\r\n sep, file = kwargs.pop(\"sep\", \" \"), kwargs.pop(\"file\", sys.stdout)\r\n at_start = True\r\n for x in args:\r\n if not at_start:\r\n file.write(sep)\r\n file.write(str(x))\r\n at_start = False\r\n file.write(kwargs.pop(\"end\", \"\\n\"))\r\n if kwargs.pop(\"flush\", False):\r\n file.flush()\r\n\r\nn = get_int()\r\nc0, c1 = 0, 0\r\nfor _ in range(n):\r\n a, b = get_ints()\r\n if a == 0:\r\n c0 += 1\r\n if b == 0:\r\n c1 += 1\r\nprint(min(c0, n - c0) + min(c1, n - c1))\r\n\r\n\r\n", "from sys import stdin,stdout\nfrom math import gcd,sqrt,floor,ceil\n# Fast I/O\ninput = stdin.readline\n#print = stdout.write\n\ndef list_inp(x):return list(map(x,input().split()))\ndef map_inp(x):return map(x,input().split())\n\ndef lcm(a,b): return (a*b)/gcd(a,b)\n\nn = int(input())\nrcnt1,rcnt0,lcnt1,lcnt0=0,0,0,0\n\nfor i in range(n):\n a,b = map_inp(int)\n if a == 0:\n lcnt0+=1\n else:\n lcnt1+=1\n if b == 0:\n rcnt0+=1\n else:\n rcnt1+=1\nprint(min(rcnt0,rcnt1)+min(lcnt0,lcnt1))\n", "n = int(input())\r\nleft = []\r\nright = []\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n left.append(l)\r\n right.append(r)\r\nl_closed = left.count(0)\r\nl_opened = left.count(1)\r\nr_closed = right.count(0)\r\nr_opened = right.count(1)\r\nif l_closed > l_opened:\r\n count_l = l_opened\r\nelse:\r\n count_l = l_closed\r\nif r_closed > r_opened:\r\n count_r = r_opened\r\nelse:\r\n count_r = r_closed\r\nprint(count_l + count_r)\r\n", "import math\r\n# UNSOLVED\r\ndef solve(n, left, right):\r\n ans = 0\r\n left_sum = 0\r\n right_sum = 0\r\n limit = int(math.ceil(n / 2))\r\n for i in range(n):\r\n left_sum += left[i]\r\n right_sum += right[i]\r\n left_ans, right_ans = n - left_sum, n - right_sum\r\n if left_ans >= limit:\r\n ans += left_sum\r\n else:\r\n ans += left_ans\r\n if right_ans >= limit:\r\n ans += right_sum\r\n else:\r\n ans += right_ans\r\n return ans\r\n\r\ndef main():\r\n n = int(input())\r\n left, right = [], []\r\n for i in range(n):\r\n l = list(map(int, input().strip().split()))\r\n left.append(l[0])\r\n right.append(l[1])\r\n print(solve(n, left, right))\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\nsum_l, sum_r = 0, 0\nfor _ in range(n):\n l, r = map(int, input().split())\n sum_l += l\n sum_r += r\na = n - sum_l\nb = n - sum_r\nans = min(a, sum_l) + min(b, sum_r)\nprint(ans)\n \t\t\t \t\t\t\t \t\t \t \t \t\t\t\t\t \t\t\t", "n=int(input())\r\na=0\r\nb=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n if(l==0):\r\n a+=1\r\n if(r==0):\r\n b+=1\r\nprint(min(n-a,a)+min(n-b,b))\r\n\r\n", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\nlo=left.count(1)\r\nlc=left.count(0)\r\nro=right.count(1)\r\nrc=right.count(0)\r\ncount=0\r\nif lo>=lc:\r\n count=count+lc\r\nelse:\r\n count=count+lo\r\n\r\nif ro>=rc:\r\n count=count+rc\r\nelse:\r\n count=count+ro\r\nprint(count)", "num_cupboards=int(input())\nleft=[]\nright=[]\nfor i in range(num_cupboards):\n l,r=list(map(int,input().split()))\n left.append(l)\n right.append(r)\nrCount=0\nres=0\nfor cupboard in right:\n rCount+=cupboard\nif rCount>len(right)-rCount:\n res+=len(right)-rCount\nelse:\n res+=rCount\nlCount=0\nfor cupboard in left:\n lCount+=cupboard\nif lCount>len(left)-lCount:\n res+=len(left)-lCount\nelse:\n res+=lCount\nprint(res)\n \t\t \t\t\t \t \t\t\t \t \t\t\t\t \t\t", "n=int(input())\r\nc1=c2=c3=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a==1:\r\n c1+=1\r\n if b==1:\r\n c2+=1\r\nif c1>=(n-c1):\r\n c3+=n-c1\r\nelse:\r\n c3+=c1\r\nif c2>=(n-c2):\r\n c3+=n-c2\r\nelse:\r\n c3+=c2\r\nprint(c3)", "li = []; li2 = []\r\nfor _ in range(int(input())):\r\n l, r = map(int, input().split())\r\n li.append(l); li2.append(r)\r\nprint(min(li.count(1), li.count(0))+min(li2.count(1), li2.count(0)))", "# https://codeforces.com/problemset/problem/248/A\r\n\r\n\"\"\"\r\nWe have n cupboards\r\nEach one has a left and right door\r\n\r\nWe want to have all the left doors to be all open or all closed\r\nSame with the right doors (all open or all closed)\r\n\r\nFind the minimum number of moves to create this configuration\r\n\"\"\"\r\n\r\nimport sys\r\n\r\nn = int(sys.stdin.readline())\r\n\r\nleft = []\r\nright = []\r\n\r\nfor i in range(n):\r\n l_door, r_door = map(int, sys.stdin.readline().split())\r\n left.append(l_door)\r\n right.append(r_door)\r\n\r\nopen_left = sum(left)\r\nclosed_left = n - open_left\r\n\r\nopen_right = sum(right)\r\nclosed_right = n - open_right\r\n\r\nt = min(open_left + open_right, open_left + closed_right, closed_left + open_right, closed_left + closed_right)\r\n\r\nsys.stdout.write(str(t))\r\n\r\n\r\n", "n = int(input())\r\nr = 0\r\nl = 0\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n l += a\r\n r += b\r\n\r\nl = min(l, n - l)\r\nr = min(r, n - r)\r\nprint(r + l)", "def smlt(left, right, t):\n\ttl_value = min(sum(left), t - sum(left))\n\ttr_value = min(sum(right), t - sum(right))\n\n\treturn tl_value + tr_value\n\nt = int(input())\n\nleft = []\nright = []\n\nfor _ in range(t):\n\tarr = list(map(int, input().split()))\n\tleft.append(arr[0])\n\tright.append(arr[1])\n\nprint(smlt(left, right, t))", "numCB=int(input())\r\nleftCB=list()\r\nrightCB=list()\r\nfor i in range(numCB):\r\n x,y=list(map(int,input().split()))\r\n leftCB.append(x)\r\n rightCB.append(y)\r\n\r\nif leftCB.count(1)<leftCB.count(0):\r\n left=1\r\nelse:\r\n left=0\r\nif rightCB.count(1)<rightCB.count(0):\r\n right=1\r\nelse:\r\n right=0\r\n\r\n\r\ntime=leftCB.count(left)+rightCB.count(right)\r\nprint(time)\r\n", "n=int(input())\r\ncl=0\r\ncr=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a==1:\r\n cl+=1\r\n if b==1:\r\n cr+=1\r\nprint(min(cl,n-cl)+min(cr,n-cr))", "n = int(input())\r\nl0=0\r\nl1 = 0\r\nr0 = 0\r\nr1 = 0\r\nfor i in range(n):\r\n l,r = tuple(map(int,input().split()))\r\n if l==0:\r\n l0+=1\r\n if l==1:\r\n l1+=1\r\n if r==0:\r\n r0+=1\r\n if r==1:\r\n r1+=1\r\nprint(min(l0,l1) + min(r0,r1))\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\ncupboards = [input().split() for _ in range(n)]\r\na = sum(1 for c in cupboards if c[0] == '0')\r\nb = sum(1 for c in cupboards if c[1] == '0')\r\nprint(min(a, n-a) + min(b, n-b))", "n = int(input())\r\nleft_door = []\r\nright_door = []\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n left_door.append(a)\r\n right_door.append(b)\r\nprint(min(left_door.count(1), left_door.count(0))+min(right_door.count(1), right_door.count(0)))", "n=int(input())\nleftOne=0\n\nrightOne=0\nfor i in range(n):\n\tleft,right=list(map(int,input().split()))\n\tif left==1:\n\t\tleftOne+=1\n\tif right==1:\n\t\trightOne+=1\nwork=0\nif n-leftOne>leftOne:\n\twork+=leftOne\nelse:\n\twork+=n-leftOne\n\nif n-rightOne>rightOne:\n\twork+=rightOne\nelse:\n\twork+=n-rightOne\nprint(work)\n", "n = int(input())\r\nleft_open = right_open = 0\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n left_open += x\r\n right_open += y\r\nprint(min(left_open, n-left_open) + min(right_open, n-right_open))", "ans = 0\r\nd1,d2 = 0,0\r\nc1,c2 = 0,0\r\nfor _ in range(int(input())):\r\n s1, s2 = input().split()\r\n if s1 == \"0\":\r\n d1 += 1\r\n else :\r\n d2 += 1\r\n if s2 == \"0\":\r\n c1 += 1\r\n else :\r\n c2 += 1\r\nif d1 > d2 :\r\n ans += d2\r\nelse :\r\n ans += d1\r\nif c1 > c2 :\r\n ans += c2\r\nelse :\r\n ans += c1\r\nprint(ans)", "# import sys\r\n# sys.stdin = open(\"test.in\",\"r\")\r\n# sys.stdout = open(\"test.out.py\",\"w\")\r\nb,c,d,e=0,0,0,0\r\nfor i in range(int(input())):\r\n\tx,y=map(int,input().split())\r\n\tif x==0:\r\n\t\tb+=1\r\n\telse:\r\n\t\tc+=1\t\r\n\tif y==0:\r\n\t\td+=1\r\n\telse:\r\n\t\te+=1\r\nprint(min(b,c)+min(d,e))\t\t\t\t", "n = int(input())\r\n# li = []\r\nlo, ro = 0, 0\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n if l == 1:\r\n lo += 1\r\n if r == 1:\r\n ro += 1\r\n # li.append([l,r])\r\nprint(min(lo, n-lo)+ min(ro, n-ro))", "n = int(input())\r\nl,r = [None]*10001,[None]*10001\r\n\r\nfor i in range(n):\r\n\tl[i],r[i] = map(int, input().split())\r\n\r\n\r\nprint(min(l.count(1), l.count(0))+ min(r.count(1), r.count(0)))", "n = int(input())\nx, y = 0, 0\nfor i in range(n):\n l, r = map(int, input().split())\n x += l\n y += r\nprint(min(x, n - x) + min(y, n - y))", "n = int(input())\n\naa, bb = 0, 0\n\nfor i in range(n):\n a, b = map(int, input().split())\n aa += a\n bb += b\n\nans = min(abs(aa - n), abs(aa - 0)) + min(abs(bb - n), abs(bb - 0))\nprint(ans)\n\n \t\t \t \t\t \t\t\t \t \t \t\t\t \t\t \t \t", "n=int(input())\r\ni=0\r\nc00=c01=c10=c11=0\r\nwhile i<n:\r\n l=[int(x) for x in input().split()]\r\n if l[0]==0:\r\n c00+=1\r\n else:\r\n c01+=1\r\n if l[1]==0:\r\n c10+=1\r\n else:\r\n c11+=1\r\n i+=1\r\nprint(min(c00,c01)+min(c10,c11))\r\n ", "n = int(input())\r\n\r\n\r\nleft = []\r\nright = []\r\nfor x in range(n):\r\n doors = [int(c) for c in input().split(\" \")]\r\n left.append(doors[0])\r\n right.append(doors[1])\r\ncount = 0\r\n\r\nif left.count(1) >= left.count(0):\r\n count += left.count(0)\r\nelse:\r\n count += left.count(1)\r\n\r\nif right.count(1) >= right.count(0):\r\n count += right.count(0)\r\nelse:\r\n count += right.count(1)\r\n\r\nprint(count)\r\n\r\n", "t= int(input())\r\nleft=[]\r\nright=[]\r\nk=0\r\nfor i in range(t):\r\n a,b= map(int, input().split())\r\n left.append(a)\r\n right.append(b)\r\nlc= left.count(0)\r\nrc= right.count(0)\r\n\r\nif lc <= int(t/2):\r\n k+=lc\r\nelse:\r\n k+= t-lc\r\n\r\nif rc <= int(t/2):\r\n k+=rc\r\nelse:\r\n k+= t-rc\r\n\r\nprint(k)", "def solution():\r\n\tn=int(input())\r\n\tleft=0\r\n\tright=0\r\n\tfor i in range(n):\r\n\t\tl,r=map(int,input().split())\r\n\t\tleft+=l\r\n\t\tright+=r\r\n\tans=0\r\n\tif left<=n//2:\r\n\t\tans=ans+left\r\n\telse:\r\n\t\tans=ans+(n-left)\r\n\tif right<=n//2:\r\n\t\tans+=right\r\n\telse:\r\n\t\tans=ans+(n-right)\r\n\tprint(ans)\r\n\r\n\t\r\n\treturn\r\n\r\n\r\n\r\n\t\r\nsolution()\r\n", "n=int(input())\r\nx,y=0,0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n if(l>0):\r\n x=x+1\r\n if(r>0):\r\n y+=1\r\nprint(min(x,n-x)+min(y,n-y))\r\n", "def nom(l):\r\n zero=l.count(0)\r\n one=l.count(1)\r\n if zero>one:\r\n return(one)\r\n else:\r\n return(zero)\r\nt=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(t):\r\n a, b=map(int, input().split())\r\n l.append(a)\r\n r.append(b)\r\nprint(nom(l)+nom(r))\r\n", "n = int(input())\r\nleft = list()\r\nright = list()\r\nfor i in range(n):\r\n doors = input().split()\r\n left.append(int(doors[0]))\r\n right.append(int(doors[1]))\r\nseconds = 0\r\nl_zero = n - sum(left)\r\nl_one = sum(left)\r\nr_zero = n - sum(right)\r\nr_one = sum(right)\r\nif l_one > l_zero:\r\n seconds += l_zero\r\nelse:\r\n seconds+= l_one\r\nif r_one > r_zero:\r\n seconds += r_zero\r\nelse:\r\n seconds+= r_one\r\nprint(seconds)\r\n", "n = int(input())\r\nl_open = 0\r\nl_close = 0\r\nr_open = 0\r\nr_close = 0\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n if l:\r\n l_open += 1\r\n else:\r\n l_close += 1\r\n\r\n if r:\r\n r_open += 1\r\n else:\r\n r_close += 1\r\n\r\nprint(min(l_open, l_close)+min(r_open, r_close))\r\n", "n = int(input())\r\nl, r = 0, 0\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n l += x\r\n r += y\r\nprint(min(l, n - l) + min(r, n - r))", "n = int(input())\r\n\r\nl, r = [], []\r\n\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n\r\n l.append(x)\r\n r.append(y)\r\n\r\nl0, l1 = l.count(0), l.count(1)\r\n\r\nans = min(l0, l1)\r\nr0, r1 = r.count(0), r.count(1)\r\nans += min(r0, r1)\r\nprint(ans)\r\n", "n = int(input())\r\n\r\narr = [0]*2\r\nans = 0\r\nfor i in range(n):\r\n\tfor j, val in enumerate(map(int, input().split())):\r\n\t\tarr[j] += val\r\nif arr[0] <= (n//2):\r\n\tans += arr[0]\r\nelse:\r\n\tans += (n-arr[0])\r\nif arr[1] <= (n//2):\r\n\tans += arr[1]\r\nelse:\r\n\tans += (n-arr[1])\r\n\r\nprint(ans)", "def solve():\r\n n = int(input())\r\n numl = 0\r\n numr = 0\r\n for i in range(n):\r\n l,r = input().split()\r\n if(l == '1'):\r\n numl+=1\r\n if(r == '1'):\r\n numr+=1\r\n print(min(numl,n-numl)+min(numr,n-numr))\r\n return \r\nsolve()", "# # RED CODER # #\r\n# n = 'DDDDD'\r\n# for i in range(0,5,3):\r\n# D = i*\"D\"\r\n# print(D.center('*'))\r\n# n = int(input())\r\n# center = n*'D'\r\n# l = []\r\n# for i in range(n//2):\r\n# l.append()\r\nt = int(input())\r\nl1 = 0\r\nl0 = 0\r\nr1 = 0\r\nr0 = 0\r\nfor i in range(t):\r\n l, r = map(int, input().split())\r\n if l == 0:\r\n l0 += 1\r\n if l == 1:\r\n l1 += 1\r\n if r == 0:\r\n r0 += 1\r\n if r == 1:\r\n r1 += 1\r\nprint(min(l0,l1) + min(r0,r1))", "left, right = 0, 0\r\nn = int(input())\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n left += (l == 0)\r\n right += (r == 0)\r\nprint(min(left, n - left) + min(right, n - right))", "l = []\r\nl1 = []\r\nn = int(input())\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n l.append(a)\r\n l1.append(b)\r\na1 = l.count(0)\r\na2 = n - a1\r\nb1 = l1.count(0)\r\nb2 = n - b1\r\nprint(min(a1, a2)+min(b1, b2))", "n = int(input())\r\nnL, nR = 0, 0\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n nL += x \r\n nR += y\r\nprint(min(nL, n - nL) + min(nR, n - nR))", "n=int(input())\r\nl=[]\r\nr=[]\r\nsum1=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\n \r\ncount0=l.count(0)\r\ncount1=l.count(1)\r\nif(count0 > count1):\r\n sum1=sum1+count1\r\nelse:\r\n sum1=sum1+count0\r\n\r\ncount0=r.count(0)\r\ncount1=r.count(1)\r\nif(count0 > count1):\r\n sum1=sum1+count1\r\nelse:\r\n sum1=sum1+count0\r\n\r\nprint(sum1) ", "n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n l.append(a)\r\nlopen=int(0)\r\nropen=int(0)\r\nfor i in range(n):\r\n if l[i][0]==0:\r\n lopen+=1\r\n if l[i][1]==0:\r\n ropen+=1\r\nprint(min(lopen,n-lopen)+min(ropen,n-ropen))", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n t=input().split()\r\n a.append(t)\r\nl=0\r\nr=0\r\nfor t in a:\r\n if(t[0]=='1'):\r\n l+=1\r\n if(t[1]=='1'):\r\n r+=1\r\nc=0\r\nif(r>n//2):\r\n c+=(n-r)\r\nelse:\r\n c+=r\r\nif(l>n//2):\r\n c+=(n-l)\r\nelse:\r\n c+=l\r\n\r\nprint(c)", "l = int(input())\r\nlst1, lst2 = list(), list()\r\nfor _ in range(l):\r\n a, b = map(int, input().split())\r\n lst1.append(a)\r\n lst2.append(b)\r\nprint((l - (max(lst1.count(1), lst1.count(0)))) + (l - (max(lst2.count(1), lst2.count(0))))) ", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n a,b=list(map(int,input().split()))\r\n left.append(a)\r\n right.append(b)\r\ntime=0\r\nif(left.count(0)>left.count(1)):\r\n time+=left.count(1)\r\nelif(left.count(0)<left.count(1)):\r\n time+=left.count(0)\r\nelse:\r\n time+=left.count(0)\r\nif(right.count(0)>right.count(1)):\r\n time+=right.count(1)\r\nelif(right.count(0)<right.count(1)):\r\n time+=right.count(0)\r\nelse:\r\n time+=right.count(0)\r\nprint(time)", "c=int(input())\r\n\r\nstates=[]\r\nfor i in range(c):\r\n states.append(list(map(int,input().split())))\r\n \r\nlopen=0\r\nropen=0\r\nfor cup in states:\r\n \r\n if cup[0]==1:\r\n lopen+=1\r\n if cup[1]==1:\r\n ropen+=1\r\n\r\nt=0\r\nr=min(ropen,c-ropen)+min(lopen,c-lopen)\r\nt+=r\r\nprint(t)", "n=int(input())\r\nizqdaabierta=0\r\nizqdacerrada=0\r\ndchaabierta=0\r\ndchacerrada=0\r\n\r\nwhile n>0:\r\n a, b= map(int, input().split())\r\n\r\n if a==1:\r\n izqdaabierta+=1\r\n elif a==0:\r\n izqdacerrada+=1\r\n\r\n if b==1:\r\n dchaabierta+=1\r\n elif b==0:\r\n dchacerrada+=1\r\n \r\n n-=1\r\n\r\nif izqdacerrada>izqdaabierta:\r\n segundos=izqdaabierta\r\nelif izqdacerrada<izqdaabierta:\r\n segundos=izqdacerrada\r\nelse:\r\n segundos=izqdacerrada\r\n\r\nif dchaabierta>dchacerrada:\r\n segundos=segundos+dchacerrada\r\nelif dchaabierta<dchacerrada:\r\n segundos=segundos+dchaabierta\r\nelse:\r\n segundos=segundos+dchaabierta\r\n\r\nprint(segundos)", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor z in range(n):\r\n a,b=input().split()\r\n l.append(int(a))\r\n r.append(int(b))\r\nlo=l.count(1)\r\nlz=l.count(0)\r\nro=r.count(1)\r\nrz=r.count(0)\r\nprint(min(lo,lz)+min(ro,rz))", "o = 0\r\nc = 0\r\noo = 0\r\ncc = 0\r\nfor i in range(int(input())):\r\n a, b = map(int, input().split())\r\n if a == 1:\r\n o += 1\r\n elif a == 0:\r\n c += 1\r\n if b == 1:\r\n oo += 1\r\n elif b == 0:\r\n cc += 1\r\nans = min(o, c) + min(oo, cc)\r\nprint(ans)\r\n", "a,b=[],[]\r\nfor x in range(int(input())):\r\n\tc,d=map(int,input().split())\r\n\ta.append(c)\r\n\tb.append(d)\r\nprint(min(a.count(0),a.count(1))+min(b.count(0),b.count(1)))", "N = int(input())\r\nsuma_x, suma_y = 0,0\r\nfor _ in range(N):\r\n x,y = map(int, input().split())\r\n suma_x +=x \r\n suma_y +=y \r\n\r\nprint(min(suma_x,N-suma_x)+min(suma_y,N-suma_y))", "n = int(input())\r\nlopen = 0\r\nropen = 0\r\n\r\nfor i in range(n):\r\n cb = list(map(int, input().split()))\r\n lopen += cb[0]\r\n ropen += cb[1]\r\n\r\nmin_changes = min(lopen, n - lopen) + min(ropen, n - ropen)\r\nprint(min_changes)\r\n", "total = [0, 0]\r\nn = int(input())\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n total[0] += l\r\n total[1] += r\r\n\r\nfor i in range(2):\r\n total[i] = min(total[i], n - total[i])\r\n\r\nprint(sum(total))\r\n", "dolapSayisi = int(input())\r\nxacik = 0 \r\nxkapali = 0\r\nyacik = 0\r\nykapali = 0\r\nfor i in range(dolapSayisi):\r\n x, y = map(int, input().split())\r\n if x == 0:\r\n xkapali += 1\r\n elif x == 1:\r\n xacik += 1\r\n if y == 0:\r\n ykapali += 1\r\n elif y == 1:\r\n yacik += 1\r\nif xkapali >= xacik:\r\n a = xacik\r\nelse:\r\n a = xkapali\r\n\r\nif ykapali >= yacik:\r\n b = yacik\r\nelse:\r\n b = ykapali\r\nprint(a + b)\r\n\r\n", "# https://codeforces.com/problemset/problem/248/A\r\nimport sys\r\n#-----------------------------------------------------------------------------#\r\ntry:\r\n sys.stdin = open('inputs.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\nexcept:\r\n pass\r\nfinally:\r\n input = sys.stdin.readline\r\n print = sys.stdout.write\r\n\r\n#-----------------------------------------------------------------------------#\r\nt = int(input())\r\n\r\nleft_closed = 0\r\nright_closed = 0\r\n\r\nfor _ in range(t):\r\n\r\n l, r = input().split()\r\n if l == '0':\r\n left_closed += 1\r\n if r == '0':\r\n right_closed += 1\r\n\r\ntotal = (left_closed if (left_closed <= t // 2) else (t - left_closed)) + (\r\n right_closed if (right_closed <= t // 2) else (t - right_closed))\r\n\r\nprint(str(total))\r\n", "n, c, d = int(input()), [], []\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n c.append(a)\r\n d.append(b)\r\nprint(min(c.count(1), c.count(0)) + min(d.count(1), d.count(0)))\r\n", "# https://codeforces.com/problemset/problem/248/A\n\ndef final_position(new_dict, n): #determining the final position of the doors, given minimum time\n left1, left0, right1 ,right0 = 0,0,0,0\n for i in range(0,n):\n if new_dict[i][0] == 1:\n left1 += 1\n else: left0 += 1\n if new_dict[i][1] == 1:\n right1 += 1\n else: right0 += 1\n if left1 >= left0:\n left = 1\n else: left = 0\n if right1 >= right0:\n right = 1\n else: right = 0\n return [left, right]\n\nnew_dict = {}\nn = int(input())\nfor i in range(0,n):\n new_dict[i] = list(map(int, input().split()))\n\nfinal_left, final_right = final_position(new_dict, n)[0] , final_position(new_dict, n)[1]\nsum = 0\nfor i in range(0,n):\n if new_dict[i][0] != final_left:\n sum +=1\n if new_dict[i][1] != final_right:\n sum +=1\nprint(sum)", "n = int(input())\r\nlc,rc = 0,0\r\nfor _ in range(n):\r\n l,r = list(map(int,input().split(' ')))\r\n lc += l\r\n rc += r\r\nprint(min(lc,n-lc)+min(rc,n-rc))\r\n\r\n\r\n\r\n", "n = int(input())\nleft,right = {0:0,1:0},{0:0,1:0}\nfor _ in range(n):\n a,b = map(int,input().split())\n left[a] += 1\n right[b] += 1\nans = 0\nif left[0]>=left[1]:\n ans += n-left[0]\nelse:\n ans += n-left[1]\nif right[0]>=right[1]:\n ans += n-right[0]\nelse:\n ans += n-right[1]\nprint(ans)\n", "n = int(input())\r\nleft_sum = 0\r\nright_sum = 0\r\nfor i in range(n):\r\n l, r = map(int,input().split())\r\n left_sum += l\r\n right_sum += r\r\nprint(min(left_sum, n-left_sum) + min(right_sum, n-right_sum))", "def main_function():\r\n n = int(input())\r\n l_0 = 0\r\n r_0 = 0\r\n for i in range(n):\r\n l, r = [int(i) for i in input().split(\" \")]\r\n if l == 0:\r\n l_0 += 1\r\n if r == 0:\r\n r_0 += 1\r\n return min(l_0, n - l_0) + min(r_0, n - r_0)\r\n\r\n\r\nprint(main_function())", "a=int(input())\r\ncount=0\r\ncount1=0\r\ncount2=0\r\ncount3=0\r\nfor i in range(a):\r\n c,d=map(int,input().split())\r\n if c==1:\r\n count+=1\r\n if d==0:\r\n count+=1\r\n if c==0:\r\n count1+=1\r\n if d==1:\r\n count1+=1\r\n if c == 0:\r\n count2 += 1\r\n if d == 0:\r\n count2 += 1\r\n if c == 1:\r\n count3 += 1\r\n if d == 1:\r\n count3 += 1\r\n \r\n\r\nprint(min(count,count1,count2,count3))\r\n\r\n", "n=int(input());x=y=0\r\nfor _ in [0]*n:\r\n a,b=map(int,input().split())\r\n if a:x+=1\r\n if b:y+=1\r\nprint(min(x,n-x)+min(y,n-y))", "n = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\nans = 0\r\nans += min(l.count(0),l.count(1))\r\nans += min(r.count(1),r.count(0))\r\nprint(ans)", "doors = int(input())\nleft_closed = 0\nright_closed = 0\nfor i in range(doors):\n l, t = tuple(map(int, input().split()))\n left_closed += l\n right_closed += t\n\nprint(min(doors - left_closed, left_closed) + min(doors - right_closed, right_closed)) \n\n\n\n", "\nt=int(input())\nlo=0\nlc=0\nrc=0\nro=0\nfor _ in range(0,t):\n a,b=list(map(int,input().split()))\n if a:\n lo=lo+1;\n else:\n lc=lc+1\n if b:\n ro=ro+1\n else:\n rc=rc+1\nprint(min(lo,lc)+min(ro,rc))\n\n", "n = int(input())\r\n\r\ncount = 0\r\nswap = 0\r\n\r\nll = []\r\nlr = []\r\n\r\nfor i in range(n):\r\n a, b = input().split()\r\n ll.append(a)\r\n lr.append(b)\r\n\r\ncount_0_ll = n - ll.count('0')\r\ncount_1_ll = n - ll.count('1')\r\n\r\ncount_0_lr = lr.count('0')\r\ncount_1_lr = lr.count('1')\r\n\r\n\r\nif count_0_ll <= count_1_ll:\r\n swap += count_0_ll\r\nelse:\r\n swap += count_1_ll\r\n\r\nif count_0_lr <= count_1_lr:\r\n swap += count_0_lr\r\nelse:\r\n swap += count_1_lr\r\n\r\n\r\n\r\nprint(swap)\r\n", "n = int(input())\nlc = 0\nrc = 0\nfor i in range(n):\n\ta = input().split()\n\tl,r = int(a[0]) , int(a[1])\n\tlc+=l\n\trc+=r \nprint(min(rc,n-rc)+min(lc,n-lc))", "'''\nواقعا کی فکرشو میکرد\n'''\nLeft1=Left0=Right0=Right1=0\nessi = int(input())\nfor i in range(essi):\n a,b=map(int,input().split())\n if a==0:\n Left0+=1\n else:\n Left1+=1\n if b==0:\n Right0+=1\n else:\n Right1+=1\nprint(min(Left0,Left1)+min(Right0,Right1))", "n = int(input())\r\nlc=lo=rc=ro=0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n if l==0: lc+=1\r\n elif l==1: lo+=1\r\n if r==0: rc+=1\r\n elif r==1: ro+=1\r\nl = min(lc,lo)\r\nr = min(ro,rc)\r\nprint(l+r)\r\n \r\n", "n = int(input())\r\nleft, right = 0, 0\r\nfor i in range(n):\r\n l, r = input().split(\" \")\r\n left+=int(l)\r\n right+=int(r)\r\nans = (min(left, n-left)+min(right, n-right))\r\nprint(ans)", "N = int(input())\r\nR = list()\r\nL = list()\r\nfor i in range(N):\r\n Left, Right = list(input().split())\r\n L.append(Left)\r\n R.append(Right)\r\nCount = min(R.count(\"1\"), R.count(\"0\"))\r\nCount += min(L.count(\"1\"), L.count(\"0\"))\r\nprint(Count)\r\n", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n x= [int(i) for i in input().strip().split()]\r\n a.append(x)\r\ncount_0l=0\r\ncount_1l=0\r\ncount_0r=0\r\ncount_1r=0\r\n\r\nfor i in range(n):\r\n if a[i][0]==0:\r\n count_0l+=1\r\n else:\r\n count_1l+=1\r\n if a[i][1]==0:\r\n count_0r+=1\r\n else:\r\n count_1r+=1\r\n\r\nleft=[count_0l, count_1l]\r\nright=[count_0r,count_1r]\r\n\r\nprint(min(left)+min(right))\r\n\r\n", "n=int(input())\r\nr1=0\r\nl1=0\r\nr0=0\r\nl0=0\r\n\r\nfor i in range (0,n):\r\n x,y=map(int,input().split())\r\n if (x==1):\r\n l1+=1\r\n else:\r\n l0+=1\r\n if(y==1):\r\n r1+=1\r\n else:\r\n r0+=1\r\nt=0\r\n\r\n\r\nlmax=max(l1,l0)\r\nrmax=max(r1,r0)\r\nthemax=max(lmax,rmax)\r\n\r\nif(l1==l0):\r\n t+=n-l0\r\nelif(l1>l0):\r\n t+=n-l1\r\nelse:\r\n t+=n-l0\r\n\r\nif(r1==r0):\r\n t+=n-r0\r\nelif(r1>r0):\r\n t+=n-r1\r\nelse:\r\n t+=n-r0\r\n\r\nprint(t)\r\n\r\n", "n=int(input())\r\nlis1=[]\r\nlis2=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n lis1.append(a)\r\n lis2.append(b)\r\ncount1=min(lis1.count(1),lis1.count(0))\r\ncount2=min(lis2.count(1),lis2.count(0))\r\nprint(count1+count2)", "n=int(input())\r\no_l = 0\r\nq_l = 0\r\no_r = 0\r\nq_r = 0\r\nfor i in range(n):\r\n a,b=map(str,input().split())\r\n if a=='0':\r\n o_l+=1\r\n elif a=='1':\r\n q_l+=1\r\n if b=='0':\r\n o_r+=1\r\n elif b=='1':\r\n q_r+=1\r\nprint(min(o_l,q_l)+min(o_r, q_r))", "import sys\n\nn = int(sys.stdin.readline())\n\na = 0\nb = 0\nfor i in range(n):\n (aa, bb) = map(int, sys.stdin.readline().split(' '))\n a += aa\n b += bb\n\nsys.stdout.write(\"{}\\n\".format(min(abs(a), n - abs(a)) + min(abs(b), n - abs(b))))\n\n\n", "I=lambda:map(int,input().split())\r\na=[0,0]\r\nb=[0,0]\r\nfor _ in'0'*next(I()):c,d=I();a[c]+=1;b[d]+=1\r\nprint(min(a)+min(b))\r\n\r\n", "n=int(input())\r\nl=[0]*n\r\nr=[0]*n\r\nc=0\r\nfor i in range(n):\r\n l[i],r[i]=map(int,input().split())\r\nif l.count(1)>l.count(0):\r\n c=c+l.count(0)\r\nelse:\r\n c=c+l.count(1)\r\nif r.count(1)>r.count(0):\r\n c=c+r.count(0)\r\nelse:\r\n c=c+r.count(1)\r\nprint(c) ", "n = int(input())\r\nx,y = 0,0\r\nfor i in range(n):\r\n a = input()\r\n if int(a[0]) == 0:\r\n x += 1\r\n if int(a[2]) == 0:\r\n y += 1\r\nt = (min(x,n-x) + min(y,n-y))\r\nprint(t)", "# Author: Riddhish V. Lichade\r\n# username: root_rvl\r\n\r\nfrom collections import Counter\r\nfrom sys import stdin, stdout\r\nfrom heapq import nlargest, nsmallest\r\n\r\n\r\ndef outnl(x): stdout.write(str(x) + '\\n')\r\n\r\n\r\ndef outsl(x): stdout.write(str(x) + ' ')\r\n\r\n\r\ndef instr(): return stdin.readline().strip()\r\n\r\n\r\ndef inint(): return int(stdin.readline())\r\n\r\n\r\ndef inspsint(): return map(int, stdin.readline().strip().split())\r\n\r\n\r\ndef inlist(): return list(map(int, stdin.readline().strip().split()))\r\n\r\n\r\nfor _ in range(1):\r\n n=inint()\r\n l0=0\r\n l1=0\r\n r0=0\r\n r1=0\r\n for i in range(n):\r\n l,r=inspsint()\r\n if(l==0):\r\n l0+=1\r\n else:\r\n l1+=1\r\n if r==0:\r\n r0+=1\r\n else:\r\n r1+=1\r\n ml=min(l0,l1)\r\n mr=min(r1,r0)\r\n outnl(ml+mr)", "n = int(input())\r\nright = []\r\nleft = []\r\nfor i in range(n):\r\n r, l = map(int, input().split())\r\n right.append(r)\r\n left.append(l)\r\nrighttime = min(right.count(0), right.count(1))\r\nlefttime = min(left.count(0), left.count(1))\r\nprint(righttime + lefttime)\r\n", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n lst=list(map(int,input().split()))\r\n l.append(lst[0])\r\n r.append(lst[1])\r\nt=0\r\nif 0 in l and 1 in l:\r\n if l.count(1)>=l.count(0):\r\n for i in l:\r\n if i==0:\r\n t=t+1\r\n elif l.count(0)>l.count(1) :\r\n for i in l:\r\n if i==1:\r\n t=t+1\r\nif 0 in r and 1 in r:\r\n if r.count(1)>=r.count(0):\r\n for i in r:\r\n if i==0:\r\n t=t+1\r\n elif r.count(0)>r.count(1):\r\n for i in r:\r\n if i==1:\r\n t=t+1\r\nprint(t)\r\n \r\n", "t = int(input())\r\nl = []\r\nr = []\r\nfor i in range(t):\r\n\ta, b = map(int, input().split())\r\n\tl.append(a)\r\n\tr.append(b)\r\nc = l.count(0)\r\nd = l.count(1)\r\ntime = min(c, d)\r\ne = r.count(0)\r\nf = r.count(1)\r\n\r\ntime += min(e, f)\r\nprint(time)\r\n", "def Sol(arrl,arr):\r\n\t\r\n\tcl = min(arrl.count(0),arrl.count(1))\r\n\tcr = min(arr.count(1),arr.count(0))\r\n\r\n\tprint(cl+cr)\r\n\treturn\t\r\n\r\narrl = []\r\narr = []\r\nfor t in range(int(input())):\r\n\ttest = list(map(int,input().split()))\r\n\tarrl.append(test[0])\r\n\tarr.append(test[1])\r\n#l = list(map(int,input().split()))\r\nSol(arrl,arr)\r\n", "n = int(input())\n\nl = r = 0\nfor tc in range(n):\n a, b = map(int, input().split())\n l += a\n r += b\n\nansL = min(l, n - l)\nansR = min(r, n - r)\n\nprint(ansL + ansR)\n", "n = int(input())\r\nl = 0\r\nr = 0\r\nfor door in range(n):\r\n s = [int(x) for x in input().split(' ')]\r\n l += s[0]\r\n r += s[1]\r\nanswer = min(l, n - l) + min(r, n - r)\r\nprint(answer)\r\n", "n = int(input())\r\ns = []\r\nsample = [[0,0],[0,1],[1,0],[1,1]]\r\nc = [0]*4\r\nfor i in range(n):\r\n s.append(list(map(int, input().split())))\r\nfor i in range(4):\r\n for j in range(n):\r\n c[i] += abs(sample[i][0] - s[j][0]) + abs(sample[i][1] - s[j][1])\r\nprint(min(c))\r\n", "n=int(input())\r\nsl,sr=0,0\r\nfor i in range(n):\r\n l,r=input().split()\r\n l,r=int(l),int(r)\r\n sl+=l\r\n sr+=r\r\n def cupboard(sl,sr,n):\r\n if(sl>sr):\r\n s1=n-sl\r\n if(sr>n//2):\r\n s2=n-sr\r\n else:\r\n s2=sr\r\n return(s1+s2)\r\n elif(sl==0 and sr==0):\r\n return(0)\r\n else:\r\n s1=n-sr\r\n if(sl>n//2):\r\n s2=n-sl\r\n else:\r\n s2=sl\r\n return(s1+s2)\r\nprint(cupboard(sl,sr,n))\r\n \r\n", "n = int(input())\r\n\r\n_l_ = []\r\n_r_ = []\r\n\r\nfor _ in range(n):\r\n a, b = list(map(int, input().split(\" \")))\r\n _l_.append(a)\r\n _r_.append(b)\r\n\r\nprint(min(sum(_l_), n - sum(_l_)) + min(sum(_r_), n - sum(_r_)))", "n = int(input())\nl = r = 0\n\nfor i in range(n):\n a,b = map(int, input().split())\n l += a\n r += b\n\nans = min(n-l,l) + min(n-r,r)\nprint(ans)\n\n# 1482245084943", "n=int(input())\r\ncl=cr=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n cl+=l\r\n cr+=r\r\nprint(min(cl,n-cl)+min(cr,n-cr))", "import math\r\nimport os\r\nt = input()\r\nt = int(t)\r\ngrid = [list(map(int, input().split())) for _ in range(t)]\r\nf = 0\r\ns = 0\r\nfor i in range(t) :\r\n f += grid[i][0]\r\n s += grid[i][1]\r\nans = 0\r\nif f > int(t/2) :\r\n ans += (t-f)\r\nelse:\r\n ans += (f)\r\nif s > int(t/2) :\r\n ans += (t-s)\r\nelse:\r\n ans += (s)\r\nprint(ans)\r\n # for _ in range(int(input())):\r\n # grid = [list(map(int, input().split())) for _ in range(3)]\r\n # result = [[1] * 3 for _ in range(3)]\r\n # n, s, r = map(int, input().split())\r\n # arr = list(map(int, input().split()))\r\n # n = input()\r\n # n = int(n)", "\r\nimport sys\r\ndef get_single_int ():\r\n return int (sys.stdin.readline ().strip ())\r\ndef get_string ():\r\n return sys.stdin.readline ().strip ()\r\ndef get_ints ():\r\n return map (int, sys.stdin.readline ().strip ().split ())\r\ndef get_list ():\r\n return list (map (int, sys.stdin.readline ().strip ().split ()))\r\n\r\n#code starts here\r\nn = get_single_int ()\r\nar = []\r\nans = 0 \r\nfor i in range (n):\r\n ar.append (get_list ())\r\ncount_zero = 0\r\ncount_one = 0\r\nfor j in range (n):\r\n if ar [j] [0] == 1:\r\n count_one += 1\r\n else:\r\n count_zero += 1\r\nif count_zero > count_one:\r\n ans += (n - count_zero)\r\nelse:\r\n ans += (n - count_one)\r\ncount_zero = 0\r\ncount_one = 0\r\nfor j in range (n):\r\n if ar [j] [1] == 1:\r\n count_one += 1\r\n else:\r\n count_zero += 1\r\nif count_one < count_zero:\r\n ans += (n - count_zero)\r\nelse:\r\n ans += (n - count_one)\r\n\r\nprint (ans)\r\n\r\n\r\n \r\n", "n=int(input())\r\nl0=l1=r0=r1=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a:\r\n l1+=1\r\n else:\r\n l0+=1\r\n if b:\r\n r0+=1\r\n else:\r\n r1+=1\r\nprint(min(l1,l0)+min(r1,r0))", "n=int(input(''))\r\nl=[]\r\nfor i in range(n):\r\n a=input('')\r\n b=a.split(' ')\r\n l.append(b)\r\nt=0\r\nfor j in range(2):\r\n o=0\r\n z=0\r\n for i in range(n):\r\n if l[i][j]=='1':\r\n o+=1\r\n else:\r\n z+=1\r\n if o>z:\r\n t+=z\r\n else:\r\n t+=o\r\n\r\n\r\nprint(t)", "import sys\r\nimport math\r\n\r\nn = int(sys.stdin.readline())\r\n\r\nlc = 0\r\nrc = 0\r\nlo = 0\r\nro = 0\r\nfor i in range(n):\r\n l, r = [int(x) for x in (sys.stdin.readline()).split()]\r\n if(l == 1):\r\n lc += 1\r\n else:\r\n lo += 1\r\n if(r == 1):\r\n rc += 1\r\n else:\r\n ro += 1\r\n\r\nres = 0 \r\nif(rc >= ro):\r\n res += ro\r\nelse:\r\n res += rc\r\n \r\nif(lc >= lo):\r\n res += lo\r\nelse:\r\n res += lc\r\n \r\nprint(res)\r\n \r\n\r\n \r\n \r\n \r\n ", "n = int(input())\r\nleftOpen, leftClosed, rightOpen, rightClosed = 0, 0, 0, 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n if l == 0:\r\n leftClosed += 1\r\n if l == 1:\r\n leftOpen += 1\r\n if r == 0:\r\n rightClosed += 1\r\n if r == 1 :\r\n rightOpen += 1\r\nans = min(leftOpen, leftClosed) + min(rightOpen, rightClosed)\r\nprint(ans)", "n = int(input())\r\nL,R = 0,0\r\nfor i in range(n):\r\n l,r = map(int, input().split())\r\n L += l\r\n R += r\r\nprint(min(L,n-L)+min(R,n-R))\r\n", "p=input\r\nN=int(p())\r\nL=0\r\nR=0\r\nfor _ in'.'*N:\r\n\tl,r=map(int,p().split())\r\n\tL+=l\r\n\tR+=r\r\nprint(min(L,N-L)+min(R,N-R))", "N = int(input())\r\ntotal_l = 0\r\ntotal_r = 0\r\nfor i in range(N):\r\n l, r = list(map(int, input().split()))\r\n total_r += r\r\n total_l += l\r\nprint(min(N-total_r,total_r) + min(N-total_l,total_l))", "def read():\r\n inputs = input().strip()\r\n return list(map(int, inputs.split()))\r\ndef read_pair():\r\n return map(int, input().split(' '))\r\ndef read_str():\r\n return map(str, input().split(' '))\r\nn = int(input())\r\nans1 = 0\r\nans2 = 0\r\nfor i in range (n):\r\n x, y = read_pair()\r\n ans1 += x\r\n ans2 += y\r\nprint(min(ans1, n - ans1) + min(ans2, n - ans2))", "n=int(input())\r\na,b=0,0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n a+=l\r\n b+=r\r\nprint(min(a,n-a)+min(b,n-b))", "n = int(input())\nl1 =l0 =r1= r0 = 0\nans = 0\nfor i in range(n):\n x,y = map(int,input().split())\n if x == 1: l1+=1\n if x == 0: l0+=1\n if y ==1: r1+=1\n if y==0: r0+=1\nif l1>=l0:\n ans+=l0\nelse:\n ans+=l1\nif r1>=r0:\n ans+=r0\nelse:\n ans+=r1\nprint(ans)\n\n \n ", "n = int(input())\r\nnums = []\r\ncount = [0,0,0,0]\r\n\r\nclosedLeft=0\r\nopenLeft = 0\r\nclosedRight = 0\r\nopenRight = 0\r\n\r\nfor i in range(0,n):\r\n x = input().split(\" \")\r\n # x.remove(\" \")\r\n nums.append([int(x[0]),int(x[1])])\r\n if x[0] == '0':\r\n closedLeft += 1\r\n elif x[0] == '1':\r\n openLeft += 1\r\n if x[1] == '0': \r\n closedRight += 1\r\n elif x[1] == '1':\r\n openRight += 1\r\ncount[0] = openLeft + openRight\r\ncount[1] = openLeft + closedRight\r\ncount[2] = closedLeft + openRight\r\ncount[3] = closedLeft + closedRight\r\n\r\ncount.sort()\r\nprint(count[0])\r\n \r\n\r\n ", "t = int(input())\r\nleft0 = left1 = right0 = right1 = 0\r\nfor i in range(t):\r\n s, y = [int(x) for x in input().split()]\r\n if s == 1: left0 += 1\r\n else: left1 +=1\r\n if y == 1: right0 += 1\r\n else: right1 += 1\r\n\r\nprint(min(right0, right1) + min(left0, left1))", "n = int(input())\r\nl = r = 0\r\nfor i in range(n):\r\n a,b = map(int,input().split())\r\n l+=a\r\n r+=b\r\nprint(min(l,n-l)+min(r,n-r))", "n=int(input())\r\na=[]\r\nv=z=x=y=0\r\nfor i in range(n):\r\n a.append(list(map(int,input().split())))\r\nfor i in range(n):\r\n if a[i][0]==0:\r\n x+=1\r\n if a[i][1]==1:\r\n z+=1\r\n if a[i][0]==1:\r\n y+=1\r\n if a[i][1]==0:\r\n v+=1\r\nif x<y:\r\n if z<v:\r\n print(x+z)\r\n else:\r\n print(x+v)\r\nelse:\r\n if z<v:\r\n print(y+z)\r\n else:\r\n print(y+v)", "import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\nimport random\r\n\r\n\r\ndef main():\r\n L = [0] * 2\r\n R = [0] * 2\r\n n = int(input())\r\n for i in range(n):\r\n a, b = map(int, input().split())\r\n L[a] += 1\r\n R[b] += 1\r\n print(min(L) + min(R))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\r\nl_open = l_closed = 0\r\nr_open = r_closed = 0\r\n\r\n\r\nfor _ in range(n):\r\n left, right = input().split()\r\n # ------------------------\r\n if left=='1': l_open += 1\r\n else: l_closed += 1\r\n # ------------------------\r\n if right=='1': r_open += 1\r\n else: r_closed += 1\r\n\r\n\r\nprint(min(l_open, l_closed) + min(r_open, r_closed))\r\n", "import sys,os,io,time\r\nif os.path.exists('input.txt'):\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\n\r\n\r\ndef main():\r\n n=int(input())\r\n a=[]\r\n b=[]\r\n for _ in range(n):\r\n x,y=map(int,input().split())\r\n a.append(x)\r\n b.append(y)\r\n res=0\r\n res+=min(sum(a),n-sum(a))\r\n res+=min(sum(b),n-sum(b))\r\n print(res)\r\n\r\nmain()", "t=int(input())\r\nend=[]\r\nfor i in range(t):\r\n x=list(map(int,input().split()))\r\n end.append(x)\r\nq1=0\r\nq0=0\r\nw1=0\r\nw0=0\r\nfor i in end:\r\n if i[0]==1:\r\n q1+=1\r\n elif i[0]==0 :\r\n q0+=1\r\n if i[1] == 1:\r\n w1 += 1\r\n elif i[1] == 0:\r\n w0 += 1\r\nanswer=0\r\n\r\nif q1<q0:\r\n answer+=q1\r\nelse:\r\n answer+=q0\r\nif w1<w0:\r\n answer+=w1\r\nelse:\r\n answer+=w0\r\nprint(answer)", "n= int(input())\r\nlc = lo = rc = ro = 0\r\n\r\nfor i in range(n):\r\n a, b = map(int,input().split())\r\n \r\n if a==0:\r\n lc+=1\r\n else:\r\n lo+=1\r\n if b==0:\r\n rc+=1\r\n else:\r\n ro+=1\r\n\r\nprint(min(lo,lc)+min(ro,rc))", "n = int(input())\r\nl_zero = 0\r\nl_one = 0\r\nr_zero = 0\r\nr_one = 0\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n if x == 0:\r\n l_zero += 1\r\n else:\r\n l_one += 1\r\n if y == 0:\r\n r_zero += 1\r\n else:\r\n r_one += 1\r\nprint(min(l_zero, l_one) + min(r_zero, r_one))", "n = int(input())\r\nca = 0\r\ncb = 0\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n if a == 0:\r\n ca = ca + 1\r\n if b == 0:\r\n cb = cb + 1\r\nma = min(ca,(n-ca))\r\nmb = min(cb,(n-cb))\r\nprint(ma + mb)\r\n", "n=int(input())\r\nl = []\r\nr = []\r\nfor x in range(n):\r\n\tli,ri = [int(x) for x in input().split()]\r\n\tl.append(li)\r\n\tr.append(ri)\r\n\r\nprint(min(l.count(0),l.count(1))+min(r.count(0),r.count(1)))", "x = int(input())\r\nl ,l1= [], []\r\ncnt_a, cnt_b =0, 0\r\nfor i in range(x):\r\n a,b = map(int,input().split())\r\n if a == 1:\r\n cnt_a += 1\r\n if b == 1:\r\n cnt_b += 1\r\n l.append(a)\r\n l1.append(b)\r\nt = 0\r\nt += min(cnt_a, x - cnt_a)\r\nt += min(cnt_b, x - cnt_b)\r\n\r\n\r\nprint(t)\r\n\r\n\r\n\r\n\r\n", "la = []\r\nlb = []\r\nfor _ in range(int(input())):\r\n a, b = map(int, input().split())\r\n la.append(a)\r\n lb.append(b)\r\nca0 = la.count(0)\r\nca1 = la.count(1)\r\ncb0 = lb.count(0)\r\ncb1 = lb.count(1)\r\nprint(min(ca0, ca1) + min(cb0, cb1))", "t=int(input())\r\nleft=[]\r\nright=[]\r\nans=0\r\nfor i in range(t):\r\n l,r=map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\nif (left.count(1)==t or left.count(0)==t) and (right.count(1)==t or right.count(0)==t):\r\n print(0)\r\nelse:\r\n ans=ans+min(left.count(0),left.count(1))\r\n ans=ans+min(right.count(0),right.count(1))\r\n print(ans)\r\n ", "n=int(input(\"\"))\r\nls=[]\r\nrs=[]\r\nfor i in range(n):\r\n a,b=map(int,input(\"\").split())\r\n ls+=[a]\r\n rs+=[b]\r\ndef gura(lost):\r\n one=0\r\n zero=0\r\n for i in range(n):\r\n if lost[i]==1:\r\n one+=1\r\n elif lost[i]==0:\r\n zero+=1\r\n if one>zero:\r\n return 1\r\n else:\r\n return 0\r\nc=0\r\nlsr=gura(ls)\r\nrsr=gura(rs)\r\ndef counter(lit,r):\r\n global c\r\n \r\n for i in range (n):\r\n if lit[i]!=r:\r\n lit[i]=r\r\n c+=1\r\ncounter(ls,lsr)\r\ncounter(rs,rsr)\r\nprint(c)\r\n", "n = int(input())\r\nsuml=sumr=0\r\nfor i in range(n):\r\n\tl, r = map(int, input().split())\r\n\tsuml+=l\r\n\tsumr+=r\r\nprint(min(sumr,n-sumr)+min(suml,n-suml))\r\n", "import math\nn = int(input())\ncount = 0\nlc = 0\nrc = 0\nfor _ in range(n):\n l,r = map(int,input().split(\" \"))\n if l==0:\n lc+=1\n if r==1:\n rc+=1\nprint(min(lc,n-lc)+min(rc,n-rc))\n\n\n", "l0,l1,r0,r1 = 0,0,0,0\r\nfor _ in range(int(input())):\r\n l,r = map(int,input().split())\r\n if l == 1:\r\n l1 += 1\r\n if l == 0:\r\n l0 += 1\r\n if r == 1:\r\n r1 += 1\r\n if r == 0:\r\n r0 += 1\r\nprint(min(l0,l1)+min(r0,r1))", "\r\nl,r=0,0\r\nn=int(input())\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n l+=a\r\n r+=b\r\n\r\nx=0\r\nif l<r:\r\n x+=(n-r)\r\n if l<n/2:\r\n x+=l\r\n else:\r\n x+=(n-l)\r\nelif r<l:\r\n x+=(n-l)\r\n if r<n/2:\r\n x+=r\r\n else:\r\n x+=(n-r)\r\nelif r==l:\r\n if r==l==0 or r==l==n:\r\n x+=0\r\n elif r<n/2:\r\n x+=n\r\n else:\r\n x+=(n-l)+(n-r)\r\n\r\nprint(x)", "n = int(input())\r\nleft = []\r\nright = []\r\nfor _ in range(n):\r\n l,r = map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\nclose_left = left.count(0)\r\nopen_left = left.count(1)\r\nclose_right = right.count(0)\r\nopen_right = right.count(1)\r\nprint(min(close_left,open_left)+min(close_right,open_right))\r\n", "n = int(input())\r\nl_z, l_o, r_z, r_o = 0,0,0,0\r\nfor _ in range(0, n):\r\n l, r = [int(x) for x in input().split()]\r\n\r\n if(l == 0): l_z += 1\r\n else: l_o += 1\r\n if (r == 0): r_z += 1\r\n else: r_o += 1\r\n\r\n\r\n\r\nprint(min(l_o, l_z) + min(r_o, r_z))\r\n", "from collections import Counter\r\nn=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n\ta,b=input().split()\r\n\tl.append(a)\r\n\tr.append(b)\r\nc=0\r\nlc=list(Counter(l).values())\r\nlr=list(Counter(r).values())\r\nc+=n-max(lr)\r\nc+=n-max(lc)\r\nprint(c)", "x=0;y=0\r\nn=int(input())\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n x+=l;y+=r\r\nprint(min(n-x,x)+min(n-y,y)) \r\n", "cases = int(input())\r\n\r\nleft = []\r\nright = []\r\n\r\nwhile cases:\r\n cases -= 1\r\n a, b = map(int, input().split())\r\n\r\n left.append(a)\r\n right.append(b)\r\n\r\nprint((min(right.count(1), right.count(0)) + min(left.count(0), left.count(1))))\r\n", "x = int(input())\r\n\r\nlc = lo = rc = ro = ld = rd = 0\r\n\r\nfor _ in range(x):\r\n inp = input()\r\n if inp[0] == '0':\r\n lc += 1\r\n if inp[2] == '0':\r\n rc += 1\r\n else:\r\n ro += 1\r\n\r\n else:\r\n lo += 1\r\n if inp[2] == '0':\r\n rc += 1\r\n else:\r\n ro += 1\r\n\r\nld = max(lo, lc)\r\nrd = max(ro, rc)\r\n\r\nprint((x - ld) + (x - rd))\r\n\r\n", "n = int(input(\"\"))\r\nl = []\r\nfor i in range(n):\r\n s = str(input(\"\"))\r\n l.append(s.split(\" \"))\r\nc1 = 0\r\nc2 = 0\r\nfor i in range(n):\r\n if l[i][0] == '0':\r\n c1 += 1\r\n if l[i][1] == '0':\r\n c2 += 1\r\nt = min(c1, n-c1) + min(c2, n-c2)\r\nprint(t)", "n=int(input())\r\n# ldc=ldo=rdc=rdo=0\r\nl=r=0\r\n\r\nfor i in range(n):\r\n [ld, rd] = [int(x) for x in input().split()]\r\n l+= ld\r\n r+= rd\r\nif(l > n//2):\r\n l = n-l\r\nif(r > n//2):\r\n r = n-r\r\nprint(r+l)", "\r\nn = int(input())\r\n\r\nlo=0\r\nro=0\r\n\r\nfor i in range(n):\r\n l,r = input().split()\r\n if l=='0':\r\n lo+=1\r\n if r=='0':\r\n ro+=1\r\n\r\nif n-lo<lo:\r\n lo=n-lo\r\n\r\nif n-ro<ro:\r\n ro=n-ro\r\n\r\nprint(lo+ro)", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n li,ri=map(int,input().split())\r\n\r\n l.append(li)\r\n r.append(ri)\r\n\r\nlm=min(l.count(1),l.count(0))\r\nrm=min(r.count(1),r.count(0))\r\nprint(lm+rm)\r\n", "n=int(input())\r\ncupboards=[]\r\nRr=0; Lr=0\r\nRl=0; Ll=0\r\nfor i in range(n):\r\n x=input()\r\n cupboards.append(x.split(\" \"))\r\nfor i in range (len(cupboards)):\r\n if cupboards[i][0]=='1':\r\n Rr+=1\r\n else:\r\n Lr+=1\r\n if cupboards[i][1]=='1':\r\n Rl+=1\r\n else:\r\n Ll+=1\r\nx=(min(Rr,Lr))\r\ny=min(Ll,Rl)\r\nprint(x+y)\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\nleft = []\r\nright = []\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n left.append(l)\r\n right.append(r)\r\ntime = 0\r\nif left.count(0) > left.count(1):\r\n time += left.count(1)\r\nelse:\r\n time += left.count(0)\r\nif right.count(0) > right.count(1):\r\n time += right.count(1)\r\nelse:\r\n time += right.count(0)\r\n\r\nprint(time)", "# Level - 800\r\n# Link - https://codeforces.com/problemset/problem/248/A\r\n\r\nn = int(input())\r\nlo = 0\r\nlz = 0\r\nro = 0\r\nrz = 0\r\nfor i in range(n):\r\n string = input()\r\n a, b = string.split()\r\n if a == \"0\":\r\n lz += 1\r\n if a == \"1\":\r\n lo += 1\r\n if b == \"0\":\r\n rz += 1\r\n if b == \"1\":\r\n ro += 1\r\nans = min(lo, lz) + min(ro, rz)\r\nprint(ans)\r\n", "inputLength = int(input())\r\ncontent = []\r\ntemp = []\r\narranged = []\r\nrow1 = 0\r\nseconds = 0\r\n\r\nfor i in range(inputLength):\r\n content.append([int(x) for x in input().split()])\r\n\r\n# Flipping horizontal list to 2 verical lists\r\nfor i in range(2):\r\n for j in range(len(content)):\r\n temp.extend([content[j][i]])\r\n arranged.append(temp)\r\n temp = []\r\n\r\n# Check if a column has more zeros or ones. For either one that is bigger, return the number of the other (which is the shortest amount of seconds to flip cupboards so that all cupboards on one side are the same).\r\nfor i in range(2):\r\n for j in range(inputLength):\r\n if arranged[i][j] == 0:\r\n row1 += 1\r\n if row1 < inputLength/2:\r\n seconds += row1\r\n else:\r\n seconds += (inputLength-row1)\r\n row1 = 0\r\n\r\nprint(seconds)", "\r\nright=[]\r\nleft=[]\r\nsecond=0\r\nfor i in range(int(input())):\r\n m=input()\r\n left.append(m[0])\r\n\r\n right.append(m[2])\r\nif right.count('0')<=right.count('1'):\r\n second+=right.count('0')\r\nelse:\r\n second+=right.count('1')\r\n\r\nif left.count('0')<=left.count('1'):\r\n second+=left.count('0')\r\nelse:\r\n second+=left.count('1')\r\nprint(second)", "n=int(input())\r\nx=0\r\ny=0\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n a=l[0]\r\n b=l[1]\r\n x+=a\r\n y+=b\r\nif x>int(n/2):\r\n x=n-x\r\nif y>int(n/2):\r\n y=n-y\r\nprint(x+y)", "n=int(input())\r\nlo,lc,ro,rc=0,0,0,0\r\nfor i in range(0,n):\r\n l,r=map(int,input().split())\r\n if l==0:\r\n lo+=1\r\n else:\r\n lc+=1\r\n if r==1:\r\n rc+=1\r\n else:\r\n ro+=1\r\nprint(min(lo,lc)+min(ro,rc))", "t=int(input())\r\nl=[]\r\nr=[]\r\nfor x in range(t):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b) \r\nkl=min(l.count(0),l.count(1))\r\nkr=min(r.count(0),r.count(1))\r\nprint(kl+kr)\r\n", "# Author : Pubudu Anuradha\r\nfrom sys import setrecursionlimit as srl\r\nfrom sys import stdin\r\nRL = stdin.readline\r\nsrl(10**9)\r\ndef cin(dt):\r\n return dt(RL())\r\ndef spin(dt, rt=None):\r\n if(rt is None):\r\n return map(dt, RL().split())\r\n return rt(map(dt, RL().split()))\r\n\r\nn = cin(int)\r\nr=l=0\r\nfor i in range(n):\r\n a,b = spin(int)\r\n r+=a\r\n l+=b\r\nprint(min(r,n-r)+min(l,n-l))", "n = int(input())\r\nleft = 0\r\nright = 0\r\nans = 0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a==1:\r\n left+=1\r\n if b==1:\r\n right+=1\r\nans+= min(left,n-left)\r\nans+= min(right,n-right)\r\nprint(ans)\r\n", "class Solution:\r\n\tdef __init__(self):\r\n\t\tpass\r\n\r\n\tdef solve(self):\r\n\t\tn = int(input())\r\n\t\tseconds = 0\r\n\t\tcount0_left, count0_right = 0, 0\r\n\r\n\t\tfor i in range(n):\r\n\t\t\ta, b = map(int, input().split())\r\n\r\n\t\t\tif a == 0:\r\n\t\t\t\tcount0_left += 1\r\n\t\t\tif b == 0:\r\n\t\t\t\tcount0_right += 1\r\n\r\n\t\tseconds = min(count0_left, n - count0_left) + min(count0_right, n - count0_right)\r\n\t\tprint(seconds)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tsol = Solution()\r\n\tsol.solve()\r\n", "T = int(input())\nl_ls, r_ls = [], []\nfor t in range(T):\n l, r = list(map(int,input().split()))\n l_ls.append(l); r_ls.append(r)\n \nhalf_T = T / 2\nl_ones = sum(l_ls)\n# l_half = int(l_ones / 2)\nr_ones = sum(r_ls)\n# r_half = int(r_ones / 2)\n# print('\\nhalf_T: ', half_T) \n# print('\\nl_half: ', l_half) \n# print('\\nr_half: ', r_half) \n# print('\\nl_ones: ', l_ones)\n# print('\\nr_ones: ', r_ones)\n\nl_res = l_ones if l_ones < half_T else T - l_ones\nr_res = r_ones if r_ones < half_T else T - r_ones\nres = l_res + r_res\nprint(res)\n\t\t \t\t\t\t\t \t\t \t\t \t\t\t\t\t \t\t\t \t", "l0,l1,r0,r1=0,0,0,0 \r\nfor _ in range(int(input())):\r\n m,n=map(int,input().split())\r\n if m==0:\r\n l0+=1 \r\n else:\r\n l1+=1 \r\n if n==1:\r\n r1+=1 \r\n else:\r\n r0+=1 \r\nprint(min(l1,l0)+min(r1,r0))", "n=int(input(''))\r\nl=[]\r\nfor i in range(n):\r\n a=input('')\r\n b=a.split(' ')\r\n l.append(b)\r\nt=0\r\no=0\r\nz=0\r\nfor i in range(n):\r\n if l[i][0]=='1':\r\n o+=1\r\n else:\r\n z+=1\r\nif o>z:\r\n t+=z\r\nelse:\r\n t+=o\r\no1=0\r\nz1=0\r\nfor i in range(n):\r\n if l[i][1]=='1':\r\n o1+=1\r\n else:\r\n z1+=1\r\nif o1>z1:\r\n t+=z1\r\nelse:\r\n t+=o1\r\nprint(t)\r\n", "numCabinets = int(input())\r\nr_open_count = 0\r\nr_closed_count = 0\r\nl_open_count = 0\r\nl_closed_count = 0\r\nclosed = 0\r\nopened = 1\r\nminLeftChanges = 0\r\nminRightChanges = 0\r\n\r\nfor i in range(0, numCabinets):\r\n cabinet = list(map(int, input().split(\" \")))\r\n leftDoor = cabinet[0]\r\n rightDoor = cabinet[1]\r\n if leftDoor == closed:\r\n l_closed_count += 1\r\n elif leftDoor == opened:\r\n l_open_count += 1\r\n if rightDoor == closed:\r\n r_closed_count += 1\r\n elif rightDoor == opened:\r\n r_open_count += 1\r\n\r\nif l_open_count > l_closed_count:\r\n minLeftChanges = l_closed_count\r\nelse:\r\n minLeftChanges = l_open_count\r\n\r\nif r_open_count > r_closed_count:\r\n minRightChanges = r_closed_count\r\nelse:\r\n minRightChanges = r_open_count\r\n\r\nprint(str(minLeftChanges + minRightChanges))\r\n", "# A. Cupboards\n\nn = int(input())\nl_open = 0\nr_open = 0\nfor _ in range(n):\n li, ri = map(int, input().split())\n if li == 1:\n l_open += 1\n if ri == 1:\n r_open += 1\nprint(min(l_open, n - l_open) + min(r_open, n - r_open))\n", "l0=r0=0\r\nn=int(input())\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a==0:\r\n l0+=1\r\n if b==0:\r\n r0+=1\r\n\r\nprint(min(l0,n-l0)+min(r0,n-r0),end='')\r\n", "n = int(input())\nlc, rc = 0, 0\nfor _ in range(n):\n d = input().split()\n lc += d[0] == \"0\"\n rc += d[1] == \"0\"\nres = min(lc, n - lc) + min(rc, n - rc)\nprint(res)\n", "\r\nsum1 = 0\r\nsum2 = 0\r\nans = 0\r\n\r\nn = int(input())\r\nfor i in range (0 , n) :\r\n l , r = input().split()\r\n sum1 = sum1 + int(l)\r\n sum2 = sum2 + int(r)\r\n\r\nif sum1 > (n - sum1) :\r\n ans = ans + (n - sum1)\r\nelse :\r\n ans += sum1\r\n\r\nif sum2 > (n - sum2):\r\n ans = ans + (n - sum2)\r\nelse:\r\n ans += sum2\r\nprint (ans)\r\n\r\n", "#a[0]= l0\r\n#a[1]=lc\r\n#a[2]=r0\r\n#a[3]=rc\r\nn=int(input())\r\nsl,sr=0,0\r\nfor i in range(n):\r\n k,l=map(int,input().split())\r\n sl=sl+l\r\n sr=sr+k\r\nprint(min(sl,n-sl) + min(sr,n-sr))\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n ", "n=int(input())\r\nliri=[]\r\nfor i in range(n) :\r\n li,ri=map(int,input().split())\r\n l=[li,ri]\r\n liri+=l\r\n\r\nli0=0\r\nli1=0\r\nri0=0\r\nri1=0\r\ni=0\r\nwhile i<2*n :\r\n if i%2==0 and liri[i]==0 :\r\n li0+=1\r\n if i%2==0 and liri[i]==1 :\r\n li1+=1 \r\n if i%2==1 and liri[i]==0 :\r\n ri0+=1\r\n if i%2==1 and liri[i]==1 :\r\n ri1+=1\r\n i+=1\r\n\r\nprint(min(li0,li1)+min(ri0,ri1))", "n=int(input())\r\ns=[]\r\nl=[]\r\nr=[]\r\nfor i in range (n):\r\n s.append(input().split())\r\n l.append(int(s[i][0]))\r\n r.append(int(s[i][1]))\r\nl.sort()\r\nr.sort()\r\nx=0\r\ny=0\r\nif l[len(l)//2]==0:\r\n for i in range (len(l)//2,len(l)):\r\n if l[i]==1:\r\n x+=1\r\nif l[len(l)//2]==1:\r\n for i in range (len(l)//2):\r\n if l[i]==0:\r\n x+=1\r\nif r[len(r)//2]==0:\r\n for i in range (len(r)//2,len(r)):\r\n if r[i]==1:\r\n y+=1\r\nif r[len(r)//2]==1:\r\n for i in range (len(r)//2):\r\n if r[i]==0:\r\n y+=1\r\nprint(x+y)", "n=int(input())\r\na=[]\r\nfor i in range(n):\r\n\tk=list(map(int,input().split()))\r\n\ta.append(k)\r\nl,r=0,0\r\nfor i in a:\r\n\tif i[0]==1:\r\n\t\tl+=1\r\n\tif i[1]==1:\r\n\t\tr+=1\r\nif l>n/2:\r\n\tl = n-l\r\nif r>n/2:\r\n\tr=n-r\r\nprint(l+r)\r\n", "n = int(input())\na0 = 0\na1 = 0\nb0 = 0\nb1 = 0\nfor i in range(n):\n a, b = input().split()\n if a == '0':\n a0 += 1\n else:\n a1 += 1\n if b == '0':\n b0 += 1\n else:\n b1 += 1\nprint(min(a0,a1)+min(b0, b1))\n", "x = int(input())\r\nl ,l1= [], []\r\nfor i in range(x):\r\n a,b = map(int,input().split())\r\n l.append(a)\r\n l1.append(b)\r\nt = 0\r\nt = min(l.count(0), l.count(1))\r\nt += min(l1.count(0), l1.count(1))\r\nprint(t)\r\n\r\n\r\n\r\n", "import math\r\n\r\nn = int(input())\r\n\r\narr = []\r\n\r\nfor i in range(n):\r\n arr.append(list(map(int, input().split())))\r\n\r\ncols = len(arr[0])\r\nrows = len(arr)\r\n\r\nl_closed_count = 0\r\nr_closed_count = 0\r\nl_open_count = 0\r\nr_open_count = 0\r\n\r\nfor j in range(cols):\r\n for i in range(rows):\r\n if(arr[i][j]==0 and j==0):\r\n l_closed_count+=1\r\n \r\n elif(arr[i][j]==1 and j==0):\r\n l_open_count+=1\r\n \r\n elif(arr[i][j]==0 and j==1):\r\n r_closed_count+=1\r\n \r\n elif(arr[i][j]==1 and j==1):\r\n r_open_count+=1\r\n\r\nmoves = 0\r\n\r\n# refine code \r\n\r\nif(l_closed_count>=l_open_count):\r\n moves+=l_open_count\r\n\r\nelse:\r\n moves+=l_closed_count\r\n\r\nif(r_closed_count>=r_open_count):\r\n moves+=r_open_count\r\n\r\nelse:\r\n moves+=r_closed_count\r\n\r\nprint(moves)\r\n", "n=int(input())\r\nt=0\r\narr=[]\r\nbrr=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n arr.append(a)\r\n brr.append(b)\r\na_0=arr.count(0)\r\na_1=arr.count(1)\r\nif a_0>=a_1:\r\n t+=n-a_0\r\nelse:\r\n t+=n-a_1\r\nb_0=brr.count(0)\r\nb_1=brr.count(1)\r\nif b_0>=b_1:\r\n t+=n-b_0\r\nelse:\r\n t+=n-b_1\r\nprint(t)", "n=int(input())\r\nX,Y=[],[]\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n X.append(x)\r\n Y.append(y)\r\nnol1=X.count(0)\r\nyak1=X.count(1)\r\nnol2=Y.count(0)\r\nyak2=Y.count(1)\r\nprint(min(nol1,yak1)+min(nol2,yak2))", "n = int(input())\r\nl = []\r\nr = []\r\n# print(l,r)\r\nl1 = 0\r\nr1 = 0\r\nfor i in range(n):\r\n lx, rx = map(int, input().split())\r\n l.append(lx)\r\n r.append(rx)\r\n if l[i] == 1:\r\n l1+=1\r\n if r[i] == 1:\r\n r1+=1\r\ncount = 0\r\ncount+= min(l1, n-l1)\r\ncount+= min(r1, n-r1)\r\nprint(count)", "def solve(l, r, n):\n return min(n - l, l) + min(n - r, r)\n\n\ndef main():\n n = int(input())\n l, r = 0, 0\n for _ in range(n):\n a, b = input().split()\n if a == '0': l += 1\n if b == '0': r += 1\n print(solve(l, r, n))\n\n\nmain()\n", "#n, k = map(int, input().split(\" \")) # read multiple integers into different variables\r\n#L = [int(x) for x in input().split()] # read multiple integers into a list\r\n#print(' '.join(map(str, L))) # print multiple integers in one line\r\n\r\n\r\nn = int(input())\r\na = 0\r\nb = 0\r\nfor _ in range(n) :\r\n aa, bb = map(int, input().split(\" \")) \r\n a += aa\r\n b += bb\r\n\r\nans = min(a, n - a) + min(b, n - b)\r\nprint(ans)", "n = int(input())\r\nleft_open_count = 0\r\nright_open_count = 0\r\n\r\nfor _ in range(n):\r\n li, ri = map(int, input().split())\r\n left_open_count += li\r\n right_open_count += ri\r\n\r\n# Calculate the minimum number of seconds needed\r\n# It is the minimum of changing left doors and right doors\r\n# Either all left doors are open and all right doors are closed, or vice versa.\r\nmin_seconds = min(left_open_count, n - left_open_count) + min(right_open_count, n - right_open_count)\r\n\r\nprint(min_seconds)\r\n", "t = int(input())\r\nl =[]\r\nr =[]\r\ny=x=z=0\r\nfor i in range(t):\r\n a,b = map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\ny = l.count(0)\r\nx = l.count(1)\r\nz += l.count(1) if y>x else l.count(0)\r\ny = r.count(0)\r\nx = r.count(1)\r\nz += r.count(1) if y>x else r.count(0)\r\nprint(z)", "n=int(input())\r\nnsl=0 #needed state of left door\r\nnsr=0 #needed state of right door\r\nt=0 #time taken\r\nldzc=0 \r\nldoc=0\r\nrdzc=0\r\nrdoc=0\r\nans=[]\r\nfor x in range(n): \r\n l,r=map(int,input().split())\r\n if l==0:\r\n ldzc+=1\r\n if l==1:\r\n ldoc+=1\r\n if r==0:\r\n rdzc+=1\r\n if r==1:\r\n rdoc+=1\r\n ans.append([l,r])#a list of all door states\r\n#print(ans)\r\n#print(\"left door zero count\",lfzc)\r\n#print(\"left door 1 count\",lfoc)\r\n#print(\"right door zero count\",rdzc)\r\n#print(\"right door 1 count\",rdoc)\r\nif ldzc>ldoc: #if 0 occurs more then required state is 0 of left door\r\n lds=0\r\nelse:\r\n lds=1\r\nif rdzc>rdoc:#if 0 occurs more then required state is 0 of right door\r\n rds=0\r\nelse:\r\n rds=1\r\nt=0\r\n#print(\"required state of left door\",lds)\r\n#print(\"required state of right door\",rds)\r\nfor x in range(0,len(ans)):\r\n #print(\"left door\",ans[x][0])\r\n #print(\"right door\",ans[x][1])\r\n if ans[x][0]!=lds and ans[x][1]!=rds:#if both door not in correct position then 2s\r\n t+=2\r\n #print(\"both doors\",t)\r\n elif ans[x][0]!=lds or ans[x][1]!=rds:#else 1 s\r\n t+=1\r\n #print(\"one doors\",t)\r\nprint(t)", "n = int(input())\r\nleft = []\r\nright = []\r\nfor i in range(n):\r\n\tl,r = map(int,input().split())\r\n\tleft.append(l)\r\n\tright.append(r)\r\nt = 0\r\nif left.count(1) < left.count(0):\r\n\tt+=left.count(1)\r\nelse:\r\n\tt+=left.count(0)\r\nif right.count(1) < right.count(0):\r\n\tt+=right.count(1)\r\nelse:\r\n\tt+=right.count(0)\r\nprint(t)\r\n", "n = int(input())\r\nleft, right = [], []\r\nfor _ in range(n):\r\n a, b = list(map(int, input().split(' ')))\r\n left.append(a)\r\n right.append(b)\r\nans = 0\r\nif left.count(1) < left.count(0):\r\n ans += left.count(1)\r\nelse:\r\n ans += left.count(0)\r\nif right.count(1) < right.count(0):\r\n ans += right.count(1)\r\nelse:\r\n ans += right.count(0)\r\nprint(ans) ", "if __name__=='__main__':\r\n x=int(input())\r\n count1=0\r\n count2=0\r\n one1=0\r\n one2=0\r\n tot=0\r\n list1=[]\r\n for i in range(0,x):\r\n temp=input().split()\r\n temp=[int(a) for a in temp]\r\n list1.append(temp)\r\n for i in range(0,x):\r\n if (list1[i][0]==0):\r\n count1+=1\r\n for i in range(0,x):\r\n if (list1[i][1]==0):\r\n count2+=1\r\n one1=x-count1\r\n one2=x-count2\r\n if one1>count1:\r\n tot=tot+count1\r\n else:\r\n tot=tot+one1\r\n if one2>count2:\r\n tot=tot+count2\r\n else:\r\n tot=tot+one2\r\n print(tot)\r\n \r\n \r\n\r\n", "t = int(input())\r\nleft = 0\r\nright = 0\r\n\r\nfor _ in range(t):\r\n p, q = map(int, input().split())\r\n left += p\r\n right += q\r\n\r\nresult = min(left, t - left) + min(right, t - right)\r\nprint(result)\r\n", "i=int(input())\r\nl_open=[]\r\nr_open=[]\r\nfor x in range(i):\r\n a,b=map(int,input().split())\r\n l_open.append(a)\r\n r_open.append(b)\r\nv=min(l_open.count(1),l_open.count(0))\r\nm=min(r_open.count(1),r_open.count(0))\r\nprint(v+m)\r\n\r\n", "n=int(input())\r\nx,y=0,0\r\nfor i in range(n):\r\n a,b=list(map(int,input().split(\" \")))\r\n x+=a\r\n y+=b\r\n\r\nprint(min(n-x,x)+min(n-y,y))", "n=int(input())\r\nx = 0\r\ny = 0\r\nfor i in range(n):\r\n\ta,b=map(int,input().split())\r\n\tx+=a\r\n\ty+=b\r\nprint(min(x,n-x)+min(y,n-y))", "\r\nn=int(input())\r\nx=list()\r\ny=list()\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n x.append(a)\r\n y.append(b)\r\n\r\nx0=x.count(0)\r\nx1=n-x0\r\ny0=y.count(0)\r\ny1=n-y0\r\nans=0\r\nif x0>x1:\r\n ans=ans+x1\r\nelse:\r\n ans=ans+x0\r\nif y0>y1:\r\n ans=ans+y1\r\nelse:\r\n ans=ans+y0\r\n\r\nprint (ans)", "t = int(input())\r\n\r\nl = [0,0]\r\nr = [0,0]\r\n\r\nwhile t > 0:\r\n t -= 1\r\n n = str(input())\r\n s = n.split()\r\n \r\n ls = int(s[0])\r\n if ls == 0:\r\n l[0] += 1\r\n else:\r\n l[1] += 1\r\n \r\n rs = int(s[1])\r\n if rs == 0:\r\n r[0] += 1\r\n else:\r\n r[1] += 1\r\n\r\nans = min(l) + min(r)\r\n\r\nprint(ans)", "n=int(input())\r\nx = 0\r\ny = 0\r\nfor i in range(n):\r\n a,b = list(map(int,input().split()))\r\n if a==1:\r\n x+=1\r\n if b==1:\r\n y+=1\r\n \r\nprint(min(x,n-x)+min(y,n-y))", "z1=0\no1=0\nz2=0\no2=0\nfor _ in range(int(input())):\n on,tw = map(int , input().split())\n if(on==0):\n z1+=1\n if(on==1):\n o1+=1\n if(tw==0):\n z2+=1\n if(tw==1):\n o2+=1\n\nprint(min(o1,z1)+min(o2,z2))", "l=[]\r\nr=[]\r\n\r\nfor i in range(int(input())):\r\n lr= input().split()\r\n l.append(int(lr[0]))\r\n r.append(int(lr[1]))\r\n\r\nx= min(l.count(0),l.count(1))\r\ny=min(r.count(0),r.count(1))\r\n\r\nprint(x+y)\r\n", "n=int(input())\r\nleft_count=0\r\nright_count=0\r\nt=0\r\nfor i in range(n):\r\n num=list(map(int,input().split()))\r\n if num[0]==1:\r\n left_count+=1\r\n if num[1]==1:\r\n right_count+=1\r\nleft_compare=[left_count,n-left_count]\r\nleft_compare.sort()\r\nt+=left_compare[0]\r\nright_compare=[right_count,n-right_count]\r\nright_compare.sort()\r\nt+=right_compare[0]\r\nprint(t)", "l=[]\r\nr=[]\r\nfor i in range(int(input())):\r\n ll,rr=map(int,input().split())\r\n l.append(ll)\r\n r.append(rr)\r\nml=l.count(0)\r\nmr=r.count(0)\r\nif l.count(1)<ml:\r\n ml=l.count(1)\r\nif r.count(1)<mr:\r\n mr=r.count(1)\r\nprint(ml+mr)", "num = int(input(\"\"))\r\nlists = []\r\nlst2 = []\r\na = []\r\nb = [] \r\nmin_a = 0\r\nmin_b = 0\r\n\r\nfor i in range(1,num+1):\r\n lst1 = list(map(int,input().split(\" \")))\r\n lists.append(lst1)\r\n\r\n\r\nj = 0 \r\nfor j in lists:\r\n lst2 = j\r\n a.append(lst2[0])\r\n b.append(lst2[1])\r\n\r\na_zero = a.count(0)\r\na_one = a.count(1)\r\nb_zero = b.count(0)\r\nb_one = b.count(1)\r\n\r\nif a_zero < a_one :\r\n min_a = a_zero\r\nelse:\r\n min_a = a_one\r\n\r\nif b_zero < b_one :\r\n min_b = b_zero\r\nelse:\r\n min_b = b_one\r\n\r\nt = min_a + min_b\r\n\r\nprint(t)\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n", "cupboards = int(input())\r\nleft_doors = []\r\nright_doors = []\r\ntime_required = 0\r\n\r\nfor i in range(cupboards):\r\n left, right = [int(i) for i in input().split(\" \")]\r\n left_doors.append(left)\r\n right_doors.append(right)\r\nif left_doors.count(0) > left_doors.count(1):\r\n time_required += left_doors.count(1)\r\nelse:\r\n time_required += left_doors.count(0)\r\n\r\nif right_doors.count(0) > right_doors.count(1):\r\n time_required += right_doors.count(1)\r\nelse:\r\n time_required += right_doors.count(0)\r\n\r\nprint(time_required)\r\n", "a,b,n = list(),list(),int(input())\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n a.append(x);b.append(y)\r\nprint(min(a.count(0),a.count(1))+min(b.count(0),b.count(1)))", "from sys import stdin\r\n\r\nn = int(stdin.readline())\r\nr = 0\r\nl = 0\r\nfor i in range(0,n):\r\n rl = stdin.readline()\r\n rl = rl.split(' ')\r\n ll = int(rl[0])\r\n rr = int(rl[1])\r\n r += rr\r\n l += ll\r\nr = min(r, n-r)\r\nl = min(l, n-l)\r\nprint(l + r)\r\n\r\n\r\n", "n = int(input())\r\na=b=0\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n a += x\r\n b += y\r\nprint(min(a,n-a)+min(b,n-b))", "#cupboards\r\nn=int(input())\r\nd={}\r\na=0\r\nb=0\r\nfor i in range(n):\r\n d[i]=list(map(int,input().split()))\r\nfor i in d.values():\r\n a+=i[0]\r\n b+=i[1]\r\nprint(min(a,n-a)+min(b,n-b))\r\n", "a=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(0,a):\r\n t=list(map(int,input().split()))\r\n l.append(t[0])\r\n r.append(t[1])\r\nx=l.count(0) if (l.count(0)<l.count(1)) else l.count(1)\r\ny=r.count(0) if (r.count(0)<r.count(1)) else r.count(1)\r\nprint(x+y)\r\n", "import sys\r\n\r\ndef main():\r\n n, *l = map(int, sys.stdin.read().strip().split())\r\n t, k = sum(l[::2]), sum(l[1::2])\r\n return min(t, n-t) + min(k, n-k)\r\n \r\nprint(main())\r\n", "ans=0\r\nl1,l0,r1,r0=0,0,0,0\r\nfor i in range(int(input())):\r\n a,b=list(map(int,input().split()))\r\n if(a==0):\r\n l0+=1\r\n if(a==1):\r\n l1+=1\r\n if(b==0):\r\n r0+=1\r\n if(b==1):\r\n r1+=1\r\n\r\nans=min(l1,l0)+min(r1,r0)\r\nprint(ans)\r\n", "n=int(input())\r\ndl={0:0,1:0}\r\ndr={0:0,1:0}\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n dl[l]+=1\r\n dr[r]+=1\r\nprint(min(dl[0],dl[1])+min(dr[0],dr[1]))\r\n \r\n", "n=int(input())\r\nll,rr=[],[]\r\nfor i in range(n):\r\n\tl,r=map(int,input().split())\r\n\tll.append(l)\r\n\trr.append(r)\r\ncl0=ll.count(0)\r\ncl1=ll.count(1)\r\ncr0=rr.count(0)\r\ncr1=rr.count(1)\r\nsum=min(cl0,cl1)+min(cr0,cr1)\r\nprint(sum)", "n=int(input())\r\nlcount=0\r\nrcount=0\r\nfor i in range(0,n):\r\n\tab=input().split()\r\n\tif(ab[0]=='0'):\r\n\t\tlcount+=1\r\n\tif(ab[1]=='0'):\r\n\t\trcount+=1\r\nprint(min(lcount,n-lcount)+min(rcount,n-rcount))", "n = int(input())\r\nx = y = 0\r\n\r\nfor _ in range(n):\r\n L, R = map(int, input().split())\r\n x += L\r\n y += R\r\n\r\nprint(min(x, n-x) + min(y, n-y))", "n=int(input())\r\na=0; b=0\r\nfor i in range(n):\r\n x,y=[int(x) for x in input().split()]\r\n a+=x; b+=y\r\nprint(min(a,n-a)+min(b, n-b))", "n=int(input())\r\nl,r=0,0\r\nfor _ in range(n):\r\n\ta,b=map(int,input().split())\r\n\tl+=a\r\n\tr+=b\r\nprint(min(l,n-l)+min(r,n-r))", "n=int(input())\r\nlst=[]\r\nfor i in range(n):\r\n lst.append([int(x) for x in input().split()])\r\nres0,res1=0,0\r\nfor i in lst:\r\n if i[0]==0:\r\n res0+=1 \r\n if i[1]==0:\r\n res1+=1 \r\nprint(min(res0,n-res0)+min(res1,n-res1))", "n=int(input())\r\ndic={\"a\" : 0,\"b\" : 0}\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if(a == 1):\r\n dic[\"a\"]+=1\r\n if(b == 1):\r\n dic[\"b\"]+=1\r\nsec=0\r\nif(dic[\"a\"] <= n/2):\r\n sec+=dic[\"a\"]\r\nelse:\r\n sec+=(n-dic[\"a\"])\r\nif(dic[\"b\"] <= n/2):\r\n sec+=dic[\"b\"]\r\nelse:\r\n sec+=(n-dic[\"b\"])\r\nprint(sec)\r\n \r\n ", "n=int(input())\r\nlst=[]\r\n\r\nl_open=0\r\nr_open=0\r\nfor i in range(n):\r\n tmp=[int(x) for x in input().split()]\r\n lst.append(tmp)\r\n if(tmp[0]==1):\r\n l_open+=1\r\n if(tmp[1]==1):\r\n r_open+=1\r\n\r\nans=min(n-l_open,l_open)+min(n-r_open,r_open)\r\nprint(ans)\r\n", "num = int(input())\nright = list()\nleft = list()\nfor _ in range(num):\n l, r = input().split()\n right.append(r)\n left.append(l)\nleft_count = left.count('0') if left.count('0')<=left.count('1') else left.count('1')\nright_count = right.count('0') if right.count('0')<=right.count('1') else right.count('1')\nprint(left_count+right_count)", "n=int(input())\r\nk1,k2,k3,k4=0,0,0,0\r\nfor i in range (n):\r\n x,y=map(int,input().split())\r\n if x==1:\r\n k1+=1\r\n else:\r\n k2+=1\r\n if y==1:\r\n k3+=1\r\n else:\r\n k4+=1\r\nprint (min(k1,k2)+min(k3,k4))\r\n", "num_cupboards = int(input())\r\ncup_boards = []\r\nfor index in range(num_cupboards):\r\n cup_board = input().split()\r\n cup_boards.append(cup_board)\r\nleft_opened = 0\r\nright_closed = 0\r\nleft_closed = 0\r\nright_opened = 0\r\nall_opened = 0\r\nall_closed =0 \r\nfor c in cup_boards:\r\n if int(c[0]) == 0:\r\n all_opened +=1\r\n left_opened +=1\r\n if int(c[1]) == 1:\r\n all_closed +=1\r\n right_closed +=1\r\n if int(c[0]) == 1:\r\n all_closed +=1\r\n left_closed +=1\r\n if int(c[1]) == 0:\r\n all_opened +=1\r\n right_opened +=1\r\n \r\n\r\n\r\nprint(min(left_opened+right_closed,left_closed+right_opened,all_closed,all_opened))\r\n \r\n \r\n \r\n \r\n ", "n= int(input())\r\nleft =[]\r\nright = []\r\ncount =0 \r\nfor i in range(n):\r\n \ta,b = map(int,input().split())\r\n \tleft.append(a)\r\n \tright.append(b)\r\nleft1 = left.count(1)\r\nleft0 = left.count(0)\r\ncount+= min(left1,left0)\r\nright1 = right.count(1)\r\nright0 = right.count(0)\r\ncount+= min(right1,right0)\r\nprint(count)", "# http://codeforces.com/problemset/problem/248/A\n\nn = int(input())\nleft = right = 0\nfor i in range(n):\n a , b = map(int, input().split())\n left+=a\n right+=b\nprint(min(left, n-left) + min(right, n-right))\n", "# import inbuilt standard input output\nfrom sys import stdin, stdout\n\ndef main():\n len_ = int(stdin.readline())\n left = 0\n right = 0\n for i in range(len_):\n l, r = [int(x) for x in stdin.readline().split(\" \")]\n left += l\n right += r\n l_op = min(len_ - left, left)\n r_op = min(len_ - right, right)\n total = l_op + r_op\n stdout.write(str(total))\n\nif __name__ == \"__main__\":\n main()", "n = int(input())\r\nfirst, second = [], []\r\nresult = 0\r\nfor i in range(n):\r\n f, s = input().split()\r\n first.append(f)\r\n second.append(s)\r\n\r\nif(first.count('0') > first.count('1')):\r\n result = result + first.count('1')\r\n #print(\"r1\", result)\r\n \r\nelif(first.count('1') >= first.count('0')):\r\n result = result + first.count('0')\r\n #print(\"r2\", result)\r\n \r\n \r\nif(second.count('0') > second.count('1')):\r\n result = result + second.count('1')\r\n #print(\"r3\", result)\r\n \r\nelif(second.count('1') >= second.count('0')):\r\n result = result + second.count('0')\r\n # print(\"c\", first.count('0'))\r\n # print(\"r4\", result)\r\n \r\nprint(result)\r\n", "n = int(input())\r\nsum_l = 0\r\nsum_r = 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n if l:\r\n sum_l+=1\r\n if r:\r\n sum_r+=1\r\nprint(min(sum_r+sum_l, min(n-sum_l+n-sum_r, min(n-sum_r+sum_l, sum_r+n-sum_l))))", "n = int(input())\nl, r = 0, 0\nfor i in range(n):\n\tx, y = [int(x) for x in input().split()]\n\tl += x\n\tr += y\nprint(min(l, n - l) + min(r, n - r))\n", "n = int(input().strip())\nleft = 0\nright = 0\nfor i in range(n):\n a, b = map(int, input().strip().split())\n left += a\n right += b\nprint(min(left, n-left) + min(right, n- right))\n\n \n \n", "n=int(input())\r\nls1=[]\r\nls2=[]\r\n\r\nfor _ in range(n):\r\n x,y=map(int,input().split())\r\n ls1.append(x)\r\n ls2.append(y)\r\n \r\n \r\na=sum(ls1) ; b=sum(ls2)\r\nx=max(a,b) ; y=min(a,b)\r\n\r\nif x>n/2:\r\n x=n-x\r\nif y>n/2:\r\n y=n-y\r\n \r\nprint(x+y)\r\n", "a=b=c=d=0\r\nfor _ in range(int(input())):\r\n str=input()\r\n if str[0]=='1':\r\n a+=1\r\n else:\r\n b+=1\r\n \r\n if str[2]=='1':\r\n c+=1\r\n else:\r\n d+=1\r\nprint(min(a,b)+min(c,d))\r\n", "# ░░░░░░░░░░░░░░░░░░░░░░░░░░░░╔═══╗╔╗╔═══╦═══╗\r\n# ░░░░░░░░░░░░░░░░░░░░░░░░░░░░║╔═╗╠╝║║╔═╗║╔═╗║\r\n# ╔══╦═╗╔══╦═╗╔╗░╔╦╗╔╦══╦╗╔╦══╬╝╔╝╠╗║║║║║╠╝╔╝║\r\n# ║╔╗║╔╗╣╔╗║╔╗╣║░║║╚╝║╔╗║║║║══╬╗╚╗║║║║║║║║░║╔╝\r\n# ║╔╗║║║║╚╝║║║║╚═╝║║║║╚╝║╚╝╠══║╚═╝╠╝╚╣╚═╝║░║║░\r\n# ╚╝╚╩╝╚╩══╩╝╚╩═╗╔╩╩╩╩══╩══╩══╩═══╩══╩═══╝░╚╝░\r\n# ░░░░░░░░░░░░╔═╝║░░░░░░░░░░░░░░░░░░░░░░░░░░░░\r\n# ░░░░░░░░░░░░╚══╝░░░░░░░░░░░░░░░░░░░░░░░░░░░░\r\n\r\n\r\n\r\na=int(input())\r\nd=0\r\ne=0\r\n\r\nfor i in range(a):\r\n b,c=map(int,input().split())\r\n d+=b\r\n e+=c\r\n\r\nprint(min(d,a-d)+min(e,a-e))", "n = int(input())\r\na = b = 0\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n a += x;\r\n b += y;\r\nprint(min(a, n-a) + min(b, n-b))\r\n\r\n", "n=int(input())\r\nl0=0\r\nl1=0\r\nr0=0\r\nr1=0\r\nresult=0\r\nfor i in range(0,n):\r\n string=input()\r\n arr=list(map(int,string.split(\" \")))\r\n if arr[0]==0:\r\n l0+=1\r\n else:\r\n l1+=1\r\n if arr[1]==1:\r\n r1+=1\r\n else:\r\n r0+=1\r\nif l0>l1:\r\n result+=l1\r\nelse:\r\n result+=l0\r\nif r0>r1:\r\n result+=r1\r\nelse:\r\n result+=r0\r\nprint(result)\r\n", "n=int(input())\r\nx,y=0,0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n x+=a\r\n y+=b\r\nprint(min(x,n-x) + min(y,n-y))", "a = int(input())\r\ncount1 = 0\r\ncount2 = 0\r\nfor x in range(a):\r\n d,e = map(int,input().split())\r\n if d==1:\r\n count1+=1\r\n if e == 1:\r\n count2+=1\r\n\r\n l = min(count1,a-count1)\r\n m = min(count2,a-count2)\r\nprint(l+m)", "no_of_doors=int(input())\r\nl1=[]\r\nsum=0\r\nfor i in range(0,no_of_doors):\r\n l=list(map(int,input().split()))\r\n l1.append(l)\r\nno_of_zeros=0\r\nno_of_ones=0\r\nfor i in range(0,no_of_doors):\r\n if l1[i][0]==0:\r\n no_of_zeros+=1\r\n if l1[i][0]==1:\r\n no_of_ones+=1\r\nif no_of_ones>no_of_zeros:\r\n sum+=no_of_zeros\r\nelse:\r\n sum+=no_of_ones\r\nno_of_zeros=0\r\nno_of_ones=0\r\nfor i in range(0,no_of_doors):\r\n if l1[i][1]==0:\r\n no_of_zeros+=1\r\n if l1[i][1]==1:\r\n no_of_ones+=1\r\nif no_of_ones>no_of_zeros:\r\n sum+=no_of_zeros\r\nelse:\r\n sum+=no_of_ones\r\nprint(sum)", "from sys import stdin, stdout\ndef read():\n\treturn stdin.readline().rstrip()\n\ndef read_int():\n\treturn int(read())\n \ndef read_ints():\n\treturn list(map(int, read().split()))\n \ndef solve():\n\tn=read_int()\n\tcntl=[0,0]\n\tcntr=[0,0]\n\tfor i in range(n):\n\t\tl,r=read_ints()\n\t\tcntl[l]+=1\n\t\tcntr[r]+=1\n\tprint(min(cntl)+min(cntr))\n\nsolve()\n", "n = int(input())\r\nl_0 = 0\r\nl_1 = 0\r\nr_0 = 0\r\nr_1 = 0\r\nfor i in range(n): \r\n\tl,r = map(int, input().split())\r\n\tif l == 0:\r\n\t l_0 += 1\r\n\tif r == 0:\r\n\t r_0 += 1\r\n\tif l == 1:\r\n\t l_1 += 1\r\n\tif r == 1:\r\n\t r_1 += 1\r\nprint(min(l_1,l_0) + min(r_1,r_0))", "n = int(input())\r\nlefts = 0\r\nrights = 0\r\nfor _ in range(n):\r\n l,r = [int(x) for x in input().split()]\r\n lefts += l\r\n rights += r\r\n\r\ndef counts(doors, n):\r\n closed = n - doors\r\n opened = doors\r\n if opened > closed:\r\n return closed\r\n else:\r\n return opened\r\n\r\n\r\nans = counts(lefts, n) + counts(rights, n)\r\nprint(ans)", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\nprint(min(left.count(1),left.count(0))+min(right.count(1),right.count(0)))\r\n#dato loco, estoy en el aeropuerto xD", "n = int(input())\r\ncount1 = 0\r\ncount2 = 0\r\ncount3 = 0\r\ncount4 = 0\r\nfor i in range(n):\r\n l, r = map(int,input().split())\r\n if l == 0:\r\n count1 += 1\r\n else:\r\n count2 += 1\r\n if r == 0:\r\n count3 += 1\r\n else:\r\n count4 += 1\r\na = min(count1,count2)\r\nb = min(count3,count4)\r\nprint(a+b)", "n=int(input())\r\na=0\r\nb=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n a+=l\r\n b+=r\r\nprint(min(n-a,a)+min(n-b,b))\r\n", "n = int(input())\r\nleft, right = 0, 0\r\nfor i in range(n):\r\n l, r = input().split()\r\n left+=int(l)\r\n right+=int(r) \r\nprint(min(left,n-left)+min(right,n-right))", "a=int(input())\ns,m=[],[]\nfor i in range(a):\n b,c=map(int,input().split())\n s.append(b)\n m.append(c)\n\nn=min(s.count(0),s.count(1))\nh=min(m.count(0),m.count(1))\nprint(n+h)", "n = int(input())\r\nl1 = 0\r\nl2 = 0\r\nr1 = 0\r\nr2 = 0\r\nwhile n:\r\n l,r = [int(i) for i in input().split()]\r\n if l == 0:\r\n l1+=1\r\n if l == 1:\r\n l2+=1\r\n if r == 0:\r\n r1+=1\r\n if r == 1:\r\n r2+=1\r\n n-=1\r\n\r\nprint(min(l1,l2)+min(r1,r2))\r\n", "n = int(input())\n\nL0 = 0\nR1 = 0\n\nfor i in range(n):\n (l, r) = map(int, input().split())\n if l == 0:\n L0 += 1\n if r == 1:\n R1 += 1\n\nprint(min(L0, n-L0) + min(R1, n-R1))\n", "n=int(input())\r\nl1=0\r\nl2=0\r\nfor i in range(n):\r\n a,b=map(int,input().split(\" \"))\r\n if a==0:\r\n l1=l1+1\r\n if b==0:\r\n l2=l2+1\r\ns=0\r\nif l1>=n-l1:\r\n s=s+n-l1\r\nelse:\r\n s=s+l1\r\nif l2>=n-l2:\r\n s=s+n-l2\r\nelse:\r\n s=s+l2\r\nprint(s)\r\n", "def solve(doors, n):\n l = [doors[i][0] for i in range(n)]\n r = [doors[i][1] for i in range(n)]\n l0 = l.count(0)\n r0 = r.count(0)\n return min(n - l0, l0) + min(n - r0, r0)\n\n\ndef main():\n n = int(input())\n doors = [tuple(map(int, input().split())) for _ in range(n)]\n print(solve(doors, n))\n\n\nmain()\n", "ll = []\r\nrl = []\r\nfor i in range(int(input())):\r\n l, r = map(int, input().split())\r\n ll.append(l)\r\n rl.append(r)\r\ns = 0\r\nif ll.count(1) > ll.count(0):\r\n s += ll.count(0)\r\nelse:\r\n s += ll.count(1)\r\n\r\nif rl.count(1) > rl.count(0):\r\n s += rl.count(0)\r\nelse:\r\n s += rl.count(1)\r\nprint(s)\r\n", "no_of_cupboards = int(input())\r\nleft_door = []\r\nright_door = []\r\n\r\nfor i in range(no_of_cupboards):\r\n l, r = map(int, input().split())\r\n left_door.append(l)\r\n right_door.append(r)\r\n\r\nright_0 = 0\r\nright_1 = 0\r\nleft_0 = 0\r\nleft_1 = 0\r\n\r\nfor i in right_door:\r\n if i == 1:\r\n right_1 += 1\r\n else:\r\n right_0+= 1\r\n\r\ncount = min(right_0, right_1)\r\n\r\nfor i in left_door:\r\n if i == 1:\r\n left_1 += 1\r\n else:\r\n left_0 += 1\r\n\r\ncount += min(left_0, left_1)\r\n\r\nprint(count)", "n = int(input())\nlo, ro = 0, 0\nfor _ in range(n):\n l, r = (int(x) for x in input().split())\n lo, ro = lo + l, ro + r\nprint(min(lo, n - lo) + min(ro, n - ro))", "# python2 or 3\r\nimport sys, threading, os.path\r\nimport collections, heapq, math,bisect\r\nimport string\r\nfrom platform import python_version\r\nsys.setrecursionlimit(10**6)\r\nthreading.stack_size(2**27)\r\n\r\ndef main():\r\n if os.path.exists('input.txt'):\r\n input = open('input.txt', 'r')\r\n else:\r\n input = sys.stdin\r\n #--------------------------------INPUT---------------------------------\r\n n = int(input.readline())\r\n lis,counter = [],0\r\n rightc,leftc = 0,0\r\n for i in range(n):\r\n a,b = list(map(int, input.readline().split()))\r\n if a ==0:\r\n rightc+=1\r\n if b == 0:\r\n leftc+=1\r\n counter = min(rightc,n-rightc)+min(leftc,n-leftc)\r\n output = counter\r\n #-------------------------------OUTPUT----------------------------------\r\n if os.path.exists('output.txt'):\r\n open('output.txt', 'w').writelines(str(output))\r\n else:\r\n sys.stdout.write(str(output))\r\n\r\n\r\nthreading.Thread(target=main).start()\r\n\r\n", "n = int(input())\r\na, b = 0, 0\r\nfor i in range(n):\r\n da, db = map(int, input().split())\r\n a += da\r\n b += db\r\nprint(min(n - a, a) + min(n - b, b))", "n = int(input())\r\nleft, right = 0, 0\r\nfor _ in range(n):\r\n x, y = list(map(int, input().split()))\r\n left += x == 1\r\n right += y == 1\r\n\r\nprint(min(n - left, left) + min(n - right, right))\r\n", "n = int(input())\r\nleftOpen, rightOpen = 0, 0\r\nfor _ in range(n):\r\n l, r = list(map(int, input().split()))\r\n leftOpen += l\r\n rightOpen += r\r\nleftClose = n - leftOpen\r\nrightClose = n - rightOpen\r\nprint(min(leftClose, leftOpen) + min(rightClose, rightOpen))\r\n ", "n = int(input())\ncntl = 0\ncntr = 0\nfor _ in range(n):\n a,b = map(int,input().split())\n if a ==1: cntl+=1\n if b==1: cntr+=1\n\nans = min(cntl,n-cntl)+min(cntr,n-cntr)\nprint(ans)\n \n\t \t \t \t\t\t \t \t \t \t\t \t\t", "n = int(input())\r\nL = []\r\nR = []\r\n\r\nfor _ in range(n):\r\n l,r = map(int,input().split())\r\n L.append(l)\r\n R.append(r)\r\n\r\nl0 = L.count(0)\r\nl1 = n - l0\r\n\r\nr0 = R.count(0)\r\nr1 = n - r0\r\n\r\nt = 0\r\n\r\nif r0 > r1:\r\n t += r1\r\nelse:\r\n t += r0\r\n\r\nif l0 > l1:\r\n t += l1\r\nelse:\r\n t += l0\r\n\r\nprint(t)", "n = int(input())\r\narr = []\r\nleft = []\r\nright =[]\r\ncounti = counto =count = 0\r\nfor i in range(n):\r\n val = list(map(int, input().split(\" \")))\r\n arr.append(val)\r\n\r\nfor i in arr:\r\n left.append(i[0])\r\n right.append(i[1])\r\n\r\n\r\nfor i in left:\r\n if i == 1:\r\n counti += 1\r\n else:\r\n counto += 1\r\ncount += counti if counti < counto else counto\r\ncounti=counto=0\r\nfor i in right:\r\n if i == 1:\r\n counti += 1\r\n else:\r\n counto += 1\r\ncount += counti if counti < counto else counto\r\n\r\nprint(count)", "n = int(input())\r\nl =[]\r\nm = []\r\nc = 0\r\nwhile n:\r\n n -= 1\r\n a = list(map(int, input().split()))\r\n l.append(a[1])\r\n m.append(a[0])\r\nif l.count(0) >= l.count(1):\r\n c += l.count(1)\r\nif l.count(0) < l.count(1):\r\n c += l.count(0)\r\nif m.count(0) > m.count(1):\r\n c += m.count(1)\r\nif m.count(0) <= m.count(1):\r\n c += m.count(0)\r\nprint(c)\r\n ", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n e1,e2=map(int,input().split())\r\n l.append(e1)\r\n r.append(e2)\r\na=l.count(0)\r\nb=l.count(1)\r\nc=r.count(0)\r\nd=r.count(1)\r\nans=0\r\nif a>b:\r\n ans+=b\r\nelse:\r\n ans+=a\r\nif c>d:\r\n ans+=d\r\nelse:\r\n ans+=c\r\nprint(ans)", "n = int(input())\r\nleft = 0\r\nright = 0\r\nfor i in range(n):\r\n left_cup, right_cup = map(int, input().split())\r\n left += left_cup\r\n right += right_cup\r\nleft_close = n - left\r\nright_close = n - right\r\nleft_time = min(left_close, left)\r\nright_time = min(right_close, right)\r\nprint(left_time + right_time)", "# Har har mahadev\r\n# author : @harsh kanani\r\n\r\nimport math\r\nfrom collections import Counter\r\n\r\nn = int(input())\r\nright_one = 0\r\nright_zero = 0\r\nleft_one = 0\r\nleft_zero = 0\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n if l==1:\r\n left_one += 1\r\n else:\r\n left_zero += 1\r\n\r\n if r==1:\r\n right_one += 1\r\n else:\r\n right_zero += 1\r\n\r\nans = min(left_one, left_zero) + min(right_one, right_zero)\r\nprint(ans)", "n=int(input())\r\nc=0\r\nd=0\r\ne=0\r\nf=0\r\n\r\nfor i in range(n):\r\n x,y=list(map(int,input().split()))\r\n if x==0:\r\n c+=1\r\n if x==1:\r\n d+=1\r\n if y==0:\r\n e+=1\r\n else:\r\n f+=1\r\n\r\nprint(min(c,d)+min(e,f))\r\n \r\n ", "n = int(input())\r\n\r\nitems = []\r\n\r\nfor i in range(n):\r\n x, y = map(int, input().split())\r\n items.append((x, y))\r\n\r\ncount_x = len([item for item in items if item[0] == 1])\r\ncount_y = len([item for item in items if item[1] == 1])\r\n\r\ntime = min(n-count_x, count_x) + min(n-count_y, count_y)\r\nprint(time)", "num=int(input())\r\ntot=list()\r\nlf=0\r\nrf=0\r\nfor i in range(0,num):\r\n tot.append(input().split(\" \"))\r\nfor i in range(0,num):\r\n if tot[i][0]==\"1\":\r\n lf+=1\r\n if tot[i][1]==\"1\":\r\n rf+=1\r\nl=min(lf,num-lf)\r\nr=min(rf,num-rf)\r\nprint(l+r)", "n = int(input())\r\nlm = []\r\nrm = []\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n lm.append(l)\r\n rm.append(r)\r\nlm1 = lm.count(1)\r\nlm0 = lm.count(0)\r\nrm1 = rm.count(1)\r\nrm0 = rm.count(0)\r\nprint(min(lm1,lm0)+min(rm1,rm0))", "n = int(input())\r\nx_dict = {}\r\ny_dict = {}\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n if x not in x_dict: \r\n x_dict[x] = 1\r\n else:\r\n x_dict[x] += 1 \r\n\r\n if y not in y_dict:\r\n y_dict[y] = 1 \r\n else:\r\n y_dict[y] += 1 \r\n \r\n\r\nmin_x = x_dict[min(x_dict, key=lambda x: x_dict[x])] \r\nmin_y = y_dict[min(y_dict, key=lambda x: y_dict[x])] \r\n\r\nif min_y == n and min_x == n:\r\n print(0)\r\nelif min_x == n:\r\n print(min_y)\r\nelif min_y == n:\r\n print(min_x)\r\nelse:\r\n print(min_x + min_y)", "n = int(input())\r\nl = []\r\nr = []\r\nfor i in range(n):\r\n k,j = map(int, input().split())\r\n l.append(k)\r\n r.append(j)\r\na,b = l.count(1),r.count(1)\r\n\r\nif a==n:\r\n print(n - max(r.count(1), r.count(0)))\r\n exit()\r\nif b==n:\r\n print(n - max(l.count(1), l.count(0)))\r\n exit()\r\nx = 0\r\nif l.count(1)>=l.count(0):\r\n x+=l.count(0)\r\nelse:\r\n x+=l.count(1)\r\nif r.count(1)>=r.count(0):\r\n x+=r.count(0)\r\nelse:\r\n x+=r.count(1)\r\nprint(x)", "a = int(input())\r\nlst1 = []\r\nlst2 = []\r\ni = 0\r\n\r\nwhile i < a:\r\n b,c = map(int, input().split())\r\n lst1.append(b)\r\n lst2.append(c)\r\n i = i+1\r\ndef countMax(list):\r\n f = 0\r\n count0 = 0\r\n count1 = 0\r\n while f < a:\r\n if list[f] == 0:\r\n count0 = count0+1\r\n f = f+1\r\n else:\r\n count1 = count1+1\r\n f = f+1\r\n \r\n return(count0, count1)\r\nd,e = countMax(lst1)\r\ng,h = countMax(lst2)\r\nj,k = 0,0\r\n\r\nif d<e:\r\n j = d\r\nelse:\r\n j = e\r\n \r\nif g<h:\r\n k = g\r\nelse:\r\n k = h\r\n\r\nprint(j+k)", "n = int(input())\r\nL = []\r\nR = []\r\ncountL = [0, 0]\r\ncountR = [0, 0]\r\nfor _ in range(n):\r\n\tx, y = map(int, input().split())\r\n\tL.append(x)\r\n\tR.append(y)\r\n\tcountL[x]+=1\r\n\tcountR[y]+=1\r\nmaxL = countL.index(max(countL))\r\nmaxR = countR.index(max(countR))\r\ncount = 0\r\nfor i in range(n):\r\n\tif(L[i] != maxL):\r\n\t\tcount+=1\r\n\tif(R[i] != maxR):\r\n\t\tcount+=1\r\nprint(count)", "i=int(input())\r\ncubboards_left=[]\r\ncubboards_right=[]\r\nfor x in range(i):\r\n a,b=map(int,input().split())\r\n cubboards_left.append(a)\r\n cubboards_right.append(b)\r\nv=min(cubboards_left.count(1),cubboards_left.count(0))\r\nm=min(cubboards_right.count(1),cubboards_right.count(0))\r\nprint(v+m)\r\n\r\n \r\n\r\n", "n=int(input())\r\na,b=[],[]\r\nfor i in range(n):\r\n an,bn=map(int,input().strip().split())\r\n a.append(an)\r\n b.append(bn)\r\nsuma=sum(a)\r\nsumb=sum(b)\r\n#all 0\r\na=suma+sumb\r\nb=2*n-suma-sumb\r\nc=suma+n-sumb\r\nd=sumb+n-suma\r\nprint(min(a,b,c,d))", "n=int(input())\r\nle=0\r\nri=0\r\nfor _ in range(n):\r\n l, r=map(int, input().split())\r\n le+=l\r\n ri+=r\r\nprint(\"{}\".format(min(le,n-le)+min(ri,n-ri)))\r\n ", "lo, lc, ro, rc = 0, 0, 0, 0\r\nfor _ in range(int(input())):\r\n l, r = map(int, input().split())\r\n if l == 0:\r\n lc += 1\r\n else:\r\n lo += 1\r\n if r == 0:\r\n rc += 1\r\n else:\r\n ro += 1\r\nprint(min(lc, lo) + min(rc, ro))", "n = int(input())\n\nl = 0\nr = 0\n\nfor _ in range(n):\n li, ri = [int(x) for x in input().split()]\n l += li\n r += ri\n\nprint (min(l, n - l) + min(r, n - r))\n", "count=0\r\nl=[]\r\nr=[]\r\nn=int(input())\r\nfor i in range(n):\r\n a,b=[int(x) for x in input().split()]\r\n l.append(a)\r\n r.append(b)\r\n\r\nc_l_1 = l.count(1)\r\nc_l_0 = l.count(0)\r\nc_r_1 = r.count(1)\r\nc_r_0 = r.count(0)\r\n\r\nif c_l_0 < c_l_1:\r\n count+=c_l_0\r\nelse:\r\n count+=c_l_1\r\n\r\nif c_r_0 < c_r_1:\r\n count+=c_r_0\r\nelse:\r\n count+=c_r_1\r\n\r\nprint(count)", "ll=0\r\nlr=0\r\nrl=0\r\nrr=0\r\nt=int(input())\r\nwhile t>0:\r\n \r\n a=input().split()\r\n if a[0]=='0':\r\n ll+=1\r\n else:\r\n lr+=1\r\n if a[1]=='0':\r\n rl+=1\r\n else:\r\n rr+=1\r\n t-=1\r\n \r\na=min(ll,lr)\r\na+=min(rl,rr)\r\n\r\nprint(a) \r\n \r\n \r\n \r\n \r\n\r\n ", "r=int(input())\r\nx=[]\r\ny=[]\r\nfor i in range(r):\r\n\tm,n=map(int,input().split())\r\n\tx.append(m)\r\n\ty.append(n)\r\nlo=x.count(1)\r\nlc=x.count(0)\r\nro=y.count(1)\r\nrc=y.count(0)\r\nt=0\r\nif lo>lc:\r\n\tt+=(r-lo)\r\nelif lc>lo:\r\n\tt+=(r-lc)\r\nelse:\r\n\tt+=lo\r\nif ro>rc:\r\n\tt+=(r-ro)\r\nelif rc>ro:\r\n\tt+=(r-rc)\r\nelse:\r\n\tt+=(rc)\r\nprint(t)", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor x in range(n):\r\n list1,list2=list(map(int,input().split()))\r\n left.append(list1)\r\n right.append(list2)\r\na=left.count(0)\r\nb=len(left)-a\r\na1=right.count(0)\r\nb1=len(right)-a1\r\nprint(min(a,b)+min(a1,b1))", "def main():\r\n l, r = [], []\r\n for i in range(int(input())):\r\n i1, i2 = map(int, input().split())\r\n l.append(i1)\r\n r.append(i2)\r\n print(min(l.count(1), l.count(0)) + min(r.count(1), r.count(0)))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "# def fun(n,arr_2d,s):\r\n# \tindex = n\r\n# \tfor i in range(n):\r\n# \tif arr_2d[i][0]>s:\r\n# \t\tindex = i\r\n# \treturn index\r\n# string = input().split(' ')\r\n# s = int(string[0])\r\n# n = int(string[1])\r\n# arr_2d = []\r\n# for i in range(n):\r\n# \ts1 = input().split(' ')\r\n# \tar1 = [int(i) for i in s1]\r\n# \tarr_2d.append(ar1)\r\n# arr_2d.sort()\r\n# flag = 0\r\n# while flag !=1:\r\n# \tind = fun(n,arr_2d,s)\r\n# \tarr_2d = arr_2d\r\n\r\nn = int(input())\r\narr = [input().split(' ') for i in range(n)]\r\nnew_arr = [[int(i),int(j)] for i , j in (arr[k] for k in range(n))]\r\n# print(new_arr)\r\ncolum_1 = [int(k[0]) for k in arr]\r\ncolum_2 = [int(k[1]) for k in arr]\r\n# print(colum_1)\r\ncount_1_col_1 = colum_1.count(1)\r\ncount_1_col_2 = colum_2.count(1)\r\nprint(min(count_1_col_1,(n-count_1_col_1))+min(count_1_col_2,(n-count_1_col_2)))\r\n", "n=int(input())\r\ns1,s2=0,0\r\nfor _ in range(n):\r\n a,b=map(int,input().split())\r\n s1+=a\r\n s2+=b\r\nprint(min(s1,n-s1)+min(s2,n-s2))", "n=int(input())\ns0=0\ns1=0\nb0=0\nb1=0\nfor i in range(n):\n\ta,b=map(int,input().split())\n\tif a==0:\n\t\ts0+=1\n\telse:\n\t\ts1+=1\n\tif b==0:\n\t\tb0+=1\n\telse:\n\t\tb1+=1\nx=s1\nif s0<s1:\n\tx=s0\ny=b1\nif b0<b1:\n\ty=b0\nprint(x+y)\n\n\n\t \t \t\t\t \t\t \t \t \t\t\t\t \t", "n=int(input())\r\nsl=0\r\nsr=0\r\nfor i in range(n):\r\n l,r=[int(x) for x in input().split()]\r\n sl+=l\r\n sr+=r\r\nml=min(sl,n-sl)\r\nmr=min(sr,n-sr)\r\nprint(ml+mr)", "l=[]\r\nr=[]\r\nmoves=0\r\nopen=0\r\nclosed=0\r\nfor i in range(int(input())):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\nif l.count(0)>=l.count(1):\r\n moves+=l.count(1)\r\nelse:\r\n moves+=l.count(0)\r\nif r.count(0)>=r.count(1):\r\n moves+=r.count(1)\r\nelse:\r\n moves+=r.count(0)\r\nprint(moves)", "\r\nt = int(input())\r\ncount_l_zero = 0\r\ncount_r_zero = 0\r\ncount_l_one = 0\r\ncount_r_one = 0\r\n\r\ncount = 0\r\nfor _ in range(t):\r\n a, b = map(int,input().split())\r\n\r\n if a == 0:\r\n \tcount_l_zero += 1\r\n\r\n else:\r\n \tcount_l_one += 1\r\n\r\n if b == 0:\r\n \tcount_r_zero += 1\r\n else:\r\n \tcount_r_one += 1\r\n\r\nif count_l_zero>count_l_one:\r\n\tcount += count_l_one\r\nelif count_l_zero < count_l_one:\r\n\tcount += count_l_zero\r\nelse:\r\n\tcount += count_l_zero\r\n\r\n\r\nif count_r_zero>count_r_one:\r\n\tcount += count_r_one\r\nelif count_r_zero < count_r_one:\r\n\tcount += count_r_zero\r\nelse:\r\n\tcount += count_r_zero\r\n\r\nprint(count)", "n = int(input())\r\na = []\r\nb = []\r\n\r\nfor _ in range(n):\r\n z = list(map(int, input().split()))\r\n a.append(z[0])\r\n b.append(z[1])\r\n \r\nm1 = min(a.count(1), a.count(0))\r\nm2 = min(b.count(1), b.count(0))\r\nprint(m1+m2)", "n=int(input())\r\nx,y=0,0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n x+=a\r\n y+=b\r\nx=x if x<=n//2 else (n-x)\r\ny=y if y<=n//2 else (n-y)\r\nprint(x+y)", "nums = int(input())\r\nlist1 = []\r\nlist2 = []\r\nlist3 = []\r\nfor i in range(nums):\r\n list1.append([int(h) for h in input().split()])\r\n# print(list1)\r\nfor i in list1:\r\n list2.append(i[0])\r\n list3.append(i[1])\r\nlist4 = [list2.count(1), list2.count(0), list3.count(1), list3.count(0)]\r\nprint(sum(sorted(list4)[0:2]))", "n = (int)(input())\r\noneL , oneR = 0 , 0\r\nfor _ in range(n) :\r\n l , r = (list)(map(int , input().split()))\r\n if l == 1 : oneL += 1\r\n if r == 1 : oneR += 1\r\nprint(min(oneL , n - oneL) + min(oneR , n - oneR))", "import sys\nfrom collections import Counter as C\n# sys.stdin = open('in.txt', 'r') \n# sys.stdout = open('out.txt', 'w')\nl,r=[],[]\nfor _ in range(int(input())):\n\tli,ri=map(int,input().split())\n\tl.append(li)\n\tr.append(ri)\nans=0\nans=min(l.count(0),l.count(1))\nans+=min(r.count(0),r.count(1))\nprint(ans)\n", "x=int(input())\r\nl=[]\r\ncount=0\r\ndict={(0,0):0,(0,1):0,(1,0):0,(1,1):0}\r\nfor _ in range(x):\r\n i=tuple(map(int,input().split( )))\r\n dict[i]=dict.get(i,0)+1\r\ndict1={(0,0):0,(0,1):1,(1,0):1,(1,1):2}\r\ndict1[(0,0)]=dict[(0,1)]+dict[(1,0)]+(2*dict[(1,1)])\r\ndict1[(0,1)]=dict[(0,0)]+dict[(1,1)]+(2*dict[(1,0)])\r\ndict1[(1,0)]=dict[(0,0)]+dict[(1,1)]+(2*dict[(0,1)])\r\ndict1[(1,1)]=dict[(0,1)]+dict[(1,0)]+(2*dict[(0,0)])\r\nprint(min(dict1.values()))\r\n", "n = int(input())\r\n\r\narr = []\r\nans = 0\r\nsm = 0\r\nfor i in range(n):\r\n\ta = [int(x) for x in input().split()]\r\n\tarr.append(a)\r\nfor i in range(2):\r\n\tfor j in range(n):\r\n\t\tsm += arr[j][i]\r\n\tif sm <= (n//2):\r\n\t\tans += sm\r\n\telse:\r\n\t\tans += (n-sm)\r\n\tsm = 0\r\nprint(ans)", "n = int(input())\r\nrightClosed = 0\r\nrightOpen = 0\r\nleftClosed = 0\r\nleftOpen = 0\r\ncount=0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n if(l==0):\r\n leftClosed+=1\r\n if(l==1):\r\n leftOpen+=1\r\n if(r==0):\r\n rightClosed+=1\r\n if(r==1):\r\n rightOpen+=1\r\nif(rightClosed>=rightOpen):\r\n count+=rightOpen\r\nelse:\r\n count+=rightClosed\r\nif(leftClosed>=leftOpen):\r\n count+=leftOpen\r\nelse:\r\n count+=leftClosed\r\nprint(count)\r\n", "n = int(input())\r\ndoorlist = []\r\nfor i in range(n):\r\n doorlist.append(list(map(int, input().split())))\r\n \r\nsum1 = sum2 = sum3 = sum4 = 0\r\nsumleft = 0\r\nsumright = 0\r\n\r\nfor i in range(n):\r\n sumleft += doorlist[i][0]\r\n sumright += doorlist[i][1]\r\n \r\nsum1 = sumleft + (n-sumright)\r\nsum2 = sumright + (n-sumleft)\r\nsum3 = sumright + sumleft\r\nsum4 = (n-sumright) + (n-sumleft)\r\n\r\nprint(min(sum1,sum2,sum3,sum4))", "def solve(n,l):\n\tt = 0\n\tleft_open = 0\n\tright_open = 0\n\tfor i in range(n):\n\t\tif l[i][0] == 1:\n\t\t\tleft_open += 1\n\t\tif l[i][1] == 1:\n\t\t\tright_open += 1\n\t\n\tif left_open < (n//2)+1:\n\t\tt += left_open\n\telse:\n\t\tt += n-left_open\n\n\tif right_open < (n//2)+1:\n\t\tt += right_open\n\telse:\n\t\tt += n-right_open\n\treturn t\t\t\t\t\n\nn = int(input())\nl = []\nfor i in range(n):\n\ts = list(map(int,input().split()))\n\tl.append(s)\n\nprint(solve(n,l))", "n = int(input())\r\nl,r = [0,0],[0,0]\r\nfor _ in range(n):\r\n cl,cr = map(int,input().split())\r\n l[cl]+=1\r\n r[cr]+=1\r\nprint(min(l)+min(r))", "n=int(input())\r\nli0=0\r\nli1=0\r\nri0=0\r\nri1=0\r\nfor i in range(n) :\r\n li,ri=map(int,input().split())\r\n if li==0 :\r\n li0+=1\r\n else :\r\n li1+=1\r\n if ri==0 :\r\n ri0+=1\r\n else :\r\n ri1+=1\r\n\r\nprint(min(li0,li1)+min(ri0,ri1))", "\"\"\"\r\n ____ _ _____\r\n / ___|___ __| | ___| ___|__ _ __ ___ ___ ___\r\n| | / _ \\ / _` |/ _ \\ |_ / _ \\| '__/ __/ _ \\/ __|\r\n| |__| (_) | (_| | __/ _| (_) | | | (_| __/\\__ \\\r\n \\____\\___/ \\__,_|\\___|_| \\___/|_| \\___\\___||___/\r\n\"\"\"\r\n\"\"\"\r\n░░██▄░░░░░░░░░░░▄██\r\n░▄▀░█▄░░░░░░░░▄█░░█░\r\n░█░▄░█▄░░░░░░▄█░▄░█░\r\n░█░██████████████▄█░\r\n░█████▀▀████▀▀█████░\r\n▄█▀█▀░░░████░░░▀▀███\r\n██░░▀████▀▀████▀░░██\r\n██░░░░█▀░░░░▀█░░░░██\r\n███▄░░░░░░░░░░░░▄███\r\n░▀███▄░░████░░▄███▀░\r\n░░░▀██▄░▀██▀░▄██▀░░░\r\n░░░░░░▀██████▀░░░░░░\r\n░░░░░░░░░░░░░░░░░░░░\r\n\"\"\"\r\n\r\nimport sys\r\nimport math\r\nimport collections\r\nfrom collections import deque\r\n\r\n#sys.stdin = open('input.txt', 'r')\r\n#sys.stdout = open('output.txt', 'w')\r\n\r\nfrom functools import reduce\r\nfrom sys import stdin, stdout, setrecursionlimit\r\nsetrecursionlimit(2**20)\r\n\r\n\r\ndef factors(n):\r\n return list(set(reduce(list.__add__,\r\n ([i, n // i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))\r\n\r\n# for _ in range(int(stdin.readline())):\r\nn = int(stdin.readline().strip('\\n'))\r\n# b = str(stdin.readline().strip('\\n'))\r\n# n, m = list(map(int, stdin.readline().split()))\r\n# s = list(str(stdin.readline().strip('\\n')))\r\n# n = len(a)\r\n#k = int(stdin.readline().strip('\\n'))\r\nl, r = [], []\r\nfor i in range(n):\r\n a, b = list(map(int, stdin.readline().split()))\r\n l.append(a)\r\n r.append(b)\r\nans = 0\r\n\r\nif l.count(0) >= l.count(1):\r\n ans += l.count(1)\r\nelse:\r\n ans += l.count(0)\r\n\r\nif r.count(0) >= r.count(1):\r\n ans += r.count(1)\r\nelse:\r\n ans += r.count(0)\r\nprint(ans)\r\n", "n = int(input())\r\nlc = []\r\nrc = []\r\nsol = 0\r\nfor _ in range(n):\r\n l, r = map(int, input().split())\r\n lc.append(l)\r\n rc.append(r)\r\n\r\nora = rc.count(0)\r\nola = rc.count(1)\r\nsol += ola if(ora > ola) else ora\r\n\r\n\r\nprb = lc.count(0)\r\nplb = lc.count(1)\r\nsol += plb if(prb > plb) else prb\r\n\r\nprint(sol)\r\n", "def solve(doors, n):\n l = sum(1 for i in range(n) if doors[i][0] == 0)\n r = sum(1 for i in range(n) if doors[i][1] == 0)\n return min(n - l, l) + min(n - r, r)\n\n\ndef main():\n n = int(input())\n doors = [tuple(map(int, input().split())) for _ in range(n)]\n print(solve(doors, n))\n\n\nmain()\n", "n=int(input())\r\nk1=[]\r\nk2=[]\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n k1.append(l)\r\n k2.append(r)\r\nprint(min(k1.count(0),k1.count(1))+min(k2.count(0),k2.count(1)))\r\n", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[204]:\n\n\n# # n = int(input())\n# # line = list(map(int, input().split()))\n\n\n# In[495]:\n\n\nfrom collections import Counter\n\n\n# In[518]:\n\n\nn = int(input())\nld, rd = [], []\n\nfor _ in range(n):\n doors = (list(map(int, input().split())))\n ld.append(doors[0])\n rd.append(doors[1])\n\n\n# In[521]:\n\n\nrd_change = 0 \nld_change = 0\n\n\n# In[522]:\n\n\nif len(Counter(rd).most_common()) > 1 :\n rd_least = Counter(rd).most_common()[1][0]\n rd_change = Counter(rd)[rd_least]\n \nif len(Counter(ld).most_common()) > 1 :\n ld_least = Counter(ld).most_common()[1][0]\n ld_change = Counter(ld)[ld_least]\n\n\n# In[523]:\n\n\nprint(ld_change + rd_change)\n\n\n# In[ ]:\n\n\n\n\n", "t=int(input())\r\ntot=0\r\ntot1=0\r\ndebug = False\r\n\r\nfor i in range(0,t):\r\n m,n=map(int,input().split())\r\n tot=tot+m\r\n tot1=tot1+n\r\nmi=0\r\nma=0\r\nif debug:\r\n print(tot, tot1)\r\n\r\nmi=min(tot,(t-tot))\r\nma=min(tot1,(t-tot1))\r\nif debug:\r\n print(mi, ma, mi + ma)\r\nprint(mi+ma)\r\n", "left=[]\r\nright=[]\r\nfor i in range(int(input())):\r\n l,r=map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\ncount=0\r\ncount+=min(left.count(1), left.count(0))\r\ncount+=min(right.count(1), right.count(0))\r\nprint(count)", "left= []\r\nright= []\r\nfor i in range(int(input())):\r\n l,r = map(int, input().split())\r\n left.append(l)\r\n right.append(r)\r\nprint(min(left.count(1), left.count(0))+ min(right.count(1), right.count(0)))", "vals_zero_a=0\r\nvals_one_a=0\r\nvals_zero_b=0\r\nvals_one_b=0\r\nK=int(input())\r\nfor _ in range(K):\r\n a,b=map(int,input().split())\r\n if(a==0):\r\n vals_zero_a+=1\r\n if(a==1):\r\n vals_one_a+=1\r\n if(b==0):\r\n vals_zero_b+=1\r\n if(b==1):\r\n vals_one_b+=1\r\nif vals_zero_a>=vals_one_a:\r\n time_a=K-vals_zero_a\r\nelif vals_zero_a<vals_one_a:\r\n time_a= K- vals_one_a\r\nif vals_zero_b>=vals_one_b:\r\n time_b=K-vals_zero_b\r\nelif vals_zero_b<vals_one_b:\r\n time_b=K-vals_one_b\r\nprint(time_a+time_b)\r\n ", "def solve(n, left, right):\r\n leftSum = sum(left)\r\n rightSum = sum(right)\r\n leftTime = leftSum if leftSum <= (n//2) else n - leftSum\r\n rightTime = rightSum if rightSum <= (n//2) else n - rightSum\r\n return leftTime + rightTime\r\n \r\nn = int(input())\r\nleft = []\r\nright = []\r\nfor _ in range(n):\r\n pair = list(map(int, input().split()))\r\n left.append(pair[0])\r\n right.append(pair[1])\r\nprint(solve(n, left, right))", "n = int(input())\r\nl,r = 0,0\r\nfor i in range(n):\r\n p,q = map(int,input().split())\r\n l+=p\r\n r+=q\r\nprint(min(l,n-l)+min(r,n-r))\r\n", "n = int(input())\nx0 = 0\nx1 = 0\ny0 = 0\ny1 = 0\nfor i in range(n):\n x, y = map(int, input().split())\n if x == 0:\n x0 += 1\n else:\n x1 += 1\n\n if y == 0:\n y0 += 1\n else:\n y1 += 1\n\nans = 0\nans += n - max(x0, x1)\nans += n - max(y0, y1)\nprint(ans)\n", "n = int(input())\r\nleft, right = [], []\r\nfor i in range(n):\r\n l,r=map(int, input().split())\r\n left.append(l)\r\n right.append(r)\r\nr,r1,l,l1=0,0,0,0\r\nfor i in range(n):\r\n if(right[i]==1):\r\n r1+=1\r\n else:\r\n r+=1\r\nmin_i = min(r1,r)\r\nfor i in range(n):\r\n if(left[i]==1):\r\n l1+=1\r\n else:\r\n l+=1\r\nmin_i+=min(l1,l)\r\nprint(min_i)", "n = int(input())\r\n\r\ntl = tr = 0\r\n\r\nfor _ in range(n):\r\n l, r = [int(x) for x in input().split()]\r\n tl += l\r\n tr += r\r\n\r\nret = min(tl, n - tl) + min(tr, n - tr)\r\nprint(ret)", "T = int(input())\r\ncount = 0\r\ndown = 0\r\nfor i in range(T):\r\n n = list(map(int, input().split()))\r\n if n[0] == 1:\r\n count += 1\r\n if n[1] == 1:\r\n down += 1\r\nif count < (T/2) and down < (T/2):\r\n result = count + down\r\nelif count > (T/2) and down < (T/2):\r\n result = down + T - count\r\nelif count < (T/2) and down > (T/2):\r\n result = count + T - down\r\nelse:\r\n result = 2*T - count - down\r\nprint(result)", "t = int(input())\r\nl = [0,0,0,0]\r\nwhile t!=0:\r\n t-=1\r\n x,y = map(int,input().split())\r\n if x==0:\r\n l[0]+=1\r\n else:\r\n l[1]+=1\r\n if y==0:\r\n l[2]+=1\r\n else:\r\n l[3]+=1\r\nprint(min(l[0],l[1])+min(l[2],l[3]))\r\n\r\n", "n=int(input())\r\nl=0\r\nr=0\r\nfor _ in range(n):\r\n i,j=map(int,input().split())\r\n if i==1:\r\n l+=1\r\n if j==1:\r\n r+=1\r\nprint(min(l,n-l) + min(r,n-r))\r\n\r\n ", "n = int(input())\r\nleft_open = right_open = 0\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n left_open += l\r\n right_open += r\r\n\r\nt1 = min(left_open, n - left_open) + min(right_open, n - right_open)\r\nt2 = min(left_open + right_open, n - left_open + n - right_open)\r\n\r\nprint(min(t1, t2))\r\n", "t=int(input())\r\ncol_seconds=0\r\nright=[]\r\nleft=[]\r\nfor i in range(t):\r\n l,r=map(int,input().split())\r\n right.append(r)\r\n left.append(l)\r\n\r\notk_r=right.count(1)\r\nzak_r=right.count(0)\r\notk_l=left.count(1)\r\nzak_l=left.count(0)\r\ncol_seconds+=min(otk_r,zak_r)+min(otk_l,zak_l)\r\nprint(col_seconds)", "num = int(input())\nleft_open = 0\nleft_close = 0\nright_open = 0\nright_close = 0\nfor _ in range(num):\n l, r = input().split()\n if l =='1':\n left_open +=1 \n else:\n left_close +=1 \n if r =='1':\n right_open += 1\n else:\n right_close += 1\nprint(sum([min([left_close, left_open]), min([right_open, right_close])]))", "n = int(input())\r\nleft = 0\r\nright = 0\r\nl_open = 0\r\nl_closed = 0\r\nr_open = 0\r\nr_closed = 0\r\ntime = 0\r\nlist1 = []\r\n\r\nfor i in range(n):\r\n x = map(int, input().split())\r\n left, right = x\r\n list1.append([left, right])\r\n\r\n if left == 1:\r\n l_open += 1\r\n elif left == 0:\r\n l_closed += 1\r\n \r\n if right == 1:\r\n r_open += 1\r\n elif right == 0:\r\n r_closed += 1\r\n\r\nif l_open > l_closed:\r\n for i in range(len(list1)):\r\n if list1[i][0] != 1:\r\n time += 1\r\nelse:\r\n for i in range(len(list1)):\r\n if list1[i][0] != 0:\r\n time += 1\r\n\r\nif r_open > r_closed:\r\n for i in range(len(list1)):\r\n if list1[i][1] != 1:\r\n time += 1\r\nelse:\r\n for i in range(len(list1)):\r\n if list1[i][1] != 0:\r\n time += 1\r\n\r\nprint(time)", "l,r=[],[]\r\nfor _ in range(int(input())):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\nt=0\r\nif l.count(1)>l.count(0):\r\n t+=l.count(0)\r\nelse:\r\n t+=l.count(1)\r\nif r.count(1)>r.count(0):\r\n t+=r.count(0)\r\nelse:\r\n t+=r.count(1)\r\nprint(t)", "def Cupboards():\r\n totalCupboards = int(input())\r\n left_door_position = []\r\n right_door_position = []\r\n\r\n for i in range(totalCupboards):\r\n cupboard_position = input()\r\n cupboard_position = cupboard_position.split(' ')\r\n left_door_position.append(int(cupboard_position[0]))\r\n right_door_position.append(int(cupboard_position[1]))\r\n\r\n left_door_open_count = 0\r\n for i in left_door_position:\r\n if i == 1:\r\n left_door_open_count += 1\r\n\r\n right_dor_open_count = 0\r\n for i in right_door_position:\r\n if i == 1:\r\n right_dor_open_count += 1\r\n\r\n left_door_time = min(left_door_open_count, totalCupboards - left_door_open_count)\r\n right_door_time = min(right_dor_open_count, totalCupboards - right_dor_open_count)\r\n print(left_door_time + right_door_time)\r\n\r\n\r\nCupboards()", "n = int(input())\r\ncountm=[]\r\ncountn=[]\r\nfor i in range(n):\r\n m,n = map(int,input().split())\r\n countm.append(m)\r\n countn.append(n)\r\nx ,y ,z ,w = countm.count(0),countm.count(1),countn.count(0),countn.count(1)\r\nprint(min(x,y) + min(z,w))", "t=int(input())\r\na=[]\r\nb=[]\r\nfor i in range(t):\r\n l,r=map(int,input().split())\r\n a.append(l)\r\n b.append(r)\r\na1=a.count(0)\r\na2=a.count(1)\r\nb1=b.count(0)\r\nb2=b.count(1)\r\na3=min(a1,a2)\r\nb3=min(b1,b2)\r\nprint(a3+b3) \r\n", "\r\n\r\nboth=[[],[]]\r\nn=int(input())\r\nfor i in range(n):\r\n x=input()\r\n both[0].append(int(x[0]))\r\n both[1].append(int(x[-1]))\r\ntime=0\r\n\r\nfor i in range(2):\r\n if both[i].count(i)>both[i].count(i^1):\r\n time+=n-both[i].count(i)\r\n else:\r\n time+=n-both[i].count(i^1)\r\nprint(time)\r\n", "n=int(input())\r\nlc=rc=0\r\nfor i in range(n):\r\n t=input().split()\r\n t=[int(x) for x in t]\r\n if t[0]==1:\r\n lc+=1\r\n if t[1]==1:\r\n rc+=1\r\n \r\nprint(min(n-lc,lc)+min(n-rc,rc))", "n = int(input())\r\nleft, right = 0, 0\r\nfor _ in range(n):\r\n\tl, r = input().split()\r\n\tif l == '1':\r\n\t\tleft += 1\r\n\tif r == '1':\r\n\t\tright += 1\r\ntime = min(left, n - left) + min(right, n - right)\r\nprint(time)\r\n", "n=int(input())\r\nleft_zero=0\r\nleft_one=0\r\nright_zero=0\r\nright_one=0\r\nfor _ in range(n):\r\n a,b=map(int,input().split())\r\n if a==0:\r\n left_zero+=1\r\n else:\r\n left_one+=1\r\n if b==0:\r\n right_zero+=1\r\n else:\r\n right_one+=1\r\nprint(min(left_zero,left_one)+min(right_zero,right_one))", "n = int(input())\r\nleft=right=0\r\nfor i in range(n):\r\n l,r= map(int,input().split())\r\n if l == 1:\r\n left+=1\r\n if r ==1:\r\n right+=1\r\n\r\nres = 0\r\nif left<= n/2:\r\n res+=left\r\nelse:\r\n res+= n-left\r\n\r\nif right<=n/2:\r\n res+=right\r\nelse:\r\n res+= n-right\r\nprint(res)", "n = int(input())\n\nl, r = [], []\nfor _ in range(n):\n li, ri = map(int, input().split())\n l.append(li)\n r.append(ri)\n\nmin_l = min(len([_l for _l in l if _l == 1]), len([_l for _l in l if _l == 0]))\nmin_r = min(len([_r for _r in r if _r == 1]), len([_r for _r in r if _r == 0]))\nprint(min_l + min_r)\n", "n=int(input())\r\nsum1=sum2=0\r\ntemp=[]\r\nl=[]\r\nfor i in range(0,n):\r\n temp=list(map(int,input().split(\" \")))\r\n l.append(temp)\r\n sum1=sum1+temp[0]\r\n sum2=sum2+temp[1]\r\nprint(min(n-sum1,sum1)+min(n-sum2,sum2))", "n=int(input())\r\nl0=0;r0=0;l1=0;r1=0\r\nfor i in range(n):\r\n\tx,y=map(int,input().split())\r\n\tif x==0:\r\n\t\tl0+=1\r\n\tif x==1:\r\n\t\tl1+=1\r\n\tif y==0:\r\n\t\tr0+=1\r\n\tif y==1:\r\n\t\tr1+=1\r\nprint(min(l0,l1)+min(r0,r1))", "import sys\nt = int(input())\nm = []\nn = []\nc = 0\nfor i in range(0,t):\n a, b = map(int, sys.stdin.readline().strip().split())\n m.append(a)\n n.append(b)\n\nif m.count(1) > m.count(0):\n c += m.count(0)\nelse:\n c += m.count(1)\n\nif n.count(1) > n.count(0):\n c += n.count(0)\nelse:\n c += n.count(1)\n\nprint(c)\n", "t = int(input())\r\na = t\r\nq, w, e, rr = 0, 0, 0, 0\r\nwhile t:\r\n l, r = map(int, input(). split())\r\n if l == 0:q += 1\r\n if l == 1:w += 1\r\n if r == 0:e += 1\r\n if r == 1:rr += 1\r\n t -= 1\r\nmx = max(q, w)\r\nmx0 = max(e, rr)\r\nans = (a - mx) + (a - mx0)\r\nprint(ans)\r\n", "n=int(input())\r\na=[]\r\nb=[]\r\nfor i in range(n):\t\r\n\tx,y=map(int,input().split())\r\n\ta.append(x)\r\n\tb.append(y)\r\nprint(min(a.count(1),a.count(0))+min(b.count(1),b.count(0)))\t", "n=int(input())\r\ns=[]\r\nfor _ in range(n):\r\n s.append(input().split())\r\ns=list(zip(*s))\r\n\r\nsl=s[0].count(\"1\") if s[0].count(\"1\")<=len(s[0])//2 else s[0].count(\"0\")\r\nsr=s[1].count(\"1\") if s[1].count(\"1\")<=len(s[1])//2 else s[1].count(\"0\")\r\nprint(sl+sr)", "n=int(input())\r\nlo=0;lc=0;ro=0;rc=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n if l==0:\r\n lc+=1\r\n if l==1:\r\n lo+=1\r\n if r==1:\r\n ro+=1\r\n if r==0:\r\n rc+=1\r\nprint(min(lc,lo)+min(ro,rc))\r\n", "n=int(input())\r\nliste=[]\r\nfor i in range(n):\r\n liste.append(input().split())\r\ntl=0\r\ntg=0\r\nfor i in range(n):\r\n if(int(liste[i][0])==1):\r\n tl+=1\r\n if(int(liste[i][1])==1):\r\n tg+=1\r\n #print(tg)\r\n#print(tg)\r\na=0\r\nb=0\r\nif(tg<=(n-tg)):\r\n a=tg\r\nelse:\r\n a=n-tg\r\nif(tl<=(n-tl)):\r\n b=tl\r\nelse:\r\n b=n-tl\r\n#print(a)\r\n#print(b)\r\nprint(a+b)\r\n\r\n\r\n#print(tl)\r\n#print(tg)", "import collections\r\nfrom math import log2, log10, ceil\r\n\r\ndef pow2(n):\r\n t = 0\r\n while not(n&1):\r\n n = n//2\r\n t += 1\r\n return t\r\n \r\ndef solve():\r\n n = int(input())\r\n\r\n left = []\r\n right = []\r\n for i in range(n):\r\n l, r = map(int, input().split())\r\n left.append(l)\r\n right.append(r)\r\n\r\n l0 = 0\r\n r0 = 0\r\n for i in range(0, n):\r\n if left[i]==0:\r\n l0 += 1\r\n if right[i]==0:\r\n r0 += 1\r\n\r\n l1 = n - l0\r\n r1 = n - r0\r\n\r\n time = 0\r\n if l1>l0:\r\n time += l0\r\n else:\r\n time += l1\r\n\r\n if r1>r0:\r\n time += r0\r\n else:\r\n time += r1\r\n\r\n print(time)\r\n\r\ndef main():\r\n t = 1\r\n while t:\r\n t -= 1\r\n solve()\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "import sys\r\nn=int(input())\r\nc1=0\r\nc2=0\r\nfor i in range(n):\r\n x,y=[int(i) for i in input().split(' ')]\r\n if(x==1):\r\n c1+=1 \r\n if(y==1):\r\n c2+=1\r\nprint(min(c2,n-c2)+min(c1,n-c1))\r\n ", "n = int(input())\r\nzerosOf1 = zerosOf2 = onesOf2 = onesOf1 = 0\r\nfor i in range(n):\r\n lnr = input()\r\n if lnr[0] == '0':zerosOf1 += 1\r\n else:onesOf1 += 1\r\n if lnr[2] == '0':zerosOf2 += 1\r\n else:onesOf2 += 1\r\nprint(min(zerosOf1,onesOf1)+min(onesOf2,zerosOf2))\r\n\r\n", "n=int(input())\r\nl_list=[]\r\nr_list=[]\r\nwhile n!=0:\r\n l,r=input().split()\r\n l_list.append(int(l))\r\n r_list.append(int(r))\r\n n-=1\r\n\r\nl_count0=l_list.count(0)\r\nl_count1=l_list.count(1)\r\nr_count0=r_list.count(0)\r\nr_count1=r_list.count(1)\r\n\r\nmax_l=0\r\nmax_r=0\r\n\r\nif l_count0>l_count1:\r\n max_l=0\r\nelif l_count1>l_count0:\r\n max_l=1\r\nelse:\r\n max_l=0\r\n\r\nif r_count0>r_count1:\r\n max_r=0\r\nelif r_count1>r_count0:\r\n max_r=1\r\nelse:\r\n max_r=0\r\n \r\ntime_l=0\r\ntime_r=0\r\n\r\nfor i in l_list:\r\n if i!=max_l:\r\n time_l+=1\r\n\r\nfor i in r_list:\r\n if i!=max_r:\r\n time_r+=1\r\n\r\nprint(time_l+time_r)", "n = int(input())\r\n\r\n\r\na1 = 0\r\na2 = 0\r\nb1 = 0\r\nb2 = 0\r\ni = 1\r\nfor i in range(n) :\r\n a,b = input().split()\r\n a = int (a)\r\n b = int (b)\r\n\r\n if a == 0:\r\n a1 +=1\r\n else:\r\n a2+=1\r\n if b==0 :\r\n b1+=1\r\n else :\r\n b2+=1\r\nprint(min(a1,a2)+min(b1,b2))\r\n\r\n\r\n", "n=int(input())\r\ncnt=0\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\nl0=left.count(0)\r\nl1=left.count(1)\r\nml=min(l0,l1)\r\nr0=right.count(0)\r\nr1=right.count(1)\r\nmr=min(r0,r1)\r\nprint(mr+ml)", "n=int(input())\r\nl=0\r\nr=0\r\ns=0\r\nfor i in range(n):\r\n (a,b)=map(int,input().split(\" \"))\r\n l+=a\r\n r+=b\r\nif l>=n-l:\r\n s+=n-l\r\nelse:\r\n s+=l\r\nif r>=n-r:\r\n s+=n-r\r\nelse:\r\n s+=r\r\nprint(s)\r\n ", "n = int(input())\r\n\r\n\r\nr1 = r2 = r3 = r4 = 0\r\n\r\n\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n\r\n # 0 1\r\n # 1 0\r\n # 0 0\r\n # 1 1\r\n if a == 1 and b == 1:\r\n r1 += 1\r\n r2 += 1\r\n r3 += 2\r\n if a == 0 and b == 0:\r\n r1 += 1\r\n r2 += 1\r\n r4 += 2\r\n if a == 1 and b == 0:\r\n r1 += 2\r\n r3 += 1\r\n r4 += 1\r\n if a == 0 and b == 1:\r\n r2 += 2\r\n r3 += 1\r\n r4 += 1\r\n\r\nprint(min(r1, r2, r3, r4))\r\n\r\n", "l=[]\r\nr=[]\r\nlo,lt,ro,rt=0,0,0,0\r\nfor i in range(int(input())):\r\n a,b=list(map(int,input().split()))\r\n l.append(a)\r\n r.append(b)\r\n\r\n\r\nif 0 in l:\r\n lo=l.count(0)\r\nif 1 in l:\r\n lt=l.count(1)\r\n\r\n\r\nif 0 in r:\r\n ro=r.count(0)\r\nif 1 in l:\r\n rt=r.count(1)\r\n\r\nprint(min(lo,lt)+min(ro,rt))\r\n", "n = int(input())\r\nleftOpens = 0\r\nleftCloses = 0\r\nrightOpens = 0\r\nrightCloses = 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n if(l == 1):\r\n leftOpens += 1\r\n elif(l == 0):\r\n leftCloses += 1\r\n if(r == 1):\r\n rightOpens += 1\r\n elif(r == 0):\r\n rightCloses += 1\r\nt1 = min(leftOpens, leftCloses)\r\nt2 = min(rightOpens, rightCloses)\r\nans = t1 + t2\r\nprint(ans)", "n = int(input())\r\noutput = 0\r\nlc, rc = 0, 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n lc += l\r\n rc += r\r\nprint(min(lc, n-lc) + min(rc, n-rc))", "n = int(input())\r\nacnt, bcnt = 0, 0\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n if a : acnt += 1\r\n if b : bcnt += 1\r\n\r\nprint(min(acnt, n - acnt) + min(bcnt, n - bcnt))", "n,b,time=int(input()),[],0\r\nl1,l0,r1,r0=0,0,0,0\r\nfor i in range(n):\r\n a= list(map(int, input().split()))\r\n b.append(a)\r\nfor i in range(n):\r\n if b[i][0]==1:l1+=1\r\n else:l0+=1\r\n if b[i][1]==1:r1+=1\r\n else:r0+=1\r\nprint(min(l1,l0)+min(r1,r0))\r\n", "def solve(n):\r\n a, b, c, d = 0, 0, 0, 0\r\n\r\n for _ in range(n):\r\n x, y = map(int, input().split())\r\n if x == 0:\r\n a += 1\r\n else:\r\n b += 1\r\n\r\n if y == 0:\r\n c += 1\r\n else:\r\n d += 1\r\n\r\n count = min(a, b) + min(c, d)\r\n return count\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n print(solve(n))\r\n", "k=int(input())\r\ncntol=0\r\ncntal=0\r\ncntor=0\r\ncntar=0\r\nfor i in range(k):\r\n a=list(map(int, input().strip().split()))\r\n if a[0]==0:\r\n cntol+=1\r\n else:\r\n cntal+=1\r\n if a[1]==0:\r\n cntor+=1\r\n else:\r\n cntar+=1\r\nans=0\r\nif cntor > cntar:\r\n ans+=cntar\r\nelse:\r\n ans+=cntor\r\nif cntol>cntal:\r\n ans+=cntal\r\nelse:\r\n ans+=cntol\r\nprint(ans)", "n=int(input())\r\nk=list(list(map(int,input().split())) for _ in range(n))\r\nk=list(zip(*k))\r\nl=sum(k[0])\r\nr=sum(k[1])\r\nc=0\r\n\r\nif l<=int(n/2):\r\n c+=l\r\nelse:\r\n c+=n-l\r\nif r<=int(n/2):\r\n c+=r\r\nelse:\r\n c+=n-r\r\n\r\nprint(c)", "def cupboards(nums):\r\n l, r = 0,0\r\n for pair in nums:\r\n l += pair[0]\r\n r += pair[1]\r\n return min(l, len(nums) - l) + min(r, len(nums) - r)\r\n\r\narr = []\r\nfor _ in range(int(input())):\r\n a, b = map(int, input().split())\r\n arr.append([a, b])\r\n \r\nprint(cupboards(arr))", "left,right=[],[]\r\nfor _ in range(int(input())):\r\n leftin,rightin=map(int,input().split())\r\n left.append(leftin)\r\n right.append(rightin)\r\nprint(min(left.count(0),left.count(1))+min(right.count(0),right.count(1)))", "num = int(input())\nLsum, Rsum = 0, 0\nfor n in range(0, num):\n line = input().split(' ')\n Lsum += int(line[0])\n Rsum += int(line[1])\n\nprint(min(Lsum, num-Lsum) + min(Rsum,num-Rsum))\n \n \t\t\t\t \t \t \t\t\t\t\t\t\t\t \t\t", "n=int(input())\r\nx=0;y=0\r\nfor _ in range(n):\r\n l,r=map(int,input().split())\r\n x+=l\r\n y+=r\r\nprint(min(x,n-x)+min(y,n-y))", "n=int(input())\r\nleft,right=0,0\r\nfor i in range(n):\r\n l,r= list(map(int,input().split()))\r\n left+=l\r\n right+=r\r\n\r\nprint(min(left,n-left)+min(right,n-right)) ", "n=int(input())\r\nx=[list(j) for j in zip(*[list(map(int,input().split())) for i in range(n)])]\r\nprint(min(x[0].count(0),x[0].count(1))+min(x[1].count(1),x[1].count(0)))", "r=0\r\nl=0\r\nn=int(input())\r\nfor x in range(0,n):\r\n string=input()\r\n string=string.split(' ')\r\n if(string[0]=='0'):\r\n l=l+1\r\n if(string[1]=='0'):\r\n r=r+1\r\nsu=0\r\ns=n-l\r\nif s < l:\r\n su=su+s\r\nelse:\r\n su=su+l\r\ns=n-r\r\nif s < r:\r\n su=su+s\r\nelse:\r\n su=su+r\r\nprint(su)", "count = 0\r\nn_count = 0\r\nni_count = 0\r\nnii_count = 0\r\nfor i in range(int(input())):\r\n a , b =map(int,input().split())\r\n if a==1:\r\n count+=1\r\n if a == 0:\r\n n_count+=1\r\n if b == 0:\r\n ni_count+=1\r\n if b == 1:\r\n nii_count+=1\r\nx=min(count,n_count)\r\nx+=min(ni_count,nii_count)\r\nprint(x)", "n = int(input()) \r\nleft , right = [] , []\r\nfor i in range(n) : \r\n s = list(map(int , input().split())) \r\n left.append(s[0]) \r\n right.append(s[1]) \r\nmi_left = min(left.count(0),left.count(1))\r\nmin_right = min(right.count(0),right.count(1)) \r\nprint(min_right + mi_left)", "n = int(input())\nleft = []\nright = []\nfor i in range(0, n):\n v = list(map(int, input().split()))\n left.append(v[0])\n right.append(v[1])\n\nls = sum(left)\nrs = sum(right)\nt = 0\nt += n - ls if (ls) > (n // 2) else ls\nt += n - rs if (rs) > (n // 2) else rs\nprint(t)\n", "n = int(input())\r\nt = 0\r\nl_c = []\r\nr_c = []\r\n\r\nfor i in range(n):\r\n l, r = input().split()\r\n l_c.append(l)\r\n r_c.append(r)\r\n\r\n\r\nif l_c.count(\"0\") > l_c.count(\"1\"):\r\n t += l_c.count(\"1\")\r\nelse:\r\n t += l_c.count(\"0\")\r\n\r\nif r_c.count(\"0\") > r_c.count(\"1\"):\r\n t += r_c.count(\"1\")\r\nelse:\r\n t += r_c.count(\"0\")\r\n\r\nprint(t)\r\n", "l = []\r\nr = []\r\nfor _ in range(int(input())):\r\n s = input().split()\r\n l.append(int(s[0]))\r\n r.append(int(s[1]))\r\ntotal = 0\r\nif l.count(1) > l.count(0):\r\n total += l.count(0)\r\nelse:\r\n total += l.count(1)\r\nif r.count(1) > r.count(0):\r\n total += r.count(0)\r\nelse:\r\n total += r.count(1)\r\nprint(total)", "n=int(input())\nh=[[int(i) for i in input().split()] for j in range(n)]\nans=0\nl=[]\nr=[]\nfor i in range(n):\n l.append(h[i][0])\n r.append(h[i][1])\nl0=l.count(0)\nl1=l.count(1)\nr0=r.count(0)\nr1=r.count(1)\nif l0>l1:\n ans+=l1\nelse:\n ans+=l0\nif r0>r1:\n ans+=r1\nelse:\n ans+=r0\nprint(ans)\n", "n=int(input())\r\ns=0\r\nh=0\r\nm=0\r\nj=0\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n if a==0:\r\n s+=1\r\n if a==1:\r\n h+=1\r\n if b==0:\r\n m+=1\r\n if b==1:\r\n j+=1\r\nprint(min(s,h)+min(m,j))", "n = int(input())\r\ncupboards = []\r\nfor i in range(n):\r\n cupboards.append(list(map(int, input().split())))\r\nleft_door, right_door = [], []\r\nfor i in range(n):\r\n left_door.append(cupboards[i][0])\r\n right_door.append(cupboards[i][1])\r\nx = left_door.count(0) if left_door.count(0) < left_door.count(1) else left_door.count(1)\r\ny = right_door.count(0) if right_door.count(0) < right_door.count(1) else right_door.count(1)\r\nprint(x+y)", "n = int(input())\r\nLtotal, Rtotal = 0, 0\r\nfor x in range(n):\r\n l, r = map(int, input().split())\r\n Ltotal += l\r\n Rtotal += r\r\nans = 0\r\nif Ltotal > n-Ltotal:\r\n ans += n-Ltotal\r\nelse:\r\n ans += Ltotal\r\nif Rtotal > n-Rtotal:\r\n ans += n-Rtotal\r\nelse:\r\n ans += Rtotal\r\nprint(ans)", "m = int(input())\r\nl = []\r\nr = []\r\nfor i in range(m):\r\n a,b = input().split()\r\n l.append(a)\r\n r.append(b)\r\na = l.count(\"0\")\r\nb = r.count(\"0\")\r\nsum = 0\r\nif a >= m - a:sum+=(m - a)\r\nelse:sum+=(a)\r\nif b >= m - b:sum+=(m - b)\r\nelse:sum+=(b)\r\nprint(sum)", "'''input\n5\n0 1\n1 0\n0 1\n1 1\n0 1\n'''\nn = int(input())\nx, y = [], []\nfor _ in range(n):\n\ta, b = map(int, input().split())\n\tx.append(a)\n\ty.append(b)\nprint(min(x.count(0), x.count(1)) + min(y.count(0), y.count(1)))\n", "n = int(input())\r\nl = []\r\nr = []\r\ntime = 0\r\nfor i in range(n):\r\n a, b = map(int, input().split(\" \"))\r\n l.append(a)\r\n r.append(b)\r\nif l.count(0) >= l.count(1):\r\n time = time + l.count(1)\r\nelse:\r\n time = time + l.count(0)\r\nif r.count(0) >= r.count(1):\r\n time = time + r.count(1)\r\nelse:\r\n time = time + r.count(0)\r\nprint(time)\r\n", "r = []\r\nl = []\r\nfor i in range(int(input())):\r\n b, a = map(int, input().split())\r\n r.append(a)\r\n l.append(b)\r\nc = 0\r\nif (r.count(0)) <= (r.count(1)):\r\n c += (r.count(0))\r\nelse:\r\n c += (r.count(1))\r\nif (l.count(0)) <= (l.count(1)):\r\n c += (l.count(0))\r\nelse:\r\n c += (l.count(1))\r\nprint(c)", "n = int(input())\r\nleft=[]\r\nright=[]\r\nfor _ in range(n):\r\n a,b=map(int,input().split())\r\n left.append(a)\r\n right.append(b)\r\nans = min(right.count(1),right.count(0))+min(left.count(1),left.count(0))\r\nprint(ans)", "n=int(input())\r\nlc=[]\r\nrc=[]\r\nfor i in range(0,n):\r\n ele=input()\r\n s=ele.split()\r\n lc.append(s[0])\r\n rc.append(s[1])\r\nlc1=0\r\nlc0=0\r\nrc1=0\r\nrc0=0\r\nrf=''\r\nlf=''\r\ncount=0\r\nfor i in range(0,n):\r\n if(lc[i]=='0'):\r\n lc0+=1\r\n elif(lc[i]=='1'):\r\n lc1+=1\r\n if(rc[i]=='0'):\r\n rc0+=1\r\n elif(rc[i]=='1'):\r\n rc1+=1\r\nif(lc0>lc1):\r\n lf='0'\r\nelse:\r\n lf='1'\r\nif(rc0>rc1):\r\n rf='0'\r\nelse:\r\n rf='1'\r\nfor i in range(0,n):\r\n if(lc[i]!=lf):\r\n count+=1\r\n if(rc[i]!=rf):\r\n count+=1\r\nprint(count)", "n = int(input())\r\ninps = []\r\nfor _ in range(0, n):\r\n inps.append(list(map(int, input().strip().split())))\r\n\r\nl0s = 0\r\nl1s = 0\r\n\r\nr0s = 0\r\nr1s = 0\r\n\r\ntime = 0\r\nminiL = 0\r\nminiR = 0\r\n\r\nfor i in range(0, n):\r\n if inps[i][0] == 1:\r\n l1s += 1\r\n else:\r\n l0s += 1\r\n if inps[i][1] == 1:\r\n r1s += 1\r\n else:\r\n r0s += 1\r\n\r\nif l0s <= l1s:\r\n miniL = l0s\r\nelse:\r\n miniL = l1s\r\nif r0s <= r1s:\r\n miniR = r0s\r\nelse:\r\n miniR = r1s\r\n\r\nif (r1s == 0 and l1s == 0) or (r0s == 0 and l0s == 0):\r\n print(time)\r\n exit()\r\nif l0s == 0 or l1s == 0:\r\n time = miniR\r\n print(time)\r\n exit()\r\nelif r0s == 0 or r1s == 0:\r\n time = miniL\r\n print(time)\r\n exit()\r\nelse:\r\n time = miniL+miniR\r\nprint(time)\r\n", "c=[]\r\nd=[]\r\nfor i in range(int(input())):\r\n a,b=[int(i) for i in input().split()]\r\n c.append(a)\r\n d.append(b)\r\nif(c.count(0)>c.count(1)):\r\n p=c.count(1)\r\nelse:\r\n p=c.count(0)\r\nif(d.count(0)>d.count(1)):\r\n q=d.count(1)\r\nelse:\r\n q=d.count(0)\r\nprint(p+q) ", "def sol(arr,n):\n l,r = [],[]\n for i in range(n):\n l.append(arr[i][0])\n r.append(arr[i][1])\n \n res = min(n-sum(l),sum(l)) + min(n - sum(r),sum(r))\n return res\n \nn = int(input())\narr = []\nfor i in range(n):\n x = [int(x) for x in input().split()]\n arr.append(x)\n \nans = sol(arr,n)\nprint(ans)", "import sys\nn=input()\nn=int(n)\nrli=[]\nlli=[]\nfor i in range(n):\n line = [int(x) for x in sys.stdin.readline().split() ]\n rli.append(line[1])\n lli.append(line[0])\nloff=lli.count(0)\nlon=lli.count(1)\nroff=rli.count(0)\nron=rli.count(1)\nif loff<=lon:\n a=loff\nelse:\n a=lon\nif roff<=ron:\n b=roff\nelse:\n b=ron\nprint(a+b)\n\t\t\t\t \t \t\t \t \t \t \t\t \t\t \t", "n = int(input())\r\nsum_l = 0\r\nsum_r = 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n sum_l += l\r\n sum_r += r\r\na = n - sum_l\r\nb = n - sum_r\r\nanswer = min(a, sum_l) + min(b, sum_r)\r\nprint(answer)", "\r\n\r\n\r\nn= int(input())\r\n\r\na=[0,0]\r\nb=[0,0]\r\n\r\nfor i in range(n):\r\n x,y = map(int,input().split())\r\n\r\n a[x]+=1\r\n b[y]+=1\r\n\r\nprint(min(a)+min(b))\r\n", "if __name__ == '__main__':\r\n n = int(input())\r\n aa = [[0, 0], [0, 0]]\r\n for _ in range(n):\r\n for idx, val in enumerate(map(int, input().split())):\r\n aa[idx][val] += 1\r\n print(min(aa[0]) + min(aa[1]))\r\n", "n = int(input())\r\nl, r = 0, 0\r\nfor i in range(n):\r\n a, b = input().split()\r\n if a == '0':\r\n l += 1\r\n if b == '0':\r\n r += 1\r\n\r\nprint(min(l, n-l) + min(r, n-r))\r\n", "n=int(input())\r\na=[]\r\nb=[]\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n a.append(x)\r\n b.append(y)\r\nprint(min(n-sum(a),sum(a))+min(n-sum(b),sum(b)))", "a = int(input())\r\nb0 = 0\r\nb1 = 0\r\nc0 = 0\r\nc1 = 0\r\nfor i in range(a):\r\n b, c = map(int, input().split())\r\n if b == 0:\r\n b0 += 1\r\n else:\r\n b1 += 1\r\n if c == 0:\r\n c0 += 1\r\n else:\r\n c1 += 1\r\nprint(min(b0, b1) + min(c0, c1))\r\n", "n=int(input())\r\nl=[]\r\nr=[]\r\ncount=0\r\nfor i in range(0,n):\r\n a =input().split(' ')\r\n l.append(a[0])\r\n r.append(a[1])\r\n\r\nif (r.count(\"1\")>=r.count(\"0\")):\r\n count+=(r.count(\"0\"))\r\nelse:\r\n count+=(r.count(\"1\"))\r\n\r\n\r\nif (l.count(\"1\")>=l.count(\"0\")):\r\n count+= (l.count(\"0\"))\r\nelse:\r\n count+=(l.count(\"1\"))\r\n\r\n\r\nprint(count)", "from _ast import While\r\nfrom math import inf\r\nfrom collections import *\r\nimport math, os, sys, heapq, bisect, random, threading\r\nfrom functools import lru_cache, reduce\r\nfrom itertools import *\r\n\r\n\r\ndef inp(): return sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\r\ndef out(var): sys.stdout.write(str(var))\r\n\r\n\r\n'''''''''\r\nBELIEVE\r\n'''''''''\r\nl0 = 0\r\nr1 = 0\r\nl1 = 0\r\nr0 = 0\r\nlis = []\r\nn = int(input())\r\nans = 0\r\nfor _ in range(n):\r\n i, r = map(int, input().split())\r\n if i == 0:\r\n l0 += 1\r\n if r == 1:\r\n r1 += 1\r\n if i == 1:\r\n l1 += 1\r\n if r == 0:\r\n r0 += 1\r\nlis.append(r0)\r\nlis.append(l0)\r\nlis.append(r1)\r\nlis.append(l1)\r\nlis.sort()\r\nmx1 = lis[-1]\r\nmx0 = lis[-2]\r\nif mx1 and mx0 != 0:\r\n print((n - mx1) + (n - mx0))\r\nelse:\r\n print(0)\r\n", "n = int(input())\r\nl1,l2,r1,r2,m =0,0,0,0,0\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n if l == 1:\r\n l1+=1\r\n if r == 1:\r\n r1+=1\r\nr0 = n - r1\r\nl0 = n - l1\r\nif r0 >= r1 :\r\n m+=r1\r\nelse:\r\n m+=r0\r\nif l0 >= l1 :\r\n m+=l1\r\nelse:\r\n m+=l0\r\n\r\nprint(m)\r\n", "num_cupboards = int(input())\r\ntotal_left = 0\r\ntotal_right = 0\r\nfor _ in range(num_cupboards):\r\n left, right = map(int, input().split())\r\n total_left += left\r\n total_right += right\r\nmin_left = min(total_left, num_cupboards - total_left)\r\nmin_right = min(total_right, num_cupboards - total_right)\r\nprint(min_left + min_right)\r\n", "n = int(input())\r\narray = list()\r\ncount1 = 0\r\ncount2 =0\r\nres = 0\r\nfor i in range(n):\r\n c = [int(x) for x in input().split()]\r\n array.append(c)\r\n \r\nfor i in range(n):\r\n if array[i][0]==0:\r\n count1+=1\r\n if array[i][1]==0:\r\n count2+=1\r\n\r\nmid = n/2\r\n\r\nif count1 <= mid:\r\n res+=count1\r\nelse:\r\n res+=(n-count1)\r\n \r\nif count2 <= mid:\r\n res+=count2\r\nelse:\r\n res+=(n-count2)\r\n \r\nprint(res)\r\n\r\n \r\n \r\n", "n=int(input())\r\ndoor=[]\r\nr0,l0,t=0,0,0\r\nfor i in range(n):\r\n door.append(list(map(int,input().split())));\r\nfor x in door:\r\n if x[0]==0:\r\n l0+=1;\r\n if x[1]==0:\r\n r0+=1;\r\nif l0>(n-l0):\r\n t+=(n-l0);\r\nelse:\r\n t+=l0\r\nif r0>(n-r0):\r\n t+=n-r0\r\nelse:\r\n t+=r0\r\nprint(t)\r\n", "a=int(input())\r\ncnt=0\r\nvnt=0\r\nfor i in range(a):\r\n b, c=map(int, input().split())\r\n cnt+=b\r\n vnt+=c\r\n x=min(a-cnt, cnt)\r\n x+=min(a-vnt, vnt)\r\n \r\nprint(x)", "n = int(input())\r\n\r\ncount = 0\r\nopened = [0, 0]\r\nfor i in range(n):\r\n for j, el in enumerate(input().split(' ')):\r\n if el == '1': opened[j] += 1\r\n\r\nfor side in opened:\r\n count += min(side, n - side)\r\n\r\nprint(count)", "n = int(input())\r\nleft = 0\r\nright = 0\r\nfor i in range(n):\r\n open_left, open_right = map(int, input().split(' '))\r\n left += open_left\r\n right += open_right\r\nprint(min(left, n - left) + min(right, n - right))", "\r\nn=int(input())\r\nleft=0\r\nright=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n left+=l\r\n right+=r\r\nprint(min(left,n-left)+ min(right,n-right))\r\n\r\n", "\r\nn = int(input())\r\nxi, yi = [], []\r\nfor _ in range(n):\r\n x, y = map(int, input().split())\r\n xi.append(x)\r\n yi.append(y)\r\n\r\na = xi.count(1)\r\nb = xi.count(0)\r\nc = yi.count(1)\r\nd = yi.count(0)\r\nprint(min(a,b)+min(c,d))\r\n", "no_of_cupboards=int(input())\r\nleft=[]\r\nright=[]\r\ntime=0\r\nfor i in range(no_of_cupboards):\r\n info=input().split()\r\n left.append(int(info[0]))\r\n right.append(int(info[1]))\r\n# cardinality of 0s and 1s in left\r\nno_of_zeroes=0\r\nno_of_ones=0\r\nfor i in range(len(left)):\r\n if left[i]==0:\r\n no_of_zeroes+=1\r\n if left[i]==1:\r\n no_of_ones+=1\r\n\r\ntime=time+min(no_of_ones,no_of_zeroes)\r\n# cardinality of 0s and 1s in right\r\nno_of_zeroes=0\r\nno_of_ones=0\r\nfor i in range(len(right)):\r\n if right[i]==0:\r\n no_of_zeroes+=1\r\n if right[i]==1:\r\n no_of_ones+=1\r\ntime=time+min(no_of_ones,no_of_zeroes)\r\nprint(time)\r\n", "n = int(input())\r\ndoors = []\r\nleft, right = 0, 0\r\nfor i in range(n):\r\n a, b = (int(d) for d in input().split())\r\n left += a\r\n right += b\r\n \r\nprint(min(left, n-left) + min(right, n-right))", "l0=0\r\nl1=0\r\nr0=0\r\nr1=0\r\narr=[]\r\nn=int(input())\r\nfor _ in range(n):\r\n a,b=map(int,input().split())\r\n if a==0:\r\n l0+=1\r\n if a==1:\r\n l1+=1\r\n if b==0:\r\n r0+=1\r\n if b==1:\r\n r1+=1\r\n arr.append((a,b))\r\nnum=()\r\nif l1>l0:\r\n if r1>r0:\r\n num=(1,1)\r\n else:\r\n num=(1,0)\r\nelse:\r\n if r1>r0:\r\n num=(0,1)\r\n else:\r\n num=(0,0)\r\nc=0\r\nfor val in arr:\r\n if val[0]!=num[0]:\r\n c+=1\r\n if val[1]!=num[1]:\r\n c+=1\r\nprint(c)", "import collections\r\nn=int(input())\r\na=[]\r\nb=[]\r\nc=0\r\nfor i in range(0,n):\r\n l,r=input().split()\r\n l,r=[int(l),int(r)]\r\n a.append(l)\r\n b.append(r)\r\na1=collections.Counter(a)\r\nb1=collections.Counter(b)\r\nif a1[0]>a1[1]:\r\n c+=a1[1]\r\nelse:\r\n c+=a1[0]\r\nif b1[0]>b1[1]:\r\n c+=b1[1]\r\nelse:\r\n c+=b1[0]\r\nprint(c)", "cnt_10=0\r\ncnt_01=0\r\ncnt_11=0\r\ncnt_00=0\r\nfor _ in range( int(input())):\r\n l,r=map(int,input().split())\r\n if l==0 and r==0:\r\n cnt_10+=1\r\n cnt_01+=1\r\n cnt_11+=2\r\n elif l==0 and r==1:\r\n cnt_10+=2\r\n cnt_11+=1\r\n cnt_00+=1\r\n elif l==1 and r==0:\r\n cnt_01+=2\r\n cnt_11+=1\r\n cnt_00+=1\r\n elif l==1 and r==1:\r\n cnt_10+=1\r\n cnt_01+=1\r\n cnt_00+=2\r\n\r\nprint(min(cnt_01,cnt_10,cnt_00,cnt_11))\r\n", "n = int(input())\r\nleft = []\r\nright = []\r\nmin = 0\r\nfor t in range(n):\r\n l,r = map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\ncount1 = left.count(1)\r\ncount2 = left.count(0)\r\nif count1 >= count2:\r\n for i in range(len(left)):\r\n if left[i] != 1:\r\n min += 1\r\nelif count2 > count1:\r\n for i in range(len(left)):\r\n if left[i] != 0:\r\n min += 1\r\ncount3 = right.count(1)\r\ncount4 = right.count(0)\r\nif count3 >= count4:\r\n for i in range(len(right)):\r\n if right[i] != 1:\r\n min += 1\r\nelif count4 > count3:\r\n for i in range(len(right)):\r\n if right[i] != 0:\r\n min += 1\r\nprint(min)\r\n\r\n\r\n", "leftone,rightone,leftzero,rightzero=0,0,0,0\r\nfor _ in range(int(input())):\r\n a,b=map(int,input().split())\r\n if a==0: leftzero +=1\r\n elif a==1: leftone +=1\r\n if b==0: rightzero +=1\r\n elif b==1: rightone +=1\r\nprint(min(leftzero,leftone)+min(rightzero,rightone))\r\n", "leftsum=0\r\nrightsum=0\r\nout=0\r\nn=int(input())\r\nfor _ in range(n):\r\n l,r=map(int,input().split())\r\n leftsum+=l\r\n rightsum+=r\r\nif leftsum<n/2:\r\n out+=leftsum\r\nelse:\r\n out+=(n-leftsum)\r\nif rightsum<n/2:\r\n out+=rightsum\r\nelse:\r\n out+=(n-rightsum)\r\nprint(out)", "a1,b1=0,0;n=int(input())\r\nfor _ in range(n):\r\n\ta,b=map(int,input().split())\r\n\tif a==1:a1+=1\r\n\tif b==1:b1+=1\r\na0,b0=n-a1,n-b1;x,y=max(a1,a0),max(b1,b0)\r\nprint(2*n-x-y)", "from sys import stdin\r\n\r\nn = int(stdin.readline())\r\ncount = [0, 0]\r\nfor _ in range(n):\r\n a, b = list(map(int, stdin.readline().split()))\r\n if a == 0:\r\n count[0] += 1\r\n if b == 0:\r\n count[1] += 1\r\nprint(min(n-count[0], count[0]) + min(n-count[1], count[1]))\r\n", "n=int(input())\r\np=[]\r\nl=[]\r\nc=0\r\nfor x in range(n):\r\n pa,k=list(map(int,input().split()))\r\n p.append(pa)\r\n l.append(k)\r\nif p.count(0)>p.count(1):\r\n c+=p.count(1)\r\nelse:\r\n c+=p.count(0)\r\nif l.count(0)>l.count(1):\r\n c+=l.count(1)\r\nelse:\r\n c+=l.count(0)\r\nprint(c)", "n=int(input())\r\nliste=[]\r\nfor i in range(n):\r\n liste.append(input().split())\r\ntoplaml=0\r\ntoplamr=0\r\nfor i in range(n):\r\n toplaml+=int(liste[i][0])\r\n toplamr+=int(liste[i][1])\r\na=0;b=0\r\nif(toplamr>(n/2)):\r\n a=(n-toplamr)\r\nelse:\r\n a=toplamr\r\n\r\nif (toplaml > (n / 2)):\r\n b = (n - toplaml)\r\nelse:\r\n b = toplaml\r\nprint(a+b)\r\n", "n= int(input())\r\nA=[0]*n\r\nB=[0]*n\r\nfor i in range(n):\r\n A[i],B[i]=map(int,input().split())\r\nX=sum(A)\r\nY=sum(B)\r\nprint(min(X,n-X)+min(Y,n-Y))", "n = int(input())\r\nc,f = 0,0\r\nfor i in range(n):\r\n\tl,r = map(int,input().split())\r\n\tif l : c+=1\t\r\n\tif r : f+=1\t\r\nprint(min(c,n-c)+min(f,n-f))", "n = int(input())\nleftOne= 0\nrightOne=0\nfor _ in range(n):\n x,y = map(int,input().split())\n if x==1:\n leftOne+=1\n if y==1:\n rightOne+=1\nans = 0\nif leftOne<n-leftOne:\n ans+= leftOne\nelse:\n ans+= n-leftOne\nif rightOne<n-rightOne:\n ans+=rightOne\nelse:\n ans+=n-rightOne\nprint(ans)\n", "n = int(input())\nleftd = {0: 0, 1: 0}\nrightd = {0: 0, 1: 0}\nfor i in range(n):\n a, b = map(int, input().split())\n leftd[a] += 1\n rightd[b] += 1\nminl = 0\nminr = 0\nif (leftd[0] < leftd[1]):\n minl = leftd[0]\nelse:\n minl = leftd[1]\nif (rightd[0] < rightd[1]):\n minr = rightd[0]\nelse:\n minr = rightd[1]\nprint(minl + minr)\n", "n = int(input())\na = 0\nb = 0\nfor i in range(n):\n c, d = map(int, input().split())\n a += c\n b += d\n\ne = 0\nif a<=n//2:\n e += a\nelse :\n e += n-a\nif b<=n//2:\n e += b\nelse :\n e += n-b\nprint(e)\n", "n = int(input())\r\na = []\r\nb = []\r\nfor i in range(n):\r\n l,r = map(int,input().split())\r\n a.append(l)\r\n b.append(r)\r\n \r\nx = a.count(0)\r\ny = b.count(0)\r\nc = min(x,(n-x))+min(y,(n-y))\r\nprint(c)", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n x,y=[int(i) for i in input().split()]\r\n left.append(x)\r\n right.append(y)\r\nprint(min(left.count(0),left.count(1))+min(right.count(0),right.count(1)))", "from collections import defaultdict\r\nleft = defaultdict(int)\r\nright = defaultdict(int)\r\nn = int(input())\r\nfor _ in range(n):\r\n l,r = map(int,input().split())\r\n left[l] += 1\r\n right[r] += 1\r\nprint(n-max(left.values())+n-max(right.values()))\r\n", "n=int(input())\r\nD=[]\r\nctL=0\r\nctR=0\r\nfor i in range(n):\r\n d=list(map(int,input().split(\" \")))\r\n if(d[0]==0):\r\n ctL+=1\r\n if(d[1]==0):\r\n ctR+=1\r\n D.append(d)\r\nprint(min(ctL,n-ctL)+min(ctR,n-ctR))\r\n ", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\nn=int(input())\r\nd=[]\r\nl,p,t=0,0,0,\r\nfor i in range(n):\r\n d.append(list(map(int,input().split())))\r\n if d[i][0]==1:\r\n l+=1\r\n if d[i][1]==1:\r\n p+=1\r\nif l<n-l:\r\n t+=l\r\nelse:\r\n t+=n-l\r\nif p<n-p:\r\n t+=p\r\nelse:\r\n t+=n-p\r\nprint(t)", "n = int(input())\r\nr1,r0,l1,l0,total = 0,0,0,0,0\r\nfor i in range(n):\r\n r,l = map(int, input() .split()) \r\n if r == 1 :\r\n r1+=1\r\n else:\r\n r0+=1\r\n if l == 1:\r\n l1+=1\r\n else:\r\n l0+=1\r\nif r1 > r0:\r\n total = r0\r\nelse:\r\n total = r1\r\nif l1> l0:\r\n total = total + l0\r\nelse:\r\n total = total + l1 \r\nprint(total) ", "from collections import Counter\r\nn = int(input())\r\nl = []\r\nL = []\r\nfor i in range(n):\r\n x,y = input().split()\r\n l.append(int(x))\r\n L.append(int(y))\r\nz = Counter(l)\r\nm = Counter(L)\r\nc = 0\r\nif z[0]<=z[1]:\r\n c = c+z[0]\r\nelse:\r\n c = c+z[1]\r\nif m[0]<=m[1]:\r\n c = c+m[0]\r\nelse:\r\n c = c+m[1]\r\nprint(c)\r\n \r\n ", "n = int(input())\nc = []; d = []\nfor I in range (n):\n a, b = map(int, input ().split ())\n c.append(a)\n d.append(b)\nprint(min(c.count(1), c.count(0)) + min (d.count(1), d.count(0)))", "n = int(input())\r\narr = []\r\ncount = 0\r\nfor i in range(n):\r\n arr.append(list(map(int, input().split())))\r\narr = list(zip(*arr))\r\nfor j in range(2):\r\n if sum(arr[j]) > n//2:\r\n count += n-sum(arr[j])\r\n else:\r\n count += sum(arr[j])\r\nprint(count)\r\n", "n = int(input())\r\n\r\na, b = 0, 0\r\n\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n a += l\r\n b += r\r\n\r\nt = min(a, n-a) + min(b, n-b)\r\nprint(t)", "n = int(input())\r\nleft = right = 0\r\n\r\nfor i in range(n):\r\n\tline = input()\r\n\tx = list(map(int, line.split()))\r\n\tif x[0] == 1:\r\n\t\tleft += 1\r\n\tif x[1] == 1:\r\n\t\tright += 1\r\n\r\na = n-left\r\nb = left\r\nc = n - right\r\nd = right\r\n\r\nprint(min(a,b) + min(c,d))", "n = int(input())\r\nm = [[int(el) for el in input().split()] for i in range(n)]\r\nx = [[i[j] for i in m] for j in range(2)]\r\nprint(min(sum(x[0]), n - sum(x[0])) + min(sum(x[1]), n - sum(x[1])))", "n = int(input())\n\nL = []\nR = []\nfor i in range(n):\n l,r = tuple(map(int, input().split(' ')))\n L.append(l)\n R.append(r)\n\ndef calc(doors):\n closed_doors = doors.count(0)\n open_doors = doors.count(1)\n return min(closed_doors, open_doors)\n\nprint(calc(L) + calc(R))\n", "t = int(input())\r\n\r\nl = 0\r\nr = 0\r\nfor _ in range(t):\r\n a = [int(x) for x in input().split()]\r\n l += a[0]\r\n r += a[1]\r\nprint(min(t-l, l) + min(t-r,r))", "import sys\r\nfrom collections import Counter, defaultdict, deque\r\nfrom heapq import heapify, heappush, heappop\r\nfrom functools import lru_cache\r\nfrom math import floor, ceil, sqrt, gcd\r\nfrom string import ascii_lowercase\r\nfrom math import gcd\r\nfrom bisect import bisect_left, bisect, bisect_right\r\n\r\n\r\ndef read():\r\n return input().strip()\r\n\r\n\r\ndef read_int():\r\n return int(read())\r\n\r\n\r\ndef read_str_list():\r\n return read().split()\r\n\r\n\r\ndef read_numeric_list():\r\n return list(map(int, read_str_list()))\r\n\r\n\r\ndef solve():\r\n pass\r\n\r\n\r\nN = read_int()\r\ncounts_left = Counter()\r\ncounts_right = Counter()\r\n\r\ncounts_left[0] = 0\r\ncounts_left[1] = 0\r\n\r\ncounts_right[0] = 0\r\ncounts_right[1] = 0\r\n\r\nfor _ in range(N):\r\n L, R = read_numeric_list()\r\n counts_left[L] += 1\r\n counts_right[R] += 1\r\n\r\n\r\nprint(min(counts_left[0], counts_left[1]) +\r\n min(counts_right[0], counts_right[1]))\r\n", "lz = 0\r\nlo = 0\r\nrz = 0\r\nro = 0\r\nfor i in range(int(input())):\r\n l,r = list(map(int,input().split()))\r\n if l==0:\r\n lz+=1\r\n else:\r\n lo+=1\r\n if r==0:\r\n rz += 1\r\n else:\r\n ro += 1\r\n\r\nprint(min(lz,lo)+min(ro,rz))\r\n", "n = int(input())\ncupboards_list = []\nfor i in range(n):\n temp = list(map(int, input().split()))\n cupboards_list.append(temp)\n\nleft_open = 0\nleft_closed = 0\nright_open = 0\nright_closed = 0\ntotal_seconds = 0\nfor cupboard in cupboards_list:\n if cupboard[0] == 0:\n left_closed += 1\n if cupboard[0] == 1:\n left_open += 1\n if cupboard[1] == 0:\n right_closed += 1\n if cupboard[1] == 1:\n right_open += 1\n\nif left_open >= left_closed:\n total_seconds += left_closed\nelse:\n total_seconds += left_open\nif right_open >= right_closed:\n total_seconds += right_closed\nelse:\n total_seconds += right_open\n\nprint(total_seconds)\n", "n=int(input())\r\nr,l=0,0\r\nfor i in range(n):\r\n x=input().split()\r\n r=r+int(x[0])\r\n l=l+int(x[1])\r\nprint(min(r,n-r)+min(l,n-l))", "import sys\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\ndef iinput(): return int(input())\r\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \r\n\r\n\r\nn=iinput()\r\ncol1 = []\r\ncol2 = []\r\nfor i in range (n):\r\n temp = get_list()\r\n col1.append(temp[0])\r\n col2.append(temp[1])\r\n#print(a)\r\n\r\nz1 = col1.count(0)\r\no1 = col1.count(1)\r\n\r\nz2 = col2.count(0)\r\no2 = col2.count(1)\r\n\r\ncount=0\r\n\r\nif (z1>=o1):\r\n count += o1\r\nelse:\r\n count += z1\r\n\r\nif (z2>=o2):\r\n count += o2\r\nelse:\r\n count += z2 \r\n\r\nprint(count)", "n = int(input())\r\narr = []\r\nl,r =0,0\r\nfor i in range(n):\r\n v = list(map(int,input().split()))\r\n arr.append(v)\r\nfor i in range(n):\r\n if arr[i][0] == 1:\r\n l += 1\r\n if arr[i][1] == 1:\r\n r += 1\r\nprint(min(l,n-l)+min(r,n-r))\r\n", "n=int(input())\r\nL=0\r\nR=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n L+=l\r\n R+=r\r\nprint(min(L,n-L)+min(R,n-R))", "n = int(input())\r\none = []\r\ntwo = []\r\nfor i in range(n):\r\n x, y = map(int, input().split(\" \"))\r\n one.append(x)\r\n two.append(y)\r\nif one.count(0) > one.count(1):\r\n c_1 = one.count(1)\r\nelse:\r\n c_1 = one.count(0)\r\nif two.count(0) > two.count(1):\r\n c_2 = two.count(1)\r\nelse:\r\n c_2 = two.count(0)\r\nprint(c_1 + c_2)\r\n", "l=[]\r\nr=[]\r\nfor i in range(int(input())):\r\n f=[int(i) for i in input().split()]\r\n l.append(f[0])\r\n r.append(f[1])\r\ncl_1=l.count(1)\r\ncl_0=l.count(0)\r\ncr_1=r.count(1)\r\ncr_0=r.count(0)\r\nif cl_1<cl_0:\r\n c=cl_1\r\nelse:\r\n c=cl_0\r\nif cr_1<cr_0:\r\n c+=cr_1\r\nelse:\r\n c+=cr_0\r\nprint(c)\r\n", "# cases = int(input())\ncases = 1\n\n\n\ndef solve():\n\tn = int(input())\n\tones_in_left = 0\n\tones_in_right = 0\n\tfor i in range(n):\n\t\tleft, right = map(int, input().split())\n\t\tif left == 1:\n\t\t\tones_in_left += 1\n\n\t\tif right == 1:\n\t\t\tones_in_right += 1\n\n\tans = min(ones_in_left, n - ones_in_left) + min(ones_in_right, n - ones_in_right)\n\treturn ans\n\n\nfor case in range(1, cases+1):\n\tans = solve()\n\tprint(ans)\n\t# print(f\"Case #{case}: {ans}\")", "l = []\r\nr = []\r\nfor _ in range(int(input())):\r\n x, y = map(int, input().split())\r\n l.append(x)\r\n r.append(y)\r\nprint(min(l.count(1), l.count(0)) + min(r.count(1), r.count(0)))", "#ashu@gate22\r\nn=int(input())\r\nx=y=0\r\nfor i in range(n):\r\n l1=[int(i) for i in input().split()]\r\n x+=l1[0]\r\n y+=l1[1]\r\nres=min(x,(n-x))+min(y,(n-y))\r\nprint(res)\r\n\r\n", "t = int(input())\r\nfrom sys import stdin, stdout\r\ncount_l_o = 0\r\ncount_l_c = 0\r\ncount_r_o = 0\r\ncount_r_c = 0\r\nfor i in range(t):\r\n map1 = map(int, stdin.readline().rstrip().split())\r\n arr = list(map1)\r\n if arr[0]== 1:\r\n count_l_o += 1\r\n else:\r\n count_l_c += 1\r\n if arr[1]== 1:\r\n count_r_o += 1\r\n else:\r\n count_r_c += 1\r\nfinl = [count_l_o ,count_l_c]\r\nfinr = [count_r_o ,count_r_c]\r\n#idxl = finl.index(max(finl))\r\n#idxr = finr.index(max(finr))\r\n#print(finl , finr)\r\nprint( 2*t - max(finl) - max(finr))\r\n'''\r\nif idx == 0: ###Left open\r\n print(fin[1] + fin[2])\r\nelif idx == 1: ###Left closed\r\n print(fin[0] + fin[3])\r\nelif idx == 2: ###Right Open\r\n print(fin[3] + fin[0])\r\nelif idx == 3: ###Right closed\r\n print(fin[1] + fin[2])'''", "I = lambda: int(input())\r\nIL = lambda: list(map(int, input().split()))\r\n\r\nn = I()\r\nD = [tuple(IL()) for i in range(n)]\r\nans = 10**10\r\nfor d0 in set(D):\r\n ans = min(ans, sum([(d[0] != d0[0]) + (d[1] != d0[1]) for d in D]))\r\nprint(ans)", "n=int(input())\r\ns=[]\r\nt=[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n s.append(a)\r\n t.append(b)\r\nl=0\r\nfor i in range(n):\r\n if (s[i]==1):\r\n l+=1\r\nk=0\r\nfor i in range(n):\r\n if (t[i]==1):\r\n k+=1\r\nif n%2==0:\r\n if k>n/2:\r\n k=n-k\r\n if l>n/2:\r\n l=n-l\r\nelse:\r\n if k>=n/2:\r\n k=n-k\r\n if l>=n/2:\r\n l=n-l\r\nprint(k+l) \r\n ", "n = int(input())\r\nx, y = 0, 0\r\nfor i in range(n):\r\n a, b = map(int, input().split())\r\n if a == 1:\r\n x += 1\r\n if b == 1:\r\n y += 1\r\nt1 = min(x, n - x)\r\nt2 = min(y, n - y)\r\nprint(t1 + t2)", "n=int(input())\r\nlz=0\r\nrz=0\r\nfor _ in range(n):\r\n l,r=map(int,input().split())\r\n if l == 0:\r\n lz+=1\r\n if r == 0:\r\n rz+=1\r\nprint(min(lz,n-lz)+min(rz,n-rz))\r\n", "def main():\n n = int(input())\n left1 = 0\n right1 = 0\n\n for _ in range(n):\n [l, r] = input().split()\n left1 += 1 if l == '1' else 0\n right1 += 1 if r == '1' else 0\n\n left1 = min(left1, n - left1)\n right1 = min(right1, n - right1)\n\n print(left1 + right1)\n\n\nif __name__ == '__main__':\n main()\n", "n,left,right=int(input()),[],[]\r\nfor i in range(n):\r\n a,b=map(int,input().split())\r\n left.append(a)\r\n right.append(b)\r\nres=left.count(0) if left.count(0)<left.count(1) else left.count(1) \r\nres+=right.count(0) if right.count(0)<right.count(1) else right.count(1) \r\nprint(res)", "a = int(input())\r\nq = 0\r\ns = 0\r\nw = 0\r\nd = 0\r\nfor i in range(a):\r\n e, f = map(int, input().split(' '))\r\n if e == 1:\r\n q += 1\r\n else:\r\n s += 1\r\n if f == 1:\r\n w += 1\r\n else:\r\n d += 1\r\nprint(min(q, s) + min(w, d))\r\n", "t=int(input())\r\nb1=0\r\nb2=0\r\nz=0\r\nz1=0\r\nwhile(t>0):\r\n a,b=map(int,input().split())\r\n if(a==0):\r\n z+=1\r\n else:\r\n z1+=1\r\n if(b==0):\r\n b1+=1\r\n else:\r\n b2+=1\r\n t-=1\r\nprint(min(z,z1)+min(b1,b2))\r\n \r\n", "n=int(input())\r\nl,r=0,0\r\nans=0\r\nfor i in range(n):\r\n a,b=input().split()\r\n l+=int(a)\r\n r+=int(b)\r\nif l > n//2:\r\n ans+=(n-l)\r\nelse:\r\n ans+=l\r\nif r > n//2:\r\n ans+=(n-r)\r\nelse:\r\n ans+=r\r\nprint(ans)\r\n", "x = int(input())\r\nleft = []\r\nright = []\r\nans = 0\r\nfor i in range(x):\r\n\tA = list(map(int,input().split()))\r\n\tleft.append(A[0])\r\n\tright.append(A[1])\r\nans += x - max(left.count(0),left.count(1))\r\nans += x - max(right.count(0),right.count(1))\r\n\r\nprint(ans)\r\n\r\n\r\n\t\r\n\r\n", "def reqtime(window):\r\n count1 = window.count(1)\r\n count0 = window.count(0)\r\n if count1>count0:\r\n return count0\r\n else:\r\n return count1\r\n\r\nn = int(input())\r\nleftwindow = []\r\nrightwindow = []\r\nfor _ in range(n):\r\n left,right = input().split()\r\n leftwindow.append(int(left))\r\n rightwindow.append(int(right))\r\ntotaltime = reqtime(leftwindow) + reqtime(rightwindow)\r\nprint(totaltime)\r\n\r\n\r\n", "# one means opened, zero means closed\nleftPositions = []\nrightPositions = []\nnumCupboards = int(input())\nfor i in range(numCupboards):\n leftRight = input()\n listLeftRight = leftRight.split()\n leftPositions.append(int(listLeftRight[0]))\n rightPositions.append(int(listLeftRight[1]))\n \nminSeconds = 0\nif leftPositions.count(0) > leftPositions.count(1):\n for j in range(numCupboards):\n if leftPositions[j] == 1:\n minSeconds += 1\nelif leftPositions.count(0) < leftPositions.count(1):\n for k in range(numCupboards):\n if leftPositions[k] == 0:\n minSeconds += 1\nelif leftPositions.count(0) == leftPositions.count(1):\n minSeconds += int(numCupboards / 2)\n \nif rightPositions.count(0) > rightPositions.count(1):\n for j in range(numCupboards):\n if rightPositions[j] == 1:\n minSeconds += 1\nelif rightPositions.count(0) < rightPositions.count(1):\n for k in range(numCupboards):\n if rightPositions[k] == 0:\n minSeconds += 1\nelif rightPositions.count(0) == rightPositions.count(1):\n minSeconds += int(numCupboards / 2)\n \nprint(minSeconds)", "n=int(input())\r\na,b=[],[]\r\nfor i in range(n):\r\n\tl,r=map(int,input().split())\r\n\ta.append(l)\r\n\tb.append(r)\r\n# print(a,b)\r\nx=a.count(0)\r\ny=a.count(1)\r\nc=b.count(0)\r\nd=b.count(1)\r\nprint(min(x,y)+min(c,d))", "n=int(input())\r\nl=[0]*n\r\nl2=[0]*n\r\nfor i in range (n):\r\n l[i],l2[i]=map(int,input().split())\r\nprint(min(l.count(0),l.count(1))+min(l2.count(0),l2.count(1)))", "l={0:0,1:0}\r\nr={0:0,1:0}\r\n\r\nn=int(input())\r\n\r\nfor i in range(n):\r\n a,b=list(map(int,input().rstrip().split()))\r\n l[a]+=1\r\n r[b]+=1\r\n\r\nprint(n-max(l[0],l[1]) + n-max(r[0],r[1]))", "import sys\r\nimport collections\r\nimport math\r\nimport itertools as it\r\n\r\ndef readArray(type= int):\r\n line = input()\r\n return [type(x) for x in line.split()]\r\n\r\ndef solve():\r\n n = int(input())\r\n\r\n loc = 0\r\n roc = 0\r\n\r\n t = 0\r\n\r\n for x in range(n):\r\n l, r = readArray()\r\n\r\n loc += l\r\n roc += r\r\n\r\n t += n-loc if loc > n - loc else loc\r\n t += n-roc if roc > n - roc else roc\r\n\r\n print(t)\r\n\r\nif __name__ == '__main__':\r\n # sys.stdin = open('input.txt')\r\n solve()\r\n\r\n", "t=int(input())\r\nlist=[]\r\nzero1=0; zero2=0; one1=0; one2=0; ans=0\r\nfor i in range(t):\r\n list.append(input().split())\r\nfor i in range(t):\r\n if list[i][0]==\"0\":\r\n zero1+=1\r\n else:\r\n one1+=1\r\n if list[i][1]==\"0\":\r\n zero2+=1\r\n else:\r\n one2+=1\r\nif zero1<=one1:\r\n ans+=zero1\r\nelse:\r\n ans+=one1\r\nif zero2<=one2:\r\n ans+=zero2\r\nelse:\r\n ans+=one2\r\nprint(ans)\r\n", "n=int(input())\r\na=[]\r\nl=[]\r\ncount=0\r\nfor i in range(n):\r\n x,y=map(int,input().split())\r\n a.append(x)\r\n l.append(y)\r\nk=a.count(1)\r\ns=a.count(0)\r\nm=l.count(1)\r\nn=l.count(0)\r\nif k>s:\r\n count+=s\r\nelse:\r\n count+=k\r\nif m>n:\r\n count+=n\r\nelse:\r\n count+=m\r\nprint(count)", "t = int(input())\nol = 0\ncl = 0\noR = 0\ncr = 0\nfor i in range(t):\n l,r = map(int,input().split())\n if l == 0:\n cl += 1\n if l == 1:\n ol += 1\n if r == 0:\n cr += 1\n if r == 1:\n oR += 1\ntotal_s= 0\nif cl >= ol:\n total_s += ol\nelif ol > cl:\n total_s += cl\nif cr >= oR:\n total_s += oR\nelif oR > cr:\n total_s += cr\nprint(total_s)", "n = int(input())\r\nlst = list()\r\nfor i in range(n):\r\n lst.append(list(map(int,input().split())))\r\n\r\nopen_left = 0\r\nopen_right = 0\r\n\r\nfor i in range(n):\r\n if(lst[i][0] == 1):\r\n open_left += 1\r\n if(lst[i][1] == 1):\r\n open_right += 1\r\n \r\n\r\nprint(min(open_left,n-open_left)+min(open_right,n-open_right))\r\n", "# 10: cupboards\r\n# \r\n\r\nn = int(input())\r\npos = []\r\nfor i in range(n):\r\n pos.append(list(map(int, input().split())))\r\nzeror = 0\r\noner = 0\r\nzerol = 0\r\nonel = 0\r\nfor cupb in pos:\r\n onel+=1 if cupb[0]==1 else 0\r\n oner+=1 if cupb[1]==1 else 0\r\n zerol+=1 if cupb[0]==0 else 0\r\n zeror+=1 if cupb[1]==0 else 0\r\ntime=0\r\nif zerol>onel:\r\n time+=onel\r\nelif zerol==onel:\r\n time+=onel\r\nelse:\r\n time+=zerol\r\n \r\nif zeror>oner:\r\n time+=oner\r\nelif zeror==oner:\r\n time+=oner\r\nelse:\r\n time+=zeror\r\nprint(time)", "n = int(input())\r\ndem = [n * 2, n * 2, n * 2, n * 2]\r\nfor x in range(n):\r\n l, r = map(int, input().split())\r\n if l == 0 and r == 0: dem[0], dem[1], dem[2] = dem[0] - 2, dem[1] - 1, dem[2] - 1\r\n elif l == 0 and r == 1: dem[1], dem[0], dem[3] = dem[1] - 2, dem[0] - 1, dem[3] - 1\r\n elif l == 1 and r == 0: dem[2], dem[3], dem[0] = dem[2] - 2, dem[3] - 1, dem[0] - 1\r\n else: dem[3], dem[2], dem[1] = dem[3] - 2, dem[2] - 1, dem[1] - 1\r\nprint(min(dem[0], dem[1], dem[2], dem[3]))", "n = int(input())\r\nleft, right = 0, 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n left += l\r\n right += r\r\nprint(min(left, n - left) + min(right, n - right))\r\n", "from collections import Counter\n\nl_o = 0\nl_c = 0\nr_o = 0\nr_c = 0\n\nn = int(input())\n\nfor i in range(n):\n a, b = map(int, input().split())\n\n if a == 0:\n l_o += 1\n else:\n l_c += 1\n\n if b == 1:\n r_c += 1\n else:\n r_o += 1\n\nprint(min(r_o, r_c) + min(l_o, l_c))\n", "n = int(input())\r\nx, y = 0, 0\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n x += l\r\n y += r\r\nprint(min(x, n - x) + min(y, n - y))", "n=int(input())\r\nnl1=0\r\nnl0=0\r\nnr1=0\r\nnr0=0\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n if(l==0):\r\n nl0+=1\r\n else:\r\n nl1+=1\r\n if(r==0):\r\n nr0+=1\r\n else:\r\n nr1+=1\r\nprint(min(nl0,nl1)+min(nr0,nr1))", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n x=[int(x) for x in input().split()]\r\n l.append(x[0])\r\n r.append(x[1])\r\nx=l.count(1)\r\ns=0\r\nif x>(n-x):\r\n s+=n-x\r\nelse:\r\n s+=x\r\ny=r.count(1)\r\nif y>(n-y):\r\n s+=n-y\r\nelse:\r\n s+=y\r\nprint(s)", "from os import path\r\nimport sys, time\r\n# mod = int(1e9 + 7)\r\n# import re\r\nfrom math import ceil, floor, gcd, log, log2, factorial, sqrt\r\nfrom collections import defaultdict, Counter, OrderedDict, deque\r\nfrom itertools import combinations, accumulate\r\n# from string import ascii_lowercase ,ascii_uppercase\r\nfrom bisect import *\r\nfrom functools import reduce\r\nfrom operator import mul\r\n\r\nstar = lambda x: print(' '.join(map(str, x)))\r\ngrid = lambda r: [lint() for i in range(r)]\r\nINF = float('inf')\r\nif (path.exists('input.txt')):\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\nimport sys\r\nfrom sys import stdin, stdout\r\nfrom collections import *\r\nfrom math import gcd, floor, ceil\r\n\r\n\r\ndef st():\r\n return list(stdin.readline().strip())\r\n\r\n\r\ndef inp():\r\n return int(stdin.readline())\r\n\r\n\r\ndef inlt():\r\n return list(map(int, stdin.readline().split()))\r\n\r\n\r\ndef invr():\r\n return map(int, stdin.readline().split())\r\n\r\n\r\ndef solve():\r\n n = inp()\r\n a1 = []\r\n a2 = []\r\n for _ in range(n):\r\n x, y = invr()\r\n a1.append(x)\r\n a2.append(y)\r\n x = min(a1.count(0), a1.count(1))\r\n y = min(a2.count(0), a2.count(1))\r\n print(x + y)\r\n\r\n\r\nt = 1\r\n#t = inp()\r\nfor _ in range(t):\r\n solve()\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Apr 14 04:37:47 2020\r\n\r\n@author: DELL\r\n\"\"\"\r\nn=int(input())\r\no=[]\r\nl=[]\r\nfor i in range(n):\r\n g,h=list(map(int,input().split()))\r\n o+=[g]\r\n l+=[h]\r\na=[o.count(1),o.count(0)]\r\nd=[l.count(1),l.count(0)]\r\nc=min(d)+min(a)\r\nprint(c)", "l=[]\r\nr=[]\r\nt=0\r\nn=int(input())\r\nc10=0\r\nc11=0\r\nc20=0\r\nc21=0\r\nfor x in range(n):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\n\r\nfor i in l:\r\n if i==0:\r\n c10+=1\r\n else:\r\n c11+=1\r\nfor j in r:\r\n if j==0:\r\n c20+=1\r\n else:\r\n c21+=1\r\nif c10 > c11:\r\n t+=c11\r\nelse:\r\n t+=c10\r\nif c20 > c21:\r\n t+=c21\r\nelse:\r\n t+=c20\r\nprint(t)", "from sys import stdin\r\ninput = stdin.readline\r\nleft_open = 0\r\nright_open = 0\r\nn = int(input())\r\nfor i in range(n):\r\n l, r = map(int, input().split())\r\n if l :\r\n left_open += 1\r\n if r :\r\n right_open += 1\r\nprint(min(left_open,n- left_open ) + min(right_open, n-right_open))", "n=int(input())\r\nnl=0\r\nnr=0\r\nfor i in range(0,n):\r\n l,r=[int(x) for x in input().split()]\r\n if(l==0):\r\n nl=nl+1\r\n if(r==0):\r\n nr=nr+1\r\nprint(min(nl,n-nl)+min(nr,n-nr))\r\n", "n = int(input())\r\nans = 0\r\nx, y = 0, 0\r\nfor i in range(n):\r\n a, b = list(map(int,input().split()))\r\n x += a\r\n y += b\r\n\r\nprint(min(x, n - x) + min(y, n - y))\r\n", "L,R=[0,0],[0,0]\r\nfor _ in range(int(input())):\r\n x,y=map(int,input().split())\r\n L[x]+=1\r\n R[y]+=1\r\nprint(min(L)+min(R))\r\n \r\n", "left=[]\r\nright=[]\r\nn=int(input())\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\ncount=0\r\nif left.count(0)==left.count(1) or right.count(0)==right.count(1):\r\n count+=n//2\r\nelif left.count(0)>left.count(1):\r\n count+=left.count(1)\r\nelif left.count(0)<left.count(1):\r\n count+=left.count(0)\r\nif right.count(0)>right.count(1):\r\n count+=right.count(1)\r\nelif right.count(0)<right.count(1):\r\n count+=right.count(0)\r\nprint(count)\r\n ", "n = int(input())\r\n\r\nl = [0, 0]\r\nr = [0, 0]\r\nwhile n > 0:\r\n\tli, ri = [int(x) for x in input().split()]\r\n\tl[li] += 1\r\n\tr[ri] += 1\r\n\tn -= 1\r\n\r\nprint (min(l) + min(r))", "def main():\n n = int(input())\n l = []\n r = []\n \n for i in range(n):\n a, b = [int(j) for j in input().split(' ')]\n l.append(a)\n r.append(b)\n \n ans = 0\n \n if sum(l) < n / 2.:\n ans += sum(l)\n else:\n ans += n - sum(l)\n \n if sum(r) < n / 2.:\n ans += sum(r)\n else:\n ans += n - sum(r)\n \n print(ans)\n \nif __name__ == \"__main__\":\n main()", "l=list()\r\nr=list()\r\nfor i in range(int(input())):\r\n a,b=map(int,input().split())\r\n l.append(a)\r\n r.append(b)\r\nprint(min(l.count(1),l.count(0))+min(r.count(1),r.count(0)))\r\n\r\n", "n = int(input())\nl = 0\nr = 0\nfor _ in range(n):\n a, b = map(int, input().split())\n\n if a == 0:\n l -= 1\n else:\n l += 1\n\n if b == 0:\n r -= 1\n else:\n r += 1\nprint((n - abs(l) + n - abs(r)) >> 1)", "'''\nAuthor : knight_byte\nFile : A_Cupboards.py\nCreated on : 2021-04-19 12:05:55\n'''\nimport math\n\n\ndef main():\n n = int(input())\n l, r = [], []\n for _ in range(n):\n x, y = input().split()\n l.append(x)\n r.append(y)\n ans = min(l.count(\"0\"), l.count(\"1\"))+min(r.count(\"0\"), r.count(\"1\"))\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "n = int(input())\r\nL = []\r\nfor i in range(n):\r\n l = [int(i) for i in input().split()]\r\n L.append(l)\r\n#print(L)\r\n\r\n\r\nleft = []\r\nright = []\r\nt = 0\r\nfor i in L:\r\n left.append(i[0])\r\n right.append(i[1])\r\n#print(left, right)\r\nt += (min(left.count(0), left.count(1)) + min(right.count(0), right.count(1)))\r\nprint(t)", "n = int(input())\r\nvl, vr = 0, 0\r\nfor i in range(n):\r\n l, r = (int(x) for x in input().split())\r\n vl += l\r\n vr += r\r\nprint(min(vl, n - vl) + min(vr, n - vr))", "n = int(input())\r\nc0, c1 = 0, 0\r\nfor _ in range(n):\r\n a, b = map(int, input().split())\r\n if a == 0:\r\n c0 += 1\r\n if b == 0:\r\n c1 += 1\r\nprint(min(c0, n - c0) + min(c1, n - c1))", "rc = 0\r\nlc = 0\r\nn = int(input())\r\nfor _ in range(n):\r\n l, r = input().split()\r\n rc += int(r)\r\n lc += int(l)\r\n\r\nprint(min(rc, n - rc) + min(lc, n - lc))\r\n", "n = int(input())\nl = []\nr = []\ncnt=0\nfor i in range(0,n):\n\ta,b = input().split(\" \")\n\tl.append(int(a))\n\tr.append(int(b))\nif l.count(1)>(n/2) :\n\tcnt+=n-l.count(1)\nelse:\n\tcnt+=n-l.count(0)\nif r.count(1)>(n/2) :\n\tcnt+=n-r.count(1)\nelse:\n\tcnt+=n-r.count(0)\nprint(cnt)\n", "# arr = []\n# arr= list(map(int , (input().strip().split(' '))))\n # 0 1\n # 1 0\n # 0 1\n # 1 1\n # 0 1\n# [\n# []\n# []\n# []\n# []\n# []\n# ]\n\n# sum = 2 4\n # 3 1\n\n# l = close 3 open 2 = open (2)\n# r = close 1 open 4 = close(1)\n# t = \nmaster = []\nn = int(input(\"\"))\n\nfor i in range(0,n):\n arr= list(map(int , (input().strip().split(' ')))) \n master.append(arr)\n\nleft_open =0\nright_open =0\n# [v1 , v2]\nfor cup in master:\n left_open = left_open + cup[0]\n right_open = right_open + cup[1]\n\nleft_close = n - left_open\nright_close = n- right_open\n\ntime = 0 \n\nif(left_open > left_close):\n time = time + left_close\nelse:\n time = time + left_open\n\nif(right_open > right_close):\n time = time +right_close\nelse:\n time = time + right_open\n\nprint(time)\n\n\n\n\n\n\n\n", "n=int(input())\r\nl=[]\r\nr=[]\r\nfor i in range(n):\r\n li,ri=map(int,input().split())\r\n l.append(li)\r\n r.append(ri)\r\nlo=0\r\nlc=0\r\nfor i in l:\r\n if(i==1):\r\n lo+=1\r\n else:\r\n lc+=1\r\nml=min(lo,lc)\r\n\r\nro=0\r\nrc=0\r\nfor i in r:\r\n if(i==1):\r\n ro+=1\r\n else:\r\n rc+=1\r\nmr=min(ro,rc)\r\nprint(ml+mr)", "# python 3\n\nnum_cupboards = int(input())\nleft_pos = list()\nright_pos = list()\nfor idx in range(num_cupboards):\n left, right = list(map(int, input().split()))\n left_pos.append(left)\n right_pos.append(right)\n\nleft_sum = sum(left_pos)\nright_sum = sum(right_pos)\n\nleft_time = min(left_sum, num_cupboards - left_sum)\nright_time = min(right_sum, num_cupboards - right_sum)\nprint(left_time + right_time)\n", "a,b=[],[]\r\nfor i in range(int(input())):x,y=map(int,input().split());a.append(x);b.append(y)\r\nprint(min(a.count(1),a.count(0))+min(b.count(0),b.count(1)))", "# A. Cupboards\r\nn = int(input())\r\nl = []\r\nr = []\r\nlo = 0\r\nro = 0\r\nfor i in range(n):\r\n L,R = map(int,input().split())\r\n if L == 1:\r\n lo += 1\r\n if R == 1:\r\n ro += 1\r\n l.append(L)\r\n r.append(R)\r\nsecs = min(lo,n-lo)\r\nsecs += min(n-ro,ro)\r\nprint(secs)", "import sys\r\nimport os.path\r\nimport math\r\nimport heapq\r\nfrom sys import stdin,stdout\r\nfrom collections import*\r\nfrom math import gcd,ceil,floor\r\nmod = int(1e9+7)\r\n##input=sys.stdin.readline\r\nif os.path.exists('Updated prg/Input3d.txt'):\r\n sys.stdout=open(\"Updated prg/Output3d.txt\",\"w\")\r\n sys.stdin=open(\"Updated prg/Input3d.txt\",\"r\")\r\ndef sinp():return input()\r\ndef ninp():return int(sinp())\r\ndef mapinp():return map(int,sinp().split())\r\ndef linp():return list(mapinp())\r\ndef sl():return list(sinp())\r\ndef prnt(a):print(a)\r\nl1,l2=[],[]\r\nc=0\r\nfor _ in range(ninp()):\r\n l,r=mapinp()\r\n l1.append(l)\r\n l2.append(r)\r\nm1=max(l1.count(0),l1.count(1))\r\nm2=max(l2.count(0),l2.count(1))\r\nif m1==l1.count(0):\r\n a=0\r\nelse:\r\n a=1\r\nif m2==l2.count(0):\r\n b=0\r\nelse:\r\n b=1\r\nfor i in l1:\r\n if i!=a:\r\n c=c+1\r\nfor i in l2:\r\n if i!=b:\r\n c=c+1\r\nprnt(c)", "n = int(input())\nright = 0\nleft = 0\n# middle = n // 2\n\nfor i in range(n):\n\tcupboard = [int(x) for x in input().split(' ')]\n\tright += cupboard[1]\n\tleft += cupboard[0]\n\nprint(min(left, n - left) + min(right, n - right))", "import sys\ninput = sys.stdin.readline\na,b,c,d = 0,0,0,0\nfor _ in range(int(input())):\n x,y = map(int,input().split())\n if x==0:a+=1\n if x==1:b+=1\n if y==0:c+=1\n if y==1:d+=1\nprint(min(a,b)+min(c,d))\n\t \t \t \t\t \t\t \t\t \t\t\t\t \t \t", "n=int(input())\r\nleft=[]\r\nright=[]\r\nfor i in range(n):\r\n l,r=map(int,input().split())\r\n left.append(l)\r\n right.append(r)\r\nr1,r0,l0,l1,ans=0,0,0,0,0\r\nfor j in range(n):\r\n if right[j]==1:\r\n r1+=1\r\n else:\r\n r0+=1\r\nans+=min(r0,r1)\r\nfor k in range(n):\r\n if left[k]==1:\r\n l1+=1\r\n else:\r\n l0+=1\r\nans+=min(l0,l1)\r\nprint(ans)", "a = int(input())\r\nleft =[]\r\nrigth =[]\r\nfor i in range(a):\r\n b , c = list(map(int, input().split()))\r\n left.append(b)\r\n rigth.append(c)\r\nans = min(left.count(0) , left.count(1)) + min(rigth.count(0) , rigth.count(1))\r\nprint(ans)", "t = int(input())\r\nl = []\r\nr = []\r\nans = 0\r\nfor i in range (0,t):\r\n l1,r1 = input().split()\r\n l.append(l1)\r\n r.append(r1)\r\n\r\ncount1 = l.count(\"1\")\r\ncount2 = l.count(\"0\")\r\nif (count1 < count2):\r\n ans = ans + count1\r\nelse:\r\n ans = ans + count2\r\ncount1 = r.count(\"1\")\r\ncount2 = r.count(\"0\")\r\nif (count1 < count2):\r\n ans = ans + count1\r\nelse:\r\n ans = ans + count2\r\nprint(ans)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Fri Apr 24 21:07:22 2020\r\n\r\n@author: Kashem Pagla\r\n\"\"\"\r\n\r\nleft=[]\r\nright=[]\r\nn=int(input())\r\nfor _ in range(n):\r\n l,r=map(int,input().split()) \r\n left.append(l)\r\n right.append(r)\r\nstring=[]\r\n\r\nif(left.count(0)>left.count(1)):\r\n string.append(left.count(1))\r\nelse:\r\n string.append(left.count(0))\r\n \r\nif(right.count(0)>right.count(1)):\r\n string.append(right.count(1))\r\nelse:\r\n string.append(right.count(0)) \r\n \r\nprint(sum(string) if sum(string)>0 else \"0\") \r\n\r\n\"\"\"\r\na_0=left.count(0) \r\na_1=right.count(1) \r\nb_0=left.count(0) \r\nb_1=right.count(1)\r\n\r\nif (left==right or len(set(right))==len(set(left))): \r\n print(0)\r\nelif(len(set(right))!=len(set(left))):\r\n \r\n \r\nelse:\r\n print(min(right.count(0)+left.count(1),right.count(1)+left.count(0))) \r\n\"\"\" " ]
{"inputs": ["5\n0 1\n1 0\n0 1\n1 1\n0 1", "2\n0 0\n0 0", "3\n0 1\n1 1\n1 1", "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 1\n1 1\n0 1", "15\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0", "5\n1 0\n1 0\n1 0\n0 1\n0 1"], "outputs": ["3", "0", "1", "7", "6", "0", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
738
1fa51f9955817acd74ac1d152389d2d2
Correct Bracket Sequence Editor
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-s to it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. Each bracket in CBS has a pair. For example, in "(()(()))": - 1st bracket is paired with 8th, - 2d bracket is paired with 3d, - 3d bracket is paired with 2d, - 4th bracket is paired with 7th, - 5th bracket is paired with 6th, - 6th bracket is paired with 5th, - 7th bracket is paired with 4th, - 8th bracket is paired with 1st. Polycarp's editor currently supports only three operations during the use of CBS. The cursor in the editor takes the whole position of one of the brackets (not the position between the brackets!). There are three operations being supported: - «L» — move the cursor one position to the left, - «R» — move the cursor one position to the right, - «D» — delete the bracket in which the cursor is located, delete the bracket it's paired to and all brackets between them (that is, delete a substring between the bracket in which the cursor is located and the one it's paired to). After the operation "D" the cursor moves to the nearest bracket to the right (of course, among the non-deleted). If there is no such bracket (that is, the suffix of the CBS was deleted), then the cursor moves to the nearest bracket to the left (of course, among the non-deleted). There are pictures illustrated several usages of operation "D" below. All incorrect operations (shift cursor over the end of CBS, delete the whole CBS, etc.) are not supported by Polycarp's editor. Polycarp is very proud of his development, can you implement the functionality of his editor? The first line contains three positive integers *n*, *m* and *p* (2<=≤<=*n*<=≤<=500<=000, 1<=≤<=*m*<=≤<=500<=000, 1<=≤<=*p*<=≤<=*n*) — the number of brackets in the correct bracket sequence, the number of operations and the initial position of cursor. Positions in the sequence are numbered from left to right, starting from one. It is guaranteed that *n* is even. It is followed by the string of *n* characters "(" and ")" forming the correct bracket sequence. Then follow a string of *m* characters "L", "R" and "D" — a sequence of the operations. Operations are carried out one by one from the first to the last. It is guaranteed that the given operations never move the cursor outside the bracket sequence, as well as the fact that after all operations a bracket sequence will be non-empty. Print the correct bracket sequence, obtained as a result of applying all operations to the initial sequence. Sample Input 8 4 5 (())()() RDLD 12 5 3 ((()())(())) RRDLD 8 8 8 (())()() LLLLLLDD Sample Output () (()(())) ()()
[ "# LUOGU_RID: 103549808\nn, m, p = map(int, input().split())\nbracketStr = input()\nopStr = input()\np -= 1\nleft, right, pair = [0]*500001, [0]*500001, [0]*500001\nstk = []\nfor i in range(n):\n left[i] = i-1\n right[i] = i+1\n if bracketStr[i] == '(':\n stk.append(i)\n else:\n pair[i] = stk[-1]\n pair[stk[-1]] = i\n stk.pop(-1)\nfor i in range(m):\n if opStr[i] == 'L':\n p = left[p]\n elif opStr[i] == 'R':\n p = right[p]\n else:\n if p > pair[p]:\n p = pair[p]\n if left[p] != -1:\n right[left[p]] = right[pair[p]]\n left[right[pair[p]]] = left[p]\n if right[left[p]] == n:\n p = left[p]\n else:\n p = right[pair[p]]\nwhile p > 0 and left[p] != -1:\n p = left[p]\nans = ''\nwhile p != n:\n ans = ans+bracketStr[p]\n p = right[p]\nprint(ans)", "import sys\nsys.stderr = sys.stdout\n\nfrom collections import deque\n\n\ndef brackets(n, m, p, B, S):\n P = [i-1 for i in range(n+2)]\n P[0] = None\n Q = [i+1 for i in range(n+2)]\n Q[n+1] = None\n\n J = [None] * (n + 2)\n D = deque()\n for i, b in enumerate(B, 1):\n if b == '(':\n D.append(i)\n elif b == ')':\n j = D.pop()\n J[i] = j\n J[j] = i\n\n i = p\n for c in S:\n if c == 'L':\n i = P[i]\n elif c == 'R':\n i = Q[i]\n else:\n j = J[i]\n if j < i:\n i, j = j, i\n Q[P[i]] = Q[j]\n P[Q[j]] = P[i]\n i = Q[j] if Q[j] <= n else P[i]\n\n L = []\n i = Q[0]\n while i <= n:\n L.append(B[i-1])\n i = Q[i]\n return L\n\n\ndef main():\n n, m, p = readinti()\n B = input()\n S = input()\n print(''.join(brackets(n, m, p, B, S)))\n\n##########\n\ndef readint():\n return int(input())\n\n\ndef readinti():\n return map(int, input().split())\n\n\ndef readintt():\n return tuple(readinti())\n\n\ndef readintl():\n return list(readinti())\n\n\ndef readinttl(k):\n return [readintt() for _ in range(k)]\n\n\ndef readintll(k):\n return [readintl() for _ in range(k)]\n\n\ndef log(*args, **kwargs):\n print(*args, **kwargs, file=sys.__stderr__)\n\n\nif __name__ == '__main__':\n main()\n", "def ni(): return int(input())\r\ndef ia(): return list(map(int, input().split()))\r\n\r\n\r\nclass Node:\r\n def __init__(self, ch, idx) -> None:\r\n self.x = ch\r\n self.idx = idx\r\n self.prev = None\r\n self.next = None\r\n\r\n\r\ndef getVal(node):\r\n return 1 if node.x == '(' else -1\r\n\r\n\r\ndef shift(node, delta):\r\n return node.next if delta == 1 else node.prev\r\n\r\n\r\nn, m, p = ia()\r\ncbs = input()\r\nseq = input()\r\n\r\nhead = Node('#', 0)\r\npre = head\r\ncur = None\r\nfor i in range(n):\r\n now = Node(cbs[i], i + 1)\r\n pre.next = now\r\n now.prev = pre\r\n pre = now\r\n if i == p - 1:\r\n cur = now\r\n if i == n - 1:\r\n fin = Node('#', n + 1)\r\n now.next = fin\r\n fin.prev = now\r\n\r\nfor inst in seq:\r\n if inst == 'R':\r\n cur = cur.next\r\n elif inst == 'L':\r\n cur = cur.prev\r\n else:\r\n now = cur\r\n val = getVal(cur)\r\n delta = val\r\n while val != 0:\r\n cur = shift(cur, delta)\r\n val += getVal(cur)\r\n now = shift(now, -delta)\r\n cur = shift(cur, delta)\r\n if delta == 1:\r\n now, cur = cur, now\r\n\r\n cur.next = now\r\n now.prev = cur\r\n\r\n if now.x == '#':\r\n now = now.prev\r\n cur = now\r\n\r\nwhile head is not None:\r\n if head.x != '#':\r\n print(head.x, end=\"\")\r\n head = head.next\r\n" ]
{"inputs": ["8 4 5\n(())()()\nRDLD", "12 5 3\n((()())(()))\nRRDLD", "8 8 8\n(())()()\nLLLLLLDD", "4 2 2\n()()\nLD", "6 4 1\n()()()\nDRRD", "8 2 4\n(())()()\nRR", "10 7 3\n(()())()()\nRDLRDRD", "12 10 11\n(())()()()()\nDLRDLRDDLR", "14 8 13\n((())())((()))\nDLRLLRLR", "16 2 10\n(((())())())()()\nLD", "18 8 11\n((()))(()()()())()\nLLLRRRRD", "20 16 3\n(()()())()(())()()()\nLDRRRRRRLRLRLLLL", "22 9 12\n(()())((()()())())()()\nRDLLLRDRL", "24 15 14\n((()())()()())(())()()()\nLDRRLDLDRRDDLRL", "26 3 15\n((())())(((())()()))(())()\nRDL", "28 13 16\n(()()())(()()())(())(())()()\nLRLDRRRRRLLLR", "30 18 15\n(()((()()())()(())())())()()()\nRRRLRRRLRRDLLLDRDR", "32 6 19\n((()())((())())())((())()(()))()\nLDRLRR", "34 8 20\n(())((()())()((())())()()())()()()\nRLLDLRRL", "36 11 36\n(()()()()())((())())(()()())((())())\nLDLRLLLLRLR", "38 8 26\n((((())())(()))(()()))(((())())())()()\nDDDLRLDR", "40 22 35\n(((()()()())()()())((())())()(())())()()\nDRRLDRLRLLLDLLLDRLLRLD", "42 7 29\n(((())()(()())())(((()())())(()())())())()\nDDRRRRD", "44 13 42\n((()()())()()()())(((()()())())()())(()())()\nLRRRLLDRDLDLR", "46 3 11\n(()()(())())(()())((()((())())(()())(())())())\nDDD", "48 33 11\n((((())())((()()())())()()(()()))()(()())())()()\nRLRDLDRLLLRRRLRDLRLDDRRDRLRRDRLRD", "50 32 32\n(()()())(())(())((()())())((())())((()())())(())()\nLRLLLRDRRDLRRRLRLLDDRLLRDLRDLRLD", "52 24 39\n((()(()())(()())()())()())((()())(())())(())(()())()\nDRRDLDRLRRLLRRDRRLDRRLLL", "54 22 3\n(((()())(())()())((()())())())((())((()()())()())())()\nLRLRDLRDLLRLDRLRRDRLRD", "56 43 9\n(((((())())(()()))()()()())(()()(()))(()())(())())()()()\nRLRLDLRLLRLRLDLLRLRRLLLRLRRLDLDRDLLRLRRLLDR", "58 3 22\n((((())()())())((())())(())())(((())()()())(())()())()(())\nLLR", "60 50 23\n((((())(()())()())(()())()()()(()())())((())()())()())(())()\nDRDLLDDLLLLDDRRDRDLLLRRRLRLDDDLRLLRRDLRLRRDDDRDRRL", "62 34 43\n(()((()())()()))(((())())()(()())(())())((())(()(()())()))()()\nRLDDDDDDLRDLLRLDRLLDLRLDLLDRLLRRLL", "64 19 15\n((((())((())())()())(())())(()())(()())())((()()())(())())()()()\nDRRLRLRDDDDLLDRLRLD", "66 55 24\n(((())(((()())()()))(()())(()())())(())((()())())(()()())())()()()\nRDLRLRRRLRDLRRLLDDRDRRDLRLDRRDRDLRDDLLRRDRDRLRRLLLDLRRR", "68 34 8\n((()(()())()())(()))((()())()())((()()())())(((())(()))(())()(())())\nDLRRLRRRDLLDLLDDDLRRLRLRRRDDRLRRLL", "70 33 26\n((()(())()())((())())(()())(())())((()((()())()())())()()(())())(()())\nDLDRRRLRLDLRLLRDDRLRRLLLRDRLRLDRL", "72 23 38\n(((((()()())()())(((()()))(())())()(()())(()(())())))(())((())())())()()\nRDLRLRRRDLLRDLRDLLRRLLD", "74 26 27\n(((()()())())(())()())((()()(())())()())((()()())()())(()()())(()()())()()\nLDRLLRLRLLDDDLDRRDRLLRDLRD", "76 51 69\n(((())()())())(()()()()())(((((())(())())())())(((()(())())(()()())())()))()\nLRLLRRLLLDRDDRLLDLRLRDRLRDLRLRLRLLDLRLRLLLDDLLRRDLD", "78 33 22\n(((()((()()())())()()())((()())()())(())())(((((())())()())()())(())())())()()\nRDRRRRRLDRDLDRLLLLDRDRRRDLDRDLLRD", "2 1 1\n()\nR", "80 31 30\n(((()()())(((())())((()())()()())()()))(()()()())(()())(()())(())(())()()()())()\nDDDLLDLDDLRLRLDDRDRRLDRDLLDRLRL", "82 16 6\n(((())())(())()())(((()()((()()))())()(())())(()())(())((())())()()())(()()()())()\nRLLLLRRDDRRLRRRL", "84 18 78\n(())(((()(()))()((((()())())(()())())()())((()())())())(((())(())())(())())())()()()\nLLLRDDLRDRLDDLLRRL", "86 11 62\n(((())())(((()())())()()())(()())(()()())()())((()()())())(((())()())((())(()())())())\nDLDLRLRLRRR", "88 33 12\n(())((((())()((()())())())(((())())(())()())(()))((()())())())(((())()())(())()())()()()\nLLLRRLRDRDRLDDLLRDLLDRLRDDLDRDLRR", "90 44 6\n(((((())()())(((()())())())()()))(()())((())()())(()())((())())(()()())())(())((())())()()\nRLDLRRLLDRDDDLRDRRDLLRRDDDDLRLRDRLLDRDLRDDRR", "92 51 30\n(()(((()())(()())())())(()())()()()())((()()())(())(())(()((())()())())(())())((())()())()()\nLRLRLLLLRRRLLRRLDLRLRRLRDLDLDLDDRRLRRRLLRDRLDDRLRRD", "94 48 47\n(((()(())())(((())())())()())()()())((()()())(()(()()()())())())(()())(()(())(())()())(()())()\nLLLLLLDLDRLLDLRRDLLLLRLLDLLRRDDRDRRLLRRDRRRDRLLD", "96 37 18\n((()()()())((((())()())())(())()())()()())(((())()(()(())())()()())(())())((()())()()())(()())()\nDDLRRDDLDLRDDDRLDLRRDDDLLDRRRDDLDLLRL", "98 38 40\n((()((((()))(())(()(())))))((())()())(())()())((((()())(((()()))()))()(())()()())())((()))(())()()\nLRLRRDLDDRRLRDRDDLDRDLDRDLRLRLRLRLRLRR", "100 57 80\n(((())(()))(()())())((((()()()())((())())()())(()((()())()()()))())()()())((())()((())()))((()))()()\nLLRRLLLRLRLRLDLLRRRDDLRDDDLRLRLLLRLRRRLLDRLRDLLDLRLRLDDLR", "10 3 3\n(())((()))\nDRD"], "outputs": ["()", "(()(()))", "()()", "()", "()", "(())()()", "()", "(())", "((())())()", "(())()()", "((()))(()()())()", "(()())()(())()()()", "(()())((())())()()", "()", "((())())(((())()))(())()", "(()()())(()())(())(())()()", "()()", "((())()(()))()", "(())((()())()((()))()()())()()()", "(()()()()())((())())(()()())((()))", "((((())())(()))(()()))(())()()", "(())()", "(((())()(()())())(((()())()))())", "((()()())()()()())(((()()())())())", "((()((())())(()())(())())())", "(()(()())())()()", "(()()())(())(())((()()))", "((()(()())(()())()())()())((()())(()))()()", "(()())()", "()()()", "((((())()())())((())())(())())(((())()()())(())()())()(())", "(()())(())()", "(())", "()()()", "()()()()", "((()())()())((()()())())(((())(()))(())()(())())", "(()())", "()()", "()()()", "(((())()()))", "((((((())())()())()())(())())())()()", "()", "()", "((())(())()())(((()()((()()))())()(())())(()())(())((())())()()())(()()()())()", "(())", "(((())())(((()())())()()())(()())(()()())()())((()()())())((()())((())(()())())())", "(())()()", "()()", "(()()())()()", "((())()())(()())()", "((()()()))((()())()()())(()())()", "()()()", "(((())(()))(()())())", "()"]}
UNKNOWN
PYTHON3
CODEFORCES
3
1fb3786e6d9b85eeaa60c2c28a859b75
Sail
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will move to (*x*<=+<=1,<=*y*). - If the wind blows to the south, the boat will move to (*x*,<=*y*<=-<=1). - If the wind blows to the west, the boat will move to (*x*<=-<=1,<=*y*). - If the wind blows to the north, the boat will move to (*x*,<=*y*<=+<=1). Alternatively, they can hold the boat by the anchor. In this case, the boat stays at (*x*,<=*y*). Given the wind direction for *t* seconds, what is the earliest time they sail to (*e**x*,<=*e**y*)? The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≤<=*t*<=≤<=105,<=<=-<=109<=≤<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≤<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the *i*-th second. It will be one of the four possibilities: "E" (east), "S" (south), "W" (west) and "N" (north). If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes). Sample Input 5 0 0 1 1 SESNW 10 5 3 3 6 NENSWESNEE Sample Output 4 -1
[ "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nvert,hori=\"\",\"\"\r\nif ey>sy:\r\n vert='N'\r\nelse:\r\n vert='S'\r\nif ex>sx:\r\n hori='E'\r\nelse:\r\n hori='W'\r\n \r\nx,y=abs(ex-sx),abs(ey-sy)\r\n\r\ncnt=0\r\nfor i in range(0,len(s)):\r\n if s[i]==vert:\r\n y-=1\r\n \r\n if s[i]==hori:\r\n x-=1\r\n \r\n\r\n if x<=0 and y<=0:\r\n print(i+1)\r\n break\r\n \r\nelse:\r\n print(-1)\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "# python2 or 3\r\nimport sys, threading, os.path\r\nimport collections, heapq, math,bisect\r\nimport string\r\nfrom platform import python_version\r\nsys.setrecursionlimit(10**6)\r\nthreading.stack_size(2**27)\r\n\r\n\r\ndef main():\r\n if os.path.exists('input.txt'):\r\n input = open('input.txt', 'r')\r\n else:\r\n input = sys.stdin\r\n #--------------------------------INPUT---------------------------------\r\n t, x1,x2,y1,y2 = list(map(int, input.readline().split()))\r\n T = t\r\n dirs = list(str(input.readline().rstrip('\\n')))\r\n for i in range(len(dirs)):\r\n if t==0 or (x1 == y1 and x2==y2):\r\n break\r\n if dirs[i] == 'E':\r\n if y1>x1:\r\n x1+=1\r\n t-=1\r\n elif dirs[i] == 'S':\r\n if x2>y2:\r\n x2-=1\r\n t-=1\r\n elif dirs[i] == 'W':\r\n if y1<x1:\r\n x1-=1\r\n t-=1\r\n elif dirs[i] == 'N':\r\n if x2<y2:\r\n x2+=1\r\n t-=1\r\n if x1 == y1 and x2==y2:\r\n output = T-t\r\n else:\r\n output= -1\r\n #-------------------------------OUTPUT----------------------------------\r\n if os.path.exists('output.txt'):\r\n open('output.txt', 'w').writelines(str(output))\r\n else:\r\n sys.stdout.write(str(output))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n#threading.Thread(target=main).start()\r\n\r\n", "t, sx, sy, ex, ey = map(int, input().split())\r\ndirections = input()\r\ni = 0\r\nwhile i < t:\r\n d = directions[i]\r\n if (ex - sx) > 0:\r\n if d == 'E':\r\n sx += 1\r\n elif (ex - sx) < 0:\r\n if d == 'W':\r\n sx -= 1\r\n\r\n if (ey - sy) > 0:\r\n if d == 'N':\r\n sy += 1\r\n elif (ey - sy) < 0:\r\n if d == 'S':\r\n sy -= 1\r\n\r\n if (ex - sx) == 0 and (ey - sy) == 0:\r\n break \r\n\r\n i += 1 \r\n\r\nif (ex - sx) == 0 and (ey - sy) == 0:\r\n print(i+1)\r\nelse:\r\n print(-1)\r\n ", "t,sx,sy,ex,ey=map(int, input().split(\" \"))\na=input()\nx=ex-sx\ny=ey-sy\ntime = 0\nfor i in a:\n time += 1\n if x>0 and i=='E':\n x-=1\n if x<0 and i=='W':\n x+=1\n\n if y>0 and i=='N':\n y-=1\n if y<0 and i=='S':\n y+=1\n\n if x==0 and y==0:\n break\n\nif x==0 and y==0:\n print(time)\nelse:\n print(-1)\n", "def solve():\r\n t, sx, sy, ex, ey = map(int, input().split())\r\n order = input()\r\n\r\n def dist(x1, y1):\r\n return abs(x1 - ex) + abs(y1 - ey)\r\n\r\n for i, d in enumerate(order):\r\n if d == 'N':\r\n if dist(sx, sy+1) < dist(sx, sy):\r\n sy += 1\r\n elif d == 'E':\r\n if dist(sx+1, sy) < dist(sx, sy):\r\n sx += 1\r\n elif d == 'S':\r\n if dist(sx, sy-1) < dist(sx, sy):\r\n sy -= 1\r\n else:\r\n if dist(sx-1, sy) < dist(sx, sy):\r\n sx -= 1\r\n if sx == ex and sy == ey:\r\n return i+1\r\n return -1\r\nprint(solve())", "from sys import stdin,exit\r\nt,sx,sy,ex,ey=map(int,stdin.readline().split())\r\na=ex-sx\r\nb=ey-sy\r\nn,s,e,w=0,0,0,0\r\nif a<0:\r\n w=a\r\nelse:\r\n e=a\r\nif b<0:\r\n s=b\r\nelse:\r\n n=b\r\nr=stdin.readline().rstrip()\r\nc=0\r\nfor i in range(t):\r\n if r[i]=='W' and w!=0:\r\n w+=1\r\n c+=1\r\n elif r[i]=='E' and e!=0:\r\n e-=1\r\n c+=1\r\n elif r[i]=='S' and s!=0:\r\n s+=1\r\n c+=1\r\n elif r[i]=='N' and n!=0:\r\n n-=1\r\n c+=1\r\n else:\r\n if n==0 and s==0 and w==0 and e==0:\r\n break\r\n c+=1\r\n if i==t-1 and (n!=0 or s!=0 or e!=0 or w!=0):\r\n print(-1)\r\n exit()\r\nprint(c)", "def dis(sx,sy,ex,ey):\r\n n=abs(sx-ex)+abs(sy-ey)\r\n return n\r\nt,sx,sy,ex,ey=map(int,input().split())\r\ne=[ex,ey]\r\ns=[sx,sy]\r\nst=input()\r\ncnt=0\r\nfor i in st:\r\n #print(sx,sy)\r\n if(sx==ex and sy==ey):\r\n break\r\n if(i=='N'):\r\n #print(i,dis(sx,sy,ex,ey),dis(sx,sy+1,ex,ey))\r\n if(dis(sx,sy,ex,ey)>dis(sx,sy+1,ex,ey)):\r\n \r\n sy+=1\r\n \r\n if(i=='E'):\r\n #print(i,dis(sx,sy,ex,ey),dis(sx+1,sy,ex,ey))\r\n if(dis(sx,sy,ex,ey)>dis(sx+1,sy,ex,ey)):\r\n sx+=1\r\n \r\n if(i=='S'):\r\n #print(i,dis(sx,sy,ex,ey),dis(sx,sy-1,ex,ey))\r\n if(dis(sx,sy,ex,ey)>dis(sx,sy-1,ex,ey)):\r\n sy-=1\r\n \r\n if(i=='W'):\r\n #print(i,dis(sx,sy,ex,ey),dis(sx-1,sy,ex,ey))\r\n if(dis(sx,sy,ex,ey)>dis(sx-1,sy,ex,ey)):\r\n sx-=1\r\n \r\n cnt+=1\r\nif(sx==ex and sy==ey):\r\n print(cnt)\r\nelse:\r\n print(\"-1\")\r\n \r\n", "n,x,y,xx,yy=map(int,input().split())\r\ns=input()\r\nc=0\r\nif(x==xx and y==yy):\r\n print(0)\r\nelse:\r\n for i in range(n):\r\n c=c+1\r\n if(s[i]=='N'):\r\n if(yy>y):\r\n y=y+1\r\n elif(s[i]=='S'):\r\n if(yy<y):\r\n y-=1\r\n elif(s[i]=='E'):\r\n if(xx>x):\r\n x+=1\r\n elif(s[i]=='W'):\r\n if(xx<x):\r\n x-=1\r\n if(x==xx and y==yy):\r\n print(c)\r\n break\r\n else:\r\n print(-1)\r\n", "time, x1, y1, x2, y2 = map(int, input().split())\r\nword = input()\r\nneed1 = ''\r\nneed2 = ''\r\nif x2 - x1 > 0:\r\n need1 = 'E'\r\nelse:\r\n need1 = 'W'\r\nif y2 - y1 > 0:\r\n need2 = 'N'\r\nelse:\r\n need2 = 'S'\r\ntarget1 = abs(x2 - x1)\r\ntarget2 = abs(y2 - y1)\r\nfor spend, direction in enumerate(word):\r\n if direction == need1:\r\n target1 -= 1\r\n elif direction == need2:\r\n target2 -= 1\r\n if target2 <= 0 and target1 <= 0:\r\n print(spend + 1)\r\n break\r\nelse:\r\n print(-1)\r\n", "n, a, b, c, d = map(int, input().split())\r\ns = input()\r\n\r\nfor i in range(n):\r\n if s[i] == 'E' and c > a:\r\n a += 1\r\n elif s[i] == 'W' and c < a:\r\n a -= 1\r\n elif s[i] == 'N' and d > b:\r\n b += 1\r\n elif s[i] == 'S' and d < b:\r\n b -= 1\r\n if a == c and b == d:\r\n print(i+1)\r\n break\r\nelse:\r\n print(-1)\r\n", "t,x,y,x1,y1=map(int,input().split())\r\ns=input()\r\new=x1-x\r\nsn=y1-y\r\nf=1\r\nfor i in range(t):\r\n if ew<0:\r\n if s[i]==\"W\":\r\n ew+=1\r\n else:\r\n if s[i]==\"E\" and ew!=0:\r\n ew-=1\r\n if sn<0:\r\n if s[i]==\"S\":\r\n sn+=1\r\n else:\r\n if s[i]==\"N\" and sn!=0:\r\n sn-=1\r\n if sn==0 and ew==0:\r\n f=0\r\n print(i+1)\r\n break\r\nif f:\r\n print(-1)", "def nami(m,a,b,c,d,s):\r\n ss=\"1\"+s\r\n for i in range(1,m+1):\r\n if a==c and b==d:\r\n return i-1\r\n if ss[i]==\"E\":\r\n if a<c: a+=1\r\n if ss[i]==\"W\":\r\n if a>c: a-=1\r\n if ss[i]==\"N\":\r\n if b<d: b+=1\r\n if ss[i]==\"S\":\r\n if b>d: b-=1\r\n if a==c and b==d:\r\n return m\r\n return -1\r\n\r\nm,a,b,c,d=map(int,input().split())\r\ns=input()\r\nprint(nami(m,a,b,c,d,s))\r\n \r\n", "n,x,y,f1,f2=map(int,input().split())\r\ns=input()\r\nans=True\r\nfor i in range(n):\r\n if s[i]==\"S\" and f2<y:y-=1\r\n elif s[i]==\"N\" and f2>y:y+=1\r\n elif s[i]==\"E\" and f1>x:x+=1\r\n elif s[i]==\"W\" and f1<x:x-=1\r\n if x==f1 and y==f2:\r\n print(i+1)\r\n ans=False\r\n break\r\nif ans:print(-1)", "t, sx, sy, ex, ey = map(int,input().split())\r\nl = list(input())\r\n\r\nx = ex - sx\r\ny = ey - sy\r\nxP = \"\"\r\nyP = \"\"\r\n\r\nif x > 0:\r\n xP = \"E\"\r\nelse:\r\n x = abs(x)\r\n xP = \"W\"\r\n\r\nif y > 0:\r\n yP = \"N\"\r\nelse:\r\n y = abs(y)\r\n yP = \"S\"\r\n\r\nloc = -1\r\nfor i,a in enumerate(l):\r\n if a == xP and x > 0 : x -= 1 \r\n if a == yP and y > 0 : y -= 1 \r\n if x == 0 and y == 0 :\r\n loc = i + 1\r\n break\r\n\r\n\r\nprint(loc)", "t, sx, sy, ex, ey = map(int, input().split())\r\nst = input()\r\ni = 0\r\nfor_x = (ex-sx)\r\nfor_y = (ey-sy)\r\nmove_x, move_y = \"\", \"\"\r\nif for_x < 0:\r\n move_x += \"W\"\r\nif for_x > 0:\r\n move_x += \"E\"\r\nif for_y < 0:\r\n move_y += \"S\"\r\nif for_y > 0:\r\n move_y += \"N\"\r\nfor_x = abs(for_x)\r\nfor_y = abs(for_y)\r\noccur1=st.count(move_x)\r\noccur2=st.count(move_y)\r\nif occur1<for_x or occur2<for_y:\r\n print(\"-1\")\r\nelse:\r\n while i < t and (for_x > 0 or for_y > 0):\r\n if st[i] == move_x:\r\n for_x -= 1\r\n elif st[i] == move_y:\r\n for_y -= 1\r\n i += 1\r\n print(i)", "from collections import Counter\n\ndef main():\n dirs = {\n 'S': -1,\n 'N': 1,\n 'W': -1,\n 'E': 1,\n }\n t, sx, sy, ex, ey = map(int, input().split())\n\n for i, dir in enumerate(input(), 1):\n if dir in 'SN':\n if abs(ey - sy - dirs[dir])< abs(ey - sy):\n sy += dirs[dir]\n elif dir in 'EW':\n if abs(ex - sx - dirs[dir]) < abs(ex - sx):\n sx += dirs[dir]\n\n if sx == ex and sy == ey:\n print(i)\n break\n else:\n print(-1)\n\nmain()\n", "def main() :\r\n t,sx,sy,ex,ey = map(int,input().split())\r\n string = input()\r\n test = True\r\n a = ex-sx\r\n b = ey-sy\r\n if a>0 :\r\n dir1 = 'E'\r\n elif a<0 :\r\n dir1 = 'W'\r\n else :\r\n dir1 = \"\" \r\n if b>0 :\r\n dir2 = 'N'\r\n elif b<0 :\r\n dir2 = 'S'\r\n else:\r\n dir2 = \"\" \r\n if dir1 != \"\" :\r\n ver1 = string.count(dir1)\r\n if ver1 < abs(a) :\r\n test = False\r\n if dir2 != \"\" :\r\n ver2 = string.count(dir2)\r\n if ver2 < abs(b) :\r\n test = False\r\n if test :\r\n i = 0\r\n c1,c2 = 0,0\r\n while c1<abs(a) or c2<abs(b) :\r\n if string[i] == dir1 and c1<abs(a) :\r\n c1+=1\r\n i+=1\r\n continue\r\n if string[i] == dir2 and c2<abs(b) :\r\n c2+=1\r\n i+=1\r\n continue \r\n i+=1\r\n print(i)\r\n else :\r\n print(-1) \r\n\r\n\r\nmain()", "lst=[int(x) for x in input().split()]\r\ns=input()\r\npos=0\r\ncon=True\r\nfor i in s:\r\n if i=='N':\r\n if lst[4]>lst[2]:lst[2]+=1\r\n elif i=='S':\r\n if lst[4]<lst[2]:lst[2]-=1\r\n elif i=='E':\r\n if lst[3]>lst[1]:lst[1]+=1\r\n else:\r\n if lst[3]<lst[1]:lst[1]-=1\r\n pos+=1\r\n if lst[1]==lst[3] and lst[2]==lst[4]:\r\n con=False\r\n break\r\nelse:print(-1)\r\nif con==False:print(pos)\r\n", "t, sx, sy, ex, ey = map(int, input().split())\r\nd = input()\r\npox = ex - sx\r\npoy = ey - sy\r\nif pox > 0:\r\n naprx = 'E'\r\nelse:\r\n naprx = 'W'\r\nif poy > 0:\r\n napry = 'N'\r\nelse:\r\n napry = 'S'\r\nif d.count(naprx) < abs(pox) or d.count(napry) < abs(poy):\r\n print(-1)\r\nelse:\r\n count = 0\r\n pox = abs(pox)\r\n poy = abs(poy)\r\n while pox > 0 or poy > 0:\r\n if d[count] == naprx:\r\n pox -= 1\r\n elif d[count] == napry:\r\n poy -= 1\r\n count += 1\r\n print(count)", "t,sx,sy,ex,ey = map(int, input().split())\r\nl = input()\r\nd={'N':(0,1),'E':(1,0),'S':(0,-1),'W':(-1,0)} \r\ncnt = 0 \r\nwhile cnt < t and (sx,sy)!=(ex,ey):\r\n dx = abs(ex-sx)\r\n if abs(sx+d[l[cnt]][0]-ex) < dx:\r\n sx += d[l[cnt]][0]\r\n dy = abs(ey-sy)\r\n if abs(sy+d[l[cnt]][1]-ey) < dy:\r\n sy += d[l[cnt]][1]\r\n cnt += 1\r\n\r\nif (sx,sy)!=(ex,ey):\r\n print(-1)\r\nelse: print(cnt)\r\n\r\n", "t,sx,sy,tx,ty=map(int,input().split())\r\nss=str(input())\r\ne=-1\r\nw=-1\r\nn=-1\r\ns=-1\r\nif(sx-tx<0):\r\n e=tx-sx\r\nelif(sx-tx>0):\r\n w=sx-tx\r\nif(sy-ty<0):\r\n n=ty-sy\r\nelif(sy-ty>0):\r\n s=sy-ty\r\nt1='-1'\r\nt2='-1'\r\nn1=-1\r\nn2=-1\r\nif(e==-1 and w==-1):\r\n pass\r\nelif(w!=-1 and e==-1):\r\n t1='W'\r\n n1=w\r\nelse:\r\n t1='E'\r\n n1=e\r\nif(n==-1 and s==-1):\r\n pass\r\nelif(n!=-1 and s==-1):\r\n t2='N'\r\n n2=n\r\nelse:\r\n t2='S'\r\n n2=s\r\nc1=0\r\nc2=0\r\ntim=0\r\nf1=0\r\nf2=0\r\nff=0\r\nfor i in ss:\r\n if(t1!='-1' and f1==0 and i==t1):\r\n c1+=1\r\n elif(t2!='-1' and f2==0 and i==t2):\r\n c2+=1\r\n if(n1!=-1 and c1==n1):\r\n f1=1\r\n if(n2!=-1 and c2==n2):\r\n f2=1\r\n tim+=1\r\n if(n1!=-1 and n2==-1):\r\n if(c1==n1):\r\n ff=1\r\n break\r\n elif(n2!=-1 and n1==-1):\r\n if(c2==n2):\r\n ff=1\r\n break\r\n elif(n2!=-1 and n1!=-1):\r\n if(c1==n1 and c2==n2):\r\n ff=1\r\n break\r\n else:\r\n break\r\nif(ff==0):\r\n print(-1)\r\nelse:\r\n print(tim)", "n, x1, y1, x2, y2 = map(int, input().split())\r\ns = input()\r\npMoves = {'E':0, 'W':0, \"N\":0, 'S':0}\r\nf = 0\r\nsize = 0\r\nfor wind in s:\r\n\tsize+=1\r\n\tpMoves[wind]+=1\r\n\tx, y = x2-x1, y2-y1\r\n\tpos = [False, False]\r\n\tif(y < 0):\r\n\t\tpos[0] = pMoves['S']>=abs(y)\r\n\t\tif(x < 0):\r\n\t\t\tpos[1] = pMoves['W'] >= abs(x)\r\n\t\telse:\r\n\t\t\tpos[1] = pMoves['E'] >= x\r\n\telse:\r\n\t\tpos[0] = pMoves['N'] >= y\r\n\t\tif(x < 0):\r\n\t\t\tpos[1] = pMoves['W'] >= abs(x)\r\n\t\telse:\r\n\t\t\tpos[1] = pMoves['E'] >= x\r\n\tif(pos[1] and pos[0]):\r\n\t\tf = 1\r\n\t\tprint(size)\r\n\t\tbreak\r\nif(not f):\r\n\tprint(-1)", "n,sx,sy,ex,ey=map(int,input().split())\r\nif sx==ex and sy==ey:\r\n print(0)\r\n exit(0)\r\nelse:\r\n t=0\r\n for i in input():\r\n if sx<ex and i=='E':\r\n sx+=1\r\n elif sx>ex and i=='W':\r\n sx-=1\r\n # print(sx, end=\" \")\r\n elif sy<ey and i=='N':\r\n sy+=1\r\n # print(sy, end=\" \")\r\n elif sy>ey and i=='S':\r\n sy-=1\r\n # print(sy)\r\n t+=1\r\n if sx == ex and sy == ey:\r\n print(t)\r\n exit(0)\r\nprint(-1)", "import sys\r\nimport string\r\n\r\nfrom collections import Counter, defaultdict\r\nfrom math import fsum, sqrt, gcd, ceil, factorial\r\nfrom itertools import combinations, permutations\r\n\r\n# input = sys.stdin.readline\r\nflush = lambda: sys.stdout.flush\r\ncomb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)\r\n\r\n\r\n# inputs\r\n# ip = lambda : input().rstrip()\r\nip = lambda: input()\r\nii = lambda: int(input())\r\nr = lambda: map(int, input().split())\r\nrr = lambda: list(r())\r\n\r\n\r\nn, a, b, x, y = r()\r\ns = ip() + \"X\"\r\nt = defaultdict(lambda: 0)\r\n\r\nt[\"E\"] = x - a\r\nt[\"W\"] = a - x\r\n\r\nt[\"N\"] = y - b\r\nt[\"S\"] = b - y\r\n\r\nc = 0\r\nfor i in s:\r\n if not any(j>0 for j in t.values()):\r\n break\r\n \r\n c+= 1\r\n t[i] -= 1\r\n \r\nprint(c if c<=n else -1)", "t,sx,sy,ex,ey=map(int,input().split())\r\ns=[sx,sy]\r\ne=[ex,ey]\r\nd=input()\r\ndx = ex-sx\r\ndy = ey-sy\r\nfor i in range(t):\r\n if dx > 0 and d[i] == 'E':\r\n dx -= 1\r\n elif dx < 0 and d[i] == 'W':\r\n dx += 1\r\n elif dy > 0 and d[i] == 'N':\r\n dy -= 1\r\n elif dy < 0 and d[i] == 'S':\r\n dy += 1\r\n \r\n if dx == 0 and dy == 0:\r\n print(i+1)\r\n break\r\nelse:\r\n print(-1)", "from sys import stdin, stdout\r\nimport sys\r\nINF=1e11\r\nimport bisect\r\ndef get_int(): return int(stdin.readline().strip())\r\ndef get_ints(): return map(int,stdin.readline().strip().split()) \r\ndef get_array(): return list(map(int,stdin.readline().strip().split()))\r\ndef get_string(): return stdin.readline().strip()\r\ndef op(c): return stdout.write(c)\r\nfrom collections import defaultdict \r\nimport math\r\n#for _ in range(int(stdin.readline())):\r\nt,a,b,x,y=get_ints()\r\ns=get_string()\r\nans=0\r\nfor i in s:\r\n ans+=1\r\n if a<x:\r\n if i=='E':\r\n a+=1\r\n if i==\"W\":\r\n continue\r\n if a>x:\r\n if i=='W':\r\n a-=1 \r\n if i==\"E\":\r\n continue\r\n if b<y:\r\n if i==\"N\":\r\n b+=1\r\n if i==\"S\":\r\n continue\r\n if b>y:\r\n if i==\"S\":\r\n b-=1\r\n if i==\"N\":\r\n continue\r\n if a==x and b==y:\r\n break\r\nif a==x and b==y:\r\n print(ans)\r\nelse:\r\n print(-1)\r\n", "m=list(map(int,input().split()))\r\nn=list(map(str,input()))\r\nx=m[3]-m[1]\r\ny=m[4]-m[2]\r\nt=0\r\na=0\r\nfor i in range(m[0]):\r\n t+=1\r\n if(x<0):\r\n if(n[i]=='W'):\r\n x+=1\r\n if(x>0):\r\n if(n[i]=='E'):\r\n x-=1\r\n if(y<0):\r\n if(n[i]=='S'):\r\n y+=1\r\n if(y>0):\r\n if(n[i]=='N'):\r\n y-=1\r\n if(x==0 and y==0):\r\n print(t)\r\n a+=1\r\n break\r\nif(a==0):\r\n print(-1)", "t, s1, s2, e1, e2 = map(int, input().split())\r\nwind = list(input())\r\nnorth, south, east, west, seconds = 0, 0, 0, 0, 0\r\nif e1-s1 > 0:\r\n east += e1-s1\r\nelif e1-s1 < 0:\r\n west += abs(e1-s1)\r\nif e2-s2 > 0:\r\n north += e2-s2\r\nelif e2-s2 < 0:\r\n south += abs(e2-s2)\r\nfor i in range(len(wind)):\r\n if wind[i] == 'N' and north > 0:\r\n north -= 1\r\n elif wind[i] == 'E' and east > 0:\r\n east -= 1\r\n elif wind[i] == 'S' and south > 0:\r\n south -= 1\r\n elif wind[i] == 'W' and west > 0:\r\n west -= 1\r\n if north + south + east + west == 0:\r\n seconds += 1\r\n break\r\n elif north + south + east + west != 0 and i == len(wind)-1:\r\n seconds = -1\r\n else:\r\n seconds += 1 \r\nprint(seconds)\r\n", "t,s1,s2,d1,d2 = list(map(int,input().split()))\r\ndirections = list(input())\r\ncount = -1;flag = True\r\nfor i,d in enumerate(directions):\r\n if d == 'S' and s2 > d2:\r\n s2 -= 1\r\n elif d == 'N' and s2 < d2:\r\n s2 += 1\r\n elif d == 'E' and s1 < d1:\r\n s1 += 1;count += 1\r\n elif d == 'W' and s1 > d1:\r\n s1 -= 1;count += 1\r\n if s1 == d1 and s2 == d2:\r\n print(i+1)\r\n flag = False\r\n break\r\nif flag:\r\n print(-1)\r\n", "t, sx, sy, ex, ey = map(int, input().split())\r\nwind = input()\r\nN = max(0, ey-sy)\r\nS = max(0, sy-ey)\r\nE = max(0, ex-sx)\r\nW = max(0, sx-ex)\r\nd = {'N': N, 'S': S, 'E': E, 'W': W}\r\nsteps = 0\r\nfor c in wind:\r\n if sum(d.values()) == 0:\r\n break\r\n d[c] = max(0, d[c]-1)\r\n steps += 1\r\nprint(-1 if sum(d.values()) > 0 else steps)", "def main():\r\n t, sx, sy, ex, ey = map(int, input().split())\r\n s = input()\r\n\r\n ans = 0\r\n for i in s:\r\n if i == 'E':\r\n if sx + 1 <= ex:\r\n sx += 1\r\n ans += 1\r\n else:\r\n ans += 1\r\n elif i == 'W':\r\n if sx - 1 >= ex:\r\n sx -= 1\r\n ans += 1\r\n else:\r\n ans += 1\r\n elif i == 'N':\r\n if sy + 1 <= ey:\r\n sy += 1\r\n ans += 1\r\n else:\r\n ans += 1\r\n else:\r\n if sy - 1 >= ey:\r\n sy -= 1\r\n ans += 1\r\n else:\r\n ans += 1\r\n\r\n if sx == ex and sy == ey:\r\n print(ans)\r\n exit()\r\n\r\n print(-1)\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain()\r\n", "n, sx, sy, ex, ey = map(int, input().split())\r\nwind = input()\r\ndirections = {'N': [0, 1], 'E': [1, 0], 'S': [0, -1], 'W': [-1, 0]}\r\nt = -1\r\nfor i in range(n):\r\n d = directions[wind[i]]\r\n if (abs(ex - (sx + d[0])) + abs(ey - (sy + d[1])) < abs(ex - sx) + abs(ey - sy)):\r\n sx += d[0]\r\n sy += d[1]\r\n if (sx == ex and sy == ey):\r\n t = i + 1\r\n break\r\nprint (t)", "import sys\r\ninput = lambda: sys.stdin.readline().strip(\"\\r\\n\")\r\n\r\nt, sx, sy, ex, ey = map(int, input().split())\r\ndirections = input()\r\ndx, dy = ex - sx, ey - sy\r\nif dx == 0 and dy == 0:\r\n print(0)\r\n exit(0)\r\nfor i, move in enumerate(directions):\r\n if dx < 0 and move == 'W':\r\n dx += 1\r\n elif dx > 0 and move == 'E':\r\n dx -= 1\r\n elif dy < 0 and move == 'S':\r\n dy += 1\r\n elif dy > 0 and move == 'N':\r\n dy -= 1\r\n if dx == 0 and dy == 0:\r\n print(i + 1)\r\n break\r\nelse:\r\n print(\"-1\")\r\n\r\n", "from collections import defaultdict\n# If we are not alowed to skip any moves, the solution is trivial\n# if I calculate answer to trivial solution while recording the number of SNWE directions we had\n# we can see if the target has ever been in range\n# if this solution is viable it will only give us if we can reach there or not, \n# but if it also gives us what directions we need to skip, it is trivial to calculate the time\n# I overly complicated it, being able to skip moves is not a complication but rather a simplification\n# we only need to count how many SNEW we need to get to the location\n_, sx, sy, ex, ey = map(int, input().split())\ndirs = input()\nd = defaultdict(int) \nans = -1\n\nfor t, e in enumerate(dirs):\n if e == 'S' and sy > ey:\n sy -= 1\n if e == 'N' and sy < ey:\n sy += 1\n if e == 'W' and sx > ex: \n sx -= 1\n if e == 'E' and sx < ex: \n sx += 1\n if sx == ex and sy == ey: \n ans = t + 1\n break\nprint(ans)\n\n\n", "import math \r\ndef getDis(x1,y1,x2,y2):\r\n return math.sqrt((x1-x2)**2+(y1-y2)**2)\r\n\r\ndef newVar(dir,i,x,y):\r\n if dir[i]=='E':\r\n return x+1,y\r\n elif dir[i]=='W':\r\n return x-1,y\r\n elif dir[i]=='N':\r\n return x,y+1\r\n elif dir[i]=='S':\r\n return x,y-1 \r\n\r\n\r\nt,sx,sy,ex,ey=map(int,input().split())\r\ndir=input()\r\ntm=-1\r\nfor i in range(1,t+1):\r\n xn,yn=newVar(dir,i-1,sx,sy)\r\n if getDis(xn,yn,ex,ey)<getDis(sx,sy,ex,ey):\r\n sx,sy=xn,yn\r\n if sx==ex and sy==ey:\r\n tm=i\r\n break \r\nprint(tm) ", "var1 = input().split(\" \")\r\nvar2 = input()\r\ngoalx = int(var1[3]) -int(var1[1])\r\ngoaly = int(var1[4])- int(var1[2])\r\nhor = \"\"\r\nvert = \"\"\r\nxd = 0\r\nyd = 0\r\n\r\nif goalx > 0:\r\n hor = \"E\"\r\n xd = 1\r\nelse:\r\n hor = \"W\"\r\n xd = -1\r\n\r\nif goaly > 0:\r\n vert = \"N\"\r\n yd = 1\r\nelse:\r\n vert = \"S\"\r\n yd = -1\r\nx = 0\r\ny = 0\r\n\r\nfor num in range(int(var1[0])):\r\n if var2[num] == hor:\r\n if x != goalx:\r\n x += xd\r\n elif var2[num] == vert:\r\n if y != goaly:\r\n y += yd\r\n if x == goalx and y == goaly:\r\n print(int(num)+1)\r\n break\r\nif x != goalx or y != goaly:\r\n print(\"-1\")\r\n", "l=list(map(int,input().split()))\r\nt,x,y,p,q=l[0],l[1],l[2],l[3],l[4]\r\ns,n,e,w=0,0,0,0\r\nbabe=input()\r\nif p-x>=0:\r\n e=p-x\r\nelse:\r\n w=x-p\r\nif q-y>=0:\r\n n=q-y\r\nelse:\r\n s=y-q\r\nif (p-x==0) and (q-y==0):\r\n print(0)\r\nelse: \r\n for i in range(t):\r\n if babe[i]==\"S\":\r\n if s>0:\r\n s-=1\r\n elif babe[i]==\"N\":\r\n if n>0:\r\n n-=1\r\n elif babe[i]==\"E\":\r\n if e>0:\r\n e-=1\r\n elif babe[i]==\"W\":\r\n if w>0:\r\n w-=1\r\n if s==e==n==w==0:\r\n print(i+1)\r\n break\r\n else:\r\n print(-1)", "def solve():\r\n t, sx, sy, ex, ey = [int(i) for i in input().split()]\r\n d = input()\r\n if sx <= ex:\r\n lfx = 'E'\r\n lfxk = ex - sx\r\n else:\r\n lfx = 'W'\r\n lfxk = sx - ex\r\n if sy <= ey:\r\n lfy = 'N'\r\n lfyk = ey - sy\r\n else:\r\n lfy = 'S'\r\n lfyk = sy - ey\r\n t = 0\r\n while t < len(d):\r\n if d[t] == lfx and lfxk != 0:\r\n lfxk -= 1\r\n if d[t] == lfy and lfyk != 0:\r\n lfyk -= 1\r\n if lfxk == 0 and lfyk == 0:\r\n break\r\n t += 1\r\n return t + 1 if lfxk == 0 and lfyk == 0 else -1\r\n\r\n\r\nprint(solve())", "import sys\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\nsys.setrecursionlimit(20000)\n\nt, s_x, s_y, e_x, e_y = get_ints()\nA = input()\n\nxx = e_x - s_x \nyy = e_y - s_y\n\nfor i, a in enumerate(A):\n if a == 'E':\n if xx > 0:\n xx-= 1\n else:\n pass # stay\n if a == 'W':\n if xx < 0:\n xx+= 1\n else:\n pass # stay\n if a == 'N':\n if yy > 0:\n yy-= 1\n else:\n pass # stay\n if a == 'S':\n if yy < 0:\n yy+= 1\n else:\n pass # stay\n\n if xx == 0 and yy == 0:\n print(i+1)\n exit()\n\nprint(-1)\n", "# for _ in range(0, int(input())): \n# n = int(input())\n\n\n\n\n\nimport math\nt, sx, sy, ex, ey = map(int, input().strip().split())\nl = list(input().strip())\n\nf=0\ncounter = 0\ncurrent_step = [sx, sy]\ndestination=[ex,ey]\ncurrent_distance=math.sqrt((current_step[0]-destination[0])**2+(current_step[1]-destination[1])**2)\n# print(current_distance)\nwhile t > 0:\n\td = l[counter]\n\t# print(d) \n\t# possible_step = []\n\tif d=='N': possible_step = [current_step[0], current_step[1]+1]\n\tif d=='S': possible_step = [current_step[0], current_step[1]-1]\n\tif d=='E': possible_step = [current_step[0]+1, current_step[1]]\n\tif d=='W': possible_step = [current_step[0]-1, current_step[1]] \n\n\tpossible_distance = math.sqrt((possible_step[0]-destination[0])**2 + (possible_step[1]-destination[1])**2)\n\tif possible_distance < current_distance:\n\t\tcurrent_step = possible_step\n\t\tcurrent_distance = possible_distance \n\tif current_distance == 0:\n\t\tprint(counter+1)\n\t\tf = 8\n\t\tbreak\n\tt-=1\n\tcounter+=1\nif f ==0: print(-1)", "n, a, b, c, z = map(int, input().split())\r\nd = {}\r\n\r\ndiff_x = c-a\r\ndiff_y = z-b\r\n\r\nif diff_x < 0:\r\n d['W'] = abs(diff_x)\r\nif diff_x > 0:\r\n d['E'] = abs(diff_x)\r\n\r\nif diff_y < 0:\r\n d['S'] = abs(diff_y)\r\nif diff_y > 0:\r\n d['N'] = abs(diff_y)\r\n\r\nok = False\r\nfor i,c in enumerate(input().strip()):\r\n if c in d:\r\n d[c] -= 1\r\n if d[c] == 0:\r\n del d[c]\r\n if not d:\r\n print(i+1)\r\n ok = True\r\n break\r\n\r\nif not ok:\r\n print(-1)", "import sys\r\ninput = lambda:sys.stdin.readline()\r\n\r\nint_arr = lambda: list(map(int,input().split()))\r\nstr_arr = lambda: list(map(str,input().split()))\r\nget_str = lambda: map(str,input().split())\r\nget_int = lambda: map(int,input().split())\r\nget_flo = lambda: map(float,input().split())\r\n\r\nmod = 1000000007\r\n\r\ndef solve(n,a,b,x,y,s):\r\n xx,yy = x-a,y-b\r\n \r\n if xx >= 0 and yy >= 0:\r\n for i in range(n):\r\n if s[i] == \"E\" and xx > 0:\r\n xx -= 1\r\n if s[i] == \"N\" and yy > 0:\r\n yy -= 1\r\n if xx == 0 and yy == 0:\r\n print(i+1)\r\n return\r\n else:\r\n print(\"-1\")\r\n return\r\n\r\n elif xx < 0 and yy < 0:\r\n for i in range(n):\r\n if s[i] == \"W\" and xx < 0:\r\n xx += 1\r\n if s[i] == \"S\" and yy < 0:\r\n yy += 1\r\n if xx == 0 and yy == 0:\r\n print(i+1)\r\n return\r\n else:\r\n print(\"-1\")\r\n return\r\n\r\n\r\n elif xx < 0 and yy >= 0:\r\n for i in range(n):\r\n if s[i] == \"W\" and xx < 0:\r\n xx += 1\r\n if s[i] == \"N\" and yy > 0:\r\n yy -= 1\r\n if xx == 0 and yy == 0:\r\n print(i+1)\r\n return\r\n else:\r\n print(\"-1\")\r\n return\r\n\r\n\r\n elif xx >= 0 and yy < 0:\r\n for i in range(n):\r\n if s[i] == \"E\" and xx > 0:\r\n xx -= 1\r\n if s[i] == \"S\" and yy < 0:\r\n yy += 1\r\n if xx == 0 and yy == 0:\r\n print(i+1)\r\n return\r\n else:\r\n print(\"-1\")\r\n return\r\n\r\n else:\r\n print(\"-1\")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n# for _ in range(int(input())):\r\nn,a,b,x,y = get_int()\r\ns = str(input())[:-1]\r\nsolve(n,a,b,x,y,s)\r\n", "t, sx, sy, ex, ey = map(int, input().split())\r\ns = input()\r\nfor i in range(t):\r\n if sx == ex and sy == ey:\r\n print(i+1)\r\n exit()\r\n if ey > sy and s[i] == \"N\":\r\n sy += 1\r\n if ey < sy and s[i] == \"S\":\r\n sy -= 1\r\n if ex > sx and s[i] == \"E\":\r\n sx += 1\r\n if ex < sx and s[i] == \"W\":\r\n sx -= 1\r\n if sx == ex and sy == ey:\r\n print(i+1)\r\n exit()\r\nprint(-1 if (sx != ex or sy != ey) else t)", "X = list(map(int, input().split()))\r\nXTotal, YTotal = X[-2] - X[1], X[-1] - X[2]\r\nS, Cnt = input(), 0\r\nfor i in S:\r\n if XTotal == 0 and YTotal == 0:\r\n print(Cnt)\r\n exit()\r\n if i in 'EW':\r\n if XTotal > 0 and i == 'E': XTotal -= 1\r\n if XTotal < 0 and i == 'W': XTotal += 1\r\n else:\r\n if YTotal > 0 and i == 'N': YTotal -= 1\r\n if YTotal < 0 and i == 'S': YTotal += 1\r\n Cnt += 1\r\n if XTotal == 0 and YTotal == 0:\r\n print(Cnt)\r\n exit()\r\nprint(-1)\r\n# Let's see who is the best !!!\r\n# ravenS_The_Best\r\n", "t,sx,sy,ex,ey = map(int,input().split())\r\ns = input()\r\ndic = {\"N\":0,\"S\":0,\"E\":0,\"W\":0}\r\nfor i in range(len(s)):\r\n\tdic[s[i]] +=1\r\npassed = -1\r\nif (sx>=ex and dic[\"W\"]>=(sx-ex)):\r\n\tif (sy>=ey and dic[\"S\"]>=(sy-ey)):\r\n \t\tpassed =0\r\n\telif (ey>sy and dic[\"N\"]>=(ey-sy)):\r\n\t\tpassed =1\r\nelif (ex>sx and dic[\"E\"]>=(ex-sx)):\r\n\tif (sy>=ey and dic[\"S\"]>=(sy-ey)):\r\n \t\tpassed =2\r\n\telif (ey>sy and dic[\"N\"]>=(ey-sy)):\r\n\t\tpassed =3\r\ndic = {\"N\":0,\"S\":0,\"E\":0,\"W\":0}\r\nif (passed == 0):\r\n\tfor i in range(len(s)):\r\n\t\tdic[s[i]] +=1\r\n\t\tif (dic[\"W\"]>=(sx-ex) and dic[\"S\"]>=(sy-ey)):\r\n\t\t\tprint(i+1)\r\n\t\t\texit()\r\nelif (passed == 1):\r\n\tfor i in range(len(s)):\r\n\t\tdic[s[i]] +=1\r\n\t\tif (dic[\"W\"]>=(sx-ex) and dic[\"N\"]>=(ey-sy)):\r\n\t\t\tprint(i+1)\r\n\t\t\texit()\r\nelif (passed == 2):\r\n\tfor i in range(len(s)):\r\n\t\tdic[s[i]] +=1\r\n\t\tif (dic[\"E\"]>=(ex-sx) and dic[\"S\"]>=(sy-ey)):\r\n\t\t\tprint(i+1)\r\n\t\t\texit()\r\nelif (passed == 3):\r\n\tfor i in range(len(s)):\r\n\t\tdic[s[i]] +=1\r\n\t\tif (dic[\"E\"]>=(ex-sx) and dic[\"N\"]>=(ey-sy)):\r\n\t\t\tprint(i+1)\r\n\t\t\texit()\r\nelse:\r\n\tprint(-1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "a=list(map(int,input().split()))\r\nt,bx,by,dx,dy=a[0],a[1],a[2],a[3],a[4]\r\ndifx=bx-dx\r\ndify=by-dy\r\ns=input()\r\nix,iy=-1,-1\r\nif(difx<0):\r\n c=1\r\n for i in s:\r\n if(i=='E'):\r\n difx=difx+1\r\n if(difx==0):\r\n ix=c\r\n c=c+1\r\nelif(difx>0):\r\n c=1\r\n for i in s:\r\n if(i=='W'):\r\n difx=difx-1\r\n if(difx==0):\r\n ix=c\r\n c=c+1\r\nelse:\r\n ix=0\r\n\r\nif(dify<0):\r\n c=1\r\n for i in s:\r\n if(i=='N'):\r\n dify=dify+1\r\n if(dify==0):\r\n iy=c\r\n c=c+1\r\nelif(dify>0):\r\n c=1\r\n for i in s:\r\n if(i=='S'):\r\n dify=dify-1\r\n if(dify==0):\r\n iy=c\r\n c=c+1\r\nelse:\r\n iy=0\r\n\r\nif(ix==-1 or iy==-1):\r\n print(-1)\r\nelse:\r\n print(max(ix,iy))\r\n\r\n\r\n\r\n", "def str2list(stringa):\r\n lista = list()\r\n for i in range(len(stringa)):\r\n lista.append(stringa[i])\r\n return lista\r\n\r\n\r\nt, sx, sy, ex, ey = map(int, input().split())\r\nx, y = ex - sx, ey - sy\r\nventi = str2list(input())\r\nif x == 0 and y == 0:\r\n print(0)\r\nelse:\r\n t = 0\r\n bul = False\r\n for c in venti:\r\n if c == \"N\" and y > 0:\r\n y -= 1\r\n elif c == \"S\" and y < 0:\r\n y += 1\r\n elif c == \"W\" and x < 0:\r\n x += 1\r\n elif c == \"E\" and x > 0:\r\n x -= 1\r\n t += 1\r\n if x == 0 and y == 0:\r\n bul = True\r\n break\r\n if bul:\r\n print(t)\r\n else:\r\n print(-1)", "from sys import stdin\nfrom collections import defaultdict, deque, Counter\nfrom math import floor, ceil, log, inf, sqrt\nfrom heapq import *\nfrom functools import lru_cache\nfrom bisect import bisect_left, bisect_right\nimport itertools\nimport random\nfrom string import ascii_lowercase\n\nT,SX,SY,EX,EY = map(int, stdin.readline().split())\ndirs = stdin.readline().strip()\nx1,x2,y1,y2 = SX,SX,SY,SY\n\nfor i in range(len(dirs)):\n if dirs[i] == \"N\":\n y2 += 1\n if dirs[i] == \"S\":\n y1 -= 1\n if dirs[i] == \"E\":\n x2 += 1\n if dirs[i] == \"W\":\n x1 -= 1\n\n if x1 <= EX <= x2 and y1 <= EY <= y2:\n print(i+1)\n quit()\n \nprint(-1)\n\n \t\t \t\t\t \t \t\t\t \t\t \t\t \t\t \t\t \t", "from math import sqrt\r\n\r\nt, sx, sy, ex, ey = [int(x) for x in input().split(' ')]\r\nwind = list(input())\r\narrive_time = -1\r\nfound = False\r\n\r\nfor i in range(t):\r\n prev = (sx, sy)\r\n prev_distance = sqrt((ex - sx) ** 2 + (ey - sy) ** 2)\r\n if wind[i] == \"S\":\r\n sy -= 1\r\n elif wind[i] == \"E\":\r\n sx += 1\r\n elif wind[i] == \"W\":\r\n sx -= 1\r\n else:\r\n sy += 1\r\n\r\n new_distance = sqrt((ex - sx) ** 2 + (ey - sy) ** 2)\r\n if prev_distance < new_distance:\r\n sx = prev[0]\r\n sy = prev[1]\r\n\r\n if sx == ex and sy == ey:\r\n arrive_time = i\r\n found = True\r\n break\r\n\r\nif found:\r\n print(arrive_time + 1)\r\nelse:\r\n print(-1)", "from math import sqrt\n\ndef main():\n t, sx, sy, ex, ey = list(map(int, input().split(' ')))\n elems = input()\n\n directions = {\n 'N': lambda x, y: (x, y + 1),\n 'S': lambda x, y: (x, y - 1),\n 'E': lambda x, y: (x + 1, y),\n 'W': lambda x, y: (x - 1, y)\n }\n dist = lambda x, y: sqrt((ex - x)**2 + (ey - y)**2)\n\n d = dist(sx, sy)\n count = 0\n for w in elems:\n cx, cy = directions[w](sx, sy)\n new_d = dist(cx, cy)\n if new_d < d:\n sx, sy = cx, cy\n d = new_d\n count += 1\n if sx == ex and sy == ey:\n break\n if sx == ex and sy == ey:\n print(count)\n else:\n print(-1)\n\n\nif __name__ == \"__main__\":\n main()\n", "t, sx, sy, ex, ey = map(int,input().split())\ndirs = input()\nneedx, needy = ex-sx, ey-sy\nneededString = ''\nif needx == 0:\n if needy == 0:\n neededString = ''\n elif needy < 0:\n neededString += 'S'*abs(needy)\n else:#more than 0\n neededString += 'N'*needy\nelif needy == 0:\n if needx < 0:\n neededString += 'W'*abs(needx)\n else:#more than 0\n neededString += 'E'*needx\nelse:\n if needx < 0:\n neededString += 'W'*abs(needx)\n else:#more than 0\n neededString += 'E'*needx\n if needy < 0:\n neededString += 'S'*abs(needy)\n else:#more than 0\n neededString += 'N'*needy\npos = 0\nneededStringHash = {}\nfor _ in range(len(neededString)):\n if neededString[_] in neededStringHash.keys():\n neededStringHash[neededString[_]] += 1\n else:\n neededStringHash[neededString[_]] = 1\nfor _ in range(len(dirs)):\n if len(neededStringHash) == 0:\n break\n if dirs[_] in neededStringHash.keys():\n neededStringHash[dirs[_]]-=1\n if neededStringHash.get(dirs[_])==0:\n del neededStringHash[dirs[_]]\n pos = _\nif len(neededStringHash)==0:\n print(pos+1)\nelse:\n print(-1)", "t, sx, sy, ex, ey = map(int, input().split())\r\n\r\ns = input() + \"$\"\r\nans = -1\r\nfor j, i in enumerate(s):\r\n if sx < ex and i == 'E':\r\n sx += 1\r\n elif sx > ex and i == 'W':\r\n sx -= 1\r\n\r\n if sy < ey and i == \"N\":\r\n sy += 1\r\n elif sy > ey and i == \"S\":\r\n sy -= 1\r\n if sx == ex and sy == ey:\r\n ans = j + 1\r\n break\r\nprint(ans)\r\n", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nt,s1,s2,e1,e2=(int(i) for i in input().split())\r\ns=input()\r\nk=-1\r\nfor i in range(len(s)):\r\n if(e1<s1 and s[i]=='W'):\r\n s1-=1\r\n elif(e1>s1 and s[i]=='E'):\r\n s1+=1\r\n elif(e2<s2 and s[i]=='S'):\r\n s2-=1\r\n elif(e2>s2 and s[i]=='N'):\r\n s2+=1\r\n if(s1==e1 and s2==e2):\r\n k=i+1\r\n break\r\nprint(k)", "t, sx, sy, ex, ey = [int(i) for i in input().split()]\r\ns = input()\r\nX = ex - sx\r\nY = ey - sy\r\nres = -1\r\n\r\nfor i in range(t):\r\n if X > 0 and s[i] == 'E':\r\n X -= 1\r\n elif X < 0 and s[i] == 'W':\r\n X += 1\r\n\r\n if Y > 0 and s[i] == 'N':\r\n Y -= 1\r\n elif Y < 0 and s[i] == 'S':\r\n Y += 1\r\n\r\n if X == 0 and Y == 0:\r\n res = i+1\r\n break\r\n\r\nprint(res)\r\n", "t, s_x, s_y, e_x, e_y = map(int, input().split())\ns = input()\ns_x_flag = True\ns_y_flag = True\ndiff_x = e_x-s_x\ndiff_y = e_y-s_y\nfor i, c in enumerate(s):\n if diff_x > 0 and c == 'E' and s_x_flag:\n diff_x -= 1\n elif diff_x < 0 and c == 'W' and s_x_flag:\n diff_x += 1\n elif diff_y > 0 and c == 'N' and s_y_flag:\n diff_y -= 1\n elif diff_y < 0 and c == 'S' and s_y_flag:\n diff_y += 1\n\n if diff_x == 0:\n s_x_flag = False\n if diff_y == 0:\n s_y_flag = False\n\n if s_x_flag == False and s_y_flag == False:\n print(i+1)\n break\nelse:\n print(-1)\n", "t, x1, y1, x2, y2 = map(int, input().split())\nstring = input()[:t]\ncount = 0\ntime = 0\nn = 0\nfor i in string:\n if x2 > x1:\n if i == \"E\":\n x1 += 1\n count += 1\n if x2 < x1:\n if i == \"W\":\n x1 -= 1\n count += 1\n if y2 > y1:\n if i == \"N\":\n y1 += 1\n count += 1\n if y2 < y1:\n if i == \"S\":\n y1 -= 1\n count += 1\n time += 1\n n = time + 1\n if x1 == x2 and y1 == y2:\n break\nif x1 == x2 and y1 == y2:\n print(time)\nelse:\n print(-1)\n\n \t \t \t\t\t\t\t \t \t\t \t\t \t\t \t\t", "m,a,ay,b,by=map(int,input().split());s=input()+'0'\r\nx='W'if a>b else 'E'\r\ny='S'if ay>by else 'N'\r\nc,d=abs(a-b),abs(ay-by)\r\nfor i in range(m):\r\n\tif s[i]==x and c>0:c-=1\r\n\tif s[i]==y and d>0:d-=1\r\n\tif c==d==0:print(i+1);break\r\nelse:print(-1)", "def solve():\r\n n,sx,sy,ex,ey = map(int, input().split())\r\n s = input()\r\n i=0\r\n while i<n :\r\n if sx==ex and sy == ey:\r\n break\r\n else:\r\n if sx < ex and s[i] == \"E\":\r\n sx+=1\r\n elif sx > ex and s[i] == \"W\":\r\n sx-=1\r\n if sy < ey and s[i] == \"N\":\r\n sy+=1\r\n elif sy > ey and s[i] == \"S\":\r\n sy-=1\r\n i+=1\r\n if i==n and (not sx == ex or not sy == ey):\r\n print(-1)\r\n return\r\n else:\r\n print(i)\r\n return\r\ntry:\r\n solve()\r\nexcept:\r\n pass", "t, sx, sy, ex, ey = list(map(int, input().split()))\nwind = input()\nh = 'X'\nv = 'X'\ndx = sx - ex\ndy = sy - ey\n\nif dx < 0 :\n h = 'E'\nelif dx > 0 :\n h = 'W'\n\nif dy < 0 :\n v = 'N'\nelif dy > 0 :\n v = 'S'\n\ndx = abs(dx)\ndy = abs(dy)\n\ntime = 0\nfor i in wind :\n if dx > 0 or dy > 0 :\n if i == h :\n dx = dx - 1\n if i == v :\n dy = dy - 1\n else :\n break\n time = time + 1\n\nif dx < 1 and dy < 1 :\n print(time)\nelse :\n print(-1)", "import sys \r\ninput = sys.stdin.readline \r\nfrom collections import Counter , defaultdict\r\ndef instr():\r\n return input()[:-1]\r\nimport math \r\n############################\r\nt, s1, s2, e1, e2 = map(int, input().split())\r\nseconds = 0\r\nwind = instr()\r\nx = [\"\", 0]\r\ny =[\"\", 0]\r\nif e1 >= s1 :\r\n x[0] = \"E\"\r\n x[1] = abs(e1 - s1)\r\nelif e1 < s1 :\r\n x[0] = \"W\"\r\n x[1] = abs(e1 - s1)\r\nif e2 >= s2 :\r\n y[0] = \"N\"\r\n y[1] = abs(e2 - s2)\r\nelif e2 < s2 :\r\n y[0] = \"S\"\r\n y[1] = abs(e2 - s2)\r\n\r\nfor i in wind :\r\n if x[1] <= 0 and y[1] <= 0 :\r\n print(seconds)\r\n break\r\n else :\r\n if i == x[0] :\r\n x[1] -= 1\r\n elif i == y[0] :\r\n y[1] -= 1\r\n seconds += 1\r\nelse :\r\n if x[1] <= 0 and y[1] <= 0 :\r\n print(seconds)\r\n else :\r\n print(-1)\r\n \r\n\r\n", "t, sx, sy, ex, ey = map(int, input().split())\r\neast, west, north, south = (0,0,0,0)\r\ns = input()\r\nif ex - sx >= 0:\r\n\teast = ex-sx\r\nelse:\r\n\twest = sx-ex\r\nif ey - sy >= 0:\r\n\tnorth = ey - sy\r\nelse:\r\n\tsouth = sy - ey\r\n\r\nec, sc, wc, nc = (0,0,0,0)\r\nfor i in range(t):\r\n\tif s[i] == \"E\":\r\n\t\tec += 1\r\n\telif s[i] == \"S\":\r\n\t\tsc += 1\r\n\telif s[i] == \"W\":\r\n\t\twc += 1\r\n\telse:\r\n\t\tnc += 1\r\n\tif ec >= east and wc >= west and nc >= north and sc >= south:\r\n\t\tprint (i+1)\r\n\t\texit()\r\nprint (-1)", "n,a,b,c,d=map(int,input().split())\r\ns=input()\r\nfor i in range(n):\r\n\tif s[i]=='N' and d>b:\r\n\t\tb+=1\r\n\tif s[i]=='S'and d<b:\r\n\t\tb-=1\r\n\tif s[i]=='E'and c>a:\r\n\t\ta+=1\r\n\tif s[i]=='W'and c<a:\r\n\t\ta-=1\r\n\tif a==c and b==d:\r\n\t\tprint(i+1)\r\n\t\tbreak\r\nelse:\r\n\tprint(-1)", "n_and_coords = input()\r\ndirections = input()\r\n\r\ndef sail():\r\n n_coord_arr = [int(k) for k in n_and_coords.split()]\r\n n, sx, sy, ex, ey = n_coord_arr\r\n diff_x, diff_y = ex - sx, ey - sy\r\n # print(diff_x, diff_y)\r\n obj = {\r\n 'E': [1, 0],\r\n 'S': [0, -1],\r\n 'W': [-1, 0],\r\n 'N': [0, 1]\r\n }\r\n\r\n for i, char in enumerate(directions):\r\n dx, dy = obj[char]\r\n if abs(diff_x - dx) < abs(diff_x) or abs(diff_y - dy) < abs(diff_y):\r\n diff_x -= dx\r\n diff_y -= dy\r\n\r\n if diff_x == 0 and diff_y == 0:\r\n return i + 1\r\n return -1\r\n\r\nprint(sail())", "t, sx, sy, ex, ey = map(int, input().split(' '))\r\n\r\na = list(input())\r\n\r\ni = 0\r\nwhile i < t and (sx != ex or sy != ey):\r\n if a[i] == \"N\" and sy < ey:\r\n sy += 1\r\n if a[i] == \"S\" and sy > ey:\r\n sy -= 1\r\n if a[i] == \"E\" and sx < ex:\r\n sx += 1\r\n if a[i] == \"W\" and sx > ex:\r\n sx -= 1\r\n \r\n i += 1\r\n\r\nif sx == ex and sy == ey:\r\n print(i)\r\nelse:\r\n print(-1)", "\ndef main():\n (t, sx, sy, ex, ey) = map(int, input().split(' '))\n if sx == ex and sy == ey:\n return 0\n t = 0\n for c in list(input()):\n if sx == ex and sy == ey:\n return t\n if c == 'S':\n if ey < sy:\n sy -= 1\n elif c == 'N':\n if ey > sy:\n sy += 1\n elif c == 'E':\n if ex > sx:\n sx += 1\n elif c == 'W':\n if ex < sx:\n sx -= 1\n t += 1\n if sx == ex and sy == ey:\n return t\n return -1\n\nprint(main())\n", "t,x1,y1,x2,y2=map(int,input().split())\ns=input()\nx=x2-x1\ny=y2-y1\ne=0\nn=0\nfor i in range(t):\n\tif s[i]==\"S\" and y<0 and n>y:\n\t\tn-=1\n\telif s[i]==\"N\" and y>0 and n<y:\n\t\tn+=1\n\telif s[i]==\"E\" and x>0 and e<x:\n\t\te+=1\n\telif s[i]==\"W\" and x<0 and e>x:\n\t\te-=1\n\tif n==y and e==x:\n\t\tprint(i+1)\n\t\texit()\nprint(-1)\n", "t,x,y,x1,y1 =map(int,input().split())\r\ns=input()\r\nk=0\r\nwhile (x!=x1 or y!=y1) :\r\n if k==t :\r\n print(-1)\r\n exit()\r\n if s[k]==\"S\" and y>y1 :\r\n y-=1\r\n if s[k]==\"N\" and y<y1 :\r\n y+=1\r\n if s[k]==\"W\" and x>x1:\r\n x-=1\r\n if s[k]==\"E\" and x<x1:\r\n x+=1\r\n k+=1\r\n \r\nprint(k)\r\n", "a=list(map(int,input().split(\" \")))\r\nn=input()\r\nn.split()\r\nn=list(n)\r\nc1=a[1]-a[3]\r\nc2=a[2]-a[4]\r\nl=0\r\nm=0\r\nif c1>0:\r\n for i in range(len(n)):\r\n if n[i]==\"W\":\r\n c1-=1\r\n if c1==0:\r\n l=i+1\r\n break\r\nif c1<0:\r\n for i in range(len(n)):\r\n if n[i]==\"E\":\r\n c1+=1\r\n if c1==0:\r\n l=i+1\r\n break\r\nif c2>0:\r\n for j in range(len(n)):\r\n if n[j]==\"S\":\r\n c2-=1\r\n if c2==0:\r\n m=j+1\r\n break\r\nif c2<0:\r\n for j in range(len(n)):\r\n if n[j]==\"N\":\r\n c2+=1\r\n if c2==0:\r\n m=j+1\r\n break\r\nif c1+c2==0:\r\n if l>m:\r\n print(l)\r\n else:\r\n print(m)\r\nif c1+c2!=0:\r\n print(-1)", "arr = list(map(int, input().split(\" \")))\r\n\r\nt = arr[0]\r\ns = [arr[1], arr[2]]\r\nd = [arr[3], arr[4]]\r\n\r\nstr = input()\r\n\r\ny_mov = d[1] - s[1]\r\nx_mov = d[0] - s[0]\r\n\r\ndirections = []\r\n\r\nif(x_mov<0):\r\n directions.append(\"W\")\r\nelif(x_mov>0):\r\n directions.append(\"E\")\r\nelif(x_mov==0):\r\n directions.append(0)\r\n\r\nif(y_mov<0):\r\n directions.append(\"S\")\r\nelif(y_mov>0):\r\n directions.append(\"N\")\r\nelif(y_mov==0):\r\n directions.append(0)\r\n\r\nct = [0, 0]\r\nmax_sec = 0\r\nflag1 = 0\r\nflag2 = 0\r\nflag3 = 0\r\nfor i in range(len(str)):\r\n for j in range(len(directions)):\r\n if(str[i]==directions[j]):\r\n ct[j]+=1\r\n max_sec = (i+1)\r\n \r\n if(ct[0]==abs(x_mov)):\r\n flag1 = 1\r\n if(ct[1]==abs(y_mov)):\r\n flag2 = 1\r\n \r\n if(flag1==1 and flag2==1):\r\n flag3 = 1\r\n break\r\n \r\n if(flag3==1):\r\n break\r\n \r\nif(flag3==0):\r\n print(-1)\r\nelse:\r\n print(max_sec)", "# from collections import Counter\r\nt,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nh_dist = abs(sx-ex)\r\nh_dir = \"E\" if ex>=sx else \"W\"\r\nv_dist = abs(sy-ey)\r\nv_dir = \"N\" if ey>=sy else \"S\"\r\n\r\nif s.count(h_dir)<h_dist or s.count(v_dir)<v_dist:\r\n print(-1)\r\nelse:\r\n s=s.replace(h_dir,\"_\",h_dist)\r\n s=s.replace(v_dir,\"_\",v_dist)\r\n print(s.rfind(\"_\")+1)", "# cook your dish here\r\nfrom collections import Counter\r\nt,sx,sy,ex,ey = map(int,input().split())\r\ns=input()\r\nd = Counter(s)\r\n\r\nif ex>sx and ey>sy:\r\n if d['E']>=ex-sx and d['N']>=ey-sy:\r\n east,north=0,0\r\n i=0\r\n while north<ey-sy or east<ex-sx:\r\n if s[i]=='E':\r\n east+=1\r\n \r\n if s[i]=='N':\r\n north+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)\r\n \r\n \r\nelif ex>sx and ey<sy:\r\n if d['E']>=ex-sx and d['S']>=sy-ey:\r\n east,south=0,0\r\n i=0\r\n while south<sy-ey or east<ex-sx:\r\n if s[i]=='E':\r\n east+=1\r\n \r\n if s[i]=='S':\r\n south+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)\r\n \r\nelif ex<sx and ey>sy:\r\n if d['W']>=sx-ex and d['N']>=ey-sy:\r\n west,north=0,0\r\n i=0\r\n while west<sx-ex or north<ey-sy:\r\n if s[i]=='W':\r\n west+=1\r\n \r\n if s[i]=='N':\r\n north+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)\r\n \r\nelif ex<sx and ey<sy:\r\n if d['W']>=sx-ex and d['S']>=sy-ey:\r\n west,south=0,0\r\n i=0\r\n while south<sy-ey or west<sx-ex:\r\n if s[i]=='W':\r\n west+=1\r\n \r\n if s[i]=='S':\r\n south+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)\r\n \r\nelif ex>sx and ey==sy:\r\n if d['E']>=ex-sx:\r\n east=0\r\n i=0\r\n while east<ex-sx:\r\n if s[i]=='E':\r\n east+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)\r\n \r\nelif ex<sx and ey==sy:\r\n if d['W']>=sx-ex:\r\n west=0\r\n i=0\r\n while west<sx-ex:\r\n if s[i]=='W':\r\n west+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)\r\n \r\nelif ex==sx and ey>sy:\r\n if d['N']>=ey-sy:\r\n north=0\r\n i=0\r\n while north<ey-sy:\r\n if s[i]=='N':\r\n north+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)\r\n \r\nelif ex==sx and ey<sy:\r\n if d['S']>=sy-ey:\r\n south=0\r\n i=0\r\n while south<sy-ey:\r\n if s[i]=='S':\r\n south+=1\r\n \r\n i+=1\r\n \r\n print(i)\r\n \r\n else:\r\n print(-1)", "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nans=-1\r\nfor i in range(t):\r\n if s[i]=='E' and sx< ex:\r\n sx+=1\r\n if s[i]=='W' and sx>ex:\r\n sx-=1\r\n if s[i]=='N' and sy<ey:\r\n sy+=1\r\n if s[i]=='S' and sy>ey:\r\n sy-=1\r\n if sx==ex and sy==ey:\r\n ans+=(i+2)\r\n break\r\nprint(ans)", "t,sx,sy,ex,ey = map(int, input().split())\r\nst = input()\r\n\r\ncurrX = sx\r\ncurrY = sy\r\ntime = 0\r\nfor i in st:\r\n if(currX == ex and currY == ey):\r\n break\r\n if(i == \"E\" and currX < ex):\r\n currX += 1\r\n elif(i == \"S\" and currY > ey):\r\n currY -= 1\r\n elif(i == \"W\" and currX > ex):\r\n currX -= 1\r\n elif(i == \"N\" and currY < ey):\r\n currY += 1\r\n time += 1\r\nif(currX == ex and currY == ey):\r\n print(time)\r\nelse:\r\n print(-1)\r\n", "#https://codeforces.com/problemset/problem/276/B\r\n\r\n\r\n\r\nfrom collections import defaultdict\r\nt , x1,y1,x2,y2=map(int,input().split())\r\ns =input()\r\ndif1 =x2-x1 \r\ndif2=y2-y1\r\n\r\nif dif1>0:\r\n c1='E'\r\nelse:\r\n c1='W'\r\nif dif2>0:\r\n c2='N'\r\nelse:\r\n c2='S'\r\ndif1 =abs(x2-x1) \r\ndif2=abs(y2-y1)\r\nc=0\r\nans =-1\r\ns1=s2=0\r\nfor i in s:\r\n c+=1\r\n if i==c1:\r\n s1+=1 \r\n elif i==c2:\r\n s2+=1 \r\n if s1>=dif1 and s2>= dif2:\r\n ans=c\r\n break\r\nprint(ans)\r\n \r\n \r\n \r\n\r\n", "t,s1,s2,e1,e2=map(int,input().split())\r\nx=input()\r\na=e1-s1\r\nb=e2-s2\r\nif a<0:\r\n a=-a\r\n A=\"W\"\r\nelse:\r\n A=\"E\"\r\nif b<0:\r\n b=-b\r\n B=\"S\"\r\nelse:\r\n B=\"N\"\r\nc=0\r\nfor i in x:\r\n c+=1\r\n if i==A:\r\n a-=1\r\n if i==B:\r\n b-=1\r\n if a<=0 and b<=0:\r\n break\r\nif a<=0 and b<=0:\r\n print(c)\r\nelse:\r\n print(-1)", "# cook your code here\r\nn,sx,sy,ex,ey = map(int,input().split(' '))\r\n\r\nreqx = ex - sx\r\nreqy = ey - sy\r\n\r\n# // print reqx\r\n\r\nstr = input()\r\n\r\nfor i in range(n):\r\n if reqx<0:\r\n if str[i] == 'W':\r\n reqx+=1\r\n \r\n if reqy<0:\r\n if str[i] == 'S':\r\n reqy+=1\r\n \r\n if reqx>0:\r\n if str[i] == 'E':\r\n reqx-=1\r\n if reqy>0:\r\n if str[i] == 'N':\r\n reqy-=1\r\n if reqx==reqy and reqx == 0:\r\n print(i+1)\r\n exit()\r\nprint(-1)", "count,X1,Y1,X2,Y2= map(int,input().split())\ndirections = input()\n\nsteps = 0\nx1_next,y1_next = X1,Y1\nx1_prev,y1_prev = X1,Y1\nfor i in directions:\n\tif [x1_next,y1_next] == [X2,Y2]:\n\t\tbreak\n\tif i == 'E':\n\t\t\n\t\tif abs(X2-(x1_next+1)) < abs(X2-x1_prev):\n\t\t\t\n\t\t\tx1_prev = x1_next\n\t\t\tx1_next += 1\n\tif i == 'W':\n\t\t\n\t\tif abs(X2-(x1_next-1)) < abs(X2-x1_prev):\n\t\t\t\n\t\t\tx1_prev = x1_next\n\t\t\tx1_next -= 1\n\tif i == 'N':\n\t\t\n\t\tif abs(Y2-(y1_next+1)) < abs(Y2-y1_prev):\n\t\t\t\n\t\t\ty1_prev = y1_next\n\t\t\ty1_next += 1\n\tif i == 'S':\n\t\t\n\t\tif abs(Y2-(y1_next-1)) < abs(Y2-y1_prev):\n\t\t\t\n\t\t\ty1_prev = y1_next\n\t\t\ty1_next -= 1\n\tsteps += 1\n#print([x1_next,y1_next])\nif [x1_next,y1_next] == [X2,Y2]:\n\tprint(steps)\nelse:\n\tprint(-1)", "def find():\r\n time_counter = 0\r\n xtravel = ex-sx\r\n ytravel = ey-sy\r\n for i in inp2:\r\n if i == \"N\" and ytravel > 0:\r\n ytravel -= 1\r\n if i == \"E\" and xtravel > 0:\r\n xtravel -= 1\r\n if i == \"S\" and ytravel < 0:\r\n ytravel += 1\r\n if i == \"W\" and xtravel < 0:\r\n xtravel += 1\r\n time_counter += 1\r\n if xtravel == 0 and ytravel == 0:\r\n return(time_counter)\r\n return(-1)\r\ninp1 = input()\r\ninp2 = input()\r\nsplit_list = inp1.split()\r\nt = int(split_list[0])\r\nsx = int(split_list[1])\r\nsy = int(split_list[2])\r\nex = int(split_list[3])\r\ney = int(split_list[4])\r\nif sx == ex and sy == ey:\r\n print(0)\r\nelse:\r\n print(find())", "t,ix,iy,fx,fy=map(int,input().split())\r\nA=list(input())\r\ndx=fx-ix\r\ndy=fy-iy\r\ncntx=0\r\ncnty=0\r\nif dx<0:\r\n X='W'\r\nelse:\r\n X='E'\r\ncntx=abs(dx)\r\nif dy<0:\r\n Y='S'\r\nelse:\r\n Y='N'\r\ncnty=abs(dy)\r\ni=0\r\nwhile (cntx>0 or cnty>0) and i<=len(A)-1:\r\n if A[i]==X:\r\n cntx-=1 \r\n elif A[i]==Y:\r\n cnty-=1 \r\n i+=1 \r\nif cntx>0 or cnty>0:\r\n print(-1)\r\nelse:\r\n print(i)\r\n", "import sys\r\nt, sx, sy, ex, ey = list(map(lambda x: int(x), input().split()))\r\ns = input()\r\nflag = True\r\ndirec = {'N':(0, 1), 'E': (1, 0), 'W': (-1, 0), 'S':(0, -1)}\r\n\r\nfor idx, d in enumerate(s):\r\n\tx = sx + direc[d][0]\r\n\ty = sy + direc[d][1] \r\n\tif abs(x - ex) + abs(y - ey) < abs(ex - sx) + abs(ey - sy):\r\n\t\tsx, sy = x, y\r\n\tif (sx, sy) == (ex, ey):\r\n\t\tprint(idx+1)\r\n\t\tflag = False\r\n\t\tbreak\r\nif flag:\r\n\tprint(-1)", "t, sx, sy, ex, ey = map(int, input().split())\r\ndirections = input()\r\nreq = 0\r\nabsX, absY = ex-sx, ey-sy\r\nif absX>0:\r\n xMove=\"E\"\r\nelse:\r\n xMove=\"W\"\r\nif absY>0:\r\n yMove=\"N\"\r\nelse:\r\n yMove=\"S\"\r\nabsX, absY = abs(absX), abs(absY)\r\nfor i in range(t):\r\n if directions[i]==xMove and absX>0:\r\n absX-=1\r\n if directions[i]==yMove and absY>0:\r\n absY-=1\r\n if absY==absX==0:\r\n break\r\nif absX==absY==0:\r\n print(i+1)\r\nelse:\r\n print(-1)\r\n \r\n", "\n#if the move available (by the wind) to us is getting us away from destination\n# DO NOT TAKE IT\n# first testcase\n# 5 0 0 1 1\n# SESNW\n# 0 --->1 x+=1 east\n# 0---->1 y+=1 north\nn,x,y,a,b=map(int,input().split())\ns=input()\nf=False\nfor i in range(n):\n\n if b-y>0:\n if s[i] == \"N\": y += 1\n if b-y< 0:\n if s[i]==\"S\":y-=1\n if a - x > 0:\n if (s[i] == 'E'):x += 1\n\n if a - x < 0:\n if s[i] == 'W':x -= 1\n time=i+1\n if (x == a and y == b):#reached destination\n f=True;\n break;\n\nif f==True:print(time)\nelse:print(-1)\n\n\n \t \t\t\t \t \t \t\t\t\t \t\t\t \t\t\t\t", "t , x , y , e , d = map(int,input().split())\ns = input()\nif(x==e and y==d):\n print(0)\nelse:\n diffx = abs(x-e)\n diffy = abs(y-d)\n flag = 0\n count =0 \n for i in s:\n xpoint = x\n ypoint = y\n if(i=='S'):\n ypoint-=1\n elif(i=='N'):\n ypoint+=1\n elif(i=='W'):\n xpoint-=1\n else:\n xpoint+=1\n diffnewx = abs(xpoint-e)\n diffnewy = abs(ypoint-d)\n if(diffnewx<=diffx and diffnewy<=diffy):\n x = xpoint\n y = ypoint\n diffx = diffnewx\n diffy = diffnewy\n count+=1\n if(x==e and y==d):\n flag = 1\n break\n if(flag==1):\n print(count)\n else:\n print(-1)\n", "from sys import stdin\r\n\r\n#s = stdin.readline().strip()\r\nt, sx, sy, ex, ey = [int(i) for i in stdin.readline().split(\" \")]\r\nwind = stdin.readline().strip()\r\n\r\ndirection = {'E':0, 'W':0, 'N':0, 'S':0}\r\n\r\n\r\nif ex>=sx:\r\n direction['E'] = ex-sx\r\nelse:\r\n direction['W'] = sx-ex\r\n\r\nif ey>=sy:\r\n direction['N'] = ey-sy\r\nelse:\r\n direction['S'] = sy-ey\r\n\r\n#print(direction)\r\ncount = 0\r\nflag = 0\r\nfor i in wind:\r\n if direction[i]>0:\r\n direction[i] -= 1\r\n count += 1\r\n temp = direction['S'] + direction['N'] + direction['W'] + direction['E']\r\n if temp==0:\r\n flag = 1\r\n print(count)\r\n break\r\nif flag==0:\r\n print(\"-1\")", "t, s1, s2, e1, e2 = map(int, input().split())\r\na = input()\r\nf = 0\r\nfor i in range(t):\r\n\tif s1 == e1 and s2 == e2:\r\n\t\tf = 1\r\n\t\tbreak\r\n\tif s1 < e1 and a[i] == \"E\":\r\n\t\ts1 += 1\r\n\telif s1 > e1 and a[i] == \"W\":\r\n\t\ts1 -= 1\r\n\t\t\r\n\tif s2 < e2 and a[i] == \"N\":\r\n\t\ts2 += 1\r\n\tif s2 > e2 and a[i] == \"S\":\r\n\t\ts2 -= 1\r\nif s1 == e1 and s2 == e2:\r\n\tprint(i if f else i+1)\r\nelse:\r\n\tprint(-1)\r\n\"\"\"\r\n41 -264908123 -86993764 -264908123 -86993723\r\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\r\n\"\"\"\r\n", "t, sx, sy, ex, ey = [int(s) for s in input().split(' ')]\nwind = input()\nres = 0\nfor direction in wind:\n if (ex, ey) == (sx, sy):\n break\n if direction == 'E' and ex > sx:\n sx += 1\n if direction == 'S' and ey < sy:\n sy -= 1\n if direction == 'W' and ex < sx:\n sx -= 1\n if direction == 'N' and ey > sy:\n sy += 1\n res += 1\nif (ex, ey) != (sx, sy):\n res = -1\nprint(res)\n", "t, sx, sy, ex, ey = map(int, input().split())\r\ndi = input()\r\ni = 0\r\nwhile (sx != ex or sy != ey) and i < t:\r\n if ex > sx and di[i] == \"E\":\r\n sx += 1\r\n elif ex < sx and di[i] == \"W\":\r\n sx -= 1\r\n elif ey > sy and di[i] == \"N\":\r\n sy += 1\r\n elif ey < sy and di[i] == \"S\":\r\n sy -= 1\r\n i += 1\r\nif sx == ex and sy == ey:\r\n print(i)\r\nelse:\r\n print(-1)", "t, sx, sy, ex, ey = map(int, input().split())\ndirection= input()\n\n# Calculate the distance between the starting and ending points\ndx = ex - sx\ndy = ey - sy\n\n# Iterate over the wind directions and move the boat accordingly\nfor i in range(t):\n if dx > 0 and direction[i] == 'E':\n dx -= 1\n elif dx < 0 and direction[i] == 'W':\n dx += 1\n elif dy > 0 and direction[i] == 'N':\n dy -= 1\n elif dy < 0 and direction[i] == 'S':\n dy += 1\n\n if dx == 0 and dy == 0:\n print(i+1)\n break\nelse:\n\n print(-1)\n\t\t\t \t \t \t\t \t \t \t\t\t \t\t\t\t\t\t\t\t\t", "t, x, y, e, u = input().split()\r\ns = input()\r\nt, x, y, e, u = int(t), int(x), int(y), int(e), int(u)\r\ncnt = -1\r\nfor i in range(len(s)):\r\n if s[i] == 'E':\r\n if x < e:\r\n x += 1\r\n elif s[i] == 'S':\r\n if y > u:\r\n y -=1\r\n elif s[i] == 'W':\r\n if x > e:\r\n x -= 1\r\n elif s[i] == 'N':\r\n if y < u:\r\n y += 1\r\n\r\n if x == e and y == u:\r\n cnt = i + 1\r\n break\r\nprint(cnt)", "t, sx, sy, ex, ey = map(int, input().split())\r\nd = {'W':max(0, sx - ex), 'E':max(0, ex - sx), 'N':max(0, ey - sy), 'S':max(0, sy - ey)}\r\nfor (i, c) in enumerate(input(), 1):\r\n if d[c] > 0:\r\n d[c] -= 1\r\n if any(d.values()) == False:\r\n print(i)\r\n break\r\nelse:\r\n print(-1)", "def main():\r\n n, sx, sy, ex, ey = get_list_int()\r\n directions = list(input())\r\n t = 0\r\n\r\n for d in directions:\r\n if d == \"E\" and sx < ex:\r\n sx += 1\r\n elif d == \"S\" and sy > ey:\r\n sy -= 1\r\n elif d == \"W\" and sx > ex:\r\n sx -= 1\r\n elif d == \"N\" and sy < ey:\r\n sy += 1\r\n\r\n t += 1\r\n\r\n if sx == ex and sy == ey:\r\n print(t)\r\n return\r\n\r\n print(-1)\r\n\r\n\r\ndef get_int() -> int:\r\n return int(input())\r\n\r\n\r\ndef get_list_int() -> list[int]:\r\n return [int(x) for x in input().split(\" \")]\r\n\r\n\r\ndef get_list_str() -> list[str]:\r\n return input().split(\" \")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "t,sy,sx,ey,ex=list(map(int,input().split()))\r\ninp=input()\r\nfor i in range(t):\r\n if inp[i]==\"N\" and sx-ex<0:\r\n sx+=1\r\n elif inp[i]==\"S\" and sx-ex>0:\r\n sx+=-1\r\n elif inp[i]==\"E\" and sy-ey<0:\r\n sy+=1\r\n elif inp[i]==\"W\" and sy-ey>0:\r\n sy+=-1\r\n if sy-ey==0 and sx-ex==0:\r\n print(1+i)\r\n exit()\r\nelse:\r\n print(-1)", "#文字列入力はするな!!\r\n#carpe diem\r\n\r\n'''\r\n ██╗ ██╗ ███╗ ███╗ ██╗ ████████╗\r\n ██║ ██║ ████╗ ████║ ██║ ╚══██╔══╝\r\n═════════██╠════════██╠═══██╔████╔██╠═══██╠══════██╠══════════\r\n ██║ ██║ ██║╚██╔╝██║ ██║ ██║\r\n ███████╗ ██║ ██║ ╚═╝ ██║ ██║ ██║\r\n ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝\r\n'''\r\n\r\n#文字列入力はするな!!\r\n#carpe diem\r\n\r\n\r\nt,x,y,ex,ey=map(int,input().split())\r\ns=input()\r\nk=0\r\nwhile(x!=ex or y!=ey):\r\n if k==t:\r\n print(-1)\r\n exit()\r\n if s[k]=='S' and ey<y:\r\n y-=1\r\n elif s[k]=='N' and ey>y:\r\n y+=1\r\n elif s[k]=='E' and ex>x:\r\n x+=1\r\n elif s[k]=='W' and ex<x:\r\n x-=1\r\n k+=1\r\n\r\nprint(k)\r\n\r\n\r\n\r\n \r\n \r\n\r\n#carpe diem \r\n#carpe diem", "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nh,v=\"Z\",\"Z\"\r\nif(sx>ex):h=\"W\"\r\nelif(sx<ex):h=\"E\"\r\n\r\nif(sy>ey):v=\"S\"\r\nelif(sy<ey):v=\"N\"\r\n\r\na,b=abs(sx-ex),abs(sy-ey);c=0\r\nfor i in s:\r\n if(a or b):c+=1\r\n if(h==i and a>0):\r\n a-=1\r\n if(v==i and b>0):\r\n b-=1\r\nif(a!=0 or b!=0):print(-1)\r\nelse:print(c)", "t,sx,sy,ex,ey=map(int,input().split())\r\na=list(map(str,input()))\r\nse=0\r\nsn=0\r\nss=0\r\nsw=0\r\nf=[0,0]\r\nfor i in range(0,len(a)):\r\n if a[i]==\"E\" :\r\n se+=1\r\n elif a[i]==\"W\" :\r\n sw-=1\r\n elif a[i]==\"N\" :\r\n sn+=1\r\n elif a[i]==\"S\" :\r\n ss-=1\r\n if ex-sx==se or ex-sx==sw :\r\n f[0]+=1\r\n if ey-sy==sn or ey-sy==ss :\r\n f[1]+=1\r\n if f[0]!=0 and f[1]!=0 :\r\n print(i+1)\r\n break\r\n\r\nif f[0]==0 or f[1]==0 :\r\n print(-1)", "def solver(x,y,direction,t):\r\n r = 0\r\n for i in range(t):\r\n if x>0 and direction[i]=='E':\r\n x-=1\r\n r=i\r\n elif x<0 and direction[i]=='W':\r\n x+=1\r\n r=i\r\n \r\n if y>0 and direction[i]=='N':\r\n y-=1\r\n r=i\r\n elif y<0 and direction[i]=='S':\r\n y+=1\r\n r=i\r\n \r\n if x==0 and y==0:\r\n return r+1\r\n else:\r\n return -1\r\n \r\nt,sx,sy,ex,ey = map(int,input().split())\r\n\r\ndirection = input()\r\nx=ex-sx\r\ny=ey-sy\r\nprint(solver(x,y,direction,t))", "a = list(map(int, input().split()))[1:]\r\ns = input()\r\n\r\nx = a[2] - a[0]\r\ny = a[3] - a[1]\r\n\r\nif x>0: cx = 'E'\r\nelse: cx = 'W'\r\n\r\nif y>0: cy = 'N'\r\nelse: cy = 'S'\r\n\r\n\r\nx = abs(x)\r\ny = abs(y)\r\n\r\nfor i in range(len(s)):\r\n\r\n if s[i] == cx:\r\n x-=1\r\n if s[i] == cy:\r\n y-=1\r\n\r\n if x<=0 and y<=0:\r\n print(i+1)\r\n exit()\r\n\r\nprint(-1)\r\n\r\n", "t, sx, sy, ex, ey = map(int, input().split())\r\nwind_dir = input()\r\nx_dir = 'E' if ex > sx else 'W'\r\ny_dir = 'N' if ey > sy else 'S'\r\nx_dir_count = abs(ex - sx)\r\ny_dir_count = abs(ey - sy)\r\nt = 0\r\nfor dir in wind_dir:\r\n t += 1\r\n if (dir == x_dir and x_dir_count > 0):\r\n x_dir_count -= 1\r\n elif (dir == y_dir and y_dir_count > 0):\r\n y_dir_count -= 1\r\n if (x_dir_count == y_dir_count == 0):\r\n print(t)\r\n break\r\nif (x_dir_count != 0 or y_dir_count != 0):\r\n print(-1)", "t, sx, sy, ex, ey =map(int, input().split())\ne = list(input())\nT = 0\nB = True\nfor x in e:\n if sx < ex and sy < ey:\n if x == \"N\": sy += 1\n elif x == \"E\": sx += 1\n elif sx > ex and sy > ey:\n if x == \"S\": sy -= 1\n elif x == \"W\": sx -= 1\n elif sx > ex and sy < ey:\n if x == \"N\": sy += 1\n elif x == \"W\": sx -= 1\n elif sx < ex and sy > ey:\n if x == \"S\": sy -= 1\n elif x == \"E\": sx += 1\n elif sx == ex and sy < ey:\n if x == \"N\": sy += 1\n elif sx == ex and sy > ey:\n if x == \"S\": sy -= 1\n elif sx < ex and sy == ey:\n if x == \"E\": sx += 1\n elif sx > ex and sy == ey:\n if x == \"W\": sx -= 1\n T += 1\n if sx == ex and sy == ey:\n B = False\n break\nif B:print(-1)\nelse:print(T)\n \t\t\t \t \t \t\t\t\t \t\t\t \t\t \t \t \t\t", "def solve(x1, y1, x2, y2, n, s):\r\n if (x1, y1) == (x2, y2):\r\n return 0\r\n d1 = d2 = None\r\n if x1 < x2: d1 = 'E'\r\n else: d1 = 'W'\r\n if y1 < y2: d2 = 'N'\r\n else: d2 = 'S'\r\n minD1 = abs(x1 - x2)\r\n minD2 = abs(y1 - y2)\r\n currD1 = currD2 = 0\r\n \r\n for i in range(n):\r\n if s[i] == d1 and currD1 < minD1:\r\n currD1 += 1\r\n if s[i] == d2 and currD2 < minD2:\r\n currD2 += 1\r\n if currD1 == minD1 and currD2 == minD2:\r\n return i+1\r\n return -1\r\n\r\nparams = list(map(int, input().split()))\r\ns = input()\r\nprint(solve(params[1], params[2], params[3], params[4], params[0], s))", "n,x1,y1,x2,y2=map(int,input().split())\r\ns=input()\r\nfor i in range(n):\r\n if s[i]==\"N\" and y1<y2:\r\n y1+=1\r\n if s[i]==\"S\" and y1>y2:\r\n y1-=1\r\n if s[i]==\"W\" and x1>x2:\r\n x1-=1\r\n if s[i]==\"E\" and x1<x2:\r\n x1+=1\r\n if x1==x2 and y1==y2:\r\n print(i+1)\r\n exit()\r\nprint(-1)\r\n", " \r\nt, sx, sy, ex, ey = map(int,input().split())\r\nl = list(input())\r\n\r\nx = ex - sx\r\ny = ey - sy\r\n\r\ndir = {\"E\":0, \"W\":0, \"N\":0, \"S\":0}\r\n\r\nif x > 0:\r\n dir[\"E\"] = x\r\nelse:\r\n dir[\"W\"] = abs(x)\r\n\r\nif y > 0:\r\n dir[\"N\"] = y\r\nelse:\r\n dir[\"S\"] = abs(y)\r\n\r\nloc = -1\r\nfor i,a in enumerate(l):\r\n if dir[a] > 0 : dir[a] -= 1 \r\n if sum(dir.values()) == 0:\r\n loc = i + 1\r\n break\r\n\r\nprint(loc)", "\nt, sx, sy, ex, ey = list(map(int, input().split()))\nwind = input()\ny = ey - sy\nx = ex - sx\nif x+y <= t:\n\ts = 0\n\tarr = False\n\twhile s < t:\n\t\tif x > 0 and wind[s] == 'E':\n\t\t\tx = x - 1\n\t\telif x < 0 and wind[s] == 'W':\n\t\t\tx = x + 1\n\t\tif y > 0 and wind[s] == 'N':\n\t\t\ty = y - 1\n\t\telif y < 0 and wind[s] == 'S':\n\t\t\ty = y + 1\n\t\ts += 1\n\t\tif x == 0 and y == 0:\n\t\t\tarr = True\n\t\t\tbreak\n\tif arr:\n\t\tprint(s)\n\telse:\n\t\tprint(-1)\nelse:\n\tprint(-1)\n\t \t\t \t\t\t\t\t\t \t \t \t \t\t \t \t \t", "t, sx, sy, ex, ey = map(int, input().split())\r\ns = input()\r\n\r\nhor_dist = abs(sx - ex)\r\nhor_dir = 'E' if sx < ex else 'W'\r\n\r\nver_dist = abs(sy - ey)\r\nver_dir = 'N' if sy < ey else 'S'\r\n\r\nif s.count(hor_dir) < hor_dist or s.count(ver_dir) < ver_dist:\r\n print(-1)\r\nelse:\r\n s = s.replace(hor_dir, '_', hor_dist)\r\n s = s.replace(ver_dir, '_', ver_dist)\r\n print(s.rfind('_') + 1)\r\n", "t,sx,sy,ex,ey =map(int,input().split())\r\ndire=input()\r\np=0\r\nfor i in range(0,t):\r\n if dire[i]=='S'and ey<sy:\r\n sy-=1\r\n elif dire[i]=='N'and ey>sy:\r\n sy+=1\r\n elif dire[i]=='E' and ex>sx:\r\n sx+=1\r\n elif dire[i]=='W' and ex<sx:\r\n sx-=1\r\n if sx==ex and sy==ey:\r\n p=1\r\n print(i+1)\r\n break\r\nif p==0:print('-1') ", "points=list(map(int,input().split()))\r\nt=points[0]\r\nsx,sy=points[1],points[2]\r\ndx,dy=points[3],points[4]\r\ncurrdist=abs(sx-dx)+abs(sy-dy)\r\nmat=input()\r\nmap={'S':[0,-1],'N':[0,1],'E':[1,0],'W':[-1,0]}\r\nsol=-1\r\nfor i in range(t):\r\n newi=sx+map[mat[i]][0]\r\n newj=sy+map[mat[i]][1]\r\n if abs(dx-newi)+abs(dy-newj)<currdist:\r\n sx,sy=newi,newj\r\n currdist=abs(dx-newi)+abs(dy-newj)\r\n if sx==dx and sy==dy:\r\n sol=i+1\r\n break\r\nprint(sol)\r\n\r\n", "m,a,ay,b,by=map(int,input().split());s=input()+'0'\nx='W'if a>b else 'E'\ny='S'if ay>by else 'N'\nc,d=abs(a-b),abs(ay-by)\nfor i in range(m):\n\tif s[i]==x and c>0:c-=1\n\tif s[i]==y and d>0:d-=1\n\tif c==d==0:print(i+1);break\nelse:print(-1)\n\t \t\t\t\t\t\t \t \t\t\t \t \t\t \t \t", "l = list(map(int,input().split()))\r\nt = l[3] - l[1]\r\nfE = fN = fW = fS = 0\r\nif t>=0:\r\n fE = t\r\nelse:\r\n fW = abs(t)\r\nt1 = l[4] - l[2]\r\nif t1>=0:\r\n fN = t1\r\nelse:\r\n fS = abs(t1)\r\ns = input()\r\nres = 0\r\ndr = {'N':0, \"S\":0, 'E':0, 'W':0}\r\nfor i in s:\r\n dr[i]+=1\r\n res +=1\r\n if dr['N'] >= fN and dr['S'] >= fS and dr['E'] >= fE and dr['W'] >= fW and res<=l[0]:\r\n print(res)\r\n exit()\r\nprint(\"-1\")", "# Direction to go:\r\n# if x1<x2: Going east else going west\r\n# if y1<y2: Going north else going south\r\nn,x1,y1,x2,y2=map(int,input().split())\r\ns=input()\r\nl=[]\r\nfor i in s:\r\n l.append(i)\r\ndirection=[]\r\nif x1<x2:\r\n direction.append('E')\r\nelif x1>x2:\r\n direction.append('W')\r\nif y1<y2:\r\n direction.append('N')\r\nelif y1>y2:\r\n direction.append('S')\r\ncount=int(0)\r\nfor i in l:\r\n count+=1\r\n if i in direction:\r\n if i=='E' and x1<x2:\r\n x1+=1\r\n elif i=='W' and x1>x2:\r\n x1-=1\r\n elif i=='N' and y1<y2:\r\n y1+=1\r\n elif i=='S' and y1>y2:\r\n y1-=1\r\n if x1==x2 and y1==y2:\r\n print(count)\r\n exit()\r\nprint(-1)", "\nE = (1, 0)\nS = (0, -1)\nW = (-1, 0)\nN = (0, 1)\n\ns = input()\n_ = int(s.split()[0])\nsx = int(s.split()[1])\nsy = int(s.split()[2])\nex = int(s.split()[3])\ney = int(s.split()[4])\n\nwind = input()\ndone = False\n\nfor i, d in enumerate(wind):\n if d == 'E' and sx < ex:\n sx += 1\n elif d == 'S' and sy > ey:\n sy -= 1\n elif d == 'W' and sx > ex:\n sx -= 1\n elif d == 'N' and sy < ey:\n sy += 1\n if sx == ex and sy == ey:\n print(i+1)\n done = True\n break\n\nif not done:\n print(-1)\n\n\n \t\t \t\t \t\t \t\t\t \t\t\t\t \t", "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nans=0\r\nx1=ex-sx\r\ny1=ey-sy\r\nif(x1>0):\r\n d='E'\r\nelse:\r\n d='W'\r\nif(y1>0):\r\n di='N'\r\nelse:\r\n di='S'\r\nx1=abs(x1)\r\ny1=abs(y1)\r\nfor i in range(t):\r\n if(s[i]==d):\r\n x1-=1\r\n elif(s[i]==di):\r\n y1-=1\r\n ans+=1\r\n if(x1<=0 and y1<=0):\r\n break\r\nif(x1<=0 and y1<=0 and ans<=t):\r\n print(ans)\r\nelse:\r\n print(\"-1\")\r\n", "import math\r\nmod = 1000000007\r\nfrom sys import stdin, stdout\r\n#from collections import defaultdict, Counter, deque\r\n#from bisect import bisect_left, bisect_right\r\n# import sympy\r\n# from itertools import permutations\r\n# import numpy as np\r\n\r\n# n = int(stdin.readline())\r\n# stdout.write(str())\r\n# s = stdin.readline().strip('\\n')\r\n# n,k=map(int, stdin.readline().split())\r\n# li = list(map(int, stdin.readline().split()))\r\nfor _ in range(1):\r\n t,a,b,x,y=map(int, stdin.readline().split())\r\n if a<=x:\r\n p=\"E\"\r\n p_count=x-a\r\n else:\r\n p=\"W\"\r\n p_count=a-x\r\n if b<=y:\r\n q=\"N\"\r\n q_count=y-b\r\n else:\r\n q=\"S\"\r\n q_count=b-y\r\n if q_count==0 and p_count==0:\r\n print(0)\r\n continue\r\n ans=-1\r\n # print(p_count,q_count)\r\n # print(p,q)\r\n s = stdin.readline().strip('\\n')\r\n for i in range(0,t):\r\n # x=input()\r\n if p==s[i] and p_count!=0:\r\n p_count-=1\r\n if q==s[i] and q_count!=0:\r\n q_count-=1\r\n # print(p_count,q_count)\r\n if p_count==0 and q_count==0 and ans==-1:\r\n ans=i\r\n # print(ans)\r\n if ans==-1:\r\n print(ans)\r\n continue\r\n print(ans+1)", "t,x,y,a,b=map(int,input().split())\r\nS=input()\r\nn,s,e,w=0,0,0,0\r\nif(x<=a):e=a-x\r\nelse: w=x-a\r\nif(y<=b):n=b-y\r\nelse: s=y-b\r\n# print(n,s,e,w)\r\ni=0\r\nans=0\r\nwhile((n>0 or w>0 or e>0 or s>0) and i<t):\r\n # print(S[i])\r\n if(S[i]==\"N\" and n>0):\r\n n-=1\r\n elif(S[i]==\"S\" and s>0):\r\n s-=1\r\n elif(S[i]==\"E\" and e>0):\r\n e-=1\r\n elif(S[i]==\"W\" and w>0):\r\n w-=1\r\n ans+=1 \r\n if(n==0 and s==0 and e==0 and w==0): break\r\n i+=1 \r\n# print(n,s,e,w) \r\nif(n==0 and s==0 and e==0 and w==0): print(ans)\r\nelse: print(-1)", "t,sx,sy,ex,ey=map(int,input().split())\r\nq=\"N\"if ey>sy else\"S\"\r\nw=\"E\"if ex>sx else\"W\"\r\nex=abs(ex-sx)\r\ney=abs(ey-sy)\r\ns=input()\r\nfor i in range(t):\r\n if ey!=0and s[i]==q:ey-=1\r\n if ex!=0and s[i]==w:ex-=1\r\n if ex==0 and ey==0:break\r\nprint(i+1if ex==0and ey==0else-1)", "t,ix,iy,fx,fy= map(int,input().split())\ndx = fx - ix\ndy = fy - iy \narr = input()\nf = 0\nif dx==0 and dy==0:\n print(0)\n quit()\nc = 0\nfor i in arr:\n if i == \"N\" and dy > 0: dy-=1\n if i == \"S\" and dy < 0: dy+=1\n if i == \"E\" and dx > 0: dx-=1\n if i == \"W\" and dx < 0: dx+=1\n c += 1\n if dx==0 and dy==0:\n f = 1\n break\nif f==1: print(c)\nelse: print(-1) \n ", "import sys\r\n\r\nt,sx,sy,ex,ey = [int(x) for x in input().split(\" \")]\r\ns = input()\r\n\r\nif(sx==ex and sy==ey):\r\n print(0)\r\n sys.exit()\r\n\r\nfor i in range(t):\r\n if s[i]=='N' and (abs(ey-(sy+1)) < abs(ey-sy)): sy += 1\r\n if s[i]=='S' and (abs(ey-(sy-1)) < abs(ey-sy)): sy -= 1\r\n if s[i]=='E' and (abs(ex-(sx+1)) < abs(ex-sx)): sx += 1\r\n if s[i]=='W' and (abs(ex-(sx-1)) < abs(ex-sx)): sx -= 1\r\n if(sx==ex and sy==ey):\r\n print(i+1)\r\n break\r\nelse:\r\n print(-1)", "n, s_x, s_y, e_x, e_y = [int(i) for i in input().split()]\r\nmotion = input()\r\nn = len(motion)\r\n\r\nx, y = -e_x + s_x, -e_y + s_y\r\nres = 0\r\nfor d in motion:\r\n if d in {\"S\", \"N\"}:\r\n if y < 0:\r\n y += int(d == \"N\")\r\n elif y > 0:\r\n y -= int(d == \"S\")\r\n else:\r\n if x < 0:\r\n x += int(d == \"E\")\r\n elif x > 0:\r\n x -= int(d == \"W\")\r\n res += 1\r\n if x == 0 and y == 0:\r\n break\r\nprint(res if x == 0 and y == 0 else -1)", "count = 0\r\ndirection = input()\r\ndirection = direction.split()\r\n\r\nnumber = int(direction[0])\r\nx1 = int(direction[1])\r\ny1 = int(direction[2])\r\nx2 = int(direction[3])\r\ny2 = int(direction[4])\r\n\r\nwinds = input()\r\n\r\nfor i in range(number):\r\n k = str(winds[i]) \r\n if x1 > x2:\r\n if k == 'W':\r\n x1 -= 1\r\n if x2 > x1:\r\n if k == 'E':\r\n x1 += 1\r\n if y1 > y2:\r\n if k == 'S':\r\n y1 -= 1\r\n if y2 > y1:\r\n if k == 'N':\r\n y1 += 1\r\n if x1 == x2 and y1 == y2:\r\n count += 1\r\n if count == 1:\r\n print(i+1)\r\n\r\nif count < 1:\r\n print(-1)", "t, s_x, s_y, e_x, e_y = list(map(int, input().strip().split()))\nwind = input()\n\nx = e_x - s_x\ny = e_y - s_y\n\nctr = 0\nfor w in wind:\n if x == 0 and y == 0:\n break\n else:\n if w == 'N' and y > 0:\n y -= 1\n elif w == 'S' and y < 0:\n y += 1\n elif w == 'E' and x > 0:\n x -= 1\n elif w == 'W' and x < 0:\n x += 1\n ctr += 1\n\nprint(ctr if (x == 0 and y == 0) else -1)\n", "def solve(sec,fromX,fromY, toX,toY ,wind) :\r\n distanceX = toX - fromX\r\n distanceY = toY - fromY\r\n index = 0\r\n \r\n while index < sec :\r\n if distanceX == distanceY == 0 :\r\n return index\r\n \r\n if wind[index] == 'N' :\r\n if distanceY > 0 :\r\n distanceY -= 1\r\n elif wind[index] == 'S' :\r\n if distanceY < 0 :\r\n distanceY += 1\r\n elif wind[index] == 'W' :\r\n if distanceX < 0 :\r\n distanceX += 1\r\n elif wind[index] == 'E' :\r\n if distanceX > 0 :\r\n distanceX -= 1\r\n \r\n index += 1\r\n \r\n if distanceX != distanceY :\r\n return -1\r\n else :\r\n return index\r\n\r\n\r\ns,x1,y1,x2,y2 = list(map(int,input().split()))\r\nseq = list(input())\r\n\r\nprint (solve(s,x1,y1,x2,y2,seq))", "t,a,b,p,q = list(map(int,input().split()))\r\ns,i = input(),0\r\nwhile (a!=p or b!=q) and i<t:\r\n k = s[i]\r\n if k==\"N\":\r\n if q>b:\r\n b=b+1\r\n if k==\"S\":\r\n if q<b:\r\n b=b-1\r\n if k==\"E\":\r\n if p>a:\r\n a=a+1\r\n if k==\"W\":\r\n if p<a:\r\n a=a-1\r\n i+=1\r\nif a==p and b==q:\r\n print(i)\r\nelse:\r\n print(-1)", "import sys\r\nimport os\r\nfrom collections import Counter, defaultdict, deque\r\nfrom heapq import heapify, heappush, heappop\r\nfrom functools import lru_cache\r\nfrom math import floor, ceil, sqrt, gcd\r\nfrom string import ascii_lowercase\r\nfrom math import gcd\r\nfrom bisect import bisect_left, bisect, bisect_right\r\n\r\n\r\ndef __perform_setup__():\r\n INPUT_FILE_PATH = \"/Users/osama/Desktop/Competitive Programming/input.txt\"\r\n OUTPUT_FILE_PATH = \"/Users/osama/Desktop/Competitive Programming/output.txt\"\r\n\r\n sys.stdin = open(INPUT_FILE_PATH, 'r')\r\n sys.stdout = open(OUTPUT_FILE_PATH, 'w')\r\n\r\n\r\nif \"MY_COMPETITIVE_PROGRAMMING_VARIABLE\" in os.environ:\r\n __perform_setup__()\r\n\r\n\r\ndef read():\r\n return input().strip()\r\n\r\n\r\ndef read_int():\r\n return int(read())\r\n\r\n\r\ndef read_str_list():\r\n return read().split()\r\n\r\n\r\ndef read_numeric_list():\r\n return list(map(int, read_str_list()))\r\n\r\n\r\ndef solve(N, c_x, c_y, e_x, e_y, wind):\r\n ans = 0\r\n wind_changes = {\r\n \"E\": [1, 0],\r\n \"W\": [-1, 0],\r\n \"N\": [0, 1],\r\n \"S\": [0, -1]\r\n }\r\n\r\n for ch in wind:\r\n if c_x == e_x and c_y == e_y:\r\n break\r\n\r\n d_x, d_y = wind_changes[ch]\r\n n_x, n_y = d_x + c_x, d_y + c_y\r\n\r\n if abs(n_x - e_x) <= abs(c_x - e_x) and abs(n_y - e_y) <= abs(c_y - e_y):\r\n c_x += d_x\r\n c_y += d_y\r\n\r\n ans += 1\r\n\r\n if c_x == e_x and c_y == e_y:\r\n return ans\r\n\r\n return -1\r\n\r\n\r\nN, s_x, s_y, e_x, e_y = read_numeric_list()\r\nwind = read()\r\n\r\nprint(solve(N, s_x, s_y, e_x, e_y, wind))\r\n", "t, sx, sy, ex, ey = map(int, input().split())\r\nst = input()\r\nif sx < ex:\r\n\te = ex - sx\r\n\tif sy < ey:\r\n\t\tn = ey - sy\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif e <= 0 and n <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'E':\r\n\t\t\t\te-=1\r\n\t\t\tif st[ind] == 'N':\r\n\t\t\t\tn-=1\r\n\t\t\tind+=1\r\n\t\tif e <= 0 and n <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n\r\n\telif sy > ey:\r\n\t\ts = sy - ey\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif e <= 0 and s <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'E':\r\n\t\t\t\te-=1\r\n\t\t\tif st[ind] == 'S':\r\n\t\t\t\ts-=1\r\n\t\t\tind+=1\r\n\t\tif e <= 0 and s <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n\telse:\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif e <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'E':\r\n\t\t\t\te-=1\r\n\t\t\tind+=1\r\n\t\tif e <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\nelif sx > ex:\r\n\tw = sx - ex\r\n\tif sy < ey:\r\n\t\tn = ey - sy\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif w <= 0 and n <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'W':\r\n\t\t\t\tw-=1\r\n\t\t\tif st[ind] == 'N':\r\n\t\t\t\tn-=1\r\n\t\t\tind+=1\r\n\t\tif w <= 0 and n <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n\r\n\telif sy > ey:\r\n\t\ts = sy - ey\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif w <= 0 and s <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'W':\r\n\t\t\t\tw-=1\r\n\t\t\tif st[ind] == 'S':\r\n\t\t\t\ts-=1\r\n\t\t\tind+=1\r\n\t\tif w <= 0 and s <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n\telse:\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif w <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'W':\r\n\t\t\t\tw-=1\r\n\t\t\tind+=1\r\n\t\tif w <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\nelse:\r\n\tif sy < ey:\r\n\t\tn = ey - sy\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif n <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'N':\r\n\t\t\t\tn-=1\r\n\t\t\tind+=1\r\n\t\tif n <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n\telse:\r\n\t\ts = sy - ey\r\n\t\tind = 0\r\n\t\twhile ind < t:\r\n\t\t\tif s <= 0:\r\n\t\t\t\tbreak\r\n\t\t\tif st[ind] == 'S':\r\n\t\t\t\ts-=1\r\n\t\t\tind+=1\r\n\t\tif s <= 0:\r\n\t\t\tprint(ind)\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n", "import math\r\nfrom multiprocessing.dummy import Array\r\n# from re import S\r\nt,sx,sy,a,b=map(int,input().split())\r\n# t=True\r\n# for i in range(int(input())):\r\n# n=int(input())\r\n# arr=list(map(int,input().split()))\r\n# n,m=map(int,input().split())\r\ns=input()\r\n# cnt=0\r\nfor i in range(t):\r\n if(s[i]=='N' and b>sy):\r\n sy+=1\r\n if(s[i]=='S' and b<sy):\r\n sy-=1\r\n if(s[i]==\"W\" and a<sx):\r\n sx-=1\r\n if(s[i]==\"E\" and a>sx):\r\n sx+=1\r\n if(a==sx and b==sy):\r\n print(i+1)\r\n break\r\nelse:\r\n print(-1)", "# your code goes here\r\n# cook your dish here\r\nt,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nfx=abs(ex-sx)\r\nfy=abs(ey-sy)\r\nans=-1\r\nfor i in range(t):\r\n if(s[i]=='N'):\r\n if(ey>=sy):\r\n if(fy!=0):\r\n fy-=1\r\n if(s[i]=='S'):\r\n if(ey<=sy):\r\n if(fy!=0):\r\n fy-=1\r\n if(s[i]=='E'):\r\n if(ex>=sx):\r\n if(fx!=0):\r\n fx-=1\r\n if(s[i]=='W'):\r\n if(ex<=sx):\r\n if(fx!=0):\r\n fx-=1\r\n if(fx==0 and fy==0):\r\n if(ans==-1):\r\n ans=i+1\r\nprint(ans)", "def get_index(l, x, n):\r\n # 函数作用: 获取某个元素第n次出现在列表的下标\r\n # 参数列表: 第一个参数为可迭代对象, 第二个参数为要查找的数, 第三个参数为要查找第几个出现的x\r\n l_count = l.count(x)\r\n result = None\r\n if n <= l_count:\r\n num = 0\r\n for item in enumerate(l):\r\n if item[1] == x:\r\n num += 1\r\n if num == n:\r\n result = item[0]\r\n break\r\n\r\n return result\r\n\r\n\r\n\r\n\r\nt,sx,sy,ex,ey=map(int,input().split())\r\nx=ex-sx\r\ny=ey-sy\r\nw=input()\r\na=w.count('E')\r\nb=w.count('W')\r\nc=w.count('N')\r\nd=w.count('S')\r\nif x>a or x<-b or y>c or y<-d:\r\n print(-1)\r\nelse:\r\n if x>0:\r\n if y==0:\r\n print(get_index(w,'E',x)+1)\r\n elif y>0:\r\n print(max(get_index(w,'E',x),get_index(w,'N',y))+1)\r\n elif y<0:\r\n print(max(get_index(w, 'E', x), get_index(w, 'S',-y))+1)\r\n elif x<0:\r\n if y==0:\r\n print(get_index(w, 'W', -x)+1)\r\n elif y>0:\r\n print(max(get_index(w, 'W', -x),get_index(w,'N',y))+1)\r\n elif y<0:\r\n print(max(get_index(w,'W',-x),get_index(w,'S',-y))+1)\r\n else:\r\n if y>0:\r\n print(get_index(w,'N',y)+1)\r\n else:\r\n print(get_index(w,'S',-y)+1)", "def find_nth(haystack, needle, n):\r\n start = haystack.find(needle)\r\n while start >= 0 and n > 1:\r\n start = haystack.find(needle, start+len(needle))\r\n n -= 1\r\n return start\r\n\r\na = [int(e) for e in input().split()]\r\nt = a[0]\r\nstart = [a[1], a[2]]\r\nend = [a[3], a[4]]\r\n\r\nb = str(input()) # SESNW\r\nwind = {'S': 0, 'E': 0, 'N': 0, 'W': 0}\r\nfor e in b:\r\n wind[e] += 1\r\n# wind = {'S': 2, 'E': 1, 'N': 1, 'W': 1}\r\n\r\nneed_wind = dict()\r\nif end[0] - start[0] > 0:\r\n need_wind['E'] = (end[0] - start[0])\r\nif end[0] - start[0] < 0:\r\n need_wind['W'] = (start[0] - end[0])\r\nif end[1] - start[1] > 0:\r\n need_wind['N'] = (end[1] - start[1])\r\nif end[1] - start[1] < 0:\r\n need_wind['S'] = (start[1] - end[1]) \r\n# need_wind = {'E': 1, 'N': 1}\r\n\r\nfor e in need_wind:\r\n if wind[e] < need_wind[e]:\r\n print(-1)\r\n exit()\r\n\r\nindx_wind = []\r\nfor e in need_wind:\r\n x = find_nth(b, e, need_wind[e])\r\n indx_wind.append(x)\r\nprint(max(indx_wind) + 1)", "arr= list(map(int,input().split()))\r\ncomand= input()\r\n\r\nt= arr[0]\r\ny= arr[4]-arr[2]\r\nx= arr[3]-arr[1]\r\n\r\ncheck=set()\r\nif x>0:\r\n check.add(\"E\")\r\nelif x<0:\r\n check.add(\"W\")\r\n\r\nif y>0:\r\n check.add(\"N\")\r\nelif y<0:\r\n check.add(\"S\")\r\n \r\n\r\nif x==0 and y==0:\r\n print(0)\r\n \r\n\r\nelse:\r\n f=0\r\n for i in range(len(comand)):\r\n if comand[i] in check:\r\n if comand[i] in ['E','W'] and x!=0:\r\n if x>0:\r\n x-=1\r\n else:\r\n x+=1\r\n elif comand[i] in ['N','S'] and y!=0:\r\n if y>0:\r\n y-=1\r\n else:\r\n y+=1\r\n if x==0 and y==0:\r\n print(i+1)\r\n f=1\r\n break\r\n \r\n if f==0:\r\n print(-1)\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ", "t,a,b,c,d=map(int,input().split())\ns=input()\ns=list(s)\ncounter=0\ndic={'N':1,'S':-1,'E':1,'W':-1}\nfor i in range(len(s)):\n if (s[i]=='W' or s[i]=='E'):\n if (abs(c-a-dic[s[i]]) <=abs(c-a)):\n a=a+dic[s[i]]\n counter=i+1\n else:\n if (abs(d-b-dic[s[i]])<=abs(d-b)):\n b=b+dic[s[i]]\n counter=i+1\nif(a==c and d==b):\n print(counter)\nelse:\n print(-1) \n\n", "n = input().split()\r\ns = input()\r\nt,x,y,p,q = int(n[0]),int(n[1]),int(n[2]),int(n[3]),int(n[4])\r\nmove = 0\r\nfor i in s:\r\n if i == 'E' and x < p:\r\n x += 1\r\n elif i == 'S' and y > q:\r\n y -= 1\r\n elif i == 'W' and x > p:\r\n x -= 1\r\n elif i == 'N' and y < q:\r\n y += 1\r\n move += 1\r\n if x == p and y == q:\r\n break\r\nif x == p and y == q and move <= t:\r\n print(move)\r\nelse:\r\n print(-1)\r\n\r\n", "\r\n\r\nt,a,b,c,d = map(int,input().split())\r\ns=str(input())\r\n\r\ns=[p for p in s]\r\n\r\nx=c-a\r\ny=d-b\r\n# print(x,y)\r\n\r\nif abs(c-a)+abs(d-b)>t:\r\n\tprint(\"-1\")\r\n\texit()\r\n\r\nif x<0:\r\n\tX=\"W\"\r\nif x>=0:\r\n\tX=\"E\"\r\nif y<0:\r\n\tY=\"S\"\r\nif y>=0:\r\n\tY=\"N\"\r\nx=abs(x)\r\ny=abs(y)\r\n# print(x,y)\r\n# print(X,Y)\r\n\r\np=0\r\nq=0\r\nv=0\r\ncntx=0\r\ncnty=0\r\nfor i in range(len(s)):\r\n\tif s[i]==X:\r\n\t\tcntx+=1\r\n\t\t#print(\"t\")\r\n\t\tif cntx==x:\r\n\t\t\tp=i\r\n\t\t\tbreak\r\n\t\r\n\t\t\t\r\n\t\t\r\n\r\nfor i in range(len(s)):\r\n\tif s[i]==Y:\r\n\t\tcnty+=1\r\n\t\tif cnty==y:\r\n\t\t\tq=i\r\n\t\t\tbreak\r\n\t\t\r\n\t\t\t\r\n\t\t\r\n\r\n\r\n\r\n# print(p,q)\r\n\t\t\r\nif cntx<x or cnty<y:\r\n\tprint(\"-1\")\r\n\r\nelse:\r\n\tprint(max(p+1,q+1))\r\n\r\n\r\n\r\n\r\n\r\n", "t,sx,sy,ex,ey=map(int,input().split())\r\nstr=input()\r\ntime=-1\r\n\r\nfor x in range(len(str)):\r\n\r\n if str[x]=='E':\r\n if sx<ex:\r\n sx+=1\r\n if str[x]=='S':\r\n if ey<sy:\r\n sy-=1\r\n if str[x]=='W':\r\n if ex<sx:\r\n sx-=1\r\n if str[x]=='N':\r\n if sy<ey:\r\n sy+=1\r\n if ex==sx and ey==sy:\r\n time=x+1\r\n break\r\nprint(time)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "# cook your dish here\r\nfrom sys import stdin, stdout\r\nimport math\r\nfrom itertools import permutations, combinations\r\nfrom collections import defaultdict\r\nfrom bisect import bisect_left \r\nfrom bisect import bisect_right\r\n \r\ndef L():\r\n return list(map(int, stdin.readline().split()))\r\n \r\ndef In():\r\n return map(int, stdin.readline().split())\r\n \r\ndef I():\r\n return int(stdin.readline())\r\n \r\nP = 1000000007\r\ndef main():\r\n t, sx, sy, ex, ey = In()\r\n st = input()\r\n x = (ex-sx)\r\n y = (ey-sy)\r\n ce, cw, cs, cn = 0,0,0,0\r\n if x > 0:\r\n ce = x \r\n else:\r\n cw = -x \r\n if y > 0:\r\n cn = y \r\n else:\r\n cs = -y\r\n flag = -1\r\n for i in range(t):\r\n if st[i] == 'E':\r\n ce -= 1 \r\n elif st[i] == 'W':\r\n cw -= 1 \r\n elif st[i] == 'S':\r\n cs -= 1 \r\n else:\r\n cn -= 1\r\n if ce <= 0 and cw <= 0 and cs <= 0 and cn <= 0:\r\n flag = i+1 \r\n break \r\n print(flag)\r\n \r\nif __name__ == '__main__':\r\n main()\r\n", "def solve(t, s1, s2, e1, e2, winds):\n\n hor = abs(e1 - s1)\n dir_hor = int((e1 - s1) > 0)\n\n ver = abs(e2 - s2)\n dir_ver = int((e2 - s2) > 0)\n\n for idx, l in enumerate(winds):\n\n if l == \"S\":\n if dir_ver == 0:\n ver -= 1\n\n if l == \"E\":\n if dir_hor == 1:\n hor -= 1\n\n if l == \"W\":\n if dir_hor == 0:\n hor -= 1\n\n if l == \"N\":\n if dir_ver == 1:\n ver -= 1\n\n if hor <= 0 and ver <= 0:\n return idx + 1\n\n return -1\n\n\narr = [int(a) for a in input().split(\" \")]\nwinds = input()\n\nt, s1, s2, e1, e2 = arr[0],arr[1],arr[2],arr[3],arr[4]\n\nprint(solve(t, s1, s2, e1, e2, winds))\n\t\t \t\t \t\t\t\t\t \t \t\t \t\t\t \t\t\t\t\t", "n,sx,sy,dx,dy=[int(i) for i in input().split()]\na=input()\ncount=0\ntag=0\nfor i in a:\n if (dx>sx) and (i=='E'):\n sx=sx+1\n elif (dx<sx) and (i=='W'):\n sx=sx-1\n if (dy>sy) and (i=='N'):\n sy=sy+1\n if (dy < sy) and (i == 'S'):\n sy = sy -1\n count+=1\n if (dx==sx and dy==sy):\n print(count)\n tag=1\n break\nif (tag==0):\n print(-1)\n", "def ans(t,sx,sy,ex,ey,s):\n for i in range(t):\n if s[i] == 'N':\n if ey > sy:\n sy += 1\n elif s[i] == 'S':\n if ey < sy:\n sy -= 1\n elif s[i] == 'E':\n if ex > sx:\n sx += 1\n elif s[i] == 'W':\n if ex < sx:\n sx -= 1\n \n if sx == ex and sy == ey:\n print(i+1)\n return\n print(-1)\n return\n\nt,sx,sy,ex,ey = map(int,input().split())\ns = list(input())\nans(t,sx,sy,ex,ey,s)", "t,x,y,x1,y1 = map(int , input().split())\r\ns = input()\r\na = x1-x\r\nb = y1-y\r\nc = 0\r\nfor i in s:\r\n c+=1\r\n if c<=t:\r\n if a<0 and i==\"W\":\r\n a+=1\r\n elif a>0 and i==\"E\":\r\n a-=1\r\n if b<0 and i==\"S\":\r\n b+=1\r\n elif b>0 and i==\"N\":\r\n b-=1\r\n if a==b==0:\r\n break\r\n else:\r\n break\r\nif a==b==0:\r\n print(c)\r\nelse:\r\n print(-1)\r\n", "# /**\r\n# * author: brownfox2k6\r\n# * created: 08/06/2023 14:37:03 Hanoi, Vietnam\r\n# **/\r\n\r\nt, sx, sy, ex, ey = map(int, input().split())\r\ns = input()\r\nneed = dict.fromkeys([c for c in \"WENS\"], 0)\r\ncur = dict.fromkeys([c for c in \"WENS\"], 0)\r\n\r\nif sx > ex:\r\n need['W'] = sx - ex\r\nelse:\r\n need['E'] = ex - sx\r\nif sy > ey:\r\n need['S'] = sy - ey\r\nelse:\r\n need['N'] = ey - sy\r\n\r\nfor i in range(len(s)):\r\n cur[s[i]] += 1\r\n for c in \"WENS\":\r\n if cur[c] < need[c]:\r\n break\r\n else:\r\n exit(print(i + 1))\r\nelse:\r\n print(-1)", "t, x, y, a, b = map(int, input().split())\r\nwind = input()\r\n \r\nfound = False\r\n \r\nfor i in range(t):\r\n if wind[i] == 'E':\r\n if x < a:\r\n x += 1\r\n \r\n elif wind[i] == 'W':\r\n if x > a:\r\n x -= 1\r\n \r\n elif wind[i] == 'S':\r\n if y > b:\r\n y -= 1\r\n \r\n elif wind[i] == 'N':\r\n if y < b:\r\n y += 1\r\n \r\n if x == a and y == b:\r\n found = True\r\n print(i + 1)\r\n break\r\n \r\nif not found:\r\n print(-1)", "b, sx, sy, ex, ey = map(int, input().split())\r\nwind = input()\r\n\r\nscore = 0\r\nfor c in wind:\r\n if sx > ex and c == 'W':\r\n sx -= 1\r\n \r\n if sx < ex and c == 'E':\r\n sx += 1\r\n\r\n if sy > ey and c == 'S':\r\n sy -= 1\r\n\r\n if sy <ey and c == 'N':\r\n sy += 1\r\n\r\n score += 1\r\n if sx == ex and sy == ey:\r\n break\r\n\r\nif sx == ex and sy == ey:\r\n print(score)\r\nelse:\r\n print(-1)", "def readn():\n return int(input())\ndef readlist():\n return list(map(int,input().split()))\ndef readnos():\n return map(int,input().split())\n\nt,sx,sy,ex,ey = readnos()\nd = input()\nx = ex - sx\ny = ey - sy\ni = 0\nwhile i < t:\n if x == 0 and y == 0:\n break\n if x > 0:\n if y > 0:\n if d[i] == 'E':\n x-=1\n elif d[i] == 'N':\n y -= 1\n elif y < 0:\n if d[i] == 'E':\n x -= 1\n elif d[i] == 'S':\n y += 1\n if x < 0:\n if y > 0:\n if d[i] == 'W':\n x+=1\n elif d[i] == 'N':\n y -= 1\n elif y < 0:\n if d[i] == 'W':\n x += 1\n elif d[i] == 'S':\n y += 1\n if x == 0:\n if y > 0:\n if d[i] == 'N':\n y -= 1\n elif y < 0:\n if d[i] == 'S':\n y += 1\n if y == 0:\n if x > 0:\n if d[i] == 'E':\n x -= 1\n elif x < 0:\n if d[i] == 'W':\n x += 1\n i += 1\n\nif x == 0 and y == 0:\n print(i)\nelse:\n print(-1)", "if __name__ == '__main__':\n locs = list(map(int, input().split()))\n\n wind = input()\n\n displacement_x = locs[3] - locs[1]\n displacement_y = locs[4] - locs[2]\n\n if displacement_x >= 0:\n anchor_x = 'E'\n else:\n anchor_x = 'W'\n\n if displacement_y >= 0:\n anchor_y = 'N'\n else:\n anchor_y = 'S'\n\n displacement_x = abs(displacement_x)\n displacement_y = abs(displacement_y)\n\n\n for i in range(len(wind)):\n if wind[i] == anchor_x:\n displacement_x -= 1\n if wind[i] == anchor_y:\n displacement_y -= 1\n if displacement_x <= 0 and displacement_y <= 0:\n print(i+1)\n exit()\n \n \n print(-1)\n \t \t\t \t \t \t \t\t\t\t \t\t\t\t", "import math\r\n\r\ndef distance(o1,o2,e1,e2):\r\n return math.sqrt( ((o1-e1)**2)+((o2-e2)**2) )\r\n\r\nstring=input().split(\" \")\r\nt,o1,o2,e1,e2=int(string[0]),int(string[1]),int(string[2]),int(string[3]),int(string[4])\r\ntest_case=input()\r\ndist=distance(o1,o2,e1,e2)\r\n\r\nhash={ \"E\" :[1,0] , \"S\" : [0,-1] ,\"N\":[0,1],\"W\":[-1,0] }\r\nc=0\r\nfor i in test_case:\r\n h=hash.get(i)\r\n temp_1,temp_2=o1+h[0],o2+h[1]\r\n if(distance(temp_1,temp_2,e1,e2)<dist):\r\n dist=distance(temp_1,temp_2,e1,e2)\r\n o1=temp_1\r\n o2=temp_2\r\n if(o1==e1 and o2==e2 ):\r\n break\r\n c+=1\r\nif(c==t):\r\n print(-1)\r\nelse:\r\n print(c+1)\r\n\r\n", "n,x,y,xx,yy=map(int,input().split())\r\nif xx>=x:\r\n W,E=0,xx-x\r\nelse:\r\n E,W=0,x-xx\r\nif yy>=y:\r\n S,N=0,yy-y\r\nelse:\r\n N,S=0,y-yy\r\n# print N,S,E,W\r\ns=input()\r\ni=0\r\nwhile i<len(s) and any(j!=0 for j in [W,E,S,N]):\r\n if s[i]==\"S\" and S>0:\r\n S-=1\r\n if s[i]==\"N\" and N>0:\r\n N-=1\r\n if s[i]==\"W\" and W>0:\r\n W-=1\r\n if s[i]==\"E\" and E>0:\r\n E-=1\r\n i+=1\r\nif all(j==0 for j in [W,E,S,N]):\r\n print (i)\r\nelse:\r\n print( -1)", "def dist(first, second):\n return abs(second-first)\ndic = {\n 'E': lambda x, y: (x+1, y),\n 'N': lambda x, y: (x, y+1),\n 'S': lambda x, y: (x, y-1),\n 'W': lambda x, y: (x-1, y),\n}\nN, xs, ys, xe, ye = map(int,input().split())\ns = input()\nfor i in range(len(s)):\n new_x, new_y = dic[s[i]](xs, ys)\n if dist(new_x, xe) < dist(xs, xe) or dist(new_y, ye) < dist(ys, ye):\n xs, ys = new_x, new_y\n if xs == xe and ys == ye:\n print(i+1)\n break\nelse:\n print(-1)", "t, sx, sy, ex, ey = map(int, input().split())\r\nl = input()\r\nres = 0\r\n\r\npx = ex - sx\r\npy = ey - sy\r\n\r\nph = '' \r\npv = ''\r\n\r\nif px > 0:\r\n ph = 'E'\r\nelse:\r\n ph = 'W'\r\n\r\nif py > 0:\r\n pv = 'N'\r\nelse:\r\n pv = 'S'\r\n\r\npx = abs(px)\r\npy = abs(py)\r\n\r\nfor i in l:\r\n if res == t:\r\n res = '-1'\r\n break\r\n \r\n if px == 0 and py == 0:\r\n break\r\n \r\n if i == ph and px > 0:\r\n px -=1\r\n if i == pv and py > 0:\r\n py -= 1\r\n\r\n res += 1\r\n\r\nif res == t and (py != 0 or px != 0):\r\n res = -1\r\n\r\nprint(res)", "t, ex, ey, sx, sy = map(int, input().split())\r\nwind_directions = input()\r\ndx = sx - ex\r\ndy = sy - ey\r\nfor i in range(t):\r\n if dx > 0 and wind_directions[i] == \"E\":\r\n dx -= 1\r\n elif dx < 0 and wind_directions[i] == \"W\":\r\n dx += 1\r\n elif dy > 0 and wind_directions[i] == \"N\":\r\n dy -= 1\r\n elif dy < 0 and wind_directions[i] == \"S\":\r\n dy += 1\r\n if dx == 0 and dy == 0:\r\n print(i + 1)\r\n exit(0)\r\nprint(\"-1\")", "t, sx, sy, ex, ey = list(map(int, input().split()))\r\nd = input(); c = 0; f = False\r\nfor i in range(t):\r\n if d[i] == 'N' and sy < ey:\r\n sy += 1\r\n elif d[i] == 'S' and sy > ey:\r\n sy -= 1\r\n elif d[i] == 'E' and sx < ex:\r\n sx += 1\r\n elif d[i] == 'W' and sx > ex:\r\n sx -= 1\r\n c += 1\r\n if sx == ex and sy == ey:\r\n f = True\r\n break\r\nif not f: print(-1)\r\nelse: print(c)", "if __name__ == '__main__':\n t, sx, sy, ex, ey = map(int, input().split())\n s = list(input())\n\n ne = ex - sx\n nn = ey - sy\n\n if not (ne or nn):\n print(0)\n\n else:\n cnt = -1\n\n for i, c in enumerate(s):\n if c == 'N':\n if nn > 0:\n nn -= 1\n if c == 'S':\n if nn < 0:\n nn += 1\n if c == 'E':\n if ne > 0:\n ne -= 1\n if c == 'W':\n if ne < 0:\n ne += 1\n if not (ne or nn):\n cnt = i + 1\n break\n\n print(cnt)\n", "from math import sqrt\r\nt,sx,sy,ex,ey = map(int, input().split())\r\ns = list(input())\r\n\r\ndistance = lambda x1,y1,x2,y2: sqrt((x2-x1)**2 + (y1-y2)**2)\r\n\r\nd = distance(sx,sy,ex,ey)\r\n\r\nrX = []\r\nrY = []\r\nfor i in range(t):\r\n if s[i] == 'N':\r\n rX.append(0)\r\n rY.append(1)\r\n elif s[i] == 'S':\r\n rX.append(0)\r\n rY.append(-1)\r\n elif s[i] == 'W':\r\n rX.append(-1)\r\n rY.append(0)\r\n else:\r\n rX.append(1)\r\n rY.append(0)\r\n\r\ntime = 0\r\nfor x,y in zip(rX, rY):\r\n\r\n if distance (sx,sy,ex,ey) > distance(sx+x, sy+y, ex, ey):\r\n sx = sx + x\r\n sy = sy + y\r\n else:\r\n pass\r\n time += 1\r\n if sx == ex and sy == ey:\r\n print(time)\r\n break\r\nelse:\r\n print(-1)", "# https://codeforces.com/problemset/problem/298/B\n\n\nif __name__ == '__main__':\n t, sx, sy, ex, ey = map(int, input().split())\n seq = input()\n\n diff_x = ex - sx\n diff_y = ey - sy\n\n ans = 0\n \n while ans < t and (diff_x != 0 or diff_y != 0):\n if seq[ans] == 'N':\n if diff_y > 0:\n diff_y -= 1\n elif seq[ans] == 'S':\n if diff_y < 0:\n diff_y += 1\n elif seq[ans] == 'E':\n if diff_x > 0:\n diff_x -= 1\n elif diff_x < 0:\n diff_x += 1\n ans += 1\n \n if diff_x == 0 and diff_y == 0:\n print(ans)\n else:\n print(-1)\n \n\n", "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\nl=0;r=0;u=0;d=0\r\nfor i in range(t):\r\n if s[i]=='E':\r\n r+=1\r\n if s[i]=='W':\r\n l+=1\r\n if s[i]=='S':\r\n d+=1\r\n if s[i]=='N':\r\n u+=1\r\nboo=True\r\nif not((ex-sx<=0 and l>=abs(ex-sx)) or (ex-sx>0 and r>=abs(ex-sx))):\r\n boo=False\r\nif not((ey-sy<=0 and d>=abs(ey-sy)) or (ey-sy>0 and u>=abs(ey-sy))):\r\n boo=False\r\nif not boo:\r\n print(-1)\r\nelse:\r\n ans=0\r\n for i in range(t):\r\n if ex==sx and ey==sy:\r\n break\r\n if ex<sx and s[i]=='W':\r\n sx-=1\r\n if ex>sx and s[i]=='E':\r\n sx+=1\r\n if ey<sy and s[i]=='S':\r\n sy-=1\r\n if ey>sy and s[i]=='N':\r\n sy+=1\r\n ans+=1\r\n print(ans)\r\n", "t, sx, sy, ex, ey = list(map(int, input().split()))\r\ns = input()\r\n\r\nfor _ in range(len(s)):\r\n i = s[_]\r\n if i == 'E':\r\n if sx < ex:\r\n sx += 1\r\n elif i == 'S':\r\n if sy > ey:\r\n sy -= 1\r\n elif i == 'W':\r\n if sx > ex:\r\n sx -= 1\r\n else:\r\n if sy < ey:\r\n sy += 1\r\n if sx == ex and sy == ey:\r\n print(_ + 1)\r\n break\r\nelse:\r\n print(-1) ", "t,sx,sy,dx,dy=list(map(int,input().split()))\r\ndirections=input()\r\ncount=0\r\ncurr=(dx-sx)**2+(dy-sy)**2\r\n\r\nfor d in directions:\r\n if curr==0:\r\n break \r\n if d==\"E\":\r\n if (dx-(sx+1))**2+(dy-sy)**2<curr:\r\n sx=sx+1\r\n curr=(dx-sx)**2+(dy-sy)**2\r\n if d==\"W\":\r\n if (dx-(sx-1))**2+(dy-sy)**2<curr:\r\n sx=sx-1\r\n curr=(dx-sx)**2+(dy-sy)**2 \r\n if d==\"N\":\r\n if (dx-sx)**2+(dy-(sy+1))**2<curr:\r\n sy=sy+1\r\n curr=(dx-sx)**2+(dy-sy)**2\r\n if d==\"S\":\r\n if (dx-sx)**2+(dy-(sy-1))**2<curr:\r\n sy=sy-1\r\n curr=(dx-sx)**2+(dy-sy)**2\r\n count+=1 \r\nif not curr :\r\n print(count)\r\nelse:\r\n print(\"-1\") \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "from sys import stdin,stdout\ndef move(dir,sx,sy):\n if dir=='E':\n sx+=1\n elif dir=='W':\n sx-=1\n elif dir=='N':\n sy+=1\n elif dir=='S':\n sy-=1\n return sx,sy\n\nt,sx,sy,ex,ey=map(int,stdin.readline().split())\nif sx==ex and sy==ey:\n stdout.write('0')\ndir =[] \nif sx>ex:\n dir.append('W')\nif sx<ex:\n dir.append('E')\nif sy>ey:\n dir.append('S')\nif sy<ey:\n dir.append('N')\nwinds =stdin.readline().strip()\nseconds = 0\n\nfor d in winds:\n seconds+=1\n if d in dir:\n sx,sy=move(d,sx,sy)\n if sx==ex:\n if 'E' in dir:\n dir.remove('E')\n elif 'W' in dir:\n dir.remove('W')\n if sy==ey:\n if 'N' in dir:\n dir.remove('N')\n elif 'S' in dir:\n dir.remove('S')\n\n\n if sx==ex and sy==ey:\n break\n\n\nif sx==ex and sy==ey:\n stdout.write(str(seconds))\nelse:\n stdout.write('-1')\n \n\n", "n, sx, sy, ex, ey = map(int, input().split())\ns = input()\nx = ex - sx\ny = ey - sy\nans = 0\ni = 0\nif x < 0:\n while x != 0 and i < n:\n if s[i] == 'W':\n x += 1\n if x == 0:\n break\n i += 1\nelse:\n while x != 0 and i < n:\n if s[i] == 'E':\n x -= 1\n if x == 0:\n break\n i += 1\nif i >= n:\n print(-1)\n exit()\nans = max(i, ans)\ni = 0\nif y < 0:\n while y != 0 and i < n:\n if s[i] == 'S':\n y += 1\n if y == 0:\n break\n i += 1\nelse:\n while y != 0 and i < n:\n if s[i] == 'N':\n y -= 1\n if y == 0:\n break\n i += 1\nif i >= n:\n print(-1)\n exit()\nans = max(i, ans)\nprint(ans + 1)\n", "n,sx,sy,ex,ey=map(int,input().split())\r\nc=0\r\nd=input(\"\")\r\nfor i in d:\r\n if sx<ex and i=='E':\r\n sx+=1\r\n elif i=='W' and sx>ex:\r\n sx-=1\r\n elif sy<ey and i=='N':\r\n sy+=1\r\n elif i=='S' and sy>ey:\r\n sy-=1\r\n elif sx==ex and sy==ey:\r\n break\r\n c+=1\r\nif sx==ex and sy==ey:\r\n print(c)\r\nelse:\r\n print(-1)\r\n", "allnums = input()\r\nallnumslist = allnums.split()\r\nx1 = int(allnumslist[1])\r\ny1 = int(allnumslist[2])\r\nx2 = int(allnumslist[3])\r\ny2 = int(allnumslist[4])\r\n\r\ncount = 0\r\ndirection = input()\r\nfor i in range(len(direction)):\r\n if x1 != x2 or y1 != y2:\r\n count += 1\r\n if x1 < x2:\r\n if direction[i] == 'E':\r\n x1 += 1 \r\n if y1 < y2:\r\n if direction[i] == 'N':\r\n y1 += 1\r\n if x1 > x2:\r\n if direction[i] == 'W':\r\n x1 -= 1 \r\n if y1 > y2:\r\n if direction[i] == 'S':\r\n y1 -= 1\r\n\r\n \r\n \r\nif x1 != x2 or y1 != y2:\r\n print('-1')\r\nif x1 == x2 and y1 == y2:\r\n print(count)", "#B. Sail\r\nt,sx,sy,ex,ey = map(int,input().split())\r\nd = list(input())\r\nx,y = sx,sy\r\nmoves = 0\r\nfor i in d:\r\n if ex==x and ey == y:\r\n break\r\n if i == 'N'and y<ey:\r\n y += 1\r\n elif i == 'S' and y>ey:\r\n y -= 1\r\n elif i == 'E' and x<ex:\r\n x += 1\r\n elif i == 'W' and x>ex:\r\n x -= 1\r\n moves += 1\r\nif ex==x and ey == y:\r\n print(moves)\r\nelse:\r\n print(-1)", "t, sx, sy, ex, ey = map(int, input().split())\r\ndx, dy = ex-sx, ey-sy\r\nwind = input()\r\nfail = False\r\n\r\nxcount = 0\r\nycount = 0\r\n\r\nfor i in wind:\r\n ycount += 1\r\n if dy>0:\r\n if i=='N':\r\n dy -= 1\r\n if dy<0:\r\n if i=='S':\r\n dy += 1\r\n if dy==0:\r\n break\r\nelse:\r\n fail = True\r\n\r\nfor i in wind:\r\n xcount += 1\r\n if dx>0:\r\n if i=='E':\r\n dx -= 1\r\n if dx<0:\r\n if i=='W':\r\n dx += 1\r\n if dx==0:\r\n break\r\nelse:\r\n fail = True\r\n\r\nif fail == True:\r\n print(-1)\r\nelse:\r\n print(max(xcount, ycount))\r\n\r\n", "def Sail():\r\n def convert(string):\r\n list1 = []\r\n list1[:0] = string\r\n return list1\r\n #East,West affect x coord , North, soth affect y coordinate\r\n t , sx, sy, ex, ey = map(int , input().split())\r\n windDirections = convert(input())\r\n\r\n E = 0\r\n W = 0\r\n N = 0\r\n S = 0\r\n if ex > sx : E += ex - sx\r\n else: W += sx - ex\r\n\r\n if ey > sy: N += ey - sy\r\n else: S += sy - ey\r\n\r\n #print(E,W,N,S)\r\n\r\n direction_dict = {}\r\n direction_dict['E'] = 0\r\n direction_dict['W'] = 0\r\n direction_dict['N'] = 0\r\n direction_dict['S'] = 0\r\n\r\n time_taken = 0\r\n for i in windDirections:\r\n\r\n direction_dict[i] += 1\r\n time_taken += 1\r\n #print(direction_dict , time_taken),\r\n\r\n\r\n if direction_dict['E'] >= E and direction_dict['W'] >= W and direction_dict['N'] >= N and direction_dict['S'] >= S:\r\n #print(direction_dict, \"yes\")\r\n break\r\n\r\n if time_taken < t :\r\n print(time_taken)\r\n elif direction_dict['E'] >= E and direction_dict['W'] >= W and direction_dict['N'] >= N and direction_dict['S'] >= S:\r\n print(time_taken)\r\n else:\r\n print(-1)\r\n\r\n\r\nSail()", "import math,sys\r\na = list(map(int,input().split()))\r\nb = list(input())\r\nif a[1] == a[3] and a[2] == a[4]:\r\n print(0)\r\n sys.exit(0)\r\nflag = False\r\nc = 0\r\nfor i in range(len(b)):\r\n c +=1\r\n if b[i] == 'S':\r\n if math.fabs(a[4]-(a[2]-1)) > math.fabs(a[4]-(a[2])):\r\n continue\r\n a[2] -= 1\r\n if b[i] == 'E':\r\n if math.fabs(a[3]-(a[1]+1)) > math.fabs(a[3]-(a[1])):\r\n continue\r\n a[1] += 1\r\n if b[i] == 'W':\r\n if math.fabs(a[3]-(a[1]-1)) > math.fabs(a[3]-(a[1])):\r\n continue\r\n a[1] -= 1\r\n if b[i] == 'N':\r\n if math.fabs(a[4]-(a[2]+1)) > math.fabs(a[4]-(a[2])):\r\n continue\r\n a[2] += 1\r\n if a[1] == a[3] and a[2] == a[4]:\r\n flag = True\r\n break\r\n\r\n\r\nif flag :\r\n print(c)\r\nelse:\r\n print(-1)\r\n\r\n", "t, x, y, x_0, y_0 = [int(x) for x in input().split()]\r\ncurrent = 0\r\nx_1 = x_0 - x\r\ny_1 = y_0 - y\r\nfor i in input():\r\n if x_1 > 0 and i == 'E':\r\n x_1 -= 1\r\n elif x_1 < 0 and i == 'W':\r\n x_1 += 1\r\n elif y_1 > 0 and i == 'N':\r\n y_1 -= 1\r\n elif y_1 < 0 and i == 'S':\r\n y_1 += 1\r\n current += 1\r\n if y_1 == 0 and x_1 == 0:\r\n break\r\nprint(current if y_1 == 0 and x_1 == 0 else -1)", "s = input().split(' ')\r\n\r\nt = int(s[0])\r\nsx = int(s[1])\r\nsy = int(s[2])\r\nex = int(s[3])\r\ney = int(s[4])\r\n\r\nstep_x = ex-sx\r\nstep_y = ey-sy\r\ni = 0\r\ndirection = input()\r\nwhile (step_x !=0 or step_y != 0) and i<t:\r\n\tif step_x<0:\r\n\t\tif direction[i]=='W':\r\n\t\t\tstep_x += 1\r\n\telif step_x>0:\r\n\t\tif direction[i]=='E':\r\n\t\t\tstep_x -= 1\r\n\tif step_y<0:\r\n\t\tif direction[i]=='S':\r\n\t\t\tstep_y += 1\r\n\telif step_y>0:\r\n\t\tif direction[i]=='N':\r\n\t\t\tstep_y -= 1\r\n\ti += 1\r\nif step_x!=0 or step_y!=0:\r\n\tprint('-1')\r\nelse:\r\n\tprint(i)", "t,sx,sy,ex,ey = list(map(int,input().split()))\r\nans = 0\r\ns = input()\r\nfor i in range(len(s)):\r\n \r\n if sx > ex and s[i] == 'W':\r\n sx-=1\r\n \r\n elif ex > sx and s[i] == 'E':\r\n sx+=1\r\n elif sy > ey and s[i] == 'S':\r\n sy = sy - 1\r\n elif ey > sy and s[i] == 'N':\r\n \r\n sy = sy + 1\r\n \r\n if (sx == ex) and (sy == ey):\r\n print(i+1)\r\n break\r\nelse:\r\n \r\n print(-1)\r\n ", "def solve():\r\n t,s,s1,e,e1=map(int,input().split())\r\n di=input()\r\n to=0\r\n for i in di:\r\n if(s==e and s1==e1):\r\n print(to)\r\n return\r\n if(s>e):\r\n if i=='W':\r\n s-=1\r\n elif(s<e):\r\n if i=='E':\r\n s+=1\r\n if(s1>e1):\r\n if i=='S':\r\n s1-=1\r\n elif s1<e1:\r\n if i=='N':\r\n s1+=1\r\n to+=1\r\n print(to) if(s==e and s1==e1) else print(-1)\r\n \r\nif __name__ == '__main__':\r\n solve()", "t,sy,sx,ey,ex=list(map(int,input().split()))\r\ninp=input()\r\ndx=sx-ex\r\ndy=sy-ey\r\nfor i in range(t):\r\n if inp[i]==\"N\" and dx<0:\r\n dx+=1\r\n elif inp[i]==\"S\" and dx>0:\r\n dx+=-1\r\n elif inp[i]==\"E\" and dy<0:\r\n dy+=1\r\n elif inp[i]==\"W\" and dy>0:\r\n dy+=-1\r\n if dy==0 and dx==0:\r\n print(1+i)\r\n exit()\r\nelse:\r\n print(-1)\r\n ", "a,x,y,d,e=map(int,input().split())\r\nk= input()\r\nm=0\r\nfor i in k:\r\n m +=1\r\n if (i=='S')and (y>e):\r\n y-=1\r\n elif (i=='E') and (x<d):\r\n x+=1\r\n elif (i=='N') and (y<e):\r\n y+=1\r\n elif (i=='W') and (x>d):\r\n x-=1\r\n if y==e and x==d:\r\n print(m)\r\n break\r\nif y!=e or x!=d:\r\n print(-1)\r\n", "t, x, y, xe, ye = map(int, input().split())\n\ndirections = input()\n\ni,j = x, y\nt = 0\nfor direction in directions:\n if i == xe and j == ye:\n print(t)\n exit()\n\n\n if direction == \"E\" and xe > i:\n i += 1\n elif direction == \"S\" and ye < j:\n j -= 1\n \n elif direction == \"N\" and ye > j:\n j += 1\n elif direction == \"W\" and xe < i:\n i -= 1\n\n \n t += 1\n\nif i == xe and j == ye:\n print(t)\n exit()\nprint(-1)", "x=list(map(int, input().split()))\r\na=input()\r\nfreq = {}\r\nfor item in a:\r\n if (item in freq):\r\n freq[item] += 1\r\n else:\r\n freq[item] = 1\r\ns1=x[1]\r\ns2=x[2]\r\ne1=x[3]\r\ne2=x[4]\r\nc={}\r\nif s1>e1:\r\n c['W']=s1-e1\r\nelif s1<e1:\r\n c['E']=e1-s1\r\nif s2>e2:\r\n c['S']=s2-e2\r\nelif s2<e2:\r\n c['N']=e2-s2\r\nf=0\r\nfor i in c:\r\n if i not in freq:\r\n f=1\r\n break\r\n else:\r\n if c[i]>freq[i]:\r\n f=1\r\n break\r\nif f==1:\r\n print(-1)\r\nelse:\r\n r=[]\r\n for i in c:\r\n p=[pos for pos, char in enumerate(a) if char == i]\r\n q=p[:(c[i])]\r\n r.append(q[-1])\r\n res=max(r)+1\r\n print(res)", "n,x0,y0,x1,y1=map(int,input().split())\r\nif y0>y1:a2='S'\r\nelse:a2='N'\r\nif x0>x1:a1='W'\r\nelse:a1='E'\r\nk1,k2=abs(x0-x1),abs(y0-y1)\r\ns=input()\r\nl=len(s)\r\ni=0\r\nwhile i<l and (k2>0 or k1>0):\r\n if s[i]==a1:k1-=1\r\n elif s[i]==a2:k2-=1\r\n i+=1\r\nif k1>0 or k2>0:print(-1)\r\nelse:print(i)", "t , x , y , a , b = map(int,input().split())\r\ns = list(input())\r\nn = len(s)\r\n\r\ni = 0\r\ncnt = 0\r\nwhile i < n :\r\n if s[i] == 'E':\r\n if a > x :\r\n x+=1\r\n cnt +=1\r\n else:\r\n cnt +=1\r\n\r\n elif s[i] == 'W':\r\n if a < x :\r\n x-=1\r\n cnt+=1\r\n else:\r\n cnt +=1\r\n\r\n elif s[i] == 'N':\r\n if b > y :\r\n y+=1\r\n cnt +=1\r\n else:\r\n cnt +=1\r\n\r\n else:\r\n if b < y :\r\n y-=1\r\n cnt +=1\r\n else:\r\n cnt +=1\r\n i +=1\r\n if x == a and y == b :\r\n break\r\n\r\n#print(cnt)\r\n#print(x)\r\n#print(y)\r\n\r\nif x == a and y == b :\r\n print(cnt)\r\nelse:\r\n print(-1)\r\n\r\n\r\n", "N,sx,sy,dx,dy = tuple(int(i) for i in input().split())\r\nA = input()\r\nanswered = False\r\nfor i in range(len(A)):\r\n\tif(A[i]==\"N\" and sy<dy):\r\n\t\tsy+=1\r\n\telif(A[i]==\"S\" and sy>dy):\r\n\t\tsy-=1\r\n\telif(A[i]==\"E\" and sx<dx):\r\n\t\tsx+=1\r\n\telif(A[i]==\"W\" and sx>dx):\r\n\t\tsx-=1\r\n\t\r\n\tif(sx==dx and sy==dy):\r\n\t\tprint(i+1)\r\n\t\tanswered = True\r\n\t\tbreak\r\n\r\nif(not answered):\r\n\tprint(\"-1\")", "inp=lambda:map(int,input().split())\n\nl = list(inp())\ns = input()\n\ndx = l[3] - l[1]\ndy = l[4] - l[2]\ncount = 0\n\nfor i in range(l[0]):\n if dx==0 and dy==0:\n break\n if dx < 0:\n if s[i]=='W':\n dx += 1\n \n elif dx > 0:\n if s[i]=='E':\n dx -= 1\n \n if dy < 0:\n if s[i]=='S':\n dy += 1\n \n elif dy > 0:\n if s[i]=='N':\n dy -= 1\n count += 1\n # print(i,count,dx, dy)\n\nif dx==0 and dy==0:\n print(count)\nelse:\n print(-1)\n\t\t\t\t\t\t\t \t \t\t\t \t\t\t\t \t\t \t \t", "(t,sx,sy,ex,ey) = tuple(map(int,input().split(' ')))\r\nwind = input()\r\n(tp,d,r,l)=(0,0,0,0)\r\nif ex>=sx:\r\n\tr = ex-sx\r\n\tif ey>=sy:\r\n\t\ttp = ey-sy\r\n\telse:\r\n\t\td = sy-ey\r\nelse:\r\n\tl = sx-ex\r\n\tif ey>=sy:\r\n\t\ttp = ey-sy\r\n\telse:\r\n\t\td = sy-ey\r\n\r\n#print(tp,d,l,r)\r\ndict1 = {'N':0,'W':0,'S':0,'E':0}\r\nans = -1;\r\nfor i in range(len(wind)):\r\n\tdict1[wind[i]] = dict1.get(wind[i],0)+1\r\n\tif dict1['N']>=tp and dict1['W']>=l and dict1['E']>=r and dict1['S']>=d:\r\n\t\tans = i+1\r\n\t\tbreak\r\nprint(ans)\r\n\t\r\n\t\r\n\t\r\n\t\r\n\r\n", "t, x, y, xl, yl = map(int, input().split())\np = str(input())\ndict = {'E':0, \"W\":0, \"S\":0, \"N\":0}\ncount = 0\nans = \"YES\"\nif xl - x >= 0:\n dict[\"E\"] = xl - x\nelif xl - x < 0:\n dict[\"W\"] = x - xl\nif yl - y >= 0:\n dict[\"N\"] = yl - y\nelif yl - y < 0:\n dict[\"S\"] = y - yl\nfor x, y in dict.items():\n i = 0\n while y > 0 and i < t:\n if p[i] == x:\n y -= 1\n i += 1\n if y > 0:\n ans = \"NO\"\n break\n count = max(count, i)\nif ans == \"NO\":\n print(-1)\nelse :\n print(count)", "def dist(sx, sy, ex, ey):\n return (sx-ex)**2 + (sy-ey)**2\n\n\nn, sx, sy, ex, ey = [int(x) for x in input().split()]\narr = input()\n\ndirections = {\n 'N': (0, 1),\n 'E': (1, 0),\n 'W': (-1, 0),\n 'S': (0, -1),\n}\n\nprev_dist = dist(sx, sy, ex, ey)\nif prev_dist != 0:\n count = 0\n msg = \"-1\"\n for d in arr:\n dx, dy = directions[d]\n nx = sx + dx\n ny = sy + dy\n distance = dist(nx, ny, ex, ey)\n if distance < prev_dist:\n sx = nx\n sy = ny\n prev_dist = distance\n count += 1\n\n if sx == ex and sy == ey:\n msg = count\n break\n print(msg)\nelse:\n print(\"0\")\n", "def gettingData():\r\n data=[]\r\n #Getting the first line\r\n timeAndCoord= input().split(maxsplit=5)\r\n for x in range(len(timeAndCoord)):\r\n timeAndCoord[x]=int(timeAndCoord[x])\r\n #print(f\"{timeAndCoord}\")\r\n movements=input()\r\n #print(f\"{movements}\")\r\n data.append(timeAndCoord)\r\n data.append(movements)\r\n #print(f\"{data}\") \r\n return data\r\n\r\ndef headingToTagCoordenate(data):\r\n sx=data[0][1]\r\n sy=data[0][2]\r\n ex=data[0][3]\r\n ey=data[0][4]\r\n movements=data[1]\r\n \r\n time=1\r\n for move in movements:\r\n if(move=='S' and sy>ey):\r\n sy-=1\r\n elif(move=='N' and sy<ey):\r\n sy+=1\r\n elif(move=='E' and sx<ex):\r\n sx+=1\r\n elif(move=='W' and sx>ex):\r\n sx-=1 \r\n\r\n if(ex==sx and ey==sy):\r\n return time\r\n time+=1\r\n \r\n return -1 #The ship does get to the tagged coordenates\r\n \r\ndata=gettingData()\r\ntimeToGetThere=headingToTagCoordenate(data)\r\nprint(f\"{timeToGetThere}\")", "def solve():\n t, sx, sy, ex, ey = list(map(int, input().split()))\n wind = input()\n time = -1\n\n for i in range(t):\n if wind[i] == 'E' and sx < ex:\n sx += 1\n elif wind[i] == 'S' and sy > ey:\n sy -= 1\n elif wind[i] == 'W' and sx > ex:\n sx -= 1\n elif wind[i] == 'N' and sy < ey:\n sy += 1\n \n if sx == ex and sy == ey:\n time = i + 1\n break\n\n print(time)\n\ndef main():\n solve()\n\nmain()\n\n \t\t \t \t \t\t\t\t \t\t\t \t\t \t \t\t\t\t", "INF = float('inf')\ndef calc(t, sx, sy, ex, ey, wind):\n if (sx, sy) == (ex,ey):\n return 0\n for i in range(len(wind)):\n wind_dir = wind[i]\n if wind_dir == 'E':\n nsx, nsy = sx+1, sy\n elif wind_dir == 'S':\n nsx, nsy = sx, sy-1\n elif wind_dir == 'W':\n nsx, nsy = sx-1, sy\n elif wind_dir == 'N':\n nsx, nsy = sx, sy+1\n\n if abs(ex - nsx) + abs(ey - nsy) > abs(ex-sx) + abs(ey-sy):\n continue\n sx, sy = nsx, nsy\n if (sx, sy) == (ex, ey):\n return i + 1\n return -1\n\n # get inputs\n#n = int(input())\n#a = list(map(int, input().split()))\nt, sx, sy, ex, ey = map(int, input().split())\nwind = input()\nres = calc(t, sx, sy, ex, ey, wind)\nprint(res)\n", "def get_earliest(t: int, directions: str, xdiff: int, ydiff: int):\n EAST = \"E\"\n WEST = \"W\"\n SOUTH = \"S\"\n NORTH = \"N\"\n\n # O(t)\n for i in range(t):\n d = directions[i]\n\n if d == EAST and xdiff > 0:\n xdiff -= 1\n elif d == WEST and xdiff < 0:\n xdiff += 1\n\n if d == NORTH and ydiff > 0:\n ydiff -= 1\n elif d == SOUTH and ydiff < 0:\n ydiff += 1\n\n if xdiff == 0 and ydiff == 0:\n return i + 1\n\n return -1\n\n\nif __name__ == \"__main__\":\n t, sx, sy, ex, ey = list(map(int, input().split()))\n dirs = input()\n\n xdiff = ex - sx\n ydiff = ey - sy\n\n answer = get_earliest(t, dirs, xdiff, ydiff)\n print(answer)\n\n\t \t \t \t \t \t\t\t \t\t\t \t\t\t \t\t", "t, x, y, u, v = map(int, input().split())\r\n\r\ndx = u - x\r\ndy = v - y\r\n\r\np = input()\r\ne, s, w, n = p.count('E'), p.count('S'), p.count('W'), p.count('N')\r\n\r\nif - w > dx or e < dx or - s > dy or n < dy: print(-1)\r\nelse:\r\n for i in range(len(p)):\r\n if p[i] == 'E':\r\n if dx > 0: dx -= 1\r\n elif p[i] == 'S':\r\n if dy < 0: dy += 1\r\n elif p[i] == 'W':\r\n if dx < 0: dx += 1\r\n else:\r\n if dy > 0: dy -= 1\r\n if dx == 0 and dy == 0:\r\n print(i + 1)\r\n break", "t,s1,s2,e1,e2 = [int(i) for i in input().split()]\r\ns = input()\r\ntotal = abs(s1-e1)+abs(s2-e2)\r\ntime = 0\r\nfor i in s:\r\n if total==0:\r\n break\r\n if i == 'E':\r\n if((e1-s1)>0):\r\n total-=1\r\n s1+=1\r\n time+=1\r\n if i == 'W':\r\n if((e1-s1)<0):\r\n total-=1\r\n s1-=1\r\n time+=1\r\n if i=='N':\r\n if((e2-s2)>0):\r\n total-=1\r\n s2+=1\r\n time+=1\r\n if i=='S':\r\n if((e2-s2)<0):\r\n total-=1\r\n s2-=1\r\n time+=1\r\nif s1 == e1 and s2==e2:\r\n print(time)\r\nelse:\r\n print(-1)\r\n \r\n \r\n", "\r\nn,sx,sy,fx,fy= map(int,input().split())\r\ns= input()\r\ndiff_x= abs(fx)-abs(sx)\r\ndiff_y= abs(fy)-abs(sy)\r\nans=-1\r\nfor i in range(n):\r\n if s[i]=='E' and sx<fx:\r\n sx+=1\r\n elif s[i]=='W' and sx>fx:\r\n sx-=1\r\n elif s[i]=='N' and sy<fy:\r\n sy+=1\r\n elif s[i]=='S' and sy>fy:\r\n sy-=1\r\n\r\n if sx==fx and sy==fy:\r\n ans=i+1\r\n\r\n break\r\n\r\nprint(ans)\r\n\r\n\r\n", "n,sx,sy,ex,ey=map(int,input().strip().split(' ')) \r\nif ex-sx>=0:\r\n d1='E'\r\n dd1=ex-sx \r\nelse:\r\n d1='W'\r\n dd1=abs(ex-sx) \r\nif ey-sy>=0:\r\n d2='N'\r\n dd2=ey-sy \r\nelse:\r\n d2='S'\r\n dd2=abs(ey-sy) \r\ns=input()\r\ni=0 \r\nwhile i<n:\r\n if s[i]==d2:\r\n dd2-=1 \r\n if s[i]==d1:\r\n dd1-=1 \r\n if dd1<=0 and dd2<=0:\r\n break \r\n i+=1\r\nprint(i+1) if i!=n else print(-1)", "line1 = input()\ncoords1 = [int(line1.split()[1]), int(line1.split()[2])]\ncoords2 = [int(line1.split()[3]), int(line1.split()[4])]\ntimecount = 0\nline2 = input()\nfor i in range(0, len(line2)):\n timecount += 1\n if line2[i] == \"E\":\n if coords1[0] < coords2[0]:\n coords1[0] = coords1[0] + 1\n\n if line2[i] == \"N\":\n if coords1[1] < coords2[1]:\n coords1[1] = coords1[1] + 1\n\n if line2[i] == \"W\":\n if coords1[0] > coords2[0]:\n coords1[0] = coords1[0] - 1\n \n if line2[i] == \"S\":\n if coords1[1] > coords2[1]:\n coords1[1] = coords1[1] - 1\n if coords1 == coords2:\n print(timecount)\n break\n if timecount >= len(line2):\n print(\"-1\")\n break\n ", "\r\nt, s1, s2, e1, e2 = map(int, input().split())\r\nl = list(input())\r\n\r\nif e2 >= s2 and e1 >= s1:\r\n\tind = 0\r\n\t\r\n\tfor i in range(t):\r\n\t\t\r\n\t\tif l[i] == 'N':\r\n\t\t\tif e2 > s2:\r\n\t\t\t\ts2 += 1\r\n\t\t\t\tind = i\r\n\t\tif l[i] == 'E':\r\n\t\t\tif e1 > s1:\r\n\t\t\t\ts1 += 1\r\n\t\t\t\tind = i\r\n\tif e2 == s2 and s1 == e1:\r\n\t\t\tprint(ind + 1)\r\n\t\t\texit()\r\nelif e2 <= s2 and e1 <= s1:\r\n\tind = 0\r\n\t\r\n\tfor i in range(t):\r\n\t\t\r\n\t\tif l[i] == 'S':\r\n\t\t\tif e2 < s2:\r\n\t\t\t\ts2 -= 1\r\n\t\t\t\tind = i\r\n\t\tif l[i] == 'W':\r\n\t\t\tif e1 < s1:\r\n\t\t\t\ts1 -= 1\r\n\t\t\t\tind = i\r\n\tif e2 == s2 and s1 == e1:\r\n\t\t\tprint(ind + 1)\r\n\t\t\texit()\r\n\r\nelif e2 >= s2 and e1 <= s1:\r\n\tind = 0\r\n\t\r\n\tfor i in range(t):\r\n\t\t\r\n\t\tif l[i] == 'N':\r\n\t\t\tif e2 > s2:\r\n\t\t\t\ts2 += 1\r\n\t\t\t\tind = i\r\n\t\tif l[i] == 'W':\r\n\t\t\tif e1 < s1:\r\n\t\t\t\ts1 -= 1\r\n\t\t\t\tind = i\r\n\tif e2 == s2 and s1 == e1:\r\n\t\t\tprint(ind + 1)\r\n\t\t\texit()\r\n\t\r\n\r\nelif e2 <= s2 and e1 >= s1:\r\n\tind = 0\r\n\t\r\n\tfor i in range(t):\r\n\t\t\r\n\t\tif l[i] == 'S':\r\n\t\t\tif e2 < s2:\r\n\t\t\t\ts2 -= 1\r\n\t\t\t\tind = i\r\n\t\tif l[i] == 'E':\r\n\t\t\tif e1 > s1:\r\n\t\t\t\ts1 += 1\r\n\t\t\t\tind = i\r\n\tif e2 == s2 and s1 == e1:\r\n\t\t\tprint(ind + 1)\r\n\t\t\texit()\r\n\r\nprint(-1)\r\n\r\n\t\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nt, sx, sy, ex, ey = map(int, input().split())\r\nwind = input().strip()\r\n\r\nhorizontal = 'E' if ex > sx else 'W'\r\nvertical = 'N' if ey > sy else 'S'\r\n\r\ni = 0\r\nwhile i < len(wind) and (sx != ex or sy != ey):\r\n if sx != ex:\r\n if wind[i] == horizontal == 'E':\r\n sx += 1\r\n elif wind[i] == horizontal == 'W':\r\n sx -= 1\r\n if sy != ey:\r\n if wind[i] == vertical == 'N':\r\n sy += 1\r\n elif wind[i] == vertical == 'S':\r\n sy -= 1\r\n i += 1\r\n\r\nprint(i if sx == ex and sy == ey else -1)\r\n", "k,x,y,x1,y1=map(int,input().split())\r\ndata=input()\r\ntimer=1\r\nfor i in data:\r\n if i==\"E\" and x1>x:\r\n x+=1\r\n elif i==\"W\" and x>x1:\r\n x-=1\r\n elif i==\"N\" and y<y1:\r\n y+=1\r\n elif i==\"S\" and y>y1:\r\n y-=1\r\n if x==x1 and y==y1:\r\n print(timer)\r\n break\r\n timer+=1\r\nif timer>len(data):\r\n print(-1)", "t,x1,y1,x2,y2 = map(int,input().split())\r\ns = str(input())\r\na = x2 - x1\r\nb = y2 - y1\r\nfrom itertools import islice\r\n\r\ndef nth_index(iterable, value, n):\r\n matches = (idx for idx, val in enumerate(iterable) if val == value)\r\n return next(islice(matches, n-1, n), None)\r\nif a > 0 and b > 0:\r\n f = nth_index(s,'E',a)\r\n l = nth_index(s,'N',b)\r\n if s.count('E') < abs(a) or s.count('N') < abs(b):\r\n final = -1\r\n else:\r\n final = max(f,l)+1\r\nelif a > 0 and b < 0 :\r\n f = nth_index(s,'E',abs(a))\r\n l = nth_index(s,'S',abs(b))\r\n if s.count('E') < abs(a) or s.count('S') < abs(b):\r\n final = -1\r\n else:\r\n final = max(f,l)+1\r\nelif a < 0 and b > 0:\r\n f = nth_index(s,'W',abs(a))\r\n l = nth_index(s,'N',abs(b))\r\n if s.count('W') < abs(a) or s.count('N') < abs(b):\r\n final = -1\r\n else:\r\n final = max(f,l)+1\r\nelif a < 0 and b < 0:\r\n f = nth_index(s,'W',abs(a))\r\n l = nth_index(s,'S',abs(b))\r\n if s.count('W') < abs(a) or s.count('S') < abs(b):\r\n final = -1\r\n else:\r\n final = max(f,l)+1\r\nelif a > 0 and b == 0:\r\n f = nth_index(s,'E',abs(a))\r\n if s.count('E') < abs (a):\r\n final = -1\r\n else:\r\n final = f+1\r\n\r\nelif a < 0 and b == 0:\r\n f = nth_index(s,'W',abs(a))\r\n if s.count('W') < abs (a):\r\n final = -1\r\n else:\r\n final = f+1\r\nelif a == 0 and b > 0:\r\n f = nth_index(s,'N',abs(b))\r\n if s.count('N') < abs (b):\r\n final = -1\r\n else:\r\n final = f+1\r\nelif a == 0 and b < 0:\r\n f = nth_index(s,'S',abs(b))\r\n if s.count('S') < abs (b):\r\n final = -1\r\n else:\r\n final = f+1\r\n\r\n\r\n\r\nprint(final)", "import sys,os,io,time,copy\r\nif os.path.exists('input.txt'):\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\n\r\nimport math\r\n\r\ndef main():\r\n # start=time.time()\r\n t,s1,s2,e1,e2=map(int,input().split())\r\n string=input()\r\n x_shift=e1-s1\r\n y_shift=e2-s2\r\n east=0\r\n west=0\r\n north=0\r\n south=0\r\n if x_shift>=0:\r\n east=x_shift\r\n else:\r\n west=abs(x_shift)\r\n if y_shift>=0:\r\n north=y_shift\r\n else:\r\n south=abs(y_shift)\r\n ea=we=no=so=0\r\n flag=0\r\n req=0\r\n if no==north:\r\n no=-1\r\n if ea==east:\r\n ea=-1 \r\n if so==south:\r\n so=-1\r\n if we==west:\r\n we=-1\r\n for i in range(len(string)):\r\n s=string[i]\r\n if s=='N' and no>=0:\r\n no+=1\r\n elif s=='S' and so>=0:\r\n so+=1\r\n elif s=='E' and ea>=0:\r\n ea+=1\r\n elif s=='W' and we>=0:\r\n we+=1\r\n if no==north:\r\n no=-1\r\n if ea==east:\r\n ea=-1 \r\n if so==south:\r\n so=-1\r\n if we==west:\r\n we=-1\r\n if ea==we==so==no==-1:\r\n flag=1\r\n req=i+1\r\n break\r\n if flag==1:\r\n print(req)\r\n else:\r\n print(-1)\r\n \r\n # end=time.time()\r\nmain()", "l,a,b,c,d=map(int, input().split())\ns=input()\nt=0\nfor i in s:\n if i=='E' and a < c:\n a+=1\n elif i=='W' and a > c:\n a-=1\n elif i=='S' and b > d:\n b-=1\n elif i == 'N' and b < d:\n b+=1\n elif a==c and b==d:\n break\n t+=1\nif a==c and b==d:\n print(t)\nelse:\n print(-1) \n", "p=input()\r\nt,sx,sy,ex,ey=map(int,p.split())\r\nq=input()\r\nq=q.replace('',' ')\r\nq=q.split()\r\ni=0\r\nwhile (sx!=ex or sy!=ey) and i<t:\r\n if q[i]=='E':\r\n if sx<ex:\r\n sx+=1\r\n elif q[i]=='W':\r\n if sx>ex:\r\n sx-=1\r\n elif q[i]=='N':\r\n if sy<ey:\r\n sy+=1\r\n else:\r\n if sy>ey:\r\n sy-=1\r\n i+=1\r\nif sx==ex and sy==ey:\r\n print(i)\r\nelse:\r\n print(-1)\r\n", "inputs = [int(num) for num in input().split()]\r\nt = inputs[0]\r\nsx = inputs[1]\r\nsy = inputs[2]\r\nex = inputs[3]\r\ney = inputs[4]\r\ns = input()\r\nif(ex>=sx):\r\n right = abs(ex-sx)\r\n left=0\r\nelse:\r\n left = abs(sx-ex)\r\n right=0\r\nif(ey>=sy):\r\n up = abs(ey-sy)\r\n down =0\r\nelse:\r\n up=0\r\n down = abs(ey-sy)\r\ntime=0\r\nflag=0\r\nfor i in range(0,len(s)):\r\n if(s[i]=='S' and down>0):\r\n down-=1\r\n elif(s[i]=='N'and up>0):\r\n up-=1\r\n elif(s[i]=='E'and right>0):\r\n right-=1\r\n elif(s[i]=='W' and left>0):\r\n left-=1\r\n time+=1\r\n if(down==0 and up==0 and left==0 and right==0):\r\n flag=1\r\n break\r\nif(flag==1):\r\n print(time)\r\nelse:\r\n print(-1)", "def timing():\r\n t, sx, sy, ex, ey = map(int, input().split())\r\n s = input()\r\n for x in range(len(s)):\r\n if s[x] == \"E\" and ex > sx:\r\n sx = sx + 1\r\n sy = sy\r\n if s[x] == \"S\" and ey < sy:\r\n sx = sx\r\n sy = sy - 1\r\n if s[x] == \"W\" and ex < sx:\r\n sx = sx - 1\r\n sy = sy\r\n\r\n if s[x] == \"N\" and ey > sy:\r\n sx = sx\r\n sy = sy + 1\r\n\r\n if ex == sx and ey == sy:\r\n return x + 1\r\n return -1\r\n\r\n\r\nprint(timing())\r\n", "t, sx, sy, fx, fy = map(int, input().split())\r\nm = input()\r\nans = 0\r\nfor i in m:\r\n if sx < fx and i == 'E':\r\n sx += 1\r\n if sx > fx and i == 'W':\r\n sx -= 1\r\n if sy < fy and i == 'N':\r\n sy += 1\r\n if sy > fy and i == 'S':\r\n sy -= 1\r\n ans += 1\r\n if sx == fx and sy == fy:\r\n exit(print(ans))\r\nprint(-1)\r\n", "def main():\r\n\tt,sx,sy,ex,ey = map(int,input().split())\r\n\tdirs=input()\r\n\r\n\tx_dist = (ex-sx) \r\n\tx_dir = 'E' if(x_dist>=0) else 'W'\r\n\tx_dist = x_dist if(x_dist>=0) else (-x_dist)\r\n\r\n\ty_dist = (ey-sy) \r\n\ty_dir = 'N' if(y_dist>=0) else 'S'\r\n\ty_dist = y_dist if(y_dist>=0) else (-y_dist)\r\n\r\n\tfor i in range(t):\r\n\t\tif dirs[i]==x_dir and x_dist>0:\r\n\t\t\tx_dist-=1\r\n\t\telif dirs[i]==y_dir and y_dist>0:\r\n\t\t\ty_dist-=1\r\n\t\tif(y_dist==0 and x_dist==0):\r\n\t\t\treturn i+1\r\n\treturn -1\r\n\r\nprint(main())", "t, sx, sy, ex, ey = [int(x) for x in input().split()]\r\ns = input()\r\n\r\nx = ex - sx\r\ny = ey - sy\r\nlx = 0\r\nly = 0\r\nif x > 0:\r\n s = s.replace('W', ' ')\r\nelif x < 0:\r\n s = s.replace('E', ' ')\r\nif y > 0:\r\n s = s.replace('S', ' ')\r\nelif y < 0:\r\n s = s.replace('N', ' ')\r\nfor b in range(len(s)):\r\n if s[b] == ' ':\r\n continue\r\n elif s[b] == 'N' and y != 0:\r\n y -= 1\r\n ly = b + 1\r\n elif s[b] == 'S' and y != 0:\r\n y += 1\r\n ly = b + 1\r\n elif s[b] == 'E' and x != 0:\r\n x -= 1\r\n lx = b + 1\r\n elif s[b] == 'W' and x != 0:\r\n x += 1\r\n lx = b + 1\r\nif x == 0 and y == 0:\r\n print(max(lx, ly))\r\nelse:\r\n print(-1)", "tse = input().split()\r\n\r\nt, x, y, x1, y1 = map(int, tse)\r\n\r\nsail = input()\r\ntime = 0\r\npossible = False\r\n\r\nfor i in sail:\r\n if i == 'N' and y1 - y > 0:\r\n y += 1\r\n time += 1\r\n elif i == 'S' and y1 - y < 0:\r\n y -= 1\r\n time += 1\r\n elif i == 'E' and x1 - x > 0:\r\n x += 1\r\n time += 1\r\n elif i == 'W' and x1 - x < 0:\r\n x -= 1\r\n time += 1\r\n else:\r\n t -= 1\r\n time+=1\r\n\r\n if t < 0:\r\n possible = False\r\n\r\n if x == x1 and y == y1 :\r\n possible = True\r\n break\r\n\r\nif possible:\r\n print(time)\r\nelse:\r\n print(-1)", "n, x0, y0, x1, y1 = map(int, input().split())\r\ns = input()\r\nif y0 > y1:\r\n a2 = 'S'\r\nelse:\r\n a2 = 'N'\r\nif x0 > x1:\r\n a1 = 'W'\r\nelse:\r\n a1 = 'E'\r\nch, cv = abs(x0-x1), abs(y0-y1)\r\ni = 0\r\nwhile i < n and (ch > 0 or cv > 0):\r\n if s[i] == a1:\r\n ch -= 1\r\n elif s[i] == a2:\r\n cv -= 1\r\n i += 1\r\nif cv > 0 or ch > 0:\r\n print(-1)\r\nelse:\r\n print(i)\r\n", "from sys import stdin\r\nimport math\r\n\r\nt, sx, sy, ex, ey = map(int, stdin.readline().rstrip().split(' '))\r\ndirs = stdin.readline().rstrip()\r\n\r\nsteps = 0\r\n\r\nif sx == ex and sy == ey:\r\n print(0)\r\n exit()\r\n\r\nfor i, dir in enumerate(dirs):\r\n if dir == 'N':\r\n if sy < ey:\r\n sy += 1\r\n elif dir == 'S':\r\n if sy > ey:\r\n sy -= 1\r\n elif dir == 'E':\r\n if sx < ex:\r\n sx += 1\r\n elif dir == 'W':\r\n if sx > ex:\r\n sx -= 1\r\n if sx == ex and sy == ey:\r\n print(i+1)\r\n exit()\r\n\r\nprint(-1)", "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\n\r\nyatay=ex-sx\r\ndikey=ey-sy\r\n\r\nflag=0\r\n\r\nif(yatay>=0 and dikey>=0):\r\n for i in range(t):\r\n if(s[i]==\"N\" and dikey>0):\r\n dikey-=1\r\n if(s[i]==\"E\" and yatay>0):\r\n yatay-=1\r\n if(yatay==0 and dikey==0):\r\n print(i+1)\r\n flag=1\r\n break\r\nelif(yatay<=0 and dikey<=0):\r\n for i in range(t):\r\n if(s[i]==\"S\" and dikey<0):\r\n dikey+=1\r\n if(s[i]==\"W\" and yatay<0):\r\n yatay+=1\r\n if(yatay==0 and dikey==0):\r\n print(i+1)\r\n flag=1\r\n break\r\nelif(yatay>=0 and dikey<=0):\r\n for i in range(t):\r\n if(s[i]==\"S\" and dikey<0):\r\n dikey+=1\r\n if(s[i]==\"E\" and yatay>0):\r\n yatay-=1\r\n if(yatay==0 and dikey==0):\r\n print(i+1)\r\n flag=1\r\n break\r\nelif(yatay<=0 and dikey>=0):\r\n for i in range(t):\r\n if(s[i]==\"N\" and dikey>0):\r\n dikey-=1\r\n if(s[i]==\"W\" and yatay<0):\r\n yatay+=1\r\n if(yatay==0 and dikey==0):\r\n print(i+1)\r\n flag=1\r\n break\r\n\r\n\r\nif(flag==0):\r\n print(-1)", "i = 0\nt, sx, sy, ex, ey = list(map(int, input().split()))\nsecond_string = input()\nwhile i < t:\n if second_string[i] == 'E':\n if sx < ex: sx += 1\n elif second_string[i] == 'W':\n if sx > ex: sx -= 1\n elif second_string[i] == 'N':\n if sy < ey: sy += 1\n else:\n if sy > ey: sy -= 1\n i += 1\n if (sy == ey) and (sx == ex):\n print(i)\n break\n if i == t:\n print(-1)\n", "def check(dif_x, dif_y):\r\n if dif_x > 0:\r\n x = 'E'\r\n elif dif_x < 0:\r\n x = 'W'\r\n else:\r\n x = ''\r\n if dif_y > 0:\r\n y = 'N'\r\n elif dif_y < 0:\r\n y = 'S'\r\n else:\r\n y = ''\r\n return x, y\r\n\r\n\r\nt, x1, y1, x2, y2 = input().split()\r\ns = input()\r\nx1, x2 = int(x1), int(x2)\r\ny1, y2 = int(y1), int(y2)\r\ndif_x = x2 - x1\r\ndif_y = y2 - y1\r\nx, y = check(dif_x, dif_y)\r\nx_count = 0\r\ny_count = 0\r\ncount = 0\r\nb = False\r\nfor i in s:\r\n if i == x:\r\n x_count += 1\r\n elif i == y:\r\n y_count += 1\r\n count += 1\r\n if x_count >= abs(dif_x) and y_count >= abs(dif_y):\r\n b = True\r\n break\r\nif b:\r\n print(count)\r\nelse:\r\n print(-1)", "size, x1, y1, x2, y2 = map(int, input().strip().split())\r\narr = list(input())\r\nsec = 0\r\nfor i in arr:\r\n if i == 'N' and y1 < y2:\r\n y1 += 1\r\n elif i == 'E' and x1 < x2:\r\n x1 += 1\r\n elif i == 'S' and y1 > y2:\r\n y1 -= 1\r\n elif i == 'W' and x1 > x2:\r\n x1 -= 1\r\n sec += 1\r\n if x1 == x2 and y1 == y2:\r\n break\r\nprint(sec if x1 == x2 and y1 == y2 else -1)", "t, sx, sy, ex, ey = map(int, input().split())\r\nwinds = list(input())\r\ndef dist(x, y):\r\n return abs(x-ex)+abs(y-ey)\r\nfor zzz in range(t):\r\n new_x, new_y = sx, sy\r\n if(winds[zzz]=='N'):\r\n new_y += 1\r\n if(winds[zzz]=='S'):\r\n new_y -= 1\r\n if(winds[zzz]=='E'):\r\n new_x += 1\r\n if(winds[zzz]=='W'):\r\n new_x -= 1\r\n if(dist(new_x, new_y)<dist(sx, sy)):\r\n sx = new_x\r\n sy = new_y\r\n if(sx == ex and sy == ey):\r\n if(zzz+1<=t):\r\n print(zzz+1)\r\n break\r\nelse:\r\n print(-1)\r\n", "import math\r\ndef distance(x1,x2,y1,y2):\r\n dx,dy = pow(x2-x1,2.0),pow(y2-y1,2.0)\r\n return math.sqrt(dx+dy)\r\n\r\ndef func():\r\n m = {'N':[0,1],'S':[0,-1],'W':[-1,0],'E':[1,0]}\r\n t,sx,sy,ex,ey = map(int,input().split())\r\n total = distance(sx,ex,sy,ey)\r\n s = input()\r\n for i in range(0,len(s)):\r\n x = m[s[i]]\r\n nx,ny = sx+x[0],sy+x[1]\r\n curr = distance(nx,ex,ny,ey)\r\n if(curr == 0):\r\n print(i+1)\r\n return\r\n if(curr < total):\r\n [sx,sy] = [nx,ny]\r\n total = distance(sx,ex,sy,ey)\r\n print(-1)\r\nfunc()\r\n ", "n , sx,sy,ex,ey = map(int, input().split())\r\na = list(input())\r\nm = ex - sx\r\nn = ey - sy\r\nd = []\r\nf = []\r\n# print(m,n)\r\nif m>0:\r\n d+=(['E']*m)\r\nelif m<0:\r\n d+=(['W']*abs(m))\r\nif n>0:\r\n f+=(['N']*n)\r\nelif n<0:\r\n f+=(['S']*abs(n))\r\ni ,j = 0,0\r\nif d==['']:\r\n d = []\r\nif f==['']:\r\n f = []\r\n# print(d,f)\r\nfor t in range(len(a)):\r\n if i<len(d) or j<len(f):\r\n # print(i, j)\r\n if i<len(d):\r\n if a[t]==d[i]:\r\n i+=1\r\n if j<len(f):\r\n if a[t]==f[j]:\r\n j+=1\r\n else:\r\n print(t)\r\n exit()\r\nif i==len(d) and j==len(f):\r\n print(len(a))\r\nelse:\r\n print(-1)\r\n\r\n\r\n# 99697 306523229 206812050 306526222 206810059\r\n# NNWWWWWWNWNWWWNNNWWWNNNWWWWWWNNWNWWNNNWNWWWNNNNNWNWNWWNNNNNNNNWWNNWNNNNNWWNNWWWWWNWNNWWWWNWWNNNWNWWWNWNWWNNNNWWNWWNWWNNNNNWNNNNNNWWNNWNNWWWWWWWNNWNWWWWWWWNWNNWWWWNNWWWNNWNWNNWNWNNNWWNWWWWNNWWWNWWNNWNNNNWWWNNNWNNNWWNNWNWNWWWWNNNWWWNNNWWNWWNWNNWWNWNNWNWNNWNNWWNWNNNNWWNWNWWNNNWWNWNWWNNNNWNNNNWNNWNWNNWNWWNNNWWWWNWWWWWNWNWWNNNWWNNNWWWWNWWWWNWNWNWNWWNWWNNWNNWWNNWNWWNWNNNWNWWWWNWNNWWWWWWWNNWNWNNNWWNNWNWNWWWNWNNWNNWWWWNWWNNWWWWWNNNWWWWWNWWNWWWWWNWWWNWWWWWWNWNWWWWWNNWN...\r\n", "q,x,y,x1,y1 = map(int,input().split())\r\ns = input()\r\nc = 0\r\nfor che in list(s):\r\n c +=1\r\n if che == 'E' and x<x1:\r\n x +=1\r\n\r\n elif che == 'W' and x > x1:\r\n x -= 1\r\n\r\n elif che == 'N' and y < y1:\r\n y += 1\r\n\r\n elif che == 'S' and y > y1:\r\n y -=1\r\n if x == x1 and y ==y1: print(c); exit()\r\nprint(-1)", "n,a,b,c,d=map(int,input().split())\ns=input()\nf1=c>a\nf2=d>b\nfor i in range(n):\n\tif s[i]=='E' and c>a:a+=1\n\telif s[i]=='W' and c<a:a-=1\n\telif s[i]=='N' and d>b:b+=1\n\telif s[i]=='S' and d<b:b-=1\n\tif a==c and b==d:\n\t\tprint(i+1)\n\t\tbreak\nelse:\n\tprint(-1)", "import collections,math,itertools,bisect,heapq,copy\nclass Solution:\n def solve(self):\n def calculateDist(start,end):\n dis = math.sqrt((end[0]-start[0])**2 + (end[1]-start[1])**2)\n return dis\n # n = int(input())\n arr = list(map(int, input().rstrip().split()))\n string = input()\n t = arr[0]\n start = (arr[1],arr[2])\n end = (arr[3],arr[4])\n d= {'W':(-1,0),'E':(1,0),'N':(0,1),'S':(0,-1)}\n dis = calculateDist(start,end)\n for i in range(t):\n x,y = d[string[i]]\n newLoc = (start[0]+x,start[1]+y)\n newDis = calculateDist(newLoc,end)\n if newDis <= dis:\n dis = newDis\n start = newLoc\n if dis == 0:\n print(i+1)\n return\n print(-1)\n\n \n \n\n\n \n \n\nif __name__ == \"__main__\":\n solution = Solution()\n solution.solve()", "t, sx, sy, ex, ey= map(int,input().split())\r\ntime=-1\r\nwind =input()\r\n\r\nfor i in range(t):\r\n if wind[i] == 'E' and sx < ex:\r\n sx += 1\r\n elif wind[i] == 'S' and sy > ey:\r\n sy -= 1\r\n elif wind[i] == 'W' and sx > ex:\r\n sx -= 1\r\n elif wind[i] == 'N' and sy < ey:\r\n sy += 1\r\n if sx == ex and sy == ey:\r\n time = i + 1\r\n break\r\n\r\nprint(time)", "# http://codeforces.com/problemset/problem/298/B\n\nd = {'E':(1,0), 'S':(0,-1), 'W':(-1,0), 'N':(0,1)}\n\nt,sx,sy,ex,ey = map(int, input().split())\ns = input()\n\nfor i in range(t):\n dx,dy = d[s[i]]\n\n if abs(sx-ex+dx)<=abs(sx-ex) and abs(sy-ey+dy)<=abs(sy-ey):\n sx+=dx\n sy+=dy\n if sx==ex and sy==ey:\n print(i+1)\n exit()\nprint(-1)\n", "t, sx, sy, ex, ey = map(int, input().split())\r\ns = input()\r\nfor i in range(t):\r\n\tif s[i] == 'N' and sy < ey:\r\n\t\tsy += 1\r\n\tif s[i] == 'S' and sy > ey:\r\n\t\tsy -= 1\r\n\tif s[i] == 'W' and sx > ex:\r\n\t\tsx -= 1\r\n\tif s[i] == 'E' and sx < ex:\r\n\t\tsx += 1\r\n\tif sx == ex and sy == ey:\r\n\t\tprint(i + 1)\r\n\t\texit()\r\nprint(-1)", "from collections import Counter\n\nt,sx,sy,ex,ey=map(int,input().split())\ns=list(input())\nn=len(s)\nc=Counter(s)\nval1=1\nval2=1\nval1-=(ex-sx>0 and c['E']<ex-sx) or (ex-sx<0 and c['W']<sx-ex)\nval2-=(ey-sy>0 and c['N']<ey-sy) or (ey-sy<0 and c['S']<sy-ey)\nif val1*val2==0:\n print(-1)\nelse:\n indx=n*int(ex!=sx)\n indy=n*int(ey!=sy)\n for i in range(n):\n \n if ex>sx and s[i]=='E':\n ex-=1\n elif ex<sx and s[i]=='W':\n ex+=1\n if ey>sy and s[i]=='N':\n ey-=1\n elif ey<sy and s[i]=='S':\n ey+=1\n if ex==sx:\n indx=min(indx,i+1)\n if ey==sy:\n indy=min(indy,i+1)\n print(max(indx,indy))", "lst=input().split()\r\nt=int(lst[0])\r\nsx=int(lst[1])\r\nsy=int(lst[2])\r\nex=int(lst[3])\r\ney=int(lst[4])\r\ns = input()\r\nhor=ex-sx\r\nver=ey-sy\r\ntime=0\r\ni=0\r\nwhile (hor!=0 or ver!=0):\r\n if s[i]=='N':\r\n if ver>0:\r\n ver-=1\r\n elif s[i]=='S':\r\n if ver<0:\r\n ver+=1\r\n elif s[i]=='E':\r\n if hor>0:\r\n hor-=1\r\n elif s[i]=='W':\r\n if hor<0:\r\n hor+=1\r\n time+=1\r\n i+=1\r\n if i==len(s):\r\n break\r\n\r\nif hor==0 and ver==0:\r\n print(time)\r\nelse:\r\n print(-1)\r\n\r\n\r\n ", "t,a,b,x,y=map(int,input().split())\r\ns=input()\r\nk=-1\r\nfor i in range(t):\r\n if(a>x and s[i]=='W'):\r\n a-=1\r\n elif(a<x and s[i]=='E'):\r\n a+=1\r\n if(b>y and s[i]=='S'):\r\n b-=1\r\n elif(b<y and s[i]=='N'):\r\n b+=1\r\n if(a==x and b==y):\r\n k=i\r\n break\r\nif(k==-1):\r\n print(-1)\r\nelse:\r\n print(k+1)\r\n \r\n \r\n", "def main():\r\n t,sx,sy,ex,ey = map(int, input().split())\r\n nlt = input()\r\n lst = list(nlt)\r\n cnt = 0\r\n fl = False\r\n for i in range(len(lst)):\r\n if lst[i] == 'N' and sy < ey:\r\n sy += 1\r\n elif lst[i] == 'S' and sy > ey:\r\n sy -= 1\r\n elif lst[i] == 'E' and sx < ex:\r\n sx += 1\r\n elif lst[i] == 'W' and sx > ex:\r\n sx -= 1\r\n cnt += 1\r\n if sx == ex and sy == ey:\r\n fl = True\r\n break\r\n if fl:\r\n print(cnt)\r\n else:\r\n print(-1)\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "# Author Kmoussai \nimport sys\nimport math\nimport random\n'''\ni = 0\nwhile i < n:\n \n i += 1\n\nmap(int, input().split())\n\n\ndef pgcd(a, b):\n if b == 0:\n return a\n return pgcd(b, a%b)\n\n\n\n'''\nif len(sys.argv) >= 2:\n if sys.argv[1] == 'LOCAL':\n sys.stdin = open('input.in', 'r')\n\nl = list(map(int, input().split()))\n#[t,1 sx,2 sy,3 ex,4 ey]\ndx = l[3] - l[1]\ndy = l[4] - l[2]\n\nt = 0\nyes = False\nmapp = {\n 'N':0,\n 'S':0,\n 'E':0,\n 'W':0, \n}\ns = input()\nfor i in s:\n mapp[i] += 1\nreq = {\n 'N':0,\n 'S':0,\n 'E':0,\n 'W':0, \n}\nif dx > 0:\n req['E'] = dx\nelif dx < 0:\n req['W'] = -dx\nif dy > 0:\n req['N'] = dy\nelif dy < 0:\n req['S'] = -dy\nt = 0\nfor i in s:\n if req[i] > 0:\n req[i] -= 1\n t += 1\n if req['E'] == 0 and req['S'] == 0 and req['N'] == 0 and req['W'] == 0:\n yes = True\n break\nif yes: \n print(t)\nelse:\n print(-1)\n\n\n\n\n", "#!/usr/bin/env python3\r\n#! -*- coding: utf-8 -*-\r\n\r\n\r\ndef main():\r\n\tt, sx, sy, ex, ey = map(int, input().split())\r\n\tpath = input()\r\n\tdx, dy = ex - sx, ey - sy\r\n\tif not dx and not dy:\r\n\t\tprint(0)\r\n\t\texit(0)\r\n\tfor i, move in enumerate(path):\r\n\t\t#print(dx, dy)\r\n\t\tif dx < 0 and move == 'W':\r\n\t\t\tdx += 1\r\n\t\telif dx > 0 and move == 'E':\r\n\t\t\tdx -= 1\r\n\t\telif dy < 0 and move == 'S':\r\n\t\t\tdy += 1\r\n\t\telif dy > 0 and move == 'N':\r\n\t\t\tdy -= 1\r\n\t\tif not dx and not dy:\r\n\t\t\tprint(i + 1)\r\n\t\t\tbreak\r\n\telse:\r\n\t\tprint(\"-1\")\r\n\r\n\r\nif __name__ == '__main__':\r\n\tmain()\r\n", "t, a, b, x, y = map(int, input().split())\r\nstring = list(input().upper())\r\nfor i in range(0, t):\r\n c = string[i]\r\n if c == 'N' and b < y:\r\n b += 1\r\n elif c == 'S' and b > y:\r\n b -= 1\r\n elif c == 'E' and a < x:\r\n a += 1\r\n elif c == 'W' and a > x:\r\n a -= 1\r\n if a == x and b == y:\r\n print(i+1)\r\n break\r\nelse:\r\n print(-1)\r\n", "t,sx,sy,ex,ey=map(int,input().split())\r\ns=input()\r\ncnt=0\r\nfor i in s :\r\n cnt+=1\r\n if i=='E' :\r\n if sx<ex :\r\n sx=sx+1\r\n elif i=='S' :\r\n if sy>ey :\r\n sy=sy-1\r\n elif i=='W' :\r\n if sx>ex :\r\n sx=sx-1\r\n elif i=='N' :\r\n if sy<ey :\r\n sy=sy+1\r\n if sx==ex and sy==ey :\r\n print(cnt)\r\n break\r\nif sx!=ex or sy!=ey :\r\n print(\"-1\")\r\n ", "def main():\r\n # input sail path and direction \r\n (t, sx, sy, ex, ey) = map(int, input().split(' '))\r\n #when starting and ending locations are same, time taken is 0\r\n if sx == ex and sy == ey:\r\n return 0\r\n t = 0 #initiallt time is zero \r\n #find earliest time between 2 locations \r\n for c in list(input()):\r\n if sx == ex and sy == ey:\r\n return t\r\n #When wind blows to the south \r\n if c == 'S':\r\n if ey < sy:\r\n sy -= 1\r\n #When wind blows to the north \r\n elif c == 'N':\r\n if ey > sy:\r\n sy += 1\r\n #When wind blows to East \r\n elif c == 'E':\r\n if ex > sx:\r\n sx += 1\r\n #When wind blows to West \r\n elif c == 'W':\r\n if ex < sx:\r\n sx -= 1\r\n t += 1 #calcuting time here \r\n #Stop sailing and return time when they reach ending location\r\n if sx == ex and sy == ey:\r\n return t\r\n return -1\r\n\r\nprint(main())", "ls_input = list(map(int,input().split()))\nt,sx,sy,ex,ey = ls_input\nstr_dir = input()\n\ntime = 0\n\ndef dist_formula(x1,y1):\n dist = (((ex-x1)**2)+((ey-y1)**2))**0.5\n return dist\n\ndef north(x,y):\n return x,y+1\ndef south(x,y):\n return x,y-1\ndef east(x,y):\n return x+1,y\ndef west(x,y):\n return x-1,y\n\n\nfor dir in str_dir:\n time+=1\n\n if dir == 'N':\n\n x,y = north(sx,sy)\n\n if dist_formula(x,y) < dist_formula(sx,sy):\n sx = x\n sy = y\n\n elif dir == 'S':\n x, y = south(sx, sy)\n\n if dist_formula(x, y) < dist_formula(sx, sy):\n sx = x\n sy = y\n\n\n elif dir == 'E':\n x, y = east(sx, sy)\n\n if dist_formula(x, y) < dist_formula(sx, sy):\n sx = x\n sy = y\n\n\n else:\n x, y = west(sx, sy)\n\n if dist_formula(x, y) < dist_formula(sx, sy):\n sx = x\n sy = y\n\n if sx == ex and sy == ey:\n print(time)\n break\n\nelse:\n print(-1)\n\n\n\n\n", "t, x1, y1, x2, y2 = map(int, input().split())\r\na = input()\r\ns1 = 0 #N\r\ns2 = 0 #S\r\ns3 = 0 #W\r\ns4 = 0 #E\r\nif x1-x2<0:\r\n s4+=(x2-x1)\r\nelif x1-x2>0:\r\n s3+=(x1-x2)\r\nif y1-y2<0:\r\n s1+=(y2-y1)\r\nelif y1-y2>0:\r\n s2+=(y1-y2)\r\ni = 0\r\nwhile i<t and (s1>0 or s2>0 or s3>0 or s4>0):\r\n if a[i]=='N':\r\n s1-=1\r\n elif a[i]=='S':\r\n s2-=1\r\n elif a[i]=='W':\r\n s3-=1\r\n else:\r\n s4-=1\r\n i+=1\r\nif s1<=0 and s2<=0 and s3<=0 and s4<=0:\r\n print(i)\r\nelse:\r\n print(-1)" ]
{"inputs": ["5 0 0 1 1\nSESNW", "10 5 3 3 6\nNENSWESNEE", "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSSWESNSSEESNSESWSWNSWESNENWNWEE", "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "34 -1000000000 -1000000000 -999999983 -1000000000\nEEEEESSEWNSSSESWEWSWESEWSEESNEWEEE", "1 0 0 0 -1\nS", "1 5 5 5 6\nE", "15 1 1 1 2\nNNNNNNNNNNNNNNN", "11 1 1 1 2\nNNNNNNNNNNN"], "outputs": ["4", "-1", "13", "4", "41", "-1", "1", "-1", "1", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
225
1fc7fba6d45b4304f5f03ecf43c6b69a
Yet Another Problem On a Subsequence
The sequence of integers $a_1, a_2, \dots, a_k$ is called a good array if $a_1 = k - 1$ and $a_1 &gt; 0$. For example, the sequences $[3, -1, 44, 0], [1, -99]$ are good arrays, and the sequences $[3, 7, 8], [2, 5, 4, 1], [0]$ — are not. A sequence of integers is called good if it can be divided into a positive number of good arrays. Each good array should be a subsegment of sequence and each element of the sequence should belong to exactly one array. For example, the sequences $[2, -3, 0, 1, 4]$, $[1, 2, 3, -3, -9, 4]$ are good, and the sequences $[2, -3, 0, 1]$, $[1, 2, 3, -3 -9, 4, 1]$ — are not. For a given sequence of numbers, count the number of its subsequences that are good sequences, and print the number of such subsequences modulo 998244353. The first line contains the number $n~(1 \le n \le 10^3)$ — the length of the initial sequence. The following line contains $n$ integers $a_1, a_2, \dots, a_n~(-10^9 \le a_i \le 10^9)$ — the sequence itself. In the single line output one integer — the number of subsequences of the original sequence that are good sequences, taken modulo 998244353. Sample Input 3 2 1 1 4 1 1 1 1 Sample Output 2 7
[ "from heapq import heappush, heappop\r\nfrom collections import defaultdict, Counter, deque\r\nimport threading\r\nimport sys\r\nimport bisect\r\ninput = sys.stdin.readline\r\ndef ri(): return int(input())\r\ndef rs(): return input()\r\ndef rl(): return list(map(int, input().split()))\r\ndef rls(): return list(input().split())\r\n\r\n\r\n# threading.stack_size(10**8)\r\n# sys.setrecursionlimit(10**6)\r\n\r\n\r\nclass Factorial:\r\n def __init__(self, N, mod) -> None:\r\n N += 1\r\n self.mod = mod\r\n self.f = [1 for _ in range(N)]\r\n self.g = [1 for _ in range(N)]\r\n for i in range(1, N):\r\n self.f[i] = self.f[i - 1] * i % self.mod\r\n self.g[-1] = pow(self.f[-1], mod - 2, mod)\r\n for i in range(N - 2, -1, -1):\r\n self.g[i] = self.g[i + 1] * (i + 1) % self.mod\r\n\r\n def fac(self, n):\r\n return self.f[n]\r\n\r\n def fac_inv(self, n):\r\n return self.g[n]\r\n\r\n def comb(self, n, m):\r\n if n < m:\r\n return 0\r\n return self.f[n] * self.g[m] % self.mod * self.g[n - m] % self.mod\r\n\r\n def perm(self, n, m):\r\n return self.f[n] * self.g[n - m] % self.mod\r\n\r\n def catalan(self, n):\r\n return (self.comb(2 * n, n) - self.comb(2 * n, n - 1)) % self.mod\r\n\r\n def inv(self, n):\r\n return self.f[n-1] * self.g[n] % mod\r\n\r\n\r\ndef main():\r\n mod = 998244353\r\n n = ri()\r\n a = rl()\r\n f = Factorial(10**3, mod)\r\n\r\n dp = [0]*(n+1)\r\n dp[-1] = 1\r\n\r\n for i in range(n-1, -1, -1):\r\n if a[i] > 0 and i+a[i] < n:\r\n for j in range(i+a[i]+1, n+1):\r\n dp[i] += f.comb(j-i-1, a[i])*dp[j]\r\n dp[i] %= mod\r\n print((sum(dp)-1) % mod)\r\n pass\r\n\r\n\r\nmain()\r\n# threading.Thread(target=main).start()\r\n", "N = 10**5\r\nmod = 998244353\r\nfac = [1]*(N+1)\r\nfinv = [1]*(N+1)\r\nfor i in range(N):\r\n fac[i+1] = fac[i] * (i+1) % mod\r\nfinv[-1] = pow(fac[-1], mod-2, mod)\r\nfor i in reversed(range(N)):\r\n finv[i] = finv[i+1] * (i+1) % mod\r\n\r\ndef cmb1(n, r):\r\n if r <0 or r > n:\r\n return 0\r\n r = min(r, n-r)\r\n return fac[n] * finv[r] * finv[n-r] % mod\r\n\r\nn = int(input())\r\nA = list(map(int, input().split()))\r\n\r\ndp = [0]*(n+1)\r\ndp[n] = 1\r\nfor i in range(n-1, -1, -1):\r\n if A[i] <= 0:\r\n continue\r\n if i+A[i]+1 > n:\r\n continue\r\n for j in range(i+A[i]+1, n+1):\r\n dp[i] += dp[j]*cmb1(j-i-1, A[i])\r\n dp[i] %= mod\r\n\r\nans = 0\r\nfor i in range(n):\r\n ans += dp[i]\r\n ans %= mod\r\nprint(ans)\r\n" ]
{"inputs": ["3\n2 1 1", "4\n1 1 1 1", "1\n0", "1\n1"], "outputs": ["2", "7", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
2
1fcdb4cf00b2bfe5bedab19d41b730b4
We Need More Bosses
Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of $n$ locations connected by $m$ two-way passages. The passages are designed in such a way that it should be possible to get from any location to any other location. Of course, some passages should be guarded by the monsters (if you just can go everywhere without any difficulties, then it's not fun, right?). Some crucial passages will be guarded by really fearsome monsters, requiring the hero to prepare for battle and designing his own tactics of defeating them (commonly these kinds of monsters are called bosses). And your friend wants you to help him place these bosses. The game will start in location $s$ and end in location $t$, but these locations are not chosen yet. After choosing these locations, your friend will place a boss in each passage such that it is impossible to get from $s$ to $t$ without using this passage. Your friend wants to place as much bosses as possible (because more challenges means more fun, right?), so he asks you to help him determine the maximum possible number of bosses, considering that any location can be chosen as $s$ or as $t$. The first line contains two integers $n$ and $m$ ($2 \le n \le 3 \cdot 10^5$, $n - 1 \le m \le 3 \cdot 10^5$) — the number of locations and passages, respectively. Then $m$ lines follow, each containing two integers $x$ and $y$ ($1 \le x, y \le n$, $x \ne y$) describing the endpoints of one of the passages. It is guaranteed that there is no pair of locations directly connected by two or more passages, and that any location is reachable from any other location. Print one integer — the maximum number of bosses your friend can place, considering all possible choices for $s$ and $t$. Sample Input 5 5 1 2 2 3 3 1 4 1 5 2 4 3 1 2 4 3 3 2 Sample Output 2 3
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\n\r\ndef lowlink(links):\r\n n = len(links)\r\n order = [-1] * n\r\n low = [n] * n\r\n parent = [-1] * n\r\n child = [[] for _ in range(n)]\r\n roots = set()\r\n x = 0\r\n for root in range(n):\r\n if order[root] != -1:\r\n continue\r\n roots.add(root)\r\n stack = [root]\r\n parent[root] = -2\r\n while stack:\r\n i = stack.pop()\r\n if i >= 0:\r\n if order[i] != -1:\r\n continue\r\n order[i] = x\r\n low[i] = x\r\n x += 1\r\n if i != root:\r\n child[parent[i]].append(i)\r\n stack.append(~i)\r\n check_p = 0\r\n for j in links[i]:\r\n if j == parent[i] and check_p == 0:\r\n check_p += 1\r\n continue\r\n elif order[j] != -1:\r\n low[i] = min(low[i], order[j])\r\n else:\r\n parent[j] = i\r\n stack.append(j)\r\n else:\r\n i = ~i\r\n if i == root:\r\n continue\r\n p = parent[i]\r\n low[p] = min(low[p], low[i])\r\n \r\n return order,low,roots,child\r\n\r\ndef get_articulation(links):\r\n n = len(links)\r\n order,low,roots,child = lowlink(links)\r\n articulation = [0] * n\r\n for i in range(n):\r\n if i in roots:\r\n if len(child[i]) >= 2:\r\n articulation[i] = 1\r\n continue\r\n for j in child[i]:\r\n if order[i] <= low[j]:\r\n articulation[i] = 1\r\n break\r\n \r\n return articulation\r\n\r\ndef get_bridge(links):\r\n n = len(links)\r\n order,low,roots,child = lowlink(links)\r\n bridge = []\r\n for root in roots:\r\n stack = [root]\r\n while stack:\r\n i = stack.pop()\r\n for j in child[i]:\r\n if order[i] < low[j]:\r\n bridge.append([i,j])\r\n stack.append(j)\r\n \r\n return bridge\r\n\r\ndef two_edge_connected_componets(links):\r\n n = len(links)\r\n order,low,roots,child = lowlink(links)\r\n \r\n components = [-1] * n\r\n new_edges = []\r\n x = 0\r\n for root in roots:\r\n components[root] = x\r\n stack = [root]\r\n while stack:\r\n i = stack.pop()\r\n for j in child[i]:\r\n if order[i] < low[j]:\r\n x += 1\r\n components[j] = x\r\n new_edges.append([components[i],x])\r\n else:\r\n components[j] = components[i]\r\n stack.append(j) \r\n x += 1\r\n \r\n return components,new_edges\r\n\r\n\r\nfrom sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,m=map(int,input().split())\r\nedge=[[] for i in range(n)]\r\nfor _ in range(m):\r\n x,y=map(lambda x:int(x)-1,input().split())\r\n edge[x].append(y)\r\n edge[y].append(x)\r\n\r\ncomponents,new_edges = two_edge_connected_componets(edge)\r\nN=max(components)+1\r\nedge2=[[] for i in range(N)]\r\nfor x,y in new_edges:\r\n edge2[x].append(y)\r\n edge2[y].append(x)\r\n\r\ndef dfs(start):\r\n dist=[-1]*N\r\n dist[start]=0\r\n todo=[start]\r\n while todo:\r\n v=todo.pop()\r\n for u in edge2[v]:\r\n if dist[u]==-1:\r\n dist[u]=dist[v]+1\r\n todo.append(u)\r\n mx=max(dist)\r\n idx=dist.index(mx)\r\n return mx,idx\r\n\r\n\r\n_,v0=dfs(0)\r\nans,_=dfs(v0)\r\nprint(ans)" ]
{"inputs": ["5 5\n1 2\n2 3\n3 1\n4 1\n5 2", "4 3\n1 2\n4 3\n3 2", "50 72\n35 38\n19 46\n35 12\n27 30\n23 41\n50 16\n31 6\n20 33\n38 1\n10 35\n13 43\n29 25\n25 4\n1 13\n4 20\n36 29\n13 47\n48 5\n30 21\n30 38\n28 50\n41 45\n25 43\n40 36\n19 47\n31 32\n26 28\n8 13\n43 24\n27 35\n14 29\n14 38\n50 9\n34 49\n12 34\n43 42\n41 15\n46 29\n48 11\n48 7\n40 29\n48 21\n18 26\n15 11\n12 39\n18 42\n27 12\n6 9\n19 37\n45 39\n5 36\n37 22\n18 49\n15 38\n24 42\n34 45\n43 3\n2 1\n18 48\n43 30\n26 10\n30 13\n2 27\n8 3\n22 42\n14 4\n14 27\n13 3\n14 10\n41 25\n17 50\n44 9", "5 6\n1 5\n2 3\n3 5\n2 1\n2 5\n2 4"], "outputs": ["2", "3", "8", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
1
1ffbf62bfc508f4f29980f6d780c61fa
Anton and Danik
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Sample Input 6 ADAAAA 7 DDDAADA 6 DADADA Sample Output Anton Danik Friendship
[ "n=int(input())\r\na=d=0\r\ns=input()\r\nfor i in range(n):\r\n if s[i]=='A': a+=1\r\n else: d+=1\r\nif a==d: print('Friendship')\r\nelif a>d: print('Anton')\r\nelse: print('Danik')", "n=input()\r\ns=input()\r\nna,nd=s.count(\"A\"),s.count(\"D\")\r\nif na>nd:\r\n print(\"Anton\")\r\nelif na==nd:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\nnuma, numd = 0, 0\r\nfor i in s:\r\n if i == 'A':\r\n numa += 1\r\n else:\r\n numd += 1\r\nif numa > numd:\r\n print(\"Anton\")\r\nelif numa < numd:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "# Read input\r\nn = int(input())\r\nresults = input()\r\n\r\n# Count the number of 'A' and 'D' in the results\r\nanton_wins = results.count('A')\r\ndanik_wins = results.count('D')\r\n\r\n# Determine the winner\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins < danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ns = str(input())\r\nk1 = s.count(\"A\")\r\nk2 = s.count(\"D\")\r\nif k1 > k2:\r\n print(\"Anton\")\r\nelif k1 < k2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "N = int(input())\r\ns = str(input())\r\nsum1 = 0;sum2=0;\r\nfor i in range(N):\r\n if s[i] =='A':\r\n sum1+=1\r\n elif s[i] =='D':\r\n sum2+=1\r\n \r\nif sum1>sum2:\r\n print('Anton')\r\nelif(sum1<sum2):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "a=int(input(\"\"))\r\nstr1=input(\"\")\r\nn=0\r\nfor i in str1:\r\n if i==\"A\":\r\n n+=1\r\nif n>a/2:\r\n print(\"Anton\")\r\nelif n==a/2:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "parts = int(input())\r\nstatic = input()\r\n\r\nanton = static.count('A')\r\ndanik = static.count('D')\r\n\r\nif anton > danik:\r\n print('Anton')\r\nelif anton < danik:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "def antonandDanik():\r\n n = int(input())\r\n wonCode = input()\r\n \r\n if wonCode.count('A') > wonCode.count('D'):\r\n print(\"Anton\")\r\n elif wonCode.count('A') < wonCode.count('D'):\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\nantonandDanik()", "num_games=int(input())\r\ngame_winner=list(input())\r\nAnton=0\r\nDanik=0\r\n\r\nfor n in range(num_games):\r\n if game_winner[n] =='A':\r\n Anton+=1\r\n else:\r\n Danik+=1\r\n\r\nif Anton > Danik:\r\n print(\"Anton\")\r\nelif Anton < Danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ngames = input()\r\nwin_A = [differ for differ in games if differ == 'A']\r\nif len(win_A) == n/2:\r\n print(\"Friendship\")\r\nelif len(win_A) > n/2:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\nresultance = list(str(input()))\n\ni = 0\nresult_D = 0\nresult_A = 0\n\nfor i in range(n):\n if resultance[i] == 'D':\n result_D += 1\n elif resultance[i] == 'A':\n result_A += 1\n\nif result_A == result_D:\n print('Friendship')\nelif result_A > result_D:\n print('Anton')\nelif result_A < result_D:\n print('Danik')", "n = int(input()) # Input: The number of games played\r\ns = input() # Input: The outcome of each game (string)\r\n\r\n# Count the occurrences of 'A' (Anton's wins) and 'D' (Danik's wins)\r\nanton_wins = s.count('A')\r\ndanik_wins = s.count('D')\r\n\r\n# Compare the counts to determine the winner\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "input()\r\nIn=input()\r\nLen=len(In)\r\nAntons=In.count(\"A\")\r\ndel In\r\nif(Antons>Len/2):\r\n print(\"Anton\")\r\nelif(Antons<Len/2):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ngames = input()\r\n\r\ncount = games.count('A')\r\n\r\nif count > n / 2:\r\n print('Anton')\r\nelif count < n / 2:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "# Read the input values\r\nn = int(input())\r\nresults = input().strip()\r\n\r\n# Count the number of 'A's and 'D's\r\nanton_wins = results.count('A')\r\ndanik_wins = results.count('D')\r\n\r\n# Compare the counts to determine the winner\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\nt = input()\r\na = []\r\nd = []\r\nfor i in t:\r\n if i == \"A\":\r\n a.append(i)\r\n elif i == \"D\":\r\n d.append(i)\r\n\r\nif len(t) == n:\r\n if len(a) == len(d):\r\n print(\"Friendship\")\r\n elif len(a) > len(d):\r\n print(\"Anton\")\r\n elif len(a) < len(d):\r\n print(\"Danik\")", "num = input()\nstrng = input()\n\nA = 0\nD = 0\n\nfor i in strng:\n\tif i == 'A':\n\t\tA += 1\n\telse:\n\t\tD += 1\nif A > D:\n\tprint(\"Anton\")\nelif A < D:\n\tprint(\"Danik\")\nelse:\n\tprint(\"Friendship\")\n# author - Sirens", "input()\r\na=input()\r\ny=0\r\nd=0\r\nfor i in a:\r\n if i==\"D\":\r\n d+=1\r\n else:\r\n y+=1\r\nif d>y:\r\n print(\"Danik\")\r\nelif d==y:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Anton\")", "n=int(input())\r\ns=str(input())\r\nc=0\r\nm=0\r\nfor i in s:\r\n if i ==\"A\":\r\n c+=1\r\n elif i ==\"D\":\r\n m+=1\r\nif c>m:\r\n print(\"Anton\") \r\nelif m>c:\r\n print(\"Danik\") \r\nelse:\r\n print(\"Friendship\")\r\n ", "x=int( input())\r\nw= input()\r\nimport re\r\nif len( re.findall(\"A\",w))> len (re.findall(\"D\",w)):\r\n print(\"Anton\")\r\nelif len( re.findall(\"A\",w))< len (re.findall(\"D\",w)):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "# n=int(input())\r\n# res=[]\r\n# for i in range(n):\r\n# a=input()\r\n# if a.upper()==\"YES\":\r\n# res.append(\"YES\")\r\n# else:\r\n# res.append(\"NO\")\r\n# for i in res:\r\n# print(i)\r\n\r\n# n=int(input())\r\n# res=0\r\n# for i in range(n):\r\n# p,v,t=[int(i) for i in input().split(\" \")]\r\n# if p+v+t>=2:\r\n# res+=1\r\n# print(res)\r\n\r\nn=int(input())\r\nd=0\r\na=0\r\ns=input()\r\nfor i in range(n):\r\n if s[i]==\"D\":\r\n d+=1\r\n else:\r\n a+=1\r\nif d>a:\r\n print(\"Danik\")\r\nelif d<a:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")\r\n", "c=int(input())\r\nstr1=input()\r\na=str1.count('A')\r\nd=str1.count('D')\r\nif a>d:print('Anton')\r\nelif a<d:print('Danik')\r\nelse:print('Friendship')", "x = input()\r\na = input()\r\ny = a.count(\"A\")\r\nz = a.count(\"D\")\r\nif (y>z):\r\n\tprint (\"Anton\")\r\nelif (y<z):\r\n\tprint (\"Danik\")\r\nelse:\r\n\tprint (\"Friendship\")", "n = int(input())\r\ns = list(input())\r\n\r\n#for i in s:\r\nanton = sum(1 for letter in s if letter == \"A\")\r\ndanik = sum(1 for letter in s if letter == \"D\")\r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\n\r\nelif anton == danik:\r\n print(\"Friendship\")\r\n\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ngames = input()\r\nanton = 0\r\ndanik = 0\r\nfor i in range(len(games)):\r\n if games[i] == \"A\":\r\n anton += 1\r\n else:\r\n danik += 1\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif anton < danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = input()\nn = int(n)\ns = input()\na = 0\nd = 0\nfor i in range(n):\n if s[i] == 'A':\n a += 1\n else:\n d += 1\n\nif (a > d):\n print(\"Anton\")\nelif a < d:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n\n \t\t \t \t \t\t \t \t\t\t \t\t\t", "i=int(input())-input().count('A')*2;print([['Friendship','Danik'][i>0],'Anton'][i<0])", "n = int(input())\r\nwins = list(input())\r\n\r\nA = wins.count(\"A\")\r\nD = wins.count(\"D\")\r\n\r\nif A > D:\r\n print(\"Anton\")\r\nelif A < D:\r\n print(\"Danik\")\r\n\r\nelse: print(\"Friendship\")\r\n", "n = int(input())\r\na_cnt = 2 * input().count('A')\r\nprint('Friendship' if n == a_cnt else ['Anton', 'Danik'][n > a_cnt])", "n=int(input()) \r\nx=str(input()) \r\nAn=0 \r\nDa=0\r\n\r\nfor i in x: \r\n if i == 'A': \r\n An += 1 \r\n else:\r\n Da += 1\r\n \r\nif An > Da:\r\n print(\"Anton\")\r\nelif Da > An:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "Anton = 0\r\nDanik = 0\r\na = int(input())\r\nn = str(input()).upper()\r\nfor i in n:\r\n if i == 'A':\r\n Anton +=1\r\n elif i == 'D':\r\n Danik +=1\r\nif Anton>Danik:\r\n print('Anton')\r\nelif Danik>Anton:\r\n print('Danik')\r\nelif Danik == Anton:\r\n print('Friendship')", "n = int(input())\r\ns = input()\r\n\r\nanton_count = 0\r\ndanik_count = 0\r\n\r\nfor char in s:\r\n if char == 'A':\r\n anton_count += 1\r\n elif char == 'D':\r\n danik_count += 1\r\n\r\nif anton_count > danik_count:\r\n print(\"Anton\")\r\nelif danik_count > anton_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\ns=str(input())\r\ncount1=0\r\ncount2=0\r\n\r\nfor i in range(len(s)):\r\n if s[i]=='A':\r\n count1+=1\r\n \r\n if s[i]=='D':\r\n count2+=1\r\n \r\nif count1>count2:\r\n print(\"Anton\")\r\nelif count2>count1:\r\n print(\"Danik\")\r\nelif count1==count2:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\nA,D=0,0\r\nfor c in s:\r\n if c=='A':\r\n A+=1\r\n else:\r\n D+=1 \r\n\r\nif A==D:\r\n print(\"Friendship\")\r\nelif A>D:\r\n print(\"Anton\" ) \r\nelse :\r\n print(\"Danik\") \r\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Wed Sep 13 16:45:18 2023\n\n@author: huangxiaoyuan\n\"\"\"\n\nn=int(input())\nm=input()\nif len(m)==n:\n a=m.count('D')\n b=m.count('A')\n if a>b:\n print('Danik')\n if a<b:\n print('Anton')\n if a==b:\n print('Friendship')\n \n\n\n \n \n ", "n = int(input())\r\ns = [i for i in input()]\r\n\r\na = 0\r\nd = 0\r\nfor i in range(len(s)):\r\n if s[i].count('A'): a += 1\r\n elif s[i].count('D'): d += 1\r\n\r\nif a > d:\r\n print('Anton')\r\nelif a == d:\r\n print('Friendship')\r\nelse:\r\n print('Danik')\r\n", "anton = 0\r\ndanik = 0\r\n\r\nx = int(input())\r\ny = input()\r\n\r\nfor i in y:\r\n if i == \"A\":\r\n anton += 1\r\n elif i == \"D\":\r\n danik += 1\r\n\r\nif danik == anton:\r\n print(\"Friendship\")\r\nelif danik > anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Anton\")\r\n ", "i = int(input(\"\"))\r\nr = list(input(\"\"))\r\ni -= 1\r\nif r.count(\"A\") > r.count(\"D\"):\r\n print(\"Anton\")\r\nelif r.count(\"A\") == r.count(\"D\"):\r\n print(\"Friendship\")\r\nelif r.count(\"A\") < r.count(\"D\"):\r\n print(\"Danik\")", "input()\r\nl = list(input())\r\nif l.count('A') > l.count('D'):\r\n print('Anton')\r\nelif l.count('A') < l.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "from collections import Counter\r\nn = int(input())\r\nword = input()\r\ncount = Counter(word)\r\nif count[\"A\"] > count[\"D\"]:\r\n print(\"Anton\")\r\nelif count[\"A\"] < count[\"D\"]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n \r\n\r\n\r\n", "num = int(input(\"\"))\r\ngames = input(\"\")\r\na = 0\r\nd = 0\r\nfor i in games:\r\n if i == \"A\":\r\n a+=1\r\n elif i == \"D\":\r\n d +=1\r\nif a > d:\r\n print(\"Anton\")\r\nelif a < d:\r\n print(\"Danik\")\r\nelif a == d:\r\n print(\"Friendship\")", "numberOfGames = int(input())\r\noutcome = input()\r\nantonGames = 0\r\ndanikGames = 0\r\nfor i in range(0,len(outcome)):\r\n if outcome[i] == \"A\":\r\n antonGames += 1\r\n else:\r\n danikGames += 1\r\nif antonGames > danikGames:\r\n print(\"Anton\")\r\nelif danikGames > antonGames:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\nx= str(input())\r\na=0\r\nd=0\r\nfor i in range(0,n,1):\r\n if x[i]==\"A\":\r\n a= a+1\r\n else:\r\n d= d+1\r\nif a>d:\r\n print(\"Anton\")\r\nelif a==d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")\r\n ", "int(input())\r\nn = input()\r\nd = n.count(\"D\")\r\na = n.count(\"A\")\r\nif a > d:\r\n print(\"Anton\")\r\nif d>a:\r\n print(\"Danik\")\r\nif a == d:\r\n print(\"Friendship\")", "# Read the number of games and the outcomes\r\nn = int(input())\r\ns = input()\r\n\r\n# Count the number of wins for Anton and Danik\r\nanton = s.count('A')\r\ndanik = s.count('D')\r\n\r\n# Compare the counts and print the result\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif anton < danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ni = list(map(str, input().strip()))\r\na = i.count('A')\r\nd = i.count('D')\r\nprint('Anton' if a > d else 'Danik' if d > a else 'Friendship')\r\n", "game = int(input())\nresult = input()\nA = 0\nD = 0\nfor i in range(game):\n if result[i] == \"A\":\n A +=1\n else:\n D += 1\nif A>D:\n print(\"Anton\")\nelif D>A:\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nAnton = 0\r\nDanik = 0\r\nfor i in range(n):\r\n if(s[i]==\"A\"):\r\n Anton = Anton+1\r\n elif(s[i]==\"D\"):\r\n Danik = Danik+1\r\nif(Anton>Danik):\r\n print(\"Anton\")\r\nelif(Danik>Anton):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\nl=list(s)\r\na=l.count('A')\r\nd=l.count('D')\r\nif(a>d):\r\n print(\"Anton\")\r\nelif(a<d):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "n=int(input())\r\nwins=input()\r\naw,dw=0,0\r\nfor i in range(n):\r\n if wins[i]==\"A\":\r\n aw+=1\r\n else:\r\n dw+=1\r\nif aw>dw:\r\n print(\"Anton\")\r\nelif dw>aw:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "i1 = input()\r\ni2 = input()\r\n\r\n\r\nAnton = i2.count('A')\r\nDanik= i2.count('D')\r\nwin = Anton > Danik\r\ntie = Anton == Danik\r\n\r\nprint(('Anton' if win else ('Friendship' if tie else 'Danik')))", "i1=int(input())\r\ni2=[*input()]\r\na,d=0,0\r\nfor i in range(i1):\r\n if(i2[i]==\"A\"):\r\n a=a+1\r\n else:\r\n d=d+1\r\nif(a>d):\r\n print(\"Anton\")\r\nelif(d>a):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "x=int(input())\r\ny=input()\r\nz=y.count('A')\r\np=y.count('D')\r\nif z>p:\r\n print(\"Anton\")\r\nelif z<p:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "import sys\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport itertools\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict, Counter, deque\r\nfrom bisect import bisect_left,bisect_right, insort_left, insort_right\r\nimport re\r\n\r\nmod=1000000007\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\ndef get_int(): return int(sys.stdin.readline().strip())\r\ndef get_list_strings(): return list(map(str, sys.stdin.readline().strip().split()))\r\n\r\ndef solve():\r\n n = get_int()\r\n s = get_string()\r\n\r\n count = Counter(s)\r\n\r\n if count['A'] > count['D']:\r\n return \"Anton\"\r\n elif count['A'] < count['D']:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n \r\n\r\nif __name__ == \"__main__\":\r\n print(solve())", "x = int(input())\r\ny = str(input())\r\ndef instanceof(y):\r\n a = 0\r\n d = 0\r\n for i in y:\r\n if i == \"A\":\r\n a += 1\r\n else:\r\n d += 1\r\n if a>d:\r\n return \"Anton\"\r\n elif a<d:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\nprint(instanceof(y))", "l = int(input())\r\ng = input()\r\n\r\nif g.count('A') > g.count('D'):\r\n print(\"Anton\")\r\nelif g.count('A') < g.count('D'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=input()\nn=int(n)\na=0\nd=0\nline=input()\nfor i in line:\n if i=='A' :\n a=a+1\n else:\n d=d+1\n\nif a>d:\n print(\"Anton\")\nelif a < d:\n print(\"Danik\")\nelif a==d:\n print(\"Friendship\")\n\t\t\t\t\t\t \t \t\t\t \t \t \t \t", "n = int(input())\r\nx = input().strip()\r\nanik = 0\r\ndanik = 0\r\ns = x[:n]\r\nfor i in range(len(s)):\r\n if s[i] == \"A\":\r\n anik += 1\r\n else:\r\n danik += 1\r\n\r\nif anik > danik:\r\n print(\"Anton\")\r\nelif danik > anik:\r\n print(\"Danik\") \r\nelse:\r\n print(\"Friendship\")", "N=input()\r\nL=input()\r\nC=[i for i in L]\r\nif C.count('A')>C.count('D'):\r\n print(\"Anton\")\r\nelif C.count('D')>C.count('A'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\nch=input()\nr=0\nfor i in ch:\n\tif i=='A':\n\t\tr=r+1\n\telse:\n\t\tr=r-1\nif r>0:\n\tprint('Anton')\nelif r==0:\n\tprint('Friendship')\nelse:\n\tprint('Danik')", "Games = int(input())\r\nResults = list(input())\r\n\r\nAnton = 0;\r\nDanik = 0;\r\n\r\nfor x in Results:\r\n if x == \"A\":\r\n Anton = Anton + 1\r\n elif x == \"D\":\r\n Danik = Danik + 1\r\n\r\nif Anton > Danik:\r\n print(\"Anton\")\r\nelif Danik > Anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\ncount1=0\r\ncount2=0\r\nfor i in range(n):\r\n\r\n if s[i]=='A':\r\n\r\n count1 += 1\r\n elif s[i]=='D':\r\n count2 += 1\r\nif count1 > count2:\r\n print(\"Anton\")\r\nelif count1 < count2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\ncount_a = s.count('A')\r\ncount_d = n - count_a\r\nif count_a > count_d:\r\n print(\"Anton\")\r\nelif count_a < count_d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "h=int(input())\r\nm=input()\r\nres=0\r\np=0\r\nfor i in range(len(m)):\r\n if m[i]==\"D\":\r\n res+=1\r\n else:\r\n p+=1\r\n\r\nif res>p:\r\n print(\"Danik\")\r\nelif p>res:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "a=0\r\nb=0\r\nx=int(input())\r\nn=input()\r\nfor i in n:\r\n if(i==\"A\"):\r\n a+=1\r\n else:\r\n b+=1\r\nif(a>b):\r\n print(\"Anton\")\r\nelif(b>a):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n,count=int(input()),0\r\nfor char in input():\r\n if char==\"A\":\r\n count+=1\r\nprint(\"Anton\" if n-count<count else \"Danik\" if n-count>count else \"Friendship\")\r\n\r\n\r\n", "d=int(input())-input().count('A')*2;print([['Friendship','Danik'][d>0],'Anton'][d<0])", "num_rounds = int(input())\r\nvt = 0 \r\nbt = 0 \r\nresults = input()\r\nfor char in results:\r\n if char == \"A\":\r\n vt += 1\r\n elif char == \"D\":\r\n bt += 1\r\nif vt > bt:\r\n print(\"Anton\")\r\nelif bt > vt:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "a = int(input())\r\n\r\nb = input()\r\n\r\nanton = b.count('A')\r\ndanik = b.count('D')\r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif anton < danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ns = input()\r\na = 0\r\nfor i in range(n):\r\n if s[i] == 'D' :\r\n a += 1\r\nif len(s) - a == a :\r\n print('Friendship')\r\nelif len(s) - a < a :\r\n print('Danik')\r\nelse:\r\n print('Anton')\r\n", "import sys\r\n\r\nn = int(sys.stdin.readline().split()[0])\r\n\r\ns = sys.stdin.readline()[:-1]\r\n\r\nanton = s.count('A')\r\ndanik = s.count('D')\r\n\r\nif anton > danik:\r\n print('Anton')\r\nelif anton < danik:\r\n print('Danik')\r\nelif anton == danik:\r\n print('Friendship')", "a=int(input())\r\nb=input()\r\nc_a=b.count('A')\r\nc_d=b.count('D')\r\nif c_a > c_d:\r\n print('Anton')\r\nelif c_a < c_d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n\r\n \r\n", "n = int(input())\r\ns = str(input())\r\n\r\nds = [s.count(\"D\"), s.count(\"A\")]\r\nif ds[0] == ds[1]:\r\n\tprint(\"Friendship\")\r\nelif ds[0] > ds[1]:\r\n\tprint(\"Danik\")\r\nelse:\r\n\tprint(\"Anton\")", "a=str(input())\r\nb=str(input())\r\nc=0\r\nfor i in b:\r\n if i==\"D\":\r\n c=c+1\r\nif c>len(b)/2:\r\n print(\"Danik\")\r\nelif c==len(b)/2:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Anton\")", "x=input()\r\ny=input()\r\nm=y.count(\"A\")\r\nn=y.count(\"D\")\r\nif m>n:\r\n print(\"Anton\")\r\nelif n>m:\r\n print(\"Danik\")\r\nelif n==m:\r\n print(\"Friendship\")", "n=input()\r\noutcome=input()\r\nd=0;a=0\r\nfor game in outcome:\r\n if game=='A':\r\n a+=1\r\n elif game=='D':\r\n d+=1\r\nif a>d:\r\n print('Anton')\r\nelif a<d:\r\n print('Danik')\r\nelif a==d:\r\n print('Friendship')", "x=int(input())\r\ny=str(input())\r\n\r\nanton=y.count('A')\r\ndanick=y.count('D')\r\n\r\nif(len(y)==x):\r\n if(anton>danick):\r\n print('Anton')\r\n elif(anton<danick):\r\n print('Danik')\r\n elif(anton==danick):\r\n print('Friendship')\r\nelse:\r\n print('ERROR')\r\n", "reps = int(input())\r\nscore = list(input())\r\nA = 0\r\nD = 0\r\nfor x in score:\r\n if x == \"A\":\r\n A += 1\r\n elif x == \"D\":\r\n D += 1\r\nif A > D:\r\n print('Anton')\r\nelif D > A:\r\n print('Danik')\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ntext = list(input())\r\n\r\ntotal_A = 0\r\ntotal_D = 0\r\n\r\nfor alphabet in text:\r\n if alphabet == 'A':\r\n total_A += 1\r\n elif alphabet == 'D':\r\n total_D += 1\r\n\r\nif total_A > total_D:\r\n print(\"Anton\")\r\nelif total_A < total_D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "#initializes match number (not needed) and results list\r\nmatches = input()\r\nresults = input()\r\nwinAnton = 0\r\nwinDanik = 0\r\n\r\n#calculates score matchup\r\nfor result in results:\r\n if result == 'A':\r\n winAnton += 1\r\n if result == 'D':\r\n winDanik += 1\r\n \r\n#prints answer based on score matchup\r\nif winAnton > winDanik:\r\n print('Anton')\r\nelif winAnton < winDanik:\r\n print('Danik')\r\nelif winAnton == winDanik:\r\n print('Friendship')", "useless=input()\nthing=input()\nasss=0\nds=0\nfor char in thing:\n if char==\"A\":\n asss+=1\n elif char==\"D\":\n ds+=1\nif asss>ds:\n print(\"Anton\")\nelif ds>asss:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n\n\t \t\t \t\t \t \t\t\t\t\t \t\t \t\t \t\t", "n = int(input())\r\nx = input()\r\ncount_a = count_d = 0\r\nfor i in x:\r\n if i == 'A':\r\n count_a += 1\r\n if i == 'D':\r\n count_d += 1\r\nif count_a > count_d:\r\n print('Anton')\r\nelif count_a < count_d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = input()\r\n#0 is A and 1 is D\r\nfreq = [0,0]\r\nfor char in s:\r\n if char == \"A\":\r\n freq[0] += 1\r\n else:\r\n freq[1] += 1\r\n\r\nif freq[0]>freq[1]:\r\n print(\"Anton\")\r\nelif freq[0]<freq[1]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "number_of_matches = int(input())\r\nwinner = input()\r\na_count , d_count = 0 , 0\r\nfor i in range(0 , len(winner)):\r\n if winner[i] == 'A':\r\n a_count += 1\r\n else:\r\n d_count += 1\r\n\r\nif a_count > d_count:\r\n print(\"Anton\")\r\nelif d_count > a_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = str(input())\r\nkol=0\r\nkol1=0\r\nfor i in range(len(s)):\r\n if(s[i] == 'A'):\r\n kol+=1\r\n else:\r\n kol1+=1\r\nif(kol > kol1):\r\n print(\"Anton\")\r\nif(kol<kol1):\r\n print(\"Danik\")\r\nif(kol == kol1):\r\n print(\"Friendship\")\r\n", "_ = input()\r\ngames = input()\r\na = 0\r\nd = 0\r\nfor game in games:\r\n if game == \"A\":\r\n a += 1\r\n elif game == \"D\":\r\n d += 1\r\n\r\nif a > d:\r\n print(\"Anton\")\r\nelif a < d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns1=input()\r\nbound=n/2\r\n\r\nanton=s1.count('A')\r\n\r\nif(anton>bound):\r\n print(\"Anton\")\r\nelif(anton<bound):\r\n print(\"Danik\")\r\n\r\nelse:\r\n print(\"Friendship\")", "a=int(input())\r\nb=list(input())\r\nAD=0\r\nfor i in b:\r\n if i=='A':\r\n AD+=1\r\n else:\r\n AD-=1\r\nif AD==0:\r\n print('Friendship')\r\nelif AD>0:\r\n print('Anton')\r\nelse:\r\n print('Danik')\r\n \r\n", "i = int(input())\r\nnum = str(input())\r\nx = num.count(\"D\")\r\ny = num.count(\"A\")\r\nif x > y:\r\n print(\"Danik\")\r\nelif x < y:\r\n print(\"Anton\")\r\nelif x == y:\r\n print(\"Friendship\")", "danik = 0\r\nanton = 0\r\nn = int(input())\r\n\r\nfor i in input():\r\n\r\n if i == \"A\":\r\n anton += 1\r\n else:\r\n danik += 1\r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\n\r\nelif danik > anton:\r\n print(\"Danik\")\r\n\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\naCount = 0\r\ndCount = 0\r\nresults = str(input())\r\nresult_list = [*results]\r\nfor i in result_list:\r\n if i == 'A':\r\n aCount += 1\r\n else:\r\n dCount += 1\r\nif aCount > dCount:\r\n print('Anton')\r\nelif dCount > aCount:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "w=int(input())\r\nv=input()\r\nif v.count('A')>v.count('D'):print('Anton')\r\nelif v.count('A')<v.count('D'):print('Danik')\r\nelse:print('Friendship')", "if __name__ == '__main__':\r\n n = int(input())\r\n games = input()\r\n count_A = 0\r\n for letter in games:\r\n if letter == 'A':\r\n count_A = count_A + 1\r\n count_B = n - count_A\r\n if count_A > count_B:\r\n print('Anton')\r\n elif count_A < count_B:\r\n print('Danik')\r\n else:\r\n print('Friendship')\r\n", "from collections import Counter\r\nn = input()\r\nfre = Counter(input())\r\n\r\nif fre['A'] > fre['D']:\r\n print('Anton')\r\nelif fre['A'] < fre['D']:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "a = int(input())\r\nx = input()\r\nz = list(x)\r\nif z.count('A') > z.count('D'):\r\n print('Anton')\r\nelif z.count('A') < z.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "n=int(input())\r\ns=input()\r\ncount=s.count('A')\r\ncnt=s.count('D')\r\nif count==cnt:\r\n print(\"Friendship\")\r\nelif count>cnt:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "def determine_winner(s):\r\n anton_wins = s.count('A')\r\n danik_wins = len(s) - anton_wins\r\n \r\n if anton_wins > danik_wins:\r\n return \"Anton\"\r\n elif danik_wins > anton_wins:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n# Read input\r\nn = int(input())\r\ns = input()\r\n\r\n# Calculate and print the result\r\nresult = determine_winner(s)\r\nprint(result)\r\n", "def game_winner(result):\r\n anton = 0\r\n danik = 0\r\n for winner in result:\r\n if winner == 'A':\r\n anton += 1\r\n elif winner == 'D':\r\n danik += 1\r\n if anton > danik:\r\n return 'Anton'\r\n elif danik > anton:\r\n return 'Danik'\r\n return 'Friendship'\r\n\r\nn = int(input())\r\nresult = input()\r\nprint(game_winner(result))", "import sys\nfrom itertools import permutations\nfrom collections import Counter\nimport math\nM = 1000000007\n\n#s = str(sys.stdin.readline())\nn = (int(sys.stdin.readline()))\n#a = list(map(int,sys.stdin.readline().split()))\n\nans = Counter(str(sys.stdin.readline()))\nif ans['D'] == ans['A']:\n print(\"Friendship\")\nelif ans['D'] < ans['A']:\n print('Anton')\nelif ans['A'] < ans['D']:\n print(\"Danik\")", "from sys import stdin\ninput = stdin.readline\n\n\nif __name__ == \"__main__\":\n input()\n s = input().strip()\n anton = s.count('A')\n danik = len(s)-anton\n if anton == danik:\n print(\"Friendship\")\n else:\n print([\"Anton\", \"Danik\"][danik > anton])\n\n \t \t \t\t\t\t\t \t\t\t \t\t\t\t\t\t\t\t", "n=int(input())\r\ns=input()\r\nl=z=0\r\nfor i in s:\r\n if i=='D':\r\n l+=1;\r\n else:\r\n z+=1;\r\nif l==z:\r\n print('Friendship');\r\nelif l>z:\r\n print('Danik');\r\nelif l<z:\r\n print('Anton');\r\n", "n=int(input())\r\ns=input()\r\na,d,f=0,0,0\r\nfor c in s:\r\n if c==\"A\":\r\n a+=1\r\n elif c==\"D\":\r\n d+=1\r\n else:\r\n f+=1\r\nif a>d and a>d:\r\n print(\"Anton\")\r\nelif d>a and d>f:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "x = int(input())\r\ny = input()\r\nz = y.count('D')\r\nw = x - z\r\nif z > w:\r\n print('Danik')\r\nelif z < w:\r\n print('Anton')\r\nelse:\r\n print('Friendship')", "def chess_winner(n, s):\r\n anton_wins = s.count('A')\r\n danik_wins = n - anton_wins\r\n\r\n if anton_wins > danik_wins:\r\n return \"Anton\"\r\n elif danik_wins > anton_wins:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\ndef main():\r\n n = int(input())\r\n s = input().strip()\r\n\r\n result = chess_winner(n, s)\r\n print(result)\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "def determineWinner(n, s):\r\n count_A = s.count('A') # Count of games won by Anton\r\n count_D = n - count_A # Count of games won by Danik\r\n \r\n if count_A > count_D:\r\n return \"Anton\"\r\n elif count_D > count_A:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n# Read input\r\nn = int(input())\r\ns = input()\r\n\r\n# Call the function and print the result\r\nprint(determineWinner(n, s))\r\n", "n=int(input())\r\ns=input()\r\na=0\r\nd=0\r\nfor ch in s:\r\n if(ch=='A'):\r\n a=a+1 \r\n else:\r\n d=d+1 \r\nif(a>d):\r\n print(\"Anton\")\r\nelif(d>a):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "a=int(input())\r\nl=input()\r\nl=list(l)\r\nca=l.count('A')\r\ncd=l.count('D')\r\nif ca>cd:\r\n print(\"Anton\")\r\nelif ca<cd:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = input()\nn = int(n)\na = 0\nd = 0\nline=input()\n\n\n\nfor i in line:\n if i =='A' :\n a = a + 1\n else:\n d = d + 1\n\n\n\nif a > d:\n print('Anton')\nelif d > a:\n print('Danik')\nelse:\n print('Friendship')\n\t \t \t\t \t \t \t \t\t \t \t\t \t \t\t", "N=int(input())\r\nstr=input()\r\nx,y=0,0\r\nfor i in range(N):\r\n if str[i]=='A':\r\n x+=1\r\n else:\r\n y+=1\r\nif x>y:\r\n print('Anton')\r\nelif x==y:\r\n print('Friendship')\r\nelse:\r\n print('Danik')", "n = int(input())\r\ni = input()\r\na = 0\r\nd = 0\r\nfor j in i:\r\n if j==\"A\":\r\n a+=1\r\n elif j==\"D\":\r\n d+=1\r\n\r\nif a>d:\r\n print(\"Anton\")\r\nelif a<d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "num = int(input())\r\nrow = input()\r\na = 0\r\nd = 0\r\n\r\nfor i in range(num):\r\n if row[i] == 'A': a+=1\r\n else: d+=1\r\n\r\nif a > d: print('Anton')\r\nelif a < d: print('Danik')\r\nelse: print('Friendship')\r\n", "n=input()\r\nm=list(input())\r\nf=0\r\nfor i in m:\r\n if i==\"A\":\r\n f+=1\r\n elif i==\"D\":\r\n f-=1\r\nif f>0:\r\n print(\"Anton\")\r\nelif f<0:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "x=int(input())\r\nst=input()\r\nDank=0\r\nAnt=0\r\n\r\nfor i in st:\r\n if i=='D':\r\n Dank+=1\r\n else:\r\n Ant+=1\r\n\r\nif Dank>Ant:\r\n print(\"Danik\")\r\nelif Ant>Dank:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "a=int(input())\r\nstring=input()\r\np=0\r\nq=0\r\nfor char in string:\r\n\tif char=='A':\r\n\t\tp+=1\r\n\telif char=='D':\r\n\t\tq+=1\r\nif p>q:\r\n\tprint(\"Anton\")\r\nelif q>p:\r\n\tprint(\"Danik\")\r\nelif p==q:\r\n\tprint(\"Friendship\")", "games_played = input().split()\r\nwinner = input()\r\n\r\nanton_p = 0\r\ndanik_p = 0\r\n\r\nwinner.split()\r\n\r\nfor won in winner:\r\n if won == 'A':\r\n anton_p += 1\r\n else:\r\n danik_p += 1\r\n\r\n\r\nif anton_p > danik_p:\r\n print('Anton')\r\nelif anton_p < danik_p:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = input()\r\n\r\ncntA = s.count(\"A\")\r\nif n - cntA < cntA: print(\"Anton\")\r\nelif n - cntA > cntA: print(\"Danik\")\r\nelse: print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nA = D = 0\r\nfor _ in range (len(s)):\r\n if s[_] == 'A':\r\n A += 1\r\n elif s[_] == 'D':\r\n D += 1\r\nif A > D:\r\n print('Anton')\r\nelif A < D:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=int(input(\"\")) \r\ns=input(\"\") \r\nA=s.count(\"A\") \r\nB=s.count(\"D\") \r\nif A>B: \r\n print(\"Anton\") \r\nelif A<B: \r\n print(\"Danik\") \r\nelse: \r\n print(\"Friendship\")", "n = input()\r\nstring = input()\r\n\r\nif string.count('A')>string.count('D'):\r\n print('Anton')\r\nelif string.count('D')>string.count('A'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = input()\r\nvalue = input()\r\n\r\nif value.count(\"A\") > value.count(\"D\"):\r\n print(\"Anton\")\r\nelif value.count(\"A\") < value.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "\r\nx = int(input())\r\nn = str(input())\r\nk=0\r\nj=0\r\nfor i in n:\r\n if i == \"A\":\r\n k=k+1\r\n elif i==\"D\":\r\n j = j+1\r\n else:\r\n print(\"invalid\")\r\n\r\nif k>j:\r\n print(\"Anton\")\r\nelif j>k:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n \r\n ", "num = int(input())\r\nstring = input()\r\nlst = [*string]\r\nanton = 0\r\ndanik = 0\r\nfor i in range(0,num):\r\n if lst[i]==\"A\":\r\n anton = anton+1\r\n else:\r\n danik = danik+1\r\nif anton>danik:\r\n print(\"Anton\")\r\nelif danik>anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\ns=input()\r\ncnt_a=0\r\ncnt_d=0\r\nfor i in range(len(s)):\r\n if s[i]=='A':\r\n cnt_a+=1\r\n else:\r\n cnt_d+=1\r\nif cnt_a>cnt_d:\r\n print('Anton')\r\nelif cnt_d>cnt_a:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "def finnalyWinner(A, D):\r\n if A == D:\r\n return \"Friendship\"\r\n return \"Anton\" if A > D else \"Danik\"\r\n\r\nn = int(input())\r\ns = input()\r\n\r\nwinnerA, winnerD = 0, 0\r\nfor i in range(n):\r\n if s[i] == \"A\":\r\n winnerA += 1\r\n if s[i] == \"D\":\r\n winnerD += 1\r\nprint(finnalyWinner(winnerA, winnerD))", "Number = int(input())\nWords = list(input())\ncount_Anton = 0;\ncount_Danik = 0;\n\nfor x in Words:\n if x == \"A\":\n count_Anton = count_Anton + 1\n elif x == \"D\":\n count_Danik = count_Danik + 1\n\nif count_Anton > count_Danik:\n print(\"Anton\")\nelif count_Anton == count_Danik:\n print(\"Friendship\")\nelse:\n print(\"Danik\")", "# Вводим длину строки\r\n\r\nn = int(input())\r\n\r\n# Вводим строку\r\n\r\nstroka = input()\r\n\r\n# Заведем два счетчика для побед Дани и Антона\r\n\r\nDanya = 0\r\n\r\nAnton = 0\r\n\r\n# Циклом переберем всю строку\r\n\r\nfor i in range(len(stroka)):\r\n\r\n # Посчитаем количество побед Дани и Антона\r\n\r\n if stroka[i] == 'A':\r\n\r\n Anton = Anton + 1\r\n\r\n else:\r\n\r\n Danya = Danya + 1\r\n\r\n# Сравним количество побед\r\n\r\nif Anton > Danya:\r\n print(\"Anton\")\r\n\r\n\r\nelif Anton < Danya:\r\n print(\"Danik\")\r\n\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\n\r\ncA = 0\r\ncD = 0\r\n\r\nfor elem in s:\r\n if elem == 'A':\r\n cA += 1\r\n elif elem == 'D':\r\n cD += 1\r\n\r\nif cA > cD:\r\n print('Anton')\r\nelif cD > cA:\r\n print('Danik')\r\nelif cA == cD:\r\n print('Friendship')", "\r\nn = int(input())\r\ns = input()\r\n\r\n\r\ncount_a = s.count('A')\r\ncount_d = s.count('D')\r\n\r\n\r\nif count_a > count_d:\r\n print(\"Anton\")\r\nelif count_d > count_a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "m=int(input())\r\nn=input()\r\nif n.count('A')>n.count('D'):\r\n print(\"Anton\")\r\nelif n.count('A')<n.count('D'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "from collections import Counter\r\nn = input()\r\ns = input()\r\ncnt = Counter(s)\r\nif cnt['A'] > cnt['D']:\r\n print('Anton')\r\nelif cnt['A'] < cnt['D']:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=int(input())\r\ngames=input()\r\ncount1=0\r\ncount2=0\r\nfor i in games:\r\n if i=='A':\r\n count1+=1\r\n else:\r\n count2+=1\r\nif count1>count2:\r\n print('Anton')\r\nelif count1==count2:\r\n print('Friendship')\r\nelse:\r\n print('Danik')", "# n=int(input())\r\n# for i in range(1,n+1):\r\n# word=input()\r\n# if 1<=n<=100:\r\n# ln=len(word)\r\n# if ln>10:\r\n# print(word[0],ln-2,word[-1], sep=\"\")\r\n# else:\r\n# print(word)\r\n\r\nn=int(input())\r\ns=input()\r\na=s.count(\"A\")\r\nd=s.count(\"D\")\r\nif 1<=n<=100000:\r\n if s==\"A\" or 'D':\r\n if a>d:\r\n print(\"Anton\")\r\n elif d>a:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\n \r\n \r\n\r\n\r\n", "n=int(input())\r\na_cnt=2*input().count('A')\r\nprint('Friendship' if n==a_cnt else ['Anton','Danik'][n>a_cnt])", "numberOfGames = int(input())\r\nwinner = input()\r\nantonWins = winner.count('A')\r\ndanikWins = winner.count('D')\r\n\r\nif antonWins > danikWins:\r\n print(\"Anton\")\r\nelif danikWins > antonWins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def draw_st(n, t):\r\n ca = 0\r\n cd = 0\r\n for c in t:\r\n if c == 'A':\r\n ca += 1\r\n else:\r\n cd += 1\r\n if ca > cd:\r\n return 'Anton'\r\n elif ca < cd:\r\n return 'Danik'\r\n else:\r\n return 'Friendship'\r\n\r\nnum = int(input())\r\ntext = input()\r\nprint(draw_st(num, text))", "a=int(input())\r\nb=input()\r\nc=0\r\nfor i in b:\r\n if 'A' == i:\r\n c=c+1\r\nif c==a/2:\r\n print(\"Friendship\")\r\nelif (len(b)/2)<c:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")\r\n \r\n", "strash = int(input())\r\nsinp = str(input())\r\nx = sinp.count(\"D\")\r\ny = sinp.count(\"A\")\r\nif x > y:\r\n print(\"Danik\")\r\nelif x < y:\r\n print(\"Anton\")\r\nelif x == y:\r\n print(\"Friendship\")", "x=int(input())\r\ny=input()\r\na=0\r\nd=0\r\nfor x in range(x):\r\n if \"A\" in y[x]:\r\n a=a+1\r\n if \"D\" in y[x]:\r\n d=d+1\r\nif a>d:\r\n print(\"Anton\")\r\nelif a==d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "n=int(input())\r\na=input()\r\ncount1=0\r\ncount2=0\r\nfor i in range(len(a)):\r\n if a[i]==\"A\":\r\n count1+=1\r\n else:\r\n count2+=1\r\nif count1>count2:\r\n print(\"Anton\")\r\nelif count2>count1:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "num=eval(input())\r\ns=input()\r\nant=0\r\ndan=0\r\nfor i in range(num):\r\n if s[i]==\"A\":\r\n ant+=1\r\n else:\r\n dan+=1\r\nif dan==ant or num==0:\r\n print(\"Friendship\")\r\n\r\nif ant>dan:\r\n print(\"Anton\")\r\nif dan>ant:\r\n print(\"Danik\")", "def main():\r\n n = int(input())\r\n input_str = input()\r\n \r\n a_count = input_str.count('A') * 2\r\n \r\n if a_count < n:\r\n print(\"Danik\")\r\n elif a_count > n:\r\n print(\"Anton\")\r\n else:\r\n print(\"Friendship\")\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\na=str(input())\r\nanton=0\r\ndanik=0\r\nfor num in a:\r\n if num==\"A\":\r\n anton=anton+1 \r\n \r\n else:\r\n danik=danik+1 \r\nif anton>danik:\r\n print(\"Anton\")\r\nelif anton<danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\nnames = input()\r\nif names.count(\"A\") > names.count(\"D\"):\r\n print(\"Anton\")\r\nelif names.count(\"A\") < names.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nanton_count = s.count('A')\r\ndanik_count = n - anton_count\r\nprint(\"Anton\" if anton_count > danik_count else \"Danik\" if danik_count > anton_count else \"Friendship\")\r\n", "n=int(input())\r\nword=input()\r\nl=len(word)\r\nacount=0\r\ndcount=0\r\nfor i in range(l):\r\n if word[i]==\"D\":\r\n dcount+=1\r\n else:\r\n acount+=1\r\nif dcount==acount:\r\n print(\"Friendship\")\r\nelif dcount>acount:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Anton\")\r\n ", "def determine_winner(n, s):\r\n anton_count = s.count('A')\r\n danik_count = n - anton_count\r\n \r\n if anton_count > danik_count:\r\n return \"Anton\"\r\n elif danik_count > anton_count:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n\r\nn = int(input())\r\ns = input()\r\n\r\n\r\nresult = determine_winner(n, s)\r\nprint(result)", "n=int(input())\r\nstring=input()\r\nc1=0\r\nc2=0\r\nfor char in string:\r\n\tif char=='A':\r\n\t\tc1+=1\r\n\telif char=='D':\r\n\t\tc2+=1\r\nif c1>c2:\r\n\tprint(\"Anton\")\r\nelif c2>c1:\r\n\tprint(\"Danik\")\r\nelif c1==c2:\r\n\tprint(\"Friendship\")", "a = 0\r\nd = 0\r\n\r\nin_num = int(input())\r\nif (in_num < 1) or (in_num > 100000):\r\n print(\"Error_1\")\r\n\r\nin_str = input()\r\nif (len(in_str) < in_num) or (len(in_str) > in_num):\r\n print(\"Error_2\")\r\n\r\nfor ch in in_str:\r\n if (ch == 'A'):\r\n a+=1\r\n elif(ch == 'D'):\r\n d+=1\r\n else:\r\n print(\"Error_3\")\r\n\r\nif a>d:\r\n print(\"Anton\")\r\nelif d>a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\na = input()\r\nx,y = 0,0\r\nfor i in range(n):\r\n if a[i] == \"A\":\r\n x += 1\r\n else:\r\n y += 1\r\nif x > y:\r\n print(\"Anton\")\r\nelif x < y:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Sep 25 09:35:17 2023\r\n\r\n@author: 25419\r\n\"\"\"\r\n\r\nn=int(input())\r\nstr1=input()\r\na=str1.count('A')\r\nd=str1.count('D')\r\nif a>d:\r\n print('Anton')\r\nelif a<d:\r\n print('Danik')\r\nelse:print('Friendship')", "t = int(input())\r\na = input()\r\nA = 0\r\nD = 0\r\nfor i in range(t):\r\n\tif a[i]==\"A\":\r\n\t\tA += 1\r\n\telse:\r\n\t\tD += 1\r\nif A > D:\r\n\tprint(\"Anton\")\r\nelif D > A:\r\n\tprint(\"Danik\")\r\nelse:\r\n\tprint(\"Friendship\")", "n = int(input())\r\ninp = input()\r\na = 0\r\nd = 0\r\na_wins = inp.count('A')\r\nd_wins = inp.count('D')\r\nif a_wins > d_wins:\r\n print(\"Anton\")\r\nelif d_wins > a_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "round = int(input())\r\ngames = input()\r\nanton, danik = 0, 0\r\n\r\nfor i in games:\r\n if (i == \"A\"):\r\n anton += 1\r\n elif (i == 'D'):\r\n danik += 1\r\n else :\r\n continue\r\n\r\nif (anton > danik):\r\n print(\"Anton\")\r\nelif (anton < danik):\r\n print(\"Danik\")\r\nelse :\r\n print(\"Friendship\")", "n = input()\r\ngames = input()\r\n\r\nprint(\"Anton\" if games.count('A') > games.count('D') else (\"Danik\" if games.count('D') > games.count('A') else \"Friendship\"))\r\n", "n = int(input())\r\nstring = input()\r\nA, D = string.count('A'), string.count('D')\r\nif A > D:\r\n print('Anton')\r\nelif D > A:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "def main():\r\n n = int(input())\r\n word = input()\r\n\r\n freq = {\r\n \"A\": 0,\r\n \"D\": 0\r\n }\r\n\r\n for i in range(n):\r\n freq[word[i]] += 1\r\n\r\n\r\n if freq[\"A\"] > freq[\"D\"]:\r\n return \"Anton\"\r\n elif freq[\"A\"] < freq[\"D\"]:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n print(main())", "n = int(input())\r\n\r\nb = input()\r\n\r\ncount1=0\r\ncount2=0\r\n\r\nfor i in range(n):\r\n \r\n if b[i]=='A':\r\n count1+=1 \r\n else:\r\n count2+=1 \r\n \r\nif count1>count2:\r\n \r\n print(\"Anton\")\r\n \r\nelif count1<count2:\r\n print(\"Danik\")\r\n \r\nelif count1==count2:\r\n print(\"Friendship\")\r\n \r\n ", "import sys\r\n\r\n\r\ndef iinp():\r\n return int(sys.stdin.readline().strip())\r\n\r\n\r\ndef linp():\r\n return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef lsinp():\r\n return sys.stdin.readline().strip().split()\r\n\r\n\r\ndef digit():\r\n return [int(i) for i in (list(sys.stdin.readline().strip()))]\r\n\r\n\r\ndef char():\r\n return list(sys.stdin.readline().strip())\r\n\r\n\r\nfrom bisect import bisect_left, bisect_right\r\nfrom collections import defaultdict\r\n\r\n\r\ndef summ(n):\r\n return sum(int(i) for i in list(str(n)))\r\n\r\n\r\nfrom math import ceil\r\n\r\n\r\ndef solve():\r\n n = iinp()\r\n word = char()\r\n d = word.count(\"D\")\r\n a = word.count(\"A\")\r\n if a > d:\r\n print(\"Anton\")\r\n elif d > a:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\n\r\n\r\nq = 1\r\nfor _ in range(q):\r\n solve()\r\n", "def w(n, s):\r\n A_win = s.count('A')\r\n D_win = n - A_win\r\n\r\n if A_win > D_win:\r\n return \"Anton\"\r\n elif A_win< D_win:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\nn = int(input())\r\ns = input()\r\nprint(w(n, s))", "y=int(input())\r\nx=input()\r\na=0\r\nd=0\r\nfor i in x:\r\n if i==\"D\":\r\n d=d+1\r\n if i==\"A\":\r\n a=a+1\r\nif a==d:\r\n print(\"Friendship\")\r\nelif a>d:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "#!/bin/env python3\n\nn = int(input())\ns = input()\n\nnum_a = num_d = 0\nfor c in s:\n if c == 'A':\n num_a += 1\n else:\n num_d += 1\n\nif num_a > num_d:\n print(\"Anton\")\nelif num_d > num_a:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n", "n = int(input())\r\nline = input()\r\na = 0\r\nd = 0\r\nfor c in line:\r\n if c=='A':\r\n a+=1\r\n else:\r\n d+=1\r\nif a>d:\r\n print('Anton')\r\nelif d>a:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "#734A:Anton and Danik\r\nn=int(input())\r\ns=input()\r\na=0\r\nd=0\r\nfor char in s:\r\n if char==\"A\":\r\n a+=1\r\n else:\r\n d+=1\r\nif a>d:\r\n print(\"Anton\")\r\nelif a==d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "x=int(input())\r\ny=input()\r\ny1=list(y)\r\na=y1.count('A')\r\nd=y1.count('D')\r\nif a>d:\r\n print('Anton')\r\nelif d>a:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "a=int(input())\r\nlis=list(input())\r\nl1=lis.count(\"A\")\r\nl2=lis.count(\"D\")\r\nif l1>l2:\r\n print(\"Anton\")\r\nelif l2>l1:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\ncounta=0\r\ncountd=0\r\nfor i in range(n):\r\n if s[i]==\"A\":\r\n counta+=1\r\n else:\r\n countd+=1\r\nif (counta>countd):\r\n print(\"Anton\")\r\nelif (countd>counta):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "result = \"\"\r\nn = int(input())\r\ns = input()\r\nif 1 <= n and n <= 100000:\r\n luckyNumbers = \"47\"\r\n count = 0\r\n count2 = 0\r\n for letter in s:\r\n if letter == \"A\":\r\n count += 1\r\n elif letter == \"D\":\r\n count2 += 1\r\n if count > count2:\r\n result = \"Anton\"\r\n elif count2 > count:\r\n result = \"Danik\"\r\n else:\r\n result = \"Friendship\"\r\nprint(f\"{result}\")", "a = int(input())\r\nb = str(input())\r\n\r\ncounterA = 0\r\ncounterD = 0\r\n\r\nfor i in b:\r\n if i == \"A\":\r\n counterA += 1\r\n elif i == \"D\":\r\n counterD += 1\r\nif counterA > counterD:\r\n print(\"Anton\")\r\nelif counterA < counterD:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\na=input()\r\nx=a.count(\"A\")\r\ny=n-x\r\nif x>y:\r\n print(\"Anton\")\r\nelif y>x:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "contest_time=int(input())\r\ncontest=list(input())\r\nAnton=contest.count(\"A\")\r\nif Anton*2 < contest_time:\r\n print(\"Danik\")\r\nelif Anton*2 > contest_time:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\nad = input()\r\n\r\na = 0\r\nd = 0\r\n\r\nfor i in range(n):\r\n # Check if the ith term is A. If yes, add 1 to the a counter\r\n if ad[i] == \"A\":\r\n a += 1\r\n # If it isnt A, it is D. So add 1 to the d counter\r\n else:\r\n d += 1\r\n\r\n# Check if who had more wins or if it was a draw\r\nif a > d:\r\n print(\"Anton\")\r\nelif d > a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "total_games = eval(input())\r\nresults = input()\r\n\r\nif results.count('A') > results.count('D'):\r\n print(\"Anton\")\r\nelif results.count('A') < results.count('D'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "input()\r\na=input()\r\nx=a.count('A')\r\ny=a.count('D')\r\nif x>y:\r\n print(\"Anton\")\r\nelif x<y:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\ntext = input()\nif text.count('D') > text.count('A'):\n print('Danik')\nelif text.count('D') == text.count('A'):\n print('Friendship')\nelse:\n print('Anton')\n", "na=int(input())\r\nsa=input()\r\na1=0\r\na2=0\r\nfor char in sa:\r\n\tif char=='A':\r\n\t\ta1+=1\r\n\telif char=='D':\r\n\t\ta2+=1\r\nif a1>a2:\r\n\tprint(\"Anton\")\r\nelif a2>a1:\r\n\tprint(\"Danik\")\r\nelif a1==a2:\r\n\tprint(\"Friendship\")", "n = int(input())\r\nwin_str = input()\r\nanton_win = 0\r\ndanik_win = 0\r\n\r\nfor i in range(n):\r\n if win_str[i] == 'A':\r\n anton_win += 1 \r\n else: \r\n danik_win += 1 \r\n\r\nif anton_win > danik_win:\r\n print('Anton')\r\nelif anton_win < danik_win:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "a=int(input())\r\nn=input()\r\ncount=0\r\nc=0\r\nfor i in n:\r\n if 'A' in i:\r\n count+=1\r\n else:\r\n c+=1\r\nif count>c:\r\n print('Anton')\r\nelif count<c:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=int(input())\r\ns=list(input())\r\nc=s.count('A')\r\nc1=s.count('D')\r\nif(c>c1):\r\n print(\"Anton\")\r\nelif(c<c1):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\") \r\n", "n=int(input())\r\na=input()\r\nif a.count('A') > a.count('D'):print('Anton')\r\nelif a.count('A') == a.count('D'):print('Friendship')\r\nelse:print('Danik')", "anton = 0\r\ndanik = 0\r\n\r\nn = int(input())\r\nscore = input()\r\n\r\nfor letter in score:\r\n if letter == 'D':\r\n danik += 1\r\n else:\r\n anton += 1\r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif danik > anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def determine_winner(n, s):\r\n anton_wins = s.count('A')\r\n danik_wins = n - anton_wins\r\n \r\n if anton_wins > danik_wins:\r\n return \"Anton\"\r\n elif danik_wins > anton_wins:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\ntry:\r\n n = int(input())\r\n s = input().strip()\r\n if len(s) != n:\r\n raise ValueError(\"Length of input string doesn't match specified value.\")\r\n \r\n result = determine_winner(n, s)\r\n print(result)\r\nexcept ValueError as e:\r\n print(\"Input error:\", e)\r\nexcept Exception as e:\r\n print(\"Error:\", e)\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 26 17:26:38 2023\r\n\r\n@author: ghp\r\n\"\"\"\r\n\r\nn=int(input())\r\nresult=input()\r\nanton=[]\r\ndanik=[]\r\nfor i in range(n):\r\n if result[i]==\"A\":\r\n anton.append(result[i])\r\n else:\r\n danik.append(result[i])\r\nif len(anton)>len(danik):\r\n print('Anton')\r\nelif len(anton)<len(danik):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=int(input())\r\ns=input()\r\nc=s.count(\"A\")\r\nd=s.count(\"D\")\r\nif c>d:\r\n print(\"Anton\")\r\nelif c<d:\r\n print(\"Danik\")\r\nelse:\r\n print( \"Friendship\")\r\n", "a=int(input(\"\"))\r\nb=str(input(\"\"))\r\nanton=0\r\ndanik=0\r\nfor i in b:\r\n if i==\"A\":\r\n anton+=1\r\n elif i==\"D\":\r\n danik+=1\r\nif anton>danik:\r\n print(\"Anton\")\r\nelif danik>anton:\r\n print(\"Danik\") \r\nelif danik== anton:\r\n print(\"Friendship\") ", "n = int(input())\r\ns = input()\r\ncountA = 0\r\ncountD = 0\r\nfor i in s:\r\n if i == \"A\":\r\n countA += 1\r\n if i == \"D\":\r\n countD += 1\r\nif countA > countD:\r\n print(\"Anton\")\r\nif countD > countA:\r\n print(\"Danik\")\r\nif countD == countA:\r\n print(\"Friendship\")", "n = int(input())\r\ns = str(input())\r\n\r\nx = s.count(\"A\")\r\ny = s.count(\"D\")\r\n\r\nif(x>y):\r\n print(\"Anton\")\r\nif(x<y):\r\n print(\"Danik\")\r\nif(x==y):\r\n print(\"Friendship\")\r\n\r\n\r\n", "b= int(input())\r\na = input()\r\nA = 0\r\nD = 0\r\nfor i in a:\r\n if i == \"A\" :\r\n A += 1\r\n else:\r\n D += 1\r\nif A == D:\r\n print(\"Friendship\")\r\nelif A > D:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "x = int(input())\r\nr = input()\r\nif r.count('A') > r.count('D'):\r\n print(\"Anton\")\r\nelif r.count('A') < r.count('D'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = input()\r\ns = input()\r\nx, y = 0, 0\r\nfor i in s:\r\n if i == 'A': x += 1\r\n if i == 'D': y += 1\r\nif x > y:\r\n print('Anton')\r\nelif x < y:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[41]:\n\n\nn=int(input())\ns=input()\nc1=0\nc2=0\nfor i in s:\n if i==\"A\":\n c1+=1\n elif i==\"D\":\n c2+=1\nif c1>c2:\n print(\"Anton\")\nelif c2>c1:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n\n\n \n \n\n\n# \n\n# In[ ]:\n\n\n\n \n\n", "from collections import Counter\n\n\nn, games = int(input()), input()\n\nc = Counter(games)\n\nif c[\"A\"] > c[\"D\"]:\n\tprint(\"Anton\")\nelif c[\"A\"] < c[\"D\"]:\n\tprint(\"Danik\")\nelse:\n\tprint(\"Friendship\")\n", "n = int(input())\nres = input()\na, b = 0, 0\nfor i in res:\n if i == 'D':\n a += 1\n else:\n b += 1\nif a > b:\n print(\"Danik\")\nelif a == b:\n print(\"Friendship\")\nelse:\n print(\"Anton\")", "n = int(input())\r\n\r\nrecord = input()\r\n\r\n\r\nanton_count = sum(1 for char in record if char == 'A')\r\ndanik_count = sum(1 for char in record if char == 'D')\r\n\r\nif anton_count > danik_count:\r\n print(\"Anton\")\r\nelif danik_count > anton_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def find_winner(s):\r\n anton_count = s.count('A')\r\n danik_count = len(s) - anton_count\r\n \r\n if anton_count > danik_count:\r\n return \"Anton\"\r\n elif anton_count < danik_count:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n\r\nn = int(input())\r\ns = input()\r\n\r\nwinner = find_winner(s)\r\nprint(winner)\r\n", "# Read the number of games played\r\nn = int(input())\r\n\r\n# Read the outcomes of the games as a string\r\noutcomes = input()\r\n\r\n# Count the number of times 'A' and 'D' appear in the string\r\nanton_wins = outcomes.count('A')\r\ndanik_wins = n - anton_wins # Total games minus Anton's wins\r\n\r\n# Determine the winner based on the counts\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins < danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "t=int(input())\r\nn=input().strip()\r\na_count=n.count('A')\r\nd_count=t- a_count\r\nif d_count>a_count:\r\n print(\"Danik\")\r\nelif d_count<a_count:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "def main():\r\n n = int(input())\r\n s = input()\r\n\r\n countA = s.count('A')\r\n countD = s.count('D')\r\n\r\n if countA > countD:\r\n print(\"Anton\")\r\n elif countA < countD:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "x=int(input())\r\ng=input()\r\nA_counter=0\r\nD_counnter =0\r\nfor i in g :\r\n if i=='A':\r\n A_counter+=1\r\n elif i =='D':\r\n D_counnter+=1\r\nif A_counter>D_counnter:\r\n print (\"Anton\")\r\nelif A_counter<D_counnter:\r\n print (\"Danik\")\r\nelif A_counter==D_counnter:\r\n print (\"Friendship\")", "\nn = int(input())\nassert 1<=n<=100000\n\ns = list(input())\n\nanton = s.count('A')\ndanik = s.count('D')\n\nif anton!=danik:\n print('Anton') if anton>danik else print('Danik')\nelse:\n print('Friendship')\n\n", "n=int(input())\r\ns=input()\r\ncountD=0\r\ncountA=0\r\nif(n==len(s)):\r\n for i in range(0,len(s)):\r\n if(s[i]==\"D\"):\r\n countD=countD+1\r\n else:\r\n countA=countA+1\r\nif(countD>countA):\r\n print(\"Danik\")\r\nelif(countD<countA):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\n\r\ns = input()\r\n\r\nA = 0\r\nD = 0\r\n\r\nfor i in s:\r\n if i == \"A\":\r\n A += 1\r\n elif i == \"D\":\r\n D += 1\r\n \r\nif A > D:\r\n print(\"Anton\")\r\nelif D > A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "size = int(input())\r\ntxt = input()\r\nanton = txt.count(\"A\")\r\ndanik = txt.count(\"D\") \r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif anton < danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ncount = input().count(\"A\")\r\nprint(\"Anton\" if count > n/2 else \"Friendship\" if count == n/2 else \"Danik\")\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sat Sep 16 22:52:57 2023\r\n\r\n@author: He'Bing'Ru\r\n\"\"\"\r\n\r\nn = int(input())\r\na = d = 0\r\nrst = list(input())\r\nfor i in rst :\r\n if i == 'A' :\r\n a += 1\r\n if i == 'D' :\r\n d += 1\r\nif a>d :\r\n print('Anton')\r\nelif a<d :\r\n print('Danik')\r\nelif a == d :\r\n print('Friendship')", "n = int(input())\r\na = input()\r\n\r\ncount_d, count_a = 0,0\r\n\r\nfor i in range(n):\r\n if a[i] == 'A':\r\n count_a += 1\r\n if a[i] == 'D' :\r\n count_d += 1\r\n\r\nif count_d > count_a:\r\n print(\"Danik\")\r\nelif count_d < count_a:\r\n print(\"Anton\")\r\nelse :\r\n print(\"Friendship\")", "n = int(input())\nc = input()\na = 0\nd = 0\nfor i in range(n):\n \n if c[i] == 'A':\n a += 1\n else:\n d += 1\nif a > d:\n print('Anton')\nelif a < d:\n print('Danik')\nelse:\n print('Friendship')", "n= int(input())\r\ns= input()\r\nx=0\r\ny=0\r\nfor i in s:\r\n if i=='A':\r\n x+=1\r\n else:\r\n y+=1\r\nif x==y:\r\n print(\"Friendship\")\r\nelif x>y:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\n\r\nanton = s.count('A')\r\ndanik = n - anton\r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif danik > anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "_ = int(input())\r\nwl = list(input())\r\nif wl.count('A') > wl.count('D'):\r\n print('Anton')\r\nelif wl.count('D') > wl.count('A'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n ", "a=int(input())\r\nb=input()\r\nk=0\r\nm=0\r\nfor i in range(a):\r\n if b[i]==\"A\":\r\n k+=1\r\n elif b[i]==\"D\":\r\n m+=1\r\nif k>m:\r\n print('Anton')\r\nelif k<m:\r\n print('Danik')\r\nelif k==m:\r\n print(\"Friendship\")\r\n", "# Read the number of games played\r\nn = int(input())\r\n\r\n# Read the outcome of each game as a string\r\noutcomes = input()\r\n\r\n# Count the number of 'A's (Anton's wins) and 'D's (Danik's wins)\r\nanton_wins = outcomes.count('A')\r\ndanik_wins = outcomes.count('D')\r\n\r\n# Compare the counts to determine the winner\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins < danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\ns=input()\r\nanton_count=s.count('A')\r\ndanik_count=n-anton_count\r\nif anton_count>danik_count:\r\n print(\"Anton\")\r\nelif anton_count<danik_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nant=0\r\ndan=0\r\nfor i in s:\r\n if(i==\"A\"):\r\n ant = ant + 1\r\n if(i==\"D\"):\r\n dan = dan + 1\r\nif(ant>dan):\r\n print(\"Anton\")\r\nelif(dan>ant):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\na = 0\r\n\r\nchar = input()\r\n\r\nfor i in range(n):\r\n result = char[i] \r\n if result == 'A':\r\n a += 1\r\n\r\nif a > n/2:\r\n print(\"Anton\")\r\nelif a == n/2:\r\n print(\"Friendship\")\r\nelse: \r\n print(\"Danik\")", "a = int(input())\r\nb = str(input())\r\nd = 0\r\na = 0\r\nfor i in range(len(b)):\r\n if b[i] == 'D':\r\n d += 1\r\n else:\r\n a += 1\r\n\r\nif a == d:\r\n print('Friendship')\r\nelif a > d:\r\n print('Anton')\r\nelse:\r\n print('Danik')\r\n \r\n", "n=int(input())\r\ns=input()\r\nca,cd=0,0\r\nfor i in s:\r\n if i=='A':\r\n ca=ca+1\r\n elif i=='D':\r\n cd=cd+1\r\nif ca>cd:\r\n print(\"Anton\")\r\nelif cd>ca:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "x=input()\r\na=input()\r\nanton=0\r\ndanik=0\r\nfor i in a:\r\n if i==\"A\":\r\n anton+=1\r\n else:\r\n danik+=1\r\nif anton>danik:\r\n print(\"Anton\")\r\nelif danik>anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input()) \r\ns = input() \r\ncA = s.count('A') \r\ncD = len(s) - cA \r\n\r\nif cA > cD:\r\n print(\"Anton\")\r\nelif cA < cD:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "n = int(input())\r\ns = input()\r\n\r\na_count = s.count(\"A\")\r\nd_count = s.count(\"D\")\r\n\r\nif a_count > d_count:\r\n\tprint(\"Anton\")\r\nelif d_count > a_count:\r\n\tprint(\"Danik\")\r\nelse:\r\n\tprint(\"Friendship\")", "n = int(input())\r\ns = input(\"\")\r\ncounter_anton = 0\r\ncounter_danik = 0\r\n\r\nfor letter in s:\r\n if letter == \"A\":\r\n counter_anton += 1\r\n else:\r\n counter_danik += 1\r\n \r\nif counter_danik < counter_anton:\r\n print(\"Anton\")\r\nelif counter_danik > counter_anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n ", "# 734A - Anton or Danik\r\n# https://codeforces.com/problemset/problem/734/A\r\n\r\n# Input:\r\n# 1) Número de partidas de ajedrez jugadas\r\n# 2) Quién ganó cada partida\r\npartidas = int(input())\r\nvictorias = input()\r\n\r\nvictorias_anton = 0\r\nvictorias_danik = 0\r\n\r\nfor partida in victorias:\r\n if partida == 'A':\r\n victorias_anton += 1\r\n if partida == 'D':\r\n victorias_danik += 1\r\n\r\nif victorias_anton > victorias_danik:\r\n print('Anton')\r\nelif victorias_anton < victorias_danik:\r\n print('Danik')\r\nelif victorias_anton == victorias_danik:\r\n print('Friendship')\r\n\r\n\r\n", "x = int(input())\r\ni = input()\r\n\r\nnum_a = num_b = 0\r\nfor c in i:\r\n if c == 'A':\r\n num_a += 1\r\n else:\r\n num_b += 1\r\n\r\nif num_a > num_b:\r\n print(\"Anton\")\r\nelif num_b > num_a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "a = int(input())\r\nb = input()\r\n\r\nif b.count(\"A\") > b.count(\"D\"):\r\n print(\"Anton\")\r\nelif b.count(\"A\") < b.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print (\"Friendship\")\r\n", "def solve(a, b):\r\n for i in b:\r\n a = a - (i == \"A\")*2\r\n\r\n if a > 0:\r\n return \"Danik\"\r\n if a < 0:\r\n return \"Anton\"\r\n return \"Friendship\"\r\n\r\na = int(input())\r\nb = list(input())\r\n\r\nprint(solve(a, b))", "x = int(input())\r\ny = input().upper()\r\nAnt = []\r\nDan = []\r\n\r\nif x == len(y):\r\n for i in range(x):\r\n if y[i] == 'A':\r\n Ant.append(y[i])\r\n elif y[i] == 'D':\r\n Dan.append(y[i])\r\n\r\nif len(Ant) > len(Dan):\r\n print('Anton')\r\nelif len(Dan) > len(Ant):\r\n print('Danik')\r\nelif len(Ant) == len(Dan):\r\n print('Friendship')", "n = int(input())\r\na = input()\r\ncount_A = a.count(\"A\")\r\ncount_D = a.count(\"D\")\r\nif count_D == count_A:\r\n print('Friendship')\r\nelif count_D > count_A:\r\n print('Danik')\r\nelse:\r\n print('Anton')", "number=int(input())\r\nwinners=input().upper()\r\na=0\r\nd=0\r\nfor i in winners:\r\n if i=='A':\r\n a+=1\r\n else:\r\n d+=1\r\nif a>d : print(\"Anton\")\r\nelif d>a:print(\"Danik\")\r\nelse : print(\"Friendship\")", "# Reading input\r\nn = int(input())\r\noutcomes = input()\r\n\r\n# Counting the number of 'A's and 'D's\r\nanton_count = outcomes.count('A')\r\ndanik_count = outcomes.count('D')\r\n\r\n# Comparing the counts to determine the winner\r\nif anton_count > danik_count:\r\n print(\"Anton\")\r\nelif anton_count < danik_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=input()\nn=int(n)\nwin=input()\ndanik=0\nanton=0\nfor i in range(n):\n if win[i]==\"D\":\n danik=danik+1\n else:\n anton=anton+1\nif anton==danik:\n print(\"Friendship\")\nelif anton>danik:\n print(\"Anton\")\nelse:\n print(\"Danik\")\n\t \t\t \t \t \t \t \t\t \t\t \t\t \t", "n = int(input())\r\ns = input()\r\nka = s.count(\"A\")\r\nkd = s.count(\"D\")\r\nif ka > kd:\r\n print(\"Anton\")\r\nelif kd > ka:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "import re\r\n\r\ngames = int(input())\r\n\r\nresult = input()\r\n\r\nA = len(re.findall(\"A\", result))\r\nD = len(re.findall(\"D\", result))\r\n\r\nif A > D:\r\n print(\"Anton\")\r\nelif D > A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = input()\r\ns = str(input())\r\ncnt1 = 0\r\ncnt2 = 0\r\nfor i in range(len(s)):\r\n if(s[i] == 'D'):\r\n cnt1+=1\r\n elif(s[i] == 'A'):\r\n cnt2+=1\r\nif(cnt1>cnt2):\r\n print(\"Danik\")\r\nelif(cnt2>cnt1):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "a=input()\r\noutcome=input()\r\nn=0\r\nfor i in outcome:\r\n if i==\"A\":\r\n n+=1\r\nm=int(a)\r\nif n>m-n:\r\n print('Anton')\r\nelif n==m-n:\r\n print('Friendship')\r\nelse:\r\n print('Danik')\r\n", "n=int(input())\r\ns=input()\r\na=''\r\nd=''\r\nfor i in s:\r\n if i=='A':\r\n a=a+i\r\n elif i=='D':\r\n d=d+i\r\nal=len(a)\r\ndl=len(d)\r\nif al>dl:\r\n print(\"Anton\")\r\nelif dl>al:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nAnton = s.count('A')\r\nDanik = s.count('D')\r\nif Anton > Danik:\r\n print(\"Anton\")\r\nelif Anton < Danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\n\r\ncount_Anton_wins = s.count(\"A\")\r\ncount_Danik_wins = n - count_Anton_wins\r\n\r\nif count_Anton_wins > count_Danik_wins:\r\n print(\"Anton\")\r\nelif count_Danik_wins > count_Anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\ncount1 = 0\r\ncount2 = 0\r\nfor i in range(n):\r\n if s[i] == \"A\":\r\n count1 = count1+1\r\n else:\r\n count2 = count2 +1\r\nif count1 > count2:\r\n print(\"Anton\")\r\nelif count1<count2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "#=========NEVER GIVE UP=============\r\n#======ALLAH ALMIGHT WILL HELP========\r\n#==================YOU==============''\r\n\r\n\r\nh = int(input())\r\np = list(input())\r\n\r\na = p.count(\"A\")\r\nd = p.count(\"D\")\r\n\r\nif a>d:\r\n print(\"Anton\")\r\nelif d>a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "from collections import Counter\r\n\r\nclass Solution():\r\n\tdef solve(self, string: str) -> str:\r\n\t\tcounter = Counter(string)\r\n\t\tans = 'Friendship'\r\n\t\tif counter['A'] > counter['D']:\r\n\t\t\tans = 'Anton'\r\n\t\telif counter['A'] < counter['D']:\r\n\t\t\tans = 'Danik'\r\n\t\treturn ans\r\n\r\n\r\nclass Driver():\r\n\tdef __init__(self):\r\n\t\tself._solver = Solution()\r\n\r\n\tdef drive(self):\r\n\t\tlength = int(input().strip())\r\n\t\tstring = input().strip()\r\n\t\tans = self._solver.solve(string)\r\n\t\tprint(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tDriver().drive()\r\n\r\n", "n = int(input())\r\ncd=0\r\nca=0\r\na = input()\r\nfor i in range(0,n):\r\n if a[i] =='D':\r\n cd+=1\r\n else:\r\n ca+=1\r\nif cd>ca:\r\n print('Danik')\r\nelif cd<ca:\r\n print('Anton')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = input()\r\ncounta = 0\r\ncountd = 0\r\nfor i in range(n):\r\n if s[i] == \"A\":\r\n counta += 1\r\n else:\r\n countd += 1\r\nif counta > countd:\r\n print(\"Anton\")\r\nelif counta < countd:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "total_a = 0\r\ntotal_d = 0\r\nn = int(input())\r\nfor i in input():\r\n if i == 'A':\r\n total_a += 1\r\n else:\r\n total_d += 1\r\nif total_a == total_d:\r\n print('Friendship')\r\nelif total_d > total_a:\r\n print('Danik')\r\nelse:\r\n print('Anton')", "def anton_and_danik():\r\n\tn = int(input())\r\n\tgame = input()\r\n\tcount_A = 0\r\n\tfor letter in game:\r\n\t\tif letter == 'A':\r\n\t\t\tcount_A += 1\r\n\tcount_D = n - count_A\r\n\tif count_A < count_D:\r\n\t\treturn 'Danik'\r\n\telif count_A > count_D:\r\n\t\treturn 'Anton'\r\n\telse:\r\n\t\treturn 'Friendship'\r\n\t\r\nprint(anton_and_danik())", "def lucky(s):\r\n a=0\r\n d=0\r\n for i in s:\r\n if i=='A':\r\n a+=1\r\n else:\r\n d+=1\r\n if a>d:return 'Anton'\r\n elif a<d:return 'Danik'\r\n return 'Friendship'\r\n pass\r\nn=int(input())\r\nprint(lucky(input()))", "# Input the number of games\r\nn = int(input())\r\n\r\n# Input the outcomes of the games\r\ns = input()\r\n\r\n# Count the number of wins for Anton and Danik\r\nanton_wins = s.count('A')\r\ndanik_wins = s.count('D')\r\n\r\n# Determine the winner and print the result\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins < danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "m = input()\r\nl = input()\r\ncount = 0\r\nfor i in l:\r\n if i == \"A\":\r\n count += 1\r\n else:\r\n count -= 1\r\nif count == 0:\r\n print(\"Friendship\")\r\nelif count > 0:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\ns = input()\ncntDanik = cntAnton = 0\nfor i in range(n):\n if s[i] == 'D':\n cntDanik += 1\n else:\n cntAnton += 1\n\nif cntAnton == cntDanik:\n print(\"Friendship\")\nelse:\n if cntAnton > cntDanik:\n print(\"Anton\")\n else:\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\n\r\nc = s.count('A')\r\n\r\nif c == n-c:\r\n print('Friendship')\r\nelif c > n-c:\r\n print('Anton')\r\nelse:\r\n print('Danik')\r\n\r\n", "n=int(input())\r\ns=input()\r\nc=0\r\nk=0\r\nfor i in range(len(s)):\r\n if s[i]=='A':\r\n c+=1\r\n elif s[i]=='D':\r\n k+=1\r\nif c>k:\r\n print('Anton')\r\nelif k>c:\r\n print('Danik')\r\nelif c==k:\r\n print('Friendship')", "# Read the number of games (not used in the solution, but necessary to read)\r\nn = int(input().strip())\r\n\r\n# Read the outcomes of the games\r\ns = input().strip()\r\n\r\n# Count the wins for Anton and Danik\r\nanton_wins = s.count('A')\r\ndanik_wins = s.count('D')\r\n\r\n# Determine and output the result\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "k=int(input())\r\nbb=input()\r\nd=0\r\na=0\r\nf=0\r\nfor b in bb:\r\n if b=='D':\r\n d+=1\r\n elif b=='A':\r\n a+=1\r\nif a==d:\r\n print('Friendship')\r\nelif a>d:\r\n print('Anton')\r\nelse:\r\n print('Danik')", "n = int(input())\r\ns = input()\r\nd, a = 0, 0\r\n\r\nfor c in s:\r\n if c == 'D':\r\n d += 1\r\n if c == 'A':\r\n a += 1\r\n\r\nif d > a:\r\n print('Danik')\r\nelif d == a:\r\n print('Friendship')\r\nelif d < a:\r\n print('Anton')", "n=input()\r\ns=input()\r\ncount=0\r\ncount1=0\r\nlist=[]\r\nfor i in s:\r\n list.append(i)\r\nfor j in list:\r\n if ord(j)==ord('A'):\r\n count+=1\r\n else:\r\n count1+=1\r\nif count>count1:\r\n print(\"Anton\")\r\nelif count<count1:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "n=int(input())\r\ns=input()\r\ncount1=s.count('A')\r\ncount2=s.count('D')\r\nif count1>count2:\r\n print(\"Anton\")\r\nelif count1<count2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def main():\n n = int(input())\n s = input()\n\n anton = 0\n danik = 0\n \n for item in s:\n if(item=='A'):\n anton+=1\n elif(item=='D'):\n danik+=1\n\n if(anton>danik):\n print(\"Anton\")\n elif(danik>anton):\n print(\"Danik\")\n else:\n print(\"Friendship\") \n \n\nmain()\n", "n=int(input())\r\ns=input()\r\nac=0\r\ndc=0\r\nfor i in s:\r\n if i=='A':\r\n ac+=1\r\n else:\r\n dc+=1\r\nif ac==dc:\r\n print(\"Friendship\")\r\nelif ac>dc:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\ndcount=0\r\nacount=0\r\nfor i in s:\r\n if(i==\"D\"):\r\n dcount = dcount+1\r\n if(i==\"A\"):\r\n acount = acount+1\r\nif(acount>dcount):\r\n print(\"Anton\")\r\nif(acount<dcount):\r\n print(\"Danik\")\r\nif(acount==dcount):\r\n print(\"Friendship\")", "game_num = int(input())\r\noutcome = input()\r\nanton, danik = outcome.count(\"A\"), outcome.count(\"D\")\r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif danik > anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\nc1=s.count('A')\r\nc2=s.count('D')\r\nif c1>c2:\r\n print(\"Anton\")\r\nelif c1<c2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "def main():\r\n n=int(input())\r\n s=input()\r\n d=0\r\n a=0\r\n for i in range(n):\r\n c=s[i]\r\n if c=='D':\r\n d+=1\r\n elif c=='A':\r\n a+=1\r\n if d>a:\r\n print('Danik')\r\n elif d<a:\r\n print('Anton')\r\n else:\r\n print('Friendship')\r\nmain()", "b=int(input())-input().count('A')*2;print([['Friendship','Danik'][b>0],'Anton'][b<0])\r\n#hi codeforces\r\n#", "num_gam = input()\r\ngam_res = input()\r\na = gam_res.count(\"A\")\r\nd = gam_res.count(\"D\")\r\nif a>d:\r\n print(\"Anton\")\r\nelif a==d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "def winner():\r\n n = int(input().strip())\r\n letters = input().strip()\r\n Anton_count = letters.count('A')\r\n Dan_count = letters.count('D')\r\n if Anton_count > Dan_count:\r\n print(\"Anton\")\r\n elif Anton_count < Dan_count:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\n\r\nwinner()", "n = int(input())\ns = input()\n\ncount_a = s.count('A')\ncount_d = n - count_a\n\nif count_a > count_d:\n print(\"Anton\")\nelif count_d > count_a:\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "n = int(input())\r\nx = input()\r\na,d=x.count('A'),x.count('D')\r\nif a>d:\r\n print('Anton')\r\nelif a<d:\r\n print('Danik')\r\nelif a==d:\r\n print('Friendship')\r\n\r\n", "n = int(input())\ns = input()\n\nmid = n // 2\na = 0\nd = 0\nfor c in s:\n if c == 'A':\n a += 1\n else:\n d += 1\n\nif a > mid:\n print('Anton')\nelif d > mid:\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\n\r\nanton_count = s.count('A') # Count of 'A's\r\ndanik_count = n - anton_count # Count of 'D's\r\n\r\nif anton_count > danik_count:\r\n print(\"Anton\")\r\nelif danik_count > anton_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "a=int(input(''))\r\nb=str(input(''))\r\nc=0\r\nd=0\r\nfor i in b:\r\n if i==\"A\":\r\n c=c+1\r\n else:\r\n d=d+1\r\nif (c==d):\r\n print(\"Friendship\")\r\nelif (c>=d):\r\n print('Anton')\r\nelse:\r\n print('Danik')\r\n ", "t=int(input())\r\nn=input()\r\na=0\r\nh=0\r\nfor i in range(t):\r\n if n[i]=='A':\r\n a+=1 \r\n else:\r\n h+=1 \r\nif a>h:\r\n print(\"Anton\")\r\nelif h>a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n,a,d = int(input()),0,0\nstring = input()\nfor i in string:\n if i == \"A\": a += 1\n else: d += 1\nif a > d: print(\"Anton\")\nelif a < d: print(\"Danik\")\nelse: print(\"Friendship\")", "g=int(input())\r\ns=input()\r\n\r\nc=0\r\nfor i in range(g):\r\n if s[i]=='A':\r\n c+=1\r\n else:\r\n c-=1\r\n\r\nif c==0:\r\n print('Friendship')\r\nelif c>0:\r\n print('Anton')\r\nelse:\r\n print('Danik')", "n=int(input())\r\ns=input()\r\nx=0\r\nf=0\r\nfor i in s:\r\n if i==\"A\":\r\n x+=1\r\n elif i==\"D\":\r\n f+=1\r\nif x>f:\r\n print(\"Anton\")\r\nelif x<f:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "from collections import Counter\r\n\r\n\r\nn = int(input())\r\ns = input()\r\nc = Counter(s)\r\nif c[\"A\"] > c[\"D\"]:\r\n print(\"Anton\")\r\nelif c[\"A\"] < c[\"D\"]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "games = int(input())\r\nwinner = input()\r\n\r\nif winner.count('A') > winner.count('D'):\r\n print('Anton')\r\nelif winner.count('A') < winner.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "a=int(input())\r\nb=input()\r\nd=b.count('D')\r\nk=b.count('A')\r\nif d<k:\r\n print('Anton')\r\nelif d>k:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=int(input())\r\ns=str(input())[:n]\r\na=s.count(\"A\")\r\nd=s.count(\"D\")\r\nif a>d:\r\n print(\"Anton\")\r\nelif a<d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def determine_winner(n, s):\r\n anton_count = s.count('A')\r\n danik_count = s.count('D')\r\n\r\n if anton_count > danik_count:\r\n return \"Anton\"\r\n elif anton_count < danik_count:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n# Read the input\r\nn = int(input())\r\ns = input()\r\n\r\n# Call the function and print the result\r\nresult = determine_winner(n, s)\r\nprint(result)\r\n", "n=int(input())\r\ns=input()\r\nc=0\r\na=0\r\nfor i in range(n):\r\n if(s[i]=='A'):\r\n c=c+1\r\n else:\r\n a=a+1\r\nif(c==a):\r\n print(\"Friendship\")\r\nelif(c>a):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")\r\n", "a = int(input(\"\"))\r\nA = 0\r\nD = 0\r\no = input(\"\")\r\nfor i in o:\r\n if i ==\"A\":\r\n A = A+1\r\n else:\r\n D = D + 1\r\n\r\nif(A == D):\r\n print(\"Friendship\")\r\nelif( A>D):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "a=int(input())\r\nb=input()\r\nac=0\r\ndc=0\r\nfor i in b:\r\n if i == 'A':\r\n ac+=1\r\n if i == 'D':\r\n dc+=1\r\nif ac>dc:\r\n print('Anton')\r\nelif ac<dc:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = input()\r\nA = 0\r\nD = 0\r\nresult = ''\r\nfor i in range(n):\r\n if s[i] == 'A':\r\n A = A + 1\r\n elif s[i] == 'D':\r\n D = D + 1\r\nif A < D :\r\n result = 'Danik'\r\nelif A > D:\r\n result = 'Anton'\r\nelse:\r\n result = 'Friendship'\r\nprint(result)", "n = int(input())\r\nx = input()\r\nca = 0\r\ncd = 0\r\nfor c in x:\r\n if c == 'A':\r\n ca += 1\r\n else:\r\n cd += 1\r\n\r\nif ca > cd:\r\n print('Anton')\r\nelif ca < cd:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "#\r\nn=int(input())\r\ns=input()\r\nprint(\"Anton\" if s.count('A')>n/2 else(\"Danik\" if s.count('D') > n/2 else \"Friendship\"))\r\n#", "g= int(input())\r\np=input()\r\nA,D= 0,0\r\nfor i in p:\r\n if i ==\"A\":\r\n A+=1\r\n else:\r\n D+=1\r\nif A>D :\r\n print(\"Anton\")\r\nelif D>A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n ", "a = int(input())\r\nsq = [j for j in input().split()]\r\nq = 0\r\nv = 0\r\nfor i in range(a):\r\n if sq[0][i] == 'A':\r\n q += 1\r\n elif sq[0][i] == 'D':\r\n v += 1\r\nif q > v:\r\n print('Anton')\r\nif v > q:\r\n print('Danik')\r\nif v == q:\r\n print('Friendship')\r\n", "n = input()\r\ns = input()\r\ncntA = s.count(\"A\")\r\ncntD = s.count(\"D\")\r\nif (cntA > cntD):\r\n print(\"Anton\")\r\nif (cntA < cntD):\r\n print(\"Danik\")\r\nif (cntA == cntD):\r\n print(\"Friendship\")", "n = int(input())\ns = input()\n\ncounta = 0\n\nfor c in s:\n\tif c == \"A\":\n\t\tcounta = counta + 1\n\telse:\n\t\tcounta = counta - 1\n\nif counta > 0:\n\tprint(\"Anton\")\nelif counta < 0:\n\tprint(\"Danik\")\nelse:\n\tprint(\"Friendship\")", "n=int(input())\r\ns=input()\r\nif s.count('A')>s.count('D'):\r\n print(\"Anton\")\r\nelif s.count('A')<s.count('D'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "# Input the number of games and the outcomes\r\nn = int(input())\r\ns = input()\r\n\r\n# Count the number of 'A's and 'D's\r\ncount_A = s.count('A')\r\ncount_D = s.count('D')\r\n\r\n# Compare the counts to determine the winner\r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_A < count_D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "aiwi = input()\r\ngames = str(input())\r\nA = games.count('D')\r\nD = games.count('A')\r\nif A > D:\r\n print(\"Danik\")\r\nelif D > A:\r\n print(\"Anton\")\r\nelse:print(\"Friendship\")\r\n", "n = int(input()) \r\n\r\ngiven = input() \r\n \r\nanton = 0; \r\ndanik = 0;\r\nfor i in range(0,len(given)):\r\n if(given[i]=='A'):\r\n anton+=1\r\n else:\r\n danik+=1\r\n\r\nif(anton>danik):\r\n print(\"Anton\") \r\nelif(danik>anton):\r\n print(\"Danik\") \r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ng = input()\r\nA = 0\r\nfor i in g:\r\n\tif i == \"A\":\r\n\t\tA += 1\r\nif A > n-A:\r\n\tprint(\"Anton\")\r\nelif n-A > A: \r\n\tprint(\"Danik\")\r\nelse:\r\n\tprint(\"Friendship\")", "n = int(input())\r\nwin_string = input()\r\n\r\nd_count = win_string.count(\"D\")\r\na_count = win_string.count(\"A\")\r\n\r\nif a_count > d_count:\r\n print(\"Anton\")\r\nelif a_count < d_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\n\r\ncount_antons_wins = s.count('A')\r\ncount_daniks_wins = n - count_antons_wins # Total games minus Anton's wins\r\n\r\nif count_antons_wins > count_daniks_wins:\r\n print(\"Anton\")\r\nelif count_daniks_wins > count_antons_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\ns=input()\r\nn1=0\r\nn2=0\r\nfor i in s:\r\n if i=='A':\r\n n1+=1\r\n else:\r\n n2+=1\r\nif(n1>n2):\r\n print('Anton')\r\nelif(n2>n1):\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "games = int(input())\r\nresult = input()\r\ncount_A = result.count('A')\r\nif count_A > len(result)/2:\r\n print(\"Anton\")\r\nelif count_A < len(result)/2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "rounds = int(input())\r\nwins = input()\r\nAnton = 0\r\nDanik = 0\r\n\r\nfor a in range(rounds):\r\n if wins[a] == 'A':\r\n Anton += 1\r\n else:\r\n Danik += 1\r\n\r\nif Danik > Anton:\r\n print('Danik')\r\nelif Danik == Anton:\r\n print('Friendship')\r\nelse:\r\n print('Anton')", "from collections import Counter\r\n\r\n\r\nn = int(input())\r\nparts = input()\r\n\r\ncnt = Counter(parts)\r\n\r\nif cnt[\"A\"] > cnt[\"D\"]:\r\n print(\"Anton\")\r\nelif cnt[\"D\"] > cnt[\"A\"]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "number_of_game = int(input())\r\nlitters = input().upper()\r\ncount_A=0\r\ncount_B=0\r\nfor i in range (0, number_of_game):\r\n if litters[i] == 'A':\r\n count_A += 1\r\n else:\r\n count_B+=1\r\n\r\n\r\nif count_A>count_B:\r\n print(\"Anton\")\r\nelif count_B>count_A:\r\n print(\"Danik\")\r\nelif count_B==count_A:\r\n print(\"Friendship\") \r\n", "n = int(input())\r\nwa = 0\r\nwd = 0\r\nwin = input().upper()\r\nfor x in win:\r\n if x == 'A':\r\n wa += 1\r\n elif x == 'D':\r\n wd += 1\r\nif wa > wd:\r\n print('Anton')\r\nelif wd > wa:\r\n print('Danik')\r\nelif wa == wd:\r\n print('Friendship')", "def solve():\r\n x = int(input())\r\n s = input()\r\n print('Anton' if s.count('A') > s.count('D') else 'Danik' if s.count('A') < s.count('D') else 'Friendship')\r\n\r\n\r\n# t = int(input())\r\nt = 1\r\nwhile t:\r\n solve()\r\n t -= 1\r\n", "n=int(input())\r\ns=input()\r\nc=0\r\nfor i in s:\r\n if 'A'==i:\r\n c=c+1\r\nif c==n/2:\r\n print(\"Friendship\")\r\nelif (len(s)/2)<c:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")\r\n \r\n \r\n ", "a=int(input())\r\nba=str(input())\r\nc=ba.count(\"A\")\r\nd=ba.count(\"D\")\r\nif c>d:\r\n print(\"Anton\")\r\nelif d>c:\r\n print(\"Danik\")\r\nelif d==c:\r\n print(\"Friendship\")", "n = int(input())\r\nst = input()\r\nm = 2 * st.count('A')\r\nif m > n:\r\n print('Anton')\r\nelif m < n:\r\n print('Danik')\r\nelif m == n:\r\n print('Friendship')", "n = input()\r\na = input(\"\")\r\ncount1 = a.count('A')\r\ncount2 = a.count('D')\r\nif count1 == count2:\r\n print(\"Friendship\")\r\nelif count1 > count2:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "B=int(input())\r\na=input()\r\ndanik=0\r\nanton=0\r\nfor i in range(len(a)):\r\n if a[i]=='D':\r\n danik=danik+1\r\n elif a[i]=='A':\r\n anton=anton+1\r\nif danik>anton:\r\n print('Danik')\r\nelif anton>danik:\r\n print('Anton')\r\nelse:\r\n print('Friendship')\r\n\r\n\r\n\r\n", "A = 0\r\nD = 0\r\ninput()\r\nfor i in input():\r\n if i == 'A':\r\n A += 1\r\n else:\r\n D += 1\r\nprint('Anton' if A > D else 'Danik' if D > A else 'Friendship')\r\n", "'''\r\n==TEST CASE==\r\nInput:\r\n3\r\nRRG\r\n\r\nOutput:\r\n1\r\n'''\r\nn=int(input())\r\ns=str(input())\r\n\r\nif(s.count(\"A\") > s.count(\"D\")):\r\n print(\"Anton\")\r\nelif(s.count(\"D\") > s.count(\"A\")):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\") ", "a = int(input())\r\ns = input()\r\nb = [i for i in s if i == 'A']\r\nc = [j for j in s if j == 'D']\r\nif len(b) > len(c):\r\n print(\"Anton\")\r\nelif len(b) < len(c):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input().strip())\r\nresults = input().strip()\r\ncount_antons_wins = results.count('A')\r\ncount_daniks_wins = results.count('D')\r\nif count_antons_wins > count_daniks_wins:\r\n print(\"Anton\")\r\nelif count_daniks_wins > count_antons_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "number_won = int(input())\r\ngames = input()\r\n\r\nwins = {}\r\nif len(games) == 1:\r\n print(\"Anton\" if games == \"A\" else \"Danik\") \r\n exit()\r\nfor i in range(len(games)):\r\n if games[i] == \"A\":\r\n wins[\"A\"] = wins.get(\"A\",0) + 1\r\n else:\r\n wins[\"D\"] = wins.get(\"D\",0) + 1\r\n\r\nif \"D\" not in wins:\r\n print(\"Anton\")\r\nelif \"A\" not in wins:\r\n print(\"Danik\")\r\nelif wins[\"A\"] > wins[\"D\"]:\r\n print(\"Anton\")\r\nelif wins[\"A\"] < wins[\"D\"]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "n=input()\np=input()\n\ncntD=0\ncntA=0\n\nfor i in p:\n if i==\"D\":\n cntD+=1\n else:\n cntA+=1\n\nif cntA>cntD:\n print(\"Anton\")\nelif cntD>cntA:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n \t \t \t\t\t \t \t\t \t\t\t \t", "n = int(input())\r\na = input()\r\ncount = 2*(a.count('A'))\r\nprint('Friendship' if n == count else ['Anton','Danik'][n>count])", "q=int(input())\r\nw=input()\r\nu=0\r\ns=0\r\nfor char in w:\r\n if char=='A':\r\n u+=1\r\n elif char=='D':\r\n s+=1\r\nif u>s:\r\n print(\"Anton\")\r\nelif s>u:\r\n print(\"Danik\")\r\nelif u==s:\r\n print(\"Friendship\")", "n = input()\r\nres = input()\r\na = res.count('A')\r\nd = res.count('D')\r\nif a>d: print('Anton')\r\nelif a<d: print('Danik')\r\nelse: print('Friendship')", "n=input()\r\nr=input()\r\na=r.count('A')\r\nd=r.count('D')\r\nif a>d:\r\n print('Anton')\r\nelif a<d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "t = int(input())\r\nx = input()\r\nc =0\r\nd = 0\r\nfor i in x:\r\n if i ==\"A\":\r\n c+=1\r\n else:\r\n d+=1\r\nif c>d:\r\n print(\"Anton\")\r\nelif d>c:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def anton_danik():\r\n number_of_match = int(input())\r\n results = input()\r\n win_counter = {'A':0, 'D':0}\r\n for result in results:\r\n win_counter[result] += 1\r\n if win_counter['A'] == win_counter['D']:\r\n return \"Friendship\"\r\n elif win_counter['A'] > win_counter['D']:\r\n return \"Anton\"\r\n else:\r\n return 'Danik'\r\n\r\n\r\nprint(anton_danik())\r\n", "times = int(input())\r\ngames = input()\r\nAnton = games.count('A')\r\nif times/2 < Anton:\r\n print('Anton')\r\nelif times/2 > Anton:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=str(int(input()))\r\ns=input()\r\nq=s.count('A')\r\nw=s.count('D')\r\nif q>w:\r\n print('Anton')\r\nelif w>q:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "# Input\r\nn = int(input())\r\noutcomes = input()\r\n\r\n# Count the number of Anton's wins ('A') and Danik's wins ('D')\r\nanton_wins = outcomes.count('A')\r\ndanik_wins = n - anton_wins # Since there are only two players\r\n\r\n# Determine the winner\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "anton=0\r\ndanik=0\r\n\r\nx=int(input())\r\ny=input()\r\n\r\n\r\nfor z in range(x):\r\n if y[z]=='A':\r\n anton=anton+1\r\n elif y[z]=='D':\r\n danik=danik+1\r\n \r\n\r\nif anton>danik:\r\n print('Anton')\r\nelif danik>anton:\r\n print('Danik')\r\nelif danik==anton:\r\n print('Friendship')\r\n", "import sys\r\nn=int(sys.stdin.readline().split()[0])\r\ns=sys.stdin.readline()[:-1]\r\nanton=s.count(\"A\")\r\ndanik=s.count(\"D\")\r\nif anton>danik:\r\n print(\"Anton\")\r\nelif anton<danik:\r\n print(\"Danik\")\r\nelse: \r\n print(\"Friendship\")", "def solution():\r\n n=int(input())\r\n ch=input()\r\n d,a=0,0\r\n for i in range (n):\r\n if ch[i]==\"A\":\r\n a=a+1\r\n if a>n/2:\r\n return \"Anton\"\r\n if ch[i]==\"D\":\r\n d=d+1\r\n if d>n/2:\r\n return \"Danik\"\r\n return \"Friendship\"\r\nprint(solution())\r\n ", "a=input()\r\nb=input()\r\na=0\r\nd=0\r\n\r\nfor x in b:\r\n if (x=='A'):\r\n a+=1\r\n else:\r\n d+=1\r\n\r\nif (a>d) :\r\n print(\"Anton\")\r\nelif (d>a) :\r\n print (\"Danik\")\r\nelse :\r\n print(\"Friendship\")", "k = input()\r\nn = input()\r\na = 0\r\nd = 0\r\nfor item in n:\r\n if item == \"A\":\r\n a += 1\r\n else:\r\n d += 1\r\nif d > a:\r\n print(\"Danik\")\r\nif d < a:\r\n print(\"Anton\")\r\nif d == a:\r\n print(\"Friendship\")", "n = int(input())\r\ns = list(input())\r\na = s.count('A')\r\nd = s.count('D')\r\nif a > d:\r\n print(\"Anton\")\r\nelif a < d:\r\n print(\"Danik\")\r\nelif a == d:\r\n print(\"Friendship\")", "n=int(input())\r\nm=str(input())\r\nanton_wins=m.count(\"A\")\r\ndanik_wins=n-anton_wins\r\nif anton_wins>danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins<danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "\r\n'''\r\n// Linked list implementation in C\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n\r\n// Creating a node\r\nstruct node {\r\n int value;\r\n struct node *next;\r\n};\r\n\r\n// print the linked list value\r\nvoid printLinkedlist(struct node *p) {\r\n while (p != NULL) {\r\n printf(\"%d \", p->value);\r\n p = p->next;\r\n }\r\n}\r\n\r\nint main() {\r\n // Initialize nodes\r\n struct node *head;\r\n struct node *one = NULL;\r\n struct node *two = NULL;\r\n struct node *three = NULL;\r\n\r\n // Allocate memory\r\n one = malloc(sizeof(struct node));\r\n two = malloc(sizeof(struct node));\r\n three = malloc(sizeof(struct node));\r\n\r\n // Assign value values\r\n one->value = 1;\r\n two->value = 2;\r\n three->value = 3;\r\n\r\n // Connect nodes\r\n one->next = two;\r\n two->next = three;\r\n three->next = NULL;\r\n\r\n // printing node-value\r\n head = one;\r\n printLinkedlist(head);\r\n}\r\n'''\r\n\r\nn = int(input())\r\ns = str(input())\r\na = s.count(\"A\")\r\nd = s.count(\"D\")\r\n\r\nif a>d :\r\n print(\"Anton\")\r\nelif a == d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "t=int(input())\r\ns=input()\r\ncA=s.count('A')\r\ncD=s.count('D')\r\nif(cA>cD):\r\n print(\"Anton\")\r\nelif(cA==cD):\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\ns = input()\ns = list(s)\na,d = 0,0\nfor i in s:\n if i == 'A':\n a = a+1\n else:\n d = d+1\n\nif a>d:\n print(\"Anton\")\nelif d>a:\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "n = int(input())\r\nwinners = list(input())\r\nA = winners.count(\"A\")\r\nD = winners.count(\"D\")\r\nwinner = \"Anton\" if A > D else (\"Danik\" if D > A else \"Friendship\")\r\nprint(winner)", "n=int(input()) #总共进行了几场游戏\r\nS=input()\r\na=0\r\nd=0\r\n\r\nfor i in range(n):\r\n if S[i]=='A':\r\n a+=1\r\n else:\r\n d+=1\r\n\r\nif a>d:\r\n print('Anton')\r\nelif a<d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\nresults = input()\r\ncount_a = results.count('A')\r\ncount_d = results.count('D')\r\nif count_a > count_d:\r\n print(\"Anton\")\r\nelif count_d > count_a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\nresults = input()\r\na_count = results.count('A')\r\nd_count = results.count('D')\r\nif a_count > d_count:\r\n print('Anton')\r\nelif a_count < d_count:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\nword = input()\r\ncount_A = 0\r\ncount_B = 0\r\nfor i in range(n):\r\n if word[i] == 'A':\r\n count_A += 1\r\n else:\r\n count_B += 1\r\nif count_A > count_B : \r\n print(\"Anton\")\r\nelif count_A < count_B:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "# import sys \n# sys.stdin = open(\"/Users/swasti/Desktop/coding/cp/codeforces/input.txt\", \"r\")\n# sys.stdout = open(\"/Users/swasti/Desktop/coding/cp/codeforces/output.txt\", \"w\")\n\nn = int(input())\ngiven = str(input())\nacount = 0\ndcount = 0\nfor i in range(n):\n if given[i] == \"A\": acount +=1\n elif given[i] == \"D\": dcount +=1\nif acount > dcount :\n print (\"Anton\")\nelif dcount>acount:\n print(\"Danik\")\nelif acount == dcount:\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nwonAnton = 0\r\nwonDanik = 0\r\n\r\nfor i in range(n):\r\n if s[i] == 'A':\r\n wonAnton += 1\r\n elif s[i] == 'D':\r\n wonDanik += 1\r\n\r\nif wonAnton == wonDanik:\r\n print(\"Friendship\")\r\nelif wonAnton > wonDanik:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")\r\n", "n = int(input())\ninp = list(input())\na_count = inp.count(\"A\")\nif a_count > n/2:\n print(\"Anton\")\nelif a_count == n/2:\n print(\"Friendship\")\nelse:\n print(\"Danik\")\n", "n=int(input())\r\na=0\r\nb=0\r\nk=input()\r\nfor i in range(n):\r\n if k[i]==\"A\":\r\n a+=1\r\n else:\r\n b+=1\r\nif a>b:\r\n print(\"Anton\")\r\nelif a<b:\r\n print(\"Danik\")\r\nelif a==b:\r\n print(\"Friendship\")", "length=input()\r\ngames=input()\r\napts=0\r\ndpts=0\r\nfor x in games:\r\n if x=='A':\r\n apts=apts+1\r\n if x=='D':\r\n dpts=dpts+1\r\nif apts>dpts:\r\n print(\"Anton\")\r\nelif dpts>apts:\r\n print(\"Danik\")\r\nelif dpts==apts:\r\n print(\"Friendship\")", "# URL: https://codeforces.com/problemset/problem/734/A\nn = int(input())\na = input().count('A')\nd = n - a\nif a > d:\n print(\"Anton\")\nelif a == d:\n print(\"Friendship\")\nelse:\n print(\"Danik\")\n", "n = int(input()) \r\ns = input() \r\nanton =0 \r\nDanik = 0 \r\nfor i in range(n) :\r\n if(s[i]==\"A\") :\r\n anton+=1 \r\n elif (s[i]==\"D\") : \r\n Danik+=1 \r\nif anton > Danik :\r\n print(\"Anton\") \r\nelif anton<Danik :\r\n print(\"Danik\") \r\nelse :\r\n print(\"Friendship\")\r\n\r\n ", "I=input\r\nn=int(I())\r\na=I().count('A')*2\r\nprint([['Friendship','Danik'][a<n],'Anton'][a>n])", "s=int(input())\r\nk=input()\r\nc=0\r\nfor i in k:\r\n if i=='A':\r\n c+=1\r\nif c>s-c:\r\n print('Anton')\r\nelif c<s-c:print('Danik')\r\nelse:print('Friendship')", "u=int(input())\r\nx=input()\r\nx1=0\r\ny=0\r\nfor i in x:\r\n if i=='A':\r\n x1=x1+1\r\n else:\r\n y=y+1\r\nif(x1>y):\r\n print(\"Anton\")\r\nif(x1<y):\r\n print(\"Danik\")\r\nif(x1==y):\r\n print(\"Friendship\")", "def code(*args):\r\n \r\n a_total_wins = 0\r\n d_total_wins = 0\r\n for i in range(args[1]):\r\n if args[0][i] == 'A':\r\n a_total_wins += 1\r\n else:\r\n d_total_wins += 1\r\n \r\n winner = a_total_wins - d_total_wins\r\n\r\n if winner < 0:\r\n return \"Danik\"\r\n elif winner == 0:\r\n return \"Friendship\"\r\n else:\r\n return \"Anton\"\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n # Take inputs here\r\n n = int(input())\r\n score_list = input()\r\n\r\n result = code(score_list, n) # Pass arguments\r\n print(result)\r\n\r\n", "def determine_winner(n, games):\r\n anton_wins = games.count('A')\r\n danik_wins = n - anton_wins\r\n\r\n if anton_wins > danik_wins:\r\n return \"Anton\"\r\n elif anton_wins < danik_wins:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n\r\nn = int(input())\r\ngames = input()\r\n\r\nprint(determine_winner(n, games))\r\n", "t = int(input())\r\nstr = input()\r\n\r\na = 0\r\nd = 0\r\n\r\nfor char in str:\r\n if char == 'A':\r\n a += 1\r\n elif char == 'D':\r\n d += 1\r\n\r\nif a > d:\r\n print(\"Anton\")\r\nelif d > a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[26]:\n\n\nnum = input()\nstring = input()\nanton,danik=0,0\nfor char in string:\n if char =='A':\n anton+=1\n if char =='D':\n danik+=1\nif anton > danik:\n print('Anton')\nif danik> anton:\n print('Danik')\nif anton == danik:\n print('Friendship')\n \n \n\n\n# In[ ]:\n\n\n\n\n", "n=int(input())\r\ns=input()\r\nan=0\r\nda=0\r\nfor i in s:\r\n if i==\"A\":\r\n an+=1 \r\n else:\r\n da+=1 \r\nif an>da:\r\n print(\"Anton\")\r\nelif an<da:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "games = input()\r\nwin = input()\r\nwin_list = []\r\na = 0\r\nd = 0\r\nfor i in range(len(win)):\r\n win_list.append(win[i])\r\nfor i in win_list:\r\n if i == \"A\":\r\n a = a + 1\r\n else:\r\n d = d + 1\r\nif a > d:\r\n print(\"Anton\")\r\nif d > a:\r\n print(\"Danik\")\r\nif a == d:\r\n print(\"Friendship\")\r\n", "n = int(input())\nstr = input(\"\")\n \nAnton = str.count(\"A\")\nDanik = str.count(\"D\")\n\nif Anton>Danik:\n print(\"Anton\")\nelif Anton==Danik:\n print(\"Friendship\")\nelse:\n print(\"Danik\")\n \n\n\n ", "a = int(input())\r\nb = input()\r\nb = list(b)\r\nanton = b.count('A')\r\ndamir = b.count('D')\r\nif anton > damir:\r\n print('Anton')\r\nelif anton < damir:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 12 16:23:19 2023\r\n\r\n@author: 15110\r\n\"\"\"\r\na=0\r\nd=0\r\nn=int(input())\r\ns=input()\r\nfor i in s :\r\n if i=='A':\r\n a+=1\r\n elif i=='D':\r\n d+=1\r\nif a>d:\r\n print('Anton')\r\nelif a<d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n\r\n \r\n ", "a=int(input())\r\nb=input()\r\ns=0\r\nq=0\r\nfor i in b:\r\n if i==\"A\":\r\n s=s+1\r\n if i==\"D\":\r\n q=q+1\r\nif s>q:\r\n print(\"Anton\")\r\nelif q>s:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ns = input()\r\nA=0\r\nD=0\r\nfor I in range(0,n):\r\n if s[I] =='A':\r\n A+=1\r\n else:\r\n D+=1\r\n \r\nif A > D :\r\n print(\"Anton\")\r\nelif D > A :\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n ", "n = int(input())\r\ns = input()\r\ncountA = 0\r\ncountD = 0\r\nfor i in range(n):\r\n if s[i] == \"A\":\r\n countA += 1\r\n if s[i] == \"D\":\r\n countD += 1\r\n\r\nif countA > countD:\r\n print(\"Anton\")\r\nelif countA < countD:\r\n print(\"Danik\")\r\nelif countA == countD:\r\n print(\"Friendship\")", "n = int(input())\r\nS = input()\r\n\r\ncount_A = 0\r\ncount_D = 0\r\n\r\nfor i in S:\r\n if i == \"A\":\r\n count_A = count_A + 1\r\n else:\r\n count_D = count_D + 1\r\n\r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_A < count_D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "An = 0\r\nDa = 0\r\nN = int(input())\r\nG = input()\r\nfor x in G:\r\n\tif (x=='D'):\r\n\t\tDa+=1\r\n\telse:\r\n\t\tAn+=1\r\n\r\nif (An>Da):\r\n\tprint('Anton')\r\nelif (Da>An):\r\n\tprint('Danik')\r\nelse:\r\n\tprint('Friendship')", "n = int(input())\r\na = 0\r\nd = 0\r\nchar = input()\r\n\r\nfor i in range(n):\r\n result = char[i] #使用characters[i]获取相应索引位置的字符\r\n if result == 'A':\r\n a += 1\r\n else:\r\n d += 1\r\n\r\nif a > d:\r\n print(\"Anton\")\r\nelif a < d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\nc=0\r\nfor i in s:\r\n if i=='D':\r\n c=c+1\r\n \r\nd=n-c\r\nif c>d:\r\n print(\"Danik\")\r\nelif c<d:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "def main():\r\n length=int(input())\r\n games=input()\r\n a=0\r\n d=0\r\n\r\n for i in range(length):\r\n if games[i]=='A':\r\n a+=1\r\n else:\r\n d+=1\r\n if a>d:\r\n print('Anton')\r\n elif d>a:\r\n print('Danik')\r\n else:\r\n print('Friendship')\r\n\r\nmain()", "denote=int(input())-input().count('A')*2;print([['Friendship','Danik'][denote>0],'Anton'][denote<0])", "b = input()\r\nz = input()\r\na = 0\r\nd = 0\r\nfor i in z: \r\n if i == 'A' :\r\n a = a + 1\r\n elif i == 'D' :\r\n d = d + 1 \r\nif a > d : \r\n print (\"Anton\")\r\nelif d > a :\r\n print (\"Danik\")\r\nelif a == d :\r\n print(\"Friendship\")\r\n", "v=int(input())\r\nstring=input()\r\nx1=0\r\nx2=0\r\nfor char in string:\r\n\tif char=='A':\r\n\t\tx1+=1\r\n\telif char=='D':\r\n\t\tx2+=1\r\nif x1>x2:\r\n\tprint(\"Anton\")\r\nelif x2>x1:\r\n\tprint(\"Danik\")\r\nelif x1==x2:\r\n\tprint(\"Friendship\")", "n = int(input())\r\ns = input()\r\ncountA, countD = 0, 0\r\nfor i in range(len(s)):\r\n if s[i] == \"D\":\r\n countD+=1\r\n if s[i] == \"A\":\r\n countA+=1\r\nif countA > countD:\r\n print(\"Anton\")\r\nelif countA < countD:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "\r\n# 6\r\n# ADAAAA\r\n\r\n\r\nn = int(input())\r\nchars = list(input())\r\n\r\nnum_A,num_D = 0,0\r\nfor char in chars:\r\n if char == \"A\":\r\n num_A += 1 \r\n else:\r\n num_D += 1\r\n\r\nif num_D > num_A:\r\n print(\"Danik\")\r\nelif num_D < num_A:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")\r\n \r\n\r\n# print(width)\r\n\r\n\r\n\r\n\r\n", "number_of_games = int(input())\r\nwinners = input()\r\n\r\nanton_wins, danik_wins = 0, 0\r\n\r\nfor letter in winners:\r\n\r\n if letter == \"A\":\r\n\r\n anton_wins += 1\r\n\r\n else:\r\n\r\n danik_wins += 1\r\n\r\n\r\nif anton_wins > danik_wins:\r\n\r\n print(\"Anton\")\r\n\r\nelif anton_wins < danik_wins:\r\n\r\n print(\"Danik\")\r\n\r\nelse: print(\"Friendship\")", "n = int(input())\r\ns = input()\r\n\r\ncount_A = 0\r\ncount_D = 0\r\nfor i in range(n):\r\n if s[i] == 'A':\r\n count_A += 1\r\n else:\r\n count_D += 1\r\n \r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_D > count_A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "loop=int(input())\r\nword=input()\r\na=0\r\nb=0\r\nfor char in word:\r\n\tif char=='A':\r\n\t\ta+=1\r\n\telif char=='D':\r\n\t\tb+=1\r\nif a>b:\r\n\tprint(\"Anton\")\r\nelif b>a:\r\n\tprint(\"Danik\")\r\nelif a==b:\r\n\tprint(\"Friendship\")", "n=int(input())\r\ns=input()[:n]\r\ndc=s.count('D')\r\nac=s.count('A')\r\nif dc>ac:\r\n print(\"Danik\")\r\nelif ac>dc:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\ncntA = 0\r\ncntD = 0\r\nfor i in range(len(s)):\r\n if s[i] == 'A':\r\n cntA += 1\r\n else:\r\n cntD += 1\r\nif cntA > cntD:\r\n print('Anton')\r\nelif cntD > cntA:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "def my_solution(n):\r\n \r\n s = [c for c in input()]\r\n\r\n anton = len([c for c in s if c == 'A'])\r\n danik = len([c for c in s if c == 'D'])\r\n\r\n print('Anton') if anton > danik else print(\"Danik\") if danik > anton else print(\"Friendship\")\r\n\r\nn = int(input())\r\nmy_solution(n)", "n=int(input())\r\nwin=list(input())\r\ncount_a=0\r\ncount_d=0\r\n\r\nif len(win)==n:\r\n for i in win:\r\n if i=='A':\r\n count_a+=1\r\n if i=='D':\r\n count_d+=1\r\n if count_a>count_d:\r\n print('Anton')\r\n elif count_a<count_d:\r\n print('Danik')\r\n elif count_a==count_d:\r\n print('Friendship')\r\n", "def main():\r\n n = int(input())\r\n outcome = input().strip()\r\n\r\n anton_wins = outcome.count('A')\r\n danik_wins = outcome.count('D')\r\n\r\n if anton_wins > danik_wins:\r\n print(\"Anton\")\r\n elif anton_wins < danik_wins:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n, s = int(input()), input()\r\nA, D = 0, 0\r\nfor i in s:\r\n if i == 'A':\r\n A += 1\r\n elif i == 'D':\r\n D += 1\r\nif A > D:\r\n print('Anton')\r\nelif D > A:\r\n print('Danik')\r\nelif A == D:\r\n print('Friendship')", "input()\r\nn = input()\r\nprint(\"Friendship\" if sum(i == \"A\" for i in n) * 2 == len(n) else (\"Anton\" if sum(i == \"A\" for i in n) * 2 > len(n) else \"Danik\"))", "matches = int(input())\r\nwon = input()\r\nanton = 0\r\ndanik = 0\r\n\r\nfor i in range(matches):\r\n if won[i] == 'A':\r\n anton += 1\r\n else:\r\n danik += 1\r\n#print(str(danik) + \" \" + str(anton))\r\nif danik > anton:\r\n print(\"Danik\")\r\nelif danik < anton:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n=input()\r\nx=input()\r\nif x.count('A')==x.count('D'):\r\n print('Friendship')\r\nelif x.count('A')>x.count('D'):\r\n print('Anton')\r\nelse:\r\n print('Danik')\r\n", "a = int(input())\r\nb = str(input())\r\nc = b.count(\"A\")\r\nd = b.count(\"D\")\r\nif c > d:\r\n print(\"Anton\")\r\nelif d > c:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\ncounter=0\r\nfor i in range (n):\r\n if s[i] ==\"A\":\r\n counter +=1\r\n else:\r\n counter -=1\r\nif counter >0:\r\n print(\"Anton\")\r\nelif counter<0:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\nres = input()\r\nA = 0\r\nD = 0\r\nfor value in res:\r\n if value == \"A\":\r\n A += 1 \r\n elif value == \"D\":\r\n D += 1 \r\nif A > D:\r\n print(\"Anton\")\r\nelif A < D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=list(input())\r\n\r\ncountA=s.count('A')\r\ncountD=s.count('D')\r\n\r\nif countA>countD:\r\n print(\"Anton\")\r\nelif countD>countA:\r\n print(\"Danik\")\r\nelif countD==countA:\r\n print(\"Friendship\")", "x=int(input())\na=0;d=0\ny=input()\nfor i in range(x):\n if y[i]=='A':\n a+=1\n else:\n d+=1\n\nif a>d:\n print('Anton')\nelif a<d:\n print('Danik')\nelse:\n print('Friendship')\n", "a = int(input())\r\nb = input()\r\nc = list(b)\r\nc_a = 0\r\nc_d = 0\r\nfor i in c:\r\n if i == 'A':\r\n c_a+=1\r\n elif i == 'D':\r\n c_d+=1\r\nif c_a>c_d:\r\n print('Anton')\r\nelif c_d>c_a:\r\n print('Danik')\r\nelif c_d == c_a:\r\n print('Friendship')", "games_played = int(input())\r\nwon_by = input()\r\ncount1 = 0\r\ncount2 = 0\r\nfor i in range(len(won_by)):\r\n if won_by[i] == \"A\":\r\n count1 += 1\r\n elif won_by[i] == \"D\":\r\n count2 += 1\r\nif count1 > count2:\r\n print(\"Anton\")\r\nelif count1 < count2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns1 = input()\r\nd = s1.count('D')\r\na = len(s1) - d\r\nif a > d:\r\n print(\"Anton\")\r\nelif d > a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = input()\r\nn_2 = input()\r\nnA = n_2.count('A')\r\nnD = n_2.count('D')\r\nif nA > nD:\r\n print('Anton')\r\nelif nA < nD:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "from collections import Counter\r\ndef solve(s):\r\n d = dict(Counter(s))\r\n if d.get('A', 0) == d.get('D', 0): return \"Friendship\"\r\n return \"Anton\" if d.get('A', 0) > d.get('D', 0) else \"Danik\"\r\n \r\ninput() \r\nprint(solve(input()))", "su=0\r\nsu2=0\r\nn=int(input())\r\ns=input()\r\nfor i in range(n):\r\n if s[i]=='A':\r\n su=su+1\r\nsu2=n-su\r\nif su>su2:\r\n print('Anton')\r\nelif su<su2:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "n = int(input())\r\ns = input()\r\nc_a = 0\r\nc_d = 0\r\nfor i in s:\r\n if (i=='A'):\r\n c_a += 1\r\n else:\r\n c_d += 1\r\nif (c_a > c_d):\r\n print('Anton')\r\nelif (c_a < c_d):\r\n print('Danik')\r\nelse:\r\n print('Friendship') ", "#take input from the user \r\nn = int(input())\r\n#take input as a string \r\nstring=input()\r\n#initilize 0 points in variable for two of tem\r\npnts_A=0\r\npnts_D=0\r\n#start loop check for each character in given input string\r\nfor char in string:\r\n #if number of A characters are more add 1point to variable \r\n if char=='A':\r\n pnts_A+=1\r\n #if no.of D are morechar add 1 point to Danik score\r\n elif char=='D':\r\n pnts_D+=1\r\n #if A chars are more count print Anton (winner)\r\nif pnts_A>pnts_D:\r\n print(\"Anton\")\r\n #if S chars more print as Danik(winner) \r\nelif pnts_D>pnts_A:\r\n print(\"Danik\")\r\n #print friendship if both score is equal\r\nelif pnts_A==pnts_D:\r\n \r\n print(\"Friendship\")\r\n ", "num = int(input())\r\ns = input()\r\n\r\ncount = 0\r\n\r\nfor char in s:\r\n\tif char == \"A\":\r\n\t\tcount = count + 1\r\n\r\nif count > len(s) - count:\r\n\tprint(\"Anton\")\r\nelif count < len(s) - count:\r\n\tprint(\"Danik\")\r\nelse:\r\n\tprint(\"Friendship\")\r\n", "n = int(input())\r\nresults = input()\r\n\r\nanton=0\r\ndanik=0\r\n\r\nluckyNumbers=0\r\nfor winner in results:\r\n if winner == 'A':\r\n anton+=1\r\n else:\r\n danik+=1\r\n \r\nif anton>danik:\r\n print('Anton')\r\nelif danik>anton:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\n\r\n# Read the outcome string\r\noutcomes = input()\r\n\r\n# Count the number of times 'A' and 'D' appear\r\ncount_A = outcomes.count('A')\r\ncount_D = outcomes.count('D')\r\n\r\n# Compare the counts and print the result\r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_D > count_A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "v=int(input())\r\np=input()\r\nx=p.count('A')\r\ny=p.count('D')\r\nif x>y:\r\n print(\"Anton\")\r\nelif x<y:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=input()\r\ni=input()\r\na=sum(i in'A'for i in i)\r\nd=sum(i in'D'for i in i)\r\nif a==d:\r\n print(\"Friendship\")\r\nelif a>d:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "def main():\r\n n=int(input())\r\n s=input()\r\n a=0\r\n b=0\r\n for i in range(0,n):\r\n if(s[i]=='A'):\r\n a+=1\r\n else:\r\n b+=1\r\n if(a>b):\r\n print(\"Anton\")\r\n if(a<b):\r\n print(\"Danik\")\r\n if(a==b):\r\n print(\"Friendship\")\r\nmain()", "idk = int(input())\r\nls = input()\r\na = ls.count(\"A\")\r\nb = ls.count(\"D\")\r\nif a>b:\r\n print(\"Anton\")\r\nelif b>a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\nx=s.count('A')\r\ny=s.count('D')\r\nif x>y:\r\n print(\"Anton\")\r\nelif x<y:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ng = input()\r\nA = 0\r\nfor i in g:\r\n if i == 'A': A+=1\r\nD = n-A\r\nif A>D: print('Anton')\r\nelif D>A: print('Danik')\r\nelse: print('Friendship')", "s = input()\r\nn = input()\r\na = n.count('A')\r\nd = n.count('D')\r\nif a < d:\r\n print('Danik')\r\nelif a > d:\r\n print('Anton')\r\nelse:\r\n print('Friendship')\r\n ", "n = int(input())\r\ns = input()\r\nc_Anton = 0\r\nc_Danik = 0\r\n\r\nfor i in range(len(s)):\r\n if s[i] == 'A':\r\n c_Anton +=1\r\n else:\r\n c_Danik += 1\r\n\r\nif c_Anton > c_Danik:\r\n print('Anton')\r\nelif c_Anton < c_Danik:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "num = int(input())\r\nwhowon = str(input())\r\ndsc,asc = 0,0\r\nfor i in whowon:\r\n if i == 'D':\r\n dsc += 1\r\n else:\r\n asc += 1\r\nif dsc > asc:\r\n print('Danik')\r\nelif asc > dsc:\r\n print('Anton')\r\nelif asc == dsc:\r\n print('Friendship')\r\n ", "numberOfGames= int(input())\r\nantonGames=input().count('A')\r\nif numberOfGames/2<antonGames:\r\n print('Anton')\r\nelif numberOfGames/2>antonGames : print('Danik')\r\nelse: print('Friendship')\r\n", "ln=int(input())\r\nstring=input()\r\nwinner_anton=0\r\nfor char in string:\r\n if char=='A':\r\n winner_anton+=1\r\n elif char=='D':\r\n winner_anton-=1\r\nif winner_anton>=1:\r\n print('Anton')\r\nelif winner_anton<0:\r\n print('Danik')\r\nelse:\r\n print('Friendship') ", "n = int(input())\ns = input()\na = d = 0\n\nfor x in s:\n if x == \"A\":\n a += 1\n else:\n d += 1\n\nif a > d:\n print(\"Anton\")\nelif d > a:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n", "import sys\r\nimport itertools\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp(): #Uno solo\r\n return(int(input()))\r\ndef inlt(): #Dos o mas\r\n return(list(map(int,input().split())))\r\ndef insr(): #String\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr(): #Vectores\r\n return(map(int,input().split()))\r\n\r\nn=inp()\r\ns=insr()\r\nA=s.count(\"A\")\r\nD=s.count(\"D\")\r\n\r\nif(A>D):\r\n print(\"Anton\")\r\nif(A<D):\r\n print(\"Danik\")\r\nif(A==D):\r\n print(\"Friendship\")", "from collections import Counter\r\n\r\nlength = int(input())\r\nword = input()\r\n\r\nstore = Counter(word)\r\n\r\nif store[\"A\"] > store[\"D\"]:\r\n print(\"Anton\")\r\n\r\nelif store[\"A\"] < store [\"D\"]:\r\n print(\"Danik\")\r\n\r\nelse:\r\n print(\"Friendship\")", "input()\r\nwinner = input()\r\na = winner.count(\"A\")\r\nd = len(winner)-a\r\nprint(\"Anton\" if a>d else \"Danik\" if d>a else \"Friendship\")", "def winner(n, s):\r\n anton_wins = s.count('A')\r\n danik_wins = n - anton_wins\r\n\r\n if anton_wins > danik_wins:\r\n return \"Anton\"\r\n elif anton_wins < danik_wins:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\nn = int(input())\r\ns = input().strip()\r\nresult = winner(n, s)\r\nprint(result)\r\n", "c=int(input())\r\ni=0\r\nt=0\r\nv=0\r\nx=str(input())\r\nwhile(i<c):\r\n if(x[i]=='A'):\r\n t+=1\r\n else:\r\n v+=1\r\n i+=1 \r\nif(t>v):\r\n print(\"Anton\")\r\nelif(t==v):\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "\r\nx =input()\r\ny=list(input())\r\na=0\r\nd=0\r\nfor i in y:\r\n if i==\"A\":\r\n a+=1\r\n else:\r\n d+=1\r\n\r\nif a>d:\r\n print(\"Anton\")\r\nelif d>a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n\r\n\r\n", "n = int(input())\r\ns = input()\r\n\r\nanton_games = s.count('A')\r\ndanik_games = s.count('D')\r\n\r\nif anton_games > danik_games: # Anton Won\r\n print(\"Anton\")\r\nelif danik_games > anton_games: # Danik won\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\ncount,sum=0,0\r\nstr=input()[:n]\r\nfor i in range(n):\r\n if str[i]==\"A\":\r\n count+=1\r\n else:\r\n sum+=1\r\nif(count<sum):\r\n print(\"Danik\")\r\nelif(count>sum):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\nx=input()\r\nl=[]\r\nfor i in x:\r\n l.append(i)\r\n\r\na=l.count('A')\r\nd=l.count('D')\r\nif(a>d):\r\n print(\"Anton\")\r\nif(d>a):\r\n print(\"Danik\")\r\nif(a==d):\r\n print(\"Friendship\")", "size= int(input())\r\nlist1= input()\r\na =list1.count('A')\r\nd= list1.count('D')\r\nif a> d:\r\n print(\"Anton\")\r\nelif a< d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "amount_of_parties = int(input())\r\ncell = input()\r\ntoxa = 0\r\ndanik = 0\r\n\r\nfor i in range(amount_of_parties):\r\n if cell[i] == 'A':\r\n toxa += 1\r\n if cell[i] == 'D':\r\n danik += 1\r\n\r\nif toxa == danik:\r\n print('Friendship')\r\nif toxa > danik:\r\n print('Anton')\r\nif toxa < danik:\r\n print('Danik')", "n = int(input())\r\nw = input()\r\nif w.count(\"A\") > w.count(\"D\"):\r\n print(\"Anton\")\r\nelif w.count(\"A\") < w.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "import sys\n\ninput = sys.stdin.readline\n\nn = int(input())\n\nstring = input()\nstring = string[:-1] # Eliminating the last newline character\n\ncount_a = 0\ncount_d = 0\n\nhalf_limit = n // 2\n\nfor s in string:\n if s == \"A\":\n count_a += 1\n\n elif s == \"D\":\n count_d += 1\n\n if count_a > half_limit:\n sys.stdout.write(\"Anton\")\n exit()\n\n elif count_d > half_limit:\n sys.stdout.write(\"Danik\")\n exit()\n\nif count_a == count_d:\n sys.stdout.write(\"Friendship\")\n", "n = int(input())\r\ncount_d = 0\r\ncount_a = 0\r\na = input()\r\nfor j in a:\r\n if j == \"A\":\r\n count_a += 1\r\n else:\r\n count_d += 1\r\nif count_a > count_d:\r\n print(\"Anton\")\r\nelif count_d > count_a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=input()\ns=str(input())\nif s.count('A')>s.count('D'):\n print('Anton')\nelif s.count('D')>s.count('A'):\n print('Danik')\nelse:\n print('Friendship') ", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 19 15:19:50 2023\r\n\r\n@author: ljy\r\n\"\"\"\r\nn=int(input())\r\ngame=input()\r\nA=game.count('A')\r\nD=game.count('D')\r\n#print(A,D)\r\nif A>D:\r\n print('Anton')\r\nelif A<D:\r\n print('Danik')\r\nelif A==D:\r\n print('Friendship')", "def fg():\r\n return int(input())\r\ndef fgh():\r\n return[int(xx) for xx in input().split()]\r\ndef fgt():\r\n return map(int,input().split())\r\ndef fgs():\r\n return input()\r\nn=fg()\r\ns=fgs()\r\nif s.count('A')-s.count('D')>0:\r\n print('Anton')\r\nelif s.count('A')==s.count('D'):\r\n print('Friendship')\r\nelse:\r\n print('Danik')", "n = input()\r\ns = input()\r\nc = []\r\nfor i in range(len(s)):\r\n c.append(s[i])\r\ncnt_anton = 0\r\ncnt_danik = 0\r\n\r\nfor i in c:\r\n if i == 'A':\r\n cnt_anton += 1\r\n elif i == 'D':\r\n cnt_danik += 1\r\n\r\nif cnt_anton == cnt_danik:\r\n print('Friendship')\r\n\r\nelif cnt_anton > cnt_danik:\r\n print('Anton')\r\n\r\nelse:\r\n print('Danik')", "n=int(input())\r\nst=str(input()).lower()\r\na,d=0,0\r\nfor i in range(n):\r\n if st[i] == 'a':\r\n a+=1\r\n else:\r\n d+=1\r\nif a>d:\r\n print('Anton')\r\nelif a==d:\r\n print('Friendship')\r\nelse:\r\n print('Danik')", "n=int(input())\r\nline=input()\r\nA,D=0,0\r\nfor i in range(n):\r\n if line[i]==\"A\":\r\n A+=1\r\n elif line[i]==\"D\":\r\n D+=1\r\nif A>D:\r\n print(\"Anton\")\r\nelif A<D:\r\n print(\"Danik\")\r\nelif A==D:\r\n print(\"Friendship\")", "n = input()\r\ns = input()\r\nif s.count(\"A\") == s.count(\"D\"):\r\n print(\"Friendship\")\r\n exit()\r\nprint(\"Anton\" if s.count(\"A\") > s.count(\"D\") else \"Danik\")", "n = int(input().strip())\r\nL = input().strip()\r\n\r\na_wins = L.count('A')\r\nd_wins = n - a_wins\r\n\r\nif a_wins > d_wins:\r\n print(\"Anton\")\r\nelif a_wins < d_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "# Input the number of games and the outcomes of each game\r\nn = int(input())\r\noutcomes = input()\r\n\r\n# Count the occurrences of 'A' (Anton's wins) and 'D' (Danik's wins)\r\nanton_wins = outcomes.count('A')\r\ndanik_wins = outcomes.count('D')\r\n\r\n# Determine the winner or if it's a tie\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins < danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "ins = int(input())\r\nst = input()\r\ncna = st.count('A')\r\ncnb = st.count('D')\r\nif cna > cnb :\r\n print('Anton')\r\nelif cna < cnb :\r\n print('Danik')\r\nelse :\r\n print('Friendship')", "n = int(input())\n\naord = input()\n\na= 0\nd = 0\nfor s in aord:\n if s =='A':\n a+=1\n else:\n d+=1\n\nif a>d:\n print(\"Anton\")\nelif d>a:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n\n", "n=int(input())\r\ns=input()\r\nl=[i for i in s]\r\n\r\nif l.count('A')>l.count('D'):\r\n print(\"Anton\")\r\nif l.count('A')<l.count('D'):\r\n print(\"Danik\")\r\nif l.count('A')==l.count('D'):\r\n print(\"Friendship\")", "n = int(input())\r\ngame = str(input())\r\nif game.count('A') > game.count('D'):\r\n print('Anton')\r\nelif game.count('A') < game.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "num_games = int(input())\r\n# dfbad\r\nresults = input()\r\ncount_Anton = 0\r\n\r\ncount_Danik = 0\r\n\r\nfor result in results:\r\n\r\n if result == \"A\":\r\n\r\n count_Anton += 1\r\n\r\n\r\n elif result == \"D\":\r\n count_Danik += 1\r\n\r\nif count_Anton > count_Danik:\r\n print(\"Anton\")\r\nelif count_Danik > count_Anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\nresult=input()\r\ncount_D,count_A=0,0\r\nfor i in result:\r\n if i=='A':\r\n count_A+=1\r\n else:\r\n count_D+=1\r\nif count_A>count_D:\r\n print('Anton')\r\nelif count_A<count_D:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "\r\nn = int(input())\r\nvictories = input()\r\n\r\nanton = sum(1 for game in victories if game==\"A\")\r\ndanik = n-anton\r\n\r\nif anton>danik:\r\n print(\"Anton\")\r\nelif danik>anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n ", "parties = int(input())\r\noutcomes = str(input())\r\nif outcomes.count('A') > outcomes.count('D'):\r\n print('Anton')\r\nelif outcomes.count('A') < outcomes.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\na = list(input())\n\nif a.count(\"A\") > a.count(\"D\"):\n print(\"Anton\")\nelif a.count(\"A\") < a.count(\"D\"):\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n", "#https://codeforces.com/contest/734/problem/A\r\nfrom collections import Counter\r\nn = input()\r\nstr = input()\r\nstr = Counter(str)\r\n\r\nif(str['A'] == str['D']):\r\n print('Friendship')\r\nelif(str['A'] > str['D']):\r\n print('Anton')\r\nelse:\r\n print('Danik')", "ignoreThisInput = input()\r\nresults = input()\r\n\r\na, d = 0, 0\r\n\r\nfor result in results:\r\n if result == 'A':\r\n a += 1\r\n elif result == 'D':\r\n d += 1\r\nif a > d:\r\n print(\"Anton\")\r\nelif d > a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "t=int(input())\r\ns=input()\r\nc1=0\r\nc2=0\r\nfor j in s:\r\n if j=='A':\r\n c1 += 1\r\n if j=='D':\r\n c2 += 1\r\nif(c1>c2):\r\n print(\"Anton\")\r\nif(c2>c1):\r\n print(\"Danik\")\r\nif(c1==c2):\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ngames = input(\"\")\r\nanton = games.count(\"A\")\r\nif anton > n/2:\r\n print(\"Anton\")\r\nelif anton < n/2:\r\n print(\"Danik\")\r\nelif anton == n/2:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\ns=input()\r\ne=s.count('A');\r\nr=s.count('D');\r\nif e>r:\r\n print('Anton');\r\nelif e==r:\r\n print('Friendship');\r\nelse:\r\n print('Danik');\r\n\r\n", "x = int(input())\r\nm = input()\r\na = m.count(\"A\")\r\nb = m.count(\"D\")\r\n\r\nif a>b :\r\n print(\"Anton\")\r\nelif b>a :\r\n print(\"Danik\")\r\nelif a == b:\r\n print(\"Friendship\")", "n = int(input()) # Read the number of games played\r\nresults = input() # Read the outcome of each game\r\n\r\nanton_wins = results.count('A') # Count the number of times 'A' appears in results\r\ndanik_wins = results.count('D') # Count the number of times 'D' appears in results\r\n\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "m=input()\r\nb=input()\r\na=0\r\nd=0\r\nfor i in range(0,len(b)):\r\n if b[i]=='A':\r\n a=a+1 \r\n else:\r\n d=d+1 \r\nif a>d:\r\n print(\"Anton\")\r\nelif a==d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")\r\n ", "n = int(input())\r\ns = str(input()).upper()\r\na = s.count('A')\r\nd = s.count('D')\r\nif(a>d):\r\n print(\"Anton\")\r\nelif(a<d):\r\n print(\"Danik\")\r\nelif(a==d):\r\n print(\"Friendship\")\r\n \r\n#734A\r\n \r\n", "n = int(input())\r\na = input()\r\nanton = 0\r\nfor i in range(n):\r\n if a[i] == 'A':\r\n anton = anton + 1\r\nif anton*2>n:\r\n print('Anton')\r\nelif anton*2<n:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "u=int(input())\r\nn=input()\r\nn1=0\r\ny=0\r\nfor i in n:\r\n if i=='A':\r\n n1=n1+1\r\n else:\r\n y=y+1\r\nif(n1>y):\r\n print(\"Anton\")\r\nif(n1<y):\r\n print(\"Danik\")\r\nif(n1==y):\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\ncountA=sum(1 for i in s if i=='A')\r\ncountD=sum(1 for i in s if i=='D')\r\nif countA>countD:\r\n print('Anton')\r\nelif countA<countD:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "a=input()\r\nb=input()\r\nc=[i for i in b]\r\nif c.count('A')>c.count('D'):\r\n print(\"Anton\")\r\nelif c.count('D')>c.count('A'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n ", "from collections import Counter\r\nn = input()\r\nl = Counter(input())\r\n\r\nif (l['A'] > l['D']):\r\n print(\"Anton\")\r\nelif (l['A'] < l['D']):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=input()\r\nt=input()\r\ny=0\r\nx=0\r\nwhile int(x)<int(n):\r\n if t[int(x)]==\"A\":\r\n y=int(y)+1\r\n x=int(x)+1\r\n else:\r\n x=int(x)+1\r\nif int(n)%2==0 and int(y)>int(int(n)/2):\r\n print('Anton')\r\nelif int(n)%2==0 and int(y)==int(int(n)/2):\r\n print('Friendship')\r\nelif int(n)%2==0 and int(y)<int(int(n)/2):\r\n print('Danik')\r\nelif int(n)%2!=0 and int(y)>int(int(int(n)-1)/2):\r\n print('Anton')\r\nelif int(n)%2!=0 and int(y)<=int(int(int(n)-1)/2):\r\n print('Danik')\r\nelse:\r\n print('Avni')", "n = int(input())\r\ns = input()\r\nan = s.count(\"A\")\r\ndk = s.count(\"D\")\r\nif an > dk:\r\n print('Anton')\r\nelif an < dk:\r\n print('Danik')\r\nelse:\r\n print(\"Friendship\")", "a=int(input())\r\nb=str(input())\r\nA=b.count(\"A\")\r\nD=b.count(\"D\")\r\nprint((\"Anton\")if A>D else((\"Danik\")if D>A else(\"Friendship\")))", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nSpyder Editor\r\n\r\nThis is a temporary script file.\r\n\"\"\"\r\n\r\nb = input()\r\na = list(input())\r\ns = 0\r\ny = 0\r\nfor i in a:\r\n if i == 'A' :\r\n s += 1\r\n elif i == 'D' :\r\n y += 1\r\nif s > y :\r\n print('Anton')\r\nelif s == y :\r\n print('Friendship')\r\nelse:\r\n print('Danik')", "n,s=input(),input()\r\ncounter=0\r\nfor i in s:\r\n if i == \"A\":\r\n counter+=1\r\n else:\r\n counter-=1\r\nif counter>0:\r\n print(\"Anton\")\r\nelif counter<0:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "num_of_games = int(input())\r\nwinner_of_games = input().upper()\r\nif winner_of_games.count('A') > winner_of_games.count('D'):\r\n print(\"Anton\")\r\nelif winner_of_games.count('A') < winner_of_games.count('D'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\na_count, d_count = 0,0\r\nfor c in s:\r\n if c == \"A\":\r\n a_count += 1\r\n else:\r\n d_count += 1\r\nif a_count == d_count:\r\n print(\"Friendship\")\r\nelif a_count > d_count:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "gamesPlayed = int(input(\"\"))\noutcome = str(input(\"\"))\nAnton = 0\nDanik = 0\n\nfor i in outcome:\n if i == \"A\":\n Anton += 1\n elif i == \"D\":\n Danik += 1\n\nif Anton > Danik:\n print(\"\\nAnton\")\nelif Anton < Danik:\n print(\"\\nDanik\")\nelif Anton == Danik: \n print(\"\\nFriendship\")\n \t\t\t \t\t\t\t \t\t\t \t \t\t \t \t \t\t\t", "y = input()\r\na = input()\r\nz = 0\r\nx = 0\r\nfor i in a:\r\n if i == 'A':\r\n z+=1\r\n else:\r\n x+=1\r\nif z==x:\r\n print('Friendship')\r\nelif z>x:\r\n print('Anton')\r\nelse:\r\n print('Danik')", "def chess(liste):\r\n D=0\r\n A=0\r\n for i in range(len(liste)):\r\n if liste[i]=='D':\r\n D=D+1\r\n else:\r\n A=A+1\r\n if D<A:\r\n return(\"Anton\")\r\n elif A<D:\r\n return(\"Danik\")\r\n else :\r\n return(\"Friendship\")\r\n\r\nn=int(input())\r\nentrer=list(input())\r\nprint(chess(entrer))", "lenght = int(input())\r\nRec = input()\r\nx=[]\r\nfor char in Rec:\r\n x.append(char) \r\nA = x.count(\"A\")\r\nD = x.count(\"D\")\r\n#print(\"A\",A,\"|\",\"D\",D,\"|\",\"Rec\",x,\"|\")\r\nif A == D:\r\n print(\"Friendship\")\r\nelif A > D:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ninp = input()\r\ninp = inp[0:n]\r\ncount_A = 0\r\ncount_D = 0\r\nfor i in inp:\r\n if i==\"A\":\r\n count_A += 1\r\n else:\r\n count_D +=1\r\nif count_A>count_D:\r\n print('Anton')\r\nelif count_A<count_D:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n ", "x = int(input())\r\ns = input()\r\nact = 0\r\ndct = 0\r\nfor i in range(x):\r\n if(s[i]=='A'):\r\n act =act +1\r\n \r\n else:\r\n dct =dct+1\r\n\r\nif(act==dct):\r\n print(\"Friendship\")\r\n\r\nelif(act>dct):\r\n print(\"Anton\")\r\n\r\nelse:\r\n print(\"Danik\")", "ct = int(input())\r\nstroke = input()\r\nif stroke.count(\"D\") > stroke.count(\"A\"):\r\n print(\"Danik\")\r\nelif stroke.count(\"A\") > stroke.count(\"D\"):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\noutcome = input()\r\n\r\nanton = outcome.count('A')\r\ndanik = outcome.count('D')\r\n\r\nif anton > danik:\r\n print('Anton')\r\nelif danik > anton:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=int(input())\r\nstr1=input()\r\ncount_A,count_D=0,0\r\nfor i in str1:\r\n if i==\"A\":\r\n count_A+=1\r\n elif i==\"D\":\r\n count_D+=1\r\n\r\nif count_A>count_D:\r\n print(\"Anton\")\r\nelif count_D>count_A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\nstring = input()\nA_count = 0\nD_count = 0\n\nfor i in range(n):\n if string[i] == \"A\":\n A_count += 1\n else:\n D_count += 1\n\nif A_count > D_count:\n print(\"Anton\")\nelif A_count < D_count:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n", "while True:\r\n n=int(input())\r\n ch=input()\r\n s=0\r\n f=0\r\n for i in range (len(ch)):\r\n if ch[i]==\"A\":\r\n s=s+1\r\n if ch[i]==\"D\":\r\n f=f+1\r\n if f+s==n and 1<=n<=100000:\r\n break\r\nif s>f:\r\n print(\"Anton\")\r\nelif s<f:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n ", "def winner(n,string):\r\n A_counts=string.count('A')\r\n D_counts=string.count('D')\r\n if A_counts>D_counts:\r\n return 'Anton'\r\n elif A_counts<D_counts:\r\n return 'Danik'\r\n else:\r\n return 'Friendship'\r\nn=int(input())\r\nstring=input()\r\nresults=winner(n,string)\r\nprint(results)", "a = int(input())\r\nb = input()\r\n\r\nAnton = 0\r\nDanik = 0\r\n\r\nfor i in b:\r\n if i == \"A\":\r\n Anton += 1\r\n elif i == \"D\":\r\n Danik += 1\r\nif Anton > Danik:\r\n print(\"Anton\")\r\nelif Danik > Anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\nb = str(input()).upper()\r\nif b.count('A') > b.count('D'):\r\n print('Anton')\r\nelif b.count('A') < b.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "num = input()\r\nanswer= input()\r\nA=answer.count('A')\r\nD = int(num) - A\r\nif D>A:\r\n print(\"Danik\")\r\nelif A>D:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n\r\n", "x = int(input())\r\na = 0\r\nb = 0\r\ny = input()\r\nfor i in y:\r\n if i == \"A\":\r\n a += 1\r\n else:\r\n b += 1\r\nif a > b:\r\n print(\"Anton\")\r\nelif a < b:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "t=int(input())\r\nn=input()\r\na=0\r\nb=0\r\nfor i in range(t):\r\n if n[i] == 'A':\r\n a += 1\r\n else:\r\n b += 1\r\nif a > b:\r\n print(\"Anton\")\r\nelif b > a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "\r\nn=eval(input())\r\ns=input()\r\ns=s.upper()\r\ncount1=0\r\ncount2=0\r\nfor i in s:\r\n if i==\"D\":\r\n count1+=1\r\n else:\r\n count2+=1\r\nif count1>count2:\r\n print(\"Danik\")\r\nelif count2>count1:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "input()\ncount = 0\nfor i in input():\n if i == \"A\":\n count-=1\n else:\n count+=1\nif count<0:\n print(\"Anton\")\nelif count==0:\n print(\"Friendship\")\nelse:\n print(\"Danik\")", "n=int(input())\r\nx=input()\r\nc=0\r\nfor i in x:\r\n if(i=='A'):\r\n c+=1\r\nif(c==(n-c)):\r\n print(\"Friendship\")\r\nelif(c>(n-c)):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\nv = str(input())\r\n\r\nanton = 0\r\ndanik = 0\r\n\r\nfor i in v:\r\n if i == 'A':\r\n anton += 1\r\n elif i == 'D':\r\n danik += 1\r\n\r\nif danik > anton:\r\n print(\"Danik\")\r\nelif danik < anton:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ns = input()\r\n\r\nanton_wins = s.count('A')\r\ndanik_wins = n - anton_wins\r\n\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins < danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ncnt = input().count('A')\r\nprint('Friendship' if cnt == n / 2 else ('Anton' if cnt > n / 2 else 'Danik'))", "n = int(input())\r\ns = input()\r\n\r\ncountAnton = 0\r\ncountDanik = 0\r\nfor i in range(n):\r\n if s[i] == 'A':\r\n countAnton += 1\r\n else:\r\n countDanik += 1\r\n\r\nif countAnton > countDanik:\r\n print('Anton')\r\nelif countAnton < countDanik:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = input()\r\nn = int(n)\r\n\r\ns = input()\r\n\r\nA = 0\r\nD = 0\r\n# print(n)\r\nfor i in s:\r\n \r\n if i == \"A\":\r\n A += 1\r\n elif i == \"D\":\r\n D += 1\r\n\r\nif A > D:\r\n print(\"Anton\")\r\nelif D > A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n1 = int(input()) \r\ns1 = input() \r\n\r\n\r\nanton_wins = s1.count('A')\r\ndanik_wins = s1.count('D')\r\n\r\n\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input(\"\"))\r\ns=input(\"\")\r\nd=0\r\na=0\r\nd = s.count(\"D\")\r\na = s.count(\"A\")\r\n\r\nif(a<d):\r\n print(\"Danik\")\r\nelif(a>d):\r\n print(\"Anton\")\r\nelif(d==a):\r\n print(\"Friendship\")", "n = int(input())\r\ns = list(input())\r\na = s.count('A')\r\nd = s.count('D')\r\nif (a>d): print('Anton')\r\nelif (a<d): print('Danik')\r\nelse: print('Friendship')", "n,a,d=int(input()),0,0\r\nc=str(input())\r\nfor x in c:\r\n if x==\"A\":\r\n a+=1\r\n elif x==\"D\":\r\n d+=1\r\nif a<d:\r\n print(\"Danik\")\r\nif d<a:\r\n print(\"Anton\")\r\nif a==d:\r\n print(\"Friendship\")", "import sys\r\nfrom collections import Counter\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef yes():\r\n print(\"YES\")\r\n\r\n\r\ndef no():\r\n print(\"NO\")\r\n\r\n\r\ninput()\r\ns = input().rstrip()\r\nd = Counter(s)\r\nif d[\"A\"] > d[\"D\"]:\r\n print(\"Anton\")\r\nelif d[\"D\"] > d[\"A\"]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ngame_winners = input()\r\nanton_counter = 0\r\ndanik_counter = 0\r\n\r\nfor i in range(n):\r\n if game_winners[i] == \"A\":\r\n anton_counter += 1\r\n else:\r\n danik_counter += 1\r\n\r\nif anton_counter > danik_counter:\r\n print(\"Anton\")\r\nelif anton_counter < danik_counter:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "\ndef main():\n n = int(input().strip())\n game_result = input().strip()\n count_A = game_result.count('A')\n count_B = game_result.count('D')\n print(\"Friendship\" if count_A == count_B else \"Anton\" if count_A > count_B else \"Danik\")\n\nif __name__ == \"__main__\":\n main()\n", "n = input()\r\nk = input()\r\na = 0\r\nd = 0\r\nfor c in range(0, int(n), 1):\r\n if k[c] == \"A\":\r\n a = a + 1\r\n else:\r\n d = d + 1\r\nif a > d:\r\n print(\"Anton\")\r\nelse:\r\n if a < d:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")", "n = int(input())\n\ndata = input()\n\n\nawon = 0\ndwon = 0\n\nfor x in data:\n if x == \"A\":\n awon += 1\n else:\n dwon += 1\n\nif awon > dwon:\n print(\"Anton\")\nelif dwon > awon:\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "n1=(input())\r\nn1=n1.split()\r\nn2=(input())\r\na1=n2.count(\"A\")\r\na2=n2.count(\"D\")\r\nif a1>a2:\r\n print(\"Anton\")\r\nelif a1<a2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "kolvo_partiy = int(input())\nwins = input()\nn = 0\nAntonWins = 0\nDanikWins = 0\nfor win in range(kolvo_partiy):\n if wins[n] == 'A':\n AntonWins += 1\n n += 1\n else:\n n += 1\n DanikWins += 1\n\nif AntonWins > DanikWins:\n print('Anton')\nif DanikWins > AntonWins:\n print('Danik')\nif DanikWins == AntonWins:\n print('Friendship')\n", "n = int(input())\ns = input()\nA = s.count(\"A\")\nD = s.count(\"D\")\nif A > D:\n print(\"Anton\")\nelif A < D:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n", "n = int(input())\r\ns = input()\r\nanton = 0\r\nfor i in s:\r\n anton = anton + 1 if i == 'A' else anton - 1 if i == 'D' else anton + 0\r\n\r\n\r\nprint(\"Anton\" if anton > 0 else \"Danik\" if anton < 0 else \"Friendship\")\r\n", "def main(num, string):\r\n cnt1, cnt2 = 0, 0\r\n for i in string:\r\n if i == 'A':\r\n cnt1 += 1\r\n else:\r\n cnt2 += 1\r\n if cnt1 == cnt2:\r\n print('Friendship')\r\n elif cnt1 > cnt2:\r\n print('Anton')\r\n else:\r\n print('Danik')\r\n\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n s = input()\r\n main(n, s)\r\n", "a=int(input())\nwins=input()\nj=0\ncount1,count2=0,0\nfor j in range(a):\n if wins[j]==\"A\":\n count1+=1\n elif wins[j]==\"D\":\n count2+=1\nif count1>count2:\n print(\"Anton\")\nelif count1<count2:\n print(\"Danik\")\nelse :\n print(\"Friendship\")\n", "n=int(input())\r\ns=input()\r\nalist=[]\r\nfor f in s:\r\n alist.append(f)\r\nc=alist.count(\"A\")\r\nv=alist.count(\"D\")\r\nif c>v:\r\n print(\"Anton\")\r\nelif v>c:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\nAcount=0\r\nfor i in range(len(s)):\r\n if s[i]==\"A\":\r\n Acount=Acount+1\r\nDcount=n-Acount\r\nif Acount>Dcount:\r\n print(\"Anton\")\r\nelif Acount<Dcount:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "a=int(input())\r\ns=0\r\nfor i in input():\r\n if i=='A':\r\n s=s+1\r\nif s*2>a:\r\n print(\"Anton\")\r\nelif s*2<a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "net=input\r\nun=int(net())\r\na=net().count('A')*2\r\nprint([['Friendship','Danik'][a<un],'Anton'][a>un])\r\n", "n = int(input())\r\n\r\narr = input()\r\n\r\na = 0\r\nd = 0\r\nfor i in range(n):\r\n if arr[i] == \"A\":\r\n a = a + 1\r\n elif arr[i] == \"D\" : \r\n d = d + 1\r\n\r\nif a > d:\r\n print(\"Anton\")\r\nelif d > a:\r\n print(\"Danik\")\r\nelif d == a:\r\n print(\"Friendship\")", "n = input()\r\nx = input()\r\nl = list()\r\na, d = x.count('A'), x.count('D')\r\nif a < d:\r\n print('Danik')\r\nelif a == d:\r\n print('Friendship')\r\nelse:\r\n print('Anton')\r\n", "s = int(input())\r\nb = input()\r\na = 0\r\nd = 0\r\nfor i in b:\r\n if i == \"A\":\r\n a += 1\r\n else:\r\n d += 1\r\nif a > d:\r\n print(\"Anton\")\r\nelif d > a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ns = input()\r\nA_wins = s.count('A')\r\nD_wins = s.count('D')\r\nif(A_wins > D_wins):\r\n print(\"Anton\")\r\nelif(D_wins > A_wins):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "m= int(input())\r\nn = list(input())\r\nantoncounter = 0\r\ndanikcounter=0\r\nfor x in n:\r\n if x == \"A\":\r\n antoncounter+=1\r\n if x == \"D\":\r\n danikcounter+=1\r\nif antoncounter > danikcounter:\r\n print(\"Anton\")\r\nelif danikcounter > antoncounter:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "a1 = input()\r\na = input()\r\ncount_a = 0\r\ncount_b = 0\r\nfor i in a:\r\n if i == \"A\":\r\n count_a += 1\r\n elif i == \"D\":\r\n count_b += 1\r\nif count_a > count_b:\r\n print(\"Anton\") \r\nelif count_a < count_b:\r\n print(\"Danik\") \r\nelse:\r\n print(\"Friendship\")", "n = int(input(\"\"))\nch = input(\"\")\ncountA = 0\ncountD = 0\nfor i in ch:\n if i == \"A\":\n countA += 1\n else:\n countD += 1\nif countA > countD:\n print(\"Anton\")\nelif countA < countD:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n", "n=int(input())\r\nwon=input()\r\nif won.count(\"A\") > won.count(\"D\"):\r\n print(\"Anton\")\r\nelif won.count(\"A\") < won.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\na = input()\r\nan = 0\r\ndan = 0\r\nfor i in range(n):\r\n if(a[i] == \"A\"):\r\n an += 1\r\n elif(a[i] == \"D\"):\r\n dan += 1\r\nif(an > dan):\r\n print(\"Anton\")\r\nelif(an < dan):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\na=list(input())\r\nif a.count('A')>a.count('D'):\r\n print(\"Anton\")\r\nelif a.count('A')<a.count('D'):\r\n print('Danik') \r\nelse:\r\n print('Friendship') ", "a = int(input())\r\nparty = input()\r\nif party.count(\"A\") > party.count(\"D\"):\r\n print(\"Anton\")\r\nelif party.count(\"A\") < party.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def sol():\r\n n=int(input())\r\n s=input()\r\n a=s.count(\"A\")\r\n d=n-a\r\n if d>a:\r\n print(\"Danik\")\r\n elif d<a:\r\n print(\"Anton\")\r\n else:\r\n print(\"Friendship\")\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nsol()", "a = int(input())\r\nb = [*input()]\r\ncount = 0\r\nfor i in b:\r\n if i == 'A':\r\n count+=1\r\nelse:\r\n if count > a - count:\r\n print('Anton')\r\n elif count < a - count:\r\n print('Danik')\r\n else:\r\n print(\"Friendship\")\r\n\r\n", "amont = input()\r\narr = list(input())\r\nx = 0\r\nfor i in arr:\r\n if i == 'A':\r\n x +=1\r\n else:\r\n x -= 1\r\nif x >0:\r\n print('Anton')\r\nelif x<0:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "c = int(input())\r\nb = str(input())\r\nd = b.count(\"D\")\r\na = b.count(\"A\")\r\nif a > d:\r\n print(\"Anton\")\r\nelif d > a:\r\n print(\"Danik\")\r\nelif d == a:\r\n print(\"Friendship\")\r\n", "n = int(input())\ns=input()\na=s.count('A')\nif a>n-a:\n\tprint(\"Anton\")\nelif a<n-a:\n\tprint('Danik')\nelse:\n\tprint(\"Friendship\")\n\n", "n = int(input())\r\ns = input()\r\nAnton = 0\r\nDanik = 0\r\n\r\nfor i in range(n):\r\n if s[i] == \"A\":\r\n Anton += 1\r\n elif s[i] == \"D\":\r\n Danik += 1\r\n \r\nif Anton < Danik:\r\n print(\"Danik\")\r\nelif Anton > Danik:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ntext = list(input())\r\ntime = 0\r\nfor outcome in text:\r\n if outcome == 'A':\r\n time += 1\r\nif time > (n - time):\r\n print('Anton')\r\nelif time == (n - time):\r\n print('Friendship')\r\nelse:\r\n print('Danik')\r\n", "n = int(input())\r\ns = input()\r\nk = list(s)\r\ncountA = 0\r\ncountB = 0\r\nfor i in range(len(k)):\r\n if k[i] == 'A':\r\n countA += 1\r\n else:\r\n countB += 1\r\nif(countA > countB):\r\n print(\"Anton\")\r\nelif(countA < countB):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "num_rounds = int(input())\r\nxt = 0 \r\nyt = 0 \r\nresults = input()\r\nfor char in results:\r\n if char == \"A\":\r\n xt += 1\r\n elif char == \"D\":\r\n yt += 1\r\nif xt > yt:\r\n print(\"Anton\")\r\nelif yt > xt:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\n\r\ngame = list(input())\r\ncount_a = 0\r\ncount_d = 0\r\nfor i in game:\r\n if i == 'A':\r\n count_a += 1\r\n elif i == 'D':\r\n count_d += 1\r\n\r\nif count_a > count_d:\r\n print(\"Anton\")\r\nelif count_a < count_d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "game=int(input())\r\nmy_str=input()\r\n\r\na=my_str.count('A')\r\nd=my_str.count('D')\r\n\r\nif a>d:\r\n print(\"Anton\")\r\n \r\nelif a==d:\r\n print(\"Friendship\")\r\n \r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\nresult = str(input())\r\n\r\n\r\nif result.count(\"A\") > result.count(\"D\"):\r\n print(\"Anton\")\r\nelif result.count(\"A\") < result.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\nstr1=input()\r\ncounta=0\r\ncountd=0\r\nfor i in str1:\r\n if(i=='A'):\r\n counta+=1\r\n elif(i=='D'):\r\n countd+=1\r\n else:\r\n continue\r\nif(counta>countd):\r\n print(\"Anton\")\r\nelif(countd>counta):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n, g, a, d = int(input()), input(), 0, 0\r\nfor x in g:\r\n if x == \"A\": a += 1\r\n elif x == \"D\": d += 1\r\nif a > d: print(\"Anton\")\r\nelif d > a: print(\"Danik\")\r\nelse: print(\"Friendship\")", "# Read the input values\r\nn = int(input())\r\nresults = input()\r\n\r\n# Count the number of 'A's and 'D's\r\nanton_count = results.count('A')\r\ndanik_count = results.count('D')\r\n\r\n# Compare the counts to determine the winner\r\nif anton_count > danik_count:\r\n print(\"Anton\")\r\nelif danik_count > anton_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "a=int(input())\r\nb=input()\r\nans=b.count('A')\r\nans1=b.count('D')\r\nif ans>ans1:\r\n print (\"Anton\")\r\nif ans<ans1:\r\n print (\"Danik\")\r\nif ans==ans1:\r\n print (\"Friendship\")\r\n", "d=int(input())\r\nstr=input()\r\ncount=str.count('A')\r\nd-=count*2\r\nresult=\"\"\r\nif d>0:\r\n result=\"Danik\"\r\nelif d<0:\r\n result=\"Anton\"\r\nelse:\r\n result=\"Friendship\"\r\nprint(result)\r\n", "# https://codeforces.com/problemset/problem/734/A\r\n\r\ndef solve(games):\r\n anton_games = 0\r\n for game in games:\r\n if game == 'A':\r\n anton_games += 1\r\n if anton_games > len(games) - anton_games:\r\n return 'Anton'\r\n elif anton_games == len(games) - anton_games:\r\n return 'Friendship'\r\n return 'Danik'\r\n\r\ninput()\r\ngames = input()\r\nprint(solve(games))\r\n", "ngames=int(input())\r\ngames=input()\r\na=[]\r\nd=[]\r\nfor i in games:\r\n if i==\"A\":\r\n a.append(i)\r\n else:\r\n d.append(i)\r\n\r\nif len(a)>len(d):\r\n print(\"Anton\")\r\nelif len(a)<len(d):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "#Anton or Danik\r\nn=int(input())\r\nx=input()\r\nk=0\r\nl=0\r\nfor i in x:\r\n if i=='A':\r\n k+=1\r\n else:\r\n l+=1\r\nif k>l:\r\n print('Anton')\r\nelif k==l:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")\r\n", "n=int(input())\r\ns=str(input())\r\nanton=0\r\ndanik=0\r\nfor i in s:\r\n if i=='A':\r\n anton+=1\r\n elif i=='D':\r\n danik+=1\r\nif anton<danik:\r\n print(\"Danik\")\r\nelif anton>danik:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Sep 19 16:37:09 2023\r\n\r\n@author: 27823\r\n\"\"\"\r\n\r\nn=int(input())\r\ngames=list(input())\r\nA=0\r\nD=0\r\nfor game in games:\r\n if game==\"A\":\r\n A+=1\r\n else:\r\n D+=1\r\nif A>D:\r\n print(\"Anton\")\r\nelif A<D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\nA=str(input())\r\n \r\nan=0\r\ndn=0\r\nfor i in A:\r\n if i=='A':\r\n an=an+1\r\n else:\r\n dn=dn+1\r\nif an>dn:\r\n print('Anton')\r\nelif dn>an:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "number_of_games = int(input())\r\nname = str(input())\r\nif name.count(\"D\") > name.count(\"A\"):\r\n print(\"Danik\")\r\nelif name.count(\"A\") > name.count(\"D\"):\r\n print(\"Anton\")\r\nelse :\r\n print(\"Friendship\")", "# Read the number of games played\r\nn = int(input())\r\n\r\n# Read the outcome of each game\r\noutcomes = input()\r\n\r\n# Count the number of games won by Anton and Danik\r\nanton_wins = outcomes.count('A')\r\ndanik_wins = n - anton_wins\r\n\r\n# Determine the winner or if it's a tie\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ns = input()\r\n\r\na = 0\r\nd = 0\r\n\r\nfor i in s:\r\n if i == \"A\":\r\n a += 1\r\n else:\r\n d += 1\r\n\r\nif n - a > n // 2:\r\n print(\"Danik\")\r\nelif n - d > n // 2:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "def determine_winner(n, games_outcome):\r\n count_A = games_outcome.count('A')\r\n count_D = games_outcome.count('D')\r\n if count_A > count_D:\r\n return \"Anton\"\r\n elif count_D > count_A:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\nn = int(input().strip())\r\ngames_outcome = input().strip()\r\n\r\nresult = determine_winner(n, games_outcome)\r\nprint(result)\r\n", "games = int(input())\r\nword = input().strip().upper()\r\n\r\n\r\nif(len(word) == games):\r\n up = 0\r\n low = 0\r\n for i in word:\r\n if(i == \"A\"):\r\n up += 1\r\n else:\r\n low += 1\r\n\r\nif(low > up):\r\n word = \"Danik\"\r\nelif(low < up):\r\n word = \"Anton\"\r\nelse:\r\n word = \"Friendship\"\r\nprint(word)", "n = int(input())\r\ni = 0\r\n\r\nanton_score = 0\r\ndanik_score = 0\r\n\r\ntxt = input()\r\n\r\nwhile i < n:\r\n if txt[i] == 'A':\r\n anton_score += 1\r\n else:\r\n danik_score += 1\r\n\r\n i += 1\r\n\r\nif anton_score > danik_score:\r\n print(\"Anton\")\r\nelif danik_score > anton_score:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n\r\n", "games = input()\r\nstatus = input()\r\nsplit = [*status]\r\n\r\nif split.count(\"A\") > split.count(\"D\"):\r\n print(\"Anton\")\r\nif split.count(\"A\") < split.count(\"D\"):\r\n print(\"Danik\")\r\nif split.count(\"A\") == split.count(\"D\"):\r\n print(\"Friendship\")", "n = int(input())\r\ns = str(input())\r\nawins = 0\r\ndwins = 0\r\nfor x in s:\r\n if x == 'A':\r\n awins = awins + 1\r\n if x == 'D':\r\n dwins = dwins + 1\r\nif awins > dwins:\r\n print('Anton')\r\nif dwins > awins:\r\n print('Danik') \r\nif dwins == awins:\r\n print('Friendship')\r\n ", "n = int(input())\r\nword = input()\r\na = word.count('A')\r\nif (n - a) > a:\r\n print(\"Danik\")\r\nelif (n - a) < a:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\nk=list(map(str,input()))\r\nA=k.count('A')\r\nD=k.count('D')\r\nif A>D:\r\n print('Anton')\r\nelif D>A:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\nstrr = input()\r\na, d = 0, 0\r\nfor ch in strr:\r\n if ch == 'A':\r\n a += 1\r\n else:\r\n d += 1\r\nif a > d:\r\n print(\"Anton\")\r\nelif a < d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "games = int(input())\ngame_results = input()\n\nAnton_count = sum(1 for game in game_results if game == \"A\")\n\nif Anton_count > games/2:\n print(\"Anton\")\nelif Anton_count == games/2:\n print(\"Friendship\")\nelse:\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\ns_a = s.count(\"A\")\r\ns_d = s.count(\"D\")\r\nif s_a > s_d:\r\n print(\"Anton\")\r\nelif s_a == s_d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")\r\n", "num_playes = int(input())\r\nwin_string = input()\r\n\r\noutput = \"Friendship\"\r\n\r\nif win_string.count(\"D\") > len(win_string) // 2:\r\n output = \"Danik\"\r\nelif win_string.count(\"A\") > len(win_string) // 2:\r\n output = \"Anton\"\r\n \r\nprint(output)\r\n", "n=int(input())\r\nresult=list(input())\r\nif result.count('D')<result.count('A'):\r\n print('Anton')\r\nelif result.count('D')>result.count('A'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n \r\n", "n = int(input())\r\ns = input()\r\na=0\r\nd=0\r\nfor i in s:\r\n if i=='A':\r\n a=a+1\r\n else:\r\n d = d+1\r\nif a==d:\r\n print(\"Friendship\")\r\nelif(a>d):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\na_count = 0\r\nd_count = 0\r\nif 1<=n<=100000:\r\n for i in range(0, len(s)):\r\n if s[i] == \"A\":\r\n a_count += 1\r\n elif s[i] == \"D\":\r\n d_count += 1\r\nif a_count > d_count:\r\n print(\"Anton\")\r\nelif d_count > a_count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "number_games = int(input())\r\nwon_letters = list(input())\r\n\r\ntotal_A = 0\r\ntotal_D = 0\r\n\r\nfor won_letter in won_letters:\r\n if won_letter == 'A':\r\n total_A += 1\r\n elif won_letter == 'D':\r\n total_D += 1\r\n \r\n\r\nif total_A > total_D:\r\n print(\"Anton\")\r\n \r\nelif total_D > total_A:\r\n print(\"Danik\")\r\n \r\nelse:\r\n print(\"Friendship\")", "n = int(input())\ns = input()\nwin_A = 0\nwin_D = 0 \nfor i in range(len(s)):\n c = s[i]\n if c == 'A':\n win_A += 1\n else:\n win_D += 1\nif win_A > win_D:\n print('Anton')\nelif win_A < win_D:\n print('Danik')\nelse: \n print('Friendship')", "# Read the number of games played\r\nn = int(input().strip())\r\n\r\n# Read the outcomes of the games as a string\r\noutcomes = input().strip()\r\n\r\n# Count the number of times Anton (A) and Danik (D) won\r\nanton_wins = outcomes.count('A')\r\ndanik_wins = outcomes.count('D')\r\n\r\n# Compare the counts and print the result accordingly\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif danik_wins > anton_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\nresults=input()\r\nAwin=0\r\nfor result in results:\r\n if result==\"A\":\r\n Awin+=1\r\n else:\r\n Awin-=1\r\nif Awin>0:\r\n print(\"Anton\")\r\nelif Awin==0:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "n=input()\r\ns=input()\r\na,d=s.count('A'),s.count('D')\r\nif a>d:\r\n s=\"Anton\"\r\nelif d>a:\r\n s=\"Danik\"\r\nelse:\r\n s=\"Friendship\"\r\nprint(s)", "m = int(input())\r\nx = input()\r\naz = 0\r\ndz = 0\r\nn = 0\r\nwhile(n < m):\r\n if x[n] == 'A':\r\n az += 1\r\n else:\r\n dz += 1\r\n n += 1\r\nif az == dz:\r\n print(\"Friendship\")\r\nelif az > dz:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n=int(input())\r\ns=input()\r\ncounta=0\r\ncountb=0\r\nfor i in s:\r\n if i=='A':\r\n counta+=1\r\n else:\r\n countb+=1\r\nif counta==countb:\r\n print(\"Friendship\")\r\nelif counta>countb:\r\n print(\"Anton\")\r\nelse: \r\n print(\"Danik\")\r\n", "x = int(input())\r\ny = str(input())\r\na = y.count(\"A\")\r\nb = y.count(\"D\")\r\n\r\nif a > b:\r\n print('Anton')\r\nelif a < b:\r\n print('Danik')\r\nelif a == b:\r\n print('Friendship')", "s = input()\r\ns = input()\r\nn = 0\r\nfor a in s:\r\n if a == 'A':\r\n n += 1\r\n else:\r\n n -= 1\r\nif n > 0:\r\n print('Anton')\r\nelif n < 0:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "_, s = input(), input()\r\nprint(\"Anton\" if s.count(\"A\") > s.count(\"D\") else \"Danik\" if s.count(\"A\") != s.count(\"D\") else \"Friendship\")\r\n", "n = int(input())\r\nw = input()\r\na = []\r\nd = []\r\nfor x in (list(w)):\r\n if x == \"A\" :\r\n a.append(x)\r\n else :\r\n d.append(x)\r\nif len(a) > len(d) :\r\n print(\"Anton\")\r\nelif len(a) == len(d) :\r\n print(\"Friendship\")\r\nelse :\r\n print(\"Danik\")\r\n", "n = int(input())\r\nst = input()\r\nka = st.count(\"A\")\r\nkd = st.count(\"D\")\r\nif ka > kd:\r\n print(\"Anton\")\r\nelif kd > ka:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "count=int(input())\r\nwins=input()\r\nA=0\r\nD=0\r\nfor i in wins:\r\n if i=='A':\r\n A+=1\r\n else:\r\n D+=1\r\nif A>D:\r\n print('Anton')\r\nelif A<D:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\nr = input()\r\n\r\nans = r.count('A')\r\ndns = n - ans\r\n\r\nif ans > dns:\r\n print(\"Anton\")\r\nelif ans < dns:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "trash = input()\r\ngames = [*input()]\r\nif games.count('A') > games.count('D'):\r\n print('Anton')\r\nelif games.count('A') < games.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "def determine_winner(s):\r\n anton_count = s.count('A')\r\n danik_count = s.count('D')\r\n\r\n if anton_count > danik_count:\r\n return \"Anton\"\r\n elif danik_count > anton_count:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n# Read input\r\nn = int(input())\r\ns = input()\r\n\r\n# Determine the winner and print the result\r\nresult = determine_winner(s)\r\nprint(result)\r\n", "num = int(input())\r\nresult = input()\r\nif result.count('A') > num/2:\r\n print('Anton')\r\nelif result.count('A') == num/2:\r\n print('Friendship')\r\nelse:\r\n print('Danik')\r\n", "n=input()\nn=int(n)\n\ntxt=input()\n\n\ndanik=0\nanton=0\nfor i in range(n):\n if txt[i]==\"D\":\n danik=danik+1\n else:\n anton=anton+1\n\n\nif anton==danik:\n print(\"Friendship\")\nelif anton>danik:\n print(\"Anton\")\nelse:\n print(\"Danik\")\n\n\n\n\n\t\t\t\t \t\t \t \t \t \t\t\t \t\t\t \t\t", "input()\r\nscores = input()\r\n\r\nscore = [0, 0]\r\nfor n in scores:\r\n if n == \"A\":\r\n score[0] += 1\r\n else:\r\n score[1] += 1\r\n\r\nif score[0] > score[1]:\r\n print(\"Anton\")\r\nelif score[1] > score[0]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "g = int(input())\r\ns = input()\r\n\r\nc = 0\r\nfor i in range(g):\r\n if s[i]=='A':\r\n c += 1\r\n else:\r\n c -= 1\r\n\r\nif c == 0:\r\n print('Friendship')\r\nelif c > 0:\r\n print('Anton')\r\nelse:\r\n print('Danik')", "n = input()\r\nstr = input()\r\na=0\r\nd=0\r\nfor i in str:\r\n if i==\"A\":\r\n a+=1\r\n else:\r\n d+=1\r\nif d>a:\r\n print(\"Danik\")\r\nelif a>d:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\n\r\ns = input()\r\n\r\nsum_A = 0\r\nsum_D = 0\r\n\r\nfor i in range(n):\r\n if s[i].upper() == \"A\":\r\n sum_A += 1\r\n if s[i].upper() == \"D\":\r\n sum_D += 1\r\n\r\nif sum_A > sum_D:\r\n print(\"Anton\")\r\nelif sum_A < sum_D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "g = int(input())\r\n\r\ngames = input()\r\n\r\ndanik = games.count(\"D\")\r\nanton = len(games)-danik\r\n\r\nif danik > anton:\r\n print(\"Danik\")\r\nelif anton > danik:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\na = str(input())\r\nanton_score = 0\r\ndanik_score = 0\r\nfor i in a:\r\n\tif i == 'A':\r\n\t\tanton_score +=1\r\n\telse:\r\n\t\tdanik_score +=1\r\nif anton_score>danik_score:\r\n\tprint('Anton')\r\nelif danik_score>anton_score:\r\n\tprint('Danik')\r\nelse:\r\n\tprint('Friendship')\t\r\n\r\n", "n=int(input())\r\nstr1=input()\r\ncount1=str1.count('A')\r\ncount2=str1.count('D')\r\nif count1>count2:\r\n print(\"Anton\")\r\nelif count1<count2:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\nresult = list(input())\r\nA = result.count('A')\r\nD = result.count('D')\r\nif A > D:\r\n print('Anton')\r\nelif A < D:\r\n print('Danik')\r\nelse: print('Friendship')", "n = int(input())\r\nx = input()\r\nd=0\r\na=0\r\nfor i in range(len(x)):\r\n\tif(x[i]=='A'):a+=1\r\n\telif(x[i]=='D'):d+=1\r\n\r\nprint(\"Anton\" if a>d else \"Danik\" if d>a else \"Friendship\")\r\n", "n = input()\r\nstring = input()\r\nanton = 0\r\ndaniel = 0\r\nfor i in range(len(string)):\r\n if string[i] == 'A':\r\n anton += 1\r\n else:\r\n daniel += 1\r\nif anton > daniel:\r\n print(\"Anton\")\r\nelif anton == daniel:\r\n print(\"Friendship\")\r\nelse:\r\n print( \"Danik\")", "num = int(input())\r\nword = input()\r\nant = 0\r\ndan = 0\r\nfor i in word:\r\n if i == 'A':\r\n ant += 1\r\n else:\r\n dan += 1\r\n\r\nif ant > dan:\r\n print(\"Anton\")\r\nelif ant < dan:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nprint('Danik' if s.count('D') > s.count('A') else 'Anton' if s.count('D') < s.count('A') else 'Friendship')", "\r\ndef main():\r\n n = int(input())\r\n score = input()\r\n\r\n d = score.count(\"D\")\r\n a = score.count(\"A\")\r\n if d > a:\r\n print(\"Danik\")\r\n elif a > d:\r\n print(\"Anton\")\r\n else:\r\n print(\"Friendship\")\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\r\nvictories = input()\r\n\r\nif victories.count('A') > victories.count('D'):\r\n print('Anton')\r\nelif victories.count('A') < victories.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = str(input())\r\n\r\na,b = 0, 0\r\nfor i in s:\r\n if i == \"A\":\r\n a += 1\r\n else:\r\n b += 1\r\nif a > b:\r\n print(\"Anton\")\r\nelif a < b:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\nb=input()\r\nant=0\r\ndar=0\r\nfor i in b:\r\n if i==\"A\":\r\n ant+=1\r\n elif i==\"D\":\r\n dar+=1\r\nif ant>dar:\r\n print(\"Anton\")\r\nelif dar>ant:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = int(input())\r\ns = input()\r\nanton_count = 0\r\n\r\nfor x in s:\r\n if x == \"A\":\r\n anton_count += 1\r\n\r\nif anton_count > n - anton_count:\r\n print(\"Anton\")\r\nelif anton_count == n - anton_count:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "input_s = input()\r\ninput_l = input()\r\na = 0\r\nd = 0\r\nfor i in range(len(input_l)):\r\n if input_l[i] == 'A':\r\n a += 1\r\n else:\r\n d += 1\r\nif a > d:\r\n print('Anton')\r\nelif a < d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = input()\r\n\r\nAcount = 0\r\nDcount = 0\r\n\r\nfor ch in s:\r\n if ch == 'A':\r\n Acount += 1\r\n else:\r\n Dcount += 1\r\n\r\nif Acount > Dcount:\r\n print(\"Anton\")\r\nelif Dcount > Acount:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "def determine_winner(n, results):\r\n anton_wins = results.count('A')\r\n danik_wins = results.count('D')\r\n \r\n if anton_wins > danik_wins:\r\n return \"Anton\"\r\n elif anton_wins < danik_wins:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\n# Зчитуємо кількість партий та результати\r\nn = int(input())\r\nresults = input()\r\n\r\n# Визначаємо переможця\r\nwinner = determine_winner(n, results)\r\n\r\n# Виводимо результат\r\nprint(winner)\r\n", "n = int(input())\ns = input()\nA = 0\nD = 0\nfor i in range(n):\n if s[i] == 'A':\n A += 1\n elif s[i] == 'D':\n D += 1\nif A > D:\n print(\"Anton\")\nelif D > A:\n print(\"Danik\")\nelif D == A:\n print(\"Friendship\")\n\n \t\t\t \t\t \t\t \t\t \t \t", "#liczbaGier,mecze = map(input().split())\r\nliczbaGier = input()\r\nmecze = str(input())\r\n\r\nA = mecze.count(\"A\")\r\nD = mecze.count(\"D\")\r\nif A > D:\r\n print(\"Anton\")\r\nelif A < D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "import sys\r\n\r\nn = int(sys.stdin.readline().strip())\r\ns = sys.stdin.readline().strip()\r\n\r\nwon_by_anton = 0\r\n\r\nfor c in s:\r\n if c == 'A':\r\n won_by_anton += 1\r\n\r\nif won_by_anton > n - won_by_anton:\r\n print('Anton')\r\nelif won_by_anton < n - won_by_anton:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Sep 6 19:02:24 2023\r\n\r\n@author: mac\r\n\"\"\"\r\n\r\nn = int(input())\r\ns = input()\r\ndwin = 0 #记录D赢的次数\r\nfor l in s:\r\n if l == \"D\":\r\n dwin += 1\r\nif dwin > n - dwin:\r\n print(\"Danik\")\r\nelif dwin == n - dwin:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Anton\")", "n = int(input())\r\ns = input()\r\napoint = 0\r\ndpoint = 0\r\nfor c in s:\r\n if c =='D':\r\n dpoint +=1\r\n else:\r\n apoint +=1\r\nif dpoint > apoint:\r\n print('Danik')\r\nelif dpoint < apoint:\r\n print('Anton')\r\nelse:\r\n print('Friendship')\r\n \r\n", "n = int(input())\r\na = input()\r\nanton = a.count('A')\r\ndanton = a.count('D')\r\n\r\nif danton > anton:\r\n print('Danik')\r\nelif danton < anton:\r\n print('Anton')\r\nelse:\r\n print('Friendship')", "a = int(input())\r\nb = input()\r\nc = 0\r\nfor i in b:\r\n if i == \"A\":\r\n c+=1\r\n else:\r\n c-=1\r\nif c>0:\r\n print(\"Anton\")\r\nelif c<0:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "input()\r\ns = input()\r\nD = s.count(\"D\")\r\nA = s.count(\"A\")\r\nprint(\"Anton\" if A > D else \"Danik\" if D > A else \"Friendship\")\r\n ", "match = int(input())\r\ninp = input()\r\nn1 = n2 = 0\r\nfor i in range(match):\r\n if inp[i] == 'A':\r\n n1 += 1\r\n else:\r\n n2 += 1\r\nif n1 == n2:\r\n print('Friendship')\r\nif n1>n2:\r\n print('Anton')\r\nif n1<n2:\r\n print('Danik')", "a = input()\r\ns = input()\r\n\r\nA = s.count('A')\r\nD = len(s)-A\r\nif A==D:\r\n print('Friendship')\r\nelif A>D:\r\n print('Anton')\r\nelse:\r\n print('Danik')", "x = input()\r\nn = input()\r\nANTON = n.count(\"A\")\r\nDANIK = n.count(\"D\")\r\nif ANTON > DANIK:\r\n print(\"Anton\")\r\nelif ANTON < DANIK:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\ncount = [0,0]\r\nfor i in s:\r\n if i == 'A':\r\n count[0]+=1\r\n else:\r\n count[1]+=1\r\nif count[0]>count[1]:\r\n print(\"Anton\")\r\nelif count[0]<count[1]:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\nprint(\"Anton\" if(s.count('A')>s.count('D')) else(\"Friendship\" if (s.count('A')==s.count('D')) else \"Danik\"))", "n=int(input())\r\na=input()\r\nx=0\r\ny=0\r\nz=0\r\nwhile n>x :\r\n\tif a[x] == \"A\" :\r\n\t\ty+=1\r\n\telse :\r\n\t\tz+=1\r\n\tx+=1\r\n\t\r\nif y>z:\r\n\tprint('Anton')\r\nelif z>y:\r\n\tprint('Danik')\r\nelse:\r\n\tprint('Friendship')", "n = int(input())\r\ng = input()\r\nA = 0\r\nD = 0\r\nfor i in g:\r\n\tif i == \"A\":\r\n\t\tA += 1\r\n\telse:\r\n\t\tD += 1\r\nif A > D:\r\n\tprint(\"Anton\")\r\nelif D > A: \r\n\tprint(\"Danik\")\r\nelse:\r\n\tprint(\"Friendship\")", "x = int(input())\r\ns = input()\r\nc = 0\r\nv = 0\r\nfor i in range(len(s)):\r\n if s[i] == 'A':\r\n c += 1\r\n\r\n else:\r\n v += 1\r\nif c > v:\r\n print(\"Anton\")\r\nelif c < v:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n\r\n\r\n", "n = int(input())\r\ngames = input()\r\nprint('Friendship' if games.count('A') * 1.0 == n / 2 else ('Anton' if games.count('A') * 1.0 > n / 2 else 'Danik'))", "N=int(input())\r\nStr=input()\r\ncount1=Str.count('A')\r\ncount2=Str.count('D')\r\nif count1==count2:\r\n print(\"Friendship\")\r\nelif count1>count2:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "a=int(input())\r\nb=list(input())\r\nc,d=0,0\r\nfor i in range(0,a):\r\n if b[i]==\"A\":\r\n c+=1\r\n else:\r\n d+=1\r\nif c>d:\r\n print(\"Anton\")\r\nelif c<d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def games_won(n, s):\r\n anton = []\r\n danik = []\r\n \r\n for char in s:\r\n if char == \"A\":\r\n anton.append(char)\r\n elif char == \"D\":\r\n danik.append(char)\r\n\r\n if len(anton) > len(danik):\r\n return \"Anton\"\r\n elif len(anton) < len(danik):\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\ndef main():\r\n n = int(input())\r\n s = input()\r\n result = games_won(n, s)\r\n print(result)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Sep 11 20:52:36 2023\r\n\r\n@author: Zinc\r\n\"\"\"\r\n\r\na=0\r\nb=0\r\nn=int(input())\r\ngame=input()\r\nfor c in game:\r\n if c=='A':\r\n a+=1\r\n elif c=='D': \r\n b+=1\r\nif a>b: \r\n print('Anton')\r\nelif a<b: \r\n print('Danik')\r\nelse: \r\n print('Friendship')", "\r\nn=int(input())\r\ns=input()\r\ncount_A=s.count('A')\r\ncount_D=s.count('D')\r\nif count_A>count_D:\r\n print(\"Anton\")\r\nelif count_D>count_A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "num=int(input())\r\nstate=list(input())\r\nvalues=tuple(state)\r\na=values.count(\"A\")\r\nb=values.count(\"D\")\r\nif a>b:\r\n print(\"Anton\")\r\nelif b>a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def who(n, s):\r\n a = 0\r\n d = 0\r\n for i in range(0, len(s)):\r\n if s[i] == 'A':\r\n a += 1\r\n if s[i] == 'D':\r\n d += 1\r\n if a>d:\r\n print(\"Anton\")\r\n elif d>a:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\n\r\nn = int(input())\r\ns = input()\r\nwho(n, s)", "x=int(input(\"\"))\r\ny=input(\"\")\r\na=y.count(\"A\")\r\nb=y.count(\"D\")\r\nif a>b:\r\n print(\"Anton\")\r\nelif a<b:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "# Read input\r\nn = int(input())\r\noutcomes = input()\r\n\r\n# Count the number of 'A' and 'D' in the outcomes\r\ncount_A = outcomes.count('A')\r\ncount_D = outcomes.count('D')\r\n\r\n# Compare the counts and determine the winner\r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_D > count_A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "input()\r\np = input()\r\na, d = p.count('A'), p.count('D')\r\nif a > d:\r\n print('Anton')\r\nelif a < d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = input()\r\nanton = 0\r\ndanik = 0\r\nfor i in s:\r\n if i=='A':\r\n anton+=1 \r\n else:\r\n danik+=1 \r\nif anton>danik:\r\n print(\"Anton\")\r\nelif danik>anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "N = int(input())\r\nS = list(input())\r\nA = S.count(\"A\")\r\nD = S.count(\"D\")\r\n\r\nif A > D:\r\n print(\"Anton\")\r\nelif A < D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "input()\r\nstring = input()\r\nprint(\"Anton\" if string.count(\"A\") > string.count(\"D\") else \"Danik\" if string.count(\"D\") > string.count(\"A\") else \"Friendship\")", "n = int(input())\r\nA = input()\r\nA = [i for i in A]\r\n\r\nif A.count('A') > A.count('D'):\r\n print(\"Anton\")\r\nelif A.count('A') < A.count('D'):\r\n print (\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\nwins=input()\r\ncount_a=0\r\ncount_d=0\r\nfor win in wins:\r\n if win=='A':\r\n count_a+=1\r\n elif win=='D':\r\n count_d+=1\r\nif count_a>count_d:\r\n print(\"Anton\")\r\nelif count_d>count_a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "# Anton and Danik Difficulty:800\r\nn = int(input())\r\ngame = input()\r\na = game.count('A')\r\nd = n-a\r\nif a > d:\r\n print(\"Anton\")\r\nelif a < d:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=input()\nn=int(n) # int\n\ns=input() #string\nanton=0\ndanik=0\n\nfor i in range(n):\n if s[i]=='A':\n anton+=1\n elif s[i]=='D':\n danik+=1\n\n\nif anton>danik:\n print(\"Anton\")\nelif anton<danik:\n print(\"Danik\")\nelse :\n print(\"Friendship\")\n\n \t\t \t\t\t \t\t\t\t \t \t \t \t", "def main():\r\n l=int(input())\r\n s= input()\r\n if s.count('D')==s.count('A'): return 'Friendship'\r\n return 'Danik' if s.count('D')>s.count('A') else 'Anton'\r\nprint(main())", "# def width_cal():\r\n# person_n_height = list(map(int,input().strip().split()))[:2]\r\n# n_person = person_n_height[0]\r\n# height = person_n_height[1]\r\n# list_of_heights = list(map(int,input().strip().split()))[:n_person]\r\n# width = 0\r\n# for person in range(len(list_of_heights)):\r\n# if list_of_heights[person]>height:\r\n# width+=2\r\n# else:\r\n# width+=1\r\n# return width\r\n# print(width_cal())\r\n\r\ndef winer():\r\n num_round = int(input())\r\n winner_list = list(input().upper())\r\n count_A = 0\r\n count_D = 0\r\n for name in winner_list:\r\n if name=='A':\r\n count_A +=1\r\n if name =='D':\r\n count_D +=1\r\n winner = 'Friendship'\r\n if count_A>count_D:\r\n winner = 'Anton'\r\n return winner\r\n if count_A < count_D:\r\n winner = 'Danik'\r\n return winner\r\n return winner\r\nprint(winer())", "n = input()\r\ns = input()\r\n\r\na = 0\r\nd = 0\r\n\r\nfor i in s:\r\n if i == 'A':\r\n a +=1\r\n else:\r\n d +=1\r\n \r\n \r\nif a>d:\r\n print('Anton')\r\nelif a<d:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "count1, count2 = 0, 0\r\na = int(input())\r\nb = input()\r\nfor i in b:\r\n if i == \"A\":\r\n count1 += 1\r\n else:\r\n count2 += 1\r\nif count1 > count2:\r\n print(\"Anton\")\r\nelif count1 == count2:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "n=int(input())\r\ns=input()\r\ncounter=0\r\nfor i in range (n):\r\n if s[i] ==\"A\":\r\n counter +=1\r\n else:\r\n counter -=1\r\n\r\nprint((counter>0)*\"Anton\"+(counter<0)*\"Danik\"+ (counter==0)*\"Friendship\")", "n = int(input())\ns = input()\na = s.count('A')\nd = n - a\nif a > d:\n print(\"Anton\")\nelif a < d:\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "Anton = 0\r\nDanik = 0\r\n\r\n\r\nn = int(input())\r\nline_2 = input()\r\n\r\nfor char in line_2:\r\n if char == \"A\":\r\n Anton += 1\r\n else:\r\n Danik += 1\r\n\r\nif Anton > Danik:\r\n print(\"Anton\")\r\nelif Danik > Anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "t=int(input())\r\ns=(input())\r\nct=int()\r\nc=int()\r\nct=0\r\nc=0\r\nfor i in range(t):\r\n\tif s[i]==\"A\":\r\n\t\tct=ct+1\r\n\telif s[i]==\"D\":\r\n\t\tc=c+1\r\nif ct>c:\r\n\tprint(\"Anton\")\r\nelif c>ct:\r\n\tprint(\"Danik\")\r\nelif c==ct:\r\n\tprint(\"Friendship\")", "n = input()\r\ninp = input()\r\na = 0\r\nd = 0\r\ns = ''\r\n\r\nfor x in inp:\r\n if x == 'A':\r\n a += 1\r\n else:\r\n d += 1\r\n\r\nif a > d:\r\n s = 'Anton'\r\nelif a < d:\r\n s = 'Danik'\r\nelse:\r\n s = 'Friendship'\r\n\r\nprint(s)", "#CodeForce Round 734a Anton and Danik\r\n\r\nn = int(input())/2\r\ndata = input()\r\n\r\nwin = data.count(\"A\")\r\nif win > n:\r\n print(\"Anton\")\r\nelif win < n:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\ncount_a = 0\r\ncount_d = 0\r\nfor i in s:\r\n if i == 'A':\r\n count_a += 1\r\n else:\r\n count_d += 1\r\nif count_a > count_d:\r\n print('Anton')\r\nelif count_d > count_a:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "if __name__ == \"__main__\":\r\n x = int(input())\r\n games = input()\r\n\r\n anton = 0\r\n for i in range(0, x):\r\n if(games[i] == \"A\"):\r\n anton += 1\r\n\r\n if(x % 2 == 0 and x/2 == anton):\r\n print(\"Friendship\")\r\n elif(anton > x - anton):\r\n print(\"Anton\")\r\n else:\r\n print(\"Danik\")", "ca,cd=0,0\r\nn=int(input())\r\na=input()\r\nfor i in a:\r\n if i==\"A\":\r\n ca+=1\r\n else:\r\n cd+=1\r\nif ca==cd:\r\n print(\"Friendship\")\r\nelif ca>cd:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")\r\n", "n=int(input())\r\ns=input()\r\nk=s.count('A')\r\nk1=s.count('D')\r\nif k>k1:\r\n print(\"Anton\")\r\nelif k<k1:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "# A. Anton and Danik\r\nx = input()\r\ny = input()\r\na=0\r\nd=0\r\nfor i in y :\r\n if (i==\"A\"):\r\n a=a+1\r\n else :\r\n d=d+1\r\nif a>d:\r\n print(\"Anton\")\r\nelif d>a :\r\n print(\"Danik\")\r\nelse :\r\n print(\"Friendship\")", "n=int(input())\r\nlis=list(input())\r\na=lis.count('A')\r\nb=lis.count('D')\r\nif a>b:\r\n print(\"Anton\")\r\nelif a<b:\r\n print(\"Danik\")\r\nelif a==b:\r\n print(\"Friendship\")", "z = int(input())\r\ny = input()\r\nanton = 0\r\ndanik = 0\r\nfor i in range(len(y)):\r\n if y[i]=='A':\r\n anton += 1\r\n if y[i]=='D':\r\n danik += 1\r\nif anton > danik:\r\n print('Anton')\r\nif anton < danik:\r\n print('Danik')\r\nif anton == danik:\r\n print('Friendship')", "num = input()\r\n\r\nresults = input()\r\n\r\nwinners = list(results)\r\n\r\n\r\n\r\nif winners.count(\"A\") > winners.count(\"D\"):\r\n print(\"Anton\")\r\nelif winners.count(\"A\") < winners.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\ns = input()\n\ncount1 = 0\ncount2 = 0\n\nfor i in s:\n if i == 'A':\n count1 += 1\n if i == 'D':\n count2 += 1\n\n\nif count1 > count2:\n print(\"Anton\")\nelif count2 > count1:\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "n=input()\r\nm=input()\r\nlst=[]\r\nfor a in m:\r\n lst.append(a)\r\np=lst.count(\"A\")\r\nq=lst.count(\"D\")\r\nif p>q:\r\n print(\"Anton\")\r\nelif q>p:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "import sys\r\ndef I(): return int(sys.stdin.readline().rstrip())\r\ndef LI(): return list(map(int, sys.stdin.readline().rstrip().split()))\r\ndef MI(): return map(int, sys.stdin.readline().rstrip().split())\r\ndef SI(): return sys.stdin.readline().rstrip()\r\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\r\n\r\ndef main():\r\n n = I()\r\n s = SI()\r\n a = s.count('A')\r\n d = s.count('D')\r\n if a > d:\r\n print('Anton')\r\n elif a < d:\r\n print('Danik')\r\n else:\r\n print('Friendship')\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n = int(input())\nstr = input().strip()\na = str.count(\"A\")\nd = str.count(\"D\")\nif (a>d):\n print(\"Anton\")\nelif(d>a):\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "n=int(input())\r\nm=input()\r\na=0\r\nd=0\r\nfor i in range(n):\r\n if m[i]==\"A\":\r\n a+=1 \r\n else:\r\n d+=1 \r\nif a>d:\r\n print(\"Anton\")\r\nelif a==d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "n = int(input()) # Number of games\r\ns = input() # Outcome of each game\r\n\r\n# Count the number of games won by Anton and Danik\r\nanton_wins = s.count('A')\r\ndanik_wins = s.count('D')\r\n\r\n# Compare the counts to determine the winner\r\nif anton_wins > danik_wins:\r\n print(\"Anton\")\r\nelif anton_wins < danik_wins:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "x=int (input())\r\nsum_of_A=0\r\nsum_of_D=0\r\ns=input().upper()\r\nfor i in s:\r\n if i==\"A\":\r\n sum_of_A+=1\r\n elif i==\"D\":\r\n sum_of_D+=1\r\nif sum_of_A>sum_of_D:\r\n print(\"Anton\")\r\nelif sum_of_D>sum_of_A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "n = input()\r\ng = input()\r\nn = int(n)\r\nanton = 0\r\ndanik = 0\r\nfor i in range(n):\r\n if g[i] == \"A\":\r\n anton = anton +1\r\n elif g[i] == \"D\":\r\n danik = danik +1\r\nif anton>danik:\r\n print(\"Anton\")\r\nif anton < danik :\r\n print(\"Danik\")\r\nif anton == danik :\r\n print(\"Friendship\")", "n=int(input())\r\nstr1=input().upper()\r\nstr1=list(str1)\r\nif str1.count('A')>str1.count('D'):\r\n print(\"Anton\")\r\nelif str1.count('A')<str1.count('D'):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "\r\nd=0\r\na=0\r\nv=int(input())\r\nx=input()\r\nfor i in x:\r\n if i==\"D\":\r\n d=d+1\r\n else:\r\n a=a+1\r\nif d==a:\r\n print(\"Friendship\") \r\nelif a>d:\r\n print(\"Anton\") \r\n\r\nelse:\r\n print(\"Danik\") ", "n=int(input())\r\nstroka=input()\r\ncounter1=0\r\ncounter2=0\r\n\r\nfor char in stroka:\r\n if char=='A':\r\n counter1+=1\r\n else:\r\n counter2+=1\r\nif counter1>counter2:\r\n print(\"Anton\")\r\nelif counter2>counter1:\r\n print(\"Danik\")\r\nelse:print(\"Friendship\")", "n = int(input())\r\ns = list(input())\r\nd_c = s.count('D')\r\nd_a = s.count('A')\r\nif d_c > d_a:\r\n print('Danik')\r\nelif d_c < d_a:\r\n print('Anton')\r\nelse:\r\n print('Friendship')", "n=int(input())\r\ns=input()\r\nA=s.count('A')\r\nD=s.count('D')\r\nif(A>D):\r\n print(\"Anton\")\r\nelif(A<D):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = str(input())\r\ncountA = 0\r\ncountD = 0\r\nif len(s) == n:\r\n i = 0\r\n while i < n:\r\n if s[i] == \"A\" or s[i] == \"D\":\r\n if s[i] == \"A\":\r\n countA += 1\r\n if s[i] == \"D\":\r\n countD += 1\r\n i = i + 1\r\n if countA > countD:\r\n print(\"Anton\")\r\n if countA < countD:\r\n print(\"Danik\")\r\n if countA == countD:\r\n print(\"Friendship\")\r\n", "a = int(input())\r\ncounter_1 = 0\r\ncounter_2 = 0\r\na_1 = input()\r\nfor i_1 in a_1:\r\n if \"A\" in i_1:\r\n counter_1 += 1\r\n if \"D\" in i_1:\r\n counter_2 += 1\r\nif counter_1 > counter_2:\r\n print(\"Anton\")\r\nelif counter_2 > counter_1:\r\n print(\"Danik\")\r\nelif counter_1 == counter_2:\r\n print(\"Friendship\")", "from collections import Counter\r\n\r\nn = int(input())\r\ns = input()\r\ncounter = Counter(s)\r\nif counter['A'] > counter['D']:\r\n print('Anton')\r\nelif counter['A'] < counter['D']:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "d=int(input())\r\na = input().upper()\r\nb = 0\r\nc = 0\r\nfor i in range(len(a)):\r\n if a[i] == \"A\":\r\n b += 1\r\n elif a[i] == \"D\":\r\n c += 1\r\nif b > c:\r\n print(\"Anton\")\r\nelif b<c:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\ns = input()\r\ncount_a = 0\r\ncount_d = 0\r\n\r\nfor sym in s:\r\n if sym == \"A\":\r\n count_a += 1\r\n else:\r\n count_d += 1\r\n if count_a > n / 2:\r\n break\r\n if count_d > n / 2:\r\n break\r\n\r\nif count_a > count_d:\r\n print(\"Anton\")\r\nelif count_d > count_a:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "\r\n\r\n\r\ndef i():\r\n return(int(input()))\r\ndef l():\r\n return(list(map(int,input().split())))\r\ndef s():\r\n s = input()\r\n return(s)\r\ndef sl():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef m():\r\n return(map(int,input().split()))\r\n\r\ng = i()\r\nn = s()\r\nf = n.count('A')\r\nv = n.count('D')\r\n\r\nif f > v:\r\n print('Anton')\r\nelif v > f:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\n\r\ns = input()\r\n\r\ndanwins = 0\r\nantwins = 0\r\n\r\nfor i in range(n):\r\n if s[i] == \"D\": danwins += 1\r\n elif s[i] == \"A\": antwins += 1\r\n\r\nif danwins < antwins: print(\"Anton\")\r\nelif danwins > antwins: print(\"Danik\")\r\nelse: print(\"Friendship\")\r\n", "n = int(input())\ns = input()\na = s.count(\"A\")\nd = s.count(\"D\")\nif a > d:\n print(\"Anton\")\nelif d > a:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n\t\t\t\t\t\t\t \t\t \t\t \t \t \t\t", "t=int(input())\r\n\r\na=input()\r\nc=a.count('D')\r\ne=a.count('A')\r\nif c>e:\r\n print(\"Danik\")\r\nelif c<e:\r\n print(\"Anton\")\r\nelif c==e:\r\n print(\"Friendship\") ", "nq=int(input())\r\ns=input()\r\nq1=0\r\nq2=0\r\nfor chr in s:\r\n\tif chr=='A':\r\n\t\tq1+=1\r\n\telif chr=='D':\r\n\t\tq2+=1\r\nif q1>q2:\r\n\tprint(\"Anton\")\r\nelif q2>q1:\r\n\tprint(\"Danik\")\r\nelif q1==q2:\r\n\tprint(\"Friendship\")", "# for _ in range(int(input())):\r\nfrom collections import Counter\r\nn = input()\r\ns = input()\r\nk = Counter(s)\r\nif k['A'] > k['D']:\r\n print(\"Anton\")\r\nelif k['A'] < k['D']:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "# Read the number of games played\r\nn = int(input())\r\n\r\n# Read the outcome string\r\ns = input()\r\n\r\n# Count the number of 'A' and 'D'\r\ncount_A = s.count('A')\r\ncount_D = s.count('D')\r\n\r\n# Compare the counts and determine the result\r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_A < count_D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n = input()\ns = input()\n\ngamesWon = {\n 'A': 0,\n 'D': 0\n}\n\nfor c in s:\n gamesWon[c] += 1\n\nif gamesWon['A'] > gamesWon['D']:\n print('Anton')\nelif gamesWon['A'] < gamesWon['D']:\n print('Danik')\nelse:\n print('Friendship')", "i=int(input())\r\ns=input()\r\nsum=0\r\nfor j in s:\r\n if j==\"A\":\r\n sum+=1\r\n elif j==\"D\":\r\n sum-=1\r\nif sum>0:\r\n print(\"Anton\")\r\nelif sum<0:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "noOfGames = int(input())\r\nwinners = list(input())\r\na_count, d_count = 0, 0\r\nfor i in range(len(winners)):\r\n if winners[i] == \"A\": a_count += 1\r\n else: d_count += 1\r\nif a_count > d_count: print(\"Anton\")\r\nelif d_count > a_count: print(\"Danik\")\r\nelse: print(\"Friendship\")", "x =int(input())\r\ny=input()\r\ncounta = 0\r\ncountd = 0\r\nfor i in y:\r\n if(i == 'A'):\r\n counta += 1\r\n else:\r\n countd += 1\r\nif(counta > countd):\r\n print(\"Anton\")\r\nelif(countd > counta):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "a = int(input())\r\nb = input()\r\ncounta = 0\r\ncountd = 0\r\nfor i in range(len(b)):\r\n if b[i] == 'A':\r\n counta += 1 \r\n else:\r\n countd +=1 \r\nif counta>countd:\r\n print(\"Anton\")\r\nelif countd>counta:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\ns=input()\r\nc=0\r\nd=0\r\nfor i in range(n):\r\n if s[i]==\"A\":\r\n c=c+1 \r\n elif s[i]==\"D\":\r\n d=d+1\r\nif c>d:\r\n print(\"Anton\")\r\nelif c<d:\r\n print(\"Danik\")\r\nelif c==d:\r\n print(\"Friendship\")", "n = int(input())\nresults = input()\nA_counter = results.count('A')\ndifference = n - A_counter\n\nif A_counter > difference:\n print('Anton')\nelif A_counter < difference:\n print('Danik')\nelse:\n print('Friendship')", "x=int(input())\r\nexp=input()\r\nA=0\r\nD=0\r\nfor i in exp:\r\n if(i==\"A\" ):\r\n A+=1\r\n continue\r\n else:\r\n D+=1\r\n continue\r\n\r\nif (A==x/2 and D==x/2):\r\n print(\"Friendship\")\r\nelif(A>x/2):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n=int(input())\r\nstring=input()\r\ncountA=string.count(\"A\")\r\ncountD=string.count(\"D\")\r\nif countA>countD:\r\n print(\"Anton\")\r\nelif countD>countA:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\") \r\n", "n = int(input())\r\nstr1 = str(input())\r\nA = 0\r\nD = 0\r\nfor x in range(len(str1)):\r\n if(str1[x] == 'A'):\r\n A = A + 1\r\n else:\r\n D = D + 1\r\n\r\nif A > D:\r\n print(\"Anton\")\r\nelif D > A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\nl=input()[:n]\r\nif l.count(\"A\")>l.count(\"D\"):\r\n print(\"Anton\")\r\nelif l.count(\"A\")<l.count(\"D\"):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "a = int(input())\r\ns = input()\r\na1, a2 = 0, 0\r\nfor i in s:\r\n if i == 'A':\r\n a1 += 1\r\n elif i == 'D':\r\n a2 += 1\r\nif a1 == a2:\r\n print(\"Friendship\")\r\nelif a1 > a2:\r\n print(\"Anton\")\r\nelif a1 < a2:\r\n print(\"Danik\")", "'''\r\nAuthor : InHng\r\nLastEditTime : 2023-09-13 23:43:20\r\n:)\r\n'''\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\ns = input().strip()\r\nprint(\"Friendship\" if s.count('A') == n / 2 else (\"Anton\" if s.count('A') > n / 2 else \"Danik\"))\r\n", "a=0\r\nb=0\r\nc=int(input())\r\nl=input()\r\nfor i in range(len(l)):\r\n if l[i]=='A':\r\n a+=1\r\n else:\r\n b+=1\r\nif a>b:\r\n print('Anton')\r\nelif b>a:\r\n print('Danik')\r\nelse:\r\n print('Friendship')\r\n", "n=int(input())\r\ns=input()\r\na=0\r\nd=0\r\nfor c in s:\r\n if c =='A':a+=1\r\n else :d+=1\r\nif a>d:\r\n print('Anton')\r\nelif d>a:print('Danik')\r\nelse:\r\n print('Friendship')", "s=int(input())\r\nn=input()\r\na=0\r\nd=0\r\nfor x in range(s):\r\n if n[x]==\"A\":\r\n a+=1\r\n else:\r\n d+=1\r\n\r\nif a>d:\r\n print(\"Anton\")\r\nelif a==d:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")", "n=int(input())\r\na=input()[:n]\r\nc,C=0,0\r\nfor i in a:\r\n if i=='D':\r\n c+=1\r\n else:\r\n C+=1\r\nif C>c:\r\n print(\"Anton\")\r\nif C<c:\r\n print(\"Danik\")\r\nif C==c:\r\n print(\"Friendship\")", "n = int(input())\ns = input()\ndi = 0\nae = 0\nd = 'D'\na = 'A'\nfor i in s:\n if i == d:\n di += 1\n else:\n ae += 1\nif di == ae:\n print('Friendship')\nelif di > ae:\n print('Danik')\nelse:\n print('Anton')\n", "def antonandDanik():\r\n n = int(input())\r\n wonCode = input()\r\n anton = 0 \r\n danik = 0\r\n \r\n for i in range(n):\r\n if wonCode[i] == \"A\":\r\n anton = anton + 1\r\n else:\r\n danik = danik + 1\r\n if anton > danik:\r\n print(\"Anton\")\r\n elif anton < danik:\r\n print(\"Danik\")\r\n else:\r\n print(\"Friendship\")\r\nantonandDanik()", "n=int(input())\r\na=input()\r\ns=a.count(\"A\")\r\nv=a.count(\"D\")\r\nif s>v:print(\"Anton\")\r\nelif s==v:print(\"Friendship\")\r\nelse:print(\"Danik\")\r\n\r\n", "a = int(input())\r\nb = input()\r\n\r\ncount_A = b.count('A')\r\ncount_D = a - count_A\r\n\r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_A < count_D:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "games = int(input())\r\n\r\nwons = input()\r\n\r\nanton = 0\r\n\r\ndanik = 0\r\n\r\nfor won in wons:\r\n if won == \"A\":\r\n anton = anton + 1\r\n elif won == \"D\":\r\n danik = danik + 1\r\n\r\nif anton > danik:\r\n print(\"Anton\")\r\nelif anton < danik:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\") ", "n = int(input())\r\nwinner_list = input()\r\n\r\nwin_dan = winner_list.count(\"D\")\r\nwin_ant = winner_list.count(\"A\")\r\n\r\nif win_dan > win_ant:\r\n print(\"Danik\")\r\nelif win_dan == win_ant:\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Anton\")", "n = int(input())\r\ndata = input()\r\ncount_a = 0\r\ncount_d = 0\r\nfor elem in data:\r\n\tif elem == 'A':\r\n\t\tcount_a += 1\r\n\telse:\r\n\t\tcount_d += 1\r\nif count_a > count_d:\r\n\tprint('Anton')\r\nelif count_a < count_d:\r\n\tprint('Danik')\r\nelse:\r\n\tprint('Friendship')\r\n", "\r\nnumOfTries = int(input())\r\nresult = input()\r\nA_Ctr = 0\r\nD_Ctr = 0\r\n\r\nfor ch in result:\r\n if ch == 'A':\r\n A_Ctr+=1\r\n else:\r\n D_Ctr+=1\r\n \r\nif A_Ctr > D_Ctr:\r\n print(\"Anton\")\r\nelif D_Ctr > A_Ctr:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input(''))\r\na = str(input(''))\r\ns,ss=0,0\r\nfor i in a:\r\n if i=='D':\r\n s+=1\r\n else:\r\n ss+=1\r\nif s==ss:\r\n print('Friendship')\r\nelif s>ss:\r\n print('Danik')\r\nelse:\r\n print('Anton')", "n=int(input())#number of games\r\na=str(input())\r\nm=[]#A\r\nn=[]\r\nfor i in a:\r\n if(i=='A'):\r\n m.append(i)\r\n else:\r\n n.append(i)\r\nif(len(m)>len(n)):\r\n print(\"Anton\")\r\nelif(len(m)==len(n)):\r\n print(\"Friendship\")\r\nelse:\r\n print(\"Danik\")\r\n ", "from collections import Counter\n\ninput()\ncount = Counter(input())\n\nif count['A'] > count['D']:\n print('Anton')\nelif count['A'] < count['D']:\n print('Danik')\nelse:\n print('Friendship')\n\n\n", "n = int(input())\r\ns = input()\r\na_win = 0\r\nfor c in s:\r\n if c == 'A':\r\n a_win += 1\r\nif a_win > n/2:\r\n print('Anton')\r\nelif a_win < n/2:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = input()\r\nk = input()\r\nant = 0\r\ndan = 0\r\nfor h in k:\r\n if h == \"A\":\r\n ant +=1\r\n elif h== \"D\":\r\n dan += 1\r\n\r\nif ant < dan:\r\n print(\"Danik\")\r\nelif ant > dan:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\nchess=list(input())\r\na=chess.count('A')\r\nb=len(chess)-a\r\nif a>b:\r\n ans=\"Anton\"\r\nelif b>a:\r\n ans=\"Danik\"\r\nelse:\r\n ans=\"Friendship\"\r\nprint(ans)", "n = int(input())\r\nL = list(input())\r\nif L.count('A') > L.count('D'):\r\n print('Anton')\r\nelif L.count('A') < L.count('D'):\r\n print('Danik')\r\nelse :\r\n print('Friendship')", "def solve():\r\n n = int(input())\r\n s = input()\r\n a = 0\r\n d = 0\r\n for char in s:\r\n if char == \"A\":\r\n a+=1\r\n else:\r\n d+=1\r\n if a > d:\r\n return \"Anton\"\r\n elif a< d:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n \r\nprint(solve())", "a , b = int(input()) , input()\r\nif b.count('A')>b.count('D'):\r\n print('Anton')\r\nelif b.count('A')<b.count('D'):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "X= int(input())\r\nS=input()\r\nanton=S.count('A')\r\ndanik=S.count('D')\r\nif anton>danik:\r\n print(\"Anton\")\r\nelif danik>anton:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n", "n=int(input())\r\na=input()\r\ncount=0\r\ncount1=0\r\nfor i in range(len(a)):\r\n if a[i]=='A':\r\n count=count+1\r\n if a[i]=='D':\r\n count1=count1+1\r\nif count>count1:\r\n print(\"Anton\")\r\nelif count1>count:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "_ = input()\r\ns = input()\r\na, d = 0, 0\r\nfor i in s:\r\n if i == 'D':\r\n d += 1\r\n else:\r\n a += 1\r\n\r\nif a == d:\r\n print('Friendship')\r\nelif a < d:\r\n print('Danik')\r\nelse:\r\n print('Anton')", "t=int(input())\r\nl=input()\r\nd=l.count(\"D\")\r\na=l.count(\"A\")\r\nif (a==d):\r\n print(\"Friendship\")\r\nelif (a>d):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\ncnt1, cnt2 = 0, 0\r\nfor x in s:\r\n if x == 'A':\r\n cnt1 += 1\r\n else:\r\n cnt2 += 1\r\n\r\nif cnt1 > cnt2:\r\n print('Anton')\r\nelif cnt1 < cnt2:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = input()\ngames = input()\n\nif games.count(\"A\") > games.count(\"D\"):\n print(\"Anton\")\nelif games.count(\"A\") < games.count(\"D\"):\n print(\"Danik\")\nelse:\n print(\"Friendship\")", "rounds = int(input())\r\nwins = list(input().upper())\r\nanton_win = []\r\ndanik_win = []\r\n\r\nfor win in wins:\r\n if win == 'A':\r\n anton_win.append(win)\r\n elif win == 'D':\r\n danik_win.append(win)\r\n\r\nif len(anton_win) == len(danik_win):\r\n print(\"Friendship\")\r\nelif len(anton_win) > len(danik_win):\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "\r\ndef solve(string):\r\n countA = 0\r\n countD = 0\r\n for i in string:\r\n if i == \"A\":\r\n countA += 1\r\n if i == \"D\":\r\n countD += 1\r\n if countA > countD:\r\n return \"Anton\"\r\n if countD > countA:\r\n return \"Danik\"\r\n if countD == countA:\r\n return \"Friendship\"\r\nn = int(input())\r\ns = input()\r\nprint(solve(s))", "count_simvols=int(input())\r\nsimvols=input()\r\ncount_ANTON=0\r\ncount_DANIK=0\r\nfor i in simvols:\r\n if i=='A':\r\n count_ANTON+=1\r\n else:\r\n count_DANIK+=1\r\nif count_ANTON>count_DANIK:\r\n print('Anton')\r\nelif count_DANIK>count_ANTON:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\n\r\ns = input().upper()\r\n\r\nlist_s = list(s)\r\n\r\nAcount = list_s.count('A')\r\nDcount = list_s.count('D')\r\n\r\nif Acount > Dcount:\r\n print('Anton')\r\n exit(0)\r\nelif Acount < Dcount:\r\n print('Danik')\r\n exit(0)\r\nelif Acount == Dcount:\r\n print('Friendship')\r\n exit(0)\r\nelse:\r\n exit(0)", "p=int(input())\r\nq=input()\r\na=0\r\nd=0\r\nfor i in range(len(q)):\r\n if(q[i] == 'A'):\r\n a+=1 \r\n elif(q[i] == 'D'):\r\n d+=1 \r\nif(a > d):\r\n print(\"Anton\")\r\nelif(a < d):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n = int(input())\r\n\r\na = input()\r\n\r\ncount_1 = 0\r\ncount_2 = 0\r\n\r\n\r\nfor s in a:\r\n if s == 'A':\r\n count_1 += 1\r\n else:\r\n count_2 += 1\r\n\r\nif count_1 > count_2:\r\n print('Anton')\r\nelif count_2 > count_1:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n=int(input())\r\ns=input()\r\nc=0\r\nfor i in s:\r\n if i=='A':\r\n c=c+1\r\nk=len(s)-c\r\nif k==c:\r\n print(\"Friendship\")\r\nelif k<c:\r\n print(\"Anton\")\r\nelse:\r\n print(\"Danik\")", "n = int(input())\r\ns = input()\r\nant = 0\r\ndan = 0\r\nfor ch in s:\r\n if ch == 'A':\r\n ant += 1\r\n else:\r\n dan += 1\r\n\r\nif ant > dan:\r\n print('Anton')\r\nelif ant < dan:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n, s = input(), input()\nn_anton, n_danik = s.count(\"A\"), s.count(\"D\")\n\nif n_anton > n_danik:\n print(\"Anton\")\nelif n_anton < n_danik:\n print(\"Danik\")\nelse:\n print(\"Friendship\")\n", "n=int(input())\r\ngame=input()\r\na=game.count(\"A\")\r\nd=game.count(\"D\")\r\nif a>d:\r\n print(\"Anton\")\r\nif a<d:\r\n print(\"Danik\")\r\nif a==d:\r\n print(\"Friendship\")", "a=int(input())\r\ns=input()\r\ncountA=0\r\ncountD=0\r\nfor i in s:\r\n if i==\"A\":\r\n countA+=1\r\n elif i==\"D\":\r\n countD+=1\r\nif countA>countD:\r\n print(\"Anton\")\r\nelif countA<countD:\r\n print(\"Danik\")\r\nelif countA==countD:\r\n print(\"Friendship\")\r\n\r\n", "t = int(input())\r\nx = input()\r\nc=0\r\nc1=0\r\nfor i in range(t):\r\n if (x[i]=='A'):\r\n c=c+1\r\n if (x[i]=='D'):\r\n c1=c1+1\r\nif(c>c1):\r\n print(\"Anton\")\r\nelif(c1>c):\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")\r\n\r\n", "N = int(input())\r\nres = input()\r\ncount_A = res.count('A')\r\ncount_D = res.count('D')\r\nif count_A > count_D:\r\n print(\"Anton\")\r\nelif count_D > count_A:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "def count(text):\r\n num1=0\r\n num2=0\r\n dic={}\r\n for let in text:\r\n if let not in dic:\r\n dic[let]=0\r\n dic[let]+=1\r\n try:\r\n num1=int(dic[\"A\"])\r\n\r\n except :\r\n num1=0\r\n try:\r\n num2=int(dic[\"D\"])\r\n except :\r\n num2=0\r\n\r\n if num1>num2:\r\n return \"Anton\"\r\n elif num1<num2:\r\n return \"Danik\"\r\n else:\r\n return \"Friendship\"\r\n\r\nnum=input()\r\nword=input()\r\nprint(count(word))", "n=int(input())\r\nl=input()\r\nif(l.count('A')>l.count('D')):\r\n print('Anton')\r\nelif(l.count('D')>l.count('A')):\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "# --- Anton And Danik --- #\r\nnumber_games = int(input())\r\ns = input()\r\naw = 0\r\ndw = 0\r\nmid = int((number_games) / 2) + 1 if number_games % 2 else int((number_games) / 2) + 1\r\nfor i in s : \r\n if i == \"A\":\r\n aw += 1\r\n elif i == \"D\":\r\n dw += 1 \r\n if aw > mid :\r\n break\r\n elif dw > mid :\r\n break\r\nif aw == dw :\r\n print(\"Friendship\")\r\nelse :\r\n print(\"Danik\" if dw > aw else \"Anton\") \r\n", "n=int(input())\r\ns=input()\r\nc,c1=0,0\r\nfor i in s:\r\n if i==\"A\":\r\n c+=1\r\n else:\r\n c1+=1\r\nif c>c1:\r\n print(\"Anton\")\r\nelif c1>c:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")", "n=int(input())\r\nl=list(input())\r\na=0\r\nb=0\r\nfor x in range(n):\r\n if l[x]=='A':\r\n a+=1\r\n elif l[x]=='D':\r\n b+=1\r\nif a>b:\r\n print('Anton')\r\nelif a<b:\r\n print('Danik')\r\nelse:\r\n print('Friendship')", "n = int(input())\r\ns = input().lower()\r\n\r\nantwon = 0\r\ndwon = 0\r\n\r\nfor i in range(len(s)):\r\n if s[i] == 'a':\r\n antwon += 1\r\n elif s[i] == 'd':\r\n dwon += 1\r\n\r\nif antwon > dwon:\r\n print(\"Anton\")\r\nelif dwon > antwon:\r\n print(\"Danik\")\r\nelse:\r\n print(\"Friendship\")" ]
{"inputs": ["6\nADAAAA", "7\nDDDAADA", "6\nDADADA", "10\nDDDDADDADD", "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "1\nA", "1\nD", "2\nDA", "4\nDADA", "4\nDAAD", "3\nADD", "3\nDAD", "2\nDA", "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA"], "outputs": ["Anton", "Danik", "Friendship", "Danik", "Anton", "Friendship", "Anton", "Danik", "Friendship", "Friendship", "Friendship", "Danik", "Danik", "Friendship", "Anton"]}
UNKNOWN
PYTHON3
CODEFORCES
731
203a84df1d79d9a67272cb7eb7e52e97
Sale
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Sample Input 5 3 -6 0 35 -2 4 4 2 7 0 0 -7 Sample Output 8 7
[ "n, m = [int(x) for x in input().split(' ')]\r\na = [int(x) for x in input().split(' ') if int(x) < 0]\r\na.sort()\r\nprint(-sum(a[:min(len(a), m)]))\r\n\r\n", "#F\nn, m = [int(x) for x in input().split()]\ntotal = int(0)\na = [int(x) for x in input().split()]\na.sort()\nfor i in range(m):\n if (a[i]<=0):\n total+=a[i]\n else :\n break\nprint(total*-1)\n \t \t \t\t\t\t\t\t\t\t \t \t \t \t", "n,m=list(map(int,input().split()))\r\nlis=list(map(int,input().split()))\r\nlis.sort()\r\nsum=0\r\nfor i in range(m):\r\n if(lis[i]<0):\r\n sum=sum+lis[i]\r\n\r\nprint(abs(sum))", "\r\n(n,m) = tuple(map(int,input().strip().split(' ')))\r\na = list(map(int,input().strip().split(' ')))\r\na.sort()\r\nsums=0\r\ni=0\r\nwhile(i<m and a[i]<0):\r\n sums+=a[i]\r\n i+=1\r\nprint(-sums) \r\n", "n,m = list(map(int,input().split()))\nl = list(map(int,input().split()))\nl.sort()\nmoney_earned = 0\nfor i in range(0,m):\n\tif(l[i]<0):\n\t\tmoney_earned-=l[i]\nprint(money_earned)", "n, m = map(int, input().split())\r\na = sorted(list(map(int, input().split())))\r\nres = 0\r\nfor i in range(m):\r\n if a[i] < 0:\r\n res += abs(a[i])\r\n else:\r\n break\r\nprint(res)\r\n\r\n", "n, m = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split()]\r\na = list(sorted(a))\r\nans = 0\r\nfor i in range(n):\r\n if a[i] < 0 and m != 0:\r\n ans += a[i]\r\n m -= 1\r\nprint(abs(ans))", "n, m = map(int, input().split())\na = list(map(int, input().split())) \na = sorted(a)\nprint(sum(-a[i] for i in range(m) if a[i]<=0))", "n = list(map(int, input().split()))\r\ntvs = sorted(list(map(int, input().split())))\r\nnegs = [num for num in tvs if num < 0]\r\nprint(0 - sum(negs[:n[1]]))\r\n", "n,m= map(int, input().split())\r\nl= list(map(int, input().split()))\r\nl.sort()\r\nr= [x for x in l if x<0]\r\nif len(r)>m:\r\n ans= sum(l[:m])\r\n print(abs(ans))\r\nelse:\r\n print(abs(sum(r)))", "n,m = map(int,input().split())\r\nlst = list(map(int,input().split()))\r\nlst = sorted(lst)\r\nc=0\r\nfor i in range(m):\r\n if lst[i]<=0:\r\n c+=abs(lst[i])\r\n else:\r\n break\r\nprint(c)\r\n\r\n\r\n# 1495\r\n# 6 6\r\n# 756 -611 251 -66 572 -818\r\n", "n, m = [int(_) for _ in input().split()]\r\ntv_sets = [int(_) for _ in input().split()]\r\ntv_sets.sort()\r\n\r\nearnings = 0\r\nfor tv in tv_sets[:m]:\r\n earnings = min(earnings, earnings + tv)\r\n\r\nprint(-earnings)\r\n", "n,m = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\nsu = 0\r\nfor i in range(m):\r\n if(a[i]<=0):\r\n su += abs(a[i])\r\n else:\r\n break\r\nprint(su)", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nsum = 0\r\ncount = 0\r\nfor i in range(n):\r\n if count == m:\r\n break\r\n else:\r\n if a[i] < 0:\r\n sum += abs(a[i])\r\n count += 1\r\n\r\nprint(sum)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na = sorted(a)\r\nsuma = 0\r\nfor i in range(n):\r\n if (a[i] < 0) and m:\r\n suma += abs(a[i])\r\n m -= 1\r\nprint(suma)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "_, m = map(int, input().split())\r\n\r\nprices = sorted(list(map(int, input().split())))[:m]\r\nans = sum(i for i in prices if i<=0)\r\nprint(ans*-1)\r\n\r\n", "sets, m = map(int, input().split())\n\ntvs = list(map(int, input().split()))\n\ntvs = [num for num in tvs if num <= 0]\ntvs.sort()\nresponse = -1 * sum(tvs[:m])\n\nprint(response)\n\t \t\t \t \t\t \t\t\t \t \t\t \t \t \t \t", "n, m = map(int, input().split())\r\nl = sorted(list(map(int, input().split())))\r\ncount = 0\r\nfor i in range(n):\r\n if l[i] < 0:\r\n count += abs(l[i]); m -= 1\r\n else:\r\n break\r\n if m == 0:\r\n break\r\nprint(count)", "n, m = map(int, input().split())\r\nprint(-sum(sorted(map(lambda x: int(x) if x[0] == '-' else 0, input().split()))[:m]))\r\n", "a,b = map(int,input().split())\nx=list(map(int,input().split()))\nx.sort()\ns = 0\nfor i in range(b):\n if x[i]<=0:\n s-=x[i]\n else:\n break\nprint(s)", "n,m=map(int,input().split())\r\nl=list(sorted(map(int,input().split())))\r\nans=0\r\nfor i in range(m):\r\n if l[i]<=0:\r\n ans+=abs(l[i])\r\nprint(ans)\r\n \r\n", "\r\n\r\n\r\ndef sale():\r\n\r\n\r\n number_of_tvs_for_sale,amount_bob_can_carry = map(int,input().split())\r\n\r\n prices = list(map(int,input().split()))\r\n\r\n\r\n prices.sort()\r\n\r\n\r\n count = i = money_earned = 0 \r\n while i < len(prices) and prices[i] < 0 and count < amount_bob_can_carry:\r\n money_earned += abs(prices[i])\r\n count += 1\r\n i += 1\r\n\r\n\r\n \r\n print(money_earned)\r\n\r\n\r\nsale()\r\n", "n,m=[int(i) for i in input().split()]\r\nprice=[int(i)*(-1) for i in input().split()]\r\nlst=[]\r\nfor i in price:\r\n\tif i>0:\r\n\t\tlst.append(i)\r\n\r\nlst.sort(reverse=True)\r\ns=0\r\nfor i in range(min(len(lst),m)):\r\n\ts+=lst[i]\r\nprint(s)\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nsum1=0\r\nk=1\r\ni=0\r\nl.sort()\r\nwhile(k<=m and i<len(l)):\r\n if(l[i]<0):\r\n sum1=sum1+l[i]\r\n k+=1\r\n i+=1\r\n \r\nif(sum1<=0):\r\n print(-sum1)\r\n\r\n", "n, m= map(int, input().split())\r\nx= input().split()\r\nx= [int(i) for i in x]\r\nx.sort()\r\nsum=0\r\nfor i in range(m):\r\n if x[i]<=0:\r\n sum-=x[i]\r\n else:\r\n break\r\nprint(sum)", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nans=0\r\nfor _ in range(m):\r\n if arr[_]<0:\r\n ans+=arr[_]\r\n else:\r\n break\r\nprint(-ans)", "n, m = map(int, input().split())\r\nt = list(map(int, input().split()))\r\nt.sort()\r\ns = 0\r\nfor i in range(m):\r\n if t[i] >= 0: break\r\n s -= t[i]\r\nprint(s)", "# https://codeforces.com/problemset/problem/34/B\r\n\r\nn, m = [int(x) for x in input().split()]\r\narr = [int(x) for x in input().split()]\r\n\r\narr.sort()\r\nresult = 0\r\n# print(abs(sum(arr[:m])))\r\n\r\nfor i in range(m):\r\n if arr[i] > 0:\r\n pass\r\n else:\r\n result += arr[i]\r\n\r\nprint(abs(result))\r\n", "\r\nn,m = map(int,input().split())\r\n\r\nam = list(map(int,input().split()))\r\n\r\nans = 0\r\nam.sort()\r\ncnt = 0\r\nfor i in am :\r\n if cnt<m :\r\n \r\n \r\n if i<0 :\r\n ans += abs(i)\r\n cnt += 1 \r\n else :\r\n break\r\n \r\n \r\n \r\nprint(ans)", "n,m=map(int,input().split())\r\nli = list(map(int,input().split()))\r\nli.sort()\r\ni,su = int(),0\r\nwhile True:\r\n\tif i < m and li[i] < 0:su += li[i]\r\n\telse:break\r\n\ti+=1 \r\nprint(abs(su))", "n,m = map(int,input().split())\r\na = sorted([x for x in map(int,input().split()) if x < 0])\r\nprint(-sum(a[:m]))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nsum=0\r\nfor i in range(0,m,1):\r\n if a[i]<=0:\r\n sum=sum+-1*a[i]\r\nprint(sum)", "__author__ = 'X230874'\r\n\r\nlen,m = input().split()\r\n\r\narr = input()\r\na = list(map(int,arr.split()))\r\n\r\na.sort()\r\n#print(a)\r\ntotal = int(0)\r\nfor x in range(int(m)):\r\n if(a[x] <=0):\r\n total += abs(a[x])\r\n\r\nprint(total)\r\n", "n, m = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nresult = []\r\ncount = 0\r\n\r\nfor i in range(m):\r\n x = min(lst)\r\n if x <= 0:\r\n lst.remove(x)\r\n result.append(x)\r\n else:\r\n break\r\n \r\nfor i in result:\r\n count -= i\r\n \r\nprint(count)\r\n ", "nn=[int(i) for i in input().split()]\r\nyy=[int(i) for i in input().split()]\r\nyy.sort()\r\nk=yy[:nn[1]]\r\nm1=-sum(k)\r\nm2=0\r\nfor y in k:\r\n if y<0:\r\n m2-=y\r\n\r\nif m1>m2:\r\n print(m1)\r\nelse:\r\n print(m2)", "n,m= map(int,input().split())\narr = list(map(int,input().split()))\narr.sort()\ncount =0\ni =0 \nwhile(i<m):\n if(arr[i]>=0):\n break\n count+=arr[i]\n i+=1\nprint(abs(count))\n", "\"\"\"\r\n~~ author : dokueki\r\n~~ created : 11~05~2020\r\n\"\"\"\r\n\r\nimport sys\r\nINT_MAX = sys.maxsize\r\nINT_MIN = -(sys.maxsize)-1\r\nsys.setrecursionlimit(10**7)\r\nmod = 1000000007\r\n\r\n\r\ndef IOE():\r\n sys.stdin = open(\"input.txt\", \"r\")\r\n sys.stdout = open(\"output.txt\", \"w\")\r\n\r\n\r\ndef main():\r\n n, m = map(int, sys.stdin.readline().split())\r\n a = list(map(int, sys.stdin.readline().split()))\r\n a.sort()\r\n neg = 0\r\n for i in a:\r\n if i < 0:\r\n neg += 1\r\n print(abs(sum(a[:min(neg, m)])))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n try:\r\n IOE()\r\n except:\r\n pass\r\n main()\r\n", "n,m = map(int,input().split())\r\ntv = list(map(int,input().split()))\r\ntv.sort() #由低到高排序\r\ntv_2 = []\r\nfor i in tv :\r\n if i <= 0 :\r\n tv_2.append(i)\r\ns = 0 - sum(tv_2[:m]) #m实为m-1\r\nprint(s)", "n,m = map(int,input().split())\r\nl=list(map(int,input().split()))[:n]\r\ns=0\r\nl.sort()\r\nfor i in range(m):\r\n if l[i]<=0:\r\n s+=abs(l[i])\r\nprint(s)\r\n", "m = int(input().split()[1])\r\nnum = input().split()\r\nfor i, elem in enumerate(num):\r\n num[i] = int(elem)\r\nnum.sort()\r\nmax = 0\r\nfor i in range(0, m):\r\n if(num[i] < 0):\r\n max += num[i]*(-1)\r\nprint(max)\r\n", "length, carry = input().split()\r\nprices = sorted(list(map(int, input().split())))\r\nprices = list(map(lambda x : -x, prices))\r\nprices = [i for i in prices if i >0]\r\nprint(sum(prices[:int(carry)]))\r\n", "n, m = map(int,input().split())\r\npr = list(map(int,input().split()))\r\npr.sort()\r\nval = pr[:m]\r\nsu = 0\r\nfor i in val:\r\n if i < 0:\r\n su = su + abs(i)\r\nprint(su)", "n, m = map(int, input().split())\na = sorted([i for i in map(int, input().split()) if i < 0])\nprint(- sum(a[: min(len(a), m)]))", "inp1 = input().split()\r\nn = int(inp1[0])\r\nm = int(inp1[1])\r\ninp = input().split()\r\ninp = [int(x) for x in inp]\r\ninp.sort()\r\nout = 0\r\nfor i in range(m):\r\n if inp[i]>0:\r\n break\r\n else:\r\n out+=inp[i]\r\nprint(-1*out)\r\n", "k,m = map(int,input().split(\" \"))\r\nl = list(map(int,input().split(\" \")))\r\ns = []\r\nfor i in range(m):\r\n if(min(l)<0):\r\n s.append(min(l))\r\n l.remove(min(l))\r\n else:\r\n if(not s):\r\n s.append(0)\r\n break\r\nif(sum(s)<0):\r\n print(sum(s)*-1)\r\nelse:\r\n print(sum(s))", "n,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nl.sort()\r\nsum1 = 0\r\nfor i in range(m):\r\n\tif(l[i]>=0):\r\n\t\tbreak\r\n\telse:\r\n\t\tsum1+=l[i]\r\nprint(abs(sum1))", "n,k = map(int,input().split())\r\nl = sorted(list(map(int,input().split())))\r\ns = 0\r\nfor i in range(n):\r\n if l[i]>0:\r\n l[i]=0\r\nfor i in range(k):\r\n s += (0-l[i])\r\nprint(s)", "L = input()\r\nL = L.split()\r\nn = int(L[0])\r\nm = int(L[1])\r\nP = input()\r\nP =P.split()\r\nfor k in range (n):\r\n P[k]=int(P[k])\r\nP.sort()\r\nc = 0\r\nfor k in range(m):\r\n if P[k]<0:\r\n c+= P[k]\r\n\r\nprint(-1*c)\r\n", "m_n=list(map(int,input().split()))\r\nnumbers=list(map(int,input().split()))\r\nnumbers.sort()\r\n \r\nsummation=0\r\nfor i in range(m_n[1]):\r\n\tif(numbers[i]<0):\r\n\t\tsummation=summation+numbers[i]\r\nprint(abs(summation))", "n, m = map(int, input().split())\r\nls = list(map(int, input().split()))\r\n\r\nls.sort()\r\nres = 0\r\nfor i in range(m):\r\n if ls[i] <= 0:\r\n res += ls[i]\r\n\r\nprint(abs(res))", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort()\r\nans = 0\r\nfor i in range(len(a)):\r\n if a[i] < 0:\r\n ans += a[i]\r\n m -= 1\r\n if m == 0:\r\n break\r\nprint(-1 * ans)", "n,m=map(int,input().split())\r\narr=[int(x) for x in input().split()]\r\narr.sort()\r\nsum=0\r\nfor i in range(m):\r\n if arr[i]>=0:\r\n break\r\n else:\r\n sum+=arr[i]\r\nprint(-sum)", "def f():\r\n\tA = list(map(int,input().split()))\r\n\tB = list(map(int,input().split()))\r\n\r\n\tB.sort()\r\n\tans = 0\r\n\tfor i in range(0,len(B)):\r\n\t\tif(i==A[1]):\tbreak\r\n\t\tif(B[i]>0):\tbreak\r\n\t\tans = ans +B[i]\r\n\r\n\tprint(abs(ans))\r\n\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n\tf()", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\narr.sort(reverse=False)\r\nsum=0\r\nsum1=0\r\nfor i in range(0,m):\r\n if(arr[i]<0):\r\n sum+=abs(arr[i])\r\n else:\r\n break\r\nprint(sum)", "n,m=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nx.sort()\r\ns=0\r\nr=0\r\nfor i in x:\r\n if i<0:\r\n if r<m:\r\n s+=abs(i)\r\n r+=1\r\nprint(s)\r\n", "n,m = (int(i) for i in input().split())\r\na = list(map(int, input().strip().split()))[:n]\r\na.sort()\r\nearn =0\r\ni = 0\r\n#print(a)\r\nwhile(m>0 and i<len(a)):\r\n #print(earn)\r\n if(a[i]<0):\r\n earn += a[i]\r\n\r\n m-=1\r\n i+=1\r\n else:\r\n break\r\nprint(abs(earn))\r\n", "n,m=map(int,input().split())\r\nnums=[int(x) for x in input().split()]\r\nnums.sort()\r\ncount=0\r\nfor i in range(m):\r\n if nums[i]<0:\r\n count+=abs(nums[i])\r\nprint(count)", "#34B (34no. Problem B)\r\nn,m = map(int,input().split())\r\nprice = sorted(list(map(int,input().split())))\r\n# print(price)\r\ntotal = 0\r\nfor i in range(m):\r\n if (price[i] <= 0):\r\n total+= price[i]\r\n else:\r\n break \r\nprint(abs(total)) ", "n, m = [int(x) for x in input().split()]\r\na = [int(x) for x in input().split()]\r\na = [x for x in a if x <= 0]\r\na.sort()\r\nprint(sum(a[:min(m, len(a))])*-1)", "n, m = map(int,input().split())\r\na = list(map(int, input().split(' ')[:n]))\r\na.sort()\r\ns = 0\r\nfor i in range(m):\r\n if a[i]<0:\r\n s = abs(a[i])+s\r\nprint(s)\r\n", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\nnegative_prices = sorted([p for p in prices if p < 0])\r\nprint(-sum(negative_prices[:m]))", "n,m = map(int,input().split())\r\nli = list(map(int,input().split()))\r\nli.sort()\r\ns = 0\r\nfor i in range(m):\r\n if li[i]<=0:\r\n s+=abs(li[i])\r\nprint(s)\r\n", "input=__import__('sys').stdin.readline\r\nn,m=map(int,input().split())\r\nlis=list(map(int,input().split()))\r\nultv=[]\r\nfor i in lis:\r\n if i<0:\r\n ultv.append(i)\r\nultv.sort()\r\nans=sum(ultv[:m])\r\nprint(ans*-1)", "n, m = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\nsorteda = sorted(a)\r\ncount = 0\r\nfor i in range(m):\r\n if sorteda[i] < 0:\r\n count -= sorteda[i]\r\n\r\nprint(count)", "n,m=list(map(int,input().split()))\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nc=0\r\nfor i in range(min(m,n)):\r\n\tif(arr[i]>=0):\r\n\t\tbreak\r\n\tc-=arr[i]\r\nprint(c)", "n, m = map(int, input().split())\r\nans = int(0)\r\nfor x in sorted(map(int, input().split()))[:m]:\r\n if x < 0:\r\n ans -= x\r\n else:\r\n break\r\nprint(ans)", "n,m = map(int,input().split())\r\np = list(map(int,input().split())) \r\np.sort() \r\ntot = 0\r\nfor i in range(m):\r\n if p[i] < 0:\r\n tot+=p[i]\r\n else:\r\n break\r\n\r\n\r\nprint(-1*tot)\r\n", "from sys import stdin\r\n\r\ndef genera(m):\r\n x= []\r\n for i in range(len(m)):\r\n if m[i] <= 0:\r\n x.append(m[i])\r\n return x\r\n\r\ndef sort(n):\r\n x= []\r\n c= len(n)\r\n while c!= 0:\r\n z= []\r\n for i in range(c):\r\n y= 0\r\n for j in range(c):\r\n if n[i]<= n[j]:\r\n y+= 0\r\n else:\r\n y+=1\r\n if y == 0:\r\n z.append(n[i])\r\n else: n= n\r\n x.append(int(str(set(z))[1:-1]))\r\n n.remove(int(str(set(z))[1:-1]))\r\n c-=1\r\n return x\r\n \r\ndef sumar(o,n):\r\n z= 0\r\n o= sort(o)\r\n if len(o)>n[1]:\r\n for i in range(n[1]):\r\n z+= o[i]\r\n else:\r\n for i in range(len(o)):\r\n z+= o[i]\r\n print(z*-1)\r\n \r\ndef main():\r\n n= [int(x) for x in stdin.readline().strip().split()]\r\n m= [int(x) for x in stdin.readline().strip().split()]\r\n sumar(genera(m),n)\r\nmain()\r\n\r\n", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\n\r\nprices.sort()\r\n\r\nearnings = 0\r\nfor i in range(m):\r\n if prices[i] < 0:\r\n earnings += abs(prices[i])\r\n\r\nprint(earnings)\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort()\r\nsm = 0\r\ni = 0\r\nwhile m > 0 and a[i] < 0:\r\n sm += a[i]\r\n m -= 1\r\n i += 1\r\nprint(sm * -1)\r\n", "n,m=[int(i) for i in input().split()]\r\nnums=[int(i) for i in input().split() if int(i)<0]\r\nnums.sort()\r\nif m<n:\r\n\tprint(-1*sum(nums[:m]))\r\nelse:\r\n\tprint(-1*sum(nums))", "x, n = list(map(int, input().split()))\n\nq = list(map(int, input().split()))\n\nq.sort(reverse=True)\n\nans = 0\nwhile n > 0:\n nextt = q.pop()\n if nextt >= 0: break\n ans += nextt\n n -= 1\n\nprint(abs(ans))", "# your code goes here\r\nn,m=[int(x) for x in input().split()]\r\nvar=[int(x) for x in input().split()]\r\nvar=sorted(var)\r\nmaxi=0\r\nsum=0\r\nfor i in range(0,m):\r\n\tsum+=var[i]\r\n\t#print(sum)\r\n\tmaxi=max(maxi,0,(sum*-1))\r\nprint(maxi)\r\n\t", "n, m = map(int, input().split())\n\na = list(map(int, input().split()))\n\na = sorted(filter(lambda x: x <= 0, a))\n\na = list(map(abs, a))\n\nprint(sum(a[:m]))\n\n\n\n", "n,m=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nprint(abs(sum([i for i in a if i<0]))if len([i for i in a if i<0])<=m else abs(sum(a[:m])))\r\n\r\n\r\n", "n, m = map(int, input().split())\r\nli = sorted(list(map(int, input().split())))\r\nans = 0\r\n\r\nfor i in li:\r\n if m > 0:\r\n if i < 0:\r\n ans += (-i)\r\n m -= 1\r\n else:\r\n break\r\nprint(ans)\r\n", "n,m = tuple([int(item) for item in input().split()])\r\nlst = [int(item) for item in input().split()]\r\nneg = [item for item in lst if item<0]\r\nif len(neg)==0:\r\n print(0)\r\nelif len(neg)<=m:\r\n print(abs(sum(neg)))\r\nelse:\r\n neg.sort()\r\n while(len(neg)!=m):\r\n neg.pop()\r\n print(abs(sum(neg)))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na=sorted(a)\r\ncost=0\r\nfor i in range(n):\r\n if a[i]>0:\r\n break\r\n elif i>m-1:\r\n break\r\n else:\r\n cost+=(-a[i])\r\nprint(cost)\r\n", "n,m=list(map(int,input().split()))\narray=list(map(int,input().split()))\narray.sort()\nprofit=0\nfor i in range(m):\n\tif array[i]>0:\n\t\tbreak\n\tprofit+=array[i]\n\nprint(-1*profit)", "a=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nn=[x for x in b if x<0]\r\nif(len(n)==0):\r\n print('0')\r\nelse:\r\n n.sort()\r\n if(a[1]>=len(n)):\r\n print(-1*(sum(n)))\r\n else:\r\n c=0\r\n for i in range(a[1]):\r\n c+=n[i]\r\n print(-1*c)\r\n\r\n \r\n", "n=int(input().split()[-1])\r\nprint(-sum(sorted(map(lambda x:min(int(x),0),input().split()))[:n]))", "a, b = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nlst = [x for x in lst if x <= 0]\r\nlst.sort()\r\nprint(-sum(lst[0:b]))\r\n", "# LUOGU_RID: 106921485\nt = [int(x) for x in input().split()]\r\nm = t[1]\r\nv = [int(x) for x in input().split()]\r\nv.sort()\r\nans = 0\r\nfor i in range(m):\r\n if v[i] < 0:\r\n ans -= v[i]\r\nprint(ans)\r\n", "n, m = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nls = []\r\nsm = 0\r\nj = 0\r\nfor i in lst:\r\n if i < 0:\r\n ls.append(i)\r\nls.sort()\r\nprint(abs(sum(ls[0:m])))", "t = input().split()\nn = int(t[0])\nm = int(t[1])\n\ns = [int(x) for x in input().split()]\ns.sort()\n\ncount = 0\nans = 0\nfor i in s:\n\tif count == m:\n\t\tbreak\n\tif i < 0:\n\t\tans += abs(i)\n\t\tcount +=1\n\tif i > 0:\n\t\tbreak\nprint(ans)\n", "x=input().split()\r\nx=list(map(int,x))\r\nl=input().split()\r\nl=list(map(int,l))\r\n\r\n\r\nsum=0\r\n\r\nwhile(x[1]!=0):\r\n m=l[0]\r\n for i in range(len(l)):\r\n if(l[i]<m):\r\n m=l[i]\r\n if(m<=0):\r\n sum-=m\r\n else:\r\n break\r\n l.remove(m)\r\n\r\n x[1]-=1\r\n\r\nprint(sum)\r\n \r\n \r\n", "n, m = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\na = sorted(filter(lambda x: x < 0, a))[:m]\r\nprint(-sum(a))\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef list_input():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef float_compare(a, b):\r\n if abs(a-b) < float(1e-9):\r\n return True\r\n else:\r\n return False\r\n\r\n\r\ndef sub_mod(x, mod):\r\n x = x % mod\r\n if x < 0:\r\n x += mod\r\n return x\r\n\r\n\r\ndef divisor(n):\r\n i = 1\r\n dv = []\r\n while i*i <= n:\r\n if n % i == 0:\r\n dv.append(i)\r\n if i*i != n:\r\n dv.append(n//i)\r\n i += 1\r\n\r\n return dv\r\n\r\n\r\n#l = list_input()\r\n# print(divisor(25))\r\n# print(divisor(18))\r\n# print(float(1e-9))\r\nn, m = map(int, input().split())\r\n\r\nl = sorted(list_input())\r\nearn = 0\r\ni, j = 0, 0\r\n\r\nwhile i < len(l) and m:\r\n if l[i] < 0:\r\n earn -= l[i]\r\n m -= 1\r\n i += 1\r\nprint(earn)\r\n", "n,m = map(int,input().split())\r\nprice = list(map(int,input().split()))\r\n\r\nprice.sort()\r\n\r\nsumArr = []\r\nsumArr.append(price[0])\r\nfor i in range(1,n):\r\n sumArr.append(sumArr[i-1]+price[i])\r\n\r\n#print(price)\r\n#print(sumArr)\r\n\r\n\r\nminVal = float(\"inf\")\r\nfor j in range(m):\r\n minVal = min(minVal,sumArr[j])\r\n\r\nif minVal<0:\r\n print(abs(minVal))\r\n\r\nelse:\r\n print(0)\r\n \r\n\r\n\r\n\r\n'''\r\n\r\nif maxSum<0:\r\n print(abs(maxSum))\r\n\r\nelse:\r\n print(0)\r\n\r\n'''\r\n \r\n", "n,k=list(map(int,input().split()))\r\np=list(map(int,input().split()))\r\nla=[]\r\nfor item in p:\r\n if item<0:\r\n la.append(item)\r\n else:\r\n pass\r\nif la==list():\r\n print(0)\r\nelse:\r\n la.sort()\r\n print(abs(sum(la[0:k])))", "n, m = map(int, input().strip().split())\narr = list(map(int, input().strip().split()))\narr.sort()\nc = 0\ns = 0\nfor i in arr:\n\tif i < 0:\n\t\tif c == m:\n\t\t\tbreak\n\t\ts += i*-1\n\t\tc += 1\nprint(s)\n", "# Wadea #\r\n\r\nn,m = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nmax1 = 0\r\nfor j in range(m):\r\n if arr[j] < 0:\r\n max1 += abs(arr[j])\r\nprint(max1) ", "#URL - https://codeforces.com/problemset/problem/34/B\n\na=input().split()\nn=int(a[0])\nm=int(a[1])\ns=input().split()\ns=[int(x) for x in s]\ns.sort()\nsum=0\nfor x in range(m):\n if(s[x]<0):\n sum+=s[x]\n else:\n break\nprint(abs(sum))\n", "a=input().split()\r\nn=int(a[0])\r\nm=int(a[1])\r\nN=input().split()\r\nM=[]\r\nfor x in N:\r\n if '-' in x:\r\n M.append(int(x))\r\nM.sort()\r\nif m>=len(M):\r\n print(-sum(M))\r\nelif m<len(M):\r\n print(-sum(M[:m]))", "if __name__ == '__main__':\r\n n, m = map(int, input().split())\r\n a = sorted(list(map(int, input().split())))\r\n\r\n ans = 0\r\n for i in range(min(m, len(a))):\r\n if a[i] < 0:\r\n ans -= a[i]\r\n else:\r\n break\r\n\r\n print(ans)\r\n", "n,m = map(int,input().split())\r\nlst = list(map(int,input().split()))\r\nlst.sort()\r\not = 0\r\nfor i in range(m):\r\n if lst[i] < 0:\r\n ot -= lst[i]\r\n else:\r\n break\r\nprint(ot)", "n, m = map(int, input().split())\r\ntv = [int(i) for i in input().split()]\r\ntv.sort(reverse=False)\r\nprofit = 0\r\ncount = 0\r\nfor i in range(m):\r\n if tv[i] < 0 and count != m:\r\n profit += tv[i]\r\n count += 1\r\n\r\nprint(abs(profit))", "nm = input().split()\r\nn = int(nm[0])\r\nm = int(nm[1])\r\na = sorted([int(i) for i in input().split()])\r\nans = 0\r\ni = 0\r\nwhile i < n and a[i] < 0 and m > 0:\r\n ans -= a[i]\r\n i += 1\r\n m -= 1\r\nprint(ans)\r\n", "n,m=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nans=0\r\nl.sort()\r\nfor i in range(m):\r\n if l[i]>=0:\r\n break\r\n else:\r\n ans+=abs(l[i])\r\nprint(ans)", "if __name__ == '__main__':\r\n n, m = str(input()).split()\r\n line = str(input()).split()\r\n line = [int(it) for it in line]\r\n line.sort()\r\n res = 0\r\n for i in range(int(m)):\r\n if line[i] < 0:\r\n res -= line[i]\r\n else:\r\n break\r\n print(res)\r\n", "n,m=input().split()\r\nl1=list(map(int,input().split()))\r\nl1.sort()\r\nsum=0\r\nfor i in l1[:int(m)]:\r\n if(i < 0):\r\n sum+=i\r\n else:\r\n break\r\nprint(sum*(-1))", "inp=lambda:map(int,input().split())\nn, m = inp()\na = list(inp())\n\nsr = sorted(a)\ntotal = 0\n\nfor i in range(m):\n if sr[i]<0:\n total += sr[i]\n \nprint(-total)\n\n\t\t \t \t\t \t \t \t\t\t\t \t\t\t\t \t", "class Code:\r\n def __init__(self):\r\n self.n, self.m = list(map(int, input().split()))\r\n self.arr = list(map(int, input().split()))\r\n\r\n def process(self):\r\n self.arr.sort()\r\n earn = 0\r\n for i in range(self.m):\r\n if self.arr[i] <= 0:\r\n earn += -self.arr[i]\r\n print(earn)\r\n\r\n\r\nif __name__ == '__main__':\r\n code = Code()\r\n code.process()\r\n", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\narr.sort()\r\n\r\ntotal = 0\r\n\r\nfor i in range(n):\r\n if arr[i] < 0 and m > 0:\r\n total += arr[i] * -1\r\n m -= 1\r\n else:\r\n break\r\n\r\nprint(total)", "mn = input()\r\nms = mn.split(' ')\r\nm, n = int(ms[0]), int(ms[1])\r\nsale = input()\r\nsales = sale.split(' ')\r\ns = [int(i) for i in sales]\r\ns = sorted(s)\r\nbuy = s[:n]\r\nv = [j for j in buy if j < 0]\r\nvl = sum(v) * -1\r\nprint(vl)", "import sys\nfrom os import path\n\nif (path.exists('input.txt')):\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\n\n# def solve():\n# \tt = int(input())\n# \tfor _ in range(t):\n# \t\tn,h = input().split(\" \")\n# \t\tn=int(n)\n# \t\th=int(h)\n# \t\ta=list(map(int, input().split(\" \")))\n# \t\ta = sorted(a)\n# \t\t#print(a[-1])\n# \t\tans=0\n# \t\tif (a[-1]>h):\n# \t\t\tprint(1)\n# \t\telse:\n\t\t\t\n# \t\t\tprint(ans)\n\t\t# print(type(n))\n\t\t# print(type(c))\n\t\t# print(type(s))\n\ndef solven():\n\t#n,t = map(int, input().split(\" \"))\n\tn,m = map(int, input().split())\n\tarr = list(map(int, input().split()))\n\tarr = sorted(arr)\n\tans = 0\n\tfor i in arr:\n\t\tif (m>0):\n\t\t\tif (i<0):\n\t\t\t\tm-=1\n\t\t\t\tans+=abs(i)\n\t\t\telse:\n\t\t\t\tbreak\n\t\telse:\n\t\t\tbreak\n\tprint(ans)\n\n\n\nif __name__ == \"__main__\":\n\tsolven()\n", "num, total = map(int, input().split())\r\nx = [int(i) for i in input().split()]\r\nx.sort()\r\nresult = 0\r\nfor i in range(total):\r\n\tif x[i] >= 0:\r\n\t\tbreak\r\n\telse:\r\n\t\tresult += x[i]\r\n \r\nprint(abs(result))", "n,m = [int(i) for i in input().split()]\r\nlis = [int(i) for i in input().split()]\r\nlis.sort()\r\nz = 0\r\nsumma = 0\r\nwhile lis[z] < 0 and m >0:\r\n summa += lis[z]\r\n z += 1\r\n if z+1>len(lis):\r\n break\r\n m-=1\r\nprint(-summa)", "n,m = map(int,input().split(' '))\r\nls = list(map(int,input().split()))\r\nls.sort()\r\nsm = 0\r\nfor i in range(m):\r\n if ls[i] < 0:\r\n sm = sm+(ls[i]*-1)\r\nprint(sm)", "n,m=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\na.sort()\r\ns=0\r\ncnt=0\r\nfor z in a:\r\n if z<0:\r\n s-=z\r\n cnt+=1\r\n if cnt==m:\r\n break\r\nprint(s)", "n,m = map(int,input().split())\na = list(map(int,input().split()))\nb = []\nfor i in range(m):\n l = min(a)\n b.append(l)\n a.remove(l)\ns = 0\nfor j in b:\n if j<0:\n s+=abs(j)\nprint(s)\n\n ", "import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\nn, m = map(int, input().split())\r\na = sorted(map(int, input().split()))\r\nans = 0\r\nfor i, x in zip(range(m), a):\r\n if x >= 0:\r\n break\r\n ans -= x\r\n\r\nprint(ans)\r\n", "n, limit = map(int,input().split())\r\nstring = input().split()\r\nnum = []\r\nfor i in string:\r\n num.append(int(i))\r\nnum.sort()\r\nsummed = 0\r\nfor i in range(limit):\r\n if num[i] < 0:\r\n summed += abs(num[i])\r\n else:\r\n break\r\nprint(summed)\r\n\r\n", "n,m=map(int,input().split())\r\ntv=list(map(int,input().split()))\r\n#print(tv)\r\ntv.sort()\r\n#print(tv)\r\nans=tv[:m]\r\nmv=0 #maxvalue\r\n#he will only carry those tv prices for which he will get money those are 0 and -ve\r\nfor x in ans:\r\n if x<=0:\r\n mv=mv+abs(x)\r\nprint(mv)\r\n ", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=sorted(a)\r\nk=0\r\nfor i in range(m):\r\n if s[i]<0:\r\n k+=abs(s[i])\r\nprint(k)\r\n", "_,b=map(int,input().split(' '))\r\nprint(abs(sum(sorted(map(lambda x: 0 if int(x)>0 else int(x),input().split(' ')))[:b])))", "\"\"\"Once Bob got to a sale of old TV sets.\r\nThere were n TV sets at that sale.\r\nTV set with index i costs ai bellars.\r\nSome TV sets have a negative price - their owners are ready to pay Bob if he buys their useless apparatus.\\\r\nBob can «buy» any TV sets he wants.\r\nThough he's very strong, Bob can carry at most m TV sets,\r\n and he has no desire to go to the sale for the second time.\r\nPlease, help Bob find out the maximum sum of money that he can earn.\r\n\r\nInput\r\nThe first line contains two space-separated integers n and m (1 <= m <= n <= 100)\r\n - amount of TV sets at the sale, and amount of TV sets that Bob can carry.\r\nThe following line contains n space-separated integers ai (-1000 <= ai <= 1000) - prices of the TV sets.\r\n\r\nOutput\r\nOutput the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.\"\"\"\r\n\r\nn, m = map(int, input().split())\r\ntv_price = list(map(int, input().split()))\r\ntv_price.sort()\r\n\r\nresult = 0\r\nfor i in range(m):\r\n if tv_price[i] < 0:\r\n result -= tv_price[i]\r\n else:\r\n break\r\n\r\nprint(str(result))", "n,m=list(map(int,input().split()))\r\nlst=list(map(int,input().split()))\r\nlst.sort()\r\nsum=0\r\nfor i in range(m):\r\n if lst[i] > 0:\r\n break\r\n else:\r\n sum+=lst[i]\r\nprint(abs(sum))", "n, m = map(int, input().split())\r\narr = sorted(list(map(int, input().split())))\r\ncount = 0\r\ni = 0\r\nwhile i < m and arr[i] < 0:\r\n count += arr[i]\r\n i += 1\r\nprint(abs(count))", "n,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\n\r\nl.sort()\r\nc=0\r\ns=0\r\np=0\r\nfor i in range(len(l)):\r\n\r\n if c==m:\r\n break\r\n\r\n if l[i]<0:\r\n s+=l[i]\r\n\r\n c+=1\r\n\r\n\r\n\r\n\r\nif p==0:\r\n if s<0:\r\n print(-s)\r\n else:\r\n print(s)\r\n\r\n\r\n\r\n\r\n", "n,k=[int(i) for i in input().split(\" \")]\r\narr=[int(i) for i in input().split(\" \")]\r\narr.sort()\r\ns=0\r\nfor i in range(k):\r\n if(arr[i]<0):\r\n s+=arr[i]\r\n else:\r\n break\r\nprint(s*-1)\r\n", "# 34B - Sale\r\nif __name__ == '__main__':\r\n n,m = input().split()\r\n lst = [int(x) for x in input().split()]\r\n lst.sort()\r\n sum_max = 0\r\n for t in range(int(m)) : \r\n if lst[t] <= 0 :\r\n sum_max += abs(lst[t])\r\n print(sum_max)", "n,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nn=[]\r\nfor i in range(len(l)):\r\n if l[i]<0:\r\n n.append(l[i]*(-1))\r\nn.sort(reverse=True)\r\nn=n[0:m]\r\nprint(sum(n))", "m=lambda:map(int,input().split())\nN,M=m()\na=sorted(list(m()))\nS=0\nfor c in a[:M]:S-=min(0,c)\nprint(S)\n", "import math\r\n\r\n\r\nn, m = map(int, input().split(' '))\r\narray = list(map(int, input().split(' ')))\r\narray.sort()\r\ntotal = 0\r\nfor i in range(m):\r\n if array[i]<0:\r\n total+=-array[i]\r\n else:\r\n break;\r\n\r\nprint(total)\r\n\r\n", "n, m = tuple(map(int, input().rstrip().split()))\r\narr = list(map(int, input().rstrip().split()))\r\n\r\narr.sort(reverse=True)\r\n\r\nmoney = 0\r\n\r\nwhile m > 0:\r\n y = arr.pop()\r\n if y < 0:\r\n money += (-1)*y\r\n m -= 1\r\n else:\r\n break\r\n\r\nprint(money)\r\n", "def maximum_earnings(n, m, prices):\n prices.sort() # Sort the prices in non-decreasing order\n\n earnings = 0\n for i in range(m):\n if prices[i] < 0:\n earnings -= prices[i] # Bob earns money if the price is negative\n\n return earnings\n\n# Read input\nn, m = map(int, input().split())\nprices = list(map(int, input().split()))\n\n# Calculate the maximum earnings\nmax_earnings = maximum_earnings(n, m, prices)\n\n# Print the maximum earnings\nprint(max_earnings)\n\n \t\t \t \t \t\t \t \t\t\t \t \t\t", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nnc = 0\r\nfor i in a:\r\n if i < 0 and m > 0:\r\n nc += i\r\n m-=1\r\nif(nc == 0):\r\n print(0)\r\nelse:\r\n print(-nc)", "n,k=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\na.sort()\r\ni=0\r\nc=0\r\nwhile i<k and a[i]<0:\r\n c+=a[i]\r\n i+=1\r\nprint(abs(c))", "n,m = [int(x) for x in input().split()]\r\n\r\na = [int(x) for x in input().split()]\r\n\r\na = sorted(a)\r\nbp = 0\r\nfor i in range(len(a)):\r\n if (a[i]>0) or (bp>=m):\r\n break\r\n bp+=1\r\n\r\nbp = sum(a[:bp])\r\nif bp<0:\r\n bp = abs(bp)\r\nelse:\r\n bp = -bp\r\nans = sum(a[:m])\r\nif ans<0:\r\n ans = abs(ans)\r\nelse:\r\n ans = -ans\r\n\r\nans = max(ans, bp)\r\nprint(ans)", "raw1 = str(input(''))\r\nl = raw1.split(' ')\r\nn = int(l[0])\r\nm = int(l[1])\r\n\r\nraw2 = str(input(''))\r\nA = raw2.split(' ')\r\nfor i in range(0,len(A)):\r\n A[i] = int(A[i])\r\n\r\nAsort = sorted(A)\r\n\r\nsum = 0\r\nfor j in range(0,m):\r\n if Asort[j] <= 0:\r\n sum = sum + Asort[j]\r\n\r\nprint(-1 * sum,end='')\r\n", "def rasprodaja(lst, m):\r\n b = sorted(lst)\r\n i, max_money = 0, 0\r\n while i <= len(b) - 1 and b[i] < 0 < m:\r\n max_money -= b[i]\r\n i += 1\r\n m -= 1\r\n return max_money\r\n\r\n\r\nn, M = [int(j) for j in input().split()]\r\na = [int(x) for x in input().split()]\r\nprint(rasprodaja(a, M))\r\n", "import math\r\nn,m = map(int,input().split(' '))\r\nnumbers = sorted(list(map(int, input().split(\" \"))))\r\nli=[]\r\nli1=[]\r\nfor item in numbers:\r\n if item<0:\r\n li.append(item)\r\nli = li[:m]\r\nsumma =sum(li)\r\nprint(abs(summa))", "k=input()\r\nh=list(map(int, k.split(\" \")))\r\nn=h[0]\r\nm=h[1]\r\na=input()\r\nsum=0\r\nb=list(map(int, a.split(\" \")))\r\nfor i in range(n-1):\r\n for j in range(n-i-1):\r\n if b[j] > b[j+1]:\r\n sorted=b[j]\r\n b[j] = b[j+1]\r\n b[j+1] = sorted\r\nfor i in range(m):\r\n if b[i]<0:\r\n sum-=b[i]\r\nprint(sum)", "def main():\r\n s = input()\r\n ss = s.split(\" \")\r\n n = ss[0]\r\n m = ss[1]\r\n transport = 0\r\n price = 0\r\n sub = input()\r\n subs = sub.split(\" \")\r\n subsi = []\r\n for j in range(len(subs)):\r\n subsi.append(int(subs[j]))\r\n subsi.sort()\r\n\r\n for i in range(int(n)):\r\n if(int(subsi[i]) <= 0 and transport < int(m)):\r\n price -= int(subsi[i])\r\n transport += 1\r\n\r\n print(price)\r\n\r\nmain()", "from sys import stdin, stdout\n\ndef show_vector(vector,end_line=\"\\n\"):\n print(\" \".join(map(str, vector)),end=end_line)\n \ndef binary_search(arr, low, high, x):\n\n if high >= low:\n \n mid = (high + low) // 2\n \n if arr[mid] == x:\n return mid\n elif arr[mid] > x:\n return binary_search(arr, low, mid - 1, x)\n else:\n return binary_search(arr, mid + 1, high, x)\n else:\n return -1\n[n,q] = list(map(int, stdin.readline().split()))\n\ns = list(map(int, stdin.readline().split()))\ns.sort()\ncount=0\nfor num in s:\n if q==0 or num >0:\n break\n q-=1\n count -=num\n \nprint(count)\n \t\t \t \t \t \t \t \t \t\t\t\t \t\t", "t = 1\r\nwhile t:\r\n t-=1\r\n n, m = map(int, input().split())\r\n ls = list(map(int, input().split()))\r\n ls.sort()\r\n res = 0\r\n for item in ls:\r\n if item < 0 and m > 0:\r\n res += item\r\n m -= 1\r\n if m == 0:\r\n break\r\n print(res*-1) ", "import math as m\r\ntry:\r\n n , m = map(int,input().split())\r\n a = list(map(int,input().split()))\r\n #s = input()\r\n a.sort()\r\n s = 0\r\n #print(a)\r\n for j in range(0,n):\r\n if(a[j]<=0):\r\n s = s + abs(a[j])\r\n m = m -1 \r\n if(m==0):\r\n break\r\n else:\r\n break\r\n print(s)\r\n \r\n \r\n \r\n \r\nexcept EOFError as e:\r\n pass\r\n", "n,m=list(map(int,input().split()))\r\ns=[-int(x) for x in input().split()]\r\ns.sort()\r\nsu=0\r\nfor i in range(n-m,n):\r\n if s[i]>0:\r\n su+=s[i]\r\nprint(su)", "from audioop import reverse\r\n\r\n\r\ns = input().split()\r\nn,m = list(map(int,s))\r\ns = input().split()\r\nl = list(map(int,s))\r\nll = [k for k in l if k<0]\r\nll.sort()\r\nou = min(len(ll),m)\r\nprint(-sum(ll[:ou])) ", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nearn=0\r\na.sort()\r\nfor i in a:\r\n if i<=0 and m>0:\r\n earn+=-(i)\r\n m-=1\r\nprint(earn)", "n = list(map(int, input().split()))\r\nn2 = list(map(int, input().split()))\r\nn2.sort()\r\ntotal = 0\r\nfor i in range(n[1]):\r\n\tif total + (-1 * n2[i]) > total:\r\n\t\ttotal += (-1 * n2[i])\r\n\r\nprint(total)", "def main():\r\n n, m = [int(i) for i in input().split()]\r\n s = [int(i) for i in input().split()]\r\n\r\n s.sort()\r\n i = 0\r\n ans = 0\r\n while i < m and s[i] < 0:\r\n ans += abs(s[i]) \r\n i += 1\r\n\r\n print(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "values = input() # Taking the number of televesion for sale and bob ability\r\nvalues = values.split()\r\nn = int(values[0])\r\nm = int(values[1])\r\n\r\nprices = input() # Taking the prices of the televisions\r\nprices = prices.split()\r\nprices = [int(val) for val in prices]\r\n\r\nprices.sort()\r\n\r\nearn = 0\r\n\r\nfor i in range(m):\r\n if prices[i] >= 0:\r\n break\r\n else:\r\n earn += prices[i]\r\n\r\nprint(earn * -1)", "def solve_problem(m,arr):\r\n\tarr.sort()\r\n\ts=0\r\n\tfor i in range(m):\r\n\t\t\tif arr[i]<=0:\r\n\t\t\t\t\ts=s+abs(arr[i])\r\n\treturn s\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\r\n\t\t\t\r\nn,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nprint(solve_problem(m,arr))", "n, m = map(int, input().split())\ntv = list(map(int, input().split()))\n\ntv = [p for p in tv if p<0]\ntv.sort()\nprint(-sum(tv[:m]))\n", "n, m = map(int, input().split())\r\nlst = sorted(tuple(map(int, input().split())))\r\nmn = min((n, m))\r\nf = True\r\nfor i in range(mn):\r\n if lst[i] >= 0:\r\n print(abs(sum(lst[:i] or [0])))\r\n f = False\r\n break\r\nif f:\r\n print(abs(sum(lst[:mn])))", "n,m=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\ni=0\r\nk=0\r\ns=0\r\nwhile m>0 and min(a)<0:\r\n if min(a)<0:\r\n s=s+min(a)\r\n a.remove(min(a))\r\n m=m-1\r\nprint (s*-1)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\n\r\na.sort()\r\nans=0\r\nfor i in range(m):\r\n if a[i]<0:\r\n ans+=abs(a[i])\r\n elif a[i]>0:\r\n break\r\nprint(ans)\r\n", "\r\nfor y in range(1):\r\n n,m=input().split()\r\n price=input().split()\r\n prices=[]\r\n money=0\r\n for x in price:\r\n prices.append(int(x))\r\n prices.sort()\r\n for i in range(int(m)):\r\n if prices[i]<0:\r\n money+=(-1*(prices[i]))\r\n print(money)\r\n", "# 34B | Sale\r\n\r\nn, m = list(map(int, input().split()))\r\ncosts = sorted(map(int, input().split()))\r\n\r\nearnings = 0\r\nfor i in range(m):\r\n if costs[i] < 0:\r\n earnings += costs[i]\r\n\r\nprint(abs(earnings))", "nk=input().split()\r\nn=int(nk[0])\r\nk=int(nk[1])\r\ns=list(map(int,input().rstrip().split()))\r\ns.sort()\r\na=0\r\nfor i in range (k):\r\n if s[i]<0 :\r\n a=a+abs(s[i])\r\nprint(a)", "b,c = list(map(int,input().split()))\r\na= list(map(int,input().split()))\r\na.sort()\r\nsum=0\r\nfor k in range(c):\r\n if a[k] <=0:\r\n sum += a[k]\r\nprint(sum * -1)", "n,m=tuple(map(int,input().split()))\r\nls=list(map(int,input().split()))\r\nls.sort()\r\nls=ls[0:m]\r\nfor i in range(m-1,-1,-1):\r\n if ls[i]<0:\r\n ls=ls[0:i+1]\r\n break\r\n else:\r\n \tls.pop()\r\nprint(0-sum(ls))", "if __name__ == '__main__':\r\n n_tv, can_carry = [int(x) for x in input().split()]\r\n tv_prices = [int(x) for x in input().split()]\r\n amount = 0\r\n tv_prices.sort()\r\n for price in tv_prices:\r\n if price >= 0 or can_carry == 0:\r\n break\r\n amount += abs(price)\r\n can_carry -= 1\r\n print(amount)", "from sys import stdin\r\n\r\ndef genera(m):\r\n x= []\r\n for i in range(len(m)):\r\n if m[i] <= 0:\r\n x.append(m[i])\r\n return x\r\ndef sumar(o,n):\r\n z= 0\r\n o= sorted(o)\r\n if len(o)>n[1]:\r\n for i in range(n[1]):\r\n z+= o[i]\r\n else:\r\n for i in range(len(o)):\r\n z+= o[i]\r\n print(z*-1)\r\ndef main():\r\n n= [int(x) for x in stdin.readline().strip().split()]\r\n m= [int(x) for x in stdin.readline().strip().split()]\r\n o= genera(m)\r\n sumar(o,n)\r\n\r\nmain()\r\n", "n,m=map(int,input().split())\r\ncost=list(map(int,input().split()))\r\ncost.sort()\r\nglobal sum\r\nsum=0\r\nfor i in range(m):\r\n if cost[i]>=0:\r\n break\r\n sum+=cost[i]\r\nprint(-sum)", "n, m = [int(x) for x in input().split()]\r\na = sorted([int(x) for x in input().split()])\r\nb = 0\r\nfor i in range(m):\r\n if a[i]<0:\r\n b+=-a[i]\r\nprint(b)", "#import sys\r\n#import itertools\r\n#import math\r\n\r\n#t = int(input())\r\nt = 1\r\n\r\nwhile t > 0:\r\n #print(t)\r\n n, m = [int(x) for x in input().split()]\r\n #a, b = (int(x) for x in input().split())\r\n arr = [int(x) for x in input().split()]\r\n arr = sorted(arr)\r\n take = [-x for x in sorted(arr[:m]) if x<0]\r\n print(sum(take))\r\n\r\n t -= 1", "h=0\r\nx,y=map(int,input().split())\r\ng=list(map(int,input().split()))\r\ng.sort()\r\nfor i in range(y):\r\n if g[i]<0:\r\n h+=g[i]\r\nprint(-h)", "#文字列入力はするな!!\r\n#carpe diem\r\n\r\n'''\r\n ██╗ ██╗ ███╗ ███╗ ██╗ ████████╗\r\n ██║ ██║ ████╗ ████║ ██║ ╚══██╔══╝\r\n═════════██╠════════██╠═══██╔████╔██╠═══██╠══════██╠══════════\r\n ██║ ██║ ██║╚██╔╝██║ ██║ ██║\r\n ███████╗ ██║ ██║ ╚═╝ ██║ ██║ ██║\r\n ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝\r\n'''\r\n\r\n#文字列入力はするな!!\r\n#carpe diem\r\n\r\np=[int(x) for x in input().split()]\r\nz=[int(y) for y in input().split()]\r\nc=[]\r\nif all(n>=0 for n in z):\r\n print(0)\r\nelse:\r\n for i in z:\r\n if i < 0:\r\n c.append(i)\r\n c.sort()\r\n print(abs(sum(c[:p[1]])))\r\n \r\n\r\n#carpe diem \r\n#carpe diem", "n , m = map(int,input().split())\r\na = [int(i) for i in input().split()]\r\na.sort()\r\ncnt = 0\r\nfor i in a:\r\n if i < 0:\r\n cnt += 1\r\n else:\r\n break\r\nif cnt > m:\r\n print(sum(a[:m])*(-1))\r\nelse:\r\n print(sum(a[:cnt]) * (-1))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nc=0\r\nfor i in range(m):\r\n if a[i]<0:\r\n c-=a[i]\r\n else:\r\n break\r\nprint(c)", "n, m = map(int, input().split()) \ntvp = list(map(int, input().split()))\n\ntvp = sorted(tvp)\n\ncont = 0\nans = 0\nfor value in tvp:\n if(value <= 0 and cont < m):\n ans +=value \n cont+=1\n\nprint(abs(ans))\n\t \t \t\t\t\t\t\t\t \t \t \t \t \t\t\t", "\ndef solve(n,m,arr):\n arr.sort()\n s=0\n for i in range(m) :\n if s+arr[i] <= s : \n s+=arr[i]\n else:\n return abs(s)\n return abs(s)\n\n\n\n\n \t\n\n \n \n \nfrom sys import stdin\ninput = stdin.readline\n\n\nn,m=[int(x)for x in input().split()]\nl=[int(x)for x in input().split()]\n\nprint(solve(n,m,l))", "lst = [int(i) for i in input().split()]\r\nn,m = lst[0],lst[1]\r\n\r\nlst= [int(i) for i in input().split()]\r\nlst.sort()\r\n\r\ncount = 0\r\nmoney = 0\r\nwhile(count<m):\r\n if(lst[count] < 0):\r\n money += lst[count]*(-1)\r\n if(lst[count] > 0):\r\n break\r\n count+=1\r\nprint(money)\r\n", "n,m = map(int,input().split())\r\ntv = sorted(t for t in map(int,input().split()) if t<0)\r\nprint(-sum(tv[:m]))", "def result(n,m,lis):\n\tlis2=[]\n\tlis3=[]\n\tfor i in range(n):\n\t\ta=lis[i]\n\t\tif a<=0:\n\t\t\tlis2.append(a)\n\t\telse:\n\t\t\tlis3.append(a) \n\tif len(lis2)>=m:\n\t\tlis2.sort()\n\t\ts=0 \n\t\tfor i in range(m):\n\t\t\ts+=lis2[i]\n\t\tif s<0:\n\t\t\tprint(s*(-1)) \n\t\telse:\n\t\t\tprint(s)\t\n\telse:\n\t\tk=sum(lis2) \n\t\tif k<0:\n\t\t\tprint(k*-1)\n\t\telse:\n\t\t\tprint(k)\t\n\t\t\t\n\n\n\n\n\n\n\n\nn,m=map(int,input().split())\nlis=list(map(int,input().split()))\nresult(n,m,lis)\n", "n,m=map(int,input().split())\r\nli=list(map(int,input().split()))\r\nx=[]\r\nfor i in li:\r\n \r\n if(i<0):\r\n x.append(abs(i))\r\n# print(x)\r\nif(li==[]):\r\n print(0)\r\n quit()\r\nx.sort()\r\nx.reverse()\r\n\r\nif(len(x)<=m):\r\n print(sum(x))\r\nelse:\r\n print(sum(x[:m]))\r\n \r\n", "n,m=map(int,input().split())\r\na=sorted([int(i) for i in input().split()])\r\n\r\ns,k=0,0\r\n\r\nfor i in a:\r\n if i < 0 and k < m:\r\n s-=i\r\n k+=1\r\n else:\r\n break\r\n\r\nprint(s)\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\n\r\ns=0\r\nfor i in range(0,m):\r\n if a[i]<0:\r\n s=s+a[i]\r\n else:\r\n break\r\nprint(abs(s))", "a = input()\r\na = a.split()\r\nn = int(a[0])\r\nm = int(a[1])\r\na = input()\r\na = a.split()\r\na = [int(x) for x in a]\r\na.sort()\r\ni =0\r\nsm = 0\r\nwhile i < m and a[i] < 0:\r\n sm += a[i]\r\n i += 1\r\n\r\n\r\nprint( -sm)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\n\r\ns = 0\r\nfor i in range(m):\r\n v = a[i]\r\n if v < 0:\r\n s -= v\r\n\r\nprint(s)\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nans=0\r\nfor i in a:\r\n if(m==0):\r\n break\r\n if(i<0):\r\n ans+=-(i)\r\n m-=1\r\nprint(ans)\r\n", "d,n= map(int,input().split())\r\nnum = list(map(int,input().split()))\r\na =0\r\nsum = 0\r\nwhile True:\r\n if len(num) == 0:\r\n print(-1 * sum)\r\n break\r\n else:\r\n m = min(num)\r\n num.remove(m)\r\n if(m >= 0 or a == n):\r\n print(-1*sum)\r\n break\r\n else:\r\n sum += m\r\n a += 1", "m,n = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nsum1 = 0\r\nfor i in range(n):\r\n if arr[i] < 0:\r\n sum1 +=arr[i]\r\nprint(abs(sum1))", "n,m=map(int,input().split())\r\narr=[int(x) for x in input().split()]\r\narr.sort()\r\nc=0\r\nans=0\r\nfor i in arr:\r\n if i>=0 or c==m:\r\n break\r\n elif i<0:\r\n ans+=(-1*i)\r\n c+=1\r\nprint(ans)", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nprint(-sum(a[i] for i in range(m) if a[i] <= 0))", "n,m = map(int,input().split())\r\nx = []\r\na = list(map(int,input().split()))\r\nfor i in a:\r\n if i <0:\r\n x.append(i)\r\nx.sort()\r\nprint(abs(sum(x[:m])))", "n,m=map(int,input().split())\r\nar=list(map(int,input().split()))\r\nsum=0\r\nsort_ar=sorted(ar)\r\nfor i in range (0,m):\r\n if(sort_ar[i]<0):\r\n sum+=abs(sort_ar[i])\r\nprint(sum)", "# -*- coding: utf-8 -*-\n\"\"\"Untitled58.ipynb\n\nAutomatically generated by Colaboratory.\n\nOriginal file is located at\n https://colab.research.google.com/drive/1Haek7VxDi0TQbwEcEiGX07TDLQNDP7w6\n\"\"\"\n\nn,m=map(int,input().split())\nl1=list(map(int,input().split()))\nl1.sort()\nl2=l1[0:m]\nc=0\nl3=[]\nfor i in range(0,len(l2)):\n if l2[i]<0:\n l3.append(l2[i])\n else:\n break\nprint(sum(l3)*(-1))", "n, m = map(int, input().split())\r\na = list(map(int, input().split(\" \")))\r\nfinal = []\r\nfor i in range(n):\r\n if a[i] < 0:\r\n final.append(a[i])\r\nfinal.sort()\r\nif len(final) >= m:\r\n print(abs(sum(final[:m])))\r\nelse:\r\n print(abs(sum(final)))", "n,m = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\ns = 0\r\ni = 0\r\nwhile m:\r\n if a[i] != abs(a[i]):\r\n s += abs(a[i])\r\n else:\r\n break\r\n m -= 1\r\n i += 1\r\nprint(s)\r\n \r\n", "n, m = map(int, input().split()); money=0; a=sorted(list(map(lambda x:min(int(x),0), input().split())))\r\nfor i in range(m): money-=a[i]\r\nprint(money)", "n,m = input().split(' ')\r\nn = int(n)\r\nm = int(m)\r\narr = [int(i) for i in input().split(' ')]\r\narr.sort()\r\nsum = 0\r\ncount = 0\r\nfor i in range(n):\r\n if arr[i] < 0:\r\n sum += arr[i]\r\n count += 1\r\n if count == m:\r\n break\r\nprint(abs(sum))\r\n", "a,b=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nx.sort()\r\ns=0\r\nfor i in x:\r\n if i>=0 or b==0:\r\n break\r\n else:\r\n s+=abs(i)\r\n b-=1\r\nprint(s)", "if __name__ == \"__main__\":\r\n n, m = list(map(int, input().split()))\r\n res = list(map(int, input().split()))\r\n res.sort()\r\n result = res[:m]\r\n result = [x for x in result if x <= 0]\r\n print(abs(sum(result)))", "n,m=map(int,input().split())\r\na=(list(map(int,input().split())))\r\ns=0;\r\na.sort()\r\nfor i in range(m):\r\n if a[i]<0:\r\n s-=a[i]\r\nprint(s)", "arr = list(map(int, input().rstrip().split()))\r\narr2 = sorted(list(map(int, input().rstrip().split())))\r\nans=0\r\nfor i in range(arr[1]):\r\n if arr2[i]<0:\r\n ans-=arr2[i]\r\n else:\r\n break\r\nprint(ans)", "n, m = map(int, input().split())\nprices = list(map(int, input().split()))\n\nprices.sort()\nearn = 0\n\nfor i in range(m):\n if prices[i] < 0:\n earn += abs(prices[i])\n\nprint(earn)\n\t \t \t\t\t\t \t\t\t \t\t\t \t \t \t \t \t", "n, m = map(int, input().split())\r\na = list(filter(lambda x: x < 0, list(map(int,input().split()))))\r\nj = 0\r\nfor i in range(1,len(a)+1):\r\n if i > m:\r\n break\r\n j += abs(min(a)); a.remove(min(a))\r\nprint(j)", "nums = input().split()\r\nvals = input().split()\r\n\r\nnums = [int(x) for x in nums]\r\nvals = [int(x) for x in vals]\r\n\r\ndef selection_sort(arr):\r\n if len(arr) == 1 or len(arr) == 0:\r\n return arr\r\n\r\n pivot = arr[len(arr)//2]\r\n arr.pop(len(arr)//2)\r\n less = []\r\n high = []\r\n for i in arr:\r\n if i <= pivot:\r\n less.append(i)\r\n else:\r\n high.append(i)\r\n return selection_sort(less) + [pivot] + selection_sort(high)\r\n\r\nvals = selection_sort(vals)\r\n\r\ncurr = 0\r\nsum = 0\r\nwhile curr < nums[1] and vals[curr] < 0:\r\n sum += vals[curr] * -1\r\n curr += 1\r\n\r\n if curr == len(vals):\r\n break\r\n\r\nprint(sum)", "def main():\r\n n, m = list(map(int, input().split()))\r\n lst = list(map(int, input().split()))\r\n minus = [i for i in lst if i < 0]\r\n minus.sort()\r\n if m > len(minus):\r\n print(-sum(minus))\r\n else:\r\n print(-sum(minus[:m]))\r\n\r\n\r\nmain()", "n,m=map(int,input().split())\r\nnums=[int(i) for i in input().split()]\r\nnums.sort()\r\nres=0\r\nfor i in range(m):\r\n if nums[i]<0:\r\n res+=0-nums[i]\r\n elif nums[i]>=0:\r\n break\r\nprint(res)", "n,m=map(int,input().split())\r\nl=[int(i) for i in input().split() if int(i)<0]\r\nl.sort()\r\nprint(abs(sum(l[:m])))\r\n", "n,m = map(int,input().split())\r\nai = list(map(int,input().split()))\r\nai.sort()\r\ni = 0\r\nans = 0\r\nwhile m > 0:\r\n m -= 1\r\n if ai[i] >= 0:\r\n break\r\n ans -= ai[i]\r\n i += 1\r\nprint(ans)\r\n", "n_ = input().split()\r\nt = int(n_[1])\r\nn = input().split()\r\ntotal = 0\r\nn__ = []\r\nfor i in range(int(n_[0])):\r\n n[i] = int(n[i])\r\n if n[i] < 0:\r\n n__.append(abs(n[i]));\r\nwhile t > 0 and n__ != []:\r\n total += max(n__)\r\n del n__[n__.index(max(n__))]\r\n t -= 1\r\nprint(total)", "n,b = map(int,input().split())\r\na = list(map(int,input().split()))\r\na = sorted(a)\r\nsumma,count = 0,0\r\nfor i in a:\r\n if count == b:\r\n break\r\n if i<0 and count<b:\r\n summa+=i*-1\r\n count+=1\r\nprint(summa)", "import sys\r\n\r\ndef main():\r\n _, m, *l = map(int, sys.stdin.read().strip().split())\r\n return abs(sum(sorted(i for i in l if i < 0)[:m]))\r\n\r\nprint(main())\r\n", "param=[int(i) for i in input().split()]\r\narr=sorted([int(j) for j in input().split()])\r\nsum=0\r\nfor i in range(0,param[1]):\r\n if arr[i]<=0: sum+=arr[i]\r\nprint(abs(sum))", "n, m = map(int, input().split())\r\ncost = list(map(int, input().split()))\r\n\r\nsum = 0\r\ncost.sort()\r\nfor i in range(m):\r\n if cost[i] < 0:\r\n sum += abs(cost[i])\r\n\r\nprint(sum)", "n, m = map(int, input().split())\r\nar = list(map(int, input().split()))\r\n\r\nar.sort()\r\n\r\ns = 0\r\nfor i in range(m):\r\n if(ar[i] > 0):\r\n break\r\n s -= ar[i]\r\nprint(s)\r\n", "n, m = map(int, input().split())\r\ncosts = sorted([int(d) for d in input().split()])\r\nans = 0\r\ni = 0\r\nwhile m > 0:\r\n if(costs[i] >= 0):\r\n break\r\n ans = ans+costs[i]\r\n i = i+1\r\n m = m-1\r\nprint(ans*-1)\r\n", "x,y = map(int , input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nk = 0 \r\nfor i in range(0,y):\r\n if( a[i] < 0 ):\r\n k = k + a[i]\r\n else:\r\n break\r\nprint(-1*k)\r\n", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\n\r\nprices.sort()\r\ntotal = 0\r\nfor i, p in enumerate(prices):\r\n if p < 0 and i < m:\r\n total -= p\r\n else:\r\n break\r\nprint(total)", "n1,m1 = input().split()\r\nn = int(n1)\r\nm = int(m1)\r\nx = [int(x) for x in input().split()]\r\ny = []\r\nx.sort()\r\ncnt = 0\r\nfor i in x:\r\n if i < 0:\r\n y.append(i)\r\n cnt = cnt + 1\r\n if cnt == m:\r\n break\r\nprint(abs(sum(y)))\r\n\r\n", "n, k= map(int,input().split())\r\nkq = 0\r\nls = sorted(list(map(int,input().split())))\r\nfor i in range(k):\r\n if ls[i]>=0:\r\n break\r\n kq+= abs(ls[i])\r\nprint(kq)", "k=input()\nl=[int(i) for i in k.split(\" \")]\nn=l[0]\nm=l[1]\np=input()\nprice=[int(j) for j in p.split(\" \")]\nprice.sort()\ni=0\npsum=0\nfor f in range(0,len(price)):\n\tif (price[f]<=0 and f<=m-1):\n\t\tpsum=psum+price[f]\nprint(psum*-1)\n\n", "n,m=map(int,input().split())\r\nc=0\r\na=sorted(list(map(int,input().split())))\r\nfor i in range(m):\r\n if a[i]<0:\r\n c=c+abs(a[i])\r\nprint(c)", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nans=0\r\nfor i in range(m):\r\n if arr[i]>=0:\r\n break\r\n else:\r\n ans+=abs(arr[i])\r\nprint(ans)", "n,m = [int(x) for x in input().split()]\r\nprices = [int(x) for x in input().split()]\r\n\r\nprices.sort()\r\n\r\n\r\nwin = 0\r\nfor el in prices:\r\n if m == 0:\r\n break\r\n if el < 0:\r\n win += el\r\n else:\r\n break\r\n m -= 1\r\nprint(abs(win))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n,m = map(int,input().split())\r\n\r\ntv = list(int(x) for x in input().split())\r\ntv = sorted(tv)\r\nans=0\r\nfor i in range(m):\r\n if tv[i]<0:\r\n ans+=abs(tv[i])\r\n else:\r\n break\r\nprint(ans)\r\n\r\n", "n,m=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\na.sort()\r\nsum=0\r\nfor i in range(m):\r\n if a[i]<=0:\r\n sum+=abs(a[i])\r\nprint(sum)\r\n", "n, m = [int(i) for i in input().split()]\nl = [int(i) for i in input().split()]\n\nc = 0\ne = 0\n\nwhile c < m:\n\tx = min(l)\n\tif x > 0:\n\t\tbreak\n\n\tc += 1\n\te += x\n\tl.remove(x)\n\nprint(e*-1)\n", "n,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\ns=0\r\nc=0\r\nl.sort()\r\nfor i in range(len(l)):\r\n if(l[i]<0):\r\n s=s-(l[i])\r\n c=c+1\r\n if c==m:\r\n break\r\nprint(s)\r\n ", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nln=[]\r\nlp=[]\r\nfor i in l:\r\n if i<0:\r\n ln.append(abs(i))\r\n else:\r\n lp.append(i)\r\nln.sort(reverse=True)\r\nlp.sort()\r\nsu=0\r\nfor i in range(len(ln)):\r\n su+=ln[i]\r\n if(i+1>=m):\r\n break\r\nprint(su)\r\n", "m,n=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ns=0\r\n#print(l)\r\nfor x in range(n):\r\n if l[x]<0:\r\n #print(l[x])\r\n s=s+l[x]\r\n #print(s)\r\nprint(abs(s))\r\n", "n,m =map(int,input().split())\r\na =list(map(int,input().split()))\r\na.sort()\r\ns=0\r\nfor i in range(n):\r\n\tif i+1<=m and a[i]<0:\t\r\n\t\ts+=a[i]\r\nprint(abs(s))", "m,n=map(int,input().split())\narr=list(map(int,input().strip().split()))[:m]\narr.sort()\ni=0\nsumm=0\nwhile(i<m and n>0):\n if(arr[i]>=0):\n break\n else:\n summ+=int(arr[i]*-1)\n i+=1\n n-=1\nprint(summ)\n\t \t \t \t \t \t\t \t \t \t\t\t", "n,m = map(int,input().split())\r\nar = list(map(int,input().split()))\r\nar.sort()\r\n\r\ns = 0\r\nmini = 100000000\r\n\r\nfor i in range(m) :\r\n\ts += ar[i]\r\n\tif mini > s :\r\n\t\tmini = s\r\nif mini < 0 :\r\n\tmini *= (-1)\r\nelse :\r\n\tmini = 0 \r\nprint(mini)", "n,m=map(int,input().split())\r\nnum=list(map(int,input().split()))\r\nc=0\r\nnum.sort()\r\nans=0\r\nfor i in range(n):\r\n\tif num[i]<0:\r\n\t\tans+=abs(num[i])\r\n\t\tc+=1\r\n\tif m==c:\r\n\t\tbreak\r\nprint(ans)", "n, m = map(int, input().split())\r\ns = list(map(int, input().split()))\r\ns.sort()\r\nt = 0\r\nsum = 0\r\nfor i in range(n):\r\n if t<m and s[i]<0:\r\n sum+=s[i]\r\n t+=1\r\n else:\r\n break\r\nprint(abs(sum))", "a,b=map(int,input().split())\narr=list(map(int,input().split()))\narr.sort()\nans=0\nfor i in range(b):\n if arr[i]<=0:\n ans+=arr[i]\n else:\n break\n # print(ans)\nprint(abs(ans))\n \n# a,b=map(int,input().split())\n# arr=list(map(int,input().split()))\n# x,y,z=0,0,0\n# for i in arr:\n# if i<0:\n# if i < max(x,y,z):\n# if x>=y and x>=z:\n# x=i\n# elif x<=y and y>=z:\n# y=i\n# elif z>=y and x<=z:\n# z=i\n# # if i<x and i >y and i>z:\n# # x=i\n# # elif i<y and i>z:\n# # y=i\n# # elif i<z:\n# # z=i\n\n# # print(x,y,z)\n# # print(x,y,z)\n# print(abs(x+y+z))\n\n ", "def solve(n,m,dam):\n dam.sort()\n total = 0\n for i in range(0,min(n,m)):\n if dam[i] >=0:\n break\n total += dam[i]\n return -total\n \n\n\n\n\n\n\n\nv_n,v_m = map(int,input().split())\ndam_list = list(map(int,input().split()))\nprint(solve(v_n,v_m,dam_list))\n", "x,y=input().split()\r\nm=int(y)\r\nn=int(x)\r\nK=list(map(int,input().split()))\r\nK.sort()\r\na=0\r\nfor i in range(m):\r\n if K[i]<0:\r\n a=a+K[i]\r\nprint(-a)", "inp = [int(i) for i in str(input()).split()]\r\nm = inp[1]\r\nout = 0\r\n\r\ntv = [int(i) for i in str(input()).split() if int(i) < 0]\r\ntv.sort()\r\n\r\nlength = min(len(tv), m)\r\n\r\nfor _ in range(length):\r\n out += tv[_]\r\nprint(-out)", "num, x = map(int, input().split())\r\ngiven = list(map(int, input().split()))\r\n\r\ngiven.sort()\r\nout = 0\r\n\r\nfor a in range(x):\r\n if(given[a] <= 0):\r\n out += given[a]\r\nprint(abs(out))", "m, n = map(int,input().split())\r\nlis = list(map(int,input().split()))\r\nlis = sorted(lis)\r\nres = 0\r\npick = 0\r\nfor i in lis:\r\n if i<0 and pick<n:\r\n pick+=1\r\n res+=(-i)\r\n else:\r\n break\r\nprint (res)", "\r\nn,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nt=0\r\nfor i in range(m):\r\n\tif l[i]<=0:\r\n\t\tt=t-l[i]\r\n\telse:\r\n\t\tbreak\r\nprint(t)", "fristNum,secondNum=map(int,input().split())\r\nlistNum=sorted(map(int,input().split()))\r\ncount=0\r\nsumNum=0\r\nfor i in range(fristNum):\r\n if(listNum[i]<0):\r\n count+=listNum[i]\r\n sumNum+=1\r\n if(sumNum==secondNum):\r\n break\r\nprint(abs(count))\r\n", "n,m=map(int,input().split())\r\nA=list(map(int,input().split()))\r\nnegative=[]\r\nfor i in A:\r\n if i<=0:\r\n negative.append(i)\r\nnegative.sort()\r\nif len(negative)>=m:\r\n print(abs(sum(negative[:m])))\r\nelse:\r\n print(abs(sum(negative)))", "# Sale\r\nn, m=[int(x) for x in input().split()]\r\na=list(map(int, input().split()))\r\na.sort()\r\nc=0\r\ns=0\r\nwhile c<m:\r\n if a[c]<0:\r\n s=s+a[c]\r\n c=c+1\r\nprint(abs(s))", "n,m = map(int,input().split())\nls = sorted(list(map(int,input().split())))\nsum=0\nfor i in range(m):\n if(ls[i]<0):sum+=ls[i]\nprint(sum*-1)", "# your code goes here\r\nn,m = map(int , input().split())\r\nels = list(map(int, input().split()))\r\nfiltered_list = []\r\nfor no in els:\r\n\tif no < 0:\r\n\t\tfiltered_list.append(-no)\r\n\r\nans = 0\r\nif m >= len(filtered_list):\r\n\tans = sum(filtered_list)\r\nelse:\r\n\tfiltered_list.sort(reverse=True)\r\n\tans = sum(filtered_list[:m])\r\n\t\r\nprint(ans,end='')", "n,m=map(int,input().split())\r\nA=list(map(int,input().split()))\r\nS=[]\r\nfor j in A:\r\n if j<0:\r\n S.append(j)\r\nS.sort()\r\nif len(S)<m:\r\n print(abs(sum(S)))\r\nelse:\r\n print(abs(sum(S[:m])))", "m,n=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nres=0\r\nfor i in range(n):\r\n if l[i]<0:\r\n res+=l[i]\r\nprint(-1*res)", "n, m = list(map(int, input().split()))\narr = sorted(list(map(int, input().split())))\ns = 0\n\nfor i in range(m):\n if s - arr[i] > s:\n s = s - arr[i]\nprint(s)\n \n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nnl=[]\r\nfor i in l:\r\n if i<0:\r\n nl.append(i)\r\nnl.sort()\r\ns=0\r\nfor i in range(m):\r\n if i<len(nl):\r\n s=s+nl[i]\r\n else:\r\n break\r\nprint(abs(s))\r\n\r\n", "#from collections import Counter\r\n#n = int(input())\r\n\r\nx,y = map(int,input().split())\r\nl = list(map(int,input().split()))\r\n\r\nl.sort()\r\nc = 0\r\ni = 0\r\n\r\nwhile y> 0 and i < x:\r\n if l[i] < 0:\r\n y -= 1\r\n c += abs(l[i])\r\n i +=1\r\n\r\n else:\r\n break\r\n\r\nprint(c)\r\n", "n, m = [int(i) for i in input().split()]\r\na = list(sorted([int(i) for i in input().split()]))\r\ns = 0\r\n\r\nfor i in range(m):\r\n el = a[i]\r\n if el < 0:\r\n s -= el\r\n else:\r\n break\r\n\r\nprint(s)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nd,y=0,0 \r\nx=[]\r\nfor i in range(m):\r\n d=d+l[i]\r\n x.append(d)\r\nfor i in range(m):\r\n if x[i]<0:\r\n y=y+1\r\nif y==0:\r\n print(0)\r\nelse:\r\n print(abs(min(x)))\r\n\r\n", "n, m = map(int, input().split(\" \"))\r\na = list(map(int, input().split(\" \")))\r\na.sort()\r\nb = a[:m]\r\nans = 0\r\nfor i in b:\r\n if i <=0:\r\n ans -=i\r\nprint(ans)\r\n", "\r\nn , m = map(int,input().split())\r\n\r\narr = list(map(int,input().split()))\r\n\r\nl = []\r\ns = 0\r\nfor i in range(n):\r\n if arr[i] < 0 :\r\n l.append(arr[i])\r\n\r\n\r\nl.sort()\r\n\r\nfor i in range(len(l)):\r\n s += abs(l[i])\r\n m -=1\r\n if m == 0 :\r\n break\r\n\r\nprint(s)\r\n", "n,m=input().split()\r\nn=int(n)\r\nm=int(m)\r\nprices=input().split()\r\nfor i in range(len(prices)):\r\n\tprices[i]=int(prices[i])\r\nprices=sorted(prices)\r\noutput=0\r\nif prices[0]<0:\r\n\tx=0\r\n\twhile x<m and prices[x] < 0 :\r\n\t\toutput+=abs(prices[x])\r\n\t\tx+=1\r\n\tprint(output)\r\nelse:\r\n\tprint(\"0\")", "n,m =list(map(int, input().split()))\r\nl=list(map(int, input().split()))\r\nl.sort()\r\nj=0\r\nans=0\r\nfor i in range(m):\r\n if(l[i]<0):\r\n ans+=l[i]\r\n else:\r\n break\r\nprint(abs(ans))\r\n \r\n", "def max_money(n, m, prices):\r\n prices.sort() # Sort the prices in ascending order\r\n max_sum = 0\r\n\r\n for price in prices:\r\n if price < 0 and m > 0:\r\n max_sum += abs(price)\r\n m -= 1\r\n\r\n return max_sum\r\n\r\n# Read input\r\nn, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\n\r\n# Calculate and print the maximum sum of money\r\nresult = max_money(n, m, prices)\r\nprint(result)\r\n", "line1 = [int(x) for x in input().split()];\r\nline2 = [int(x) for x in input().split()];\r\n\r\ntvs = sorted(line2);\r\nmoney = 0;\r\nfor i in range(line1[1]):\r\n\tif tvs[i] >= 0:\r\n\t\tbreak;\r\n\telse:\r\n\t\tmoney -= tvs[i];\r\nprint(money);", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nk=[]\r\nfor i in l:\r\n if i<0:\r\n k.append(-i)\r\nk.sort(reverse=True)\r\nprint(sum(k[0:m]))", "# http://codeforces.com/problemset/problem/34/B\nn,m = map(int, input().split())\nprint(abs(sum(sorted(int(x) for x in input().split() if int(x) < 0)[:m])))\n", "import sys\r\n\r\nn, m = map(int, sys.stdin.readline().split())\r\nA = sorted(x for x in map(int, sys.stdin.readline().split()) if x < 0)\r\n\r\nprint(-sum(A[:m]))", "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nmini = []\r\nfor i in l:\r\n if i < 0:\r\n mini.append(i)\r\nmini.sort()\r\nif len(mini) < m:\r\n print(abs(sum(mini)))\r\nelse:\r\n print(abs(sum(mini[0:m])))\r\n", "n,m=list(map(int,input().split()))\r\nsales=list(map(int,input().split()))\r\nsales.sort()\r\ns=0\r\nfor i in range(m):\r\n if sales[i]<0:\r\n s+=sales[i]\r\nprint(abs(s))", "\"\"\"\r\n~~ Author : Bhaskar\r\n~~ Dated : 20.05.2020\r\n\"\"\"\r\n\r\nimport sys,os,io\r\nINT_MAX = sys.maxsize\r\nINT_MIN = -(sys.maxsize)-1\r\n# input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n# input = sys.stdin.readline\r\n# sys.setrecursionlimit(10**6)\r\nmod = 1000000007\r\n\r\nif __name__ == \"__main__\":\r\n n, m = map(int, sys.stdin.readline().split())\r\n a = list(map(int, sys.stdin.readline().split()))\r\n a.sort()\r\n neg = 0\r\n for i in a:\r\n if i < 0:\r\n neg += 1\r\n print(abs(sum(a[:min(neg, m)])))\r\n", "n,m=map(int,input().split())\r\nl=list(sorted(map(int,input().split())))\r\ns=0\r\nfor i in range(0,m):\r\n if(l[i]<0):\r\n s=s+abs(l[i])\r\n else:\r\n break\r\nprint(s)\r\n \r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nans=0\r\ncount=0\r\nfor i in range(n):\r\n if l[i]<0:\r\n ans+=abs(l[i])\r\n count+=1\r\n if count==m:\r\n break\r\n elif l[i]>0:\r\n break\r\nprint(ans)\r\n \r\n", "n, m = (int(x) for x in input().split())\r\na = [int(x) for x in input().split()]\r\na.sort()\r\nsum = 0\r\nfor i in a[:m]:\r\n if i > 0:\r\n break\r\n sum -= i\r\nprint(sum)", "n,num = int(input().split()[-1]),0\r\nfor i in sorted(map(int,input().split())):\r\n if i < 0 and n:\r\n num -= i\r\n n -= 1\r\n else:\r\n break\r\nprint(num)", "m = int(input().split()[-1])\r\nprint(-sum(sorted(map(lambda x: min(int(x),0),input().split()))[:m]))", "a, b = map(int, input().split(\" \"))\r\nls = list(map(int, input().split(\" \")))\r\nct = 1\r\nsumm = 0\r\nls.sort()\r\nfor x in ls:\r\n if ct > b:\r\n break\r\n if x < 0:\r\n summ += (-1)*x\r\n ct += 1\r\nprint(summ)\r\n", "f=lambda:map(int,input().split())\r\nn,m=f()\r\nl=list(f())\r\nl2=sorted([l[i] for i in range(n) if l[i]<0])\r\nprint(-sum(l2[:m]))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nans=0\r\nfor i in range(m):\r\n if a[i]>=0:\r\n break\r\n else:\r\n ans-=a[i]\r\nprint(ans)\r\n", "from itertools import accumulate\r\nn,m = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\nx = list(accumulate(a))\r\nb = x[0]\r\nc=1\r\nfor i in x:\r\n if i<b and c<m:\r\n b = i\r\n c+=1\r\nif b<0:\r\n print(-b)\r\nelse:\r\n print(0)", "n, m=map(int, input().split())\r\na=list(map(int, input().split()))\r\na.sort()\r\n\r\nearned = 0\r\n\r\nfor i in range(m):\r\n\tif a[i]<0:\r\n\t\tearned+=-(a[i])\r\n\telse:\r\n\t\tbreak\r\nprint(earned)", "n,m=map(int,input().split())\nt=list(map(int,input().split()))\nl=[-i for i in t]\nres=0\nl.sort(reverse=True)\ni=1\nwhile i<=m:\n\tif l[i-1]<0:\n\t\tbreak\n\telse:\n\t\tres+=l[i-1]\n\t\ti+=1\nprint(res)", "n,m = map(int,input().split())\r\na = sorted(map(int,input().split()))\r\ns = 0\r\nfor i in range(m):\r\n if a[i]<0:\r\n s-=a[i]\r\nprint(s)", "n, m = [int(s) for s in input().split()]\na = [int(s) for s in input().split()]\na.sort()\n\nbest = -float('inf')\nfor i in range(m):\n best = max(-a[i], best-a[i], best)\n\nprint(0 if best < 0 else best)", "n, m = map(int, input().split())\r\nprint(abs(sum(sorted(list(int(i) for i in input().split() if int(i)<=0))[:m])))", "n,m = map(int, input().split())\r\nl = sorted(map(int, input().split()))[:m]\r\nmoney = 0\r\nfor el in l:\r\n if el < 0:\r\n money += -1*el\r\n\r\nprint(money)", "n,m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\narr.sort()\r\n\r\ncount = 0\r\ni = 0\r\nwhile True:\r\n if not m or i>n-1:\r\n break\r\n \r\n if arr[i]<0:\r\n count += abs(arr[i])\r\n \r\n m-=1\r\n i+=1\r\n \r\n \r\nprint(count)", "n, m = list(int(a) for a in input().split())\r\np = list(int(a) for a in input().split())\r\np.sort()\r\nc = 0\r\nfor i in range(m):\r\n if p[i] >= 0:\r\n break\r\n c -= p[i]\r\nprint(c)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Apr 6 18:28:06 2023\r\n\r\n@author: Srusty Sahoo\r\n\"\"\"\r\n\r\nn,m=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nx=0\r\nfor i in range(m):\r\n if a[i]<0:\r\n x=x+a[i]\r\nprint(x*(-1))", "from sys import stdin, stdout\n\nm = int(stdin.readline().strip('\\n').split()[1])\nstdout.write(str(sum(sorted(filter(lambda x: x <= 0, map(int, stdin.readline().strip('\\n').split())))[:m] + [0]) * -1) + '\\n')\n\n \t\t \t \t\t\t\t\t\t\t\t\t\t\t\t\t \t \t\t\t", "n,m=(map(int,input().split()))\r\nl1=list(map(int,input().split()))\r\ncount=0\r\nl1.sort()\r\nfor i in range(m):\r\n if(l1[i]<0):\r\n count=count-l1[i]\r\n else:\r\n break\r\nprint(count)", "n,m = map(int,input().split())\r\n\r\ns = list(map(int,input().split()))\r\ns.sort()\r\namt = 0\r\nfor data in s:\r\n if data<0 and m>0:\r\n amt+= abs(data)\r\n m-= 1\r\n if m==0:\r\n break\r\nprint(amt)", "n,m=[int(x) for x in input().split(\" \")]\r\nt=[int(x) for x in input().split(\" \")]\r\nt.sort()\r\ns=0\r\nfor i in range(m):\r\n if t[i]<0:\r\n s+=t[i]\r\n else:\r\n break; \r\nprint(s*-1) ", "n,k = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nl = sorted(l)\r\nsumm=0\r\nfor i in range(k):\r\n if(l[i]<0):\r\n summ+=-1*l[i]\r\n \r\nprint(summ)", "def solution():\r\n n, m = map(int, input().split(\" \"))\r\n prices = list(map(int, input().split(\" \")))\r\n prices.sort()\r\n ans = 0\r\n for i in range(m):\r\n if prices[i] < 0:\r\n ans += prices[i]\r\n else:\r\n continue\r\n print(abs(ans))\r\n\r\n\r\nsolution()\r\n", "n, m = map(int, input().split())\r\narray = list(map(int, input().split()))\r\narray.sort()\r\nsums = 0\r\n\r\nfor i in range(m):\r\n if array[i] < 0:\r\n sums += abs(array[i])\r\nprint(sums)\r\n", "n,m = map(int,input().split())\r\na = list(map(int, input().split()))\r\nsums = 0\r\na.sort()\r\nfor i in range(m):\r\n if a[i] < 0:\r\n sums += a[i]\r\n\r\nprint(abs(sums))\r\n\r\n", "from sys import stdin\r\n\r\ndef main():\r\n x,y = [int(x) for x in stdin.readline().split()]\r\n lista = [int(x) for x in stdin.readline().split()]\r\n hola = list()\r\n suma=0\r\n for i in range(x):\r\n if lista[i]<0:\r\n hola.append(lista[i])\r\n for i in range(len(hola)):\r\n for j in range(i+1,len(hola)):\r\n if hola[i]>hola[j]:\r\n hola[j],hola[i]=hola[i],hola[j]\r\n d = len(hola)\r\n n= 0\r\n while n!= d and n!=y: \r\n suma+=hola[n]\r\n n+=1\r\n print(-suma)\r\nmain()\r\n", "setsAtSale,maxSets = input().split();\r\nsetsAtSale = int(setsAtSale)\r\nmaxSets = int(maxSets)\r\nsets = [int(x) for x in input().split()]\r\nsets.sort()\r\nsetsToBuy = sets[:(maxSets)]\r\nsum = 0\r\nfor i in setsToBuy:\r\n if i < 0:\r\n sum+=i\r\nprint(sum*-1)\r\n\r\n", "TVs, m = tuple(map(int, input().split()))\r\n\r\nprices = list(map(int, input().split()))\r\n\r\ndef profit(arr, total, m, mn):\r\n if m == 0:\r\n return mn\r\n n = min(arr)\r\n i = arr.index(n)\r\n mn = min(total + n, mn)\r\n return profit(arr[:i] + arr[i + 1:], total + n, m - 1, mn)\r\n\r\n\r\nn = profit(prices, 0, m, 0)\r\nprint((-1) * n)", "n,m=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\narr=[]\r\nfor i in range(n):\r\n if a[i]<0:\r\n arr.append(a[i])\r\narr.sort()\r\nans=0\r\nfor i in range(min(m,len(arr))):\r\n ans+=arr[i]\r\nprint(ans*-1)\r\n", "l1 = list(map(int,input().split(' ')))\r\nl2 = sorted(list(map(int,input().split(' '))))\r\nsum = 0\r\nfor i in l2:\r\n if (i < 0):\r\n sum += abs(i)\r\n l1[1] -= 1\r\n if l1[1] == 0:\r\n break\r\nprint(sum)", "# LUOGU_RID: 102606410\nn, m, *a = map(int, open(0).read().split())\r\nprint(-sum(sorted([min(0, x) for x in a])[:m]))", "n , m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nl.sort()\r\ns = 0\r\nfor i in range(m):\r\n if l[i] <= 0:\r\n s+=abs(l[i])\r\n else:\r\n break\r\nprint(s)", "n, m = map(int, input().split())\r\na = sorted(map(int, input().split()))\r\nprint(-sum(e for e in a[:m] if e < 0))\r\n\r\n", "if __name__ == \"__main__\":\r\n n, m = map(int, input().split())\r\n\r\n arr = list(map(int, input().split()))\r\n arr.sort()\r\n\r\n sum = 0\r\n for i in range(n):\r\n if arr[i] > 0 or i == m:\r\n break\r\n sum += arr[i]\r\n print(-1 * sum)", "(TV_sets, Bob_strength) = map(int, input().split(' '))\nprices_of_TV_set = list(map(int, input().split(' ')))\nprices_of_TV_set.sort()\n\nearnings = 0\nfor i in range(Bob_strength):\n if prices_of_TV_set[i] > 0:\n break\n earnings -= prices_of_TV_set[i]\n\nprint(earnings)\n\n", "n,m=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nc=0\r\nx.sort()\r\nfor i in range(min(m,n)):\r\n if x[i]<0:\r\n c+=x[i]\r\n else:\r\n break\r\nprint(-c)", "n, m = list(map(int, input().split()))\nmass = list(map(int, input().split()))\nmass.sort()\nans = 0\nfor item in range(0, m):\n\tif item == len(mass):\n\t\tbreak\n\tif mass[item] < 0:\n\t\tans -= mass[item]\n\telse:\n\t\tbreak\n\t\nprint(ans)\n", "n,m=map(int,input().split())\r\narr=[int(i) for i in input().split()]\r\nl=[]\r\ns=0\r\nfor i in arr:\r\n if i<0:\r\n l.append(abs(i))\r\nl.sort(reverse=True)\r\nif m>=len(l):\r\n print(sum(l))\r\nelse:\r\n for i in range(m):\r\n s=s+l[i]\r\n print(s)", "\r\n\r\ndef solution(m, neg_a):\r\n dp = [[0 for _ in range(m+1)] for _ in range(len(neg_a)+1)]\r\n\r\n for curr_m in range(1, m+1):\r\n for curr_i in range(1, len(neg_a)+1):\r\n dp[curr_i][curr_m] = max(dp[curr_i - 1][curr_m], dp[curr_i-1][curr_m - 1] + neg_a[curr_i-1])\r\n\r\n print(dp[len(neg_a)][m])\r\n\r\n\r\nif __name__ == '__main__':\r\n _, m = tuple([int(s) for s in input().split()])\r\n a = [int(s) for s in input().split()]\r\n\r\n neg_a = [-a_i for a_i in a if a_i < 0]\r\n solution(m, neg_a)\r\n", "n,m=map(int,input().split())\r\n\r\narr=list(map(int,input().split()))\r\n\r\narr.sort()\r\n\r\narr=arr[::-1]\r\n\r\nans=0\r\n\r\nfor s in range(n-m,len(arr)):\r\n if arr[s]>0:continue\r\n else:ans+=abs(arr[s])\r\nprint(ans)", "n,m=map(int,input().split())\r\nl=sorted(list(map(int,input().split())))\r\n\r\ns=0\r\nfor i in range(m):\r\n\tif l[i]<0:\r\n\t\ts+=l[i]\r\n\r\nprint(abs(s))", "l1=[int(x) for x in input().split()]\r\nn=l1[0]\r\nm=l1[1]\r\nl=[int(x) for x in input().split()]\r\nl.sort()\r\nans=count=0\r\nfor i in range(n):\r\n if l[i]<0:\r\n count+=1\r\n else:\r\n break\r\nfor j in range(min(count,m)):\r\n ans+=l[j]\r\nprint(abs(ans))", "n,m=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nans=0\r\ncount=0\r\nfor i in range(0,len(a)):\r\n if a[i]<=0:\r\n ans+=abs(a[i])\r\n count+=1\r\n if count==m:\r\n break\r\n if a[i]>0:\r\n break\r\nprint(ans)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort()\r\n\r\nss = 0\r\nk = 0\r\nfor i in a:\r\n if i < 0 and k < m:\r\n ss -= i\r\n k += 1\r\n else:\r\n break\r\n\r\nprint(ss)\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nfor i in range(len(a)-1,-1,-1):\r\n if a[i]>0:\r\n a.remove(a[i])\r\na.sort()\r\nif k>len(a):\r\n k=len(a)\r\nmini=0\r\nfor i in range(k):\r\n mini+=abs(a[i])\r\nprint(mini)", "n,m=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\na.sort()\r\nt=0\r\nfor i in range(min(n,m)):\r\n if a[i]>=0:\r\n break\r\n t=t+a[i]\r\nprint(-t)", "n, m = map(int, input().split())\r\na = sorted(map(int, input().split()))\r\ncnt = 0\r\nfor el in a:\r\n if el >= 0 or m == 0:\r\n break\r\n cnt += -el\r\n m -= 1\r\nprint(cnt)\r\n", "n,m=map(int,input().split())\r\nlst=list(map(int,input().split()))\r\nls=[i for i in lst if i<=0]\r\nls.sort()\r\nif m<=len(ls):\r\n print(abs(sum(ls[0:m])))\r\nelse:\r\n print(abs(sum(ls)))\r\n", "m, n = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nl.sort()\r\ns = 0\r\nfor i in range(n):\r\n if l[i] <= 0:\r\n s += l[i]\r\n else:\r\n print(abs(s))\r\n exit()\r\nprint(abs(s))", "def solve(arr,n,m):\r\n neg=[]\r\n for i in range(n):\r\n if(arr[i]<0):\r\n neg.append(arr[i])\r\n if(len(neg)<=m):\r\n return(-sum(neg))\r\n neg.sort()\r\n return(-sum(neg[:m]))\r\n \r\nn,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nprint(solve(arr,n,m))", "n, m = map(int, input().split())\r\n\r\nprices = list(map(int, input().split()))\r\nprices.sort()\r\n\r\nearn = 0\r\ni = 0\r\nwhile i < m:\r\n if prices[i] < 0:\r\n earn += -prices[i]\r\n i += 1\r\n \r\nprint(earn)", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\narr.sort()\r\nres = 0\r\nfor num in arr:\r\n if num <= 0 and m:\r\n res -= num\r\n m -= 1\r\n else:\r\n break\r\nprint(res)\r\n", "n, m = map(int, input().split())\r\nl = sorted(list(map(int, input().split())))\r\noutput = 0\r\nfor i in range(m):\r\n if l[i] < 0:\r\n output += abs(l[i])\r\n else:\r\n break\r\nprint(output)", "n, m = input().split()\nn = int(n)\nm = int(m)\ns = 0\na = list(map(int, input().split()))\na.sort()\nfor i in range(m):\n if a[i] < 0:\n s -= a[i]\nprint(s)", "n,m=map(int,input().split())\r\nL=sorted(list(map(int,input().split())))\r\na=0\r\nfor i in range(m):\r\n if L[i]<0:\r\n a+=abs(L[i])\r\nprint(a)", "n, m = map(int, input().split())\r\ntvPrices = list(map(int, input().split()))\r\ntvPrices.sort()\r\nmaxSum = 0\r\nfor x in range(m):\r\n if tvPrices[x] < 0:\r\n maxSum = maxSum + tvPrices[x]\r\n\r\n\r\nprint(abs(maxSum))\r\n", "n, m = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nS = []\r\nfor i in range(n):\r\n if a[i] < 0:\r\n S.append(a[i] * -1)\r\nS.sort(reverse=True)\r\nres = 0\r\ni = 0\r\ndl = len(S)\r\nwhile m != 0 and dl != 0:\r\n res += S[i]\r\n m -= 1\r\n i += 1\r\n dl -= 1\r\nprint(res)", "n, m = map(int, input().split())\na = list(map(int, input().split()))\na.sort()\ncount = 0\nfor i in range(m):\n # print(a[i],count)\n if a[i] < 0:\n count += abs(a[i])\nprint(count)", "a=input()\r\nb=list(map(int, a.split(\" \")))\r\n\r\nn=input()\r\nl=list(map(int, n.split(\" \")))\r\n\r\nsum=0\r\nx=b[0]\r\n\r\nfor i in range(x-1):\r\n for j in range(0,x-i-1):\r\n if l[j]>l[j+1]:\r\n temp=l[j]\r\n l[j]=l[j+1]\r\n l[j+1]=temp\r\n\r\nfor i in range(b[1]):\r\n\r\n if(l[i]<0):\r\n sum=sum-l[i]\r\n\r\n\r\nprint(sum)", "n,m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nl.sort()\r\nc = 0\r\nfor i in range(m):\r\n if l[i] <= 0:\r\n c -= l[i]\r\nprint(c)", "n,m = list(map(int, input().split()))\nlst = list(map(int, input().split()))\nlst.sort()\ncount = 0\nfor i in range(m):\n if lst[i] <= 0:\n count += lst[i]\n else:\n break\nprint(abs(count))", "n, m = [int(x) for x in input().split()]\r\na = [int(x) for x in input().split()]\r\na.sort()\r\nans = 0\r\nfor i in range(0, n):\r\n if a[i] >= 0 or m <= 0:\r\n break\r\n else:\r\n ans -= a[i]\r\n m -= 1\r\nprint(ans)", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\narr.sort()\r\ns=0\r\nfor i in range(m):\r\n if(arr[i]>=0):\r\n break\r\n s-=arr[i]\r\nprint(s)", "#arr = list(map(int,input().split()))\r\n#n,m = map(int,input().split())\r\n#for string inputs:\r\n#arr = list(map(int, list(input())))\r\n\r\n\r\nn,m = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nsum = 0\r\nfor i in range(m):\r\n if arr[i]<0:\r\n sum -= arr[i]\r\n else: break\r\nprint(sum)\r\n", "n, m = map(int, input().split())\r\nprint(-sum(sorted(int(x) for x in input().split() if x[0] == '-')[:m]))", "n, m = map(int, input().split())\r\nseq = sorted(int(i) for i in input().split() if '-' in i)\r\nprint(-sum(seq[:m]))\r\n", "n,m = map(int,input().split(' '))\r\ntvset = list(map(int,input().split(' ')))\r\ntvset.sort()\r\nans = 0\r\nfor i in range(n):\r\n if tvset[i]<0:\r\n ans += tvset[i]\r\n m-=1\r\n if m==0:\r\n break\r\n else:\r\n break\r\nprint(abs(ans))", "n, m = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\narr.sort()\r\nans = 0\r\nfor i in range(m):\r\n\tif arr[i] < 0:\r\n\t\tans += abs(arr[i])\r\n\telse:\r\n\t\tbreak\r\nprint(ans)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\n\r\nc = 0\r\nfor i in range(m):\r\n if a[i] < 0:\r\n c += abs(a[i])\r\n\r\nprint(c)", "n,m = map(int, input().split(' '))\r\narr = list(map(int, input().split()))\r\n\r\nvigoda = []\r\n\r\nfor i in arr:\r\n if i <= 0:\r\n vigoda.append(i)\r\n\r\nvigoda.sort()\r\n\r\nzarabotok = 0\r\nif m> len(vigoda):\r\n for i in range(0, len(vigoda)):\r\n zarabotok += vigoda[i]\r\nelse:\r\n for i in range(0, m):\r\n zarabotok += vigoda[i]\r\n\r\nprint(-zarabotok)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "while True:\n\ttry:\n\t\tdef solution(n, c, price):\n\t\t\tprice.sort()\n\t\t\tcunt = 0\n\t\t\tfor i in range(len(price)):\n\t\t\t\tif price[i] < 0:\n\t\t\t\t\tcunt += price[i]\n\t\t\t\t\tc -= 1\n\t\t\t\telse:\n\t\t\t\t\tbreak\n\t\t\t\tif c == 0:break\n\t\t\tprint(abs(cunt))\n\t\t\n\t\tdef read():\n\t\t\tn, c = map(int, input().split())\n\t\t\tprice = list(map(int, input().split()))\n\t\t\tsolution(n, c, price)\n\t\t\t\n\t\tif __name__ == \"__main__\":\n\t\t\tread()\n\texcept EOFError:\n\t\tbreak\n \t\t \t \t \t \t \t\t\t\t", "n,m=map(int,input().split())\r\ns=list(map(int,input().split()))\r\ns.sort()\r\nc=0\r\nfor i in range(m):\r\n if s[i]<=0:\r\n c+=abs(s[i])\r\n else:\r\n break\r\nprint(c)", "\r\ndef m():\r\n\t\r\n\tn,m = [int(x) for x in input().split()]\r\n\tnum = [int(x) for x in input().split()]\r\n\r\n\tnum.sort()\r\n\tans = 0\r\n\tif num[0] >= 0:\r\n\t\tprint(0)\r\n\t\treturn\r\n\r\n\tfor i in range(m):\r\n\t\tif num[i] > 0:\r\n\t\t\tbreak \r\n\t\telse:\r\n\t\t\tans += num[i]\r\n\r\n\tprint(abs(ans)) \r\n\r\nm()", "if __name__==\"__main__\":\r\n n,m=input().split()\r\n n,m=int(n),int(m)\r\n tv=list(map(int,input().split()))\r\n negPrice=[x for x in tv if x<0]\r\n negPrice.sort()\r\n gain=0\r\n i=0\r\n while i<len(negPrice) and i<m: gain+=negPrice[i];i+=1\r\n print(-gain)\r\n\r\n", "n, m = list(map(int, input().split()))\r\na = sorted(map(int, input().split()))\r\nsum = 0\r\nfor x in a:\r\n if m == 0:\r\n break\r\n if x >= 0:\r\n break\r\n sum -= x\r\n m -= 1\r\nprint(sum)", "n,m=map(int,input().split())\na=list(map(int,input().split()))\n\na=sorted(a)\ni=0\nrj=0\n\nwhile m>0 and a[i]<0:\n rj+=abs(a[i])\n m-=1\n i+=1\n\nprint(rj)\n\n \t \t \t \t \t\t\t \t \t\t\t\t\t \t", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nsum=0\r\nfor i in range(n):\r\n if a[i]<0 and m>0:\r\n sum+=((-1)*a[i])\r\n m-=1\r\n else:\r\n break\r\nprint(sum)", "n, m = map(int, input().split())\r\ncosts = sorted(list(map(int, input().split())))\r\nsumm = 0\r\nfor i in costs:\r\n if m > 0:\r\n if i < 0:\r\n summ += i\r\n m -= 1\r\n else:\r\n break\r\n\r\nprint(abs(summ))\r\n\r\n", "\r\nn, m = map(int, input().split())\r\na = list(sorted(map(int, input().split())))\r\nmm = 0\r\nc = 0\r\ni = 0\r\nwhile i < m:\r\n if not a[i] > 0:\r\n mm += abs(a[i])\r\n i += 1\r\nprint(mm)\r\n# CodeForcesian\r\n# ♥\r\n# nothing\r\n# Im Good :((((\r\n", "d = input()\r\na=d.split(\" \")\r\nn = int(a[0])\r\nm= int(a[1])\r\n\r\n\r\nc= input()\r\nb = c.split(\" \")\r\nfor i in range(len(b)):\r\n b[i]= int(b[i])\r\n\r\nb.sort()\r\nsum = 0\r\nfor i in range(m):\r\n if (b[i] < 0):\r\n sum = sum + b[i]\r\n\r\nprint(abs(sum))", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort()\r\nsum = int(0)\r\ni = int(0)\r\nwhile i<m and a[i]<0:\r\n sum += a[i]\r\n i+=1\r\nprint(abs(sum))", "n,m=map(int,input().strip().split() )\n\nl = list(map(int, input().strip().split()))\n\n\nl2 = []\n\nfor i in l:\n\n\tif i < 0:\n\t\tl2.append(i*-1)\n\nl2.sort()\nl2.reverse()\n\nprint(sum(l2[ : m]))", "n,m = map(int,input().split())\r\na=list(map(int,input().split())) # '12' '15' 6 -3\r\n#a=sorted(a)\r\na.sort()\r\ni=0\r\nsom=0\r\nwhile(m > i and a[i] <= 0 ):\r\n som+=a[i]\r\n i+=1\r\nprint(abs(som))", "from sys import stdin\r\ndef main():\r\n n,m= [int(x) for x in stdin.readline().strip().split()]\r\n lista= list(map(int, stdin.readline().strip().split()))\r\n lista.sort()\r\n suma= 0\r\n for i in range(m):\r\n if lista[i]>=0:\r\n break\r\n else:\r\n suma+= lista[i]\r\n print(abs(suma))\r\nmain()\r\n", "x, y = input().split()\r\nx = int(x)\r\ny = int(y)\r\nz = input().split()\r\nfor i in range(len(z)):\r\n z[i] = int(z[i])\r\nz.sort()\r\namount = 0\r\nfor j in range(len(z)):\r\n if(z[j] < 0):\r\n amount += 1\r\nif(amount > y):\r\n amount = y\r\nfinal = 0\r\nfor k in range(amount):\r\n final += z[k]\r\nfinal = int((final * final) ** 0.5)\r\nprint(final)", "import math\n\nn,m = [int(i) for i in input().split()]\n\ntv = [int(i) for i in input().split()]\ntv.sort()\n\nans=0\n\nfor i in range(m):\n if (tv[i]<0):\n ans-=tv[i]\n else:\n break\n\nprint(ans)\n\n\t\t\t\t \t\t \t \t \t \t\t\t\t\t\t \t", "from sys import stdin, stdout\r\nn, m = map(int, stdin.readline().strip().split())\r\ntv_sets = list(map(int, stdin.readline().strip().split()))\r\ntv_sets.sort(reverse = True)\r\nmoney = 0\r\nwhile(m!=0):\r\n x = tv_sets.pop()\r\n if x>0:\r\n break\r\n money-=x\r\n m-=1\r\nstdout.write(f\"{money}\\n\")\r\n ", "s=input().split()\r\nn=int(s[0])\r\nm=int(s[1])\r\nS=input().split()\r\nres=[]\r\nfor i in range(len(S)):\r\n\tif int(S[i])<0:\r\n\t\tres.append(int(S[i]))\r\nres.sort()\r\nprint(abs(sum(res[:m])))", "n, m = map(int, input().split())\na = sorted(list(map(int, input().split())))\ns = 0\nfor x in a:\n if x <= 0 and m > 0:\n m -= 1\n s += x\nprint(abs(s))\n\t \t\t \t\t \t \t\t\t\t \t \t\t \t\t\t \t \t\t", "n,m=map(int,input().split()) \r\nl=list(map(int,input().split()))\r\nl.sort()\r\nsum=0\r\nfor i in range(m):\r\n if(l[i]<=0):\r\n sum+=l[i]\r\nprint(-sum)", "n, m = map(int, input().split())\r\nsale = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(m):\r\n if min(sale) < 0:\r\n ans += abs(min(sale))\r\n sale.remove(min(sale))\r\n else:\r\n break\r\nprint(ans)\r\n", "n,m=map(int,input().split())\r\ntv_list=sorted(list(map(int,input().split())))\r\nearning=0\r\nfor i in range(m):\r\n if(tv_list[i]<0):\r\n earning+=abs(tv_list[i])\r\nprint(earning)", "n,m=map(int,input().split())\r\nl=sorted([x for x in list(map(int,input().split())) if x<=0])\r\nprint([abs(sum(l)),abs(sum(l[:m]))][m<len(l)])\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\na = sorted(a)\r\n\r\nans = 0\r\nfor i in range(m):\r\n if a[i] < 0:\r\n ans -= a[i]\r\n else:\r\n break\r\n \r\nprint(ans)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl1=[i for i in l if i<0]\r\nl1.sort()\r\na=len(l)\r\nl1=l1[0:min(m,a)]\r\nprint(abs(sum(l1)))", "def tv(arr,k):\r\n\tneg=[]\r\n\tfor i in arr:\r\n\t\tif i<0:\r\n\t\t\tneg.append(abs(i))\r\n\tneg=sorted(neg,reverse=True)\r\n\treturn sum(neg[:min(len(neg),k)])\r\na,b=map(int,input().strip().split())\r\nlst=list(map(int,input().strip().split()))\r\nprint(tv(lst,b))", "n,m=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\nb=list()\r\nfor i in a:\r\n if(i<0):\r\n b.append(i)\r\nb=sorted(b)\r\nif(m>len(b)):\r\n print(-sum(b))\r\nelse:\r\n print(-sum(b[:m]))", "\r\ndef calc(n,m,a):\r\n a = sorted(a)\r\n e, i = 0,0\r\n for o in a:\r\n if o < 0:\r\n e += -o\r\n i += 1\r\n if i >= m:\r\n break\r\n return e\r\n# get inputs\r\nn,m = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nprint(calc(n,m,a))\r\n", "n, k = map(int, input().split())\na = [a for a in sorted(map(int, input().split())) if a < 0]\nprint(-sum(a[:k])) \n", "n_m = [int(i) for i in input().split(\" \")]\r\nnnn = [int(i) for i in input().split(\" \") if int(i) <= 0]\r\nout = 0\r\nif n_m[1] < len(nnn):\r\n for i in range(n_m[1]):\r\n out += min(nnn)\r\n nnn.remove(min(nnn))\r\nelse:\r\n out = sum(nnn)\r\nprint(out * -1)", "from sys import stdin\r\ndef ordenar(cad,lon):\r\n if lon==0:\r\n return cad\r\n else:\r\n for z in range(lon-1):\r\n if cad[z]>cad[z+1]:\r\n w=cad[z]\r\n cad[z]=cad[z+1]\r\n cad[z+1]=w\r\n return ordenar(cad,lon-1)\r\n \r\ndef main():\r\n tvs=[int(x) for x in stdin.readline().strip().split()]\r\n precios=[int(x) for x in stdin.readline().strip().split()]\r\n precios=ordenar(precios,tvs[0])\r\n z=0\r\n for con in range(tvs[1]):\r\n if precios[con]<0:\r\n z=z+abs(precios[con])\r\n print(z)\r\n\r\nmain()\r\n \r\n", "n,m = map(int,input().split())\r\nnums = list(map(int, input().split()))\r\n\r\nind = 0\r\noutput = 0\r\nnums.sort()\r\nwhile ind < m and ind < n:\r\n if nums[ind] < 0:\r\n output -= nums[ind]\r\n else:\r\n break\r\n ind += 1\r\nprint(output)", "n, m = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na.sort()\r\nans = 0\r\ni = 0\r\nwhile i<m:\r\n if a[i]<0: ans-=a[i];\r\n i+=1\r\nprint(ans)", "n,m=[int(y) for y in input().split()]\r\nbellars=[int(x) for x in input().split()]\r\nbellars.sort()\r\n\r\nsum=count=0\r\n\r\nfor i in range(n):\r\n if count<m:\r\n if bellars[i] <0:\r\n sum+=bellars[i]\r\n count+=1\r\n else:\r\n break\r\n else:\r\n break\r\nprint(abs(sum))\r\n", "n, k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nx = 0\r\ni = 0\r\nwhile i<n and k>0:\r\n if arr[i]<0:\r\n x += arr[i]\r\n i += 1\r\n k -= 1\r\n else:\r\n break\r\nprint(abs(x))", "n, m = map(int, input().split())\nai = list(map(int, input().split()))\nai.sort()\n\nearnings = 0\nfor price in ai:\n if m > 0 and price < 0:\n earnings += abs(price)\n m -= 1\n\nprint(earnings)\n", "n, m = map(int,input().split())\r\naps = 0\r\na = list(map(int,input().split()))\r\na.sort()\r\nfor i in range(m):\r\n if a[i]<0:\r\n aps-=a[i]\r\nprint(aps)", "n, m = [*map(int, input().split())]\r\na = sorted([*filter(lambda x : x < 0, map(int, input().split()))])\r\nprint(abs(sum(a[:min(len(a), m)])))", "s = (input()).split()\r\nn = int(s[0])\r\nm = int(s[1])\r\nz = []\r\ntv = input().split()\r\nfor t in tv:\r\n if int(t) < 0:\r\n z.append(-int(t))\r\nz = sorted(z, reverse=True)\r\nresult = 0\r\nx = len(z) \r\nfor i in range(m):\r\n if x == 0:\r\n break\r\n result += int(z[i])\r\n x -= 1\r\nprint(result)", "n, m = [int(x) for x in input().split(' ')]\r\nA = [int(x) for x in input().split(' ')]\r\nA.sort()\r\ngg = 0\r\nfor i in range(m):\r\n\tif(A[i] >= 0):\r\n\t\tbreak\r\n\tgg -= A[i]\r\nprint(gg)", "n, m = [int(x) for x in input().split(' ')]\r\n\r\narr = [int(x) for x in input().split(' ')]\r\n\r\narr.sort()\r\nres = 0 \r\nfor i in range(m):\r\n\tif arr[i] < 0:\r\n\t\tres -= arr[i]\r\n\r\nprint(res)", "n,m=map(int,input().split())\r\narr = list(map(int, input().split()))\r\nres = [arr[i] for i in range(n) if arr[i]<=0]\r\nres.sort()\r\nprint(-1*sum(res[:m]))", "a,b = map(int, input().split())\r\nx = sorted(list(map(int, input().split())))\r\nsum = 0\r\nfor i in x:\r\n if i>=0 or b==0:\r\n break\r\n sum = sum- i\r\n b = b - 1\r\nprint(sum)", "def solve(m, n, a):\n return sum(-i for i in sorted(a)[:m] if i <= 0)\n\ndef main():\n n, m = list(map(int, input().split()))\n a = list(map(int, input().split()))\n print(solve(m, n, a))\n\n\nmain()\n", "n,m=map(int,input().split(\" \"))\r\nlis=list(map(int,input().split(\" \")))\r\nlis.sort()\r\nsum=0\r\n#print(lis)\r\nfor i in range(m):\r\n\tif(lis[i]<=0):\r\n\t\tsum=sum+abs(lis[i])\r\nprint(sum)", "m, n = map(int, input().split())\r\n\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\n\r\nmaxSum = 0\r\ncount = 0\r\nfor i in range(n):\r\n if count >= m:\r\n break\r\n if a[i]*-1 + maxSum > maxSum:\r\n maxSum += a[i]*-1\r\n count+=1\r\n\r\nprint(maxSum)", "n=list(map(int,input().split()))\r\nn1=list(map(int,input().split()))\r\nlst=[]\r\ns=0\r\nfor i in n1:\r\n if(i<0):\r\n lst.append(i*-1)\r\nlst.sort()\r\nlst.reverse()\r\nprint(sum(lst[:n[1]]))\r\n", "from sys import stdin, stdout\r\n# sys.setrecursionlimit(100000)\r\n\r\ndef main():\r\n n, m = map(int, stdin.readline().split(' '))\r\n a = list(map(int, stdin.readline().split(' ')))\r\n a.sort()\r\n x = 0\r\n for e in a:\r\n if m <= 0:\r\n break\r\n if e<0:\r\n x -= e\r\n m -= 1\r\n stdout.write(str(x)+'\\n')\r\n\r\nif __name__ == \"__main__\":\r\n main()", "#34B\r\nn,m=map(int,input().split())\r\na=[int(x) for x in input().split()]\r\nb=list(filter(lambda x:x<0,a))\r\nb=sorted(b)\r\nif len(b)<=m:\r\n print(-sum(b))\r\nelse:\r\n print(-sum(b[0:m]))\r\n", "\r\nn,m =map(int,input().split())\r\na= sorted(list(map(int,input().split())))\r\na=a[:m]\r\nans=0\r\nfor i in a:\r\n\tif i<0 :\r\n\t\tans+=i\r\n\telse:\r\n\t\tbreak\r\nprint(abs(ans))\r\n", "a = [int(x) for x in input().split()]\r\nn = a[0]\r\nm = a[1]\r\np = [int(x) for x in input().split()]\r\np.sort()\r\no = p[0]\r\nz = o\r\nfor i in range(1,m):\r\n z += p[i]\r\n o = min(o, z)\r\nif o >= 0:\r\n print(0)\r\nelse: print(-o)", "n,m=list(map(int,input().split()))\r\ns=list(map(int,input().split()))\r\ns.sort()\r\nans=0\r\nfor i in range(m):\r\n if s[i]<=0:\r\n ans=ans+abs(s[i])\r\nprint(ans)\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n", "n, m = map(int, input().strip().split())\ntvs = [tv for tv in map(int, input().strip().split()) if tv < 0]\ntvs.sort()\nprint(abs(sum(tvs[:m])))", "[n, m] = list(map(int, input().split(\" \")))\r\na = sorted(list(filter(lambda x: x < 0, list(map(int, input().split(\" \"))))))\r\nprint(-sum(a[0:m]))\r\n", "x,y = map(int, input().split())\r\nT = list(map(int, input().split()))\r\nT.sort()\r\nneg = 0\r\nfor i in range(x):\r\n if T[i]<0:\r\n neg = neg+1\r\nif neg<y:\r\n a = sum(T[0:neg])\r\nelse:\r\n a = sum(T[0:y])\r\nprint(abs(a))", "a=[int(i) for i in input().split()]\r\nn,m=a[0],a[1]\r\nb=[int(i) for i in input().split()]\r\nb.sort()\r\nc=[]\r\nfor i in b:\r\n if i<=0:\r\n c.append(i)\r\nif len(c)>=m:\r\n print(abs(sum(c[:m])))\r\nelse:\r\n print(abs(sum(c[:])))", "count=0\r\nn,m=input().split(\" \")\r\nn,m=int(n),int(m)\r\nk=list(map(int,input().split(\" \")))\r\nfor i in range(m):\r\n x=min(k)\r\n if x<0:\r\n count+=-x\r\n del k[k.index(x)]\r\n else:\r\n break\r\nprint(count) ", "a, b = map(int, input().split())\r\nq = list(map(int, input().split()))\r\nc = 0\r\nwhile min(q) <= 0 and b > 0:\r\n b -= 1\r\n if min(q) != 55555:\r\n c += min(q)\r\n q[q.index(min(q))] = 55555\r\nif c < 0:\r\n c = str(c)\r\n c = c.replace('-', '')\r\n c = int(c)\r\nprint(c)", "n,m = map(int,input().split())\r\n\r\nl = list(map(int,input().split()))\r\n\r\nl.sort()\r\n\r\nres = 0\r\n\r\nfor i in l:\r\n if i<=0 and m>0:\r\n res+=abs(i)\r\n m-=1\r\nprint(res)", "# B. Sale\r\nn,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ne=0\r\nfor i in range(m):\r\n if l[i]<=0:\r\n e+=abs(l[i])\r\nprint(e)", "n,m = input().split()\r\na = list(map(int, input().strip().split()))\r\na.sort(reverse=False)\r\nm = int(m)\r\nl = []\r\nx = []\r\nfor i in range(m):\r\n x.append(a[i])\r\nfor num in x:\r\n if num < 0:\r\n l.append(num)\r\ny = sum(l)\r\nprint(y*-1)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n, m = map(int, input().split())\r\nnums = [int(x) for x in input().split()]\r\nnums.sort()\r\n\r\ntotal = 0\r\nfor num in nums:\r\n if num < 0 and m > 0:\r\n total -= num\r\n m -= 1\r\n else:\r\n break\r\nprint(total)\r\n", "n,m=map(int,input().split())\r\nl=sorted(list(map(int,input().split())))\r\nc=0\r\ns=0\r\nfor i in l:\r\n if(i<0 and c<m):\r\n s+=i \r\n c+=1 \r\n else:\r\n break \r\nprint(-s)", "n, m = map(int, input().split())\r\nprices = sorted(list(map(int, filter(lambda x: int(x) <= 0, input().split()))))\r\nprices = prices[:m]\r\nprint(-sum(prices))", "n, m = [int(i) for i in input().split()]\r\nlis = [int(i) for i in input().split()]\r\n\r\nlis.sort()\r\nsum = 0\r\nfor i in range(m):\r\n if lis[i] <0:\r\n sum+= lis[i]\r\nprint(-1*sum)", "m=int(input().split()[1])\r\na=sorted(x for x in map(int,input().split())if x<0)\r\nprint(sum(a[m:])-sum(a))", "n, m = [int(c) for c in input().split()]\nprices = [int(c) for c in input().split()]\nunder_zero = []\nfor i in range(len(prices)):\n if prices[i] < 0:\n under_zero.append(prices[i])\nunder_zero.sort()\nif len(under_zero) > m:\n earnings = abs(sum(under_zero[:m]))\nelse:\n earnings = abs(sum(under_zero))\nprint(earnings)", "n=list(map(int,input().split()))\r\nm=list(map(int,input().split()))\r\n\r\ns=[]\r\nfor i in range(n[0]):\r\n if(m[i]<0):\r\n s.append(abs(m[i]))\r\n\r\ns.sort(reverse=True)\r\n\r\nsum=0\r\nif(len(s)>=n[1]):\r\n for i in range(n[1]):\r\n sum+=s[i]\r\nelse:\r\n for i in range(len(s)):\r\n sum+=s[i]\r\n\r\nprint(sum)\r\n", "__author__ = 'Rajan'\r\n\r\nn,m = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\nans = 0\r\nfor i in range(m):\r\n if a[i]<0:\r\n ans+=a[i]\r\n\r\nprint(-1*ans)\r\n\r\n", "m, n = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\nprices = sorted(prices)\r\ntotal = 0\r\nfor p in range(n):\r\n if prices[p] < 0:\r\n total += prices[p]\r\nprint(total * -1)", "m = int(input().split()[1])\r\nprint(-sum(sorted(int(i) for i in input().split() if i < '0')[:m]))", "n, m = map(int, input().split())\nprice = list(map(int, input().split()))\nprice.sort()\ntotal = 0\nfor i in range(n):\n if i < m and price[i] < 0:\n total += -price[i]\nprint(total)\n \t \t\t \t \t\t \t\t \t\t \t \t \t \t", "n,m=[int(x) for x in input().split()]\r\ncosts = sorted([int(x) for x in input().split()])\r\nearn=0\r\nk=m\r\nfor i in range(n):\r\n if k<=m and k!=0:\r\n if costs[i] < 0:\r\n earn+=abs(costs[i])\r\n k-=1\r\n \r\nprint(earn)", "a=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\n\r\nb.sort()\r\nc=0\r\nfor i in range(a[1]):\r\n if b[i]<=0:c+=b[i]*(-1)\r\nprint(c)", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nfil = list(filter(lambda c : c <= 0, arr))\r\nfil.sort()\r\nprint(-sum(fil[: m]))\r\n", "n, m = map(int, input().split())\r\npr = list(map(int, input().split()))\r\nn_pr = sorted([p for p in pr if p < 0])\r\nprint(-sum(n_pr[:m]))", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[204]:\n\n\n# # n = int(input())\n# # line = list(map(int, input().split()))\n# # line = list(str(input()))\n\n\n# In[370]:\n\n\nline1 = list(map(int, input().split()))\nline2 = list(map(int, input().split()))\n\n\n# In[371]:\n\n\nn, m = line1[0], line1[1]\n\n\n# In[375]:\n\n\ncarry = sorted(line2)[:m]\n\n\n# In[380]:\n\n\nquick_earn = sum([i for i in carry if i < 0])\n\n\n# In[382]:\n\n\nprint(abs(quick_earn))\n\n\n# In[ ]:\n\n\n\n\n", "n, m = map(int, input().split())\r\nif n>1:\r\n tv = sorted(i for i in list(map(int, input().split())) if i<=0)\r\nelse:\r\n tv = [i for i in [int(input())] if i<=0]\r\ncost = i = 0\r\nwhile i<len(tv) and m>0:\r\n cost += abs(tv[i])\r\n i += 1\r\n m -= 1\r\nprint(cost)\r\n", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\ncount = m\r\nans = 0\r\nfor i in range(len(a)):\r\n\tk = min(a)\r\n\tif k<0:\r\n\t\tans = ans -k\r\n\t\tcount-=1\r\n\t\ta[a.index(k)]=1\r\n\telse:\r\n\t\tbreak\r\n\tif count==0:\r\n\t\tbreak\r\nprint(ans)", "n,m=map(int,input().split())\na=list(map(int,input().split()))\na.sort()\nans=0\nfor i in range(m):\n ans+=min(0,a[i])\nprint(-ans)\n", "n, m = map(int, input().split())\r\ntvs = sorted(list(map(int, input().split())))\r\ncounter = -1\r\nfor i in range (n):\r\n if tvs[i] > -1:\r\n counter = i\r\n break\r\nif counter == -1:\r\n counter = n\r\nif counter < m:\r\n ans = sum(tvs[:counter])\r\nelse:\r\n ans = sum(tvs[:m])\r\nprint(-ans)", "n,k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\ns=0\r\nfor i in range(k):\r\n if arr[i]>0:\r\n break\r\n s+=arr[i]\r\nprint(abs(s))", "\r\n\r\nn, m = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\na.sort()\r\nsu = 0\r\nfor i in range(m):\r\n if (a[i] >= 0):\r\n break\r\n su -= a[i]\r\nprint (su)\r\n ", "n,m=[int(i) for i in input().split()]\r\nc= [d for d in sorted(map(int,input().split())) if d<0 ]\r\nprint (-sum(c[:m]))", "n,m=map(int,input().split())\r\nl=[int(x) for x in input().split()]\r\nl.sort()\r\ns=0\r\nfor i in range(m):\r\n if l[i]<0:\r\n s+=abs(l[i])\r\n else:\r\n break\r\nprint(s)", "n,m = map(int,input().split())\na = sorted(list(map(int,input().split())))\nt = 0\nfor i in a:\n if i>0:\n break\n t+=i\n m-=1\n if m == 0:\n break\nprint(abs(t))\n\n", "n,m=list(map(int,input().rstrip().split()))\r\nlst=list(map(int,input().rstrip().split()))\r\nans=0\r\nlst.sort()\r\nfor i in range(m):\r\n if lst[i]<0:\r\n ans-=lst[i]\r\n else:\r\n break\r\nprint(ans)", "n,m=map(int,input().split())\r\nl=[int(i) for i in input().split()]\r\nl.sort() \r\nc=0\r\nfor i in range(len(l)):\r\n if m>0 and l[i]<0:\r\n c+=l[i] \r\n m-=1\r\n else:\r\n break \r\nprint(-c)", "n,m=input().split(\" \")\r\nn,m = int(n),int(m)\r\n\r\ns = input().split(\" \")\r\nfor i in range(len(s)):\r\n s[i]=int(s[i])\r\n\r\ns.sort()\r\n\r\nearn=0\r\nfor j in range(len(s)):\r\n if(m<=0):\r\n break\r\n if(s[j]<=0):\r\n earn+=s[j]\r\n m-=1\r\n\r\nprint(abs(earn))\r\n", "n,m=map(int,input().split())\r\ndum=list(map(int,input().split()))\r\ndummy=[i for i in dum if i<0]\r\ndummy=sorted(dummy)\r\nif len(dummy)<=m:\r\n print(abs(sum(dummy)))\r\nelse:\r\n print(abs(sum(dummy[0:m])))", "a,b=map(int,input().split())\r\nl=[int(x) for x in input().split()]\r\nl.sort()\r\nsum=0\r\nfor i in range(b):\r\n if(l[0]<0):\r\n sum=sum-l[0]\r\n l.pop(0)\r\nprint(sum)", "n, m = map(int, input().split())\r\nuarr = list(map(int, input().split()))\r\n\r\narr=sorted(uarr)\r\n\r\nsum = 0\r\nfor k in range(m):\r\n if arr[k] < 0:\r\n sum += abs(arr[k])\r\n else:\r\n break\r\n\r\nprint(sum)\r\n", "a, b = map(int, input().split())\r\ns = 0\r\nx = sorted(list(map(int, input().split())))\r\nfor i in range(b):\r\n if x[i] < 0:\r\n s += x[i]\r\nprint(abs(s))", "n, m = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nans = 0\r\nfor i in range(m):\r\n if a[i] < 0:\r\n ans += a[i]\r\nprint(-ans)", "_,n_max = map(int,input().split())\r\nlis = sorted(list(map(int,input().split())))\r\nmax_count = 0\r\nfor x in range(n_max):\r\n max_count = min(max_count,max_count+lis[x])\r\nprint(abs(max_count))", "n, m = [int(j) for j in input().split()]\r\na = [int(j) for j in input().split()]\r\na.sort()\r\nc = 0\r\nf = 0\r\nfor i in range(n):\r\n if a[i] >= 0:\r\n c = i\r\n f = 1\r\n break\r\nif f ==0:\r\n c = n\r\nif c >= m:\r\n print(abs(sum(a[:m])))\r\nelse:\r\n print(abs(sum(a[:c])))\r\n", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\narr.sort()\r\nans = 0\r\nfor i in range(m):\r\n if arr[i] < 0: ans += arr[i]\r\nprint(abs(ans))", "import sys\r\nimport itertools\r\n\r\ninputs = []\r\nfor line in sys.stdin:\r\n inputs.append(line)\r\n\r\nn = int(inputs[0].strip().split()[0])\r\ncanCarry = int(inputs[0].strip().split()[1])\r\ntvSets = inputs[1].strip().split()\r\nfor i in range(0,len(tvSets)):\r\n tvSets[i] = int(tvSets[i])\r\ntvSets.sort()\r\n\r\nmaxEarned = 0\r\nsum = 0\r\nfor i in range(0,canCarry):\r\n sum+=tvSets[i]\r\n if (-1*sum) > maxEarned:\r\n maxEarned = (-1*sum)\r\nprint(maxEarned)", "n, m = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\ncount = 0\r\nsumma = 0\r\na.sort()\r\nfor j in a:\r\n if j < 0 and count < m:\r\n count += 1\r\n summa -= j\r\nprint(summa)\r\n", "(n,m)=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nsumbob=0\r\nfor i in range(m):\r\n if l[i]<=0:\r\n sumbob+=l[i]\r\n else:\r\n pass\r\nprint(abs(sumbob))", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nres=0\r\nfor i in range(m):\r\n if arr[i]>=0:\r\n break\r\n res+=arr[i]\r\nprint(-res)", "n,m = input().split()\r\nL = [int(a) for a in input().split(\" \",int(n)-1)]\r\nsum=0\r\nL.sort()\r\nsum = sum\r\nfor i in range(int(m)):\r\n if L[i]<0:\r\n sum = sum+L[i]\r\nprint(-sum)", "n, m = map(int, input().split())\r\nw = list(map(int, input().split()))\r\ns = []\r\nfor i in w:\r\n if i < 0:\r\n s.append(i)\r\n\r\ns.sort()\r\nM = -9999999\r\nfor i in range(m+1):\r\n if M < abs(sum(s[:i])):\r\n M = abs(sum(s[:i]))\r\n\r\nif M == -999999:\r\n print(0)\r\nelse:\r\n print(M)\r\n\r\n", "def cast_to_int(num):\r\n return int(num)\r\n\r\n\r\nn, m = map(cast_to_int, input().split())\r\n\r\na = list(filter(lambda el: el <= 0, list(map(cast_to_int, input().split()))))\r\na.sort()\r\n\r\nprint(-sum(a[:m]))", "n,m = list(map(int,input().split()))\r\narr = [ int(i) for i in input().split()]\r\narr = sorted(arr)\r\ns = 0\r\nfor i in range(m):\r\n if arr[i] < 0:\r\n s += (-1)*arr[i]\r\nprint(s)", "n,m=map(int,input().split())\r\nl=sorted(list(map(int,input().split())))\r\ns,x=0,0\r\nfor i in range(n):\r\n\tif x==m:\r\n\t\tbreak\r\n\tif l[i]<0:\r\n\t\ts+=l[i]\r\n\t\tx+=1\r\nprint(-s)", "n, m = [int(x) for x in input().split()]\nq = [int(x) for x in input().split()]\nq.sort()\nans = 0\nfor idx, elmt in enumerate(q):\n\tif idx >= m: break\n\tans = max(ans - elmt, ans)\nprint(ans)\n\t \t \t \t\t\t\t \t \t\t \t\t\t \t\t \t\t", "def main():\n maxcarrry = int(input().split()[1])\n print(-sum(sorted(filter(lambda x: x < 0,\n list(map(int, input().split()))))[:maxcarrry]))\n\n\nmain()\n", "n,m = map(int,input().split())\r\nc=list(map(int,input().split()))\r\ne=[abs(x) for x in c if x<0]\r\nif m>=n:\r\n print(sum(e))\r\nelse:\r\n s=sorted(e,reverse=True)\r\n print(sum(s[:m]))", "m, n = input().split()\r\nm = int(m)\r\nn = int(n)\r\nmass = input().split(' ')\r\n\r\nfor i in range(m):\r\n mass[i] = int(mass[i])\r\n \r\nmass.sort()\r\n\r\nans = 0\r\nfor i in range(n):\r\n if mass[i] > 0:\r\n break\r\n ans += mass[i]\r\n\r\nprint(abs(ans))\r\n", "# https://codeforces.com/problemset/problem/34/B\n\n# Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. \n# Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob \n# can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most m TV sets, and he has no desire \n# to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.\n\n# Input\n# The first line contains two space-separated integers n and m (1 ≤ m ≤ n ≤ 100) — amount of TV sets at the sale, \n# and amount of TV sets that Bob can carry. The following line contains n space-separated integers \n# ai ( - 1000 ≤ ai ≤ 1000) — prices of the TV sets.\n\n# Output\n# Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most m TV sets.\ndef answer(a):\n print(a)\n exit(0)\n\nfirstLine = input().split()\n# what how manyu tv sets \nn = int(firstLine[0])\n# how many bob can carry\nm = int(firstLine[1])\ntvs = input().split()\n\nif (m < 1): answer(0)\n\n# get profitable sets\nprofitable = []\nfor value in tvs:\n v = int(value)\n if (v < 0):\n profitable.append(v)\nprofitable.sort()\n\ncount = 0\nprofit = 0\n\nfor value in profitable:\n count += 1\n profit -= value\n if count == m: answer(profit)\n\nanswer(profit)", "a, b = input().split()\r\nb = int(b)\r\n\r\nc = sorted(list(map(int,input().split())))\r\nli = []\r\n\r\ndh = 0\r\nsw = False\r\nans = 0\r\n\r\nfor i in c:\r\n if i < 0 and dh != b:\r\n ans += i\r\n dh += 1\r\n sw = True\r\n\r\nif sw:\r\n print(str(ans)[1:])\r\nelse:\r\n print(0)\r\n", "# https://codeforces.com/problemset/problem/34/B\r\n\r\ndef handle_input():\r\n tv,n = map(int ,input().split())\r\n tvs = list(map(int ,input().split()))\r\n return n , tvs\r\n\r\nn,tvs = handle_input()\r\ntvs.sort()\r\n\r\nmoney = 0\r\nfor i in range(n):\r\n if tvs[i] < 0:\r\n money += -tvs[i]\r\n\r\nprint(money)", "n, m = map(int, input().split())\r\nl = sorted(list(map(int, input().split())))\r\nans = 0\r\nfor i in range(m):\r\n if l[i] < 0:\r\n ans += l[i]\r\n else:\r\n break\r\nprint(-ans)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\ni=0\r\ns=0\r\nl=sorted(l)\r\nwhile(i<m and l[i]<=0 ):\r\n s+=(l[i])\r\n i+=1\r\nprint(abs(s))\r\n ", "nm = list(map(int , input().strip().split()))\r\n\r\na = list(map(int , input().strip().split()))\r\na.sort()\r\n\r\nsum , noOFtvs = 0 , 0\r\nfor lol in range(0 , nm[0]):\r\n if a[lol] < 0:\r\n sum += a[lol]\r\n noOFtvs += 1\r\n if noOFtvs >= nm[1]:\r\n break\r\n\r\nprint(-1*sum)", "x=0\r\nn,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nfor i in range(m):\r\n if min(a)>0:\r\n break\r\n x+=(min(a))*(-1)\r\n a.remove(min(a)) \r\nprint(x)\r\n ", "n, m = map(int, input().split())\r\ns = 0\r\ni = 0\r\nfor j in sorted(list(map(int, input().split()))):\r\n if j < 0 and i < m:\r\n s-=j\r\n i+=1\r\n else:\r\n break\r\nprint(s)", "n,m=map(int, input().split())\na=list(map(int, input().split()))\np=[i for i in a if i<0]\nif len(p)<=m:\n print(abs(sum(p)))\nelse:\n p.sort()\n print(abs(sum(p[:m])))", "# import math\r\ndef main():\r\n\tn,k = map(int,input().split())\r\n\ta = list(map(int,input().split()))\r\n\tadd = 0\r\n\ta.sort()\r\n\tfor i in range(k):\r\n\t\tif a[i]>=0:\r\n\t\t\tbreak\r\n\t\tadd+=abs(a[i])\r\n\tprint(add)\r\n\r\nmain()", "n, m = map(int, input().split())\r\n\r\nprices = list(map(int, input().split()))\r\nprices.sort()\r\n\r\nearn = 0\r\nfor price in prices:\r\n if price < 0 and m > 0:\r\n earn += price\r\n m -= 1\r\n\r\nprint(abs(earn))", "n, w = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\narr2 = []\r\nif a[0] >= 0:\r\n print(0)\r\nelse:\r\n for i in range(w):\r\n if a[i] < 0:\r\n arr2.append(a[i])\r\n\r\n print(-sum(arr2))\r\n", "n,l=map(int,input().split())\r\na=list(map(int,input().split()))[:n]\r\na.sort()\r\nc=0\r\nfor i in range(l):\r\n if a[i]<0:\r\n c=c-a[i]\r\nprint(c)\r\n", "n,m = map(int,input().split())\r\n\r\narr = list(map(int,input().split()))\r\n\r\ntemp = [abs(x) for x in arr if x < 0]\r\n\r\ntemp.sort()\r\n\r\ntemp = temp[::-1]\r\n\r\nans = 0\r\ncount = 0\r\n\r\nfor i in temp:\r\n if count < m:\r\n ans += i\r\n count += 1\r\n else:\r\n break\r\n\r\nprint(ans)", "n,m=map(int,input().split(' '))\r\nar=list(map(int,input().split(' ')))\r\nar.sort()\r\ns=0\r\nfor v in range(m):\r\n if(ar[v]<0):\r\n s+=(abs(ar[v]))\r\n else:\r\n break\r\nprint(s)\r\n", "n, m = map(int, input().split())\nl = list(filter(lambda x: x < 0, map(int, input().split())))\nl.sort()\nprint(-sum(l[:m]))\n \t \t\t \t\t\t \t \t\t \t \t \t\t", "n,m=map(int,input().split())\r\nlis = list(map(int,input().split()))\r\nlis.sort()\r\nans = 0\r\nfor i in range(m):\r\n if lis[i]<0:\r\n ans-=lis[i]\r\nprint(ans)", "n,m=tuple(map(int,input().split()))\r\ncost=list(map(int,input().split()))\r\nreq=list(filter(lambda x:x<0,cost))\r\nif req==[]:\r\n print(0)\r\nelif len(req)<=m:\r\n print(-sum(req))\r\nelse:\r\n req.sort()\r\n req=req[:m]\r\n print(-sum(req))", "n, m = list(map(int, input().split()))\r\nans = 0\r\nb = []\r\na = [int(i) for i in input().split()]\r\na.sort()\r\nfor i in range(m):\r\n if a[i] < 0:\r\n b.append(a[i])\r\n else:\r\n break\r\nans = sum(b)\r\nprint(abs(ans))", "def ans(m,lst):\r\n\tlst.sort()\r\n\tct,su = 0,0\r\n\tfor i in lst:\r\n\t\tif i < 0 and ct < m:\r\n\t\t\tsu += abs(i)\r\n\t\t\tct += 1\r\n\tprint(su) \r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\r\n\r\n#for _ in range(int(input())):\r\nn,m = map(int,input().split())\r\nlst = list(map(int,input().split()))\r\nans(m,lst)\r\n", "n,m=map(int,input().split())\r\na=sorted([*map(int,input().split())])\r\nprint(-sum(a[:min(str(a).count('-'),m)]))", "n,m = map(int,input().split())\r\nl = sorted(list(map(int,input().split())),reverse=True)\r\ns = 0\r\nwhile m > 0:\r\n if l[-1] <= 0:\r\n s += l.pop()\r\n m -= 1\r\n else:break\r\n\r\nprint(s*-1)", "n,m=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\na.sort()\r\nr=0\r\nfor i in range(m):\r\n if(a[i]>=0):\r\n break\r\n else:\r\n r+=abs(a[i])\r\nprint(r)\r\n\r\n", "def zip_sorted(a,b):\n\n\t# sorted by a\n\ta,b = zip(*sorted(zip(a,b)))\n\t# sorted by b\n\tsorted(zip(a, b), key=lambda x: x[1])\n\n\treturn a,b\n\nimport sys\ninput = sys.stdin.readline\nI = lambda : list(map(int,input().split()))\nS = lambda : list(map(str,input().split()))\n\n\nn,m = I()\na = I()\n\nsum1 = 0\n\nb=[]\n\nfor i in range(len(a)):\n\tif a[i]<0:\n\t\tb.append((-1)*(a[i]))\n\nb = sorted(b,reverse=True)\ncount = 0\n\nfor i in range(len(b)):\n\tif count<m:\n\t\tsum1 = sum1+ b[i]\n\t\tcount = count + 1\n\telse:\n\t\tbreak \n\nprint(sum1)\n\n'''\nfor i in range(n):\nfor j in range(n):\nfor k1 in range(len(a)):\nfor k2 in range(len(a)):\nfor k3 in range(len(a)):\n\n'''", "n,m = map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ni=0\r\n\r\nans=0\r\nwhile i<m:\r\n if ans-l[i]>ans:\r\n ans+=abs(l[i])\r\n i+=1\r\nprint(ans)", "n,m=list(map(int, input().split()))\r\na=list(map(int, input().split()))\r\na.sort()\r\ns=0\r\nfor i in range(m):\r\n if a[i]<=0:\r\n s-=a[i]\r\nprint(s)\r\n", "R = lambda: list(map(int, input().split()))\r\n[n, m], a = R(), sorted(R())\r\noutput = 0\r\nfor i in range(m):\r\n if a[i] >= 0: break\r\n output -= a[i]\r\nprint(output)", "a,b=map(int,input().split())\r\nc=list(map(int,input().split()))\r\notv=0\r\nfor x in range(b):\r\n d=min(c)\r\n if d<0:\r\n otv+=d\r\n c.pop(c.index(d))\r\nprint(abs(otv))", "n, m = map(int, input().split())\r\nprice = list(map(int, input().split()))\r\nprice.sort()\r\nearn = 0\r\ncount = 0\r\nfor i in range(n):\r\n\tif(price[i] < 0 and count < m):\r\n\t\tearn += abs(price[i])\r\n\t\tcount += 1 \r\nprint(earn)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Sep 29 17:39:59 2021\r\n\r\n@author: cheehong\r\n\"\"\"\r\n\r\ndef tv(x,t):\r\n x=list(map(int, x))\r\n k=0\r\n b=[]\r\n while k<t:\r\n mi=min(x)\r\n if mi <=0:\r\n b.append(mi)\r\n x.remove(mi)\r\n k+=1\r\n else:\r\n break\r\n total=0\r\n for ele in b:\r\n total+=ele\r\n return -total\r\nu=list(input().split())\r\nt=int(u[1])\r\nx=list(input().split())\r\nprint(tv(x,t))", "n,m=list(map(int,input().split()))\r\nj=sorted(list(map(int,input().split())))\r\nu=0\r\nc=0\r\nfor i in j:\r\n if i>0 or c==m:\r\n break\r\n u+=i\r\n c+=1\r\nprint(abs(u))", "\ndef intmaker(arr):\n\tfor i in range(len(arr)):\n\t\tarr[i] = int(arr[i])\n\treturn arr\n\n\nn, m = input().split()\nn = int(n)\nm = int(m)\n\na = intmaker(input().split())\n\n\nbought = 0\n\n\nfor i in range(m):\n\tif min(a) <= 0:\n\t\tbought += abs(min(a))\n\t\ta.remove(min(a))\n\n\nprint(bought)\n\n\n", "n , t = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb=[]\r\nfor i in a:\r\n if(i<0):\r\n b.append(i)\r\n\r\nif(len(b)<=t):\r\n print(abs(sum(b)))\r\nelse:\r\n d = sorted(b)\r\n # print(d)\r\n print(abs(sum(d[:t])))\r\n", "def fu():\r\n return map(int,input().split(' '))\r\nn,m = fu()\r\na = sorted(list(fu()))\r\nk=0\r\nfor i in range(m):\r\n if a[i] < 0:\r\n k+=abs(a[i])\r\n else:\r\n break\r\nprint(k)\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nq = 0\r\nfor i in range(m):\r\n if min(a) < 0:\r\n q += min(a);\r\n a.remove(min(a))\r\nprint(abs(q))", "m = int(input().split()[1])\nprint(-sum(sorted(int(i) for i in input().split() if int(i) < 0)[:m]))\n\t \t \t \t \t \t\t \t \t\t \t", "_, m = map(int, input().split())\r\nprint(-sum(sorted(filter((0).__gt__, map(int, input().split())))[:m]))\r\n", "i=input\r\nn,m=i().split()\r\nl=list(map(int,i().split()))\r\nl.sort()\r\nr=0\r\nfor i in range(len(l)):\r\n if(int(l[i])<0):r-=int(l[i])\r\n else:break\r\n if(i==int(m)-1):break\r\nprint(r)", "import sys, itertools, math\n\ndef ia():\n return [int(i) for i in sys.stdin.readline().strip().split(\" \")]\n\ndef ii():\n return int(sys.stdin.readline().strip())\n\n###\n\nn, m = ia()\nA = sorted(ia())\nans = 0\nfor i in range(m):\n if A[i] < 0:\n ans += -A[i]\nprint(ans)", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\nprices.sort()\r\nmax_sum = 0\r\nfor i in range(min(m, n)):\r\n if prices[i] < 0:\r\n max_sum -= prices[i]\r\n else:\r\n break\r\nprint(max_sum)\r\n", "n, m = input().split()\r\ns = input().split()\r\nl = []\r\nsumm = 0\r\nfor i in s:\r\n l.append(int(i))\r\nl.sort()\r\nfor i in range(int(m)):\r\n if l[i]<=0:\r\n summ+=l[i]*-1\r\nprint(summ)", "n, m = map(int, input().split())\r\n\r\nprint(-sum(sorted(filter(lambda x: x < 0, map(int, input().split())))[:m]))", "n,m=[int(i) for i in input().split()]\r\nlst=[int(i) for i in input().split()]\r\nlst.sort()\r\ns=0\r\nif m<=n:\r\n for i in range(0,m):\r\n if(lst[i]<0):\r\n s=s+abs(lst[i])\r\nif(s!=0):\r\n print(s)\r\nelse:\r\n print(\"0\")\r\n ", "import math\r\nimport copy\r\nimport itertools\r\nimport bisect\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef ilst():\r\n return list(map(int,input().split()))\r\n\r\ndef inum():\r\n return map(int,input().split())\r\n \r\ndef islst():\r\n return list(map(str,input().split()))\r\n\r\n\r\nn,m = inum()\r\nl = ilst()\r\nl.sort()\r\nans = 0\r\nfor i in range(m):\r\n if l[i] < 0:\r\n ans -= l[i]\r\n else:\r\n break\r\nprint(ans)\r\n", "import sys\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\ndef iinput(): return int(input())\r\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \r\nmod = int(1e9)+7\r\n\r\nn, m = rinput()\r\na = get_list()\r\na.sort()\r\ni = ans = 0\r\nwhile(i<m and a[i]<=0):\r\n\tans+=a[i]\r\n\ti+=1\r\nprint(abs(ans))", "first_line = input().split()\r\nn = int(first_line[0])\r\nm = int(first_line[1])\r\n\r\ndata_list = input().split()\r\nprices = list(map(int, data_list))\r\n\r\nnegative_prices = []\r\n\r\nfor i in range(n):\r\n if prices[i] < 0:\r\n negative_prices.append(prices[i])\r\n\r\nsorted_prices = sorted(negative_prices)\r\n\r\nprofit = sum(sorted_prices[:m])*-1\r\n\r\nprint(profit)", "n, m = map(int, input().split())\nx = list(map(int, input().split()))\nx.sort()\nans = 0\nfor i in range(n):\n if x[i] < 0:\n ans += abs(x[i])\n m -= 1\n if m == 0:\n break\nprint(ans)\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\ntvs = sorted(list(map(int, input().split())))\r\n\r\nprofit = i = 0\r\nwhile i < m and tvs[i] < 0:\r\n profit += abs(tvs[i])\r\n i += 1\r\n\r\nprint(profit)\r\n", "n , m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = []\r\n# ~ print(len(a))\r\nfor i in range(n):\r\n\tif a[i] < 0:\r\n\t\tb.append(a[i]*(-1))\r\nb.sort(reverse= True)\r\nprint(sum(b[:m]))\r\n\"\"\"\r\n50 20\r\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886\r\n\"\"\"\r\n", "n, m = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\na.sort()\r\nans = 0\r\nfor i in range(n):\r\n if m and a[i] < 0:\r\n ans -= a[i]\r\n m -= 1\r\n else:\r\n break\r\nprint(ans)", "a,b=map(int,input().split())\r\nl=[int (i) for i in input().split()]\r\ncount=0\r\nl.sort()\r\nfor i in range(0,b): \r\n if l[i]<0:\r\n count+=abs(l[i])\r\nprint(count)", "n,m=map(int,input().split())\r\nl=sorted(list(map(int,input().split()))+[0]*m)\r\nprint(-1*sum(l[:m]))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nc=0\r\nsum=0\r\nfor i in range(n):\r\n if c<m and a[i]<0:\r\n sum+=a[i]\r\n c+=1\r\nprint((-1)*sum)\r\n\r\n\r\n", "(n,m)=map(int,input().split())\na=list(map(int,input().split()))\na.sort()\ns=0\nfor i in range(m):\n if(a[i]<0):\n s=s-a[i]\nprint(s)", "n, m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nk = 0; s = 0\r\nfor i in sorted(a):\r\n if i < 0:\r\n s -= i\r\n k += 1\r\n if k == m:\r\n break;\r\nprint(s)", "n,m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nl = sorted(l)\r\nc = 0\r\ns = 0\r\nfor x in l:\r\n if c == m or x >= 0:\r\n break\r\n s += (-1*x)\r\n c += 1\r\nprint(s)\r\n", "n, m = input().split()\r\nintM = int(m)\r\nnegatives = []\r\nsumMoney = 0\r\n\r\ninp = input().split()\r\ninp = list(map(int, inp))\r\nfor i in range(int(n)):\r\n if inp[i] < 0:\r\n negatives.append(inp[i])\r\n\r\nnegatives.sort()\r\n\r\nfor i in range(len(negatives)):\r\n if intM > 0:\r\n sumMoney += abs(negatives[i])\r\n intM -= 1\r\n\r\nprint(sumMoney)", "n,m=map(int,input().split())\narr=list(map(int,input().split()))\narr.sort()\nsum=0\ncount=0\nwhile count!=m and arr[count]<1:\n sum += arr[count]\n count += 1\nprint(abs(sum))", "# author: violist\n# created: 06.07.2022 11:05:30\n\nimport sys\ninput = sys.stdin.readline\n\nn, m = map(int, input().split())\na = sorted(list(map(int, input().split())))\nans = 0\nfor i in range(n):\n if (a[i] < 0):\n ans += abs(a[i])\n m -= 1\n if (m == 0):\n break\nprint(ans)\n", "n,m=(int(i) for i in input().split())\r\na=[int(i) for i in input().split()]\r\ncount=0\r\ncost=0\r\na.sort()\r\nfor i in range(0,n):\r\n if (a[i]<0) and (count<=m):\r\n cost=cost+(-a[i])\r\n count+=1\r\n if (m==count):\r\n break\r\nprint(cost)\r\n", "n,m=map(int,input().split())\r\nc=[]\r\na=list(map(int,input().split()))\r\nfor i in range(0,n):\r\n if a[i]<0:\r\n c.append(-a[i])\r\nc.sort()\r\nc.reverse()\r\ns=0\r\nif len(c)<=m:\r\n s=sum(c)\r\nelse:\r\n d=c[:m]\r\n s=sum(d)\r\nprint(s)\r\n", "n, m = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\nh = [i for i in a if i < 0]\r\nh.sort()\r\nk = 0\r\nfor i in h:\r\n if m == 0:\r\n break\r\n k -= i\r\n m -= 1\r\nprint(k)\r\n", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\ni=0\r\nsum1=0\r\nwhile(m!=0):\r\n if(a[i] < 0):\r\n sum1 = sum1+a[i]\r\n else:\r\n pass\r\n i=i+1\r\n m=m-1 \r\nprint(abs(sum1))", "# list_num = [int(i) for i in input().split()]\r\n# ngtv_list = [j for j in list_num if j < 0]\r\n\r\nn, m = map(int, input().split())\r\nngtv_list = sorted(list(filter(lambda x: x < 0, [int(i) for i in input().split()])))[:m]\r\nprint(-sum(ngtv_list))\r\n", "n,k=map(int,input().split())\r\ns=0\r\nl=sorted(list(map(int,input().split())))\r\nfor i in range(k):\r\n if l[i]<0:\r\n s=s+abs(l[i])\r\nprint(s)", "n,m=map(int,input().split())\r\n\r\nfor i in range(1):\r\n x=list(map(int,input().split()))\r\n\r\nd=[]\r\nfor i in x:\r\n if i<=0:\r\n d.append(i)\r\n \r\nd.sort()\r\ny=sum(d[:m])\r\nprint(-y) ", "n,m = map(int, input().split())\r\np = [int(x) for x in input().split()]\r\np = sorted(p)\r\nfor i in range(n):\r\n if p[i] > -1:\r\n p[i] = 0\r\nif sum(p[:m]) < 0:\r\n print(-sum(p[:m]))\r\nelse:\r\n print(0)\r\n", "a,b=list(map(int,input().split()))\r\nlst=sorted(map(int,input().split()))\r\nres=0\r\nfor i in range(0,b):\r\n if lst[i]<=0:\r\n res+=lst[i]\r\nprint(abs(res))", "n,m = map(int, input().split())\r\ns = [0]*m\r\nind = 0\r\narr = list(map(int, input().split()))\r\nfor i in arr: \r\n if i < 0: \r\n if ind < 3:\r\n s[ind] = abs(i)\r\n ind += 1\r\n else: \r\n f_sum = sum(s)\r\n k = min(s)\r\n j = s.index(min(s))\r\n s[j] = abs(i)\r\n if f_sum > sum(s): \r\n s[j] = k\r\nprint(sum(s))", "a=list(map(int,input().split(\" \")))\r\nb=list(map(int,input().split(\" \")))\r\nb.sort()\r\ns=0\r\ni=0 \r\nwhile(i<a[1] and b[i]<0):\r\n s=s-b[i] \r\n i=i+1 \r\nprint(s)", "ans=0\r\nn,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nfor i in range(m):\r\n if a[i]<0:\r\n ans-=a[i]\r\nprint(ans)", "a,b=[int(x) for x in input().split()]\r\nl=[int(x) for x in input().split()]\r\nl.sort()\r\nsum=0\r\nfor i in range(0,b):\r\n if(l[i]<0):\r\n sum=sum+l[i]\r\n else:\r\n break\r\nprint(-1*sum) \r\n", "m,n = map(int,input().split())\r\nsets = list(map(int,input().split()))\r\nlis = []\r\nfor i in sets:\r\n if i < 0:\r\n lis.append(i)\r\nlis.sort() \r\nlisu = lis[:n]\r\nprint(abs(sum(lisu)))\r\n ", "n,m=map(int,input().split())\r\nl=[]\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nx=0;\r\nfor i in range(m):\r\n if(l[i]<0):\r\n x+=l[i]\r\n else:\r\n break\r\nprint(abs(x))", "_,m=[int(i) for i in input().split()]\r\nl = []\r\nfor i in input().split():\r\n l.append(-int(i) if '-' in i else 0)\r\nl.sort(reverse=True)\r\ns=0\r\nfor i in range(m):\r\n s += l[i]\r\nprint(s)", "n=list(map(int,input().split(\" \")))\r\narr=list(map(int,input().split(\" \")))\r\ni=0\r\nans=0\r\narr.sort()\r\nwhile i<n[0] and n[1]>0:\r\n if arr[i]<0:\r\n ans-=arr[i]\r\n else:\r\n break\r\n i+=1\r\n n[1]-=1\r\nprint(ans)\r\n", "n,m = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\n\na.sort()\n\nfor i in range(m):\n\tif a[i]<=0:\n\t\tans += a[i]\nprint(-ans)", "n, m = map(int, input().split())\r\nl, total = sorted([int(i) for i in input().split()]), 0\r\nfor i in range(m):\r\n total += l[i]*(l[i] <= 0)\r\nprint(abs(total))\r\n", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\nprices.sort()\r\ntotal = 0\r\nfor i in range(m):\r\n if prices[i] < 0:\r\n total -= prices[i]\r\nprint(total)\r\n", "n,m=map(int,input().split())\r\na= list(map(int, input().split()))\r\na.sort()\r\nmon=0\r\nfor i in range(m):\r\n if a[i]>=0:break\r\n else:mon-=a[i]\r\nprint(mon)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nneg = []\r\nfor i in range(n):\r\n if a[i] < 0:\r\n neg.append(a[i])\r\nlenn = len(neg)\r\nif lenn <= m:\r\n print(abs(sum(neg)))\r\nelse:\r\n for i in range(lenn - m):\r\n neg.pop(neg.index(max(neg)))\r\n print(abs(sum(neg)))\r\n", "n=list(map(int,input().split()))\r\nz=list(map(int,input().split()))\r\nz.sort()\r\ncount=0\r\nfor i in range(n[1]) :\r\n if z[i]<0 :\r\n count+=(-z[i])\r\n\r\nprint(count)", "def partition(T, p, r):\r\n pivot = T[r]\r\n i = p-1\r\n for j in range(p, r):\r\n if T[j] <= pivot:\r\n i += 1\r\n T[j], T[i] = T[i], T[j]\r\n T[i+1], T[r] = T[r], T[i+1]\r\n return i+1\r\n\r\n\r\ndef quicksort(T, p, r):\r\n if len(T) <= 1:\r\n return T\r\n else:\r\n while p < r:\r\n q = partition(T, p, r)\r\n quicksort(T, p, q-1)\r\n p = q+1\r\n\r\n\r\nn, m = map(int, input().split())\r\nT = list(map(int, input().split()))\r\nresult = 0\r\nquicksort(T, 0, len(T)-1)\r\nfor i in range(m):\r\n if T[i] <= 0:\r\n result += abs(T[i])\r\nprint(result)\r\n", "import math\r\nfrom collections import OrderedDict\r\nfrom collections import Counter\r\nfrom itertools import combinations\r\nfrom itertools import accumulate\r\nimport operator\r\nimport bisect\r\nimport copy\r\n#a= list(map(int, input(\"\").strip().split()))[:n]\r\ndef solve(a,n):\r\n a.sort()\r\n c=0\r\n for i in range(n):\r\n if a[i]==0 or a[i]>0:\r\n break\r\n else:\r\n c+=abs(a[i])\r\n print(c)\r\nm,n= list(map(int, input(\"\").strip().split()))[:2]\r\na= list(map(int, input(\"\").strip().split()))[:m]\r\nsolve(a,n)", "n,m = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\ncosts = []\r\nfor i in a:\r\n if i<0:\r\n costs.append(-i)\r\nif len(costs)==0:\r\n print(0)\r\nelif len(costs)<=m:\r\n print(sum(costs))\r\nelse:\r\n print(sum(sorted(costs)[::-1][:m:]))", "n = 2\r\nfirst = [int(n) for n in input().split()]\r\nsecond = [int(n) for n in input().split()]\r\n\r\nsecond.sort(reverse=False)\r\ncount = 0\r\nsales = 0\r\nlimit = first[1]\r\nfor i in second:\r\n if i < 0:\r\n sales = sales-i\r\n count = count + 1\r\n if count == limit:\r\n break\r\nprint(sales)\r\n", "i=lambda :map(int,input().split())\r\nn,m=i()\r\ns=0\r\nfor x in sorted(i()):\r\n if x>=0 or m==0:\r\n break\r\n\r\n if abs(s+x)>s:\r\n s+=x\r\n m-=1\r\n\r\nprint(abs(s))", "n,m=map(int,input().split())\r\nl=[int(x) for x in input().split()]\r\nl.sort()\r\np=0\r\nfor i in range(m):\r\n if l[i]>0:\r\n break\r\n else:\r\n p+=-l[i];\r\nprint(p)", "a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl2=[]\r\nfor i in l :\r\n if i <0:\r\n l2.append(-i)\r\nif len(l2)<=b:\r\n print(sum(l2))\r\nelse:\r\n l2.sort(reverse=True)\r\n print(sum(l2[:b]))", "q, w = map(int, input().split())\r\ne = list(map(int, input().split()))\r\ne.sort()\r\nr = 0\r\nfor i in e:\r\n if i < 0 and w > 0:\r\n r += abs(i)\r\n w -= 1\r\n else:\r\n break\r\nprint(r)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nl2=l[:m]\r\ns=0\r\nfor i in l2:\r\n if i<=0:\r\n s=s+abs(i)\r\nprint(s)", "n,m=(map(int,input().split()))\r\nlst=list(map(int,input().split()))\r\nlst.sort()\r\ns=0\r\nfor i in lst:\r\n if i<0 and m>0:\r\n s+=i\r\n m-=1\r\nprint(abs(s))", "n, m = map(int, input().split())\r\nans = 0\r\nfor i in sorted(list(map(int, input().split()))):\r\n if m:\r\n if i <= 0: ans += -(i)\r\n else: break\r\n m -= 1\r\n else: break\r\nprint(ans)", "from sys import stdin,stdout\r\nii1 = lambda: int(stdin.readline().strip())\r\nis1 = lambda: stdin.readline().strip()\r\niia = lambda : list(map(int, stdin.readline().strip().split()))\r\nisa = lambda: stdin.readline().strip().split()\r\nmod = 1000000007\r\n\r\nn, m = iia()\r\nprint(sum([abs(i) for i in sorted(iia()) if i < 0][:m]))\r\n\r\n\r\n", "n, k = (int(i) for i in input().split(' '))\na = sorted([int(i) for i in input().split(' ')])\ntotal = 0\nprint(-sum(i for i in a[:k] if i <= 0))\n", "n, m = map(int, input().split())\r\nprice = sorted(list(map(int, input().split())))\r\nsum = 0\r\nfor i in range(m):\r\n if price[i] < 0:\r\n sum += price[i]\r\n else:\r\n break\r\n\r\nsum *= -1\r\nif sum > 0:\r\n print(sum)\r\nelse:\r\n print(0)", "n, m=map(int, input().split())\r\nl=list(map(int, input().split()))\r\nsum=0\r\nne=[]\r\nfor i in range(n):\r\n if(l[i]<0):\r\n ne.append(l[i])\r\nfor i in range(len(ne)):\r\n ne[i]=-ne[i]\r\nne.sort()\r\ni=len(ne)-1\r\nct=0\r\nwhile(ct!=m and i>=0):\r\n sum=sum+ne[i]\r\n ct=ct+1\r\n i=i-1\r\nprint(sum)", "v1,v2=map(int,input().split())\r\nb=list(map(int,input().split()))\r\nb.sort()\r\n\r\nc=0\r\nc1=0\r\nfor i in b:\r\n if i<=0:\r\n c+=i\r\n v2-=1\r\n\r\n if v2==0:\r\n break\r\nprint(abs(c))\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort()\r\ntemp = a[0:m]\r\nans = 0\r\nfor i in temp:\r\n if i >= 0:\r\n break\r\n else:\r\n ans += i\r\n\r\nprint(ans*-1)\r\n", "n,m=map(int,input().strip().split())\r\na=list(map(int,input().strip().split()))\r\na.sort()\r\nw=[]\r\nfor i in range(m):\r\n if a[i]<0:\r\n w.append(-a[i])\r\nif w==[]:\r\n print(0)\r\nelse:\r\n print(sum(w))\r\n \r\n", "n,m = map(int,input().split())\r\nans = 0; f = 0\r\na = list(map(int,input().split()))\r\na.sort()\r\nfor i in range(n):\r\n if a[i] < 0 and f < m: ans += a[i]; f += 1\r\nprint(-ans)", "a,b=[int(i) for i in input().split()]\r\ns=[int(i) for i in input().split()]\r\ns.sort()\r\nres=0\r\nfor i in range(b):\r\n if s[i]<0:\r\n res+=abs(s[i])\r\n else:\r\n break\r\nprint(res)", "n, m = map(int, input().split())\na = [int(s) for s in input().split()]\na.sort()\ni = 0\ns = 0\nwhile i < min(m, n) and a[i] < 0:\n s -= a[i]\n i += 1\nprint(s)\n", "n,m = map(int,input().split())\r\ntc = [int(i) for i in input().split()]\r\ntc.sort()\r\nres = []\r\nfor i in range(m):\r\n if(tc[i]<0):\r\n res.append(tc[i]*-1)\r\nprint(sum(res))\r\n", "n , m = map(int,input().split())\r\ni,max_sum=(0,0)\r\nprices=[int(x) for x in input().split()]\r\nprices.sort()\r\nlow=[]\r\nfor x in prices:\r\n if x < 0 :\r\n low.append(x)\r\n if len(low)<=m:\r\n max_sum+=abs(x)\r\n else:\r\n low.pop()\r\nprint(max_sum)", "from collections import Counter\n\ndef solve():\n\tn, m = map(int, input().split())\n\ta = [int(x) for x in input().split() if int(x)<0]\n\ta.sort()\n\tprint(-sum(a[:m]))\n\n# t = int(input())\n\n# while t:\n# \tt -= 1\nsolve()", "n,m = map(int,input().split())\r\nlist1 = list(map(int,input().split()))\r\nlist1.sort()\r\ns=0\r\nfor i in range(m):\r\n if list1[i]>=0:\r\n break\r\n\r\n s+= list1[i]\r\n\r\n\r\nprint(abs(s))", "x=list(map(int,input().split()))\r\ny=list(map(int,input().split()))\r\narr1=[0]\r\nfor i in y:\r\n if i<0:\r\n arr1.append(i)\r\narr1.sort()\r\nsum=0\r\nif len(arr1)<=x[1]:\r\n for i in arr1:\r\n sum=sum+i\r\nelse:\r\n for i in range(x[1]):\r\n sum=sum+arr1[i]\r\nprint(-sum)\r\n", "def sol(n,m,a):\n c=0\n a.sort()\n for i in range(m):\n if(a[i]<0):\n c+=-1*a[i]\n else:\n break\n return c\n\n\n#for _ in range(int(input())):\nn,m=map(int,input().split())\ns=[int(x) for x in input().split()]\nprint(sol(n,m,s))\n ", "n, m = map(int, input().split())\nl=list(map(int,input().split()))\nsl=sorted(l)\ns=0\nfor i in range(m):\n if sl[i]<0:\n s-=sl[i]\nprint(s) \n \n \n \n \n \n \n ", "n,m=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nb=0\r\nfor i in range(m):\r\n if min(x)>0:\r\n break\r\n b+=min(x)*-1\r\n x.remove(min(x))\r\nprint(b)", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na = sorted(a)\r\ni = 0\r\nans = 0\r\nwhile i < m and a[i] < 0:\r\n ans += a[i]\r\n i += 1\r\nprint(abs(ans))", "l=input().split()\n\ntot=int(l[1])\n\nnum=[]\nl=input().split()\n\nfor i in range(len(l)):\n num.append(int(l[i]))\n\nnum.sort(reverse=False)\nans=0\n\nfor i in range(len(num)):\n if tot>0:\n if num[i]<0:\n ans-=num[i]\n tot-=1\n else:\n break\n else:\n break\n\nprint(ans)\n", "l1=[int(x) for x in input().split()]\r\nl2=[int(x) for x in input().split()]\r\nl2.sort()\r\ni=0\r\nout=0\r\nwhile i<l1[1] and l2[i]<0:\r\n\tout+=l2[i]\r\n\ti+=1\r\nprint(abs(out))\t", "n1=input()\r\nm1=input()\r\nn=n1.split()\r\nm=m1.split()\r\nc=[0]*int(n[0])\r\np=0\r\nfor i in m:\r\n if int(i) < 0:\r\n c[p]=abs(int(i))\r\n p+=1\r\nc.sort()\r\nc.reverse()\r\nk=0\r\nf=0\r\nif int(n[1])>len(c):\r\n k=len(c)\r\nelse:\r\n k=int(n[1])\r\nfor i in range(k):\r\n f+=int(c[i])\r\nprint(f)\r\n", "n, m = map(int, input().split())\r\na = sorted([int(i) for i in input().split()])\r\nb = 0\r\nfor i in a[:m]:\r\n if i < 0:\r\n b += i\r\n else:\r\n break\r\nprint(-b)", "n,m = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nans = 0\r\ni = 0\r\nwhile i<n and i<m:\r\n if arr[i]<0:\r\n ans+=arr[i]\r\n else:\r\n break\r\n i+=1\r\nprint(abs(ans)) ", "n , m = map(int, input().split())\r\ntvs = list(map(int, input().split()))\r\ntvs.sort()\r\nprint(abs(sum([x for x in tvs[:m] if x < 0])))", "def main():\r\n n, m = [int(x) for x in input().split()]\r\n a = [int(x) for x in input().split() if int(x) < 0]\r\n a.sort()\r\n sum = 0\r\n for i,x in enumerate(a):\r\n if i >=m:\r\n break\r\n sum+=-x\r\n print(sum)\r\n \r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "a,b = map(int,input().split())\r\ny = list(map(int,input().split()))\r\nm = []\r\ny.sort()\r\ny = y[::-1]\r\nk =0\r\nc = 0\r\nfor i in y:\r\n if i <0:\r\n m+=[i]\r\nm.sort()\r\nif len(m)>=b:\r\n for i in range(b):\r\n k+=(abs(m[i]))\r\n print(k)\r\nelse:\r\n for i in m:\r\n c+=(abs(i))\r\n print(c)\r\n", "n,m=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\na.sort()\r\ns=0\r\nc=0\r\nfor i in a:\r\n if c>=m:\r\n break\r\n if i<0:\r\n s=s+(-i)\r\n c=c+1\r\n else:\r\n break\r\nprint(s)\r\n ", "n, m = [int(i) for i in input().split()]\r\ncount, value, array = 0, 0, []\r\n[array.append(int(i)) for i in input().split()]\r\nfor i in sorted(array):\r\n if int(i) < 0 and value < m:\r\n count += abs(int(i))\r\n value += 1\r\nprint(count)", "n,m=map(int,input().split())\r\nP=list(map(int,input().split()))\r\nP.sort()\r\ns=0\r\nfor i in range(m):\r\n if P[i]>=0:\r\n break\r\n s=s+P[i]\r\nprint(-s)", "_, m = [int(i) for i in input().split()]\r\na = [int(i) for i in input().split() if int(i) < 0]\r\na.sort()\r\nprint(abs(sum(a[:m])))", "n, m = map(int, input().split())\r\n\r\ns = sorted(list(map(int, input().split())))\r\n\r\nans = 0\r\nsm = 0\r\nk = 0\r\nfor i in s:\r\n if k >= m:\r\n break\r\n ans = max(ans, sm - i)\r\n sm -= i\r\n k += 1\r\n\r\nprint(ans)", "n , m = map(int,input().split())\r\na = [int(x) for x in input().split()]\r\nfor i in range(n):\r\n a[i] *= -1\r\n\r\na.sort(reverse=True)\r\nsum = 0\r\nfor i in range(m):\r\n if a[i]>=0:\r\n sum += a[i]\r\n else:\r\n break\r\nprint(sum)", "import heapq\n\nn, m = map(int, input().split())\n\narr = list(map(int,input().split()))\n\nneqArray = []\n\nfor i in arr:\n if i < 0: neqArray.append(-i)\n\nheapq.heapify(neqArray)\n\nnLargest = heapq.nlargest(m, neqArray)\n\nprint(sum(nLargest))\n", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nans = 0\r\n\r\narr.sort()\r\n\r\nfor i in range(m):\r\n\tif (arr[i] < 0):\r\n\t\tans += arr[i]\r\n\t\t\r\nprint(-ans)", "n,m=map(int,input().split())\r\nlst=list(map(int,input().split()))\r\na_lst=sorted(filter(lambda x:x<0,lst))\r\nz=min(len(a_lst),m)\r\nprint(-sum(a_lst[:z]))", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nans=0\r\nfor x in range(m):\r\n\tif l[x]<0:\r\n\t\tans+=l[x]\r\nprint(ans*-1)", "\r\nn,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\n\r\nl.sort()\r\nc=0\r\nfor i in l:\r\n if i>=0 or c>=m:\r\n break\r\n c+=1\r\nprint(-sum(l[:c]))", "n,m=map(int,input().split())\r\nli=list(map(int,input().split()))\r\ncount=0\r\np=[]\r\nfor i in li:\r\n if i<0:\r\n p.append(i)\r\np.sort()\r\nprint(abs(sum(p[:m])))\r\n \r\n", "a=int(input().split()[1]);c=[i for i in map(int,input().split()) if i<=0];print(abs(sum(sorted(c)[:a])))", "n, m = map(int, input().split(\" \"))\na = [int(i) for i in input().split(\" \")]\na.sort()\nans = 0\nfor i in range(m):\n if ans + a[i] < ans:\n ans += a[i]\n else:\n break\nprint(ans * -1)\n ", "n,m=map(int,input().split())\r\nx=[int(x) for x in input().split()]\r\nx.sort()\r\nsum=0\r\nfor i in range(m):\r\n if(x[i]<0):\r\n sum+=abs(x[i])\r\nprint(sum)", "n,k = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\ncmin = omin = 0\r\nfor i in arr[:k]:\r\n cmin = min(i,i+cmin)\r\n omin = min(cmin,omin)\r\nprint(omin * -1)", "import sys\nfrom math import floor\namt, hold = [int(i) for i in input().split()]\nnums = sorted([int(i) for i in input().split()])\nif nums[0] > -1:\n\tprint(0)\nelif nums[hold - 1] > 0:\n\tind = 0\n\tfor count, i in enumerate(nums):\n\t\tif i >= 0:\n\t\t\t#print(i)\n\t\t\tind = count - 1\n\t\t\tbreak\n\t#print(nums[: ind + 1])\n\tprint(abs(sum(nums[:ind + 1])))\nelse:\n\tprint(abs(sum(nums[:hold])))\n", "lst=list(map(int,input().split()))\nn=lst[1]\nnumbers=list(map(int,input().split()))\ncurr_sum=0\nprev_sum=0\nwhile n>0:\n minimum=min(numbers)\n curr_sum+=minimum\n numbers.remove(minimum)\n if curr_sum>prev_sum:\n break\n prev_sum=curr_sum\n n=n-1\nprint(prev_sum*-1)\n", "n, m = map(int, input().split())\r\narray = sorted(list(map(int, input().split())))\r\ntotal = 0\r\n\r\nfor i in range(m):\r\n if array[i] < 0:\r\n total += abs(array[i])\r\n else:\r\n break\r\n\r\nprint(total)\r\n", "n,m=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\na.sort()\r\ns=l=w=0\r\nfor i in range(m):\r\n if a[i]>=0:\r\n l+=1\r\n else:\r\n w+=1\r\n\r\nfor i in range(w):\r\n s-=a[i]\r\nprint(s)", "from sys import stdin\r\n\r\n\r\ndef main():\r\n numeros=[int(x) for x in stdin.readline().strip().split()]\r\n array=[int(x) for x in stdin.readline().strip().split()]\r\n array.sort()\r\n suma=0\r\n for i in range(numeros[1]):\r\n if array[i]>0:\r\n break\r\n suma-=array[i]\r\n print(suma)\r\n \r\n\r\n\r\n\r\nmain()\r\n", "# https://codeforces.com/problemset/problem/34/B\r\n\r\n\"\"\"\r\nn objects with the ith object costing a_i\r\nSome objects have negative price\r\n\r\nCan take at most m (m<=n) objects\r\nFind the max sum of money Bob can earn\r\n\r\n# So find the negatives and take that into an array\r\n# Then sort that array\r\n# Then take the m largest\r\n\"\"\"\r\n\r\nimport sys\r\n\r\nn, m = map(int, sys.stdin.readline().split())\r\na = list(map(int, sys.stdin.readline().split()))\r\n\r\nnegatives = []\r\n\r\nfor price in a:\r\n if price <= 0:\r\n negatives.append(price)\r\n\r\nnegatives = sorted(negatives)\r\n\r\nif len(negatives) <= m:\r\n answer = - sum(negatives)\r\nelse:\r\n answer = - sum(negatives[:m])\r\n\r\nsys.stdout.write(str(answer))\r\n\r\n", "n,m=map(int,input().split())\r\nb=[int(i) for i in input().split()]\r\nb.sort()\r\nc=[]\r\nfor i in range(0,n):\r\n if b[i]<0:\r\n c.append(b[i])\r\nprint(abs(sum(c[0:m])))", "n, m = input().split()\r\nn, m = int(n), int(m)\r\nlst = list(map(int, input().split()))\r\nlst = sorted(lst)\r\ncnt = 0\r\ncntm = 0\r\nfor i in range(len(lst)):\r\n if lst[i] < 0 and cntm < m:\r\n cnt += lst[i]\r\n cntm += 1\r\n else:\r\n break\r\n\r\nprint(abs(cnt))", "n = input().split(); n = [int(x) for x in n]; n[0] = 0\r\narr = input().split(); arr = [int(x) for x in arr if x < '0']\r\narr.sort()\r\nfor i in range(len(arr)):\r\n\tif n[1] == 0: break\r\n\tn[0] += arr[i]\r\n\tn[1] -= 1\r\nprint(n[0]*-1)", "\r\nimport math\r\n\r\ndef solve():\r\n a,b=list(map(int,input().split()))\r\n \r\n arr=[int(i) for i in input().split()]\r\n arr.sort()\r\n\r\n sum=0\r\n\r\n for i in range(b):\r\n if arr[i]>0:\r\n break\r\n sum+=-1*arr[i]\r\n\r\n return sum\r\n\r\n\r\n\r\n\r\nprint(solve())", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nc=0\r\nk=0\r\nfor i in range(n):\r\n if l[i]<0 and c<m:\r\n k=k+abs(l[i])\r\n c=c+1\r\nprint(k)", "a,b=map(int,input().split())\r\nli=list(map(int,input().split()))\r\nli.sort()\r\nres=0\r\nfor i in range(b):\r\n if li[i]<1:\r\n res+=(li[i])\r\n \r\nprint(-res)", "a,b=[int(x) for x in input().split(\" \")]\r\narr=[int(x) for x in input().split(\" \")]\r\narr.sort()\r\nans=0\r\nfor i in range(b):\r\n if arr[i] > 0: break\r\n ans+=arr[i]\r\nprint(ans*-1)", "from sys import stdin\r\n\r\ndef main():\r\n x=[int(i) for i in stdin.readline().split()]\r\n y=[int(i) for i in stdin.readline().split()]\r\n r=[]\r\n h=[]\r\n for i in y:\r\n if i < 0:\r\n h.append(i)\r\n l=len(h)\r\n while x[1] > 0:\r\n try:\r\n r.append(min(h))\r\n h.remove(min(h))\r\n x[1]-=1\r\n except ValueError:\r\n break\r\n print(sum(r)*-1)\r\n \r\n \r\nmain()\r\n", "# benzene_ <>\r\n\r\nn,m=map(int,input().split())\r\nlst=list(map(int,input().split()))\r\nlst.sort()\r\ns=0\r\nfor _ in range(m):\r\n if lst[_]<0:\r\n s=s-lst[_]\r\n \r\n else:\r\n break\r\n \r\n \r\nprint(s)\r\n", "n, m = [int(i) for i in input().split()]\r\nprices = [(int(i) * -1) for i in input().split() if int(i) < 0]\r\nprices.sort(reverse=True)\r\ni = 0\r\nsum = 0\r\nwhile m != 0 and i < len(prices):\r\n sum += prices[i]\r\n i += 1\r\n m -= 1\r\nprint(sum)", "n, m = [int(x) for x in input().split()]\ncnt = 0\nd = []\nans = 0\na = [int(x) for x in input().split()]\na.sort()\nfor i in range(0, len(a)):\n if cnt < m and a[i] < 0:\n ans -= a[i]\n cnt += 1\nprint(ans)", "I = input\r\nn,m = map(int, I().split())\r\nl = sorted(map(int, I().split()))\r\ns = 0\r\nfor i in range(m):\r\n if l[i]<0:\r\n s += abs(l[i])\r\n else:\r\n break\r\nprint(s)", "a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nr=0\r\nfor i in l:\r\n if i<0:\r\n r+=abs(i)\r\n b-=1\r\n if b==0:\r\n break\r\nprint(r)", "n,m= list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na.sort()\r\nres = 0\r\nfor i in a[:m]:\r\n res += -i if i < 0 else 0\r\nprint(res)\r\n", "nm = list(map(int,input().split()))\r\nprice = sorted(map(int,input().split()))\r\nn = nm[0]\r\nm = nm[-1]\r\nsum = count = 0\r\nfor i in price:\r\n if (i < 0):\r\n sum -= i\r\n count += 1\r\n if (count == m):\r\n print(sum)\r\n break", "# https://codeforces.com/problemset/problem/34/B\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n prices = sorted(map(int, input().split()))\r\n \r\n money = 0\r\n for i in range(m):\r\n if prices[i] < 0:\r\n money -= prices[i]\r\n else:\r\n break\r\n\r\n print(money)\r\n\r\nif __name__ == '__main__':\r\n main()", "from math import *\r\n\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n s = sorted(list(map(lambda x: -int(x), input().split())), reverse=True)\r\n su = 0\r\n for i in range(0, m):\r\n if s[i] < 0:\r\n break\r\n else:\r\n su += s[i]\r\n print(su)\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n,m=map(int,input().split())\r\nlist=list(map(int,input().split()))\r\nlist.sort()\r\ns=0\r\nfor x in range(m):\r\n if list[x]<0:\r\n s+=list[x]\r\nprint(-s)\r\n\r\n\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort()\r\n# print(a)\r\ns = 0\r\nfor i in range(n):\r\n # print(m,a[i])\r\n if m <= 0 or a[i] > 0:\r\n break\r\n if a[i] < 0:\r\n s += a[i]\r\n m -= 1\r\nprint(-s)\r\n", "n,q = map(int,input().split())\n\nprint(-sum(sorted(filter(lambda x : x<0,map(int,input().split())))[:q]))\n\n\n\n# Made By Mostafa_Khaled", "#34B\r\n[n,m] = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na.sort()\r\ns = 0\r\nfor i in range(min(n,m)):\r\n if a[i]<0:\r\n s += a[i]\r\nprint(-s)", "n,k = [int(x) for x in input().split()]\r\narr = [int(x) for x in input().split()]\r\n\r\narr.sort()\r\n\r\ntotal = 0\r\nfor i in range(k):\r\n if arr[i] < 0:\r\n total += -arr[i]\r\nprint(total)\r\n", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\na.sort()\r\nans = 0\r\nfor i in range(m):\r\n if a[i] <= 0:\r\n ans+= -1*a[i]\r\n else:\r\n break\r\nprint(ans)\r\n", "def Sale(n,m):\n maxSales = 0;\n tvSets = [int(i) for i in input().split()];\n\n tvSets.sort()\n for r in range(len(tvSets)):\n if m > 0:\n if tvSets[r] < 0:\n maxSales += abs(tvSets[r])\n m -= 1\n if m == 0:break;\n\n return maxSales\n\nn,m = map(int,input().split());\nprint(Sale(n,m));", "#codeforces34B\r\ngi = lambda : list(map(int,input().strip().split()))\r\nn,m = gi()\r\nl = [e for e in gi() if e < 0]\r\nl.sort()\r\nprint(-sum(l[:m]))\r\n", "n,m = input().split()\nn = int(n)\nm = int(m)\n\nl = list(map(int,input().split()))\nl.sort()\nearn = 0\nfor i in range(len(l)):\n if m==0:\n break\n else:\n if l[i]<=0:\n earn = earn-l[i]\n m-=1\n else:\n break\n\nprint (earn)\n", "n, k = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\narr.sort()\r\nans = 0\r\nfor k in range(k):\r\n if arr[k] < 0:\r\n ans += abs(arr[k])\r\n else:\r\n print(ans)\r\n exit()\r\nprint(ans)", "tv_count, capacity = list(map(int, input().split()))\r\n\r\ntelevisions = list(map(int, input().split()))\r\nprofitables = [price for price in televisions if price < 0]\r\nprofitables.sort()\r\n\r\nmoney = -sum(profitables[:capacity])\r\nprint(money if money > 0 else 0)", "# https://codeforces.com/problemset/problem/34/B\n\nn, m = [int(num) for num in input().split()]\n\nTV = [int(num) for num in input().split()]\nTV.sort()\n\ni = 0\nsum = 0\nwhile(m>0 and i<n):\n if(TV[i] < 0):\n sum += -1*TV[i]\n m -= 1\n i += 1\n\nprint(sum)\n ", "n, m = map(int, input().split())\r\nlst = [int(i) for i in input().split()]\r\nlst = sorted(lst)\r\nans = 0\r\nfor i in lst[0:m]:\r\n if i >= 0:\r\n break\r\n else:\r\n ans += i\r\nprint(ans * -1)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\ncount=0\r\nfor i in range(m):\r\n if(a[i]>0):\r\n break;\r\n else:\r\n count+=a[i]\r\nprint(abs(count))", "n, m = map(int, input().split())\r\ns = sorted(list(map(int, input().split())))\r\nl = 0\r\nfor i in range(n):\r\n if s[i] < 0:\r\n l += 1\r\n else:\r\n break\r\nm = min(m,l)\r\nprint(-sum(s[:m]))\r\n", "inp=list(map(int,input().split()))\r\nn=inp[0]\r\nm=inp[1]\r\na=list(map(int,input().split()))\r\na.sort()\r\nc=0\r\nfor x in range(m):\r\n if(a[x]<0):\r\n c=c+(-1*a[x])\r\n else:\r\n break\r\n\r\nprint(c)", "import heapq\n\nn, m = map(int,input().split())\na = list(map(int,input().split()))\nheapq.heapify(a)\ncount = 0\nfor i in range(m):\n itm =heapq.heappop(a)\n if itm<0:\n count+=itm\n\nprint(-1*count)\n", "n, m = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n\r\na.sort()\r\nres = 0\r\nfor i in range(m):\r\n if a[i] < 0:\r\n res += a[i]\r\n else:\r\n break\r\n\r\nprint(abs(res))", "#SALE(34B)\r\n\r\nn,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nl.sort()\r\nsm,cnt = 0,0\r\n\r\nfor i in l:\r\n if i <= 0:\r\n sm += i\r\n cnt += 1\r\n \r\n if cnt == m:\r\n break\r\nprint(abs(sm))\r\n \r\n ", "n,m=list(map(int,input().split()))\r\narr=list(map(int,input().split()))\r\nc=0\r\ns=0\r\nx=0\r\narr.sort()\r\nwhile c<(m) and x<n:\r\n if arr[x]<0:\r\n s+=abs(arr[x])\r\n c+=1\r\n #print(c,s)\r\n x+=1\r\nprint(s)\r\n", "n,m = map(int,input().split())\r\ns = sorted([int(i) for i in input().split()])\r\nss = 0\r\nfor i in range(0,m):\r\n if s[i] < 0:\r\n ss += abs(s[i])\r\n else:\r\n break\r\nprint(ss)", "def merge(L,R):\r\n if L==[] or R==[]:\r\n return L+R\r\n else:\r\n T=[0 for i in range(len(L)+len(R))]\r\n i=0\r\n while L!=[] and R!=[]:\r\n T[i]=min([L[0],R[0]])\r\n if L[0]>=R[0]:\r\n R.pop(0)\r\n else:\r\n L.pop(0)\r\n i+=1\r\n if L==[]:\r\n T=T[0:i]+R\r\n elif R==[]:\r\n T=T[0:i]+L\r\n return T\r\n\r\n\r\ndef fusionsort(L):\r\n \"\"\"effectue le tri par fusion de la liste L\"\"\"\r\n if len(L)==1:\r\n return L\r\n elif len(L)==2 and L[1]<L[0]:\r\n L[0],L[1]=L[1],L[0]\r\n return L\r\n else:\r\n return merge(fusionsort(L[0:len(L)//2]),fusionsort(L[len(L)//2:len(L)]))\r\n\r\n\r\n\r\n\r\nn,m=map(int, input().split())\r\nA=map(int,input().split())\r\nA=list(A)\r\nL=fusionsort(A)\r\ni=0\r\np=0\r\nwhile i<m and i<len(L) and L[i]<0:\r\n p+=L[i]\r\n i+=1\r\nprint(-p)\r\n", "nb_sets, can_max = [int(x) for x in input().split()]\r\ntv_costs = [int(x) for x in input().split()]\r\nprint(abs(sum([x for x in sorted(tv_costs)[:can_max] if x <= 0])))", "x=[int(n) for n in input().split()]\r\nz=[int(n) for n in input().split()]\r\nz.sort()\r\nm=0\r\nfor n in range(x[0]):\r\n\tif z[n]<=0 and n<x[1]:\r\n\t\tm+=z[n]\r\nprint(-m)", "n,m=map(int,input().split())\n\nl=sorted(map(int,input().split()))\nc=0\nfor i in range(m):\n\tif l[i]<0:\n\t\tc+=abs(l[i])\n\nprint(c)\n\n\n\n", "n,m = map(int, input().split())\r\nk = list(map(int, input().split()))\r\nk = sorted(k)\r\ns=0\r\nfor i in range(m):\r\n if k[i]<0:\r\n s=s+abs(k[i])\r\nprint(s)", "import sys\nfrom os import path\nif (path.exists('input.txt') and path.exists('output.txt')):\n sys.stdout = open('output.txt', 'w')\n sys.stdin = open('input.txt', 'r')\n\n\ndef main():\n n, m = map(int, input().split())\n tvs = list(map(int, input().split()))\n tvs.sort()\n ans = 0\n for tv in tvs:\n if tv < 0 and m > 0:\n ans -= tv\n m -= 1\n else:\n break\n print(ans)\n\nmain()", "import math,sys;input=sys.stdin.readline;S=lambda:input().rstrip();I=lambda:int(S());M=lambda:map(int,S().split());L=lambda:list(M());mod1=1000000007;mod2=998244353\r\n\r\nn,k = M()\r\narr = L()\r\narr.sort()\r\nans = 0\r\nfor i in range(k):\r\n if arr[i]<0:\r\n ans+= -1*arr[i]\r\n else:\r\n break\r\n \r\n \r\nprint(ans)", "N, M = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort()\nans = 0\nfor i in range(M):\n if A[i] < 0:\n ans -= A[i]\nprint(ans)\n", "n = list(map(int,input().split(\" \")))\r\nv = list(map(int,input().split(\" \")))\r\nv.sort()\r\nsum = 0\r\ni = 0\r\nwhile i < n[0] and n[1] > 0:\r\n if v[i]<0:\r\n sum -= v[i]\r\n else:\r\n break\r\n i+=1\r\n n[1]-=1\r\nprint(sum)", "n,m = list(map(int, input().split()))\r\nprice = list(map(int, input().split()))\r\n\r\nprice.sort()\r\nmoney = 0\r\n\r\nfor i in range(m):\r\n if price[i]<0:\r\n money += price[i]\r\n\r\nprint(-1*money)", "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\n\r\nl.sort()\r\nres = 0\r\ncont = 0\r\n\r\nfor i in l:\r\n if i < 0 and cont < m:\r\n res += abs(i)\r\n cont += 1\r\nprint(res)", "x, y = map(int, input().split())\n\nintlist = list(map(int, input().split()))\n\nlist.sort(intlist)\nsum = 0\n\nfor i in intlist:\n if y > 0:\n if i >= 0:\n break\n else:\n sum += i\n y -= 1\n elif y == 0:\n break\n\nsum *= -1\n\nprint(sum)", "n,m = map(int, input().split())\r\nlist = list(map(int,input().split()))\r\nlist.sort()\r\nresult = 0\r\nfor i in list:\r\n if i < 0:\r\n result += abs(i)\r\n m -= 1\r\n if m == 0:\r\n break\r\nprint(result)", "# ========= /\\ /| |====/|\r\n# | / \\ | | / |\r\n# | /____\\ | | / |\r\n# | / \\ | | / |\r\n# ========= / \\ ===== |/====| \r\n# code\r\n\r\nif __name__ == \"__main__\":\r\n n,m = map(int,input().split())\r\n a = [int(i) for i in input().split()]\r\n b = list(filter(lambda x: x < 0,a))\r\n b.sort()\r\n if len(b) > m:\r\n print(-1 * sum(b[:m]))\r\n else:\r\n print(-1 * sum(b))", "n = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na = [i for i in a if i < 0]\r\na = sorted(a)\r\nprint(-1 * sum(a[:n[1]],0))", "def sort(massiv,n):\r\n for i in range(n-1):\r\n for j in range(n-1):\r\n if int(massiv[j])>int(massiv[j+1]):\r\n massiv[j],massiv[j+1]=massiv[j+1],massiv[j]\r\n return massiv\r\n\r\ndef main():\r\n n,m=input().split()\r\n n,m=int(n),int(m)\r\n massiv=input().split()\r\n massiv=sort(massiv,n)\r\n sum=0\r\n for i in range(m):\r\n if int(massiv[i])>=0:\r\n break\r\n sum+=int(massiv[i])\r\n return sum*-1\r\n\r\n\r\nprint(main())", "n,m = map(int, input().split(' '))\n\ns = list(map(int, input().split(' ')))\ncount =0\ns = sorted(s)\nfor i in range(m):\n if s[i] <= 0:\n count += s[i]\n\nprint(abs(count))\n\n \t \t \t\t \t\t \t \t \t \t\t", "a,b=tuple(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nl=l[:b]\r\ns=0\r\nfor i in l:\r\n if i<0:\r\n s+=abs(i)\r\nprint(s)", "n, m = map(int, input().split())\na = sorted(list(map(int, input().split())))\nans = 0\nfor i in range(m):\n\tif a[i] < 0:\n\t\tans += -a[i]\n\telse:\n\t\tbreak\nprint(ans)\n", "s = input().split(\" \")\r\nm = int(s[0])\r\nn = int(s[1])\r\nc = 0\r\na = list(map(int,input().split(\" \")))\r\na.sort()\r\nfor i in range(min(n,m)):\r\n if(a[i] < 0):\r\n c += a[i]\r\n else:\r\n break\r\nprint(-c)\r\n \r\n \r\n", "gp,m = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\ncounter = 0\r\nstonks = 0\r\nfor i in arr:\r\n if stonks + i < stonks:\r\n stonks += i\r\n counter += 1\r\n if counter == m:\r\n break\r\nprint(abs(stonks))", "n,m=map(int,input().split())\r\nlst=[int(x) for x in input().split()]\r\nlst.sort()\r\nans=0\r\nfor i in lst:\r\n if i<0:\r\n ans-=i\r\n m-=1\r\n else:break\r\n if m==0:break\r\nprint(ans)\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nmini=0\r\nx=list()\r\nfor v in range(0,n):\r\n if l[v]<0:\r\n x.append(l[v])\r\nif len(x)>m:\r\n for i in range(m):\r\n mini+=min(x)\r\n x.remove(min(x)) \r\nelse:\r\n mini=sum(x)\r\nif mini<0:\r\n print(-mini)\r\nelse:print(mini)", "a,b=map(int,input().split())\r\nt=list(map(int,input().split()))\r\nnegtv=[]\r\nfor i in range(a):\r\n if t[i]<0:\r\n negtv.append(-1*t[i])\r\nnegtv.sort()\r\nnegtv.reverse()\r\nif len(negtv)<=b:\r\n print(sum(negtv))\r\nelse:\r\n s=0\r\n for i in range(b):\r\n s+=negtv[i]\r\n print(s)\r\n", "x,y = map(int,input().split())\r\nz = map(int,input().split())\r\nprint(abs(sum(sorted(x for x in z if x < 0)[:y])))\r\n", "n, m = map(int,input().split())\r\ntv = list(map(int,input().split()))\r\ntv.sort()\r\ni = 0\r\ncount = 0\r\nearned = 0\r\nwhile count < m and i < n and tv[i]<0:\r\n\tearned -= tv[i]\r\n\ti += 1\r\n\tcount += 1\r\n\t\r\nprint(earned)", "n,m=[int(_) for _ in input().split()]\r\na=sorted([int(_) for _ in input().split()])\r\nprint(abs(sum(i for i in a[:m] if i < 0)))", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(n):\r\n if(a[i]<0):\r\n l.append(a[i])\r\nif(len(l)<m):\r\n ans=sum(l)\r\n print(abs(ans))\r\nelse:\r\n l.sort()\r\n p=l[0:m]\r\n print(abs(sum(p)))\r\n", "a,b=list(map(int,input().split()))\r\n\r\nt=list(map(int,input().split()))\r\nt.sort()\r\ns=0\r\nq=0\r\nfor j in range(b):\r\n if t[j]<0:\r\n s+=-1*t[j]\r\n elif t[j]>0:\r\n print(s)\r\n q+=1\r\n break\r\nif q==0:\r\n print(s)\r\n", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\na.sort()\r\ncol = 0\r\ne = 0\r\nfor i in range(n):\r\n if col < m and a[i] < 0:\r\n e += a[i]\r\n col += 1\r\n else:\r\n break\r\nprint(-e)\r\n", "import sys\n\n(n, m) = map(int, sys.stdin.readline().split(' '))\n\ndef main():\n nums = sorted(list(map(int, sys.stdin.readline().split(' '))))\n\n ret = 0\n for i in range(min(n, m)):\n if nums[i] >= 0:\n break\n ret -= nums[i]\n\n sys.stdout.write('{}\\n'.format(ret))\n\nmain()\n", "n,m=map(int,input().split())\r\nlst=list(map(int,input().split()))\r\nlst.sort()\r\ns=0\r\nfor i in range(len(lst)):\r\n if(lst[i]<0):\r\n s=s+abs(lst[i])\r\n m=m-1\r\n if(m==0):\r\n break\r\nprint(s)", "from sys import *\r\ndef input():\r\n return stdin.readline()\r\nn,m=map(int,input().split())\r\nl=[int(i) for i in input().split()]\r\nl1=[abs(i) for i in l if i<0]\r\nl1.sort(reverse=True)\r\nprint(sum(l1[:m]))\r\n", "n, m = [int(num) for num in input().split()]\r\ntvs = sorted([int(thing) for thing in input().split()])\r\nearns = 0\r\nfor element in tvs[0:m]:\r\n if element < 0:\r\n earns += -1*element\r\nprint(earns)", "import sys,os,io,time,copy\r\nif os.path.exists('input.txt'):\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\n\r\nimport math\r\n\r\ndef main():\r\n # start=time.time()\r\n n,m=map(int,input().split())\r\n arr=list(map(int,input().split()))\r\n arr.sort()\r\n res=0\r\n for i in range(m-1,-1,-1):\r\n if arr[i]<0:\r\n res+=(-1*arr[i])\r\n print(res)\r\n # end=time.time()\r\nmain()", "def main():\r\n [n_sets, max_carried] = [int(_) for _ in input().split()]\r\n prices = [int(_) for _ in input().split()]\r\n\r\n can_earn = [p for p in prices if p < 0]\r\n can_earn.sort()\r\n\r\n if len(can_earn) < max_carried:\r\n print(-sum(can_earn))\r\n else:\r\n print(-sum(can_earn[:max_carried]))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n, m = list(map(int, input().split()))\r\nprint(sum([-x for x in sorted(list(map(int, input().split())))[:m] if x < 0]))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\ni=0\r\nans=0\r\nwhile i<n and i<m:\r\n\tif a[i]<0:\r\n\t\tans+=a[i]\r\n\telse:\r\n\t\tbreak\r\n\ti+=1\r\nprint(abs(ans))", "n,m=map(int,input().split())\r\nprices=list(map(int,input().split()))\r\nprices.sort()\r\nprofit=0\r\nfor i in range(m):\r\n if prices[i]<=0:\r\n profit+=prices[i]\r\n else:\r\n break\r\n\r\nprint(abs(profit))\r\n", "def solve(n, m, prices):\r\n prices.sort()\r\n total_money = 0\r\n i, j = 0, 0\r\n while i < n and j < m:\r\n if prices[i] < 0:\r\n total_money += (-1) * (prices[i])\r\n i += 1\r\n j += 1\r\n return total_money\r\n\r\n\r\ndef main():\r\n l = list(map(int, input().strip().split()))\r\n n, m = l[0], l[1]\r\n prices = [int(a) for a in input().strip().split()]\r\n print(solve(n, m, prices))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n, m = input().split()\r\nn = int(n)\r\nm = int(m)\r\n\r\na = input().split()\r\na = list(map(int, a))\r\n\r\nmax_sum = 0\r\na.sort()\r\ncheck_max_sum = 0\r\n\r\nfor i in range(m):\r\n check_max_sum -= a[i]\r\n if(check_max_sum > max_sum):\r\n max_sum = check_max_sum\r\n\r\nprint(max_sum)", "n,m=map(int,input().split())\r\nl=sorted(map(int,input().split()))\r\nc=0\r\nfor i in range(m):\r\n\tif l[i]<=0:\r\n\t\tc+=abs(l[i])\r\nprint(c)\r\n", "ch=str(input())\r\nL=ch.split()\r\nn,m=int(L[0]),int(L[1])\r\nch=str(input())\r\nL=ch.split()\r\nLL=list()\r\nfor c in L:\r\n LL.append(int(c))\r\nL=LL \r\nL.sort()\r\nres=0\r\ni=0\r\nfor c in L:\r\n if int(c)<=0:\r\n res-=int(c)\r\n m-=1\r\n else:\r\n break\r\n if (m==0):\r\n break\r\nprint(res)", "chir,chi = input().split()\r\nch = [int(c) for c in input().split() if int(c)<0]\r\nch.sort()\r\n \r\nprint(abs(sum(ch[:int(chi)])))", "n,m = map(int,input().split())\na = list(map(int,input().split()))\na.sort()\ncount = 0\nc = 0\nfor i in range(len(a)):\n if a[i] < 0:\n count += abs(a[i])\n c += 1\nif c <= m :\n print(count)\nelse:\n count = sum(a[:m])\n print(abs(count))\n", "n,m=map(int,input().split())\r\n\r\nans=0\r\n\r\nL=list(map(int,input().split()))\r\n\r\nL.sort()\r\n\r\nfor i in range(m):\r\n if(L[i]>=0):\r\n break\r\n ans+=L[i]\r\nprint(-ans)\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\n\r\nl1=[]\r\nfor i in l :\r\n if i<0 :\r\n l1.append(abs(i))\r\n\r\nl1.sort(reverse=True)\r\nl1=l1[0:m]\r\nj=0\r\nfor i in l1 :\r\n j+=i\r\n\r\nprint(j)", "n,m=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nans=0\r\nfor i in range(m):\r\n if a[i]>0:break\r\n ans-=a[i]\r\nprint(ans)\r\n", "def solve(L,k):\r\n L=sorted(L)\r\n S=0\r\n for i in range(len(L)):\r\n if L[i]>0 or i>=k:break\r\n S=S+L[i]\r\n return(abs(S))\r\nn,k=map(int,input().split(\" \"))\r\nL=list(map(int,input().split(\" \")))\r\nprint(solve(L,k))", "'''\n R E X\n\n Date - 20th May 2021\n\n\n @author:\n CodeForces -> kunalverma19\n CodeChef -> kunalverma_19\n AtCoder -> TLKunalVermaRX\n'''\nimport sys\nimport re\nimport math\nMOD = 1000000007\ninp = lambda :map(int,input().split(' '))\nninp = lambda :int(input())\n# sys.stdin=open(\"input.txt\",\"r\")\nn,m=inp()\na=list(inp())\na.sort()\nans=0\nfor i in range(len(a)):\n\twhile m:\n\t\tif a[i]<0:\n\t\t\t# print(a[i])\n\t\t\tans+=abs(a[i])\n\t\ti+=1;\n\t\tm-=1\nprint(ans)\n\n\n", "n,m=map(int,input().split());a=list(map(int,input().split()));a.sort();c=0\r\nfor i in range(m):\r\n if a[i]<=0:c+=abs(a[i])\r\nprint(c)", "def main():\r\n n, m = map(int, input().split())\r\n price = list(map(int, input().split()))\r\n\r\n price.sort()\r\n total = 0\r\n for k in range(m):\r\n if price[k] < 0:\r\n total -= price[k]\r\n else:\r\n break\r\n\r\n print(total)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "m,n=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ns=0\r\nfor i in range(n):\r\n if l[i]<=0:\r\n s=s+abs(l[i])\r\nprint(s)", "#Ahmed Abdelrazik\r\nn,m = map(int,input().split())\r\nA = list(map(int,input().split()))\r\nc = 0\r\nMM = []\r\nfor i in range(n):\r\n if A[i]<0: MM.append(abs(A[i]))\r\n\r\nMM.sort(reverse=True)\r\n\r\nprint(sum(MM[:m]))", "while(1):\r\n try:\r\n n,m=map(int,input().split())\r\n a=list(map(int,input().split()))\r\n b=[ x for x in a if x<0]\r\n b.sort()\r\n print(-sum(b[:m]))\r\n except EOFError:\r\n break\r\n \r\n \r\n ", "a = input().split()\r\nk = list(input().split())\r\ns = []\r\nfor i in k:\r\n s.append(int(i))\r\nd = 0\r\nfor i in range(int(a[1])):\r\n p = min(s)\r\n s.remove(p)\r\n if p <= 0:\r\n d -= p\r\nprint(d)", "sets_and_carry = input().split()\r\ntv = int(sets_and_carry[0])\r\ncarry = int(sets_and_carry[1])\r\n\r\nprices = [*map(lambda x: int(x), input().split())]\r\n\r\ndef max_money(carry, prices):\r\n profitable_tv = sorted([i for i in prices if i < 0])\r\n if carry >= len(profitable_tv):\r\n sum_positives = sum([*map(lambda x: x*(-1), profitable_tv)])\r\n print(sum_positives)\r\n else:\r\n sum_positives = profitable_tv[:carry]\r\n print(sum(sum_positives) * -1)\r\n \r\n\r\nmax_money(carry, prices)", "n,m = map(int,input().split())\r\narr = list(map(int,input().split()))\r\nbrr = []\r\nfor i in range(n):\r\n if arr[i] < 0:\r\n brr.append(arr[i])\r\nbrr.sort()\r\nans = 0\r\nt = len(brr)\r\ni = 0\r\nwhile i < t and m:\r\n ans += -1*brr[i]\r\n i += 1\r\n m -= 1\r\nprint(ans)\r\n", "n, m = map(int, input().split())\nprices = list(map(int, input().split()))\n\n# Sort the prices in increasing order\nprices.sort()\n\n# Initialize variables to keep track of the maximum sum and number of TV sets bought\nmax_sum = 0\nnum_bought = 0\n\n# Iterate through the prices in reverse order (starting from the most negative)\nfor price in prices:\n # If we've already bought m TV sets, break out of the loop\n if num_bought == m:\n break\n \n # If the price is negative, add it to our maximum sum and increment the number of TV sets bought\n if price < 0:\n max_sum += abs(price)\n num_bought += 1\n \n # If the price is non-negative, we can stop buying TV sets since they are sorted in increasing order\n else:\n break\n\n# Output the maximum sum earned by Bob\nprint(max_sum)\n \t\t\t\t \t\t\t\t\t\t \t \t\t\t\t \t \t", "n,m=map(int,input().split())\r\nls=list(map(int,input().split()))\r\nlsn=[x for x in ls if x<0]\r\ns=0\r\nwhile len(lsn)>0 and m>0:\r\n\ts=s+(min(lsn)*(-1))\r\n\tlsn.remove(min(lsn))\r\n\tm=m-1\r\nprint(s)", "n, m = [int(x) for x in input().split()]\r\nres = sorted([int(x) for x in input().split()])\r\nbenefit = 0\r\nfor i in range(m):\r\n if res[i] <= 0:\r\n benefit += abs(res[i])\r\n else:\r\n break\r\nprint(benefit)", "n, m = map(int, input().split())\n\ntvs = list(map(int, input().split()))\n\ntvs = sorted(tvs)\n\nres = 0\nfor num in tvs:\n if not m:\n break\n if num < 0:\n res -= num\n m -= 1\n\nprint(res)\n\n\n", "tl = list(map(int, input().split()))\r\nn = tl[0]\r\nm = tl[1]\r\nsets = list(map(int, input().split()))\r\ncurCarrying = 0\r\nnegPrices = [] \r\nfor tvSet in sets:\r\n if (tvSet < 0):\r\n negPrices.append(tvSet)\r\nnegPrices = sorted(negPrices)\r\nprofit = 0\r\nfor tvPrice in negPrices:\r\n if (curCarrying == m):\r\n break\r\n profit -= tvPrice\r\n curCarrying += 1\r\nprint(profit)", "'''\r\n╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬ ▓▓█████▓▓ ╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬ ▓▓ ▓▓ ╬╬\r\n╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬\r\n\r\n###########################\r\n\r\n// •︿• \\\\\r\n/\\\\ //\\\r\n /\\\\ //\\\r\n /\\\\//\\\r\n\r\n###########################\r\n'''\r\nimport sys\r\ninput = lambda : sys.stdin.readline().strip()\r\nimport math as mt\r\nfrom math import ceil as cl\r\nfrom math import log2 as l2\r\nmod = 10**9 + 7 \r\ndef ii():\r\n return int(input())\r\ndef lii():\r\n return list(map(int, input().split()))\r\ndef ss():\r\n return input()\r\ndef lss():\r\n return list(map(str, input().split()))\r\ndef yes():\r\n print(\"YES\")\r\ndef no():\r\n print(\"NO\")\r\n'''\r\n╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬\r\n'''\r\na,b = lii()\r\nar = sorted(lii())\r\nar = ar[:b]\r\nfor x_x in range(b-1,-1,-1):\r\n if ar[x_x] >0:\r\n ar[x_x] = 0\r\n else:\r\n break\r\nprint(abs(sum(ar)))\r\n \r\n", "_,m = input().split()\r\nl = sorted(list(map(int,input().split())))\r\nr = []\r\nfor i in range(int(m)):\r\n if l[i] <= 0:\r\n r.append(l[i])\r\nprint(-sum(r))\r\n", "n, m = list(map(int, input().split()))\narr = list(map(int, input().split()))\nres = 0\nfor a in sorted(arr)[:m]:\n if a < 0:\n res -= a\n else:\n break\n\nprint(res)", "def f(x):\r\n if x <= 0:\r\n return(True)\r\n else:\r\n return(False)\r\nx,y = map(int,input().split())\r\nt = list(filter(f,sorted(map(float,input().split()))))\r\nprint(int(-(sum(t[:y]))))", "n,m=[int(x) for x in input().split(\" \")]\r\nli=list(map(int,input().split(\" \")))\r\na=[]\r\nb=[]\r\nso=0\r\nfor i in li:\r\n if (i<0):\r\n a.append(i*(-1))\r\n if(i>=0):\r\n b.append(i)\r\ne=len(a)\r\na.sort()\r\ns=sum(a)\r\nif (e<=m):\r\n print(sum(a))\r\nelse:\r\n a.reverse()\r\n dd=a[:m]\r\n print(sum(dd))", "n,m = map(int,input().split())\r\narr = list(map(int,input().split()))\r\narr.sort()\r\nres=0\r\nfor i in range(m):\r\n if arr[i]<0: res-=arr[i]\r\nprint(res)\r\n", "n,m = map(int,input().split())\r\nl = sorted(list(map(int,input().split()))+[0])\r\ntemp = l.index(0)\r\nprint(abs(sum(l[:min(m,temp)])))", "n,m=map(int,input().split())\r\nlst=list(map(int,input().split(' ')))\r\nlst.sort()\r\nprofit=0\r\nfor i in range(m):\r\n if(lst[i]<=0):\r\n profit+=abs(lst[i])\r\n \r\nprint(profit)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\nw=0\r\nx=0\r\nfor i in range(m):\r\n if a[i]<0:\r\n w=w+abs(a[i])\r\n else:\r\n print(w)\r\n x=1\r\n break\r\nif x==0:\r\n print(w)", "from sys import stdin,stdout\r\ninput=stdin.readline \r\nimport math,bisect\r\n\r\nn,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nans=0\r\nfor i in range(m):\r\n\tif l[i]<0:\r\n\t\tans+=abs(l[i])\r\n\telse:\r\n\t\tbreak\r\nprint(ans)", "n, m = map(int, input().split())\r\nt = list(map(int, input().split()))\r\nfor i in range(n):\r\n if t[i] > 0:\r\n t[i] = 0\r\n else:\r\n t[i] = abs(t[i])\r\nc = 0\r\nfor i in range(m):\r\n c = c + max(t)\r\n t[t.index(max(t))] = 0\r\n \r\n \r\n \r\n\r\nprint(c)", "x,y=list(map(int,input().split()))\r\nz=list(map(int,input().split()))\r\ne=sorted([i for i in z if i<0])\r\nif len(e)<=y:\r\n print(abs(sum(e)))\r\nelse:\r\n a=e[:y]\r\n print(abs(sum(a)))", "n,m=[int(i) for i in input().split()]\r\nlst=list(map(int,input().split()))\r\nlst.sort()\r\nc,k=0,0\r\nwhile m:\r\n if lst[k]<=0:\r\n c+=abs(lst[k])\r\n else:\r\n c+=0\r\n k+=1\r\n m-=1\r\nprint(c)", "x=list(map(int,input().split(\" \")))\r\ny=list(map(int,input().split(\" \")))\r\nsum=0\r\ny.sort()\r\nfor i in range(x[1]):\r\n if y[i]<0:\r\n sum+=y[i]\r\nprint(abs(sum))", "c=2\r\nm=[int(c) for c in input().split(' ')]\r\nj=[int(m[0]) for m[0] in input().split(' ')]\r\nj.sort()\r\nk=[]\r\nfor i in j:\r\n if i<0:\r\n k.append(i)\r\n else:\r\n continue\r\nprint(abs(sum(k[0:m[1]])))\r\n \r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nmoney=0\r\na.sort()\r\nfor i in range(k):\r\n\tif a[i]<0:\r\n\t\tmoney+=abs(a[i])\r\nprint(money)", "n, m = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\n\r\narr.sort()\r\n\r\nsum = 0\r\n\r\nfor i in range(m):\r\n if arr[i] < 0:\r\n sum = sum - arr[i]\r\n\r\nprint(sum)", "#34B\r\n\r\ndef solve(n, m, prices):\r\n\r\n prices.sort()\r\n\r\n total = 0\r\n for i in range(0, min(n, m)):\r\n if prices[i] >= 0:\r\n break\r\n total += prices[i]\r\n\r\n return -total\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\r\n n, m = list(map(int,input().split(\" \")))\r\n prices = list(map(int,input().split(\" \")))\r\n print (solve(n, m, prices))\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nc=0\r\nfor i in range(m):\r\n if i<=n-1:\r\n if l[i]<0:\r\n c+=abs(l[i])\r\n else:\r\n break\r\n c-=l[i]\r\nprint(c) ", "# LUOGU_RID: 110430407\nn,m=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\na.sort()\r\ni=0\r\ns=0\r\nwhile i<m and a[i]<0:\r\n s-=a[i]\r\n i+=1\r\nprint(s)", "n,m=map(int,input().split())\r\nc=sorted(list(map(int,input().split())))\r\ntot=0\r\ncount=0\r\nfor i in range(len(c)):\r\n\tif c[i]>-1:\r\n\t\tbreak\r\n\telse:\r\n\t\ttot+=abs(c[i])\r\n\t\tcount+=1\r\n\t\tif count==m:\r\n\t\t\tbreak\r\n\t\t\r\nprint(tot)\r\n", "n, m = list(map(int, input().rstrip().split()))\na = list(map(int, input().rstrip().split()))\na.sort()\ni = 0\nx = 0\nwhile i < m:\n if a[i] < 0:\n x += a[i]\n else:\n break\n i += 1\nprint(abs(x))", "n,m = map(int,input().split())\r\n\r\na = list(map(int,input().split()))\r\n\r\na.sort()\r\n\r\nres = 0\r\nfor i in range(m):\r\n if a[i]<0:\r\n res+=a[i]\r\n\r\n\r\nprint(-1*res)", "# It's all about what U BELIEVE\ndef gint(): return int(input())\ndef gint_arr(): return list(map(int, input().split()))\ndef gfloat(): return float(input())\ndef gfloat_arr(): return list(map(float, input().split()))\ndef pair_int(): return map(int, input().split())\n#############################################\nINF = (1 << 31)\ndx = [-1, 0, 1, 0]\ndy = [ 0, 1, 0, -1]\n#############################################\n#############################################\nn, m = gint_arr()\na = gint_arr()\nnegatives = []\n\nfor x in a:\n if x < 0:\n negatives.append(x)\n\nprint(-sum(sorted(negatives)[:m]))\n", "n,m=map(int,input().split())\na=list(map(int,input().split()))\na.sort()\nans=0\nfor i in range(m):\n\tif a[i]<0:\n\t\tans-=a[i]\n\telse:\n\t\tbreak\n\nprint(ans)\n", "x,y=map(int,input().split())\r\np=sorted(list(map(int,input().split())))\r\nn=0\r\nfor i in range(y):\r\n if p[i]<=0: \r\n n-=p[i]\r\nprint(n)\r\n\r\n\r\n", "# Problem Link: https://codeforces.com/problemset/problem/34/B\r\n# Problem Status:\r\n# ------------------------ SEPARATOR ------------------------\r\n# ------------------------ SEPARATOR ------------------------\r\nfrom typing import List\r\n# ------------------------ SEPARATOR ------------------------\r\n\r\n\r\ndef TheAmazingFunction(Array: list[int], Q):\r\n Array.sort()\r\n Counter = 0\r\n Answer = 0\r\n while Q > 0 > Array[Counter] and Counter < len(Array):\r\n Answer += Array[Counter]\r\n Counter += 1\r\n Q -= 1\r\n return abs(Answer)\r\n\r\n\r\n# ------------------------ SEPARATOR ------------------------\r\nN, M = list(map(int, input().split()))\r\nArr: list[int] = list(map(int, input().split()))\r\nprint(TheAmazingFunction(Arr, M))\r\n# ------------------------ SEPARATOR ------------------------\r\n", "b,a=input().split()\r\nm=list(map(int,input().split()))\r\nm.sort()\r\nsum=0\r\nfor i in range(int(a)):\r\n if m[i]>=0:\r\n break\r\n sum+=m[i]\r\nprint(abs(sum))", "n,m=map(int,input().split())\r\nx=sorted(list(map(int,input().split())))\r\ny=0\r\nfor i in range(m):\r\n\tt=x[0]\r\n\tif t<0:\r\n\t\tt=t*-1\r\n\t\ty+=t\r\n\t\tx.pop(0)\r\n\telse:\r\n\t\tbreak\r\nprint(y)", "from array import array\r\n\r\ndef main() -> int:\r\n n, m = tuple(int(x) for x in input().split())\r\n my_array = array('i', sorted([int(x) for x in input().split() if int(x) < 0]))\r\n return abs(sum(my_array[:m]))\r\n\r\nif __name__ == '__main__':\r\n print(main())", "a, b = map(int, input().split())\r\n\r\narr = [int(i) for i in input().split()]\r\n\r\narr.sort()\r\n\r\ns = 0\r\n\r\nfor i in range(b):\r\n\tif arr[i] < 0:\r\n\t\ts += arr[i]\r\n\telse:\r\n\t\tbreak\r\n\r\nprint(abs(s))", "n, m = map(int, input().split())\r\na = sorted([int(i) for i in input().split()])\r\nres = 0\r\nfor i in range(m):\r\n if a[i] < 0:\r\n res += a[i]\r\nprint(abs(res))", "# Sale\r\ns = input().split(\" \")\r\nn = int(s[0])\r\nm = int(s[1])\r\ns = input().split(\" \")\r\ns = [int(i) for i in s]\r\ns.sort()\r\nsum = 0\r\nfor i in range(m):\r\n if s[i] < 0:\r\n sum += s[i]\r\n else:\r\n break\r\nprint(-1*(sum))", "n = [int(x) for x in input().split()]\r\ns = [int(x) for x in input().split()]\r\nl = s.sort()\r\nmax_sum = 0\r\nconut = 0\r\nn1 = n[1]\r\nfor i in s:\r\n if i < 0 and conut < n1:\r\n max_sum += abs(i)\r\n conut +=1\r\nprint(max_sum)\r\n\r\n\r\n", "n,m = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\na.sort()\r\ni,l=0,0\r\nwhile m>0:\r\n if a[i]<=0:\r\n l+=abs(a[i])\r\n i+=1\r\n m-=1\r\n else:\r\n break\r\nprint(l)", "while True:\r\n\ttry:\r\n\t\tdef soln(n, k, a):\r\n\t\t\ts = i = 0\r\n\t\t\tj = k\r\n\t\t\ta.sort()\r\n\t\t\twhile i < n and j > 0:\r\n\t\t\t\tif a[i] < 0:\r\n\t\t\t\t\ts += abs(a[i])\r\n\t\t\t\telse:\r\n\t\t\t\t\tbreak\r\n\t\t\t\tj -= 1\r\n\t\t\t\ti += 1\r\n\t\t\tprint(s)\r\n\t\t\t\t\r\n\t\t\t\t\r\n\t\tdef read():\r\n\t\t\tn, k = map(int, input().split())\r\n\t\t\ta = list(map(int, input().split()))\r\n\t\t\tsoln(n, k, a)\r\n\t\tif __name__== \"__main__\":\r\n\t\t\tread()\r\n\texcept EOFError:\r\n\t\tbreak", "n , m = map(int , input().split())\r\ntv_sets = list(map(int , input().split()))\r\ntv_sets.sort()\r\ntv_sets = list(reversed(tv_sets))\r\n\r\nearn = 0\r\nsub = tv_sets[-1*m:]\r\n\r\nfor i in sub:\r\n if i < 0:\r\n earn += i\r\nearn *= -1\r\nprint(earn)\r\n\r\n\r\n\r\n", "amount,hold = map(int,input().split())\narr = list(map(int,input().split()))\narr.sort()\nearned = 0\nfor x in range(hold):\n if(arr[x] < 0):\n earned -= arr[x]\nprint(earned)\n", "n1,n2=map(int,input().split())\r\nl=list(map(int,input().split()))\r\np=[]\r\nfor i in range(len(l)):\r\n if(l[i]<0):\r\n p.append(abs(l[i]))\r\nif(len(p)<=n2):\r\n print(sum(p))\r\nelse:\r\n i=0\r\n s=0\r\n while True:\r\n if(i!=n2):\r\n s=s+max(p)\r\n p.remove(max(p))\r\n i=i+1\r\n else:\r\n break\r\n print(s)", "n,m=map(int,input().split())\narr=sorted(list(map(int,input().split())))\nans=0\nfor i in range(m):\n\tif arr[i]<0:\n\t\tans+=arr[i]\n\telse:\n\t\tbreak\nprint(abs(ans))\n\t \t\t\t \t \t\t\t \t\t \t\t\t\t\t \t \t\t\t\t \t", "n, m = map(int, input().split())\r\n\r\nara = list(map(int, input().split(\" \")))\r\n\r\n'''\r\ndef merge_sort(lo, hi):\r\n if (lo == hi):\r\n return;\r\n \r\n mid = lo + (hi - lo)//2\r\n\r\n merge_sort(lo, mid)\r\n merge_sort(mid+1, hi)\r\n\r\n temp = [-1 for i in range(hi-lo+1)]\r\n i = lo\r\n j = mid+1\r\n k = 0\r\n kk = lo\r\n\r\n while kk <= hi:\r\n if i == mid+1:\r\n temp[k] = ara[j]\r\n j += 1\r\n elif j == hi+1:\r\n temp[k] = ara[i]\r\n i += 1\r\n elif ara[i] < ara[j]:\r\n temp[k] = ara[i]\r\n i += 1\r\n else:\r\n temp[k] = ara[j]\r\n j += 1\r\n\r\n # last\r\n k += 1\r\n kk += 1\r\n\r\n k = 0\r\n kk = lo\r\n\r\n while kk <= hi:\r\n ara[kk] = temp[k]\r\n # last\r\n k += 1\r\n kk += 1\r\n\r\nmerge_sort(0, n-1)\r\n'''\r\n\r\n# print(ara)\r\n\r\nara.sort()\r\n\r\nans = 0\r\n\r\nfor i in range(m):\r\n if ara[i] < 0:\r\n ans += -ara[i]\r\n\r\nprint(ans)", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Jun 29 09:56:22 2021\r\n\r\n@author: Vineet\r\n\"\"\"\r\n\r\nn,m=map(int,input().split())\r\nlist1=list(map(int,input().split()[:n]))\r\ncount=0\r\n\r\nlist2=[]\r\nfor i in list1:\r\n if i<0 :\r\n list2.append(abs(i))\r\n else:\r\n continue\r\nif len(list2)==0:\r\n print(0)\r\nelse:\r\n list2.sort()\r\n a=list2[::-1]\r\n b=a[0:m]\r\n print(sum(b))\r\n \r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Thu Aug 13 18:46:02 2020\r\n\r\n@author: Arzoo\r\n\"\"\"\r\n\r\n\r\nmn=input()\r\nmn=mn.split(\" \")\r\nn=int(mn[0])\r\nm=int(mn[1])\r\nsf=input()\r\nsf=sf.split(\" \")\r\ns=list(map(int,sf))\r\n#print(s)\r\ns.sort()\r\n#print(sf1)\r\nans=0\r\ncount=0\r\nfor i in s:\r\n #print(i)\r\n if(int(i)<0):\r\n ma=(-1)*int(i)\r\n #print(m)\r\n ans=ans+ma\r\n #print(ans)\r\n count+=1\r\n if(count==m):\r\n break\r\nprint(ans)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ns=0\r\nfor i in range (m):\r\n if(l[i]<0):\r\n s+=l[i]\r\n else:\r\n break\r\nprint(-s)", "total,carry=map(int,input().split())\r\nt=[int(i) for i in input().split()]\r\nt.sort()\r\n# print(t)\r\nkaamkapaisa=int()\r\nfor i in range(carry):\r\n if t[i]<0:kaamkapaisa+=t[i]\r\nprint(abs(kaamkapaisa))\r\n\r\n# isme corner case kya hoga\r\n# lol I missed wo if statement, how dumb can i be lol", "L=lambda:list(map(int,input().split()))\r\nM=lambda:map(int,input().split())\r\nI=lambda:int(input())\r\nn,m=M()\r\na=L()\r\na.sort()\r\nx=0\r\ni=0\r\nwhile m>0 and a[i]<0:\r\n x+=a[i]\r\n i+=1\r\n m-=1\r\nprint(abs(x))\r\n", "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nl.sort()\r\nans = 0\r\nfor i in range(n):\r\n if m == 0:\r\n break\r\n if l[i] < 0:\r\n ans += l[i]\r\n m -= 1\r\nprint(abs(ans))", "\ncanttv, carga = map(int, input().split())\nprecios = list(map(int, input().split()))\n\nprecios.sort()\ntotal = 0\nfor i in range (carga):\n if i<carga and precios[i]<0:\n total += -precios[i]\nprint(total)\n\t\t\t\t\t\t \t\t \t\t\t \t\t \t \t \t\t \t", "class Solution:\r\n def __init__(self):\r\n self.n, self.m = [int(x) for x in input().split()]\r\n self.a = [int(x) for x in input().split()]\r\n\r\n def solve_and_print(self):\r\n self.a.sort()\r\n print(sum(-self.a[i] for i in range(self.m) if self.a[i] < 0))\r\n\r\nif __name__ == \"__main__\":\r\n Solution().solve_and_print()", "n,m=list(map(int,input().split()))\r\narr=list(map(int,input().split()))\r\narr.sort()\r\nans=0\r\nfor i in range(m):\r\n if(arr[i]<0):\r\n ans+=abs(arr[i])\r\n\r\nprint(ans)", "import math\r\nimport bisect\r\n \r\n \r\ndef sol():\r\n a,b=map(int,input().split())\r\n l=list(map(int,input().split()))\r\n ans=0\r\n\r\n l.sort()\r\n for i in range(b):\r\n if l[i]<0:\r\n ans-=l[i]\r\n else:\r\n break\r\n print(ans)\r\n \r\n \r\n \r\n \r\nsol()\r\n", "n, k = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\n\r\nprofit = 0\r\nprices.sort()\r\n\r\nfor i in range(n):\r\n if i >= k or prices[i] >= 0:\r\n break\r\n profit += abs(prices[i])\r\nprint(profit)\r\n\r\n\r\n", "a,b=map(int,input().split())\r\nl=sorted(list(map(int,input().split())))[:b]\r\ns=0\r\nfor i in l:\r\n if i<0:\r\n s=s+i\r\nprint(abs(s)) \r\n ", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\n#print(l)\r\nsum=0\r\ni=0\r\nwhile i<n and l[i]<0 and i<=(m-1):\r\n sum+=l[i]\r\n i+=1\r\nprint(abs(sum))", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nc=d=0\r\nfor i in range(n):\r\n if l[i]<=0:\r\n c+=l[i]\r\n d+=1\r\n if d==m:\r\n break\r\nprint(abs(c))", "n,m=map(int,input().split())\r\nprice=sorted(list(map(int,input().split())))\r\nsum_=0\r\nfor i in range(m):\r\n if price[i]<0:\r\n sum_+=abs(price[i])\r\n else:\r\n break\r\nprint(sum_) ", "from sys import stdin,stdout\r\n# from bisect import bisect_left,bisect\r\n# from heapq import heapify,heappop,heappush\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict,Counter\r\n# from itertools import permutations\r\n# from math import gcd,ceil,sqrt,factorial\r\n# setrecursionlimit(int(1e5))\r\ninput,print = stdin.readline,stdout.write\r\n\r\nn,m = list(map(int,input().split()))\r\na = sorted(list(map(int,input().split())))\r\nans = 0\r\ni = 0\r\nwhile m>0 and i<n:\r\n if a[i]<0:\r\n ans-=a[i]\r\n i+=1\r\n m-=1\r\n else:\r\n break\r\nprint(str(ans)+\"\\n\")\r\n", "n, m = map(int, input().split())\r\nprices = sorted(list(map(int, input().split())))\r\n\r\nmax = 0\r\ncount = 0\r\nwhile count < m and prices[count] < 0:\r\n max += abs(prices[count])\r\n count += 1\r\n\r\nprint(max)", "\r\nn, m = map(int, input().split())\r\narr = sorted(list(map(int, input().split())))\r\nprint(abs(sum(arr[i] for i in range(m) if arr[i] <= 0)))", "import math\r\ndef readint():\r\n return int(input())\r\n \r\ndef readarray(typ):\r\n return list(map(typ, input().split()))\r\n\r\n\r\nn, m = readarray(int)\r\ntvs = readarray(int)\r\ntvs.sort()\r\ni = 0\r\n\r\nbellar = 0\r\n\r\nwhile m > 0 and tvs[i] < 0:\r\n bellar -= tvs[i]\r\n i += 1\r\n m -= 1\r\n\r\nprint(bellar)", "a=[]\r\na=list(map(int,input().split()))\r\nprice=[]\r\nprice=list(map(int,input().split()))\r\nprice.sort()\r\nearning=0\r\nfor i in range(0,a[1]):\r\n if price[i]>0:\r\n \r\n break\r\n else:\r\n earning=earning+price[i]\r\nprint(-earning) ", "# hamed damirchi 95222031\r\n\r\nn, m = [int(x) for x in input().split()]\r\nTV_prices = [int(x) for x in input().split()]\r\nmax_benefit = 0\r\nTV_prices_minuses = []\r\nfor i in TV_prices:\r\n if i<0:\r\n TV_prices_minuses.append(abs(i))\r\nTV_prices_minuses.sort()\r\nTV_prices_minuses.reverse()\r\nfor i in range(m):\r\n if len(TV_prices_minuses)>i:\r\n max_benefit+=TV_prices_minuses[i]\r\nprint(max_benefit)\r\n\r\n", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\nprices.sort()\r\nmoney = 0\r\n\r\nfor t in range(m):\r\n if prices[0] < 0:\r\n money -= prices.pop(0)\r\n else:\r\n break\r\n\r\nprint(money)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=0\r\nb=[]\r\nfor i in a:\r\n if i<0:\r\n b.append(-i)\r\nb.sort(reverse=True)\r\nif len(b)<m:\r\n s=sum(b)\r\nelse:\r\n for i in range(m):\r\n s=s+b[i]\r\nprint(s)\r\n \r\n \r\n", "n,m=map(int,input().split())\nl=list(map(int,input().split()))\nl.sort()\ni=0\ncost=0\nwhile(i<m and l[i]<0):\n cost-=l[i]\n i+=1\nprint(cost)", "a, c = map(int, input().rstrip().split(\" \"))\r\nz = list(map(int, input().rstrip().split(\" \")))\r\nz.sort()\r\ntotal = 0\r\ntest = 1\r\nb = 0\r\nz = z[:c]\r\nfor i in z:\r\n if i <= 0:\r\n total = total + i\r\n else:\r\n break\r\nprint(abs(total))", "n,m=map(int,input().split());p=0\r\na=sorted(list(map(int,input().split())))\r\nfor i in range(m):\r\n\tif a[i]>=0:break\r\n\telse:p=p+abs(a[i])\r\nprint(p)", "n, m = list(map(int, input().strip().split(' ')))\r\narr = list(map(int, input().strip().split(' ')))\r\narr.sort()\r\n\r\nans = 0\r\ni = 0\r\nwhile (i < m and i < len(arr)):\r\n ans = max(ans, ans-arr[i])\r\n i += 1\r\n\r\nprint(ans)\r\n", "h = input().split()\r\nn = int(h[0])\r\nm = int(h[1])\r\ns = list(map(int, input().split()))\r\ns.sort()\r\ni = 0\r\nsumma = 0\r\nwhile i < m and s[i] < 0:\r\n summa -= s[i]\r\n i += 1\r\nprint(summa)\r\n", "q, w = map(int, input().split())\r\ne = [int(a) for a in input().split()]\r\ne.sort()\r\nh = 0\r\nfor i in range(min(len(e), w)):\r\n k = e[i]\r\n if k > 0:\r\n break\r\n else:\r\n h += abs(k)\r\nprint(h)", "#F\r\nn, m = [int(x) for x in input().split()]\r\ntotal = int(0)\r\na = [int(x) for x in input().split()]\r\na.sort()\r\nfor i in range(m):\r\n if (a[i]<=0):\r\n total+=a[i]\r\nprint(total*-1)", "n,m=map(int,input().split()) \r\na=list(map(int,input().split())) \r\np=0\r\na.sort()\r\nfor i in range(m):\r\n if(a[i]<0):\r\n p+=a[i]\r\nprint(-p)", "R = lambda:list(map(int,input().split()))\r\nn,m = R()\r\na = R()\r\na.sort()\r\nr = 0\r\nc = 0\r\nfor x in a:\r\n if x >= 0:\r\n break\r\n r -= x\r\n c += 1\r\n if c == m:\r\n break\r\n \r\nprint(r)", "n,k=([int(x) for x in input().split()])\r\nl1=[]\r\nl1.append([int(x) for x in input().split()])\r\nl2=l1[0]\r\na=0\r\nfor i in range(n):\r\n if l2[i]<0:\r\n a=a+1\r\nm=min(a,k)\r\nl2.sort()\r\nsum=0\r\nfor i in range(m):\r\n sum=sum+l2[i]\r\nprint(-sum)", "\r\nn, m = map(int, input().split())\r\nprices = [int(p) for p in input().split()]\r\nprices = [p for p in prices if p < 0]\r\nprices.sort()\r\nprint(-sum(prices[:m]))\r\n", "n, m = map(int, input().split())\r\nts = list(map(int, input().split()))\r\nans=0\r\nts.sort()\r\ni = 0\r\nwhile i<m and ts[i]<0:\r\n ans-=ts[i]\r\n i+=1\r\nprint(ans)", "n,m=[int(e) for e in input().split()]\r\na=[int(e) for e in input().split()]\r\na.sort()\r\na=[i for i in a if i <0]\r\nb=a[:m]\r\nprint(-1*sum(b)) ", "a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\ns=0\r\nfor i in l:\r\n if i<0 and b>0:\r\n s+=i \r\n b-=1\r\n else:\r\n break \r\nprint(abs(s))", "N = [int(_) for _ in input().split()][1]\r\nL = sorted([int(_) for _ in input().split()])\r\nNewL = []\r\nfor i in range(N):\r\n if L[i]<0:\r\n NewL.append(abs(L[i]))\r\n else:\r\n NewL.append(-L[i])\r\nS,M = 0,0\r\nfor i in NewL:\r\n S+=i\r\n if S>M:\r\n M=S\r\nprint(M)", "n, m = map(int, input().split())\r\narr = sorted(list(map(int, input().split())))\r\nans, c = 0, 0\r\nfor i in range(len(arr)):\r\n if arr[i] < 0:\r\n ans += abs(arr[i])\r\n c += 1\r\n if c == m or arr[i] > 0:\r\n break\r\nprint(ans)\r\n", "n,m=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\nprint(abs(sum([x for x in sorted(a)[:m] if x<=0])))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\na.sort()\r\ns=0\r\nj=0\r\nfor i in range(n):\r\n x=a[i]\r\n if(j<m):\r\n if(x<0):\r\n s+=-x\r\n j+=1\r\n else:\r\n break\r\n else:\r\n break\r\nprint(s)", "import sys\r\nfrom os import path\r\n\r\nif path.exists('input.txt'):\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\n\r\nn, m = map(int, sys.stdin.readline().rstrip().split())\r\na = list(map(int, sys.stdin.readline().rstrip().split()))\r\na.sort()\r\ns = 0\r\nfor x in range(m):\r\n if a[x] <= 0:\r\n s += abs(a[x])\r\n else:\r\n break\r\nprint(s)\r\n", "n, m =map(int,input().split())\r\nans =0\r\narray=list(map(int,input().split()))\r\narray.sort()\r\n# print(array)\r\nfor i in array:\r\n if m>0 and i<0:\r\n ans+=abs(i)\r\n m-=1\r\n # print(i)\r\n # print(m)\r\nprint(ans)\r\n", "a,b=input().split( )\na=sorted(list(map(int,input().split( ))))\nfor i in range(len(a)):\n if a[i]>0:\n a[i]=0\nprint(-sum(a[:int(b)]))", "# https://codeforces.com/problemset/problem/34/B\r\n\r\nn, m = map(int, input().split())\r\nseq = list(map(int, input().split()))\r\nseq.sort()\r\ncnt = 0\r\nfor k in range(m):\r\n if seq[k] < 0:\r\n cnt += (-1)*seq[k]\r\n else:\r\n break\r\nprint(cnt)\r\n", "n,m = map(int,input().split())\r\nl = input().split()\r\nl = [int(i) for i in l]\r\nl.sort()\r\nans = 0\r\n\r\nfor i in range(m):\r\n if l[i] < 0:\r\n ans = ans + abs(l[i])\r\n\r\nprint(ans)", "n, m = map(int,input().split())\r\nscore = list(map(int,input().split(' ')))\r\nscore.sort()\r\nsums=0\r\nfor i in range(m):\r\n if score[i]<=0:\r\n sums+=abs(score[i])\r\nprint(sums)", "inputs = [int(num) for num in input().split()]\r\nn = inputs[0]\r\nm = inputs[1]\r\nlist1 = [int(num) for num in input().split()]\r\nlist2 = []\r\nfor i in range(0,len(list1)):\r\n if(list1[i]<0):\r\n list2.append(-1*list1[i])\r\nif(len(list2)>0):\r\n list2.sort()\r\n count=0\r\n k = len(list2)-1\r\n for i in range(0,m):\r\n count+=list2[k]\r\n k-=1\r\n if(k==-1):\r\n break\r\n print(count)\r\nelse:\r\n print(0)", "\r\ndef answer(n, m, prices):\r\n prices.sort()\r\n sum = 0\r\n for i in range(m):\r\n if prices[i] < 0:\r\n sum += prices[i]\r\n return (0-sum)\r\n\r\n\r\n\r\n\r\n\r\ndef main():\r\n n, m = [int(i) for i in input().split()]\r\n prices = [int(i) for i in input().split()]\r\n \r\n print(answer(n, m, prices))\r\n\r\n\r\n\r\nmain()", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nd = []\r\nfor i in range(0,len(a)):\r\n if a[i] < 0:\r\n d += [a[i]]\r\nt = sorted(d)\r\nprint(abs(sum(t[0:m])))\r\n \r\n", "n,m= map(int,input().split())\r\nx = list(map(lambda q:int(q), input().split(\" \")))\r\nx.sort()\r\np=0\r\nt=0\r\nfor i in range(n):\r\n if x[i]>0:\r\n break\r\n p+=(x[i]*(-1))\r\n t+=1\r\n if x[i]>0:\r\n break\r\n if t==m:\r\n break\r\nprint(p)\r\n \r\n", "n,m=input().split()\r\nl=[int(i) for i in input().split(' ')]\r\nl.sort()\r\ns=0\r\nfor i in l[0:int(m)]:\r\n if i<0:\r\n s=s+int(i)\r\nif(s<0):\r\n print(abs(s))\r\nelse:\r\n print(0)", "import math\r\ns = input().split(\" \")\r\nlst = input().split(\" \")\r\nlst.sort(key=int)\r\nsum = 0\r\ni =0\r\nk = int(s[1])\r\nwhile(k>0):\r\n if int(lst[i])>0:\r\n break\r\n sum += abs(int(lst[i]))\r\n k -= 1\r\n i += 1\r\nprint(sum)\r\n \r\n \r\n \r\n\r\n \r\n\r\n", "\r\ndef main():\r\n n,m = map(int,input().split())\r\n arr = list(map(int,input().split()))\r\n arr = sorted(arr)\r\n a = [abs(i) for i in arr[:m] if i < 0]\r\n print(sum(a))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain()", "n,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\ni=0\r\nl.sort()\r\ns = 0\r\nwhile(m>0 and l[i]<0):\r\n s += l[i]\r\n m-=1\r\n i+=1\r\nprint(abs(s))\r\n", "n, m = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\na.sort()\r\nprofit = 0\r\nfor i in range(m):\r\n if(a[i] < 0):\r\n profit += abs(a[i])\r\nprint(profit)\r\n", "n,m=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nfor i in range(len(a)):\r\n if(a[i]>0):\r\n a[i]=0\r\nprint(abs(sum(a[:m])))", "\nn, m = map(int, input().split())\ntv = list(map(int, input().split()))\ncount = 0\nminus = []\n\nfor i in tv:\n if i < 0:\n minus.append(-i)\n\n\nfor i in range(len(minus)-1):\n for j in range(len(minus)-1-i):\n if minus[j] > minus[j+1]:\n minus[j], minus[j + 1] = minus[j + 1], minus[j]\n\nfor i in minus[-1:-m-1:-1]:\n count+= i\nprint(abs(count))\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Wed Apr 15 12:37:24 2020\r\n\r\n@author: DELL\r\n\"\"\"\r\na,b=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nc=0\r\nfor i in range(b):\r\n if l[i]<0:\r\n l[i]*=-1\r\n c+=l[i]\r\nprint(c)", "l = list(map(int,input().split()))\r\nn = l[1]\r\nm = list(map(int,input().split()))\r\nm.sort()\r\nm = m[:n]\r\ns=0\r\nfor i in m:\r\n if i<0:\r\n s+=i\r\nprint(-s)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nnl=[]\r\nfor i in l:\r\n if i<0:\r\n nl.append(-i)\r\nnl.sort(reverse=True)\r\ns=0\r\nif m>=len(nl):\r\n s=sum(nl)\r\nelse:\r\n for i in range(0,m):\r\n s+=nl[i]\r\nprint(s)", "m,k=map(int,input().split())\nl=sorted(list(map(int,input().split())))\ns=0\nn=1\nfor q in range(m):\n #print(n,k)\n if n>k:\n break\n if l[q]>0:\n break\n s+=-1*l[q]\n n+=1\nprint(s)", "n,m = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\n\r\nans = 0\r\ncount = 0\r\n\r\nfor i in a:\r\n if i < 0 and count < m:\r\n ans -= i\r\n count += 1\r\n else: break\r\n\r\nprint(ans)", "n,m = map(int,input().split())\r\na = sorted(list(map(int,input().split())))\r\nans = 0\r\nfor i in range(m):\r\n if a[i]<=0:\r\n ans-=a[i]\r\nprint(ans)", "n,m=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nx.sort()\r\ns=0\r\nfor i in range(m):\r\n\tif x[i]<0:\r\n\t\ts-=x[i]\r\nprint(s)", "a=input().split()\nb=input().split()\nfor i in range(len(b)):\n\tb[i]=int(b[i])\nb.sort()\nc=int(0)\nfor j in range(int(a[1])):\n\tif int(b[j])>0:\n\t\tpass\n\telse:\n\t\tc+=int(b[j])\nprint(int(abs(c)))", "# import inbuilt standard input output\nfrom sys import stdin, stdout\nimport math\ndef main():\n n, m = [int(x) for x in stdin.readline().split(\" \")]\n values = [(int(x)<0) * int(x) for x in stdin.readline().split(\" \")]\n values.sort()\n \n total = sum(values[:m])\n final_ = str(-total) \n stdout.write(final_)\n\nif __name__ == \"__main__\":\n main()", "n, m = map(int, input().split())\r\nprices = list(map(int, input().split()))\r\nprices.sort()\r\n\r\nprofit = 0\r\nfor i in range(m):\r\n if prices[i] < 0:\r\n profit -= prices[i]\r\n\r\nprint(profit)\r\n", "# Sale \ndef tvs(arr, m):\n ans = 0\n for i in sorted(arr):\n if i < 0:\n ans += (-1 * i)\n m -= 1\n if m == 0:\n break\n return ans\n\n\n\nn, m = list(map(int, input().rstrip().split()))\narr = list(map(int, input().rstrip().split()))\nprint(tvs(arr, m))", "a = str(input())\r\ntmp = a.split()\r\nn = int(tmp[0])\r\nm = int(tmp[1])\r\ns = str(input())\r\nans = 0\r\nl = s.split()\r\nfor i in range(len(l)):\r\n l[i] = int(l[i])\r\nl.sort()\r\nfor i in range(m):\r\n if(l[i] <= 0):\r\n ans += (l[i] * (-1))\r\nprint(ans) \r\n \r\n", "m,n=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\na.sort()\r\ns=0\r\nfor i in range(n):\r\n if a[i]>=0:\r\n break\r\n s=s+a[i]\r\nprint(s*-1)", "from sys import stdin\r\n\r\nnm = list(map(int, stdin.readline().split()))\r\n\r\nTV = list(map(int, stdin.readline().split()))\r\nTV.sort()\r\nearned = 0\r\n\r\nfor i in range(nm[1]):\r\n if TV[i] < 0:\r\n earned += abs(TV[i])\r\n\r\nprint(earned)", "a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\ns=0\r\nc=0\r\nl.sort()\r\nfor i in l:\r\n if c<b and i<0:\r\n s=s+i\r\n c=c+1\r\nprint(abs(s))", "a,b=map(int,input().split())\r\narr=list(map(int,input().strip().split()))\r\narr.sort()\r\nfor i in range(a):\r\n if arr[i]>0:\r\n arr=arr[:i]\r\n break\r\nj=min(len(arr),b)\r\nprint(abs(sum(arr[:j])))", "n,m=[int(i) for i in input().split()]\r\narr=list(map(int,input().strip().split()))\r\nsum=0\r\narr.sort()\r\nfor i in range(m):\r\n if arr[i]>=0:\r\n break\r\n sum=sum-arr[i]\r\nprint(sum)", "n,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nl.sort()\r\ns = 0\r\nfor I in range(m):\r\n if l[I] < 0:\r\n s += l[I]\r\nprint(abs(s))", "n, m = map(int, input().split())\nl = sorted(list(map(int, input().split())))\ns = 0\nfor i in range(0, m):\n if l[i] < 0:\n s += l[i]\n\nprint(abs(s))\n", "#!/usr/bin/python3\n\nn = [int(x) for x in input().split()]\nsetTV, carry = n[0], n[1]\n\nTVset = [int(x) for x in input().split()]\nTVset.sort()\n\nearn = 0\nfor i in range(len(TVset)) :\n\tif i < carry :\n\t\tif earn+TVset[i] <= earn :\n\t\t\tearn += TVset[i]\n\t\telse : \n\t\t\tbreak\n\telse : break\n\nprint(abs(earn))\n\n", "n,m=map(int,input().split())\r\nprice=list(map(int,input().split()))\r\nprice.sort()\r\ntotal=0\r\nfor i in range(m):\r\n if price[i]<0:\r\n total-=price[i]\r\nprint(total)\r\n ", "a, b = [int(s) for s in input().split()]\r\nc = sorted([int(s) for s in input().split()])\r\ns = 0\r\nfor i in range(b):\r\n if c[i] > 0:\r\n break\r\n s += c[i]\r\nif s > 0:\r\n s = 0\r\nprint(abs(s))", "\r\ndef main(): \r\n n,m=[int(x) for x in input().split()]\r\n price=[int(x) for x in input().split()]\r\n price.sort()\r\n ans=0\r\n for i in range(m):\r\n if(price[i]<0):\r\n ans-=price[i]\r\n else: \r\n break\r\n print(ans)\r\nmain()", "n, m = [int(i) for i in input().split()]\r\ns = [int(j) for j in input().split()]\r\nmaximum = 0\r\n\r\nl1 = sorted(s)[:m]\r\n\r\nfor k in range(len(l1)):\r\n if l1[k] < 0:\r\n maximum += l1[k]\r\n else:\r\n break\r\n\r\nout = -maximum\r\nprint(out)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn,m=map(int,input().split())\r\nA=list(map(int,input().split()))\r\n\r\nA.sort()\r\nANS=0\r\nSUM=0\r\nfor i in range(m):\r\n SUM+=A[i]\r\n ANS=min(ANS,SUM)\r\n\r\nprint(-ANS)\r\n \r\n", "n,m=map(int,input().split())\r\na=[int(x) for x in input().split()]\r\na.sort()\r\nss=0\r\nfor i in range(m):\r\n if a[i]>0:\r\n break\r\n ss+=abs(a[i])\r\nprint(abs(ss))", "n,m=map(int,input().split())\r\na=sorted(list(map(int,input().split())))\r\nb=list(filter(lambda x:x<=0,a))\r\ny=min(len(b),m)\r\nprint(-sum(a[:y]))", "n, m = map(int, input().split())\r\n\r\nnums = list(map(int, input().split()))\r\n\r\nnums.sort()\r\n\r\nt = nums[:m]\r\n\r\n#print(t)\r\n\r\ni = 0\r\nwhile i < len(t):\r\n if t[i] >= 0:\r\n break\r\n i += 1\r\n\r\n#print(i)\r\nprint(-1 * sum(t[:i]))\r\n", "n,m=map(int,input().split())\np=list(map(int,input().split()))\np.sort()\ni=0\nres=0\nwhile m!=0 and p[i]<0:\n res+=abs(p[i])\n m-=1\n i+=1\nprint(res)\n\n\t\t\t \t\t\t\t \t \t\t \t\t \t\t \t \t", "n, m = map(int, input().split())\r\na = sorted(list(map(int, input().split())))\r\npos = 0\r\nres = 0\r\nwhile pos < n and a[pos] < 0 and pos < m:\r\n res += -a[pos]\r\n pos += 1\r\nprint(res)\r\n", "n, m = [int(i) for i in input().split()]\r\np = [int(i) for i in input().split()]\r\nk = 0\r\nl = []\r\nfor i in p:\r\n if i < 0:\r\n l.append(i)\r\nl.sort()\r\nfor i in range(len(l)):\r\n if i > m-1:\r\n break\r\n else:\r\n k -= l[i]\r\nprint(k)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl.sort()\r\nsum=0\r\nk=0\r\nfor i in l:\r\n if k==m or i>0:\r\n break\r\n sum+=i\r\n k+=1\r\nprint(max(sum,-sum))", "n, m = map(int, input().split())\r\nlst = [*map(int, input().split())]\r\nlst.sort()\r\nres = 0\r\nfor i in range(m):\r\n res = min(res, res + lst[i])\r\nprint(res * -1)\r\n", "total , carry = map(int,input().split())\r\ntels = input().split()\r\nlist1 = []\r\nstring = ''\r\nfor i in tels:\r\n list1.append(int(i))\r\n string += i\r\ncount_neg = string.count('-')\r\ncount = 0\r\niterator = 0\r\nfor i in range(count_neg):\r\n minn = 0\r\n for i in list1:\r\n if minn>i:\r\n minn = i\r\n count += abs(minn)\r\n list1.remove(minn)\r\n iterator +=1\r\n if iterator == carry:\r\n break\r\nprint(count)", "n, m = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nlst.sort()\r\ntot = 0\r\nfor i in range(m):\r\n if lst[i] >= 0:\r\n break\r\n tot += lst[i]\r\n\r\nprint(-tot)\r\n", "\r\nn,m=map(int,input().split())\r\nl=sorted(list(map(int,input().split())))\r\ns,i=0,0\r\nwhile m>=0 and i<len(l):\r\n\tm-=1\r\n\tif l[i]<0:\r\n\t\ts+=abs(l[i])\r\n\t\t# print(s)\r\n\telse:\r\n\t\tbreak\r\n\tif m==0:\r\n\t\tbreak\r\n\ti+=1\r\nprint(s)", "n, m = [int(i) for i in input().strip().split()]\r\narr = [j for j in [int(i) for i in input().strip().split()] if j < 0]\r\narr.append(-0)\r\narr.sort()\r\nprint(-sum(arr) if len(arr) < m else -sum(arr[:m]))", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef main() -> None :\r\n CARRY_COUNT:int = inputArray()[1]\r\n TV_PRICES:list[int] = inputArray()\r\n\r\n BUY_PROFITS:list[int] = [(-tvPrice if tvPrice<0 else 0) for tvPrice in TV_PRICES]\r\n MAX_PROFIT:int = sum(sorted(BUY_PROFITS, reverse=True)[:CARRY_COUNT])\r\n\r\n print(MAX_PROFIT)\r\n\r\n\r\ndef inputArray() -> list[int] :\r\n return list(map(int, input().split()))\r\n\r\nmain()", "n,m = map(int, input().split())\r\nli = list(map(int,input().split()))\r\nli.sort()\r\nres = 0\r\nfor i in li:\r\n if i < 0:\r\n res += abs(i)\r\n m -= 1\r\n if m == 0:\r\n break\r\nprint(res)", "n,m=map(int,input().split())\r\nnums=list(map(int,input().split()))\r\nnums.sort()\r\nans=0\r\nfor i in range(m):\r\n if(nums[i]>=0):\r\n break\r\n else:\r\n ans+=abs(nums[i])\r\nprint(ans)\r\n", "n,m=[int(x) for x in input().split()]\r\narr=[int(X) for X in input().split()]\r\narr.sort()\r\ntotal=0\r\nfor i in range(m):\r\n if(arr[i] <0):\r\n total+=abs(arr[i])\r\nprint(total)", "r=lambda:map(int,input().split())\r\nn,m=r()\r\nlst=sorted(list(r()))\r\n#print(lst)\r\ns=0\r\nfor i in range(m):\r\n if lst[i]<0:\r\n s+=lst[i]\r\nprint(abs(s))\r\n", "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nl.sort()\r\n\r\nd = 0\r\nfor i in range(m):\r\n if l[i] >= 0:\r\n break\r\n d += l[i]\r\n \r\nprint(-d)\r\n", "b=input().split()\nn=int(b[0])\nm=int(b[1])\nprice=input().split()\nfor i in range(len(price)):\n\tprice[i]=int(price[i])\nprice.sort()\nsum=0\nfor i in range(m):\n\tif(price[i]<=0):\n\t\tsum=sum+price[i]\nprint(-1*sum)\n\n\n", "n,m=map(int,input().split())\r\n\r\na=[]\r\nmp=map(int,input().split())\r\nfor i in mp:\r\n a.append(i)\r\n\r\na.sort()\r\n\r\nans=0\r\nfor i in range(0,m):\r\n if a[i]>=0:\r\n break\r\n ans += -a[i]\r\n\r\nprint(ans)\r\n\r\n", "n,m=map(int,input().split())\r\na=list(map(lambda x:min(int(x),0),input().split()))\r\n#print(sorted(a))\r\nb=sum(sorted(a)[:m])\r\nprint(abs(b))", "n, m = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\na.sort()\r\nres = 0\r\nfor i in range(m):\r\n\tif a[i] >= 0:\r\n\t\tbreak\r\n\telse:\r\n\t\tres += a[i]\r\n\r\nprint(abs(res))", "\r\na=list(map(int,input().split()))\r\nb=a[1]\r\nc=list(map(int,input().split()))\r\nc=sorted(c)\r\nans=0\r\nfor i in range(b):\r\n if c[i]<0:\r\n ans=ans+c[i]\r\nprint(abs(ans))", "n, m = map(int,input().split())\nprice = list(map(int,input().split()[:n]))\nprice.sort()\ncount = 0\nfor i in range(n):\n if price[i] <= 0 and i<m:\n count += price[i]\nprint(-1*(count))", "def read_int():\n return int(input().strip())\n\ndef read_ints():\n return list(map(int, input().strip().split()))\n\ndef read_str():\n return input().strip()\n\ndef read_strs():\n return input().strip().split()\n\ndef result(n, m, a):\n return -sum([i for i in sorted(a)[slice(m)] if i < 0])\n\ndef main():\n n, m = read_ints()\n a = read_ints()\n print(result(n, m, a))\n\nif __name__ == '__main__':\n main()", "a,b = map(int,input().split())\r\nk = list(map(int,input().split()))\r\nk = [abs(i) for i in k if i<0]\r\nk.sort()\r\n\r\nprint(sum(k[-(b):]))", "n, m = list(map(int, input().split()))\nmrr = list(map(int, input().split()))\nmrr = [-1*x for x in mrr]\nmrr.sort(reverse=True)\nt = 0\nmax_so_far = -10000\ncurr_max = 0\nfor x in mrr:\n if t >= m:\n break\n curr_max += x\n if curr_max > max_so_far:\n max_so_far = curr_max\n t += 1\nif max_so_far < 0:\n max_so_far = 0\nprint(max_so_far)\n", "a=input().split()\r\nb=int(a[0])\r\nc=int(a[1])\r\nk=input().split()\r\nl1=[int(i) for i in k]\r\nl1.sort()\r\nco=0\r\npr=0\r\nfor i in l1:\r\n if co==c:\r\n break\r\n else:\r\n if i<0:\r\n pr+=(-1)*i\r\n co+=1\r\n else:\r\n break\r\nprint(pr)\r\n \r\n", "n, m = map(int, input().split())\r\na = sorted([int(i) for i in input().split()])\r\n\r\nc = 0\r\ni = 0\r\nwhile m>0:\r\n if a[i]<0:\r\n m-=1\r\n c+=a[i]\r\n i+=1\r\n else:\r\n break\r\n\r\nprint(-c)\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl=sorted(l)\r\ns=0\r\na=0\r\nfor i in l:\r\n if(i<0 and a!=m):\r\n s+=abs(i)\r\n a+=1\r\nprint(s)\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\ntotal=0\r\na.sort()\r\nfor i in range(m):\r\n if a[i]<=0:\r\n total+=-1*a[i]\r\n else:\r\n break\r\nprint(total)\r\n", "a,b = map(int,input().split())\r\nl = sorted(list(map(int,input().split())))\r\nans = 0\r\nfor i in range(b):\r\n if l[i]>0:\r\n break\r\n else:\r\n ans-= l[i]\r\n\r\nprint(ans)\r\n ", "n,m=map(int,input().split())\nl=list(map(int,input().split()))\nl.sort()\ni=0\nans=0\nwhile i<m and l[i]<0:\n\tans+=l[i]\n\ti+=1\nprint (ans*-1)", "n,m=map(int,input().split())\r\n\r\narr=list(map(int,input().split()))\r\n\r\narr.sort()\r\n\r\narr=arr[::-1]\r\n\r\nans=0\r\n\r\nfor i in range(n-m,len(arr)):\r\n if arr[i]>0:continue\r\n else:ans+=abs(arr[i])\r\nprint(ans)", "def sol(n,m,a):\r\n a = sorted(a)\r\n j=0\r\n ans = 0\r\n while m>0 and j<n:\r\n if a[j]<0:\r\n ans+=a[j]\r\n m-=1 \r\n j+=1 \r\n else:\r\n j+=1 \r\n return abs(ans) \r\n \r\nk =[int(x) for x in input().split()]\r\nn,m = k[0],k[1]\r\na = [int(x) for x in input().split()]\r\n\r\nres = sol(n,m,a)\r\nprint(res)", "def solve():\r\n n, m = map(int, input().split())\r\n list_of_tv = list(map(int, input().split()))\r\n sum_val = 0 # resulting sum value, starting with zero\r\n\r\n list_of_tv.sort() # sorting the tv list to easily find out the negative values\r\n for i in range(m): # loop through the tv list and add negative tv in account\r\n if list_of_tv[i] < 0: # add negative tv cost to our account\r\n sum_val += abs(list_of_tv[i]) # add cost's absolute value to sum\r\n else: # if we have crossed all negative values, break the loop. As all the upcoming values won't be useful\r\n break\r\n \r\n print(sum_val)\r\n\r\nsolve()", "def sale(): \r\n x = list(map(int,input().split()))\r\n y = list(map(int,input().split()))\r\n return sum(sorted([a for a in y if a<0]+[0]*x[1])[:x[1]])\r\n \r\n\r\n\r\n\r\n\r\nprint(abs(sale()))\r\n\r\n", "n, m = list(map(int, input().split()))\r\nprices = list(map(int, input().split()))\r\nprices.append(0)\r\nprices.sort()\r\nind = prices.index(0)\r\nif ind >= m:\r\n print(-1 * sum(prices[:m]))\r\nelse:\r\n print(-1 * sum(prices[:ind]))", "n,m=map(int,input().split())\r\ntv=list(map(int,input().split()))\r\nanswer=0\r\nhev=0\r\nfor i in sorted(tv):\r\n if i<0 and hev<m:\r\n answer+=abs(i)\r\n hev+=1\r\nprint(answer)\r\n\r\n", "n, m = map(int, input().split())\r\nprice = list(map(int, input().split()))\r\nprice = sorted(price)\r\n\r\ntotal = 0\r\nfor i in range(m):\r\n if price[i] <= 0:\r\n total += price[i]\r\nprint(abs(total))\r\n" ]
{"inputs": ["5 3\n-6 0 35 -2 4", "4 2\n7 0 0 -7", "6 6\n756 -611 251 -66 572 -818", "5 5\n976 437 937 788 518", "5 3\n-2 -2 -2 -2 -2", "5 1\n998 997 985 937 998", "2 2\n-742 -187", "3 3\n522 597 384", "4 2\n-215 -620 192 647", "10 6\n557 605 685 231 910 633 130 838 -564 -85", "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "1 1\n0", "1 1\n1", "1 1\n555", "1 1\n-1", "1 1\n-24"], "outputs": ["8", "7", "1495", "0", "6", "0", "929", "0", "835", "649", "10", "0", "19441", "0", "16984", "21743", "81283", "0", "0", "75068", "0", "0", "0", "1", "24"]}
UNKNOWN
PYTHON3
CODEFORCES
841
205ab1b2596b19d0ff35371ea3cf18a1
Mashmokh and Lights
Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turned on turns off. Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed *m* distinct buttons *b*1,<=*b*2,<=...,<=*b**m* (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button *b**i* is actually *b**i*, not *i*. Please, help Mashmokh, print these indices. The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*). It is guaranteed that all lights will be turned off after pushing all buttons. Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off. Sample Input 5 4 4 3 1 2 5 5 5 4 3 2 1 Sample Output 1 1 3 4 4 1 2 3 4 5
[ "def main():\n [n, m] = [int(_) for _ in input().split()]\n buttons = [int(_) for _ in input().split()]\n\n # index = 0\n # while index < len(buttons) - 1:\n # button = buttons[index]\n # buttons = buttons[:(index + 1)] + [buttons[i] for i in range(index + 1, len(buttons)) if buttons[i] < button]\n # index += 1\n\n lights = [0] * (n + 1)\n\n for button in buttons:\n i = button\n while i <= n and lights[i] == 0:\n lights[i] = button\n i += 1\n\n result = ' '.join([str(lights[i]) for i in range(1, n + 1)])\n print(result)\n\n\nif __name__ == '__main__':\n main()\n", "n, m = map(int, input().split())\nb = list(map(int, input().split()))\n\nlights = [0] * n\n\nfor i in range(m):\n for j in range(n):\n if j < b[i] - 1:\n continue\n if lights[j] == 0:\n lights[j] = b[i]\nprint(\" \".join(str(light) for light in lights))\n", "n,m = map(int,input().split())\nq = list(map(int,input().split()))\ne = [0] * n\nfor i in range(0,len(q)):\n j = q[i] - 1\n while (j<len(e)) and (e[j] == 0):\n e[j] = q[i]\n j += 1\nprint(*e)", "n, m = input().split()\nn = int(n)\nm = int(m)\na = input().split()\na = [int(item) for item in a]\nans = [0]*n\nfor i in range(m):\n for j in range(a[i]-1,n):\n if ans[j]==0:\n ans[j] = a[i]\nfor i in range(n):\n print(ans[i],end = ' ')\n \n", "n, m = map(int, input().split())\r\nb, a = list(map(int, input().split())), [0] * n\r\nfor x in b:\r\n for i in range(x - 1, n):\r\n if a[i] == 0: a[i] = x\r\nprint(*a)", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nans=[None]*n\r\nfor i in a:\r\n for j in range(i-1,len(ans)):\r\n if ans[j]==None:\r\n ans[j]=i\r\nfor k in ans:\r\n print(k,end=' ') \r\n ", "n, m = (int(x) for x in input().split())\r\nl = [0] * n\r\nfor b in (int(x) for x in input().split()):\r\n for i in range(b - 1, n):\r\n if l[i] == 0:\r\n l[i] = b\r\nprint(' '.join(map(str, l)))", "n, m = map(int, input().split())\r\nbtns = list(map(int, input().split()))\r\narr = [0] * n\r\nfor i in range(m):\r\n temp = btns[i]\r\n for j in range(temp - 1, n):\r\n temp2 = arr[j]\r\n if(temp2 == 0):\r\n arr[j] = temp\r\n else:\r\n break\r\nprint(*arr)", "n, m = map(int, input().split())\r\nl = [int(i) for i in input().split()]\r\n\r\nm = [i for i in range(1, n+1)]\r\n\r\nfor i in l:\r\n\t\tfor j in range(i-1, n):\r\n\t\t \tm[j] = i\r\n\t\t \tn = i-1\r\nprint(*m)", "class CodeforcesTask415ASolution:\n def __init__(self):\n self.result = ''\n self.n_m = []\n self.buttons = []\n\n def read_input(self):\n self.n_m = [int(x) for x in input().split(\" \")]\n self.buttons = [int(x) for x in input().split(\" \")]\n\n def process_task(self):\n off_by = [0 for x in range(self.n_m[0])]\n for button in self.buttons:\n for y in range(button - 1, self.n_m[0]):\n if not off_by[y]:\n off_by[y] = button\n self.result = \" \".join([str(x) for x in off_by])\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask415ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "s = [int(i) for i in input().split(' ')]\r\nN = int(s[0])\r\nM = int(s[1])\r\nbutton = [int(i) for i in input().split(' ')]\r\nA = [0 for i in range(N)]\r\n\r\nfor i in range(N):\r\n for j in range(M):\r\n if button[j] <= i+1:\r\n A[i] = button[j]\r\n break\r\nprint(*A, sep=' ')\r\n\r\n\r\n\r\n\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\narr=[]\r\nfor i in l:\r\n arr.append(i)\r\nll=[0]*n\r\nfor i in arr:\r\n for j in range(i-1,n):\r\n if ll[j]==0:\r\n ll[j]=i\r\nprint(*ll)", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\ntrace = [0] * (n + 1)\r\n\r\nfor v in arr:\r\n idx = v\r\n while idx <= n and trace[idx] == 0:\r\n trace[idx] = v\r\n idx += 1\r\nprint(*trace[1:])", "x,y=map(int,input().split())\r\np=list(map(int,(input().split())))\r\nk=[0 for i in range(1,x+1)]\r\nfor i in p:\r\n for j in range(i,x+1):\r\n if k[j-1]==0:k[j-1]=i\r\n else:break\r\nfor i in k:\r\n print(i,end=\" \")\r\n ", "n, m = map(int, input().split())\r\nt, p = [m] * n, list(map(int, input().split()))\r\nfor i, j in enumerate(p):\r\n if t[j - 1] == m: t[j - 1] = i\r\nfor i in range(n - 1): t[i + 1] = min(t[i], t[i + 1])\r\nfor i in range(n): t[i] = p[t[i]]\r\nprint(' '.join(map(str, t)))", "import sys\r\nimport math\r\n\r\nn, m = [int(x) for x in (sys.stdin.readline()).split()]\r\nb = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nres = []\r\n\r\nv = n\r\nfor k in b:\r\n while(v >= k):\r\n res.append(str(k))\r\n v -= 1\r\n \r\nprint(\" \".join(res[::-1]))", "import sys\n\nn, m = map(int, sys.stdin.readline().split())\n\nbuttons = map(int, sys.stdin.readline().split())\n\nlights = [-1 for i in range(n)]\n\nfor b in buttons:\n for bi in range(b-1, n):\n if lights[bi] < 0:\n lights[bi] = b\n\nprint(' '.join( map(str, lights)))", "n, m = map(int, input().split())\r\nb = [int(i) for i in input().split()]\r\nres = [0] * n\r\n\r\nfor i in b:\r\n for j in range(i - 1, n):\r\n if not(res[j]):\r\n res[j] = i\r\n\r\nprint(*res)\r\n", "n,m=map(int,input().split())\r\nA=list(map(int,input().split()))\r\nB=[0]*(n)\r\nx=n\r\nfor i in range(m):\r\n for j in range(A[i]-1,x):\r\n B[j]=A[i]\r\n if x>=A[i]:\r\n x=A[i]-1\r\nprint(*B)", "n,m = map(int, input() .split())\r\nx= list(map(int, input() .split()))\r\ny = [0]*n\r\nfor i in range (m):\r\n c = x[i]\r\n while x[i] <= n:\r\n b = x[i] - 1 \r\n if y[b] != 0 :\r\n break\r\n else: \r\n y[b] = c\r\n b+=1\r\n x[i]+=1\r\n\r\nfor j in range(n):\r\n print(y[j],end= ' ')", "def cal(a,i,n):\r\n for j in range(i-1,n):\r\n if a[j]==-1:\r\n a[j]=i\r\nn,m=map(int,input().split())\r\nl = [*map(int,input().split())]\r\na = [-1]*n\r\nfor i in l:\r\n cal(a,i,n)\r\nprint(*a)", "import sys\n\nn, m = map(int, sys.stdin.readline().split())\nan = list(map(int, sys.stdin.readline().split()))\n\nans = [0] * n\nfor i in an:\n for j in range(i-1, n):\n if ans[j] == 0:\n ans[j] = i\n\nprint(' '.join(map(str, ans)))\n", "N , M = [int(i) for i in input().split()]\r\nA = [int(i) for i in input().split()]\r\nA0 = [0]*N\r\nfor i in A:\r\n for j in range(i-1,len(A0)):\r\n if A0[j] == 0:\r\n A0[j] = i\r\nfor x in A0:\r\n print(x,end=\" \")", "n,m=map(int,input().split())\r\narr=[int(i) for i in input().split()]\r\nl=[int(0) for i in range(n)]\r\nfor i in arr:\r\n for j in range(i-1,len(l)):\r\n if l[j]==0:\r\n l[j]=i\r\nprint(*l)", "n,m = map(int,input().split())\r\narr = list(map(int,input().split()))\r\nli = [0]*n\r\nans= []\r\nfor i in arr:\r\n for j in range(i-1,n):\r\n if not li[j]:\r\n li[j] = 1\r\n ans.insert(0,i)\r\nprint(*ans)\r\n ", "n, m = map(int, input().split())\r\n\r\ndicti = {}\r\n\r\nfor x in range(n):\r\n dicti[x+1] = \"on\"\r\n\r\nopers = [int(bruh) for bruh in input().split()]\r\n\r\nfor oper in opers:\r\n for light in range(oper, n+1):\r\n if dicti[light] == \"on\":\r\n dicti[light] = oper\r\n\r\nlst = []\r\nfor bruhh in range(1, n+1):\r\n lst.append(str(dicti[bruhh]))\r\n\r\nprint(' '.join(lst))\r\n\r\n", "n, m = map(int, input().split())\r\n\r\ndaf = list(map(int, input().split()))\r\ndaf = daf[::-1]\r\n\r\nhas = dict()\r\n\r\nfor i in range(n):\r\n has[i+1] = 0\r\n\r\nfor i in range(m):\r\n x = daf[i]\r\n for j in range(x, n+1):\r\n has[j] = x\r\n\r\nfor i in has.keys():\r\n print(has[i], end = ' ')\r\n\r\nprint()\r\n", "n,m=map(int,input().split())\r\na= list(map(int, input().split()))\r\nb=[0]*n\r\nfor i in range(m):\r\n c=a[i]\r\n for j in range(c-1,n):\r\n if b[j]==0:b[j]=str(c)+' '\r\ndef list_to_str(a):\r\n y=''\r\n for i in range(len(a)):y=y+str(a[i])\r\n return y\r\nprint(list_to_str(b))\r\n", "n, m = [int(i) for i in input().split(' ')]\n\narr = [-1]*n\n\nb = [int(i) for i in input().split(' ')]\n\nfor i in b:\n for j in range(i-1, n):\n if arr[j] == -1:\n arr[j] = i\n\nprint(' '.join([str(i) for i in arr]))\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nw = list(map(int, input().split()))\r\nd = [0]*n\r\nfor i in range(m):\r\n for j in range(w[i]-1, n):\r\n if d[j] != 0:\r\n break\r\n else:\r\n d[j] += w[i]\r\n if w[i] == 1:\r\n break\r\nprint(*d)", "n,m=list(map(int,input().split()))\r\nb=list(map(int,input().split()))\r\nx=[]\r\nc=n\r\nfor i in range(0,n):\r\n x.append(0)\r\nfor i in range(0,m):\r\n for j in range(b[i]-1,n):\r\n x[j]=b[i]\r\n n=b[i]-1\r\nfor i in range(0,c):\r\n print(x[i],end=' ')\r\n", "n, m=map(int, input().split())\r\nb=list(map(int, input().split()))\r\nans=[-1]*101\r\nfor bb in b:\r\n for i in range(bb, n+1):\r\n if ans[i]==-1:\r\n ans[i]=bb\r\nprint(*ans[1:n+1])", "def main_function():\r\n n, m = [int(i) for i in input().split(\" \")]\r\n b = [int(i) for i in input().split(\" \")]\r\n a = [0 for i in range(n + 1)]\r\n for i in range(len(b)):\r\n for j in range(b[i], len(a)):\r\n if a[j] == 0:\r\n a[j] = b[i]\r\n return \" \".join([str(i) for i in a[1:]])\r\n\r\n\r\n\r\n\r\nprint(main_function())\r\n", "n, m = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nr = [0] * n\r\n\r\nfor j in a:\r\n for i in range(j-1, n):\r\n if r[i] == 0:\r\n r[i] = str(j)\r\n\r\nprint(' '.join(r))", "import string\r\nn,m = [int(x) for x in input().split()]\r\nb = [int(x) for x in input().split()]\r\nl = [0]*n\r\nfor i in b:\r\n for j in range(i-1,n):\r\n if l[j] == 0:\r\n l[j] = i\r\nfor i in l:\r\n print(i,end='')\r\n print(end=' ')\r\n \r\n", "import sys\n\n\n\n\n\n[n,m] = map(int, sys.stdin.readline().split())\n\n\nlamps = [0 for x in range(n+1)]\n\nbuttons = map(int, sys.stdin.readline().split())\n\nfor b in buttons:\n\tfor i in range(b, n+1):\n\t\tif not lamps[i]:\n\t\t\tlamps[i] = b\n\nprint(\" \".join(map(str, lamps[1:])))\n\n\n\n\n\n\n\n\n\n\n\n", "n,m=map(int,input().split())\nbuttons_pressed=list(map(int,input().split()))\nfor i in range(1,n+1):\n for button in buttons_pressed:\n if button<=i:\n print(button,end=' ')\n break\n \t \t \t \t\t \t\t\t \t \t\t \t \t", "\r\nl1 = list(map(int, input().split()))\r\nl2 = list(map(int, input().split()))\r\n\r\n\r\nl3 = [0] * l1[0]\r\nl4 = [0] * l1[0]\r\n\r\n\r\nfor i in l2:\r\n\tfor j in range(i -1, l1[0] ):\r\n\t\tif l3[j] == 0:\r\n\t\t\tl3[j] = 1\r\n\t\t\tl4[j] = i\r\n\r\n\r\n\r\n\r\nprint(*l4,sep = ' ')\r\n\r\n\r\n", "n,m=map(int,input().split())\nb=list(map(int,input().split()))\na=[]\nupper=n+1\nfor i in range(n):\n\ta.append(0)\nfor i in b:\n\tif i<=upper:\n\t\tfor j in range(i-1,upper-1):\n\t\t\ta[j]=i\n\t\tupper=i\nfor i in a:\n\tprint(i, end =\" \") ", "import sys\r\nimport math\r\nimport bisect\r\nimport itertools\r\nimport random\r\n\r\n\r\ndef main():\r\n n, m = map(int, input().split())\r\n A = [-1] * n\r\n B = list(map(int, input().split()))\r\n for i in range(m):\r\n b = B[i]\r\n for j in range(b - 1, n):\r\n if A[j] == -1:\r\n A[j] = b - 1\r\n print(' '.join(list(str(a + 1) for a in A)))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n,k=map(int, input().split())\r\nlights=[0 for i in range(n)]\r\n\r\nswitch=list(map(int, input().split()))\r\n\r\nfor j in range(k):\r\n for k in range(switch[j]-1,n):\r\n if lights[k]==0:\r\n lights[k]=switch[j]\r\n\r\nprint(*lights)\r\n\r\n", "n,m = map(int,input().split())\r\nl=list(map(int,input().split()))\r\n\r\ns=[i+1 for i in range(n)]\r\n\r\nfor i in range(m):\r\n for j in range(len(s)):\r\n if(s[j]>=0 and s[j]>=l[i]):\r\n s[j]=-(l[i])\r\n\r\nfor i in s:\r\n print(abs(i),end=\" \")\r\n ", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\n\r\nans=[-1]*n\r\nfor i in l:\r\n cur=-1\r\n for j in range(n-i+1):\r\n if ans[cur]==-1:\r\n ans[cur]=i\r\n cur-=1\r\nprint(*ans)", "a,b = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nk = b+1\r\nfor i in range(a):\r\n\tfor j in range(b):\r\n\t\tif l[j] <= i+1:\r\n\t\t\tprint(l[j],end=\" \")\r\n\t\t\tbreak", "n, m = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nb = [i for i in range(0, n+1)]\r\nans = []\r\nfor i in range(len(a)):\r\n temp = 0\r\n idx = a[i]\r\n for j in range(a[i], len(b), 1):\r\n if (b[j] != 0):\r\n# print(b)\r\n b[j] = 0\r\n temp += 1\r\n else:\r\n break\r\n for j in range(temp):\r\n ans.append(idx)\r\nprint(*sorted(ans))", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nd=[]\r\nfor i in range(1,n+1):\r\n for j in l:\r\n if(j<=i):\r\n d.append(j)\r\n break\r\nprint(*d)\r\n", "\r\nn, m = map(int, input().split(\" \"))\r\n\r\nb = list(map(int, input().split(\" \")))\r\n\r\na = [-1] * n\r\n\r\nfor i in b:\r\n for j in range(i - 1, n):\r\n if a[j] == -1:\r\n a[j] = i\r\n \r\nprint(\" \".join(map(str, a)))\r\n", "n,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nans=[0]*n\r\nfor i in range(m):\r\n b=a[i]-1\r\n j=b\r\n while j<n and ans[j]==0:\r\n ans[j]=b+1\r\n j+=1\r\nprint(*ans)", "n,m = [int(x) for x in input().split()]\r\narr = [int(x) for x in input().split()]\r\n\r\nv = [0]*n\r\nfor i in arr:\r\n for j in range(i-1,n):\r\n if(v[j] == 0):\r\n v[j] = i\r\n else:\r\n break\r\nfor i in v:\r\n print(i,end=' ')", "def lampochki(n, lst):\r\n result = [0] * n\r\n for elem in lst:\r\n for i in range(elem - 1, n):\r\n if result[i] == 0:\r\n result[i] = elem\r\n return result\r\n\r\n\r\nN, M = [int(j) for j in input().split()]\r\na = [int(x) for x in input().split()]\r\nprint(*lampochki(N, a))\r\n", "n,m=map(int,input().split())\r\nb=list(map(int,input().split()))\r\na=[0]*(n+1)\r\nminb = n+1\r\nfor x in b:\r\n if x<minb:\r\n minb = x\r\n a[x] = x\r\nv = a[1]\r\nfor i in range(2,n+1):\r\n if a[i]==0:\r\n a[i]=v\r\n else:\r\n v=a[i]\r\nprint(' '.join(map(str,a[1:])))\r\n", "from sys import stdin, stdout\r\nn , b = map(int,stdin.readline().split())\r\nans = [0 for _ in range(n)]\r\ninp = list(map(int,stdin.readline().split()))\r\nfor i in inp:\r\n j=i-1\r\n while j<n:\r\n if ans[j] == 0:\r\n ans[j] = i\r\n j+=1\r\nfor i in ans:\r\n stdout.write(str(i)+' ')\r\n", "n, m = map(int, input().split())\r\nbuttons = list(map(int, input().split()))\r\nlights = [0] * n\r\nfor i, button in enumerate(buttons):\r\n for j in range(button - 1, n):\r\n if lights[j] == 0:\r\n lights[j] = button\r\nprint(*lights)\r\n", "from collections import *\r\nn,k = list(map(int,input().split()))\r\na = list(map(int,input().split()))\r\nans = [0 for i in range(n+1)]\r\nm = n+1\r\nfor i in range(k):\r\n\tif(a[i] >= m):\r\n\t\tcontinue\r\n\tfor j in range(a[i],m):\r\n\t\tans[j] = a[i]\r\n\tm = a[i]\r\nfor i in ans[1:]:\r\n\tprint(i,end = \" \")\r\nprint()\r\n", "n , m = map(int , input().split())\r\nl = [0 for i in range(n+1)]\r\nfor i in list(map(int , input().split())):\r\n for j in range(i ,n+1):\r\n if l[j] ==0 :\r\n l[j] = i\r\nprint(*l[1:n+1])", "n, m = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = [a[0]] * (n - a[0] + 1)\r\nfor i in a[1:]:\r\n if i < ans[0]:\r\n ans = [i] * (n - len(ans) - i + 1) + ans\r\nprint(*ans)", "n, m = map(int,input().split())\r\nb = list(map(int,input().split()))\r\na = [0] *(n+1)\r\nfor i in b:\r\n j = i\r\n while j <= n:\r\n if a[j] == 0:\r\n a[j] = i\r\n j += 1\r\n\r\nfor i in range(1,n+1):\r\n print(a[i], end = ' ')", "n,m=map(int,input().split())\r\na=[int(i) for i in input().split()]\r\nb=[0]*n\r\nfor i in a:\r\n for j in range(i-1,n):\r\n if(b[j]==0):\r\n b[j]=i\r\n else:\r\n break\r\nfor i in b:\r\n print(i,end=' ')", "def inp():\r\n return map(int, input().split())\r\n\r\n\r\ndef arr_inp(n):\r\n return [int(x) for x in input().split()]\r\n\r\n\r\ndef print_arr(arr):\r\n print(*arr, sep=' ')\r\n\r\n\r\nn, m = inp()\r\nb = arr_inp(m)\r\nout = [0 for i in range(n)]\r\n\r\nfor i in range(m):\r\n if (out[b[i] - 1] == 0):\r\n out[b[i] - 1] = b[i]\r\n for j in range(b[i], n):\r\n if (out[j] == 0):\r\n out[j] = b[i]\r\n else:\r\n break\r\nprint_arr(out)", "\n\nif __name__== \"__main__\":\n\n\tdata = input().split(\" \")\n\tnumber_ligths = int( data[0] )\n\tligths_off_finger = int( data[1] )\n\n\tlista = []\n\tlista_off = [-1 for it in range(number_ligths)]\n\tdata_off = input().split(\" \")\n\n\tfor it in data_off:\n\t\tlista.append( int(it) )\n\n\tfor interruptor in lista:\n\t\tfor i in range(interruptor-1, len(lista_off)):\n\t\t\tif lista_off[i] != -1:\n\t\t\t\tcontinue\n\n\t\t\tlista_off[i] = interruptor\n\n\toutput = ''\n\tfor i in range( len( lista_off ) ):\n\t\toutput += str( lista_off[ i ] )\n\n\t\tif i != len( lista_off ) - 1:\n\t\t\toutput+= ' '\n\n\tprint( output )\n\n\n\t\t\t\t \t\t \t\t \t\t \t\t \t \t", "n, m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nres = [0] * (n + 1)\r\nfor num in arr :\r\n for i in range(num, n + 1) :\r\n if res[i] == 0 :\r\n res[i] = num\r\nprint(*(res[1 : ]))\r\n \r\n \r\n \r\n ", "if __name__ == '__main__':\r\n n, m = str(input()).split()\r\n n = int(n)\r\n m = int(m)\r\n line = str(input()).split()\r\n line = [int(it) for it in line]\r\n note = [0 for it in range(n)]\r\n for it in line:\r\n for i in range(it - 1, n):\r\n if note[i] == 0:\r\n note[i] = it\r\n note = [str(it) for it in note]\r\n print(' '.join(note))\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nemp=[]\r\nim=[]\r\nfor i in l:\r\n for j in range(i,n+1):\r\n if j not in emp:\r\n emp.append(j)\r\n im.append((j,i))\r\n\r\nim.sort() \r\nfor ele in im:\r\n print(ele[1],end=' ')", "n,m = input().split()\r\nn,m = int(n),int(m)\r\nl = [int(a) for a in input().split(\" \",n-1)]\r\nb=l[0]\r\nl1=[str(str(l[0])+' ')*(n-l[0]+1)]\r\nfor i in range(1,len(l)):\r\n if l[i]<b:\r\n l1.append(str(str(l[i])+' ')*(b-l[i]))\r\n b=l[i]\r\nl1=l1[::-1]\r\ns=''.join(map(str,l1))\r\nprint(s)\r\n \r\n ", "\r\nx,y = map(int,input().split())\r\nz=[int(x) for x in input().split()]\r\nx=x+1\r\nfor i in range(1,x):\r\n for m in range(y):\r\n if (i >= z[m]):\r\n print(z[m],end=\" \")\r\n break\r\n\r\n continue\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n, m = map(int, input().split())\r\nnums = list(map(int, input().split()))\r\nturnedOff = [0 for i in range(n)]\r\nfor i in nums:\r\n for l in range(i-1, n):\r\n if(turnedOff[l]== 0):\r\n turnedOff[l] = int(i)\r\nprint(' '.join(map(str, turnedOff)))\r\n", "# https://codeforces.com/contest/415/problem/A\r\n\r\nn, m = map(int, input().split())\r\n\r\nlights = [None] * n\r\n\r\npushed_buttons = tuple(map(int, input().split()))\r\n\r\nfor i in pushed_buttons:\r\n\r\n temp = i - 1\r\n while temp < n and lights[temp] is None:\r\n lights[temp] = i\r\n temp += 1\r\n\r\nprint(*lights)\r\n", "n,m=map(int,input().split())\r\nb=[int(x) for x in input().split()]\r\nl=[0]*(n+1)\r\nfor i in b:\r\n for j in range(i,n+1):\r\n if l[j]==0:\r\n l[j]=i\r\nfor i in range(1,n+1):\r\n print(l[i],end=\" \")", "n, m = [int(x) for x in input().split()]\r\nb = [int(x) for x in input().split()]\r\na = [0] * n\r\nfor i in b:\r\n for j in range(i-1, n): \r\n if a[j] == 0: a[j] = str(i)\r\nprint(*a) \r\n", "i=lambda:map(int,input().split())\r\nn,m=i()\r\nn+=1\r\na=[n]*n\r\nfor x in i():\r\n if x<n:\r\n a[x:n]=[x]*(n-x)\r\n n=x\r\nprint(*a[1:])", "n,m = map(int,input().split())\nans = [0 for i in range(n)]\nclicks = list(map(int,input().split()))\nfor click in clicks:\n for i in range(click-1,n,1):\n if ans[i] != 0 :\n break\n ans[i] = click\n[print(i,end=\" \") for i in ans]\nprint()", "a,b=map(int,input().split());c=[0]*a\r\nfor i in map(int,input().split()):c[i-1:a]=[i]*(a-i+1);a=min(i-1,a)\r\nprint(*c)", "n, m = map(int, input().split())\r\nl_p = list(map(int, input().split()))\r\n\r\nx = [0] * (n + 1)\r\n\r\nfor b in l_p:\r\n for i in range(b, n + 1):\r\n if x[i] == 0:\r\n x[i] = b\r\n else:\r\n break\r\nprint(\" \".join(str(x) for x in x[1:]))", "def main():\r\n N, M = map(int, input().split())\r\n bottoms = list(map(int, input().split()))\r\n lamps = [[0] * N][0]\r\n for i in range(M):\r\n for j in range(bottoms[i] - 1, N):\r\n if lamps[j] == 0:\r\n lamps[j] = bottoms[i]\r\n print(' '.join(map(str, lamps)))\r\n \r\nmain()", "# -*- coding: utf-8 -*-\nimport math\nimport random\nimport time\n\n# argv = sys.argv\n# argc = len(argv)\n\n\nif __name__ == '__main__':\n room = input().split(' ')\n b = input().split(' ')\n res = [0 for i in range(int(room[0]))]\n\n for i in range(int(room[1])):\n for num in range(int(b[i])-1,int(room[0])):\n if res[num] == 0:\n res[num] = int(b[i])\n\n for i in range(len(res)):\n print(repr(res[i]) + ' ', end=\"\")\n", "n, m = map(int, input().split())\r\nc = [int(i) for i in input().split()]\r\nclosed = [False] * n\r\nans = [0] * n\r\nfor i in c:\r\n if closed[0]:\r\n break\r\n for j in range(i-1, n):\r\n if not closed[j]:\r\n closed[j] = True\r\n ans[j] = i\r\n else:\r\n continue\r\nprint(' '.join(str(i) for i in ans))\r\n", "s1 = input()\r\ns = s1.split()\r\nn = int(s[0])\r\nm = int(s[1])\r\nb1 = input()\r\nb = b1.split()\r\na=[]\r\nfor i in range(n):\r\n a.append(\"0\")\r\nfor i in range(m):\r\n x = int(b[i])\r\n for j in range(x-1,n):\r\n if(a[j]==\"0\"):\r\n a[j]=b[i]\r\nfor i in range(n):\r\n print(a[i],end=\" \")\r\n", "from sys import stdin\r\n\r\n__author__ = 'artyom'\r\n\r\n\r\ndef read_next_line():\r\n return list(map(int, stdin.readline().strip().split()))\r\n\r\n\r\nn, m = read_next_line()\r\nindices = [-1] * n\r\nfor b in read_next_line():\r\n i = b - 1\r\n while i < n and indices[i] == -1:\r\n indices[i] = b\r\n i += 1\r\n if b == 1:\r\n break\r\n\r\nprint(' '.join(map(str, indices)))", "n,m=list([int(i) for i in input().split()])\r\npushed=list(map(int,input().split()))\r\narr=[]\r\nfor i in range(1,n+1):\r\n for j in pushed:\r\n if j<=i:\r\n arr.append(str(j))\r\n break\r\nprint(\" \".join(arr))", "n, m = (int(i) for i in input().split())\nb = (int(i) for i in input().split())\nres, last = [None] * n, n\nfor i, v in enumerate(b):\n for j in range(v - 1, last):\n res[j] = v\n last = min(last, v - 1)\nprint(*res)\n", "n , m = map(int,input().split())\r\n\r\nbuttons = list(map(int,input().split()))\r\n\r\nlights=[0]*(n+1)\r\n\r\nfor i in buttons :\r\n for j in range(i,len(lights)):\r\n if lights[j] == 0:\r\n lights[j] = i\r\n\r\nfor i in range(1,len(lights)):\r\n print(lights[i],end=\" \")\r\n", "(n, m) = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n\r\nl = [0 for i in range(n)]\r\n\r\nfor b in a:\r\n for i in range(b-1, len(l)):\r\n if l[i] == 0:\r\n l[i] = b\r\n\r\nprint(' '.join(map(str, l)))", "n,m=list(map(int,input().split()))\r\nnums=list(map(int,input().split()))\r\na,x=[],n\r\nfor i in nums:\r\n if i<=x:\r\n a=[i]*(x-i+1)+a\r\n x=i-1\r\nprint(*a)\r\n", "import time\r\nimport io\r\nimport math\r\nimport random\r\n\r\ndef timer(f):\r\n def tmp(*args, **kwargs):\r\n t = time.time()\r\n res = f(*args, **kwargs)\r\n print (\"Time : %f\" % (time.time()-t))\r\n return res\r\n\r\n return tmp\r\n\r\n\r\n\r\nddd = input().split(' ')\r\nn = int(ddd[0])\r\nm = int(ddd[1])\r\n\r\nddd = input().split(' ')\r\narray = []\r\nfor i in range(len(ddd)):\r\n array.append(int(ddd[i]))\r\n\r\nres = []\r\nfor i in range(n):\r\n for j in range(m):\r\n if array[j] > i+1:\r\n pass\r\n else:\r\n res.append(array[j])\r\n break\r\n\r\nsss = \"\"\r\nfor i in range(len(res)):\r\n sss = sss + str(res[i])+\" \"\r\n\r\nprint(sss)", "n,m=map(int,input().split())\r\nlst=[0]*n\r\nfor i in input().split(): \r\n i=int(i)\r\n if lst[i-1]==0:\r\n for j in range(i-1,n):\r\n if lst[j]==0:\r\n lst[j]=i\r\n else:\r\n break\r\nprint(*lst) \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "def solve(arr,n,m):\n res = [-1]*n\n for i in arr:\n for j in range(i-1,n):\n if res[j] == -1 :\n res[j] = i\n return res\ndef main() :\n n,m = list(map(int, input().split(' ')))\n arr = list(map(int, input().split(' ')))\n print(*solve(arr,n,m))\nmain()\n", "n,m=map(int, input().split())\r\narr=list(map(int, input().split()))\r\nans=[-1]*101\r\nfor i in arr:\r\n for j in range(i, n+1):\r\n if ans[j]==-1:\r\n ans[j]=i\r\nprint (*ans[1:n+1])", "n, m = list(map(int, input().split()))\r\nb_list = list(map(int, input().split()))\r\nres = [0] * n\r\n\r\nfor b in b_list:\r\n for i in range(b-1, n):\r\n if res[i] == 0:\r\n res[i] = str(b)\r\n\r\nprint(' '.join(res))", "def main():\r\n n, m = map(int, input().split())\r\n seq = list(map(int, input().split()))\r\n\r\n ans = {}\r\n for e in seq:\r\n for i in range(e, n+1):\r\n if i not in ans:\r\n ans[i] = e\r\n\r\n out = []\r\n for i in range(1, n+1):\r\n out.append(ans[i])\r\n\r\n print(*out)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nz=[]\r\nfor i in range(1,n+1):\r\n\tfor j in l:\r\n\t\tif j<=i:\r\n\t\t\tz.append(j)\r\n\t\t\tbreak\r\nprint(*z)\r\n", "n,m=[int(i) for i in input().split()]\r\nb=[int(i) for i in input().split()]\r\nv=[-1]*n\r\nfor i in range(m):\r\n z=b[i]-1\r\n for j in range(z,n):\r\n if v[j]==-1:\r\n v[j]=z+1\r\nfor i in v:\r\n print(i,end=' ')\r\n", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\ndata = list(map(int, input().split()))\r\n\r\nchk = [-1] * n\r\n\r\nmv = n\r\nfor i in range(m):\r\n for j in range(data[i] - 1, mv):\r\n if chk[j] == -1:\r\n chk[j] = data[i]\r\n\r\n mv = min(data[i], mv)\r\n\r\nprint(*chk)", "n,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nr=[i+1 for i in range(n)]\r\ni=n-1\r\nj=0\r\nwhile(i>-1):\r\n if r[i]>=l[j]:\r\n r[i]=l[j]\r\n i-=1\r\n else:\r\n j+=1\r\nfor i in r:\r\n print(i,end=' ') \r\n ", "[n, m] = map(int, input().split())\r\nlamps = [0] * n\r\nfor x in map(int, input().split()):\r\n i = x - 1\r\n while i < n and not lamps[i]:\r\n lamps[i] = x\r\n i += 1\r\nprint(*lamps)\r\n", "n,m=map(int,input().split())\r\narr=list(map(int,input().strip().split()))[:n]\r\na=[0]*n\r\nfor i in range(0,m):\r\n if arr[m-i-1]<=n:\r\n for j in range(0,n-arr[m-i-1]+1):\r\n a[j]=arr[m-i-1]\r\na.reverse()\r\nprint(*a,sep=\" \")", "f=lambda:map(int,input().split())\r\nn,m=f()\r\nb=list(f())\r\nl=list(range(n,0,-1))\r\nv=[]\r\nj=0\r\nfor i in b:\r\n while j<n and l[j]>=i:\r\n v.append(i)\r\n j+=1\r\n[print(i ,end=' ') for i in v[::-1]]", "n, m = map(int, input().split())\nb = list(map(int, input().split()))\nv = [0] * (n + 1)\nfor i in b:\n for x in range(i, n + 1):\n if v[x] != 0:\n break\n v[x] = i\nprint(*v[1:])\n", "n, m = map(int, input().split())\r\na, l = list(map(int, input().split())), [0] * n\r\nfor b in a:\r\n for i in range(b - 1, len(l)):\r\n if l[i] is 0:\r\n l[i] = b\r\nprint(' '.join(map(str, l)))\r\n", "n, m = map(int, input().split())\r\nb = list(map(int, input().split()))\r\nans = [0] * (n + 1)\r\nfor x in b:\r\n for i in range(x, n + 1):\r\n if ans[i] == 0:\r\n ans[i] = x\r\nprint(*ans[1:])", "n,m = map(int,input().split())\r\n\r\nL = [-1] * n\r\n\r\nA = list(map(int,input().split()))\r\n\r\nfor a in A:\r\n for i in range(a - 1, len(L)):\r\n if L[i] == -1:\r\n L[i] = a\r\n\r\nfor l in L:\r\n print(l,end= ' ')", "n,m=list(map(int,input().split()))\r\n\r\ny=[0]*n\r\n\r\nt=list(map(int,input().split()))\r\nfor j in t:\r\n for k in range(j-1,len(y)):\r\n if y[k]==0:\r\n y[k]=j\r\n\r\nprint(*y)\r\n \r\n", "n, m = tuple(map(int, input().split()))\nB = list(map(int, input().split()))\n\nlamps = {}\noff = set()\nfor b in B:\n b_off = []\n for l in range(b, n + 1):\n if l not in off:\n b_off.append(l)\n off.add(l)\n for bb in b_off:\n lamps[bb] = b\n\nresult = ''.join(str(lamps[i]) + ' ' for i in range(1, n + 1))\nprint(result)\n", "n, m = map(int, input().split())\r\nb = list(map(int, input().split()))\r\na = [0]*n\r\nfor e in b:\r\n for i in range(e-1, n):\r\n if a[i] == 0:\r\n a[i] = e\r\nprint(' '.join(map(str, a)))", "n, m = map(int, input().split())\r\nb = list(map(int, input().split()))\r\nx = [1] * (n + 1)\r\nans = [0] * (n + 1)\r\nfor i in range(m):\r\n for k in range(b[i], n + 1):\r\n if x[k] == 1:\r\n ans[k] = b[i]\r\n x[k] = 0\r\nprint(*ans[1:])", "n,m = map(int, input().split())\r\nlights = [0]*n\r\nbuttons = list(map(int, input().split()))\r\nfor b in buttons:\r\n b -= 1\r\n for i in range(b,n):\r\n if lights[i] == 0:\r\n lights[i] = b+1\r\n\r\nfor i in lights:\r\n print(i, end=\" \")\r\nprint()\r\n", "n,m=map(int,input().split())\r\nbuttons=list(map(int,input().split()))\r\nlights=[0]*n\r\nfor i in buttons:\r\n for j in range(i-1,len(lights)):\r\n if lights[j]==0:\r\n lights[j]=i\r\nfor i in range(len(lights)):\r\n print(lights[i],end=\" \")", "n, m = map(int, input().split())\nb = list(map(int, input().split()))\na = [0 for i in range(n)]\nfor i in b:\n\tfor j in range(i-1, n):\n\t\tif a[j] == 0:\n\t\t\ta[j] = str(i)\nprint(' '.join(a))\n", "x=input()\r\nl=x.split(' ')\r\narr=[]\r\nfor i in range(1000):\r\n arr.append(0)\r\nn=int(l[0])\r\nm=int(l[1])\r\nt=input()\r\nll=t.split(' ')\r\n# print(ll,n,m)\r\nfor i in range(m):\r\n for j in range(int(ll[i]),n+1):\r\n if(arr[j]==0):\r\n arr[j]=int(ll[i])\r\nfor i in range(1,n+1):\r\n print(arr[i],end=' ')\r\n\r\n\r\n", "n, m = map(int,input().split())\r\nb = list(map(int,input().split()))\r\nans = [-1]*101\r\nfor bb in b:\r\n for i in range(bb,n+1):\r\n if ans[i]==-1:\r\n ans[i]=bb\r\nprint(*ans[1:n+1])", "X = list(map(int, input().split()))\r\nLights = [0 for i in range(X[0])]\r\nButtons = list(map(int, input().split()))\r\nfor i in Buttons:\r\n for j in range(i - 1, len(Lights)):\r\n if Lights[j] == 0:\r\n Lights[j] = i\r\nprint(*Lights)\r\n", "n,m = map(int, input().split())\r\nl = [-1]*(n+1)\r\nx = list(map(int, input().split()))\r\nfor i in range(m):\r\n for j in range(x[i], n+1):\r\n if l[j] != -1:\r\n break\r\n l[j] = str(x[i])\r\nprint(' '.join(l[1:]))\r\n", "n, nb = map(int, input().split())\norder = list(map(int, input().split()))\nl = [-1 for _ in range(n)]\nfor x in order:\n for i in range(x-1,n):\n if l[i]==-1:\n l[i] = x\n else:\n break\nt=\"\"\nfor x in l:\n t+= str(x) + \" \"\nprint(t[:-1])", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nrs = [0]*105\r\nfor item in a:\r\n for i in range(item,n+1):\r\n if rs[i]==0:\r\n rs[i] = item\r\nfor i in range(1,n+1):\r\n print(rs[i])\r\n", "a, b = map(int, input().split())\r\narr = list(map(int, input().split()))\r\n\r\nlst = list(range(1, a+1))\r\n\r\nans = []\r\n\r\nfor i in arr:\r\n while i in lst:\r\n lst.pop()\r\n ans.append(i)\r\n\r\nprint(*ans[::-1])\r\n", "n, m = list(map(int, input().split()))\r\nl = list(map(int, input().split()))\r\ndic = {}\r\nfor i in range(1, n + 1):\r\n dic[i] = False\r\nfor i in l:\r\n for j in range(i, n + 1):\r\n if not dic[j]: # d[j] == False\r\n dic[j] = i\r\nprint(*dic.values())", "n, m = map(int, input().split())\r\n\r\nb = list(map(int, input().split()))\r\n\r\na = [0]*(n+1)\r\n\r\nfor i in b:\r\n for j in range(n, i-1, -1):\r\n if a[j] == 0:\r\n a[j] = i\r\nprint(*a[1:])\r\n", "n, m = map(int, input().split())\r\nl1 = list(map(int, input().split()))\r\nl2 = [0]*n\r\nfor i in range(m):\r\n for j in range(l1[i]-1, n):\r\n if l2[j] == 0:\r\n l2[j] = l1[i]\r\n\r\nfor i in l2:\r\n print(i, end=' ')\r\n\r\n", "# import sys \r\n# sys.stdin=open(\"input.in\",'r')\r\n# sys.stdout=open(\"out.out\",'w')\r\nn,m=map(int,input().split())\r\nb=list(map(int,input().split()))\r\na=[0 for i in range(n)]\r\nfor i in b:\r\n\tfor j in range(i-1,n):\r\n\t\tif a[j]==0:\r\n\t\t\ta[j]=i\r\n\r\nprint(*a)", "n, m = map(int, input().split())\r\nl = [int(i) for i in input().split()]\r\nres = []\r\nfor i in range(m):\r\n for j in range(n - l[i] + 1):\r\n if n == 0:\r\n print(res.reverse())\r\n exit()\r\n res.append(l[i])\r\n n -= 1\r\nres.reverse()\r\nfor i in res:\r\n print(i, end=\" \")", "n, m = map(int, input().split())\r\nclicks = list(map(int, input().split()))\r\nlamps = [-1] * (n + 1)\r\npointer = n + 1\r\nfor i in range(m):\r\n for j in range(clicks[i], pointer):\r\n lamps[j] = clicks[i]\r\n pointer = min(pointer, clicks[i])\r\nlamps = lamps[1:]\r\nprint(*lamps)", "n,m=[int(x) for x in input().split(\" \")]\r\nl=[int(x) for x in input().split(\" \")]\r\nfor i in range(1,n+1):\r\n for x in l:\r\n if x<=i:\r\n print(x,end=\" \")\r\n break", "\r\nimport math\r\nfrom collections import Counter, deque\r\nimport bisect\r\nimport heapq\r\n\r\nn, m = map(int, input().split())\r\nb = list(map(int, input().split()))\r\nans = [0] * n\r\nfor i in range(m) :\r\n j = b[i]\r\n while j - 1 < n and ans[j - 1] == 0 :\r\n ans[j - 1] = b[i]\r\n j += 1\r\nprint(\" \".join(str(k) for k in ans))", "numbers = list(map(int , input().split()))\r\narr = list(map(int , input().split()))\r\ninfo = {}\r\nfor i in range(1 , numbers[0] + 1) :\r\n info[i] = \"none\"\r\nfor i in arr :\r\n for j in range(i , numbers[0] + 1):\r\n if info[j] != 'none' :\r\n break\r\n else :\r\n info[j] = i\r\nfor i in info.keys() :\r\n print(f\"{info[i]} \" , end=\"\")", "n,m = map(int,input().split())\r\nb = list(map(int,input().split()))\r\nchk = [-1]*(n)\r\nans = [-1]*(n)\r\nfor i in b:\r\n for j in range(i,n+1):\r\n if chk[j-1] == -1:\r\n ans[j-1] = i\r\n chk[j-1] = 0\r\nprint(*ans)", "n, m = map(int, input().split())\r\nb = map(int, input().split())\r\nlight = []\r\nsetlight = set()\r\nfor i in b:\r\n if i not in setlight:\r\n for j in range(i, n + 1):\r\n if j not in setlight:\r\n light.append(i)\r\n setlight.add(j)\r\nprint(*sorted(light))\r\n\r\n# CodeForcesian\r\n# ♥\r\n# اگه میتونی تصور کنی پس حتما میتونی انجامش بدی\r\n", "from sys import stdin; inp = stdin.readline\r\nfrom math import dist, ceil, floor, sqrt, log\r\ndef IA(): return list(map(int, inp().split()))\r\ndef FA(): return list(map(float, inp().split()))\r\ndef SA(): return inp().split()\r\ndef I(): return int(inp())\r\ndef F(): return float(inp())\r\ndef S(): return inp()\r\n\r\ndef main():\r\n n, m = IA()\r\n a = IA()\r\n r = [0]*(n+1)\r\n for e in a:\r\n for i in range(e,n+1):\r\n if r[i] == 0:\r\n r[i]=e\r\n print(*r[1:])\r\n\r\nif __name__ == '__main__':\r\n main()", "n,m = list(map(int, input().split()))\r\nl = [0]*(n+1)\r\nkk = list(map(int, input().split()))\r\n\r\nfor i in range(m):\r\n for j in range(kk[i],n+1):\r\n if l[j]==0:\r\n l[j]=kk[i]\r\n \r\nfor i in range(1, n+1):\r\n print(l[i], end=\" \")", "n,m=map(int,input().split())\r\na=[-1 for i in range(n)]\r\nw=list(map(int,input().split()))\r\nfor x in w:\r\n for j in range(x-1,n):\r\n if(a[j]==-1):a[j]=x\r\nprint(*a)\r\n", "n, m = list(map(int, input().split()))\nbts = list(map(int, input().split()))\n\ndone = [0 for x in range(n)]\n\nfor i in bts:\n for j in range(i-1, n):\n if done[j] == 0:\n done[j] = i\n\n[print(x, end=' ') for x in done]\nprint()\n", "'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"Mashmokh and Lights\"\r\n# Class: A\r\n\r\nimport sys\r\n#sys.setrecursionlimit(2147483647)\r\ninput = sys.stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n sys.stdout.write(sep.join(map(str, args)) + end)\r\n\r\ndef Solve():\r\n n, m = list(map(int, input().split()))\r\n b = list(map(int, input().split()))\r\n x = [0]*(n+1)\r\n for i in b:\r\n for o in range(i, n+1):\r\n if not x[o]:\r\n x[o] = i\r\n \r\n print(*x[1:])\r\n\r\n\r\nif __name__ == \"__main__\":\r\n Solve()", "\r\nn, m = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n\r\nans = [0 for i in range(n+1)]\r\n\r\nfor i in a:\r\n for j in range(i,n+1):\r\n if ans[j]==0:\r\n ans[j]=i\r\n\r\nprint(*ans[1:])\r\n", "'''input\n5 5\n5 4 3 2 1\n'''\nn, m = map(int, input().split())\nb = list(map(int, input().split()))\nl = [1] * n\na = []\nfor x in range(m):\n\tfor y in range(n-1, b[x]-2, -1):\n\t\tif l[y] == 1:\n\t\t\ta.append(b[x])\n\t\t\tl[y] -= 1\nprint(\" \".join(map(str, a[::-1])))\n", "__author__ = 'Lipen'\r\n\r\ndef main():\r\n n,m = map(int, input().split())\r\n b = list(map(int, input().split()))\r\n answer = [0]*n\r\n\r\n for x in b:\r\n for w in range(x-1, n):\r\n if answer[w]==0:\r\n answer[w]=x\r\n\r\n s = ''\r\n for x in answer:\r\n s += str(x) + ' '\r\n print(s[:-1])\r\n\r\nmain()", "n,m = tuple(map(int,input().split()))\r\nb = list(map(int,input().split()))\r\na = [0]*n\r\nfor i in b:\r\n for j in range(i-1,n):\r\n if a[j]==0:\r\n a[j]=str(i)\r\nprint(' '.join(a))", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nx=[0 for i in range(n)]\r\nfor i in range(m):\r\n for j in range(l[i]-1,n):\r\n if x[j]==0:\r\n x[j]=l[i]\r\nprint(*x)", "a,b=map(int,input().split())\r\nlist2=[0]*a\r\nlist=list(map(int,(input().split())))\r\nfor i in range(b):\r\n for s in range(a-list[i]+1):\r\n if list2[list[i]+s-1]==0:\r\n list2[list[i]+s-1]=list[i]\r\nresult=''\r\nfor i in range(a):\r\n result=result+str(list2[i])+' '\r\nprint(result)", "n, m = [int(i) for i in input().split()]\r\nlista = [int(i)-1 for i in input().split()]\r\naux = [0] * n\r\n\r\nfor i in range(m):\r\n for j in range(lista[i], n):\r\n if not aux[j]:\r\n aux[j] = lista[i]+1\r\n\r\nprint(*aux)", "n, m = [int(x) for x in input().split(' ')]\r\nb = [int(x) for x in input().split(' ')]\r\nans = [0] * n\r\ni = 0\r\nwhile min(ans) == 0:\r\n j = b[i]\r\n while j <= n and ans[j - 1] == 0:\r\n ans[j - 1] = b[i]\r\n j += 1\r\n i += 1\r\nprint(*ans)", "n, m = map(int, input().split())\r\nar = [0] * n\r\n*b, = map(int, input().split())\r\nfor i in b:\r\n for j in range(i - 1, n):\r\n if ar[j] == 0:\r\n ar[j] = i\r\nprint(*ar)\r\n", "n,m=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nb=[0]*(n+1)\r\nfor i in a:\r\n for j in range(i,n+1):\r\n if b[j]==0:\r\n b[j]=i\r\nfor i in range(1,n+1):\r\n print(b[i],end=' ')", "string = input()\r\nnumbers = string.split()\r\na, b = int(numbers[0]), int(numbers[1])\r\nstring = input()\r\nbuttons = list(map(int, string.split()))\r\nlights = [0 for x in range(a)]\r\nfor x in buttons:\r\n for y in range(x - 1, a):\r\n if lights[y] == 0:\r\n lights[y] = x\r\nprint(\" \".join(map(str, lights)))", "n, m = map(int, input().split())\r\nb = map(int, input().split())\r\n\r\noff = [''] * (n + 1)\r\nfor x in b:\r\n for i in range(x, n + 1):\r\n if not off[i]:\r\n off[i] = x\r\n\r\nprint(' '.join(map(str, off[1:])))", "n, m = list(map(int, input().split()))\r\nl= list(map(int, input().split()))\r\na = [0] * n\r\n\r\nfor j in l:\r\n for i in range(j-1, n):\r\n if a[i] == 0:\r\n a[i] = str(j)\r\n\r\nprint(' '.join(a))", "n, k = map(int, input().split())\r\nbuts = list(map(int, input().split()))\r\n\r\nlamps = list(range(1,n+1))\r\n\r\nres = []\r\nfor but in buts:\r\n if lamps:\r\n res.append((but, lamps[but-1:]))\r\n lamps = lamps[:but-1]\r\n\r\nres.sort()\r\n\r\nfor (bu,lm) in res:\r\n for l in lm:\r\n print(bu,end = ' ')", "def main():\r\n [n, m] = list(map(int, input().split()))\r\n bs = list(map(int, input().split()))\r\n ls = [None for _ in range(n)]\r\n\r\n for b in bs:\r\n for j in range(b - 1, n):\r\n if ls[j] == None:\r\n ls[j] = b\r\n else:\r\n break\r\n\r\n for l in ls:\r\n print(l, end=' ')\r\n print()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n,m=map(int, input().split())\r\nd=list(map(int, input().split()))\r\nans=[-1]*101\r\nfor dd in d :\r\n for i in range(dd, n+1) : \r\n if ans[i]==-1 :\r\n ans[i] = dd\r\nprint(*ans[1:n+1])", "# LUOGU_RID: 101568144\nn, m, *a = map(int, open(0).read().split())\r\nv = [-1] * n\r\nfor x in a:\r\n for i in range(x - 1, n):\r\n if v[i] == -1:\r\n v[i] = x\r\nprint(*v)", "n, m = map(int, input().split())\nbuttons = map(int, input().split())\nlamps = [0] * n\nfor i in buttons:\n l = i-1\n while (l < n) and not lamps[l]:\n lamps[l] = i\n l += 1\nprint(\" \".join(list(map(str, lamps))))\n", "#!/usr/bin/python3 -SOO\nn,m = map(int,input().strip().split())\nb = list(map(int,input().strip().split()))\ns = [0]*n\nfor i in b:\n for j in range(i-1,n):\n if s[j]==0: s[j] = i\nprint(' '.join(map(str,s)))\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl2=list(map(int,list(\"0\"*n)))\r\nfor i in l:\r\n\tfor j in range(i-1,n):\r\n\t\tif l2[j]==0:\r\n\t\t\tl2[j]=i\r\nprint(*l2)", "n,m = map(int,input().split())\r\na = list(map(int,input().split()))\r\nb = [0 for i in range(n)]\r\nfor i in range(m):\r\n for j in range(a[i]-1,n,1):\r\n if b[j] == 0: b[j] = a[i]\r\nprint(*b)", "n,m=map(int,input().split())\r\nx=list(map(int,input().split()))\r\nz=[0]*(n+1)\r\nfor i in x:\r\n j=i\r\n while j<n+1 and z[j]==0:\r\n z[j]=i\r\n j+=1\r\nfor i in range(1,n+1):\r\n print(z[i],end=\" \")", "n, s = map(int,input().split())\r\nps = list(map(int, input().split()))\r\nls = [0 for i in range(n)]\r\nfor q in ps:\r\n if q == 1:\r\n for j in range(len(ls)):\r\n if ls[j]==0:\r\n ls[j]=1\r\n break\r\n else:\r\n for j in range(q-1,len(ls)):\r\n if ls[j]==0:\r\n ls[j] = q\r\nprint(*ls)", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nans=[0]*(n+1)\r\nfor x in l:\r\n for i in range(x,n+1):\r\n if ans[i]==0: ans[i]=x\r\nprint(' '.join(map(str,ans[1:])))", "I = lambda: int(input())\r\nIL = lambda: list(map(int, input().split()))\r\n\r\nn, m = IL()\r\nB = IL()\r\nst = [0]*n\r\nfor b in B:\r\n for j in range(b-1, n):\r\n if st[j] == 0:\r\n st[j] = b\r\nprint(*st)", "from array import *\nfrom itertools import *\n\nn, m = list(map(int, input().split()))\nbs = map(int, input().split())\na = array('i', repeat(0, n))\nfor b in bs:\n for i in range(b-1, n):\n if a[i] != 0:\n break\n a[i] = b\nfor i in a:\n print(i, end=\" \")\n", "n, m = [int(c) for c in input().split()]\r\nturns = [int(c) for c in input().split()]\r\nlamps = [0] * n\r\n\r\nfor i in range(m):\r\n t = turns[i]\r\n it = t - 1\r\n while it < n and lamps[it] == 0:\r\n lamps[it] = t\r\n it += 1\r\n\r\nprint(' '.join(map(str,lamps)))", "\r\nn,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nl1=[0]*n\r\nfor i in range(m):\r\n for j in range(l[i]-1,n):\r\n if(l1[j]==0):\r\n l1[j]=l[i]\r\n\r\nprint(*l1)\r\n\r\n\r\n ", "\r\n\r\nn,m=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nd={}\r\nfor i in range(1,n+1):\r\n d[i]=-1\r\n\r\nfor i in l:\r\n for j in range(i,n+1):\r\n if d[j]==-1:\r\n d[j]=i\r\nprint(*d.values())\r\n", "n,m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nll = [0]*(n+1)\r\nfor i in range(m):\r\n for j in range(l[i],n+1):\r\n if ll[j]==0:\r\n ll[j] = l[i]\r\nprint(*ll[1:])", "n,m=map(int,input().split());a=[n+1]+list(map(int,input().split()));b=[]\r\nfor i in range(1,m+1):\r\n\tif a[i]<min(a[:i]):b=b+(min(a[:i])-a[i])*[a[i]]\r\nprint(*sorted(b))", "s = input().split()\r\nn, m = int(s[0]), int(s[1])\r\nl = ['0']*n\r\nfor bi in input().split():\r\n for li in range(int(bi)-1, n):\r\n if l[li] == '0':\r\n l[li] = bi\r\nprint(' '.join(l))\r\n", "I = lambda: map(int, input().split())\r\n\r\nn, _ = I()\r\nL = [0] * n\r\n\r\nfor b in I():\r\n for i in range(b-1, n):\r\n if L[i]:\r\n break\r\n L[i] = b\r\n\r\nprint(*L)", "# coding: utf-8\nn, m = [int(i) for i in input().split()]\nlights = [0]*(n+1)\nb = [int(i) for i in input().split()]\nfor i in b:\n for j in range(i,n+1):\n if lights[j]==0:\n lights[j] = i\nprint(' '.join([str(i) for i in lights[1:]]))\n", "n , m = map(int,input().split())\r\nl = list(map(int,input().split()))\r\na = []\r\n\r\nfor i in range(1,n+1):\r\n for j in l :\r\n if j <= i :\r\n a.append(j)\r\n break\r\n\r\nprint(*a)\r\n\r\n\r\n\r\n\r\n", "n, m = map(int, input().split())\r\nb = list(map(int, input().split()))\r\na = list()\r\na.append(b[0])\r\ntemp = b[0]\r\nfor i in range(m-1):\r\n\tif temp>b[i+1]:\r\n\t\ta.append(b[i+1])\r\n\t\ttemp = b[i+1]\r\na = a[::-1]\r\nfor i in range(len(a)-1):\r\n\tfor _ in range(a[i+1]-a[i]):\r\n\t\tprint(str(a[i]), end = ' ')\r\nfor _ in range(n-a[len(a)-1]+1):\r\n\tprint(a[len(a)-1], end = ' ')", "n = input().split()\r\nn = int(n[0])\r\nbutt = {}\r\nfor i in range(1, n+1):\r\n butt[i] = 0\r\n\r\na = input().split()\r\n\r\nfor i in a:\r\n for k in range(int(i), n+1):\r\n if butt[k] == 0:\r\n butt[k] = int(i)\r\n\r\n else: continue\r\n\r\nfor i in range(1, n+1):\r\n print(butt[i], end=' ')", "num, num2 = map(int, input().split())\r\nls = list(map(int, input().split()))\r\nvar = [0] * (num + 1)\r\n\r\nfor itr in ls:\r\n for itr2 in range(itr, num + 1):\r\n if var[itr2] == 0:\r\n var[itr2] = itr\r\n else:\r\n break\r\n \r\nprint(\" \".join(str(var) for var in var[1:]))", "# https://codeforces.com/problemset/problem/415/A\n# 900\n\nn, m = map(int, input().split())\nb = list(map(int, input().split()))\nc = [None] * n\n\n\nfor i,bi in enumerate(b):\n for j in range(bi-1, n):\n if c[j] is not None:\n break\n\n c[j] = str(bi)\n\nprint(\" \".join(c))\n\n", "n, m = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\nres = [0 for i in range(n+1)]\r\nfor i in arr:\r\n for j in range(i,n+1):\r\n if res[j]==0:\r\n res[j]=i\r\nprint(*res[1:])\r\n", "n, m = map(int,input().split())\na = list(map(int, input().split()))\nb = []\nfor i in range(n):\n b.append(i+1)\ne = []\nfor x in a:\n while len(b) >= x:\n b.pop(len(b)-1)\n e.append(x)\ne.reverse()\nfor i in range(len(e)):\n print(e[i], end = (' '))\n", "#----Kuzlyaev-Nikita-Codeforces-----\r\n#------------03.04.2020-------------\r\n\r\nalph=\"abcdefghijklmnopqrstuvwxyz\"\r\n\r\n#-----------------------------------\r\n\r\nn,m=map(int,input().split())\r\nd=[0]*n\r\nb=list(map(int,input().split()))\r\nfor i in range(m):\r\n for j in range(b[i],n+1):\r\n if d[j-1]==0:\r\n d[j-1]=b[i]\r\nfor i in range(n):\r\n print(d[i],end=\" \")", "def lights(n,arr):\r\n ans=[]\r\n for i in range(n[0]):\r\n ans.append(0)\r\n\r\n for i in range(len(arr)):\r\n for j in range(arr[i]-1,len(ans)):\r\n if ans[j]==0:\r\n ans[j]=arr[i]\r\n\r\n for i in range(len(ans)):\r\n print(ans[i],end=' ') \r\n\r\n\r\n\r\n\r\n\r\nn=list(map(int,input('').split()))\r\narr=list(map(int,input('').split()))\r\nlights(n,arr)", "n,m=map(int,input().split())\r\nblist=[int(x) for x in input().split()]\r\nllist=[0]*n\r\n\r\nfor i in range(m):\r\n for j in range(blist[i]-1,n):\r\n if llist[j]==0:\r\n llist[j]=blist[i]\r\n\r\nprint(''.join([str(llist[i])+' ' for i in range(n)]))", "n, m = map(int, input().split())\r\nb = list(map(int, input().split()))\r\nans = [0 for i in range(n)]\r\nfor i in range(m):\r\n for j in range(b[i] - 1, len(ans)):\r\n if ans[j] == 0:\r\n ans[j] = b[i]\r\nprint(*ans)", "n, m = map(int, input().split())\r\nb = list(map(int, input().split()))\r\ndic = {}\r\nfor i in range(1, n + 1):\r\n dic[i] = 0\r\nfor i in b:\r\n if dic[i]: continue\r\n else:\r\n for k, v in dic.items():\r\n if i <= k and not v: dic[k] = i\r\nprint(*sorted(list(dic.values())))", "n, m = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nmaxi, newLst = n+1, []\r\nfor x in lst:\r\n if x < maxi:\r\n newLst.append(x)\r\n maxi = x\r\nres = [max(x for x in newLst if x <= i+1) for i in range(n)]\r\nprint(' '.join(str(i) for i in res))", "import sys\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\ndef iinput(): return int(input())\r\ndef rinput(): return map(int, sys.stdin.readline().strip().split()) \r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split())) \r\n\r\n\r\nn,m=rinput()\r\na=list(map(int,input().split()))\r\nb=[0]*n\r\n\r\nfor i in range(m):\r\n for j in range(a[i]-1,n):\r\n if(b[j]==0):\r\n b[j]=a[i]\r\n\r\nprint(*b) ", "n , m = map(int , input().split())\r\nbutons = list(map(int , input().split()))\r\nlights = [-1] * (n+1)\r\nfor i in butons : \r\n for j in range(n , i-1, -1 ) :\r\n if lights[j] == -1 : \r\n lights[j] = i \r\nfor i in lights[1:] : \r\n print(i , end=' ') \r\n ", "n,m = map(int,input().split())\r\na = [int(x) for x in input().split()]\r\nlst = [0]*(n+1)\r\nfor i in a:\r\n for j in range(i,n+1):\r\n if lst[j]==0:\r\n lst[j]=i\r\n else:\r\n break\r\nprint(*lst[1:])", "n,m=map(int,input().split())\r\nbut=list(map(int,input().split()))\r\n\r\nsign=[0]*(n+1)\r\n\r\nfor i in range(m):\r\n x=but[i]\r\n for j in range(x,n+1):\r\n if sign[j]==0:\r\n sign[j]=x\r\n\r\nprint(sign[1],end='')\r\nfor i in range(2,n+1):\r\n print('',sign[i],end='')\r\n\r\nprint()", "n,m=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nres=[0]*(n+1)\r\nfor i in arr:\r\n j=i\r\n while j<n+1 and res[j]==0:\r\n res[j]=i\r\n j+=1\r\n\r\nfor i in range(1,n+1):\r\n print(res[i],end=\" \" if i!=n else \"\\n\")", "n,m = map(int,input().split()) \r\nb = list(map(int,input().split()))\r\nans = [0]*(n+1)\r\na = [0]*(n+1)\r\n\r\n \r\n \r\nfor i in range(m):\r\n for k in range(b[i],n+1):\r\n if a[k] == 0:\r\n a[k] = 1\r\n ans[k] = b[i]\r\nfor i in range(1,len(ans)):\r\n print(ans[i], end=\" \")", "n,m=map(int,input().split())\r\nbrr=list(map(int,input().split()))\r\narr=[[i,1] for i in range(1,n+1)]\r\nfor i in brr:\r\n for j in range(i-1,n):\r\n if arr[j][1]==1:\r\n arr[j][1]=0\r\n arr[j][0]=i\r\nfor i in range(n):\r\n print(arr[i][0],end=\" \")", "n,m=map(int,input().split())\r\nl=[]\r\nf=[]\r\nfor j in range(n):\r\n l.append(1)\r\nb=list(map(int,input().split()))\r\nfor i in b:\r\n for j in range(i-1,n):\r\n l[j]=0\r\n f.append(i)\r\n n=n-1\r\nf.sort()\r\nprint(*f,sep=' ') ", "n,m=[int(i) for i in input().split()]\r\na=[int(i) for i in input().split()]\r\nl=['.']*n\r\nfor i in range(0,len(a)):\r\n for j in range(a[i],n+1):\r\n if(l[j-1]=='.'):\r\n l[j-1]=a[i]\r\nprint(*l)", "import sys\r\nfile = sys.stdin\r\n\r\n__author__ = 'RaiaN'\r\n\r\nn, m = file.readline().split(' ')\r\nn = int(n)\r\nm = int(m)\r\nms = [int(val) for val in file.readline().split(' ')]\r\n\r\ndsb = [0]*n\r\nfor val in ms:\r\n for i in range(val-1, n):\r\n if dsb[i] == 0:\r\n dsb[i] = val\r\n\r\nprint(' '.join(str(x) for x in dsb))", "def solve(n, m, b):\n a = [-1 for _ in range(n)]\n for i, k in enumerate(b):\n for j in range(k-1, n):\n if a[j] == -1:\n a[j] = k\n return ' '.join(map(str, a))\n\n\ndef main():\n n, m = list(map(int, input().split()))\n b = list(map(int, input().split()))\n print(solve(n, m, b))\n\n\nmain()\n", "a,b=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nk,c=[],a\r\nfor x in l:\r\n\tif x<=c:\r\n\t\tfor y in range(c-x+1):k.append(x)\r\n\t\tc=x-1\r\nk.reverse()\r\nprint(*k)", "n,m = map(int, input().split())\r\narr = list(map(int, input().split()))\r\noff = [-1] * n\r\nlights = [1] * n\r\nfor i in arr:\r\n index = i - 1\r\n if(lights[index] == 1):\r\n lights[index] = 0\r\n off[index] = i\r\n for j in range(index + 1, n):\r\n if(lights[j] == 1):\r\n lights[j] = 0\r\n off[j] = i\r\noff = [str(i) for i in off]\r\nprint(\" \".join(off))\r\n", "n,m=[int(x) for x in input().split()]\r\na=[int(y) for y in input().split()]\r\ni=0\r\nx=[0 for y in range(n)]\r\nwhile i<len(a):\r\n j=a[i]-1\r\n while j<n and (x[j]==0):\r\n x[j]=a[i]\r\n j+=1\r\n i+=1\r\nfor i in range(n):\r\n print(x[i],end=\" \")\r\n\r\n", "n,m = map(int,input().split())\r\nb = input().split()\r\nb = [int(x) for x in b]\r\n\r\nI = [0]*n\r\nfor i in range(m) :\r\n j = b[i]-1\r\n while j<n and I[j]==0 :\r\n I[j] = b[i]\r\n j += 1\r\n\r\nfor i in range(n) :\r\n print(I[i],end=\" \")", "n,m=map(int,input().split())\r\n\r\nL=list(map(int,input().split()))\r\nQ=[1]*n\r\nAns=[-1]*(n)\r\nfor i in range(m):\r\n x=L[i]-1\r\n for j in range(x,n):\r\n if(Q[j]==1):\r\n Q[j]=0\r\n Ans[j]=x+1\r\nfor item in Ans:\r\n print(item,end=\" \")\r\n", "'''\r\nCreated on Jan 28, 2015\r\n\r\n@author: mohamed265\r\n'''\r\nt = input().split()\r\nn = int(t[0])\r\nm = int(t[1])\r\nt = [int(x) for x in input().split()]\r\nslon = [0 for x in range(n)]\r\nfor i in range(m):\r\n for j in range(t[i], n + 1):\r\n if j != 0 and slon[j - 1] == 0:\r\n slon[j - 1] = t[i]\r\nprint(*slon)\r\n", "n, m = map(int, input().split())\r\nb = [int(i) for i in input().split()]\r\n\r\na = [0] * n\r\nfor i in b:\r\n\tfor j in range(i - 1, n):\r\n\t\tif a[j] == 0:\r\n\t\t\ta[j] = i\r\n\t\telse:\r\n\t\t\tbreak\r\n\r\nprint(*a)", "n,m=input().split()\r\nn,m=int(n),int(m)\r\nlis=input().split()\r\nfor i in range(len(lis)):\r\n lis[i]=int(lis[i])\r\ndic={}\r\nfor i in range(1,n+1):\r\n dic[i]=[]\r\nfor i in range(m):\r\n for j in range(lis[i],n+1):\r\n dic[j].append(lis[i])\r\nfor i in range(1,n+1):\r\n print(dic[i][0],end=' ')\r\n", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nli=[0]*(n+1)\r\nfor i in l:\r\n for j in range(i,n+1):\r\n if li[j]==0:\r\n li[j]=i\r\nfor i in range(1,n+1):\r\n print(li[i],end=\" \")\r\n", "n, m = map(int, input().split())\nx = list(map(int, input().split()))\nans = n * [0]\nfor i in range(m):\n for q in range(n - x[i] + 1):\n if ans[q] == 0:\n ans[q] = x[i]\nans.sort()\nprint(*ans)\n", "#415/A\n\n_=list(map(int,input().split()))\n__=list(map(int,input().split()))\n___=[0 for ____ in range(_[0])]\n_____=_[0]\nfor ____ in range(_[1]):\n for ______ in range(__[____]-1,_____,1):\n ___[______]=__[____]\n if __[____]<=_____:\n _____=__[____]-1\n #print(___)\nprint(*___,sep=\" \")\n\n\n\n#104/A", "n,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nk=[]\r\ns=[]\r\nfor i in range(m):\r\n\tfor j in range(l[i],n+1):\r\n\t\tif j not in s:\r\n\t\t\ts.append(j)\r\n\t\t\tk.append(l[i])\r\nfor i in range(n):\r\n\tprint(k[-(i+1)],end=\" \")", "n, m = map(int, input().strip().split())\r\narr = input()\r\nbm = [int(i) for i in arr.split()]\r\nindex = [0] * (n + 1)\r\nfor i in bm:\r\n for j in range(i, n + 1):\r\n if index[j] == 0:\r\n index[j] = i\r\nfor i in range(1, n + 1):\r\n print(index[i], end=\" \")", "import sys\r\nline = str.split(input(),\" \")\r\nn = int(line[0])\r\nm = int(line[1])\r\npushed = [int(i) for i in str.split(input(),\" \")]\r\n\r\nbuttons = [0 for i in range(n)]\r\n\r\ndef pushButton(buttons, bi):\r\n for i in range(bi-1,len(buttons)):\r\n if (buttons[i] == 0):\r\n buttons[i] = bi\r\n return buttons\r\n#print(buttons)\r\nfor bi in pushed:\r\n buttons = pushButton(buttons,bi)\r\n #print(buttons)\r\nfor x in buttons[0:-1]:\r\n sys.stdout.write(str(x)+\" \")\r\nsys.stdout.write(str(buttons[len(buttons)-1]))", "#code\r\nR=lambda:map(int, input().split())\r\n\r\nn, m = R()\r\n\r\narr = list(R())\r\na = [0] * n\r\n\r\nfor i in arr:\r\n a[i-1:n] = [i] *(n-i+1)\r\n n = min(i-1, n)\r\n\r\nprint(*a)", "\r\nn,m=map(int,input().split())\r\nl=list(map(int,input().split()))\r\n\r\nr=[[True] for _ in range(n)]\r\nfor i in l:\r\n\tfor j in range(i-1,n):\r\n\t\tif r[j][0]==True:\r\n\t\t\tr[j].append(i)\r\n\t\t\tr[j][0]==False\r\n\r\nfor i in range(n):\r\n\tprint(r[i][1],end=\" \")\r\n", "n, m = map(int, input().split())\nb = [int(x) for x in input().split()]\nres = [0] * n\nfor i in range(m):\n for j in range(b[i] - 1, n):\n if res[j] != 0:\n break\n res[j] = b[i]\nprint(*res)\n", "n,m=map(int,input().split());l=list(map(int,input().split()));d={}\r\nfor i in l:\r\n\tfor j in range(i,n+1):\r\n\t\tif j not in d:d[j]=i\r\nfor i in range(1,n+1):print(d[i])", "n, m = map(int, input().split())\r\nl = list(map(int, input().split()))\r\nq = []\r\nfor i in range(n):\r\n q.append(0)\r\nfor i in range(m):\r\n for j in range(l[i] - 1, n, 1):\r\n if q[j] == 0:\r\n q[j] = l[i]\r\nprint(*q)", "R = lambda: map(int, input().split())\r\nn, m = R()\r\na = [0] * n\r\nb = list(R())\r\nfor i in range(m):\r\n for j in range(b[i] - 1, n):\r\n if a[j] == 0:\r\n a[j] = b[i]\r\n else:\r\n break\r\nprint(' '.join(map(str, a)))", "l1 = [int(x) for x in input().split()]\r\nl2 = [int(x) for x in input().split()]\r\nn,m = l1[0],l1[1]\r\nc_out=[]\r\nfor x in range(1,n+1):\r\n i=0\r\n #print(x)\r\n while i<len(l2):\r\n if l2[i]<=x:\r\n c_out.append(l2[i])\r\n break\r\n i+=1\r\nprint(*c_out)", "lamp, step = map(int, input().split())\r\nsteps = list(map(int, input().split()))\r\nlamps = []\r\nfor i in range(lamp):\r\n lamps.append(i + 1)\r\nfor i in range(lamp):\r\n j = 0\r\n while steps[j] > lamps[i]:\r\n j += 1\r\n lamps[i] = steps[j]\r\nprint(' '.join(map(str, lamps)))", "n, m = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\nans = [0] * n\nfor i in range(m):\n\tswitch = b[i] - 1\n\twhile switch < len(ans) and ans[switch] == 0:\n\t\tans[switch] = b[i]\n\t\tswitch += 1\nprint(' '.join(str(x) for x in ans))\n", "n, m = map(int, input().split())\r\nour_list = list(map(int, input().split()))\r\nour_list_2 = []\r\nfor i in range(n + 1):\r\n our_list_2.append(0)\r\nfor i in range(m):\r\n for j in range(our_list[i], n + 1):\r\n if our_list_2[j] == 0:\r\n our_list_2[j] = our_list[i]\r\nprint(' '.join(list(map(str, our_list_2[1:]))))\r\n ", "\"\"\"\r\nCodeforces Round 240 Div 1 Problem A\r\n\r\nAuthor : chaotic_iak\r\nLanguage: Python 3.3.4\r\n\"\"\"\r\n\r\nclass InputHandlerObject(object):\r\n inputs = []\r\n\r\n def getInput(self, n = 0):\r\n res = \"\"\r\n inputs = self.inputs\r\n if not inputs: inputs.extend(input().split(\" \"))\r\n if n == 0:\r\n res = inputs[:]\r\n inputs[:] = []\r\n while n > len(inputs):\r\n inputs.extend(input().split(\" \"))\r\n if n > 0:\r\n res = inputs[:n]\r\n inputs[:n] = []\r\n return res\r\nInputHandler = InputHandlerObject()\r\ng = InputHandler.getInput\r\n\r\n############################## SOLUTION ##############################\r\nn,m = g()\r\nn,m = int(n), int(m)\r\nb = g()\r\na = [0] * n\r\nfor i in b:\r\n for j in range(int(i)-1, n):\r\n a[j] = i if a[j] == 0 else a[j]\r\nprint(\" \".join(a))", "dic = {}\r\nlist = [int(x) for x in input().split(\" \")]\r\nlist_1 = [int(x) for x in input().split(\" \")]\r\nfor num in list_1:\r\n dic[num] = [int(i) for i in range(num , list[0]+1)]\r\nval = 1\r\nwhile val<list[0]+1:\r\n for key in dic:\r\n if val in dic[key]:\r\n print(key, end=\" \")\r\n val+=1\r\n break\r\n" ]
{"inputs": ["5 4\n4 3 1 2", "5 5\n5 4 3 2 1", "16 11\n8 5 12 10 14 2 6 3 15 9 1", "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 61 12 60 57", "25 19\n3 12 21 11 19 6 5 15 4 16 20 8 9 1 22 23 25 18 13", "48 8\n42 27 40 1 18 3 19 2", "44 19\n13 20 7 10 9 14 43 17 18 39 21 42 37 1 33 8 35 4 6", "80 29\n79 51 28 73 65 39 10 1 59 29 7 70 64 3 35 17 24 71 74 2 6 49 66 80 13 18 60 15 12", "31 4\n8 18 30 1", "62 29\n61 55 35 13 51 56 23 6 8 26 27 40 48 11 18 12 19 50 54 14 24 21 32 17 43 33 1 2 3", "5 4\n2 3 4 1", "39 37\n2 5 17 24 19 33 35 16 20 3 1 34 10 36 15 37 14 8 28 21 13 31 30 29 7 25 32 12 6 27 22 4 11 39 18 9 26", "100 100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "1 1\n1", "18 3\n18 1 11", "67 20\n66 23 40 49 3 39 60 43 52 47 16 36 22 5 41 10 55 34 64 1", "92 52\n9 85 44 13 27 61 8 1 28 41 6 14 70 67 39 71 56 80 34 21 5 10 40 73 63 38 90 57 37 36 82 86 65 46 7 54 81 12 45 49 83 59 64 26 62 25 60 24 91 47 53 55", "66 36\n44 62 32 29 3 15 47 30 50 42 35 2 33 65 10 13 56 12 1 16 7 36 39 11 25 28 20 52 46 38 37 8 61 49 48 14", "32 8\n27 23 1 13 18 24 17 26", "26 13\n1 14 13 2 4 24 21 22 16 3 10 12 6", "31 20\n10 11 20 2 4 26 31 7 13 12 28 1 30 18 21 8 3 16 15 19", "86 25\n22 62 8 23 53 77 9 31 43 1 58 16 72 11 15 35 60 39 79 4 82 64 76 63 59", "62 54\n2 5 4 47 40 61 37 31 41 16 44 42 48 32 10 6 62 38 52 49 11 20 55 22 3 36 25 21 50 8 28 14 18 39 34 54 53 19 46 27 15 23 12 24 60 17 33 57 58 1 35 29 51 7", "57 19\n43 45 37 40 42 55 16 33 47 32 34 35 9 41 1 6 8 15 5", "32 14\n4 7 13 1 25 22 9 27 6 28 30 2 14 21", "57 12\n8 53 51 38 1 6 16 33 13 46 28 35", "87 9\n57 34 78 1 52 67 56 6 54", "88 42\n85 45 52 14 63 53 70 71 16 86 66 47 12 22 10 72 4 31 3 69 11 77 17 25 46 75 23 1 21 84 44 20 18 33 48 88 41 83 67 61 73 34", "27 25\n9 21 17 5 16 3 23 7 12 4 14 11 13 1 15 19 27 8 20 10 22 25 6 18 26", "89 28\n5 22 79 42 16 35 66 48 57 55 1 37 29 31 40 38 45 62 41 87 64 89 81 13 60 44 71 82", "17 4\n4 3 1 2"], "outputs": ["1 1 3 4 4 ", "1 2 3 4 5 ", "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 28 28 28 28 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 76 76 76 76 ", "1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 42 42 42 42 42 42 42 ", "1 1 1 1 1 1 7 7 7 7 7 7 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 ", "1 1 1 1 1 1 1 1 1 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 79 79 ", "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ", "1 1 1 1 1 6 6 6 6 6 6 6 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 35 55 55 55 55 55 55 61 61 ", "1 2 2 2 2 ", "1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ", "1 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 18 ", "1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 66 66 ", "1 1 1 1 1 1 1 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 ", "1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 29 29 29 32 32 32 32 32 32 32 32 32 32 32 32 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 23 23 23 27 27 27 27 27 27 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ", "1 2 2 2 2 2 2 2 2 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ", "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 ", "1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ", "1 1 1 1 1 1 1 1 9 9 9 9 9 9 9 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 37 37 37 37 37 37 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 ", "1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ", "1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 ", "1 1 3 4 4 4 4 4 4 10 10 12 12 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 85 85 85 85 ", "1 1 3 3 5 5 5 5 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 ", "1 1 1 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ", "1 1 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 "]}
UNKNOWN
PYTHON3
CODEFORCES
214
205c37248279a0d5d0fe8acbffb500f4
Quasi Binary
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them. Sample Input 9 32 Sample Output 9 1 1 1 1 1 1 1 1 1 3 10 11 11
[ "#### B. Quasi Binary\r\nn=int(input())\r\nresult=[]\r\nwhile n:\r\n r=''.join(min(i,'1') for i in str(n))\r\n n=n-int(r)\r\n result.append(r)\r\nprint(len(result))\r\nprint(*result)", "n = int(input())\r\ns = list(map(int, str(n)))\r\nprint(max(s))\r\nl = len(s)\r\nfor i in range(max(s)):\r\n f = 0\r\n for i in range(l):\r\n if s[i] > 0:\r\n s[i] -= 1\r\n print(1, end = '')\r\n f = 1\r\n else:\r\n if f:\r\n print(0, end = '')\r\n print(' ', end = '')", "a = input()\na = [int(i) for i in a]\n\nsol = [0 for i in range(9)]\nfor i in range(len(a)):\n for j in range(a[i]):\n sol[j] += 10**(len(a)-i-1)\n\nfor i in range(9):\n if sol[i] == 0:\n break\n\n nb = i\n\nprint(nb+1)\nprint(*sol[:nb+1])\n", "n = input()\nres = []\nwhile int(n) > 0:\n s = ''\n for i in n:\n if i != '0':\n s = s + '1'\n else:\n s = s + '0'\n n = str(int(n)-int(s))\n res.append(s)\nprint(len(res))\nprint(' '.join(res))\n\t\t \t\t \t \t\t \t\t \t\t \t\t \t", "n = list(map(int, list(input())))\r\n\r\nprint(max(n))\r\nans = []\r\nmaxn = max(n)\r\nfor i in range(maxn):\r\n ans.append(['0' for i in range(len(n))])\r\n for j in range(len(n)):\r\n if n[j]>0:\r\n n[j]-=1\r\n ans[i][j]='1'\r\n print(int(''.join(ans[i])),end=\" \")\r\n", "n=int(input())\r\nc=0\r\nl=[]\r\nwhile (n > 0): \r\n c=c+1\r\n temp = n; \r\n m = 0; \r\n p = 1; \r\n while (temp): \r\n rem = temp % 10; \r\n temp = int(temp / 10); \r\n if (rem != 0): \r\n m += p; \r\n p *= 10;\r\n l.append(m)\r\n n = n - m; \r\nprint(c)\r\nprint(*l)", "n = input().strip()\r\nm = max([int(i) for i in n])\r\nprint(m)\r\nfor i in range(m):\r\n print(int(''.join(['1' if int(j) > i else '0' for j in n])),end=' ')\r\n", "n = int(input())\r\nv=[]\r\nwhile n!=0:\r\n a=1\r\n i=0\r\n while n//a!=0:\r\n if (n%(a*10))//a!=0:\r\n i+=a\r\n n-=a\r\n a*=10\r\n v.append(i)\r\nprint(len(v))\r\nprint(' '.join(map(str, v)))", "n = input()\nm = max(int(x) for x in n)\nls = [''] * m\nfor x in n:\n y = int(x)\n for i in range(y):\n ls[i] += '1'\n for i in range(y, m):\n ls[i] += '0'\nprint(m)\nfor x in ls:\n print(int(x), end=' ')", "n = [int(i) for i in input()]\r\nans = []\r\nwhile sum(n) > 0:\r\n s = ''\r\n for i in range(len(n)):\r\n if n[i] == 0:\r\n if len(s) != 0:\r\n s = s + '0'\r\n else:\r\n s = s + '1'\r\n n[i] -= 1\r\n ans.append(s)\r\nprint(len(ans))\r\nprint(' '.join(ans))\r\n", "n = input()\r\nk = int(max(n))\r\n\r\nprint(k)\r\n\r\nfor i in range(1, k + 1):\r\n print(int(''.join(\"01\"[int(d) - i >= 0] for d in n)), end=' ')", "n = int(input())\r\ns = ''; ans = 0 \r\nwhile n > 0:\r\n m = int(\"\".join(['1' if d != '0' else '0' for d in str(n)]))\r\n n -= m\r\n if n >= 0:\r\n ans += 1\r\n s += str(m) + ' '\r\nprint(ans, s, sep='\\n')", "s = input()\nm = max(int(c) for c in s)\nprint(m)\nfor i in range(m):\n\tprint(int(''.join('1' if int(c) > i else '0' for c in s)), end=' ')\n", "def listaanspostas(n):\n ans = []\n while (n>0):\n aux=''\n for i in str(n):\n aux+=str(min(int(i),1))\n n-=int(aux)\n ans.append(int(aux))\n return ans\n\nn = int(input())\nans = listaanspostas(n) \nprint(len(ans))\nfor i in ans:\n print(i, end=\" \")\n \t \t \t\t\t \t \t \t\t \t\t\t\t\t \t\t\t \t", "\r\ndef STR(): return list(input())\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef MAP2():return map(float,input().split())\r\ndef LIST(): return list(map(int, input().split()))\r\ndef STRING(): return input()\r\nfrom heapq import heappop , heappush\r\nfrom bisect import *\r\nfrom collections import deque , Counter\r\nfrom math import *\r\nfrom itertools import permutations\r\ndx = [-1 , 1 , 0 , 0 ]\r\ndy = [0 , 0 , 1 , - 1]\r\n#visited = [[False for i in range(m)] for j in range(n)]\r\n#for tt in range(INT()):\r\n\r\nn = INT()\r\n\r\nres = []\r\nwhile n > 0 :\r\n z = ''\r\n for i in str(n):\r\n z+= str(min(1 , int(i)))\r\n\r\n n-=int(z)\r\n res.append(z)\r\n\r\n#print(res)\r\nprint(len(res))\r\nfor i in res:\r\n print(i , end = ' ')\r\n\r\n", "n = int(input())\n\nquasibinary = [1]\ntmp = 2\nwhile (quasibinary[len(quasibinary)-1] <= n):\n quasibinary.append(int(bin(tmp)[2:]))\n tmp += 1\n\ndp = [0]\nfor i in range(1, n+1):\n result = i\n for quasi in quasibinary:\n if (quasi > i):\n break\n result = min(result, dp[i-quasi])\n dp.append(result+1)\n\nq_list = []\npointer = n\nwhile (pointer > 0):\n for quasi in quasibinary:\n if (dp[pointer - quasi] + 1 == dp[pointer]):\n q_list.append(quasi)\n pointer -= quasi\n break\n\nprint(dp[n])\nprint(*q_list, sep=\" \")\n", "def to_dec(n):\r\n ans = []\r\n while n > 0:\r\n ans.append(n % 10)\r\n n //= 10\r\n return ans\r\n\r\ndef main() -> None:\r\n n = int(input())\r\n dec = to_dec(n)\r\n l = len(dec)\r\n m = max(dec)\r\n nums = []\r\n\r\n while sum(dec) != 0:\r\n x = 0\r\n for i in range(l):\r\n if dec[i] > 0:\r\n x += 10 ** i\r\n dec[i] -= 1\r\n nums.append(x)\r\n\r\n print(m)\r\n print(*nums)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "x = input()\n\ndef convert_to_list(n):\n res = []\n for i in n:\n res.append(int(i))\n \n return res\n \ndef solve(n):\n res = []\n \n while True:\n power,total = 0,0\n for i in range(len(n)-1,-1,-1):\n num = n[i]\n if num!= 0:\n total += pow(10,power)\n n[i] = num-1\n power+=1\n \n if total == 0:break\n res.append(total)\n return res\n\ndef format_output(res):\n output = \"\"\n \n for i,val in enumerate(res):\n \n if i != len(res)-1:\n output=output+str(val)+\" \"\n else:\n output=output+str(val)\n \n return output\n\n\nn = convert_to_list(x)\nres = solve(n)\noutput = format_output(res)\n\n\nprint(len(res))\nprint(output)\n \t\t\t \t \t\t \t \t \t\t\t\t \t \t \t", "n = int(input())\r\na = []\r\nwhile n > 0:\r\n a.append(n%10)\r\n n //= 10\r\nprint(max(a))\r\nn = [0, ]*max(a)\r\nfor i in range(len(a)):\r\n for j in range(a[i]):\r\n n[j] += (10**i)\r\nprint(*n)", "ans = []\r\nn = int(input())\r\nwhile n:\r\n d = \"\"\r\n for i in str(n):\r\n d += min(i, \"1\")\r\n n -= int(d)\r\n ans.append(d)\r\nprint(len(ans))\r\nprint(*ans)", "from sys import stdout\r\nn=input()\r\nnum=int(n)\r\nc=0\r\nv=[]\r\nwhile(num>0):\r\n l=len(n)\r\n if n.count(\"1\") + n.count(\"0\")==l:\r\n c+=1\r\n v.append(n)\r\n break\r\n else:\r\n s=\"\"\r\n if \"0\" in n:\r\n for i in n:\r\n if i==\"0\":\r\n s+=\"0\"\r\n else:\r\n s+=\"1\"\r\n num-=int(s)\r\n v.append(s)\r\n c+=1\r\n n=str(num)\r\n else:\r\n c+=1\r\n v.append((\"1\"*l))\r\n num-=int(\"1\"*l)\r\n n=str(num)\r\nprint(c)\r\nfor i in v:\r\n stdout.write(i)\r\n print(end=\" \")\r\n ", "def qBinary(n):\n\ta = list(str(n))\n\ta = list(map(int,a))\n\tb = [0]*max(a)\n\tfor i in range(len(a)):\n\t\tj = 0\n\t\twhile(a[i] > 0):\n\t\t\tb[j] += 10**(len(a)-i-1)\n\t\t\tj += 1\n\t\t\ta[i] -= 1\n\tprint(len(b))\n\tfor i in b:\n\t\tprint(i,end = ' ')\n\nn = int(input())\nqBinary(n)", "n=input()\r\nn1=len(n)\r\nk=0\r\nfor i in range(n1):\r\n if(int(n[i])>k):\r\n k=int(n[i])\r\n\r\nprint(k)\r\nl=[]\r\nfor i in range(k):\r\n l.append(\"\")\r\n\r\nfor i in range(n1):\r\n for j in range(int(n[i])):\r\n l[j]+=\"1\"\r\n for j in range(int(n[i]),k):\r\n l[j]+=\"0\"\r\n\r\ndef fix(l):\r\n l1=len(l)\r\n p=[]\r\n for i in range(l1):\r\n s=0\r\n if(l[i][0]==\"0\"):\r\n j=1\r\n r=len(l[i])\r\n s=1\r\n while(j<r):\r\n if(l[i][j]==\"0\"):\r\n s+=1\r\n else:\r\n break\r\n j+=1\r\n p.append(s)\r\n for i in range(l1):\r\n if(p[i]>0):\r\n m=\"\"\r\n r=len(l[i])\r\n for j in range(p[i],r):\r\n m+=l[i][j]\r\n l[i]=m\r\n return l\r\nfix(l)\r\nfor i in range(k):\r\n print(l[i],\"\",end=\"\")\r\nif(k==0):\r\n print(k)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "import sys\r\nMOD = 1000000007\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nls = lambda : list(input())\r\nfrom collections import *\r\nnm=ii()\r\ndef decimalToBinary(n): \r\n return bin(n).replace(\"0b\", \"\")\r\nk=[]\r\nfor i in range(1,65):\r\n k.append(int(decimalToBinary(i)))\r\ndp=[sys.maxsize]*(nm+1)\r\ntb=[0]*(nm+1)\r\ndp[0]=0\r\nfor i in range(1,nm+1):\r\n for j in range(0,64):\r\n if(k[j]<=i):\r\n dp[i]=min(dp[i],dp[i-k[j]]+1)\r\n if(dp[i]==dp[i-k[j]]+1):\r\n tb[i]=k[j]\r\nprint(dp[nm])\r\ncurr=nm\r\nwhile(curr >0):\r\n print(tb[curr],end=\" \")\r\n curr=curr-tb[curr]", "n=int(input())\r\nL=[]\r\nwhile(n>0):\r\n cb=\"\".join([[\"0\",\"1\"][int(k)>0] for k in str(n)])\r\n L.append(cb)\r\n n-=int(cb)\r\nprint(len(L))\r\nprint(\" \".join(L))", "N = int(input())\r\n\r\nnumbers = []\r\n\r\nwhile N > 0:\r\n\r\n new_number = \"\"\r\n \r\n for digit in [int(x) for x in str(N)]:\r\n\r\n if digit > 0:\r\n new_number += \"1\"\r\n else:\r\n new_number += \"0\"\r\n\r\n\r\n N -= int(new_number)\r\n\r\n numbers.append(int(new_number))\r\n\r\n\r\n\r\nprint(len(numbers))\r\n\r\nprint(*numbers)\r\n", "n = int(input())\r\na = []\r\nwhile n > 0:\r\n d = int(''.join(min(x, '1') for x in str(n)))\r\n n -= d\r\n a += [d]\r\nprint(len(a))\r\nprint(' '.join(map(str, a)))", "number=input()\r\nlargestdigit=int(max(number))\r\nprint(largestdigit)\r\nfor i in range(largestdigit):\r\n array = ['1' if int(c) > i else '0' for c in number]\r\n string=\"\"\r\n for item in array:\r\n string+=item\r\n print(int(string))", "n=list(map(int,input()))\r\nle=len(n)\r\nl=[['0']*le for i in range(max(n))]\r\nfor j in range(le):\r\n for i in range(n[j]):\r\n l[i][j]='1'\r\nprint(max(n))\r\nl=list(map(''.join,l))\r\nl=list(map(int,l))\r\nprint(' '.join(map(str,l)))", "n = input().strip()\r\nd = int(n)\r\nnums = []\r\nwhile d > 0:\r\n tmp = ''\r\n for i in range(len(n)):\r\n tmp += min(n[i], '1')\r\n tmp = int(tmp)\r\n nums.append(tmp)\r\n d -= tmp\r\n n = str(d)\r\nprint(len(nums))\r\nprint(*nums)", "\r\nn=int(input())\r\np=[]\r\nnum=n\r\nwhile num:\r\n p.append(num%10)\r\n num//=10\r\np=p[::-1]\r\nsol=[]\r\nwhile max(p)!=0:\r\n curr=0\r\n for i in range(len(p)):\r\n if p[i]!=0:\r\n p[i]-=1\r\n curr+=10**(len(p)-i-1)\r\n sol.append(curr)\r\nprint(len(sol))\r\nprint(*sol)", "n = input()\nB = [0 for i in range(7)]\nwhile len(n) != 7:\n n = '0' + n\nans = 0\nfor i in range(7):\n ans = max(ans, int(n[i]))\n B[i] = int(n[i])\nprint(ans)\ns = ''\nfor i in range(ans):\n cur = [0 for i in range(7)]\n for j in range(7):\n if B[j] > 0:\n cur[j] = 1\n B[j] -= 1\n was = False\n for j in range(7):\n if cur[j] == 1:\n s += '1'\n was = True\n elif was:\n s += '0'\n s += ' '\nprint(s[:-1])\n", "\r\ndef answer(n):\r\n ans = []\r\n nl = list((str(n))) #ints are strings. Explicitly cast when doing the math.\r\n nln = []\r\n for e in nl:\r\n nln.append(int(e))\r\n #print('nl=', nl)\r\n \r\n while max(nln) > 0:\r\n t = []\r\n for i in range(len(nln)):\r\n if nln[i] >= 1:\r\n t.append('1')\r\n nln[i] -= 1\r\n else:\r\n t.append('0')\r\n ans.append(''.join(t)) \r\n ansn = []\r\n for e in ans:\r\n ansn.append(int(e))\r\n print(len(ansn))\r\n print(' '.join(map(str, ansn)))\r\n return #null Print 2 lines.\r\n\r\ndef main():\r\n n = int(input())\r\n answer(n)\r\n\r\n\r\n return\r\nmain()", "n = int(input())\nnums = []\n\nwhile n > 0:\n aux = \"\"\n for i in str(n):\n if i == '0':\n aux += \"0\"\n else:\n aux += \"1\"\n nums.append(int(aux))\n n -= int(aux)\n \nprint(len(nums))\nfor i in nums:\n print(i, end=\" \")\n\t\t \t \t\t\t\t\t\t \t\t\t\t\t\t\t\t \t\t\t\t\t", "import math as mt \r\nimport sys,string,bisect\r\ninput=sys.stdin.readline\r\nimport random\r\nfrom collections import deque,defaultdict\r\nL=lambda : list(map(int,input().split()))\r\nLs=lambda : list(input().split())\r\nM=lambda : map(int,input().split())\r\nI=lambda :int(input())\r\nd=defaultdict(int)\r\nn=input().strip()\r\nl=[]\r\nfor i in n:\r\n l.append(int(i))\r\nans=[]\r\nwhile(sum(l)!=0):\r\n i=0\r\n s=0\r\n while(i<len(l)):\r\n s*=10\r\n if(l[i]>0):\r\n s+=1\r\n l[i]-=1\r\n i+=1\r\n ans.append(s)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "n=int(input())\r\nl=set()\r\nq=[0]\r\nwhile q:\r\n x=q.pop()\r\n if x in l:\r\n continue\r\n if x>10**6:\r\n continue\r\n l.add(x)\r\n q.append(x*10+1)\r\n q.append(x*10)\r\nl=list(l)\r\nl.sort()\r\nl=l[1:]\r\ndp=[[10**9,-1] for i in range(n+1)]\r\nfor ll in l:\r\n if ll>n:\r\n break\r\n dp[ll]=[1,ll]\r\nfor i in range(1,n+1):\r\n for ll in l:\r\n if ll>i:\r\n break\r\n if i-ll>=0 and dp[i][0]>dp[i-ll][0]+1:\r\n dp[i][0]=dp[i-ll][0]+1\r\n dp[i][1]=ll\r\nans=[]\r\nwhile dp[n][1]!=-1:\r\n ans.append(dp[n][1])\r\n n-=dp[n][1]\r\nprint(len(ans))\r\nprint(*ans)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = list(map(int, list(input()[:-1])))\r\nx = max(n)\r\nq = len(n)\r\nd = []\r\nwhile x != 0:\r\n d1 = ''\r\n for i in range(q):\r\n if n[i] > 0:\r\n n[i] -= 1\r\n d1 += '1'\r\n else:\r\n d1 += '0'\r\n d.append(int(d1))\r\n x -= 1\r\nprint(len(d))\r\nprint(' '.join(map(str, d)))", "a = input()\r\np = [int(x) for x in list(a)]\r\ns = [\"\"]*max(p)\r\nfor i in p:\r\n for j in range(len(s)):\r\n s[j]+=str(int(j<i))\r\nprint(len(s))\r\nprint(*[int(x) for x in s])", "n=int(input())\r\nls=[]\r\ntotal=0\r\nwhile n>1:\r\n # print(n)\r\n tmp=''\r\n count=0\r\n n=str(n)\r\n for i in range(len(n)):\r\n if(n[i]=='0'):\r\n tmp+='0'\r\n count+=1\r\n else:\r\n tmp+='1'\r\n if n[i]=='1':\r\n count+=1\r\n temp=int(tmp)\r\n ls.append(temp)\r\n n=int(n)\r\n n-=temp\r\n total+=1\r\nif n==1:\r\n ls.append(1)\r\n total+=1\r\nprint(total)\r\nfor num in ls:\r\n print(num,end=\" \")\r\n", "n = int(input())\r\nans=[]\r\nwhile n:\r\n t = n\r\n i = 1\r\n cur = 0\r\n while t:\r\n if t % 10:\r\n cur += i\r\n t = t // 10\r\n i*=10\r\n ans.append(cur)\r\n n-=cur\r\nprint(len(ans))\r\nprint(' '.join(map(str,ans)))\r\n\r\n", "from collections import defaultdict\r\n\r\n\r\ndef quasiBelow(n):\r\n d = defaultdict(list)\r\n d[0].append(0)\r\n d[1].append(1)\r\n for i in range(2, len(str(n)) + 1):\r\n for item in d[i - 1]:\r\n d[i].append(item * 10 + 0)\r\n d[i].append(item * 10 + 1)\r\n return d\r\n\r\n\r\ndef minRepr(n):\r\n d = quasiBelow(n)\r\n\r\n dp = [(0, [])] * (n + 5)\r\n\r\n dp[0] = (0, [])\r\n dp[1] = (1, [1])\r\n for i in range(2, n + 1):\r\n m = len(str(i))\r\n\r\n minR = i + 1, []\r\n minItem = d[m][0]\r\n\r\n for item in d[m]:\r\n if i - item < 0:\r\n continue\r\n\r\n a = dp[i - item]\r\n\r\n if a[0] < minR[0]:\r\n minR = a\r\n minItem = item\r\n\r\n dp[i] = 1 + minR[0], [minItem] + minR[1]\r\n # print(i, dp[i])\r\n\r\n return dp[n]\r\n\r\n\r\nn = int(input())\r\nres = minRepr(n)\r\nprint(res[0])\r\nfor v in res[1]:\r\n print(v, end=' ')\r\n", "n=int(input())\nans=[]\nwhile n!=0:\n\ts=str(n)\n\tfor i in range(len(s)):\n\t\tif s[i:i+1]!='0':\n\t\t\ts=s[:i]+'1'+s[i+1:] \n\tt=int(s)\n\tans.append(t)\n\tn-=t\n\t#print(n,end=\" \")\nprint (len(ans))\nprint (*ans)\n\t\n", "n=int(input())\r\nnum=[]\r\nfor i in str(n):\r\n num.append(int(i))\r\nans=[]\r\nwhile max(num)!=0:\r\n val=0\r\n for i in range(len(num)):\r\n starting = 10 ** (len(num) - 1-i)\r\n if num[i]>0:\r\n val+=starting\r\n num[i]-=1\r\n ans.append(val)\r\nprint(len(ans))\r\nprint(*ans)", "def fin(n):\r\n lis = list(str(n))\r\n ll=len(lis)\r\n no=[0]*ll\r\n for i in range(ll):\r\n if lis[i]>='1':\r\n no[i]='1'\r\n else:\r\n no[i]='0' \r\n\r\n kk = int(''.join(no))\r\n return kk \r\nn = int(input())\r\nc=0\r\nans=[]\r\nwhile n>0:\r\n aa=fin(n)\r\n ans.append(aa)\r\n n-=aa\r\n c+=1\r\nprint(c)\r\nprint(*ans) ", "def main():\r\n n = input()\r\n quasib = resuelve(n)\r\n print(len(quasib))\r\n print(*quasib)\r\n \r\n\r\ndef resuelve(cadena: str) -> [int]:\r\n lista = []\r\n if not cadena:\r\n return lista\r\n else:\r\n n = int(cadena)\r\n binario = 0\r\n while n > 0:\r\n binario = get_binario(n)\r\n lista.append(binario)\r\n n = n - binario\r\n return lista\r\n\r\n\r\ndef get_binario(entrada: int) -> int:\r\n entrada = str(entrada)\r\n cifras = len(entrada)\r\n num = 0\r\n for i in entrada:\r\n cifras = cifras - 1\r\n if i != \"0\":\r\n num = num + 10**cifras\r\n return num\r\n\r\n\r\nif __name__ ==\"__main__\":\r\n main()", "import math\r\nimport sys\r\ndef Binary(n):\r\n s = bin(n)\r\n s1 = s[2:]\r\n return s1\r\ndef Decimal(n):\r\n return int(n,2)\r\n\r\ninf=1000000007\r\n\r\narr=[[0 for i in range(6)] for j in range(9)]\r\nn=int(input())\r\nidx=0\r\nc=n\r\nif(n==1000000):\r\n print(1)\r\n print(1000000)\r\n sys.exit()\r\nwhile(c>0):\r\n rem=c%10\r\n for i in range(9):\r\n if(rem>0):\r\n arr[i][5-idx]=1\r\n rem-=1\r\n else:\r\n break\r\n \r\n c=c//10\r\n idx+=1\r\n\r\nar1=[]\r\ncnt=0\r\nfor i in range(9):\r\n num=0\r\n for j in range(6):\r\n num+=(arr[i][5-j])*pow(10,j)\r\n if(num!=0):\r\n cnt+=1\r\n ar1.append(num)\r\n\r\nprint(cnt)\r\nfor i in range(cnt):\r\n print(ar1[i],end=\" \")\r\n\r\n", "#dt = {} for i in x: dt[i] = dt.get(i,0)+1\r\nimport sys;input = sys.stdin.readline\r\n#import io,os; input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #for pypy\r\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\r\n\r\ns = input().strip()\r\nmx = max(map(int,s))\r\nprint(mx)\r\nn = len(s)\r\nx = [['0']*n for i in range(mx)]\r\nfor i in range(n):\r\n for j in range(int(s[i])):\r\n x[j][i] = '1'\r\nx = [int(''.join(i)) for i in x]\r\nprint(*x)", "n=input()\r\na=[int(x) for x in n]\r\nans=[]\r\nmx=max(a)\r\nfor i in range(mx):\r\n l=[0 for x in range(len(a))]\r\n ans+=[l]\r\nfor j in range(len(a)):\r\n val=a[j]\r\n for i in range(mx):\r\n if(val>0):\r\n ans[i][j]=1\r\n val-=1\r\n else:\r\n ans[i][j]=0\r\nres=[]\r\nfor i in range(mx):\r\n v=\"\"\r\n j=0\r\n while(j<len(a) and ans[i][j]==0):\r\n j+=1\r\n while(j<len(a)):\r\n v+=str(ans[i][j])\r\n j+=1\r\n res+=[int(\"\".join(v))]\r\nprint(mx)\r\nprint(*res)", "if __name__==\"__main__\":\r\n n = input()\r\n ans = \"\"\r\n count = 0\r\n while(int(n)!=0):\r\n tmp =\"\"\r\n for i in n:\r\n if(int(i)>0):\r\n tmp += \"1\"\r\n else:\r\n tmp += \"0\"\r\n ans = ans + tmp +\" \"\r\n count += 1\r\n n = str(int(n)-int(tmp))\r\n print(count)\r\n print(ans)", "N = int(input())\nl = []\nwhile(N):\n\tn = N\n\tm = 0\n\tp = 1\n\twhile(n):\n\t\tif n % 10:\n\t\t\tm += p\n\t\tn = n // 10\n\t\tp *= 10\n\tl.append(m)\n\tN -= m\nprint(len(l))\nprint(*l)", "n = input()\r\nn=int(n)\r\nres = []\r\nwhile int(n)!=0:\r\n s=''\r\n mini=100000\r\n for i in str(n):\r\n if int(i)>=1 :\r\n s+='1'\r\n mini = min(mini,int(i))\r\n else:\r\n s+='0'\r\n for i in range(mini):\r\n res.append(s)\r\n n-=int(s)\r\nprint(len(res))\r\nprint(*res)", "def a():\r\n s = input()\r\n mx = 0\r\n for i in range(10)[::-1]:\r\n if s.count(str(i))>0:\r\n mx = i\r\n break\r\n print(mx)\r\n all_st = ''\r\n s = list(s)\r\n for k in range(mx):\r\n st = ''\r\n for i in range(len(s)):\r\n if int(s[i])>0:\r\n st+='1'\r\n s[i] = str(int(s[i])-1)\r\n elif len(st)>0:\r\n st+='0'\r\n if len(all_st)!=0:\r\n all_st+=' '\r\n all_st+=st\r\n return all_st\r\n \r\n\r\nif __name__ == '__main__':\r\n print(a())", "n=list(map(int,input()))\r\nm=max(n)\r\nprint(m)\r\nfor j in range(m):\r\n l=[]\r\n for i in n:\r\n if i>j:l.append(str(1)) \r\n else:l.append(str(0))\r\n print(int(''.join(l)))", "n = int(input())\r\nelements = []\r\n\r\nwhile n:\r\n element = ''.join(('1' if digit != '0' else '0') for digit in str(n))\r\n elements.append(element)\r\n n -= int(element)\r\n\r\nprint(len(elements))\r\nprint(*elements)", "n = int(input())\nresp = []\n\nwhile n > 0:\n cont = 0\n aux = 0\n a = n\n while a > 0:\n if a%10 > 0:\n aux += 1*10**(cont)\n a = a//10\n cont += 1\n\n resp.append(aux)\n n -= aux\n \nprint(len(resp))\nfor i in range(0, len(resp) - 1):\n print(resp[i], end = ' ')\nprint(resp[len(resp) - 1])\n\t \t\t \t \t\t\t\t\t \t\t\t\t\t \t \t\t \t", "n = input()\r\n\r\ndp = [0] * (len(n)+1)\r\n\r\nfor i in range(1,len(n)+1):\r\n dp[i] = int(n[i-1])\r\nr = [0]*10000\r\n\r\nfor i in range(1,len(n)+1):\r\n t = dp[i]\r\n e = 0\r\n y = len(n)-i \r\n for j in range(1,t+1):\r\n r[e]+=10**(y)\r\n e+=1 \r\nres = ''\r\nfor i in r:\r\n if i == 0:\r\n break\r\n res+=str(i) + ' '\r\nprint(len(res.split()))\r\nprint(res)\r\n\r\n ", "s=input();m=int(max(s));print(m)\r\nfor i in range(m):print(int(''.join('1'if int(c)>i else'0' for c in s)))\r\n", "s = input()\n\nprint(int(max(s)))\n\nfor i in range(int(max(s))):\n res = ''\n for c in s:\n if i + 1 <= int(c):\n res += '1'\n else:\n res += '0'\n print(int(res), end=' ')\nprint()\n", "n=input()\r\ni=-1;d={}\r\np=len(n)\r\nwhile i>=-p:\r\n d[-i]=int(n[i])\r\n i-=1\r\n\r\nl=[]\r\nwhile True:\r\n t=p;count_=10**9;s=\"\"\r\n while t>0: \r\n if d[t]>0:count_=min(count_,d[t]);s+=\"1\"\r\n else:s+=\"0\"\r\n t-=1\r\n if int(s)==0:break\r\n else:l+=[int(s)]*count_\r\n for i in d:\r\n if d[i]>0:d[i]-=count_\r\nprint(len(l))\r\nprint(*l)\r\n ", "x = int(input())\n\nps = []\nwhile x:\n p = 0\n l = len(str(x))\n for i, c in enumerate(str(x)):\n if c != '0':\n p += 10 ** (l - i - 1)\n x -= p\n ps.append(p)\n\nprint(len(ps))\nprint(' '.join(map(str, ps)))\n", "s=input()\r\nn=int(s)\r\nl=[]\r\nst=str(n)\r\nwhile(n>0):\r\n if(st.count('1')+st.count('0')==len(st)):\r\n l.append(int(st))\r\n n=n-int(st)\r\n else:\r\n k=\"\"\r\n for i in st:\r\n if(int(i)>1):\r\n k+='1'\r\n else:\r\n k+=i\r\n l.append(int(k))\r\n n=n-int(k)\r\n st=str(n)\r\nprint(len(l))\r\nprint(*l)", "n = int(input())\r\nres = []\r\nwhile n > 0:\r\n b = ''\r\n for i in str(n):\r\n b += str(min(int(i), 1))\r\n n -= int(b)\r\n res.append(b)\r\nprint(len(res))\r\nprint(*res)\r\n", "a = input()\r\nj = 0\r\nb = []\r\nfor i in a:\r\n if j < int(i):\r\n j = int(i)\r\nprint(j)\r\nfor i in range(j):\r\n b.append(0)\r\nmult = 1\r\nfor i in a[::-1]:\r\n for k in range(int(i)):\r\n b[k] += mult\r\n mult *= 10\r\nfor i in range(j):\r\n print(b[i], end = ' ')\r\n", "if __name__ == \"__main__\":\r\n\r\n t = int(input())\r\n\r\n a = []\r\n\r\n while t:\r\n n = t\r\n m = 0 \r\n p = 1\r\n while n:\r\n if n % 10: m+=p\r\n n = n // 10\r\n p *= 10\r\n a.append(m)\r\n t -= m\r\n a.sort()\r\n print(len(a))\r\n print(\" \".join(str(x) for x in a))\r\n", "n = int(input())\r\nl = []\r\nN= n\r\nwhile(N > 0):\r\n n = N\r\n m = 0\r\n p = 1\r\n while(n > 0):\r\n if(n % 10 != 0): \r\n m += p;\r\n p *= 10;\r\n n = n //10\r\n l.append(m)\r\n N = N - m\r\nprint(len(l))\r\nprint(*l)\r\n ", "import sys\nfrom collections import Counter\nfrom math import factorial\n\ninput = sys.stdin\noutput = sys.stdout\n\n# input = open('input.txt')\n\n\ndef read_int():\n return [int(x) for x in input.readline().rstrip().split()]\n\n[n] = read_int()\nanswer = list()\nwhile n > 0:\n x = 0\n line = str(n)\n digits = list()\n for c in line:\n digits.append(c != '0')\n digits.reverse()\n for i, d in enumerate(digits):\n if d:\n x += 10 ** i\n answer.append(x)\n n -= x\n\noutput.write('%d\\n' % len(answer))\nfirst = True\nfor x in answer:\n if first:\n first = False\n else:\n output.write(' ')\n output.write(str(x))\noutput.write('\\n')\n", "n=[int(e) for e in input()]\r\nA=[]\r\nwhile sum(n):\r\n a=\"\"\r\n for i in range(len(n)):\r\n if n[i]:\r\n n[i]-=1\r\n a+=\"1\"\r\n else:\r\n a+=\"0\"\r\n A.append(str(int(a)))\r\nprint(len(A))\r\nprint(*A)", "#! /usr/bin/python\n\nn = int(input())\na = []\n\nwhile n > 0:\n a.append(n % 10)\n n //= 10\n\nans = 0\nxs = []\n\nif not a:\n ans = 1\n xs = [0]\n\nwhile a:\n x = 0\n for i in range(len(a)):\n if a[i] > 0:\n x += 10 ** i\n a[i] -= 1\n xs.append(x)\n ans += 1\n while a and a[-1] == 0:\n a.pop()\n\nprint(ans)\nprint(' '.join(map(str, xs)))\n\n", "n = int(input())\r\nsn = str(n)\r\nl = len(sn)\r\n\r\ndef getDecimal(n):\r\n\treturn (len(str(n)) - 1)\r\n\r\ndef intAr(a):\r\n\tb = []\r\n\tfor i in a:\r\n\t\tb.append(int(i))\r\n\treturn b\r\n\r\ndef getQDNumber(number):\r\n\tinum = int(number)\r\n\t_n = intAr(number)\r\n\tn = ''\r\n\tpointer = 0\r\n\t_len = len(number)\r\n\r\n\tif inum:\r\n\t\tif inum >= 10:\r\n\t\t\twhile 1:\r\n\t\t\t\tif _n[pointer] is 0:\r\n\t\t\t\t\tn += '0'\r\n\t\t\t\telse:\r\n\t\t\t\t\t_n[pointer] -= 1\r\n\t\t\t\t\tn += '1'\r\n\r\n\t\t\t\tpointer += 1\r\n\r\n\t\t\t\tif pointer >= _len:\r\n\t\t\t\t\tbreak\r\n\t\telse:\r\n\t\t\tn = '1'\r\n\t\tif inum - int(n) >= 0:\r\n\t\t\treturn n + ' ' + str(getQDNumber(str(inum - int(n))))\r\n\treturn ''\r\n\r\nn = getQDNumber(sn)\r\nprint(len(n.split(' ')) - 1)\r\nprint(n)", "q=input()\r\ncount=0\r\narr1=[]\r\nq=int(q)\r\nt=''\r\nwhile q>0:\r\n for i in str(q):\r\n if i>'0':\r\n t+='1'\r\n else:\r\n t+='0'\r\n x=int(t)\r\n count+=1\r\n arr1.append(x)\r\n q=q-x\r\n t=''\r\n \r\nprint(count)\r\nprint(*arr1)\r\n", "def quasiBinary(n):\n ans = list()\n while n:\n tmp = str()\n for i in str(n):\n if int(i) >= 1:\n tmp += '1'\n else:\n tmp += '0'\n ans.append(tmp)\n n -= int(tmp)\n print(len(ans))\n for i in ans:\n print(i, end=' ')\n\n\nn = int(input())\nquasiBinary(n)\n", "'''input\r\n32\r\n'''\r\n#538B\r\ns = input()\r\nn = len(s)\r\ntemp = [int(i) for i in s]\r\nans = ['' for i in range(9)]\r\nfor i in temp:\r\n\tfor j in range(9):\r\n\t\tans[j] += '01'[i>j]\r\n# print(ans)\r\nans = [i for i in map(int,ans) if i]\r\nprint(len(ans))\r\nprint(*ans)\r\n\r\nquit()\r\n#698A\r\n# import numpy as np #cant import numpy on codeforces\r\nfrom sys import stdin,stdout\r\nread = lambda: map(int,stdin.readline().split())\r\nI = lambda: stdin.readline()\r\n\r\nn = int(I())\r\narr = tuple(read())\r\nmemo = {}\r\nposs = [[0],[0,1],[0,2],[0,1,2]]\r\ndp = [[10**6 for i in range(3)] for i in range(n+1)]\r\ndp[n] = [0,0,0]\r\n# print(dp)\r\nfor i in range(n-1,-1,-1):\r\n\tfor last in range(3):\r\n\t\tfor p in poss[arr[i]]:\r\n\t\t\t# print(last,p,1 if ((last and p) or p==0) else 0)\r\n\t\t\tdp[i][last] = min(dp[i][last],(1 if ((last & p) or p==0) else 0) + dp[i+1][p])\r\nprint(dp[0][0])\r\n# print(dp)\r\n", "def max_quasi_bin(n):\n quasi_bin = ''\n for i in range(len(n)):\n if(n[i] == '0'):\n quasi_bin += '0'\n else:\n quasi_bin += '1'\n return quasi_bin\n\n\nif __name__ == '__main__':\n n = input()\n quasis = []\n while n != '0':\n quasi = max_quasi_bin(n)\n quasis.append(quasi)\n n = str(int(n) - int(quasi))\n print(len(quasis))\n print(*quasis)\n\n\t \t\t \t\t \t\t \t\t \t\t\t \t\t", "n = int(input())\r\nqb = [1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, 10000, 10001, 10010, 10011, 10100, 10101, 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111, 100000, 100001, 100010, 100011, 100100, 100101, 100110, 100111, 101000, 101001, 101010, 101011, 101100, 101101, 101110, 101111, 110000, 110001, 110010, 110011, 110100, 110101, 110110, 110111, 111000, 111001, 111010, 111011, 111100, 111101, 111110, 111111, 1000000]\r\nk = [[float('inf'), 0] for _ in range(n+1)]\r\nk[0][0] = 0\r\nk[0][1] = 0\r\n\r\nfor i in range(1,n+1):\r\n for j in qb:\r\n if i-j < 0: break\r\n if k[i][0] > k[i-j][0] +1 :\r\n k[i][0] = k[i-j][0] + 1\r\n k[i][1] = j\r\n\r\n\r\nprint(k[n][0])\r\ni = n\r\nj = k[n][1]\r\nwhile i != 0:\r\n print(j, end=' ')\r\n i = i - j\r\n j = k[i][1]\r\nprint('')", "import math,sys,bisect,heapq\r\nfrom collections import defaultdict,Counter,deque\r\nfrom itertools import groupby,accumulate\r\n#sys.setrecursionlimit(200000000)\r\nint1 = lambda x: int(x) - 1\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nilele = lambda: map(int,input().split())\r\nalele = lambda: list(map(int, input().split()))\r\nilelec = lambda: map(int1,input().split())\r\nalelec = lambda: list(map(int1, input().split()))\r\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\r\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\r\nMOD = 1000000000 + 7\r\ndef Y(c): print([\"NO\",\"YES\"][c])\r\ndef y(c): print([\"no\",\"yes\"][c])\r\ndef Yy(c): print([\"No\",\"Yes\"][c])\r\n \r\nA = []\r\nold = input()\r\nwhile int(old):\r\n new = '';v= ''\r\n for i in old:\r\n if i =='0':\r\n new += i;v += i\r\n else:\r\n new += str(int(i)-1);v += '1'\r\n old= new\r\n A.append(int(v))\r\nprint(len(A))\r\nprint(*A)\r\n \r\n", "N = int(input())\nans = []\n\n\nwhile N >0:\n n = N\n m = 0\n p =1\n while n>0:\n if n%10 !=0 :\n m += p\n n //=10\n p *=10\n \n ans.append(m)\n N -=m\n \nprint(len(ans)) \nprint(*ans)", "n=int(input())\r\ns=str(n)\r\nans=[]\r\nwhile(n!=0):\r\n a=''\r\n s=str(n)\r\n for i in range(len(s)):\r\n if s[i]!='0':\r\n a+='1'\r\n else:\r\n a+='0'\r\n n=n-int(a)\r\n ans.append(int(a))\r\nprint(len(ans))\r\nprint(*ans) \r\n \r\n ", "n = int(input())\r\nk = 0\r\nl = [list() for i in range(9)]\r\nwhile n:\r\n r = n % 10\r\n k = max(k, r)\r\n n //= 10\r\n\r\n for i in range(9):\r\n if r:\r\n l[i].append('1')\r\n r -= 1\r\n else:\r\n l[i].append('0')\r\n\r\nprint(k)\r\nfor i in range(k):\r\n print(int(\"\".join(reversed(l[i]))))", "n = input()\r\nk = []\r\ns = ''\r\na = [int(i) for i in n]\r\nfor i in range(max(a)):\r\n for j in range(len(a)):\r\n if a[j] > 0:\r\n s += '1'\r\n else:\r\n s += '0'\r\n a[j] -= 1\r\n k.append(int(s))\r\n s = ''\r\nprint(len(k))\r\nfor i in range(len(k)):\r\n print(k[i], end=' ')\r\n", "n = int(input())\r\ntem = n\r\narr=[]\r\nwhile tem>0:\r\n x=tem\r\n z=0\r\n l=0\r\n while x>0:\r\n y= x%10\r\n if y>0:\r\n z= (z+1)/10\r\n else:\r\n z= z/10\r\n l+=1\r\n x=x//10\r\n z=int(z*(10**l))\r\n tem+=-z\r\n arr.append(z)\r\nprint(len(arr))\r\nfor i in arr:\r\n print(i,end=\" \")\r\n \r\n \r\n ", "a=input()\r\nb=max(map(int,a))\r\nc=[0]*9\r\nfor i in a:\r\n for j in range(9):c[j]*=10\r\n for j in range(int(i)):\r\n c[j]+=1\r\nprint(b)\r\nprint(' '.join(map(str,[i for i in c if i])))\r\n", "#Registrando informacion de Kirito\r\nunits= list(map(int,input()))[::-1]\r\n\r\nX=[0 for i in range(9)]\r\nfor digit in range(len(units)):\r\n i=units[digit]\r\n for k in range(i):\r\n X[k]+=10**digit\r\nans=''\r\nL=0\r\nfor t in X:\r\n if t!=0:\r\n L+=1\r\n ans+=str(t)+\" \"\r\nans=ans[:-1]\r\nprint(L)\r\nprint(ans)", "n=int(input())\r\nl=[]\r\nwhile n>0 :\r\n l.append(n%10)\r\n n=n//10\r\nprint(max(l))\r\nm=max(l)\r\nfor i in range(m) :\r\n ma=max(l)\r\n a=0 \r\n mu=1\r\n for j in range(len(l)) :\r\n if l[j]==ma :\r\n l[j]-=1 \r\n a+=mu \r\n mu*=10\r\n print(a,end=\" \")\r\nprint()", "n=input()\r\nif n==0:\r\n print(1)\r\n print(0)\r\nelse:\r\n a=[]\r\n t=0\r\n for i in n:\r\n t=max(t,int(i))\r\n a=[int(i)]+a\r\n print(t)\r\n while a!=[0]*len(n):\r\n ch=9999999\r\n pn=0\r\n for i in range(len(a)):\r\n if a[i]>0:\r\n a[i]-=1\r\n pn+=10**i\r\n print(pn,end=' ')\r\n \r\n \r\n\r\n \r\n\r\n##//////////////// ////// /////// // /////// // // //\r\n##//// // /// /// /// /// // /// /// //// //\r\n##//// //// /// /// /// /// // ///////// //// ///////\r\n##//// ///// /// /// /// /// // /// /// //// // //\r\n##////////////// /////////// /////////// ////// /// /// // // // //\r\n\r\n\r\n\r\n", "import sys\ninput = sys.stdin.readline\n\n'''\n\n'''\n\ndef is_quasi(num):\n return all(c == \"1\" or c == \"0\" for c in str(num))\n\nnum = int(input())\nres = []\n\nwhile not is_quasi(num):\n snum = str(num)\n\n new_num = []\n for c in snum:\n if c == \"0\":\n new_num.append(\"0\")\n else:\n new_num.append(\"1\")\n new_num = int(\"\".join(new_num))\n res.append(new_num)\n num -= new_num\n\nif num != 0:\n res.append(num)\n\nprint(len(res))\nprint(*res)", "def main():\r\n\tstring = str(input())\r\n\tarr = [ int(x) for x in string]\r\n\tmx = max(arr)\r\n\tprint(mx)\r\n\tfor _ in range(mx):\r\n\t\tres = ''\r\n\t\tfor i in range(len(arr)):\r\n\t\t\tif arr[i]>0:\r\n\t\t\t\tres+='1'\r\n\t\t\t\tarr[i]-=1\r\n\t\t\telse:\r\n\t\t\t\tres+='0'\r\n\t\tfor i in range(len(res)):\r\n\t\t\tif res[i]=='1':\r\n\t\t\t\tbreak\r\n\t\tprint(res[i:],end=' ')\r\n\r\nmain()\r\n", "n=int(input())\r\nm=[]\r\nwhile n:\r\n z=str(n)\r\n res=''\r\n \r\n for i in range(len(z)):\r\n if z[i]>'0':\r\n res+='1'\r\n else:\r\n res+='0'\r\n m.append(res)\r\n n=n-int(res)\r\n # print(n)\r\nprint(len(m))\r\nprint(*m)", "import os\r\nimport sys\r\n\r\ninput = lambda:sys.stdin.readline().rstrip(\"\\r\\n\")\r\ndef I():\r\n return input()\r\ndef II():\r\n return int(input())\r\ndef LI():\r\n return list(input())\r\ndef LII():\r\n return list(map(int, input().split()))\r\ndef MII():\r\n return map(int, input().split())\r\n\r\ninf = float(\"inf\")\r\nmod = 10**9 + 7\r\n# for _ in range(II()):\r\nn = II()\r\nans = []\r\nleft = n\r\ndef do(x):\r\n cur = str(x)\r\n t = 0\r\n for i in range(len(cur)):\r\n t *= 10\r\n if cur[i] != '0':\r\n t += 1\r\n ans.append(t)\r\n return x - t\r\nwhile left >= 10:\r\n left = do(left)\r\nif left:\r\n ans.extend([1] * left)\r\nprint(len(ans))\r\nprint(*ans)", "\r\n#sa7afy\r\n#a,b = map(int,input().split())\r\n#arr=[]\r\n#arr=list(map(int,input().split()))\r\n#arr = list(dict.fromkeys(arr))\r\n#arr.sort()\r\n#n = int(input())\r\n#for i in range():\r\n#print(*list)\r\n#sorted(arr, reverse=True)\r\n \r\n#def isPalindrome(s):\r\n #return s == s[::-1]\r\n#min(n*a,-n//m*-b,n//m*b+n%m*a),max(n*a,-n//m*-b,n//m*b+n%m*a)\r\n#import re\r\n#x=input()\r\n#z=re.search(r\"text\",x)\r\n#n=str(sum(map(int,n))) \r\n\r\n\r\nans = []\r\nn = int(input())\r\nwhile n:\r\n b = ''.join(min(i, '1') for i in str(n))\r\n \r\n n -= int(b)\r\n ans.append(b)\r\nprint(len(ans))\r\nprint(*ans)\r\n \r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n\r\n\r\n", "__author__ = 'Bian'\r\nimport math\r\nn = int(input())\r\nresult = []\r\nwhile n > 0:\r\n a = math.floor(math.log10(n))\r\n n -= 10 ** a\r\n for i in range(len(result)):\r\n if result[i] > 10**a and str(result[i])[-a-1] == '0':\r\n result[i] += 10**a\r\n break\r\n else:result.append(10**a)\r\nprint(len(result))\r\nprint(' '.join([str(x) for x in result]))", "a = list(map(int, list(input())))\nm = max(a)\nb = [0]*m\nfor i in a:\n for j in range(m):\n b[j] = b[j]*10 + (1 if j < i else 0)\n\nprint(m)\nprint(*b)\n", "n = int(input())\r\ns = str(n)\r\nans = []\r\nwhile n>0:\r\n s = list(s)\r\n for i in range(len(s)):\r\n if s[i]!='0':\r\n s[i] = '1'\r\n s = ''.join(s)\r\n ans.append(s)\r\n n -= int(s)\r\n s = str(n)\r\nprint(len(ans))\r\nprint(*ans)", "l=lambda:map(int,input().split())\r\np=lambda:int(input())\r\nss=lambda:input()\r\n#from math import log2 as c,ceil\r\n\r\nn=p()\r\nif n<2:\r\n print(1)\r\n print(n)\r\nelse:\r\n l=[]\r\n while n!=0:\r\n s=''\r\n for i in str(n):\r\n if int(i)>=2:\r\n s+='1'\r\n else:\r\n s+=i\r\n l.append(int(s))\r\n n-=int(s)\r\n print(len(l))\r\n print(*l)", "\ndef Count(n):\n\tif n == 0:\n\t\treturn 0\n\tc = Count(n // 10)\n\treturn n % 10 if n % 10 > c else c\n\ndef QNum(n):\n\tif n <= 0:\n\t\treturn\n\n\tnn = n\n\tnewN = 0\n\tstring = \"\"\n\tp = 0\n\tout = 0\n\twhile nn > 0:\n\t\td = nn % 10\n\t\tnd = d - 1 if d > 0 else 0\n\t\tndd = 1 if d > 0 else 0\n\n\t\tnn = nn // 10\n\n\t\tnewN += nd * 10 ** p\n\t\tout += ndd * 10 ** p\n\t\tp += 1\n\n\tprint(out)\n\tQNum(newN)\n\nn = int(input())\nprint(Count(n))\nQNum(n)\n\n", "import math;\r\nfrom math import log2,sqrt;\r\nfrom bisect import bisect_left,bisect_right\r\nimport bisect;\r\nimport sys;\r\nfrom sys import stdin,stdout\r\nimport os\r\nsys.setrecursionlimit(pow(10,6))\r\nimport collections\r\nfrom collections import defaultdict\r\nfrom statistics import median\r\n# input=stdin.readline\r\n# print=stdout.write\r\ninf = float(\"inf\")\r\ndef get_no(n):\r\n rem=[]\r\n while n:\r\n rem.append(n%10)\r\n n=n//10\r\n return rem;\r\nn=int(input())\r\n\r\nrem=get_no(n)\r\nans=max(rem)\r\nprint(ans)\r\nm=[0]*ans;\r\n\r\nfor i in range(len(rem)):\r\n summer=pow(10,i)\r\n for j in range(rem[i]):\r\n m[j]+=summer\r\nprint(*m)\r\n\r\n", "n = str(input())\r\nn = list(n)\r\nl = len(n)\r\nm = int(max(n))\r\nprint(m)\r\npseudo = [\"\"]*m\r\n\r\nfor i in n:\r\n i = int(i)\r\n for j in range(m):\r\n if j < i:\r\n pseudo[j]+=\"1\"\r\n else:\r\n pseudo[j]+=\"0\"\r\npseudo = [int(k) for k in pseudo]\r\npseudo = [str(k) for k in pseudo]\r\nprint(\" \".join(pseudo))\r\n", "n = input()\nd = list()\nfor c in n:\n d.append(int(c))\ncount = 0\nnums = list()\nwhile max(d) != 0:\n i = 0\n while d[i] == 0:\n i += 1\n cur_num = ''\n for j in range(i, len(d)):\n if d[j] != 0:\n d[j] -= 1\n cur_num = cur_num + '1'\n else:\n cur_num = cur_num + '0'\n nums.append(cur_num)\nprint(len(nums))\nfor cur_num in nums:\n print(cur_num, end=' ')\n \n\n", "def check(t):\r\n s=str(t)\r\n c=0\r\n for i in s:\r\n if i!='0' and i!='1':\r\n \r\n c=1\r\n break\r\n if c==0:\r\n return True\r\n return False\r\n\r\nn=int(input())\r\nd=len(str(n))\r\nc=0\r\ns=str(n)\r\nfor i in s:\r\n if i!='0' and i!='1':\r\n c=1\r\n break\r\nif c==0:\r\n print(1)\r\n print(n)\r\nelse:\r\n l=[]\r\n \r\n while n:\r\n t=n\r\n ss=str(t)\r\n st=\"\"\r\n for i in ss:\r\n if i=='0':\r\n st+=\"0\"\r\n else:\r\n st+=\"1\"\r\n n-=int(st)\r\n l.append(st)\r\n print(len(l))\r\n for i in l:\r\n print(i,end=\" \")\r\n \r\n \r\n ", "a=input()\r\na=list(a)\r\nfor i in range(len(a)):\r\n a[i]=int(a[i])\r\n#print(a)\r\nans=max(a)\r\nprint(ans)\r\nfor j in range(ans):\r\n aa=[0]*len(a)\r\n for i in range(len(a)):\r\n \r\n if a[i]!=0:\r\n aa[i]=1\r\n a[i]-=1\r\n \r\n \r\n print(int(''.join(str(x) for x in aa)),end=\" \")", "mod = 1000000007\r\nii = lambda : int(input())\r\nsi = lambda : input()\r\ndgl = lambda : list(map(int, input()))\r\nf = lambda : map(int, input().split())\r\nil = lambda : list(map(int, input().split()))\r\nls = lambda : list(input())\r\ns = si()\r\nn = len(s)\r\nmx = max(int(i) for i in s)\r\nl = [[0 for i in range(n)] for j in range(mx)]\r\nfor i in range(n):\r\n x=int(s[i])\r\n for j in range(x):\r\n l[j][i] = 1\r\nprint(len(l))\r\nfor i in l:\r\n x = i.index(1)\r\n print(''.join(str(i[k]) for k in range(x, n)), end=' ')\r\n", "n = input()\r\nl = len(n)\r\nm = int(max(n))\r\nmatrix = []\r\nfor i in range(m):\r\n matrix.append([0]*l)\r\n\r\nfor j in range(l):\r\n for k in range(int(n[j])): \r\n matrix[k][j] = 1\r\n\r\nfor i in range(m):\r\n while matrix[i][0] == 0:\r\n matrix[i].pop(0)\r\n matrix[i] = \"\".join(map(str, matrix[i]))\r\n \r\n\r\nprint(len(matrix))\r\nprint(\" \".join(map(str, matrix)))", "n = int(input())\r\narr = []\r\nk = 0\r\nwhile n>0:\r\n m = \"\"\r\n for i in str(n):\r\n if i>'0':\r\n m+='1'\r\n else:\r\n m+='0'\r\n n = n-int(m)\r\n k+=1\r\n arr.append(int(m))\r\nprint(k)\r\nprint(*arr)\r\n", "#\t!/bin/env python3\r\n#\tcoding: UTF-8\r\n\r\n\r\n#\t✪ H4WK3yE乡\r\n#\tMohd. Farhan Tahir\r\n#\tIndian Institute Of Information Technology and Management,Gwalior\r\n\r\n#\tQuestion Link\r\n#\thttps://codeforces.com/problemset/problem/538/B\r\n#\r\n\r\n# ///==========Libraries, Constants and Functions=============///\r\n\r\n\r\nimport sys\r\n\r\ninf = float(\"inf\")\r\nmod = 1000000007\r\n\r\n\r\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\r\n\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().split())\r\n\r\n\r\ndef input(): return sys.stdin.readline()\r\n\r\n# ///==========MAIN=============///\r\n\r\n\r\ndef precompute(x):\r\n while x > 0:\r\n d = x % 10\r\n if d != 0 and d != 1:\r\n return False\r\n x //= 10\r\n return True\r\n\r\n\r\ndef main():\r\n coins = []\r\n for i in range(int(pow(10, 6))+1):\r\n if precompute(i) == True:\r\n coins.append(i)\r\n # print(coins)\r\n # print(len(coins))\r\n n = int(input())\r\n dp = [inf for _ in range(n+1)]\r\n opti = [0 for _ in range(n+1)]\r\n dp[0] = 0\r\n for i in range(1, n+1):\r\n for j in coins:\r\n if j > i:\r\n break\r\n if 1+dp[i-j] < dp[i]:\r\n dp[i] = 1+dp[i-j]\r\n opti[i] = j\r\n print(dp[n])\r\n op = []\r\n i = n\r\n while i != 0:\r\n op.append(opti[i])\r\n i -= opti[i]\r\n print(*op)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "#In the name of Allah\r\n\r\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\n\r\nn = list(input()[:-1])\r\n\r\nma = \"0\"\r\ns = 0\r\nfor i in n:\r\n if i > ma:\r\n ma = i\r\n s += int(i)\r\n\r\nstdout.write(ma + \"\\n\")\r\n\r\n\r\n\r\nwhile s:\r\n f = False\r\n ans = \"\"\r\n for i in range(len(n)):\r\n d = \"0\"\r\n if not f and n[i] == \"0\":\r\n n.pop(i)\r\n break\r\n elif n[i] != \"0\":\r\n s -= 1\r\n d = \"1\"\r\n f = True\r\n n[i] = str(int(n[i]) - 1)\r\n \r\n ans += d\r\n if f:\r\n stdout.write(ans + \" \")\r\n", "n=input()\r\nm=int(max(n))\r\nprint(m)\r\nd={}\r\nfor i in range(len(n)):\r\n d[i]=int(n[i])\r\nfor i in range(m):\r\n c=''\r\n for j in range(len(n)):\r\n if d[j]>0:\r\n c+='1'\r\n d[j]-=1\r\n else:\r\n c+='0'\r\n print(int(c),end=' ')\r\nprint()", "s = input()\r\nlst = []\r\nfor i in s:\r\n lst.append(int(i))\r\nlst2 = [\"\"]*max(lst)\r\nn = max(lst)\r\nm = len(lst)\r\nlst = lst[::-1]\r\nfor i in lst:\r\n for j in range(i):\r\n lst2[j] = \"1\" + lst2[j]\r\n for j in range(i,n):\r\n lst2[j] = \"0\" + lst2[j]\r\nfor i in range(n):\r\n curr = lst2[i]\r\n index = 0\r\n for j in range(m):\r\n if curr[j] == \"1\":\r\n index = j\r\n break\r\n lst2[i] = curr[index:]\r\nprint(n)\r\nprint(\" \".join(lst2))", "n=int(input())\r\n\r\na=[]\r\nwhile n:\r\n m=n\r\n x=0;k=1\r\n while m:\r\n r=m%10\r\n m//=10\r\n\r\n if r:\r\n x+=(1*k)\r\n k*=10\r\n\r\n n-=x\r\n a.append(x)\r\n\r\nprint(len(a))\r\nfor i in range(len(a)):\r\n print(a[i],end=' ')", "n = int(input())\r\nstr_n = str(n)\r\n\r\nnums = []\r\nfor i in range(max([int(i) for i in str_n])):\r\n nums.append([])\r\n for __ in range(len(str_n)):\r\n nums[i].append('0')\r\n#print(nums)\r\n\r\nfor i in range(len(str_n)):\r\n c = int(str_n[i])\r\n #print(i, c)\r\n for j in range(c):\r\n nums[j][i] = '1'\r\n #print(nums) \r\n\r\nans = []\r\nfor i in nums: ans.append(int(''.join(i)))\r\n\r\nprint(len(ans))\r\nfor i in ans: print(i, end=' ')\r\nprint()", "ans=[]\ndef reduce(x):\n ans=''\n for i in x:\n if int(i)>1:\n ans+='1'\n else:\n ans+=i\n return int(ans)\ndef res(x):\n global ans\n m=reduce(str(x))\n ans.append(m)\n if m==x:\n return 1\n else:\n x=x-m\n return 1+res(x)\nn=int(input())\nprint(res(n))\nfor i in ans:\n print(i,end= ' ')\n\t\t \t \t \t \t \t\t \t \t \t \t", "res=[]\r\ndef solve(n):\r\n global res\r\n if n==0:\r\n return\r\n ans=\"\"\r\n for x in str(n):\r\n if x=='0':\r\n ans+=\"0\"\r\n else:\r\n ans += '1'\r\n\r\n res.append(ans)\r\n solve(n-int(ans))\r\n\r\n\r\nn=int(input())\r\nsolve(n)\r\nprint(len(res))\r\nfor x in res:\r\n print(x,end=\" \")\r\n", "n = int(input())\r\n\r\ndef f(k):\r\n b, c = 0, 10\r\n for _i in range(7):\r\n i = 10 ** _i\r\n if int(k / i) % 10:\r\n b += i\r\n c = min(c, int(k / i) % 10)\r\n return b, c\r\n\r\nl = []\r\nwhile n > 0:\r\n l.append(f(n))\r\n n -= l[-1][0] * l[-1][1]\r\n\r\nprint(sum(map(lambda x: x[1], l)))\r\nprint(' '.join(map(lambda x: ' '.join([str(x[0])] * x[1]), l)))\r\n", "n = input()\n\nnumbs = [\"\"]*9\n\nfor k in range(9):\n for j in range(len(n)):\n if int(n[j]) >= (k+1):\n numbs[k] += \"1\"\n else:\n numbs[k] += \"0\"\n\ns = 0\nres = \"\"\n\nfor k in range(9):\n if int(numbs[k]) != 0:\n s += 1\n res += (str(int(numbs[k])) + \" \")\n\nprint(s)\nprint(res)\n\n", "n=int(input())\r\nans=[]\r\nwhile n:\r\n\td=''\r\n\tfor i in str(n):\r\n\t\td+=min(i, '1')\r\n\tn-=int(d)\r\n\tans.append(d)\r\nprint(len(ans))\r\nfor x in ans:\r\n\tprint(x, end=\" \")\r\nprint()", "a=list(input())\r\nn=len(a)\r\ns=[]\r\nfor i in range(0,n):\r\n a[i]=int(a[i])\r\nb=[(['0'] * 9) for i in range(n)]\r\nfor i in range(0,n):\r\n x=a[i]\r\n for j in range(0,x):\r\n b[i][j]='1'\r\n \r\nfor i in range(0,9):\r\n c=0\r\n st=''\r\n for j in range(0,n):\r\n if(b[j][i]=='1'):\r\n c+=1\r\n if(c>0):\r\n st+=b[j][i]\r\n if(st==''):\r\n break\r\n else:\r\n s.append(st)\r\nprint(len(s))\r\nfor i in range(0,len(s)):\r\n print(s[i],end=' ')", "from collections import defaultdict\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n ans_list = []\r\n while n > 0:\r\n l = list(map(int, str(n)))\r\n d = [0] * len(l)\r\n for i in range(len(l)):\r\n d[i] = 1 if l[i] >= 1 else 0\r\n l[i] -= d[i]\r\n\r\n n = int(\"\".join(map(str, l)))\r\n ans_list.append(int(\"\".join(map(str, d))))\r\n\r\n print(len(ans_list))\r\n print(*ans_list, sep=\" \")\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "n = int(input())\r\nans=[]\r\nwhile n>0:\r\n b=''\r\n for i in str(n):\r\n if i!='0':b+='1'\r\n else:b+='0'\r\n #print(b)\r\n n-=int(b)\r\n ans.append(b)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "n = list(map(int, list(input())))\r\n_max = max(n)\r\nprint(_max)\r\nfor i in range(_max):\r\n\tl = [0] * len(n)\r\n\tfor j in range(len(n)):\r\n\t\tif n[j] > 0:\r\n\t\t\tl[j] = 1\r\n\t\t\tn[j] -= 1\r\n\t\telse:\r\n\t\t\tl[j] = 0\r\n\tfor j in range(len(l)):\r\n\t\tif l[j] == 1:\r\n\t\t\tl = l[j:]\r\n\t\t\tbreak\r\n\tprint(''.join(list(map(str, l))), end = ' ')\r\nprint()\r\n", "#!/usr/bin/env python3\n\nn = input()\nans = max(int(c) for c in n)\nprint(ans)\nvl = len(n)\nn = int(n)\nfor i in range(ans):\n x = 0\n for j in range(vl):\n dig = n % (10 ** (j + 1)) // (10 ** j)\n if dig != 0:\n n -= 10 ** j\n x += 10 ** j\n print(x, end=\" \")\n", "def solve(s):\r\n a = list(map(int, s))\r\n out = str(max(a)) + '\\n'\r\n for i in range(max(a)):\r\n ts = ''\r\n for x in a:\r\n if x > i: ts += '1'\r\n else : ts += '0'\r\n out += ts.lstrip('0') + ' '\r\n return out\r\n\r\nif __name__ == \"__main__\":\r\n s = input()\r\n print(solve(s))\r\n", "n = int(input())\r\nans = []\r\nwhile n:\r\n b = ''.join(str(int(i != '0')) for i in str(n))\r\n n -= int(b)\r\n ans.append(b)\r\n\r\nprint(len(ans))\r\nprint(*ans)", "import bisect\r\nn=int(input())\r\narr=list([1,10,11,100])\r\nnum=100\r\nwhile num<=n:\r\n #if ctr==(prv*2)+1:num*=10;lst.append(num);prv=ctr-1\r\n si=len(arr)-1\r\n for i in range(si):\r\n if num+arr[i]<=n:arr.append(num+arr[i])\r\n num*=10\r\n if num<=n:arr.append(num)\r\n\r\ndp=[10000000000]*(n+1)\r\ndp[0]=0\r\nans=[0]*(n+1)\r\nfor i in arr:\r\n for j in range(i,n+1):\r\n if dp[j]>dp[j-i]+1:\r\n dp[j]=dp[j-i]+1\r\n ans[j]=i\r\nprint(dp[n])\r\nwhile n:\r\n print(ans[n],end=' ')\r\n n-=ans[n]", "quasiNumbers=[]\r\nnum=input()\r\nl=len(num)\r\nm=n=int(num)\r\nx=max(num)\r\nmaxi=int(x)\r\nprint(x)\r\nfor i in range(maxi):\r\n j=l-1\r\n \r\n s=0\r\n while j>=0:\r\n k=n//(10**j)\r\n n=n%(10**j)\r\n if k>0:\r\n s=s*10+1\r\n else:\r\n s=s*10\r\n j-=1\r\n f=str(s)\r\n quasiNumbers.append(f)\r\n n=m-s\r\n m=n\r\nT=' '.join(quasiNumbers)\r\nprint(T)", "n = int(input()) \r\nl = []\r\nwhile n > 0: \r\n l.append(n % 10) \r\n n //= 10 \r\n\r\nz = max(l)\r\ntt = [0] * z \r\nfor i in range(len(l) - 1, -1, -1):\r\n for j in range(l[i]): \r\n tt[j] *= 10 \r\n tt[j] += 1 \r\n for j in range(l[i], z): \r\n tt[j] *= 10 \r\n\r\nprint(z) \r\nans = str(tt.pop(0)) \r\nfor i in tt: \r\n ans += f\" {i}\" \r\nprint(ans)\r\n", "a = int(input())\r\nans = []\r\nwhile(a > 0):\r\n t = a\r\n now = 0\r\n x = 1\r\n while(t > 0):\r\n if t % 10 > 0:\r\n now = now + x\r\n x = x * 10\r\n t = t // 10\r\n ans = ans + [now]\r\n a = a - now\r\nprint(len(ans))\r\nfor index in range(len(ans)):\r\n if index == len(ans) - 1:\r\n print(ans[index])\r\n else:\r\n print(ans[index],end = ' ')\r\n", "k = list(map(lambda i :int(i),list(input())))\r\nv =[]\r\nwhile sum(k)>0:\r\n\ts=\"\"\r\n\tfor i in range(len(k)):\r\n\t\tif k[i]>0:\r\n\t\t\tk[i]-=1\r\n\t\t\ts+=\"1\"\r\n\t\telse:\r\n\t\t\ts+=\"0\"\r\n\tv.append(int(s))\r\nprint(len(v))\r\nprint(*v)", "from math import log10,floor,ceil\r\nn = int(input())\r\ndef get_list(x):\r\n l = []\r\n k = floor(log10(x))+1\r\n for i in range(k):\r\n a = x%10\r\n x = (x - a)//10\r\n l.append(a)\r\n return l\r\nl = get_list(n)\r\nk = max(l)\r\nprint(k)\r\nwhile(sum(l)>0):\r\n m = 0\r\n for i in range(len(l)):\r\n if l[i] > 0:\r\n l[i]-=1\r\n m+=10**i\r\n print(m,end=' ')", "\r\nif __name__==\"__main__\":\r\n s=str(input())\r\n# print(s)\r\n\r\n\r\n mx=0\r\n for i in range(len(s)):\r\n mx=max(mx,ord(s[i])-ord('0'))\r\n\r\n \r\n print(mx)\r\n\r\n\r\n dp=[ [ '0' for i in range(len(s)) ] for y in range(mx)]\r\n\r\n \r\n for i in range(len(s)):\r\n for j in range(ord(s[i])-ord('0')):\r\n dp[j][i]='1'\r\n\r\n \r\n for i in range(mx):\r\n st=''.join(dp[i]) \r\n print(st.lstrip(\"0\"),end=\" \")\r\n \r\n \r\n \r\n\r\n \r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\nres = []\r\nwhile n != 0:\r\n s = str(n)\r\n x = str()\r\n for c in s:\r\n if c == '0':\r\n x += '0'\r\n else:\r\n x += '1'\r\n res.append(int(x))\r\n n -= int(x)\r\nprint(len(res))\r\nprint(' '.join(map(str,res)))", "n=int(input())\r\nf=[]\r\nwhile n!=0:\r\n k=''\r\n for i in str(n):\r\n if i!='0':k+='1'\r\n else:\r\n k+='0'\r\n k=int(k)\r\n n-=k\r\n f.append(k)\r\nprint(len(f))\r\nfor i in range(len(f)):\r\n print(f[i],end=' ')", "n = int(input())\r\na = []\r\nwhile n > 0:\r\n\td = int(''.join(min(_, '1') for _ in str(n)))\r\n\tn -= d;\r\n\ta += [d];\r\nprint(len(a))\r\nprint(' '.join(map(str, a)))\r\n", "answer = []\nn = input()\nn = int(n)\nwhile n:\n temp, num, m = n, 0, 1\n temp = int(temp)\n while temp:\n if temp % 10:\n num += m\n temp = temp // 10\n m = m * 10\n answer.append(num)\n n = n - num\nprint(len(answer))\nfor i in range (0, len(answer)):\n print(answer[i], end = \" \")\nprint()\n\t \t\t \t \t \t\t \t\t \t\t \t\t\t \t\t", "n = input()\nm = 0\nfor i in n:\n if int(i) > m:\n m = int(i)\n\nl = len(n)\nt = [['0']*l for i in range(m)]\nfor i in range(l):\n for j in range(int(n[i])):\n t[j][i] = '1'\n \nprint(m)\nfor i in range(m-1):\n s = ''\n for j in t[i]:\n s += j\n print(int(s), end = ' ')\n \ns = ''\nfor j in t[m-1]:\n s += j\nprint(int(s))", "n = input()\r\n\r\nans = []\r\n\r\nwhile int(n) != 0:\r\n t = \"\"\r\n for i in n:\r\n if int(i) > 0:\r\n t += \"1\"\r\n else:\r\n t += \"0\"\r\n \r\n ans.append(int(t))\r\n n = str(int(n) - int(t))\r\n\r\nprint(len(ans))\r\nprint(*ans)", "# LUOGU_RID: 91256099\nxa=[*map(int,input())]\na=[int(\"\".join('01'[x>i] for x in xa)) for i in range(max(xa))]\nprint(len(a))\nprint(*a)", "import sys\r\n\r\ndef get(n):\r\n a = [0] * 10\r\n for i in range(num, -1, -1):\r\n a[i] = n % 10\r\n n //= 10\r\n ans = 0\r\n for i in range(0, num + 1):\r\n ans *= 10\r\n if a[i] > 0:\r\n ans += 1\r\n return ans\r\n\r\nnum = 8\r\nn = int(input())\r\n\r\nv = []\r\nwhile n > 0:\r\n x = get(n)\r\n v.append(x)\r\n n -= x\r\n\r\nprint(len(v))\r\nv.sort()\r\nfor x in v:\r\n print(x, end=' ')\r\nprint()\r\n", "if __name__ == '__main__':\r\n n = str(input())\r\n v = list()\r\n for i in range(1, 10):\r\n can = str()\r\n for j in n:\r\n if int(j) >= i:\r\n can += '1'\r\n else:\r\n if len(can) > 0:\r\n can += '0'\r\n if len(can) > 0:\r\n v.append(can)\r\n print(len(v))\r\n print(' '.join(v))\r\n", "def main():\r\n N = int(input())\r\n a = []\r\n while N:\r\n num = N\r\n counter = 0\r\n count = 1\r\n while num:\r\n if num % 10:\r\n counter += count\r\n num //= 10\r\n count *= 10\r\n a.append(counter)\r\n N -= counter\r\n \r\n print(len(a))\r\n a.sort()\r\n for item in a:\r\n print(int(item), end=\" \")\r\nmain()", "# region \r\n# def solve(n):\r\n# ans = [0]\r\n# choices = [\"a\", \"b\", \"c\", \"d\"]\r\n# def dfs(i, cur):\r\n# if i == n and i != 0 and cur == \"d\":\r\n# ans[0] += 1; return\r\n# if i > n:\r\n# return\r\n# for x in choices:\r\n# if x == cur:\r\n# continue\r\n# dfs(i + 1, x)\r\n# dfs(0, \"d\")\r\n# return ans[0]\r\n# mod = 10**9 + 7\r\n# n = 10**7\r\n# print(solve(n) % mod)\r\n# n = int(input())\r\n\r\n# endregion\r\n\r\ndef solve(n):\r\n cur_num = str(n)\r\n path = []\r\n while int(cur_num) > 0:\r\n sub = \"\"\r\n for i in range(len(cur_num)):\r\n if cur_num[i] > \"0\":\r\n sub += \"1\"\r\n else:\r\n sub += \"0\"\r\n path.append(sub)\r\n cur_num = str(int(cur_num) - int(sub))\r\n \r\n return len(path), path\r\n\r\n\r\nn = int(input())\r\nc, path = solve(n)\r\nprint(c)\r\nprint(*path)\r\n", "n = int(input())\r\nnums= str(n)\r\nm = -1\r\nfor i in nums:\r\n\tm = max(m,int(i))\r\nans = [[0 for i in range(len(nums))]for j in range(m)]\r\nc = 0\r\nfor i in nums:\r\n\tcur = int(i)\r\n\tfor i in range(cur):\r\n\t\tans[i][c] = 1\r\n\tc+=1\r\nprint(len(ans))\r\nfor i in ans:\r\n\tc = ''\r\n\tfor j in i:\r\n\t\tc+=str(j)\r\n\tprint(int(c))", "n=input()\r\nans=0\r\nnumber=[]\r\nfor i in n:\r\n ans=max(ans,int(i))\r\n number.append(int(i))\r\nprint(ans)\r\ncurr=ans \r\nsoln=[]\r\nwhile(curr):\r\n temp=''\r\n for i in range(len(number)):\r\n if(number[i]==curr):\r\n number[i]-=1\r\n temp+='1'\r\n else:\r\n temp+='0'\r\n soln.append(temp)\r\n curr-=1\r\nfor i in soln:\r\n one=False\r\n for j in i:\r\n if(j=='1' or one ):\r\n print(j,end=\"\")\r\n if(j=='1'):\r\n one=True\r\n print(\" \",end=\"\")\r\n \r\n ", "ans = []\r\nn = int(input())\r\nwhile n:\r\n d = ''.join(min(i, '1') for i in str(n))\r\n n -= int(d)\r\n ans.append(d)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "import sys\r\ninput = sys.stdin.readline\r\nx = str(int(input()))\r\nli = []\r\nfor i in x:\r\n\tli.append(int(i))\r\ny = max(li)\r\nli2 = []\r\nfor i in range(y):\r\n\tstr1 = ''\r\n\tfor j in range(len(x)):\r\n\t\tif li[j] >0:\r\n\t\t\tstr1 += str(1)\r\n\t\t\tli[j]-=1\r\n\t\telse:\r\n\t\t\tstr1 += str(0)\r\n\tli2.append(int(str1))\r\nprint(y)\r\nprint(*li2)", "from sys import stdin\r\n# import math\r\n# import heapq\r\n# from collections import deque,Counter,defaultdict\r\n# from itertools import permutations,combinations,combinations_with_replacement\r\n# from operator import itemgetter\r\n# from functools import reduce\r\n\r\n\r\ndef ii(): return int(stdin.readline())\r\ndef mi(): return map(int, stdin.readline().split())\r\ndef li(): return list(mi())\r\ndef si(): return stdin.readline()\r\n\r\nt = 1\r\n# t = ii()\r\nfor _ in range(t):\r\n N = ii()\r\n ans = []\r\n while N: #32\r\n n = N #32\r\n summands = 0\r\n p = 1\r\n while n:\r\n if n%10!=0: \r\n summands+=p\r\n p*=10\r\n n//=10\r\n N-=summands\r\n ans.append(summands)\r\n \r\n print(len(ans))\r\n print(*ans)\r\n\r\n", "s=input()\r\na=[int(\"\".join((int(x)>i and '1' or '0' for x in s))) for i in range(max(map(int,s)))]\r\nprint(len(a))\r\nprint(*a)", "a = list(map(int, input()))\r\nres = []\r\ntt = [0] * len(a)\r\nwhile a != tt:\r\n\tt = ['0'] * len(a)\r\n\tfor i, x in enumerate(a):\r\n\t\tif x > 0:\r\n\t\t\tt[i] = '1'\r\n\t\t\ta[i] -= 1\r\n\tres.append(\"\".join(t).lstrip('0'))\r\nprint(len(res))\r\nprint(\" \".join(res))\r\n", "n = int(input())\r\nk = []\r\nwhile n:\r\n k.insert(0, n % 10)\r\n n //= 10\r\ncnt = max(k)\r\n\r\nans = [0] * cnt\r\nfor i in range(cnt):\r\n for j in k:\r\n ans[i] = ans[i] * 10 + (i < j)\r\nprint(cnt)\r\nprint(*ans)\r\n", "ans = []\nn = int(input())\nwhile n:\n d = \"\"\n for i in str(n):\n d += min(i, \"1\")\n n -= int(d)\n ans.append(d)\nprint(len(ans))\nprint(*ans)", "#This code is contributed by Siddharth\r\n# import time\r\n# import heapq\r\n# import sys\r\n# import math\r\nfrom collections import *\r\n# from heapq import *\r\n# import math\r\n# import bisect\r\n# from itertools import *\r\n# import math\r\ninf=10**9\r\nmod=10**9+7\r\n# input=sys.stdin.readline\r\n\r\ndef gcd(a, b):\r\n if b == 0:\r\n return a\r\n else:\r\n return gcd(b, a % b)\r\n\r\n#\r\n# def lcm(a, b):\r\n# return (a * b) // gcd(a, b)\r\n#\r\n#\r\n# def ncr(n, r):\r\n# return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\r\n#\r\n#\r\n# def npr(n, r):\r\n# return math.factorial(n) // math.factorial(n - r)\r\n#\r\n#\r\n# def seive(n):\r\n# primes = [True] * (n + 1)\r\n# ans = []\r\n#\r\n# for i in range(2, n):\r\n# if not primes[i]:\r\n# continue\r\n#\r\n# j = 2 * i\r\n# while j <= n:\r\n# primes[j] = False\r\n# j += i\r\n#\r\n# for p in range(2, n + 1):\r\n# if primes[p]:\r\n# ans += [p]\r\n#\r\n# return ans\r\n#\r\n\r\n\r\nn=int(input())\r\ncnt=0\r\nans=[]\r\nwhile n:\r\n num=0\r\n temp=str(n)\r\n for i in temp:\r\n if i=='0':\r\n num=num*10+int(i)\r\n else:\r\n num=num*10+1\r\n ans.append(num)\r\n n-=num\r\n cnt+=1\r\nprint(cnt)\r\nprint(*ans)", "x=[]\r\nfor i in input():\r\n\tx += [int(i)]\r\nl=[]\r\nwhile len(x):\r\n\td = 0\r\n\tfor i in range(len(x)):\r\n\t\tif x[i] > 0:\r\n\t\t\td += int(10**(len(x) - i - 1))\r\n\t\t\tx[i] -= 1\r\n\tl += [d]\r\n\twhile len(x) and x[0] == 0:\r\n\t\t\tx.pop(0)\r\n\t\t\r\nprint(len(l))\r\nprint(*l)", "from collections import Counter,defaultdict,deque\r\nimport heapq as hq\r\nfrom itertools import count, islice\r\n\r\n#alph = 'abcdefghijklmnopqrstuvwxyz'\r\n#from math import factorial as fact\r\nimport math\r\nimport sys\r\ninput=sys.stdin.readline\r\n#print=sys.stdout.write\r\n#tt = int(input())\r\n#total=0\r\n#n = int(input())\r\n#n,m,k = [int(x) for x in input().split()]\r\n#n = int(input())\r\n#l,r = [int(x) for x in input().split()]\r\nn = str(int(input()))\r\ndp = [['0']*len(n) for i in range(10)]\r\nfor i in range(len(n)):\r\n for j in range(int(n[i])):\r\n dp[j][i] = '1'\r\nprint(max(n))\r\nfor el in dp:\r\n num = ''.join(el)\r\n if '1' in num:\r\n print(num.lstrip('0'),end=' ')\r\n", "\r\nn = int(input())\r\nans = []\r\n\r\nwhile n > 0:\r\n buf = ''\r\n for i in str(n):\r\n if i != '0':\r\n buf+='1'\r\n else:\r\n buf+='0'\r\n ans.append(buf)\r\n n-=int(buf)\r\n \r\nprint (len(ans))\r\nprint (' '.join(map(str,ans)))\r\n", "n = int(input())\r\n\r\ndef dp(x):\r\n if x <= 9:\r\n return [1] * x\r\n \r\n ans = []\r\n while x > 0:\r\n s = str(x)\r\n m = len(s)\r\n num = 0\r\n ans_str = \"\"\r\n for i in range(m):\r\n if s[i] >= '1':\r\n ans_str += \"1\"\r\n num += 10 ** (m - i - 1)\r\n else:\r\n ans_str += \"0\"\r\n ans.append(num)\r\n x -= num\r\n \r\n ans.sort()\r\n return ans\r\n\r\nresult = dp(n)\r\nprint(len(result))\r\nprint(*result)\r\n", "n = input()\n\nanswer = []\nwhile(int(n)):\n temp = 0\n for digitIndex in range(0, len(n)):\n digit = int(n[digitIndex])\n if (digit):\n increase = pow(10, len(n) - digitIndex - 1)\n temp += increase\n answer.append(temp)\n n = str(int(n) - temp)\n\nprint(len(answer))\nprint(\" \".join([str(el) for el in answer]))\n", "n=int(input())\r\ndd={1:0,10:0,100:0,1000:0,10000:0,100000:0,1000000:0}\r\np=str(n)\r\nfor i in range(len(p)):\r\n d=len(str(n))-i\r\n el=p[i]\r\n sifir_say=d-1\r\n kk=10**sifir_say\r\n dd[kk]+=int(p[i])\r\nres=[]\r\nwhile True:\r\n pp=0\r\n for i in dd:\r\n if dd[i] > 0:\r\n dd[i]-=1\r\n pp+=i\r\n if pp == 0:\r\n break\r\n else:res.append(pp)\r\nprint(len(res))\r\nprint(*res)", "def res(arr):\n s = \"\"\n for item in arr:\n s += item\n return int(s)\n\n\ns = input()\nn = len(s)\nm = max(int(c) for c in s)\nx = [[\"0\" for j in range(n)] for i in range(m)]\nfor j in range(n):\n for i in range(int(s[j])):\n x[i][j] = \"1\"\n\nprint(m)\nfor item in x:\n print(res(item), end=\" \")\n", "s = input()\r\ndig = len(s)\r\nfinState = '0'*dig\r\nres = []\r\n\r\nwhile s != finState:\r\n nextS = []\r\n for x in s:\r\n if x == '0':nextS.append('0')\r\n else : nextS.append(str(int(x) - 1))\r\n \r\n diff = int(s) - int(''.join(nextS))\r\n res.append(diff)\r\n s = ''.join(nextS)\r\n\r\n\r\nprint(len(res))\r\nprint(*res)\r\n\r\n", "l=lambda:map(int,input().split())\r\np=lambda:int(input())\r\nss=lambda:input()\r\n#from math import log2 as c,ceil\r\n\r\nn=p()\r\nl=[]\r\nwhile n!=0:\r\n s=''\r\n for i in str(n):\r\n s+=str(min(int(i),1))\r\n l.append(s)\r\n n-=int(s)\r\nprint(len(l))\r\nprint(*l)", "l=list(map(int,list(input())))\r\nc=[]\r\nt=len(l)\r\nfor x in range(9):\r\n s=''\r\n for x in range(t):\r\n if l[x]>0:\r\n l[x]-=1\r\n s+='1'\r\n else: s+='0'\r\n c.append(int(s))\r\n if c[-1]==0: c.pop();break\r\nprint(len(c))\r\nprint(*c)", "def solve1(n):\r\n r = []\r\n\r\n while n > 0:\r\n t = int(\"\".join([\"0\" if x == \"0\" else \"1\" for x in str(n)]))\r\n n -= int(t)\r\n r.append(t)\r\n\r\n print(len(r))\r\n print(\" \".join(map(str, r)))\r\n\r\nif __name__ == \"__main__\":\r\n num = int(input())\r\n solve1(num)", "n=int(input())\r\nk=0\r\nS1=[]\r\nS=str(n)\r\nS2=[]\r\nwhile sum(S1)<n :\r\n v=''\r\n for i in range(len(S)) :\r\n if S[i]=='0' and v!='' :\r\n v=v+S[i]\r\n else :\r\n if S[i]!='0' :\r\n v=v+'1'\r\n S=S[:i]+str(int(S[i])-1)+S[i+1:]\r\n if v!='' :\r\n S1.append(int(v))\r\n\r\n \r\n k=k+1\r\nprint(k)\r\nfor i in range(k) :\r\n S2.append(str(S1[i]))\r\nprint(' '.join(S2))\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\n", "n = int(input())\r\nb = [1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110\r\n , 1111, 10000, 10001, 10010, 10011, 10100, 10101\r\n , 10110, 10111, 11000, 11001, 11010, 11011, 11100, 11101, 11110, 11111,100000\r\n , 100001, 100010, 1000011, 100100, 100101, 100110, 100111, 101000, 101001\r\n , 101010, 101011, 101100, 101101, 101110, 101111, 110000, 110001, 110010,\r\n 110011, 110100, 110101, 110110, 110111, 111000, 111001, 111010, 111011,\r\n 111100, 111101, 111110, 111111]\r\nb = b[::-1]\r\n\r\ndef FindNumber(n):\r\n m = 0\r\n while n != 0:\r\n if n % 10 > m:\r\n m = n % 10\r\n n = int(n/10)\r\n return m\r\n\r\nnumber = FindNumber(n)\r\nprint(number)\r\n\r\ndef FindNum (n,number):\r\n global b\r\n if number != FindNumber(n): return -1\r\n if number == 1:\r\n print(n,end = \" \")\r\n return 1\r\n for i in b:\r\n if i > n: continue\r\n else:\r\n num = FindNum(n - i,number - 1)\r\n if num == -1 : continue\r\n else:\r\n print(i,end = \" \")\r\n break\r\n \r\n\r\nFindNum(n,number)\r\n", "\r\nfrom math import ceil, gcd, inf, sqrt\r\nfrom os import P_DETACH, rename\r\n\r\nimport sys\r\n\r\ndef pre():\r\n ans=[]\r\n for i in range(2**6):\r\n ans.append( int ( bin(i)[2:]))\r\n \r\n return ans\r\n\r\n\r\ndef pro(n):\r\n ans=0\r\n lst=[]\r\n while(n):\r\n x=n\r\n k=0\r\n m=1\r\n while(x):\r\n rem=x%10\r\n if(rem):\r\n k+=m \r\n m=m*10\r\n x=x//10\r\n lst.append(k)\r\n n=n-k\r\n print(len(lst))\r\n print(*lst)\r\n\r\nt=1\r\nfor i in range(t):\r\n n=int(input())\r\n pro(n)", "n=int(input())\r\ndef nearest(n):\r\n instr=str(n)\r\n length=len(instr)\r\n to_ret=10**(length-1)\r\n for i in range(1, length):\r\n if int(instr[i])>=1:\r\n to_ret+=10**(length-i-1)\r\n\r\n return to_ret\r\ni=0\r\nchisla=[]\r\nwhile n!=0:\r\n d=nearest(n)\r\n chisla.append(d)\r\n n-=d\r\n i+=1\r\n\r\nprint(i)\r\nfor c in range(i):\r\n print(chisla[c], end=' ')\r\n", "s=input()\r\nn=len(s)\r\na=[]\r\nfor ch in s:\r\n\ta.append(int(ch))\r\nans=max(a)\r\nprint(ans)\r\nfor i in range(ans):\r\n\tnum=0\r\n\tfor j in range(n):\r\n\t\tnum*=10\r\n\t\tif a[j]>0:\r\n\t\t\tnum+=1\r\n\t\t\ta[j]-=1\r\n\tprint(num,end=\" \")\r\n", "x = int(input())\nans = []\nwhile x>=10:\n curr = ''\n for i in range(len(str(x))):\n if int(str(x)[i])>0:\n curr+='1'\n else:\n curr+='0'\n ans.append(curr)\n x-=int(curr)\nwhile x:\n ans.append(1)\n x-=1\nprint(len(ans))\nfor i in ans:\n print(i,end=' ')\n", "import sys\r\nimport math\r\nimport bisect\r\n\r\ndef solve(n):\r\n A = []\r\n for c in list(str(n)): \r\n A.append(int(c))\r\n B = []\r\n while max(A) > 0:\r\n tmp = []\r\n for i in range(len(A)):\r\n if A[i]:\r\n tmp.append(1)\r\n A[i] -= 1\r\n else:\r\n tmp.append(0)\r\n B.append(tmp)\r\n #print('B: ' + str(B))\r\n ans = []\r\n for tmp in B:\r\n val = 0\r\n for a in tmp:\r\n val = val * 10 + a\r\n ans.append(val)\r\n #print('ans: %s' % (str(ans)))\r\n return ans\r\n\r\ndef main():\r\n n = int(input())\r\n A = solve(n)\r\n print(len(A))\r\n print(' '.join(list(str(a) for a in A)))\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\nres=[]\n\nwhile (n>0):\n\n\tb=''\n\tfor i in str(n):\n\t\tb+=str(min(int(i),1))\n\tn-=int(b)\n\tres.append(int(b))\n\nprint(len(res))\nprint(*res)", "x=input()\r\ns=int(max(x))\r\nprint(s)\r\nls=list(map(int,x))\r\nv=[]\r\n\r\ndef f(s):\r\n\tres=0\r\n\ts.reverse()\r\n\tfor n in range(len(s)):\r\n\t\tres+=s[n]*(10**n)\r\n\treturn res\r\n\r\nres=[]\r\nfor n in range(s):\r\n\tj=[]\r\n\tfor n in range(len(ls)):\r\n\t\tif ls[n]>0:\r\n\t\t\tj.append(1)\r\n\t\t\tls[n]-=1\r\n\t\telse:\r\n\t\t\tj.append(0)\r\n\tv.append(j)\r\n\r\nres=list(map(f,v))\r\nprint(*res)", "# 538B\r\n\r\n__author__ = 'artyom'\r\n\r\ni, a, n = 1000000, [], int(input())\r\nwhile i > 0:\r\n a.append(n // i)\r\n n %= i\r\n i //= 10\r\n\r\np, l = [], len(a)\r\nwhile 1:\r\n y, z = '', 1\r\n for i in range(l):\r\n if a[i] > 0:\r\n a[i] -= 1\r\n y += '1'\r\n z = 0\r\n elif not z:\r\n y += '0'\r\n if z:\r\n break\r\n else:\r\n p.append(y)\r\n\r\nprint(len(p))\r\nprint(' '.join(p))", "\r\nnum = [int(i) for i in input()]\r\nnum = num[::-1]\r\nans = []\r\nwhile num:\r\n right = len(num)-1\r\n s = ''\r\n while right >= 0:\r\n if num[right]:\r\n num[right] -= 1\r\n s += '1'\r\n else:\r\n s += '0'\r\n right -= 1\r\n ans.append(s)\r\n while num and not num[-1]:\r\n num.pop()\r\nprint(len(ans))\r\nprint(*ans)\r\n", "n = int(input())\r\n\r\ndigits = []\r\nmax_len = 0\r\nwhile n:\r\n d = n % 10\r\n if d > max_len: max_len = d\r\n digits.append(d)\r\n n //= 10\r\n\r\nanswer = []\r\nfor i, d in enumerate(digits):\r\n row = [10**i] * d + [0] * (max_len - d)\r\n answer.append(row)\r\n\r\nresult = ''\r\nfor j in range(max_len):\r\n result += str(sum([row[j] for row in answer])) + ' '\r\n\r\nprint(max_len)\r\nprint(result)", "# LUOGU_RID: 126093946\nmaxn = 10\njl = [0] * maxn\n\nn = int(input())\nans1 = 0\nx = n\ncnt = 0\ntot = 0\n\nwhile x:\n ans1 = max(ans1, x % 10)\n cnt += x % 10\n jl[tot] = x % 10\n tot += 1\n x //= 10\n\nprint(ans1)\n\nwhile cnt:\n jud = False\n for i in range(tot-1, -1, -1):\n if jl[i]:\n print('1', end='')\n cnt -= 1\n jl[i] -= 1\n jud = True\n elif jud:\n print('0', end='')\n print(' ', end='')\n\nprint()", "def get_ner(n):\r\n k = 0\r\n while True:\r\n res = int(str(bin(k+1))[2:])\r\n if res > n:\r\n break\r\n k += 1\r\n return int(str(bin(k))[2:])\r\n\r\nn = int(input())\r\nans = []\r\nwhile n != 0:\r\n k = n; m = 0; p = 1\r\n while (k != 0):\r\n if k % 10 != 0:\r\n m+=p\r\n k //= 10\r\n p *= 10\r\n ans.append(m)\r\n n -= m\r\nprint(len(ans))\r\nprint(*ans)", "c = [int(x) for x in list(input())]\r\nprint(max(c))\r\n\r\nfor _ in range(max(c)):\r\n d = []\r\n for i in range(len(c)):\r\n if c[i] > 0: d.append('1'); c[i] -= 1\r\n else: d.append('0')\r\n print(int(''.join(d)), end=' ')\r\nprint('')", "number = int(input())\nv = []\n\nwhile number > 0:\n temp, aux, quasi = number, 1, 0\n while temp:\n if temp % 10:\n quasi = quasi + aux\n temp = temp // 10\n aux = aux * 10\n v.append(quasi)\n number = number - quasi\n\nv.sort()\nprint(len(v))\nfor item in v:\n print(item, end=\" \")\n\n\t \t \t\t\t\t \t\t\t\t\t\t \t\t\t \t \t \t", "n = int(input())\r\nans = []\r\nwhile n>0:\r\n temp = n\r\n p = 1\r\n m = 0\r\n while temp>0:\r\n if (temp%10)>0:\r\n m+=p\r\n p*=10\r\n temp//=10\r\n if m>0:\r\n ans.append(m)\r\n n -= m\r\nprint(len(ans))\r\nfor x in ans:\r\n print(x,end=' ')", "d = list(map(int, list(input())))\r\nr = []\r\nn = len(d)\r\n\r\nfor i in range(n):\r\n while d[i] > 0:\r\n w = '' \r\n for j in range(i,n):\r\n if d[j] > 0:\r\n d[j] -= 1\r\n w += '1'\r\n else:\r\n w += '0'\r\n r.append(w)\r\n\r\nprint(len(r))\r\nprint(\" \".join(r))\r\n", "n = input()\nl = len(n)\nt = int(n)\nk = 0\nwhile t > 0:\n k = max(k, t % 10)\n t //= 10\n# So we will have k numbers and each of length l\n# Lets get a dp and store them. At the end we will reform it\ndp = [[0 for j in range(l)]for i in range(k)]\n\nfor j in range(l):\n num = int(n[j])\n i = 0\n while num > 0:\n dp[i][j] = 1\n num -= 1\n i += 1\nprint(k)\nres = []\nfor i in range(k):\n num = 0\n for j in range(l):\n num = num*10+dp[i][j]\n res.append(num)\n# print(dp)\nprint(*res)\n", "n=int(input())\r\na=[0]*10\r\nk=1\r\nwhile(n>0):\r\n m=n%10\r\n for i in range(m):\r\n a[i]+=k \r\n k*=10\r\n n=int(n/10)\r\ni=0\r\nk=0\r\nwhile(a[i]!=0):\r\n i+=1\r\n k+=1\r\nprint(k)\r\nfor x in a:\r\n if(x!=0):\r\n print(x,end=\" \")\r\n \r\n \r\n\r\n", "digits = list(map(int, list(input())))\r\nquasis = list()\r\n\r\nfor x in range(max(digits)) :\r\n\tnextQuasi = \"\";\r\n\tfor y in range(len(digits)) :\r\n\t\tif(digits[y] > 0) :\r\n\t\t\tnextQuasi += \"1\"\r\n\t\t\tdigits[y]-=1\r\n\t\telse :\r\n\t\t\tnextQuasi += \"0\"\r\n\tquasis.append(int(nextQuasi))\r\n\r\nprint (len(quasis))\r\nprint (\" \".join(map(str, quasis)))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n", "import sys,os.path\r\nif __name__ == '__main__':\r\n if(os.path.exists('input.txt')):\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n sys.stdout = open(\"output.txt\",\"w\")\r\n n = input()\r\n ans = []\r\n no = int(n)\r\n while no>0:\r\n # print(no)\r\n temp = \"\"\r\n for i in range(len(n)):\r\n a = int(n[i])\r\n if a>=1:\r\n temp+=\"1\"\r\n else:\r\n temp+=\"0\"\r\n no = int(n)-int(temp)\r\n n = str(no)\r\n ans.append(temp)\r\n print(len(ans))\r\n print(*ans)\r\n", "#------------------------------warmup----------------------------\r\nimport os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\n \r\nBUFSIZE = 8192\r\n \r\n \r\nclass FastIO(IOBase):\r\n newlines = 0\r\n \r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n \r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n \r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n \r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n \r\n \r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n \r\n \r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n \r\n#-------------------game starts now-----------------------------------------------------\r\na=[]\r\nfor i in range(1,65):\r\n a.append(int(bin(i).replace(\"0b\",\"\")))\r\nn=int(input())\r\nans=[999999999999999]*(n+1)\r\nans[0]=0\r\nans[1]=1\r\nfor i in range(2,n+1):\r\n for j in a:\r\n if i-j>=0:\r\n ans[i]=min(ans[i],ans[i-j]+1)\r\nprint(ans[n])\r\nu=[0]*(ans[n])\r\nt=0\r\ns=set(a)\r\nr=n\r\nfor i in range(n-1,-1,-1):\r\n if ans[r]-ans[i]==1 and (r-i)in s:\r\n u[t]=r-i\r\n t+=1\r\n r=i\r\nprint(*u,sep=\" \")\r\n", "n = int(input())\r\n\r\nresult = []\r\nwhile True:\r\n temp = str(n)\r\n ans = \"\"\r\n for i in range(len(temp)):\r\n if int(temp[i]) < 2:\r\n if temp[i] == \"0\":\r\n ans += \"0\"\r\n else:\r\n ans += \"1\"\r\n else:\r\n ans += \"1\"\r\n\r\n result.append(int(ans))\r\n n -= int(ans)\r\n if n == 0:\r\n break\r\n\r\nprint(len(result))\r\nfor i in range(len(result)):\r\n print(result[i], end=\" \")\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "ans=0\r\nl=[]\r\nn=int(input())\r\nwhile n:\r\n res=''\r\n p=str(n)\r\n for i in range(len(p)):\r\n if int(p[i])>=1:\r\n res+='1'\r\n else:\r\n res+='0'\r\n n-=int(res)\r\n ans+=1\r\n l.append(int(res))\r\nprint(ans)\r\nprint(*l)", "# Description of the problem can be found at http://codeforces.com/problemset/problem/538/B\r\n\r\nn = int(input())\r\n\r\nd_n = {}\r\n\r\nt_n = n\r\nm = 0\r\ni = 0\r\nwhile t_n > 0:\r\n i = max(1, i * 10)\r\n d_n[i] = t_n % 10\r\n t_n //= 10\r\n m = max(d_n[i], m)\r\n\r\nprint(m)\r\nfor _ in range(m):\r\n t_i = i\r\n o = 0\r\n while t_i > 0:\r\n o *= 10\r\n o += 1 if d_n[t_i] > 0 else 0\r\n d_n[t_i] -= 1\r\n t_i //= 10\r\n print(o, end = \" \")", "\r\nn=int(input())\r\nif(1<=n<9):\r\n print(n) \r\n for i in range(n):\r\n print(1,end=' ')\r\n \r\nelse:\r\n x=str(n)\r\n x=list(x)\r\n cnt=0\r\n res=[]\r\n while(n>0):\r\n tem=''\r\n for i in range(len(x)):\r\n if(x[i]!='1' and x[i]!='0'):\r\n x[i]='1'\r\n tem+=x[i] \r\n else:\r\n tem+=x[i] \r\n \r\n tem=int(tem)\r\n n=n-tem\r\n \r\n cnt=cnt+1 \r\n x=str(n)\r\n x=list(x)\r\n res.append(tem)\r\n res=reversed(res) \r\n print(cnt)\r\n print(*res,sep=' ') ", "n = input()\r\nx = int(max(n))\r\nprint(x)\r\nl = [*map(int, n)]\r\nres = [[0] * len(l) for _ in range(max(l))]\r\nfor i in range(x):\r\n for j in range(len(l)):\r\n if l[j] > 0:\r\n l[j] -= 1\r\n res[i][j] += 1\r\nres = [int(''.join(map(str, e))) for e in res]\r\nprint(*res, sep=' ')", "s = input()\r\nm = 0\r\nfor c in s:\r\n m = max(m, int(c))\r\nprint(m)\r\nfor i in range(m):\r\n flag = False\r\n for c in s:\r\n if int(c) > i:\r\n print(1, end='')\r\n flag = True\r\n elif flag:\r\n print(0, end = '')\r\n print(' ', end='')", "\"\"\"\nAuthor: Ove Bepari\n\n _nnnn_ \n dGGGGMMb ,''''''''''''''''''''''.\n @p~qp~~qMb | Promoting GNU/Linux |\n M|@||@) M| _;......................'\n @,----.JM| -'\n JS^\\__/ qKL\n dZP qKRb\n dZP qKKb\n fZP SMMb\n HZM MMMM\n FqM MMMM\n __| \". |\\dS\"qML\n | `. | `' \\Zq\n_) \\.___.,| .'\n\\____ )MMMMMM| .'\n `-' `--' hjm\n\n\"\"\"\n\n# Starting point, just bored and needed\n# to write some comment so writing em\n# i don't even know what i'm doing\n# okay let me solve a problem now\n\nans = []\ndef minQuasi(n):\n if n <= 0:\n return\n m = ''.join(min(i, '1') for i in str(n))\n minQuasi(n - int(m))\n ans.append(m)\n\nn = int(input())\nminQuasi(n)\nprint( len(ans) )\nprint(*ans)\n", "n = int(input())\na = []\nwhile n > 0:\n x = n\n b = []\n while x:\n if x % 10:\n b.append('1')\n else:\n b.append('0')\n x //= 10\n b = int(''.join(b[::-1]))\n a.append(b)\n n -= b\n\nprint(len(a))\nprint(*sorted(a)[::-1])\n\n\t \t\t\t\t\t\t \t \t\t \t\t \t\t", "n=int(input())\r\nr=[]\r\n\r\nwhile n:\r\n res = ''.join(min(i,'1') for i in str(n))\r\n n-=int(res)\r\n r.append(int(res))\r\n \r\nprint(len(r))\r\nprint(*r)\r\n ", "def tostr(l):\r\n l=l[l.index(1):]\r\n s=''\r\n for i in l:\r\n s+=str(i)\r\n return s;\r\nn=int(input())\r\nml=len(str(n))\r\nl=[int(i) for i in str(n)]\r\nl1=[];c=0\r\nwhile(len(l)>0):\r\n x=l[0]\r\n l.remove(x)\r\n i=0;x1=x;\r\n while(i<len(l1) and x1):\r\n l1[i][c]=1;i+=1;x1-=1;\r\n while(len(l1)<x):\r\n l1.append([0]*(ml-len(l)-1)+[1]+[0]*(len(l)))\r\n c+=1\r\nprint(len(l1))\r\nl2=[]\r\nfor i in l1:\r\n l2.append(tostr(i))\r\nprint(*l2)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn = int(input())\r\nm = 0 \r\nc = 0 \r\nl = []\r\nwhile(n > 0):\r\n m = max(m, n % 10)\r\n l.append(n % 10)\r\n c += 1 \r\n n = n // 10 \r\nprint(m)\r\nfor i in range(m):\r\n ans = ''\r\n for j in range(c):\r\n if(l[j]):\r\n ans += '1'\r\n l[j] -= 1 \r\n else:\r\n ans += '0'\r\n for j in range(c - 1, -1, -1):\r\n if(ans[j] == '1'):\r\n ans = ans[:j + 1]\r\n break\r\n print(ans[::-1], end = ' ')", "strN = input()\n\nl = len(strN)\n\nstrN = list(map(int, list(strN)))\n\nk = max(strN)\n\nprint(k)\n\nres = [0 for i in range(k)]\n\nfor i in range(l):\n\tfor j in range(strN[i]):\n\t\tres[j] += 10**(l-i-1);\n\t\t\nprint(*res, sep = \" \")\n\n\n", "a = list(map(int,list(input())))\r\nx = []\r\ng = max(a)\r\nfor _ in range(g):\r\n c=''\r\n for i in range(len(a)):\r\n if a[i]>0:\r\n a[i]-=1\r\n c = c+'1'\r\n elif c:\r\n c = c+'0'\r\n x+=[c]\r\nprint(g)\r\nprint(*sorted(x))\r\n", "from sys import *\r\ninput = lambda:stdin.readline()\r\n\r\nint_arr = lambda : list(map(int,stdin.readline().strip().split()))\r\nstr_arr = lambda :list(map(str,stdin.readline().split()))\r\nget_str = lambda : map(str,stdin.readline().strip().split())\r\nget_int = lambda: map(int,stdin.readline().strip().split())\r\nget_float = lambda : map(float,stdin.readline().strip().split())\r\n\r\n\r\nmod = 1000000007\r\nsetrecursionlimit(1000)\r\n\r\nn = int(input())\r\nres = []\r\n\r\nwhile n:\r\n temp = n\r\n tot = 0\r\n mul = 1\r\n while temp:\r\n rem = temp % 10\r\n if rem:\r\n tot += mul\r\n mul *= 10\r\n temp //= 10\r\n res += [tot]\r\n n -= tot\r\nprint(len(res))\r\nprint(*res)", "import operator\n\na = [int(i) for i in list(input())]\n\nret = []\nwhile a.count(0) != len(a):\n cur = list(map(lambda x: 1 if x > 0 else 0, a))\n ret.append(''.join(str(e) for e in cur).lstrip('0'))\n a = list(map(operator.sub, a, cur))\n\nprint(len(ret))\nprint(' '.join(ret))", "if __name__==\"__main__\":\r\n n = int(input())\r\n ans = \"\"\r\n count = 0\r\n while(n!=0):\r\n tmp = 0\r\n for i in str(n):\r\n if(int(i)>0):\r\n tmp = tmp*10+1\r\n else:\r\n tmp = tmp*10\r\n ans = ans + str(tmp) +\" \"\r\n count += 1\r\n n = n-tmp\r\n print(count)\r\n print(ans)", "a = int(input())\r\nb = a\r\nn = 0\r\nsp = []\r\nkol = 0\r\nmaxi = 0\r\nwhile b > 0:\r\n k = b%10\r\n if k > maxi:\r\n maxi = k\r\n sp.append(k)\r\n n+=1\r\n b = b//10\r\nprint(maxi)\r\ns = 0\r\nfor i in range(maxi):\r\n for j in range(n):\r\n if sp[j] > 0:\r\n sp[j] -= 1\r\n s += 10**j\r\n print(s, end = ' ')\r\n s = 0\r\n", "s = input().strip()\narr = []\nwhile s:\n\ts = str(s)\n\tx = ''.join(['1' if i != '0' else '0' for i in s])\n\ts = int(s)\n\ts -= int(x)\n\tarr.append(x)\nprint(len(arr))\nprint(*arr)", "n = int(input())\r\nans = []\r\nwhile n != 0:\r\n\tk = ''\r\n\tfor i in range(len(str(n))):\r\n\t\tif str(n)[i] == '0':\r\n\t\t\tk+='0'\r\n\t\telse:\r\n\t\t\tk+='1'\r\n\tans.append(k)\r\n\tn-=int(k)\r\nprint(len(ans))\r\nprint(*ans)\r\n", "import sys\r\nfin = sys.stdin\r\nn = int(fin.readline())\r\nr = []\r\nwhile n > 0:\r\n p10 = 1\r\n cr = 0\r\n while p10 <= n:\r\n if n // p10 % 10 != 0:\r\n cr += p10\r\n n -= p10\r\n p10 *= 10\r\n r.append(cr)\r\nprint(len(r))\r\nfor x in r:\r\n print(x, end = ' ')\r\n", "'''input\n415\n'''\nfrom sys import stdin, stdout\nimport math\nfrom copy import deepcopy\nimport sys\n\n\n\ndef check(arr):\n\tfor i in range(len(arr)):\n\t\tif arr[i] > 0:\n\t\t\treturn True\n\treturn False\n\n\ndef parse(arr):\n\ttemp = []\n\tfor string in arr:\n\t\tfor j in range(len(string)):\n\t\t\tif string[j] != '0':\n\t\t\t\ttemp.append(string[j:])\n\t\t\t\tbreak\n\treturn temp\n\n# main starts\nnarr = list(stdin.readline().strip())\nfor i in range(len(narr)):\n\tnarr[i] = int(narr[i])\n\nprint(max(narr))\nans = []\nwhile check(narr):\n\tt = ''\n\tfor i in range(len(narr)):\n\t\tif narr[i] > 0:\n\t\t\tt += '1'\n\t\t\tnarr[i] -= 1\n\t\telse:\n\t\t\tt += '0'\n\tans.append(t)\n\nans = parse(ans)\nprint(*ans)\n", "n = input()\r\nans = int(max(list(n)))\r\nprint(ans)\r\nfor i in range(ans):\r\n num = \"\"\r\n for pos in range(len(n)):\r\n if int(n[pos]) >= i + 1:\r\n num += \"1\"\r\n else:\r\n num += \"0\"\r\n print(int(num), end = \" \")", "n=int(input())\nd={}\nx=0\nmaximum=-1\nlist1=[]\nwhile(n>0):\n d[str(10**x)]=n%10\n if(maximum< n%10):\n maximum=n%10\n n=n//10\n x+=1\nfor z in range(maximum):\n sum1=0\n for y in d:\n if(int(d[y])>0):\n sum1+=int(y)\n d[y]-=1\n list1.append(sum1)\nprint(len(list1))\nfor x in list1:\n print(x,end=\" \")\n", "n = int(input())\r\n\r\nr = [int(i) for i in str(n)]\r\ng = max(r)\r\nl = len(r)\r\nres = []\r\nfor i in range(g):\r\n s = \"\"\r\n for j in range(l):\r\n s += \"1\" if r[j] >= 1 else \"0\"\r\n r[j] -= 1\r\n res.append(str(int(s)))\r\nprint(len(res))\r\nprint(\" \".join(res))\r\n", "import sys\nimport math\ninput = sys.stdin.readline\n\n\ndef int_array():\n return list(map(int, input().strip().split()))\n\n\ndef str_array():\n return input().strip().split()\n\n\ndef lower_letters():\n lowercase = [chr(i) for i in range(97, 97+26)]\n return lowercase\n\n\ndef upper_letters():\n uppercase = [chr(i) for i in range(65, 65+26)]\n return uppercase\n\n######################## TEMPLATE ENDS HERE ########################\n\n\nn = input().strip(); \nans = [];\nwhile(int(n) > 0):\n x = '1';\n for i in range(1, len(n)):\n if int(n[i]) > 0:\n x += '1';\n else:\n x += '0';\n ans.append(x); \n n = str(int(n) - int(x));\nprint(len(ans)); print(*ans);", "# Problem: B. Quasi Binary\r\n# Contest: Codeforces - Codeforces Round #300\r\n# URL: https://codeforces.com/contest/538/problem/B\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n# \r\n# Powered by CP Editor (https://cpeditor.org)\r\n\r\nfrom collections import defaultdict\r\nfrom functools import reduce\r\nfrom bisect import bisect_right\r\nfrom bisect import bisect_left\r\n#import sympy #Prime number library\r\nimport copy\r\nquasi=[0]\r\nfor i in range(1,65):\r\n\tquasi.append(int(bin(i)[2:]))\r\ndef main():\r\n n=input();size=len(n)\r\n n=int(n)\r\n ans=[]\r\n while n!=0:\r\n \tp=''\r\n \tfor i in str(n):\r\n \t\tif i=='0':\r\n \t\t\tp+='0'\r\n \t\telse:\r\n \t\t\tp+='1'\r\n \tans.append(p)\r\n \tn-=int(p)\r\n print(len(ans))\r\n print(\" \".join(map(str,ans)))\r\n \r\n\r\n\r\n\r\ndef primes1(n): #return a list having prime numbers from 2 to n\r\n \"\"\" Returns a list of primes < n \"\"\"\r\n sieve = [True] * (n//2)\r\n for i in range(3,int(n**0.5)+1,2):\r\n if sieve[i//2]:\r\n sieve[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1)\r\n return [2] + [2*i+1 for i in range(1,n//2) if sieve[i]]\r\n \r\ndef GCD(a,b):\r\n if(b==0):\r\n return a\r\n else:\r\n return GCD(b,a%b)\r\n \r\nif __name__ == '__main__':\r\n main()", "n = int(input())\r\n\r\nans = []\r\n\r\nwhile n:\r\n t = 0\r\n for i in range(len(str(n))):\r\n if (n//(10**i)) % 10:\r\n t += 10**i\r\n ans.append(str(t))\r\n n -= t\r\n\r\nprint('{0}\\n{1}'.format(len(ans), ' '.join(ans)))\r\n", "n = int(input())\r\nres = []\r\nwhile n > 0:\r\n sn = str(n)\r\n tmp = ''\r\n for e in map(int, sn):\r\n tmp += '1' if e >= 1 else '0'\r\n n -= int(tmp)\r\n res.append(tmp)\r\nprint(len(res))\r\nprint(*res)\r\n", "n=int(input())\r\nl=[]\r\nwhile n!=0:\r\n\ts=''\r\n\tfor i in list(str(n)):\r\n\t\tif i=='0':\r\n\t\t\ts+='0'\r\n\t\telse:\r\n\t\t\ts+='1'\r\n\tn-=int(s)\r\n\tl.append(int(s))\r\nprint(len(l))\r\nprint(*l)\r\n", "import sys,os,io\r\nimport math,bisect,operator\r\ninf,mod = float('inf'),10**9+7\r\n# sys.setrecursionlimit(10 ** 6)\r\nfrom itertools import groupby,accumulate\r\nfrom heapq import heapify,heappop,heappush\r\nfrom collections import deque,Counter,defaultdict\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nNeo = lambda : list(map(int,input().split()))\r\ntest, = Neo()\r\nn = test\r\nAns = []\r\nwhile n > 0:\r\n k = len(str(n))-1\r\n p = n//(10**k)\r\n n -= p*(10**k)\r\n for i in range(min(len(Ans),p)):\r\n Ans[i] += 10**k\r\n for i in range(p-min(len(Ans),p)):\r\n Ans.append(10**k)\r\nprint(len(Ans))\r\nprint(*Ans)\r\n \r\n ", "intab = \"0123456789\"\r\nouttab = \"0111111111\"\r\ntrantab = str.maketrans(intab,outtab)\r\ndef quasi(x):\r\n return int(x.translate(trantab))\r\n\r\nans = []\r\nn = int(input())\r\nwhile n > 0:\r\n val = quasi(str(n))\r\n n -=val\r\n ans.append(val)\r\n\r\nprint(len(ans))\r\nprint(\" \".join(map(str,ans)))", "n = input()\nans1 = max([int(x) for x in n])\nans2 = ['' for _ in range(ans1)]\nfor i in n:\n cnt = int(i)\n for j in range(ans1):\n if cnt > 0:\n ans2[j] += '1'\n cnt -= 1\n else:\n ans2[j] += '0'\nprint(ans1)\nprint(' '.join([str(int(x)) for x in ans2]))\n\n", "number = str(input())\nstrContat = ''\ncount = 0\nnumbers = []\nwhile int(number) != 0: \n for i in number:\n if(int(i) > 0):\n strContat = strContat + '1'\n else:\n strContat = strContat + '0'\n number = str(int(number) - int(strContat))\n count += 1\n numbers.append(strContat)\n strContat = ''\nprint(count)\nprint(' '.join(numbers))\n\n \t \t \t\t \t \t \t \t\t\t \t \t \t \t", "import sys\r\nf = sys.stdin\r\n\r\ns = f.readline().strip()\r\nsi = []\r\nfor i in range(len(s)):\r\n si.append(int(s[i]))\r\n\r\nr = []\r\n\r\nfor k in range(9):\r\n ki = 0\r\n for i in range(len(si)):\r\n if si[i]>0:\r\n si[i] -= 1\r\n ki += 10**(len(si)-i-1)\r\n if ki==0:\r\n break\r\n r.append(str(ki))\r\n \r\n \r\nprint(len(r))\r\nprint(' '.join(r)) \r\n", "n = int(input())\r\nlst = list()\r\nwhile n > 0:\r\n t = ''\r\n for elem in str(n):\r\n t += str(min(int(elem), 1))\r\n n -= int(t)\r\n lst.append(t)\r\nprint(len(lst))\r\nprint(*lst)\r\n", "import os\r\nimport sys\r\nfrom io import BytesIO, IOBase\r\nfrom collections import Counter, defaultdict\r\nimport math\r\nimport heapq\r\nimport bisect\r\nimport collections\r\ndef ceil(a, b):\r\n return (a + b - 1) // b\r\nBUFSIZE = 8192\r\ninf = float('inf')\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\nget = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\nmod = 10 ** 9 + 7\r\n# for _ in range(int(get())):\r\n# n=int(get())\r\n# l=list(map(int,get().split()))\r\n# = map(int,get().split())\r\n###################################################################################################\r\nl=[]\r\ndef fun(x,k):\r\n if x==0:\r\n l.append(int(k))\r\n return\r\n fun(x-1,\"1\"+k)\r\n fun(x-1,\"0\"+k)\r\nfun(8,\"\")\r\nl.sort()\r\n###################################################################################################\r\nn=int(get())\r\nans=[]\r\ndp=[inf]*(n+1)\r\ndp[0]=1\r\nfor i in l:\r\n if i<=(n):\r\n dp[i]=1\r\nd=defaultdict(list)\r\nfor i in range(2,n+1):\r\n x=inf\r\n y=0\r\n for j in range(len(l)):\r\n if 0<=i-l[j]<=i and dp[i-l[j]]<x:\r\n x=min(x,dp[i-l[j]])\r\n y=i-l[j]\r\n d[i]=y\r\n dp[i]=min(dp[i],x+1)\r\nfor i in l:\r\n d[i]=0\r\nx=n\r\nfor i in range(dp[n]):\r\n y=x\r\n x=d[x]\r\n ans.append(y-x)\r\nprint(len(ans))\r\nprint(*ans)\r\n# print(n)\r\n# print(len(ans))\r\n# print(*ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\nl = []\r\nc = 0\r\nn1 = n\r\na = 0\r\nwhile n1:\r\n b = ''\r\n for i in str(n1):\r\n b+=str(min(int(i),1))\r\n n1-=int(b)\r\n l.append(b)\r\n c+=1\r\nprint(c)\r\nprint(*l) \r\n \r\n \r\n ", "\r\n\r\ndef main(k):\r\n num = list(map(int, k))\r\n res = []\r\n while True:\r\n st = []\r\n flag = False\r\n for i in range(len(num)):\r\n if num[i] > 0:\r\n st.append('1')\r\n num[i] -= 1\r\n flag = True\r\n else:\r\n st.append('0')\r\n if not flag:\r\n break\r\n res.append(str(int(\"\".join(st))))\r\n print(str(len(res)))\r\n print(\" \".join(res))\r\n\r\n\r\nif __name__ == '__main__':\r\n s = input()\r\n main(s)\r\n", "inp=input()\nL=[]\nwhile int(inp)>0:\n\ttoa=''\n\tfor i in inp:\n\t\tif i!='0':\n\t\t\ttoa+='1'\n\t\telse:\n\t\t\ttoa+='0'\n\tinp=str(int(inp)-int(toa))\n\tL.append(int(toa))\nprint(len(L))\nfor i in L:\n\tprint(i,end=' ')\n", "def doChislo(n):\r\n s = str(n)\r\n answ = 0\r\n for i in range(len(s)):\r\n if s[i] != '0':\r\n answ += 10 ** (len(s) - i - 1)\r\n return answ\r\n\r\ndef main():\r\n n = int(input())\r\n answ = []\r\n while n:\r\n m = doChislo(n)\r\n n -= m\r\n answ.append(m)\r\n \r\n print(len(answ))\r\n print(*answ)\r\n \r\nmain()\r\n ", "import math\n\nsn = input()\nn = int(sn)\nln = len(sn)\n\nk = 0\nfor i in sn:\n k = max(k, int(i))\n\nprint(k)\n\nb = []\nfor i in range(k):\n b.append(0)\n\nfor i in range(ln):\n si = sn[i]\n add = int(math.pow(10, ln - i - 1))\n for j in range(int(si)):\n b[j] += add\n\nres = str(b[0])\nfor i in range(1, k):\n res += \" \" + str(b[i])\n\nprint(res)\n\t\t \t\t\t\t\t\t\t\t \t\t\t\t\t\t \t\t \t\t\t\t\t \t", "given = int(input())\r\nanswer= []\r\nwhile given != 0:\r\n current = ''\r\n for i in str(given):\r\n current += str(min(int(i), 1))\r\n given -= int(current)\r\n answer.append(current)\r\nprint(len(answer))\r\nprint(*answer)\r\n", "import math\r\nfrom decimal import *\r\n\r\nc = []\r\ndef coins(x):\r\n if(len(x)==7):\r\n c.append(int(x))\r\n else:\r\n c.append(int(x+'1'))\r\n coins(x+'1')\r\n if(x!= ''):\r\n c.append(int(x+'0'))\r\n coins(x+'0')\r\ncoins('')\r\nc =sorted(c)\r\n\r\nn = int(input())\r\ndp = [int(10e7)]*(n+1)\r\nans = [[]]*(n+1)\r\ndp[0]= 0\r\nfor i in range(1, n+1):\r\n for j in c:\r\n if(i-j>=0):\r\n if(dp[i-j]+1 < dp[i]):\r\n dp[i] = dp[i-j]+1\r\n ans[i] = ans[i-j]+[str(j)]\r\n else:\r\n break\r\nprint(len(ans[-1]))\r\nprint(' '.join(ans[-1]))", "n = [int(x) for x in list(input())]\r\nl = len(n)\r\nstrn = ''\r\nlst = []\r\ncount = 0\r\nwhile 1:\r\n for i in range(l):\r\n if n[i]!=0:\r\n strn += '1'\r\n n[i] -= 1\r\n else:\r\n strn += '0'\r\n if strn!='0'*l:\r\n lst.append(strn)\r\n count += 1\r\n strn = ''\r\n else:\r\n break\r\nprint(count)\r\nfor i in lst:\r\n print(int(i),end=' ')", "sum = int(input())\r\narr = [0]*10\r\nc = 1\r\nwhile sum>0:\r\n x = int(sum%10)\r\n sum//=10\r\n for i in range(x):\r\n arr[i] += c\r\n c *= 10\r\ncnt = 0\r\nfor i in range(10):\r\n if arr[i] != 0:\r\n cnt += 1\r\nprint(cnt)\r\nfor i in range(10):\r\n if arr[i] != 0:\r\n print(arr[i],end = \" \")\r\n", "num = input()\r\nle = len(num)\r\nnum2 = [0] * le\r\nfor i in range(le):\r\n num2[i] = int(num[i])\r\nprint(max(num2))\r\nfor i in range(le):\r\n while num2[i] > 0:\r\n print(1,end=\"\")\r\n for j in range(i+1,le):\r\n if num2[j] > 0:\r\n num2[j] -= 1\r\n print(1,end=\"\")\r\n else:\r\n print(0,end=\"\")\r\n print(\" \",end=\"\")\r\n num2[i] -= 1\r\n", "#!/usr/bin/python3\ns=input()\nnum=list()\nres=list()\nfor i in s:\n num.append(int(i))\nwhile True:\n tmps=\"\"\n for i,v in enumerate(num):\n if v > 0:\n num[i]-=1\n tmps+=\"1\"\n else:\n tmps+=\"0\"\n res.append(int(tmps))\n if(all(map(lambda x:x==0,num))):\n break\nprint (len(res))\nprint (\" \".join(map(str,res)))\n", "n = int(input())\r\na = [0 for i in range(0,100)]\r\nm = 0\r\nt = 1\r\nwhile(n > 0):\r\n b = int(n%10)\r\n m = max(m,b)\r\n for i in range(0,b):\r\n a[i] = a[i] + t\r\n t = t*10\r\n n = n/10\r\n \r\nprint(m)\r\nfor i in range(0,m):\r\n print(a[i],end=\" \")", "n = int(input())\r\n\r\nsteps = 0\r\ns = ''\r\n\r\nwhile True:\r\n\tif n == 0:\r\n\t\tbreak\r\n\telif n == 1:\r\n\t\ts += str(n)\r\n\t\tsteps += 1\r\n\t\tbreak\r\n\telse:\r\n\t\tn_str = str(n)\r\n\t\tn_str_upd = ''\r\n\t\tfor i in range(len(n_str)):\r\n\t\t\tif ord(n_str[i]) > ord('0'):\r\n\t\t\t\tn_str_upd += str(int(n_str[i]) - 1)\r\n\t\t\telse:\r\n\t\t\t\tn_str_upd += str(int(n_str[i]))\r\n\t\tsteps += 1\r\n\t\tn_upd = int(n_str_upd)\r\n\t\ts += str(n - n_upd) + ' '\r\n\t\tn = n_upd\r\n\r\nprint(steps)\r\nprint(s)\r\n\r\n\r\n\r\n\r\n\r\n", "import math\r\nimport sys\r\n#from collections import deque, Counter, OrderedDict, defaultdict\r\n#import heapq\r\n#ceil,floor,log,sqrt,factorial,pow,pi,gcd\r\n#import bisect\r\nfrom bisect import bisect_left,bisect_right\r\ninput = sys.stdin.readline\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input().strip()\r\n return(list(s[:len(s)]))\r\ndef invr():\r\n return(map(int,input().split()))\r\ndef recur(n):\r\n if n>10**6:\r\n return\r\n s.add(n)\r\n recur(n*10)\r\n recur(n*10+1)\r\ns=set()\r\nrecur(1)\r\nl=list(s)\r\nl.sort()\r\nn=inp()\r\nk=bisect_right(l,n)\r\nl=l[:k]\r\ndp=[sys.maxsize for i in range(n+1)]\r\ndp[0]=0\r\nnum=n\r\nv=[0 for i in range(n+1)]\r\nfor i in range(1,n+1):\r\n for each in l:\r\n if each<=i:\r\n if dp[i-each]+1<dp[i]:\r\n dp[i]=dp[i-each]+1\r\n v[i]=each\r\nprint(dp[n])\r\nwhile(num>0):\r\n print(v[num],end=\" \")\r\n num-=v[num]", "__author__ = 'ploskov'\n\n\ndef termination_condition(digit_list: 'list'):\n for digit in digit_list:\n if digit > 0:\n return False\n return True\n\n\ndef main():\n number = input()\n\n digit_list = [int(digit) for digit in number]\n\n answer = []\n while not termination_condition(digit_list):\n sub_number = [0 for digit in number]\n for index in range(len(digit_list)):\n if digit_list[index] > 0:\n sub_number[index] = 1\n digit_list[index] -= 1\n answer.append(str(int(''.join(map(str, sub_number)))))\n\n print(len(answer))\n print(' '.join(answer))\n\n\nif __name__ == '__main__':\n main()\n", "n=int(input())\r\nl=list()\r\nans=\"\"\r\nwhile(n):\r\n ans=''.join(min(i,'1') for i in str(n))\r\n l.append(ans)\r\n #print(int(ans))\r\n a=int(ans)\r\n n=n-a\r\nprint(len(l))\r\nprint(*l)", "#! /usr/bin/python3\r\n\r\ndef solve():\r\n n = int(input())\r\n if n == 0:\r\n print(1)\r\n print(0)\r\n return\r\n \r\n a = [0] * 10\r\n k = n;\r\n max = 0\r\n for i in range (0, 10):\r\n if k > 0:\r\n a[i] = k % 10\r\n if a[i] > max:\r\n max = a[i]\r\n \r\n k = int(k / 10)\r\n \r\n print(max)\r\n sum = 0;\r\n #while sum < n:\r\n for j in range(0, max):\r\n r = 0\r\n k = 1\r\n for i in range(0, 10):\r\n if a[i] > 0:\r\n a[i] = a[i] - 1\r\n r = r + k\r\n k = k * 10\r\n \r\n print(r, end=' ')\r\n sum = sum + r\r\n\r\nsolve() ", "from sys import stdin\r\n\r\nn = int(stdin.readline().rstrip())\r\na = str(n)\r\nl = []\r\nwhile n > 0:\r\n x = 1\r\n for i in a[1:]:\r\n if int(i)>0:\r\n x= x*10+1\r\n else:\r\n x = x* 10\r\n l.append(x)\r\n\r\n n = n-x\r\n a = str(n)\r\nprint(len(l))\r\nprint(*l)\r\n", "n=input()\r\nk=max(n)\r\nprint(k)\r\nfor _ in range(1,int(k)+1):\r\n f=''\r\n for i in n:\r\n if int(i)>=_:\r\n f+='1'\r\n else:\r\n f+='0'\r\n print(int(f),end=' ')", "n=list(map(int,list(input())))\r\nans=[0 for i in range(max(n))]\r\nn.reverse()\r\nfor i in range(len(n)):\r\n for j in range(n[i]):\r\n ans[j]+=10**i\r\nprint(len(ans))\r\nprint(*ans)", "s = int(input().strip())\nnos = []\nwhile s != 0:\n\tval = str()\n\tfor x in range(len(str(s))):\n\t\tif str(s)[x] != '0':\n\t\t\tval = val + \"1\"\n\t\telse:\n\t\t\tval = val + \"0\"\n\ts -= int(val)\n\tnos += [int(val)]\nprint(len(nos))\nfor x in range(len(nos)):print(nos[x],end=\" \")\nprint()\n", "n = input()\r\nl = []\r\ns = ''\r\na = [int(i) for i in n]\r\n#for i in range(min(a)):\r\nfor i in range(max(a)):\r\n for j in range(len(a)):\r\n if a[j] > 0:\r\n s += '1'\r\n else:\r\n s += '0'\r\n a[j] -= 1\r\n l.append(int(s))\r\n s = ''\r\nprint(len(l))\r\nfor i in range(len(l)):\r\n print(l[i], end=' ')\r\n", "n = int(input())\nk = []\nwhile n:\n k.insert(0, n % 10)\n n //= 10\ncnt = max(k)\n\nans = [0]*cnt\nfor i in range(cnt):\n for j in k:\n ans[i] = ans[i]*10+(i < j)\nprint(cnt)\nprint(*ans)", "n = int(input())\r\nls = []\r\nwhile n:\r\n x = [c for c in str(n)]\r\n for i in range(len(x)):\r\n if x[i] > '1':\r\n x[i] = '1'\r\n low = int(''.join(x))\r\n n -= low\r\n ls.append(low)\r\nprint(len(ls))\r\nprint(*ls)\r\n\r\n", "n = int(input())\r\nm = 0\r\nc = 1\r\ni = n\r\nwhile i > 0:\r\n m = max(m, i % 10)\r\n i = i // 10\r\na = [0] * m\r\ni = n\r\nwhile i > 0:\r\n for j in range(i % 10):\r\n a[j] += c\r\n c = c * 10\r\n i = i // 10\r\nprint(m)\r\nfor i in range(m):\r\n print(a[i], end=' ')", "n = input().strip()\na = list(n)\nc = [int(i) for i in a]\nresults = []\nwhile sum(c) > 0:\n qb = [0 for i in range(len(c))]\n for i in range(len(c)):\n if c[i] > 0:\n qb[i] = 1\n c[i] -= 1\n qbs = int(''.join([str(c) for c in qb]))\n results.append(qbs)\n \nprint(len(results))\nprint(' '.join([str(num) for num in results]))\n\n", "################# <----------------- Quicksilver_ -----------------> ##################\r\ns=input()\r\nn=int(s)\r\ncont=[]\r\nwhile n>0:\r\n res=''\r\n for i in s:\r\n if i!='0':\r\n res+='1'\r\n else:\r\n res+='0'\r\n n-=int(res)\r\n cont.append(res)\r\n s=str(n)\r\nprint(len(cont))\r\nfor i in cont:\r\n print(i,end=' ')\r\n", "n=int(input())\r\nl=[]\r\nwhile n!=0:\r\n b=''\r\n for i in str(n):\r\n b+=str(min(int(i),1))\r\n n-=int(b)\r\n l.append(b)\r\nprint(len(l))\r\nprint(*l)", "n = list(input())\r\nt = int(max(n))\r\nans = []\r\nfor i in range(t):\r\n ans.append(['0']*len(n))\r\n\r\nfor i in range(len(n)):\r\n c = int(n[i])\r\n for j in range(c):\r\n ans[j][i] = '1'\r\n\r\nans2 = []\r\nfor i in ans:\r\n ans2.append(int(''.join(i)))\r\n\r\nprint(t)\r\nans2.sort()\r\nprint(*ans2)", "s=input()\r\nr=[]\r\nwhile set(s)!=set('0'):r+=[str(int(''.join(['0','1'][i!='0']for i in s)))];s=list(map(lambda x:str(max(0,int(x)-1)),s))\r\nprint(len(r))\r\nprint(' '.join(r))", "#rOkY\n#FuCk\n\n############################### kOpAl ##################################\n\n\ns=str(input())\nma=0\nfor i in range(0,len(s),1):\n d=int(s[i])\n ma=max(ma,d)\nprint(ma)\nfor i in range(0,ma,1):\n if(i>0):\n print(' ',end='')\n f=0\n for j in range(0,len(s),1):\n if(int(s[j])>i):\n f=1\n if(f):\n if(int(s[j])>i):\n print(1,end='')\n else:\n print(0,end='')\nprint()\n\n \t\t \t\t \t\t\t \t \t\t \t \t", "import sys\r\n# sys.stdin=open('input.txt','r')\r\n# sys.stdout=open('output.txt','w')\r\n\r\n\r\nn=input()\r\nl=[int(i) for i in n] \r\nans=[]\r\nfor i in range(int(max(n))):\r\n s=''\r\n for j in range(len(n)):\r\n if l[j]>0:\r\n l[j]-=1\r\n s+='1'\r\n else:\r\n s+='0'\r\n ans.append(int(s))\r\nprint(max(n))\r\nprint(*ans)", "x=(input())\r\nlol=\"\"\r\nc=0\r\nyo=[]\r\nwhile int(x)>0:\r\n if int(x)<10:\r\n c+=int(x)\r\n yo=yo+[1]*int(x)\r\n x=0\r\n else: \r\n for i in x:\r\n if int(i)>=1:\r\n lol+=\"1\"\r\n else:\r\n lol+=\"0\"\r\n x=str(int(x)-int(lol))\r\n yo.append(lol)\r\n lol=\"\"\r\n c+=1\r\n #print(x) \r\nprint(c)\r\nprint(*yo)\r\n ", "def qasi(n):\r\n if n==0:\r\n print(1)\r\n print(0)\r\n return\r\n c=0\r\n l=[]\r\n while (n>=1):\r\n s=str(n)\r\n ans=\"\"\r\n for x in s:\r\n if x!=\"0\":\r\n ans+=\"1\"\r\n else:\r\n ans+=\"0\"\r\n n-=int(ans)\r\n s+=ans\r\n c+=1\r\n l.append(ans)\r\n print(c)\r\n for x in l:\r\n print(x,end=\" \")\r\n print()\r\n return\r\n\r\n\r\nt=int(input())\r\nqasi(t)", "import sys\r\ninput = lambda:sys.stdin.readline()\r\n\r\nint_arr = lambda: list(map(int,input().split()))\r\nstr_arr = lambda: list(map(str,input().split()))\r\nget_str = lambda: map(str,input().split())\r\nget_int = lambda: map(int,input().split())\r\nget_flo = lambda: map(float,input().split())\r\n\r\nmod = 1000000007\r\n\r\n# def solve():\r\n# for _ in range(int(input())):\r\nn = int(input())\r\nout = []\r\nwhile n:\r\n mul = 1\r\n tmp = 0\r\n x = n\r\n while x:\r\n rem = x % 10\r\n if rem:\r\n tmp += mul\r\n mul *= 10\r\n x //= 10\r\n out += [tmp]\r\n n -= tmp\r\n\r\nprint(len(out))\r\nprint(*out)\r\n\r\n\r\n", "#coding=utf-8\r\n#!/usr/bin/python3\r\n\r\ndef getVal(n):\r\n\tr = 0\r\n\tbas = 1\r\n\twhile n > 0:\r\n\t\tif n % 10 > 0:\r\n\t\t\tr += bas\r\n\t\tbas *= 10\r\n\t\tn = int(n / 10)\r\n\treturn r\r\n\r\nres = []\r\nn = int(input())\r\nwhile n > 0:\r\n\tt = getVal(n)\r\n\tn -= t\r\n\tres.append(t)\r\n\r\nprint(len(res))\r\nfor x in res:\r\n\tprint(x, \"\", end='')\r\n", "n=input().rstrip()\r\nans=[]\r\nwhile n!=\"0\":\r\n\tsub=\"\"\r\n\tfor i in n:\r\n\t\tif int(i)>=1:\r\n\t\t\tsub+='1'\r\n\t\telse:\r\n\t\t\tsub+='0'\r\n\tans.append(sub)\r\n\tn=str(int(n)-int(sub))\r\nprint(len(ans))\r\nprint(*ans)\r\n", "def QuasiBinary(n):\r\n \r\n if n==415:\r\n return ([1, 101, 101, 101, 111])\r\n \r\n l = len(str(n))\r\n a = int(\"1\"*l)\r\n ans = []\r\n \r\n while n>0:\r\n if a<=n: \r\n# print(\"Appending a:\",a,\" n:\",n)\r\n ans.append(a)\r\n n = n - a\r\n else:\r\n# print(\"13 a:\",a,\" n:\",n)\r\n if a%2==0:\r\n a = a - 9\r\n else:\r\n a = a - 1\r\n \r\n return ans\r\n\r\n \r\n\r\n\r\n\r\ns=input()\r\n\r\n#ans = QuasiBinary(s)\r\n\r\nm=int(max(s))\r\nprint(m)\r\nfor i in range(m):\r\n ans = []\r\n for c in s:\r\n if int(c)>i:\r\n ans.append(1)\r\n else:\r\n ans.append(0)\r\n print(\"\".join(str(i) for i in ans[ans.index(1):]), end = \" \")\r\n", "n = [int(i) for i in input()]\nn_sorted = list(map(lambda x: list(x), list(enumerate(n.copy()))))\nn_sorted.sort(key=lambda x:x[1])\nestado = ['1' for i in range(len(n))]\nnumeros = []\nfor k in n_sorted:\n numeros += k[1] * [int(''.join(estado))]\n sub = k[1]\n for i in n_sorted:\n i[1] -= sub\n estado[k[0]] = '0'\nprint(len(numeros))\nprint(*numeros)\n \t\t\t\t \t \t \t\t\t \t\t\t\t \t \t\t", "def min_pos(arr):\n min_number = 10\n min_index = 0\n for i in range(len(arr)):\n if arr[i] != 0 and arr[i] < min_number:\n min_number = arr[i]\n min_index = i\n return min_number, min_index\n\n\nn = list(map(int, input()))\nmax_number = max(n)\nres = []\nptr = 0\nfor _ in range(len(n)):\n min_number = min_pos(n)[0]\n min_index = min_pos(n)[1]\n for i in range(min_number):\n new_string = ''\n for j in range(len(n)):\n if n[j] != 0:\n new_string += '1'\n n[j] -= 1\n else:\n new_string += '0'\n res.append(new_string)\nres = list(map(int, res))\nnew_res = [x for x in res if x != 0]\nprint(max_number)\nprint(*new_res)\n", "import sys\r\nimport math\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\n\r\ndef quasibinary_repr(num):\r\n\r\n results = []\r\n num_digits = int(math.log10(num)) + 1\r\n\r\n while num > 0:\r\n\r\n cur_num = num\r\n cur_quasi_num = 0\r\n\r\n for i in range(num_digits):\r\n\r\n result = (cur_num % 10)\r\n\r\n if result > 0:\r\n cur_quasi_num = cur_quasi_num + 1 * (10**i)\r\n\r\n cur_num = cur_num // 10\r\n\r\n num = num - cur_quasi_num\r\n results.append(cur_quasi_num)\r\n\r\n return results\r\n\r\n\r\nnum = inp()\r\nresult = quasibinary_repr(num)\r\nprint(len(result))\r\nprint(*result, sep=\" \")\r\n\r\n\r\n\r\n\r\n", "num = int(input().strip())\r\nprint(max(int(x) for x in str(num)))\r\n\r\nwhile num > 0:\r\n req_num = int(\"\".join(\"1\" if int(x) >= 1 else \"0\" for x in str(num)))\r\n num -= req_num\r\n print(req_num,end=\" \")", "n = input().strip()\nm = max([int(i) for i in n])\nprint(m)\nfor i in range(m):\n print(int(''.join(['1' if int(j) > i else '0' for j in n])),end=' ')\n", "s = input()\r\nmas = []\r\nres=0\r\nfor i,x in enumerate(s):\r\n x=int(x)\r\n for j,y in enumerate(mas):\r\n if x==0:\r\n mas[j]+='0'\r\n else:\r\n mas[j]+='1'\r\n x-=1\r\n for i in range(x):\r\n res+=1\r\n mas.append('1')\r\nprint(res)\r\nprint(*mas)", "a = input()\r\nn = [q for q in a]\r\ns = []\r\nt = [\"0\"]*len(n)\r\n\r\nwhile n != t:\r\n d = \"\"\r\n for i in range(len(n)):\r\n if n[i] == \"0\":\r\n d += \"0\"\r\n else:\r\n d += \"1\"\r\n n[i] = str(int(n[i])-1)\r\n s.append(int(d))\r\n \r\nprint(len(s))\r\nprint(\" \".join(map(str, s)))", "n = int(input())\r\nnums = [int(i) for i in str(n)]\r\noutput = []\r\n\r\nfor index,i in enumerate(nums):\r\n j = 0\r\n while j < i:\r\n try:\r\n output[j] += 1\r\n except:\r\n output.append(1)\r\n j+=1\r\n if index != len(nums) -1:\r\n output = list(map(lambda x: x*10,output))\r\n \r\n \r\nprint(len(output))\r\nfor i in output:\r\n print(i,end=\" \")\r\n\r\n ", "n = int(input())\ns=\"\"\nans = 0\nwhile n:\n ans+=1\n n1=n\n mul=1\n num=0\n while n1:\n if n1%10:num+=mul\n n1//=10\n mul*=10\n n-=num\n s+=str(num)+\" \"\nprint(str(ans)+\"\\n\"+s)", "n = int(input())\r\nprev = []\r\nwhile n:\r\n x = ''.join(str(int(i != '0')) for i in str(n))\r\n prev.append(x)\r\n n -= int(x)\r\nprint(len(prev))\r\nprint(*prev)", "n=int(input())\r\na=[]\r\nwhile n>0:\r\n\tdig=n%10\r\n\ta.append(dig)\r\n\tn=n//10\r\na.reverse()\r\nk=len(a)\r\nb=[]\r\nfor i in range(9):\r\n\tw=''\r\n\tfor j in range(k):\r\n\t\tif a[j]>0:\r\n\t\t\tw+='1'\r\n\t\t\ta[j]-=1\r\n\t\telse:\r\n\t\t\tw+='0'\r\n\tb.append(int(w))\r\n\r\nc=[]\r\nfor i in b:\r\n\tif i!=0:\r\n\t\tc.append(i)\r\nprint(len(c))\r\nfor i in c:\r\n\tprint(i,end=' ')\r\nprint()\r\n\r\n", "n=input()\r\na=[]\r\nfor i in range(len(n)):\r\n a.append(int(n[i]))\r\nanswer=[]\r\nfor j in range(9,0,-1):\r\n c=0\r\n for k in range(len(a)):\r\n if a[k]==j:\r\n a[k]-=1\r\n c+=10**(len(a)-k-1)\r\n if c>0:\r\n answer.append(c)\r\nprint(len(answer))\r\nfor l in range(len(answer)):\r\n print(answer[l],end=' ')", "n = input()\r\n\r\nl = len(n)\r\n\r\nans = []\r\n\r\nfor i in range(len((n))):\r\n\tans.append(int(n[i:])//(10**(len(n[i:])-1)))\r\n\r\n# print(ans)\r\n\r\nout = []\r\n\r\n# tot = [ans[0]]\r\n\r\n# for i in range(1,l):\r\n# \ttot.append(0 if(ans[i] < ans[0]) else (ans[i]-ans[0]))\r\n\r\n# print(tot)\r\n\r\n# s = sum(tot)\r\n\r\n# print(s)\r\n\r\n\r\n\r\n\r\n\r\nwhile(any(ans)):\r\n\r\n\ttemp = []\r\n\tfor i in range(l):\r\n\r\n\t\tif(ans[i] > 0):\r\n\t\t\ttemp.append(10**(l-i-1))\r\n\t\t\tans[i] -= 1\r\n\r\n\tout.append(sum(temp))\r\n\r\n\r\n\r\n\r\n\r\nprint(len(out))\r\nprint(*out)\r\n\r\n# print((any([1,2,0])))", "R = lambda: map(int, input().split())\r\nx = int(input())\r\nxs = list(map(int, str(x)))\r\nres = []\r\nwhile max(xs):\r\n k = min(filter(lambda i : i > 0, xs))\r\n raw = [1 if i >= k else 0 for i in xs]\r\n num = 0\r\n for xx in raw:\r\n num = 10 * num + xx\r\n res += [num] * k\r\n xs = [a - b for a, b in zip(xs, [i * k for i in raw])]\r\nprint(len(res))\r\nprint(' '.join(map(str, res)))", "__author__ = \"runekri3\"\r\n\r\ninp = input()\r\nouts = [0] * 9\r\ndigits = [int(digit) for digit in list(inp)]\r\n\r\nfor power in range(7):\r\n if not digits:\r\n break\r\n power_of_10 = 10 ** power\r\n digit = digits.pop()\r\n for index in range(digit):\r\n outs[index] += power_of_10\r\n\r\nresult = [str(number) for number in outs if number != 0]\r\nprint(len(result))\r\nprint(\" \".join(result))", "n = int(input())\n \nans = []\nwhile n > 0:\n \n\tN = n\n\tp = 1\n\tm = 0\n\twhile N > 0:\n\t\tif N%10:\n\t\t\tm += p\n\n\t\tN //= 10\n\t\tp *= 10\n \t\n\tans.append(m)\n\tn -= m\n \nprint(len(ans))\nprint(*ans)\n", "n = list(map(int, input()))\r\nans = []\r\nwhile(True):\r\n num = \"\"\r\n for i in range(len(n)):\r\n if n[i]>0:\r\n num += \"1\"\r\n n[i] -= 1\r\n else:\r\n num += \"0\"\r\n num = int(num)\r\n if num == 0:\r\n break\r\n else:\r\n ans.append(num)\r\nprint(len(ans))\r\nprint(' '.join(map(str, ans)))\r\n", "# from debug import debug\r\nimport sys;input = sys.stdin.readline\r\ninf = int(1e10)\r\nn = int(input())\r\n\r\nans = []\r\nwhile n:\r\n\ta = n\r\n\td = 0\r\n\tc = 0\r\n\twhile a:\r\n\t\tr = a%10\r\n\t\tif r != 0: d += 10**c\r\n\t\tc+=1\r\n\t\ta//=10\r\n\tn -= d\r\n\tans.append(d)\r\nprint(len(ans))\r\nprint(*ans)\r\n\r\n", "# import sys\r\n# sys.stdin = open(\"input.txt\",\"r\")\r\n# sys.stdout = open(\"output.txt\",\"w\")\r\n\r\ndef fun(n):\r\n\tn = str(n)\r\n\tl = []\r\n\tfor i in n:\r\n\t\tif i == '0': l.append('0')\r\n\t\telse: l.append('1')\r\n\treturn int(''.join(l))\r\n\r\nn = int(input())\r\nl = []\r\nwhile(not n==0):\r\n\tx = fun(n)\r\n\tn -= x\r\n\tl.append(x)\r\nsorted(l)\r\nprint(len(l))\r\nfor i in l: print(i,end = ' ')", "n=input()\r\nl=[]\r\nfor i in range(9):\r\n s=''\r\n for j in n:\r\n if ord(j)-i-48>0:\r\n s+='1'\r\n else:\r\n s+='0'\r\n l.append(s)\r\nfor i in range(9):\r\n l[i]=int(l[i])\r\nwhile True:\r\n try:\r\n l.remove(0)\r\n except:\r\n break\r\nprint(len(l))\r\nprint(*l)", "s = input()\r\nmat=[]\r\n\r\nfor i in s:\r\n mat.append(int(i))\r\n\r\nsat = [0] * max(mat)\r\n\r\nfor i in range(len(mat)):\r\n for j in range(mat[i]):\r\n sat[j] +=10**(len(mat) - i - 1)\r\n\r\nprint(len(sat))\r\nprint(*sat)\r\n", "n=int(input())\r\n\r\nans=[]\r\n\r\nwhile(n>0):\r\n s=''\r\n\r\n for i in str(n):\r\n s+=str(min(int(i),1))\r\n\r\n n-=int(s)\r\n ans.append(int(s))\r\n\r\nprint(len(ans))\r\nprint(*ans)\r\n", "from sys import stdin\r\ninp = stdin.readline\r\n\r\ns = inp().strip()\r\n\r\nn = max([int(x) for x in s])\r\nprint(n)\r\n\r\narr = [set() for i in range(n)]\r\n\r\nfor i, c in enumerate(s):\r\n for j in range(int(c)):\r\n arr[j].add(i)\r\n\r\nprint(*[\"\".join([\"1\" if c in arr[i] else \"0\" for c in range(min(arr[i]), len(s))]) for i in range(n)])\r\n", "n = int(input())\ntn = n\narr = [0]*10\ni = 1\nwhile(tn):\n\tval = tn%10\n\ttn //= 10\n\tfor j in range(val):\n\t\tarr[j] += i\n\ti *= 10\n\nj = 9\nwhile(arr[j]==0):\n\tj-=1\n\nprint(j+1)\nfor _ in range(j+1):\n\tprint(arr[_])\n", "def solve(num):\r\n nums = list(map(int, [c for c in str(num)]))\r\n \r\n rv = []\r\n for v in list(range(9, 0, -1)):\r\n curval = 0\r\n for idx, n in enumerate(nums):\r\n if n >= v:\r\n curval += 10**(len(nums) - 1 - idx)\r\n if(curval > 0):\r\n rv.append(str(curval))\r\n \r\n return max(nums), \" \".join(rv)\r\n\r\nimport sys\r\ndata = sys.stdin.read().strip()\r\ncount, ans = solve(data)\r\nprint(count)\r\nprint(ans)", "\r\n\r\nn=int(input())\r\na=[]\r\nwhile n!=0:\r\n b=''\r\n for i in str(n):\r\n b+=str(min(int(i),1))\r\n n-=int(b)\r\n a.append(b)\r\nprint(len(a))\r\nprint(*a)", "#eid_mubarak\r\nfrom sys import stdin, stdout\r\ncin = stdin.readline\r\ncout = stdout.write\r\n\r\ndef num(n):\r\n\ts = str(n)\r\n\tt = ''\r\n\tfor ch in s:\r\n\t\tif ch == '0':\r\n\t\t\tt += '0'\r\n\t\telse:\r\n\t\t\tt += '1'\r\n\treturn int(t)\r\n\t\r\nn = int(cin())\r\n\r\nans = []\r\n\r\nwhile n:\r\n\tk = num(n)\r\n\tn -= k\r\n\tans.append(k)\r\n\t#k = n\r\n\t#while k:\r\n\t\t\r\ncout(str(len(ans)) + '\\n')\r\nfor bin in ans:\r\n\tcout(str(bin) + ' ')\r\n\r\n\r\n'''\r\nlst = [11111, 11110, 11101, 11100, 11011, 11010, 11001, 11000, 10111, 10110, 10101, 10100, 10011, 10010, 10001, 10000,\r\n\t\t1111, 1110, 1101, 1100, 1011, 1010, 1001, 1000,\r\n\t\t111, 110, 101, 100,\r\n\t\t11, 10, 1]\r\ni = 0\r\nans = []\r\n\r\nwhile i < len(lst) and n:\r\n\tk = n//lst[i]\r\n\tfor j in range(k):\r\n\t\tans.append(lst[i])\r\n\tn -= lst[i] * k\r\n\ti += 1\r\n\r\ncout(str(len(ans)) + '\\n')\r\nfor val in ans:\r\n\tcout(str(val) + ' ')\r\n#eid_mubarak\r\n'''", "n = int(input())\r\nh = []\r\ns = str(n)\r\nfor i in range(len(s)):\r\n h.append(int(s[i]))\r\nprint(max(h))\r\nl = [[0 for i in range(len(h))] for j in range(max(h))]\r\nfor i in range(max(h)):\r\n for j in range(len(h)):\r\n if i < h[j]:\r\n l[i][j] = 1\r\nfor i in range(len(l)):\r\n s = ''\r\n for j in range(len(l[i])):\r\n s += str(l[i][j])\r\n print(int(s), end = ' ')\r\n", "n = list(input())\r\narr = [int(i) for i in n]\r\nm = int(max(n))\r\nprint(m)\r\nfor i in range(len(arr)):\r\n while arr[i] > 0:\r\n t = ''\r\n for j in range(i, len(arr)):\r\n if arr[j] > 0:\r\n t += '1'\r\n arr[j] -= 1\r\n else:\r\n t += '0'\r\n print(t, end=\" \")", "import sys\r\nn = int(input())\r\nif n == 0:\r\n print(1)\r\n print(0)\r\n sys.exit()\r\nt = n\r\ndigits = []\r\nbig = 0\r\nwhile t !=0:\r\n digit = t%10\r\n big = max(big, digit)\r\n digits.insert(0, digit)\r\n t //= 10\r\nnumbers = [0 for x in range(big)]\r\nfor k in range(len(digits)):\r\n for i in range(big):\r\n numbers[i] *= 10\r\n if digits[k] > 0:\r\n numbers[i] += 1\r\n digits[k] -= 1\r\n \r\nprint(big)\r\nprint(*numbers)", "#!/bin/python\r\nn = int(input())\r\n\r\nnumbers = []\r\n\r\nwhile n != 0:\r\n\tdigits = list(str(n))\r\n\tnext_number = int(''.join(list('1' if digit != '0' else '0' for digit in digits)))\r\n\r\n\tnumbers.append(next_number)\r\n\tn -= next_number\r\n\r\nprint(len(numbers))\r\nprint(' '.join(str(number) for number in numbers))", "def solve(s):\r\n l = [\"\"]*9\r\n m = int(s[0])\r\n for e in s:\r\n c = int(e)\r\n m = max(m, c)\r\n for i in range(m):\r\n if c > 0:\r\n l[i] += \"1\"\r\n else:\r\n l[i] += \"0\"\r\n c -= 1\r\n print(m); print(\" \".join(l))\r\n\r\ndef main():\r\n solve(input())\r\n\r\nif __name__ == \"__main__\":\r\n main()" ]
{"inputs": ["9", "32", "1", "415", "10011", "10201", "314159", "999999", "2", "10", "21", "98", "102030", "909090", "909823", "1000000", "111111", "123456", "987654", "908172", "8", "100009", "900000", "1435", "1453"], "outputs": ["9\n1 1 1 1 1 1 1 1 1 ", "3\n10 11 11 ", "1\n1 ", "5\n1 101 101 101 111 ", "1\n10011 ", "2\n100 10101 ", "9\n1 1 1 1 11 1011 101011 101011 111111 ", "9\n111111 111111 111111 111111 111111 111111 111111 111111 111111 ", "2\n1 1 ", "1\n10 ", "2\n10 11 ", "9\n10 11 11 11 11 11 11 11 11 ", "3\n10 1010 101010 ", "9\n101010 101010 101010 101010 101010 101010 101010 101010 101010 ", "9\n101000 101100 101100 101100 101100 101100 101101 101111 101111 ", "1\n1000000 ", "1\n111111 ", "6\n1 11 111 1111 11111 111111 ", "9\n100000 110000 111000 111100 111110 111111 111111 111111 111111 ", "9\n100000 101000 101010 101010 101010 101010 101010 101011 101111 ", "8\n1 1 1 1 1 1 1 1 ", "9\n1 1 1 1 1 1 1 1 100001 ", "9\n100000 100000 100000 100000 100000 100000 100000 100000 100000 ", "5\n1 101 111 111 1111 ", "5\n10 110 111 111 1111 "]}
UNKNOWN
PYTHON3
CODEFORCES
288
2069be9dcf332b37be07c41ab9a6cbe3
Prime Number
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...<=+<=*a**n*. Now Simon wants to reduce the resulting fraction. Help him, find the greatest common divisor of numbers *s* and *t*. As GCD can be rather large, print it as a remainder after dividing it by number 1000000007 (109<=+<=7). The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109). Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). Sample Input 2 2 2 2 3 3 1 2 3 2 2 29 29 4 5 0 0 0 0 Sample Output 8 27 73741817 1
[ "import sys\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\nmod = 10 ** 9 + 7\r\nn, x = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\nans = pow(x, sum(a[:n - 1]), mod)\r\nma = a[-1]\r\n\r\nwhile len(a) > 1:\r\n cur, num = a.pop(), 1\r\n\r\n while a and a[-1] == cur:\r\n a.pop()\r\n num += 1\r\n\r\n if num % x:\r\n a.append(cur)\r\n break\r\n\r\n while num:\r\n num -= x\r\n a.append(cur - 1)\r\n\r\nprint((ans * pow(x, min(ma, ma - a[-1]), mod)) % mod)\r\n", "modulus = 10**9 +7\r\n\r\nn, x = map(int,input().split())\r\ns = list(map(int,input().split()))\r\n\r\ntot = sum(s)\r\npowers=[tot-x for x in s]\r\npowers.sort(reverse=True)\r\n\r\nwhile True:\r\n\r\n low=powers[-1]\r\n cnt = 0\r\n while len(powers) > 0 and powers[-1]==low:\r\n cnt += 1\r\n powers.pop()\r\n if cnt%x==0:\r\n cnt=cnt // x\r\n for n in range(cnt):\r\n powers.append(low+1)\r\n else:\r\n low = min(low, tot)\r\n print(pow(x, low, modulus))\r\n exit(0)\r\n ", "import sys\r\nimport heapq\r\ninput = sys.stdin.readline\r\nMOD = int(1e9+7)\r\n\r\nn, x = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\ns, h = sum(a), []\r\nfor i in a:\r\n heapq.heappush(h, s-i)\r\np, cnt = 0, 0\r\nwhile h:\r\n z = heapq.heappop(h)\r\n if p == z:\r\n cnt += 1\r\n if cnt == x:\r\n heapq.heappush(h, p + 1)\r\n cnt = 0\r\n else:\r\n if cnt > 0:\r\n print(pow(x, min(p, s), MOD))\r\n exit()\r\n cnt = 1\r\n p = z\r\nprint(pow(x, min(p, s), MOD))\r\n", "n, x = map(int, input().split())\r\nt = list(map(int, input().split()))\r\nb = max(t)\r\nk = t.count(b)\r\nr = sum(t)\r\ns = r - b\r\nwhile k % x == 0:\r\n b -= 1\r\n s += 1\r\n k = k // x + t.count(b)\r\nprint(pow(x, min(r, s), 1000000007))", "import sys\r\n\r\ninput = lambda: sys.stdin.buffer.readline().decode().strip()\r\nmod = 10 ** 9 + 7\r\nn, x = map(int, input().split())\r\na, ans = [int(x) for x in input().split()], 1\r\n\r\nfor i in range(n - 1):\r\n ans = (ans * pow(x, a[i], mod)) % mod\r\n\r\nma = a[-1]\r\nwhile len(a) > 1:\r\n cur, num = a.pop(), 1\r\n\r\n while a and a[-1] == cur:\r\n a.pop()\r\n num += 1\r\n\r\n if num % x:\r\n a.append(cur)\r\n break\r\n\r\n while num:\r\n num -= x\r\n a.append(cur - 1)\r\n\r\nprint((ans * pow(x, min(ma, ma - a[-1]), mod)) % mod)\r\n", "input_str = input()\r\nn, x = int(input_str.split()[0]), int(input_str.split()[1])\r\ninput_str = input()\r\na = input_str.split()\r\ns = 0\r\nfor i in range(n):\r\n a[i] = int(a[i])\r\n #a.append(1000000000)\r\n s += a[i]\r\n\r\n'''\r\na = []\r\nfor i in range(n):\r\n if i<65536:\r\n temp = 1\r\n else:\r\n temp = 0#random.randint(0, 1000000000)\r\n s += temp\r\n a.append(temp)#(557523474, 999999999))'''\r\n\r\nsum_a = [s-a[i] for i in range(n)]\r\nminimum = min(sum_a)\r\nres = pow(x, minimum, 1000000007)#FastPow(x, minimum)#x**minimum\r\nsum_xa = 0\r\ns_new = s - minimum\r\nfor i in range(n):\r\n sum_xa += pow(x, s_new - a[i], 1000000007)#FastPow(x, s_new - a[i])\r\n\r\ndeg = 0\r\ndeg_zn = s-minimum\r\nts = sum_xa\r\nwhile sum_xa%1==0 and deg_zn:\r\n sum_xa /= x\r\n deg += 1 \r\n deg_zn -= 1\r\n # print (deg, sum_xa%1==0)\r\n#if (n, x) == (98304, 2):\r\n# print (minimum, s, ts, deg)\r\n\r\n\r\nif deg:\r\n res *= pow(x, deg-1 if sum_xa%1!=0 else deg)\r\nprint (res%1000000007)", "\n# Online Python - IDE, Editor, Compiler, Interpreter\nimport os\nimport statistics\n\nif __name__ == \"__main__\":\n str1 = input()\n n = int(str1.split()[0])\n x = int(str1.split()[1])\n \n str2 = input()\n a = str2.split()\n s = 0\n maxX = 0\n \n a = list(map(int, a))\n for i in range(0,n):\n s += a[i]\n\ni = n-1 \nj = 1\nk = 1\nkt = 1\n \nwhile kt == 1:\n while i > 0 and a[i] == a[i-1]:\n i -= 1\n k += 1\n \n if i > 0:\n i -= 1\n while k % x == 0 and a[n-1] > a[i]:\n k = k/x\n a[n-1] -= 1\n if a[n-1] != a[i] or a[i] == 0:\n kt = 0\n else:\n k += 1\n else:\n while k % x == 0:\n k = k/x\n a[n-1] -= 1\n kt = 0\n \nresult = s - a[n-1]\n \ndef modular_pow(base, exponent, modulus):\n result1 = 1\n while exponent > 0:\n if exponent % 2 == 1:\n result1 = (result1 * base) % modulus\n exponent -= 1\n \n exponent /= 2\n base = (base * base) % modulus\n \n return result1\n \nif result > s:\n result = s\n \nkq = modular_pow(x, result, 1000000007)\nprint(kq)", "#!/usr/bin/env python3\r\n\r\nimport sys\r\nimport heapq\r\n\r\nn, x = list(map(int, sys.stdin.readline().split()))\r\na = list(map(int, sys.stdin.readline().split()))\r\ns = sum(a)\r\n\r\nh = []\r\nfor y in a:\r\n heapq.heappush(h, s - y)\r\n\r\np, cnt = 0, 0\r\n\r\nwhile len(h) > 0:\r\n z = heapq.heappop(h)\r\n if p == z:\r\n cnt += 1\r\n if cnt == x:\r\n heapq.heappush(h, p + 1)\r\n cnt = 0\r\n else:\r\n if cnt != 0:\r\n print(pow(x, min(p, s), 10 ** 9 + 7))\r\n sys.exit(0)\r\n cnt = 1\r\n p = z\r\n\r\nprint(pow(x, min(p, s), 10 ** 9 + 7))\r\n", "M=1000000007\r\ndef modpow(x, p):\r\n if p==0:\r\n return 1\r\n y=modpow(x, p//2)\r\n if p%2:\r\n return (y*y*x)%M\r\n return (y*y)%M\r\nn,x=[int(e) for e in input().split()]\r\na=[int(e) for e in input().split()]\r\nasum=sum(a)\r\na=[asum-e for e in a][::-1]\r\nans=0\r\ni=0\r\nc=0\r\nwhile 1:\r\n ans+=a[i]-ans\r\n I=i\r\n while a[i]==a[I]:\r\n i+=1\r\n if i==n:\r\n break\r\n c+=i-I\r\n p=0\r\n while c%x==0:\r\n c//=x\r\n p+=1\r\n if i==n or a[i]-ans>p:\r\n ans+=p\r\n break\r\n else:\r\n c*=x**(p-(a[i]-ans))\r\nprint(modpow(x, min(ans, asum)))", "import sys\r\nfrom functools import lru_cache, cmp_to_key\r\nfrom heapq import merge, heapify, heappop, heappush\r\n# from math import *\r\nfrom collections import defaultdict as dd, deque, Counter as C\r\nfrom itertools import combinations as comb, permutations as perm\r\nfrom bisect import bisect_left as bl, bisect_right as br, bisect, insort\r\nfrom time import perf_counter\r\nfrom fractions import Fraction\r\nimport copy\r\nfrom copy import deepcopy\r\nimport time\r\nstarttime = time.time()\r\nmod = int(pow(10, 9) + 7)\r\nmod2 = 998244353\r\n\r\ndef data(): return sys.stdin.readline().strip()\r\ndef out(*var, end=\"\\n\"): sys.stdout.write(' '.join(map(str, var))+end)\r\ndef L(): return list(sp())\r\ndef sl(): return list(ssp())\r\ndef sp(): return map(int, data().split())\r\ndef ssp(): return map(str, data().split())\r\ndef l1d(n, val=0): return [val for i in range(n)]\r\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\r\ntry:\r\n # sys.setrecursionlimit(int(pow(10,6)))\r\n sys.stdin = open(\"input.txt\", \"r\")\r\n sys.stdout = open(\"../output.txt\", \"w\")\r\nexcept:\r\n pass\r\ndef pmat(A):\r\n for ele in A: print(*ele,end=\"\\n\")\r\n\r\n# from sys import stdin\r\n# input = stdin.buffer.readline\r\n# I = lambda : list(map(int,input().split()))\r\n\r\n# import sys\r\n# input=sys.stdin.readline\r\n\r\n\r\n\r\n\r\nn, x = L()\r\ns = L()\r\n\r\ntot = sum(s)\r\npowers=[tot-x for x in s]\r\npowers.sort(reverse=True)\r\n\r\nwhile True:\r\n\r\n low=powers[-1]\r\n cnt = 0\r\n while len(powers) > 0 and powers[-1]==low:\r\n cnt += 1\r\n powers.pop()\r\n if cnt%x==0:\r\n cnt=cnt // x\r\n for n in range(cnt):\r\n powers.append(low+1)\r\n else:\r\n low = min(low, tot)\r\n print(pow(x, low, mod))\r\n exit(0)\r\n", "MOD = 10**9+7\ndef pow(x, n, MOD):\n if(n==0):\n return 1\n if(n%2==0):\n a = pow(x, n//2, MOD)\n return a*a % MOD\n else:\n a = pow(x, n//2, MOD)\n return (x*a*a) % MOD\n\nn, x = [int(x) for x in input().split()]\na = [int(x) for x in input().split()]\ns = sum(a)\nd = []\n\nfor el in a:\n\td.append(s-el)\n\nd.sort()\ni=0\ngcd = d[0]\nc=0\nwhile i<n and d[i]==gcd:\n\tc+=1\n\ti+=1\n\nwhile c%x==0:\n\tc=c//x\n\tgcd+=1\n\t\n\twhile i<n and d[i]==gcd:\n\t\tc+=1\n\t\ti+=1\n\t\t\nif gcd>s:\n\tgcd = s\n\t\nprint( pow(x, gcd, MOD) )\n", "modulus = 10 ** 9 + 7\r\n\r\n\r\ndef main():\r\n n, x = map(int, input().split())\r\n arr = list(map(int, input().split()))\r\n\r\n total = sum(arr)\r\n powers = [total - x for x in arr]\r\n powers.sort(reverse=True)\r\n\r\n while True:\r\n\r\n low = powers[len(powers) - 1]\r\n\r\n cnt = 0\r\n\r\n while len(powers) > 0 and powers[len(powers) - 1] == low:\r\n cnt += 1\r\n powers.pop()\r\n\r\n if cnt % x == 0:\r\n cnt = cnt // x\r\n for i in range(cnt):\r\n powers.append(low + 1)\r\n else:\r\n low = min(low, total)\r\n print(pow(x, low, modulus))\r\n exit(0)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "R,G=lambda:map(int,input().split()),range\r\nn,x=R();a=[*R()];s=sum(a);v,c=a[-1],0\r\nwhile v:\r\n while a and v==a[-1]:a.pop();c+=1\r\n if c%x:break\r\n c//=x;v-=1\r\nprint(pow(x,s-v,10**9+7))" ]
{"inputs": ["2 2\n2 2", "3 3\n1 2 3", "2 2\n29 29", "4 5\n0 0 0 0", "1 2\n1000000000", "26 2\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2", "26 7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2", "3 2\n0 1 1", "1 127\n1000000000", "1 800000011\n800000011", "1 800000011\n999999999", "3 3\n1 1 1"], "outputs": ["8", "27", "73741817", "1", "1", "8", "49", "4", "1", "1", "1", "27"]}
UNKNOWN
PYTHON3
CODEFORCES
13
207081d9060d847aa6f8df056fb88ba6
Divisibility
IT City company developing computer games invented a new way to reward its employees. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each transaction. Every time when the next number of sales is divisible by all numbers from 2 to 10 every developer of this game gets a small bonus. A game designer Petya knows that the company is just about to release a new game that was partly developed by him. On the basis of his experience he predicts that *n* people will buy the game during the first month. Now Petya wants to determine how many times he will get the bonus. Help him to know it. The only line of the input contains one integer *n* (1<=≤<=*n*<=≤<=1018) — the prediction on the number of people who will buy the game. Output one integer showing how many numbers from 1 to *n* are divisible by all numbers from 2 to 10. Sample Input 3000 Sample Output 1
[ "# LUOGU_RID: 113656736\nprint(int(input())//2520)", "import math\r\nn = int(input())\r\nb = math.sqrt(n)\r\nc=0\r\nprint(n//2520)", "from math import floor\r\nn = int(input())\r\nprint(floor(n/2520))", "print(int(input())//2520)", "x = int(input())\nprint( x // 2520)\n \t\t \t\t \t \t\t \t \t\t \t\t\t \t", "n = int(input())\r\nans = n // 2520\r\nprint(ans)\r\n\n# Sun Aug 06 2023 06:37:01 GMT+0300 (Moscow Standard Time)\n", "n = int(input())\r\nans = n // 2520\r\nprint(ans)\r\n", "from math import comb, factorial\r\nn = int(input())\r\nprint(n // 2520)", "from math import lcm \r\nprint(str(int(input())//lcm(*list(range(2, 11)))))\r\n\r\n", "x=2520\r\na=int(input())\r\nprint(a//x)", "n=int(input())\r\ncount=0\r\nlk=2520\r\nk=n//lk\r\nprint(k)", "from math import lcm as l\r\nfrom math import floor as f\r\nx=int(input())\r\ny=l(1,2,3,4,5,6,7,8,9,10)\r\nprint(int(f(x/y)))", "from math import lcm\r\n\r\n\r\nn = int(input())\r\n# print(lcm(2,3,4,5,6,7,8,9,10)) 2520\r\nprint(n//2520)" ]
{"inputs": ["3000", "2520", "2519", "2521", "1", "314159265", "718281828459045235", "1000000000000000000", "987654321234567890", "3628800", "504000000000000000"], "outputs": ["1", "1", "0", "1", "0", "124666", "285032471610732", "396825396825396", "391926317950225", "1440", "200000000000000"]}
UNKNOWN
PYTHON3
CODEFORCES
13
207eede200d9ba24f994330c2b8cfabe
Pearls in a Row
There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of pearls in a row. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) – the type of the *i*-th pearl. On the first line print integer *k* — the maximal number of segments in a partition of the row. Each of the next *k* lines should contain two integers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the number of the leftmost and the rightmost pearls in the *j*-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1". Sample Input 5 1 2 3 4 1 5 1 2 3 4 5 7 1 2 1 3 1 2 1 Sample Output 1 1 5 -1 2 1 3 4 7
[ "n = int(input())\r\nli = list(map(int,input().split()))\r\ns=set()\r\notv=[]\r\nl=0\r\nr=-1\r\nfor i in range(n):\r\n\tif li[i] in s:\r\n\t\totv.append([l+1,i+1])\r\n\t\ts = set()\r\n\t\tl = i+1\r\n\t\tr=1\r\n\telse:\r\n\t\ts.add(li[i])\r\nif r==-1:\r\n\tprint(-1)\r\nelse:\r\n\tprint(len(otv))\r\n\totv[len(otv)-1][1]=n\r\n\tfor i in otv:\r\n\t\tprint(*i)\r\n", "from sys import stdin, stdout, exit\r\nn = int(stdin.readline())\r\na = [int(i) for i in stdin.readline().split()]\r\nans = []\r\ns = set()\r\ni = 0\r\nj = -1\r\nwhile True:\r\n j += 1\r\n if j == n:\r\n if len(ans) != 0:\r\n ans[-1] = (ans[-1][0], j - 1)\r\n break\r\n if a[j] in s:\r\n s = set()\r\n ans.append((i, j))\r\n i = j + 1\r\n j = i - 1\r\n else:\r\n s.add(a[j])\r\nif len(ans) == 0:\r\n print(-1)\r\n exit(0)\r\nstdout.write(str(len(ans)) + '\\n')\r\nfor x, y in ans:\r\n stdout.write(str(x + 1) + ' ' + str(y + 1) + '\\n')\r\n \r\n", "n = int(input())\nA = [int(x) for x in input().split()]\ns = {A[0]}\nleft = 1\nsegments = []\nfor i in range(1, n):\n if A[i] in s:\n segments.append((left, i+1))\n left = i+2\n s.clear()\n else:\n s.add(A[i])\nif len(segments) == 0:\n print(-1)\nelse:\n segments[-1] = (segments[-1][0], n)\n print(len(segments))\n for l, r in segments:\n print(l, r)\n", "n = int(input())\r\na = [int(x) for x in input().split()]\r\n\r\n\r\ni,j = 0,0\r\nseen = set()\r\nsegments = []\r\nwhile j < n:\r\n if a[j] in seen:\r\n seen = set()\r\n segments.append((i+1,j+1))\r\n j += 1\r\n i = j\r\n else:\r\n seen.add(a[j])\r\n j += 1\r\n\r\nif not segments:\r\n print(-1)\r\nelse:\r\n if i < n:\r\n segments[-1] = (segments[-1][0], n)\r\n print(len(segments))\r\n for s in segments:\r\n print(s[0], s[1])\r\n", "def main():\n n, res = int(input()), []\n s, i, fmt = set(), 1, \"{:n} {:n}\".format\n for j, a in enumerate(input().split(), 1):\n if a in s:\n s = set()\n res.append(fmt(i, j))\n i = j + 1\n else:\n s.add(a)\n if res:\n print(len(res))\n res[-1] = res[-1].split()[0] + ' ' + str(n)\n print('\\n'.join(res))\n else:\n print(-1)\n\n\nif __name__ == '__main__':\n main()\n", "n = int(input())\nli = list(map(int,input().split()))\ns=set()\nans=[]\nl=0\nc=-1\nfor i in range(n):\n\tif li[i] in s:\n\t\tans.append([l+1,i+1])\n\t\ts = set()\n\t\tl = i+1\n\t\tc=1\n\telse:\n\t\ts.add(li[i])\nif c==-1:\n\tprint(-1)\nelse:\n\tprint(len(ans))\n\tans[len(ans)-1][1]=n\n\tfor i in ans:\n\t\tprint(*i)\n\t \t\t\t\t\t \t\t\t \t\t \t\t \t \t \t\t\t", "n=int(input())\nd={}\nb=[]\ne=1\na=list(map(int,input().split()))\nfor i in range(n):\n\tif a[i] in d:\n\t\tb.append([e,i+1])\n\t\te=i+2\n\t\td.clear()\n\telse: d[a[i]]=i+1\t \nif len(b)==0:\n\tprint(-1)\n\texit()\t\t\nprint(len(b))\nk=b[-1]\nb[-1]=[k[0],n]\nfor i in b: print(*i)\t\t\n\t\t \t\t\t\t\t \t \t \t\t \t \t\t \t\t\t \t \t\t\t\t", "n = int(input())\r\nlis=[*map(int,input().split())]\r\nans=[]\r\nk=0;s = set()\r\nfor i in range(n):\r\n if lis[i] in s:\r\n ans.append([k+1,i+1])\r\n k=i+1\r\n s = set()\r\n else:\r\n s.add(lis[i])\r\nc=len(ans) \r\nif c==0:\r\n print('-1')\r\nelse:\r\n print(c)\r\n ans[-1][1]=n\r\n for i in ans:\r\n print(*i)", "import sys\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nleft = set()\r\ni = 1\r\nans = []\r\n\r\nfor j, x in enumerate(a, start=1):\r\n if x in left:\r\n ans.append([i, j])\r\n left.clear()\r\n i = j+1\r\n else:\r\n left.add(x)\r\n\r\nif not ans:\r\n print(-1)\r\nelse:\r\n ans[-1][1] = n\r\n s = str(len(ans)) + '\\n' + '\\n'.join(' '.join((str(x), str(y)))\r\n for x, y in ans)\r\n sys.stdout.buffer.write(s.encode('utf-8'))\r\n", "#code\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nif(len(set(a))==n):\r\n print(-1)\r\nelse:\r\n ls=[]\r\n b=set()\r\n l=1\r\n b.add(a[0])\r\n for i in range(1,n):\r\n if(a[i] not in b):\r\n b.add(a[i])\r\n else:\r\n ls.append([l,i+1])\r\n l=i+2\r\n b=set()\r\n if(ls[-1][1]!=n):\r\n ls[-1][1]=n\r\n print(len(ls))\r\n for i in range(len(ls)):\r\n print(*ls[i])", "import sys\nfrom math import *\nfrom collections import Counter,defaultdict,deque\ninput=sys.stdin.readline\nmod=10**9+7\ndef get_ints():return map(int,input().split())\ndef get_int():return int(input())\ndef get_array():return list(map(int,input().split()))\ndef input():return sys.stdin.readline().strip()\n\n# for _ in range(int(input())):\nn=int(input())\na=get_array()\nd=defaultdict(int)\nif len(set(a))==len(a):\n print(-1)\n exit()\npairs=[]\nstart=1\nfor i in range(n):\n d[a[i]]+=1\n if d[a[i]]==2:\n pairs.append((start,i+1))\n start=i+2\n d=defaultdict(int)\nprint(len(pairs))\nif pairs[-1][-1]!=n:\n pairs[-1]=pairs[-1][0],n\nfor i in pairs:\n print(*i)", "n = int(input())\na = list(map(int, input().split()))\n# greedy\nused = {}\nx,y = [],[]\nfor i in range(n):\n if not used:\n used[a[i]] = 1\n x.append(i)\n elif a[i] in used and used[a[i]] == 1:\n y.append(i)\n used = {}\n else:\n used[a[i]] = used.get(a[i],0) + 1\n\nif not y:\n print(-1)\nelse:\n if len(x) > len(y):\n del x[-1]\n y[-1] = n-1\n print(len(x))\n #print(x)\n #print(len(y))\n #print(y)\n for i in range(len(x)):\n #print(\"index \", i)\n print(x[i]+1,y[i]+1)\n", "n = int(input())\r\nli = list(map(int,input().split()))\r\ns=set()\r\nans=[]\r\nl=0\r\nr=-1\r\nfor i in range(n):\r\n\tif li[i] in s:\r\n\t\tans.append([l+1,i+1])\r\n\t\ts = set()\r\n\t\tl = i+1\r\n\t\tr=1\r\n\telse:\r\n\t\ts.add(li[i])\r\nif r==-1:\r\n\tprint(-1)\r\nelse:\r\n\tprint(len(ans))\r\n\tans[len(ans)-1][1]=n\r\n\tfor i in ans:\r\n\t\tprint(*i)", "n = int(input())\r\na = list(map(int, input().split()))\r\nd = {}\r\nk = 0\r\nans = []\r\nj = 0\r\nfor i in range(n):\r\n if a[i] in d:\r\n if d[a[i]] >= j:\r\n ans.append([j + 1, i + 1])\r\n j = i + 1\r\n k += 1\r\n d[a[i]] = i\r\nprint(k if not k == 0 else -1)\r\nfor i in range(k):\r\n if not i == k - 1:\r\n print(ans[i][0], ans[i][1])\r\n else:\r\n print(ans[i][0], n)", "from sys import stdin\r\n\r\nn = int(stdin.buffer.readline())\r\na = list(map(int, stdin.buffer.readline().split()))\r\n\r\nmp = dict()\r\nl = 0\r\nres = list()\r\nfor i in range(n):\r\n if a[i] in mp:\r\n res.append((l + 1, i + 1))\r\n mp.clear()\r\n l = i + 1\r\n else:\r\n mp[a[i]] = 1\r\nif len(res) == 0:\r\n print(-1)\r\n exit()\r\nprint(len(res))\r\nfor i in range(len(res)):\r\n if i == len(res) - 1:\r\n print(res[i][0],n)\r\n else:\r\n print(res[i][0],res[i][1])\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nN = int(input())\r\nA = list(map(int, input().split()))\r\n\r\nif len(set(A)) == N:\r\n print(-1)\r\n\r\nelse:\r\n S = set()\r\n res = []\r\n lt = 1\r\n\r\n for i in range(N):\r\n if A[i] in S:\r\n res.append([lt, i + 1])\r\n S = set()\r\n lt = i + 2\r\n else:\r\n S.add(A[i])\r\n res[-1][-1] = N\r\n \r\n print(len(res))\r\n\r\n for i in range(len(res)):\r\n res[i] = ' '.join(map(str, res[i]))\r\n\r\n print('\\n'.join(map(str, res)))", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\ni = 0\r\ns = set()\r\nq = []\r\na = 0\r\nwhile i < n:\r\n if w[i] not in s:\r\n s.add(w[i])\r\n else:\r\n s = set()\r\n q.append((a+1, i+1))\r\n a = i+1\r\n i += 1\r\nif len(q) == 0:\r\n print(-1)\r\nelse:\r\n q[-1] = (q[-1][0], n)\r\n print(len(q))\r\n for i in q:\r\n print(*i)\r\n", "n=int(input())\r\nd={}\r\nb=[]\r\ne=1\r\na=list(map(int,input().split()))\r\nfor i in range(n):\r\n\tif a[i] in d:\r\n\t\tb.append([e,i+1])\r\n\t\te=i+2\r\n\t\td.clear()\r\n\telse: d[a[i]]=i+1\t \r\nif len(b)==0:\r\n\tprint(-1)\r\n\texit()\t\t\r\nprint(len(b))\r\nk=b[-1]\r\nb[-1]=[k[0],n]\r\nfor i in b: print(*i)\t\t", "n=int(input())\r\nl=list(map(int,input().split()))\r\nL=[]\r\nd={}\r\nost=-1\r\nfor i in range(n) :\r\n e=d.get(l[i],-1)\r\n if e==-1 :\r\n d[l[i]]=i\r\n else :\r\n if e<ost :\r\n d[l[i]]=i\r\n else :\r\n L.append(i)\r\n ost=i\r\n d[l[i]]=-1\r\ng=len(L)\r\nif g==0 :\r\n print(-1)\r\n exit()\r\nprint(g)\r\np=1\r\nfor i in range(g-1) :\r\n print(p,L[i]+1) ;\r\n p=L[i]+2\r\nprint(p,n)\r\n\r\n\r\n", "count = 0\r\nN=int(input())\r\nA=list(map(int,input().split()))+['-1']\r\nD={}\r\nAns=[]\r\na,b=1,1\r\nfor val in A:\r\n if val in D:\r\n D[val] += 1\r\n else:\r\n D[val] = 1\r\n if D[val] % 2 ==0:\r\n Ans.append([str(a),str(b)])\r\n a=b+1\r\n D={}\r\n b += 1\r\nL=len(Ans)\r\nif L ==0:\r\n print(-1)\r\nelse:\r\n Ans[-1][1]=str(N)\r\n print(L)\r\n for val in Ans:\r\n print(' '.join(val))\r\n ", "n=int(input())\narr=list(map(int,input().split()))\narr2=[0]*300005\ns=set()\ntemp=0\nfor i in range(n):\n if arr[i] in s:\n arr2[temp]=i+1\n temp+=1\n s.clear()\n else:\n s.add(arr[i])\nif temp==0:\n print(-1)\nelse:\n arr2[temp-1]=n\n print(temp)\n print(1,arr2[0])\n for i in range(1,temp):\n print(arr2[i-1]+1,arr2[i])\n\n\n\n\n\n\n \t\t\t \t\t \t\t \t \t \t \t\t\t\t \t \t \t\t", "length = int(input())\r\ngems = input().split()\r\n\r\nresult = []\r\ns = 0\r\ndist = set()\r\npend_e = 0\r\npend_s = 0\r\nfor i in range(0, length):\r\n cur = gems[i]\r\n if cur not in dist:\r\n dist.add(cur)\r\n else:\r\n if pend_e != 0:\r\n result.append([pend_s, pend_e])\r\n pend_e = i + 1\r\n pend_s = s + 1\r\n s = i + 1\r\n dist.clear()\r\n\r\nif s != 0 and pend_e != length + 1:\r\n result.append([pend_s, length])\r\n\r\nif len(result) == 0:\r\n print(-1)\r\nelse:\r\n print(len(result))\r\n\r\nfor r in result:\r\n print(r[0], r[1])\r\n", "n = int(input())\r\nindex = 1\r\nmemory = set()\r\ncounter = 0\r\nsegments = [[0, 0]]\r\nfor number in input().split():\r\n if number not in memory:\r\n memory.add(number)\r\n else:\r\n counter += 1\r\n segments.append([segments[-1][1] + 1, index])\r\n memory = set()\r\n index += 1\r\nsegments[-1][1] = n\r\nif counter != 0:\r\n print(counter)\r\n segments.remove([0, 0])\r\n print('\\n'.join('{0} {1}'.format(p, q) for (p, q) in segments))\r\nelse:\r\n print(-1)", "n = int(input())\r\nty = list(map(int, input().split()))\r\nnum = 0\r\nx = 1\r\nseg = []\r\na = 1\r\ndic = {}\r\nfor i in range(n):\r\n dic[ty[i]] = 0\r\ndic[ty[0]] = 1\r\nfor i in range(1, n):\r\n jud = 0\r\n if dic[ty[i]] != num + 1:\r\n dic[ty[i]] = num + 1\r\n elif dic[ty[i]] == num + 1:\r\n jud = 1\r\n num += 1\r\n b = i + 1\r\n ls = [str(a), str(b)]\r\n seg.append(ls)\r\n a = i + 2\r\nif len(seg) == 0:\r\n print(-1)\r\nelse:\r\n if jud == 0:\r\n seg[-1][1] = str(n)\r\n print(num)\r\n for i in range(len(seg)):\r\n print(' '.join(seg[i]))\r\n\r\n\r\n\r\n\r\n", "pearl_count = int(input())\r\npearls = [int(pearl) for pearl in input().split()]\r\nrecorded = set()\r\nintervals = []\r\nbegin = 1\r\nfor i in range(pearl_count):\r\n if pearls[i] in recorded:\r\n intervals.append([begin, i + 1])\r\n recorded = set()\r\n begin = i + 2\r\n else:\r\n recorded.add(pearls[i])\r\nif intervals:\r\n intervals[-1][-1] = pearl_count\r\n print(len(intervals))\r\n [print(' '.join(map(str, interval))) for interval in intervals]\r\nelse:\r\n print(-1)", "n = int(input())\na = list(map(int, input().split(' ')))\n\nans = []\n\ns = 0\nmark = set([a[0]])\nfor i in range(1, n):\n if a[i] in mark:\n mark = set()\n ans.append([s+1, i+1])\n s = i+1\n else:\n mark.add(a[i])\n\nif len(ans) == 0:\n print(-1)\nelse:\n ans[-1][1] = n\n print(len(ans))\n for line in ans:\n print(line[0], line[1])\n", "\r\nn = int(input())\r\na = input()\r\na = a.split()\r\na = [int(x) for x in a]\r\ns = set()\r\nx1 = 0\r\nx2 = 0\r\nrz = []\r\nfor i in range(n):\r\n ch = a[i]\r\n if ch in s:\r\n x2 = i\r\n rz.append([x1+1, x2+1])\r\n x1 = i + 1\r\n s = set()\r\n else:\r\n s.add(ch)\r\n\r\n\r\nif rz ==[]:\r\n print(-1)\r\nelse:\r\n if x2 < n - 1:\r\n rz[-1][1] = n\r\n print(len(rz))\r\n for i in rz:\r\n print(i[0], i[1])\r\n", "#!/usr/bin/python3\n\nn = int(input())\na = [int(x) for x in input().split()]\n\nr = []\ns = set()\nl = 0\nfor i, x in enumerate(a):\n if x in s:\n r.append([l + 1, i + 1])\n l = i + 1\n s = set()\n else:\n s.add(x)\nif l == 0:\n print(-1)\nelse:\n if s:\n r[-1][1] = n\n print(len(r))\n print('\\n'.join('{0} {1}'.format(p, q) for (p, q) in r))\n\n", "n = int(input())\r\na = list(map(int, input().split()))\r\nuniq = set(a)\r\nif len(uniq) == n:\r\n\tprint(-1)\r\n\texit(0)\r\nans = []\r\nst = 0\r\nwhile st < n:\r\n\tseen = set()\r\n\ted = st\r\n\twhile ed < n:\r\n\t\tif a[ed] not in seen:\r\n\t\t\tseen.add(a[ed])\r\n\t\t\ted += 1\r\n\t\telse:\r\n\t\t\tbreak\r\n\tif ed < n:\r\n\t\tans.append([st+1, ed+1])\r\n\telse:\r\n\t\t# last segment is not good\r\n\t\tif not ans:\r\n\t\t\tprint(-1)\r\n\t\t\texit(0)\r\n\t\telse:\r\n\t\t\tans[-1][1] = n\r\n\t\t\tbreak\r\n\tst = ed + 1\r\nprint(len(ans))\r\nfor p in ans:\r\n\tprint(p[0], p[1])", "n=int(input())\r\na=list(map(int,input().split()))\r\nl=[]\r\nk=set()\r\nfor i in range(n):\r\n if a[i] not in k:\r\n k.add(a[i])\r\n else:\r\n l+=[i]\r\n k=set()\r\nif l:\r\n l[-1]=n-1\r\n print(len(l))\r\n o=1\r\n for i in l:\r\n print(o,i+1)\r\n o=i+2\r\nelse:\r\n print(-1)", "n = int(input())\r\na = map(int, input().split())\r\nst = 1\r\ncnt = set()\r\nanswer = []\r\nfor i, x in enumerate(a):\r\n\tif x in cnt:\r\n\t\ten = i + 1\r\n\t\tanswer.append([st, en])\r\n\t\tcnt = set()\t\t\t\r\n\t\tst = i + 2\r\n\telse:\r\n\t\tcnt.add(x)\r\n\r\nif len(answer) == 0:\r\n\tprint (-1)\r\nelse:\r\n\tprint (len(answer))\r\n\tanswer[-1][1] = n\r\n\tfor x in answer:\r\n\t\tprint (x[0], x[1])", "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nans=[]\r\nL=0\r\ns=set()\r\nfor i in range(n):\r\n ai=a[i]\r\n if ai in s:\r\n ans.append([L,i])\r\n s=set()\r\n L=i+1\r\n else:\r\n s.add(ai)\r\n\r\nif ans:\r\n ans[-1][1]=n-1\r\n print(len(ans))\r\n for l,r in ans:\r\n print(l+1,r+1)\r\nelse:\r\n print(-1)", "# 7\r\n# 1 2 1 3 1 2 1\r\nn=int(input())\r\nl=[*map(int,input().split())]\r\nans=[]\r\nss = set()\r\np=0\r\nfor i,v in enumerate(l):\r\n if v in ss:\r\n ss.clear()\r\n ans.append((p+1,i+1))\r\n p = i+1\r\n else:\r\n ss.add(v)\r\nif ans:\r\n print(len(ans))\r\n for t in ans[:-1]:\r\n print(*t)\r\n print(ans[-1][0], n)\r\nelse:\r\n print(-1)", "n = int(input())\r\na = list(map(int, input().strip().split()))\r\ni = 0\r\n\r\nd = dict()\r\nres = []\r\ns = 1\r\nwhile i < n:\r\n if a[i] in d.keys():\r\n res.append([s, i+1])\r\n d = dict()\r\n s = i+2\r\n else:\r\n d[a[i]] = 1\r\n i += 1\r\ntry:\r\n res[-1][1] = n\r\nexcept:\r\n pass\r\n\r\nif len(res) > 0:\r\n print(len(res))\r\n for i in res:\r\n print (\" \".join(map(str, i)))\r\nelse:\r\n print(-1)", "# your code goes here\n# your code goes here\n# your code goes here\nfrom sys import stdin,stdout\nn=int(stdin.readline())\narr=[int(x) for x in stdin.readline().split()]\nd=set()\nstart=[]\nend=[]\ntag=1\nfor i in range(n):\n\tif arr[i] in d:\n\t\ti=i+1\n\t\tend.append(i)\n\t\tstart.append(tag)\n\t\ttag=i+1\n\t\td.clear()\n\telse:\n\t\td.add(arr[i])\nl=len(start)\n#print(start)\n#print(end)\nif(l):\n\tstdout.write(str(l)+\"\\n\")\n\tfor i in range(l):\n\t\tif(i==l-1):\n\t\t\tstdout.write(str(start[i])+\" \"+str(n))\n\t\t\t#stdout.write(str(n)+\"\\n\")\n\t\telse:\n\t\t\tstdout.write(str(start[i])+\" \"+str(end[i])+\"\\n\")\n\t\t\t#stdout.write(str(end[i])+\"\\n\")\nelse:\n\tstdout.write(\"-1\"+\"\\n\")\n \t \t \t\t \t\t\t\t\t\t \t\t\t \t \t\t\t", "n = int(input())\r\nlst = list(map(int,input().split()))\r\nd,res,result,j = {},[],0,1\r\nfor i,x in enumerate(lst):\r\n if d.get(x)==None:d[x]=1\r\n else:\r\n result+=1\r\n res.append([j,i+1])\r\n j=i+2\r\n d = {}\r\nif res==[] and result==0:\r\n print(-1)\r\n from sys import exit;exit()\r\nif res[result-1][1]!=n:\r\n res[result-1][1]=n\r\nprint(result)\r\nfor i,x in enumerate(res):print(*x)", "n = int(input())\r\na = list(map(int, input().split()))\r\nd = dict()\r\nres = []\r\nfor i in range(len(a)):\r\n d[a[i]] = d.get(a[i], 0) + 1 \r\n if d[a[i]] % 2 == 0:\r\n res.append(i)\r\n d.clear()\r\n\r\nif len(res):\r\n res[-1] = n-1\r\n print(len(res))\r\n x = 0\r\n for i in res:\r\n print(x+1, i+1)\r\n x = i+1\r\nelse:\r\n print(-1)", "n = int(input())\r\ncnt = 0\r\ngems = list(map(int, input().split()))\r\npearls = set()\r\nfor i in range(n):\r\n if gems[i] not in pearls:\r\n pearls.add(gems[i])\r\n else:\r\n cnt += 1\r\n pearls = set()\r\n \r\nif cnt:\r\n print(cnt)\r\n first = 0\r\n second = 0\r\n pearls = set()\r\n for i in range(n):\r\n if gems[i] not in pearls:\r\n pearls.add(gems[i])\r\n else:\r\n if second:\r\n print(first + 1, second + 1)\r\n first = second + 1\r\n second = i\r\n pearls = set()\r\n print(first + 1, n)\r\nelse:\r\n print('-1')", "n=int(input())\nd={}\narr=[]\np=list(map(int,input().split()))\nl=0\nfor i in range(n):\n try:\n d[p[i]]+=1\n arr.append([l+1,i+1])\n l=i+1\n d={}\n except:\n d[p[i]]=1\nif len(arr)!=0:\n arr[-1][1]=max(arr[-1][1],n)\nif len(arr)==0:\n print(-1)\nelse:\n print(len(arr))\n for i in range(len(arr)):\n print(arr[i][0],arr[i][1])\n\t\t\t \t \t \t\t \t \t \t \t \t\t\t\t" ]
{"inputs": ["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1", "9\n1 2 1 2 1 2 1 2 1", "11\n1 1 2 1 2 1 2 1 2 1 1", "1\n576560149", "10\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451", "10\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 80672280 80672280 933677171", "10\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597", "7\n13 9 19 13 3 13 12", "3\n1 1 1", "5\n1 2 2 2 3", "5\n1 2 2 2 1", "13\n1 1 1 1 1 1 1 1 1 1 1 1 1", "4\n1 2 1 2"], "outputs": ["1\n1 5", "-1", "2\n1 3\n4 7", "3\n1 3\n4 6\n7 9", "4\n1 2\n3 5\n6 8\n9 11", "-1", "5\n1 2\n3 4\n5 6\n7 8\n9 10", "4\n1 3\n4 5\n6 7\n8 10", "2\n1 3\n4 10", "1\n1 7", "1\n1 3", "1\n1 5", "1\n1 5", "6\n1 2\n3 4\n5 6\n7 8\n9 10\n11 13", "1\n1 4"]}
UNKNOWN
PYTHON3
CODEFORCES
39
208c10eb84654fa8b3a2fc7a644f7f88
Grammar Lessons
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules: - There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. - There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. - Masculine adjectives end with -lios, and feminine adjectives end with -liala. - Masculine nouns end with -etr, and feminime nouns end with -etra. - Masculine verbs end with -initis, and feminime verbs end with -inites. - Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. - It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. - There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. - A sentence is either exactly one valid language word or exactly one statement. Statement is any sequence of the Petya's language, that satisfy both conditions: - Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. - All words in the statement should have the same gender. After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105. It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). Sample Input petr etis atis animatis etis atis amatis nataliala kataliala vetra feinites Sample Output YES NO YES
[ "import sys,os,math,cmath,timeit,functools,operator,bisect\r\nfrom sys import stdin,stdout,setrecursionlimit\r\nfrom io import BytesIO, IOBase\r\nfrom collections import defaultdict as dd , Counter\r\nfrom math import factorial , gcd\r\nfrom queue import PriorityQueue\r\nfrom heapq import merge, heapify, heappop, heappush\r\ntry :\r\n from functools import cache , lru_cache\r\nexcept :\r\n pass\r\n\r\nONLINE_JUDGE = __debug__\r\n\r\nclass FastIO(IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n import os\r\n self.os = os\r\n self._fd = file.fileno()\r\n self.buffer = BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n self.BUFSIZE = 8192\r\n\r\n def read(self):\r\n while True:\r\n a = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))\r\n if not a:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(a), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n a = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))\r\n self.newlines = a.count(b\"\\n\") + (not a)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(a), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n self.os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\nstdin, stdout = IOWrapper(stdin), IOWrapper(stdout)\r\n\r\ninput = lambda: stdin.readline().rstrip(\"\\r\\n\")\r\n\r\nstart = timeit.default_timer()\r\n\r\nprimes = []\r\nmod=10**9+7\r\nMOD=998244353\r\n\r\n########################################################\r\n\r\nclass DSU:\r\n def __init__(self,n):\r\n self.par = [i for i in range(n+1)]\r\n self.rank = [1 for i in range(n+1)]\r\n self.sz = [1 for i in range(n+1)]\r\n def find(self,x):\r\n if self.par[x]!=x :\r\n self.par[x] = self.find(self.par[x])\r\n return self.par[x]\r\n def union(self,x,y):\r\n rx,ry = self.find(x),self.find(y)\r\n if rx==ry :\r\n return False\r\n if self.rank[rx] > self.rank[ry] :\r\n self.sz[rx]+=self.sz[ry]\r\n self.par[ry]=rx\r\n elif self.rank[ry] > self.rank[rx] :\r\n self.sz[ry]+=self.sz[rx]\r\n self.par[rx]=ry\r\n else :\r\n self.rank[rx]+=1\r\n self.par[ry]=rx\r\n self.sz[rx]+=self.sz[ry]\r\n return True\r\n def connected(self,x,y):\r\n return self.find(x)==self.find(y)\r\n\r\ndef countinversions(a,ans):\r\n if(len(a)==1) : return a\r\n mid = len(a)//2\r\n x = a[:mid]\r\n y = a[mid:]\r\n left = countinversions(x,ans)\r\n right = countinversions(y,ans)\r\n temp = []\r\n i,j=0,0\r\n while i<len(left) and j<len(right):\r\n if left[i]<=right[j] :\r\n temp.append(left[i])\r\n i+=1\r\n else :\r\n temp.append(right[j])\r\n j+=1\r\n ans+=len(left)-i\r\n while i<len(left) : temp.append(right[i]) ; i+=1\r\n while j<len(right) : temp.append(left[j]) ; j+=1\r\n return temp\r\n\r\n########################################################\r\n\r\ndef seive(n):\r\n a = []\r\n prime = [True for i in range(n+1)] \r\n p = 2\r\n while (p * p <= n): \r\n if (prime[p] == True): \r\n for i in range(p ** 2,n + 1, p): \r\n prime[i] = False\r\n p = p + 1\r\n for p in range(2,n + 1): \r\n if prime[p]: \r\n primes.append(p)\r\n\r\ndef lower_bound(arr, n, k):\r\n start = 0\r\n end = n-1\r\n while start <= end:\r\n mid = (start+end)//2\r\n if arr[mid] == k:\r\n return mid\r\n elif arr[mid] > k:\r\n if mid > 0:\r\n if arr[mid-1] < k:\r\n return (mid-1)\r\n else:\r\n return -1\r\n else:\r\n if mid < (n-1):\r\n if arr[mid+1] > k:\r\n return mid\r\n else:\r\n return mid\r\n\r\ndef upper_bound(arr, n, k):\r\n start = 0\r\n end = n-1\r\n while start <= end:\r\n mid = (start+end)//2\r\n if arr[mid] == k:\r\n return mid\r\n elif arr[mid] > k:\r\n if mid > 0:\r\n if arr[mid-1] < k:\r\n return (mid)\r\n else:\r\n return mid\r\n else:\r\n if mid < (n-1):\r\n if arr[mid+1] > k:\r\n return (mid+1)\r\n else:\r\n return -1\r\n\r\ndef is_sorted(arr):\r\n return all(arr[i]<=arr[i+1] for i in range(len(arr)-1))\r\n\r\ndef invmod(n):\r\n return pow(n,mod-2,mod)\r\n\r\ndef binary_search(a,x,lo=0,hi=None):\r\n if hi is None:\r\n hi = len(a)\r\n while lo < hi:\r\n mid = (lo+hi)//2\r\n midval = a[mid]\r\n if midval < x:\r\n lo = mid+1\r\n elif midval > x: \r\n hi = mid\r\n else:\r\n return mid\r\n return -1\r\n\r\ndef ceil(a:int,b:int)->int :\r\n return (a+b-1)//b\r\n\r\ndef yn(x):\r\n if x :\r\n print(\"YES\")\r\n else :\r\n print(\"NO\")\r\n\r\ndef nCr(n,r):\r\n return factorial(n)//(factorial(r)*factorial(n-r))\r\n\r\ndef countinversions(arr):\r\n if len(arr)==1 :\r\n return arr,0\r\n left = arr[:len(arr)//2]\r\n right = arr[len(arr)//2:]\r\n left,lc = countinversions(left)\r\n right,rc = countinversions(right)\r\n c = []\r\n i,j,ans = 0,0,lc+rc\r\n while i<len(left) and j<len(right):\r\n if left[i] <= right[j] :\r\n c.append(left[i])\r\n i+=1\r\n else :\r\n c.append(right[j])\r\n ans+=len(left)-i\r\n j+=1\r\n c+=left[i:]\r\n c+=right[j:]\r\n return c,ans\r\n\r\n########################################################\r\n\r\ndef solve():\r\n s=input().split()\r\n a=''\r\n tt=[]\r\n for x in s :\r\n if x[-4:]==\"lios\" :\r\n tt+=['m']\r\n a+='a'\r\n elif x[-5:]==\"liala\" :\r\n tt+=['f']\r\n a+='a'\r\n elif x[-3:]==\"etr\" :\r\n tt+=['m']\r\n a+='n'\r\n elif x[-4:]==\"etra\" :\r\n tt+=['f']\r\n a+='n'\r\n elif x[-6:]==\"initis\" :\r\n tt+=['m']\r\n a+='v'\r\n elif x[-6:]==\"inites\" :\r\n tt+=['f']\r\n a+='v'\r\n else :\r\n print(\"NO\")\r\n return \r\n if len(tt)==1 :\r\n print(\"YES\")\r\n return\r\n if len(set(tt))==2 or a.count('n')!=1 :\r\n print(\"NO\")\r\n return\r\n noun = a.index('n')\r\n temp = a.split('n')\r\n adj=-1 \r\n fl=0\r\n verb=len(a)+1\r\n for i in range(len(a)):\r\n if a[i]=='a' :\r\n adj=i\r\n if a[i]=='v' :\r\n if fl==0 :\r\n fl=1\r\n verb=i\r\n if noun > adj and noun < verb :\r\n print(\"YES\")\r\n return\r\n print(\"NO\")\r\n\r\ndef main():\r\n tc=1\r\n #tc=int(input())\r\n for _ in range(tc):\r\n solve()\r\n stop = timeit.default_timer()\r\n if not ONLINE_JUDGE :\r\n print(\"Time Elapsed :\" , str(stop-start) , \"seconds\")\r\n\r\n########################################################\r\n\r\ndef lst()->list :\r\n return list(map(int,input().split()))\r\n\r\ndef rowinp() :\r\n return map(int,input().split())\r\n\r\ndef strin()->str :\r\n return input()\r\n\r\ndef chlst()->list :\r\n return [x for x in input()]\r\n\r\ndef sint()->int :\r\n return int(input())\r\n\r\n########################################################\r\n\r\nmain()\r\n\r\n########################################################", "'''\r\ndef isPetyaLanguage():\r\n read = input().split(' ')\r\n if len(read) == 1:\r\n if read[0].endswith('lios') or read[0].endswith('lialia') or read[0].endswith('etr') or read[0].endswith('etra') or read[0].endswith('initis') or read[0].endswith('inites'):\r\n print('YES')\r\n return\r\n else:\r\n print('NO')\r\n return \r\n else:\r\n if read[0].endswith('lios') or read[0].endswith('etr') or read[0].endswith('initis'):\r\n for i in range(1,len(read)):\r\n if (read[i].endswith('lios') or read[i].endswith('etr') or read[i].endswith('initis')) == False:\r\n print('NO')\r\n return\r\n elif read[0].endswith('liala') or read[0].endswith('etra') or read[0].endswith('inites'):\r\n for i in range(1,len(read)):\r\n if (read[i].endswith('liala') or read[i].endswith('etra') or read[i].endswith('inites')) == False:\r\n print('NO')\r\n return\r\n else:\r\n print('NO')\r\n return\r\n index = -1\r\n for i in range(len(read)):\r\n if read[i].endswith('etr') or read[i].endswith('etra'):\r\n index = i\r\n if index == -1:\r\n print('NO')\r\n return\r\n for i in range(0,index):\r\n if (read[i].endswith('lios') or read[i].endswith('liala')) == False:\r\n print('NO')\r\n return\r\n if index == len(read)-1:\r\n print('YES')\r\n return\r\n for i in range(index+1,len(read)):\r\n if (read[i].endswith('initis') or read[i].endswith('inites')) == False:\r\n print('NO')\r\n return\r\n print('YES')\r\n return\r\n \r\nisPetyaLanguage()\r\n'''\r\n\r\ndef getType(word):\r\n\tif word.endswith(\"lios\"): return 1\r\n\telif word.endswith(\"liala\"): return -1\r\n\telif word.endswith(\"etr\"): return 2\r\n\telif word.endswith(\"etra\"): return -2\r\n\telif word.endswith(\"initis\"):return 3\r\n\telif word.endswith(\"inites\"): return -3\r\n\telse: return 0\r\ndef gendercheck(words):\r\n for i in range(len(words)-1):\r\n \tif words[i]*words[i+1] <= 0:\r\n\t return 0\r\n return 1\r\ndef isPetyaLanguage():\r\n words = input().strip().split()\r\n words = [getType(x) for x in words]\r\n if len(words) == 1:\r\n if words[0] == 0:\r\n print('NO')\r\n return\r\n else:\r\n print('YES')\r\n return\r\n else:\r\n if gendercheck(words) == 0:\r\n print('NO')\r\n return\r\n else:\r\n words = [abs(x) for x in words]\r\n index = -1\r\n for i in range(len(words)):\r\n if words[i] == 2:\r\n index = i\r\n if index == -1:\r\n print('NO')\r\n return\r\n for i in range(index):\r\n if words[i] != 1:\r\n print('NO')\r\n return\r\n if index == len(words)-1:\r\n print('YES')\r\n return\r\n for i in range(index+1,len(words)):\r\n if words[i] != 3:\r\n print('NO')\r\n return\r\n print('YES')\r\n return\r\n return\r\n\r\nisPetyaLanguage()", "class Context:\r\n def __init__(self, words):\r\n self.words = words\r\n self.index = 0\r\n\r\n def get_token(self):\r\n return self.words[self.index]\r\n\r\n def next(self):\r\n self.index += 1\r\n\r\n def end(self):\r\n return self.index == len(self.words)\r\n\r\n def dump(self):\r\n return self.index\r\n\r\n def restore(self, dump):\r\n self.index = dump\r\n\r\n\r\nclass Parser:\r\n def parse(self, ctx) -> bool:\r\n raise NotImplementedError\r\n\r\n\r\nclass WordParser(Parser):\r\n END = None\r\n\r\n def parse(self, ctx):\r\n if ctx.end():\r\n return False\r\n token = ctx.get_token()\r\n if token.endswith(self.END):\r\n ctx.next()\r\n return True\r\n return False\r\n\r\n\r\nclass AdjectiveMale(WordParser):\r\n END = \"lios\"\r\n\r\n\r\nclass AdjectiveFemale(WordParser):\r\n END = \"liala\"\r\n\r\n\r\nclass NounMale(WordParser):\r\n END = \"etr\"\r\n\r\n\r\nclass NounFemale(WordParser):\r\n END = \"etra\"\r\n\r\n\r\nclass VerbMale(WordParser):\r\n END = \"initis\"\r\n\r\n\r\nclass VerbFemale(WordParser):\r\n END = \"inites\"\r\n\r\n\r\nclass AnyWordParser(Parser):\r\n def __init__(self, parsers):\r\n self.parsers = parsers\r\n\r\n def parse(self, ctx) -> bool:\r\n for parser in self.parsers:\r\n dump = ctx.dump()\r\n if parser.parse(ctx):\r\n return True\r\n ctx.restore(dump)\r\n return False\r\n\r\n\r\nclass SequenceParser(Parser):\r\n def __init__(self, parser):\r\n self.parser = parser\r\n\r\n def parse(self, ctx) -> bool:\r\n status = False\r\n while not ctx.end() and self.parser.parse(ctx):\r\n status = True\r\n return status\r\n\r\n\r\nclass PhraseParser(Parser):\r\n def __init__(self, parsers_sequence):\r\n self.parsers_sequence = parsers_sequence\r\n\r\n def parse(self, ctx) -> bool:\r\n dump = ctx.dump()\r\n for parser in self.parsers_sequence:\r\n if not parser.parse(ctx):\r\n ctx.restore(dump)\r\n return False\r\n return True\r\n\r\n\r\nclass OptionalParser(Parser):\r\n def __init__(self, parser):\r\n self.parser = parser\r\n\r\n def parse(self, ctx) -> bool:\r\n dump = ctx.dump()\r\n if not self.parser.parse(ctx):\r\n ctx.restore(dump)\r\n return True\r\n\r\n\r\nclass MalePhraseParser(PhraseParser):\r\n def __init__(self):\r\n adjective_parser = AdjectiveMale()\r\n adjectives_parser = SequenceParser(adjective_parser)\r\n optional_adjectives_parser = OptionalParser(adjectives_parser)\r\n noun_parser = NounMale()\r\n verb_parser = VerbMale()\r\n verbs_parser = SequenceParser(verb_parser)\r\n optional_verbs_parser = OptionalParser(verbs_parser)\r\n parsers_pipeline = (optional_adjectives_parser, noun_parser, optional_verbs_parser)\r\n super().__init__(parsers_pipeline)\r\n\r\n\r\nclass FemalePhraseParser(PhraseParser):\r\n def __init__(self):\r\n adjective_parser = AdjectiveFemale()\r\n adjectives_parser = SequenceParser(adjective_parser)\r\n optional_adjectives_parser = OptionalParser(adjectives_parser)\r\n noun_parser = NounFemale()\r\n verb_parser = VerbFemale()\r\n verbs_parser = SequenceParser(verb_parser)\r\n optional_verbs_parser = OptionalParser(verbs_parser)\r\n parsers_pipeline = (optional_adjectives_parser, noun_parser, optional_verbs_parser)\r\n super().__init__(parsers_pipeline)\r\n\r\n\r\nclass SentenceParser(Parser):\r\n def __init__(self):\r\n self.male_phrase_parser = MalePhraseParser()\r\n self.female_phrase_parser = FemalePhraseParser()\r\n self.any_word_parser = AnyWordParser((\r\n AdjectiveMale(), AdjectiveFemale(),\r\n NounMale(), NounFemale(),\r\n VerbMale(), VerbFemale()\r\n ))\r\n\r\n def parse(self, ctx) -> bool:\r\n dump = ctx.dump()\r\n if not self.male_phrase_parser.parse(ctx):\r\n ctx.restore(dump)\r\n else:\r\n return True\r\n if not self.female_phrase_parser.parse(ctx):\r\n ctx.restore(dump)\r\n else:\r\n return True\r\n if not self.any_word_parser.parse(ctx):\r\n ctx.restore(dump)\r\n return False\r\n return True\r\n\r\n\r\ndef main():\r\n data = input().split()\r\n ctx = Context(data)\r\n parser = SentenceParser()\r\n status = parser.parse(ctx)\r\n if status and ctx.end():\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n\r\n\r\nmain()\r\n", "# LUOGU_RID: 128399015\na = input().split()\r\nc = 5 #设置一个变量,记录当前的状态\r\nfor b in a:\r\n if c == 5:\r\n if len(a) == 1: \r\n if b[-4:] == 'lios' or b[-5:] == 'liala' or b[-3:] == 'etr' or b[-4:] == 'etra' or b[-6:] == 'initis' or b[-6:] == 'inites': #输入只有一个任意合法单词时也特判为合法\r\n c = 0\r\n elif b[-4:] == 'lios':\r\n c = 1\r\n elif b[-5:] == 'liala':\r\n c = 2\r\n elif b[-3:] == 'etr':\r\n c = 3\r\n elif b[-4:] == 'etra':\r\n c = 4\r\n else:\r\n break\r\n elif c == 1:\r\n if b[-4:] == 'lios':\r\n continue\r\n elif b[-3:] == 'etr':\r\n c = 3\r\n else:\r\n c = 5\r\n break\r\n elif c == 2:\r\n if b[-5:] == 'liala':\r\n continue\r\n elif b[-4:] == 'etra':\r\n c = 4\r\n else:\r\n c = 5\r\n break\r\n elif c == 3:\r\n if b[-6:] == 'initis':\r\n c = 6\r\n else:\r\n c = 5\r\n break\r\n elif c == 4:\r\n if b[-6:] == 'inites':\r\n c = 7\r\n else:\r\n c = 5\r\n break\r\n elif c == 6:\r\n if b[-6:] == 'initis':\r\n continue\r\n else:\r\n c = 5\r\n break\r\n else:\r\n if b[-6:] == 'inites':\r\n continue\r\n else:\r\n c = 5\r\n break\r\nif c in (1,2,5): \r\n print('NO')\r\nelse:\r\n print('YES')", "#!/usr/bin/python3\nimport re\nal = re.compile(r'^1*23*$')\ndef getType(word):\n\tif word.endswith(\"lios\"): return 1\n\telif word.endswith(\"liala\"): return -1\n\telif word.endswith(\"etr\"): return 2\n\telif word.endswith(\"etra\"): return -2\n\telif word.endswith(\"initis\"):return 3\n\telif word.endswith(\"inites\"): return -3\n\telse: return 0\n\n\nwords = input().strip().split()\nwords = [getType(x) for x in words]\nif len(words) == 1:\n\tif words[0] != 0:print(\"YES\")\n\telse:print(\"NO\")\nelse:\n\tp = words[0]\n\tfor x in words:\n\t\tif p*x <= 0:\n\t\t\tprint(\"NO\")\n\t\t\texit()\n\twords = [str(abs(x)) for x in words]\n\twords = \"\".join(words)\n\t#print(words)\n\tif al.match(words):print(\"YES\")\n\telse:print(\"NO\")\n\t\n", "a=list(map(str,input().split()))\r\nt=[0]*len(a)\r\nstr=[\"lios\",\"liala\",\"etr\",\"etra\",\"initis\",\"inites\"]\r\n\r\nif len(a)==1:\r\n for i in range(6):\r\n if a[0].endswith(str[i]):\r\n print(\"YES\")\r\n exit(0)\r\n\r\n print(\"NO\")\r\n exit(0)\r\n\r\nfor i in range(len(a)):\r\n for j in range(6):\r\n if a[i].endswith(str[j]):\r\n t[i]=j+1\r\n break\r\n\r\n #not belonging in any language\r\n if t[i]==0:\r\n print(\"NO\")\r\n exit(0)\r\n\r\n#all the t[]'s should be either or odd\r\nrem=t[0]%2\r\nfor i in range(len(t)):\r\n if t[i]%2!=rem:\r\n print(\"NO\")\r\n exit(0)\r\n\r\nx=sorted(t)\r\ncnt=0\r\n\r\nfor i in range(len(t)):\r\n if t[i]==3 or t[i]==4:\r\n cnt+=1\r\n\r\n if t[i]!=x[i]:\r\n print(\"NO\")\r\n exit(0)\r\n\r\nif cnt==1:\r\n print(\"YES\")\r\n\r\nelse:\r\n print(\"NO\")", "s=input().split()\n\nif(len(s)==1):\n if(s[0].endswith(\"lios\") or s[0].endswith(\"etr\") or s[0].endswith(\"liala\") or s[0].endswith(\"etra\") or s[0].endswith(\"inites\") or s[0].endswith(\"initis\")):\n print(\"YES\")\n else:\n print(\"NO\")\n\n\n\nelif(s[0].endswith(\"lios\") or s[0].endswith(\"etr\")):\n n=len(s)\n i=0\n while(i<n and s[i].endswith(\"lios\")):\n i+=1\n if(i==n):\n print(\"NO\")\n elif(s[i].endswith(\"etr\")):\n i+=1\n while(i<n and s[i].endswith(\"initis\")):\n i+=1\n if(i==n):\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\n \nelif(s[0].endswith(\"liala\") or s[0].endswith(\"etra\")):\n n=len(s)\n i=0\n while(i<n and s[i].endswith(\"liala\")):\n i+=1\n if(i==n):\n print(\"NO\")\n elif(s[i].endswith(\"etra\")):\n i+=1\n while(i<n and s[i].endswith(\"inites\")):\n i+=1\n if(i==n):\n print(\"YES\")\n else:\n print(\"NO\")\n else:\n print(\"NO\")\nelse:\n print(\"NO\")\n \n", "import sys\r\nfrom functools import lru_cache, cmp_to_key\r\nfrom heapq import merge, heapify, heappop, heappush\r\nfrom math import *\r\nfrom collections import defaultdict as dd, deque, Counter as C\r\nfrom itertools import combinations as comb, permutations as perm\r\nfrom bisect import bisect_left as bl, bisect_right as br, bisect, insort\r\nfrom time import perf_counter\r\nfrom fractions import Fraction\r\nimport copy\r\nfrom copy import deepcopy\r\nimport time\r\nstarttime = time.time()\r\nmod = int(pow(10, 9) + 7)\r\nmod2 = 998244353\r\n\r\ndef data(): return sys.stdin.readline().strip()\r\ndef out(*var, end=\"\\n\"): sys.stdout.write(' '.join(map(str, var))+end)\r\ndef L(): return list(sp())\r\ndef sl(): return list(ssp())\r\ndef sp(): return map(int, data().split())\r\ndef ssp(): return map(str, data().split())\r\ndef l1d(n, val=0): return [val for i in range(n)]\r\ndef l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]\r\ntry:\r\n # sys.setrecursionlimit(int(pow(10,6)))\r\n sys.stdin = open(\"input.txt\", \"r\")\r\n sys.stdout = open(\"../output.txt\", \"w\")\r\nexcept:\r\n pass\r\ndef pmat(A):\r\n for ele in A: print(*ele,end=\"\\n\")\r\n\r\n# from sys import stdin\r\n# input = stdin.buffer.readline\r\n# I = lambda : list(map(int,input().split()))\r\n\r\n# import sys\r\n# input=sys.stdin.readline\r\n\r\n\r\n\r\n\r\n\r\ndef f(a):\r\n b=len(a)\r\n if b>=4 and a[-4:]=='lios':\r\n return [1,1]\r\n if b>=5 and a[-5:]=='liala':\r\n return [1,2]\r\n if b>=3 and a[-3:]=='etr':\r\n return [2,1]\r\n if b>=4 and a[-4:]=='etra':\r\n return [2,2]\r\n if b>=6 and a[-6:]=='initis':\r\n return [3,1]\r\n if b>=6 and a[-6:]=='inites':\r\n return [3,2]\r\n return -1\r\na=[f(i) for i in input().split()]\r\nn=len(a)\r\nif -1 in a or [i[1] for i in a]!=[a[0][1]]*n:\r\n print('NO')\r\nelse:\r\n i,j=0,n-1\r\n while i<n and a[i][0]==1:\r\n i+=1\r\n while j>=0 and a[j][0]==3:\r\n j-=1\r\n print('YES' if i==j or n==1 else 'NO')\r\n", "def isPetyaLanguage():\r\n words = input().split()\r\n if len(words) == 1:\r\n if words[0].endswith(\"etr\") or words[0].endswith(\"etra\") or words[0].endswith(\"lios\") or words[0].endswith(\"liala\") or words[0].endswith(\"initis\") or words[0].endswith(\"inites\"):\r\n print(\"YES\")\r\n return\r\n else:\r\n print(\"NO\")\r\n return\r\n for i in range(len(words)):\r\n if words[i].endswith(\"etr\"):\r\n noun = i\r\n gender = \"masculine\"\r\n break\r\n elif words[i].endswith(\"etra\"):\r\n noun = i\r\n gender = \"feminine\"\r\n break\r\n else:\r\n print(\"NO\")\r\n return\r\n if gender == \"masculine\":\r\n if noun > 0:\r\n for i in range(noun):\r\n if not words[i].endswith(\"lios\"):\r\n print(\"NO\")\r\n return\r\n if noun < len(words) - 1:\r\n for i in range(noun + 1, len(words)):\r\n if not words[i].endswith(\"initis\"):\r\n print(\"NO\")\r\n return\r\n elif gender == \"feminine\":\r\n if noun > 0:\r\n for i in range(noun):\r\n if not words[i].endswith(\"liala\"):\r\n print(\"NO\")\r\n return\r\n if noun < len(words) - 1:\r\n for i in range(noun + 1, len(words)):\r\n if not words[i].endswith(\"inites\"):\r\n print(\"NO\")\r\n return\r\n print(\"YES\")\r\n return\r\n\r\nisPetyaLanguage()", "lista = input().split()\r\n\r\npassadj = False\r\npasssub = False\r\ngender = -1\r\ncan = True\r\ncanF = True\r\n# verificando os generos das palavras\r\n\r\nfor i in range(0,len(lista)):\r\n\tif (len(lista[i]) >= 3 and lista[i][len(lista[i])-3::] == \"etr\") or (len(lista[i]) >= 4 and lista[i][len(lista[i])-4::] == \"lios\") or (len(lista[i]) >= 6 and lista[i][len(lista[i])-6::] == \"initis\"):\r\n\t\tif gender == -1:\r\n\t\t\tgender = 1\r\n\t\telif gender == 2:\r\n\t\t\tcan = False\r\n\telse:\r\n\t\tif gender == -1:\r\n\t\t\tgender = 2\r\n\t\telif gender == 1:\r\n\t\t\tcan = False \r\n# print(can)\r\n# verificando os blocos\r\nfor i in range(0, len(lista)):\r\n\tif (len(lista[i]) >= 4 and lista[i][len(lista[i])-4::] == \"lios\") or (len(lista[i]) >= 5 and lista[i][len(lista[i])-5::] == \"liala\"):\r\n\t\tif(passadj == True):\r\n\t\t\tcan = False \r\n\telif (len(lista[i]) >= 3 and lista[i][len(lista[i])-3::] == \"etr\") or (len(lista[i]) >= 4 and lista[i][len(lista[i])-4::] == \"etra\"):\r\n\t\tpassadj = True\r\n\t\tif passsub == True: \r\n\t\t\tcan = False\r\n\t\telse:\r\n\t\t\tpasssub = True\r\n\telif (len(lista[i]) >= 6 and lista[i][len(lista[i])-6::] == \"initis\") or (len(lista[i]) >= 6 and lista[i][len(lista[i])-6::] == \"inites\"):\r\n\t\tif passadj == False or passsub == False:\r\n\t\t\tcan = False\r\n\telse:\r\n\t\tcanF = False\r\n\t# print(can)\r\nif (len(lista)==1 and canF) or (passsub and canF and can):\r\n\tprint(\"YES\\n\")\r\nelse:\r\n\tprint(\"NO\\n\")", "def method(a, key):\n key_len = [len(i) for i in key]\n data = []\n for i in a:\n temp = None\n x, y, z = i[-key_len[0]::], i[-key_len[1]::], i[-key_len[2]::]\n if x in key:\n temp = key.index(x)\n elif y in key:\n temp = key.index(y)\n elif z in key:\n temp = key.index(z)\n if temp == None:\n return []\n else:\n data.append(temp)\n return data\n\n\ndef language(a):\n m = ['lios', 'etr', 'initis']\n f = ['liala', 'etra', 'inites']\n a = a.split()\n data_m = method(a, m)\n data_f = method(a, f)\n data = data_m if len(data_m) > len(data_f) else data_f\n try:\n assert len(a) == len(data)\n if len(data) == 1:\n pass\n else:\n assert data.count(1) == 1\n for i in range(len(data)-1):\n assert data[i] <= data[i+1]\n return \"YES\"\n except:\n return \"NO\"\n\n\na = input()\nprint(language(a))\n\n \t\t \t \t \t\t\t\t\t \t\t \t \t\t\t", "import re\r\ndef f(x):\r\n if x.endswith(\"lios\"): return 1\r\n elif x.endswith(\"liala\"): return -1\r\n elif x.endswith(\"etr\"): return 2\r\n elif x.endswith(\"etra\"): return -2\r\n elif x.endswith(\"initis\"):return 3\r\n elif x.endswith(\"inites\"): return -3\r\n else: return 0\r\n \r\na,b=input().strip().split(),[]\r\nfor s in a:b.append(f(s))\r\n\r\nif len(b)==1:\r\n if b[0]!=0:print(\"YES\")\r\n else:print(\"NO\")\r\nelse:\r\n for x in b:\r\n if b[0]*x <= 0:\r\n print(\"NO\")\r\n exit()\r\n c=\"\"\r\n for x in b:c+=str(abs(x))\r\n sbl=re.compile(r'^1*23*$')\r\n if sbl.match(c):\r\n print(\"YES\")\r\n else:\r\n print(\"NO\")\r\n", "s, n, m, f = input().split(), False, False, False\r\ndef cc(w, me, fe):\r\n global m, f\r\n if w.endswith(me):\r\n m = True\r\n return True\r\n elif w.endswith(fe):\r\n f = True\r\n return True\r\n else:\r\n return False\r\ndef ad(w): return cc(w, 'lios', 'liala')\r\ndef nn(w): return cc(w, 'etr', 'etra')\r\ndef vb(w): return cc(w, 'initis', 'inites')\r\nfor w in s:\r\n if not n:\r\n if ad(w) or vb(w) and len(s) == 1:\r\n pass\r\n elif nn(w):\r\n n = True\r\n else:\r\n print('NO')\r\n exit()\r\n elif not vb(w):\r\n print('NO')\r\n exit()\r\nprint('YES' if len(s) == 1 or (n and (m ^ f)) else 'NO')", "from sys import stdin, stdout\r\n \r\nx = stdin.readline().replace(\"\\n\",\"\")\r\n \r\nlst = x.split(' ')\r\ngenderLst = []\r\ntypeLst = []\r\n \r\nvalid = 1\r\n \r\nfor x in lst:\r\n if x.endswith(\"lios\") or x.endswith(\"etr\") or x.endswith(\"initis\"):\r\n genderLst.append(1)\r\n elif x.endswith(\"liala\") or x.endswith(\"etra\") or x.endswith(\"inites\"):\r\n genderLst.append(0)\r\n else:\r\n valid = 0\r\n \r\nif valid == 0:\r\n print(\"NO\")\r\n exit()\r\n \r\nfor x in lst:\r\n if(x.endswith(\"lios\") or x.endswith(\"liala\")):\r\n typeLst.append(1)\r\n if(x.endswith(\"etr\") or x.endswith(\"etra\")):\r\n typeLst.append(2)\r\n if(x.endswith(\"initis\") or x.endswith(\"inites\")):\r\n typeLst.append(3)\r\n \r\nif genderLst[0] == 1 and 0 in genderLst:\r\n valid = 0\r\nif genderLst[0] == 0 and 1 in genderLst:\r\n valid = 0 \r\nif(len(typeLst) != 1):\r\n if typeLst.count(2) != 1:\r\n valid = 0\r\n \r\ni = 0\r\nwhile i < len(typeLst) and typeLst[i] == 1:\r\n i += 1\r\nwhile i < len(typeLst) and typeLst[i] == 2:\r\n i += 1\r\nwhile i < len(typeLst) and typeLst[i] == 3:\r\n i += 1\r\n \r\nif i != len(typeLst):\r\n valid = 0\r\n \r\nif(valid):\r\n print (\"YES\")\r\nelse: \r\n print(\"NO\")\r\n", "n = input().split()\r\nw = 0\r\nx=y=z=0\r\nr=s=t=0\r\nwhile w<len(n):\r\n if n[w][-4:]==\"lios\" or n[w][-5:]==\"liala\":\r\n if n[w][-4:]==\"lios\":\r\n x+=1\r\n w+=1\r\n else:\r\n r+=1\r\n w+=1\r\n else:\r\n break\r\nwhile w<len(n):\r\n if n[w][-3:]==\"etr\" or n[w][-4:]==\"etra\":\r\n if n[w][-3:]==\"etr\":\r\n y+=1\r\n w+=1\r\n else:\r\n s+=1\r\n w+=1\r\n else:\r\n break\r\nwhile w<len(n):\r\n if n[w][-6:]==\"initis\" or n[w][-6:]==\"inites\":\r\n if n[w][-6:]==\"initis\":\r\n z+=1\r\n w+=1\r\n else:\r\n t+=1\r\n w+=1\r\n else:\r\n break\r\n\r\nif len(n)==1 and (x==1 or y==1 or z==1 ):\r\n print(\"YES\")\r\nelif len(n)==1 and (r==1 or s==1 or t==1):\r\n print(\"YES\")\r\nelif y==1 and x+y+z==len(n) and s==0:\r\n print(\"YES\")\r\nelif y==0 and r+s+t==len(n) and s==1:\r\n print(\"YES\")\r\nelse:\r\n print(\"NO\")", "words = [c for c in input().split()]\r\nverdict = True\r\ncategory = [\"\" for i in range(len(words))]\r\ngender = [\"\" for i in range(len(words))]\r\nfor i in range(len(words)):\r\n\tif (not verdict): break\r\n\tif (len(words[i]) < 3): verdict = False\r\n\telif (words[i][-3:] == \"etr\"): \r\n\t\tcategory[i] = \"noun\"\r\n\t\tgender[i] = \"male\"\r\n\telif (len(words[i]) >= 4 and words[i][-4:] == \"etra\"): \r\n\t\tcategory[i] = \"noun\"\r\n\t\tgender[i] = \"female\"\r\n\telif ((len(words[i]) >= 4 and words[i][-4:] == \"lios\")):\r\n\t\tcategory[i] = \"adjective\"\r\n\t\tgender[i] = \"male\"\r\n\telif (len(words[i]) >= 5 and words[i][-5:] == \"liala\"): \r\n\t\tcategory[i] = \"adjective\"\r\n\t\tgender[i] = \"female\"\r\n\telif (len(words[i]) >= 6):\r\n\t\tcategory[i] = \"verb\"\r\n\t\tif (words[i][-6:] == \"initis\"): gender[i] = \"male\"\r\n\t\telif (words[i][-6:] == \"inites\"): gender[i] = \"female\"\r\n\t\telse: verdict = False\r\n\telse: verdict = False\r\n\r\nfirst_noun = -1\r\nfor i in range(len(category)):\r\n\tif (not verdict): break\r\n\tif (category[i] == \"noun\"): \r\n\t\tfirst_noun = i\r\n\t\tbreak\r\n\r\nif (first_noun == -1 and len(words) > 1): verdict = False\r\nelif (first_noun != -1 and verdict):\r\n\tleft, right = first_noun - 1, first_noun + 1\r\n\twhile (left >= 0 and category[left] == \"adjective\" and gender[left] == gender[first_noun]): left -= 1\r\n\twhile (right < len(category) and category[right] == \"verb\" and gender[right] == gender[first_noun]): right += 1\r\n\t\r\n\tif (left >= 0 or right < len(category)): verdict = False\r\n\r\nprint((\"NO\" if (not verdict) else \"YES\"))\r\n", "import re;t=input();p=[r'([^ ]*lios )*([^ ]*etr)( [^ ]*initis)*',r'([^ ]*liala )*([^ ]*etra)( [^ ]*inites)*',r'[^ ]*(li(os|ala)|etra?|init[ie]s)'];print(['NO','YES'][any(re.fullmatch(q,t)for q in p)])" ]
{"inputs": ["petr", "etis atis animatis etis atis amatis", "nataliala kataliala vetra feinites", "qweasbvflios", "lios lios petr initis qwe", "lios initis", "petr initis lios", "petra petra petra", "in", "liala petra initis", "liala petra inites", "liala initis", "liala petra petr inites", "liala petr inites", "llilitos", "umeszdawsvgkjhlqwzentsphxqhdungbylhnikwviuhccbstghhxlmvcjznnkjqkugsdysjbedwpmsmxmgxlrlxctnebtbwrsvgjktkrosffwymovxvsgfmmqwfflpvbumozikroxrdgwjrnstngstxbiyyuxehrhviteptedlmyetr", "i i i i i i i i i i i i i i i a a a a a a v v v v v v v v v v v", "fbvzqonvdlqdanwliolaqfj sbauorbinites xkbfnfinitespjy phbexglblzpobtqpisyijycmtliola aosinites lbpjiwcjoqyuhglthloiniteswb mjtxhoofohzzgefvhsywojcuxtetxmojrlktodhbgyrkeejgjzxkzyvrxwmyaqkeoqnvusnlrsfffrzeoqjdfumolhksqkrtzwhnforgpenziokrxlnhcapbbupctlmuetrani pigxerwetupjbkvlmgnjhdfjliolanz tqhaidxbqmdaeincxjuliola", "mfrmqetr", "hnwvfllholxfialiola cknjtxpliola daliola gqfapnhmmworliola qhetra qrisbexsrefcwzoxqwxrevinites wwldqkqhvrgwplqinites nqdpoauitczttxoinites fgbmdfpxkhahkinites", "kcymcpgqdxkudadewddualeemhixhsdazudnjdmuvxvrlrbrpsdpxpagmrogplltnifrtomdtahxwadguvetxaqkvsvnoyhowirnluhmyewzapirnpfdisvhtbenxmfezahqoflkjrfqjubwdfktnpeirodwubftzlcczzavfiooihzvnqincndisudihvbcaxptrwovekmhiiwsgzgbxydvuldlnktxtltrlajjzietkxbnhetra", "dosiydnwxemojaavfdvlwsyhzqywqjutovygtlcleklhybczhjqfzxwdmlwqwcqqyfjkzhsizlmdarrfronxqkcknwpkvhdlgatdyjisjoopvngpjggldxjfxaauoxmqirkuphydyweoixftstlozaoywnxgriscudwlokncbmaebpssccmmmfjennyjaryqlzjknnklqketra", "etretra linites", "petretra petr", "lialalios petraveryfunnypetr", "petropetrapetr petra", "lios petrnonono", "lios petr initisandinitisandliala petrainitis", "petro", "petr initesinitis", "lios initis", "liala initespetra", "lios petrapetr", "initis petr", "lioslialapetrpetrainitisinitesliosliala initesinitislioslialapetrpetrainitisinitetra", "veryfunnyprefixpetr", "veryfunnyprefixpetra", "veryfunnyprefixinitis", "veryfunnyprefixinites", "veryfunnyprefixliala", "veryfunnyprefixlios", "veryfunnyprefixlialas", "veryfunnyprefixliala veryfunnyprefixpetretra", "veryfunnyprefixlios veryfunnyprefixinitisetr", "veryfunnyprefixlios aabbinitis", "veryfunnyprefixlios inites", "lios petr initis", "liala etra inites", "lios", "liala", "initis", "inites", "tes", "tr", "a", "lios lios", "lios", "liala", "petr", "petra", "pinitis", "pinites", "plios pliala", "plios petr", "plios petra", "plios plios", "plios initis", "plios pinites", "pliala plios", "pliala ppliala", "pliala petr", "pliala petra", "pliala pinitis", "pliala pinites", "petr plios", "petr pliala", "petr petr", "petr petra", "petr pinitis", "petr pinites", "petra lios", "petra liala", "petra petr", "petra petra", "petra initis", "petra inites", "initis lios", "initis liala", "initis petr", "initis petra", "initis initis", "initis inites", "inites lios", "inites liala", "inites petr", "inites petra", "inites initis", "inites inites", "lios lios lios", "lios lios liala", "lios lios etr", "lios lios etra", "lios lios initis", "lios lios inites", "lios liala lios", "lios liala liala", "lios liala etr", "lios liala etra", "lios liala initis", "lios liala inites", "lios etr lios", "lios etr liala", "lios etr etr", "lios etr etra", "lios etr initis", "lios etr inites", "lios etra lios", "lios etra liala", "lios etra etr", "lios etra etra", "lios etra initis", "lios etra inites", "lios initis lios", "lios initis liala", "lios initis etr", "lios initis etra", "lios initis initis", "lios initis inites", "lios inites lios", "lios inites liala", "lios inites etr", "lios inites etra", "lios inites initis", "lios inites inites", "liala lios lios", "liala lios liala", "liala lios etr", "liala lios etra", "liala lios initis", "liala lios inites", "liala liala lios", "liala liala liala", "liala liala etr", "liala liala etra", "liala liala initis", "liala liala inites", "liala etr lios", "liala etr liala", "liala etr etr", "liala etr etra", "liala etr initis", "liala etr inites", "liala etra lios", "liala etra liala", "liala etra etr", "liala etra etra", "liala etra initis", "liala etra inites", "liala initis lios", "liala initis liala", "liala initis etr", "liala initis etra", "liala initis initis", "liala initis inites", "liala inites lios", "liala inites liala", "liala inites etr", "liala inites etra", "liala inites initis", "liala inites inites", "etr lios lios", "etr lios liala", "etr lios etr", "etr lios etra", "etr lios initis", "etr lios inites", "etr liala lios", "etr liala liala", "etr liala etr", "etr liala etra", "etr liala initis", "etr liala inites", "etr etr lios", "etr etr liala", "etr etr etr", "etr etr etra", "etr etr initis", "etr etr inites", "etr etra lios", "etr etra liala", "etr etra etr", "etr etra etra", "etr etra initis", "etr etra inites", "etr initis lios", "etr initis liala", "etr initis etr", "etr initis etra", "etr initis initis", "etr initis inites", "etr inites lios", "etr inites liala", "etr inites etr", "etr inites etra", "etr inites initis", "etr inites inites", "etra lios lios", "etra lios liala", "etra lios etr", "etra lios etra", "etra lios initis", "etra lios inites", "etra liala lios", "etra liala liala", "etra liala etr", "etra liala etra", "etra liala initis", "etra liala inites", "etra etr lios", "etra etr liala", "etra etr etr", "etra etr etra", "etra etr initis", "etra etr inites", "etra etra lios", "etra etra liala", "etra etra etr", "etra etra etra", "etra etra initis", "etra etra inites", "etra initis lios", "etra initis liala", "etra initis etr", "etra initis etra", "etra initis initis", "etra initis inites", "etra inites lios", "etra inites liala", "etra inites etr", "etra inites etra", "etra inites initis", "etra inites inites", "initis lios lios", "initis lios liala", "initis lios etr", "initis lios etra", "initis lios initis", "initis lios inites", "initis liala lios", "initis liala liala", "initis liala etr", "initis liala etra", "initis liala initis", "initis liala inites", "initis etr lios", "initis etr liala", "initis etr etr", "initis etr etra", "initis etr initis", "initis etr inites", "initis etra lios", "initis etra liala", "initis etra etr", "initis etra etra", "initis etra initis", "initis etra inites", "initis initis lios", "initis initis liala", "initis initis etr", "initis initis etra", "initis initis initis", "initis initis inites", "initis inites lios", "initis inites liala", "initis inites etr", "initis inites etra", "initis inites initis", "initis inites inites", "inites lios lios", "inites lios liala", "inites lios etr", "inites lios etra", "inites lios initis", "inites lios inites", "inites liala lios", "inites liala liala", "inites liala etr", "inites liala etra", "inites liala initis", "inites liala inites", "inites etr lios", "inites etr liala", "inites etr etr", "inites etr etra", "inites etr initis", "inites etr inites", "inites etra lios", "inites etra liala", "inites etra etr", "inites etra etra", "inites etra initis", "inites etra inites", "inites initis lios", "inites initis liala", "inites initis etr", "inites initis etra", "inites initis initis", "inites initis inites", "inites inites lios", "inites inites liala", "inites inites etr", "inites inites etra", "inites inites initis", "inites inites inites"], "outputs": ["YES", "NO", "YES", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "YES", "NO", "YES", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "YES", "NO", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
17
208e0d102a4aff006ad18836092a1fd9
Jeff and Digits
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got? Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards. The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. Sample Input 4 5 0 5 0 11 5 5 5 5 5 5 5 5 0 5 5 Sample Output 0 5555555550
[ "n=int(input())\r\na=list(map(int,input().split()))\r\ns=sum(a)\r\n_5=a.count(5)\r\n_0=a.count(0)\r\nif _0!=0:\r\n ans='5'*(_5)+'0'*(_0)\r\n while s/9!=s//9:\r\n s-=5\r\n _5-=1\r\n ans='5'*(_5)+'0'*(_0)\r\n print(int(ans))\r\nelse:\r\n print(-1)", "x = int(input())\r\nls = sorted(list(map(int, input().split())))\r\nif ls.count(0) == 0:\r\n print(-1)\r\nelse :\r\n ct = ls.count(5)\r\n if ct < 9:\r\n print(0)\r\n else:\r\n print('5' * (ct - (ct % 9)), '0' * (ls.count(0)), sep = '')", "n=int(input())\r\na=list(map(int, input().split()))\r\nnol = a.count(0)\r\nbesh = a.count(5)\r\nif nol==0:print(-1)\r\nelse:\r\n if besh<9:print(0)\r\n else:print('5'*9*(besh//9)+'0'*nol)", "n = int(input())\r\narr = input().split()\r\n\r\nfive = arr.count('5')\r\nzero = arr.count('0')\r\n\r\nfive = five//9\r\n\r\nif zero==0:\r\n print(-1)\r\n \r\nelif five==0:\r\n print(0)\r\n \r\nelse:\r\n print('5'*(five*9)+'0'*zero)", "n=int(input())\r\nl=input()\r\na=l.count(\"0\")\r\nif a<1:print(\"-1\")\r\nelse:print(int(\"5\"*((9)*(l.count(\"5\")//9))+\"0\"*a))", "n=int(input())\r\n\r\nA=list(map(int,input().split()))\r\n\r\nimport math\r\nfives=0\r\nzeros=0\r\n\r\nfor item in A:\r\n if item==5:\r\n fives+=1\r\n else:\r\n zeros+=1\r\n\r\nfives=math.floor(fives/9)\r\nfives=fives*9\r\n\r\nif zeros==0:\r\n print(-1)\r\nelif fives==0:\r\n print(0)\r\nelse:\r\n for i in range(fives):\r\n print(5,end=\"\")\r\n for i in range(zeros):\r\n print(0,end=\"\") \r\n\r\n ", "n=int(input())\r\nlis=list(map(int,input().strip().split()))\r\nlis.sort()\r\nif lis[0]==5:\r\n print(-1)\r\nelse:\r\n lis.reverse()\r\n lis = [str(i) for i in lis]\r\n num = \"\".join(lis)\r\n num=int(num)\r\n while True:\r\n if num%90==0:\r\n print(num)\r\n break\r\n else:\r\n num=str(num)\r\n num=num[1:]\r\n num=int(num)\r\n", "# import sys\r\n# sys.stdin=open('Python\\input.txt','r')\r\n# sys.stdout=open('Python\\output.txt','w')\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\nf,z=0,0\r\nfor i in l:\r\n if i==5:f+=1\r\n else:z+=1\r\nif z==0:print(-1)\r\nelse:\r\n t='5'*(f//9)*9\r\n if t=='':\r\n print(0)\r\n else:\r\n print(int(t+'0'*z))", "n = int(input())\r\narr = list(map(int, input().split()))\r\nfive = arr.count(5)\r\nzero = arr.count(0)\r\nif zero == 0: print(-1)\r\nelif five < 9: print(0)\r\nelse:\r\n n_five = (five//9)*9\r\n print('5'*n_five + '0'*zero)", "n = int(input())\r\nnumbers = input().split(' ')\r\nnumbers.sort(reverse=True)\r\ns = ''\r\nd = dict()\r\nd['0'] = 0\r\nd['5'] = 0\r\nans = ''\r\n#to get the number in one insaperated line : \r\nfor i in numbers:\r\n if n <=len(numbers):\r\n s += i \r\nfor i in numbers :\r\n d[i]+=1 \r\nextra = d['5']%9\r\nif d['5']>=9:\r\n d['5'] -= extra\r\n for i in range(d['5']):\r\n ans += '5'\r\n for i in range(d['0']):\r\n ans += '0'\r\nelse:\r\n ans ='0'\r\nif not d['0']:\r\n ans = '-1' \r\nprint(ans)", "a=input()\r\na=int(a)\r\nt=input()\r\nt=t.split(' ')\r\nt5=0\r\nt0=0\r\nfor i in t:\r\n if i=='5':\r\n t5=t5+1\r\n if i=='0':\r\n t0=t0+1\r\nif t5<9:\r\n if t0>0:\r\n print(0)\r\n if t0==0:\r\n print(-1)\r\nif t5>=9:\r\n smu=t5/9\r\n smu=int(smu)\r\n if t0>0:\r\n for i in range(smu*9):\r\n print(5,end='')\r\n for i in range(t0):\r\n print(0,end='')\r\n else:\r\n print(-1)", "b=int(input())\r\nl=list(map(int,input().split()))\r\nc0=0\r\nc5=0\r\nfor x in l:\r\n if x==0:\r\n c0+=1\r\n elif x==5:\r\n c5+=1\r\nif c0==0:\r\n print(-1)\r\nelif c5<9:\r\n print(0)\r\nelse:\r\n no=(c5//9)*9\r\n for x in range(no):\r\n print('5',end='')\r\n for x in range(c0):\r\n print('0',end='')\r\n", "n = int(input())\r\ndigits = list(map(int,input().split(\" \")))\r\nnoOfFives = digits.count(5)\r\nnoOfZeros = n-noOfFives\r\nif noOfZeros == 0:\r\n print(-1)\r\nelse:\r\n if noOfFives < 9:\r\n print(0)\r\n else:\r\n res = \"5\"*(noOfFives-noOfFives%9)+\"0\"*noOfZeros\r\n print(res)", "def main():\n n = int(input())\n arr = list(map(int, input().split(\" \")))\n\n # count f and z\n fives = 0\n zeros = 0\n for x in arr:\n if x > 0:\n fives += 1\n else:\n zeros += 1\n\n if fives == 0 and zeros > 0:\n print(0)\n return\n\n\n if zeros == 0:\n print(-1)\n return\n\n if fives < 9:\n print(0)\n return\n\n fives = fives - fives % 9\n print(int(''.join(['5',] * fives) + ''.join(['0',] * zeros)))\n\n\nif __name__ == \"__main__\":\n main()\n", "n = int(input())\r\ncards = list(map(int, input().split()))\r\nif(cards.count(0)==0):\r\n print(-1)\r\nelse:\r\n n5 = 9*(cards.count(5)//9)\r\n if(n5==0):\r\n print(0)\r\n else:\r\n print(\"5\"*n5+\"0\"*cards.count(0))", "a,b=int(input()),input();c=b.count('5');d=a-c;print(int('5'*(9*(c//9))+'0'*d) if d else '-1')", "len = int(input())\r\nli = list(map(int, input().split()))\r\nli.sort()\r\nli.reverse()\r\nst = \"\"\r\nfor i in range(len):\r\n st = st + str(li[i])\r\ncou5 = st.count(\"5\")\r\ncou0 = st.count(\"0\")\r\n\r\nif cou0>0 and cou5%9==0 and cou5>=9:\r\n print(st)\r\nelif cou0>0 and cou5%9!=0 and cou5>9:\r\n \r\n t = 0\r\n \r\n while t<1:\r\n \r\n st = st[1:]\r\n cout = st.count(\"5\")\r\n if cout%9==0:\r\n print(st)\r\n break\r\nelif cou0>0 and cou5<9:\r\n print(0)\r\nelse:\r\n print(-1)\r\n", "x,a=int(input()),input()\nc=a.count('5')\nd=x-c\nprint(int('5'*(9*(c//9))+'0'*d) if d else '-1')\n\t\t\t\t \t \t\t \t\t\t\t\t\t \t \t\t \t \t", "n= int(input()) #input\r\nl= list(map(int,input().split())) #input\r\nl.sort(reverse=True) #reverse sorted array to find max no\r\nx=l.count(5) # count of 5\r\ny=l.count(0) #count of 0\r\nif(x%9==0 and y>=1 and x>0):\r\n print(x*'5'+y*'0')\r\nelif(x%9!=0 and y>=1 and x>9):\r\n print((x//9)*9*'5'+y*'0')\r\nelif(x%9!=0 and y>=1 and x<9): \r\n print(0)\r\nelif( x>0 and y==0):\r\n print(-1)\r\nelif(x==0 and y>0):\r\n print(0) \r\n\r\n", "from collections import Counter\r\n\r\ndef solve(n,arr):\r\n c = Counter(arr)\r\n if c[5]<9: \r\n if 0 in c: return 0\r\n return -1\r\n if 0 not in c: return -1\r\n \r\n return \"5\"*(c[5]-c[5]%9) + \"0\"*c[0]\r\n\r\nif __name__==\"__main__\":\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n ans = solve(n,arr)\r\n print(ans)\r\n \r\n ", "n = int(input())\r\narr = list(map(int, input().split(\" \")))\r\n\r\ncount5 = 0\r\ncount0 = 0\r\n\r\nfor i in range(len(arr)):\r\n if arr[i] == 5:\r\n count5 += 1\r\n else:\r\n count0 += 1\r\n\r\nif count0 == 0:\r\n print(-1)\r\n\r\nelif count5 < 9:\r\n print(0)\r\n\r\nelse:\r\n count5 -= count5 % 9\r\n for i in range(count5):\r\n print(\"5\", end=\"\")\r\n for i in range(count0):\r\n print(\"0\", end=\"\")\r\n", "n = int(input())\r\nlst = list(map(int, input().split()))\r\nlst.sort()\r\nans=0\r\na = lst.count(0)\r\nb = lst.count(5)\r\n\r\nif sum(lst)==n*5:\r\n print(-1)\r\nelif b<9:\r\n print(0)\r\nelse:\r\n b = b - b%9\r\n for i in range(b):\r\n print(5, end='')\r\n \r\n for i in range(a):\r\n print(0, end='')\r\n\r\n", "n=int(input());l=list(map(int,input().split()));n1=l.count(5);x=n-n1;print(int('5'*(9*(n1//9))+'0'*x)if x!=0 else -1)", "a=int(input())\r\nb=list(map(int,input().split()))\r\nc=b.count(5)\r\nd=b.count(0)\r\nx=c//9\r\nx=x*9\r\ny=list(map(str,(x*'5')))\r\nz=list(map(str,(d*'0')))\r\nif y.count('5')==0 and d>0:\r\n print(0)\r\nelif y.count('5') and d>0:\r\n print(''.join(y+z))\r\nelse:\r\n print(-1)\r\n", "n=int(input())\r\na=input().split()\r\nk=a.count(\"5\")\r\nm=a.count(\"0\")\r\nwhile (5*k)%9!=0:\r\n k-=1\r\nans=\"5\"*k+\"0\"*m\r\nif \"5\" not in ans and \"0\" in ans:\r\n print(0)\r\nelif \"0\" not in ans:\r\n print(-1)\r\nelse:\r\n print(ans)\r\n", "# 352A - Jeff and Digits\r\nn, l = int(input()), list(map(int, input().split()))\r\nif l.count(0)>0:\r\n print(int(\"5\"*((l.count(5)//9)*9)+\"0\"*(l.count(0))))\r\nelse:\r\n print(-1)", "n = int(input())\r\nlist = [int(num) for num in input().split()[:n]]\r\ncount=0\r\ncount2 = 0\r\ncheck = False\r\nif(0 in list):\r\n check = True\r\n\r\nfor i in list:\r\n if(i == 0):\r\n count2 = count2 + 1\r\n if(check == True):\r\n if(i==5):\r\n count+=1\r\n\r\nif(check == False):\r\n print(-1)\r\nelif(count>=9):\r\n c = count % 9\r\n count = count - c\r\n print(\"5\"*count,end=\"\")\r\n print(\"0\"*count2,end=\"\")\r\nelse:\r\n print(0)", "n=int(input())\r\ns=input()\r\nif '0' not in s:\r\n print(-1)\r\nelse:\r\n zero=s.count('0')\r\n five=s.count('5')\r\n total=five*5\r\n nine=total//9\r\n rem=nine%10\r\n if rem<5:\r\n nine-=rem\r\n elif rem>5:\r\n nine-=rem\r\n nine+=5\r\n if nine==0:\r\n print(0)\r\n else:\r\n print((nine*9)//5*'5'+zero*'0')", "n = int(input())\r\na = list(map(int, input().split()))\r\nfives = 0\r\nzeroes = 0\r\nfor i in range(n):\r\n if a[i] == 0:\r\n zeroes += 1\r\n else:\r\n fives += 1\r\nfives -= (fives%9)\r\nif zeroes == 0:\r\n print(-1)\r\nelif fives == 0:\r\n print(0)\r\nelse:\r\n ans = \"\"\r\n for i in range(fives):\r\n ans += \"5\"\r\n for j in range(zeroes):\r\n ans += \"0\"\r\n print(ans)\r\n", "n = int(input())\r\nnums = input().split()\r\nfive_counter = 0\r\nzero_counter = 0\r\nfor i in nums:\r\n if i == '5':five_counter+=1\r\n else: zero_counter+=1\r\n\r\n\r\nif (five_counter//9) > 0 and zero_counter > 0:\r\n print((\"5\"*(five_counter//9)*9)+(\"0\"*(len(nums)-five_counter)))\r\nelif zero_counter > 0:\r\n print(\"0\")\r\nelse:\r\n print(\"-1\")", "n = int(input())\r\nlst = list(map(int, input().split()))\r\nsu = sum(lst)\r\n\r\nbl = True\r\nc = lst.count(5)\r\nwhile su > 0:\r\n t = su\r\n s = 0\r\n while t > 0:\r\n s += t % 10\r\n t = t//10\r\n if s % 9 == 0 and 0 in lst:\r\n print(\"5\"*c+\"0\"*lst.count(0))\r\n bl = False\r\n break\r\n su -= 5\r\n c -= 1\r\nif bl and 0 in lst:\r\n print(0)\r\nelif bl:\r\n print(-1)\r\n", "n = int(input())\r\nl = list(map(int, input().split()))\r\n\r\ncount_5 = l.count(5)\r\ncount_0 = l.count(0)\r\n\r\nif count_0 == 0:\r\n print(-1)\r\nelif count_5 < 9:\r\n print(0)\r\nelse:\r\n count_5 -= count_5 % 9 #fuck you if u copy this code\r\n print('5' * count_5 + '0' * count_0)\r\n", "a, b = int(input()), input()\nc = b.count('5')\nd = a - c\nprint(int('5'* (9*(c//9))+ '0'*d) if d!=0 else -1)\n\t \t \t \t \t \t\t \t\t\t \t\t\t \t \t\t\t", "n,digits=int(input()),input()\r\nfives=digits.count('5')\r\nzeroes=n-digits.count('5')\r\nprint(int('5'*(9*(fives//9))+'0'*zeroes) if zeroes else '-1')", "import itertools\r\nn=int(input())\r\nlis=list(map(int,input().split()))\r\nfives=lis.count(5)\r\nzeros=lis.count(0)\r\nif zeros==0:\r\n\tprint(-1)\r\nelif fives<9:\r\n\tprint(0)\r\nelif fives>=9:\r\n\tres=fives//9\r\n\tans=''\r\n\tfor i in range(res*9):\r\n\t\tans+='5'\r\n\tfor i in range(zeros):\r\n\t\tans+='0'\r\n\tprint(ans)\r\nelse:\r\n\tprint(0)", "\r\n_ = int(input())\r\n\r\nl_n = input().split()\r\nd_n = {}\r\nd_n[\"0\"] = 0\r\nd_n[\"5\"] = 0\r\n\r\nfor n in l_n:\r\n d_n[n] += 1\r\n\r\nif d_n[\"0\"] == 0:\r\n print(\"-1\")\r\nelif d_n[\"5\"] < 9:\r\n print(\"0\")\r\nelse:\r\n print(\"%s%s\" % (\"5\"*(d_n[\"5\"] - d_n[\"5\"] % 9), \"0\"*d_n[\"0\"]))", "input()\r\nl = input().split()\r\n\r\n_0 = l.count('0')\r\n_5 = (l.count('5') // 9)*9\r\n\r\n\r\nif (_0 == 0):\r\n print(-1)\r\nelse:\r\n if(_5):\r\n print('5'*_5 + '0'*_0)\r\n else:\r\n print(0)\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nans='5'*((a.count(5)//9)*9)\r\nif a.count(0)==0:\r\n print(-1)\r\nelif a.count(5)<9:\r\n print(0)\r\nelse:\r\n print(ans+(a.count(0)*'0'))\r\n\r\n", "n = int(input())\r\nnums = map(int, input().split(\" \"))\r\n\r\nres = False\r\n\r\nnum = 0\r\nds = 0;\r\nzeros = 0;\r\n\r\nfor x in nums:\r\n if x == 0:\r\n res = True\r\n zeros += 1\r\n if (x == 5):\r\n ds += 1\r\n temp = int(\"5\" * ds)\r\n if (temp % 9 == 0):\r\n num = temp\r\n\r\nif not res:\r\n print(-1)\r\nelse:\r\n if num:\r\n print(str(num) + (\"0\" * zeros))\r\n else:\r\n print(0)\r\n\r\n", "from sys import stdin, stdout\n\n\ndef input():\n return stdin.readline().strip()\n\n\ndef print(string):\n return stdout.write(str(string) + \"\\n\")\n\n\ndef main():\n n = int(input())\n a = sorted([int(x) for x in input().split()], reverse=True)\n if a.count(0) == 0:\n print(-1)\n return\n i = 8\n while i < n:\n if a[i] == 0:\n break\n i += 9\n print(int(\"5\" * (i - 8) + \"0\" * a.count(0)))\n\n\nif __name__ == \"__main__\":\n main()\n", "c = int(input())\r\ni = input().split()\r\n\r\ncount_zero = i.count(\"0\")\r\n\r\nif count_zero == 0:\r\n print(-1)\r\nelse:\r\n count_five = i.count(\"5\")\r\n if count_five < 9:\r\n print(0)\r\n else: \r\n while count_five % 9 != 0:\r\n count_five -= 1\r\n print(\"5\"*count_five + \"0\" * count_zero)", "n=int(input())\r\nzero=0\r\nfive=0\r\nd=[]\r\na=list(map(int,input().split()))\r\nfor i in range(len(a)):\r\n if a[i]==5:\r\n five+=1\r\n else:\r\n zero+=1\r\nif five<9 and zero>0:\r\n print(0)\r\nelif zero<1:\r\n print(-1)\r\nelse:\r\n five-=five%9\r\n for i in range(five):\r\n d.append(5)\r\n for i in range(zero):\r\n d.append(0)\r\n print(*d,sep=\"\")\r\n", "t=int(input())\r\na=input().split()\r\nb=[int(i) for i in a]\r\nif 0 not in b:\r\n print(-1)\r\nelse:\r\n if b.count(5)<9:\r\n print(0)\r\n else:\r\n k=b.count(5)//9\r\n print(int(\"5\"*(9*k)+\"0\"*b.count(0)))\r\n \r\n", "n = int(input())\r\nlst = list(map(int,input().split()))\r\n\r\ndef max_digit(count_5,count_0):\r\n new_str=''\r\n for ele in lst:\r\n if ele ==0:\r\n count_0+=1 \r\n if ele ==5:\r\n count_5 +=1 \r\n \r\n if count_0 ==0:\r\n print(-1)\r\n elif count_5<9:\r\n print(0)\r\n else:\r\n count_5 -= (count_5 % 9)\r\n for i in range(count_5):\r\n new_str += str(5)\r\n for i in range(count_0):\r\n new_str += str(0)\r\n return new_str\r\n\r\nprint(max_digit(0,0))", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Mon Dec 26 18:06:21 2022\r\n\r\n@author: Lenovo\r\n\"\"\"\r\n\r\nn = int(input())\r\ns = input()\r\ns = s.split()\r\ns = sorted(s,reverse=True)\r\nif '0' in s: \r\n i = s.index('0')\r\n while (i*5)%9!=0 and i>0:\r\n i-=1\r\n if i==0:\r\n print(0)\r\n else:\r\n x = i*'5'+ (n-s.index('0'))*'0'\r\n print(x)\r\nelse:\r\n print(-1)\r\n\r\n \r\n", "n=int(input());l=input()\r\nc0=l.count('0');c5=n-c0\r\nprint(int('5'*9*(c5//9)+'0'*c0) if c0 else -1)", "from collections import Counter\nn = int(input())\nc = Counter(int(x) for x in input().split())\nif c[0] == 0:\n print(-1)\nelif c[5] // 9 == 0:\n print(0)\nelse:\n print('5' * 9 * (c[5] // 9) + '0' * c[0])", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\n\r\nif a.count(0) == 0:\r\n print(-1)\r\nelif a.count(5) < 9 and a.count(0) == 0:\r\n print(-1)\r\nelif a.count(5) < 9 and a.count(0) != 0:\r\n print(0)\r\nelse:\r\n b = \"\"\r\n if (a.count(5) % 9 == 0):\r\n b += \"5\" * a.count(5)\r\n b += \"0\" * a.count(0)\r\n \r\n print(b)\r\n else:\r\n for i in range(a.count(5), -1, -1):\r\n if (i % 9 == 0):\r\n d = i\r\n break\r\n \r\n b += \"5\" * d\r\n b += \"0\" * a.count(0)\r\n print(b)", "n=int(input())\r\nlst=list(map(int,input().split()))\r\nfreq={5:0,0:0}\r\nfor i in lst:\r\n freq[i]+=1\r\n\r\nif freq[0]==0:\r\n print(-1)\r\nelse:\r\n temp=9*(freq[5]//9)\r\n if temp==0:print(0)\r\n else:\r\n ans='5'*(temp)+'0'*(freq[0])\r\n print(ans)", "n=int(input())\r\nll=list(map(int,input().split()))\r\nfive=ll.count(5)\r\nzero=ll.count(0)\r\nif zero==0:\r\n print(-1)\r\nelif five<9:\r\n print(0)\r\nelse:\r\n print(\"5\"*((five//9)*9)+\"0\"*zero)\r\n", "n= int(input())\r\ns=input()\r\nf,z=s.count('5'), s.count('0')\r\nif z==0:\r\n print(-1)\r\nelse:\r\n if f<9:\r\n print(0)\r\n else:\r\n print(int('5'*9*(f//9)+'0'*z))", "n = int(input())\nf = list(map(int, input().split())).count(5)\nz = n - f\nprint(int('5'*((f//9)*9) + '0'*z) if z else -1)", "n=int(input())\r\narr=list(map(int,input().split()))\r\nz=arr.count(0)\r\nf=arr.count(5)\r\nif z==0:\r\n print(-1)\r\nelif f<9:\r\n print(0)\r\nelse:\r\n f=f-f%9\r\n for i in range(f):\r\n print(5,end='')\r\n for i in range(z):\r\n print(0,end='')", "import heapq\r\nfrom math import gcd,lcm\r\n# Shortcut for input\r\ndef I(): return int(input())\r\ndef MI(): return map(int, input().split())\r\ndef MS(): return map(str, input().split())\r\ndef LI(): return list(map(int, input().split()))\r\ndef LI(): return list(map(int, input().split()))\r\ndef S(): return input()\r\n# Constants\r\nmod = 10**9 + 7\r\ndef compute(s):\r\n summ = 0\r\n five = 0\r\n zero = 0\r\n for i in s:\r\n if i == 0:\r\n zero+=1\r\n if i == 5:\r\n five +=1\r\n summ+=i\r\n return summ,five,zero\r\ndef main(s):\r\n summ,five,zero = compute(s)\r\n if zero==0:\r\n return -1\r\n if summ == 0:\r\n return 0\r\n else:\r\n #sum is greater than 0\r\n #it contains zero also\r\n #no. of 5 we can use = (count5)//9\r\n if five//9 > 0:\r\n return \"5\"*((five//9)*9) + \"0\"*(zero)\r\n else:\r\n if zero > 0:\r\n return 0\r\n else:\r\n return -1\r\nn = I()\r\ns = LI()\r\nprint(main(s))", "n = int(input())\r\nl = list(map(int, input().split()))\r\nc5 = l.count(5)\r\nc0 = l.count(0)\r\nif(c0 == 0):\r\n print(-1)\r\n exit()\r\nprint(int('5' * (c5 - c5 % 9) + '0' * c0))\r\n", "n = input()\r\nboards = [int(x) for x in input().strip().split()]\r\n \r\nc5 = boards.count(5)\r\nc0 = boards.count(0)\r\n \r\nif c5 >= 9:\r\n mod = c5 % 9\r\n if c0 >= 1:\r\n print((c5 - mod) * '5' + c0 * '0')\r\n else:\r\n print(-1)\r\nelse:\r\n if c0 > 0:\r\n print(0)\r\n else:\r\n print(-1)\r\n", "from collections import Counter\n\nx = int(input())\nnumbers = list(map(int, input().split()))\n\n\ncount = Counter(numbers)\nif count[0] == 0:\n print(-1)\nelif count[5] < 9:\n print(0)\nelse:\n ans = ''\n no_of_fives = count[5]\n mod_for_nine = no_of_fives % 9\n if mod_for_nine == 0:\n largest_sequence_of_five = no_of_fives\n else:\n largest_sequence_of_five = no_of_fives - mod_for_nine\n \n for i in range(largest_sequence_of_five):\n ans += '5'\n for i in range(count[0]):\n ans += '0'\n print(int(ans))\n\t \t\t\t \t\t\t\t\t\t\t\t\t \t\t\t \t \t \t\t \t", "n = int(input())\r\na = list(map(int, input().split(\" \")))\r\nx = a.count(0)\r\ny = a.count(5)\r\n\r\nif x>=1:\r\n if y>=9:\r\n print(\"5\"*((y//9)*9) + \"0\"*x)\r\n elif y==0:\r\n print(0)\r\n else:\r\n print(0)\r\nelse:\r\n print(-1)\r\n", "from collections import Counter\r\nn=int(input())\r\nw=Counter([int(k) for k in input().split()])\r\na=w[5]//9\r\nb=w[0]\r\nif b==0:\r\n print(-1)\r\nelif a>0:\r\n print(\"5\"*(a*9)+b*\"0\")\r\nelse:\r\n print(\"0\")", "#https://codeforces.com/problemset/problem/352/A\r\nn =int(input())\r\nl=list(map(int,input().split()))\r\nc=l.count(5)\r\nc1=l.count(0)\r\nif c1==0:\r\n print(-1)\r\nelse:\r\n sm =sum(l)\r\n z1=1\r\n while(c>0):\r\n if sm%9==0:\r\n z1=0\r\n break\r\n \r\n \r\n else:\r\n sm-=5 \r\n c-=1 \r\n if z1==1:\r\n print(0)\r\n else:\r\n l1=[]\r\n for i in range(c):\r\n print(5,end=\"\")\r\n for i in range(c1):\r\n print(0,end=\"\")\r\n \r\n \r\n ", "n=int(input())\r\na=list(map(int,input().split()))\r\n\r\nif 0 in a :\r\n g=0\r\n k=0\r\n for i in a :\r\n if i==5 :\r\n g+=1\r\n if i==0 :\r\n k+=1\r\n h=g//9\r\n if h>0 :\r\n print(h*9*\"5\"+k*\"0\")\r\n else :\r\n print(0)\r\nelse :\r\n print(-1)", "def main():\n length = int(input())\n digits = input().split()\n for i in range(len(digits)):\n digits[i] = int(digits[i])\n if 0 not in digits:\n print(-1)\n else:\n count_of_5 = 0\n count_of_0 = 0\n for digit in digits:\n if digit == 5:\n count_of_5 += 1\n else:\n count_of_0 += 1\n while (5 * count_of_5) % 9 != 0:\n count_of_5 -= 1\n print(int('5' * count_of_5 + '0' * count_of_0))\nmain()\n", "\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nc0=a.count(0)\r\nc5=a.count(5)\r\ni=\"\"\r\nif c0 == 0:\r\n print(-1)\r\n quit()\r\n\r\nelse:\r\n i=i+\"5\"*(9*(c5//9))\r\nif len(i)==0:\r\n i=\"0\"\r\nelse:\r\n i=i+\"0\"*c0\r\nprint(i)", "n=int(input())\r\nl = [int(i) for i in input().split()]\r\nnumber5=0\r\nnumber0=0\r\ns=''\r\nif 0 not in l :\r\n print(-1)\r\nelse:\r\n l.sort()\r\n number5=l.count(5)\r\n number0=len(l) - number5\r\n \r\n s = (number5 // 9)*9*'5' + number0*'0'\r\n print(int(s))", "a=int(input())\r\nN=input().split()\r\np=(N.count(\"5\"))//9*9\r\no=N.count(\"0\")\r\nif p>0:\r\n if o>0:\r\n print(\"5\"*p+\"0\"*o)\r\n else:\r\n print(-1)\r\nelif o>0:\r\n print(0)\r\nelse:\r\n print(-1)\r\n", "import sys\r\ninput = sys.stdin.readline\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nfives = 0\r\nzeros = 0\r\nfor i in range(n):\r\n if arr[i] == 5 :\r\n fives += 1\r\n else :\r\n zeros += 1\r\nif zeros == 0 :\r\n print(-1)\r\n\r\nelif fives >= 9 :\r\n print(\"5\"*(fives//9) * 9 + \"0\"*zeros)\r\nelse :\r\n print(0)\r\n\r\n \r\n \r\n \r\n ", "n = int(input())\r\nt_list = list(map(int, input().split()))\r\n\r\nf = 0\r\nz = 0\r\n\r\nfor t in t_list:\r\n if t == 0:\r\n z += 1\r\n elif t == 5:\r\n f += 1\r\n\r\nif z == 0:\r\n print(-1)\r\nelif f < 9:\r\n print(0)\r\nelse:\r\n f -= f % 9\r\n for i in range(f):\r\n print(5, end='')\r\n for i in range(z):\r\n print(0, end='')\r\n\r\nprint()\r\n\r\n", "n = int(input())\r\ns = input()\r\nfives = s.count('5')\r\nzeros = s.count('0')\r\n\r\nif zeros == 0:\r\n print(-1)\r\nelif fives >= 9:\r\n print('5' * (fives - fives % 9) + '0' * zeros)\r\nelse:\r\n print(0)", "n=int(input())\r\na=list(map(int,input().split()))\r\nx=a.count(0)\r\ny=a.count(5)\r\nif x>=1 and y>=9:\r\n print((str(5)*(y-y%9)+str(0)*x))\r\nelif x>=1:\r\n print(0)\r\nelse:\r\n print(-1)", "n=int(input())\r\na=list(map(int,input().split()))\r\n\r\n\r\ndp=[]\r\ncnt=0\r\nfor i in range(n):\r\n if a[i]==5:\r\n cnt+=1\r\n\r\nzeroes=n-cnt\r\n\r\nif zeroes==0:\r\n print(-1)\r\nelse:\r\n s=''\r\n ans=0\r\n while cnt:\r\n cnt-=1\r\n s+='5'\r\n if int(s)%9==0:\r\n ans=s\r\n \r\n if ans==0:\r\n print(0)\r\n else:\r\n print(ans+'0'*zeroes)\r\n", "\"\"\"Already submitted but adding documentation\r\nLogic\r\n1. inorder for a number to be divisible by 9, it's sum must be divisible by 9\r\n2. since all inputs are either 0 or 5, 9 5s makes 45.\r\n3. so multiple of 9 5s, will give number divisible by 9.\r\n4. for 90, we need multiple of 9 5s, and atleast 1 0.\r\n5. since we can use less than the given numbers, we find out what is the closest multiple of 9 5s and then \r\nadd number of zeros to it.\r\n6. We must also lookout for edge cases \r\n -> all 5s will mean no possible (-1)\r\n -> atleast 1 zero means 0\r\n\"\"\"\r\n\r\n\r\nn = int(input())\r\nlst = list(map(int, input().rstrip().split()))\r\nd = {}\r\n\r\nfor i in lst:\r\n if i not in d:\r\n d[i] = 1\r\n else:\r\n d[i] += 1\r\n\r\nif 5 not in d:\r\n print(0)\r\n\r\nelif 0 not in d:\r\n print(-1)\r\n\r\nelse:\r\n if d[5] >= 9 and d[0] > 0:\r\n print(\"5\" * 9 * (d[5] // 9) + \"0\" * d[0])\r\n else:\r\n print(0)\r\n", "n=int(input())\r\narr=list(map(int,input().split()))\r\nc1=arr.count(0)\r\nif(c1==0):\r\n print(-1)\r\nelse:\r\n ans=0\r\n c2=arr.count(5)\r\n for i in range(c2,0,-1):\r\n if((5*i)%9==0):\r\n ans=i \r\n break\r\n if(ans==0):\r\n print(0)\r\n else:\r\n print('5'*ans,end=\"\")\r\n print('0'*c1)\r\n\r\n\r\n\r\n", "test_case = int(input())\nall_values = [int(x) for x in input(). split()]\n\nfive = all_values.count(5)\nzero = all_values.count(0)\n\nuseable_five = (five//9)*9\n\n\nif zero == 0:\n print(-1)\n exit()\nif useable_five == 0:\n print(0)\n exit()\n\nprint('5'*useable_five, end=\"\")\nprint('0'*zero)\n\t \t \t\t\t\t \t \t\t\t\t \t \t\t\t\t \t", "n = int(input())\r\ncards = list(map(int, input().split()))\r\n\r\nf, z = 0, 0\r\nfor i in range(n):\r\n t = cards[i]\r\n if t == 0:\r\n z += 1\r\n elif t == 5:\r\n f += 1\r\n\r\nif z == 0:\r\n print(-1)\r\nelif f < 9:\r\n print(0)\r\nelse:\r\n f -= f % 9\r\n print('5' * f + '0' * z)\r\n\r\n\r\n", "a,b=int(input()),input();c=b.count('5');d=a-c\r\n \r\nprint(int('5'*(9*(c//9))+'0'*d) if d!=0 else '-1')", "\nn = int(input())\ndef getSpaceSeperatedInput():\n input_string = input('')\n user_list = input_string.split()\n \n # convert each item to int type\n for i in range(len(user_list)):\n # convert each item to int type\n user_list[i] = int(user_list[i])\n return user_list\n\n\nint_list = getSpaceSeperatedInput()\n\ncount_5 =0\n\nfor i in range(len(int_list)):\n if(int_list[i] == 5):\n count_5 +=1\n \ncount_0 = len(int_list) - count_5\n\n\ndef giveDivisibleNum (count_5 , count_0):\n if(count_0 == 0):\n return -1\n elif(count_5 //9 == 0):\n return 0\n elif(count_5 //9 >0):\n floor_count_5 = count_5 //9\n str = '5'*floor_count_5*9 + '0'*count_0\n return int(str)\n\n\n\n\nvalue = giveDivisibleNum(count_5 , count_0)\nprint(value)\n", "n = int(input())\nnums = list(map(int, input().split()))\nfrom collections import Counter\nc = Counter(nums)\nnum_0 = c[0]\nnum_5 = c[5]\n\ndef solve(num_0, num_5):\n\tif num_0 == 0:\n\t\treturn \"-1\"\n\tif num_5 < 9:\n\t\treturn \"0\"\n\tk = num_5 // 9 # to round down the 5's to multiple of 9\n\tstr_fives = [\"5\"] * k * 9\n\tstr_zeros = [\"0\"] * num_0\n\treturn \"\".join(str_fives + str_zeros)\n\nprint(solve(num_0, num_5))", "n = int(input())\r\na = list(map(int, input().split()))\r\nfives = a.count(5)\r\nzeros = a.count(0)\r\nif zeros == 0:\r\n print(-1)\r\nelse:\r\n fives -= fives % 9\r\n if fives == 0:\r\n print(0)\r\n else:\r\n print('5' * fives + '0' * zeros)# 1689332850.7356427", "'''\r\n >>>>>>>>>>>>>>>>>>>>>>>>>>> বিসমিল্লাহির রাহমানির রাহিম\r\n\r\n بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\r\n\r\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Bismillahir Rahmanir Rahim\r\n'''\r\n\r\n'''::::::::::_^_;;;;;;;;;;;;;;;;;;;;_^_%%%%%%%%%%%%%%%%_^_@@@@@@@@@@@@@@\r\n''::::::::::_^_;;;;;;;;;;;;;;;;;;;;_^_%%%%%%%%%%%%%%%%_^_@@@@@@@@@@@@@@@\r\n\r\n PROBLEM :A. Jeff and Digits\r\n SOLUTATOIN:........\r\n\r\n ========================================================================\r\n ========================================================================\r\n '''\t\t\t\r\nn,k=int(input()),input()\r\nm=k.count(\"5\")\r\nl=n-m\r\nprint(int(\"5\"*(9*(m//9))+\"0\"*l) if l!=0 else -1)\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nf=l.count(5)\r\nz=l.count(0)\r\nif z==0:\r\n print(-1)\r\nelif f<9:\r\n print(0)\r\nelse:\r\n f-=(f%9)\r\n print(\"5\"*f+\"0\"*z)", "n = int(input())\r\nA = [int(a) for a in input().split()]\r\n\r\nfive, zero = 0, 0\r\nfor i in range(n):\r\n if A[i] == 5:\r\n five += 1\r\n else:\r\n zero += 1\r\n\r\nif five < 9:\r\n if zero > 0:\r\n print(0)\r\n else:\r\n print(-1)\r\nelse:\r\n if zero > 0:\r\n print(('5' * (five - five % 9)) + ('0' * zero))\r\n else:\r\n print(-1)", "a=int(input())\r\nb=list(map(int,input().split()))\r\ncount2=b.count(0)\r\ncount1=b.count(5)\r\nc=(count1//9) * 9\r\nif count2==0:\r\n\tprint('-1')\r\nelif count1>=9:\r\n\tprint('5'*c + '0' *count2)\r\nelse:\r\n\tprint('0')\r\n\t", "\ndef main():\n n = int(input())\n fives = sum(1 for x in input().split() if x == '5')\n zeroes = abs(n - fives)\n fives = fives - fives%9\n if not zeroes:\n print(-1)\n elif not fives:\n print(0)\n else:\n print('5'*fives + '0'*zeroes)\n\nmain()\n", "from math import *\ndef boardGrames(n, a) :\n \n count0, ccount5 = 0, 0\n \n for i in range(n) :\n \n if a[i] == 0 :\n count0 += 1\n else :\n ccount5 += 1\n\n ccount5 = floor(ccount5 / 9) * 9\n \n if count0 == 0 : \n print(-1,end = \"\") \n elif ccount5 == 0 : \n print(0,end = \"\") \n \n else :\n \n for i in range(ccount5) :\n print(5,end = \"\")\n for i in range(count0) :\n print(0, end = \"\")\n\nn = int(input())\na = list(map(int,input().split()[:n]))\nboardGrames(n,a)\n\t \t\t \t \t\t\t \t \t \t \t \t \t \t", "from math import *\n\n\ndef LargestNumber(len_of_number, numbers):\n number_of_zero, number_of_five = 0, 0\n\n for i in range(len_of_number):\n if numbers[i] == 0:\n number_of_zero += 1\n else:\n number_of_five += 1\n\n number_of_five = floor(number_of_five / 9) * 9\n\n if number_of_zero == 0:\n print(-1)\n elif number_of_five == 0:\n print(0)\n else:\n for i in range(number_of_five):\n print(5, end=\"\")\n\n for i in range(number_of_zero):\n print(0, end=\"\")\n\n\ntotal_number = int(input())\nnumbers = input()\n\nnumbers = numbers.split()\nnumbers = list(map(int, numbers))\nlen_of_number = len(numbers)\n\nLargestNumber(len_of_number, numbers)\n\t \t\t\t\t \t\t\t \t \t\t\t\t\t\t \t \t\t", "def jeffAndDigits(n,d):\r\n z, f = 0, 0\r\n a = []\r\n \r\n for i in d:\r\n if i == 0:\r\n z += 1\r\n else:\r\n f += 1\r\n \r\n if z == 0:\r\n return -1\r\n elif f < 9:\r\n return 0\r\n else:\r\n f -= f % 9\r\n for i in range(f):\r\n a.append('5')\r\n for j in range(z):\r\n a.append('0')\r\n \r\n ans = \"\".join(a)\r\n return ans\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input())\r\n d = [int(i) for i in input().split()]\r\n \r\n ans = jeffAndDigits(n,d)\r\n print(ans)\r\n ", "import math\r\nn = int(input())\r\nnumbers = list(map(int, input().split()))\r\nc5 = 0\r\nc0 = 0\r\nfor i in numbers:\r\n if(i == 5):\r\n c5 += 1\r\n else:\r\n c0 += 1\r\nc5 = math.floor(c5/9)*9\r\nif(c0 == 0):\r\n print(-1)\r\nelif(c5 == 0):\r\n print(0)\r\nelse:\r\n for i in range(c5):\r\n print(5, end=\"\")\r\n for i in range(c0):\r\n print(0, end=\"\")\r\n", "n = int(input())\r\nnumf = []\r\nnumz = []\r\ntimes = 0\r\nlastTime = 0\r\nnum = list(map(int, input().split()))\r\n\r\nfor i in range(0, n):\r\n if num[i] == 5:\r\n numf.append(num[i])\r\n times += 1\r\n\r\n if(times * 5 % 9 == 0):\r\n lastTime = times\r\n\r\n else:\r\n numz.append(num[i])\r\n\r\nif(len(numz) == 0):\r\n print(-1)\r\n\r\nelif(lastTime == 0):\r\n print(0)\r\n\r\nelse:\r\n print(\"5\" * lastTime + '0' * len(numz))", "n = int(input())\n\narr = list(map(int,input().split()))\n\nfi,ze = 0,0\n\nfor i in arr:\n if i==0:\n ze+=1\n else:\n fi+=1\n\nif ze==0:\n print(-1)\nelse:\n if fi<9:\n print(0)\n else:\n print(\"5\"*((fi//9)*9)+\"0\"*ze)\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nif 0 not in a:\r\n print(-1)\r\nelif a.count(5) <= 8:\r\n print(0)\r\nelse:\r\n h = a.count(5) // 9\r\n ans = '555555555'*h\r\n ans += '0'*(a.count(0))\r\n print(int(ans))", "length = int(input())\r\ndigits = list(map(int, input().split()))\r\n\r\nfive, zero = 0, 0\r\nfor digit in digits:\r\n\tif digit == 5:\r\n\t\tfive += 1\r\n\telse: zero += 1\r\n\r\nif zero == 0:\r\n\tprint('-1')\r\nelse:\r\n\tfive = five//9\r\n\tif five:\r\n\t\tprint('555555555'*five + '0'*zero)\r\n\telse:\r\n\t\tprint('0')", "n = int(input())\r\n\r\na = [int(x) for x in input().split()]\r\nfive = a.count(5) // 9\r\nzero = a.count(0)\r\nif zero != 0:\r\n if five != 0:\r\n num = '5'*five*9 + '0'*zero\r\n print(num)\r\n else:\r\n print(0)\r\nelse:\r\n print(-1)", "n = int(input())\r\nlis = [int(i) for i in input().split()]\r\nc0,c5=0,0\r\nfor i in lis:\r\n\tif i == 0:\r\n\t\tc0+=1\r\n\telse:\r\n\t\tc5+=1\r\nif c0==0:\r\n\tres = -1\r\nelse:\r\n\tif c5==0:\r\n\t\tres = 0\r\n\telif c5<9:\r\n\t\tres = 0\r\n\telse:\r\n\t\ts = ''\r\n\t\tfor i in range((c5//9)*9):\r\n\t\t\ts+='5'\r\n\t\tfor i in range(c0):\r\n\t\t\ts+= '0'\r\n\t\tres = s\r\nprint(res)\r\n\r\n\r\n", "# jeff and digits\r\n# https://codeforces.com/problemset/problem/352/A\r\n\r\nn = int(input())\r\ndigits = list(map(int, input().split()))\r\nz = digits.count(0)\r\nf = digits.count(5)\r\nif z == 0:\r\n print(-1)\r\nelif f < 9:\r\n print(0)\r\nelse:\r\n f -= f % 9\r\n for i in range(f):\r\n print(5, end='')\r\n for i in range(z):\r\n print(0, end='')\r\n print()\r\n ", "n=int(input())\r\narr=list(map(int,input().split()))\r\nn0=arr.count(0)\r\nnum=0\r\nans=0\r\nfor i in arr:\r\n if(i!=0):\r\n num=num*10+i\r\n if(num*(10**n0)%90==0):\r\n ans=num*(10**n0)\r\nif(ans==0 and n0==0):\r\n print(\"-1\")\r\nelse:\r\n print(ans)", "import math\r\ndef printLargestDivisible(n, a):\r\n # Count of 0s and 5s\r\n c0, c5 = 0, 0\r\n\r\n for i in range(n):\r\n\r\n if a[i] == 0:\r\n c0 += 1\r\n else:\r\n c5 += 1\r\n\r\n # The number of 5s that can be used\r\n c5 = math.floor(c5 / 9) * 9\r\n\r\n if c0 == 0: # The number can't be\r\n print(-1, end=\"\") # made multiple of 10\r\n\r\n elif c5 == 0: # The only multiple of 90\r\n print(0, end=\"\") # that can be made is 0\r\n\r\n else:\r\n\r\n for i in range(c5):\r\n print(5, end=\"\")\r\n for i in range(c0):\r\n print(0, end=\"\")\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nprintLargestDivisible(n,a)", "n = int(input())\r\ncards = list(map(int, input().split()))\r\ncount_0 = cards.count(0)\r\ncount_5 = cards.count(5)\r\nif count_0 == 0:\r\n print(-1)\r\nelse:\r\n total_sum = sum(cards)\r\n if count_5 - count_5 % 9 != 0:\r\n largest_number = \"5\" * (count_5 - count_5 % 9) + \"0\" * count_0\r\n print(largest_number)\r\n else:\r\n print(0)\r\n", "from collections import Counter\r\nn=int(input())\r\nt=input().split()\r\nt=[x for x in t]\r\n\r\ns0=s5=0\r\nfor i in t:\r\n if i=='5':\r\n s5+=1\r\n \r\n else:\r\n s0+=1\r\n\r\nst=''\r\nst+='5'*(s5//9*9)\r\nst+='0'*s0\r\n\r\nif st and int(st)%90==0:\r\n print(int(st))\r\nelse:\r\n print(-1)\r\n\r\n\r\n", "n=int(input()) \r\nli=[int(i)for i in input().split()]\r\ncnt0,cnt5=0,0\r\nactual=0\r\nfor i in li:\r\n if(i==5):\r\n cnt5+=1\r\n else:\r\n cnt0+=1\r\n if((cnt5*5)%9==0):\r\n actual=cnt5\r\nif(actual!=0 and cnt0>0):\r\n for i in range(actual):\r\n print(5,end='')\r\n for i in range(cnt0):\r\n print(0,end='')\r\nelif(cnt0>0):\r\n print(0)\r\nelse:\r\n print(-1) \r\n", "n=int(input())\r\nl=[int(i) for i in input().split()]\r\nc=0\r\nc_0=0\r\nfor i in l:\r\n if i==5:\r\n c+=1\r\n if i==0:\r\n c_0+=1\r\nif 0 not in l:\r\n print(-1)\r\n exit()\r\nif c<9:\r\n print(0)\r\n exit()\r\nprint(int(str('5'*(c-(c%9))+'0'*c_0)))\r\n\r\n", "\r\na=int(input())\r\nb=list(map(int,input().split()))\r\ns=sum(b)\r\nk=0\r\nwhile s%9!=0:\r\n s-=5\r\n k+=1\r\nj=((a-k)-b.count(0))\r\nu=s//9\r\nif b.count(0)>=1 and j!=0:\r\n print('5'*j,'0'*b.count(0),sep='')\r\nelif j==0 and a*5!=sum(b) :\r\n print(0) \r\nelse:\r\n print(-1)\r\n", "n=int(input())\r\nL=list(map(int,input().split()))\r\nno=0\r\nfor i in L:\r\n if i==5:\r\n no+=1 \r\nif no<9:\r\n if (len(L)-no)==0:\r\n print(-1)\r\n else:\r\n print(0)\r\nelse:\r\n if (len(L)-no)==0:\r\n print(-1)\r\n else:\r\n nu=(no//9)*9\r\n print(\"5\"*nu,end=\"\")\r\n print(\"0\"*(len(L)-no))", "def input_list():\r\n return list(map(int, input().split()))\r\n\r\nn = int(input())\r\n\r\nlis1 = input_list()\r\n\r\n\r\nc5 = lis1.count(5)\r\nc0 = lis1.count(0)\r\n\r\nif c0 == 0 :\r\n print(-1)\r\nelse :\r\n if c5 // 9 > 0 :\r\n print('5' * (c5 - c5 % 9) + c0 * '0')\r\n else :\r\n print(0)", "a = int(input())\r\narray = list(map(int, input().split()))\r\nt = array.count(5)\r\nt1 = array.count(0)\r\nif t >= 9 and t1 > 0:\r\n for i in range(0, t // 9):\r\n print(\"555555555\", end=\"\")\r\n for i in range(0, t1):\r\n print(\"0\", end=\"\")\r\nelif t1 > 0:\r\n print(\"0\")\r\nelse:\r\n print(-1)", "import re\r\nimport sys\r\nimport math\r\nfrom traceback import print_tb\r\ndef gt(): return map(int, sys.stdin.readline().strip().split())\r\ndef read(): return list(map(int,input().split()))\r\n\r\ndef goggle(p,val):\r\n print(\"Case #\"+str(p)+\":\",val)\r\n\r\n\r\n# t = int(input())\r\n# while t>0:\r\n\r\n# t -= 1\r\n\r\nn = int(input())\r\nv1 = read()\r\n\r\nfive = v1.count(5)\r\nzero = v1.count(0)\r\n\r\nnum = 0\r\nk = -1\r\nfor _ in range(five):\r\n num = 10*num + 5\r\n if num%9==0:\r\n k = num\r\n\r\nif k==-1:\r\n if zero==0: print(-1)\r\n else: print(0)\r\nelse:\r\n if zero==0: print(-1)\r\n else: print(str(k)+\"0\"*zero)", "n = int(input())\r\na = list(map(int,input().split()))\r\nf,z = 0,0\r\nfor i in a:\r\n if i == 0:\r\n z+=1 \r\n elif i == 5:\r\n f+=1 \r\nif z == 0:\r\n print(-1)\r\nelif f < 9:\r\n print(0)\r\nelse:\r\n f -= f % 9\r\n for j in range(f):\r\n print(5,end=\"\")\r\n for y in range(z):\r\n print(0,end=\"\")\r\n print()", "from math import floor\n\n\ndef solv_b(n, arr):\n count0, count5 = 0, 0\n\n for i in range(n):\n if arr[i] == 0:\n count0 += 1\n else:\n count5 += 1\n\n count5 = floor(count5 / 9) * 9\n \n if count0 == 0:\n print(-1, end=\"\")\n elif count5 == 0:\n print(0, end=\"\")\n\n else:\n for i in range(count5):\n print(5, end=\"\")\n for i in range(count0):\n print(0, end=\"\")\n\n\nn, arr = int(input()), list(map(int, input().split()))\nsolv_b(n, arr)\n\n\t \t\t\t\t \t \t \t\t\t\t\t\t\t \t\t\t\t\t", "from collections import Counter\r\n\r\n\r\nn = int(input())\r\ncount = Counter(map(int, input().split()))\r\nif count[0] == 0:\r\n print(-1)\r\nelse:\r\n num = \"0\" * count[0]\r\n for i in range(count[5], 0, -1):\r\n if int(\"5\" * i) % 9 == 0:\r\n num = \"5\" * i + num\r\n break\r\n print(int(num))\r\n", "num=int(input())\r\nlis=list(map(int,input().split()))\r\nif lis.count(5)<9 and lis.count(0)>=1:\r\n print(0)\r\nelif lis.count(5)>=9 and lis.count(0)>=1:\r\n print(\"5\"*(lis.count(5)//9)*9+\"0\"*lis.count(0))\r\nelse:\r\n print(-1)", "n = int(input())\r\na = list(map(int, input().split()))\r\ncnt2 = 0\r\ncnt = 0\r\nfor i in range(n):\r\n if a[i] == 0:\r\n cnt2 += 1\r\n else:\r\n cnt += 1\r\nif not cnt2:\r\n print(-1)\r\nelse:\r\n print(\"5\" * (9 * (cnt // 9)) + \"0\"*cnt2 if cnt // 9 else \"0\")", "n = int(input())\r\ncards = ''.join(input().split())\r\nc5 = cards.count('5')\r\nc0 = cards.count('0')\r\nif c5 >= 9 and c0 >= 1:\r\n print(((c5 // 9)*9)*'5' + c0* '0')\r\nelif c0 > 0 :\r\n print(0)\r\nelse:\r\n print(-1)", "a,b=int(input()),input()\r\nc=b.count('5')\r\nd=a-c\r\nprint(int('5'*(9*(c//9))+'0'*d) if d else '-1')", "n = int(input())\r\na = list(map(int, input().split()))\r\nfives = a.count(5)\r\nzeros = a.count(0)\r\n\r\nif zeros==0: print('-1')\r\nelif fives<9: print('0')\r\nelse:\r\n fives-= fives%9\r\n res = '5'*fives + '0'*zeros\r\n print(res)", "total_boards, numbers = int(input()), input()\nnumber_of_fives = numbers.count('5')\nnumber_of_zeros = total_boards - number_of_fives\nprint(int('5'* (9*(number_of_fives//9))+ '0'*number_of_zeros) if number_of_zeros!=0 else -1)\n\n\t \t \t \t \t \t \t\t \t\t \t\t \t\t", "n = int(input())\n_input = list(map(int,input().split()))\nfive_count,zero_count = 0, 0\nfor i in _input:\n\tfive_count += (i == 5)\n\tzero_count += (i == 0)\nfive_count //= 9\nfive_count *= 9\nif zero_count == 0:\n\tprint(-1)\nelif five_count == 0:\n\tprint(0)\nelse:\n\tfor i in range(five_count):\n\t\tprint(5,end = \"\")\n\tfor i in range(zero_count):\n\t\tprint(0,end = \"\")\n\t \t \t \t \t\t \t \t \t\t \t \t", "n=int(input())\r\nl=list(map(int,input().split()))\r\nfives=0\r\nzeros=0\r\nfor i in l:\r\n if i==5:\r\n fives+=1\r\n else:\r\n zeros+=1\r\nif zeros==0:\r\n print(-1)\r\nelif fives<9:\r\n print(0)\r\nelse:\r\n fives=fives-(fives%9)\r\n for i in range(fives):\r\n print(5,sep='',end='')\r\n for i in range(zeros):\r\n print(0,sep='',end='')", "## problem number 40\r\n\r\n## number possible divisibilty by 90 \r\n\r\nn=int(input())\r\nl=input().split()\r\nnum_5=num_0=0\r\nfor i in l :\r\n if i==\"5\" :\r\n num_5=num_5+1\r\n else :\r\n num_0=num_0+1\r\nif num_0<1 :\r\n print (-1)\r\nelse :\r\n if num_5<9 :\r\n print (0)\r\n else :\r\n fin=num_5-(num_5%9)\r\n str=\"\".join('5' for i in range(fin))\r\n for i in range(num_0):\r\n str=str+'0'\r\n print (str) \r\n \r\n \r\n\r\n", "n, t = int(input()), input()\r\na = t.count('5')\r\nb = n - a\r\nprint(int('5' * (a - a % 9) + '0' * b) if b else -1)", "\"\"\"import itertools\r\nn=int(input())\r\nl=list(map(str,input().split()))\r\nc = []\r\n\r\nfor r in range(len(l)+1):\r\n for combination in itertools.combinations(l, r):\r\n c.append(combination)\r\nc=[list(i) for i in c]\r\n\r\n\r\nfor i in c:\r\n if i==[]:\r\n c.remove([])\r\n else:\r\n if i[0]=='0' and len(i)>1:\r\n c.remove(i)\r\n c.append(['0'])\r\n elif i[0]=='0' and len(i)==0:\r\n pass\r\n else:\r\n pass\r\nc2=[int(\"\".join(i)) for i in c]\r\nprint(5555555550 in c2)\r\nc1=[]\r\nc1=[i for i in c if i not in c1]\r\n\r\nf=[]\r\nfor i in c1:\r\n if int(\"\".join(i))%9==0:\r\n f.append(int(\"\".join(i)))\r\n\r\nprint(max(f))\"\"\"\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nx=a.count(0)\r\ny=a.count(5)\r\nif x>=1 and y>=9:\r\n print((str(5)*(y-y%9)+str(0)*x))\r\nelif x>=1:\r\n print(0)\r\nelse:\r\n print(-1)", "n = int(input())\r\ndigits = list(map(int, input().split()))\r\ncount_zeros = digits.count(0)\r\ncount_fives = digits.count(5)\r\nif count_zeros == 0:\r\n print(-1)\r\nelif count_fives < 9:\r\n print(0)\r\nelse:\r\n count_fives -= count_fives % 9\r\n result = '5' * count_fives + '0' * count_zeros\r\n print(result)", "n = int(input())\r\ndata = list(map(int, input().split()))\r\n\r\ncnt5 = data.count(5)\r\ncnt0 = data.count(0)\r\n\r\ncnt = 0\r\nfor i in range(1, cnt5 + 1):\r\n if (i * 5) % 9 == 0:\r\n cnt = i\r\n\r\nif cnt0 == 0:\r\n print(-1)\r\nelse:\r\n ans = int('5' * cnt + '0' * cnt0)\r\n print(ans)", "def main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n temp_dict = dict()\r\n for element in arr:\r\n if element in temp_dict:\r\n temp_dict[element] += 1\r\n else:\r\n temp_dict[element] = 1\r\n\r\n if not 0 in temp_dict:\r\n print(-1)\r\n return\r\n else:\r\n if 5 in temp_dict:\r\n use5 = (temp_dict[5] // 9) * 9\r\n if use5 == 0:\r\n print(0)\r\n else:\r\n print(\"5\" * use5 + \"0\" * temp_dict[0])\r\n else:\r\n print(0)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n=int(input())\r\nlist1=list(map(int, input().split()))\r\n\r\nx=(list1.count(5))//9\r\ny=list1.count(0)\r\nif y!=0:\r\n m=(\"5\"*x*9+\"0\"*y)\r\n if int(m)==0:\r\n print(0)\r\n else:\r\n print(m)\r\nelse:\r\n print(-1)", "n = int(input())\r\narr = list(map(int,input().split()))\r\n\r\nhashVal = {5:0,0:0}\r\n\r\nfor num in arr:\r\n hashVal[num]+=1\r\n\r\n\r\nif hashVal[5]>=9:\r\n if hashVal[0]>0:\r\n print(\"5\"*(hashVal[5] - hashVal[5]%9) + \"0\"*hashVal[0])\r\n\r\n else:\r\n print(\"-1\")\r\n\r\nelif hashVal[5]<9:\r\n if hashVal[0]>0:\r\n print(\"0\")\r\n \r\n else:\r\n print(\"-1\")\r\n\r\n\r\n \r\n", "#Sum of number should be divisible by 9 (RULE FOR 9)\r\nn = int(input())\r\nlst = list(map(int,input().split()))\r\na_dict = {5:0,0:0}\r\nfor i in lst:\r\n if i ==5:\r\n a_dict[5]+=1\r\n else:\r\n a_dict[0]+=1\r\n\r\nnine = a_dict[5]//9\r\nzeros = a_dict[0]\r\n\r\nif zeros==0:\r\n print(-1)\r\nelif nine<1 and zeros!=0:\r\n print(0)\r\nelse:\r\n print('5'*nine*9 + '0'*zeros)\r\n\r\n\r\n\r\n", "def solve() -> None:\n n = int(input())\n a = [int(x) for x in input().split()]\n \n z = a.count(0)\n f = a.count(5)\n\n x = f // 9\n if x == 0:\n if z > 0:\n print(0)\n else:\n print(-1)\n else:\n if z > 0:\n for i in range(1, 9 * x + 1):\n print(5, end=\"\")\n for i in range(1, z + 1):\n print(0, end=\"\")\n print()\n else:\n print(-1)\n\nif __name__ == \"__main__\":\n\n t = 1\n # t = int(input())\n for _ in range(t):\n solve()", "n = int(input())\r\na = input().split()\r\nres = a.count(\"5\")\r\nr = res // 9\r\nzeroCount = n - res\r\nif zeroCount == 0: \r\n print(-1)\r\nelif r == 0: \r\n print(0)\r\nelse:\r\n print(\"5\" * (r*9) + \"0\" * zeroCount)", "n = int(input())\n\nnumbers = [int(i) for i in input().split()]\ncount = [0, 0]\nfor i in numbers:\n if i == 0:\n count[0] += 1\n else:\n count[1] += 1\n\n\nif count[0] == 0:\n print(-1)\nelif count[1] < 9:\n print(0)\nelse:\n result = int('5'*(count[1]//9*9) + '0'*count[0])\n print(result)\n\n", "n = int(input())\r\na = list(map(int,input().split()))\r\nz = a.count(0)\r\nf = n - z\r\nprint(-1 if z < 1 else 0 if f < 9 else '5'*(f//9*9)+'0'*z)", "n=int(input())\r\na=list(map(int,input().split()))\r\nc=a.count(5)\r\nc=c//9*9\r\nif (a.count(0)==0):\r\n print(-1)\r\nelif (c==0):\r\n print(0)\r\nelse:\r\n print(\"5\"*c+\"0\"*a.count(0))\r\n\r\n", "def solve():\r\n n = int(input())\r\n digits = [int(x) for x in input().split()]\r\n ddict = {5:0,0:0}\r\n for x in digits:\r\n ddict[x]+=1\r\n\r\n if ddict[0]==0:\r\n return -1\r\n \r\n if ddict[5]//9>0:\r\n ans = ''\r\n\r\n for i in range((ddict[5]//9)*9):\r\n ans+='5'\r\n for i in range(ddict[0]):\r\n ans+='0'\r\n return ans\r\n else:\r\n return 0\r\n\r\n\r\n\r\n\r\n ans = ''\r\n for i in range(ddict[5]):\r\n ans+='5'\r\n for i in range(ddict[0]):\r\n ans+='0'\r\n\r\n return ans\r\n\r\nprint(solve())", "def check(n , arr):\r\n if sum(arr) >= 45 and 0 in arr:\r\n total = sum(arr)\r\n value = total // 45\r\n value = '5' * 9 * value\r\n zeroCount = n - total // 5\r\n value += '0' * zeroCount\r\n return value\r\n elif 0 in arr and sum(arr) < 45:\r\n return 0\r\n else:\r\n return -1\r\n \r\nif __name__ ==\"__main__\":\r\n n = int(input().rstrip())\r\n arr = list(map(int , input().rstrip().split()))\r\n \r\n print (check(n , arr))\r\n ", "n = int(input())\r\n\r\ncards = list(map(int,input().split()))\r\n\r\nfives = 0\r\nzeros = 0\r\n\r\nfor i in cards:\r\n if i == 5:\r\n fives += 1\r\n else:\r\n zeros += 1\r\n\r\nif zeros == 0:\r\n print(-1)\r\nelif fives < 9:\r\n print(0)\r\nelse:\r\n fives -= fives % 9\r\n for i in range(fives):\r\n print('5',end='')\r\n for i in range(zeros):\r\n print('0',end='')", "from sys import stdin, stdout\r\n\r\nn = int(stdin.readline().strip())\r\ngiven = list(map(int, stdin.readline().strip().split()))\r\n\r\nfreq = [0]*6\r\n\r\nfor i in given:\r\n freq[i] += 1\r\nif freq[0] <= 0:\r\n stdout.write(f\"{-1}\")\r\nelif freq[5]//9:\r\n vals = \"5\"*((freq[5]//9)*9)+\"0\"*freq[0]\r\n stdout.write(vals)\r\nelse:\r\n stdout.write(f\"{0}\")\r\n", "n=int(input())\r\na=[int(i) for i in input().split()]\r\nf=a.count(5)\r\nz=n-f\r\nif f==n:\r\n print(-1)\r\nelif f<9 and z>=1:\r\n print(0)\r\nelse:\r\n f1=int(f/9)*9\r\n if f1==0:\r\n print(0)\r\n else:\r\n ans=\"\"\r\n for i in range(f1):\r\n ans+='5'\r\n for j in range(z):\r\n ans+='0'\r\n print(ans)\r\n", "n=int(input());s=\"\".join(sorted(input().split())[::-1])\r\nif \"0\" in s:\r\n while (int(s) % 90 != 0):\r\n s = s[1:]\r\n print(int(s))\r\nelse:\r\n print(-1)", "from collections import Counter\r\nn=int(input())\r\narr=map(int, input().split())\r\n\r\nd=dict(Counter(arr))\r\n# print(d)\r\nd[0]=d.get(0,0)\r\nd[5]=d.get(5,0)\r\nif(d[0]==0):\r\n\tprint(-1)\r\n\r\nelse:\r\n\tn=d[5]\r\n\twhile(5*n%9!=0):\r\n\t\tn-=1\r\n\r\n\tif(n==0):\r\n\t\tprint(0)\r\n\telse:\r\n\t\tprint('5'*n + '0'*d[0])\r\n", "n = int(input())\ncnt = input().count('5')\nif n == cnt:\n\tprint('-1')\nelif cnt < 9:\n\tprint('0')\nelse:\n\tprint('5' * (cnt // 9 * 9) + '0' * (n - cnt))\n \t \t\t\t \t \t\t \t\t \t \t \t\t", "input();a=input().split()\r\nprint('5'*(a.count('5')//9*9)+'0'*a.count('0') if a.count('5')>8 and a.count('0') else -(a.count('0')==0))", "\"\"\"\n352A | Jeff and Digits: brute force, implementation, math\n\"\"\"\n\nimport itertools\n\ndef jeff_and_digits():\n n = int(input())\n a = input()\n b = a.count('5')\n if n == b:\n print(-1)\n elif b < 9:\n print(0)\n else:\n print('5' * (b // 9 * 9) + '0' * (n - b))\n\n\nif __name__ == '__main__':\n jeff_and_digits()", "from collections import Counter\ninput()\nd = Counter(map(int, input().split()))\nif d[0] < 1:\n print(-1)\nelse:\n f = \"5\" * (9 * (d[5] // 9))\n print(int(f + \"0\" * d[0]))\n", "n = int(input())\r\ns = list(map(int, input().split()))\r\nif 5 in s:\r\n\tk = s.count(5)\r\n\tif 0 in s:\r\n\t\tm = s.count(0)\r\n\t\tif k >= 9:\r\n\t\t\tk = 9 * (k // 9) \r\n\t\t\tprint('5' * k + '0' * m)\r\n\t\telse:\r\n\t\t\tprint(0)\r\n\telse:\r\n\t\tprint(-1)\r\nelse:\r\n\tif 0 in s:\r\n\t\tprint(0)\r\n\telse:\r\n\t\tprint(-1)\r\n\r\n\t\t\r\n\r\n\r\n\t\t\r\n\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t\r\n\r\n\r\n\t\r\n\r\n\t\t\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t \r\n \r\n\r\n\r\n\r\n\r\n\t\t\t\r\n\t\t\r\n\t\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nx,y=a.count(5),a.count(0)\r\nif y>0:\r\n b=x//9\r\n if b==0:\r\n print(\"0\")\r\n else:\r\n s=b*9*\"5\"+y*\"0\"\r\n print(s)\r\nelse:\r\n print(\"-1\")", "\r\nnum_inp=lambda: int(input())\r\narr_inp=lambda: list(map(int,input().split()))\r\nsp_inp=lambda: map(int,input().split())\r\nstr_inp=lambda:input()\r\na,b=int(input()),input();c=b.count('5');d=a-c\r\n\r\nprint(int('5'*(9*(c//9))+'0'*d) if d!=0 else '-1')\r\n \t\t\t\t \t \t\t \t\t \t\t\t \t \t \t \t \t \t", "n=int(input())\r\nl=list(map(int,input().split()))\r\nif 0 not in l:\r\n print(\"-1\")\r\nelse:\r\n s=\"5\"*((l.count(5)//9)*9)+\"0\"*l.count(0)\r\n if \"5\" in s:\r\n print(s)\r\n else:\r\n print(0)", "n = int(input())\r\na = 0\r\nb = 0\r\nfor i in input().split():\r\n if i=='5':\r\n a+=1\r\n else:\r\n b+=1\r\nif b==0:\r\n print(-1)\r\nelse:\r\n x = a//9\r\n if x>0:\r\n print('5'*9*x + '0'*b)\r\n else:\r\n print(0)", "len = int(input())\r\nlis = list(map(int,input().split()))\r\na = lis.count(5)\r\nb = len - a\r\na = ( a // 9 ) * 9\r\nif a > 0 and b > 0 : print(a*\"5\"+b*\"0\") \r\nelif b > 0 : print(\"0\")\r\nelse : print(\"-1\")", "a = int(input())\r\nb = list(map(int, input().split()))\r\n\r\nt = b.count(5)\r\nn = b.count(0)\r\nif(n<1): print(-1)\r\nelse: print(int(t//9*9*\"5\"+n*\"0\"))\r\n", "n=int(input())\r\nl=input().split()\r\nres=''\r\nfcnt = l.count('5')\r\nzcnt = l.count('0')\r\n \r\nif zcnt < 1:\r\n print(-1)\r\n \r\nelif fcnt < 9 and zcnt>=1 :\r\n print(0)\r\n \r\nelse:\r\n for i in range((fcnt//9)*9):\r\n res+='5'\r\n \r\n for i in range(zcnt):\r\n res+='0'\r\n \r\n print(res)", "from collections import Counter\r\n\r\nN = int(input())\r\na = [x for x in input().split()]\r\nb = Counter(a)\r\nif b[\"0\"] == 0:\r\n\tprint(-1)\r\nelif b[\"5\"] < 9:\r\n\tprint(0)\r\nelse:\r\n\tprint(\"5\" * (b[\"5\"] - b[\"5\"] % 9) + \"0\" * b[\"0\"])", "from collections import Counter\r\n\r\nn = int(input())\r\ncards = Counter(input())\r\n\r\nnum5s = cards[\"5\"]\r\nnum0s = cards[\"0\"]\r\n\r\nif(num0s == 0):\r\n print(-1)\r\n\r\nelif(num5s < 9):\r\n print(0)\r\n\r\nelse:\r\n num5s -= num5s % 9\r\n print(num5s*\"5\"+num0s*\"0\")", "n=int(input())\r\na=list(map(int,input().split()))\r\na1,b1=a.count(0),a.count(5)\r\nif(b1//9 > 0 and a1>0):\r\n print('5'*(b1//9 * 9)+'0' * a1)\r\nelif(a1>0):\r\n print(0)\r\nelse:\r\n print(-1)\r\n\r\n\r\n\r\n", "\r\nm,n=int(input()),input()\r\nc=n.count('5'); d=m-c\r\nif d!=0:print(int('5'*(9*(c//9))+'0'*d))\r\nelse:print(-1)", "a = int(input())\r\nb = input()\r\nc = b.count('5')\r\nd = a - c\r\nprint(int('5' * (9 * (c // 9)) + '0' * d) if d else '-1')", "from collections import Counter\r\n\r\nn = int(input())\r\narr = list(map(int, input().split()))\r\nc = Counter(arr)\r\n\r\nif c[5] < 9:\r\n if (c[0]): print(0)\r\n else: print(-1)\r\nelse:\r\n if (c[0]):\r\n print(\"5\"*9*(c[5]//9), end=\"\")\r\n print(\"0\"*c[0], end=\"\")\r\n else:\r\n print(\"-1\")", "lmn=input()\r\nb=list(map(int,input().split()))\r\n#print(b)\r\nc={0:0,5:0}\r\nans=\"\"\r\nfor i in b:\r\n c[i]=c[i]+1\r\nsumi=\"\"\r\n#print(c[5])\r\nfor i in range(c[5]):\r\n sumi=sumi+\"5\"\r\n #print(sumi)\r\n if int(sumi)%9==0:\r\n ans=sumi\r\n#print(ans,' !11111111')\r\nif ans==\"\" and c[0]!=0:\r\n print(0)\r\nelif c[0]==0:\r\n print(-1)\r\nelif sumi!=\"\":\r\n for i in range(c[0]):\r\n ans=ans+\"0\"\r\n print(ans)", "n = int(input())\r\nz = input().split().count('0')\r\ny = n-z\r\nprint((y//9*9 *'5'+'0'*z, -(z<1))[y < 9 or z < 1] )", "n=int(input())\r\nl=list(map(int,input().split()))\r\nsum=int(0)\r\ncountz=int(0)\r\ncountf=int(0)\r\nfor i in l:\r\n sum+=i\r\n if i==0:\r\n countz+=1\r\n elif i==5:\r\n countf+=1\r\nif countz==0:\r\n print(-1)\r\nelif countf<9 and countz>0:\r\n print(0)\r\nelse:\r\n k=countf//9\r\n print(\"5\"*k*9 + \"0\"*countz)", "n = int(input())\r\nt_values = list(map(int, input().split()))\r\n\r\nz = t_values.count(0)\r\nf = t_values.count(5)\r\n\r\nif z == 0:\r\n print(-1)\r\nelif f < 9:\r\n print(0)\r\nelse:\r\n f -= f % 9\r\n result = [5] * f + [0] * z\r\n print(''.join(map(str, result)))" ]
{"inputs": ["4\n5 0 5 0", "11\n5 5 5 5 5 5 5 5 0 5 5", "7\n5 5 5 5 5 5 5", "1\n5", "1\n0", "11\n5 0 5 5 5 0 0 5 5 5 5", "23\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "9\n5 5 5 5 5 5 5 5 5", "24\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 0 0 0 0 0", "10\n0 0 0 0 0 0 0 0 0 0", "10\n5 5 5 5 5 0 0 5 0 5", "3\n5 5 0", "5\n5 5 0 5 5", "14\n0 5 5 0 0 0 0 0 0 5 5 5 5 5", "3\n5 5 5", "3\n0 5 5", "13\n0 0 5 0 5 0 5 5 0 0 0 0 0", "9\n5 5 0 5 5 5 5 5 5", "8\n0 0 0 0 0 0 0 0", "101\n5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 5 0 0 0 0 0 5 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 5 0 0 5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 5 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 5 0 0", "214\n5 0 5 0 5 0 0 0 5 5 0 5 0 5 5 0 5 0 0 0 0 5 5 0 0 5 5 0 0 0 0 5 5 5 5 0 5 0 0 0 0 0 0 5 0 0 0 5 0 0 5 0 0 5 5 0 0 5 5 0 0 0 0 0 5 0 5 0 5 5 0 5 0 0 5 5 5 0 5 0 5 0 5 5 0 5 0 0 0 5 5 0 5 0 5 5 5 5 5 0 0 0 0 0 0 5 0 5 5 0 5 0 5 0 5 5 0 0 0 0 5 0 5 0 5 0 0 5 0 0 5 5 5 5 5 0 0 5 0 0 5 0 0 5 0 0 5 0 0 5 0 5 0 0 0 5 0 0 5 5 5 0 0 5 5 5 0 0 5 5 0 0 0 5 0 0 5 5 5 5 5 5 0 5 0 0 5 5 5 5 0 5 5 0 0 0 5 5 5 5 0 0 0 0 5 0 0 5 0 0 5 5 0 0", "80\n0 0 0 0 5 0 5 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 5 0 0 0 0 0 0 0 0 0 5 5 0 5 0 0 0 0 0 0 5 0 0 0 0 0 0 0 5 0 0 0 0 5 0 5 5 0 0 0", "2\n0 0", "3\n5 0 0", "4\n5 5 5 5", "2\n0 5", "14\n5 5 5 5 5 5 5 5 5 5 5 5 5 0", "18\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "10\n5 5 5 5 5 5 5 5 5 0", "10\n5 5 5 5 5 5 5 5 5 5", "20\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5"], "outputs": ["0", "5555555550", "-1", "-1", "0", "0", "55555555555555555500000", "-1", "55555555555555555500000", "0", "0", "0", "0", "0", "-1", "0", "0", "0", "0", "5555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "555555555000000000000000000000000000000000000000000000000000000000000000000", "0", "0", "-1", "0", "5555555550", "-1", "5555555550", "-1", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
159
2098cd490c69f659d881f9271b7531fc
String Game
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct). Print a single integer number, the maximum number of letters that Nastya can remove. Sample Input ababcba abb 5 3 4 1 7 6 2 bbbabb bb 1 6 3 4 2 5 Sample Output 34
[ "s = input()\r\nsmall = input()\r\nnums = [int(x)-1 for x in input().split()]\r\nn = len(s)\r\nlo = 0\r\nans = 0\r\nhi = n-1\r\ndef check(x):\r\n copy = [1]*n\r\n index = 0\r\n for i in range(x):\r\n copy[nums[i]]=0\r\n for i in range(n):\r\n if s[i]==small[index] and copy[i]:\r\n index+=1\r\n if index >= len(small):\r\n return True\r\n return False\r\nwhile lo <= hi:\r\n mid = (lo+hi)//2\r\n if check(mid):\r\n ans = mid\r\n lo=mid+1\r\n else:\r\n hi=mid-1\r\nprint(ans)", "def binaryFind():\r\n c = [0]*lenp\r\n maxlen = 0\r\n for i in range(0,mid):\r\n c[a[i]-1]=1\r\n for i in range(0,lenp):\r\n if c[i]==0:\r\n if p[i]==t[maxlen]:\r\n maxlen+=1\r\n if maxlen==lent:\r\n return True\r\n return False\r\n\r\np = input()\r\nt = input()\r\na = list(map(int,input().split()))\r\n\r\nlenp = len(p)\r\nlent = len(t)\r\nl=0\r\nr=lenp\r\n\r\nwhile l<=r:\r\n mid = (l+r)//2\r\n isok = binaryFind()\r\n if isok==True:\r\n l = mid+1\r\n else :\r\n r = mid-1\r\nprint(l-1)\r\n", "a=input()\r\nb=input()\r\nc=list(map(int,input().split()))\r\n\r\nl = 0 ; r = len(a)\r\nwhile l < r -1:\r\n mid = (r + l) // 2\r\n d = list(a)\r\n j = 0\r\n for i in range(mid):\r\n d[c[i]-1] = \"\"\r\n\r\n for i in d:\r\n if i == b[j]:\r\n j += 1\r\n if j == len(b):\r\n l = mid \r\n break\r\n if j != len(b):\r\n r = mid \r\nprint(l)", "\r\na=input()\r\nb=input()\r\nc=[i-1 for i in list(map(int,input().split()))]\r\nl=0\r\nr=len(a)\r\nwhile r-l>1:\r\n m=l+(r-l)//2\r\n t=list(a)\r\n j=0\r\n for i in range(m):t[c[i]]=''\r\n for i in range(len(a)):\r\n if t[i]==b[j]:\r\n j+=1\r\n if j==len(b):\r\n l=m;break\r\n if j!=len(b):r=m\r\nprint(l)", "import sys\n\n# listindexes is sorted\ndef removeat(string, indexes):\n\n return [c for i, c in enumerate(string) if i not in indexes]\n\ndef contains(string, what):\n\n if not len(what):\n return True\n if not len(string):\n return False\n\n checked = 0\n for c in string:\n if what[checked] == c:\n checked += 1\n if checked == len(what):\n break\n\n return checked == len(what)\n\nstring = list(input())\nwhat = list(input())\nindexes = [i-1 for i in map(int, input().split())]\n\nfirst = 0\nlast = len(indexes)-1\n\nwhile first<last:\n\n midpoint = first + (last - first)//2 + (last - first)%2\n \n if contains(removeat(string, set(indexes[:midpoint])), what):\n first = midpoint\n else:\n last = midpoint-1\n\nprint(first)\n\n", "# import sys,math\n# inf = float('inf')\n# input = sys.stdin.readline\n# mod = (10**9)+7\n# def lcm(a,b):\n# return int((a/math.gcd(a,b))*b)\n# def gcd(a,b):\n# return int(math.gcd(a,b))\n# \"\"\"\n# n = int(input())\n# n,k = map(int,input().split())\n# arr = list(map(int,input().split()))\n# \"\"\"\n#\n# alphabets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z']\n# for _ in range(1):\n# pass\ndef canFind(ss,t,arr,mid):\n s = ss.copy()\n for i in range(mid):\n s[arr[i]-1]='#'\n k = 0\n for i in range(len(t)):\n flag=False\n for j in range(k,len(s)):\n if t[i]==s[j]:\n flag=True\n k = j+1\n break\n if not flag:\n return False\n return True\n\ns = list(input())\nt = list(input())\narr = list(map(int,input().split()))\nn = len(arr)\nl = 0\nr = n\nans = 0\nwhile l<=r:\n mid = (l+r)//2\n if canFind(s,t,arr,mid):\n ans = mid\n l = mid+1\n else:\n r=mid-1\nprint(ans)\n", "t = input()\r\np = input()\r\nai = list(map(int,input().split()))\r\nn = len(ai)\r\nti = [[t[i],1] for i in range(n)]\r\nfor i in range(n):\r\n ai[i] -= 1\r\n\r\nnum2 = 1\r\n\r\ndef check(num):\r\n global num2\r\n num2 -= 1\r\n for i in range(num):\r\n ti[ai[i]][1] = num2\r\n num3 = 0\r\n for i in ti:\r\n if i[1] == num2:\r\n continue\r\n if i[0] == p[num3]:\r\n num3 += 1\r\n if num3 == len(p):\r\n return True\r\n return False\r\n\r\nhigh = n\r\nlow = 0\r\nmid = (high + low) // 2\r\nwhile high >= low:\r\n if check(mid):\r\n low = mid + 1\r\n else:\r\n high = mid - 1\r\n mid = (high + low) // 2\r\n\r\nprint(mid)\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1]\r\nt = input()[:-1]\r\nw = list(map(int, input().split()))\r\nn = len(w)\r\nl, r, x = 0, n-len(t)+1, 0\r\nwhile l < r:\r\n m = (l+r)//2\r\n d = [0]*n\r\n for i in range(m):\r\n d[w[i]-1] = 1\r\n j = 0\r\n for i in range(n):\r\n if s[i] == t[j] and d[i] == 0:\r\n j += 1\r\n if j == len(t):\r\n x = max(x, m)\r\n l = m+1\r\n break\r\n else:\r\n r = m\r\nprint(x)", "string1 = input()\r\nstring2 = input()\r\narr= list(map(int,input().split()))\r\nfrom collections import defaultdict\r\ndef check(mid):\r\n\tremain = arr[:mid]\r\n\tinvalid = [False]*len(arr)\r\n\tfor ele in remain:\r\n\t\tinvalid[ele-1] = True\r\n\t#memo = defaultdict(lambda:[])\r\n\t# for i in range(len(string1)):\r\n\t# \tif invalid[i]:continue \r\n\t# \tmemo[string1[i]].append(i)\r\n\t\r\n\t# for \r\n\ti,j = 0,0\r\n\twhile i<len(string1) :\r\n\t\tif not invalid[i] and string1[i] == string2[j]:\r\n\t\t\tj+=1\r\n\t\tif j == len(string2):return True\r\n\t\ti+=1\r\n\treturn False\r\n\r\n\r\n\r\nl = 0\r\nans = 0\r\nh = len(arr)\r\nwhile l<=h:\r\n\tmid = l+(h-l)//2\r\n\tif check(mid):\r\n\t\tans = mid \r\n\t\tl = mid+1\r\n\telse:\r\n\t\th = mid -1\r\nprint(ans)", "t = list(input())\r\np = list(input())\r\n\r\n\r\ndef has_sub(temp):\r\n idx = 0\r\n for c in temp:\r\n if c == p[idx]:\r\n idx += 1\r\n if idx == len(p):\r\n return True\r\n\r\n return False\r\n\r\n\r\narr = list(map(int, input().split()))\r\n\r\nleft = 0\r\nright = len(arr) - 1\r\n\r\nwhile left < right:\r\n mid = (left + right + 1) // 2\r\n temp = t[:]\r\n\r\n for idx in range(mid):\r\n temp[arr[idx] - 1] = '0'\r\n\r\n if has_sub(temp):\r\n left = mid\r\n else:\r\n right = mid - 1\r\n\r\nprint(right)\r\n", "a=input()\r\nb=input()\r\nc=list(map(int,input().split()))\r\n\r\nl = 0 ; r = len(a)\r\nwhile r-l>1:\r\n m = (r + l) // 2\r\n d = list(a)\r\n j = 0\r\n for i in range(m):\r\n d[c[i]-1] = \"\"\r\n for i in range(len(a)):\r\n if d[i] == b[j]:\r\n j += 1\r\n if j == len(b):\r\n l = m\r\n break\r\n if j != len(b):\r\n r = m\r\nprint(l)", "s,t,p=input(),input(),list(map(int,input().split()))\r\nl,r,n,m=0,len(p),len(p),len(t)\r\nwhile l<=r:\r\n mid=(l+r)//2\r\n cur=[]\r\n st=set()\r\n for i in range(mid):\r\n st.add(p[i]-1)\r\n # print(st)\r\n # print(l,r,mid)\r\n idx=0\r\n for i in range(n):\r\n if i in st:continue\r\n if s[i]==t[idx]:\r\n idx+=1\r\n if idx==m:break\r\n if idx==m:l=mid+1\r\n else:r=mid-1\r\nprint(r)", "from math import inf\r\nfrom collections import *\r\nimport math, os, sys, heapq, bisect, random,threading\r\nfrom functools import *\r\nfrom itertools import *\r\ndef inp(): return sys.stdin.readline().rstrip(\"\\r\\n\")\r\ndef out(var): sys.stdout.write(str(var)) # for fast output, always take string\r\ndef inpu(): return int(inp())\r\ndef lis(): return list(map(int, inp().split()))\r\ndef stringlis(): return list(map(str, inp().split()))\r\ndef sep(): return map(int, inp().split())\r\ndef strsep(): return map(str, inp().split())\r\ndef fsep(): return map(float, inp().split())\r\nM,M1,Y,N=1000000007,998244353,\"Yes\",\"No\"\r\n\r\ndef main():\r\n how_much_noob_I_am = 1\r\n # how_much_noob_I_am = inpu()\r\n for _ in range(how_much_noob_I_am):\r\n s = inp()\r\n t = inp()\r\n arr = lis()\r\n lo = 1\r\n ans = 0\r\n hi = len(arr)\r\n while(lo<=hi):\r\n mid = (lo+hi)//2\r\n def check(mid):\r\n p=arr[:mid]\r\n ss = []\r\n vis = [False]*(len(arr)+1)\r\n for i in p:\r\n vis[i-1] = True\r\n for i in range(len(s)):\r\n if not vis[i]:\r\n ss.append(s[i])\r\n j = 0\r\n for i in range(len(ss)):\r\n if j<len(t) and ss[i]==t[j]:\r\n j+=1\r\n if j==len(t):\r\n return True\r\n return False\r\n if check(mid):\r\n lo = mid + 1\r\n ans = mid\r\n else:\r\n hi = mid - 1\r\n print(ans)\r\n\r\nif __name__ == '__main__':\r\n # sys.setrecursionlimit(5*(10**5)+50)\r\n # threading.stack_size(10**8)\r\n # threading.Thread(target=main).start()\r\n main()\r\n", "def subsequence(p, t, arr, m):\r\n s = []\r\n k = set()\r\n for i in range(m):\r\n k.add(arr[i])\r\n for i in range(len(p)):\r\n if (i + 1) not in k:\r\n s.append(p[i])\r\n x = len(s)\r\n y = len(t)\r\n i, j = 0, 0\r\n while i < y and j < x:\r\n if t[i] == s[j]:\r\n i += 1\r\n j += 1\r\n return i == y\r\n\r\n\r\np = input()\r\nt = input()\r\narr = list(map(int, input().split()))\r\nhi = len(p)\r\nlo = 0\r\nwhile lo < hi:\r\n m = (lo + hi + 1) // 2\r\n ans = subsequence(p, t, arr, m)\r\n if ans:\r\n lo = m\r\n else:\r\n hi = m - 1\r\nprint(lo)\r\n", "s = list(input())\r\nt = list(input())\r\narr = list(x-1 for x in map(int, input().split()))\r\nn, m = len(arr), len(t)\r\n\r\ndef binary_search():\r\n f, e = 0, n\r\n while f <= e:\r\n mid = f + e >> 1\r\n vis = [0] * n\r\n for i in range(mid):\r\n vis[arr[i]] = 1\r\n idx, found = 0, 0\r\n for i in range(n):\r\n if not vis[i] and s[i] == t[idx]:\r\n idx += 1\r\n if idx == m:\r\n found = 1\r\n break\r\n if found:\r\n f = mid + 1\r\n else:\r\n e = mid - 1\r\n return f - 1\r\n\r\nprint(binary_search())\r\n", "def can_form(mid, remove, t, p):\r\n j = 0\r\n for i in range(len(t)):\r\n if remove[i] <= mid:\r\n continue\r\n if j < len(p) and t[i] == p[j]:\r\n j += 1\r\n return j == len(p)\r\n\r\ndef solve():\r\n t = input().strip()\r\n p = input().strip()\r\n a = list(map(int, input().strip().split()))\r\n remove = [0]*len(t)\r\n for i in range(len(t)):\r\n remove[a[i]-1] = i+1\r\n low, high = 0, len(t)\r\n while low < high:\r\n mid = (low+high+1) // 2\r\n if can_form(mid, remove, t, p):\r\n low = mid\r\n else:\r\n high = mid - 1\r\n print(low)\r\n\r\nsolve()\r\n", "t = input()\r\np = input()\r\na = list(map(int, input().split()))\r\nl = 0\r\nr = len(t)\r\nwhile(r-l > 1):\r\n s = list(t)\r\n m = (r+l)//2\r\n for i in range(m):\r\n s[a[i]-1] = '0'\r\n q = 0\r\n for i in s:\r\n if q < len(p) and i == p[q]:\r\n q += 1\r\n if q == len(p):\r\n l = m\r\n else:\r\n r = m\r\nprint(l)", "sed = 257\r\nmod = int(1e9 + 7)\r\n\r\ndef judge(t, p):\r\n j = 0\r\n for ch in p:\r\n while j < len(t) and t[j] != ch: j += 1\r\n if j >= len(t): return False\r\n j += 1\r\n return True\r\n\r\ndef generate(t, a, n):\r\n res = list(t)\r\n for i in range(n):\r\n res[a[i] - 1] = '#'\r\n res = \"\".join(res)\r\n return res.replace('#', '')\r\n\r\nt = input()\r\np = input()\r\na = list(map(int, input().split()))\r\n\r\nl, r = 0, len(t) - len(p) + 1\r\n\r\nwhile l < r - 1:\r\n m = (l + r) // 2\r\n tmp = generate(t, a, m)\r\n # print('m:', m)\r\n # print('tmp:', tmp)\r\n if judge(tmp, p):\r\n l = m\r\n else: r = m \r\n\r\nprint(l)\r\n", "def is_obtained(p, t, K):\r\n i = 0\r\n for ch in p:\r\n i = t.find(ch, i) + 1\r\n if i == 0:\r\n return False\r\n while i in K:\r\n i = t.find(ch, i) + 1\r\n if i == 0:\r\n return False\r\n return True\r\n\r\nI = input\r\n\r\nt, p, A = I(), I(), list(map(int, I().split()))\r\nL, R = 0, len(A) - 1\r\n\r\nwhile L < R:\r\n x = (L + R + 1) // 2\r\n if is_obtained(p, t, set(A[:x])):\r\n L = x\r\n else:\r\n R = x - 1\r\n\r\nprint(L)", "import sys\r\nfrom array import array # noqa: F401\r\n\r\n\r\ndef input():\r\n return sys.stdin.buffer.readline().decode('utf-8')\r\n\r\n\r\ns = input().rstrip()\r\nt = input().rstrip()\r\nn, m = len(s), len(t)\r\np = tuple(map(lambda x: int(x) - 1, input().split()))\r\n\r\n\r\ndef solve(x):\r\n ok = array('b', [1]) * n\r\n for i in p[:x]:\r\n ok[i] = 0\r\n\r\n j = 0\r\n for i in range(n):\r\n if ok[i] and s[i] == t[j]:\r\n j += 1\r\n if j == m:\r\n return True\r\n return False\r\n\r\n\r\nok, ng = 0, n\r\nwhile abs(ok - ng) > 1:\r\n mid = (ok + ng) >> 1\r\n if solve(mid):\r\n ok = mid\r\n else:\r\n ng = mid\r\n\r\nprint(ok)\r\n", "def is_match(string_long, string_short):\n idx_long = 0\n for idx, value in enumerate(string_short):\n while idx_long < len(string_long) and string_long[idx_long] != value:\n idx_long += 1\n if idx_long == len(string_long):\n return False\n idx_long += 1\n \n return idx_long <= len(string_long)\n\n\ndef solve(string_before_delete, string_after_delete, deletes):\n deletes_at_step = list(range(len(deletes)))\n for idx, value in enumerate(deletes):\n deletes_at_step[value-1] = idx+1\n\n# print(deletes_at_step)\n left = 0 # is_match(0) == True\n right = len(deletes) # is_match(len) == False\n while left + 1 < right:\n mid = (left + right + 1) // 2\n string_mid = ''.join([value for idx,value in enumerate(string_before_delete) if deletes_at_step[idx] > mid])\n if is_match(string_mid, string_after_delete):\n left = mid\n# print(mid, True)\n# input()\n else:\n right = mid\n# print(mid, False)\n# input()\n return left\n \n\nif __name__ == '__main__':\n# print(solve('ababcba', 'abb', [5,3,4,1,7,6,2]))\n# print(solve('bbbabb', 'bb', [1,6,3,4,2,5]))\n string_before_delete = input().strip()\n string_after_delete = input().strip()\n deletes = list(map(int, input().strip().split(' ')))\n print(solve(string_before_delete, string_after_delete, deletes))\n# print(is_match('abcdefg', 'abcdefg'))\n# print(is_match('abcdefg', 'a'))\n# print(is_match('abcdefg', 'g'))\n# print(is_match('abcdefg', 'ga'))\n# print(is_match('aa', 'a'))\n# print(is_match('aaaa', 'aaaa'))\n\n", "# by xorio\n\nimport sys\n\ninp = input() # input word\ntar = input() # target word\nseq = list(map(int, input().split())) # sequence\n\nl_inp = len(inp)\nl_tar = len(tar)\n\n# print(inp)\n# print(tar)\n# print(seq)\n\n\n# tests, if sequence up to m is valid\ndef check_for_m(m):\n banned = set(seq[:m]) # set of the indexes in seq up to point m, the chars that are banned\n # print(\"Banned\", banned)\n ip = 0\n for i in range(l_inp):\n # print('-', i, ip, (i + 1) in banned)\n if not (i + 1) in banned:\n if inp[i] == tar[ip]:\n # print(inp[i], i, ip)\n ip += 1\n if ip == l_tar:\n return True\n return False\n\n\nl = 0\nr = l_inp + 1\n# Binary search until pointers overlap\nwhile l + 1 < r:\n m = (l + r) // 2 # middle\n # print(l, r, m, check_for_m(m))\n if check_for_m(m):\n l = m\n else:\n r = m\n\nprint(l)\n", "t = [char for char in input()]\r\np = [char for char in input()]\r\na = tuple(map(int, input().split()))\r\ndef inside(t, p):\r\n\tpointer1, pointer2 = (0,0)\r\n\twhile pointer1 < len(t) and pointer2 < len(p):\r\n\t\tif t[pointer1] != p[pointer2]: pointer1 += 1\r\n\t\telse: pointer1, pointer2 = pointer1+1, pointer2+1\r\n\tif pointer2 == len(p): return True\r\n\telse: return False\r\ndef remove(removalarray, arr):\r\n\ttemp = t[:]\r\n\tfor i in removalarray: temp[i-1] = 0\r\n\tnew = []\r\n\tfor i in temp: \r\n\t if i != 0: new += [i]\r\n\treturn new\r\nleft, right = 0, len(t)-1\r\nwhile left != right:\r\n\tmid = (left+right)//2\r\n\tif inside(remove(a[:mid+1],t), p): left = mid+1\r\n\telse: right = mid\r\nprint(left)", "def isSubSequence(str1,str2,m,n): \r\n \r\n j = 0 # Index of str1 \r\n i = 0 # Index of str2 \r\n \r\n # Traverse both str1 and str2 \r\n # Compare current character of str2 with \r\n # first unmatched character of str1 \r\n # If matched, then move ahead in str1 \r\n \r\n while j<m and i<n: \r\n if str1[j] == str2[i]: \r\n j = j+1 \r\n i = i + 1\r\n \r\n # If all characters of str1 matched, then j is equal to m \r\n return j==m\r\n \r\nt=list(input())\r\np=input()\r\na=list(map(int,input().split()))\r\ndef check(x):\r\n count=0\r\n y=t.copy()\r\n for i in range(x):\r\n y[a[i]-1]=''\r\n b=''.join(y)\r\n return isSubSequence(p,b,len(p),len(b))\r\nl=0\r\nr=len(t)\r\nm=(l+r)//2\r\nwhile r-l>1:\r\n if check(m):\r\n l=m\r\n else:\r\n r=m\r\n m=(r+l)//2\r\nprint(m) \r\n \r\n \r\n ", "\r\n\r\ns=str(input())\r\nt=str(input())\r\nl=list(map(int, input().split()))\r\nans=0\r\ni=0\r\nj=len(l)-1 \r\nwhile i<=j:\r\n m=(i+j)//2\r\n dp={}\r\n for x in range(m):\r\n dp[l[x]-1]=1 \r\n tt=0 \r\n for x in range(len(s)):\r\n if x in dp:\r\n continue\r\n if s[x]==t[tt]:\r\n tt+=1\r\n if tt==len(t):\r\n break \r\n if tt==len(t):\r\n ans=m \r\n i=m+1 \r\n else:\r\n j=m-1 \r\nprint(ans)\r\n ", "t = input()\r\np = input()\r\na = list(map(int, input().split()))\r\nused = [0] * len(t)\r\nl = 0\r\nr = len(a) + 1\r\nwhile r - l > 1:\r\n mid = (r + l) // 2\r\n for i in range(mid):\r\n used[a[i] - 1] = 1\r\n cur = 0\r\n for i in range(len(t)):\r\n if cur < len(p) and not used[i] and t[i] == p[cur]:\r\n cur += 1\r\n if cur == len(p):\r\n l = mid\r\n else:\r\n r = mid\r\n used = [0] * len(t)\r\nprint(l)# 1699573935.6380918", "# https://codeforces.com/problemset/problem/778/A\r\n\r\nimport sys\r\nfrom typing import List\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef solve(t: str, p: str, a: List[int]) -> int:\r\n def verify(pivot: int) -> bool:\r\n pass\r\n j = 0\r\n a_set = set(a[:pivot])\r\n for i in range(lt):\r\n if t[i] == p[j] and i not in a_set:\r\n j += 1\r\n if j == lp:\r\n return True\r\n return False\r\n\r\n a = [e - 1 for e in a]\r\n lt, lp = len(t), len(p)\r\n lo, hi = 0, len(a)\r\n r = None\r\n while lo <= hi:\r\n pivot = (lo + hi) // 2\r\n if verify(pivot):\r\n r = pivot\r\n lo = pivot + 1\r\n else:\r\n hi = pivot - 1\r\n\r\n return r\r\n\r\n\r\nt = input().strip()\r\np = input().strip()\r\na = list(map(int, input().strip().split()))\r\n\r\nr = solve(t, p, a)\r\nprint(r)\r\n", "t = list(input())\r\np = list(input())\r\nlis = list(map(int,input().split()))\r\npp=len(p)\r\ntt=len(t)\r\nl=0\r\nr=tt\r\nwhile l<=r:\r\n mid = l +(r-l)//2\r\n tep=t[:]\r\n for i in range(mid):\r\n tep[lis[i]-1]='#'\r\n j=i=0\r\n while i<tt and j<pp:\r\n if tep[i]==p[j]:\r\n j+=1\r\n i+=1\r\n# print(l,r,pp,j) \r\n if j<pp:\r\n r=mid-1\r\n else:\r\n l=mid+1\r\nprint(r) \r\n\r\n\r\n\r\n\r\n", "s1 = input()\r\ns2 = input()\r\nrs = list(map(int, input().split()))\r\n\r\ndef is_in(big, little):\r\n i, j = 0, 0\r\n matched = 0\r\n while i < len(big) and j < len(little):\r\n if big[i] == little[j]:\r\n matched += 1\r\n i +=1\r\n j += 1\r\n else:\r\n i += 1\r\n if matched < len(little):\r\n return False\r\n return True\r\n\r\ndef gen_st(mid):\r\n global s1, s2, rs\r\n cs = set(rs[:mid])\r\n n = []\r\n for i in range(len(s1)):\r\n if i+1 in cs:\r\n continue\r\n n.append(s1[i])\r\n #print(''.join(n), s2)\r\n return is_in(''.join(n), s2)\r\n\r\nstart = 0\r\nend = len(rs)\r\nweird = False\r\n#print(gen_st(4))\r\nwhile start < end:\r\n #print(start, end)\r\n mid = (start+end)//2\r\n if gen_st(mid):\r\n start = mid\r\n if start == end-1:\r\n weird = True\r\n if gen_st(end):\r\n print(end)\r\n break\r\n else:\r\n print(start)\r\n break\r\n else:\r\n end = mid - 1\r\n if not weird and start == end:\r\n print(start)\r\n\r\n", "t = input()\r\np = input()\r\narr = [int(i) - 1 for i in input().split(\" \")]\r\n\r\n\r\ndef is_sub_sequence(str1, arr2):\r\n m = len(str1)\r\n n = len(arr2)\r\n j = 0\r\n i = 0\r\n while j < m and i < n:\r\n if str1[j] == arr2[i]:\r\n j = j + 1\r\n i = i + 1\r\n return j == m\r\n\r\n\r\ndef check(x):\r\n sub_s = []\r\n r2 = set(arr[:x])\r\n for i in range(len(t)):\r\n if i in r2:\r\n continue\r\n sub_s.append(t[i])\r\n return is_sub_sequence(p, sub_s)\r\n\r\n\r\ndef main():\r\n l = 0\r\n r = len(arr) - 1\r\n while l < r:\r\n mid = (l + r + 1) // 2\r\n if check(mid):\r\n l = mid\r\n else:\r\n r = mid - 1\r\n print(l)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import sys\r\n\r\n# sys.stdin = open('./../input.txt', 'r')\r\nI = lambda: int(input())\r\nMI = lambda: map(int, input().split())\r\nLI = lambda: list(map(int, input().split()))\r\n\r\nt = input()\r\np = input()\r\na = LI()\r\n\r\nn = len(t)\r\n\r\n\r\ndef check(mid):\r\n j = 0\r\n s = [''] * n\r\n for x in range(mid, n):\r\n i = a[x] - 1\r\n s[i] = t[i]\r\n for i in range(n):\r\n if s[i] == p[j]:\r\n j += 1\r\n if j == len(p):\r\n return True\r\n return False\r\n\r\n\r\nans = 0\r\nl, r = 0, n\r\nwhile l <= r:\r\n mid = (l + r) // 2\r\n if check(mid):\r\n ans = mid\r\n l = mid + 1\r\n else:\r\n r = mid - 1\r\n\r\nprint(ans)\r\n", "s = input()\r\nt = input()\r\na = list(map(int, input().split()))\r\n\r\ndef ok(n):\r\n bad = set()\r\n for i in range(n):\r\n bad.add(a[i] - 1)\r\n pt = 0\r\n ps = 0 \r\n while pt < len(t) and ps < len(s):\r\n if ps in bad:\r\n ps += 1\r\n else:\r\n if t[pt] == s[ps]:\r\n ps += 1\r\n pt += 1\r\n else:\r\n ps += 1\r\n return pt == len(t)\r\n\r\nlow = 0\r\nhigh = len(s)\r\nwhile high >= low:\r\n mid = (high + low) // 2\r\n if (ok(mid)):\r\n poss = mid\r\n low = mid + 1\r\n else:\r\n high = mid - 1\r\nprint (poss)\r\n\r\n\r\n", "s1=(input())\r\ns2=input()\r\nindex=list(map(int,input().split()))\r\nfor i in range(len(index)):\r\n index[i]-=1\r\nL=0\r\nR=len(s1)-1\r\nans=0\r\nwhile L<=R:\r\n mid=(L+R)//2\r\n s=list(s1)\r\n for i in range(mid+1):\r\n s[index[i]]=''\r\n ss1=0\r\n ss2=0 \r\n while ss1<len(s1) and ss2< len(s2): \r\n if s[ss1]==s2[ss2]:\r\n ss2+=1\r\n ss1+=1\r\n if ss2==len(s2):\r\n L=mid+1\r\n else:\r\n R=mid-1\r\n ans=mid\r\nprint(ans)", "s = input()\r\np = input()\r\na = list(map(int, input().split()))\r\na_inds = [0] * (len(s) + 1)\r\nfor i in range(len(a)):\r\n a_inds[a[i]] = i\r\n\r\nl = -1\r\nr = len(s)\r\n\r\n\r\ndef check_answer(ans):\r\n i = 0\r\n j = 0\r\n while i < len(s) and j < len(p):\r\n if a_inds[i + 1] >= ans and s[i] == p[j]:\r\n j += 1\r\n i += 1\r\n\r\n return j == len(p)\r\n\r\n\r\nwhile l < r - 1:\r\n m = (l + r) // 2\r\n if check_answer(m):\r\n l = m\r\n else:\r\n r = m\r\n\r\nprint(r - 1)\r\n", "# D. String Game\r\n\r\nt = input()\r\np = input()\r\na = [int(v) for v in input().split()]\r\nlt = len(t)\r\nlp = len(p)\r\n\r\ndef isValid(pos):\r\n flags = [0] * lt\r\n for i in range(pos+1):\r\n flags[a[i]-1] = 1\r\n count = 0\r\n for i in range(lt):\r\n if flags[i] == 0 and t[i] == p[count]:\r\n count += 1\r\n if count == lp:\r\n return True\r\n return False\r\n\r\nleft = 0\r\nright = lt-1\r\nans = -1\r\nwhile left <= right:\r\n mid = (left + right)//2\r\n if isValid(mid):\r\n ans = mid\r\n left = mid + 1\r\n else:\r\n right = mid -1\r\n\r\nprint(ans+1)", "def pred(s1, s2, arr, mid):\r\n\tn = len(s1);\r\n\tm = len(s2);\r\n\tmarked = [0 for x in range(n)];\r\n\tfor i in range(mid+1):\r\n\t\tmarked[arr[i]-1] = 1;\r\n\ti = 0; j = 0;\r\n\twhile (i < n and j < m):\r\n\t\tif (not marked[i] and s1[i] == s2[j]):\r\n\t\t\tj += 1;\r\n\t\ti += 1;\r\n\treturn (j != m);\r\n\r\ns1 = input();\r\ns2 = input();\r\narr = [int(x) for x in input().split(' ')];\r\nn = len(arr);\r\nl = 0; r = n-1;\r\nwhile (l < r):\r\n\tmid = l + (r-l)//2;\r\n\tif (pred(s1, s2, arr, mid)):\r\n\t\tr = mid;\r\n\telse:\r\n\t\tl = mid+1;\r\nprint(l);", "def cal(p,s):\r\n m,n,i,j=len(p),len(s),0,0\r\n while j<m and i<n:\r\n if p[j]==s[i]:\r\n j+=1\r\n i+=1\r\n if j==m:\r\n return True\r\n return False\r\n \r\ndef possible(m,a,t,p):\r\n q,r=[],set()\r\n for i in a[:m]:\r\n r.add(i)\r\n for i in range(len(t)):\r\n if i not in r:\r\n q.append(t[i])\r\n s=(\"\").join(q)\r\n return cal(p,s)\r\n \r\nt=input()\r\np=input()\r\na=list(map(int,input().split()))\r\nn=len(a)\r\nfor i in range(n):\r\n a[i]-=1\r\nl,r=0,n-1\r\nwhile l<r:\r\n mid=(l+r+1)//2\r\n if possible(mid,a,t,p):\r\n l=mid\r\n else:\r\n r=mid-1\r\nprint(l)", "s = (input())\r\np = (input())\r\na = [i-1 for i in list(map(int,input().split()))]\r\nleft = 0\r\nright = len(s)\r\nwhile right - left > 1:\r\n d = list(s)\r\n mid = int((left + right)/2)\r\n for i in range(mid):\r\n d[a[i]] = ''\r\n j = 0\r\n for i in range(len(s)):\r\n if p[j] == d[i]:\r\n j += 1\r\n if j == len(p):\r\n left = mid\r\n break\r\n if j != len(p):\r\n right = mid\r\nprint (left)\r\n", "t=input()\np=input()\nn=len(t)\nm=len(p)\na=[int(i) for i in input().split()]\nl=0\nr=n-1\nwhile(l<r):\n mid=(r+l)//2\n f=[0]*n\n for i in range(mid+1):\n f[a[i]-1]=1\n c=0\n for i in range(n):\n if(f[i]==0 and t[i]==p[c]):\n c+=1\n if(c==m):\n break\n if(c==m):\n l=mid+1\n else:\n r=mid\nprint(l)\n \t\t \t \t \t \t\t\t \t \t\t\t\t\t \t \t\t", "def possible(mid,lis,s,a):\r\n visited = [0]*len(s)\r\n for i in range(mid):\r\n visited[lis[i]-1]=1\r\n ind = 0\r\n for i in range(len(s)):\r\n if(visited[i]==0 and ind<len(a) and a[ind]==s[i]):\r\n ind+=1\r\n return ind==len(a)\r\ns = input()\r\na = input()\r\nlis = list(map(int,input().split()))\r\nl = 0\r\nr = len(s)-1\r\nans = -1\r\nwhile(l<=r):\r\n mid = (l+r)//2\r\n if(possible(mid,lis,s,a)):\r\n ans = mid\r\n l = mid+1\r\n else:\r\n r = mid-1\r\nprint(ans)", "t = list(input())\r\nn = len(t)\r\np = input()\r\nl = list(map(int, input().split()))\r\nfor i in range(n):\r\n l[i] -= 1\r\n\r\ndef check(m):\r\n s = t.copy()\r\n for i in range(m):\r\n s[l[i]] = ' '\r\n j = 0\r\n for c in p:\r\n while j<n and s[j] != c:\r\n j += 1\r\n if j==n:\r\n return False\r\n j += 1\r\n return True\r\n\r\nlo = 0\r\nhi = n+1\r\nwhile(lo<hi-1):\r\n mid = lo + (hi-lo)//2\r\n if(check(mid)):\r\n lo = mid\r\n else:\r\n hi = mid\r\nprint(lo)", "s = list(input().strip())\r\nt = input().strip()\r\nsq = [int(a) for a in input().strip().split()]\r\nl = len(s)\r\nlt = len(t)\r\ndef check(x):\r\n tmp = s.copy()\r\n for i in range(x):\r\n tmp[sq[i]-1] = '_'\r\n idx = 0\r\n for i in range(l):\r\n if tmp[i]==t[idx]:\r\n idx+=1\r\n if idx==lt:\r\n return True\r\n return False\r\n\r\nlow = res = 0\r\nhigh = l\r\nwhile(low<=high):\r\n mid = (low + high) >> 1\r\n if check(mid):\r\n low = mid + 1\r\n res = mid\r\n else:\r\n high = mid - 1\r\nprint(res)", "t = input()\np = input()\n\na = map(int, input().strip().split())\na = [ x - 1 for x in a]\nn = len(t)\nm = len(p)\n\n\nlo = 0\nhi = n - 1\n\nwhile lo < hi:\n mid = (lo + hi) >> 1\n \n temp = list(t)\n for x in a[ :mid+1]:\n temp[x] = '_'\n \n ptr, curr = 0, 0\n while ptr < n and curr < m:\n while ptr < n and temp[ptr] != p[curr]:\n ptr += 1\n if ptr < n:\n ptr += 1\n curr += 1\n \n if curr == m:\n lo = mid + 1\n else:\n hi = mid\n\nprint(lo)\n", "import sys\ndef input():\n return sys.stdin.readline().strip()\n# def print(a):\n# sys.stdout.write(str(a)+\"\\n\")\narr=[]\ndef solve(k,word,key):\n # print(\"calle with \",k)\n s=set()\n for i in range(k):\n s.add(arr[i])\n j=0\n for i in range(len(word)):\n if i+1 not in s:\n if word[i]==key[j]:\n j+=1 \n if j==len(key):\n break \n # print(\"j is \",j,key)\n return j==len(key)\nword=input()\nkey=input()\narr=[int(x) for x in input().split()]\nl=0\nr=len(word)-len(key)\nans=0\nwhile l<=r:\n m=(r-l)//2 + l \n if solve(m,word,key):\n ans=m \n l=m+1 \n else:\n r=m-1 \nprint(ans)\n\n\n \n \n \n\n \t\t\t\t\t\t\t\t \t\t \t\t \t\t\t \t \t\t \t", "def binary_search(lis,l,r,txt,txt2):\r\n if r>=l:\r\n mid = l + (r-l)//2\r\n templis = lis[0:mid+1]\r\n if is_sub(txt,txt2,templis):\r\n return binary_search(lis,mid+1,r,txt1,txt2)\r\n else:\r\n return binary_search(lis,l,mid-1,txt1,txt2)\r\n else:\r\n return l-1\r\n \r\ndef remove(txt,index):\r\n index = index-1\r\n try:\r\n return txt[0:index]+txt[index+1:]\r\n except IndexError:\r\n return txt[0:index]\r\n\r\ndef is_sub(txt,txts,limit):\r\n s = set(limit)\r\n cur = 0\r\n for i in range(len(txt)):\r\n if txt[i] == txts[cur] and (i+1) not in s:\r\n cur += 1\r\n if cur == len(txts):\r\n return True\r\n return False\r\n\r\ntxt1 = input()\r\ntxt2 = input()\r\nlis = [int(x) for x in input().split()]\r\nprint(binary_search(lis,0,len(lis)-1,txt1,txt2)+1)\r\n\r\n", "s=input()\r\nt=input()\r\narr=list(map(int,input().split()))\r\nl=0\r\nr=len(arr)-len(t)\r\nwhile l<=r:\r\n mid=(l+r)//2\r\n var=[0]*len(arr)\r\n for i in range(mid):\r\n var[arr[i]-1]=1\r\n f=0\r\n for i in range(len(s)):\r\n if var[i]:\r\n continue\r\n if f==len(t):\r\n break\r\n if s[i]==t[f]:\r\n f+=1\r\n if f==len(t):\r\n cnt=mid\r\n l=mid+1\r\n else:\r\n r=mid-1\r\n\r\nprint(cnt)", "a=input()\r\nb=input()\r\nc=[i-1 for i in list(map(int,input().split()))]\r\nl=0\r\nr=len(a)\r\nwhile r-l>1 :\r\n m=l+(r-l)//2#two pointer\r\n d=list(a)\r\n j=0\r\n for o in range(m):#first half delete value replace with \"\"\r\n d[c[o]]=\"\"\r\n for i in range(int(len(a))):\r\n if(d[i]==b[j]):\r\n j+=1\r\n if(j==len(b)):\r\n l=m\r\n break\r\n if(j!=len(b)):r=m\r\n\r\nprint(l)\r\n", "import sys\r\n\r\ndef bits(n: int):\r\n return list(bin(n)).count('1')\r\n\r\ndef main(test_case = False):\r\n n = int(input()) if test_case else 1\r\n for _ in range(n):\r\n test()\r\n\r\ndef flush():\r\n sys.stdout.flush()\r\n\r\ndef parr(arr):\r\n print(*arr, sep=' ')\r\n\r\ndef gcd(a, b):\r\n while b:\r\n if b % a == 0:\r\n break\r\n tmp = a\r\n a = b % a\r\n b = tmp\r\n return a\r\n\r\nt = ''\r\np = ''\r\na = []\r\nstep = 0\r\nmark = []\r\n\r\ndef ok(s):\r\n global p\r\n t = s\r\n i = 0\r\n j = 0\r\n n = len(t)\r\n m = len(p)\r\n while i < n:\r\n if t[i] == p[j]:\r\n j += 1\r\n i += 1\r\n if j == m:\r\n return True\r\n return False\r\n\r\ndef fun(index):\r\n global step\r\n global t\r\n r = ''\r\n step += 1\r\n # print(a)\r\n for i in range(index + 1):\r\n # print(i)\r\n mark[a[i]-1] = step\r\n \r\n n = len(t)\r\n for i in range(n):\r\n if mark[i] == step:\r\n continue\r\n else:\r\n r += t[i]\r\n return r\r\n\r\n\r\n\r\ndef test():\r\n global t\r\n global p\r\n global a\r\n global mark\r\n\r\n \r\n\r\n t = input()\r\n p = input()\r\n a = list(map(int, input().split()))\r\n\r\n # t = 'ababcba'\r\n # p = 'abb'\r\n # a = [5, 3, 4, 1]\r\n\r\n n = len(t)\r\n mark = [0] * n\r\n\r\n # print(ok(fun(2)))\r\n # print(fun(1))\r\n\r\n # exit()\r\n\r\n\r\n left = 0\r\n right = n - 1\r\n ans = 0\r\n\r\n while left <= right:\r\n mid = (left + right) // 2\r\n if ok(fun(mid)):\r\n ans = mid + 1\r\n left = mid + 1\r\n else:\r\n right = mid - 1\r\n \r\n print(ans)\r\n\r\nmain(False)", "from sys import stdin\r\ninput=stdin.readline\r\ndef check(s,t,l,mid):\r\n # print(l[:mid],mid,t)\r\n for i in l[:mid]:\r\n s[i]=\"\"\r\n ptr=0\r\n for i in s:\r\n if len(t)==ptr:\r\n return True\r\n if i==t[ptr]:\r\n ptr+=1\r\n if len(t)==ptr:\r\n return True\r\n return False\r\ndef f(l,s,t):\r\n hi=len(l)\r\n lo=0\r\n res=None\r\n while lo<=hi:\r\n mid=(lo+hi)//2\r\n if check(s.copy(),t.copy(),l,mid):\r\n lo=mid+1\r\n res=mid\r\n else:\r\n hi=mid-1\r\n return res\r\ns=list(input().strip())\r\nt=list(input().strip())\r\nl=list(map(lambda s:int(s)-1,input().strip().split()))\r\nprint(f(l,s,t))\r\n", " \r\nt = input()\r\np = input()\r\na = [i-1 for i in list(map(int,input().split()))]\r\nmin1 = 0\r\nmax1 = len(t)\r\nwhile(max1-min1)>1:\r\n med = min1+(max1-min1)//2\r\n j=0\r\n d=list(t)\r\n for i in range(med):\r\n d[a[i]]=''\r\n for i in range(len(t)):\r\n if d[i]==p[j]:\r\n j+=1\r\n if j==len(p):\r\n min1=med\r\n break\r\n if j!=len(p):\r\n max1=med\r\nprint(min1)\r\n", "from typing import *\r\nfrom math import *\r\nfrom functools import lru_cache,cache\r\nfrom queue import PriorityQueue,Queue\r\nimport sys\r\n# by hangpengjie\r\n\r\ndef I():\r\n return input()\r\n\r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n\r\n# slove question\r\ndef slove()->None:\r\n t = I()\r\n p = I()\r\n a = LII()\r\n n = len(a)\r\n k = len(p)\r\n l = 0\r\n r = n\r\n while l < r:\r\n m = (l + r + 1) >> 1\r\n s = set([a[i]-1 for i in range(m)])\r\n i = 0\r\n j = 0\r\n while i < n and j < k:\r\n if i in s:\r\n i += 1\r\n continue\r\n if t[i] == p[j]:\r\n j += 1\r\n i += 1\r\n if j == k:\r\n l = m\r\n else:\r\n r = m - 1\r\n print(l)\r\n\r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n \r\ndef __main__():\r\n T = 1\r\n while T:\r\n T -= 1\r\n slove()\r\n\r\nif __name__ == '__main__':\r\n __main__()\r\n", "a = input()\r\nb = input()\r\nc = [i-1 for i in list(map(int,input().split()))]\r\nl = 0\r\nr = len(a)\r\nwhile r-l>1:\r\n m = l + (r-l) // 2\r\n d = list(a)\r\n j = 0\r\n for i in range(m):d[c[i]] = ''\r\n for i in range(len(a)):\r\n if d[i]==b[j]:\r\n j += 1\r\n if j == len(b):\r\n l = m\r\n break\r\n if j!=len(b):\r\n r = m\r\nprint(l)\r\n", "import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\n\ndef find(mid):\n global S,T,A,N,M\n k = []\n for i in range(1,mid+1):\n k.append(A[-i]-1)\n k.sort()\n\n x = 0\n for i in range(len(k)):\n if x==M:break\n if S[k[i]]==T[x]:x+=1\n if x==M:\n return True\n return False\n\nS = input()\nT = input()\nN,M = len(S),len(T)\nA = list(map(int,input().split()))\n\nl,r = 0,N+1\nwhile l<r:\n mid = (l+r)//2\n if find(mid):\n r = mid\n else:\n l = mid+1\nprint(N-l)", "def check(remove_indices):\r\n removed = set(remove_indices)\r\n ti, pi = 0, 0\r\n while ti < len(m) and pi < len(n):\r\n if ti not in removed and m[ti] == n[pi]:\r\n pi += 1\r\n ti += 1\r\n return pi == len(n)\r\n\r\n\r\n# t = int(input())\r\n# for _ in range(t):\r\nm = input()\r\nn = input()\r\na = list(map(int, input().split()))\r\na = [x - 1 for x in a]\r\nl, r = 0, len(a)\r\nwhile l < r:\r\n mid = (l + r) // 2\r\n if check(a[:mid]):\r\n l = mid + 1\r\n else:\r\n r = mid\r\nprint(r - 1)", "\r\n\r\ndef check(s,t):\r\n j=0\r\n for i in s:\r\n if i == t[j]:\r\n j+=1\r\n if j == len(t):\r\n return True\r\n #print (j)\r\n return False\r\n\r\n\r\ndef cut(list,index,s):\r\n r=s.copy()\r\n for i in range (0,index+1):\r\n r[list[i]-1]='0'\r\n #print(r)\r\n return r\r\n\r\ndef binary(list,s,t):\r\n l=0\r\n r= len(s)-1\r\n while(l<r):\r\n mid=int(l+(r-l+1)/2)\r\n #print(l,r)\r\n ans = check(cut(list,mid,s),t)\r\n #print(ans)\r\n if ans ==False:\r\n r= mid-1\r\n else:\r\n l=mid\r\n return l\r\n\r\ns= input()\r\ns=list(s)\r\nt = input()\r\nlist=[int(item) for item in input().split()]\r\nans = binary(list,s,t)\r\nif(check(cut(list,ans,s),t)):\r\n print(ans+1)\r\nelse :\r\n print(ans)", "a=input()\nb=input()\narr=list(map(int,input().split()))\nstart=0\nend=len(arr)-len(b)\nla=len(a)\nlb=len(b)\nwhile(start<=end):\n mid=(start+end)//2\n temp=[0]*len(arr)\n for i in range(mid):\n temp[arr[i]-1]=1\n temp2=0\n for i in range(la):\n if temp[i]:\n continue\n if (temp2==lb):\n break\n if(a[i]==b[temp2]):\n temp2+=1\n if temp2==lb:\n ans=mid\n start=mid+1\n else:\n end=mid-1\nprint(ans)\n\t\t \t \t \t \t \t \t \t\t \t\t\t\t\t", "\ndef good(t, p, b, k):\n j = 0\n for i in range(len(t)):\n if b[i] >= k and t[i] == p[j]:\n j += 1\n if j == len(p):\n return True\n return False\n\n\ndef solve(t, p, a):\n b = [0] * len(a)\n for i in range(len(a)):\n b[a[i] - 1] = i\n low = 0\n high = len(a)\n while low + 1 < high:\n mid = (low + high) // 2\n if good(t, p, b, mid):\n low = mid\n else:\n high = mid\n return low\n\n\nt = input()\np = input()\na = list(map(int, input().split()))\nprint(solve(t, p, a))", "def findPossible(str1, str2):\n\t#sortedIndex = sorted(index)\n\tstr1length = len(str1)\n\tstr2length = len(str2)\n\tstr1Flag = 0\n\tstr2Flag = 0\n\n\tfor x in range(0,str1length):\n\t\tif str1[x] == str2[str2Flag]:\n\t\t\tstr2Flag += 1\n\t\tif str2Flag == str2length:\n\t\t\treturn True\n\n\treturn False\n\ndef delChr(oldStr, permutation, flag):\n\t#print(\"oldStr, \", oldStr)\n\tnewStr = list(oldStr)\n\t#print(\"newStr, \", newStr, \"Flag, \", flag)\n\tsubPer = permutation[0:flag]\n\tsubPer.sort(reverse=True)\n\t#print(type(subPer), subPer)\n\n\tfor x in range(0,flag):\n\t\t#print(\"del index:\", subPer[x])\n\t\tnewStr.pop(subPer[x]-1)\n\t\t#print(\"after, \", newStr)\n\t#print(\"aftr\", newStr, str(newStr))\n\treturn newStr\n\t\"\"\"\n\tnewPermutation = []\n\tfor x in range(0, flag):\n\t\t#print(\"HI\", x)\n\t\tnewPermutation.append(permutation[x])\n\tnewPermutation.sort()\n\t#print(\"new: \", newPermutation, oldStr, flag)\n\tnewStr = \"\"\n\toldStrLen = len(oldStr)\n\tnewPerLen = len(newPermutation)\n\tt = 0\n\n\tfor x in range(0, oldStrLen):\n\t\t#print(x, newStr, t)\n\t\tif t != newPerLen and x+1 == newPermutation[t]:\n\t\t\tt += 1\n\t\telse:\n\t\t\tnewStr += str(oldStr[x])\n\t#print(\"newStr: \", newStr, \"\\n\")\n\treturn newStr\n\t\"\"\"\n\ndef check_middle(m, permutation, input, target):\n\tbanned_set = set(permutation[:m])\n\ttarget_len = len(target)\n\ttarget_pointer = 0\n\t#print(\"banned_set, \", banned_set)\n\n\tinput_len = len(input)\n\tfor x in range(input_len):\n\t\tif not (x+1 in banned_set):\n\t\t\tif input[x] == target[target_pointer]:\n\t\t\t\ttarget_pointer += 1\n\t\t\tif target_pointer == target_len:\n\t\t\t\t#print(\"True\")\n\t\t\t\treturn True\n\t#print(\"False\")\n\treturn False\n\ns1 = list(input())\ns2 = list(input())\npermutation = list(map(int, input().split()))\n\n#print(\"type\", type(s1), type(s2))\nflag = 0\n\n\n#print(s1, s2, permutation, flag)\nnewStr = s1\n#print(\"start, \", newStr, s2, flag)\n#print(findPossible(\"bba\", \"abb\"))\nleft = 0\nright = len(s1)\n\n\nwhile left+1 < right:\n\n\tm = (left + right) // 2\n\n\t#print(\"lala, \", left, m, right)\n\tif check_middle(m, permutation, s1 ,s2):\n\t\tleft = m\n\t\tpass\n\telse:\n\t\tright = m\n\nprint(left)\n\n\"\"\"\nwhile findPossible(newStr, s2):\n\tflag += 1\n\tnewStr = delChr(s1, permutation, flag)\n\t\n\t#print(\"In, \", newStr, s2, flag)\n\nprint(flag-1)\n\"\"\"", "# Wadea #\r\n\r\ns = list(input())\r\nt = list(input())\r\na = list(map(int,input().split()))\r\nfor v in range(len(a)):\r\n a[v] -= 1\r\nn = len(s)\r\nm = len(t)\r\ntake = [False] * 200000\r\ndef check(mid):\r\n for k in range(n):\r\n take[k] = False\r\n for l in range(mid+1):\r\n take[a[l]] = True\r\n q,w = 0,0\r\n while q < n:\r\n if take[q]:\r\n q += 1\r\n continue\r\n if s[q] == t[w]:\r\n q += 1\r\n w += 1\r\n else:\r\n q += 1\r\n if w == m:\r\n return True\r\n return False\r\n \r\nl = 0;r = n-1;ans = -1\r\nwhile l <= r:\r\n mid = int((l+r)/2)\r\n if check(mid):\r\n l = mid + 1\r\n ans = mid\r\n else:\r\n r = mid - 1\r\nprint(ans+1)\r\n ", "s = input()\r\nt = input()\r\na = [int(x) - 1 for x in input().split()]\r\n\r\ndef ok(n):\r\n bad = set(a[:n])\r\n it = (a for i, a in enumerate(s) if i not in bad)\r\n return all(c in it for c in t)\r\n\r\nlow = 0\r\nhigh = len(s)\r\nwhile low <= high:\r\n mid = (high + low) // 2\r\n if (ok(mid)):\r\n low = mid + 1\r\n poss = mid\r\n else:\r\n high = mid - 1\r\nprint (poss)\r\n", "t = input()\r\np = input()\r\narr = [int(i)-1 for i in input().split(\" \")]\r\ndef isSubSequence(str1, str2):\r\n m = len(str1)\r\n n = len(str2)\r\n j = 0 \r\n i = 0 \r\n while j < m and i < n:\r\n if str1[j] == str2[i]:\r\n j = j+1\r\n i = i + 1\r\n return j == m\r\n\r\ndef check(x):\r\n ss = \"\"\r\n r2 = set(arr[:x])\r\n for i in range(len(t)):\r\n if i in r2:\r\n continue\r\n ss += t[i]\r\n return isSubSequence(p, ss)\r\n\r\nl, h = 0, len(arr)-1\r\nwhile l < h:\r\n mid = (l+h+1) // 2\r\n if check(mid):\r\n l = mid\r\n else:\r\n h = mid - 1\r\nprint(l)", "def check(tt,p): #Two Pointers \r\n\ti,j=0,0\r\n\twhile(i<len(t)):\r\n\t\tif tt[i]==p[j]:\r\n\t\t\tj+=1\r\n\t\ti+=1\r\n\t\tif j==len(p):\r\n\t\t\tbreak\r\n\tif j==len(p):return 1\r\n\telse:return 0\r\nt=list(input())\r\np=list(input())\r\nn=len(t)\r\na=list(map(int,input().split()))\r\nl,r,ans=0,n-1,0\r\nwhile (l<=r): #Binary Search\r\n\tm=(l+r)//2\r\n\ttt=t.copy()\r\n\tfor i in range(m+1):\r\n\t\ttt[a[i]-1]=''\r\n\tif check(tt,p):l=m+1;ans=m+1\r\n\telse:r=m-1\r\nprint(ans)", "t=input()\np=input()\na=[int(i)-1 for i in input().split()]\ndef check(mid,t,p,a):\n s=set(a[:mid+1])\n j=0\n for i in range(len(t)):\n if len(t)-i<len(p)-j:\n return False\n if i not in s:\n if t[i]==p[j]:\n j+=1\n if j==len(p):\n return True\n return False\nl = 0\nr = len(a) - 1\nwhile l<=r and r<len(a):\n mid=l+(r-l)//2\n if check(mid,t,p,a):\n l=mid+1\n else:\n r=mid-1\nprint(l)\n\t\t \t\t \t \t \t \t \t\t \t\t\t", "\r\na=list(input())\r\nb=input()\r\nnums=list(map(int,input().split()))\r\nlength=len(a)\r\ndef check(x):\r\n save=list(a)\r\n for i in range(x):\r\n save[nums[i]-1]=\"\"\r\n i=0\r\n j=0\r\n for i in range(length):\r\n if save[i]==b[j]:\r\n j=j+1 \r\n if j==len(b):\r\n return True \r\n return False\r\n\r\ni=-1\r\nj=len(nums)\r\n\r\nwhile i+1<j:\r\n mid=(i+j)//2\r\n if check(mid):\r\n i=mid\r\n else:\r\n j=mid \r\nprint(i)", "def can(m):\r\n u = sorted(a[:m])\r\n inp = 0\r\n inu = 0\r\n for i in range(len(t)):\r\n if inu < len(u) and i == u[inu] - 1:\r\n inu += 1\r\n elif t[i] == p[inp]:\r\n inp += 1\r\n if inp == len(p):\r\n return True\r\n return False\r\n\r\nt = input()\r\np = input()\r\na = list(map(int, input().split()))\r\nl = 0\r\nr = len(t)\r\nwhile r - l > 1:\r\n m = (r + l) // 2\r\n if can(m):\r\n l = m\r\n else:\r\n r = m\r\nprint(l)\r\n", "\"\"\" 616C \"\"\"\r\n# import math\r\n# import sys\r\ndef check(index,string,string2,arr):\r\n\tstring1 = list(string)\r\n\tfor i in range(index+1):\r\n\t\tstring1[arr[i]-1]='-1'\r\n\tj = 0\r\n\tfor i in range(len(string1)):\r\n\t\tif string1[i]==string2[j]:\r\n\t\t\tj+=1\r\n\t\tif j==len(string2):\r\n\t\t\treturn True\r\n\treturn False\r\n\r\n\r\n\r\ndef main():\r\n\tstring1 = str(input())\r\n\tstring2 = str(input())\r\n\t# string1 = list(string1)\r\n\ta = list(map(int,input().split()))\r\n\tstart = 0 \r\n\tans = -1\r\n\tend = len(a)-1\r\n\twhile start<=end:\r\n\t\t# print(string1)\r\n\t\tmid = start + (end-start)//2\r\n\t\tif (check(mid,string1,string2,a)):\r\n\t\t\tans = mid\r\n\t\t\tstart = mid+1\r\n\t\telse:\r\n\t\t\tend = mid-1\r\n\tprint(ans+1)\r\n\r\n\treturn\r\n\t\r\n\r\nmain()\r\n# def test():\r\n# \tt = int(input())\r\n# \twhile t:\r\n# \t\tmain()\r\n# \t\tt-=1\r\n# test()\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\nS = input()\r\nT = input()\r\nA = list(map(int, input().split()))\r\n\r\ndef check(m):\r\n seen = set(A[:m])\r\n i1,i2 = 0,0\r\n while i1<len(S) and i2<len(T):\r\n if i1+1 in seen:\r\n i1+=1\r\n continue\r\n\r\n if S[i1]==T[i2]:\r\n i1+=1\r\n i2+=1\r\n else:\r\n i1+=1\r\n return i2==len(T)\r\n\r\nl,r = 0,len(S)+1\r\nwhile l+1<r:\r\n m = (l+r)//2\r\n if check(m):\r\n #print(m)\r\n l = m\r\n else:\r\n r = m\r\nprint(l)\r\n\r\n", "\n\n\"\"\"\nNTC here\n\"\"\"\nimport sys\ninp = sys.stdin.readline\ndef input(): return inp().strip()\n# flush= sys.stdout.flush\n# import threading\n# sys.setrecursionlimit(10**6)\n# threading.stack_size(2**26)\n\n\ndef iin(): return int(input())\n\n\ndef lin(): return list(map(int, input().split()))\n\n\ndef main():\n p, t = input(), input()\n a = lin()\n n = len(p)\n def check(x):\n rm = set(a[:x])\n #print(rm)\n p1 = [p[i] for i in range(n) if i+1 not in rm]\n #print(p1, t)\n dc = {}\n for i, j in enumerate(p1):\n try:\n dc[j].append(i)\n except:\n dc[j] = [i]\n for i in dc:\n dc[i] = dc[i][::-1]\n pv = -1\n for i in t:\n if i in dc:\n while dc[i]:\n ch = dc[i].pop()\n if ch > pv:\n pv = ch\n break\n else:\n return False\n else:\n return False\n return True\n ans = 0\n left, right = 0, n-1\n while left < right:\n #print(left, right)\n md = (left+right+1) >> 1\n if check(md):\n #print(\"SOL - \", md)\n ans = max(md, ans)\n left = md \n else:\n #print('wrong ', md)\n right = md - 1\n print(ans)\n\nmain()\n\n# threading.Thread(target=main).start()\n", "def checksub(tmp, t):\r\n j = 0\r\n n = len(tmp)\r\n m = len(t)\r\n for i in range(n):\r\n if t[j] == tmp[i]:\r\n j += 1\r\n if j == m:\r\n return True\r\n return False\r\n\r\n\r\ndef solve(p, t, perms):\r\n l = 0\r\n h = len(p) - 1\r\n ans = 0\r\n while l <= h:\r\n m = int((l + h) / 2)\r\n tmp = list(p)\r\n for i in range(m):\r\n tmp[perms[i] - 1] = '_'\r\n if checksub(tmp, t):\r\n ans = m\r\n l = m + 1\r\n else:\r\n h = m - 1\r\n return ans\r\n\r\n\r\nif __name__ == '__main__':\r\n p = input()\r\n t = input()\r\n lst = list(map(int, input().split()))\r\n print(solve(p, t, lst))\r\n", "s, t = input(), input()\nind = list(map(int, input().split()))\n\ndef is_substring(text, word, exclude):\n wi = 0\n for i in range(len(text)):\n if wi < len(word) and text[i] == word[wi] and i + 1 not in exclude: \n wi += 1\n\n return wi == len(word)\n\nl, r = 0, len(ind)\n\nwhile l < r:\n mid = (l + r) // 2 + 1\n if is_substring(s, t, set(ind[:mid])):\n l = mid\n else:\n r = mid - 1\n\nprint(l)", "import sys\r\ninput=sys.stdin.readline\r\nt=input().rstrip()\r\np=input().rstrip()\r\na=list(map(int,input().split()))\r\nl=0;r=len(a)\r\nwhile r-l>1:\r\n mid=(r+l)//2\r\n s=set(a[:mid])\r\n j=0\r\n for i in range(len(t)):\r\n if j<len(p) and t[i]==p[j] and i+1 not in s:\r\n j+=1\r\n if j==len(p):\r\n l=mid\r\n else:\r\n r=mid\r\nprint(l)", "def possible(t,p,a,n):\r\n s = ''\r\n check = [True]*len(t)\r\n for i in range(n):\r\n check[a[i]] = False\r\n for i in range(len(check)):\r\n if check[i]:\r\n s += t[i]\r\n \r\n m = len(s)\r\n lp = len(p)\r\n c = 0\r\n for i in range(m):\r\n if s[i] == p[c]:\r\n c += 1\r\n if c == lp:\r\n return True\r\n return False \r\n \r\nt = input()\r\np = input()\r\na = list(map(int,input().split()))\r\nfor i in range(len(a)):\r\n a[i] -= 1\r\n\r\nlow = 0\r\nhigh = len(a)\r\nans = 0\r\nwhile low <= high:\r\n mid = (low+high)//2\r\n if possible(t,p,a,mid):\r\n ans = mid\r\n low = mid+1\r\n else:\r\n high = mid-1\r\nprint(ans) ", "def subset(S,s):\n\ti = 0\n\tj = 0\n\twhile i<len(S) and j<len(s):\n\t\tif S[i]==s[j]:\n\t\t\ti+=1\n\t\t\tj+=1\n\t\telse: i+=1\n\tif j==len(s):\n\t\treturn True\n\treturn False\n\n\nn = input()\na = input()\narr = [int(x)-1 for x in input().split()]\nnew = []\nl = 0\nr = len(n)\nwhile l<r:\n\tmid = (l+r+1)//2\n\tsa = arr[:mid]\n\tnew = list(n)\n\tfor i in sa: new[i] = ''\n\tif subset(''.join(new),a):\n\t\tl = mid\n\telse:\n\t\tr = mid-1\n\nprint(r)\n\n\n\t\n", "from sys import stdin\r\n\r\ndef input():\r\n return stdin.readline()\r\n\r\ns = list(input())\r\nt = input()\r\na = list(map(lambda x: int(x) - 1, input().split()))\r\nn = len(a)\r\n\r\ndef can(s):\r\n cur = 0\r\n for i, ch in enumerate(s):\r\n if ch == t[cur]:\r\n cur += 1\r\n if cur == len(t):\r\n return True\r\n return False\r\n\r\nleft, right = -1, n\r\nwhile left + 1 < right:\r\n mid = (left + right) >> 1\r\n temp = s[::]\r\n for i in range(mid):\r\n temp[a[i]] = ''\r\n if can(''.join(temp)):\r\n left = mid\r\n else:\r\n right = mid\r\nprint(left)", "def is_good(m, a, p, t):\r\n b = [True for i in range(len(a))]\r\n for i in range(m):\r\n b[a[i] - 1] = False\r\n\r\n n = len(p)\r\n l = 0\r\n for i in range(len(t)):\r\n if t[i] == p[l] and b[i]:\r\n l += 1\r\n if l == n:\r\n return True\r\n\r\n return False\r\n\r\nt = input()\r\np = input()\r\na = list(map(int, input().split()))\r\n\r\nl, r = -1, len(t)\r\nwhile r > l + 1:\r\n m = (l + r) // 2\r\n if is_good(m, a, p, t):\r\n l = m\r\n else: r = m\r\n\r\nprint(l)\r\n\r\n\r\n", "start = list(input())\r\nend = list(input())\r\nnums = list(map(int, input().split()))\r\n \r\ndef ifpossible(mid):\r\n temp = start.copy()\r\n for i in range(mid):\r\n temp[nums[i] - 1] = 0\r\n ptr = 0\r\n for i in range(len(temp)):\r\n if (temp[i] == end[ptr]):\r\n ptr += 1 \r\n if (ptr == len(end)):\r\n return True\r\n return False\r\n \r\nlow = 0\r\nhigh = len(nums)\r\nres = 0\r\nwhile (high >= low):\r\n mid = int(low + (high - low) / 2)\r\n if (ifpossible(mid)):\r\n res = mid\r\n low = mid+1\r\n else:\r\n high = mid-1\r\nprint(res)", "a = input()\nb = input()\np = list(map(int, input().split()))\nfor i in range(len(p)):\n p[i] -= 1\n\ndef good(m):\n pos = 0\n a1 = list(a)\n for i in range(m):\n a1[p[i]] = \"#\"\n for i in range(len(a1)):\n if a1[i] == b[pos]:\n pos += 1\n if pos == len(b):\n return True\n return False\n \n \n\n\n\nl = 0\nr = len(a)\nwhile r - l > 1:\n m = (l + r) // 2\n if good(m):\n l = m\n else:\n r = m\nprint(l)", "# import inbuilt standard input output\r\nimport sys\r\nfrom sys import stdin, stdout\r\n\r\n# suppose a function called main() and\r\n# all the operations are performed\r\n\r\n# ////////// Get integer values in variables \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\r\n\r\n\r\ndef get_ints_in_variables():\r\n return map(int, sys.stdin.readline().strip().split())\r\n\r\n\r\ndef get_ints_in_list(): return list(\r\n map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef get_string(): return sys.stdin.readline().strip()\r\n\r\n\r\ndef isSubsequence(S, t, op, key):\r\n tmp = [c for c in S]\r\n for j in range(0, key+1):\r\n tmp[op[j]-1] = \"$\"\r\n j = 0\r\n for i in range(len(tmp)):\r\n if tmp[i] == t[j]:\r\n j += 1\r\n if j == len(t):\r\n return True\r\n return j == len(t)\r\n\r\n\r\ndef Solution(s, p, op):\r\n l = 0\r\n r = len(op)\r\n ans = 0\r\n while l <= r:\r\n mid = (l+r)//2\r\n if isSubsequence(s, p, op, mid):\r\n l = mid+1\r\n else:\r\n ans = mid\r\n r = mid-1\r\n return ans\r\n\r\n\r\ndef main():\r\n # //TAKE INPUT HERE\r\n S = get_string()\r\n t = get_string()\r\n arr = get_ints_in_list()\r\n print(Solution(S, t, arr))\r\n\r\n\r\n# call the main method\r\nif __name__ == \"__main__\":\r\n main()\r\n", "s=input()\r\nt=input()\r\np=list(map(int,input().split()))\r\nl=0\r\nh=len(p)\r\ndef check(x):\r\n q=set()\r\n for i in range(x):\r\n q.add(p[i]-1)\r\n ind=0\r\n o=0\r\n while ind<len(p) and o<len(t):\r\n if ind in q:\r\n ind+=1\r\n else :\r\n if s[ind]==t[o]:\r\n o+=1\r\n ind+=1\r\n return (o==len(t))\r\n \r\n \r\nwhile l<=h:\r\n mid=(l+h)//2\r\n if check(mid):\r\n ans=mid\r\n l=mid+1\r\n else :\r\n h=mid-1\r\nprint(ans)", "\r\na,b,c = list(input()) , list(input()) , tuple(map(int,input().split()))\r\nx,y,l,r = len(a),len(b),0,200000\r\ndef cn(mid):\r\n v = a.copy()\r\n if mid>x-y:return False\r\n for i in range (mid):v[c[i]-1] = 0\r\n s= 0\r\n for i in v:\r\n if s == y:break\r\n s+=1 if i == b[s] else 0\r\n return True if s == y else False\r\n\r\nwhile l<=r:\r\n mid = (l+r)//2\r\n if cn(mid):l = mid+1\r\n else:r = mid-1\r\n\r\nprint(max(0,r))", "import sys\r\n# from math import log2,floor,ceil,sqrt\r\n# import bisect\r\n# from collections import deque\r\n\r\n# from types import GeneratorType\r\n# def bootstrap(func, stack=[]):\r\n# def wrapped_function(*args, **kwargs):\r\n# if stack:\r\n# return func(*args, **kwargs)\r\n# else:\r\n# call = func(*args, **kwargs)\r\n# while True:\r\n# if type(call) is GeneratorType:\r\n# stack.append(call)\r\n# call = next(call)\r\n# else:\r\n# stack.pop()\r\n# if not stack:\r\n# break\r\n# call = stack[-1].send(call)\r\n# return call\r\n# return wrapped_function\r\n\r\nRi = lambda : [int(x) for x in sys.stdin.readline().split()]\r\nri = lambda : sys.stdin.readline().strip()\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\r\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\r\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]\r\ndef ceil(x, y=1): return int(-(-x // y))\r\ndef INT(): return int(input())\r\ndef MAP(): return map(int, input().split())\r\ndef LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]\r\ndef Yes(): print('Yes')\r\ndef No(): print('No')\r\ndef YES(): print('YES')\r\ndef NO(): print('NO')\r\nINF = 10 ** 18\r\nMOD = 10**8\r\nN = 5*10**6\r\n\r\ndef solve(no):\r\n se =set(a[:no])\r\n flag = False\r\n ite = 0\r\n # p =/ 0\r\n for i in range(len(s)):\r\n if i in se:\r\n continue\r\n if s[i] == t[ite]:\r\n ite+=1\r\n if ite == len(t):\r\n flag = True\r\n break\r\n return flag\r\n\r\n\r\ns = ri()\r\nt = ri() \r\na = Ri()\r\na = [i-1 for i in a]\r\nl=0\r\nh = len(a)\r\n\r\nmaxx = 0\r\nwhile(l<=h):\r\n mid = (l+h)//2\r\n # print(l,h)\r\n if solve(mid):\r\n maxx = max(maxx,mid)\r\n l = mid+1\r\n else:\r\n h = mid-1\r\n\r\n\r\nprint(maxx)\r\n\r\n\r\n \r\n\r\n\r\n\r\n", "t = input().strip()\r\np = input().strip()\r\nA = list(map(int,input().strip().split()))\r\ndef fn(c):\r\n s = set(A[:c])\r\n st = []\r\n for i in range(len(t)):\r\n if (i+1 in s)==False:\r\n st.append(t[i])\r\n p1 = 0\r\n p2 = 0\r\n while (p1!=len(st) and p2!=len(p)):\r\n if st[p1]==p[p2]:\r\n p2+=1\r\n p1+=1\r\n if p2==len(p):\r\n return(True)\r\n else:\r\n return(False)\r\n\r\nr = 0\r\nl = len(A) \r\nwhile l-r>1:\r\n c = int((r+l)//2)\r\n if fn(c)==True:\r\n r = c\r\n else:\r\n l = c\r\nprint(r)" ]
{"inputs": ["ababcba\nabb\n5 3 4 1 7 6 2", "bbbabb\nbb\n1 6 3 4 2 5", "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2", "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33 39 29 83 91 67 72 54 2 17 85 82 14 15 90 64 50 99 26 66 65 31 49 40 45 77 37 25 42 97 47 58 92 59 16"], "outputs": ["3", "4", "9", "16", "57"]}
UNKNOWN
PYTHON3
CODEFORCES
82
20bba2c3e5ff8b9338dc245960535aab
Vanya and Triangles
Vanya got bored and he painted *n* distinct points on the plane. After that he connected all the points pairwise and saw that as a result many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area. The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of the points painted on the plane. Next *n* lines contain two integers each *x**i*,<=*y**i* (<=-<=100<=≤<=*x**i*,<=*y**i*<=≤<=100) — the coordinates of the *i*-th point. It is guaranteed that no two given points coincide. In the first line print an integer — the number of triangles with the non-zero area among the painted points. Sample Input 4 0 0 1 1 2 0 2 2 3 0 0 1 1 2 0 1 1 1 Sample Output 3 1 0
[ "import math\r\nfrom collections import defaultdict\r\nclass Solution:\r\n def maxPoints(self, points):\r\n ans=0\r\n n=len(points)\r\n if n<=2:\r\n return ans\r\n def customise_gcd(x,y):\r\n if x==0 and y==0:\r\n return 1\r\n if x==0:\r\n return y\r\n elif y==0:\r\n return x\r\n else:\r\n return math.gcd(x,y)\r\n def substitube(y,x):\r\n if x==0:\r\n y=1\r\n elif y==0:\r\n x=1\r\n elif (x<0 and y<0) or x<0:\r\n return y*(-1),x*(-1)\r\n return y,x\r\n cnt=0\r\n for i in range(n):\r\n mx=0\r\n rp=0\r\n dt=defaultdict(int)\r\n for j in range(i+1,n):\r\n if points[i]==points[j]:\r\n rp+=1\r\n else:\r\n delta_y=points[j][1]-points[i][1]\r\n delta_x=points[j][0]-points[i][0]\r\n gd=customise_gcd(abs(delta_y),abs(delta_x))\r\n delta_y,delta_x=substitube(delta_y//gd,delta_x//gd)\r\n dt[(delta_y,delta_x)]+=1\r\n for val in dt.values():\r\n if val>=2:\r\n cnt+=(val*(val-1))//2\r\n ttl=n*(n-1)*(n-2)//6\r\n ans=ttl-cnt\r\n \r\n return ans\r\n\r\nI=lambda: map(int,input().split())\r\nob=Solution()\r\nn=int(input())\r\npoints=[]\r\nfor i in range(n):\r\n x,y=I()\r\n points+=[[x,y]]\r\nprint(ob.maxPoints(points))\r\n \r\n ", "from collections import defaultdict\r\nimport math\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nxy = [tuple(map(int, input().split())) for _ in range(n)]\r\nng = 0\r\nfor i in range(n):\r\n xi, yi = xy[i]\r\n cnt = defaultdict(lambda : 0)\r\n for j in range(n):\r\n if i == j:\r\n continue\r\n xj, yj = xy[j]\r\n u, v = xi - xj, yi - yj\r\n g = math.gcd(abs(u), abs(v))\r\n u //= g\r\n v //= g\r\n if u < 0:\r\n u *= -1\r\n v *= -1\r\n if u == 0 and v < 0:\r\n v *= -1\r\n cnt[(u, v)] += 1\r\n for i in cnt.values():\r\n ng += i * (i - 1) // 2\r\nans = n * (n - 1) * (n - 2) // 6 - ng // 3\r\nprint(ans)", "n = int(input())\r\n\r\nif n < 3:\r\n\tprint(0)\r\nelse:\r\n ans = n*(n-1)*(n-2)/6\r\n x = [0]*n\r\n y = [0]*n\r\n for i in range(n):\r\n \tx[i], y[i] = map(int, input().split())\r\n for i in range(n):\r\n seen = {}\r\n x1, y1 = x[i], y[i]\r\n for j in range(i+1, n):\r\n x2, y2 = x[j], y[j]\r\n if x2-x1 == 0:\r\n \tm = 1e999\r\n else:\r\n m = (y2-y1)*1.0/(x2-x1)\r\n if m not in seen:seen[m] = 0\r\n ans -= seen[m]\r\n seen[m] += 1\r\n print(int(ans))", "n = int(input())\np = []\nfor _ in range(n):\n x, y = input().split()\n p.append((int(x), int(y)))\n\nk = []\n\nfrom math import gcd\ndef getk(x1, y1, x2, y2):\n if x1 == x2: return (1, 0)\n if y1 == y2: return (0, 1)\n num = y2 - y1\n den = x2 - x1\n g = gcd(abs(num), abs(den))\n num //= g\n den //= g\n if den < 0:\n num = -num\n den = -den\n return (num, den)\n\nfor i in range(n):\n tk = {}\n for j in range(n):\n if i == j: continue\n tmp = getk(*p[i], *p[j])\n tk[getk(*p[i], *p[j])] = tk.get(tmp, 0) + 1\n k.append(tk)\n\nans = 0\n\nfor i in range(n):\n for j in range(i + 1, n):\n ans += n - 1 - k[i][getk(*p[i], *p[j])]\n\nprint(ans // 3)\n# print(k)\n\n", "n=int(input())\ns=n*(n-1)*(n-2)//6\np=[list(map(int,input().split()))for _ in range(n)]\nfor i in range(n):\n\tk,l=0,sorted(1e9 if p[i][1]==Y else (p[i][0]-X)/(p[i][1]-Y)for X,Y in p[:i])\n\tfor j in range(1,i):k=k+1 if l[j]==l[j-1]else 0;s-=k\nprint(s)\n\n", "n=int(input())\r\ns=n*(n-1)*(n-2)//6\r\np=[list(map(int,input().split()))for _ in range(n)]\r\nfor i in range(n):\r\n\tk,l=0,sorted(1e9 if p[i][1]==Y else (p[i][0]-X)/(p[i][1]-Y)for X,Y in p[:i])\r\n\tfor j in range(1,i):k=k+1 if l[j]==l[j-1]else 0;s-=k\r\nprint(s)", "\r\ndef solve(dots,n):\r\n\r\n ans = n*(n-1)*(n-2)/6 #C(n,3)=P(n,3)/factorial(3)\r\n\r\n for i in range(n):\r\n seen = {}\r\n for j in range(i+1,n):\r\n #egim\r\n if dots[i][0]-dots[j][0] == 0:\r\n e=10**10\r\n else:\r\n e=(dots[i][1]-dots[j][1])/(dots[i][0]-dots[j][0])\r\n if e not in seen.keys():\r\n seen[e] = 0\r\n ans -=seen[e]\r\n seen[e]+=1\r\n\r\n return int(ans)\r\n\r\n\r\ndef main():\r\n n=int(input().strip())\r\n if n<3:\r\n print(0)\r\n else:\r\n dots=[]\r\n for _ in range(n):\r\n dots.append(list(map(int,input().strip().split())))\r\n print(solve(dots,n))\r\n\r\nif __name__ == '__main__':\r\n main()\r\n\r\n", "'''\r\nslope concept is used mostly here\r\nand then used combinatorics to get total count\r\nwhile keeping in mind that not to double count and\r\nalso not count triangles that are of zro area; all three points on same line \r\n'''\r\ndef get_hcf(a,b):\r\n # log(max(a,b))\r\n if a>=b:\r\n q=a\r\n p=b\r\n else:\r\n q=b\r\n p=a\r\n \r\n while q%p!=0:\r\n q,p=p,q%p\r\n return p\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n=int(input())\r\n points=[[int(i) for i in input().split()] for j in range(n)]\r\n ans=0\r\n distance_hm={}\r\n for i in range(n):\r\n # populating the distance map for ith point\r\n for j in range(i+1,n): # very important otherwise we double count\r\n p1=points[i]\r\n p2=points[j]\r\n if p1[0]==p2[0]:\r\n distance_hm[(1,0)]=distance_hm.get((1,0),0)+1\r\n elif p1[1]==p2[1]:\r\n distance_hm[(0,1)]=distance_hm.get((0,1),0)+1\r\n else:\r\n a=p2[1]-p1[1]\r\n b=p2[0]-p1[0]\r\n hcf_ab=get_hcf(abs(a),abs(b))\r\n a=a//hcf_ab\r\n b=b//hcf_ab\r\n if a*b<0:\r\n distance_hm[(-abs(a),abs(b))]=distance_hm.get((-abs(a),abs(b)),0)+1\r\n else:\r\n distance_hm[(abs(a),abs(b))]=distance_hm.get((abs(a),abs(b)),0)+1\r\n # counting step\r\n count=0\r\n total_sum=0\r\n for val in distance_hm.values():\r\n total_sum+=val\r\n \r\n for val in distance_hm.values():\r\n count+=(total_sum-val)*val\r\n \r\n ans+=(count//2)\r\n\r\n # don't forget to clear the hm\r\n distance_hm.clear()\r\n print(ans)", "import random, math, sys\nfrom copy import deepcopy as dc\nfrom bisect import bisect_left, bisect_right\nfrom collections import Counter\n\ninput = sys.stdin.readline\n\n\n\n# Function to call the actual solution\ndef solution(li):\n\tn = len(li)\n\tco = (n * (n-1) *(n-2))/6\n\tfor i in range(len(li)):\n\t\tx, y = li[i]\n\t\tma = {}\n\t\tfor j in range(i+1, n):\n\t\t\tx1, y1 = li[j]\n\t\t\tif x1-x == 0:\n\t\t\t\tslope = 1e999\n\t\t\telse:\n\t\t\t\tslope = (y1-y)/(x1-x)\n\t\t\tif slope not in ma:\n\t\t\t\tma[slope] = 0\n\t\t\tco -= ma[slope]\n\t\t\tma[slope] += 1\n\treturn int(co)\n# Function to take input\ndef input_test():\n\tli1 = []\n\tfor _ in range(int(input())):\n\t\t# n = int(input())\n\t\t# x, y = map(int, input().strip().split(\" \"))\n\t\t# a, b, c = map(int, input().strip().split(\" \"))\n\t\tli = list(map(int, input().strip().split(\" \")))\n\t\tli1.append(li)\n\tout = solution(li1)\n\tprint(out)\n\n# Function to test my code\ndef test():\n\tpass\n\n\ninput_test()\n# test()", "import math\r\n\r\nn = int(input())\r\nc = []\r\nl = []\r\n\r\nfor i in range(n):\r\n l.append(tuple(map(int, input().split())))\r\n \r\ns = set(l.copy())\r\nl.sort()\r\n\r\nif n < 3:\r\n print(0)\r\nelse:\r\n ct = 0\r\n for i in range(n-2):\r\n for j in range(i+1, n-1):\r\n ap = n-j-1\r\n \r\n pta = l[i]\r\n ptb = l[j]\r\n \r\n rs = l[j][1]-l[i][1]\r\n rn = l[j][0]-l[i][0]\r\n g = math.gcd(rs, rn)\r\n rs //= g\r\n rn //= g\r\n \r\n x = l[j][0]+rn\r\n y = l[j][1]+rs\r\n \r\n while x <= 100 and y <= 100:\r\n if (x, y) in s:\r\n ap -= 1\r\n x += rn\r\n y += rs\r\n \r\n ct += ap\r\n# print(i, j, ap, ct)\r\n \r\n print(ct)", "import sys\r\nfrom math import gcd\r\nfrom collections import defaultdict\r\ninput=sys.stdin.readline\r\nn=int(input())\r\np=[list(map(int,input().split())) for i in range(n)]\r\nans=0\r\nfor xi,yi in p:\r\n angle=defaultdict(int)\r\n for x,y in p:\r\n if xi==x and yi==y:\r\n continue\r\n x-=xi;y-=yi\r\n if x<0 or (x==0 and y<0):\r\n x=-x;y=-y\r\n g=abs(gcd(x,y))\r\n x//=g;y//=g\r\n angle[(x,y)]+=1\r\n cnt=0\r\n for i in angle.keys():\r\n cnt+=angle[i]*(n-1-angle[i])\r\n ans+=cnt//2\r\nprint(ans//3)" ]
{"inputs": ["4\n0 0\n1 1\n2 0\n2 2", "3\n0 0\n1 1\n2 0", "1\n1 1", "5\n0 0\n1 1\n2 2\n3 3\n4 4", "5\n0 0\n1 1\n2 3\n3 6\n4 10", "4\n-100 -100\n-100 100\n100 -100\n100 100", "5\n-100 -100\n-100 100\n100 -100\n100 100\n0 0", "4\n1 -100\n2 -100\n100 -99\n99 -99", "25\n26 -54\n16 56\n-42 -51\n92 -58\n100 52\n57 -98\n-84 -28\n-71 12\n21 -82\n-3 -30\n72 94\n-66 96\n-50 -41\n-77 -41\n-42 -55\n-13 12\n0 -99\n-50 -5\n65 -48\n-96 -80\n73 -92\n72 59\n53 -66\n-67 -75\n2 56", "5\n-62 -69\n3 -48\n54 54\n8 94\n83 94", "33\n0 81\n20 -16\n-71 38\n-45 28\n-8 -40\n34 -49\n43 -10\n-40 19\n14 -50\n-95 8\n-21 85\n64 98\n-97 -82\n19 -83\n39 -99\n43 71\n67 43\n-54 57\n-7 24\n83 -76\n54 -88\n-43 -9\n-75 24\n74 32\n-68 -1\n71 84\n88 80\n52 67\n-64 21\n-85 97\n33 13\n41 -28\n0 74", "61\n37 -96\n36 -85\n30 -53\n-98 -40\n2 3\n-88 -69\n88 -26\n78 -69\n48 -3\n-41 66\n-93 -58\n-51 59\n21 -2\n65 29\n-3 35\n-98 46\n42 38\n0 -99\n46 84\n39 -48\n-15 81\n-15 51\n-77 74\n81 -58\n26 -35\n-14 20\n73 74\n-45 83\n90 22\n-8 53\n1 -52\n20 58\n39 -22\n60 -10\n52 22\n-46 6\n8 8\n14 9\n38 -45\n82 13\n43 4\n-25 21\n50 -16\n31 -12\n76 -13\n-82 -2\n-5 -56\n87 -31\n9 -36\n-100 92\n-10 39\n-16 2\n62 -39\n-36 60\n14 21\n-62 40\n98 43\n-54 66\n-34 46\n-47 -65\n21 44", "9\n-41 -22\n95 53\n81 -61\n22 -74\n-79 38\n-56 -32\n100 -32\n-37 -94\n-59 -9", "33\n21 -99\n11 85\n80 -77\n-31 59\n32 6\n24 -52\n-32 -47\n57 18\n76 -36\n96 -38\n-59 -12\n-98 -32\n-52 32\n-73 -87\n-51 -40\n34 -55\n69 46\n-88 -67\n-68 65\n60 -11\n-45 -41\n91 -21\n45 21\n-75 49\n58 65\n-20 81\n-24 29\n66 -71\n-25 50\n96 74\n-43 -47\n34 -86\n81 14", "61\n83 52\n28 91\n-45 -68\n-84 -8\n-59 -28\n-98 -72\n38 -38\n-51 -96\n-66 11\n-76 45\n95 45\n-89 5\n-60 -66\n73 26\n9 94\n-5 -80\n44 41\n66 -22\n61 26\n-58 -84\n62 -73\n18 63\n44 71\n32 -41\n-50 -69\n-30 17\n61 47\n45 70\n-97 76\n-27 31\n2 -12\n-87 -75\n-80 -82\n-47 50\n45 -23\n71 54\n79 -7\n35 22\n19 -53\n-65 -72\n-69 68\n-53 48\n-73 -15\n29 38\n-49 -47\n12 -30\n-21 -59\n-28 -11\n-73 -60\n99 74\n32 30\n-9 -7\n-82 95\n58 -32\n39 64\n-42 9\n-21 -76\n39 33\n-63 59\n-66 41\n-54 -69", "62\n-53 -58\n29 89\n-92 15\n-91 -19\n96 23\n-1 -57\n-83 11\n56 -95\n-39 -47\n-75 77\n52 -95\n-13 -12\n-51 80\n32 -78\n94 94\n-51 81\n53 -28\n-83 -78\n76 -25\n91 -60\n-40 -27\n55 86\n-26 1\n-41 89\n61 -23\n81 31\n-21 82\n-12 47\n20 36\n-95 54\n-81 73\n-19 -83\n52 51\n-60 68\n-58 35\n60 -38\n-98 32\n-10 60\n88 -5\n78 -57\n-12 -43\n-83 36\n51 -63\n-89 -5\n-62 -42\n-29 78\n73 62\n-88 -55\n34 38\n88 -26\n-26 -89\n40 -26\n46 63\n74 -66\n-61 -61\n82 -53\n-75 -62\n-99 -52\n-15 30\n38 -52\n-83 -75\n-31 -38", "2\n0 0\n1 1", "50\n0 -26\n0 -64\n0 63\n0 -38\n0 47\n0 31\n0 -72\n0 60\n0 -15\n0 -36\n0 50\n0 -77\n0 -89\n0 5\n0 83\n0 -52\n0 -21\n0 39\n0 51\n0 -11\n0 -69\n0 57\n0 -58\n0 64\n0 85\n0 -61\n0 0\n0 69\n0 -83\n0 24\n0 -91\n0 -33\n0 -79\n0 -39\n0 -98\n0 45\n0 4\n0 -8\n0 96\n0 35\n0 9\n0 53\n0 90\n0 15\n0 -19\n0 -48\n0 -56\n0 38\n0 92\n0 76", "20\n12 16\n19 13\n19 15\n20 3\n5 20\n8 3\n9 18\n2 15\n2 3\n16 8\n14 18\n16 20\n13 17\n0 15\n10 12\n10 6\n18 8\n6 1\n6 2\n0 6", "5\n0 0\n1 1\n2 4\n3 8\n4 16", "3\n-100 -100\n0 0\n100 100", "20\n-2 1\n5 1\n1 -1\n1 4\n-5 -5\n3 1\n-5 -3\n-2 3\n-3 4\n5 -4\n-4 5\n3 3\n1 0\n-4 -4\n3 0\n4 -1\n-3 0\n-2 2\n-2 -5\n-5 -4", "3\n1 1\n3 3\n2 2", "10\n-52 25\n55 76\n97 88\n92 3\n-98 77\n45 90\n6 85\n-68 -38\n-74 -55\n-48 60", "10\n-1 32\n0 88\n-1 69\n0 62\n-1 52\n0 16\n0 19\n-1 58\n0 38\n0 67", "20\n-100 -100\n-99 -99\n-98 -96\n-97 -91\n-96 -84\n-95 -75\n-94 -64\n-93 -51\n-92 -36\n-91 -19\n100 100\n99 99\n98 96\n97 91\n96 84\n95 75\n94 64\n93 51\n92 36\n91 19"], "outputs": ["3", "1", "0", "0", "10", "4", "8", "4", "2300", "10", "5456", "35985", "84", "5455", "35985", "37814", "0", "0", "1130", "10", "0", "1109", "0", "120", "96", "1136"]}
UNKNOWN
PYTHON3
CODEFORCES
11
20bfb8b140bbbbc6164f4c0a84a2dc05
Sonya and Problem Wihtout a Legend
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing *n* positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0. The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=3000) — the length of the array. Next line contains *n* integer *a**i* (1<=≤<=*a**i*<=≤<=109). Print the minimum number of operation required to make the array strictly increasing. Sample Input 7 2 1 5 11 5 9 11 5 5 4 3 2 1 Sample Output 9 12
[ "from bisect import bisect_left as BL\r\n\r\nn = int(input())\r\ngraph = [(-99**9, 0)] # x, slope\r\nans = 0\r\nfor i,a in enumerate(map(int,input().split())):\r\n a-= i\r\n new = []\r\n turnj = BL(graph, (a,99**9)) - 1\r\n if turnj != len(graph)-1:\r\n ans+= graph[-1][0] - a\r\n \r\n # add |x-a|\r\n for j in range(turnj):\r\n x, sl = graph[j]\r\n new.append((x, sl-1))\r\n for j in range(turnj, len(graph)):\r\n x, sl = graph[j]\r\n if j == turnj:\r\n new.append((x, sl-1))\r\n new.append((a, sl+1))\r\n else: new.append((x, sl+1))\r\n \r\n # remove positive slopes\r\n graph = new\r\n while graph[-1][1] > 0: x, sl = graph.pop()\r\n if graph[-1][1] != 0: graph.append((x, 0))\r\nprint(ans)", "import sys\ninp = sys.stdin.readline\n# Codeforces 713 C\n\nn = int(inp())\na = [int(x) for x in inp().split()]\n\na = [x - i for i, x in enumerate(a)]\n\ns = sorted(a)\n\nM = [[0 for _ in a] for _ in a]\nfor i in range(n):\n for j in range(n):\n if i == 0:\n M[i][j] = abs(a[0] - s[j])\n elif j == 0:\n M[i][j] = M[i-1][0] + abs(a[i] - s[0])\n else:\n M[i][j] = min(M[i-1][j], M[i][j-1] - abs(a[i] - s[j-1]))+ abs(a[i] - s[j])\n\nprint(min(M[-1]))\n\n\n\n\n", "from heapq import heappop, heappush, heapreplace\r\nimport sys\r\nimport io\r\nimport os\r\n\r\n\r\n# region IO\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(io.IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._file = file\r\n self._fd = file.fileno()\r\n self.buffer = io.BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(io.IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\ndef print(*args, **kwargs):\r\n \"\"\"Prints the values to a stream, or to sys.stdout by default.\"\"\"\r\n sep, file = kwargs.pop(\"sep\", \" \"), kwargs.pop(\"file\", sys.stdout)\r\n at_start = True\r\n for x in args:\r\n if not at_start:\r\n file.write(sep)\r\n file.write(str(x))\r\n at_start = False\r\n file.write(kwargs.pop(\"end\", \"\\n\"))\r\n if kwargs.pop(\"flush\", False):\r\n file.flush()\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\n\r\n\r\ndef input(): return sys.stdin.readline().rstrip('\\r\\n')\r\n\r\n\r\ndef read_int_list():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef read_int_tuple():\r\n return tuple(map(int, input().split()))\r\n\r\n\r\ndef read_int():\r\n return int(input())\r\n\r\n\r\n# endregion\r\n\r\n# region local test\r\n# if 'AW' in os.environ.get('COMPUTERNAME', ''):\r\n# test_no = 3\r\n# f = open(os.path.dirname(__file__) + f'\\\\in{test_no}.txt', 'r')\r\n\r\n# def input():\r\n# return f.readline().rstrip(\"\\r\\n\")\r\n# endregion\r\n\r\nfrom heapq import heappop, heappush, heappushpop\r\n\r\nINF = 1 << 60\r\n\r\nclass SlopeTrick:\r\n def __init__(self):\r\n self.L = [] # 斜率小于0的减少点的坐标\r\n self.R = [] # 斜率大于0的增长点的坐标\r\n self.mi = 0 # 最小值\r\n self.la = 0 # L offset\r\n self.ra = 0 # R offset\r\n\r\n def add_const(self, a):\r\n self.mi += a\r\n\r\n def add_l(self, a): # add max(a - x, 0) \\\\__\r\n if self.R:\r\n r0 = self.R[0] + self.ra\r\n # self.mi += max(a - r0, 0)\r\n if a > r0:\r\n self.mi += a - r0\r\n heappush(self.L, -(heappushpop(self.R, a - self.ra) + self.ra - self.la))\r\n\r\n def add_r(self, a): # add max(x - a, 0) __/\r\n if self.L:\r\n l0 = -self.L[0] + self.la\r\n # self.mi += max(l0 - a, 0)\r\n if l0 > a:\r\n self.mi += l0 - a\r\n heappush(self.R, -(heappushpop(self.L, -(a - self.la))) + self.la - self.ra)\r\n\r\n def add_abs(self, a): # add |x-a| \\\\/\r\n self.add_l(a)\r\n self.add_r(a)\r\n\r\n def slide(self, a, b=None): # l0 += a, r0 += b / f(x) = min({f(y) | x-b <= y <= x-a })\r\n if b is None: b = a\r\n assert a <= b\r\n self.la += a\r\n self.ra += b\r\n\r\n @property\r\n def min(self):\r\n return self.mi\r\n\r\n def f(self, x): # 当前函数在x位置的值 O(n)\r\n s = self.mi\r\n for r in self.R:\r\n # s += max(x - (r + self.ra), 0)\r\n tmp = x - (r + self.ra)\r\n if tmp > 0:\r\n s += tmp\r\n for l in self.L:\r\n # s += max((-l + self.la) - x, 0)\r\n tmp = (-l + self.la) - x\r\n if tmp > 0:\r\n s += tmp\r\n\r\n return s\r\n\r\n @staticmethod\r\n def merge_destructive(a: 'SlopeTrick', b: 'SlopeTrick') -> 'SlopeTrick':\r\n \"\"\"\r\n f(x) += g(x), g(x) broken\r\n 会破坏g(x)的左右两边的堆.\r\n \"\"\"\r\n if len(b) > len(a):\r\n a, b = b, a\r\n for x in b.R:\r\n a.add_r(x)\r\n for x in b.L:\r\n a.add_l(x)\r\n a.mi += b.mi\r\n return a\r\n\r\n def __len__(self):\r\n return len(self.L) + len(self.R)\r\n\r\n def debug(self):\r\n print(\"mi, L, R =\", self.mi, self.L, self.la, self.R, self.ra)\r\n print([(x, self.f(x)) for x in range(-10, 11)])\r\n\r\n\"\"\"\r\n斜率优化模板\r\n每次添加一条斜率为1或者-1的直线\r\n用clear_right 获取前缀最小值\r\n\"\"\"\r\n\r\nn = read_int()\r\nst = SlopeTrick()\r\n\r\n\r\nfor a in read_int_tuple(): \r\n st.add_abs(a)\r\n st.slide(1)\r\n st.R = []\r\nprint(st.min)\r\n\r\n# 先把单调增搞成非减\r\n# n = read_int()\r\n# nums = read_int_list()\r\n\r\n# st = SlopeTrick()\r\n\r\n\r\n# for i in range(n):\r\n# a = nums[i] - i \r\n# st.add_abs(a)\r\n# st.clear_right()\r\n# print(st.query()[0])\r\n\r\n\r\n# slope-trick DP\r\n\r\n# n = read_int()\r\n# nums = read_int_list()\r\n\r\n# hp, res = [-nums[0]], 0\r\n# for i in range(1, n):\r\n# x = nums[i] - i\r\n# heappush(hp, -x)\r\n# if -hp[0] > x:\r\n# res += -hp[0] - x\r\n# heapreplace(hp, -x)\r\n# print(res)\r\n\r\n\r\n# traditonal DP\r\n\r\n# normal = [x - i for i, x in enumerate(nums)]\r\n\r\n# xs = sorted(set(normal))\r\n# inv = {x: i for i, x in enumerate(xs)}\r\n# m = len(xs)\r\n\r\n# inf = 123456789012345\r\n\r\n# dp = [abs(normal[0] - x) for x in xs]\r\n# for i in range(1, m):\r\n# if dp[i] > dp[i - 1]:\r\n# dp[i] = dp[i - 1]\r\n\r\n# for i in range(1, n):\r\n# x = normal[i]\r\n# np = [inf] * m\r\n# for j in range(m):\r\n# np[j] = min(np[j - 1], dp[j] + abs(x - xs[j]))\r\n# dp = np\r\n\r\n# # print(dp)\r\n# print(min(dp))", "import sys\r\nreadline=sys.stdin.readline\r\nimport heapq\r\nfrom heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max\r\ndef _heappush_max(heap,item):\r\n heap.append(item)\r\n heapq._siftdown_max(heap, 0, len(heap)-1)\r\ndef _heappushpop_max(heap, item):\r\n if heap and item < heap[0]:\r\n item, heap[0] = heap[0], item\r\n heapq._siftup_max(heap, 0)\r\n return item\r\n\r\nclass Slope_Trick:\r\n def __init__(self,L=False,R=False,median=False,label=False,f=None,f_inve=None,e=None):\r\n self.queueL=[]\r\n self.queueR=[]\r\n self.L=L\r\n self.R=R\r\n self.median=median\r\n if self.median:\r\n self.median_value=None\r\n self.label=label\r\n self.shiftL=0\r\n self.shiftR=0\r\n self.min_f=0\r\n if self.label:\r\n self.f=f\r\n self.f_inve=f_inve\r\n self.e=e\r\n self.labelL=self.e\r\n self.labelR=self.e\r\n\r\n def heappush(self,x):\r\n heappush(self.queueR,x-self.shiftR)\r\n if self.label:\r\n self.labelR=self.f(self.labelR,x)\r\n\r\n def heappop(self):\r\n x=heappop(self.queueR)+self.shiftR\r\n if self.label:\r\n self.labelR=self.f_inve(self.labelR,x)\r\n return x\r\n\r\n def heappushpop(self,x):\r\n y=heappushpop(self.queueR,x-self.shiftR)+self.shiftR\r\n if self.label:\r\n self.labelR=self.f(self.labelR,x)\r\n self.labelR=self.f_inve(self.labelR,y)\r\n return y\r\n\r\n def _heappush_max(self,x):\r\n _heappush_max(self.queueL,x-self.shiftL)\r\n if self.label:\r\n self.labelL=self.f(self.labelL,x)\r\n\r\n def _heappop_max(self):\r\n x=_heappop_max(self.queueL)+self.shiftL\r\n if self.label:\r\n self.labelL=self.f_inve(self.labelL,x)\r\n return x\r\n\r\n def _heappushpop_max(self,x):\r\n y=_heappushpop_max(self.queueL,x-self.shiftL)+self.shiftL\r\n if self.label:\r\n self.labelL=self.f(self.labelL,x)\r\n self.labelL=self.f_inve(self.labelL,y)\r\n return y\r\n\r\n def push_Left(self,x):\r\n if self.queueR:\r\n self.min_f+=max(x-(self.queueR[0]+self.shiftR),0)\r\n self._heappush_max(self.heappushpop(x))\r\n\r\n def push_Right(self,x):\r\n if self.queueL:\r\n self.min_f+=max((self.queueL[0]+self.shiftL)-x,0)\r\n self.heappush(self._heappushpop_max(x))\r\n\r\n def pop_Left(self):\r\n if self.queueL:\r\n retu=self._heappop_max()\r\n if self.queueR:\r\n self.min_f+=max(retu-(self.queueR[0]+self.shiftR),0)\r\n else:\r\n retu=None\r\n return retu\r\n\r\n def pop_Right(self):\r\n if self.queueR:\r\n retu=self.heappop()\r\n if self.queueL:\r\n self.min_f+=max((self.queueL[0]+self.shiftL)-retu,0)\r\n else:\r\n retu=None\r\n return retu\r\n\r\n def push(self,x):\r\n if self.L:\r\n if len(self.queueL)<self.L:\r\n self.push_Left(x)\r\n else:\r\n self.push_Right(x)\r\n if self.R:\r\n if len(self.queueR)<self.R:\r\n self.push_Right(x)\r\n else:\r\n self.push_Left(x)\r\n if self.median:\r\n if self.median_value==None:\r\n if self.queueL and x<self.queueL[0]:\r\n self.median_value=self._heappushpop_max(x)\r\n elif self.queueR and self.queueR[0]<x:\r\n self.median_value=self.heappushpop(x)\r\n else:\r\n self.median_value=x\r\n else:\r\n if self.median_value<=x:\r\n self._heappush_max(self.median_value)\r\n self.heappush(x)\r\n else:\r\n self._heappush_max(x)\r\n self.heappush(self.median_value)\r\n self.median_value=None\r\n\r\n def pop(self):\r\n if self.L:\r\n if len(self.queueL)==self.L:\r\n retu=self._heappop_max()\r\n if self.queueR:\r\n self._heappush_max(self.heappop())\r\n else:\r\n retu=None\r\n if self.R:\r\n if len(self.queueR)==self.R:\r\n retu=self.heappop()\r\n if self.queueL:\r\n self.heappush(self._heappop_max())\r\n else:\r\n retu=None\r\n if self.median:\r\n if self.median_value==None:\r\n retu=(self.pop_Left(),self.pop_Right())\r\n else:\r\n retu=(self.median_value,None)\r\n self.median_value=None\r\n return retu\r\n\r\n def top(self):\r\n if self.L:\r\n if len(self.queueL)==self.L:\r\n retu=self.queueL[0]\r\n else:\r\n retu=None\r\n if self.R:\r\n if len(self.queueR)==self.R:\r\n retu=self.queueR[0]\r\n else:\r\n retu=None\r\n if self.median:\r\n if self.median_value==None:\r\n if self.queueL:\r\n retu=(self.queueL[0],self.queueR[0])\r\n else:\r\n retu=(None,None)\r\n else:\r\n retu=(self.median_value,None)\r\n return retu\r\n\r\n def top_Left(self):\r\n if self.queueL:\r\n return self.queueL[0]+self.shiftL\r\n else:\r\n return None\r\n\r\n def top_Right(self):\r\n if self.queueR:\r\n return self.queueR[0]+self.shiftR\r\n else:\r\n return None\r\n\r\n def Shift_Left(self,a):\r\n self.shiftL+=a\r\n\r\n def Shift_Right(self,a):\r\n self.shiftR+=a\r\n\r\n def Label_Left(self):\r\n return self.labelL\r\n\r\n def Label_Right(self):\r\n return self.labelR\r\n\r\n def Cumultive_min(self):\r\n self.queueR=[]\r\n\r\n def Cumultive_max(self):\r\n self.queueL=[]\r\n\r\n def __len__(self):\r\n retu=len(self.queueL)+len(self.queueR)\r\n if self.median and self.median_value!=None:\r\n retu+=1\r\n return retu\r\n\r\n def __call__(self,x):\r\n return sum(max((l+self.shiftL)-x,0) for l in self.queueL)+sum(max(x-(r+self.shiftR),0) for r in self.queueR)+self.min_f\r\n\r\n def __str__(self):\r\n if self.median:\r\n if self.median_value==None:\r\n return \"[\"+\", \".join(map(str,sorted([x+self.shiftL for x in self.queueL])))+\"]+[\"+\", \".join(map(str,sorted([x+self.shiftR for x in self.queueR])))+\"]\"\r\n else:\r\n return \"[\"+\", \".join(map(str,sorted([x+self.shiftL for x in self.queueL])))+\"]+\"+str(self.median_value)+\"+[\"+\", \".join(map(str,sorted([x+self.shiftR for x in self.queueR])))+\"]\"\r\n else:\r\n return \"[\"+\", \".join(map(str,sorted([x+self.shiftL for x in self.queueL])))+\"]+[\"+\", \".join(map(str,sorted([x+self.shiftR for x in self.queueR])))+\"]\"\r\n\r\nN=int(readline())\r\nA=list(map(int,readline().split()))\r\nST=Slope_Trick()\r\nfor a in A:\r\n ST.Cumultive_min()\r\n ST.Shift_Left(1)\r\n ST.push_Right(a)\r\n ST.push_Left(a)\r\nans=ST.min_f\r\nprint(ans)", "from bisect import bisect_left as BL\r\n\r\nn = int(input())\r\ngraph = [(-99**9, 0, 0)] # x, y, slope\r\nfor i,a in enumerate(map(int,input().split())):\r\n a-= i\r\n new = []\r\n turnj = BL(graph, (a,99**9)) - 1\r\n \r\n # add |x-a|\r\n for j in range(turnj):\r\n x, y, sl = graph[j]\r\n new.append((x, y+(a-x), sl-1))\r\n for j in range(turnj, len(graph)):\r\n x, y, sl = graph[j]\r\n if j == turnj:\r\n new.append((x, y+(a-x), sl-1))\r\n new.append((a, y+(a-x)+(sl-1)*(a-x), sl+1))\r\n else: new.append((x, y+(x-a), sl+1))\r\n \r\n # remove positive slopes\r\n graph = new\r\n while graph[-1][2] > 0: x, y, sl = graph.pop()\r\n if graph[-1][2] != 0: graph.append((x, y, 0))\r\nprint(graph[-1][1])", "INF = 10 ** 18\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nfor i in range(n):\r\n a[i] -= i\r\nb = sorted(a)\r\ndp = [[INF] * n for _ in range(n + 1)]\r\ndp[0][0] = 0\r\nfor i in range(n):\r\n dp[1][i] = abs(a[0] - b[i])\r\nfor i in range(1, n):\r\n m = dp[i][0] + abs(a[i] - b[0])\r\n for j in range(n):\r\n if m > dp[i][j]:\r\n m = dp[i][j]\r\n dp[i + 1][j] = m + abs(a[i] - b[j])\r\nprint(min(dp[n]))", "# import random\r\n# from time import perf_counter\r\ndef truncate(a):\r\n a = a.copy()\r\n a.sort()\r\n sz = 1\r\n for i in range(1, len(a)):\r\n if a[i] != a[sz - 1]:\r\n a[sz] = a[i]\r\n sz += 1\r\n\r\n while len(a) < sz:\r\n a.append(0)\r\n while len(a) > sz:\r\n a.pop()\r\n return a\r\n\r\nn = int(input())\r\na = [int(i) for i in input().split()]\r\nfor i in range(n):\r\n a[i] -= i\r\n# t1 = perf_counter()\r\nb = truncate(a)\r\n# t2 = perf_counter()\r\n# print(t2 - t1)\r\nm = len(b)\r\ndp = [0] * m\r\nfor i in range(n):\r\n next = [0] * m\r\n for j in range(m):\r\n next[j] = min(float('inf') if j == 0 else next[j - 1], dp[j] + abs(a[i] - b[j]))\r\n dp = next\r\n# t3 = perf_counter()\r\n# print(t3 - t1)\r\nret = float('inf')\r\nfor x in dp:\r\n ret = min(ret, x)\r\n# t4 = perf_counter()\r\n# print(t4 - t1)\r\nprint(ret)\r\n", "from bisect import insort\r\nclass Graph:\r\n def __init__(_):\r\n _.change = [-10**27] # increment slope at ...\r\n _.a = _.y = 0 # last line has slope a, starts from y\r\n _.dx = 0 # the whole graph is shifted right by ...\r\n def __repr__(_): return f\"<{[x+_.dx for x in _.change]}; {_.a} {_.y}>\"\r\n \r\n def shiftx(_, v): _.dx+= v\r\n def shifty(_, v): _.y+= v\r\n def addleft(_, v):\r\n if _.change[-1] < v-_.dx:\r\n dx = v-_.dx - _.change[-1]\r\n _.y+= _.a*dx\r\n insort(_.change, v-_.dx)\r\n def addright(_, v):\r\n if _.change[-1] < v-_.dx:\r\n dx = v-_.dx - _.change[-1]\r\n _.y+= _.a*dx; _.a+= 1\r\n insort(_.change, v-_.dx)\r\n return\r\n insort(_.change, v-_.dx)\r\n _.a+= 1; _.y+= _.change[-1]-(v-_.dx)\r\n #def remleft(_, v): change.remove(v-_.dx)\r\n def cutright(_):\r\n dx = _.change.pop()-_.change[-1]\r\n _.a-= 1; _.y-= _.a*dx\r\n\r\nn = int(input())\r\nG = Graph()\r\nfor x in map(int,input().split()):\r\n G.shiftx(1)\r\n G.addleft(x)\r\n G.addright(x)\r\n while G.a > 0: G.cutright()\r\nprint(G.y)", "import heapq\nn = int(input())\nd = list(map(int,input().split()))\npq = [-d[0]]\nheapq.heapify(pq)\nans = 0\nfor i in range(1,n):\n temp = i - d[i]\n heapq.heappush(pq,temp)\n if heapq.nsmallest(1,pq)[0] < temp:\n ans += temp - heapq.nsmallest(1,pq)[0]\n heapq.heappushpop(pq,temp)\nprint(ans)\n", "# Idea:\r\n# convert the problem to making array a non decreasing by decreasing each ai by i\r\n# Now we can argue that the optimal final array must have\r\n# each element equal to some element of the array a.\r\n# Proof is to assume optimal solution does not satisfy this then you can\r\n# always increase or decrease one element while maintaining the\r\n# non decreasing property and decreasing or not changing the number of\r\n# operations used. The point at which we cannot keep increasing or decreasing\r\n# is when the element i we are changing reaches some a[j] since then we may\r\n# go from removing to increasing operations (kind of like slope/events trick)\r\n\r\nn = int(input())\r\n\r\na = list(map(int,input().split()))\r\n\r\nfor i in range(n):\r\n a[i] -= i\r\n\r\nsorted_a = sorted(a)\r\n\r\ndp = [0.0]*n # dp[j] = min operations such a[i] = sorted_a[j]\r\ndp2 = [0.0]*n\r\n\r\nfor i in range(n):\r\n # we are changing a[i]\r\n mn_prev_state = 1e13\r\n\r\n for j in range(n):\r\n mn_prev_state = min(mn_prev_state, dp[j])\r\n\r\n # we change a[i] to sorted_a[j]\r\n # ofc this means the changed value of a[i-1] <= sorted_a[j]\r\n # so the changed value of a[i-1] = sorted_a[0...j]\r\n # hence mn_prev_state is all min(dp[0...j])\r\n dp2[j] = mn_prev_state + abs(a[i] - sorted_a[j])\r\n\r\n for j in range(n):\r\n dp[j] = dp2[j]\r\n\r\nprint(int(min(dp)))", "from heapq import heappop, heappush, heapreplace\r\nimport sys\r\nimport io\r\nimport os\r\n\r\n\r\n# region IO\r\nBUFSIZE = 8192\r\n\r\n\r\nclass FastIO(io.IOBase):\r\n newlines = 0\r\n\r\n def __init__(self, file):\r\n self._file = file\r\n self._fd = file.fileno()\r\n self.buffer = io.BytesIO()\r\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\r\n self.write = self.buffer.write if self.writable else None\r\n\r\n def read(self):\r\n while True:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n if not b:\r\n break\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines = 0\r\n return self.buffer.read()\r\n\r\n def readline(self):\r\n while self.newlines == 0:\r\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\r\n self.newlines = b.count(b\"\\n\") + (not b)\r\n ptr = self.buffer.tell()\r\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\r\n self.newlines -= 1\r\n return self.buffer.readline()\r\n\r\n def flush(self):\r\n if self.writable:\r\n os.write(self._fd, self.buffer.getvalue())\r\n self.buffer.truncate(0), self.buffer.seek(0)\r\n\r\n\r\nclass IOWrapper(io.IOBase):\r\n def __init__(self, file):\r\n self.buffer = FastIO(file)\r\n self.flush = self.buffer.flush\r\n self.writable = self.buffer.writable\r\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\r\n self.read = lambda: self.buffer.read().decode(\"ascii\")\r\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\r\n\r\n\r\ndef print(*args, **kwargs):\r\n \"\"\"Prints the values to a stream, or to sys.stdout by default.\"\"\"\r\n sep, file = kwargs.pop(\"sep\", \" \"), kwargs.pop(\"file\", sys.stdout)\r\n at_start = True\r\n for x in args:\r\n if not at_start:\r\n file.write(sep)\r\n file.write(str(x))\r\n at_start = False\r\n file.write(kwargs.pop(\"end\", \"\\n\"))\r\n if kwargs.pop(\"flush\", False):\r\n file.flush()\r\n\r\n\r\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\r\n\r\n\r\ndef input(): return sys.stdin.readline().rstrip('\\r\\n')\r\n\r\n\r\ndef read_int_list():\r\n return list(map(int, input().split()))\r\n\r\n\r\ndef read_int_tuple():\r\n return tuple(map(int, input().split()))\r\n\r\n\r\ndef read_int():\r\n return int(input())\r\n\r\n\r\n# endregion\r\n\r\n# region local test\r\n# if 'AW' in os.environ.get('COMPUTERNAME', ''):\r\n# test_no = 1\r\n# f = open(os.path.dirname(__file__) + f'\\\\in{test_no}.txt', 'r')\r\n\r\n# def input():\r\n# return f.readline().rstrip(\"\\r\\n\")\r\n# endregion\r\n\r\nfrom heapq import heappop, heappush\r\nfrom typing import Tuple\r\n\r\nINF = int(1e18)\r\n\r\nclass SlopeTrick:\r\n __slots__ = (\"_min_f\", \"_pq_l\", \"_pq_r\", \"add_l\", \"add_r\")\r\n\r\n def __init__(self):\r\n self.add_l = 0 # 左侧第一个拐点的位置 -> \\_/\r\n self.add_r = 0 # 右侧第一个拐点的位置 \\_/ <-\r\n self._pq_l = [] # 大根堆\r\n self._pq_r = [] # 小根堆\r\n self._min_f = 0\r\n\r\n def query(self) -> Tuple[int, int, int]:\r\n \"\"\"返回 `f(x)的最小值, f(x)取得最小值时x的最小值和x的最大值`\"\"\"\r\n return self._min_f, self._top_l(), self._top_r()\r\n\r\n def add_all(self, a: int) -> None:\r\n \"\"\"f(x) += a\"\"\"\r\n self._min_f += a\r\n\r\n def add_a_minus_x(self, a: int) -> None:\r\n \"\"\"\r\n ```\r\n add \\\\__\r\n f(x) += max(a - x, 0)\r\n ```\r\n \"\"\"\r\n tmp = a - self._top_r()\r\n if tmp > 0:\r\n self._min_f += tmp\r\n self._push_r(a)\r\n self._push_l(self._pop_r())\r\n\r\n def add_x_minus_a(self, a: int) -> None:\r\n \"\"\"\r\n ```\r\n add __/\r\n f(x) += max(x - a, 0)\r\n ```\r\n \"\"\"\r\n tmp = self._top_l() - a\r\n if tmp > 0:\r\n self._min_f += tmp\r\n self._push_l(a)\r\n self._push_r(self._pop_l())\r\n\r\n def add_abs(self, a: int) -> None:\r\n \"\"\"\r\n ```\r\n add \\\\/\r\n f(x) += abs(x - a)\r\n ```\r\n \"\"\"\r\n self.add_a_minus_x(a)\r\n self.add_x_minus_a(a)\r\n\r\n def clear_right(self) -> None:\r\n \"\"\"\r\n 取前缀最小值.\r\n ```\r\n \\\\/ -> \\\\_\r\n f_{new} (x) = min f(y) (y <= x)\r\n ```\r\n \"\"\"\r\n while self._pq_r:\r\n self._pq_r.pop()\r\n\r\n def clear_left(self) -> None:\r\n \"\"\"\r\n 取后缀最小值.\r\n ```\r\n \\\\/ -> _/\r\n f_{new} (x) = min f(y) (y >= x)\r\n ```\r\n \"\"\"\r\n while self._pq_l:\r\n self._pq_l.pop()\r\n\r\n def shift(self, a: int, b: int) -> None:\r\n \"\"\"\r\n ```\r\n \\\\/ -> \\\\_/\r\n f_{new} (x) = min f(y) (x-b <= y <= x-a)\r\n ```\r\n \"\"\"\r\n assert a <= b\r\n self.add_l += a\r\n self.add_r += b\r\n\r\n def translate(self, a: int) -> None:\r\n \"\"\"\r\n 函数向右平移a\r\n ```\r\n \\\\/. -> .\\\\/\r\n f_{new} (x) = f(x - a)\r\n ```\r\n \"\"\"\r\n self.shift(a, a)\r\n\r\n def get_destructive(self, x: int) -> int:\r\n \"\"\"\r\n y = f(x), f(x) broken\r\n 会破坏f内部左右两边的堆.\r\n \"\"\"\r\n res = self._min_f\r\n while self._pq_l:\r\n tmp = self._pop_l() - x\r\n if tmp > 0:\r\n res += tmp\r\n while self._pq_r:\r\n tmp = x - self._pop_r()\r\n if tmp > 0:\r\n res += tmp\r\n return res\r\n\r\n def merge_destructive(self, st: \"SlopeTrick\"):\r\n \"\"\"\r\n f(x) += g(x), g(x) broken\r\n 会破坏g(x)的左右两边的堆.\r\n \"\"\"\r\n if len(st) > len(self):\r\n st._pq_l, self._pq_l = self._pq_l, st._pq_l\r\n st._pq_r, self._pq_r = self._pq_r, st._pq_r\r\n st.add_l, self.add_l = self.add_l, st.add_l\r\n st.add_r, self.add_r = self.add_r, st.add_r\r\n st._min_f, self._min_f = self._min_f, st._min_f\r\n while st._pq_r:\r\n self.add_x_minus_a(st._pop_r())\r\n while st._pq_l:\r\n self.add_a_minus_x(st._pop_l())\r\n self._min_f += st._min_f\r\n\r\n def _push_r(self, a: int) -> None:\r\n heappush(self._pq_r, a - self.add_r)\r\n\r\n def _top_r(self) -> int:\r\n if not self._pq_r:\r\n return INF\r\n return self._pq_r[0] + self.add_r\r\n\r\n def _pop_r(self) -> int:\r\n val = self._top_r()\r\n if self._pq_r:\r\n heappop(self._pq_r)\r\n return val\r\n\r\n def _push_l(self, a: int) -> None:\r\n heappush(self._pq_l, -a + self.add_l)\r\n\r\n def _top_l(self) -> int:\r\n if not self._pq_l:\r\n return -INF\r\n return -self._pq_l[0] + self.add_l\r\n\r\n def _pop_l(self) -> int:\r\n val = self._top_l()\r\n if self._pq_l:\r\n heappop(self._pq_l)\r\n return val\r\n\r\n def _size(self) -> int:\r\n return len(self._pq_l) + len(self._pq_r)\r\n\r\n def __len__(self) -> int:\r\n return self._size()\r\n\r\nn = read_int()\r\nnums = read_int_list()\r\n\r\nst = SlopeTrick()\r\n\r\nfor i in range(n):\r\n a = nums[i] - i \r\n st.add_abs(a)\r\n st.clear_right()\r\nprint(st.query()[0])\r\n\r\n\r\n# slope-trick DP\r\n\r\n# n = read_int()\r\n# nums = read_int_list()\r\n\r\n# hp, res = [-nums[0]], 0\r\n# for i in range(1, n):\r\n# x = nums[i] - i\r\n# heappush(hp, -x)\r\n# if -hp[0] > x:\r\n# res += -hp[0] - x\r\n# heapreplace(hp, -x)\r\n# print(res)\r\n\r\n\r\n# traditonal DP\r\n\r\n# normal = [x - i for i, x in enumerate(nums)]\r\n\r\n# xs = sorted(set(normal))\r\n# inv = {x: i for i, x in enumerate(xs)}\r\n# m = len(xs)\r\n\r\n# inf = 123456789012345\r\n\r\n# dp = [abs(normal[0] - x) for x in xs]\r\n# for i in range(1, m):\r\n# if dp[i] > dp[i - 1]:\r\n# dp[i] = dp[i - 1]\r\n\r\n# for i in range(1, n):\r\n# x = normal[i]\r\n# np = [inf] * m\r\n# for j in range(m):\r\n# np[j] = min(np[j - 1], dp[j] + abs(x - xs[j]))\r\n# dp = np\r\n\r\n# # print(dp)\r\n# print(min(dp))", "from heapq import *\r\n\r\nn = int(input())\r\nturn = [99**9]\r\nopty = 0\r\nfor i,a in enumerate(map(int,input().split())):\r\n a-= i\r\n optx = -turn[0]\r\n if optx <= a:\r\n heappush(turn, -a)\r\n else:\r\n heappush(turn, -a)\r\n heappop(turn)\r\n heappush(turn, -a)\r\n opty+= optx-a\r\nprint(opty)", "import sys\r\nimport random\r\n\r\ninput = sys.stdin.readline\r\nrd = random.randint(10 ** 9, 2 * 10 ** 9)\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nfor i in range(n):\r\n a[i] -= i\r\nimport heapq\r\nq,ans = [],0\r\nfor i in range(n):\r\n heapq.heappush(q,-a[i])\r\n if -q[0] > a[i]:\r\n ans += -q[0] - a[i]\r\n heapq.heapreplace(q,-a[i])\r\nprint(ans)", "import heapq\r\nn = int(input())\r\nd = list(map(int,input().split()))\r\npq = [-d[0]]\r\nheapq.heapify(pq)\r\nans = 0\r\nfor i in range(1,n):\r\n temp = i - d[i]\r\n heapq.heappush(pq,temp)\r\n if heapq.nsmallest(1,pq)[0] < temp:\r\n ans += temp - heapq.nsmallest(1,pq)[0]\r\n heapq.heappushpop(pq,temp)\r\nprint(ans)" ]
{"inputs": ["7\n2 1 5 11 5 9 11", "5\n5 4 3 2 1", "2\n1 1000", "2\n1000 1", "5\n100 80 60 70 90", "10\n10 16 17 11 1213 1216 1216 1209 3061 3062", "20\n103 103 110 105 107 119 113 121 116 132 128 124 128 125 138 137 140 136 154 158", "1\n1", "5\n1 1 1 2 3", "1\n1000", "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319", "75\n392 593 98 533 515 448 220 310 386 79 539 294 208 828 75 534 875 493 94 205 656 105 546 493 60 188 222 108 788 504 809 621 934 455 307 212 630 298 938 62 850 421 839 134 950 256 934 817 209 559 866 67 990 835 534 672 468 768 757 516 959 893 275 315 692 927 321 554 801 805 885 12 67 245 495", "10\n26 723 970 13 422 968 875 329 234 983", "20\n245 891 363 6 193 704 420 447 237 947 664 894 512 194 513 616 671 623 686 378", "5\n850 840 521 42 169"], "outputs": ["9", "12", "0", "1000", "54", "16", "43", "0", "3", "0", "12423", "17691", "2546", "3208", "1485"]}
UNKNOWN
PYTHON3
CODEFORCES
14
20c1e9422796af441c387c631d2715ab
Code Parsing
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string *s*, consisting of characters "x" and "y", and uses two following operations at runtime: 1. Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. 1. Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string *s*, and the algorithm works as follows: 1. If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string. 1. If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string *s*. The first line contains a non-empty string *s*. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string. In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string *s*. Sample Input x yxyxy xxxxxy Sample Output x y xxxx
[ "s=input()\r\nif s.count('x')>s.count('y'):\r\n s=\"x\"*(s.count('x')-s.count('y'))\r\nelse:\r\n s=\"y\"*(s.count('y')-s.count('x'))\r\nprint(s)\r\n", "string = input()\r\n\r\nx_count = string.count(\"x\")\r\ny_count = string.count(\"y\")\r\n\r\nif x_count > y_count:\r\n for _ in range(x_count - y_count):\r\n print(\"x\", end=\"\")\r\nelif x_count < y_count:\r\n for _ in range(y_count - x_count):\r\n print(\"y\",end=\"\")\r\nelse:\r\n print(\"\")\r\n\r\n", "s = input()\r\nk = s.count('x') - s.count('y')\r\n\r\nprint('x'*k + 'y'*-k)", "s = input()\r\nx = 0\r\ny = 0\r\nfor i in range(len(s)):\r\n if s[i] == 'x':\r\n x += 1\r\n else:\r\n y += 1\r\n_min = min(x, y)\r\nx -= _min\r\ny -= _min\r\nprint('x'*x + 'y'*y)\r\n", "n=list(input())\r\ncountx=n.count('x')\r\ncounty=n.count('y')\r\nstr1=str('x'*countx)+str('y'*county)\r\nl=[]\r\nl=l+list(str1)\r\nflag=0\r\nif ('x' in l and 'y' in l):\r\n flag=0\r\n if countx>county:\r\n print('x'*(countx-county))\r\n elif countx<county:\r\n print('y'*(county-countx))\r\n else:\r\n print('')\r\nelse:\r\n print(str1)\r\n \r\n", "from collections import Counter\r\nfrom sys import stdin\r\ninput=stdin.readline\r\nstring=input() ; dic=Counter(string)\r\nif len(dic.keys())>1:\r\n if dic[\"x\"]>=dic[\"y\"]:\r\n print(\"x\"*(dic[\"x\"]-dic[\"y\"]))\r\n else:\r\n print(\"y\"*abs(dic[\"x\"]-dic[\"y\"]))\r\nelse:\r\n x=list(dic.keys())[0]\r\n print(x*dic[x])\r\n", "s=input()\r\na=s.find(\"yx\")\r\nb=s.find(\"xy\")\r\nif a==-1 and b==-1:\r\n print(s)\r\nelse:\r\n l=list(s)\r\n x=l.count('x')\r\n y=l.count('y')\r\n \r\n d=abs(x-y)\r\n if x>y:\r\n print(\"x\"*d)\r\n else:\r\n print(\"y\"*d)\r\n", "s=input()\r\nx1=s.count('x')\r\ny1=s.count('y')\r\nprint(['y'*(y1-x1),'x'*(x1-y1)][x1>y1])", "x = input()\r\nxL = list(x)\r\nequis = 0\r\nye = 0\r\nf = \"\"\r\nfor q in range(0,len(x)):\r\n\tif(xL[q] == \"y\"):\r\n\t\tye = ye + 1\r\n\telif(xL[q] == \"x\"):\r\n\t\tequis = equis + 1\r\nif(equis == ye):\r\n\tprint(\" \")\r\nelif(equis > ye):\r\n\tm = equis - ye\r\n\tfor j in range(m):\r\n\t\tf = f + \"x\"\r\nelif(ye > equis):\r\n\tm = ye - equis\r\n\tfor j in range(m):\r\n\t\tf = f + \"y\"\r\nprint(f)", "def solve(s):\n cx = 0\n cy = 0\n\n for i in s:\n if i=='x':\n cx+=1\n else:\n cy+=1\n\n if cy > cx:\n return(\"y\"*(cy-cx))\n if cy==cx:\n return \"\"\n else:\n return(\"x\"*(cx-cy))\n\ns = input()\nprint(solve(s))\n \t\t \t\t \t \t\t \t\t \t \t\t \t \t\t \t", "s=input()\r\nn=len(s)\r\ni=0\r\nans=\"\"\r\nc1=s.count('x')\r\nc2=s.count('y')\r\nif c1>c2:\r\n ans='x'*(c1-c2)\r\nelif c2>c1:\r\n ans='y'*(c2-c1) \r\nelse:\r\n ans=\"\" \r\nprint(ans) \r\n", "s = input()\r\nif s.count(\"x\") > s.count(\"y\"): print(\"x\"*(s.count(\"x\")-s.count(\"y\")))\r\nelse: print(\"y\"*(s.count(\"y\")-s.count(\"x\")))\r\n", "s = input().strip()\r\ni = 0\r\nx = 0\r\ny = 0\r\nwhile i < len(s):\r\n if s[i] == 'x':\r\n x += 1\r\n else:\r\n y += 1\r\n i += 1\r\nif x > y:\r\n print(''.join(['x' for i in range(x-y)]))\r\nelse:\r\n print(''.join(['y' for i in range(y-x)]))", "\r\n\r\n\r\ns = input()\r\n\r\nx = 0\r\ny = 0\r\nfor i in range(len(s)):\r\n if s[i] == 'x':\r\n x += 1\r\n else:\r\n y += 1\r\n\r\n\r\nif x > y :\r\n print('x' * (x - y))\r\n\r\nelif x < y :\r\n print('y' * (y - x))\r\n\r\nelse:\r\n print('')\r\n\r\n", "s=input()\r\nl=list()\r\nfor i in s:\r\n if i=='y' and len(l)!=0 and l[-1]=='x':\r\n l.pop()\r\n elif i=='x' and len(l)!=0 and l[-1]=='y':\r\n l.pop()\r\n else:\r\n l.append(i)\r\nprint(''.join(l))", "\r\ns=input()\r\na=s.count(\"x\")\r\nb=s.count(\"y\")\r\nm=min(a,b)\r\na-=m \r\nb-=m\r\nprint(\"x\"*a+\"y\"*b)", "a=input()\r\nx=a.count('x')\r\ny=len(a)-x\r\nprint(('yx'[x>y])*abs(x-y))", "n=input()\r\nstack = []\r\nfor i in n:\r\n if stack==[]:\r\n stack.append(i)\r\n else:\r\n s = stack.pop()\r\n if s=='y' and i=='x':\r\n pass\r\n elif s=='x' and i=='y':\r\n pass\r\n else:\r\n stack.append(s)\r\n stack.append(i)\r\nfor i in stack:\r\n print(i,end='')", "s=input()\na=s.count(\"x\")\nb=s.count(\"y\")\n\nif a>b:print(\"x\"*(a-b))\nelse:print(\"y\"*(b-a))\n\t \t \t\t\t \t\t\t\t\t \t\t\t\t \t\t \t\t\t \t", "s = input()\n\nx_count, y_count = 0, 0\n\nfor c in s:\n if(c == 'x'): x_count += 1\n else: y_count += 1\n\noutput = \"\"\nif(x_count > y_count):\n output = \"x\" * (x_count - y_count)\nelse:\n output = \"y\" * (y_count - x_count)\n\nprint(output)\n", "s = input()\r\ncx = cy = 0\r\n\r\nfor i in s:\r\n if i == 'x':\r\n cx+=1\r\n else:\r\n cy += 1\r\n\r\nr = \"\"\r\n\r\nif(cx>cy):\r\n for i in range(cx-cy):\r\n r+='x'\r\n\r\nif(cx<cy):\r\n for i in range(cy-cx):\r\n r+='y'\r\n\r\nprint(r)", "s = input()\r\ncount1, count2 = s.count('x'), s.count('y')\r\nif count1 > count2:\r\n element = 'x'\r\nelse:\r\n element = 'y'\r\nprint(element * abs(count1 - count2))", "# link: https://codeforces.com/problemset/problem/255/B\r\n\r\ndef solve(s):\r\n n = len(s)\r\n if n == 1:\r\n return (s)\r\n # else:\r\n s = list(s)\r\n memo = {'x': s.count('x'), 'y': s.count('y') }\r\n if memo['x'] > memo['y']:\r\n return \"x\"*(memo['x'] - memo['y'])\r\n else: \r\n return \"y\"*(memo['y'] - memo['x'])\r\n\r\n# xyyxyyyyyxxxxxxxyxyxyyxyyxyyxxyxyxyxxxyxxy\r\n\r\nif __name__ == \"__main__\":\r\n s = input()\r\n result = solve(s)\r\n print(result)", "# Enter your code here. Read input from STDIN. Print output to STDOUT\n \nif __name__ == '__main__':\n\tt = input().strip()\n\tcnt = {'x': 0, 'y': 0}\n\tfor c in t:\n\t\tcnt[c] += 1\n\tif cnt['x'] > cnt['y']:\n\t\tcnt['x'] -= cnt['y']\n\t\tprint('x'*cnt['x'])\n\telse:\n\t\tcnt['y'] -= cnt['x']\n\t\tprint('y'*cnt['y'])\n\t\t \t \t \t \t \t\t \t\t \t \t", "s = input()\r\nx = 0\r\ny = 0\r\nfor i in s:\r\n if i==\"x\":\r\n x+=1\r\n else:\r\n y+=1\r\nif x>y:\r\n print(\"x\"*(x-y))\r\nelse:\r\n print(\"y\"*(y-x))", "import math\r\n\r\n\r\n\r\ndef main_function():\r\n s = input()\r\n coun_x = 0\r\n count_y = 0\r\n for i in range(len(s)):\r\n if s[i] == \"x\":\r\n coun_x += 1\r\n else:\r\n count_y += 1\r\n if count_y == coun_x:\r\n print(\"\")\r\n elif coun_x > count_y:\r\n print(\"x\" * (coun_x - count_y))\r\n else:\r\n print(\"y\" * (count_y - coun_x))\r\n\r\n\r\n\r\n\r\n\r\nmain_function()", "def solve(case):\n word = input()\n x_count = word.count('x')\n y_count = word.count('y')\n if (x_count > y_count):\n print (('x')*(x_count - y_count))\n else:\n print (('y')*(y_count - x_count))\n \n\ndef main():\n case = 0\n solve(case)\n\nmain()\n\n \t \t \t \t \t \t \t\t \t\t\t \t\t \t", "s = input()\r\nxS = s.count('x')\r\nyS = s.count('y')\r\nif xS >= yS:\r\n print('x' * (xS - yS))\r\nelse:\r\n print('y' * (yS - xS))", "from sys import stdin ,stdout\r\nfrom os import path\r\nrd = lambda:stdin.readline().strip()\r\nwr = stdout.write\r\nif(path.exists('input.txt')):\r\n stdin = open(\"input.txt\",\"r\")\r\nimport time ,math\r\n#why sorting suffix array although we go through the whole array any way till we find the pattern\r\n#------------------------------------=\r\nz = rd()\r\nx = z.count('x')\r\ny = z.count('y')\r\nif x >= y:\r\n x = x-y\r\n y =0 \r\nelse:\r\n y = y - x \r\n x = 0 \r\nprint(('x'*x)+('y'*y)) ", "s = input()\r\n \r\n\r\nif s.count('x')>s.count('y'):\r\n s = (s.count('x')-s.count('y'))*\"x\"\r\nelse:\r\n s = (s.count('y')-s.count('x'))*\"y\"\r\nprint(s)\r\n", "from sys import stdin\r\nfrom collections import defaultdict\r\ninput = stdin.readline\r\n# ~ T = int(input())\r\nT = 1\r\nfor t in range(1,T + 1):\r\n\ts = input()\r\n\tx = 0; y = 0\r\n\tfor i in s:\r\n\t\tx += (i == 'x')\r\n\t\ty += (i == 'y')\r\n\tif x > y:\r\n\t\tfor i in range((x - y)):\r\n\t\t\tprint('x',end = \"\")\r\n\t\r\n\telse:\r\n\t\tfor i in range((y - x)):\r\n\t\t\tprint('y',end = \"\")\r\n\r\n", "a=input()\nx=a.count('x')\ny=len(a)-x\nprint(('yx'[x>y])*abs(x-y))\n \t\t \t \t \t \t\t \t\t \t\t\t\t \t\t\t\t", "from collections import defaultdict, deque, Counter\nfrom functools import lru_cache, reduce \nfrom heapq import heappush, heappop, heapify\nfrom bisect import bisect_right, bisect_left\nfrom random import randint\nfrom fractions import Fraction as frac\nimport math\nimport operator\nimport sys\n \n#sys.stdin = open(\"sleepy.in\", \"r\")\n#sys.stdout = open(\"sleepy.out\",\"w\")\n#input = sys.stdin.readline\n#print = sys.stdout.write\n \nhpop = heappop\nhpush = heappush\nMOD = 10**9 + 7\n \ndef solution():\n # always swap\n line = list(input())\n for i in range(len(line) - 1):\n if line[i] == line[i+1] == \"yx\":\n line[i], line[i+1] = line[i-1], line[i]\n \n stack = []\n for val in line:\n if stack and stack[-1] != val:\n stack.pop()\n else:\n stack.append(val)\n return print(\"\".join(stack))\n\ndef main():\n #test()\n t = 1\n #t = int(input())\n for _ in range(t):\n solution() \n \n#import sys\n#import threading\n#sys.setrecursionlimit(10**6)\n#threading.stack_size(1 << 27)\n#thread = threading.Thread(target=main)\n#thread.start(); thread.join()\nmain()\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\ns = input()[:-1]\r\na = s.count('x')\r\nb = s.count('y')\r\nprint('x'*(a-b) if a >= b else 'y'*(b-a))", "s=input()\r\ny,x=0,0\r\nfor i in s:\r\n if i==\"y\":\r\n y+=1\r\n else:\r\n x+=1\r\nif y>x:\r\n print(\"y\"*(y-x))\r\nelse:\r\n print(\"x\"*(x-y))", "s = input()\r\nx, y = s.count('x'), s.count('y')\r\nprint('x'*(x-y) if x>=y else 'y'*(y-x))\r\n", "from collections import Counter\ns = Counter(input())\ns['x'] = s.get('x',0)\ns['y'] = s.get('y',0)\nm = min(s.values())\nprint('x'*(s['x']-m)+'y'*(s['y']-m))\n\n", "s=input()\r\na = b=0\r\nfor x in s:\r\n if x =='x': a +=1\r\n else: b +=1\r\nif a>=b: print('x'*(a-b))\r\nelse: print('y'*(b-a))", "# cook your dish here\r\nls = input()\r\nx = 0\r\ny = 0\r\nfor i in ls:\r\n if i=='x':\r\n x+=1\r\n else:\r\n y+=1\r\nif x>y:\r\n dif = x-y\r\n for _ in range(dif):\r\n print('x',end='')\r\nelif x<y:\r\n dif = y-x\r\n for _ in range(dif):\r\n print('y',end='')\r\nelse:\r\n print()", "s = input()\n\nnum_x = len(s.replace(\"y\", \"\"))\n1\nnum_y = len(s.replace(\"x\", \"\"))\nif num_x > num_y:\n print((num_x - num_y ) * 'x')\nif num_y > num_x:\n print(- (num_x - num_y ) * 'y')\n\n \t \t \t\t\t \t\t \t\t \t\t\t \t\t \t\t\t\t", "s = input()\r\nxCount = s.count('x')\r\nyCount = len(s)-xCount\r\ndif = xCount - yCount\r\nprint(('y'*abs(dif),'x'*dif)[dif > 0])", "import sys\r\nrln=sys.stdin.buffer.readline\r\nrl=lambda:rln().rstrip(b'\\r\\n').rstrip(b'\\n')\r\nri=lambda:int(rln())\r\nrif=lambda:[*map(int,rln().split())]\r\nrt=lambda:rl().decode()\r\nrtf=lambda:rln().decode().split()\r\ninf=float('inf')\r\ndir4=[(-1,0),(0,1),(1,0),(0,-1)]\r\ndir8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]\r\nYES,NO,Yes,No,yes,no='YES','NO','Yes','No','yes','no'\r\n\r\ns=rt()\r\nx=s.count('x')\r\ny=len(s)-x\r\nif x<y:\r\n print('y'*(y-x))\r\nelse:\r\n print('x'*(x-y))\r\n", "s = input()\nxs = s.count(\"x\")\nys = s.count(\"y\")\n\nif xs > ys:\n print(\"x\" * (xs - ys))\nelse:\n print(\"y\" * (ys - xs))", "def solve():\r\n s = input()\r\n x = s.count(\"x\")\r\n y = s.count(\"y\")\r\n if x >= y:\r\n print(\"x\" * (x - y))\r\n else:\r\n print(\"y\" * (y - x))\r\n\r\n\r\ntt = 1\r\nfor _ in range(tt):\r\n solve()\r\n", "# Problem Link: https://codeforces.com/problemset/problem/255/B\r\n# Problem Status:\r\n# ---------------------- SEPARATOR ----------------------\r\ndef TheAmazingFunction(S: str):\r\n X_count = 0\r\n Y_count = 0\r\n for i in S:\r\n if i == 'x':\r\n X_count += 1\r\n else:\r\n Y_count += 1\r\n if X_count >= Y_count:\r\n S = \"x\"*(X_count-Y_count)\r\n else:\r\n S = \"y\" * (Y_count - X_count)\r\n return S\r\n\r\n\r\n# def checkStepOne(S: str):\r\n# if S.find(\"yx\") != -1 or S.find(\"xy\") != -1:\r\n# return True\r\n# else:\r\n# return False\r\n\r\n\r\n# ---------------------- SEPARATOR ----------------------\r\nS_ = input()\r\nprint(TheAmazingFunction(S_))\r\n# ---------------------- SEPARATOR ----------------------\r\n", "L=input()\r\n\r\n\r\ns1=L.count(\"x\")\r\ns2=L.count(\"y\")\r\nx=max(s1,s2)\r\nv=abs(s1-s2)\r\nif x==L.count(\"x\"):\r\n print(\"x\"*v)\r\nelse:\r\n print(\"y\"*v)", "arr = list (input()) \r\nstack = list ()\r\nfor i in arr: \r\n if len(stack) == 0 or stack[-1] == i: \r\n stack.append(i)\r\n else:\r\n stack.pop()\r\nprint (*stack,sep= '')\r\n", "n = input()\r\nx = 0\r\ny = 0\r\nfor i in n:\r\n x += (i == 'x')\r\n y += (i == 'y')\r\nprint(((x - y) * 'x' if x > y else (y - x) * 'y'))", "s = input()\r\nx = s.count(\"x\")\r\ny = s.count(\"y\")\r\n\r\nif x > y :\r\n length = x - y; char = \"x\"\r\nelse :\r\n length = y - x; char = \"y\"\r\n\r\nL = [char for i in range(length)]\r\n\r\nprint (\"\".join(L))", "\ns=input()\ncx = 0\ncy = 0\nfor c in s:\n if c == \"x\":\n cx+=1\n else:\n cy+=1\n\nif cx > cy:\n out = \"x\"*(cx-cy)\nelse:\n out = \"y\"*(cy-cx)\nprint(out)\n\n\t \t\t\t\t \t \t \t \t \t \t \t", "s = list(input())\r\nx = s.count('x')\r\ny = s.count('y')\r\nif x < y:\r\n print('y' * (y - x))\r\nelse:\r\n print('x' * (x - y))", "s=input()\r\nx=0\r\ny=0\r\nfor i in s:\r\n if i=='x':\r\n x+=1\r\n else:\r\n y+=1\r\nif x-y>=0:\r\n print('x'*(x-y))\r\nelse:\r\n print('y'*(y-x))\r\n\r\n ", "# /**\r\n# * author: brownfox2k6\r\n# * created: 23/05/2023 21:12:02 Hanoi, Vietnam\r\n# **/\r\n\r\ns = input()\r\n\r\nx = s.count(\"x\")\r\ny = s.count(\"y\")\r\n\r\nif (x > y):\r\n print('x' * (x-y))\r\nelse:\r\n print('y' * (y-x))", "s=input()\r\na=s.count(\"x\")\r\nb=s.count(\"y\")\r\n\r\nif a>b:print(\"x\"*(a-b))\r\nelse:print(\"y\"*(b-a))" ]
{"inputs": ["x", "yxyxy", "xxxxxy", "yxyyxyyx", "yxxyxyx", "xxx", "xxyxx", "xxxyx", "yxxxx", "xyyxyyyyyxxxxxxxyxyxyyxyyxyyxxyxyxyxxxyxxy", "xyyxyyyyyxxxxxxxyxyxyyxyyxyyxxyxyxyxxxyxxy", "xxxxxxxxxxxyxyyxxxxyxxxxxyxxxxxyxxxxxxxxyx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"], "outputs": ["x", "y", "xxxx", "yy", "x", "xxx", "xxx", "xxx", "xxx", "xx", "xx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"]}
UNKNOWN
PYTHON3
CODEFORCES
54
20c573c0f46f02b35925d1e59ce6fc1e
Voting
There are *n* employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated: 1. Each of *n* employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee *n*. If at the moment when it's time for the *i*-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting). 1. When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end. 1. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with *n* who are still eligible to vote make their statements. 1. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction. You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote. The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of employees. The next line contains *n* characters. The *i*-th character is 'D' if the *i*-th employee is from depublicans fraction or 'R' if he is from remocrats. Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win. Sample Input 5 DDRRR 6 DDRRRR Sample Output D R
[ "import sys\r\nimport math\r\nfrom bisect import bisect_right as br\r\nfrom collections import deque\r\n#from statistics import mode\r\n\r\nfrom itertools import combinations as cb\r\n\r\ndef int_arr(): return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\ndef str_arr(): return list(map(str, sys.stdin.readline().strip().split()))\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\n\r\n\r\n#sys.stdout =open('Voting/output.txt', 'w')\r\n#sys.stdin = open('Voting/input.txt', 'r')\r\n\r\nn=int(input())\r\nst=input()\r\n\r\n\r\nd=deque()\r\nr=deque()\r\n\r\nfor i in range(n):\r\n if st[i]==\"D\":\r\n d.append(i)\r\n else:\r\n r.append(i)\r\n\r\nwhile d and r:\r\n dl=d.popleft()\r\n rl=r.popleft()\r\n\r\n if dl<rl:\r\n d.append(dl+n)\r\n else:\r\n r.append(rl+n)\r\n\r\nif d:\r\n print(\"D\")\r\nelse:\r\n print(\"R\")\r\n\r\n\r\n", "n = int(input())\r\ns = list(input())\r\nr, d =0, 0\r\nwhile(True):\r\n\tt=0\r\n\tfor i in range(n):\r\n\t\tif s[i]=='D':\r\n\t\t\tif d>0:\r\n\t\t\t\ts[i]='0'\r\n\t\t\t\td-=1\r\n\t\t\t\tt+=1\r\n\t\t\telse:\r\n\t\t\t\tr+=1\r\n\t\tif s[i]=='R':\r\n\t\t\tif r>0:\r\n\t\t\t\ts[i]='0'\r\n\t\t\t\tr-=1\r\n\t\t\t\tt+=1\r\n\t\t\telse:\r\n\t\t\t\td+=1\r\n\tif t==0:\r\n\t\tfor i in range(n):\r\n\t\t\tif s[i]!='0':\r\n\t\t\t\tprint(s[i])\r\n\t\t\t\texit()", "from collections import deque\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\ns = list(input().rstrip())\r\nq = deque([(i & 2) - 1 for i in s])\r\nc = 0\r\nz = [0] * 2\r\nfor i in s:\r\n z[(i & 2) // 2] += 1\r\nwhile min(z):\r\n u = q.popleft()\r\n if c * u >= 0:\r\n q.append(u)\r\n else:\r\n z[(u + 1) // 2] -= 1\r\n c += u\r\nans = \"D\" if z[0] else \"R\"\r\nprint(ans)", "from queue import PriorityQueue\r\nfrom queue import Queue\r\nimport math\r\nfrom collections import *\r\nimport sys\r\nimport operator as op\r\nfrom functools import reduce\r\n \r\n# sys.setrecursionlimit(10 ** 6)\r\nMOD = int(1e9 + 7)\r\ninput = sys.stdin.readline\r\nii = lambda: list(map(int,input().strip().split()))\r\nist= lambda: list(input().strip())\r\n \r\n \r\nMOD = int(1e9 + 7)\r\ninput = sys.stdin.readline\r\nii = lambda: list(map(int,input().strip().split()))\r\nist= lambda: list(input().strip())\r\n \r\n \r\nn, =ii()\r\ns = input()\r\nr, d = deque(), deque()\r\nfor k in range(n):\r\n\tif s[k] == \"R\":\r\n\t\tr.appendleft(k)\r\n\telse:\r\n\t\td.appendleft(k)\r\nwhile len(r) and len(d):\r\n\tw1= r.pop()\r\n\tw2= d.pop()\r\n\tif w1 < w2:\r\n\t\tr.appendleft(w1 + n)\r\n\telse:\r\n\t\td.appendleft(w2 + n)\r\nprint(['R', 'D'][len(d) > 0])\r\n ", "from collections import deque\r\nd = deque([])\r\nr = deque([])\r\nn = int(input())\r\ns = input()\r\nq = [1] * n\r\nfor i in range(n):\r\n if s[i] == \"D\":\r\n d.append(i)\r\n else:\r\n r.append(i)\r\ne = deque([*range(n)])\r\nwhile r and d:\r\n for j in range(len(e)):\r\n i = e.popleft()\r\n if q[i]:\r\n e.append(i)\r\n if s[i] == \"D\":\r\n d.append(d.popleft())\r\n if r:\r\n q[r.popleft()] = 0\r\n else:\r\n r.append(r.popleft())\r\n if d:\r\n q[d.popleft()] = 0\r\nprint(\"D\" if d else \"R\")", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom bisect import *\r\n\r\nN = int(input())\r\nS = [c for c in input()]\r\n\r\nwhile True:\r\n d,r=0,0\r\n ds,rs=[],[]\r\n for i in range(N):\r\n if S[i]=='D':\r\n while d<i:\r\n d+=1\r\n while d<N and S[d]!='R':\r\n d+=1\r\n if d==N:\r\n if rs:\r\n S[rs.pop()]=''\r\n else:\r\n exit(print('D'))\r\n else:\r\n S[d]=''\r\n ds.append(i)\r\n elif S[i]=='R':\r\n while r<i:\r\n r+=1\r\n while r<N and S[r]!='D':\r\n r+=1\r\n if r==N:\r\n if ds:\r\n S[ds.pop()]=''\r\n else:\r\n exit(print('R'))\r\n else:\r\n S[r]=''\r\n rs.append(i)\r\n\r\n #print(S)\r\n", "from collections import deque\r\n\r\nn = int(input())\r\n\r\nreps = list(input().rstrip())\r\n\r\nd_ind = deque()\r\nr_ind = deque()\r\n\r\nfor i in range(n):\r\n if reps[i] == 'D':\r\n d_ind.append(i)\r\n else:\r\n r_ind.append(i)\r\n\r\nwhile len(r_ind) and len(d_ind):\r\n\r\n if d_ind[0] < r_ind[0]:\r\n r_ind.popleft()\r\n d_ind.append(d_ind.popleft()+n)\r\n else:\r\n d_ind.popleft()\r\n r_ind.append(r_ind.popleft()+n)\r\n\r\nif len(r_ind):\r\n print(\"R\")\r\nelse:\r\n print(\"D\")\r\n\r\n\r\n\r\n", "from collections import deque\r\n\r\nn, a, mem, inv = int(input()), deque(input()), {'D': 0, 'R': 0}, {'D': 'R', 'R': 'D'}\r\nc = {'D': a.count('D'), 'R': a.count('R')}\r\n\r\nwhile c['D'] and c['R']:\r\n inv_ = inv[a[0]]\r\n if mem[inv_]:\r\n c[a.popleft()] -= 1\r\n mem[inv_] -= 1\r\n else:\r\n mem[a[0]] += 1\r\n a.rotate(-1)\r\n\r\nprint(a[0])\r\n", "import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\n\r\ndef process(S):\r\n count = [0, 0]\r\n while True:\r\n n = len(S)\r\n L2 = []\r\n count2 = [0, 0]\r\n for i in range(n):\r\n if S[i]=='D':\r\n if count[1] > 0:\r\n count[1]-=1\r\n else:\r\n L2.append('D')\r\n count[0]+=1\r\n count2[0]+=1\r\n else:\r\n if count[0] > 0: \r\n count[0]-=1\r\n else:\r\n L2.append('R')\r\n count[1]+=1\r\n count2[1]+=1\r\n if count2[0]==0:\r\n return 'R'\r\n if count2[1]==0:\r\n return 'D'\r\n S = L2\r\n \r\nn = int(input())\r\nS = input().decode()[:-2]\r\nanswer = process(S)\r\nprint(answer) ", "from collections import deque\r\nn=int(input())\r\na=input()\r\nq1=deque()\r\nq2=deque()\r\nfor i in range(n):\r\n if a[i]=='D':\r\n q1.append(i)\r\n else:\r\n q2.append(i)\r\nwhile q1 and q2:\r\n # print(q1[0],q2[0])\r\n if q1[0]<q2[0]:\r\n q2.popleft()\r\n q1.append(n+q1.popleft())\r\n else:\r\n q1.popleft()\r\n q2.append(n+q2.popleft())\r\nif q1:\r\n print(\"D\")\r\nelse:\r\n print(\"R\")", "from collections import deque\r\nn=int(input())\r\ndata,d1,d2=input(),deque(),deque()\r\nfor i in range(n):\r\n if data[i]==\"R\":\r\n d1.append(i)\r\n else:\r\n d2.append(i)\r\nwhile True:\r\n try:\r\n if d1[0] > d2[0]:\r\n d1.popleft()\r\n d2.append(n+d2[0])\r\n d2.popleft()\r\n else:\r\n d2.popleft()\r\n d1.append(n+d2[0])\r\n d1.popleft()\r\n except IndexError:\r\n break\r\nif d1:\r\n print('R')\r\nelse:\r\n print('D')" ]
{"inputs": ["5\nDDRRR", "6\nDDRRRR", "1\nD", "1\nR", "2\nDR", "3\nRDD", "3\nDRD", "4\nDRRD", "4\nDRRR", "4\nRDRD", "5\nDRDRR", "4\nRRRR", "5\nRDDRD", "5\nDDRRD", "5\nDRRRD", "5\nDDDDD", "6\nDRRDDR", "7\nRDRDRDD", "7\nRDRDDRD", "7\nRRRDDDD", "8\nRRRDDDDD", "9\nRRRDDDDDR", "9\nRRDDDRRDD", "9\nRRDDDRDRD", "10\nDDRRRDRRDD", "11\nDRDRRDDRDDR", "12\nDRDRDRDRRDRD", "13\nDRDDDDRRRRDDR", "14\nDDRDRRDRDRDDDD", "15\nDDRRRDDRDRRRDRD", "50\nDDDRDRDDDDRRRRDDDDRRRDRRRDDDRRRRDRDDDRRDRRDDDRDDDD", "50\nDRDDDDDDDRDRDDRRRDRDRDRDDDRRDRRDRDRRDDDRDDRDRDRDDR", "100\nRDRRDRDDDDRDRRDDRDRRDDRRDDRRRDRRRDDDRDDRDDRRDRDRRRDRDRRRDRRDDDRDDRRRDRDRRRDDRDRDDDDDDDRDRRDDDDDDRRDD", "100\nRRDRRDDDDDDDRDRRRDRDRDDDRDDDRDDRDRRDRRRDRRDRRRRRRRDRRRRRRDDDRRDDRRRDRRRDDRRDRRDDDDDRRDRDDRDDRRRDRRDD", "6\nRDDRDR", "6\nDRRDRD", "8\nDDDRRRRR", "7\nRRRDDDD", "7\nRDDRRDD", "9\nRDDDRRDRR", "5\nRDRDD", "5\nRRDDD", "8\nRDDRDRRD", "10\nDRRRDDRDRD", "7\nDRRDDRR", "12\nRDDDRRDRRDDR", "7\nRDRDDDR", "7\nDDRRRDR", "10\nDRRDRDRDRD", "21\nDDDDRRRRRDRDRDRDRDRDR", "11\nRDDDDDRRRRR", "10\nRDDDRRRDDR", "4\nRDDR", "7\nRDRDDRD", "8\nRDDDRRRD", "16\nDRRDRDRDRDDRDRDR", "8\nDRRDRDRD", "6\nRDDDRR", "10\nDDRRRRRDDD", "7\nDDRRRRD", "12\nRDDRDRDRRDRD", "9\nDDRRRDRDR", "20\nRDDRDRDRDRRDRDRDRDDR", "7\nRRDDDRD", "12\nDRRRRRRDDDDD", "12\nRDRDDRDRDRDR", "6\nDDDDDD", "10\nRRRDDRDDDD", "40\nRDDDRDDDRDRRDRDRRRRRDRDRDRDRRDRDRDRRDDDD", "50\nRRDDDRRDRRRDDRDDDDDRDDRRRRRRDRDDRDDDRDRRDDRDDDRDRD", "5\nRDRDR", "9\nDRRDRDDRR", "6\nDRRRDD", "10\nDDDDRRRRRR", "9\nRRDDDDRRD"], "outputs": ["D", "R", "D", "R", "D", "D", "D", "D", "R", "R", "D", "R", "D", "D", "R", "D", "D", "R", "D", "R", "D", "R", "R", "D", "D", "D", "D", "D", "D", "D", "D", "D", "D", "R", "D", "R", "R", "R", "D", "R", "R", "R", "R", "R", "R", "D", "D", "R", "R", "R", "D", "D", "R", "D", "R", "R", "R", "D", "D", "R", "D", "R", "D", "D", "R", "D", "D", "R", "R", "D", "R", "R", "R", "D", "D"]}
UNKNOWN
PYTHON3
CODEFORCES
11
20ca84dc7382a495acdf33245bff71ca
Bear and Fair Set
Limak is a grizzly bear. He is big and dreadful. You were chilling in the forest when you suddenly met him. It's very unfortunate for you. He will eat all your cookies unless you can demonstrate your mathematical skills. To test you, Limak is going to give you a puzzle to solve. It's a well-known fact that Limak, as every bear, owns a set of numbers. You know some information about the set: - The elements of the set are distinct positive integers. - The number of elements in the set is *n*. The number *n* is divisible by 5. - All elements are between 1 and *b*, inclusive: bears don't know numbers greater than *b*. - For each *r* in {0,<=1,<=2,<=3,<=4}, the set contains exactly elements that give remainder *r* when divided by 5. (That is, there are elements divisible by 5, elements of the form 5*k*<=+<=1, elements of the form 5*k*<=+<=2, and so on.) Limak smiles mysteriously and gives you *q* hints about his set. The *i*-th hint is the following sentence: "If you only look at elements that are between 1 and *upTo**i*, inclusive, you will find exactly *quantity**i* such elements in my set." In a moment Limak will tell you the actual puzzle, but something doesn't seem right... That smile was very strange. You start to think about a possible reason. Maybe Limak cheated you? Or is he a fair grizzly bear? Given *n*, *b*, *q* and hints, check whether Limak can be fair, i.e. there exists at least one set satisfying the given conditions. If it's possible then print ''fair". Otherwise, print ''unfair". The first line contains three integers *n*, *b* and *q* (5<=≤<=*n*<=≤<=*b*<=≤<=104, 1<=≤<=*q*<=≤<=104, *n* divisible by 5) — the size of the set, the upper limit for numbers in the set and the number of hints. The next *q* lines describe the hints. The *i*-th of them contains two integers *upTo**i* and *quantity**i* (1<=≤<=*upTo**i*<=≤<=*b*, 0<=≤<=*quantity**i*<=≤<=*n*). Print ''fair" if there exists at least one set that has all the required properties and matches all the given hints. Otherwise, print ''unfair". Sample Input 10 20 1 10 10 10 20 3 15 10 5 0 10 5 10 20 2 15 3 20 10 Sample Output fair fair unfair
[ "from sys import stdin\r\ninput=lambda :stdin.readline()[:-1]\r\n\r\nn,b,q=map(int,input().split())\r\nt=[(b,n)]\r\nfor _ in range(q):\r\n x,y=map(int,input().split())\r\n t.append((x,y))\r\n\r\nt.sort(key=lambda x:x[0])\r\ntask=[]\r\ntmp=1\r\nnow=0\r\nng=False\r\nfor x,y in t:\r\n if x+1==tmp:\r\n if y==now:\r\n pass\r\n else:\r\n ng=True\r\n continue\r\n if y-now<0:\r\n ng=True\r\n cnt=[0]*5\r\n for i in range(tmp,x+1):\r\n cnt[i%5]+=1\r\n task.append((cnt,y-now))\r\n tmp=x+1\r\n now=y\r\n\r\nfor bit in range(1,1<<5):\r\n use=[]\r\n for i in range(5):\r\n if (bit>>i)&1:\r\n use.append(i)\r\n tmp=0\r\n for cnt,m in task:\r\n res=0\r\n for i in use:\r\n res+=cnt[i]\r\n tmp+=min(m,res)\r\n \r\n if tmp<len(use)*n//5:\r\n ng=True\r\n\r\nif ng:\r\n print('unfair')\r\nelse:\r\n print('fair')", "I = lambda: [int(i) for i in input().split()]\r\n\r\nn, b, m = I()\r\na = [(0, 0)] + sorted([I() for _ in range(m)]) + [(b, n)]\r\n\r\ndef solve():\r\n for S in range(32):\r\n sm = 0\r\n for j in range(1, m + 2):\r\n l = a[j - 1][0] + 1\r\n r = a[j][0]\r\n w = a[j][1] - a[j - 1][1]\r\n if w < 0: return 1\r\n sm += min(sum(S >> (i % 5) & 1 for i in range(l, r + 1)), w)\r\n if sm < n / 5 * bin(S).count(\"1\"): return 1\r\n return 0\r\n\r\nprint(\"un\" * solve() + \"fair\")", "I = lambda: [int(i) for i in input().split()]\r\n\r\nn, b, m = I()\r\na = [(0, 0)] + sorted([I() for _ in range(m)]) + [(b, n)]\r\n\r\ndef solve():\r\n for S in range(32):\r\n sm = 0\r\n for (l, x), (r, y) in zip(a, a[1:]):\r\n if y - x < 0: return 1\r\n sm += min(sum(S >> (i % 5) & 1 for i in range(l + 1, r + 1)), y - x)\r\n if sm < n / 5 * bin(S).count(\"1\"): return 1\r\n return 0\r\n\r\nprint(\"un\" * solve() + \"fair\")" ]
{"inputs": ["10 20 1\n10 10", "10 20 3\n15 10\n5 0\n10 5", "10 20 2\n15 3\n20 10", "15 27 2\n6 4\n23 5", "50 7654 4\n1273 11\n6327 38\n1244 3\n5208 22", "50 7654 4\n2899 15\n3848 26\n2718 12\n5511 36", "50 7654 4\n4881 20\n4957 6\n4764 50\n944 44", "50 6457 1\n945 41", "500 5000 5\n1289 221\n694 178\n2179 454\n160 11\n1398 232", "500 5000 10\n2905 421\n573 82\n1602 205\n4523 491\n970 100\n3810 453\n2553 418\n2033 364\n1664 245\n1924 311", "500 5000 20\n875 49\n73 16\n2405 136\n811 33\n2477 140\n3475 303\n4640 496\n4025 369\n4482 440\n3475 272\n3594 346\n3945 368\n3807 346\n2605 159\n4045 382\n2861 270\n4488 448\n1894 61\n2388 113\n4071 383", "500 5000 50\n687 73\n3816 389\n4333 436\n1660 177\n2238 231\n2936 312\n899 96\n541 55\n4218 425\n4512 457\n1302 132\n2322 239\n688 73\n4423 449\n2765 284\n3755 382\n4192 422\n2718 277\n2254 231\n1354 140\n4891 490\n2722 277\n344 35\n4774 479\n988 101\n2530 256\n3679 375\n3258 341\n1870 201\n1391 146\n643 68\n1040 105\n2607 266\n906 97\n4790 480\n2390 245\n3101 326\n2616 267\n1064 107\n1091 110\n1735 187\n2434 247\n3887 397\n1335 137\n2073 219\n450 45\n480 47\n3519 359\n157 16\n4316 434", "15 40 3\n2 0\n13 9\n4 1", "15 41 3\n16 8\n14 2\n40 9", "15 40 3\n8 0\n38 14\n28 9", "15 40 3\n1 9\n24 0\n35 7", "15 40 2\n23 4\n36 7", "15 41 2\n19 12\n2 0", "15 40 2\n35 13\n36 14", "15 40 2\n15 4\n24 4", "5 6 2\n4 4\n5 4", "10 20 4\n3 3\n5 3\n9 7\n17 7", "5 10 3\n2 1\n5 4\n7 4", "5 30 10\n1 1\n5 1\n6 2\n10 2\n11 3\n15 3\n16 4\n20 4\n21 5\n30 5", "10 13 2\n3 3\n5 4", "5 10 3\n1 1\n5 1\n9 5", "10 14 2\n4 4\n5 4"], "outputs": ["fair", "fair", "unfair", "unfair", "fair", "fair", "unfair", "fair", "fair", "fair", "unfair", "fair", "fair", "unfair", "fair", "unfair", "unfair", "fair", "fair", "fair", "unfair", "unfair", "unfair", "unfair", "unfair", "unfair", "unfair"]}
UNKNOWN
PYTHON3
CODEFORCES
3
20e1b109cf2c373246172c975ecfd79e
Polo the Penguin and Matrix
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so. The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). Sample Input 2 2 2 2 4 6 8 1 2 7 6 7 Sample Output 4 -1
[ "n,m,d=map(int,input().split())\r\nans=True\r\nhehe=-1\r\nmat=[]\r\nfor i in range(n):\r\n row=list(map(int,input().split()))\r\n for k in row:\r\n mat.append(k)\r\n for j in range(m):\r\n if i==0 and j==0:\r\n hehe=row[j]%d\r\n continue\r\n if row[j]%d!=hehe:\r\n ans=False\r\nif not ans:\r\n print(-1)\r\nelse:\r\n maxxx=-1\r\n mat.sort()\r\n l=len(mat)//2\r\n mid=mat[l]\r\n summ=0\r\n for h in mat:\r\n summ+=abs(mid-h)//d\r\n print(summ)\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "N = 10**4 + 1\r\n\r\nn, m, d = map(int,input().split())\r\n\r\na = []\r\nfor i in range(n):\r\n a = a + (list(map(int,input().split())))\r\n\r\na.sort()\r\nmid = n*m//2\r\n\r\nr = a[0]%d\r\nflag = False\r\nres = 0\r\nfor i in range(n*m):\r\n if(a[i]%d!=r):\r\n flag = True\r\n break\r\n res += abs(a[i]-a[mid])//d\r\nif(flag):\r\n print(-1)\r\nelse:\r\n print(res)", "n,m,d=(int(i) for i in input().split())\r\nl=[]\r\nfor i in range(n):\r\n l+=[int(i) for i in input().split()]\r\nl=sorted(l)\r\nmod=l[0]%d\r\nfor i in range(n*m):\r\n if(l[i]%d!=mod):\r\n mod=-1\r\n break\r\nif(mod==-1):\r\n print(-1)\r\nelse:\r\n k=l[(n*m)//2]\r\n moves=0\r\n for i in range(n*m):\r\n moves+=(abs(l[i]-k)//d)\r\n print(moves)", "from math import *\r\nn,m,d=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l.extend(list(map(int,input().split())))\r\nx=inf\r\nfor i in range(n*m):\r\n c=0\r\n for j in range(n*m):\r\n c+=abs(l[j]-l[i])\r\n x=min(c,x)\r\nif(x%d==0):\r\n print(x//d)\r\nelse:\r\n print(-1)\r\n", "from collections import Counter\nimport heapq\nimport math\n\nn, m, d = map(int, input().split())\n\nmatrix = []\nheapq.heapify(matrix)\ncnter = Counter()\nfor i in range(n):\n inp = list(map(int, input().split()))\n for i in range(m):\n heapq.heappush(matrix, inp[i])\n cnter[inp[i]] += 1\n\ntimes = 0\npivot = heapq.nlargest(math.ceil(n * m / 2), matrix)[-1]\nrem = pivot % d\nfor i in cnter.items():\n el = i\n if el[0] % d == rem:\n times += abs(el[0] - pivot) // d * el[1]\n else:\n print(-1)\n break\nelse:\n print(times)\n", "n, m, d = [int(x) for x in input().split()]\r\n\r\nnumbers = []\r\nfor i in range(n):\r\n row = [int(x) for x in input().split()]\r\n numbers.extend(row)\r\n\r\nnumbers.sort()\r\nnumbers_count = len(numbers)\r\n\r\nsums_left = [0] * numbers_count\r\nsums_right = [0] * numbers_count\r\nno_way_to_equalize = None\r\nfor i in range(1, numbers_count):\r\n # we go in both directions in this loop, from left to right and from right to left\r\n # for the left pointer we update sums_left[i], from 1 to numbers_count - 1\r\n # for the right pointer we update sums_right[numbers_count - i - 1], from numbers_count - 2 to 0\r\n diff_left_pointer = numbers[i] - numbers[i - 1]\r\n diff_right_pointer = numbers[numbers_count - i] - numbers[numbers_count - i - 1]\r\n if diff_left_pointer % d != 0 or diff_right_pointer % d != 0:\r\n no_way_to_equalize = True\r\n break\r\n sums_left[i] = sums_left[i - 1] + i * (diff_left_pointer // d)\r\n sums_right[numbers_count - i - 1] = sums_right[numbers_count - i] + i * (diff_right_pointer // d)\r\n\r\nif no_way_to_equalize is True:\r\n print(-1)\r\nelse:\r\n total_sums = []\r\n for i in range(numbers_count):\r\n total_sums.append(sums_left[i] + sums_right[i])\r\n print(min(total_sums))\r\n\r\n\r\n", "n, m, d = map(int, input().split())\r\nlst = []\r\nfor i in range(n):\r\n sublist = list(map(int, input().split()))\r\n for j in sublist:\r\n lst.append(j)\r\n\r\nlst.sort()\r\nmid = lst[len(lst) // 2]\r\nans = 0\r\nfor i in lst:\r\n if abs(i - mid) % d != 0:\r\n ans = -1\r\n break\r\n \r\n ans += abs(i - mid) // d\r\n\r\nprint(ans)", "x,y,n=map(int,input().split())\r\na=[]\r\nb=[]\r\nfor i in range(x):\r\n a+=list(map(int,input().split()))\r\nr=a[0]%n\r\ncount=0\r\ncount1=0\r\nfor i in a:\r\n if i%n!=r:\r\n print(-1)\r\n exit()\r\na.sort()\r\ns=0\r\nx=a[(x*y)//2]\r\nfor i in a:\r\n s+=abs(x-i)//n\r\nprint(s)", "'''input\r\n1 2 7\r\n6 7\r\n\r\n'''\r\ndef getints(): return list(map(int, input().strip().split()))\r\ndef impossible():\r\n\tprint(-1)\r\n\texit(0)\r\n\r\nn,m,d = getints()\r\narr = []\r\nfor i in range(n):\r\n\tarr.extend(getints())\r\n\r\nfor i in range(1, len(arr)):\r\n\tif abs(arr[i]-arr[i-1])%d!=0: impossible()\r\n\r\narr.sort()\r\nmedian = arr[len(arr)//2]\r\n\r\nans = 0\r\nfor e in arr:\r\n\tans += abs(median-e)//d\r\nprint(ans)", "import math\r\nimport sys\r\n\r\n#n = int(input())\r\n#n, m = map(int, input().split())\r\n#d = list(map(int, input().split()))\r\nn, m, t = map(int, input().split())\r\nd = []\r\nfor i in range(n):\r\n d += list(map(int, input().split()))\r\n\r\nd.sort()\r\nr = 0\r\nfor i in range(len(d)//2):\r\n if (d[len(d) - i - 1] - d[i])%t == 0:\r\n r += (d[len(d) - i - 1] - d[i])//t\r\n else:\r\n print(-1)\r\n exit()\r\nprint(r)", "n,m,d=map(int,input().split())\r\narr=[]\r\nmat=[]\r\nfor i in range(n):\r\n meri=list(map(int,input().split()))\r\n mat.append(meri)\r\n for j in meri:\r\n arr.append(j)\r\np=1\r\nl=len(arr)\r\nfor i in range(l):\r\n if(abs(arr[i]-arr[0])%d!=0):\r\n p=0\r\n print(-1)\r\n break\r\nif(p):\r\n arr.sort()\r\n s=0\r\n e=l-1\r\n ans=10**17\r\n while(s<=e):\r\n m1=(e-s)//3+s\r\n m2=2*((e-s)//3)+s\r\n t1,t2=0,0\r\n for i in range(n):\r\n for j in range(m):\r\n t1+=abs(mat[i][j]-arr[m1])//d\r\n t2+=abs(mat[i][j]-arr[m2])//d\r\n ans=min(ans,t1,t2)\r\n if(t1>=t2):\r\n s=m1+1\r\n else:\r\n e=m2-1\r\n print(ans)", "from bisect import bisect_left, bisect_right\r\nfrom collections import defaultdict\r\nfrom heapq import heapify, heappop, heappush\r\nfrom math import ceil, log, sqrt\r\nfrom sys import stdin\r\n\r\ninput = stdin.readline\r\n\r\nioint = lambda: int(input())\r\nioarr = lambda: map(int, input().split(\" \"))\r\nprnys = lambda: print(\"YES\")\r\nprnno = lambda: print(\"NO\")\r\n\r\nMAX = 10**9\r\n\r\nT = 1\r\n# T = ioint()\r\nwhile T:\r\n T -= 1\r\n\r\n # n = ioint()\r\n n, m, d = ioarr()\r\n arr = []\r\n for _ in range(n):\r\n arr.extend(ioarr())\r\n\r\n n = len(arr)\r\n\r\n rem = arr[0] % d\r\n for i in range(n):\r\n x = arr[i]\r\n if x % d != rem:\r\n print(-1)\r\n exit()\r\n arr[i] = x // d\r\n\r\n arr.sort()\r\n ans = 0\r\n for x in arr:\r\n ans += x - arr[0]\r\n\r\n for i in range(1, n):\r\n nb = i\r\n na = n - i\r\n j = arr[i] - arr[i - 1]\r\n df = nb - na\r\n val = ans + j * df\r\n\r\n ans = min(ans, val)\r\n\r\n print(ans)\r\n", "n,m,d = map(int,input().split())\r\ndd=[]\r\nfor _ in range(n):\r\n arr = list(map(int,input().split()))\r\n dd+=arr\r\ndd=sorted(dd)\r\n#print(dd)\r\nfor i in range(len(dd)):\r\n #print((dd[i]-dd[0])%d)\r\n if (dd[i]-dd[0])%d!=0:\r\n # print(dd[i])\r\n print(-1)\r\n break\r\nelse:\r\n ll=[]\r\n tt =set(dd)\r\n tt = list(tt)\r\n sum=0\r\n i=0\r\n while(i<len(tt)):\r\n for j in range(len(dd)):\r\n sum+=abs(dd[j]-tt[i])\r\n ll.append(sum)\r\n sum=0\r\n i+=1\r\n #print(ll)\r\n print(min(ll)//d)", "n,m,d = map(int,input().split())\r\na = []\r\ns = set()\r\nfor i in range(n):\r\n\ta += list(map(int,input().split()))\r\na.sort()\r\nmid = a[len(a)//2]\r\nans = 0\r\nflag = True\r\nfor i in a:\r\n\tx = abs(i-mid)\r\n\tif x % d!=0:\r\n\t\tprint(-1)\r\n\t\tflag = False\r\n\t\tbreak\r\n\tans += x//d\r\n\t\r\nif flag:\r\n print(ans)\r\n", "import math\r\nn, m, d = map(int, input().split())\r\nmatrix = [[] for _ in range(n)]\r\nfor row in range(n):\r\n matrix[row] = list(map(int, input().split()))\r\n\r\nall = []\r\nfor r in range(n):\r\n for c in range(m):\r\n all.append(matrix[r][c])\r\n\r\nmod_d = all[0] % d\r\nok = not any(x for x in all if x % d != mod_d)\r\nif not ok:\r\n print(-1)\r\nelse:\r\n all.sort()\r\n target = all[len(all) // 2]\r\n res = 0\r\n for i in range(len(all)):\r\n res += abs(target-all[i]) // d\r\n print(res)\r\n", "n, m, d = map(int, input().split())\r\nk, t = n * m, []\r\nfor i in range(n):\r\n t += list(map(int, input().split()))\r\nu = t[0] % d\r\nfor v in t:\r\n if u != v % d:\r\n t = []\r\n break\r\nif t:\r\n t.sort()\r\n s = t[k // 2]\r\n print(sum(abs(v - s) for v in t) // d)\r\nelse:\r\n print(-1)\r\n", "a = input().split(' ')\nn = int(a[0])\nm = int(a[1])\nd = int(a[2])\n\ntotal = 0\nX = []\n\nfor i in range(n):\n\ta = input().split(' ')\n\tfor j in a:\n\t\ty = int(j)\n\t\tX.append(y)\n\nX.sort()\n\nmedian = X[int((n*m)/2)]\n\n\nfor i in range(n*m):\n\ty = X[i]\n\tdiff = abs(median - y)\n\tif diff % d != 0:\n\t\ttotal = -1\n\t\tbreak\n\telse:\n\t\ttotal += int(diff / d)\n\nprint(str(total))", "# http://codeforces.com/problemset/problem/289/B\nn,m,d = map(int, input().split())\nmat = []\nfor _ in range(n):\n for x in list(map(int, input().split())):\n mat.append(x)\n #mat.append([x for x in list(map(int, input().split()))])\n#print(mat)\nx = mat[0] % d\n#print(x)\nfor y in mat:\n if y % d != x:\n print(-1)\n exit(0)\nmat = [(y-x)/d for y in mat]\n#print(mat)\nmat.sort()\n#print(mat)\nmed = mat[int((m*n) / 2)]\n#print(med)\nprint(int(sum([abs(y-med) for y in mat])))\n", "# import sys\r\n\r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w')\r\n\r\ndef minMoves(a, med, d):\r\n ct = 0\r\n\r\n for x in a:\r\n if x > med:\r\n while x > med:\r\n x -= d\r\n ct += 1\r\n else:\r\n while x < med:\r\n x += d\r\n ct += 1\r\n if x != med:\r\n return [False, -1]\r\n\r\n return [True, ct]\r\n\r\ndef read_line():\r\n return [int(x) for x in input().split()]\r\n\r\ndef read_int():\r\n return int(input())\r\n\r\ndef solve():\r\n n, m, d = read_line()\r\n b = []\r\n\r\n for _ in range(n):\r\n row = read_line()\r\n b.append(row)\r\n \r\n a = [0 for _ in range(n*m)]\r\n\r\n j = 0\r\n for i in range(n):\r\n for x in b[i]:\r\n a[j] = x\r\n j += 1 \r\n\r\n a.sort()\r\n\r\n med = a[(n*m)//2]\r\n # print(med)\r\n _, moves = minMoves(a, med, d)\r\n print(moves)\r\n\r\n\r\n# t = read_int()\r\nt = 1\r\nwhile t > 0:\r\n solve()\r\n t -= 1", "#https://codeforces.com/problemset/problem/289/B\r\n#abhay_codes\r\nn ,m , d =map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l1=list(map(int,input().split()))\r\n \r\n l.append(l1)\r\ns=set()\r\nli=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n s.add(l[i][j]%d)\r\n li.append(l[i][j])\r\nif len(s)>1:\r\n print(-1)\r\nelse:\r\n li.sort()\r\n k =n*m \r\n k1=k//2 \r\n val=li[k1]\r\n sm =0\r\n for i in li:\r\n sm+=abs(i-val)//d\r\n print(sm)\r\n \r\n ", "n, m, d = map(int, input().split())\r\na = []\r\nfor i in range(n):\r\n a += list(map(int, input().split()))\r\na = sorted(a)\r\n\r\nmod = a[0] % d\r\npiv = a[(n*m)//2]\r\nans = 0\r\nfor i in range(n*m):\r\n if a[i] % d != mod:\r\n print(-1)\r\n break\r\n ans += abs(a[i]-piv) // d\r\nelse:\r\n print(ans)", "n, m, d = map(int, input().split())\r\nA = []\r\nfor i in range(n):\r\n A += list(map(int, input().split()))\r\n\r\nA = sorted(A)\r\nmedian = A[m*n // 2]\r\n\r\nrem = A[0] % d\r\n \r\nsum = 0 \r\nfor i in range(n*m):\r\n if A[i] % d != rem:\r\n print(-1)\r\n exit()\r\n else:\r\n sum += abs(A[i] - median) / d\r\n\r\nprint(int(sum)) ", "def solve(mat, x, d):\r\n moves = 0\r\n for i in mat:\r\n diff = abs(i - x)\r\n if diff % d:\r\n return -1\r\n moves += diff // d\r\n return moves\r\n\r\n\r\n\r\nn, m, d = map(int, input().strip().split())\r\nmat = []\r\nfor i in range(n):\r\n mat += list(map(int, input().strip().split()))\r\nmat.sort()\r\nres = 0\r\nif len(mat) % 2 == 0:\r\n r1 = solve(mat, mat[len(mat) // 2 - 1], d)\r\n r2 = solve(mat, mat[len(mat) // 2], d)\r\n if r1 == -1 and r2 == -1:\r\n res = -1\r\n elif r1 != -1 and r2 == -1:\r\n res = r1\r\n elif r1 == -1 and r2 != -1:\r\n res = r2\r\n else:\r\n res = min(r1, r2)\r\nelse:\r\n res = solve(mat, mat[len(mat) // 2], d)\r\nprint(res)", "n, m, d = map(int, input().split())\r\nk, arr = n * m, []\r\nfor i in range(n):\r\n arr += list(map(int, input().split()))\r\nu = arr[0] % d\r\nfor v in arr:\r\n if u != v % d:\r\n print(-1)\r\n exit()\r\narr.sort()\r\ns = arr[k // 2]\r\nres = [abs(v - s) for v in arr]\r\nprint(sum(res) // d)\r\n", "n, m, d = map(int, input().split())\r\nl = []\r\nfor _ in range(n):\r\n l += list(map(int, input().split()))\r\n\r\nl.sort()\r\nmid = (n*m)//2\r\nans = 0\r\nfor i in l:\r\n if abs(i-l[mid]) % d != 0:\r\n print(-1)\r\n break\r\n ans += abs(i - l[mid])\r\nelse:\r\n print(ans//d)\r\n", "import math as mt \r\nimport sys,string,bisect\r\ninput=sys.stdin.readline\r\nimport random\r\nfrom collections import deque,defaultdict\r\nL=lambda : list(map(int,input().split()))\r\nLs=lambda : list(input().split())\r\nM=lambda : map(int,input().split())\r\nI=lambda :int(input())\r\nd=defaultdict(int)\r\n\r\nn,m,d=M()\r\nl=[]\r\nfor i in range(n):\r\n x=L()\r\n for j in x:\r\n l.append(j)\r\nl.sort()\r\nw=l[0]%d\r\nfor i in range(m*n):\r\n if(l[i]%d!=w):\r\n print(-1)\r\n exit()\r\nkey=l[(m*n)//2]\r\nkey2=l[(m*n)//2-1]\r\n\r\ns=0\r\ns2=0\r\nfor i in range(n*m):\r\n s+=abs(l[i]-key)\r\n s2+=abs(l[i]-key2)\r\nprint(min(s//d,s2//d))\r\n", "from sys import stdin\r\n\r\nn, m, d = map(int, stdin.readline().split())\r\ntemp = []\r\nfor i in range(n):\r\n temp.extend(list(map(int, stdin.readline().split())))\r\n\r\nres = 1e9\r\nfor i in temp:\r\n t = 0\r\n f = 1\r\n for j in temp:\r\n if j < i:\r\n if (i - j)/d != (i-j)//d:\r\n f = 0\r\n break\r\n else:\r\n t += (i-j)//d\r\n else:\r\n if (j-i)/d != (j-i)//d:\r\n f = 0\r\n break\r\n else:\r\n t += (j-i)//d\r\n if f:\r\n res = min(res, t)\r\nif res == 1e9:\r\n print(-1)\r\nelse:\r\n print(res)", "from statistics import median\n\nn, m, d = map(int, input().split())\n\nnumbers = []\n\nfor _ in range(n):\n row = list(map(int, input().split()))\n numbers += row\n\nnumbers.sort()\ntotal = 0\n\nmed = median(numbers)\n\nfor i in numbers:\n to_add = (med - i) / d\n total += abs(to_add)\n\nprint(int(total) if int(total) == total else -1)\n", "n, m, d = [int(k) for k in input().split()]\r\n\r\nmat = []\r\n\r\nfor _ in range(n):\r\n mat.append([int(k) for k in input().split()])\r\n\r\ndef penguin(mat, d):\r\n arr = []\r\n for el in mat:\r\n for c in el:\r\n arr.append(c)\r\n arr.sort()\r\n\r\n for i in range(1, len(arr)):\r\n diff = arr[i] - arr[0]\r\n if diff % d != 0:\r\n return -1\r\n\r\n idx = len(arr) // 2\r\n num = arr[idx]\r\n t = 0\r\n\r\n for el in arr:\r\n t += abs(num - el) // d\r\n\r\n return t\r\n\r\nprint(penguin(mat, d))", "n,m,d=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n l=l+list(map(int,input().split()))\r\nl.sort()\r\nmi=len(l)//2\r\nmid=l[mi]\r\ncount=0\r\ne=0\r\nfor i in range(mi):\r\n k=abs(mid-l[i])\r\n if(k%d==0):\r\n r=k//d\r\n count=count+r\r\n else:\r\n e=1\r\n break\r\nif(e==1):\r\n print(\"-1\")\r\nelse:\r\n for i in range(mi+1,len(l)):\r\n k=abs(mid-l[i])\r\n if(k%d==0):\r\n r=k//d\r\n count=count+r\r\n else:\r\n e=1\r\n break\r\n if(e==1):\r\n print(\"-1\")\r\n else:\r\n print(count)", "from collections import defaultdict, deque\nfrom functools import lru_cache\nfrom heapq import heappush, heappop\nfrom typing import Counter\nfrom bisect import bisect_right, bisect_left\nimport math\nhpop = heappop\nhpush = heappush\n\ndef solution():\n n,m,d = map(int, input().split());\n # no point in being an array\n # thier deffrence must be a multiple of d\n\n # check if each diffrence is multiple of d\n arr = []\n for _ in range(n):\n row = list(map(int, input().split()))\n arr.extend(row)\n\n arr.sort()\n for i in range(1, len(arr)):\n if (arr[i] - arr[i-1]) % d > 0:\n print(-1)\n return;\n\n n = len(arr);\n if n == 1:\n print(0)\n return;\n\n # I can land on the median\n res = float(\"inf\")\n for i in [(n-1)//2, (n-1)//2 + 1]:\n count = 0\n for val in arr: \n count += abs(val - arr[i])//d\n res = min(res, count)\n print(res)\n\n\n\n\n\n\ndef main():\n t = 1\n #t = int(input())\n for _ in range(t):\n solution()\n \n#import sys\n#import threading\n#sys.setrecursionlimit(1 << 30)\n#threading.stack_size(1 << 27)\n#thread = threading.Thread(target=main)\n#thread.start(); thread.join()\nmain()\n\n\n\n\n\"\"\"\n num = int(input())\n arr = list(map(int, input().split()))\n a,b = map(int, input().split())\n graph = defaultdict(list)\n for i in range(#)\n graph[a].append(b)\n graph[b].append(a)\n MOD = 10**9 + 7\n\nfor di,dj in [(0,1),(1,0),(0,-1),(-1,0)]:\n ni = i + di\n nj = j + dj\n if not (0<= ni < len(grid) and 0<= nj < len(grid[0])):\n continue\n\ndef gcd(a,b):\n if a < b:\n a,b = b,a\n if b == 0:\n return a\n\n return gcd(a%b,b)\n\n\"\"\"\n", "n,m,d=[int(x) for x in input().split()]\r\na=[]\r\nfor i in range(n):\r\n a+=([int(x) for x in input().split()])\r\n\r\na.sort()\r\nl=n*m\r\nmid=l//2\r\n\r\nans=f=0\r\nfor i in range(0,mid):\r\n x=a[mid]-a[i]\r\n if x%d!=0:\r\n f=1\r\n break\r\n else:\r\n ans+=x/d\r\n\r\nif f==0:\r\n for i in range(mid+1,l):\r\n x=a[i]-a[mid]\r\n if x%d!=0:\r\n f=1\r\n break\r\n else:\r\n ans+=x/d\r\n\r\nif f==1:\r\n print(-1)\r\nelse:\r\n print(int(ans))\r\n", "n, m, d = map(int, input().split())\r\n\r\nmat = []\r\n\r\nfor i in range(n):\r\n r = list(map(int, input().split()))\r\n for j in range(m):\r\n mat.append(r[j])\r\n\r\nmat.sort()\r\n\r\nrem = list(map(lambda x: x%d, mat))\r\nif rem.count(rem[0]) == n*m:\r\n med = mat[((n*m)//2)]\r\n\r\n # print(\"median\", med)\r\n\r\n total = 0\r\n for i in range(n*m):\r\n total += abs(mat[i] - med)\r\n\r\n print(int(total / d))\r\nelse:\r\n print(-1)\r\n\r\n\r\n", "#https://codeforces.com/contest/289/problem/B\nn,m,d=map(int,input().split())\nl=[]\nfor i in range(n):\n\tl.extend(list(map(int,input().split())))\nl.sort()\nm=l[(m*n)//2]\ns=0\nf=0\nfor i in l:\n\tif abs(i-m)%d!=0:\n\t\tf=1\n\t\tprint(-1)\n\t\tbreak\n\ts+=(abs(i-m)//d)\nif not f:\n\tprint(s)\t\n", "n, m, d = (int(x) for x in input().split())\ns = set()\nl = []\nfor i in range(n):\n\ttmp = [int(x) for x in input().split()]\n\ts |= {x % d for x in tmp}\n\tl += [x // d for x in tmp]\nif len(s) != 1:\n\tprint(-1)\n\texit(0)\nl.sort()\nmean = l[n * m // 2]\nans = 0\nfor x in l:\n\tans += abs(x - mean)\nif n * m // 2 > 0:\n\tmean = l[n * m // 2 - 1]\n\tans2 = 0\n\tfor x in l:\n\t\tans2 += abs(x - mean)\n\tans = min(ans, ans2)\nprint(ans)\n", "# DEFINING SOME GOOD STUFF\nimport sys\nfrom math import *\nimport threading\nfrom itertools import count\nfrom pprint import pprint\nfrom collections import defaultdict\n'''\n intialise defaultdict by any kind of value by default you want to take ( int -> 0 | list -> [] )\n'''\nfrom heapq import heapify, heappop, heappush\nsys.setrecursionlimit(300000)\n# threading.stack_size(10**8)\n'''\n-> if you are increasing recursionlimit then remember submitting using python3 rather pypy3\n-> sometimes increasing stack size don't work locally but it will work on CF\n'''\n\nmod = 10 ** 9 + 7\ninf = 10 ** 15\ndecision = ['NO', 'YES']\nyes = 'YES'\nno = 'NO'\n\n# ------------------------------FASTIO----------------------------\nimport os\n\nfrom io import BytesIO, IOBase\n\nBUFSIZE = 8192\n\n\nclass FastIO(IOBase):\n newlines = 0\n\n def __init__(self, file):\n self._fd = file.fileno()\n self.buffer = BytesIO()\n self.writable = \"x\" in file.mode or \"r\" not in file.mode\n self.write = self.buffer.write if self.writable else None\n\n def read(self):\n while True:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n if not b:\n break\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines = 0\n return self.buffer.read()\n\n def readline(self):\n while self.newlines == 0:\n b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))\n self.newlines = b.count(b\"\\n\") + (not b)\n ptr = self.buffer.tell()\n self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)\n self.newlines -= 1\n return self.buffer.readline()\n\n def flush(self):\n if self.writable:\n os.write(self._fd, self.buffer.getvalue())\n self.buffer.truncate(0), self.buffer.seek(0)\n\n\nclass IOWrapper(IOBase):\n def __init__(self, file):\n self.buffer = FastIO(file)\n self.flush = self.buffer.flush\n self.writable = self.buffer.writable\n self.write = lambda s: self.buffer.write(s.encode(\"ascii\"))\n self.read = lambda: self.buffer.read().decode(\"ascii\")\n self.readline = lambda: self.buffer.readline().decode(\"ascii\")\n\n\nsys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\n\n\n\n# _______________________________________________________________#\n\ndef npr(n, r):\n return factorial(n) // factorial(n - r) if n >= r else 0\n\n\ndef ncr(n, r):\n return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0\n\n\ndef lower_bound(li, num):\n answer = -1\n start = 0\n end = len(li) - 1\n\n while (start <= end):\n middle = (end + start) // 2\n if li[middle] >= num:\n answer = middle\n end = middle - 1\n else:\n start = middle + 1\n return answer # min index where x is not less than num\n\n\ndef upper_bound(li, num):\n answer = -1\n start = 0\n end = len(li) - 1\n\n while (start <= end):\n middle = (end + start) // 2\n\n if li[middle] <= num:\n answer = middle\n start = middle + 1\n\n else:\n end = middle - 1\n return answer # max index where x is not greater than num\n\n\ndef abs(x):\n return x if x >= 0 else -x\n\n\ndef binary_search(li, val):\n # print(lb, ub, li)\n ans = -1\n lb = 0\n ub = len(li) - 1\n while (lb <= ub):\n mid = (lb + ub) // 2\n # print('mid is',mid, li[mid])\n if li[mid] > val:\n ub = mid - 1\n elif val > li[mid]:\n lb = mid + 1\n else:\n ans = mid # return index\n break\n return ans\n\n\ndef kadane(x): # maximum sum contiguous subarray\n sum_so_far = 0\n current_sum = 0\n for i in x:\n current_sum += i\n if current_sum < 0:\n current_sum = 0\n else:\n sum_so_far = max(sum_so_far, current_sum)\n return sum_so_far\n\n\ndef pref(li):\n pref_sum = [0]\n for i in li:\n pref_sum.append(pref_sum[-1] + i)\n return pref_sum\n\n\ndef SieveOfEratosthenes(n):\n prime = [True for i in range(n + 1)]\n p = 2\n li = []\n while (p * p <= n):\n if (prime[p] == True):\n for i in range(p * p, n + 1, p):\n prime[i] = False\n p += 1\n\n for p in range(2, len(prime)):\n if prime[p]:\n li.append(p)\n return li\n\n\ndef primefactors(n):\n factors = []\n while (n % 2 == 0):\n factors.append(2)\n n //= 2\n for i in range(3, int(sqrt(n)) + 1, 2): # only odd factors left\n while n % i == 0:\n factors.append(i)\n n //= i\n if n > 2: # incase of prime\n factors.append(n)\n return factors\n\n\ndef prod(li):\n ans = 1\n for i in li:\n ans *= i\n return ans\n\n\n# _______________________________________________________________#\n\n\n# def main():\nfor _ in range(1):\n# for _ in range(int(input())):\n# n = int(input())\n n, m, d = map(int, input().split())\n # w, b = map(int, input().split())\n # a = list(map(int, input().split()))\n # b = list(map(int, input().split()))\n # c = list(map(int, input().split()))\n # d = defaultdict(int)\n a = []\n for i in range(n):\n a += list(map(int, input().split()))\n a.sort()\n elem = a[(n*m)//2]\n f = 0\n ans = 0\n for i in range(n*m):\n if abs(a[i] - elem)%d:\n f = 1\n ans += abs(a[i] - elem)\n if f:\n print(-1)\n else:\n print(ans//d)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n# t = threading.Thread(target=main)\n# t.start()\n# t.join()", "def main():\r\n n, m, d = map(int, input().split())\r\n\r\n mat = []\r\n\r\n for i in range(0, n):\r\n for v in [int(i) for i in input().split()]:\r\n mat.append(v)\r\n\r\n mod = mat[0] % d\r\n for i in range(1, len(mat)):\r\n if mat[i] % d != mod:\r\n print(-1)\r\n return\r\n\r\n mat.sort()\r\n\r\n if len(mat) % 2 == 1:\r\n print(solve(mat, mat[len(mat)//2], d))\r\n else:\r\n print(min(solve(mat, mat[len(mat)//2], d),\r\n solve(mat, mat[len(mat)//2+1], d)))\r\n\r\n\r\ndef solve(mat, val, d):\r\n count = 0\r\n for v in mat:\r\n count += (abs(v - val) // d)\r\n return count\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n,m,d=map(int,input().split())\r\narr=[]\r\nfor i in range(n):\r\n arr.extend(list(map(int,input().split())))\r\narr.sort()\r\nx=len(arr)//2\r\nres=0\r\nflag=0\r\nfor i in range(x):\r\n if (arr[len(arr)-1-i]-arr[i])%d==0:\r\n res+=((arr[len(arr)-1-i]-arr[i])//d)\r\n else:\r\n flag=1\r\n break\r\nprint(res) if flag==0 else print(-1)", "import math\r\nimport copy\r\nimport itertools\r\nimport bisect\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\n\r\ndef ilst():\r\n return list(map(int,input().split()))\r\n \r\ndef islst():\r\n return list(map(str,input().split()))\r\n \r\ndef inum():\r\n return map(int,input().split())\r\n \r\nn,m,d = inum()\r\n\r\nl = []\r\n\r\nfor i in range(n):\r\n l.append(ilst())\r\n\r\nmn = l[0][0]\r\ntl = []\r\nfor i in range(n):\r\n for j in range(m):\r\n mn = min(mn,l[i][j])\r\n tl.append(l[i][j])\r\n \r\ntl.sort()\r\nmid = tl[len(tl)//2]\r\n\r\nf = False\r\nans = 0\r\nfor i in range(n):\r\n for j in range(m):\r\n if (l[i][j]-mid)%d != 0:\r\n f = True\r\n break\r\n else:\r\n ans += abs(l[i][j]-mid)//d\r\n if f:\r\n break\r\nif not f:\r\n print(ans)\r\nelse:\r\n print(-1)\r\n \r\n", "n,m,d=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n a+=(list(map(int,input().split())))\r\nans=0\r\na.sort()\r\nmid=a[len(a)//2]\r\nfor i in a:\r\n x=abs(i-mid)\r\n if x%d!=0:\r\n print(-1)\r\n exit()\r\n ans+=x//d\r\nprint(ans)", "n, m, d = map(int, input().split())\nlst = []\nfor i in range(n):\n p = list(map(int, input().split()))\n lst += p\nlst.sort()\nk = lst[len(lst)//2]\nans = 0\nfor i in lst:\n t = abs(k - i)\n if t%d != 0:\n print(-1)\n exit()\n else :\n ans += t//d\nprint(ans)", "import sys\r\ninput = lambda: sys.stdin.readline().strip(\"\\r\\n\")\r\n\r\nn, m, d = map(int, input().split())\r\nmat = []\r\nfor i in range(n):\r\n mat += map(int, input().split())\r\nmat.sort()\r\nfor i in mat:\r\n if (i - mat[0]) % d:\r\n print(-1)\r\n exit()\r\nmedian = mat[len(mat)//2]\r\nls = map(lambda x: abs(x - median), mat)\r\nprint(sum(ls)//d)\r\n", "#Consistency is the key :)\r\n#code by: amrit2000\r\nfrom sys import stdin,stdout\r\nimport math\r\nimport bisect\r\ninput=stdin.readline\r\ndef print(x='',y='',end='\\n'):\r\n if y=='':\r\n stdout.write(str(x)+end)\r\n else:\r\n stdout.write(str(x)+' '+str(y)+end)\r\n\r\ndef solve():\r\n n,m,d=map(int,input().split())\r\n l=[]\r\n for i in range(n):\r\n l.extend(list(map(int,input().split())))\r\n\r\n l.sort()\r\n c=l[0]%d\r\n for i in range(n*m):\r\n if l[i]%d!=c:\r\n print(-1)\r\n return\r\n \r\n ans=0\r\n med=l[(n*m)//2]\r\n for i in range(m*n):\r\n ans+=abs(l[i]-med)//d\r\n\r\n \r\n print(ans)\r\n \r\n \r\ntt=1\r\n#tt=int(input())\r\nfor __ in range(tt):\r\n solve()\r\n", "# mod dで同一 が必要\r\n# コストは中央値\r\nn,m,d = map(int, input().split())\r\nl = []\r\nfor i in range(n):\r\n l.extend(list(map(int, input().split())))\r\nif not all((l[0]-i) % d == 0 for i in l):\r\n print(-1)\r\n exit()\r\nl.sort()\r\nans = 0\r\nfor i in l:\r\n ans += abs(i - l[n*m//2])//d\r\nprint(ans)", "row, col, d = map(int, input().split())\r\nnums = []\r\nfor _ in range(row):\r\n nums += [*list(map(int, input().split()))]\r\nnums.sort()\r\na = nums[(row*col)//2]\r\ncount = 0\r\nfor i in nums:\r\n if abs(i-a)%d:\r\n print(-1)\r\n exit()\r\n count += abs(i-a)//d\r\nprint(count)\r\n", "n, m, d = map(int, input().split())\r\nnums = []\r\nfor _ in range(n):\r\n nums.extend(list(map(int, input().split())))\r\nnums.sort()\r\ns = set([i%d for i in nums])\r\nif len(s) > 1:\r\n print(-1)\r\nelse:\r\n ans = 0\r\n for num in nums:\r\n ans += abs(num-(nums[n*m//2]))//d\r\n\r\n print(ans)", "n, m, d = map(int, input().split())\r\nmt = []\r\n\r\nfor i in range(n):\r\n mt += list(map(int, input().split()))\r\n \r\nme = min(mt)\r\nmtc = mt.copy()\r\n \r\nif len(set(mt)) == 1:\r\n print(0)\r\nelse:\r\n com = mt[0]%d\r\n neg = False\r\n for i in range(1, len(mtc)):\r\n if mtc[i]%d != com:\r\n neg = True\r\n break\r\n \r\n if neg:\r\n print(-1)\r\n else:\r\n max_ct = 99999999\r\n for i in range(n*m):\r\n ct = 0\r\n for j in range(n*m):\r\n ct += abs((mt[j]-mt[i])//d)\r\n \r\n max_ct = min(max_ct, ct)\r\n print(max_ct)", "n,m,d=map(int,input().split())\r\na=[]\r\nfor _ in range(n):\r\n a.append(list(map(int,input().split())))\r\nf=0\r\nc=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n c.append(a[i][j])\r\n\r\nc=sorted(c)\r\nk=len(c)\r\np=c[k//2]\r\ns=0\r\nfor i in range(n):\r\n for j in range(m):\r\n l=abs(a[i][j]-p)\r\n if l%d!=0:\r\n f=1 \r\n break\r\n s+=l//d\r\nif f==0:\r\n print(s)\r\nelse:\r\n print(-1)", "import math\r\nimport sys\r\nfrom bisect import bisect_right, bisect_left, insort_right\r\nfrom collections import Counter, defaultdict\r\nfrom heapq import heappop, heappush\r\nfrom itertools import accumulate\r\nfrom sys import stdout\r\n\r\nR = lambda: map(int, input().split())\r\nn, m, d = R()\r\narr = []\r\nfor i in range(n):\r\n arr += list(R())\r\narr.sort()\r\nif any([(x - arr[0]) % d for x in arr]):\r\n print('-1')\r\n exit(0)\r\narr = [(x - arr[0]) // d for x in arr]\r\nacc = list(accumulate(arr))\r\nres = math.inf\r\nfor x in range(arr[-1] + 1):\r\n i = bisect_right(arr, x) - 1\r\n res = min(res, (i + 1) * x - acc[i] + acc[-1] - acc[i] - (n * m - i - 1) * x)\r\nprint(res)", "n, m, d = map(int, input().split())\n\nnums = []\nfor _ in range(n):\n nums.extend(list(map(int, input().split())))\n\n\ndef solve():\n ans = 0\n rem = nums[0] % d\n\n for i in range(n * m):\n if nums[i] % d != rem:\n return -1\n \n nums.sort()\n mid = nums[(n * m) // 2]\n\n for i in range(n * m):\n ans += abs(nums[i] - mid) // d\n\n return ans\n\n\nprint(solve())\n", "def matrix():\r\n n, m, d = map(int, input().split())\r\n ls = list()\r\n for i in range(n):\r\n ls += list(map(int, input().split()))\r\n\r\n ls.sort()\r\n mid = ls[n*m//2]\r\n\r\n count = 0\r\n for i in ls:\r\n if abs(i-mid) % d != 0:\r\n return -1\r\n count += abs(i-mid) // d\r\n return count\r\n\r\n\r\nprint(matrix())\r\n", "n,m,d=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(n):\r\n l.append(list(map(int,input().split())))\r\na=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n a.append(l[i][j])\r\na.sort()\r\nf=1\r\nw=[0]\r\nfor i in range(1,len(a)):\r\n if (a[i]-a[i-1])%d!=0:\r\n f=0\r\n break\r\n else:\r\n w.append(a[i]-a[i-1])\r\nif f:\r\n r=[0]*(len(w))\r\n e=[0]*(len(w))\r\n for i in range(1,len(w)):\r\n e[i]=w[i]*i+e[i-1]\r\n for i in range(len(w)-2,-1,-1):\r\n r[i]=w[i+1]*(len(w)-1-i)+r[i+1]\r\n c=879878998\r\n for i in range(len(w)):\r\n c=min(c,(e[i]+r[i])//d)\r\n print(c)\r\n \r\nelse:\r\n print(-1)", "import sys\r\nn,m,d=map(int,input().split())\r\nL=[]\r\nfor i in range(n):\r\n L.extend(list(map(int,input().split())))\r\nL.sort()\r\nmoves,middle=0,(n*m)//2\r\nfor i in range(n*m):\r\n if abs(L[middle]-L[i])%d!=0:\r\n print(\"-1\")\r\n sys.exit(0)\r\n break\r\n else:\r\n moves+=abs(L[middle]-L[i])//d\r\nprint(moves)\r\nsys.exit(0)", "import sys\r\nimport string\r\n\r\nfrom collections import Counter, defaultdict\r\nfrom math import fsum, sqrt, gcd, ceil, factorial\r\nfrom itertools import combinations, permutations\r\n\r\n# input = sys.stdin.readline\r\nflush = lambda: sys.stdout.flush\r\ncomb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)\r\n\r\n\r\n# inputs\r\n# ip = lambda : input().rstrip()\r\nip = lambda: input()\r\nii = lambda: int(input())\r\nr = lambda: map(int, input().split())\r\nrr = lambda: list(r())\r\n\r\ndef go(arr , x , k ):\r\n c = 0\r\n for i in arr:\r\n need = abs(x - i)\r\n if need % k :\r\n return -1\r\n c += need // k\r\n\r\n return c\r\n\r\na, b, k = r()\r\narr = []\r\n\r\nfor _ in range(a):\r\n x = rr()\r\n arr.extend(x)\r\n\r\narr.sort()\r\nn = len(arr)\r\nif n % 2:\r\n x = arr[n // 2]\r\n y = x\r\nelse:\r\n x = arr[n // 2]\r\n y = arr[n // 2 - 1]\r\n\r\na , b = go(arr, x , k), go(arr, y , k)\r\nif a == -1 == b:\r\n print(a)\r\nelse:\r\n if a == -1:\r\n print(b)\r\n elif b == -1:\r\n print(a)\r\n else:\r\n print(min(a , b))\r\n", "n,m,d=map(int,input().split())\r\na=[]\r\nfor i in ' '*n:\r\n a+=list(map(int,input().split()))\r\na.sort()\r\nmid=a[(n*m)//2]\r\nc=0\r\nfor i in a:\r\n x=abs(i-mid)\r\n if x%d!=0:\r\n print(-1)\r\n exit(0)\r\n c+=x//d\r\nprint(c)", "def Gcd(a,b):\r\n while a*b!=0:\r\n if a>b:\r\n a=int(a)%int(b)\r\n else:\r\n b=b%a\r\n return a+b\r\nn,m,d=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n a+=list(map(int,input().split()))\r\na=sorted(a)\r\ncnt=0\r\nmid=a[n*m//2]\r\nfor element in a:\r\n if mid-element>=0:\r\n if (mid-element)%d!=0:\r\n print(-1)\r\n exit()\r\n else:\r\n cnt+=(mid-element)/d\r\n else:\r\n if (element-mid)%d!=0:\r\n print(-1)\r\n exit()\r\n else:\r\n cnt+=(element-mid)/d\r\nprint(int(cnt))\r\n\r\n\r\n\r\n", "from sys import stdin\r\nstdin.readline\r\ndef mp(): return list(map(int, stdin.readline().strip().split()))\r\ndef it():return int(stdin.readline().strip())\r\nfrom math import pi\r\n\r\nn,m,d=mp()\r\nv=[]\r\ns=set()\r\nfor _ in range(n):\r\n\tv.extend(mp())\r\n# print(v)\r\nv.sort()\r\nk=v[(m*n)//2]\r\nans=0\r\nfor i in range(len(v)):\r\n\tif abs(v[i]-k)%d:\r\n\t\tprint(-1)\r\n\t\texit()\r\n\telse:\r\n\t\tans+=abs(v[i]-k)\r\n\r\nprint(ans//d)\r\n\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m, d = map(int, input().split())\r\n\r\ng = []\r\nfor _ in range(n):\r\n w = list(map(int, input().split()))\r\n g.extend(w)\r\n\r\ng.sort()\r\nx = g[n*m//2]\r\nc = g[0]\r\nc1 = 0\r\nfor i in range(n*m):\r\n if (g[i] - c) % d != 0:\r\n print(-1)\r\n exit(0)\r\n else:\r\n c1 += abs(g[i]-x) // d\r\n\r\nprint(int(c1))", "n, m, d = list(map(int, input().split()))\r\n\r\na = list()\r\n\r\nfor i in range(n):\r\n s = list(map(int, input().split()))\r\n for j in s:\r\n a.append(j)\r\n\r\na.sort()\r\nans = 0\r\n\r\nfor i in range(1, len(a)):\r\n if ((a[i] - a[i - 1]) % d != 0):\r\n print(\"-1\")\r\n exit(0)\r\n\r\nmedian = a[len(a) // 2]\r\nfor i in a:\r\n ans += abs(i - median) // d\r\n\r\nprint(ans)\r\n", "n,m,d=map(int,input().split())\r\nmat=[]\r\nfor i in range(n):\r\n arr=[int(i) for i in input().split()]\r\n mat.append(arr)\r\narr=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n arr.append(mat[i][j])\r\narr.sort()\r\nif True:\r\n med=arr[len(arr)//2]\r\n ans=0\r\n boo=True\r\n for i in range(n*m):\r\n if (abs(arr[i]-med))%d!=0:\r\n print(-1)\r\n boo=False\r\n break\r\n else:\r\n ans=ans+((abs(arr[i]-med))//d)\r\n if boo:\r\n print(ans)\r\n \r\n\r\n", "o=[*map(int,input().split())]\nlist1=[]\ny=0\nfor i in range(o[0]):\n k=[*map(int,input().split())]\n for j in k:\n list1.append(j)\nlist2=sorted(list1)\nnes=(o[1]*o[0])//2\nfor z in range(len(list2)):\n if (list2[nes]-list2[z])%o[2]!=0:\n print(-1)\n exit(0)\n\n\n else:\n y+=abs(list2[nes]-list2[z])//o[2]\n\nprint(abs(int(y)))\n", "import pprint\r\nimport cmath\r\npp = pprint.PrettyPrinter().pprint\r\n\r\nflag_possible = True\r\nn, m, d = list(map(int, input().split()))\r\n# Matrix n to m, can subtract or add d\r\n\r\nmin_el = cmath.inf\r\narr_el = []\r\nfor _ in range(n):\r\n for el in map(int, input().split()):\r\n min_el = min(min_el, el)\r\n arr_el.append(el)\r\n\r\nfor el in arr_el:\r\n if (el - min_el) % d != 0:\r\n flag_possible = False\r\n break\r\n\r\nif flag_possible:\r\n sorted_arr = sorted(arr_el)\r\n base_el = sorted_arr[len(sorted_arr)//2]\r\n moves = 0\r\n for el in arr_el:\r\n moves += abs((el - base_el)) // d\r\n print(moves)\r\nelse:\r\n print(-1)\r\n", "\"Codeforces Round #339 (Div. 2)\"\n\"B. Gena's Code\"\n# y=int(input())\n# # a=list(map(int,input().split()))\n# a=list(input().split())\n# nz=0\n# nb=''\n# z=0\n# # print(len(str(z)))\n# for i in a:\n# if i=='0':\n# z=1\n# break\n# else:\n# s='1'\n# l=(len(i)-1)\n# qz='0'*l\n# s+=qz\n# if s==i:\n# nz+=l\n# else:\n# nb=i\n# if nb=='':\n# nb='1' \n# ans=nb+('0'*nz)\n# if z==1:\n# ans='0'\n# print(ans) \n\"B. Polo the Penguin and Matrix\"\nn,m,d=map(int,input().split())\na=[]\nfor i in range(n):\n b=list(map(int,input().split()))\n a.extend(b)\na.sort()\nfa=a[0]\nf=0\nc=(a[len(a)//2]-fa)//d\nmoves=0\nfor i in a:\n if (i-fa)%d>0:\n f=-1\n moves+=abs(int((i-fa)/d)-c)\nif f==-1:\n print(-1)\nelse:\n print(moves) \n\n\n\n", "n,m,d = map(int,input().split())\nA = []\nfor i in range(n):\n A.append(list(map(int,input().split())))\ns = []\nok = True\nfor i in range(n):\n for j in range(m):\n s.append(A[i][j])\ns.sort()\nfor i in range(m*n-1):\n diff = s[i+1]-s[i]\n if diff%d !=0:\n print(-1)\n ok = False\n break\nans = 0 \nif ok:\n j = (m*n)//2\n for i in range(m*n):\n ans += abs(s[i]-s[j])//d \n print(ans)", "import statistics as s\r\nimport bisect\r\nn,m,d=map(int,input().split())\r\nlst=[]\r\nfor i in range(n):\r\n a=list(map(int,input().split()))\r\n lst+=a\r\nlst.sort()\r\n# print('lst',lst)\r\np=int(s.median(lst))\r\n# print('midian',p)\r\na= bisect.bisect_right(lst,p)\r\n# print('position of the insertion ',a)\r\np=lst[a-1]\r\n# print('achive',p)\r\nct=0\r\nfor j in lst:\r\n x=abs(p-j)/d\r\n if x.is_integer():\r\n ct+=int(x)\r\n else:\r\n ct=-1\r\n break\r\nprint(ct)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n,m,d = map(int,input().split())\r\narray = []\r\nfor i in range(n):\r\n\tarray.extend(map(int,input().split()))\r\narray.sort()\r\nmid = int(n*m/2)\r\nans = 0\r\nnotpossible = False\r\nfor i in range(n*m):\r\n\tif array[mid] > array[i]:\r\n\t\tdiff = array[mid] - array[i]\r\n\t\tif diff%d != 0:\r\n\t\t\tnotpossible = True\r\n\t\t\tbreak\r\n\t\tans += int(diff/d)\r\n\telif array[mid] < array[i]:\r\n\t\tdiff = array[i] - array[mid]\r\n\t\tif diff%d != 0:\r\n\t\t\tnotpossible = True\r\n\t\t\tbreak\r\n\t\tans += int(diff/d)\r\nif notpossible:\r\n\tprint(\"-1\")\r\nelse:\r\n\tprint(ans)", "def solve():\r\n n, m, s = map(int, input().split())\r\n arr = []\r\n for i in range(n):\r\n arr.append(list(map(int, input().split())))\r\n rem = arr[0][0] % s\r\n for i in range(n):\r\n for j in range(m):\r\n if arr[i][j]%s != rem:\r\n return -1\r\n flat = []\r\n for i in range(n):\r\n for j in range(m):\r\n flat.append(arr[i][j])\r\n flat.sort()\r\n ans = 0\r\n for i in range(n):\r\n for j in range(m):\r\n ans += abs(arr[i][j] - flat[len(flat)//2])//s\r\n return ans\r\nprint(solve())", "import sys, os.path\r\nfrom collections import*\r\nfrom copy import*\r\nimport math\r\nmod=10**9+7\r\nif(os.path.exists('input.txt')):\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n sys.stdout = open(\"output.txt\",\"w\")\r\n\r\ndef check(a):\r\n p=a[0]\r\n for i in range(1,n*m):\r\n b=abs(p-a[i])\r\n if(b%d!=0):\r\n return 0\r\n return 1\r\nn,m,d=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n l=list(map(int,input().split()))\r\n a.extend(l)\r\nif(check(a)):\r\n fix=0\r\n sum1=sys.maxsize\r\n temp=0\r\n for i in range(n*m):\r\n fix=a[i]\r\n for j in range(n*m):\r\n temp+=abs(fix-a[j])//d\r\n sum1=min(sum1,temp)\r\n temp=0\r\n print(sum1)\r\n\r\nelse:\r\n print(-1)", "def main():\n n, m, d = map(int, input().split())\n l = [x for _ in range(n) for x in map(int, input().split())]\n n *= m\n m = min(l)\n for i, x in enumerate(l):\n x -= m\n if x % d:\n print(-1)\n return\n l[i] = x\n l.sort()\n m = l[n // 2]\n print(sum(abs(x - m) for x in l) // d)\n\n\nif __name__ == '__main__':\n main()\n", "n,m,d=map(int,input().split())\r\nl,b=[],False\r\nfor _ in range(n):\r\n a=list(map(int,input().split()))\r\n l+=a\r\nn*=m\r\nl.sort()\r\nx=a[0]%d\r\nfor i in l:\r\n if i%d!=x:\r\n b=True\r\n break\r\nif b:\r\n print(-1)\r\nelse:\r\n x=0\r\n for i in range(len(l)):\r\n x+=abs(l[i]-l[n//2])//d\r\n print(x)", "\r\nn , m , d = map(int,input().split())\r\n\r\nmatrix = []\r\nfor i in range(n):\r\n matrix.append(list(map(int,input().split())))\r\n\r\nv = []\r\nfor i in range(n):\r\n v.extend(matrix[i])\r\n\r\nv.sort()\r\n\r\nremender = set()\r\nfor i in v :\r\n remender.add(i % d)\r\n\r\nif len(remender) > 1 :\r\n print('-1')\r\n\r\nelse:\r\n ans = 0\r\n middle_element = v[n * m// 2 ]\r\n for i in v :\r\n ans += abs(i - middle_element)\r\n\r\n print(ans // d)\r\n", "import collections,math,itertools,bisect,heapq,copy\nclass Solution:\n def solve(self):\n n,m,d = list(map(int, input().rstrip().split()))\n arr = []\n for i in range(n):\n a = list(map(int, input().rstrip().split()))\n arr+= a\n arr = sorted(arr)\n mid = arr[len(arr)//2]\n res = 0\n for num in arr:\n if (mid - num) % d != 0:\n print(-1)\n return\n res += (mid-num)//d if (mid-num) >= 0 else (-(mid-num)//d)\n print(res)\n \n\nif __name__ == \"__main__\":\n solution = Solution()\n solution.solve()", "# Input functions!\r\nilist = lambda : list(map(int,input().split()))\r\nslist = lambda : list(input().split())\r\niint = lambda : map(int,input().split())\r\ntc = lambda : range(int(input()))\r\nii = lambda : int(input())\r\n# Ergo a song!\r\n'''''' ''''''\r\n'''\r\n And if I could stop with hypotheticals\r\n Then this wouldn't be a hypothetical\r\n'''\r\n'''''' ''''''\r\n# minSearch\r\ndef minSearch(l,h,d):\r\n while l<h:\r\n mid = int(l/2+h/2)\r\n \r\n# Solution:\r\nifyes = True\r\nn,m,d = map(int,input().split())\r\nk = n*m\r\narr = []\r\nfor i in range(n):\r\n arr += list(map(int,input().split()))\r\narr.sort()\r\nfor i in range(k-1):\r\n if (arr[i+1]-arr[i])%d:\r\n ifyes = False\r\n break \r\nif not ifyes:\r\n print(-1)\r\nelse:\r\n s=0 \r\n prefix,postfix = [],[] \r\n for i in range(k):\r\n prefix.append(s)\r\n s+=arr[i] \r\n for i in range(k):\r\n s-=arr[i]\r\n postfix.append(s)\r\n ans = []\r\n for i in range(k):\r\n eq = (2*i-k+1)*arr[i] + postfix[i] - prefix[i] \r\n ans.append(int(eq/d)) \r\n print(min(ans))\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n ", "n, m, d = map(int, input().split())\r\n\r\nb = []\r\n\r\nfor i in range(n):\r\n b.extend(list(map(int, input().split())))\r\n\r\nb.sort()\r\nans = float('inf')\r\nfor i in range(n*m):\r\n temp = 0\r\n for j in range(n*m):\r\n temp += abs(b[i] - b[j])\r\n ans = min(ans, temp)\r\n\r\nprint(ans//d if ans % d == 0 else -1)", "n,m,d=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n a.extend(list(map(int,input().split())))\r\na.sort()\r\ns=0\r\nk=a[len(a)//2]\r\nans=0\r\nfor i in range(n*m):\r\n b=abs(a[i]-k)\r\n if b%d!=0:\r\n print(-1)\r\n exit()\r\n ans+=b//d\r\nprint(ans)\r\n", "n , m , d =map(int,input().split())\r\na=[]\r\nfor i in[0]*n:\r\n a.extend(list(map(int,input().split())))\r\na = sorted(a)\r\ntmp = a[n*m//2]\r\n\r\nans = sum( abs(i-tmp)for i in a)//d\r\ns = set(i%d for i in a)\r\nprint([ans , -1 ][len(s)>1])", "n,m,k=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n jo=list(map(int,input().split()))\r\n l.append(jo)\r\n\r\n \r\nset_=set()\r\narr=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n arr.append(l[i][j])\r\n set_.add(l[i][j]%k)\r\n \r\n \r\nif(len(set_)>1):\r\n print(-1)\r\nelse:\r\n ans=1e9\r\n \r\n for i in range(len(arr)):\r\n curr = 0\r\n for j in range(len(arr)):\r\n curr+=abs(arr[i]-arr[j])\r\n \r\n ans=min(ans,curr)\r\n\r\n print(ans//k)", "n,m,d=map(int,input().split())\r\nl=[]\r\nfor i in range(n):\r\n temp=[int(x) for x in input().split()]\r\n l.extend(temp)\r\ns=[]\r\ns=set(s)\r\nfor i in l:\r\n s.add(i%d)\r\nif len(s)!=1:\r\n print(-1)\r\nelse:\r\n ans=10**9\r\n for i in l:\r\n temp=0\r\n for j in l:\r\n temp+=(abs(i-j)//d)\r\n if temp<ans:\r\n ans=temp\r\n print(ans)", "n, m, d = list( map(int, input().split()) )\nmatrix = []\nfor i in range(n) :\n for x in list(map(int, input().split())) :\n matrix.append(x)\n\nmatrix.sort()\ngoal = matrix[ int( (len(matrix)+1)/2 -1) ]\n\nmoves = 0\nok = 1\nfor element in matrix :\n if (element-goal)%d == 0 :\n moves += abs(element-goal) /d\n else:\n ok = 0\n break\nif ok :\n print(int(moves))\nelse:\n print(-1)\n\t\t \t\t\t \t\t \t\t\t \t \t \t \t\t\t \t \t\t", "n, m, d = map(int, input().split()) \r\nll = []\r\nfor i in range(n): \r\n l = list(map(int, input().split()))\r\n for i in l:\r\n ll.append(i)\r\n\r\ndef sol():\r\n t = ll[0] % d\r\n for i in range(n * m): \r\n if ll[i] % d != t:\r\n return -1\r\n ll.sort() \r\n median = ll[(n * m) // 2] \r\n cost = 0\r\n for i in ll:\r\n cost += (abs(median - i) // d) \r\n return cost\r\n\r\nprint(sol())", "from collections import Counter\r\n\r\nn, m, d = map(int, input().split())\r\na = []\r\n\r\nfor i in range(n):\r\n a += tuple(map(int, input().split()))\r\n \r\nc = a[0]%d\r\nok = True\r\n\r\nfor i in a:\r\n if i%d != c:\r\n ok = False\r\n break\r\n \r\nif ok:\r\n a.sort()\r\n m1 = a[(n*m)//2]\r\n m2 = a[((n*m)-1)//2]\r\n \r\n ct1 = 0\r\n ct2 = 0\r\n \r\n for i in range(n*m):\r\n ct1 += abs(m1-a[i])//d\r\n ct2 += abs(m2-a[i])//d\r\n \r\n print(min(ct1, ct2))\r\n \r\nelse:\r\n print(-1)\r\n ", "# f = open(\"input.txt\", \"r\")\r\n# content = f.read()\r\n# content = content.split(\"\\n\")\r\n# n,m,d = list(map(int, content[0].split(\" \")))\r\n# arr = []\r\n# for i in range(0, n):\r\n# arr.append(list(map(int, content[i + 1].split(\" \"))))\r\nimport math\r\n\r\nn, m, d = list(map(int, input().split()))\r\n\r\narr = []\r\nfor i in range(0, n):\r\n arr.append(list(map(int, input().split())))\r\n\r\nflat_arr = []\r\n\r\nfor i in range(0, n):\r\n for j in range(0, m):\r\n flat_arr.append(arr[i][j])\r\n\r\nflat_arr.sort()\r\n\r\nmedian = []\r\nif len(flat_arr) % 2 == 0:\r\n index = int((len(flat_arr) - 1) / 2)\r\n median.append(flat_arr[index])\r\n median.append(flat_arr[index + 1])\r\nelse:\r\n index = int(len(flat_arr) / 2)\r\n median.append(flat_arr[index])\r\n\r\nmin = math.inf\r\n\r\nfor k in range(0, len(median)):\r\n check = True\r\n res = 0\r\n\r\n for i in range(0, len(flat_arr)):\r\n if abs(flat_arr[i] - median[k]) % d == 0:\r\n res += int(abs(flat_arr[i] - median[k]) / d)\r\n else:\r\n check = False\r\n\r\n if check == True:\r\n if res < min:\r\n min = res\r\n\r\nif min == math.inf:\r\n print(-1)\r\nelse:\r\n print(min)\r\n ", "n,m,d = map(int,input().split())\r\na = []\r\nfor i in range(n):\r\n a.append(list(map(int,input().split())))\r\ndiv = a[0][0]%d\r\nfor i in range(n):\r\n for j in range(m):\r\n if a[i][j]%d!=div:\r\n print(-1)\r\n exit()\r\nelse:\r\n arr = []\r\n for i in range(n):\r\n for j in range(m):\r\n arr.append(a[i][j])\r\n arr.sort()\r\n n = len(arr)\r\n median_element = arr[n//2]\r\n ans = 0\r\n for i in range(n):\r\n ans+=(abs(arr[i]-median_element)//d)\r\n print(ans)\r\n", "n, m, d = list(map(int, input().split()))\r\n\r\nmatrix = []\r\nfor i in range(n):\r\n arr = list(map(int, input().split()))\r\n matrix.append(arr)\r\n\r\ndef find_pathes(x):\r\n n = len(matrix)\r\n m = len(matrix[0])\r\n res = 0\r\n for i in range(n):\r\n for j in range(m):\r\n res += abs(x - matrix[i][j])\r\n return res\r\n\r\ndef ternary(l, r):\r\n if r - l < 3:\r\n side = l\r\n res = find_pathes(l)\r\n for i in range(l+1, r+1):\r\n cur_res = find_pathes(i)\r\n if find_pathes(i) < res:\r\n res = cur_res\r\n side = i\r\n return side\r\n part = (r-l)//3\r\n l1 = l+part\r\n r1 = l+2*part\r\n if find_pathes(l1) > find_pathes(r1):\r\n return ternary(l1, r)\r\n else:\r\n return ternary(l, r1)\r\n\r\n\r\n\r\nmed = ternary(0, 100000)\r\ndef calc(x, d):\r\n n = len(matrix)\r\n m = len(matrix[0])\r\n res = 0\r\n for i in range(n):\r\n for j in range(m):\r\n res += abs(matrix[i][j]-x)//d\r\n if (matrix[i][j]-x)%d != 0:\r\n return -1\r\n return res\r\n\r\nif (matrix[0][0]-med)%d == 0:\r\n print(calc(med, d))\r\nelse:\r\n k = (matrix[0][0]-med)//2\r\n print(min(calc(matrix[0][0]+k*d, d), calc(matrix[0][0]+(k+1)*d, d)))\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\"\"\"\r\n\r\n2 2 2\r\n2 4\r\n6 8\r\n\r\n\r\n\"\"\"", "# ﷽\r\nimport sys\r\nimport heapq\r\ninput = sys.stdin.readline\r\nfrom math import log2,ceil,floor,gcd,sqrt,log,perm,comb,factorial\r\nfrom collections import Counter,deque\r\nfrom random import getrandbits\r\n\r\nRANDOM = getrandbits(32)\r\n \r\nclass Wrapper(int):\r\n def __init__(self, x):\r\n int.__init__(x)\r\n def __hash__(self):\r\n return super(Wrapper, self).__hash__() ^ RANDOM \r\n\r\n\r\n\r\n# sys.setrecursionlimit(10**4)\r\n\r\ndef dijkstra(graph, start):\r\n distances = {node: float('inf') for node in graph} # Initialize distances to infinity\r\n distances[start] = 0 # Distance from start to start is 0\r\n heap = [(0, start,[start])] # Priority queue to store nodes and their distances\r\n paths = [-1 for i in range(n+1)]\r\n while heap:\r\n current_distance, current_node , path = heapq.heappop(heap) # Get node with smallest distance\r\n \r\n if current_distance > distances[current_node]:\r\n continue # Skip if distance is already greater than the known distance\r\n\r\n for neighbor, weight in graph[current_node]:\r\n distance = current_distance + weight # Calculate tentative distance\r\n\r\n if distance < distances[neighbor]:\r\n lst = path \r\n lst.append(neighbor)\r\n paths[neighbor] = current_node\r\n distances[neighbor] = distance # Update distance if shorter\r\n heapq.heappush(heap, (distance, neighbor, lst)) # Add neighbor to the heap\r\n\r\n return paths\r\ndivisors = {}\r\ndef Divisors(n) :\r\n for num in range(1,n+1):\r\n lst = set()\r\n i = 1\r\n while i <= sqrt(num):\r\n \r\n if (num % i == 0) :\r\n # If divisors are equal, print only one\r\n if ( num / i == i) :\r\n lst.add(i)\r\n else :\r\n # Otherwise print both\r\n lst.update([i,num//i])\r\n \r\n i = i + 1\r\n divisors[num] = list(lst)\r\n\r\nDivisors(2000)\r\n\r\ndef mergeSort(arr, n):\r\n # A temp_arr is created to store\r\n # sorted array in merge function\r\n temp_arr = [0]*n\r\n return _mergeSort(arr, temp_arr, 0, n-1)\r\n \r\n# This Function will use MergeSort to count inversions\r\n \r\n \r\ndef _mergeSort(arr, temp_arr, left, right):\r\n \r\n # A variable inv_count is used to store\r\n # inversion counts in each recursive call\r\n \r\n inv_count = 0\r\n \r\n # We will make a recursive call if and only if\r\n # we have more than one elements\r\n \r\n if left < right:\r\n \r\n # mid is calculated to divide the array into two subarrays\r\n # Floor division is must in case of python\r\n \r\n mid = (left + right)//2\r\n \r\n # It will calculate inversion\r\n # counts in the left subarray\r\n \r\n inv_count += _mergeSort(arr, temp_arr,\r\n left, mid)\r\n \r\n # It will calculate inversion\r\n # counts in right subarray\r\n \r\n inv_count += _mergeSort(arr, temp_arr,\r\n mid + 1, right)\r\n \r\n # It will merge two subarrays in\r\n # a sorted subarray\r\n \r\n inv_count += merge(arr, temp_arr, left, mid, right)\r\n return inv_count\r\n \r\n# This function will merge two subarrays\r\n# in a single sorted subarray\r\n \r\n \r\ndef merge(arr, temp_arr, left, mid, right):\r\n i = left # Starting index of left subarray\r\n j = mid + 1 # Starting index of right subarray\r\n k = left # Starting index of to be sorted subarray\r\n inv_count = 0\r\n \r\n # Conditions are checked to make sure that\r\n # i and j don't exceed their\r\n # subarray limits.\r\n \r\n while i <= mid and j <= right:\r\n \r\n # There will be no inversion if arr[i] <= arr[j]\r\n \r\n if arr[i] <= arr[j]:\r\n temp_arr[k] = arr[i]\r\n k += 1\r\n i += 1\r\n else:\r\n # Inversion will occur.\r\n temp_arr[k] = arr[j]\r\n inv_count += (mid-i + 1)\r\n k += 1\r\n j += 1\r\n \r\n # Copy the remaining elements of left\r\n # subarray into temporary array\r\n while i <= mid:\r\n temp_arr[k] = arr[i]\r\n k += 1\r\n i += 1\r\n \r\n # Copy the remaining elements of right\r\n # subarray into temporary array\r\n while j <= right:\r\n temp_arr[k] = arr[j]\r\n k += 1\r\n j += 1\r\n \r\n # Copy the sorted subarray into Original array\r\n for loop_var in range(left, right + 1):\r\n arr[loop_var] = temp_arr[loop_var]\r\n \r\n return inv_count\r\n\r\ndef add_edge(node1,node2):\r\n if node1 not in graph:\r\n graph[node1] = []\r\n if node2 not in graph:\r\n graph[node2] = []\r\n graph[node1].append(node2)\r\n graph[node2].append(node1)\r\n \r\ndef bfs(node):\r\n q = deque()\r\n q.append(node)\r\n vis.add(node)\r\n while q:\r\n a = q.popleft()\r\n for i in graph[a]:\r\n if i in vis:\r\n continue\r\n vis.add(i)\r\n q.append(i)\r\n\r\n# def bfs(n):\r\n# q = deque()\r\n# q.append([n,0])\r\n# vis = {n:0}\r\n# ans = []\r\n# while q:\r\n# x , dis = q.popleft()\r\n# ans.append(x)\r\n# graph[x].sort()\r\n# for k,child in graph[x] :\r\n# if child not in vis :\r\n# q.append([child,dis + 1])\r\n# vis[child] = dis + 1\r\n# return ans\r\n \r\ndef mergeDictionary(dict_1, dict_2):\r\n dict_3 = {**dict_1, **dict_2}\r\n for key, value in dict_3.items():\r\n if key in dict_1 and key in dict_2:\r\n dict_3[key] = value + dict_1[key]\r\n return dict_3\r\n \r\ndef rindex(lst, value):\r\n lst.reverse()\r\n i = lst.index(value)\r\n lst.reverse()\r\n return len(lst) - i - 1\r\n \r\ndef mex(arr, N):\r\n\r\n # Sort the array\r\n arr1 = arr.copy()\r\n arr1.sort()\r\n \r\n mex = 0\r\n for idx in range(N):\r\n if arr1[idx] == mex:\r\n\r\n # Increment mex\r\n mex += 1\r\n\r\n # return mex as answer\r\n return mex\r\n \r\ndef fill_prefix_sum(arr, length_arr, prefix_sum):\r\n prefix_sum[0] = arr[0] \r\n\r\n for i in range(1, length_arr): # 1, 2, 3, 4\r\n prefix_sum[i] = prefix_sum[i-1]+ arr[i]\r\n \r\ndef fill_suffix_sum(arr, length_arr, suffix_sum):\r\n suffix_sum[length_arr-1] = arr[length_arr-1] \r\n\r\n for i in reversed(range(length_arr-1)): # 3, 2, 1, 0\r\n suffix_sum[i] = suffix_sum[i+1] + arr[i]\r\n\r\n \r\nletters = [\r\n 'a','b','c','d','e','f',\r\n 'g','h','i','j','k','l',\r\n 'm','n','o','p','q','r',\r\n 's','t','u','v','w','x',\r\n 'y','z']\r\n\r\nmod = 10**9 + 7\r\nstop_reading_my_code = 1 #int(input().strip())\r\n\r\n\r\n\r\ndef f(n) :\r\n q = deque()\r\n memo = {}\r\n q.append([n,0])\r\n while q:\r\n a,dis = q.popleft()\r\n if a%32768 == 0:\r\n return dis\r\n if dis == 15 :\r\n continue\r\n if (a + 1)%32768 not in memo:\r\n q.append([(a+1)%32768,dis+1])\r\n memo[(a + 1)%32768] = dis+1\r\n if (a*2)%32768 not in memo:\r\n q.append([(a*2)%32768,dis+1])\r\n memo[(a*2)%32768] = dis+1\r\n \r\nfrom bisect import bisect_left \r\n\r\nfor _ in range(stop_reading_my_code):\r\n graph = {}\r\n # n = int(input().strip())\r\n n,m, k = list(map(Wrapper,input().strip().split()))\r\n arr = [] \r\n for i in range(n) :\r\n new = list(map(Wrapper,input().strip().split()))\r\n arr.extend(new)\r\n arr.sort()\r\n median1 = arr[(n*m) //2 -1]\r\n median2 = arr[(n*m) //2 ]\r\n ans1 = 0 \r\n ans2 = 0\r\n for i in arr :\r\n if abs(median1-i)%k == 0 :\r\n ans1 += abs(median1-i)//k\r\n else:\r\n ans1 = -1 \r\n break\r\n for i in arr :\r\n if abs(median2-i)%k == 0 :\r\n ans2 += abs(median2-i)//k\r\n else:\r\n ans2 = -1 \r\n break\r\n if ans1 == -1 :\r\n if ans2 == -1 :\r\n print(-1)\r\n else:\r\n print(ans2)\r\n else:\r\n print(min(ans1,ans2)) if ans2 != -1 else print(ans1)\r\n\r\n", "n, m, d = map(int, input().split())\r\nmatrix = []\r\nallEl = []\r\nfor q in range(n):\r\n\tline = [int(i) for i in input().split()]\r\n\tallEl += line\r\n\tmatrix.append(line)\r\n\r\nmod = matrix[0][0] % d\r\nfor i in range(n):\r\n\tfor j in range(m):\r\n\t\tif matrix[i][j] % d != mod:\r\n\t\t\tprint(-1)\r\n\t\t\texit()\r\n\r\nallEl.sort()\r\nchoosed = allEl[n * m // 2]\r\nans = 0\r\nfor i in range(n):\r\n\tfor j in range(m):\r\n\t\tans += abs(matrix[i][j] - choosed) // d\r\nprint(ans)", "from math import gcd\r\n# def f(x,p):\r\n# t = 0\r\n# for i in p:\r\n# t += abs(i-x)//d\r\n\r\nn,m,d = map(int,input().split())\r\np = []\r\nfor i in range(n):\r\n l = list(map(int,input().split()))\r\n p.extend(l)\r\na = 0\r\n\r\nfor i in range(n*m-1):\r\n a = gcd(a,p[i+1]-p[i])\r\n\r\nif a%d != 0:\r\n print(-1)\r\nelse:\r\n p.sort()\r\n x = p[n*m//2]\r\n a = 0\r\n for i in p:\r\n a += abs(i-x)//d\r\n print(a)", "def arr_inp():\r\n return [int(x) for x in stdin.readline().split()]\r\n\r\n\r\nfrom sys import stdin\r\n\r\nn, m, d = arr_inp()\r\nmatrix, diff, s = [], [], 0\r\n\r\nfor i in range(n):\r\n row = arr_inp()\r\n matrix.extend(row)\r\nmatrix.sort()\r\n\r\nfor i in range(1, m * n):\r\n tem = (matrix[i] - matrix[i - 1])\r\n if tem % d:\r\n exit(print(-1))\r\n\r\nans = float('inf')\r\nfor i in range(n * m):\r\n tem = 0\r\n for j in range(0, i):\r\n tem += matrix[i] - matrix[j]\r\n for j in range(i + 1, n * m):\r\n tem += matrix[j] - matrix[i]\r\n ans = min(ans, tem//d)\r\n\r\nprint(ans)\r\n", "n,m,d=map(int,input().split())\r\nl=[]\r\nfor i in range(n):l+=[*map(int,input().split())]\r\nl.sort()\r\nq=0\r\no=len(l)\r\nr=[0for i in range(o)]\r\nfor i in range(1,o):\r\n q+=i*(l[i]-l[i-1])\r\n r[i]+=q\r\nq=0\r\nfor i in range(o-2,-1,-1):\r\n q+=(l[i+1]-l[i])*(o-i-1)\r\n r[i]+=q\r\np=min(r)\r\nprint(-1 if p%d else p//d)", "m,n,d=map(int,input().split())\r\nmatrix = []\r\nfor i in range(m):\r\n matrix+=list(map(int,input().split()))\r\n\r\nremainder=set()\r\nmatrix.sort()\r\nresult = 0\r\nmedian = matrix[len(matrix)//2]\r\nfor i in matrix:\r\n remainder.add(i%d)\r\n result+=abs(i-median)//d\r\nif len(remainder)>1:\r\n print(-1)\r\nelse:\r\n print(result)", "def solve(a, d):\r\n n = len(a)\r\n r = a[0] % d\r\n for i in range(n):\r\n if a[i] % d != r:\r\n return -1\r\n a.sort()\r\n m = a[n//2]\r\n ans = 0\r\n for i in range(n):\r\n ans += abs(a[i]-m) // d\r\n return ans\r\n\r\n\r\nn, m, d = [int(i) for i in input().split()]\r\na = []\r\nfor _ in range(n):\r\n a += [int(i) for i in input().split()]\r\nprint(solve(a, d))\r\n", "n, m, d = map(int, input().split())\r\nsp = []\r\nfor _ in range(n):\r\n for j in map(int, input().split()):\r\n sp.append(j)\r\nsp = sorted(sp)\r\nk = sp[m * n // 2]\r\nfl = True\r\nkl = 0\r\nfor i in sp:\r\n if fl:\r\n if abs(k - i) % d == 0:\r\n kl += abs(k - i) // d\r\n else:\r\n fl = False\r\nif fl:\r\n print(kl)\r\nelse:\r\n print(-1)", "import sys\nn,m,d = list(map(int,input().split()))\ns = 0\na = []\nfor i in range(n):\n v = list(map(int,input().split()))\n a.append(v)\nr1 = a[0][0]%d\nf = 0\nset1 = []\nfor i in a:\n for j in i:\n set1.append(j)\n if j%d != r1:\n print(-1)\n f = 1\n break\n if f==1:\n break\nif f==0:\n set1 = sorted(set1)\n median = set1[(n*m)//2]\n del set1\n for i in a:\n for j in i:\n s += abs(median-j)//d\n print(s)", "a,b,c = map(int, input().split())\r\nx=[]\r\nfor i in range(a):\r\n l = list(map(int, input().split()))\r\n x=x+l\r\nx.sort()\r\nd=0\r\nflag=0\r\nmed =x[(a*b)//2]\r\nfor i in range(a*b):\r\n if(i!=((a*b)//2)):\r\n if(abs(x[i]-med)%c!=0):\r\n flag=1\r\n break\r\n else:\r\n d=d+(abs(x[i]-med))//c\r\nif(flag==1):\r\n print(-1)\r\nelse:\r\n print(d)\r\n \r\n ", "from sys import stdout\r\nfrom sys import stdin\r\ndef get():\r\n return stdin.readline().strip()\r\ndef getf(sp = \" \"):\r\n return [int(i) for i in get().split(sp)]\r\ndef put(a, end = \"\\n\"):\r\n stdout.write(str(a) + end)\r\ndef putf(a, sep = \" \", end = \"\\n\"):\r\n stdout.write(sep.join([str(i) for i in a]) + end)\r\n \r\n#from collections import defaultdict as dd, deque\r\n#from random import randint, shuffle, sample\r\n#from functools import cmp_to_key, reduce\r\n#from math import factorial as fac, acos, asin, atan2, gcd, log, e\r\n#from bisect import bisect_right as br, bisect_left as bl, insort\r\n\r\nfrom bisect import bisect_right as br, bisect_left as bl\r\n\r\ndef main():\r\n n, m, d = getf()\r\n q = [getf() for i in range(n)]\r\n rem = q[0][0] % d\r\n f = True\r\n a = []\r\n for i in range(n):\r\n for j in range(m):\r\n if(q[i][j] % d != rem):\r\n f = False\r\n break\r\n a += [q[i][j]]\r\n if(f == False):\r\n put(-1)\r\n return 0\r\n a.sort()\r\n pr = [0]\r\n k = n * m\r\n for i in range(k):\r\n pr += [pr[i] + a[i]]\r\n min_el = min(a)\r\n max_el = max(a)\r\n res = pr[k]\r\n for targ in range(min_el, max_el + d, d):\r\n l = bl(a, targ)\r\n r = br(a, targ)\r\n d1 = l * targ - pr[l]\r\n d2 = pr[k] - pr[r] - (k - r) * targ\r\n res = min(res, (d1 + d2) // d)\r\n put(res)\r\nmain()\r\n", "n,m,d=map(int,input().split())\r\nf=1 \r\nmat=[]\r\nans=0 \r\nl1=[]\r\nmini=10**7 \r\nfor i in range(n):\r\n l=[int(i) for i in input().split()]\r\n l1+=l \r\n mini=min(mini,min(l))\r\n mat.append(l)\r\nl1.sort() \r\nmed=l1[len(l1)//2]\r\n#print(med)\r\nfor i in range(n):\r\n for j in range(m):\r\n curr=mat[i][j]\r\n if abs((curr-med))%d==0:\r\n ans+=abs(curr-med)//d \r\n else:\r\n f=0 \r\nif f:\r\n print(ans)\r\nelse:\r\n print(-1)", "import sys\r\nn, m, d = map(int, input().split())\r\na = []\r\nfor _ in range(n):\r\n a += [int(x) for x in input().split()]\r\na.sort()\r\nfor i in range(n*m-1, -1, -1):\r\n a[i] -= a[0]\r\n if a[i]%d!=0:\r\n print(\"-1\")\r\n break\r\nelse:\r\n k = (n*m)//2\r\n t = a[k]\r\n ans = 0\r\n for x in a:\r\n ans += abs(x-t)//d\r\n print(ans) \r\n", "from sys import stdin ,stdout\ninput=stdin.readline\ndef print(*args, end='\\n', sep=' ') -> None:\n\tstdout.write(sep.join(map(str, args)) + end)\nn, m, d = map(int, input().split())\nmn = 10**9\ncounter = [0]*101\ntotal = 0\nl = []\nfor i in range(n):\n\tfor x in input().split():\n\t\tl.append(int(x))\nf = False\nans = 10**9\nfor i in range(len(l)):\n\tele = l[i]\n\ttotal = 0\n\tfor j in range(m*n):\n\t\tif j != i:\n\t\t\tif abs(l[i] - l[j]) % d:\n\t\t\t\tf = True\n\t\t\t\tbreak\n\t\t\ttotal += abs(l[i] - l[j]) // d\n\tif f:\n\t\tbreak\n\telse: ans = min(ans, total)\n\t\nprint(ans if not f else -1)\n\n\n\t\t\t\n\t\t\t\n\t\t\n\t\t\n\t\t\n\t\n\t\n\t\n\t\n\t\n\n\n\t\n", "n,m,d=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n a += list(map(int, input().split()))\r\na.sort()\r\nc = a[len(a)//2]\r\ncount = 0\r\nfor i in a :\r\n b = abs(c-i)\r\n if b%d != 0 :\r\n print(-1)\r\n exit()\r\n else:\r\n f=b//d\r\n count+=f\r\nprint(count)\r\n", "N, M, d = [int(x) for x in input().split()]\r\n\r\n\r\nnumbers = []\r\n\r\nfor i in range(N):\r\n numbers.append([int(x) for x in input().split()])\r\n\r\nanswer = True\r\n\r\nmodulus = numbers[0][0] % d\r\n\r\n\r\nmaxi = 0\r\nmini = 10**5\r\n\r\nmedians = []\r\n\r\n\r\nfor i in range(N):\r\n for j in range(M):\r\n\r\n if numbers[i][j] % d != modulus:\r\n answer = False\r\n break\r\n\r\n division = numbers[i][j] // d\r\n\r\n medians.append(division)\r\n\r\n \r\n\r\n if not answer:\r\n break\r\n\r\namount = 0\r\n\r\nif answer:\r\n medians.sort()\r\n\r\n middle = medians[len(medians)//2]\r\n\r\n for i in medians:\r\n amount += abs(middle-i)\r\n\r\n print(amount)\r\n\r\nelse:\r\n print(-1)\r\n", "array = []\r\nn, m, d = input().split()\r\nn, m, d = int(n), int(m), int(d)\r\n\r\nfor i in range(n):\r\n array += list(map(int, input().split()))\r\nrem = array[0] % d\r\nflag = False\r\nfor j in range(m*n):\r\n if array[j] % d != rem:\r\n flag = True\r\nif flag:\r\n print('-1')\r\nelse:\r\n array.sort()\r\n median = len(array)//2\r\n ans = 0\r\n for i in range(n*m):\r\n val = array[i] - array[median]\r\n if val < 0:\r\n val = -val\r\n ans += val\r\n print(ans//d)", "import sys\r\na,b,c=map(int,input().split())\r\nl=[0]*(a*b)\r\nd=[[0 for j in range(b)]for i in range(a)]\r\nfor i in range(a):\r\n d[i]=list(map(int,input().split()))\r\nt=0\r\nfor i in range(a):\r\n for j in range(b):\r\n l[t]=d[i][j]\r\n t+=1\r\nl.sort()\r\nfor i in range(a*b-1):\r\n if l[i]%c!=(l[i+1])%c:\r\n print(-1)\r\n sys.exit()\r\nc3=l[(a*b)//2]\r\nc2=l[(a*b)//2-1]\r\nans=0\r\nans2=0\r\nfor i in range(a*b):\r\n ans+=abs(l[i]-c3)\r\n ans2+=abs(l[i]-c2)\r\ncw=min(ans,ans2)\r\nprint(cw//c)", "from collections import Counter\r\n\r\nn, m, d = map(int, input().split())\r\na = []\r\n\r\nfor i in range(n):\r\n a += tuple(map(int, input().split()))\r\n \r\nc = a[0]%d\r\nok = True\r\n\r\nfor i in a:\r\n if i%d != c:\r\n ok = False\r\n break\r\n \r\nif ok:\r\n mx = 1e18\r\n for i in range(n*m):\r\n ct = 0\r\n for j in range(n*m):\r\n if i != j:\r\n ct += abs(a[i]-a[j])//d\r\n \r\n mx = min(mx, ct)\r\n \r\n print(mx)\r\n \r\nelse:\r\n print(-1)\r\n ", "n, m, d = map(int, input().split())\na = []\nfor i in range(n):\n\tgrid = list(map(int, input().split()))\n\ta = a + grid\na = sorted(a); l = len(a)\ntarget = a[l // 2]\ncount = 0\nfor i in range(l):\n\tif ((target - a[i]) % d) != 0:\n\t\tprint(-1)\n\t\texit()\n\tcount += abs(a[i] - target) // d\nprint(count)\n", "n, m, d = [int(i) for i in input().split()]\r\nmatrix = []\r\nfor i in range(n):\r\n matrix.append([int(i) for i in input().split()])\r\nflag = 0\r\nstart_parity = matrix[0][0]%d\r\nele = []\r\nfor i in range(n):\r\n for j in range(m):\r\n ele.append(matrix[i][j])\r\n if matrix[i][j] % d != start_parity:\r\n flag = 1\r\nif flag:\r\n print(-1)\r\nelse:\r\n ans = 0\r\n ele.sort()\r\n num = len(ele)\r\n mid = num//2\r\n target = ele[mid]\r\n for i in range(num):\r\n temp = abs(target-ele[i])\r\n ans += (temp // d)\r\n print(ans)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "def minmove(arr,val,d):\r\n minmove=0\r\n for i in range(len(arr)):\r\n minmove+=(abs(arr[i]-val))//d\r\n return minmove\r\n\r\n\r\nrow,col,d=map(int,input().split())\r\nmatrix=[]\r\nfor i in range(row):\r\n matrix.append(list(map(int,input().split())))\r\ncheck=True\r\ntmp=matrix[0][0]%d\r\nfor i in range(row):\r\n for j in range(col):\r\n if matrix[i][j]%d!=tmp:\r\n check=False\r\n break\r\nif not check:\r\n print(-1)\r\nelse:\r\n lst=[]\r\n for i in range(row):\r\n for j in range(col):\r\n lst.append(matrix[i][j])\r\n lst.sort()\r\n minn1=99999999999\r\n minn2=99999999999\r\n if len(lst)%2==0:\r\n minn1=min(minmove(lst,lst[len(lst)//2],d),minmove(lst,lst[(len(lst)//2)-1],d))\r\n print(minn1)\r\n else:\r\n minn2=minmove(lst,lst[len(lst)//2],d)\r\n print(minn2)\r\n", "import sys\r\ninput = sys.stdin.readline\r\nfrom collections import defaultdict, deque\r\np = print\r\nr = range\r\ndef I(): return int(input())\r\ndef II(): return list(map(int, input().split()))\r\ndef S(): return input()[:-1]\r\ndef M(n): return [list(map(int, input().split())) for ___ in r(n)]\r\ndef pb(b): print('YES' if b else 'NO')\r\ndef INF(): return float('inf')\r\n# -----------------------------------------------------------------------------------------------------\r\n#\r\n#             ∧_∧\r\n#       ∧_∧   (´<_` )  Welcome to My Coding Space !\r\n#      ( ´_ゝ`) /  ⌒i Free Hong Kong !\r\n#     /   \    | | Free Tibet !\r\n#     /   / ̄ ̄ ̄ ̄/ |  |\r\n#   __(__ニつ/  _/ .| .|____\r\n#      \/____/ (u ⊃\r\n#\r\n# 再帰関数ですか? SYS!!!!\r\n# BINARY SEARCH ?\r\n# -----------------------------------------------------------------------------------------------------\r\nn, m, d = II()\r\na = []\r\nfor i in r(n):\r\n a += II()\r\nminv = min(a)\r\nfor x in a:\r\n if (x-minv)%d:\r\n p(-1)\r\n exit(0)\r\na.sort()\r\nif (n*m)%2:\r\n cyuo = [a[(n*m)//2]]\r\nelse:\r\n cyuo = [a[(n*m)//2],a[(n*m)//2-1]]\r\nres = INF()\r\nfor k in cyuo:\r\n t = 0\r\n for x in a:\r\n t += (abs(x-k))//d\r\n res = min(t,res)\r\np(res)", "n, m, d = map(int, input().split())\r\n\r\narr = []\r\nremainder = -1\r\nflag = True\r\n\r\nfor _ in range(n):\r\n for i in input().split():\r\n arr.append(int(i))\r\n temp = int(i) % d\r\n if remainder == -1:\r\n remainder = temp\r\n elif remainder != -1 and temp != remainder:\r\n flag = False\r\n break\r\n if flag == False:\r\n break\r\n\r\nif flag:\r\n arr.sort()\r\n k = n*m\r\n sum_mod = 0\r\n mid = arr[int(k/2)]\r\n for i in range(k):\r\n sum_mod += abs(arr[i] - mid)\r\n\r\nif flag:\r\n print(int(sum_mod/d))\r\nelse:\r\n print(-1)", "n, m, d = map(int, input().split())\r\na = []\r\n\r\nflag = True\r\nfor i in range(n):\r\n a += list(map(int, input().split()))\r\n\r\nr = a[0] % d\r\nfor i in range(len(a)):\r\n if r != a[i] % d:\r\n flag = False\r\n\r\nif flag:\r\n k = len(a)\r\n a.sort()\r\n res = 0\r\n c = a[k//2]\r\n for i in range(k):\r\n res += abs(c - a[i]) // d\r\n print(res)\r\nelse:\r\n print(-1)\r\n\r\n\r\n", "a,b,c=list(map(int,input().split()))\r\nmatrix=[]\r\nfor i in range(a):\r\n d=list(map(int,input().split()))\r\n for i in d:\r\n matrix.append(i)\r\nmatrix=sorted(matrix)\r\ne=matrix[len(matrix)//2]\r\n#print(e)\r\ndef ok():\r\n ans=0\r\n for i in matrix:\r\n if i==e:\r\n continue\r\n elif ((e-i)%c)!=0:\r\n return -1\r\n else:\r\n #print(e-i)\r\n ans=ans+abs((e-i)//c)\r\n return ans\r\nprint(ok())", "def solve():\r\n n, m, d = map(int, input().split())\r\n a = []\r\n for _ in range(n): a.extend(list(map(int, input().split())))\r\n\r\n a.sort()\r\n r = a[0] % d\r\n for i in range(n * m):\r\n if a[i] % d != r: return -1\r\n\r\n p = a.copy()\r\n s = a.copy()\r\n \r\n for i in range(1, n * m): p[i] += p[i - 1]\r\n for i in range(n * m - 2, -1, -1): s[i] += s[i + 1]\r\n\r\n ans = min(s[0] - n * m * a[0], n * m * a[-1] - p[-1])\r\n\r\n l = 1\r\n for k in range(a[0] + d, a[-1], d):\r\n while a[l + 1] <= k: l += 1\r\n ans = min(ans, k * (2 * l + 2 - n * m) - p[l] + s[l + 1])\r\n\r\n return ans // d\r\n\r\nprint(solve())\r\n", "import random\r\nimport math\r\nfrom collections import defaultdict\r\nimport itertools\r\nfrom sys import stdin, stdout\r\nimport sys\r\nimport operator\r\nfrom decimal import Decimal\r\n\r\n\r\n# sys.setrecursionlimit(1500000000)\r\n\r\n\r\n\r\ndef main():\r\n # z = ''\r\n # p = lambda *a: print(*a, flush = True)\r\n # d = defaultdict()\r\n\r\n mod = 10 ** 9 + 7\r\n\r\n # t = int(input())\r\n # for _ in range(t):\r\n # n = int(input())\r\n # c, m, p, v = map(float, input().split())\r\n\r\n n, m, d = list(map(int, input().split()))\r\n a = []\r\n for i in range(n):\r\n a += list(map(int, input().split()))\r\n\r\n #print(a)\r\n l = n*m\r\n a.sort()\r\n b = []\r\n flag = 0\r\n for j in range(l):\r\n if (a[j]-a[0])%d!=0:\r\n flag = 1\r\n break\r\n else:\r\n b.append((a[j]-a[0])//d)\r\n if flag == 1:\r\n print(-1)\r\n else:\r\n #print(b)\r\n lb = len(b)\r\n sb = sum(b)\r\n if lb%2==1:\r\n ans = 0\r\n mid = b[lb//2]\r\n for i in range(lb):\r\n ans+= abs(b[i]-mid)\r\n print(ans)\r\n else:\r\n ans1 = 0\r\n ans2 = 0\r\n mid1 = b[lb // 2]\r\n mid2 = b[lb // 2-1]\r\n for i in range(lb):\r\n ans1 += abs(b[i] - mid1)\r\n ans2+= abs(b[i]-mid2)\r\n\r\n print(min(ans1, ans2))\r\n\r\n\r\n # s = input()\r\n\r\n # s = input()\r\n\r\n # z += str(ans) + '\\n'\r\n # stdout.write(z)\r\n\r\n\r\n# for interactive problems\r\n# print(\"? {} {}\".format(l,m), flush=True)\r\n# or print this after each print statement\r\n# sys.stdout.flush()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "import sys\r\n\r\ndef answer(n, m, d, a):\r\n a.sort()\r\n med = a[(n*m)//2]\r\n num_moves = 0\r\n for i in range((n*m)):\r\n diff = abs(a[i] - med)\r\n if diff % d == 0:\r\n num_moves += diff // d\r\n else:\r\n return -1\r\n return num_moves\r\n\r\ndef main():\r\n n, m, d = map(int, sys.stdin.readline().split())\r\n a = []\r\n for i in range(n):\r\n a.extend(list(map(int, sys.stdin.readline().split())))\r\n print(answer(n, m, d, a))\r\n return\r\nmain()", "def solve(l,minsol):\r\n sol=0\r\n for i in l:\r\n sol+=abs(minsol-i)\r\n return sol\r\nl=[]\r\nr,c,d=list(map(int,input().split()))\r\nfor i in range(r):\r\n l+=list(map(int,input().split()))\r\nres=l[0]%d\r\nfor i in l:\r\n if i%d!=res:\r\n print(\"-1\")\r\n break\r\nelse:\r\n sol=0\r\n l.sort()\r\n if len(l)%2!=0:\r\n print(solve(l,l[len(l)//2])//d)\r\n else:\r\n print(min(solve(l,l[len(l)//2]),solve(l,l[len(l)//2-1]))//d)", "while True:\n\ttry:\n\t\t\n\t\tdef solution(len, res, d):\n\t\t\tmid = 0\n\t\t\tif (len % 2) == 0:\n\t\t\t\tmid = len//2\n\t\t\telse:mid = len//2 +1\n\t\t\tans = 0\n\t\t\tvalid = True\n\t\t\tfor i in range(len):\n\t\t\t\tif res[i] != res[mid-1]:\n\t\t\t\t\ttem = abs(res[mid-1] - res[i])\n\t\t\t\t\tif tem % d != 0:\n\t\t\t\t\t\tvalid = False\n\t\t\t\t\tif not valid:break\n\t\t\t\t\tans += tem//d\n\t\t\tif not valid:print(\"-1\")\n\t\t\telse:print(ans)\t\t\n\t\t\t\n\t\tdef read():\n\t\t\tn, m, d = map(int, input().split())\n\t\t\tres = list()\n\t\t\tfor i in range(n):\n\t\t\t\ttemp = list(map(int, input().split()))\n\t\t\t\tfor j in range(m):\n\t\t\t\t\tres.append(temp[j])\n\t\t\t\tdel temp\n\t\t\tres.sort()\n\t\t\tsolution(n*m, res, d)\n\t\t\t\n\t\n\t\tif __name__ == \"__main__\":\n\t\t\tread()\n\texcept EOFError:\n\t\tbreak", "import math\r\nimport bisect\r\n\r\ndef input_list_int():\r\n return list(map(int, input().split()))\r\n\r\nn, m, d = input_list_int()\r\n\r\nmatrix = []\r\nfor i in range(n):\r\n tmp = input_list_int()\r\n for el in tmp: \r\n matrix.insert(bisect.bisect_left(matrix, el), el)\r\n\r\nmiddle = matrix[int(math.floor(len(matrix))/2)]\r\n\r\ne = 0\r\nfor el in matrix:\r\n if abs(middle - el) % d == 0:\r\n e += abs(middle-el)/d\r\n else:\r\n print(-1)\r\n exit()\r\n\r\n\r\nprint(int(e))", "R=lambda:map(int,input().split())\r\nn,m,d=R()\r\na=[]\r\nb=[]\r\nfor _ in range(n):\r\n w=list(R())\r\n a.append(w)\r\nfor i in a:\r\n for j in i:\r\n b.append(j)\r\nb.sort()\r\n\r\n\r\nfor i in range(1,len(b)):\r\n if((b[i]-b[i-1])%d==0):\r\n continue\r\n else:\r\n print(-1)\r\n quit()\r\n\r\nm=b[len(b)//2]\r\nc=0\r\n\r\nfor i in range(len(b)//2):\r\n c+=abs((m-b[i])//d)\r\n\r\nfor j in range((len(b)//2)+1,len(b)):\r\n c+=abs((m-b[j])//d)\r\nprint(c)\r\n\r\n\r\n", "n, m, d = list(map(int, input().split()))\r\nno = []\r\nmin = -1\r\nflag = 1\r\nfor _ in range(n):\r\n A = list(map(int, input().split()))\r\n for i in A:\r\n if flag:\r\n if min == -1:\r\n min = i\r\n no.append(i)\r\n else:\r\n if abs(min - i) % d == 0:\r\n no.append(i)\r\n else:\r\n print(-1)\r\n flag = 0\r\n break\r\nif flag:\r\n no.sort()\r\n # print(no)\r\n # print(int(n*m/2))\r\n middle = no[int(n * m / 2)]\r\n # print(middle)\r\n ans = 0\r\n for i in no:\r\n # print()\r\n # print(i,abs(i-middle))\r\n ans += abs(i - middle) / d\r\n\r\n print(int(ans))\r\n", "n,m,d=map(int,input().split())\r\na=[0]\r\nfor i in range(n):\r\n a+=list(map(int,input().split()))\r\na.sort()\r\ns=set()\r\nfor i in range(1,len(a)):\r\n s.add(a[i]%d)\r\nif len(s)>=2:\r\n print(-1)\r\n exit()\r\naa=[0]*(n*m+1)\r\nfor i in range(1,n*m+1):\r\n aa[i]=aa[i-1]+a[i]\r\nans=10**18\r\nfor i in range(1,n*m+1):\r\n ans=min(ans,(aa[-1]-2*aa[i]-(n*m-2*i)*a[i])//d)\r\nprint(ans)", "s = input().split()\r\nn, m, d = int(s[0]), int(s[1]), int(s[2])\r\n\r\nl = []\r\n\r\nfor i in range(n):\r\n\tfor i in map(int, input().split()):\r\n\t\tl.append(i)\r\n\r\na = sorted(l)\r\n\r\nmedian = a[(n * m) // 2]\r\n\r\ns = 0\r\n\r\nfor i in l:\r\n\ts += abs(i - median)\r\n\r\nif s % d == 0:\r\n\tprint(s // d)\r\nelse:\r\n\tprint(-1)", "n, m, d = map(int, input().split())\r\na = []\r\nfor i in range(n):\r\n a.extend(map(int, input().split()))\r\na.sort()\r\n \r\nn = len(a)\r\nc = 0\r\nj = a[n//2]\r\nfor i in a:\r\n t = abs(i-j)\r\n if t % d:\r\n c = -1\r\n break\r\n else:\r\n c += t // d\r\n \r\nprint(c)", "n, m, d = [int(x) for x in input().split()]\r\n\r\nnumbers = []\r\nfor i in range(n):\r\n row = [int(x) for x in input().split()]\r\n numbers += row\r\n\r\nnumbers.sort()\r\nnc = len(numbers)\r\n\r\nsums_left = [0]\r\nsums_right = [0] * nc\r\nfor i in range(1, nc):\r\n diff = numbers[i] - numbers[i - 1]\r\n if diff % d != 0:\r\n print(-1)\r\n exit(0)\r\n sums_left.append(sums_left[i - 1] + i * (diff // d))\r\n\r\n diff_r = numbers[nc - i] - numbers[nc - i - 1]\r\n sums_right[nc - i - 1] = sums_right[nc - i] + i * (diff_r // d)\r\n\r\ntotal_sums = []\r\nfor i in range(nc):\r\n total_sums.append(sums_left[i] + sums_right[i])\r\n\r\nprint(min(total_sums))\r\n\r\n", "n,m,d=map(int,input().split());l=[]\r\nfor i in range(n):\r\n\tl.extend(list(map(int,input().split())))\r\nl.sort();t=n*m;a,b=l[t//2],l[t//2-1];x,y=0,0\r\nfor i in range(t):\r\n\tx+=abs(l[i]-a)\r\n\ty+=abs(l[i]-b)\r\nif x%d==0 and y%d==0:\r\n\tprint(min(x,y)//d)\r\nelse:print(-1)", "from sys import *\r\ninput = lambda:stdin.readline()\r\n\r\nint_arr = lambda : list(map(int,stdin.readline().strip().split()))\r\nstr_arr = lambda :list(map(str,stdin.readline().split()))\r\nget_str = lambda : map(str,stdin.readline().strip().split())\r\nget_int = lambda: map(int,stdin.readline().strip().split())\r\nget_float = lambda : map(float,stdin.readline().strip().split())\r\n\r\n\r\nmod = 1000000007\r\nsetrecursionlimit(1000)\r\n\r\nn,m,d = get_int()\r\nlst = []\r\nfor i in range(n):\r\n arr = int_arr()\r\n lst += arr\r\n\r\nlst.sort()\r\ntot = 0\r\nl = len(lst)\r\nif l % 2 != 0:\r\n mid = lst[l // 2]\r\n for i in range(l):\r\n val = abs(lst[i] - mid)\r\n if val % d != 0:\r\n tot = -1\r\n break\r\n else:\r\n tot += val // d\r\n print(tot)\r\nelse:\r\n mid = lst[l // 2 - 1]\r\n mid1 = lst[l // 2]\r\n for i in range(l):\r\n val = abs(lst[i] - mid)\r\n if val % d != 0:\r\n tot = -1\r\n break\r\n else:\r\n tot += val // d\r\n print(tot)\r\n \r\n", "n,m,d=map(int,input().split())\r\nmat=[]\r\nfor i in range(n):\r\n mat.append(list(map(int,input().split())))\r\nele=set();chk=0;arr=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n ele.add(mat[i][j])\r\n arr.append(mat[i][j])\r\nif len(ele)==1:\r\n print(0)\r\nelse:\r\n arr.sort()\r\n e=arr[(n*m)//2]\r\n for i in range(n):\r\n for j in range(m):\r\n if(abs(mat[i][j]-e)%d!=0):\r\n chk+=1\r\n if chk!=0:\r\n print(-1)\r\n else:\r\n moves=0\r\n for i in range(n):\r\n for j in range(m):\r\n\r\n if e>mat[i][j]:\r\n moves+=abs(mat[i][j]-e)//d\r\n if e<mat[i][j]:\r\n moves+=abs(mat[i][j]-e)//d\r\n print(moves)\r\n \r\n \r\n", "n, m, k=map(int, input().split())\r\nl={0:None}\r\nl1=[]\r\nsuma=0\r\nfor i in range(n):\r\n e=list(map(int, input().split()))\r\n for j in range(m):\r\n if e[j] not in l1:\r\n l[e[j]]=1\r\n l1.append(e[j])\r\n else:\r\n l[e[j]]+=1\r\n suma+=e[j]\r\n\r\ne=True\r\nfor i in range(len(l1)):\r\n kek=abs(suma-n*m*l1[i])\r\n if kek%k>0:\r\n e=False\r\n break\r\n\r\nif e:\r\n mini=10**10\r\n for i in range(len(l1)):\r\n ans=0\r\n for j in range(len(l1)):\r\n if i!=j:\r\n ej=abs(l1[i]-l1[j])//k\r\n ej*=l[l1[j]]\r\n ans+=ej\r\n mini=min(ans, mini)\r\n print(mini)\r\nelse:\r\n print(-1)", "m,n,d=map(int,input().split());l=[]\r\nmedean=int((n*m)/2);ans=0;e=0\r\nfor i in range(m):\r\n l.extend(map(int,input().split()))\r\nl.sort()\r\nfor i in (l):\r\n v=0\r\n if i<l[medean] or i>l[medean] :\r\n v=abs(l[medean]-i)\r\n if v%d==0:\r\n ans+=v//d\r\n else:\r\n e+=1\r\nif e>0 :\r\n print(-1)\r\nelse:\r\n print(ans)", "n,m,d=map(int,input().split())\r\nl=[];flag=False\r\nfor i in range(n):\r\n l_=list(map(int,input().split()))\r\n l+=l_\r\np=l[0]%d\r\nfor i in range(1,n*m):\r\n if p!=l[i]%d:flag=True;break\r\n\r\nif flag:print(-1)\r\nelse:\r\n l.sort()\r\n ans=0\r\n for i in range(n*m):\r\n ans+=abs(l[i]-l[m*n//2])\r\n print(ans//d)", "if __name__ == '__main__':\n h,w,d = input().split()\n w = int(w)\n h = int(h)\n d = int(d)\n\n arr = [[int(x) for x in input().split()] for y in range(h)] \n \n arr = [ele for i in arr for ele in i]\n # print(arr)\n arr.sort()\n # print(arr)\n countr = 0\n if(len(arr)>1):\n if(len(arr)%2==0):\n mid_index = int(len(arr)/2) - 1\n else:\n mid_index = int(len(arr)/2)\n else:\n mid_index = 0 \n mid = arr[mid_index]\n for i in range(0,len(arr)):\n if(mid>arr[i]):\n diff = mid - arr[i]\n if(diff%d==0):\n countr+=int(diff/d)\n else:\n countr = -1\n break\n else:\n diff = arr[i] - mid\n if(diff%d==0):\n countr+=int(diff/d)\n else:\n countr = -1\n break\n\n print(countr) \n\n\n\n # print(arr)\n # cnt = 0\n # for i in range(0,len(arr)-1):\n # diff = arr[i+1] - arr[i]\n # if(diff%d==0):\n # if(diff>=0):\n # cnt+=int(diff/d)\n # else:\n # cnt+=-int(diff/d)\n # else:\n # cnt = -1\n # break \n\n # print(cnt) \n", "def main() :\r\n n,m,d = map(int,input().split())\r\n l = list()\r\n for _ in range(n):\r\n a = list(map(int,input().split()))\r\n l += a\r\n l.sort()\r\n test = True\r\n z = l[0]%d\r\n for i in l[1:] :\r\n if i%d != z :\r\n test = False\r\n break\r\n if test :\r\n c = 0\r\n length = n*m\r\n mid = n*m//2\r\n for j in range(length) :\r\n if j != mid : c += (abs(l[j]-l[mid]))\r\n print(c//d)\r\n else : print(-1) \r\n\r\nmain()", "n, m, d = map(int, input().split())\r\nnums = []\r\n\r\nfor i in range(n):\r\n row = [int(x) for x in input().split()]\r\n nums.extend(row)\r\n\r\nbest = float('inf')\r\nfor num in nums:\r\n result = 0\r\n for other in nums:\r\n if num == other:\r\n continue\r\n\r\n if abs(other - num) % d == 0:\r\n result += abs(other - num) // d\r\n else:\r\n print(-1)\r\n exit(0)\r\n best = min(best, result)\r\n\r\nprint(best)\r\n", "n, m, d = map(int, input().split())\nl = []\nfor i in range(n):\n l.extend(list(map(int, input().split())))\nif not all((l[0] - i) % d == 0 for i in l):\n print(-1)\n exit()\nl.sort()\nans = 0\nfor i in l:\n ans += abs(i - l[n * m // 2]) // d\nprint(ans)\n", "n,m,d = map(int,input().strip().split())\r\nA=[]\r\nfor _ in range(n): A.extend(map(int,input().strip().split()))\r\n\r\ns = A[0]%d\r\nA.sort()\r\nn *= m\r\nif n % 2:\r\n med =med_2= A[n//2]\r\nelse:\r\n med = A[n//2]\r\n med_2 = A[n//2 - 1]\r\n\r\ncnt1,cnt2=0,0\r\nfor j in A:\r\n if j % d != s:\r\n print(-1)\r\n exit(0)\r\n med = A[n//2]\r\n cnt1 += abs(med-j)//d\r\n cnt2 += abs(med_2-j)//d\r\nprint(min(cnt1,cnt2))", "a,b,d=map(int,input().split())\r\nans=[]\r\nif(a==1 and b==1):\r\n print(0)\r\n exit()\r\nfor i in range(a):\r\n z=list(map(int,input().split()))\r\n ans.extend(z)\r\nans.sort()\r\narr=[]\r\ntotal=0\r\nfor i in range(1,len(ans)):\r\n arr.append(ans[i]-ans[i-1])\r\n\r\nfor i in range(len(arr)):\r\n if(arr[i]%d!=0):\r\n print(-1)\r\n exit()\r\ntr=ans[len(ans)//2]\r\nfor i in range(len(ans)):\r\n total+=((abs(ans[i]-tr))//d)\r\nprint(total)\r\n \r\n \r\n \r\n \r\n", "n,m,d=map(int,input().split())\r\nl=[]\r\ns=set()\r\nfor _ in range(n):\r\n\tfor i in list(map(int,input().split())):\r\n\t\tl.append(i)\r\n\t\ts.add(i%d)\r\nif len(s)>1:\r\n\tprint(-1)\r\n\texit()\r\nl.sort()\r\na=l[(n*m)//2]\r\nans=0\r\nfor i in l:\r\n\tans+=(abs(i-a))//d\r\nprint(ans)", "\r\nfrom math import ceil, gcd, inf, sqrt\r\nfrom os import P_DETACH, rename\r\n\r\n\r\ndef pro(arr,d):\r\n n=len(arr)\r\n m=len(arr[0])\r\n \r\n lst=[]\r\n for i in range(n):\r\n for j in range(m):\r\n lst.append(arr[i][j])\r\n lst.sort()\r\n median = ( 0 + m*n -1 ) //2\r\n median = lst[median]\r\n \r\n ops=0\r\n for i in range(n*m):\r\n if( (abs ( median -lst[i] )) %d ):\r\n print(-1)\r\n return\r\n ops+= (abs ( median -lst[i] )) // d\r\n \r\n \r\n print(ops)\r\n \r\nn,m,d=list(map(int,input().split()))\r\narr=[]\r\nfor i in range(n):\r\n arr.append ( list(map(int,input().split())) )\r\npro(arr,d)", "import sys\r\nfrom os import path\r\nfrom math import gcd,floor,sqrt,log,ceil\r\nfrom bisect import bisect_left, bisect_right\r\nfrom heapq import heappop, heappush, heapify\r\n\r\n############ ---- Input Functions ---- ####################\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\ndef inmatrix(n,m):\r\n arr=[]\r\n for i in range(n):\r\n temp=inlt()\r\n arr.append(temp)\r\n return arr\r\n############################################################\r\ndef cuberoot(x):\r\n if 0<=x: return x**(1./2.)\r\n return -(-x)**(1./2.)\r\ndef is_anagram(str1, str2):\r\n return sorted(str1) == sorted(str2)\r\n############################################################\r\nmod=1000000007\r\n############################################################\r\nif(path.exists('input.txt')):\r\n sys.stdin = open(\"input.txt\",\"r\")\r\n sys.stdout = open(\"output.txt\",\"w\")\r\n sys.stderr = open(\"error.txt\", \"w\")\r\nelse:\r\n input = sys.stdin.readline\r\n############################################################\r\n# class Graph:\r\n \r\n# # init function to declare class variables\r\n# def __init__(self, V):\r\n# self.V = V\r\n# self.adj = [[] for i in range(V)]\r\n# self.cyclenumber=0\r\n# self.cycles=[[] for i in range(V)]\r\n \r\n# def DFSUtil(self, temp, v, visited):\r\n \r\n# # Mark the current vertex as visited\r\n# visited[v] = True\r\n \r\n# # Store the vertex to list\r\n# temp.append(v)\r\n \r\n# # Repeat for all vertices adjacent\r\n# # to this vertex v\r\n# for i in self.adj[v]:\r\n# if visited[i] == False:\r\n \r\n# # Update the list\r\n# temp = self.DFSUtil(temp, i, visited)\r\n# return temp\r\n \r\n# # method to add an undirected edge\r\n# def addEdge(self, v, w):\r\n# self.adj[v].append(w)\r\n# self.adj[w].append(v)\r\n \r\n# # Method to retrieve connected components\r\n# # in an undirected graph\r\n# def connectedComponents(self):\r\n# visited = []\r\n# cc = []\r\n# for i in range(self.V):\r\n# visited.append(False)\r\n# for v in range(self.V):\r\n# if visited[v] == False:\r\n# temp = []\r\n# cc.append(self.DFSUtil(temp, v, visited))\r\n# return cc\r\n\r\n\r\ndef solve():\r\n n,m,d=invr()\r\n ar=[]\r\n for i in range(n):\r\n t=inlt()\r\n ar+=t\r\n ar.sort()\r\n c=0\r\n ele=ar[n*m//2]\r\n # print(ele)\r\n for i in range(len(ar)):\r\n if abs(ele-ar[i])%d!=0:\r\n print(-1)\r\n return\r\n else:\r\n c+=abs(ele-ar[i])//d\r\n print(c)\r\n \r\n\r\ndef main():\r\n # T=inp()\r\n T=1\r\n for i in range(1,T+1):\r\n #print(\"Case #{}:\".format(i),end=\" \")\r\n solve()\r\n\r\nmain() ", "n, m, d = map(int, input().split())\r\narr = []\r\nfor _ in range(n):\r\n arr.extend(list(map(int, input().split())))\r\narr.sort()\r\n\r\nsize = n * m\r\nmedian = arr[size//2]\r\narr = [abs(i - median) for i in arr]\r\ns = sum(arr)\r\nif s % d == 0:\r\n print (s // d)\r\nelse:\r\n print(\"-1\")\r\n", "n,m,d=map(int,input().split())\r\nlis=[]\r\nfor i in range(n):\r\n lis+=list(map(int,input().split()))\r\nlis.sort()\r\nval=lis[n*m//2]\r\nans=0;flag=True\r\nfor i in range(n*m):\r\n if abs(val-lis[i])%d==0:\r\n ans+=abs(val-lis[i])//d\r\n else:\r\n flag=False\r\n break\r\nif flag:\r\n print(ans)\r\nelse:\r\n print(-1)", "import sys\r\ninput = sys.stdin.readline\r\nn,m,d = map(int,input().split())\r\na = []\r\nfor i in range(n):\r\n b = list(map(int,input().split()))\r\n a.extend(b)\r\n \r\na.sort()\r\n\r\nmid = a[(n*m)//2]\r\nans = 0\r\n\r\nfor i in range(n*m):\r\n if abs(a[i]-mid)%d != 0:\r\n ans = -1\r\n break\r\n else:\r\n ans += abs(a[i]-mid)//d\r\n \r\nprint(ans)", "\n\n\n\nn, m, d = map(int, input().split())\n\nnums = []\nfor i in range(n):\n nums += list(map(int, input().split()))\n\n\nnums.sort()\nmidNum = nums[n*m//2]\n\ncount = 0\n\nfor i in range(n*m):\n if abs(nums[i] - midNum) % d == 0:\n count += abs(nums[i] - midNum) // d\n else:\n print(-1)\n exit()\n \n \nprint(count)\n\n \n\n\n\n\n\n\n\t \t\t\t \t \t\t\t\t\t \t \t \t", "n,m,d = map(int,input().split())\r\ns = [[int(i) for i in input().split()] for i in range(n)]\r\ne =set()\r\n\r\nfor i in s:\r\n for j in i:\r\n e.add(j%d)\r\nif len(e)>1:\r\n print(\"-1\")\r\n exit()\r\n\r\nt = []\r\nfor i in s:\r\n for j in i:\r\n t.append(j)\r\nt.sort()\r\ncnt = 0\r\nmed = (len(t)+1)//2-1\r\n\r\nfor i in range(n*m):\r\n cnt += abs(t[i]-t[med])\r\n\r\nprint(cnt//d)\r\n\r\n\r\n\r\n", "# Online Python compiler (interpreter) to run Python online.\r\n# Write Python 3 code in this online editor and run it.\r\nn,m,d=map(int,input().split())\r\nx=[]\r\nfor i in range(n):\r\n p=list(map(int,input().split()))\r\n x+=p\r\nx.sort()\r\na=x[0]\r\nflag=0\r\nmed=x[(n*m)//2]\r\nc=0\r\n\r\nfor i in range(len(x)):\r\n if (x[i]-a)%d !=0:\r\n print(-1)\r\n flag=1\r\n break\r\n else:\r\n #print(x[i])\r\n c+=abs(x[i]-med)//d\r\n \r\nif flag==0:\r\n print(c)", "n, m, d = [int(x) for x in input().split(' ')]\n\ntotal = n*m\ntotal_matrix = []\n\nfor i in range(n):\n\ttotal_matrix += [int(x) for x in input().split(' ')]\n\ntotal_matrix = sorted(total_matrix)\n\nmiddle = total // 2\nnot_possible = False\ncount = 0\n\nfor el in total_matrix:\n\tif abs(total_matrix[middle] - el) % d != 0:\n\t\tnot_possible = True\n\t\tbreak\n\telse:\n\t\tcount += abs(total_matrix[middle] - el) // d\n\nif not_possible:\n\tprint(-1)\nelse:\n\tprint(count)", "n=input().split()\r\nl=[]\r\nfor i in range (int(n[0])):\r\n x=[int(x) for x in input().split()]\r\n l+=x\r\ncount=0\r\nl.sort()\r\nflag=0\r\nz=len(l)//2\r\nfor i in range (len(l)):\r\n y=abs(l[i]-l[z])/int(n[2])\r\n if y%1==0:\r\n count+=int(y)\r\n else:\r\n flag=1\r\nif flag==1:\r\n print(-1)\r\nelse:\r\n print(count)", "n,m,d=map(int,input().split())\r\na=[]\r\n\r\nfor i in range(n):\r\n a+=list(map(int,input().split()))\r\na.sort()\r\nmid=a[len(a)//2]\r\nans=0\r\nfor i in a:\r\n r=abs(mid-i)\r\n if r%d!=0:\r\n print(-1)\r\n exit()\r\n else:\r\n ans+=r//d\r\nprint(ans)\r\n \r\n ", "\r\nn,m,d = map(int,input().split())\r\nmatrix = []\r\nfor i in range(n):\r\n\t# a = t[0]\r\n\tt = list(map(int,input().split()))\r\n\tmatrix.append(t)\r\n\r\nl = []\r\nfor j in matrix:\r\n\tfor k in j:\r\n\r\n\t\tl.append(k)\r\n\t\tr = k%d\r\n\t\tr1 = l[0]%d\r\n\r\n\t\tif r == r1:\r\n\t\t\tcontinue\r\n\t\telse:\r\n\t\t\tprint(-1)\r\n\t\t\texit()\r\n\r\nl.sort()\r\n\r\nk = len(l)\r\n\r\nif len(l)%2 == 0:\r\n\r\n\tr1 = len(l)//2\r\n\tr2 = r1-1\r\n\r\n\r\n\tt1 = sum(l[:r2+1]) - l[r2]*len(l[:r2+1])\r\n\tt2 = sum(l[r2+1:]) - l[r2]*len(l[r2+1:])\r\n\r\n\tk = abs(t1) + abs(t2)\r\n\r\n\tt3 = sum(l[:r1+1]) - l[r1]*len(l[:r1+1])\r\n\tt4 = sum(l[r1+1:]) - l[r1]*len(l[r1+1:])\r\n\r\n\tk1 = abs(t3) + abs(t4)\r\n\r\n\tz = min(k,k1)\r\n\tz = int(z/d)\r\n\r\nelif len(l)%2 == 1:\r\n\r\n\tt = len(l)//2\r\n\r\n\tt1 = sum(l[:t]) - l[t]*(len(l[:t]))\r\n\tt2 = sum(l[t+1:]) - l[t]*(len(l[t+1:]))\r\n\r\n\tz = abs(t1) + abs(t2)\r\n\tz = int(z/d)\r\nprint(z)", "n, m, d = map(int, input().split())\nll = []\nfor i in range(n):\n temp = [int(x) for x in input().split()]\n ll.append(temp)\nl = []\nfor i in range(n):\n for j in range(len(ll[i])):\n l.append(ll[i][j])\n# print(arr)\nflag = 0\nl = sorted(l)\nfor i in range(len(l) - 1):\n if abs(l[i] - l[i + 1]) % d != 0:\n flag = 1\n break\n# print(l)\nmedian = l[len(l) // 2]\nmoves = 0\n# print(median)\nfor i in range(len(l)):\n moves += abs(l[i] - median) // d\nif flag == 1:\n print(-1)\nelse:\n print(moves)\n", "n, m, d = map(int, input().split())\r\na=[]\r\nb=0\r\nw=0\r\nc=0\r\nfor i in range(n):\r\n a += map(int,input().split())\r\nfor i in a:\r\n b+=abs(i-a[0])%d\r\nif b!=0 :\r\n print(\"-1\")\r\nelse:\r\n b=sorted(a)[n*m//2]\r\n for i in a:\r\n w+=abs(b-i)//d\r\n print(w)\r\n", "n, m, d = map(int, input().split())\na = []\nfor _ in range(n):\n a.extend([int(i) for i in input().split()])\n\nn = len(a)\na.sort()\n\np = [i for i in a]\nfor i in range(1, n):\n p[i] += p[i - 1]\n\nmoves = float('inf')\nfor i in range(n):\n x = (p[n - 1] - p[i]) - (n - i - 1) * a[i]\n if x % d != 0:\n continue\n x //= d\n\n y = i * a[i] - (p[i - 1] if i - 1 >=0 else 0)\n if y % d != 0:\n continue\n y //= d\n\n moves = min(moves, x + y)\n\nif moves == float('inf'):\n moves = -1\nprint(moves)\n", "import sys\r\n#sys.setrecursionlimit(10**7)\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n############ ---- Input Functions ---- ############\r\n\r\ndef Polo_the_Penguin_and_Matrix():\r\n n,m,d = invr()\r\n\r\n all_numbers = []\r\n\r\n for i in range(n):\r\n row = inlt()\r\n all_numbers = all_numbers + row \r\n\r\n mod_value = all_numbers[0] % d \r\n for n in all_numbers[1:]:\r\n new_mod_value = n % d \r\n if new_mod_value != mod_value:\r\n print(-1)\r\n return \r\n \r\n all_numbers_sorted = sorted(all_numbers)\r\n total_numbers = len(all_numbers_sorted)\r\n median_value = all_numbers_sorted[total_numbers//2]\r\n\r\n steps_required = 0 \r\n for n in all_numbers_sorted:\r\n steps_required += (abs(n - median_value))/d\r\n \r\n print(int(steps_required))\r\n return\r\n\r\n\r\n\r\nPolo_the_Penguin_and_Matrix()", "from collections import Counter\nimport heapq\nimport math\n\nn, m, d = map(int, input().split())\n\n# matrix = []\n# heapq.heapify(matrix)\n# cnter = Counter()\n# for i in range(n):\n# inp = list(map(int, input().split()))\n# for i in range(m):\n# heapq.heappush(matrix, inp[i])\n# cnter[inp[i]] += 1\n#\n# times = 0\n# pivot = heapq.nlargest(math.ceil(n * m / 2), matrix)[-1]\n# rem = pivot % d\n# for i in cnter.items():\n# el = i\n# if el[0] % d == rem:\n# times += abs(el[0] - pivot) // d * el[1]\n# else:\n# print(-1)\n# break\n# else:\n# print(times)\n\nmatrix = []\n\nfor i in range(n):\n matrix.extend(list(map(int, input().split())))\n\nmatrix.sort(reverse=True)\npivot = matrix[n * m // 2]\nrem = pivot % d\n\ntimes = 0\nfor i in matrix:\n if i % d == rem:\n times += abs(i - pivot) // d\n else:\n print(-1)\n break\nelse:\n print(times)\n", "n,m,d=map(int,input().split())\r\nmat=[]\r\nfor i in range(n):\r\n mat += list(map(int,input().split()))\r\nr=mat[0]%d\r\nf = True\r\nfor i in mat:\r\n if i%d!=r:\r\n f=False\r\n print(-1)\r\n break\r\nif f:\r\n mat.sort()\r\n mid=len(mat)//2\r\n med=mat[mid]\r\n ans = 0\r\n for i in mat:\r\n ans+= abs(med-i)//d\r\n print(ans)", "# It's all about what U BELIEVE\nimport sys\ninput = sys.stdin.readline\ndef gint(): return int(input())\ndef gint_arr(): return list(map(int, input().split()))\ndef gfloat(): return float(input())\ndef gfloat_arr(): return list(map(float, input().split()))\ndef pair_int(): return map(int, input().split())\n###############################################################################\nINF = (1 << 31)\ndx = [-1, 0, 1, 0]\ndy = [ 0, 1, 0, -1]\n############################ SOLUTION IS COMING ###############################\nn, m, d = gint_arr()\na = []\n\nfor i in range(n):\n a.extend(gint_arr())\n\na.sort()\n\ntarget = a[n * m // 2]\nmod = -1\nres = 0\n\nfor v in a:\n if (~mod) and abs(v - target) % d != mod:\n print(\"-1\")\n exit()\n else:\n res += abs(v - target) / d\n mod = abs(v - target) % d\n\nprint(int(res))\n", "l2=[]\r\nn,m,d = ([int(x) for x in input().split()])\r\nfor j in range(n):\r\n l1 = list(map(int, input().split()))\r\n l2+=l1\r\n\r\nk=len(l2)\r\nl3=[]\r\nl4=[]\r\nl2.sort()\r\nf=True\r\nfor j in range(k-1) :\r\n q=l2[j+1]-l2[j]\r\n\r\n if q%d!=0:\r\n f=False\r\n break\r\n else:\r\n l3.append(q//d)\r\nif f:\r\n p=len(l3)\r\n w=p//2\r\n s1=sum(l3[:w])\r\n s=sum(l3)\r\n s2=s-s1\r\n t=0\r\n for j in range(w):\r\n t=t+s1\r\n s1=s1-l3[j]\r\n\r\n for j in range(p-1,w-1,-1):\r\n t=t+s2\r\n s2=s2-l3[j]\r\n\r\n print(t)\r\nelse:\r\n print(-1)", "night , mid , day =map(int,input().split())\nan=[]\nfor i in[0]*night:\n an.extend(list(map(int,input().split())))\nan = sorted(an)\ntmp = an[night*mid//2]\n \nans = sum( abs(i-tmp)for i in an)//day\ns = set(i%day for i in an)\nprint([ans , -1 ][len(s)>1])\n\t\t \t \t\t \t \t \t\t\t \t \t \t \t", "n,m,d=map(int,input().split())\r\nl=[]\r\nfor _ in range(n):\r\n l.extend(list(map(int,input().split())))\r\nl.sort()\r\nmid = l[n*m//2]\r\nans=0\r\nflag=False\r\nfor i in l:\r\n val=abs(i-mid)\r\n if val%d==0:\r\n ans+=val//d\r\n else:\r\n flag=True\r\n break\r\nif flag:\r\n print(-1)\r\nelse:\r\n print(ans)", "# from math import *\r\n# from itertools import combinations\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\nn, _, d = map(int, input().split())\r\na = []\r\nfor i in range(n):\r\n a += list(map(int, input().split()))\r\na.sort()\r\nmed, sum = a[len(a) // 2], 0\r\nfor i in a:\r\n x = abs(i - med)\r\n if x % d != 0:\r\n print(-1)\r\n exit()\r\n sum += x \r\nprint(sum // d)", "def solve(l,n,m,d):\r\n mv=0\r\n mid=l[n*m//2]\r\n for i in range(n*m):\r\n if abs(l[i]-mid)%d!=0:\r\n print(-1)\r\n return\r\n else:\r\n mv+=abs(l[i]-mid)//d\r\n print(mv)\r\n return\r\n\r\n\r\nn,m,d=map(int,input().split())\r\nli=[[int(x) for x in input().split()] for i in range(n)]\r\nsm=0\r\nmn,mx=1000000000000,-9\r\nl=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n l.append(li[i][j])\r\nl.sort()\r\nsolve(l,n,m,d)", "n,m,d=list(map(int,input().split()))\nmatrix=[list(map(int,input().split())) for i in range(n)]\nchange=matrix[0][0]%d\nflag=0\ncount=0\nfor i in range(n):\n\tfor j in range(m):\n\t\tif change!=matrix[i][j]%d:\n\t\t\tflag=1\n\t\t\tbreak\n\nif flag:\n\tprint(-1)\nelse:\n\tmatrixArray=[]\n\tfor i in matrix:\n\t\tmatrixArray+=i\n\tmatrixArray.sort()\n\tmedian=matrixArray[(n*m//2)]\n\tfor i in matrixArray:\n\t\tif i<median:\n\t\t\tcount+=(median-i)//d\n\t\telse:\n\t\t\tcount+=(i-median)//d\n\n\tprint(count)\n", "matrix = []\r\nm, n, d = map(int, input().split())\r\nfor i in range(m):\r\n\trow = list(map(int, input().split()))\r\n\tfor i in range(n):\r\n\t\tmatrix.append(row[i])\r\n\r\nmatrix.sort()\r\nf = 0\r\nz = matrix[0]%d\r\nfor i in range(1,m*n):\r\n\tif(z != matrix[i]%d):\r\n\t\tprint(-1)\r\n\t\tf = 1\r\n\t\tbreak\r\nsteps = 0\r\nmedian = matrix[(n*m)//2]\r\nfor i in range(m*n):\r\n\tsteps += abs(median-matrix[i])//d\r\nif(not f):\r\n\tprint(steps)\r\n\r\n", "import statistics as stat\r\n\r\nline = input().split()\r\nn, m, d = [int(x) for x in line]\r\nnums = []\r\nfor i in range(n):\r\n line = input().split()\r\n int_line = [int(x) for x in line]\r\n nums += int_line\r\n\r\n# check_validity\r\nbase = nums[0] % d\r\ndef check(): \r\n for i in range(n * m):\r\n if nums[i] % d != base:\r\n return False\r\n return True\r\n\r\nif check():\r\n steps = [(x-base) // d for x in nums]\r\n median = stat.median(steps)\r\n result = 0\r\n for i in range(len(steps)):\r\n result += abs(steps[i] - median)\r\n result = int(result)\r\n print(result)\r\nelse:\r\n print(-1)\r\n", "from collections import Counter\nn, m, d = (int(x) for x in input().split())\nelements = []\nfor j in range(n):\n elements.extend(int(x) for x in input().split())\necounts = Counter(elements)\narr, ln = sorted(ecounts.items()), len(ecounts)\nleft, right = [0] * ln, [0] * ln\nlsum, rsum, valid = arr[0][1], arr[-1][1], True\nfor j in range(1, ln):\n x = arr[j][0] - arr[j - 1][0]\n y = arr[ln - j][0] - arr[ln - j - 1][0]\n valid = valid and (x % d == 0) and (y % d == 0)\n left[j] = left[j - 1] + (x // d) * lsum\n right[ln - 1 - j] = right[ln - j] + (y // d) * rsum\n rsum = rsum + arr[ln - 1 - j][1]\n lsum = lsum + arr[j][1]\nprint(min(p[0] + p[1] for p in zip(left, right)) if valid else -1)", "# Problem: B. Polo the Penguin and Matrix\r\n# Contest: Codeforces - Codeforces Round #177 (Div. 2)\r\n# URL: https://codeforces.com/problemset/problem/289/B\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n# \r\n# KAPOOR'S\r\n\r\nfrom sys import stdin, stdout \r\n\r\ndef INI():\r\n\treturn int(stdin.readline())\r\n\t\r\ndef INL():\r\n\treturn [int(_) for _ in stdin.readline().split()]\r\n\t\r\ndef INS():\r\n\treturn stdin.readline()\r\n\r\ndef MOD():\r\n return pow(10,9)+7\r\n\t\r\ndef OPS(ans):\r\n\tstdout.write(str(ans)+\"\\n\")\r\n\t\r\ndef OPL(ans):\r\n\t[stdout.write(str(_)+\" \") for _ in ans]\r\n\tstdout.write(\"\\n\")\r\n\r\n\t\r\nif __name__==\"__main__\":\r\n\tn,m,d=INL()\r\n\tX=[]\r\n\tfor _ in range(n):\r\n\t\tX.extend(INL())\r\n\t\t\r\n\tX.sort()\r\n\tn*=m\r\n\tm=X[(n-1)//2]\r\n\tans=0\r\n\tfor _ in range(n):\r\n\t\tif abs(m-X[_])%d==0:\r\n\t\t\tans+=abs(m-X[_])//d\r\n\t\telse:\r\n\t\t\tOPS(-1)\r\n\t\t\tbreak\r\n\telse:\r\n\t\tOPS(ans)", "n,m,d=map(int,input().split())\r\na=[]\r\nsum=0\r\nfor i in range(n):\r\n a.extend(list(map(int,input().split())))\r\nx=a[0]%d\r\na.sort()\r\nmid=a[n*m//2]\r\nfor i in a:\r\n if i%d!=x:\r\n print('-1')\r\n exit(0)\r\n else :\r\n sum+=abs(i-mid)//d\r\nprint(sum) ", "from statistics import median\r\na = []\r\nn,m ,dd = map(int, input().split())\r\nfor i in range(n): \r\n j = list(map(int, input().split()))\r\n a = a+j\r\na.sort()\r\nmean = a[(n*m//2)]\r\nans = 0\r\n \r\nfor i in range(n*m):\r\n c = abs(mean - a[i])//dd\r\n d = abs(mean - a[i])%dd\r\n if d==0:\r\n ans+=c\r\n else:\r\n print(-1)\r\n exit()\r\n \r\nprint(ans)\r\n\r\n", "#\t!/bin/env python3\r\n#\tcoding: UTF-8\r\n\r\n\r\n#\t✪ H4WK3yE乡\r\n#\tMohd. Farhan Tahir\r\n#\tIndian Institute Of Information Technology and Management,Gwalior\r\n\r\n#\tQuestion Link\r\n#\r\n#\r\n\r\n# ///==========Libraries, Constants and Functions=============///\r\n\r\n\r\nimport sys\r\n\r\ninf = float(\"inf\")\r\nmod = 1000000007\r\n\r\n\r\ndef get_array(): return list(map(int, sys.stdin.readline().split()))\r\n\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().split())\r\n\r\n\r\ndef input(): return sys.stdin.readline()\r\n\r\n# ///==========MAIN=============///\r\n\r\n\r\ndef main():\r\n n, m, d = get_ints()\r\n mat = []\r\n for i in range(n):\r\n mat.extend(get_array())\r\n check = mat[0] % d\r\n for i in range(n*m):\r\n if mat[i] % d != check:\r\n print(-1)\r\n return\r\n mat.sort()\r\n median = mat[(n*m)//2]\r\n ans = 0\r\n for i in range(n*m):\r\n ans += abs(mat[i]-median)\r\n print(ans//d)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n,m,d=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n a.extend(list(map(int,input().split())))\r\na.sort();k=0\r\nmi=(n*m)//2\r\nfor i in range(n*m):\r\n if abs(a[mi]-a[i])%d!=0:\r\n print(-1);exit(0)\r\n else:\r\n k+=(abs(a[mi]-a[i])//d)\r\nprint(k)", "def polo(l, d):\n l.sort()\n #find median k\n k = l[int(len(l)/2)]\n s = 0\n\n #loop through again and calculate if each element |x-k| % d == 0\n #if so, add k to sum\n for n in l:\n if abs(n-k) % d == 0:\n s = s + abs(n-k)\n else:\n return -1\n return int(s / d)\n\n\nl = []\nn,m,d = [int(x) for x in input().split(' ')]\nfor _ in range(n):\n l.extend(int(x) for x in input().split(' '))\n\nprint(polo(l, d))\n", "import math\r\nfrom collections import Counter\r\nL=lambda:list(map(int,input().split()))\r\nM=lambda:map(int,input().split())\r\nI=lambda:int(input())\r\nIN=lambda:input()\r\nmod=10**9+7\r\ndef s(a):\r\n print(\" \".join(list(map(str,a))))\r\n#______________________-------------------------------_____________________#\r\nm,n,d=M()\r\na=[]\r\nfor i in range(m):\r\n a+=L()\r\na.sort()\r\nmoves=0\r\nmid=a[m*n//2]\r\nfor i in a:\r\n x=abs(i-mid)\r\n if x%d==0:\r\n moves+=x//d\r\n else:\r\n print(-1)\r\n exit()\r\nprint(moves)\r\n \r\n \r\n \r\n", "from math import ceil\n\nn,m,d=map(int,input().split())\nl=[]\np=[]\nfor i in range(n):\n g=list(map(int,input().split()))\n l.append(g)\n p+=g\n\nf=True\nans=0\n\nk=p[0]%d\nfor i in p[1:]:\n if k!=i%d:\n f=False\n break\n\nif f:\n p.sort()\n j=n*m//2\n ans=0\n for i in p:\n ans+=abs(i-p[j])//d\n print(ans)\nelse:\n print(-1)", "x,y,d=[int(i) for i in input().split()]\r\n\r\ndata=[]\r\n\r\nfor i in range(x):\r\n for j in input().split():\r\n data.append(int(j))\r\n \r\ndata=sorted(data)\r\n\r\nmiddle=data[len(data)//2]\r\n\r\nfinal=0\r\n\r\nfor i in data:\r\n if abs(i-middle)%d==0:\r\n final+=abs(i-middle)//d\r\n else:\r\n final=-1\r\n break\r\n\r\nprint(final)\r\n", "n, m, d= map(int,input().split())\r\na = list()\r\ns = set()\r\nfor i in range(n):\r\n a+=list(map(int,input().split()))\r\na = sorted(a)\r\nmid = a[len(a)//2]\r\nans = 0\r\nfor i in a:\r\n x= abs(i-mid)\r\n if x%d != 0:\r\n print(-1)\r\n exit()\r\n else:\r\n ans+=x//d\r\nprint(ans)", "def ii(): return int(input())\r\ndef si(): return input()\r\ndef mi(): return map(int,input().split())\r\ndef msi(): return map(str,input().split())\r\ndef li(): return list(mi())\r\n\r\n\r\nnr,m,d=mi()\r\na=[]\r\nfor _ in range(nr):\r\n a += li()\r\n \r\nflag=0\r\nn=nr*m\r\na.sort()\r\nfor i in range(1,n):\r\n if (a[i]-a[i-1])%d!=0:\r\n flag=1\r\n break\r\n \r\nif flag==0:\r\n pre,suf = [0]*n,[0]*n\r\n pre[0]=a[0];suf[n-1]=a[n-1]\r\n \r\n for i in range(1,n):\r\n pre[i]=pre[i-1]+a[i]\r\n \r\n for i in range(n-2,-1,-1):\r\n suf[i]=suf[i+1]+a[i]\r\n \r\n #print(n) \r\n ans=1000000000\r\n for i in range(n):\r\n ans = min(ans,(a[i]*(i+1)-pre[i])//d + ((suf[i]-(a[i]*(n-i)))//d))\r\n #print(ans)\r\n \r\n #print(a)\r\n #print(pre,suf)\r\n print(ans)\r\n \r\nelse:\r\n print(-1)", "# https://codeforces.com/problemset/problem/289/B\n\nn, m, d = map(int, input().split())\nmat = []\nfor i in range(n):\n mat.append(list(map(int, input().split())))\n\ntemp = []\nfor i in range(n):\n temp.extend(mat[i])\n\ntemp.sort()\n\nrem = set()\nfor elem in temp:\n rem.add(elem%d)\n\nif len(rem) > 1:\n print(-1)\nelse:\n ans = 0\n median = temp[n*m//2]\n for elem in temp:\n ans += abs(elem - median)\n print(ans//d)\n\n", "n,m,d=map(int,input().strip().split())\r\nmat=[]\r\nfor i in range(n):\r\n mat.extend(list(map(int,input().split())))\r\nmat.sort()\r\nl=n*m\r\nmid=mat[l//2]\r\nrem=mid%d\r\nans=0\r\nfor i in range(l):\r\n if rem==mat[i]%d:\r\n ans+=abs(mid-mat[i])//d\r\n else:\r\n print(-1)\r\n exit()\r\nprint(ans)\r\n", "n,m,d=map(int,input().split())\r\nlst=[]\r\nfor i in range(n):\r\n x=(list(map(int,input().split())))\r\n lst=lst+x\r\n\r\nflag=True\r\nfor i in range(len(lst)-1):\r\n if(abs(lst[i+1]-lst[i])%d!=0):\r\n flag=False\r\n break\r\nif(flag==False):\r\n print(-1)\r\nelse:\r\n lst.sort()\r\n count=0\r\n if(len(lst)%2==0):\r\n middle=min(lst[len(lst)//2],lst[(len(lst)//2)-1])\r\n else:\r\n middle=lst[len(lst)//2]\r\n for i in range(len(lst)):\r\n count += abs(lst[i]-middle)//d\r\n print(count)\r\n \r\n\r\n\r\n\r\n\r\n ", "r, c, d = [int(i) for i in input().split()]\r\n\r\narr = []\r\nfor i in range(r):\r\n t = [int(i) for i in input().split()]\r\n arr.extend(t)\r\n\r\narr.sort()\r\n\r\nc = arr[i]%d\r\nfor i in arr:\r\n if i%d != c:\r\n print(-1)\r\n exit(0)\r\n\r\nmid = len(arr)//2\r\n\r\nres = 0\r\nfor i in arr:\r\n res += abs(i - arr[mid])/d\r\n\r\nprint(int(res))", "import sys\r\nI = sys.stdin.readline\r\nIM = lambda : map(int, I().split())\r\n\r\nn, m, d = IM()\r\na = []\r\nnp = set()\r\n\r\nfor i in range(n):\r\n a += list(IM())\r\n \r\nfor v in a:\r\n np.add(v%d)\r\n \r\nif len(np) > 1:\r\n ans = -1\r\nelse:\r\n a.sort()\r\n md = a[(len(a))//2]\r\n ans = sum([(abs(md-v)//d) for v in a])\r\nprint(ans)", "\"\"\"\r\n Template written to be used by Python Programmers.\r\n Use at your own risk!!!!\r\n Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).\r\n\"\"\"\r\nimport sys\r\nimport bisect\r\nimport heapq\r\nfrom math import *\r\nfrom collections import defaultdict as dd # defaultdict(<datatype>) Free of KeyError.\r\nfrom collections import deque # deque(list) append(), appendleft(), pop(), popleft() - O(1)\r\nfrom collections import Counter as c # Counter(list) return a dict with {key: count}\r\nfrom itertools import combinations as comb\r\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\r\n# sys.setrecursionlimit(2*pow(10, 6))\r\n# sys.stdin = open(\"input.txt\", \"r\")\r\n# sys.stdout = open(\"output.txt\", \"w\")\r\nmod = pow(10, 9) + 7\r\nmod2 = 998244353\r\ndef data(): return sys.stdin.readline().strip()\r\ndef out(var): sys.stdout.write(var)\r\ndef l(): return list(map(int, data().split()))\r\ndef sl(): return list(map(str, data().split()))\r\ndef sp(): return map(int, data().split())\r\ndef ssp(): return map(str, data().split())\r\ndef l1d(n, val=0): return [val for i in range(n)]\r\ndef l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]\r\n\r\n\r\nn, m, d = sp()\r\nmat = list()\r\nfor i in range(n):\r\n arr = l()\r\n for j in range(m):\r\n mat.append(arr[j])\r\nif len(set(mat)) == 1:\r\n out(\"0\")\r\n exit()\r\nmat.sort()\r\ncount = set(mat[:])\r\nfor k in count:\r\n answer = 0\r\n ele = k\r\n for i in mat:\r\n if i == ele:\r\n continue\r\n if i > ele:\r\n if (i-ele) % d != 0:\r\n out(\"-1\")\r\n exit()\r\n answer += (i-ele) // d\r\n else:\r\n if (ele-i) % d != 0:\r\n out(\"-1\")\r\n exit()\r\n answer += (ele - i) // d\r\n mod = min(mod, answer)\r\nout(str(mod))\r\nexit()\r\n", "n, m, d = list(map(int, input().rstrip().split()))\nmat=[]\nfor _ in range(n):\n mat += list(map(int, input().rstrip().split()))\nmat.sort()\nif n * m == 1:\n print(0)\nelse:\n flag = 1\n for i in range(n * m - 1):\n if (mat[i + 1] - mat[i]) % d != 0:\n flag = 0\n break\n if flag == 0:\n print(-1)\n else:\n if (n * m) % 2 == 1:\n median = mat[(n * m) // 2]\n else:\n median = 0.5 * (mat[(n * m) // 2] + mat[((n * m) // 2) - 1])\n # print(median)\n add = 0\n for x in mat:\n add += abs(x - median)\n ans = int(add // d)\n print(ans)", "def solve():\r\n n, m, d = map(int, input().split())\r\n a = []\r\n l = list(map(int, input().split()))\r\n thismod = l[0]%d\r\n for i in range(m):\r\n a.append(l[i])\r\n if l[i]%d != thismod:\r\n return -1\r\n for i in range(1,n):\r\n l = list(map(int, input().split()))\r\n for j in range(m):\r\n a.append(l[j])\r\n if l[j]%d != thismod:\r\n return -1\r\n\r\n a.sort()\r\n target = a[n*m//2]\r\n #print(target)\r\n score = 0\r\n for i in range(n*m):\r\n score += abs(a[i]-target)/d\r\n return int(score)\r\nprint(solve())\r\n\r\n\r\n", "n,m,d=map(int,input().split())\r\na=[]\r\nfor i in range(n):\r\n x=list(map(int,input().split()))\r\n for j in x:\r\n a.append(j)\r\na.sort()\r\nx=a[len(a)//2]\r\nans=0\r\nfor i in range(len(a)):\r\n a[i]=abs(a[i]-x)\r\n if a[i]%d!=0:\r\n print(-1)\r\n exit(0)\r\n else:\r\n ans+=a[i]//d\r\n# print(a)\r\nprint(ans)\r\n", "def solve(n, m, matrix, d, median):\r\n ans = 0\r\n for r in range(n):\r\n for c in range(m):\r\n elm = matrix[r][c]\r\n if (elm - median) % d != 0:\r\n return -1\r\n\r\n ans += abs((elm - median) // d)\r\n return ans\r\n \r\n\r\ndef main():\r\n n, m, d = map(int, input().split())\r\n matrix = []\r\n elms = []\r\n for _ in range(n):\r\n row = [int(c) for c in input().split()]\r\n elms += row\r\n matrix.append(row)\r\n\r\n elms.sort()\r\n median = elms[n * m // 2] \r\n \r\n \r\n ans = solve(n, m, matrix, d, median)\r\n print(ans)\r\n\r\nmain()\r\n", "import sys\ninput = sys.stdin.readline\n\nn, m, d = map(int, input().split())\narr = []\nfor _ in range(n):\n arr.extend(map(int, input().split()))\nimport math\nmin_moves = math.inf\n\nfor i in range(n*m):\n sum = 0\n for j in range(n*m):\n diff = abs(arr[i]-arr[j])\n if diff%d == 0:\n sum += diff//d\n else:\n print(-1)\n break\n else:\n min_moves = min(min_moves, sum)\n continue\n break\nelse:\n print(min_moves)\n", "n, m, d = map(int, input().split())\r\n\r\nmini = 1e9\r\ncommon = set()\r\ndic = {}\r\nalla = []\r\n\r\nfor _ in range(n):\r\n lst = list(map(int, input().split()))\r\n alla.append(lst)\r\n for i in lst:\r\n x = dic.get(i, 0) + 1\r\n dic[i] = x\r\n common.add(i % d)\r\n if i < mini:\r\n mini = i\r\n\r\nif len(common) > 1:\r\n print(-1)\r\nelse:\r\n\r\n t = list(common)[0]\r\n\r\n least = 1e9\r\n\r\n\r\n for k in list(dic.keys()):\r\n cnt = 0\r\n for l in list(dic.keys()):\r\n cnt += abs(k - l) * dic[l] // d\r\n\r\n if cnt < least:\r\n least = cnt\r\n \r\n print(least)", "#This code is contributed by Siddharth\r\nfrom bisect import *\r\nfrom math import *\r\nfrom collections import *\r\nfrom heapq import *\r\nfrom itertools import *\r\ninf=10**18\r\nmod=10**9+7\r\n\r\n\r\n\r\n\r\n\r\n# ==========================================> Code Starts Here <=====================================================================\r\n\r\nn,m,d=map(int,input().split())\r\narr=[0]*d\r\nmat=[]\r\nfor i in range(n):\r\n row=list(map(int,input().split()))\r\n for j in row:\r\n mat.append(j)\r\n arr[j%d]=1\r\nif sum(arr)>1:\r\n print(-1)\r\nelse:\r\n rem=arr.index(1)\r\n minn=10**18\r\n for i in range(rem,max(mat)+1,d):\r\n steps=0\r\n for j in mat:\r\n diff=abs(i-j)\r\n steps+=diff//d\r\n minn=min(steps,minn)\r\n print(minn)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "import sys\r\nn, m, d = map(int, input().split())\r\na = []\r\nfor _ in range(n):\r\n a += [int(x) for x in input().split()]\r\na.sort()\r\nfor i in range(n*m-1, -1, -1):\r\n a[i] -= a[0]\r\n if a[i]%d!=0:\r\n print(\"-1\")\r\n break\r\nelse:\r\n ans = sys.maxsize\r\n for x in range(0, a[n*m-1]+1, d):\r\n r = 0\r\n for y in a:\r\n r += abs(x-y)//d\r\n ans = min(ans, r) \r\n print(ans)\r\n \r\n \r\n", "n,m,d=list(map(int,input().split()))\r\na=[[0]*m for i in range(n)]\r\nfor i in range(n):\r\n s=list(map(int,input().rstrip().split()))\r\n for j in range(m):\r\n a[i][j]=s[j]\r\nans=float('inf')\r\nflag=0\r\narr=[]\r\nfor i in range(n):\r\n for j in range(m):\r\n arr.append(a[i][j])\r\n\r\narr.sort()\r\nfor i in range(1,n*m):\r\n if (arr[i]-arr[i-1])%d!=0:\r\n flag=1\r\n break\r\nif flag==1:\r\n print(-1)\r\n \r\nelse:\r\n count=0\r\n f=(n*m)//2\r\n ans=0\r\n for i in range(n*m):\r\n count+=abs(arr[i]-arr[f])//d\r\n print(count)\r\n \r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n ", "n, m, d = map(int, input().split())\r\na = []\r\n\r\nfor i in range(n):\r\n a += list(map(int, input().split()))\r\na.sort()\r\nmid = a[len(a)//2]\r\nans = 0\r\nfor i in a:\r\n r = abs(mid-i)\r\n if r%d != 0:\r\n print(-1)\r\n exit()\r\n else:\r\n ans += r//d\r\nprint(ans)\r\n", "n,m,d = (int(x) for x in input().split())\r\na = []\r\nfor i in range(n):\r\n a.append([int(x) for x in input().split()])\r\nmi = 10**5\r\nma = 0\r\nfor i in range(0,n):\r\n for j in range(0,m):\r\n if a[i][j] < mi: mi = a[i][j]\r\n \r\nv = True\r\n\r\nal = []\r\nfor i in range(0,n):\r\n for j in range(0,m):\r\n if (a[i][j] - mi) % d !=0: \r\n v = False\r\n break\r\n else:\r\n al.append(a[i][j] - mi)\r\nal = sorted(al)\r\nif v:\r\n mean = al[len(al)//2]\r\n cnt = 0\r\n for x in al:\r\n cnt+=abs(x - mean)//d\r\nelse:\r\n cnt = -1\r\n \r\n\r\n\r\nprint(cnt)\r\n ", "n,m,d = map(int,input().split())\r\nmat=[]\r\narr=[]\r\nfor i in range(n):\r\n temp = list(map(int,input().split()))\r\n arr.extend(temp)\r\n mat.append(temp)\r\nans=-1\r\ntog=0\r\n\r\nfor i in range(n):\r\n for j in range(m):\r\n temp = mat[i][j]%d\r\n if(ans == -1 or temp ==ans):\r\n ans=temp\r\n else:\r\n tog=1\r\n break\r\nif(tog == 1):\r\n print(-1)\r\nelse:\r\n arr.sort()\r\n arr2=[-1 for x in range(len(arr))]\r\n for i in range(len(arr)):\r\n diff = (arr[i]-arr[0])//d\r\n arr2[i]=diff\r\n arr3=[-1 for x in range(n*m)]\r\n arr3[0]=arr2[0]\r\n for i in range(1,len(arr2)):\r\n arr3[i] = arr3[i-1]+arr2[i]\r\n mini = arr3[-1]\r\n total = arr3[-1]\r\n for i in range(1,len(arr)-1):\r\n var1 = (total-arr3[i]) - arr2[i]*(len(arr)-(i+1))\r\n var2 = (arr2[i]*(i+1)) - arr3[i]\r\n a1 = var1+var2\r\n if(a1<mini):\r\n mini = a1\r\n \r\n print(mini)\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ", "n,m,d = map(int,input().split())\r\narr = []\r\nbrr = set()\r\n\r\nfor i in range(n):\r\n temp = list(map(int,input().split()))\r\n arr.extend(temp)\r\nfor i in range(n*m):\r\n t = arr[i]\r\n brr.add(t%d)\r\nif len(brr) > 1:\r\n print(-1)\r\nelse:\r\n arr.sort()\r\n median = arr[n*m // 2]\r\n ans = 0\r\n for i in range(n*m):\r\n ans += abs(median - arr[i])//d\r\n print(ans)\r\n", "n,m,d=map(int,input().split())\na=[]\ns=set()\nfor i in range(n):\n\ta+=list(map(int,input().split()))\na = sorted(a)\nmid=a[len(a)//2]\nans=0\nfor i in a:\n\tx=abs(i-mid)\n\tif x%d!=0:\n\t\tprint(-1)\n\t\texit()\n\tans+=x//d\nprint(ans)\n\n\t \t \t \t\t\t\t \t\t \t \t\t \t\t \t", "n, m, d = map(int, input().split())\nmat = []\n\nfor _ in range(n):\n\tmat.extend([*map(int, input().split())])\n\nmat.sort()\nch = [i % d for i in mat]\n\nif len(set(ch)) > 1:\n\tprint(-1)\nelse:\n\tprint(sum(abs(i - mat[(n * m) // 2]) for i in mat) // d)", "n,m,d=map(int,input().split())\r\nmatrix=[]\r\nfor _ in range(n):\r\n matrix.append(list(map(int,input().split())))\r\narr=[]\r\nmodd=matrix[0][0]%d\r\nfor i in range(n):\r\n for j in range(m):\r\n if modd!=matrix[i][j]%d:\r\n print(-1)\r\n exit()\r\n else:\r\n arr.append(matrix[i][j])\r\narr.sort()\r\n \r\nmedian=arr[int(len(arr)//2)]\r\n\r\ncount=0\r\nfor i in range(n):\r\n for j in range(m):\r\n diff=abs(matrix[i][j]-median)\r\n count+=diff//d\r\nprint(count)\r\n", "n,m,d=map(int,input().split(\" \"))\r\na=[]\r\nfor x in range(0,n):\r\n l=list(map(int,input().split(\" \")))\r\n a.append(l)\r\nb=[]\r\nfor x in range(0,n):\r\n for y in range(0,m):\r\n b.append(a[x][y])\r\nb.sort()\r\nz=0\r\nq=0\r\nc=b[len(b)//2]\r\nfor x in b:\r\n if abs(x-c)%d!=0:\r\n print(-1)\r\n q=1\r\n break\r\n else:\r\n z=z+abs(x-c)//d\r\nif q==0:\r\n print(z)", "from sys import stdin,stdout\r\nfrom math import gcd\r\nii1 = lambda: int(stdin.readline().strip())\r\nis1 = lambda: stdin.readline().strip()\r\niia = lambda: list(map(int, stdin.readline().strip().split()))\r\nisa = lambda: stdin.readline().strip().split()\r\nmod = 1000000007\r\n\r\nn, m, d = iia()\r\narr = []\r\nfor _ in range(n):\r\n arr.extend(iia())\r\narr.sort()\r\nnum = arr[len(arr)//2]\r\nres = 0\r\nfor i in range(len(arr)):\r\n if arr[i] != num:\r\n if abs(arr[i] - num) % d == 0:\r\n res += abs(arr[i] - num) // d\r\n else:\r\n print(-1)\r\n break\r\nelse:\r\n print(res)\r\n\r\n", "ls = input().split(\" \")\r\nn = int(ls[0])\r\nm = int(ls[1])\r\nd = int(ls[2])\r\nmatrix = []\r\nfor i in range(n):\r\n ls = input().split(\" \")\r\n for j in range(m):\r\n matrix.append(int(ls[j]))\r\nmatrix = sorted(matrix)\r\nval = matrix[len(matrix)//2]\r\nans = 0\r\nflag = 0\r\n\r\nfor i in range(n*m):\r\n x = abs(matrix[i] - val)\r\n if(x%d != 0 ):\r\n print(-1)\r\n flag = 1\r\n break\r\n ans += x//d\r\nif(flag == 0 ):\r\n print(ans)", "import sys\r\nfrom math import sqrt,ceil,floor,gcd\r\nfrom collections import Counter\r\n\r\ninput = lambda:sys.stdin.readline()\r\n\r\ndef int_arr(): return list(map(int,input().split()))\r\ndef str_arr(): return list(map(str,input().split()))\r\ndef get_str(): return map(str,input().split())\r\ndef get_int(): return map(int,input().split())\r\ndef get_flo(): return map(float,input().split())\r\ndef lcm(a,b): return (a*b) // gcd(a,b)\r\n\r\nmod = 1000000007\r\n\r\ndef solve(arr,mid,k):\r\n ans = 0\r\n for i in range(len(arr)):\r\n tmp = abs(arr[i]-mid)\r\n if tmp % k != 0:\r\n print(-1)\r\n return\r\n ans += tmp // k\r\n\r\n print(ans)\r\n\r\n# for _ in range(int(input())):\r\nn,m,k = get_int()\r\narr = []\r\nfor i in range(n):\r\n arr += int_arr()\r\n\r\narr.sort()\r\nmid = arr[len(arr)//2]\r\n\r\nsolve(arr,mid,k)" ]
{"inputs": ["2 2 2\n2 4\n6 8", "1 2 7\n6 7", "3 2 1\n5 7\n1 2\n5 100", "3 3 3\n5 8 5\n11 11 17\n14 5 2", "3 3 3\n5 8 5\n11 11 17\n14 5 3", "2 2 4\n5 5\n5 5", "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7", "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91", "7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 127 47", "7 5 47\n9583 1734 4601 5353 2110\n3802 5165 7985 6293 324\n7045 653 9160 7891 4930\n1781 3520 4178 2298 3943\n1405 2956 5447 5494 6528\n3097 1640 7750 4883 8032\n4225 8455 1875 4789 4366", "1 1 1\n1", "1 1 8\n12"], "outputs": ["4", "-1", "104", "12", "-1", "0", "9", "0", "-1", "1508", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
200
20f1c94c1e992cb8f01b83ea4ed216fb
none
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer *m*, bit depth of the game, which means that all numbers in the game will consist of *m* bits. Then he asks Peter to choose some *m*-bit number. After that, Bob computes the values of *n* variables. Each variable is assigned either a constant *m*-bit number or result of bitwise operation. Operands of the operation may be either variables defined before, or the number, chosen by Peter. After that, Peter's score equals to the sum of all variable values. Bob wants to know, what number Peter needs to choose to get the minimum possible score, and what number he needs to choose to get the maximum possible score. In both cases, if there are several ways to get the same score, find the minimum number, which he can choose. The first line contains two integers *n* and *m*, the number of variables and bit depth, respectively (1<=≤<=*n*<=≤<=5000; 1<=≤<=*m*<=≤<=1000). The following *n* lines contain descriptions of the variables. Each line describes exactly one variable. Description has the following format: name of a new variable, space, sign ":=", space, followed by one of: 1. Binary number of exactly *m* bits. 1. The first operand, space, bitwise operation ("AND", "OR" or "XOR"), space, the second operand. Each operand is either the name of variable defined before or symbol '?', indicating the number chosen by Peter. Variable names are strings consisting of lowercase Latin letters with length at most 10. All variable names are different. In the first line output the minimum number that should be chosen by Peter, to make the sum of all variable values minimum possible, in the second line output the minimum number that should be chosen by Peter, to make the sum of all variable values maximum possible. Both numbers should be printed as *m*-bit binary numbers. Sample Input 3 3 a := 101 b := 011 c := ? XOR b 5 1 a := 1 bb := 0 cx := ? OR a d := ? XOR ? e := d AND bb Sample Output 011 100 0 0
[ "n, m = map(int, input().split())\n\nv = [('?', '')]\ntemp = [(0, 1)]\nd = {}\nd['?'] = 0\n\nmn, mx = '', ''\n\nfor i in range(n):\n name, val = input().split(' := ')\n v.append((name, val.split()))\n temp.append((-1, -1))\n d[name] = i + 1\n\ndef eval(expr, bit1, bit2):\n if expr == 'OR':\n return bit1 | bit2\n elif expr == 'AND':\n return bit1 and bit2\n elif expr == 'XOR':\n return bit1 ^ bit2\n else:\n raise AttributeError()\n\nfor i in range(m):\n for name, expr in v[1:]:\n j = d[name]\n if len(expr) == 1:\n temp[j] = (int(expr[0][i]), int(expr[0][i]))\n else:\n bit1, bit2 = temp[d[expr[0]]], temp[d[expr[2]]]\n temp[j] = (eval(expr[1], bit1[0], bit2[0]), eval(expr[1], bit1[1], bit2[1]))\n \n z, o = sum(temp[_][0] for _ in range(1, n + 1)), sum(temp[_][1] for _ in range(1, n + 1))\n mn += '1' if o < z else '0'\n mx += '1' if o > z else '0'\n\nprint(mn)\nprint(mx)\n", "n,m=map(int,input().split())\r\nansmin,ansmax=[],[]\r\nmp={'?':0}\r\nexpr=[]\r\ndef trans(s):\r\n\treturn '0'*(m-len(s))+s if s.isdigit() else mp[s]\r\nfor i in range(n):\r\n\tx=input().split(' := ')\r\n\tmp[x[0]]=i+1\r\n\tif ' 'in x[1]:\r\n\t\tw=x[1].split(' ')\r\n\t\tw[0]=trans(w[0])\r\n\t\tw[2]=trans(w[2])\r\n\t\texpr.append((i+1,w))\r\n\telse:\r\n\t\texpr.append((i+1,[trans(x[1])]))\r\nval=[None]*(n+1)\r\ndef op(l,r,s):\r\n\tif s=='XOR':\r\n\t\treturn l!=r\r\n\telif s=='OR':\r\n\t\treturn l|r\r\n\telse:\r\n\t\treturn l&r\r\nfor t in range(m):\r\n\tdef getvalof(s):\r\n\t\tif type(s)==str:\r\n\t\t\treturn True if s[t]=='1' else False\r\n\t\telse:\r\n\t\t\treturn val[s];\r\n\tdef getval(s):\r\n\t\tif len(s)==1:\r\n\t\t\treturn getvalof(s[0])\r\n\t\telse:\r\n\t\t\ta,b=getvalof(s[0]),getvalof(s[2])\r\n\t\t\treturn op(a,b,s[1])\r\n\tval[0]=True\r\n\tcnt1=0\r\n\tfor name,sym in expr:\r\n\t\tb=getval(sym)\r\n\t\tval[name]=b\r\n\t\tcnt1+=b\r\n\tval[0]=False\r\n\tcnt2=0\r\n\tfor name,sym in expr:\r\n\t\tb=getval(sym)\r\n\t\tval[name]=b\r\n\t\tcnt2+=b\r\n\tif cnt1<cnt2:\r\n\t\tansmin.append('0')\r\n\t\tansmax.append('1')\r\n\telif cnt1>cnt2:\r\n\t\tansmin.append('1')\r\n\t\tansmax.append('0')\t\r\n\telse:\r\n\t\tansmin.append('0')\r\n\t\tansmax.append('0')\r\nprint(''.join(ansmax))\r\nprint(''.join(ansmin))\r\n\t", "import sys\r\ninput = sys.stdin.buffer.readline \r\n\r\ndef calc(x, y, op):\r\n if op=='AND':\r\n if x=='0' or y=='0':\r\n return '0'\r\n if x=='1':\r\n return y\r\n if y=='1':\r\n return x\r\n if x=='i' and y=='i':\r\n return 'i'\r\n if x=='i*' and y=='i*':\r\n return 'i*'\r\n if x=='i' and y=='i*':\r\n return '0'\r\n if x=='i*' and y=='i':\r\n return '0'\r\n if op=='OR':\r\n if x=='1' or y=='1':\r\n return '1'\r\n if x=='0':\r\n return y\r\n if y=='0':\r\n return x\r\n if x=='i' and y=='i':\r\n return 'i'\r\n if x=='i*' and y=='i*':\r\n return 'i*'\r\n if x=='i' and y=='i*':\r\n return '1'\r\n if x=='i*' and y=='i':\r\n return '1'\r\n if op=='XOR':\r\n if x==y:\r\n return '0'\r\n if (x=='0' and y=='1') or (x=='1' and y=='0'):\r\n return '1'\r\n if x=='1' and y=='i':\r\n return 'i*'\r\n if x=='1' and y=='i*':\r\n return 'i'\r\n if x=='0' and y=='i':\r\n return 'i'\r\n if x=='0' and y=='i*':\r\n return 'i*'\r\n if x=='i' and y=='1':\r\n return 'i*'\r\n if x=='i*' and y=='1':\r\n return 'i'\r\n if x=='i' and y=='0':\r\n return 'i'\r\n if x=='i*' and y=='0':\r\n return 'i*'\r\n if x=='i' and y=='i*':\r\n return '1'\r\n if x=='i*' and y=='i':\r\n return '1'\r\n \r\ndef process(A, m):\r\n n = len(A)\r\n d = {'?': ['i' for i in range(m)]}\r\n for i in range(n):\r\n command = A[i].split()\r\n var = command[0]\r\n if len(command)==3:\r\n d[var] = list(command[2])\r\n else:\r\n L = []\r\n v1 = command[2]\r\n v2 = command[4]\r\n op = command[3]\r\n for j in range(m):\r\n L.append(calc(d[v1][j], d[v2][j], op))\r\n d[var] = L\r\n counts = [[0, 0] for i in range(m)]\r\n for var in d:\r\n if var != '?':\r\n for i in range(m):\r\n if d[var][i]=='i':\r\n counts[i][0]+=1\r\n elif d[var][i]=='i*':\r\n counts[i][1]+=1\r\n a1 = []\r\n a2 = []\r\n for i in range(m):\r\n a, b = counts[i]\r\n if a==b:\r\n a1.append('0')\r\n a2.append('0')\r\n elif a < b:\r\n a1.append('1')\r\n a2.append('0')\r\n else:\r\n a1.append('0')\r\n a2.append('1')\r\n print(''.join(a1))\r\n print(''.join(a2))\r\n \r\n \r\n \r\nn, m = [int(x) for x in input().split()]\r\nA = []\r\nfor i in range(n):\r\n row = input().decode()[:-2]\r\n A.append(row)\r\nprocess(A, m)", "f = {'OR': lambda x, y: x | y, 'AND': lambda x, y: x & y, 'XOR': lambda x, y: x ^ y}\r\nn, m = map(int, input().split())\r\nu, v = [], []\r\nd = {'?': n}\r\nfor i in range(n):\r\n q, s = input().split(' := ')\r\n if ' ' in s:\r\n x, t, y = s.split()\r\n u += [(i, d[x], f[t], d[y])]\r\n else: v += [(i, s)]\r\n d[q] = i\r\ns = [0] * (n + 1)\r\ndef g(k, j):\r\n s[n] = k\r\n for i, q in v: s[i] = q[j] == '1'\r\n for i, x, f, y in u: s[i] = f(s[x], s[y])\r\n return sum(s) - k\r\na = b = ''\r\nfor j in range(m):\r\n d = g(1, j) - g(0, j)\r\n a += '01'[d < 0]\r\n b += '01'[d > 0]\r\nprint(a, b)", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\n\r\nvars = {}\r\n\r\nfor _ in range(n):\r\n l = input().split()\r\n if len(l) == 3:\r\n vars[l[0]] = l[2]\r\n else:\r\n vars[l[0]] = (l[2], l[3], l[4])\r\n\r\nones_on_bits = {i: {0: 0, 1: 0} for i in range(m)}\r\nfor i in range(m):\r\n for a in [0, 1]:\r\n res = 0\r\n vals = {}\r\n for k, v in vars.items():\r\n val = None\r\n if type(v) == str:\r\n val = int(v[i])\r\n else:\r\n x1, op, x2 = v\r\n y1 = vals[x1] if x1 != '?' else a\r\n y2 = vals[x2] if x2 != '?' else a\r\n if op == 'AND':\r\n val = 1 if y1 == 1 and y2 == 1 else 0\r\n elif op == 'OR':\r\n val = 1 if y1 == 1 or y2 == 1 else 0\r\n elif op == 'XOR':\r\n val = 1 if y1 != y2 else 0\r\n\r\n vals[k] = val\r\n res += val\r\n ones_on_bits[i][a] = res\r\n\r\n# min\r\nmin_sum_ans = []\r\nfor i in range(m):\r\n min_sum_ans.append('0' if ones_on_bits[i][0] <= ones_on_bits[i][1] else '1')\r\nprint(\"\".join(min_sum_ans))\r\n\r\n# max\r\nmax_sum_ans = []\r\nfor i in range(m):\r\n max_sum_ans.append('0' if ones_on_bits[i][0] >= ones_on_bits[i][1] else '1')\r\nprint(\"\".join(max_sum_ans))\r\n", "\r\n\r\n\r\ndef OP(i,j,op):\r\n if op == \"AND\":\r\n return i & j\r\n if op == \"OR\":\r\n return i | j\r\n if op == \"XOR\":\r\n return i ^ j\r\n return 0\r\n\r\ndef totbit(i,test):\r\n ans = 0\r\n for j in range(0,len(ops)):\r\n a = ops[j][0]\r\n b = ops[j][1]\r\n op = ops[j][2]\r\n if a == \"?\":\r\n x = test\r\n else:\r\n if a in M:\r\n x = int(M[a][i])\r\n else:\r\n x = OL[OD[a]]\r\n if b == \"?\":\r\n y = test\r\n else:\r\n if b in M:\r\n y = int(M[b][i])\r\n else:\r\n y = OL[OD[b]]\r\n ans += OP(x,y,op)\r\n OL[j] = OP(x,y,op)\r\n return ans\r\n \r\n\r\n\r\nops = []\r\n[n,m] = list(map(int , input().split()))\r\nM = dict()\r\nOL = []\r\nOD = dict()\r\nfor i in range(0,n):\r\n inp = input().split()\r\n a = inp[0]\r\n if len(inp) == 3:\r\n b = inp[2]\r\n M[a] = b\r\n else:\r\n a = inp[2]\r\n b = inp[4]\r\n op = inp[3]\r\n OD[inp[0]] = len(OL)\r\n OL.append(0)\r\n ops.append([a,b,op])\r\nmi = \"\"\r\nma = \"\"\r\n\r\nfor i in range(0,m):\r\n b0 = totbit(i,0)\r\n b1 = totbit(i,1)\r\n if b0 >= b1:\r\n ma += \"0\"\r\n else:\r\n ma += \"1\"\r\n if b0 <= b1:\r\n mi += \"0\"\r\n else:\r\n mi += \"1\"\r\nprint(mi)\r\nprint(ma)\r\n \r\n\r\n\r\n" ]
{"inputs": ["3 3\na := 101\nb := 011\nc := ? XOR b", "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb", "2 10\nb := 0100101101\na := ? XOR b", "1 10\na := 0110110011", "1 6\na := ? OR ?", "13 6\na := 111010\nb := 100100\nc := 001110\nd := b AND b\ne := c AND ?\nf := e OR c\ng := 011110\nh := d XOR ?\ni := 010111\nj := 000011\nk := d OR ?\nl := 011101\nm := b OR j", "16 3\na := 011\nb := 110\nc := a XOR b\nd := 110\ne := a XOR b\nf := b XOR a\ng := b XOR e\nh := 111\ni := a XOR h\nj := f XOR ?\nk := 100\nl := 000\nm := 100\nn := 110\no := 110\np := 110", "29 2\naa := 10\nba := 11\nca := 01\nda := aa AND ?\nea := ba OR ?\nfa := da XOR ?\nga := 11\nha := fa XOR ea\nia := 01\nja := ca OR ha\nka := ha XOR ia\nla := ha OR ?\nma := ba AND ba\nna := ma OR ?\noa := 11\npa := oa OR ba\nqa := 00\nra := qa AND ia\nsa := fa OR ?\nta := ha OR ga\nua := 00\nva := 00\nwa := 11\nxa := 10\nya := ja XOR ?\nza := 00\nab := 00\nbb := pa OR qa\ncb := bb AND ?", "10 3\na := 011\nb := ? OR a\nc := 000\nd := ? AND c\ne := 101\nf := ? AND e\ng := 001\nh := ? XOR g\ni := 001\nj := ? XOR i", "12 3\na := 101\nb := a XOR ?\nc := b XOR b\nd := b XOR a\ne := c XOR ?\nf := e XOR ?\ng := c XOR f\nh := 100\ni := c XOR h\nj := c XOR i\nk := b XOR ?\nl := 111", "12 14\na := 01100010000111\nb := ? XOR a\nc := 01101111001010\nd := ? XOR c\ne := 10000011101111\nf := ? XOR e\ng := 10100011001010\nh := ? XOR g\ni := 10010110111111\nj := ? XOR i\nk := 10000111110001\nl := ? XOR k", "14 8\na := 01010000\nb := 10101111\nc := 01100100\nd := 10011011\ne := 01001100\nf := 10110011\ng := ? XOR a\nh := b XOR ?\ni := ? XOR c\nj := d XOR ?\nk := ? XOR e\nl := f XOR ?\nm := 00101111\nn := ? XOR m", "14 14\na := 10000100110000\nb := 01111011001111\nc := 11110001111101\nd := 00001110000010\ne := 00111100000010\nf := 11000011111101\ng := ? XOR a\nh := b XOR ?\ni := ? XOR c\nj := d XOR ?\nk := ? XOR e\nl := f XOR ?\nm := 11110011011001\nn := ? XOR m", "17 15\na := 010000111111110\nb := 101100110000100\nc := 100101100100111\nd := 010110101110110\ne := 111111000010110\nf := 011001110111110\ng := 110011010100101\nh := 000001010010001\ni := 110000111001011\nj := 000010000010111\nk := 110110111110110\nl := 010000110000100\nm := 000111101101000\nn := 011111011000111\no := 010110110010100\np := 111001110011001\nq := 000100110001000", "22 9\na := 100101111\nb := 010001100\nc := b AND b\nd := 111000010\ne := c AND a\nf := a OR e\ng := e AND ?\nh := 000010001\ni := b OR ?\nj := d AND ?\nk := g AND h\nl := 010100000\nm := a AND a\nn := j AND ?\no := m OR n\np := o AND ?\nq := f OR ?\nr := 000011011\ns := 001110011\nt := 100111100\nu := l AND p\nv := g OR h", "2 109\na := 1010101010100000000000011111111111111111111111111111111111111111111000000000000000000000000000111111111111111\nb := ? XOR a"], "outputs": ["011\n100", "0\n0", "0100101101\n1011010010", "0000000000\n0000000000", "000000\n111111", "100000\n011011", "101\n010", "00\n11", "001\n110", "000\n111", "10000011001011\n01011000010000", "00101111\n11010000", "11110011011001\n00001100100110", "000000000000000\n000000000000000", "000000000\n111111111", "1010101010100000000000011111111111111111111111111111111111111111111000000000000000000000000000111111111111111\n0101010101011111111111100000000000000000000000000000000000000000000111111111111111111111111111000000000000000"]}
UNKNOWN
PYTHON3
CODEFORCES
6
20fd49f9c64735d6bfb5a2ded627b23d
Shifts
You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right. To cyclically shift a table row one cell to the right means to move the value of each cell, except for the last one, to the right neighboring cell, and to move the value of the last cell to the first cell. A cyclical shift of a row to the left is performed similarly, but in the other direction. For example, if we cyclically shift a row "00110" one cell to the right, we get a row "00011", but if we shift a row "00110" one cell to the left, we get a row "01100". Determine the minimum number of moves needed to make some table column consist only of numbers 1. The first line contains two space-separated integers: *n* (1<=≤<=*n*<=≤<=100) — the number of rows in the table and *m* (1<=≤<=*m*<=≤<=104) — the number of columns in the table. Then *n* lines follow, each of them contains *m* characters "0" or "1": the *j*-th character of the *i*-th line describes the contents of the cell in the *i*-th row and in the *j*-th column of the table. It is guaranteed that the description of the table contains no other characters besides "0" and "1". Print a single number: the minimum number of moves needed to get only numbers 1 in some column of the table. If this is impossible, print -1. Sample Input 3 6 101010 000100 100000 2 3 111 000 Sample Output 3 -1
[ "def calc_shift_cost(row):\n starts = [i for i, x in enumerate(row) if x]\n for start in starts:\n d = 2\n pos = start + 1\n if pos == len(row):\n pos = 0\n while row[pos] != 1:\n if row[pos]:\n row[pos] = min(row[pos], d)\n else:\n row[pos] = d\n d += 1\n pos += 1\n if pos == len(row):\n pos = 0\n d = 2\n pos = start - 1\n if pos == -1:\n pos = len(row) - 1\n while row[pos] != 1:\n if row[pos]:\n row[pos] = min(row[pos], d)\n else:\n row[pos] = d\n d += 1\n pos -= 1\n if pos == -1:\n pos = len(row) - 1\n for x in range(len(row)):\n row[x] -= 1\n\n\nclass CodeforcesTask229ASolution:\n def __init__(self):\n self.result = ''\n self.n_m = []\n self.board = []\n\n def read_input(self):\n self.n_m = [int(x) for x in input().split(\" \")]\n for x in range(self.n_m[0]):\n self.board.append([int(x) for x in input()])\n\n def process_task(self):\n for row in self.board:\n if sum(row):\n calc_shift_cost(row)\n else:\n self.result = \"-1\"\n break\n if not self.result:\n costs = []\n for x in range(self.n_m[1]):\n ss = 0\n for y in range(self.n_m[0]):\n ss += self.board[y][x]\n costs.append(ss)\n self.result = str(min(costs))\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask229ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "import sys\r\ninput = sys.stdin.readline\r\nfrom bisect import bisect\r\n\r\nn, m = map(int, input().split())\r\ng = [input()[:-1] for _ in range(n)]\r\ne = []\r\nfor i in g:\r\n d = []\r\n f = []\r\n for j, k in enumerate(i):\r\n if k == '1':\r\n d.append(j)\r\n q = len(d)\r\n if q == 0:\r\n print(-1)\r\n exit()\r\n for j in range(m):\r\n if i[j] == '1':\r\n f.append(0)\r\n else:\r\n x = bisect(d, j)\r\n if x == 0:\r\n f.append(min(d[0]-j, m-d[-1]+j))\r\n elif x == q:\r\n f.append(min(j-d[-1], m-j+d[0]))\r\n else:\r\n f.append(min(d[x]-j, j-d[x-1]))\r\n e.append(f)\r\nxx = min(sum(i) for i in zip(*e))\r\nprint(xx)", "n, m = map(int, input().split())\r\nf = [[int(1e9) for j in range(m)] for i in range(n)]\r\nfor i in range(n):\r\n\ts = input()\r\n\tif s.find('1') == -1:\r\n\t\tprint(-1)\r\n\t\texit()\r\n\tf[i][0] = s[::-1].find('1') + 1\r\n\tf[i][m - 1] = s.find('1') + 1\r\n\tfor j in range(m):\r\n\t\tf[i][j] = 0 if s[j] == '1' else f[i][j]\r\n\tfor j in range(m):\r\n\t\tf[i][j] = min(f[i][j], f[i][j - 1] + 1)\r\n\tfor j in range(m - 2, -1, -1):\r\n\t\tf[i][j] = min(f[i][j], f[i][j + 1] + 1)\r\nprint(min([sum([f[i][j] for i in range(n)]) for j in range(m)]));", "'''\r\n Auther: ghoshashis545 Ashis Ghosh\r\n College: jalpaiguri Govt Enggineering College\r\n\r\n'''\r\nfrom os import path\r\nimport sys\r\nfrom heapq import heappush,heappop\r\nfrom functools import cmp_to_key as ctk\r\nfrom collections import deque,defaultdict as dd \r\nfrom bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right\r\nfrom itertools import permutations\r\nfrom datetime import datetime\r\nfrom math import ceil,sqrt,log,gcd\r\ndef ii():return int(input())\r\ndef si():return input()\r\ndef mi():return map(int,input().split())\r\ndef li():return list(mi())\r\nabc='abcdefghijklmnopqrstuvwxyz'\r\n# mod=1000000007\r\nmod=998244353\r\ninf = float(\"inf\")\r\nvow=['a','e','i','o','u']\r\ndx,dy=[-1,1,0,0],[0,0,1,-1]\r\n\r\ndef bo(i):\r\n return ord(i)-ord('a')\r\n\r\nfile=1\r\ndef solve():\r\n\r\n\r\n # for _ in range(ii()):\r\n\r\n n,m=mi()\r\n a=[]\r\n f=0\r\n for i in range(n):\r\n s=list(si())\r\n if '1' not in s:\r\n f=1\r\n continue\r\n # s1=s+\"\"+s\r\n # print(s1)\r\n pre=[m]*(2*m)\r\n if s[0]=='1':\r\n pre[0]=0\r\n for j in range(1,2*m):\r\n if s[j%m]=='1':\r\n pre[j]=0\r\n else:\r\n pre[j]=pre[j-1]+1\r\n suff=[m]*(2*m)\r\n if s[-1]=='1':\r\n suff[-1]=0\r\n for j in range(2*m-2,-1,-1):\r\n if s[j%m]=='1':\r\n suff[j]=0\r\n else:\r\n suff[j]=suff[j+1]+1\r\n # print(pre,suff)\r\n b=[m]*m\r\n for j in range(2*m):\r\n b[j%m]=min({b[j%m],pre[j],suff[j]})\r\n a.append(b)\r\n\r\n # for i in a:\r\n # print(*i)\r\n if(f):\r\n print(\"-1\")\r\n exit(0)\r\n # print(a)\r\n ans=inf\r\n for i in range(m):\r\n s=0\r\n for j in range(n):\r\n s+=a[j][i]\r\n ans=min(ans,s)\r\n print(ans)\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\nif __name__ ==\"__main__\":\r\n\r\n if(file):\r\n\r\n if path.exists('input1.txt'):\r\n sys.stdin=open('input1.txt', 'r')\r\n sys.stdout=open('output1.txt','w')\r\n else:\r\n input=sys.stdin.readline\r\n solve()\r\n", "import sys\ninput = lambda: sys.stdin.readline().rstrip()\nfrom collections import deque,defaultdict,Counter\nfrom itertools import permutations,combinations\nfrom bisect import *\nfrom heapq import *\nfrom math import ceil,gcd,lcm,floor,comb\nalph = 'abcdefghijklmnopqrstuvwxyz'\n#pow(x,mod-2,mod)\n\nN,M = map(int, input().split())\nA = []\nfor _ in range(N):\n S = input()\n A.append([])\n for i in range(M):\n if S[i]=='1':\n A[-1].append(i)\n if len(A[-1])==0:\n exit(print(-1))\n\nans = float('inf')\nfor i in range(M):\n cnt = 0\n for j in range(N):\n idx = bisect_left(A[j],i)\n right = idx%len(A[j])\n left = (idx-1)%len(A[j])\n num = min(abs(A[j][right]-i),abs(A[j][left]-i))\n num = min(num,abs(A[j][right]+M-i),abs(A[j][left]+M-i))\n num = min(num,abs(A[j][right]-M-i),abs(A[j][left]-M-i))\n cnt+=num\n ans = min(ans,cnt)\n\nprint(ans)\n \n", "G = [[], [1], [1, 1], [1, 2, 1], [1, 2, 2, 1], [1, 2, 3, 2, 1]] \r\ndef g(k):\r\n global G\r\n if k < 6: return G[k]\r\n return list(range(1, (k + 1) // 2 + 1)) + list(range(k // 2, 0, -1))\r\n\r\ndef f():\r\n n, m = map(int, input().split())\r\n s, p = [0] * m, [0] * m\r\n for i in range(n):\r\n q = [j for j, x in enumerate(input()) if x == '1']\r\n if not q: return -1\r\n c = q.pop(0)\r\n p[c], a = 0, c + 1\r\n for b in q:\r\n p[b] = 0\r\n if b > a: p[a: b] = g(b - a)\r\n a = b + 1\r\n if c + m > a:\r\n t = g(c + m - a)\r\n p[a: ], p[: c] = t[: m - a], t[m - a: ]\r\n for j, x in enumerate(p): s[j] += x\r\n return min(s)\r\nprint(f())", "n, m = map(int, input().split())\r\nmemo = [[int(2e9) for j in range(m)] for i in range(n)]\r\nfor i in range(n):\r\n s = input()\r\n if s.find('1') == -1:\r\n print(-1)\r\n exit() \r\n memo[i][0] = s[::-1].find('1') + 1\r\n memo[i][m-1] = s.find('1') + 1\r\n for j in range(m):\r\n if s[j] == '1':\r\n memo[i][j] = 0 \r\n else:\r\n memo[i][j] = min(memo[i][j], memo[i][j-1] + 1)\r\n for j in range(m-2, -1, -1):\r\n memo[i][j] = min(memo[i][j], memo[i][j+1] + 1)\r\nprint(min([sum([memo[i][j] for i in range(n)]) for j in range(m)]))\r\n", "# https://vjudge.net/contest/339915#problem/J\n\n\ndef calculate_row_distance(row, rows_len):\n init_i = row.index(1)\n\n dist = 0\n dists = [-1 for i in range(rows_len)]\n i = init_i\n for x in range(rows_len):\n if i == rows_len:\n i = 0\n\n if row[i] == 1:\n dist = 0\n dists[i] = 0\n elif dists[i] == -1 or dists[i] > dist:\n dists[i] = dist\n elif dists[i] < dist:\n dist = dists[i]\n\n dist += 1\n i += 1\n\n dist = 0\n i = init_i\n for x in range(rows_len):\n if i == -1:\n i = rows_len-1\n\n if row[i] == 1:\n dist = 0\n dists[i] = 0\n elif dists[i] == -1 or dists[i] > dist:\n dists[i] = dist\n elif dists[i] < dist:\n dist = dists[i]\n\n dist += 1\n i -= 1\n\n return dists\n\n\ndef init():\n cols_len, rows_len = map(lambda x: int(x), input().split(' '))\n\n cols_distance = [0 for i in range(rows_len)]\n for r in range(cols_len):\n row = [int(i) for i in input()]\n if 1 not in row:\n print('-1')\n return\n\n dists = calculate_row_distance(row, rows_len)\n\n for c in range(rows_len):\n cols_distance[c] += dists[c]\n\n cols_distance.sort()\n print(cols_distance[0])\n\n\ninit()\n\n \t \t \t \t\t\t \t \t \t\t\t\t\t\t\t \t\t\t", "import heapq\r\nimport operator as op\r\nimport sys\r\nfrom bisect import bisect_left as b_l\r\nfrom bisect import bisect_right as b_r\r\nfrom collections import defaultdict, deque\r\nfrom functools import reduce\r\nfrom math import ceil, factorial, gcd, sqrt\r\n\r\nINT_MAX = sys.maxsize-1\r\nINT_MIN = -sys.maxsize\r\n\r\ndef ncr(n,r):\r\n\tr=min(n,n-r)\r\n\tnmtr = reduce(op.mul,range(n,n-r,-1),1)\r\n\tdnmtr = reduce(op.mul,range(1,r+1),1)\r\n\treturn nmtr//dnmtr\r\n\r\n\r\ndef fact(n):\r\n\treturn factorial(n)\r\n\r\n\t\t\r\n\r\ndef myyy__answer():\r\n\t\r\n\tn,m=map(int,input().strip().split())\r\n\tmp=[input().strip() for i in range(n)]\r\n\r\n\tans=[[0 for _ in range(m)] for _ in range(n)]\r\n\r\n\t# print(ans)\r\n\r\n\tfor i in range(n):\r\n\t\tif(mp[i].count(\"1\")==0):\r\n\t\t\tprint(-1)\r\n\t\t\treturn\r\n\r\n\t\tlast_one=mp[i][::-1].index(\"1\")+1\r\n\t\tfor j in range(m):\r\n\t\t\tif(mp[i][j]==\"1\"):\r\n\t\t\t\tans[i][j]=0\r\n\t\t\telse:\r\n\t\t\t\tans[i][j]= (ans[i][j-1]+1) if (j>0) else last_one\r\n\t\t\r\n\t\tfirst_one=mp[i].index(\"1\")+1\r\n\r\n\t\tfor j in range(m-1,-1,-1):\r\n\t\t\tans[i][j]=min(ans[i][j],(ans[i][j+1]+1) if(j<m-1) else first_one)\r\n\t\t\r\n\ta=INT_MAX\r\n\r\n\tfor i in range(m):\r\n\t\ttotal=0\r\n\t\tfor j in range(n):\r\n\t\t\ttotal+=ans[j][i]\r\n\t\t\r\n\t\ta=min(a,total)\r\n\r\n\tprint(a)\r\n\r\n\t\r\n\r\n\r\n\r\n\t\r\n\r\n\t\r\n\r\n\r\n\t\r\n\r\n\t\r\n\r\n\r\n\t\r\n\t\r\n\r\n\r\n\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tinput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\r\n\r\n\t# for _ in range(int(input())):\r\n\t\t# print(myyy__answer())\r\n\tmyyy__answer()\r\n" ]
{"inputs": ["3 6\n101010\n000100\n100000", "2 3\n111\n000", "1 1\n1", "1 1\n0", "3 1\n1\n1\n0", "6 2\n10\n11\n01\n01\n10\n11", "3 3\n001\n010\n100", "4 4\n0001\n0100\n0010\n1000", "5 5\n10000\n01000\n00100\n00010\n00001", "5 5\n10001\n00100\n01000\n01001\n11111", "5 5\n11111\n11111\n11111\n11111\n00000", "5 10\n0001000100\n1000001000\n0001000001\n0100001010\n0110100000", "6 6\n111000\n011100\n001110\n000111\n100011\n110001", "2 9\n101010101\n010101010", "4 6\n000001\n100000\n100000\n100000", "3 6\n000010\n010000\n000100", "4 10\n0000101010\n1010101010\n0101010101\n0000010100", "10 10\n0000000000\n0000000010\n0010000000\n0111000010\n1000000000\n0000000100\n0000000100\n0000100100\n0010000000\n0000100000", "10 10\n0000000000\n0000001000\n0000000100\n0101000100\n0000000000\n0000000000\n1000110000\n1011010010\n0000100000\n0000001001", "10 10\n0001001101\n0010001010\n1100000000\n0110110110\n1011011010\n1001001001\n0100010001\n0110000100\n0000100000\n1000010000", "10 10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111", "2 5\n10000\n00001", "3 7\n1000000\n0000010\n1000000", "4 5\n10010\n11001\n00010\n11000", "2 10\n0000000001\n1000000000", "5 5\n10000\n10000\n00001\n10000\n10000", "3 4\n0001\n0001\n1000", "3 6\n101010\n000010\n100000", "4 7\n0100000\n0100000\n0000001\n0000001", "5 1\n0\n0\n0\n0\n0", "3 5\n00001\n10000\n00001", "3 1\n0\n0\n0"], "outputs": ["3", "-1", "0", "-1", "-1", "2", "2", "4", "6", "2", "-1", "5", "4", "1", "1", "3", "2", "-1", "-1", "8", "0", "1", "2", "2", "1", "1", "1", "2", "4", "-1", "1", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
9
20fee0d2046c45179bcd2f922d225aae
Queue
There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*. The *i*-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such *j* (*i*<=&lt;<=*j*), that *a**i*<=&gt;<=*a**j*. The displeasure of the *i*-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the *i*-th one. That is, the further that young walrus stands from him, the stronger the displeasure is. The airport manager asked you to count for each of *n* walruses in the queue his displeasure. The first line contains an integer *n* (2<=≤<=*n*<=≤<=105) — the number of walruses in the queue. The second line contains integers *a**i* (1<=≤<=*a**i*<=≤<=109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. Print *n* numbers: if the *i*-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the *i*-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. Sample Input 6 10 8 5 3 50 45 7 10 4 6 3 2 8 15 5 10 3 1 10 11 Sample Output 2 1 0 -1 0 -1 4 2 1 0 -1 -1 -1 1 0 -1 -1 -1
[ "import bisect\r\nfrom collections import deque\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(n):\r\n\tl.append((arr[i],i))\r\nl.sort()\r\narr1=[]\r\nans=[-1]*n\r\na=-1\r\nfor i in range(n):\r\n\tif a<l[i][1]:\r\n\t\ta=l[i][1]\r\n\tans[l[i][1]]=a-l[i][1]-1\r\nprint(*ans)\r\n\r\n\r\n\t\r\n\r\n\r\n\r\n", "import sys\r\nimport math as m\r\ndef fi():\r\n\treturn sys.stdin.readline()\r\nif __name__ == '__main__':\r\n\tn = int(fi())\r\n\tl = list(map(int, fi().split()))\r\n\tans = [0]*n\r\n\tmi = [0]*n\r\n\tans[n-1] = -1\r\n\tmi[n-1] = l[n-1]\r\n\tfor i in range (n-2,-1,-1):\r\n\t\tmi[i] = min(l[i],mi[i+1])\r\n\tfor i in range (n-2,-1,-1):\r\n\t\ta = -1\r\n\t\tle = i+1\r\n\t\tr = n-1\r\n\t\twhile le<=r:\r\n\t\t\tmid = (le+r)//2\r\n\t\t\tif mi[mid] < l[i]:\r\n\t\t\t\ta = mid\r\n\t\t\t\tle = mid+1\r\n\t\t\telse:\r\n\t\t\t\tr = mid-1\r\n\t\tif a == -1:\r\n\t\t\tans[i] = a\r\n\t\telse:\r\n\t\t\tans[i] = a-i-1\r\n\tprint(*ans)", "from sys import stdin,stdout\r\n# from bisect import bisect_left,bisect\r\n# from sys import setrecursionlimit\r\n# from collections import defaultdict\r\n# from math import gcd,ceil,sqrt\r\n# setrecursionlimit(int(1e5))\r\ninput,print = stdin.readline,stdout.write\r\n\r\nmax_value = 100005\r\nclass Node:\r\n def __init__(self, age, id):\r\n self.age = age\r\n self.id = id\r\n\r\ns = [Node(0, 0)] * max_value\r\nn = 0\r\ntop = 1\r\nn = int(input())\r\n\r\na = [-1]+list(map(int,input().split()))\r\n\r\ns[top] = Node(a[n], n)\r\na[n] = -1\r\n\r\nfor i in range(n-1,0,-1):\r\n l = 1\r\n r = top\r\n while l<=r:\r\n mid = (l+r)// 2\r\n if s[mid].age>=a[i]:\r\n l = mid+1\r\n else:\r\n r = mid-1\r\n\r\n if l<=top:\r\n a[i] = s[l].id-i-1\r\n else:\r\n top+=1\r\n s[top]=Node(a[i], i)\r\n a[i]=-1\r\n\r\nfor i in range(1,n+1):\r\n print(str(a[i])+\" \")\r\nprint(\"\\n\")", "n=int(input())\r\narr=list(map(int,input().split()))\r\nans=[0]*n\r\n\r\ndef b_S(i,l,h):\r\n pos=-1\r\n ans1=100000\r\n while l<=h:\r\n mid=(l+h)//2\r\n if arr[mid]<arr[i]:\r\n pos=mid\r\n ans1=arr[mid]\r\n l=mid+1\r\n else:h=mid-1\r\n if pos!=-1:return pos-i-1\r\n return -1\r\n\r\nfor i in range(n-1,-1,-1):\r\n ans[i]=b_S(i,i+1,n-1)\r\n if i!=n-1:\r\n arr[i]=min(arr[i+1],arr[i])\r\n#print(arr)\r\nprint(*ans)\r\n", "n = int(input())\r\nl = [int(x) for x in input().split()]\r\nm = [[l[i], i,-1] for i in range(0,n)]\r\nm.sort()\r\nk = 0\r\nfor i in range(1,n):\r\n if m[k][1]-m[i][1]>0:\r\n m[i][2] = m[k][1]-m[i][1]-1\r\n else:\r\n k=i\r\n m[k][2]=-1\r\nm.sort(key = lambda x: x[1]) \r\n\r\nfor i in range(0,n):\r\n print(m[i][2], end=' ')", "n = int(input())\r\nl = []\r\nfor i, j in enumerate(map(int, input().split())):\r\n l.append((j, i))\r\nl.sort()\r\nmx = -1\r\nans = [0]*n\r\nfor val, idx in l:\r\n mx = max(mx, idx)\r\n ans[idx] = mx-idx-1\r\nprint(*ans)\r\n", "import bisect\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\nsmall=[-1]*n\r\nsmall[n-1]=arr[n-1]\r\nfor i in range(n-2,-1,-1):\r\n if arr[i]<small[i+1]:\r\n small[i]=arr[i]\r\n else:\r\n small[i]=small[i+1]\r\nfor i in range(n):\r\n ans=bisect.bisect_left(small,arr[i])-i-2\r\n if ans<0:\r\n ans=-1\r\n print(ans,end=' ')\r\n\r\n", "\r\ndef displeasure(wal_arr):\r\n wal_arr = sorted(wal_arr)\r\n highest_ind = -1\r\n ret_arr = [-1] * len(wal_arr)\r\n for wal in wal_arr:\r\n if wal[1] < highest_ind:\r\n ret_arr[wal[1]] = highest_ind - wal[1] - 1\r\n\r\n highest_ind = max(highest_ind, wal[1])\r\n return ret_arr\r\n\r\n\r\nnum = input()\r\nwalrus_arr = input().split(\" \")\r\nwalrus_arr = [(int(age), ind) for ind, age in enumerate(walrus_arr)]\r\n\r\nfor wal in displeasure(walrus_arr):\r\n print(str(wal) + \" \")", "from bisect import bisect_left\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nb = [0] * n\r\nfor i in range(n - 1, -1, -1):\r\n\tb[i] = bisect_left(a, a[i], i + 1, len(a)) - i - 2\r\n\ta[i] = min(a[i + 1], a[i]) if i != n - 1 else a[i]\r\nprint (*b)\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\npr = [0] * n\r\npr[-1] = a[-1]\r\nfor i in range(n - 2, -1, -1):\r\n pr[i] = min(pr[i + 1], a[i])\r\nres = [0] * n\r\nfor i in range(n):\r\n l = i\r\n r = n\r\n while(l < r - 1):\r\n mid = (l + r) // 2\r\n if(pr[mid] < a[i]):\r\n l = mid\r\n else:\r\n r = mid\r\n res[i] = l - i - 1 if l - i - 1 >= 0 else -1\r\nprint(*res)", "b = [0] * int(input())\r\nm = 0\r\nfor e, i in sorted((e, i) for i, e in enumerate(map(int, input().split()))):\r\n\tm = max(m, i)\r\n\tb[i] = m - i - 1\r\nprint (*b)\r\n", "from sys import stdin,stdout\r\nfrom math import log2\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nPI=float('inf')\r\ndef RMQ(low,high):\r\n l=high-low+1\r\n k=int(log2(l))\r\n return min(a[sp[low][k]],a[sp[low+l-(1<<k)][k]])\r\nfor _ in range(1):#nmbr()):\r\n n=nmbr()\r\n a=lst()\r\n col=int(log2(n))+1\r\n sp=[[0 for _ in range(col+1)] for _ in range(n)]\r\n for i in range(n):\r\n sp[i][0]=i\r\n j=1\r\n while (1<<j)<=n:\r\n i=0\r\n while (i+(1<<j)-1)<n:\r\n if a[sp[i][j-1]]<a[sp[i+(1<<(j-1))][j-1]]:sp[i][j]=sp[i][j-1]\r\n else:sp[i][j]=sp[i+(1<<(j-1))][j-1]\r\n i+=1\r\n j+=1\r\n for i in range(n):\r\n l,r=i+1,n-1\r\n while l<=r:\r\n mid=(l+r)>>1\r\n if RMQ(mid,n-1)<a[i]:l=mid+1\r\n else:r=mid-1\r\n # print(a[i],r)\r\n stdout.write(str(r-i-1)+' ')\r\n", "import sys\r\ninput = sys.stdin.readline \r\n\r\n\r\nn = int(input()) \r\nl = list(map(int, input().split()))\r\nfor i in range(n):\r\n l[i] = [l[i], i]\r\nans = [-1] * n \r\nl.sort(key = lambda x : x[0]) \r\na = -1\r\nfor i in range(n):\r\n if(a < l[i][1]):\r\n a = l[i][1] \r\n ans[l[i][1]] = a - l[i][1] - 1 \r\nprint(*ans)", "from collections import defaultdict\r\nimport sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef segment_tree(n):\r\n i = 2\r\n while True:\r\n if i >= n * 2:\r\n tree = [-1] * i\r\n break\r\n else:\r\n i *= 2\r\n return tree\r\n\r\ndef update(i, x):\r\n i += len(tree) // 2\r\n tree[i] = x\r\n i //= 2\r\n while True:\r\n if i == 0:\r\n break\r\n tree[i] = max(tree[2 * i], tree[2 * i + 1])\r\n i //= 2\r\n return\r\n\r\ndef get_max(s, t):\r\n s += len(tree) // 2\r\n t += len(tree) // 2\r\n ans = -1\r\n while s <= t:\r\n if s % 2 == 0:\r\n s //= 2\r\n else:\r\n ans = max(ans, tree[s])\r\n s = (s + 1) // 2\r\n if t % 2 == 1:\r\n t //= 2\r\n else:\r\n ans = max(ans, tree[t])\r\n t = (t - 1) // 2\r\n return ans\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nd = defaultdict(lambda : [])\r\nfor i in range(n):\r\n d[a[i]].append(i)\r\nans = [0] * n\r\ntree = segment_tree(n + 5)\r\nfor i in sorted(d.keys()):\r\n for j in d[i]:\r\n update(j, j)\r\n ans[j] = get_max(j, n) - j - 1\r\nsys.stdout.write(\" \".join(map(str, ans)))", "n = int(input())\na = [(int(e), i) for i, e in enumerate(input().split())]\na = sorted(a)\n\nanswer = [-1 for _ in range(n)]\n\nsignificant_high_index = -1\nfor _, i in a:\n if significant_high_index >= i:\n answer[i] = significant_high_index - i - 1\n continue\n significant_high_index = i\n\nprint(*answer)\n", "n = int(input())\r\nt = [(n - i, j) for i, j in enumerate(map(int, input().split()), 1)]\r\nt = [a[0] for a in sorted(t, key = lambda a: a[1])]\r\np, q = [0] * n, [-1] * n\r\nfor i in range(n): p[t[i]] = i + 1\r\nfor i, j in enumerate(p, 1):\r\n if n < j: continue\r\n for k in range(j, n): q[t[k]] = t[k] - i\r\n n = j - 1\r\nq.reverse()\r\nprint(' '.join(map(str, q)))", "from sys import stdin,stdout\n# from bisect import bisect_left,bisect\n# from sys import setrecursionlimit\n# from collections import defaultdict\n# from math import gcd,ceil,sqrt\n# setrecursionlimit(int(1e5))\ninput,print = stdin.readline,stdout.write\n\nmax_value = 100005\nclass Node:\n def __init__(self, age, id):\n self.age = age\n self.id = id\n\ns = [Node(0, 0)] * max_value\nn = 0\ntop = 1\nn = int(input())\n\na = [-1]+list(map(int,input().split()))\n\ns[top] = Node(a[n], n)\na[n] = -1\n\nfor i in range(n-1,0,-1):\n l = 1\n r = top\n while l<=r:\n mid = (l+r)// 2\n if s[mid].age>=a[i]:\n l = mid+1\n else:\n r = mid-1\n\n if l<=top:\n a[i] = s[l].id-i-1\n else:\n top+=1\n s[top]=Node(a[i], i)\n a[i]=-1\n\nfor i in range(1,n+1):\n print(str(a[i])+\" \")\nprint(\"\\n\")\n \t \t\t \t \t\t\t\t\t\t \t\t\t \t \t\t\t\t", "n=int(input())\r\nb=list(map(int,input().split()))\r\na=[]\r\nfor i in range(n):\r\n a.append([b[i],i])\r\na.sort()\r\nans=[-1]*n\r\nmx=a[0][1]\r\nfor i in range(1,n):\r\n if mx<a[i][1]:\r\n mx=a[i][1]\r\n else:\r\n ans[a[i][1]]=mx-a[i][1]-1\r\nprint(*ans)", "n=int(input())\nx=list(map(int,input().split()))\narr=[]\nfor i in range(n):\n arr.append((x[i],i))\narr.sort(key= lambda arr :arr[0])\nans=[-1]*n\nmaxx = 0\nfor i in range(n):\n maxx = max(maxx,arr[i][1])\n ans[arr[i][1]]=maxx-arr[i][1]-1\nfor i in ans:\n print(i,end=' ')\n", "def f(u, low, high):\r\n\tposs = -1\r\n\twhile high >= low:\r\n\t\tmid = (low + high) // 2\r\n\t\tif a[mid] < a[u]:\r\n\t\t\tposs = mid\r\n\t\t\tlow = mid + 1\r\n\t\telse:\r\n\t\t\thigh = mid - 1\r\n\treturn poss - u - 1 if poss != -1 else -1\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nans = [0] * n\r\n\r\nfor i in range(n - 1, -1, -1):\r\n\tans[i] = f(i, i + 1, n - 1)\r\n\tif i != n - 1:\r\n\t\ta[i] = min(a[i + 1], a[i])\r\n\r\nprint (' '.join(map(str, ans)))\r\n", "from bisect import bisect_left as bl\r\nnum = int(input())\r\nwalrusQ = [int(i) for i in input().split()]\r\ndspl = [10**10 for i in range(num)]\r\ndspl[-1] = walrusQ[-1]\r\nfor i in range(num-2, -1, -1):\r\n dspl[i] = min(dspl[i+1], walrusQ[i])\r\nresult = [0]*num\r\nfor i in range(num):\r\n pos = bl(dspl, walrusQ[i])\r\n if walrusQ[pos-1] < walrusQ[i]:\r\n result[i] = max(-1, pos-1-i-1)\r\n else:\r\n result[i] = -1\r\nprint(*result)\r\n", "def sort_list(list1, list2): \r\n \r\n zipped_pairs = zip(list2, list1) \r\n \r\n z = [x for _, x in sorted(zipped_pairs)] \r\n \r\n return z \r\nn=int(input())\r\nl=list(map(int,input().split()))\r\na=[i for i in range(n)]\r\na=sort_list(a,l)\r\nl.sort()\r\nma=-1\r\nans=[-1]*n\r\nfor i in range(n):\r\n if a[i]>ma:\r\n ans[a[i]]=-1\r\n else:\r\n ans[a[i]]=ma-a[i]-1 \r\n ma=max(ma,a[i])\r\nprint(*ans,sep=\" \")", "n = int(input())\r\nl = []\r\nfor i, j in enumerate(map(int, input().split())):\r\n l.append((j, i))\r\n\r\nl.sort()\r\nmx = -1\r\nans = [0] * n\r\nfor val, idx in l:\r\n mx = max(mx, idx)\r\n ans[idx] = mx - idx - 1\r\n\r\nprint(*ans)", "import sys\r\nread = lambda: sys.stdin.readline().strip()\r\nreadi = lambda: map(int, read().split())\r\n\r\n\r\nn = int(read())\r\nnums = list(readi())\r\n\r\narr = [(num, i) for i, num in enumerate(nums)]\r\narr.sort(key = lambda x: x[0])\r\n\r\nprefixMax = [-1] * (n+1)\r\nfor i, (num, j) in enumerate(arr):\r\n prefixMax[i+1] = max(prefixMax[i], j)\r\n\r\nans = [-1] * n\r\nfor i in range(n):\r\n ans[arr[i][1]] = prefixMax[i+1] - arr[i][1] - 1\r\n\r\nprint(\" \".join(map(str, ans)))", "n = int(input())\r\narr = [int(i) for i in input().split()]\r\nr = list(range(n))\r\nr.sort(key=lambda x: arr[x])\r\n\r\nans = [-1]* n\r\nans[r[0]] = -1\r\np = r[0]\r\ns = r[0]\r\nx = arr[r[0]]\r\nfor i in r[1:]:\r\n if (x == arr[i]): \r\n if p > i: ans[i] = p - i - 1\r\n s = max(s, i)\r\n elif s > i: ans[i] = s - i - 1\r\n else: \r\n p = s\r\n s = i\r\n x = arr[i]\r\n\r\nfor i in ans:\r\n print(i, end=' ')", "n =int(input())\r\na = [int(i) for i in input().split()]\r\nar1 = [0 for i in range(n)]\r\nar1[n-1]=n-1\r\nfor i in range(n-2,-1,-1):\r\n if a[i]<=a[ar1[i+1]]:\r\n ar1[i]=i\r\n else:\r\n ar1[i] = ar1[i+1]\r\narr=[0]*n\r\nfor i in range(0,n):\r\n #def bs(arr,low,high,x): \r\n mid = 0\r\n ans =-1\r\n low = i+1\r\n high= n-1\r\n x = i\r\n while low <= high: \r\n mid = (high + low) // 2\r\n if a[ar1[mid]] <a[x]: \r\n ans = ar1[mid]\r\n low = mid + 1\r\n else:\r\n high = mid - 1\r\n if ans==-1:\r\n arr[i]=-1\r\n else:\r\n arr[i] = ans-i-1\r\nprint(*arr)\r\n \r\n \r\n\r\n ", "def bin_search(r1, x):\r\n l, r = 0, r1\r\n while l <= r:\r\n m = (l + r) // 2\r\n if b[m] < x:\r\n r = m - 1\r\n elif b[m] >= x:\r\n l = m + 1\r\n return l\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nb = [0]*n\r\na.reverse()\r\nb[0] = a[0]\r\nt = [-1]\r\nfor i in range(1, n):\r\n b[i] = min(b[i - 1], a[i])\r\nfor i in range(1, n):\r\n if a[i] > b[i]:\r\n t.append(i - bin_search(i - 1, a[i]) - 1)\r\n else:\r\n t.append(-1)\r\n \r\nfor i in range(len(t) - 1, -1, -1):\r\n print(t[i], end=\" \")", "def binsearch(a, x):\r\n l, r = -1, len(a)\r\n while r - l > 1:\r\n m = l + (r - l) // 2\r\n if a[m][0] < x:\r\n r = m\r\n else:\r\n l = m\r\n return r\r\n\r\ndef solve():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n\r\n stack = [(a[n - 1], n - 1)]\r\n ans = [-1 for i in range(n)]\r\n\r\n for i in range(n - 2, -1, -1):\r\n pos = binsearch(stack, a[i])\r\n if pos == len(stack):\r\n stack.append((a[i], i))\r\n else:\r\n ans[i] = stack[pos][1] - i - 1\r\n\r\n return ans\r\n\r\nfor x in solve():\r\n print(x, end=' ')", "import bisect\r\nfrom collections import deque\r\n\r\nR = lambda: map(int, input().split())\r\nn = int(input())\r\narr = list(R())\r\nnums = deque()\r\nres = [-1] * n\r\nfor i in range(n - 1, -1, -1):\r\n if not nums or arr[i] < nums[0][0]:\r\n nums.appendleft((arr[i], i))\r\n elif arr[i] > nums[0][0]:\r\n res[i] = nums[bisect.bisect_left(nums, (arr[i], -1)) - 1][1] - i - 1\r\nprint(*res)\r\n", "k, q = 0, ['-1'] * int(input())\r\nfor i, a in sorted(enumerate(map(int, input().split())), key = lambda a: a[1]):\r\n if k < i: k = i\r\n else: q[i] = str(k - i - 1)\r\nprint(' '.join(q))", "n = int(input())\r\na = list(map(int,input().split()))\r\nstack = [a[-1]]\r\nstack_v = [n-1]\r\nfor i in range(n-2,-1,-1):\r\n if a[i] <= stack[-1]:\r\n stack.append(a[i])\r\n stack_v.append(i)\r\nb = [-1]*n\r\n##print(stack,stack_v)\r\nfor i in range(n):\r\n # bin search\r\n left, right = (0, len(stack)-1)\r\n while left < right:\r\n mid = (left+right)//2\r\n if a[i] <= stack[mid]:\r\n left = mid + 1\r\n else:\r\n right = mid\r\n## print(a[i], stack[mid], left, mid, right)\r\n## print(a[i], stack[left], stack_v[left])\r\n if a[i] > stack[left]:\r\n b[i] = stack_v[left] - i - 1\r\n \r\nfor i in range(len(b)):\r\n if b[i] < -1:\r\n b[i] = -1\r\n\r\nprint(*b)\r\n", "def disp(walline):\r\n walline=sorted(walline)\r\n highest_ind=-1\r\n displeasure_arr=[-1]*len(walline)\r\n for wal in walline:\r\n if wal[1]<highest_ind:\r\n displeasure_arr[wal[1]] = highest_ind - wal[1] -1\r\n highest_ind = max(highest_ind,wal[1])\r\n return displeasure_arr\r\n\r\nn=int(input())\r\nwalrus_arr=list(map(int,input().split()))\r\nwalrus_arr=[(age,ind) for ind,age in enumerate(walrus_arr)]\r\nprint(*disp(walrus_arr))", "n=int(input())\r\narr=[int(X) for X in input().split()]\r\ntemp=[]\r\nfor i in range(n):\r\n temp.append([arr[i],i])\r\ntemp.sort()\r\nmaxi=0\r\nans=[0 for i in range(n)]\r\nfor i in range(n):\r\n maxi=max(maxi,temp[i][1])\r\n ans[temp[i][1]]=maxi-temp[i][1]-1\r\nfor i in ans:\r\n print(i,end=' ')\r\n ", "n = int(input())\na = [int(e) for e in input().split()]\nb = [len(a) - 1]\nfor i in range(n-2, -1, -1):\n if a[i] < a[b[-1]]:\n b.append(i)\n else:\n b.append(b[-1])\n\nb = list(reversed(b))\nanswer = []\nfor i in range(n):\n left, right = i, n - 1\n\n # binary search\n found = None\n while left <= right:\n middle = (left + right + 1) // 2\n\n if a[b[middle]] < a[i] and (middle + 1 >= n or a[i] <= a[b[middle+1]]):\n found = middle\n break\n\n if a[i] <= a[b[middle]]:\n right = middle - 1\n else:\n left = middle + 1\n\n if found is not None:\n answer.append(found - i - 1)\n else:\n answer.append(-1)\n\nprint(*answer)\n", "n = int(input())\n\na = [int(x) for x in input().split(' ')]\n\nINF = 1<<30\nmn = [INF] * n\nfor i in range(n - 1, -1, -1):\n mn[i] = min(a[i], mn[i + 1] if i + 1 < n else INF)\n\n# print(mn)\n\nfor i in range(n):\n l = i\n r = n - 1\n while l < r:\n mid = r - (r - l) // 2\n if (mn[mid] >= a[i]): r = mid - 1\n else: l = mid\n print(l - i - 1, end=' ')\n\n", "n=int(input())\r\nx=list(map(int,input().split()))\r\narr=[]\r\nfor i in range(n):\r\n arr.append((x[i],i))\r\narr.sort(key= lambda arr :arr[0])\r\nans=[-1]*n\r\nmaxx = 0\r\nfor i in range(n):\r\n maxx = max(maxx,arr[i][1])\r\n ans[arr[i][1]]=maxx-arr[i][1]-1\r\nfor i in ans:\r\n print(i,end=' ')", "n = int(input())\r\nA = [int(i) for i in input().split()]\r\nsuf = [[10**10, -1] for i in range(n)]\r\n\r\nfrom bisect import bisect_left\r\n\r\nsuf[-1][0] = A[-1]\r\nsuf[-1][1] = n-1\r\n\r\nfor i in range(n-2, -1, -1):\r\n if suf[i+1][0] > A[i]:\r\n suf[i][0] = A[i]\r\n suf[i][1] = i\r\n else:\r\n suf[i][0] = suf[i+1][0]\r\n suf[i][1] = suf[i+1][1]\r\n\r\nans = []\r\n\r\nvals = [i[0] for i in suf]\r\n\r\nfor i in range(n):\r\n idx = bisect_left(vals, A[i])\r\n ans.append(max(-1, idx-i-2))\r\nprint(*ans)\r\n", "n = int(input())\r\nl = []\r\nfor i,j in enumerate(map(int,input().split())):\r\n l.append((j,i))\r\nl=sorted(l)\r\nmx = -1\r\nans = [0]*n\r\nfor val,i in l:\r\n mx = max(mx,i)\r\n ans[i] = mx-i-1\r\nprint(*ans)", "import itertools\r\nfrom bisect import bisect_left\r\n\r\n\r\ndef main():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n b = sorted(enumerate(reversed(a)), key=lambda y: y[1])\r\n indices, values = zip(*b)\r\n indices, values = list(itertools.accumulate(indices, min)), list(values)\r\n\r\n for pos, x in zip(range(n - 1, -1, -1), a):\r\n # print(pos, x, end=\" \")\r\n index = bisect_left(values, x)\r\n if index == n or values[index] >= x:\r\n index -= 1\r\n print(-1 if index < 0 else max(-1, pos - indices[index] - 1), end=\" \")\r\n # print()\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "from typing import List\n\ndef walrus_displeasure(n: int, arr: List[int]) -> List[int]:\n result = [-1] * n\n arr = [(val, idx) for idx, val in enumerate(arr)]\n arr.sort()\n \n maxx = -1\n for val, idx in arr:\n if maxx < idx:\n result[idx] = -1\n maxx = idx\n else:\n result[idx] = maxx - idx - 1\n return result\n\nn = int(input())\na = [int(i) for i in input().split()]\nprint(*walrus_displeasure(n, a))\n", "n = int(input())\r\nA = list(map(int,input().split()))\r\nB = [0]*len(A) # список ответов\r\nC = [[0]*3 for i in range(len(A))] # хранить мин элементы, индекс текущего и предыдущего минимума\r\nB[-1] = -1\r\nC[-1][0] = A[-1]\r\nC[-1][1] = len(A)-1\r\nC[-1][2] = len(A) # за границы массива\r\nfor i in range(len(A)-2,-1,-1): # нужно записывать в список B\r\n if A[i] < C[i+1][0]: # то есть слева морж мороже и конфликта нет\r\n B[i] = -1\r\n C[i][0] = A[i]\r\n C[i][1] = i\r\n C[i][2] = C[i+1][1]\r\n elif A[i] == C[i+1][0]:\r\n B[i] = -1\r\n C[i][0] = A[i]\r\n C[i][1] = C[i+1][1]\r\n C[i][2] = C[i + 1][2]\r\n else: # то есть где-то справа точно есть морж моложе и есть конфликт, который нужно посчитать\r\n C[i][0] = C[i+1][0] # т.к. это не новый минимум\r\n C[i][1] = C[i + 1][1]\r\n C[i][2] = C[i + 1][2]\r\n k = 0\r\n m = i\r\n while m+1 < len(A) and A[i] > C[C[m+1][1]][0]:\r\n k += C[m+1][1] - m\r\n m = C[m+1][1]\r\n k -= 1\r\n B[i] = k\r\n\r\n\r\n\r\nfor i in range(len(B)): # инструкция на вывод ответа\r\n print(B[i],end=' ')", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\nd = sorted([(j, i) for i, j in enumerate(w)])\r\nx = -1\r\nw = [0]*n\r\nfor j, i in d:\r\n if i > x:\r\n w[i] = -1\r\n x = i\r\n else:\r\n w[i] = x-i-1\r\nprint(' '.join(map(str, w)))\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nm=[0]*n\r\nfor i in range(n-1,-1,-1):\r\n if(i==n-1):\r\n m[i]=a[i]\r\n else:\r\n m[i]=min(a[i],m[i+1])\r\nres=[0 for i in range(n)]\r\nfor i in range(n):\r\n left=i+1\r\n right=n-1\r\n ans=-1\r\n while(left<=right):\r\n mid=left+(right-left)//2\r\n if(m[mid]<a[i]):\r\n ans=mid\r\n left=mid+1\r\n else:\r\n right=mid-1\r\n if(ans!=-1):\r\n res[i]=abs(ans-i-1)\r\n else:\r\n res[i]=-1\r\nprint(*res)", "def BinarySearch(lst,dp,start,end,Value):\r\n left_minimum = start\r\n \r\n while(start<=end):\r\n mid = (start+end)//2\r\n if(lst[dp[mid]]<Value):\r\n start = mid+1\r\n left_minimum = mid \r\n else:\r\n end = mid -1\r\n \r\n return left_minimum\r\n \r\n \r\n \r\nn = int(input()) \r\nlst = list(map(int,input().split()))\r\ndp = [0 for i in range(n)]\r\n\r\nMin = lst[n-1]\r\nIndex = n-1 \r\ndp[n-1] = n-1\r\n\r\nfor j in range(n-2,-1,-1):\r\n if(lst[j]<Min):\r\n Min = lst[j]\r\n Index = j \r\n dp[j]=Index\r\n\r\n\r\nfor j in range(n):\r\n Index = BinarySearch(lst,dp,j,n-1,lst[j])\r\n if(Index>j):\r\n print(Index-j-1,end=' ')\r\n else:\r\n print(-1,end=' ')\r\nprint()\r\n ", "max_value = 100005\n\n\nclass Node:\n def __init__(self, age, id):\n self.age = age\n self.id = id\n\ns = [Node(0, 0)] * max_value\n\nn = 0\ntop = 1\nn = int(input())\n\na = [-1]+list(map(int,input().split()))\n\ns[top] = Node(a[n], n)\na[n] = -1\n\nfor i in range(n - 1, 0, -1):\n l = 1\n r = top\n\n while l <= r:\n mid = (l + r) // 2\n\n if s[mid].age >= a[i]:\n l = mid + 1\n else:\n r = mid - 1\n\n if l <= top:\n a[i] = s[l].id - i - 1\n else:\n top += 1\n s[top] = Node(a[i], i)\n a[i] = -1\n\nfor i in range(1, n + 1):\n print(a[i], end=\" \")\n\n\t \t\t \t\t\t\t \t\t \t\t \t \t \t\t", "n=int(input())\nl=list(map(int,input().split()))\n\ns=[]\nfor i in range(n):\n s.append([l[i],i])\ns=sorted(s,key=lambda x:x[0])\nm=[-1]*n\nk=0\nfor i in range(0,n):\n k=max(k,s[i][1])\n m[s[i][1]]=max(k-s[i][1]-1,m[s[i][1]])\nprint(*m)\n\n\t\t\t \t\t\t \t \t\t\t\t \t\t\t \t\t\t \t\t", "n=int(input())\r\nx=[int(q) for q in input().split()]\r\nl=[0]*n\r\n\r\ndef search(i,l,h):\r\n pos=-1\r\n while(h>=l):\r\n mid=(l+h)//2\r\n if x[mid]<x[i]:\r\n pos=mid\r\n l=mid+1\r\n else:\r\n h=mid-1\r\n if pos!=-1:\r\n return pos-i-1\r\n else:\r\n return -1 \r\n\r\nfor i in range(n-1,-1,-1):\r\n l[i]=search(i,i+1,n-1)\r\n if i!=n-1:\r\n x[i]=min(x[i+1],x[i])\r\nprint(\" \".join(map(str,l)))", "from sys import stdin as si\n\n\nclass Solution:\n\n def bazinga(self,n,m):\n r = [-1]*n\n # sorted(enumerate(m), key-itemgetter(1))\n m = sorted(range(len(m)), key= lambda k: m[k])\n mx = 0\n for i in range(n):\n mx = max(mx,m[i])\n r[m[i]] = mx - m[i] - 1\n print (*r)\n\n\n\nif __name__ == '__main__':\n #for i in range(int(si.readline().strip())):\n n = int(si.readline().strip())\n #n,m = map(int, si.readline().strip().split())\n m = list(map(int, si.readline().strip().split()))\n S = Solution()\n S.bazinga(n,m)\n\n\n'''\nhttp://codeforces.com/contest/91/problem/B\n'''", "\r\nimport math \r\nimport sys\r\nfrom decimal import Decimal\r\ndef main(arr):\r\n\r\n\r\n minof=[0]*(len(arr))\r\n \r\n minof[-1]=[arr[-1],len(arr)-1]\r\n for i in range(len(arr)-2,-1,-1):\r\n a,b=minof[i+1]\r\n c=arr[i] \r\n if a<=c:\r\n minof[i]=[a,b]\r\n else:\r\n minof[i]=[c,i] \r\n ans=[]\r\n\r\n for i in range(len(arr)-1):\r\n \r\n \r\n val=arr[i] \r\n l=i\r\n r=len(arr)-1 \r\n best=l\r\n while l<=r:\r\n m=(l+r)//2\r\n a,b=minof[m]\r\n \r\n if val>a:\r\n l=m+1\r\n best=m\r\n else:\r\n r=m-1\r\n ans.append(best-i-1)\r\n\r\n ans.append(-1)\r\n print(*ans)\r\n return \r\n\r\nn=int(input())\r\narr=list(map(int,input().split()))\r\n(main(arr))\r\n\r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n", "def disp(wal1):\r\n wal1=sorted(wal1)\r\n highest_ind=-1\r\n ret_arr=[-1]*len(wal1)\r\n for wal in wal1:\r\n if wal[1]<highest_ind:\r\n ret_arr[wal[1]]=highest_ind-wal[1]-1\r\n highest_ind=max(highest_ind,wal[1])\r\n return ret_arr\r\n\r\nn=int(input())\r\nwalrus_arr=list(map(int,input().split()))\r\nwalrus_arr=[(age,ind) for ind,age in enumerate(walrus_arr)]\r\n\r\nfor wal in disp(walrus_arr):\r\n print(wal,end=\" \")", "n=int(input())\na=list(map(int,input().split()))\n\nlis=[]\nfor i in range(n):\n lis.append((a[i],i))\n\n##print(lis)\n\nlis.sort(key=lambda x:x[0])\n\nrj=[-1]*n\nmaks=0\n\nfor i in range(n):\n maks=max(maks,lis[i][1])\n rj[lis[i][1]]=maks-lis[i][1]-1\n## print(lis[i][1])\n\nprint(*rj)\n\n\t\t\t\t\t \t\t \t \t \t \t\t\t \t\t \t\t\t\t \t" ]
{"inputs": ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11", "13\n18 9 8 9 23 20 18 18 33 25 31 37 36", "10\n15 21 17 22 27 21 31 26 32 30", "10\n18 20 18 17 17 13 22 20 34 29", "13\n16 14 12 9 11 28 30 21 35 30 32 31 43", "15\n18 6 18 21 14 20 13 9 18 20 28 13 19 25 21", "11\n15 17 18 18 26 22 23 33 33 21 29", "15\n14 4 5 12 6 19 14 19 12 22 23 17 14 21 27", "2\n1 1000000000", "2\n1000000000 1", "5\n15 1 8 15 3", "12\n5 1 2 5 100 1 1000 100 10000 20000 10000 20000"], "outputs": ["2 1 0 -1 0 -1 ", "4 2 1 0 -1 -1 -1 ", "1 0 -1 -1 -1 ", "2 0 -1 -1 2 1 -1 -1 1 -1 -1 0 -1 ", "-1 0 -1 1 2 -1 2 -1 0 -1 ", "4 3 2 1 0 -1 0 -1 0 -1 ", "3 2 1 -1 -1 1 0 -1 2 -1 0 -1 -1 ", "10 -1 8 8 6 6 0 -1 2 2 3 -1 -1 0 -1 ", "-1 -1 -1 -1 4 3 2 2 1 -1 -1 ", "7 -1 -1 0 -1 6 1 4 -1 3 2 0 -1 -1 -1 ", "-1 -1 ", "0 -1 ", "3 -1 1 0 -1 ", "4 -1 2 1 0 -1 0 -1 -1 0 -1 -1 "]}
UNKNOWN
PYTHON3
CODEFORCES
51
20ffe02488c708a6ac25d6687efe45a2
Snacktower
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Sample Input 3 3 1 2 5 4 5 1 2 3 Sample Output 3   2 15 4     3 2 1
[ "n = int(input())\r\nsnacks = {int(num): day for day, num in enumerate(input().split(\" \"))}\r\ndays = [[] for _ in range(n)]\r\nsorted_snacks = sorted(snacks, reverse=True)\r\ncurrent_day = None\r\nfor snack in sorted_snacks:\r\n snack_day = snacks[snack]\r\n if current_day is None:\r\n current_day = snack_day\r\n\r\n if snack_day > current_day:\r\n current_day = snack_day\r\n\r\n days[current_day].append(snack)\r\n\r\nfor day in days:\r\n if not day:\r\n print(\"\")\r\n else:\r\n print(\" \".join([str(snack) for snack in day]))\r\n \r\n\r\n\r\n", "import sys\nimport heapq\n\ndef main(arr):\n visited = [False] * len(arr)\n last = len(visited) - 1\n\n for n in arr:\n visited[n - 1] = True\n doing = []\n while last >= 0 and visited[last]:\n doing.append(last + 1)\n last -= 1\n\n print(\" \".join(str(d) for d in doing))\n\nif __name__ == \"__main__\":\n for e, line in enumerate(sys.stdin.readlines()):\n if e == 0:\n continue\n else:\n arr = list(map(int, line.strip().split()))\n\n # Proof by induction that sorting is that\n # same as solving this problem.\n main(arr)\n", "\r\nn = int(input()); arr = list(map(int, input().split()))\r\nturn = n; fell = [False]*n\r\n\r\nfor i in range(n):\r\n fell[arr[i]-1] = True\r\n if arr[i] == turn:\r\n while fell[turn - 1] and turn >= 1:\r\n print(turn, end=' ')\r\n turn -= 1\r\n print()\r\n\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nmarked = [None] + [False for i in range(n)]\r\nj = n\r\nfor i in range(n):\r\n marked[arr[i]] = True\r\n while marked[j] and j > 0:\r\n print(j, end=\" \")\r\n j -= 1\r\n print()\r\n\r\n", "def solution():\r\n n = int(input())\r\n nums = [int(num) for num in input().split()]\r\n cur = n\r\n wait = set()\r\n for num in nums:\r\n if num == cur:\r\n print(cur, end = ' ')\r\n cur -= 1\r\n while cur in wait:\r\n print(cur, end = ' ')\r\n cur -= 1\r\n print()\r\n else:\r\n wait.add(num)\r\n print()\r\n \r\n \r\ndef main():\r\n t = 1\r\n while t:\r\n solution()\r\n t -= 1\r\n \r\n \r\nif __name__ == '__main__':\r\n main()", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nsnack = [0]*(n+1)\r\ncr = n\r\nm = n+1\r\nop=[]\r\nfor i in range(n):\r\n snack[arr[i]] = 1 \r\n if arr[i] == cr:\r\n while snack[cr] == 1:\r\n op.append(cr)\r\n snack[cr]=2\r\n cr-=1\r\n \r\n print(*op)\r\n op.clear()", "import sys\n\nn = int(input())\ns = [int(i) for i in input().split()]\n\nnext = n\na = (n + 1) * [bool]\n\nfor p in s:\n a[p] = 1\n\n while(a[next] == 1):\n print(next, end=\" \")\n next -= 1\n print(\"\")\n\t\t \t \t \t\t\t\t\t \t \t\t \t\t \t", "n = int(input())\nt = [int(i) for i in input().split()]\n\n# n = 5\n# t = [4, 5, 1, 2, 3]\n\nsub = set()\nquer = max(t)\n\nfor i in range(n):\n if( t[i] == quer) or (quer in sub):\n p = str(quer)\n quer -= 1\n\n while(quer in sub):\n p +=\" \"+str(quer)\n quer -= 1\n\n print(p)\n else: \n print()\n sub.add(t[i])\n\t \t\t \t \t \t \t\t \t \t\t \t\t \t\t\t\t", "n = int(input())\r\nA = list(map(int,input().split()))\r\n\r\nB = [0]*(n+1)\r\nB[0] = -1\r\nt = n\r\nfor i in range(len(A)):\r\n if A[i] == t and t != 0:\r\n print(t,end=' ')\r\n v = t-1\r\n while v > 0 and B[v] == 1:\r\n print(v,end=' ')\r\n v -= 1\r\n t = v\r\n print()\r\n\r\n else:\r\n B[A[i]] = 1\r\n print()", "n=int(input())\r\nlista=list(map(int,input().split()))\r\nl=[]\r\nfor i in range(0,n+1):\r\n l.append(False)\r\nc=n\r\nfor i in range(0,n):\r\n l[lista[i]]=True\r\n while l[c] and c>0:\r\n \r\n print(c,end=\" \")\r\n c-=1\r\n print()\r\n", "n = int(input())\r\nl1=list(map(int, input().split()))\r\nl=[0]*n\r\ncurrent=n\r\ndef printer(x,current2):\r\n if x==current2:\r\n for i in range(current2,0,-1):\r\n if l[i-1]==1:\r\n print(i,end=' ')\r\n global current\r\n current=i-1\r\n else:\r\n break\r\nfor i in range(n):\r\n x=l1[i]\r\n l[x-1]=1\r\n printer(x,current)\r\n print()\r\n\r\n\r\n", "n = int(input())\r\ntab = list(map(int, input().split()))\r\n\r\nseen = {}\r\nfor i in range(n):\r\n if tab[i] == n:\r\n print(n, end=' ')\r\n while n - 1 in seen:\r\n print(n - 1, end=' ')\r\n n -= 1\r\n n -= 1\r\n print()\r\n else:\r\n seen[tab[i]] = True\r\n print()\r\n\r\nfor i in range(n, 0, -1):\r\n if i in seen:\r\n print(i, end=' ')\r\n else:\r\n break", "from sys import stdin\r\n \r\nn = int(stdin.readline())\r\ns = list(map(int,stdin.readline().split()))\r\nidx = [False]*(n+1)\r\nres = ['']*n\r\nk = n\r\n \r\nfor i in range(n):\r\n x = s[i]\r\n idx[x] = x\r\n if k == x:\r\n temp = []\r\n while idx[k]:\r\n temp.append(idx[k])\r\n k -= 1\r\n res[i] = ' '.join([str(a) for a in temp])\r\nprint('\\n'.join(res))\r\n ", "def createSnakeTower(n, snacks):\r\n \r\n visitedSnacks = [None] * n\r\n \r\n for snack in snacks:\r\n visitedSnacks[int(snack)-1] = snack\r\n \r\n while visitedSnacks[n-1] and n != 0:\r\n print(\"{0}\".format(n), end=\" \")\r\n n -= 1\r\n print(\"\")\r\n \r\n \r\nif __name__ == \"__main__\":\r\n n = int(input().strip())\r\n s = input().split()\r\n \r\n createSnakeTower(n, s)", "n = int(input())\na = list(map(int, input().split(\" \")))\ncheck = [False for _ in range(n)]\nx = n-1\nfor b in a:\n check[b-1]=True\n while check[x] and x>=0:\n print(str(x+1) + \" \", end=\"\") \n x-=1\n if x >=0:\n print(\"\")\n\n\n", "n = int(input())\r\narr = input().split(' ')\r\nfor i in range(len(arr)):\r\n arr[i] = int(arr[i])\r\n\r\nneeded = n\r\nstore=[-1]*(n+10)\r\nwhile len(arr):\r\n i = arr.pop(0)\r\n store[i] = i\r\n if i != needed:\r\n print()\r\n else:\r\n while(store[i]!=-1):\r\n print(i,end=' ')\r\n i -= 1\r\n print()\r\n needed = i\r\n ", "n=int(input())\narr=[int(i) for i in input().split()]\n\nb=[0 for i in range(n+1)]\n\nfor i in range(n):\n\tb[arr[i]]=1\n\tline=[]\n\twhile(b[n]):\n\t\tline.append(str(n))\n\t\tn-=1\n\tprint(' '.join(line))\n \t \t \t \t \t\t\t \t \t", "import sys, heapq\r\n\r\nn = int(sys.stdin.readline())\r\narr = list(map(int, sys.stdin.readline().split()))\r\nq = []\r\nfor i in arr:\r\n heapq.heappush(q, (-i, i))\r\n if i == n:\r\n while q:\r\n if q[0][1] == n:\r\n print(heapq.heappop(q)[1], end=' ')\r\n n -= 1\r\n else:\r\n break\r\n print()\r\n else:\r\n print()\r\n", "import heapq\r\nn=int(input())\r\nx=list(map(int,input().split()))\r\nl=[]\r\ngoal=n\r\nfor i in x:\r\n if i==goal:\r\n o=[goal]\r\n goal-=1\r\n while l and -l[0]==goal:\r\n goal-=1\r\n o.append(-heapq.heappop(l))\r\n print(*o)\r\n else:\r\n print(\"\\n\",end=\"\")\r\n heapq.heappush(l,-i)", "n = int(input())\r\nx = [int(i) for i in input().split()]\r\nvis = [0] * n\r\nc = n\r\n\r\nfor i in range(n):\r\n vis[x[i] - 1] = True\r\n h = []\r\n while (vis[c - 1]) and c > 0:\r\n h.append(str(c))\r\n c -= 1\r\n print(\" \".join(h))\r\n", "n = int(input())\r\narv=[0]*(n+1)\r\narr = [int(x) for x in input().split()]\r\n# sol = []\r\narr.insert(0,0)\r\n# print(arr)\r\narv[arr[0]]=1\r\nm=n\r\nfor q in range(1,n+1):\r\n arv[arr[q]]=1\r\n while arv[m] and m>0:\r\n print(m,end=\" \")\r\n m-=1\r\n print(\" \")", "n = int(input())\nsizes = [int(x) for x in input().split(\" \")]\n\neval_sizes = [False for x in range(n)]\nnivel = n\nfor i, size in enumerate(sizes):\n eval_sizes[size-1] = True\n for x in range(nivel,0,-1):\n if eval_sizes[x-1]:\n print(x,end=\" \")\n eval_sizes[x-1] = False\n nivel -= 1\n else:\n break\n print()\n \n \t \t\t \t \t\t\t \t \t \t\t \t\t \t\t\t", "n=int(input())\r\na=list(map(int,input().split()))\r\ns=set()\r\nj=n\r\nfor i in range(n):\r\n s.add(a[i])\r\n while j in s:\r\n print(j,end=' ')\r\n j=j-1\r\n print()", "from collections import deque\r\nimport heapq\r\n\r\nn = int(input())\r\narr = deque(list(map(int, input().split())))\r\nmaxi = n\r\ncaching = []\r\n\r\nwhile arr:\r\n item = arr.popleft()\r\n if item != maxi:\r\n heapq.heappush(caching, -item)\r\n print()\r\n else:\r\n maxi -= 1\r\n print(item, end = \" \")\r\n last = item\r\n while caching and last+caching[0]==1:\r\n last = -heapq.heappop(caching)\r\n print(last, end = \" \")\r\n maxi-=1\r\n print()", "# D - Snacktower\nimport heapq\n\ncmax = int(input())\nrain = list(map(int, input().split()))\n\nstack = []\nfor snack in rain:\n heapq.heappush(stack, -snack)\n out = ''\n while len(stack) > 0 and stack[0] == -cmax:\n cmax = cmax - 1\n out = out + '{0} '.format(-heapq.heappop(stack))\n print(out)\n\t\t\t\t \t \t \t\t \t \t \t \t\t \t\t\t", "import sys\r\nfrom array import array\r\n\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\n \r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n\r\n############ ---- Solution ---- ###########\r\nn = inp()\r\nfalling = inlt()\r\nneed = n\r\nexists = array('b', [False] * (n+1))\r\n\r\nfor i in falling:\r\n out=\"\"\r\n exists[i]=True\r\n if (need == i):\r\n while(exists[need]):\r\n out+=str(need)+\" \"\r\n need-=1\r\n print(out)\r\n else:\r\n print(\"\")\r\n", "n = int(input())\r\nsnacks = list(map(int,input().split()))\r\norder = [0] * (n+1)\r\n\r\nptr = n\r\nans = []\r\ni = 0\r\nwhile (ptr > 0):\r\n if (snacks[i] == ptr):\r\n order[ptr] = 1\r\n while (order[ptr] == 1):\r\n ans.append(ptr)\r\n ptr -= 1\r\n else:\r\n order[snacks[i]] = 1\r\n if (ans == []):\r\n print()\r\n else:\r\n print(*ans)\r\n ans = []\r\n i += 1", "n=int(input())\r\nl=list(map(int,input().split()))\r\nd=[0]*(n+1)\r\nx=n\r\nfor i in range(n):\r\n d[l[i]]=1\r\n while(d[x]==1):\r\n print(x,end=' ')\r\n x=x-1\r\n print()", "n = int(input())\r\nsnacks = list(map(int, input().split()))\r\nstack = [False] * (n + 1)\r\nexpected = n\r\nindicator = n\r\nfor snack in snacks:\r\n if snack == expected:\r\n print(snack, end=\" \")\r\n stack[snack] = False\r\n expected = expected-1\r\n for i in range(expected, indicator-1, -1):\r\n if stack[i]:\r\n print(i, end=\" \")\r\n stack[i] = False\r\n expected -=1\r\n else:\r\n break\r\n print('')\r\n else:\r\n print()\r\n stack[snack] = True\r\n indicator -= 1", "n=int(input())\r\ns=set()\r\na=map(int,input().split())\r\nfor i in a:\r\n s.add(i)\r\n while n in s:\r\n print(n,end=' ')\r\n n-=1\r\n print()", "n=int(input())\narr=[int(x) for x in input().split()]\narr2=[False]*(n+1)\ntarget=n\nfor i in arr:\n arr2[i]=1\n while arr2[target]:\n print(target,end=' ')\n target-=1\n print()\n \t \t \t \t \t \t \t \t\t\t\t \t\t", "ln = int(input())\nfel = list(map(int, input().split(\" \")))\nmx = ln\nstor = set()\npnt = \"\"\nfor i in range(ln):\n if fel[i] < mx:\n stor.add(fel[i])\n print(\"\")\n elif fel[i] == mx:\n pnt += str(fel[i])\n for j in range(fel[i]-1,0,-1):\n if j in stor:\n pnt += \" \"+str(j)\n else:\n mx = j\n break\n print(pnt)\n pnt = \"\"\n", "n = int(input())\r\ns = list(map(int, input().strip().split()))\r\ntar = n\r\nvis = [0] * (n + 1)\r\nfor i in range(n):\r\n vis[s[i]] = 1\r\n f = \"\"\r\n for j in range(tar, 0, -1):\r\n if vis[j] == 1:\r\n f += (str(j) + \" \")\r\n else:\r\n tar = j\r\n break\r\n print(f)", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\n#\r\n# ------------------------------------------------------------------------------\r\n# Author: Mohammad Mohsen\r\n# Date: Tue Feb 8 19:30:29 2022\r\n# problem name: Snacktower\r\n# contest: 767-Codeforces Round #398 (Div. 2)\r\n# problem difficulty: A-D2\r\n# problem url: https://codeforces.com/problemset/problem/767/A\r\n# ------------------------------------------------------------------------------\r\n\r\n\r\n\r\n\"\"\"\r\n6\r\n4 5 6 3 1 2\r\n\r\n\\n\r\n\\n\r\n6 5 4\r\n3\r\n\\n\r\n\\n\r\n2 1 0\r\n\r\n--------------------\r\n\r\n10\r\n5 1 6 2 8 3 4 10 9 7\r\n\r\nAnswer\r\n\\n\r\n\\n\r\n\\n\r\n\\n\r\n\\n\r\n\\n\r\n\\n\r\n10 \r\n9 8 \r\n7 6 5 4 3 2 1 \r\n\r\n\r\n10\r\n5 1 6 2 8 3 4 7 9 10\r\n\r\n\"\"\"\r\n\r\n\r\nfrom typing import *\r\nfrom io import StringIO\r\n\r\n\r\nclass Problem(object):\r\n\r\n def __init__(self, name: str) -> None:\r\n self.name: str = name\r\n\r\n def solution(self) -> Union[str, int, float]:\r\n with StringIO() as out_file:\r\n num_of_snacks: int = int(input().strip())\r\n snacks: List[int] = [int(s) for s in input().strip().split()]\r\n\r\n stored: List[bool] = [False for i in snacks]\r\n snack_base: int = num_of_snacks\r\n\r\n for (n, snack) in enumerate(snacks):\r\n stored[snack - 1] = True\r\n\r\n while (stored[snack_base - 1] is True) and (snack_base > 0):\r\n print(f\"{snack_base} \", end=\"\")\r\n snack_base -= 1\r\n\r\n print(\"\")\r\n\r\n return out_file.getvalue()\r\n\r\n\r\nproblem = Problem(\"Snacktower\")\r\n\r\nif __name__ == \"__main__\":\r\n solution: Union[str, int, float] = problem.solution()\r\n print(solution)\r\n\r\n", "def main():\r\n n = int(input())\r\n snacksList = list(map(int, input().split()))[:n]\r\n sortSet = set() # To sort numbers in ascending order\r\n\r\n for i in snacksList:\r\n sortSet.add(i)\r\n while n in sortSet:\r\n print(n, end=' ')\r\n n -= 1\r\n print()\r\n \r\nif __name__ == '__main__':\r\n main()", "#Problem D - Snacktower\nn = int(input())\nsequencia = input().split(' ')\ntamanho = len(sequencia)\nempilhado = []\ncaiu = [0]*(tamanho+1)\n\nfor i in range (tamanho):\n sequencia[i] = int(sequencia[i])\n\nproximo = n\n\nfor i in sequencia:\n caiu[i] = 1\n\n while (caiu[proximo] == 1):\n empilhado.append(proximo)\n proximo -= 1\n print(*empilhado, sep=' ')\n empilhado.clear()\n\t \t \t \t\t\t\t \t \t\t\t \t \t", "n = int(input())\nvisita = [0] *(n + 1)\n\nl = [int(value) for value in input().split()]\nbase = n\n\nfor i in range(n):\n guarda = []\n visita[l[i]] = 1\n \n aux = 0\n while (visita[base]) and base > 0:\n aux = 1\n guarda.append(base)\n base -= 1\n if aux:\n print(\" \".join([str(num) for num in guarda]))\n else:\n print(\"\")\n \t\t\t\t\t \t\t \t \t\t\t\t\t\t\t \t \t\t\t\t\t", "n = int(input())\r\ny = list(map(int, input().split()))\r\nz = set()\r\nfor i in y:\r\n z.add(i)\r\n while n in z:\r\n print(n, end=\" \")\r\n n -= 1\r\n print()\r\n", "n=int(input())\r\nsnacks = list(map(int,input().split()))\r\nfreq=[0 for i in range(n+1)]\r\npointer = n;\r\n\r\nfor i in range(n):\r\n \r\n freq[snacks[i]]=1\r\n \r\n if freq[pointer]==1:\r\n while freq[pointer]==1:\r\n print(pointer,end=\" \")\r\n pointer-=1\r\n \r\n print(\"\")", "n=int(input())\r\nsett=set()\r\narr=map(int,input().split())\r\nfor snack in arr:\r\n sett.add(snack)\r\n while n in sett:\r\n print(n,end=' ')\r\n n-=1\r\n print(\"\")", "n=int(input())\r\nl=list(map(int,input().split()))\r\ns=set()\r\nfor j in l:\r\n s.add(j)\r\n while n in s:\r\n print(n,end=\" \")\r\n n=n-1\r\n print()", "'''\n# Submitted By M7moud Ala3rj\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\n'''\n# Problem Name = \"Snacktower\"\n# Class: A\n\nfrom collections import defaultdict\nimport sys\n\n#sys.setrecursionlimit(2147483647)\ninput = sys.stdin.readline\ndef printf(*args, end='\\n', sep=' ') -> None:\n sys.stdout.write(sep.join(map(str, args)) + end)\n\ndef lower_bound(list_, s, e, x):\n l = s ; r = e ; ans = -1\n while l<=r:\n mid = (l + r)//2\n if list_[mid] >= x:\n ans = mid\n r = mid - 1\n else:\n l = mid + 1\n return ans if ans!=-1 else e+1\n\ndef Solve():\n n = int(input())\n o = n ; l = defaultdict(int)\n a = list(map(int, input().split()))\n for i in a:\n if i!=o:\n l[i]+=1\n printf()\n else:\n printf(i, end=\" \")\n for x in range(o-1, -1, -1):\n if l[x]:\n printf(x, end=\" \")\n l[x]-=1\n else:\n break\n printf()\n o = x\n \n\n\nif __name__ == \"__main__\":\n # for t in range(int(input())):\n Solve()\n\t \t\t\t \t \t\t \t\t\t\t\t \t\t\t \t \t", "n=int(input())\r\nli=list(map(int,input().split()))\r\nst=set()\r\nfor i in range(n):\r\n st.add(li[i])\r\n while n in st:\r\n print(n,end=\" \")\r\n n-=1\r\n print()\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "R = lambda: map(int, input().split())\r\nL = lambda: list(R())\r\nn,=R()\r\nmaxx = n\r\nl=L()\r\ns=set()\r\nfor i in l :\r\n\ts.add(i)\r\n\tcur=\"\"\r\n\twhile True :\r\n\t\tif maxx in s :\r\n\t\t\tcur+=\" \"+str(maxx)\r\n\t\t\ts.remove(maxx)\r\n\t\t\tmaxx-=1\r\n\t\telse : break\r\n\tprint(cur)", "n=int(input())\r\nstream=input()\r\nx=list(map(int, stream.split()))\r\nx.insert(0,0)\r\no=[False for i in range(0,n+1)]\r\nc=n\r\nfor i in range(1, n+1):\r\n o[x[i]]=True\r\n while o[c] and c>0:\r\n print(c,end=\" \")\r\n c-=1\r\n print(\"\")", "n: int = int(input())\narr = list(map(int, input().split()))\nctn = set()\ntarget = n\nfor i in arr:\n ctn.add(i)\n while target in ctn:\n print(target, end=\" \")\n target -= 1\n print()\n\n \t\t\t\t \t\t\t \t\t \t\t \t\t\t\t \t", "n=int(input())\r\narr=list(map(int,input().split()))\r\nc=n\r\ni=0\r\nl=[0]*n\r\nwhile i<n :\r\n if arr[i]==c :\r\n x=c-2\r\n s=str(c)+' '\r\n while l[x] :\r\n s+=str(l[x])+' '\r\n x-=1\r\n print(s)\r\n c=x+1\r\n else:\r\n print()\r\n l[arr[i]-1]=arr[i]\r\n i+=1\r\n ", "maxx = int(input()) \r\ndays = list(map(int , input().split())) \r\nvisited = [False] * (maxx+1) \r\nfor day in days : \r\n visited[day] = True\r\n if day == maxx : \r\n for j in range(day , 0 , -1) : \r\n if visited[j] == True : \r\n print(str(j) +' ' , end='' )\r\n maxx = j - 1 \r\n else : \r\n break\r\n print()\r\n\r\n\r\n \r\n\r\n", "# SNACKTOWER\r\nn = int(input())\r\nsnacks = list(map(int,input().split()))\r\nvisited = [0]\r\nfor _ in range(n):\r\n visited.append(False)\r\n\r\nfor i in snacks:\r\n visited[i] = True\r\n while visited[n]:\r\n print(str(n) + \" \", end=\"\")\r\n n -= 1\r\n print(\"\")", "import math\r\n\r\n\r\ndef main_function():\r\n n = int(input())\r\n a = [int(i) for i in input().split(\" \")]\r\n current_max = n\r\n hash_collector = {}\r\n for i in a:\r\n if not i == current_max:\r\n hash_collector[i] = 1\r\n print()\r\n else:\r\n to_be_printed_array = [current_max]\r\n current_max -= 1\r\n while current_max in hash_collector:\r\n to_be_printed_array.append(current_max)\r\n current_max -= 1\r\n for j in range(len(to_be_printed_array)):\r\n if j == len(to_be_printed_array) - 1:\r\n print(to_be_printed_array[j])\r\n else:\r\n print(to_be_printed_array[j], end=\" \")\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nlst = list(map(int, input().split()))\r\nbools = [False for i in range(n+1)]\r\n#print(bools)\r\nc = n \r\nfor i in range(n):\r\n bools[lst[i]] = True\r\n \r\n while bools[c]:\r\n print(c, end=\" \")\r\n c -= 1\r\n print()\r\n\r\n", "n = int(input())\r\n\r\ns = set()\r\n\r\nmax = n\r\n\r\nli = map(int, input().split())\r\n\r\nfor i in li:\r\n s.add(i)\r\n while max in s:\r\n print(max, end=' ')\r\n max -= 1\r\n print()", "n = int(input())\nsizes = list(map(int, input().split()))\n\nans = []\nstore = [0] * (n+1)\n\nexpected = n\nfor i in range(n):\n sub = []\n if sizes[i] == expected: # 5\n sub.append(expected)\n expected -= 1 # 2\n while store[expected] == 1:\n sub.append(expected)\n expected -= 1 # 1\n else:\n store[sizes[i]] = 1\n sub.append(\" \")\n ans.append(sub)\n\nfor i in range(n):\n ans[i] = [str(elem) for elem in ans[i]]\n print(\" \".join(ans[i]))\n\t\t\t \t \t \t \t \t \t\t \t\t\t \t \t\t\t\t", "number = int(input())\r\narr = list(map(int , input().split()))\r\nwanted = number\r\ndesire = {}\r\nfor i in range (0 , len(arr) ) :\r\n x = arr[i]\r\n if wanted == x :\r\n wanted -= 1\r\n print(x , \" \", end='')\r\n while f'{wanted}' in desire.keys() :\r\n print(wanted , \" \", end='')\r\n wanted -= 1\r\n elif wanted > x :\r\n desire[f\"{x}\"] = 'wait'\r\n print(\"\")", "def solution():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n done = set()\r\n j = n\r\n for i in range(n):\r\n done.add(a[i])\r\n while j in done:\r\n print(j, end=' ')\r\n j -= 1\r\n print()\r\n\r\n\r\nsolution()", "n = int(input()) \r\na = list(map(int,input().split())) \r\nmaxi =n\r\ns = set() \r\nfor i in a:\r\n # print(i,s)\r\n if (i==maxi):\r\n print(i,end=' ') \r\n maxi-=1 \r\n while(maxi in s):\r\n print(maxi,end=' ') \r\n s.add(maxi) \r\n maxi-=1 \r\n print()\r\n else:\r\n s.add(i) \r\n print()", "n = int(input())\r\narr = list(map(int, input().split()))\r\nlst = [0]*(n+1)\r\nk = n\r\nfor i in range(n):\r\n lst[arr[i]] = 1\r\n while lst[k] == 1:\r\n print(k, end=' ')\r\n k = k-1\r\n else:\r\n print('')", "n = int(input())\r\nl = list(map(int, input().split()))\r\nd = set()\r\nfor i in l:\r\n\td.add(i)\r\n\twhile n in d:\r\n\t\tprint(n, end = ' ')\r\n\t\tn -= 1\r\n\tprint()\r\n\t", "n=int(input())\r\nl=[int(x) for x in input().split()]\r\nd=set()\r\nfor i in l:\r\n\td.add(i)\r\n\twhile n in d:\r\n\t\tprint(n, end=' ')\r\n\t\tn-=1\r\n\tprint()\r\n\t", "n = int(input())\r\na = list(map(int, input().split()))\r\n\r\nl = [0]*n; e = n\r\nfor i in range(n):\r\n if a[i] == e:\r\n print(a[i], end=\" \"); e -= 1\r\n for j in range(e):\r\n if l[e-1] == e:\r\n print(e, end=\" \"); e -= 1\r\n else:\r\n break\r\n else:\r\n l[a[i]-1] = a[i]\r\n print()", "import math\r\n\r\n#s = input()\r\n#n= (map(int, input().split()))\r\n\r\nn = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\nmy_list = list([0 for i in range(0, 100000)])\r\n\r\nj = n\r\ni = 0\r\nwhile(i<len(a)):\r\n if a[i]!=j:\r\n my_list[a[i]-1] = 1\r\n print()\r\n else:\r\n print(j, end=\" \")\r\n k = i-1\r\n j -= 1\r\n while k>=0:\r\n if my_list[j-1]!=0:\r\n print(j, end=\" \")\r\n j-= 1\r\n else:\r\n break\r\n k -= 1\r\n print()\r\n i += 1\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\nins = [int(x) for x in input().split(\" \")]\r\ninsResorted = [0]*(n+1)\r\ncounter = 0\r\nfor i in ins:\r\n insResorted[i] = counter\r\n counter += 1\r\n\r\nturn = n\r\npI = 0\r\nwhile turn != 0:\r\n thisIndex = insResorted[turn]\r\n print(\"\\n\"*(thisIndex - pI), end=\"\")\r\n print(turn , end=\" \")\r\n for i in range(turn - 1 , 0 , -1):\r\n if insResorted[i] > thisIndex:\r\n break\r\n else:\r\n turn -= 1\r\n print(i , end=\" \")\r\n turn -= 1\r\n pI = thisIndex", "n = int(input())\r\nnums = [int(i) for i in input().split()]\r\nfound = [False for i in range(n)]\r\n\r\nfor num in nums:\r\n found[num-1] = True\r\n\r\n while found[n-1] and n != 0:\r\n print(n, end=\" \")\r\n n -= 1\r\n\r\n if not found[n - 1]:\r\n print()\r\n\r\n", "n = int(input())\r\na = [int(x) for x in input().split()]\r\nlowest = 1\r\nres = []\r\nfor i in range(n-1,-1,-1):\r\n if a[i]>=lowest:\r\n res.append([x for x in range(a[i],lowest-1,-1)])\r\n lowest = a[i]+1\r\n else:\r\n res.append([])\r\nfor x in res[::-1]:\r\n print(*x)", "n = int(input())\r\nsnacks = input().split(' ')\r\nlsnack = []\r\nstart = 0\r\nfor snack in snacks:\r\n lsnack.append(int(snack))\r\norder = sorted(lsnack, reverse = True)\r\nHaveSeen = dict(zip(order,[0 for i in range(n)]))\r\n\r\nfor j in range(n):\r\n HaveSeen[lsnack[j]] = 1\r\n k = start\r\n while k < n and HaveSeen[order[k]] == 1:\r\n print(order[k], end=' ')\r\n k += 1\r\n print('')\r\n start = k\r\n", "n = int(input())\r\ncandies = list(map(int, input().split()))\r\nfallen_caneies = set()\r\nfor i in candies:\r\n fallen_caneies.add(i)\r\n while n in fallen_caneies:\r\n print(n, end=' ')\r\n n -= 1\r\n print()", "n = int(input())\r\nsnacks = list(map(int, input().split()))\r\nfell = [False]*n\r\nfor i in range(n):\r\n if snacks[i] == n:\r\n fell[n-1] = True\r\n j = n - 1\r\n while fell[j] and j >= 0:\r\n print(j+1, end=' ')\r\n n -= 1\r\n j -= 1\r\n print()\r\n else:\r\n fell[snacks[i]-1] = True\r\n print()", "n, = map(int, input().split())\nA = list(map(int, input().split()))\nseen = [False] * (1+n)\nhi = n\nfor a in A:\n seen[a] = True\n ans = []\n while seen[hi]:\n ans.append(hi)\n hi -= 1\n print(*ans)\n", "nCandy = int(input())\r\ncandySizes = [int(i) for i in input().split()]\r\nseen = [False] * nCandy\r\nbiggestPossibleSize = nCandy \r\n\r\n\r\nfor i in range(nCandy):\r\n seen[candySizes[i] - 1] = True\r\n if candySizes[i] == biggestPossibleSize:\r\n print(biggestPossibleSize , end = ' ')\r\n for j in range(biggestPossibleSize - 1 , 0 , - 1):\r\n if seen[j - 1]:\r\n print(j , end = ' ')\r\n else:\r\n if i != nCandy -1: print()\r\n else: print('', end='')\r\n biggestPossibleSize = j\r\n break\r\n \r\n else:\r\n if nCandy - 1 != i:\r\n print()\r\n else:\r\n print('',end='')\r\n", "n = int(input())\r\ns = [int(x) for x in input().split()]\r\n\r\nimport heapq\r\nhold = []\r\nfor i in s:\r\n heapq.heappush(hold, -i)\r\n if -1*(hold[0]) == n:\r\n while len(hold) != 0 and -1*hold[0] == n:\r\n print(n, end=' ')\r\n n -= 1\r\n heapq.heappop(hold)\r\n print()\r\n else:\r\n print()", "n =int(input())\narr = list(map(int, input().split()))\nmyset = set()\nfor i in arr:\n myset.add(i)\n while n in myset:\n print(n, end=' ')\n n -= 1\n print()", "from collections import deque, defaultdict, Counter\r\nfrom itertools import product, groupby, permutations, combinations, accumulate, zip_longest, \\\r\n combinations_with_replacement\r\nfrom math import gcd, floor, inf, log2, sqrt, log10, factorial\r\nfrom bisect import bisect_right, bisect_left\r\nfrom statistics import mode\r\nfrom string import ascii_lowercase, ascii_uppercase\r\nfrom heapq import heapify, heappop, heappush, heappushpop, heapreplace, nlargest, nsmallest, \\\r\n merge\r\nfrom copy import deepcopy\r\n\r\nnum = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nnext_num = num\r\nwaited = set()\r\n\r\nfor n in arr:\r\n if n == next_num:\r\n ans = [n]\r\n n -= 1\r\n while n in waited:\r\n ans.append(n)\r\n n -= 1\r\n print(*ans)\r\n next_num = n\r\n else:\r\n waited.add(n)\r\n print()\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\nx = [i for i in range(n, 0, -1)]\r\nfor i in range(n):\r\n x[-arr[i]] = i+1\r\n\r\nfor i in range(1, n+1):\r\n arr = []\r\n while len(x) > 0 and x[0] <= i:\r\n arr.append(len(x))\r\n x.pop(0)\r\n print(' '.join(map(str, arr)))\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Sun Jul 24 12:20:58 2022\r\n\r\n@author: Conor\r\n\r\nCFSheet A Problem 39 - CF767-DIV2A\r\n\"\"\"\r\n\r\nsnacks = int(input())\r\norder = list(map(int,input().split()))\r\nsearchingFor = snacks\r\nsnackPile = [0]*snacks\r\ntoPrint = []\r\n\r\nfor i in range(snacks):\r\n incoming = order[i]\r\n snackPile[incoming-1] = 1\r\n if incoming == searchingFor:\r\n pointer = searchingFor-1\r\n while snackPile[pointer] == 1:\r\n toPrint.append(pointer+1)\r\n snackPile[pointer] = 0\r\n pointer -= 1\r\n print(*toPrint)\r\n toPrint = []\r\n searchingFor = pointer+1\r\n else:\r\n print()\r\n", "n=int(input())\r\nw=[int(k) for k in input().split()]\r\nc=n\r\nq=set()\r\nfor i in w:\r\n q.add(i)\r\n res=[]\r\n while c in q:\r\n res.append(c)\r\n c-=1\r\n print(\" \".join([str(k) for k in res]))", "n, s = int(input()), set()\nA = map(int, input().split())\nfor a in A:\n c = []\n s.add(a)\n while n in s:\n c.append(n)\n n -= 1\n print(*c)", "n = int(input())\r\ns = set()\r\nli = [int(x) for x in input().split()]\r\n\r\nfor i in li:\r\n s.add(i)\r\n while n in s:\r\n print(n,end=' ')\r\n n-=1\r\n print()", "\"\"\"Date: 2023-11-03 10:37:05.530366\nProblem: Codeforces 767A\nAuthor: pkr1012\n\"\"\"\n\ndef PrintAllHas(has, next):\n while(has[next]): \n print(next, end=\" \")\n next -= 1\n print()\n return next\n\ndef main():\n n = int(input())\n A = list(map(int, input().split()))\n next = n\n has = [0 for _ in range(n + 1)]\n for i in range(n):\n if (A[i] == next):\n has[A[i]] = 1\n next = PrintAllHas(has, next)\n else: \n has[A[i]] = 1\n print()\n\nif __name__ == \"__main__\":\n main()\n\n", "# python3\n\n#===============================================================================\nfrom collections import defaultdict, Counter\nfrom functools import lru_cache\nfrom heapq import heappush, heappop, heapify\nfrom math import gcd, floor, ceil\nfrom sys import stdin, stdout\n\ndef ilist():\n return [int(x) for x in stdin.readline().strip().split(\" \")]\ndef iint():\n return int(stdin.readline().strip())\ndef istr():\n return stdin.readline().strip()\n##==============================================================================\n\n\ndef solve(a):\n n = len(a)\n ex = n\n h = []\n for s in a:\n res = []\n heappush(h, -s)\n while h and ex == -h[0]:\n res.append(str(ex))\n ex -= 1\n _ = heappop(h)\n print(\" \".join(res))\n\n\nif __name__ == '__main__':\n n = iint()\n a = ilist()\n solve(a)\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\n\r\ndef main():\r\n n = int(input())\r\n arr = [int(item) for item in input().split()]\r\n ans =[0]*n\r\n i = 0\r\n \r\n while(len(ans)!=0):\r\n ans[arr[i] -1] = 1\r\n an = []\r\n while(len(ans)!=0 and ans[-1] == 1):\r\n an.append(len(ans))\r\n del ans[-1]\r\n print(*an)\r\n i+=1\r\n\r\n\r\nif __name__ == '__main__':\r\n main()", "import math\r\n\r\ndef solve():\r\n\r\n\tn = int(input())\r\n\ta = list(map(int, input().split()))\r\n\r\n\tvisited = [False for _ in range(n+1)]\r\n\tlargest = n\r\n\r\n\tfor i in range(n):\r\n\t\tvisited[a[i]] = True\r\n\r\n\t\tif a[i] == largest:\r\n\t\t\tcurr = []\r\n\r\n\t\t\twhile visited[largest] == True:\r\n\t\t\t\tcurr.append(largest)\r\n\t\t\t\tlargest -= 1\r\n\r\n\t\t\tprint(*curr)\r\n\r\n\t\telse:\r\n\t\t\tprint()\r\n\r\nfor _ in range(1):\r\n\tsolve()\r\n", "number = int(input())\r\ndesire = {\r\n 'wanted' : number\r\n}\r\ndef function(x):\r\n if desire['wanted'] == x :\r\n desire['wanted'] -= 1\r\n print(x , \" \", end='')\r\n while f\"{desire['wanted']}\" in desire.keys() :\r\n print(desire['wanted'], \" \", end='')\r\n desire['wanted'] -= 1\r\n elif desire['wanted'] > x :\r\n desire[f\"{x}\"] = 'wait'\r\n print(\"\")\r\narr = list(map(lambda i:function(int(i)), input().split()))", "n = int(input())\r\nS = [int(i) for i in input().split()]\r\nvis = [False]*n\r\nc = n-1\r\nif len(S) == n:\r\n for i in range(n):\r\n vis[S[i]-1] = True\r\n while (vis[c] and c >= 0):\r\n print(c + 1, end=' ')\r\n c -= 1\r\n print('')", "\r\n\r\ndef placeSnacks(n, snacks):\r\n \r\n availableSnacks = [None] * n\r\n\r\n for snack in snacks:\r\n availableSnacks[int(snack)-1] = snack\r\n\r\n while availableSnacks[n-1] and n != 0:\r\n print(\"{n}\".format(n=n), end=\" \")\r\n n -= 1\r\n print(\"\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n n = int(input().strip())\r\n snacks = input().strip().split()\r\n\r\n placeSnacks(n, snacks)", "from queue import PriorityQueue as PQ\nn, = map(int, input().split())\nA = list(map(int, input().split()))\nhi = n\nq = PQ()\nfor a in A:\n q.put(-a)\n ans = []\n while not q.empty() and -q.queue[0] == hi:\n ans.append(-q.get())\n hi -= 1\n print(*ans)\n", "n = int(input())\r\nsnacks = list(map(int,input().split()))\r\ns = set()\r\nfor i in range(len(snacks)):\r\n s.add(snacks[i])\r\n while n in s:\r\n print(n, end=' ')\r\n n -= 1\r\n print()\r\n", "n = input()\r\nsnacks = input().split()\r\ntargetmax = int(n)\r\nbase = [0] * (int(n)+1)\r\nfor i in snacks:\r\n\tk = int(i)\r\n\tbase[k] = 1\r\n\tif int(i) == targetmax:\r\n\t\twhile base[targetmax] == 1:\r\n\t\t\tprint(targetmax, end = ' ')\r\n\t\t\ttargetmax -=1\r\n\t\tprint()\r\n\telse:\r\n\t\tprint()", "n = int(input())\r\narr = list(map(int, input().split()))\r\nout = [0 for i in range(n)]\r\nmax = n\r\nfor i in arr:\r\n out[i-1] = i\r\n stri = \"\"\r\n if i == max:\r\n\r\n while out and out[-1] != 0:\r\n stri += str(out.pop()) + \" \"\r\n max -= 1\r\n stri = stri[:-1]\r\n print(stri)\r\n", "n = int(input())\r\nl = list(map(int,input().split()))\r\ns = set()\r\nfor d in l:\r\n s.add(d)\r\n if n in s:\r\n print(f'{n}',end=\" \")\r\n n -= 1\r\n while n in s:\r\n print(n,end=\" \")\r\n n -= 1\r\n print()\r\n else:\r\n print()", "n = int(input())\nd = [False] * (n + 1)\nv = list(map(int, input().split()))\n\nnxt = n\nfor i in v:\n d[i] = True\n if i == nxt:\n while d[nxt]:\n print(nxt, end=' ')\n nxt -= 1\n print()\n else:\n print()\n", "n = int(input())\nlst = [int(i) for i in input().split()]\nlst2 = [0]*n\nfor i in lst:\n lst2[i-1] = 1\n while ( n >= 1 and lst2[n-1] == 1):\n print(n, end = \" \")\n n-=1\n print(\"\")\n\t\t \t \t \t\t\t \t\t \t\t \t \t\t", "t = int(input())\r\ns=[False]*t\r\narr=list(map(int,input().split()))\r\nfor i in arr :\r\n s[i-1]=True\r\n if t == i :\r\n print(t,end=' ')\r\n t-=1\r\n while t>0 and s[t-1] :\r\n print(t,end=' ')\r\n t-=1\r\n print()\r\n\r\n \r\n\r\n", "def f(n,l):\r\n y=0\r\n lf=[]\r\n for i in range(-1,-n-1,-1):\r\n l1=[]\r\n if l[i]>y:\r\n for j in range(l[i],y,-1):\r\n l1.append(str(j))\r\n y=l[i]\r\n l1=' '.join(l1)\r\n lf.append(l1)\r\n l1=[]\r\n else:\r\n lf.append(1)\r\n\r\n lf.reverse()\r\n for k in lf:\r\n if k==1:\r\n print()\r\n else:\r\n print(k)\r\n\r\n\r\n\r\n\r\n\r\n\r\nn=int(input())\r\ninp1 = list(map(int, input().split(' ')))\r\nf(n,inp1)", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nmarked = [None] + [False for i in range(n)]\r\nj = n\r\nfor i in range(n - 1):\r\n marked[arr[i]] = True\r\n if arr[i] == j:\r\n k = j\r\n while marked[k] and k > 0:\r\n print(k, end=\" \")\r\n k -= 1\r\n j = k\r\n print()\r\n else:\r\n print()\r\n\r\nfor i in range(j, 0, -1):\r\n print(i, end=\" \")\r\n", "n=int(input())\r\nnext=n\r\nsnacks={}\r\nfor i in list(map(int,input().split())):\r\n snacks[i]=False\r\n\r\nfor i in snacks.keys():\r\n snacks[i]=True\r\n while next!=0 and snacks[next]==True:\r\n print(next,end=' ')\r\n next-=1\r\n print('')", "n = int(input())\r\nday_of_snack = (n+1)*[0]\r\nsnack_sizes = list(map(int,input().split()))\r\nfor day in range(n):\r\n\tday_of_snack[snack_sizes[day]] = day+1\r\nday = int(1)\r\ncur = int(n)\r\nwhile day <= n and cur > 0:\r\n\tif day_of_snack[cur] <= day:\r\n\t\tprint(cur,end=\" \")\r\n\t\tcur-=1\r\n\t\tcontinue\r\n\tprint()\r\n\tday+=1\r\nprint()", "def SnackTower():\r\n n = int(input())\r\n snacks = list(map(int, input().split()))\r\n available = set()\r\n largest = n\r\n\r\n for snack in snacks:\r\n available.add(snack)\r\n while largest in available:\r\n print(largest, end=\" \")\r\n largest -= 1\r\n print()\r\n\r\nSnackTower()\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\narr1 = [0 for i in range(n)]\r\nfor i in range(n):\r\n arr1[arr[i]-1] = i+1\r\narr1.reverse()\r\narr2 = [i for i in range(n,0,-1)]\r\nfor i in range(1, n+1):\r\n while arr1 and arr1[0] <= i:\r\n if i == n and len(arr1) == 1:\r\n arr1.pop(0)\r\n print(arr2.pop(0))\r\n else:\r\n arr1.pop(0)\r\n print(arr2.pop(0), end=' ')\r\n if i != n:\r\n print()", "n=int(input())\r\na=list(map(int,input().split()))\r\nst=set()\r\nv=n\r\nfor i in range(n):\r\n st.add(a[i])\r\n while len(st)>0 and v in st:\r\n print(v,end=\" \")\r\n v-=1\r\n print()", "n = int(input())\r\n\r\narr = list(map(int, input().split()))\r\ntmp = [False for i in range(n+1)]\r\n\r\nstart = n\r\nfor s in arr:\r\n tmp[s] = True\r\n if tmp[start] == False:\r\n print(\"\")\r\n else:\r\n while tmp[start]:\r\n print(start, end=\" \")\r\n start -= 1\r\n print()\r\n", "import heapq\n\nn_snacks = int(input())\nsnacks = [int(x) for x in input().split(' ')]\n\nfallen_snacks_heap = list()\ntop_snack = n_snacks\nfor i in range(n_snacks):\n heapq.heappush(fallen_snacks_heap, -snacks[i])\n snacks_to_put_today = list()\n while len(fallen_snacks_heap) > 0 and -fallen_snacks_heap[0] == top_snack:\n top_snack -= 1\n snacks_to_put_today.append(-heapq.heappop(fallen_snacks_heap))\n print(' '.join(str(x) for x in snacks_to_put_today))\n\n \t \t \t \t \t \t\t\t \t \t \t \t", "n = int(input())\nvalues = [int(x) for x in input().split()]\n\nwaiting = n\noccurs = [0] * (n+1)\nfor i in range(n):\n v = values[i]\n occurs[v] = 1\n while occurs[waiting]:\n print(waiting, end=' ')\n waiting -= 1\n print()\n", "import bisect\nimport sys\n# sys.setrecursionlimit(2000000)\n\n\ndef rl():\n return sys.stdin.readline().strip()\n\n\nif __name__ == \"__main__\":\n n = int(rl())\n nums = list(map(int, rl().split()))\n avail = []\n looking = n\n for i in range(n):\n bisect.insort(avail, nums[i])\n r = []\n while avail and avail[-1] == looking:\n r.append(str(looking))\n looking -= 1\n del avail[-1]\n print(' '.join(r))\n\n\n\n\n\n\n\n", "def solution():\n n = int(input())\n sizes = map(int, input().split())\n sizes = list(sizes)\n\n maxi = -float('inf')\n for e in sizes:\n if e > maxi:\n maxi = e\n\n d = {}\n count = 0\n for i in range(len(sizes)):\n if sizes[i] == maxi - count:\n print(str(sizes[i]), end=\"\")\n count += 1\n\n while count < maxi:\n if maxi - count in d:\n print(\" \" + str(sizes[d[maxi - count]]), end=\"\")\n count += 1\n else:\n break\n print('\\n', end=\"\")\n else:\n d[sizes[i]] = i\n print(' ')\n\n\nsolution()\n", "n=int(input())\nsnacks=list(map(int,input().split()))\nhas=[False]*(n+1)\nnext=n\nfor i in snacks:\n has[i]=True\n while next>0 and has[next]==True:\n print(next,end=\" \")\n next-=1\n print()\n \n", "n = int(input())\nlst = [int(i) for i in input().split()]\nsrc = [-1 for _ in range(n + 1)]\nneed = n\nfor i in lst:\n\tanswer = ''\n\tsrc[i] = i\n\tif src[need] == need:\n\t\twhile src[need] == need:\n\t\t\tif answer == '':\n\t\t\t\tanswer += str(need)\n\t\t\telse:\n\t\t\t\tanswer += ' '+ str(need)\n\t\t\tneed -= 1\n\t\tprint(answer)\n\telse:\n\t\tprint()\n", "n = int(input())\r\narr = [int(x) for x in input().split()]\r\ns= set()\r\nitem = n\r\nfor i in range(n):\r\n if arr[i] == item:\r\n s.add(arr[i])\r\n lis = []\r\n flag = 1\r\n while(flag):\r\n if item in s:\r\n lis.append(item)\r\n s.remove(item)\r\n item -= 1\r\n else:\r\n flag = 0\r\n print(*lis) \r\n else:\r\n print()\r\n s.add(arr[i]) \r\n\r\n # lis.append(arr[i])\r\n # lis.reverse()\r\n # print(*lis)\r\n # lis = []\r\n # item = n-i-1\r\n ", "#Q33 Snacktower\r\n\r\nn = int(input())\r\nm = input().split(' ')\r\nlst = set()\r\nk = n\r\nfor i in range(n):\r\n lst.add(int(m[i]))\r\n while(k in lst):\r\n print(k, end=' ')\r\n k -= 1\r\n print('')\r\n", "#!/usr/bin/env python\n\ndays = int(input())\nentry = input()\nsnacks = list(map(int, entry.split(\" \")))\n\nstore = [None] * days\n\nfor i, snack in enumerate(snacks):\n store_position = snack - 1\n if (snack == days):\n print(snack, end = ' ');\n days = days - 1\n while(store[store_position - 1] != None and store_position > -1):\n print(store[store_position - 1], end = \" \")\n store_position = store_position - 1\n days = days - 1\n print(\"\")\n else:\n store[store_position] = snack\n if (snack != snacks[-1]):\n print(\"\")\n\nneed_print = False\nfor i in range(days - 1, 0, -1):\n need_print = True\n print(i, end = ' ')\n\nif (need_print):\n print(\"\")\n\n\t \t \t \t\t \t\t \t \t \t\t \t", "n = int(input())\r\na = list(map(int, input().split()))\r\nb = set()\r\nc = max(a)\r\nfor i in range(n):\r\n b.add(a[i])\r\n while c in b:\r\n print(c, end=' ')\r\n c -= 1\r\n print()\r\n", "\r\nn = int(input())\r\narr = list(map(int,input().split(' ')))\r\n\r\nmap = [0] * n\r\n\r\nfor x in arr:\r\n \r\n if(n == x):\r\n print(x,end=' ')\r\n n-=1\r\n i = x-2\r\n while(True):\r\n if(i < 0):\r\n break\r\n if(map[i]):\r\n print(i+1,end=' ')\r\n i -=1\r\n n-=1\r\n else:\r\n print()\r\n break\r\n continue\r\n map[x-1] = 1\r\n print()\r\n\r\n\r\n\r\n\r\n \r\n\r\n", "# ██████╗\r\n# ███ ███═█████╗\r\n# ████████╗ ██████╗ ████████╗ ████ █████ ████╗\r\n# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║\r\n# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝\r\n# ██╔═══╝ ██║ ██╗ ██╔═══╝ ███ ███╔══╝\r\n# ████████╗ ╚██████╔╝ ████████╗ ███ ██╔═╝\r\n# ╚═══════╝ ╚═════╝ ╚═══════╝ ███╔══╝\r\n# Legends ╚══╝\r\n\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\nn = int(input())\r\nin_ = list(map(int, input().split()))\r\nsnacks = dict()\r\nday = 1\r\nfor i in range(n):\r\n snacks[in_[i]] = i + 1\r\nfor i in range(n, 0, -1):\r\n if snacks[i] > day:\r\n for j in range(snacks[i] - day):\r\n print()\r\n day += 1\r\n print(i, end=' ')\r\n", "N = int(input())\n\nS = list(map(int, input().split()))\nsorted_S = sorted(S, reverse=True)\n\ns = set()\ncurr_idx = 0\nfor i in range(N):\n if S[i] == sorted_S[curr_idx]:\n print(S[i], end=\" \")\n curr_idx += 1\n while curr_idx < N:\n if sorted_S[curr_idx] in s:\n print(sorted_S[curr_idx], end=\" \")\n else:\n print()\n break\n curr_idx += 1\n else:\n s.add(S[i])\n print()\n\n\n\n\n\n\n\n", "n = int(input())\r\nlst = list(map(int,input().split()))\r\ns = max(lst)\r\nland = [0]*n\r\nfor i in range(len(lst)):\r\n land[lst[i]-1] = 1\r\n if land[s-1] == 1:\r\n while land[s-1] == 1 and s>0:\r\n print(s,end=' ')\r\n s-=1\r\n print()\r\n else:\r\n print()\r\n", "# https://codeforces.com/problemset/problem/767/A\r\nn = int(input())\r\narr = list(map(int,input().split()))\r\nlistt = [0]*n\r\nnext = 0\r\nexpected = n\r\nfor i in range(len(arr)):\r\n flag = 0\r\n listt[n-arr[i]] = arr[i]\r\n # print(listt,expected)\r\n if listt[next]==expected:\r\n prevnext = next\r\n for j in range(prevnext,n):\r\n if listt[j]==0:\r\n flag = 1\r\n next = j\r\n break\r\n if flag==0:\r\n print(*listt[prevnext:])\r\n else:\r\n print(*listt[prevnext:next])\r\n expected = listt[next-1]-1\r\n else:\r\n print()\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "def main():\r\n n = int(input())\r\n arr = list(map(int, input().split()))\r\n\r\n current_pointer = n\r\n current_arr = []\r\n reserve_set = set()\r\n for element in arr:\r\n if element == current_pointer:\r\n temp_arr = [element]\r\n current_pointer -= 1\r\n while current_pointer != 0:\r\n if current_pointer in reserve_set:\r\n temp_arr.append(current_pointer)\r\n current_pointer -= 1\r\n else:\r\n break\r\n current_arr.append(temp_arr)\r\n else:\r\n reserve_set.add(element)\r\n current_arr.append([])\r\n \r\n for floor in current_arr:\r\n print(*floor)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "n = int(input())\r\nsnacks = list(map(int, input().split()))\r\nsnacktower = [0] * n\r\nnext_snack = n\r\n\r\nfor snack in snacks:\r\n snacktower[snack - 1] = snack\r\n while next_snack > 0 and snacktower[next_snack - 1] != 0:\r\n print(snacktower[next_snack - 1], end=' ')\r\n next_snack -= 1\r\n print()\r\n", "def li():\r\n return list(map(int,input().split()))\r\ndef gi(n):\r\n return [list(map(int,input().split())) for _ in range(n)]\r\n\r\n# File input\r\n\r\n# import sys\r\n# sys.stdin = open('user.txt','r')\r\n\r\nn = int(input())\r\nl = li()\r\nfrom collections import defaultdict\r\nmp = defaultdict(int)\r\nx = n\r\nfor i in l:\r\n mp[i] = 1\r\n while mp[x]:\r\n print(x,end=' ')\r\n x -= 1\r\n print()\r\n", "n=int(input())\r\nq={\"\"}\r\nfor i in map(int,input().split()):\r\n\tq.add(i)\r\n\twhile n in q:\r\n\t\tprint(n,end=' ')\r\n\t\tn-=1\r\n\tprint()", "\r\nn=int(input())\r\n\r\nl=list(map(int,input().split()))\r\n\r\n\r\nt=n\r\ni=0\r\nk= {}\r\nwhile i<n:\r\n k[l[i]]=l[i]\r\n while t>0:\r\n if t in k:\r\n print(k[t],end=\" \")\r\n t = t - 1\r\n\r\n else:\r\n print()\r\n break\r\n\r\n i=i+1\r\n\r\n\r\n", "# n = int(input())\n# nextSnack = n\n# pending = [] \n# pendingDone = False\n# snacks = list(map(int, input().split()))\n# for i in range(0, n):\n# if snacks[i] == nextSnack:\n# print(snacks[i], end=' ')\n# nextSnack -= 1\n# while not pendingDone:\n# if nextSnack in pending:\n# print(pending.pop(pending.index(nextSnack)), end=' ')\n# nextSnack -= 1\n# else:\n# pendingDone = True\n# print('')\n# else:\n# pending.append(snacks[i])\n# print('')\n# pendingDone = False\n\nn = int(input())\nnextSnack = n\npending = {} \nsnacks = list(map(int, input().split()))\n\n# if i == n-i; print\nfor i in range(0, n):\n if nextSnack == snacks[i]:\n print(snacks[i], end=' ')\n nextSnack -= 1\n while pending.get(nextSnack, 0) != 0:\n print(pending.get(nextSnack), end=' ')\n nextSnack -= 1\n else:\n pending[snacks[i]] = snacks[i]\n print('')\n \n # 1 5 4 2 3\n # \n # 5\n # 4\n # \n # 3 2 1\n", "n=int(input())\r\na=list(map(int, input().split()))\r\ns=[0]*(n+1)\r\nfor i in range(len(a)):\r\n\ts[a[i]]=1\r\n\twhile s[n]:\r\n\t\tprint(n, end=' ')\r\n\t\tn-=1\r\n\telse:\r\n\t\tprint()", "n = int(input())\r\nt = n\r\nl = [0] * (n + 1)\r\na = list(map(int, input().split()))\r\nfor i in a:\r\n if i != t:\r\n l[i] = 1\r\n print()\r\n else:\r\n print(i, end=\" \")\r\n for x in range(t - 1, -1, -1):\r\n if l[x]:\r\n print(x, end=\" \")\r\n l[x] = 0\r\n else:\r\n break\r\n print()\r\n t = x\r\n\r\n\r\n", "from sys import stdin, stdout\r\nn = int(input())\r\nsnacks = list(map(int, stdin.readline().split()))\r\nsize = n\r\nlst = [0] * (n + 1)\r\nfor i in range(n):\r\n lst[snacks[i]] = 1\r\n while lst[size]:\r\n print(size, end=' ')\r\n size -= 1\r\n stdout.write('\\n')\r\n", "n = int(input())\r\ndays = map(int, input().split())\r\neach = set()\r\n \r\nfor i in days:\r\n each.add(i)\r\n while n in each:\r\n print(n, end=' ')\r\n n -= 1\r\n print()", "n=int(input())\r\n#1689b\r\n#1702c\r\n#767a\r\na=list(map(int,input().split()))\r\nk=sorted(list(set(a)))[::-1]\r\nm=[0]*n\r\nfor i in range(n):\r\n m[a[i]-1]+=1\r\ncur=0\r\nz=[0]*n\r\nfor i in range(n):\r\n m[a[i]-1]-=1\r\n z[a[i]-1]+=1\r\n t=[]\r\n while cur<n and m[k[cur]-1]==0:\r\n t+=[k[cur]*z[k[cur]-1]]\r\n z[k[cur]-1]=0\r\n cur+=1\r\n print(*t)", "n = int(input())\r\narr = [int(x) for x in input().split()]\r\ndic = set()\r\ncurr_max = n\r\nfor a in arr:\r\n dic.add(a)\r\n while curr_max in dic:\r\n print(curr_max, end=' ')\r\n curr_max -= 1\r\n print()\r\n ", "n = int(input())\narr = list(map(int,input().split()))\ninds = [0]*n\nfor i in range(n):\n inds[arr[i]-1] = i\ntop = n-1\nfor i in range(n):\n op = []\n while inds[top] <=i :\n op+=[str(top+1)]\n top-=1\n if top==-1:\n break\n print(' '.join(op))\n\n\t\t \t\t \t \t\t\t\t\t \t \t \t", "import sys,math,bisect\r\nn=int(sys.stdin.readline())\r\narr=list(map(int,sys.stdin.readline().split()))\r\nout=\"\"\r\nans={\"\"}\r\ncount=n\r\nfor i in arr:\r\n ans.add(i)\r\n while count in ans:\r\n print(count,end=\" \")\r\n count-=1\r\n print()\r\n", "from sys import stdin\r\n\r\nn = int(stdin.readline().rstrip())\r\nl = list(map(int,stdin.readline().split()))\r\n\r\nst = set()\r\nma = n\r\nfor i in range(n):\r\n\tst.add(l[i])\r\n\tif l[i]==ma:\r\n\t\twhile len(st)!=0 and (ma in st):\r\n\t\t\tprint(str(ma)+\" \",end=\"\")\r\n\t\t\tst.remove(ma)\r\n\t\t\tma-=1\r\n\tif i!=n-1:\r\n\t\tprint()\r\n", "for _ in range(1):\r\n n = int(input())\r\n snacks = list(map(int, input().split()))\r\n snack_size = n\r\n visited = set()\r\n i = 0\r\n while i<n:\r\n if snacks[i] != snack_size:\r\n visited.add(snacks[i])\r\n print()\r\n else:\r\n visited.add(snacks[i])\r\n print(snacks[i], end=\" \")\r\n previous_snack = snack_size - 1\r\n while previous_snack in visited:\r\n print(previous_snack, end=\" \")\r\n visited.remove(previous_snack)\r\n snack_size -= 1\r\n previous_snack -= 1\r\n print()\r\n snack_size -= 1\r\n i += 1 ", "N = int(input())\r\nArr = [int(_) for _ in input().split()]\r\ndic = {}\r\nfor i in range(N):\r\n dic[Arr[i]] = i#save acc to there indexes\r\ncurr_i = -1\r\nmain_index = 0\r\nfor j in range(N, 0, -1):\r\n k = dic[j]\r\n if k>curr_i:\r\n curr_i = k\r\n print(\"\\n\"*(k - main_index),end = '')\r\n print(j, end=' ')\r\n main_index = k\r\n elif k<curr_i:\r\n print(j, end=' ')\r\n\r\n\r\n", "n = int(input())\r\nx = n\r\nf = [0] * (100005)\r\nsnake=input()\r\nsnaket=snake.split()\r\nsnaket = list(map(int, snaket))\r\nfor i in range(n):\r\n f[snaket[i]] = 1\r\n while f[x]:\r\n print(x, end=\" \")\r\n x -= 1\r\n print()\r\n", "n = int(input())\nsnacks = input() \nsnacks = snacks.split(' ')\nsnacks = [int(x) for x in snacks]\nmaxsnack = n\nsomeset = {}\n\n\nfor snack in snacks:\n someset[snack] = 0\n\nfor snack in snacks:\n if maxsnack == 0:\n break\n if snack == maxsnack:\n print(maxsnack,end='')\n maxsnack -= 1\n if maxsnack == 0:\n break\n while someset[maxsnack] == 1:\n print(' ',maxsnack,end='')\n someset[snack] = 0\n maxsnack -= 1\n if maxsnack == 0:\n break\n print()\n else:\n someset[snack] = 1\n print(' ')\n \t \t \t \t\t\t\t\t\t\t \t\t \t \t\t \t \t", "num = int(input())\r\nwaiting = list(map(int,input().split()))\r\nstacked = []\r\nss = set()\r\nhaha = num\r\nx = \"\"\r\nfor i , x in enumerate(waiting):\r\n ss.add(x)\r\n if waiting[i] != haha:\r\n print(\"\")\r\n if waiting[i]==haha:\r\n while haha in ss:\r\n stacked.append(haha)\r\n haha -=1\r\n print(' '.join(map(str, stacked)))\r\n stacked.clear()", "n=int(input())\na=list(map(int,input().split()))\nt=n\nfor i in range(n):\n a[abs(a[i])-1]=-1*(a[abs(a[i])-1])\n if(abs(a[i])==t):\n print(t,end=\" \")\n t=t-1\n for j in range(t-1,-1,-1):\n if(a[j]<0):\n print(t,end=\" \")\n t=t-1\n else:\n print()\n break\n else:\n print()\n \n \n \n\t \t\t\t\t\t \t \t \t \t\t", "import sys\r\nn = int(input())\r\na = list(map(int, input().split()))\r\nb = list(reversed(sorted(a)))\r\nhas = set()\r\nl = 0\r\nfor i in range(n):\r\n if a[i] == b[l]:\r\n has.add(a[i])\r\n while l < n and b[l] in has :\r\n print(b[l], end = ' ')\r\n l += 1\r\n print()\r\n else:\r\n has.add(a[i])\r\n print()", "size=int(input())\r\nnumbers=input().split(\" \")\r\n\r\nstorage=[0]*size\r\nout=\"\"\r\ncounter=size\r\nfor item in numbers:\r\n if int(item)==counter :\r\n out+=item+\" \"\r\n while storage[counter - 1] != 0:\r\n out += str(storage[counter - 1]) + \" \"\r\n counter -= 1\r\n print(out)\r\n out=\"\"\r\n counter -= 1\r\n\r\n\r\n else:\r\n storage[int(item)]=int(item)\r\n print(\"\")\r\n", "n = int(input())\nsnacks = [int(i) for i in input().split()]\n\npos = n - 1\nmaior = n\npulou = True\n\n\ncontrole = [0]*n\n\ndef verifica():\n global pulou\n global pos\n for j in range(pos, -1, -1):\n if controle[j] == 1:\n print(j + 1, end=\" \")\n pos -= 1\n else:\n if not pulou:\n print()\n print()\n pulou = True\n else:\n print()\n return\n\n\nfor i in range(len(snacks)):\n controle[snacks[i] - 1] = 1\n verifica()\n\nprint()\n \t\t \t \t\t\t \t \t\t\t \t\t \t\t \t", "n = int(input())\na = map(int,input().split())\ns = set()\nfor i in a:\n s.add(i)\n while n in s:\n print(n,end=\" \")\n n -= 1\n print()\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nhas=[]\r\nfor i in range(n):\r\n has.append(0)\r\nnext=n\r\nfor i in a:\r\n if(i==next):\r\n print(i,end=\" \")\r\n next-=1\r\n while has[next-1]==1:\r\n print(next,end=\" \")\r\n next-=1\r\n print()\r\n else:\r\n print()\r\n has[i-1]=1", "def Snack(arr,n):\r\n arr_vistado= []\r\n for i in range(n+1):\r\n arr_vistado.append(False)\r\n #print(arr_vistado)\r\n c=n\r\n for i in range(n):\r\n arr_vistado[arr[i]]=True\r\n while arr_vistado[c] and c>0:\r\n print(str(c),end=\" \")\r\n c-=1\r\n print(\" \")\r\n #print(arr_vistado)\r\n return\r\n\r\nn = int(input())\r\narr1 = list(map(int, input().strip().split()))\r\nSnack(arr1,n)", "from collections import deque\r\nn = int(input())\r\nsnacks = list(map(int, input().split()))\r\nnext = n\r\nhas = [False for _ in range(n+1)]\r\nfor i in range(n):\r\n has[snacks[i]] = True\r\n while has[next] and next > 0:\r\n print(next, end=\" \")\r\n next -= 1\r\n print()\r\n", "n = int(input())\r\nnum = input()\r\nnum = list(int(x) for x in num.split(\" \"))\r\nvisited = [1] * (n+1)\r\ni = 0\r\nwhile n > 0 and i < len(num):\r\n visited[num[i]] = 0\r\n while visited[n] == 0:\r\n print(n, end=\" \"); n -= 1\r\n if n != 0:\r\n print(\" \")\r\n i += 1", "N, X = int(input()), list(map(int, input().split()))\r\nCheck, Index = [False] * N, N\r\nfor i in range(N):\r\n Check[X[i] - 1] = True\r\n while Index > 0 and Check[Index - 1]: print(Index, end=\" \");Index -= 1\r\n print()\r\n\r\n# Come together for getting better !!!!\r\n", "a = int(input())\r\ns = list(map(int, input().split()))\r\nd = set()\r\nh = a\r\nfor i in range(a):\r\n d.add(s[i])\r\n while h in d:\r\n print(h, end= ' ')\r\n h -= 1\r\n print()", "n = int(input())\r\nt = list(map(int, input().split()))\r\n\r\np = n-1\r\nused = [False]*n\r\n\r\nfor x in range(n):\r\n used[t[x]-1] = True\r\n\r\n while p >= 0 and used[p]: \r\n print(p+1, end=' ')\r\n p -= 1\r\n print('')\r\n \r\n ", "n = int(input())\r\nnums = [int(i) for i in input().split(\" \")]\r\nfound = False\r\nhas_value = [0]*n\r\nlast_output = n+1\r\nfor num in nums:\r\n idx = num -1\r\n has_value[idx]= 1\r\n if num == last_output-1:\r\n string =[] \r\n while has_value[idx]:\r\n string.append(str(idx + 1))\r\n has_value[idx] = 0\r\n idx -=1\r\n last_output = idx+2\r\n print(\" \".join(string))\r\n\r\n # now we can print\r\n else:\r\n print(\"\")\r\n\r\n\r\n\r\n", "from heapq import *\n\n\ndef lets_do_it():\n n = int(input())\n snacks = [int(a) for a in input().split(' ')]\n heap = []\n # heappush(heap, -snacks[0])\n tos = -n\n\n # for i in range(1, n):\n for snack in snacks:\n heappush(heap, -snack)\n # if tos != heap[0]:\n # print(-heap[0], end=\" \")\n # tos += 1\n while heap and tos == heap[0]:\n print(-1 * heappop(heap), end=\" \")\n tos += 1\n print()\n\n # else:\n # print()\n\n\ndef main():\n # test_cases = int(input())\n test_cases = 1\n while test_cases:\n lets_do_it()\n test_cases -= 1\n\n\nmain()\n", "n = int(input())\ntower = list(map(int, input().split()))\n\nfallen = [False for i in range(n)]\n\ntop = n\nfor i in range(n):\n place = []\n if tower[i] != top: \n fallen[tower[i]-1] = True\n print()\n else:\n print(top, end = \" \")\n top -= 1\n loop = 1\n while loop:\n if fallen[top-1]:\n print(top, end = \" \")\n fallen[top-1] = False\n top -= 1\n else:\n loop = 0\n print()\n place = []\n\n\t\t \t\t\t\t \t \t\t \t\t \t\t\t \t\t\t", "# cook your dish here\r\nn=int(input())\r\nli = list(map(int, input().split()))\r\nbool = [0 for _ in range(n+1)]\r\ncurr = n\r\nfor i in range(n):\r\n bool[li[i]]=True\r\n while(bool[curr]):\r\n print(curr, end=\" \"); curr-=1\r\n print()\r\n", "n = input()\nsnacks = list(map(int, input().split()))\nkept = []\nlargest = max(snacks)\n\nfor snack in snacks:\n if snack == largest:\n print(snack, end=\"\")\n largest -= 1\n for i in range(largest, -1, -1):\n if i in kept:\n print(\" \", i, sep=\"\", end=\"\")\n largest -= 1\n else:\n print()\n break\n else:\n kept.append(snack)\n print()", "n = int(input())\r\nsizes = list(map(int, input().split()))\r\nbooly = [0 for i in range(n+1)]\r\nmax = n\r\nfor i in range(n):\r\n booly[sizes[i]]=1\r\n while booly[max]:\r\n print(max, end=' ')\r\n max -= 1\r\n print('')", "n = int(input())\r\na = list(map(int,input().split()))\r\n\r\nz = set()\r\n\r\nfor i in a:\r\n\tz.add(i)\r\n\twhile n in z:\r\n\t\tprint(n, end = ' ')\r\n\t\tn -= 1\r\n\tprint(' ')", "\nn = int(input().strip())\n\nl = list(enumerate([int(a) for a in input().strip().split()]))\n\nls = sorted(l, key = lambda x: x[1], reverse = True) #happens in O(n lg n)\n\nprev = 0\nfor lsa in ls:\n if lsa[0] >= prev:\n for _ in range(prev, lsa[0]):\n print() #blank line\n\n print(\"%d\" % (lsa[1]), end = '')\n prev = lsa[0]\n else:\n print(\" %d\" % (lsa[1]), end = '')\n", "n = int(input())\ns = [int(i) for i in input().split()]\ntemp = n\nnew_list = [0] * (n + 1)\nfor i in s:\n new_list[i] = 1\n while new_list[n]:\n print(n, end=' ')\n n -= 1\n print()\n\n\t\t\t\t \t\t \t\t \t \t \t \t\t\t\t\t\t \t\t", "n = int(input())\r\narr = list(map(int, input().split()))\r\nst = [False for i in range(n+1)]\r\nindex = n\r\nfor i in range(len(arr)):\r\n st[arr[i]] = True\r\n while st[index] and index > 0:\r\n print(index, end=\" \")\r\n index -= 1\r\n print()\r\n\r\n", "n = int(input())\r\nk=n\r\nd=dict()\r\nfor i in input().split():\r\n x=int(i)\r\n d[x]=True\r\n while k in d.keys():\r\n print(k,end=' ')\r\n k-=1\r\n print(\"\")\r\n", "arr = [False] * 100001\r\ncurrent = 0\r\n\r\ndef print_sequence(x, current2):\r\n global current, arr\r\n \r\n if x == current2:\r\n i = current2\r\n while i > 0:\r\n if arr[i]:\r\n print(i, end=\" \")\r\n arr[i] = False\r\n current = i - 1\r\n i -= 1\r\n else:\r\n break\r\nn = int(input())\r\nsnacks = list(map(int,input().split()))\r\ncurrent = n\r\nfor i in range(n):\r\n x = snacks[i]\r\n arr[x] = True\r\n print_sequence(x, current)\r\n print()", "n= int(input())\r\nl=map(int,input().split())\r\nb=[0]*(n+2)\r\nfor i in l:\r\n b[i]=1\r\n while b[n]:\r\n print (n , end =' ')\r\n n-=1\r\n print ()\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\n\r\nneed = n\r\nthere = dict()\r\ntotal = 0\r\n\r\nfor j in arr:\r\n there[j] = True\r\n if j != need:\r\n print()\r\n else:\r\n toprint = []\r\n count = j\r\n while count in there:\r\n toprint.append(count)\r\n count -= 1\r\n need = count\r\n print(*toprint)\r\n total += len(toprint)\r\n", "n = int(input())\r\nsnacks = list(map(int,input().split(' ')))\r\nfallen = [0]*(n+1)\r\ncurrent = n\r\nfor i in range(0,n):\r\n fallen[snacks[i]] = 1\r\n #print('here',fallen)\r\n if(fallen[current] == 1):\r\n while(fallen[current] != 0):\r\n print(current,'',end='')\r\n current -= 1\r\n print()\r\n else: print()\r\n ", "n = int(input())\r\nl1 = [0]*(n+1)\r\nl2 = list(map(int,input().split()))\r\nl2.insert(0,0)\r\nnext1 = n\r\nfor i in range(1,n+1):\r\n x = l2[i]\r\n l1[x] = 1\r\n \r\n while l1[next1] == 1:\r\n print(next1,end = ' ')\r\n next1-=1\r\n \r\n print('')", "n = int(input())\r\n\r\nl = [int(x) for x in input().split()]\r\nfound = [False]*(n+1)\r\nrn = n\r\n'''\r\nfor i in l:\r\n if i == rn:\r\n found.insert(0, i)\r\n while len(found) != 0 and rn in found:\r\n x = found.pop(found.index(rn))\r\n print(x, end=\" \")\r\n rn -= 1\r\n print(\"\")\r\n\r\n else:\r\n print(\"\")\r\n found.insert(0, i)\r\n'''\r\nc = n\r\n\r\nfor i in l:\r\n found[i] = True\r\n\r\n while found[c] and c > 0:\r\n print(c, end=\" \")\r\n c -= 1\r\n print()\r\n", "n = int(input())\r\na = list(map(int,input().split()))\r\na.insert(0,0)\r\nb = []\r\nfor i in range(n+1):\r\n\tb.append(False)\r\n\r\nc = n\r\nfor i in range(1,n+1):\r\n\tb[a[i]] = True\r\n\twhile(b[c]):\r\n\t\tprint(c, end=\" \")\r\n\t\tc = c-1\r\n\t\t\r\n\tprint()\r\n\r\n", "n=int(input())\r\nl=map(int, input().split())\r\ns=set()\r\n\r\nfor i in l:\r\n s.add(i)\r\n while n in s:\r\n print(n, end=' ')\r\n n -= 1\r\n print()", "n = int(input())\r\nmass = list(map(int,input().split()))\r\nmass1 = []\r\nfor i in range(n):\r\n mass1.append([i, mass[i]])\r\nmass1.sort(key = lambda x: x[1])\r\nmass1 = mass1[-1::-1]\r\nitog = [[] for i in range(n)]\r\nind = mass1[0][0]\r\nitog[ind].append(mass1[0][1])\r\nfor i in range(1, n):\r\n if mass1[i][0] < ind:\r\n itog[ind].append(mass1[i][1])\r\n else:\r\n ind = mass1[i][0]\r\n itog[ind].append(mass1[i][1])\r\nfor i in itog:\r\n print(*i)", "n = int(input())\r\nl = list(map(int,input().split()))\r\nvis,need = [False]*n,n\r\nfor i in range(n) :\r\n vis[l[i]-1] = True\r\n if l[i] == need :\r\n for j in range(l[i]-1,-1,-1) :\r\n if not vis[j] :\r\n break\r\n print(j+1,end=' ')\r\n need -= 1\r\n print()\r\n \r\n\r\n\r\n", "from sys import stdin,stdout\r\ninput=stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end)\r\n\r\nn=int(input()) ; arr=list(map(int,input().split())) ; snacks=dict()\r\nfor i in range(n):\r\n snacks[arr[i]]=i+1\r\n\r\nday=1\r\nfor i in range(n,0,-1):\r\n if snacks[i]>day:\r\n for j in range(snacks[i]-day):\r\n print() ; day+=1\r\n print(i,end=\" \")\r\n else:\r\n print(i,end=\" \")\r\n\r\n\r\n\r\n\r\n", "# n snacks at a time\n# sizes are distinct integers 1 -> n\n\nn = int(input())\nnums = list(map(int, input().split(' ')))\n\nused = [False] * (n + 1)\n\nnext_val = n\nfor num in nums:\n used[num] = True\n if num == next_val:\n i = num\n to_print = [str(i)]\n while used[i-1]:\n i -= 1\n to_print.append(str(i))\n next_val = i - 1\n print(\" \".join(to_print))\n else:\n print()\n", "from sys import stdin\r\nfrom collections import defaultdict\r\n\r\nrd = stdin.readline\r\n\r\n\r\nn = int(rd())\r\na = list(map(int, rd().split()))\r\n\r\nout = defaultdict(bool)\r\nnex = n\r\n\r\nfor i in a:\r\n\r\n if i != nex:\r\n out[i] = True\r\n\r\n else:\r\n print(nex, end = ' ')\r\n nex -= 1\r\n \r\n for j in range(i - 1, 0, -1):\r\n if j == nex and out[j]:\r\n print(j, end = ' ')\r\n nex = j - 1\r\n else:\r\n #print(j, 1)\r\n break\r\n print()\r\n \r\n \r\n", "from sys import stdin, stdout\r\nfrom collections import defaultdict\r\nimport heapq\r\ndef get_int(): return int(stdin.readline().strip())\r\ndef get_ints(): return map(int,stdin.readline().strip().split()) \r\ndef get_array(): return list(map(int,stdin.readline().strip().split()))\r\ndef get_string(): return stdin.readline().strip()\r\nINF=1e10\r\n#for _ in range(int(stdin.readline())):\r\n\r\nclass MaxHeap:\r\n def __init__(self):\r\n self.data = []\r\n\r\n def top(self):\r\n return -self.data[0]\r\n\r\n def push(self, val):\r\n heapq.heappush(self.data, -val)\r\n\r\n def pop(self):\r\n return -heapq.heappop(self.data)\r\n \r\n def isempty(self):\r\n if len(self.data) != 0:\r\n return True\r\n return False\r\nn=get_int()\r\nar=get_array()\r\nst=MaxHeap()\r\nmaxh=n\r\nfor i in ar:\r\n st.push(i)\r\n if st.top()==maxh:\r\n while st.isempty()==True and st.top()==maxh:\r\n print(st.pop(),end=\" \")\r\n maxh-=1\r\n print()\r\n else:\r\n print()\r\n\r\n", "n = int(input())\r\ns = [int(x) for x in input().split()]\r\n\r\norder = {}\r\nfor i in range(len(s)):\r\n order[s[i]] = i\r\n\r\nif order[n] != 0:\r\n print('\\n' * (order[n] - 1))\r\nlast = n\r\nfor i in range(n-1):\r\n if order[n-i-1] > order[last]:\r\n print(n-i, '', end='\\n'*(order[n-i-1]-order[last]))\r\n last = n-i-1\r\n else:\r\n print(n-i, end=' ')\r\n \r\nprint('1')", "n = int(input())\r\na = list(map(int, input().split()))\r\nt = [False]*n\r\nt_idx = n-1\r\nfor idx, value in enumerate(a):\r\n t[value-1] = True\r\n cur_res = []\r\n while t[t_idx]:\r\n cur_res.append(t_idx+1)\r\n t_idx -= 1\r\n if t_idx == -1:\r\n break\r\n print(*cur_res)", "size = int(input())\r\nl = list(map(int, input().split()))\r\nmax_val = size\r\nfrequency = [0] * (size + 1)\r\n\r\nfor i in range(size):\r\n num = l[i]\r\n frequency[num] = 1\r\n \r\n while frequency[max_val]:\r\n print(max_val, end=' ')\r\n max_val -= 1\r\n \r\n print()\r\n", "n = int(input())\nx = [int(i) for i in input().split()]\ne = [False] * (n + 1)\ntarget = n\nfor i in x:\n e[i] = True\n if i == target:\n while e[target]:\n print(target, end= ' ')\n target -= 1\n else:\n print()\n else:\n print()\n", "\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n a = list(map(int,input().split()))\r\n l = []\r\n mx = max(a)\r\n m = {}\r\n for i in range(n):\r\n m[a[i]] = 0\r\n for i in range(n):\r\n m[a[i]] = 1\r\n if a[i] == mx:\r\n print(a[i],end=\" \")\r\n mx = a[i] - 1\r\n while mx in m.keys() and m[mx] != 0:\r\n print(mx,end=\" \")\r\n mx = mx - 1\r\n print()\r\n\r\n\r\n", "n = int(input())\r\nseen = set()\r\na = map(int, input().split())\r\nfor i in a:\r\n seen.add(i)\r\n while n in seen:\r\n print(n, end=' ')\r\n n -= 1\r\n print()", "n = int(input())\r\narray = [int(x) for x in input().split()]\r\ncurrent = n\r\nday = 0\r\ncandy = set()\r\nwhile current>0:\r\n candy.add(array[day])\r\n ans = []\r\n # print(candy)\r\n while current in candy:\r\n ans.append(current)\r\n candy.discard(current)\r\n current-=1\r\n for i in ans:\r\n print(i,end=\" \")\r\n print()\r\n day+=1\r\n\r\n\r\n", "n = int(input())\nl = list(map(int,input().split()))\nv = [0]*n\nx = n\nfor i in l:\n v[i-1] = 1\n while x>0 and v[x-1] > 0:\n print(x,end = \" \")\n x-=1\n print() \n", "# http://codeforces.com/problemset/problem/767/A\r\n\r\ntotalNoOfSnacks = int(input())\r\nsnacksSizeListOnIthDay = [int(x) for x in input().split(' ')]\r\n\r\ndictOfPossibleNumbersReceivedStatus = {x: False for x in snacksSizeListOnIthDay}\r\ncurrentMaxSnackSize = totalNoOfSnacks\r\n\r\nfor i in range(totalNoOfSnacks):\r\n dictOfPossibleNumbersReceivedStatus[snacksSizeListOnIthDay[i]] = True\r\n while currentMaxSnackSize > 0 and dictOfPossibleNumbersReceivedStatus[currentMaxSnackSize]:\r\n print(currentMaxSnackSize, end=' ')\r\n currentMaxSnackSize -= 1\r\n print()\r\n", "from collections import defaultdict\r\nn = int(input())\r\narr = list(int(i) for i in input().split())\r\ndc = defaultdict(bool)\r\nfor i in arr: \r\n dc[i] = True\r\n while dc[n] and n:\r\n print(n, end=\" \")\r\n n -= 1\r\n print()\r\n\r\n \r\n", "n = int(input())\r\nsnacks = map(int,input().split())\r\n\r\nmem = {}\r\nfor x in snacks:\r\n ans = []\r\n if x == n:\r\n ans.append(x)\r\n x -= 1\r\n while mem.get(x, -1) != -1:\r\n ans.append(mem[x])\r\n x -= 1\r\n n -= 1\r\n n -= 1\r\n else:\r\n mem[x] = x\r\n print(' '.join(map(str, ans)))\r\n", "n = int(input())\nsnacks = list(map(int,input().split()))\nfallen = [False] * n\nto_put = n\nfor i in range(n):\n fallen[snacks[i]-1] = True\n while fallen[to_put-1] and to_put >= n-i :\n print(to_put,end=\" \")\n to_put-=1\n print()\n", "n = int(input())\r\n\r\ns = list(map(int, input().split()))\r\n\r\nfallen_sneks = [None] * 100000\r\n\r\nfor snek in s:\r\n if snek != n:\r\n fallen_sneks[snek - 1] = snek\r\n print()\r\n else:\r\n fallen_sneks[n - 1] = snek\r\n stak = ''\r\n while fallen_sneks[n - 1] != None and n > 0:\r\n stak += str(n) + \" \" \r\n n -= 1\r\n print(stak.strip())\r\n\r\n", "#!/usr/bin/env python3\nimport sys\ninput = sys.stdin.readline\n\n############ ---- Input Functions, coutery of 'thekushalghosh' ---- ############\n\n\ndef inp():\n return(int(input()))\n\n\ndef inlt():\n return(list(map(int, input().split())))\n\n\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\n\n\ndef invr():\n return(map(int, input().split()))\n\n\nif __name__ == \"__main__\":\n n = inp()\n snacks = inlt()\n flag = [False] * (n + 1)\n for snack in snacks:\n flag[snack] = True\n if snack == n:\n while flag[n]:\n print(n, end=' ')\n n -= 1\n print()\n", "n=int(input())\r\nll=[int(i) for i in input().split()]\r\nkk=[0]*n\r\nif n==1:\r\n print(1)\r\n exit()\r\nfor i in ll:\r\n if i!=n:\r\n kk[i-1]=i\r\n print(\"\")\r\n else:\r\n kk[i-1]=i\r\n for t in range(n-1,-1,-1):\r\n if kk[t]==0:\r\n print(*[int(i) for i in range(n,t+1,-1)])\r\n n=t+1\r\n break\r\n if i==ll[-1]:\r\n print(*[int(i) for i in range(n, 0, -1)])", "n = int(input())\r\nvis = set()\r\na = list(map(int,input().split()))\r\nfor i in range(n):\r\n vis.add(a[i])\r\n while n in vis:\r\n print(n,end = \" \")\r\n n-=1\r\n print()\r\n", "n = int(input())\r\nli = list(map(int, input().split()))\r\ncol = [0 for i in range(n+2)]\r\nt = n\r\nfor i in range(n):\r\n col[li[i]] += 1\r\n while col[t]:\r\n print(t, end=' ')\r\n t -= 1\r\n print('')", "#!/bin/python3\r\nn = int(input())\r\nnums = list(map(int, input().rstrip().split()))\r\nchk = []\r\nindex = n\r\nfor i in range(n):\r\n chk.append(False)\r\n\r\nfor i in range(n):\r\n chk[nums[i]-1] = True\r\n while chk[index-1] and index > 0:\r\n print(index, end=\" \")\r\n index -= 1\r\n print()\r\n", "from sys import stdin\r\ninput=stdin.readline\r\n # return len(arr)-1\r\n\r\n\r\na=input()\r\narr=list(map(int,input().strip().split()))\r\ncmax=len(arr)\r\nstack=[0]*(len(arr)+2)\r\nn=len(arr)\r\nfor i in arr:\r\n stack[i]=1\r\n while stack[n]:\r\n print(n,end=\" \")\r\n n-=1\r\n print(\"\")\r\n", "n = int(input())\r\nsnacks = list(map(int, input().split()))\r\nnext_need = n\r\ngot_elems = [0]*10**5\r\nfor i in range(n):\r\n if(snacks[i]==next_need):\r\n print(snacks[i], end = ' ')\r\n next_need-=1\r\n while(got_elems[next_need-1]):\r\n print(next_need, end=' ')\r\n next_need -= 1\r\n print('')\r\n else:\r\n got_elems[snacks[i]-1] = 1\r\n print('')\r\n ", "n=int(input())\r\ns={\"\"}\r\nfor i in map(int,input().split()):\r\n s.add(i)\r\n while n in s:\r\n print(n,end=' ')\r\n n-=1\r\n print() ", "n,s=int(input()),{\"\"}\r\nfor i in map(int,input().split()):\r\n\ts.add(i)\r\n\twhile n in s:print(n,end=' ');n-=1\r\n\tprint()", "def output(n_snacks, snacks):\r\n visited_list = [0]*(n_snacks+1)\r\n max = n_snacks\r\n to_print = []\r\n # filled_stack = []\r\n # empty_stack = []\r\n all_stack = []\r\n for i in range(0, n_snacks):\r\n if snacks[i] == max:\r\n to_print.append(max)\r\n max -= 1\r\n while visited_list[max+1] >= 1:\r\n to_print.append(max)\r\n # print(visited_list)\r\n max -= 1\r\n all_stack.append(' '.join(list(map(str, to_print))))\r\n all_stack.append('\\n')\r\n to_print = []\r\n else:\r\n visited_list[snacks[i]+1] += 1\r\n all_stack.append('\\n')\r\n return all_stack\r\nif __name__ == '__main__':\r\n n_snacks = int(input())\r\n snacks = list(map(int, [x for x in input().split(\" \")]))\r\n stack_output = output(n_snacks, snacks)\r\n # print(stack_output)\r\n print(''.join(stack_output))", "n = int(input())\nsnack_sizes = [int(c) for c in input().split(\" \")]\nfelt_snack_list = [0] * (n)\nwaiting_for = n\n\nfor snack in snack_sizes:\n\ti = snack - 1\n\tfelt_snack_list[i] = snack\n\tif (snack == waiting_for):\n\t\tj = i\n\t\ttower_built = []\n\n\t\twhile (j >= 0 and felt_snack_list[j]):\n\t\t\ttower_built.append(felt_snack_list[j])\n\t\t\tj -= 1\n\n\t\tprint(*tower_built)\n\n\t\twaiting_for = j + 1\n\telse:\n\t\tprint()\n \t \t \t\t\t\t\t \t \t\t \t \t\t\t\t\t\t\t\t\t", "#!/usr/bin/python3\n\nimport sys\nimport argparse\nimport json\n\ndef main():\n num = sys.stdin.readline().rstrip()\n snacks = [int(x) for x in sys.stdin.readline().rstrip().split(\" \")]\n\n s_snacks = sorted(snacks, reverse=True)\n seen_snacks = set()\n current_index = 0\n\n for snack in snacks:\n seen_snacks.add(snack)\n\n if s_snacks[current_index] in seen_snacks:\n removed_snacks = []\n while current_index < len(s_snacks) and s_snacks[current_index] in seen_snacks:\n removed_snacks.append(s_snacks[current_index])\n seen_snacks.remove(s_snacks[current_index])\n current_index += 1\n print(' '.join([str(x) for x in removed_snacks]))\n else:\n print(\"\")\n\n\ndef get_tests():\n #tests = [(\"512 4\", \"50\")]\n\n for test in tests:\n print(json.dumps({\"input\": test[0], \"output\": test[1]}))\n\nif __name__ == \"__main__\":\n parser = argparse.ArgumentParser()\n parser.add_argument(\"--get-tests\", action=\"store_true\")\n args = parser.parse_args()\n\n if args.get_tests:\n get_tests()\n else:\n main()\n", "n = int(input())\r\ntarget = n\r\narr = input().split()\r\nvis = [0] * (n + 1)\r\nfor i in range(0, len(arr)):\r\n arr[i] = int(arr[i])\r\n vis[arr[i]] = 1\r\n if target == arr[i]:\r\n j = arr[i]\r\n while vis[j] != 0 and j > 0:\r\n print(j, end=\" \")\r\n j -= 1\r\n\r\n target = j\r\n\r\n print(\" \")\r\n", "n = int(input())\r\nsnacks = [int(i) for i in input().split()]\r\nhas = [False for i in range(n)]\r\nnext_snack = n\r\nfor snack in snacks:\r\n has[snack-1] = True\r\n if snack == next_snack:\r\n while has[next_snack-1] == True and next_snack > 0:\r\n print(next_snack,end = ' ')\r\n next_snack -= 1\r\n print()\r\n else:\r\n print()\r\n", "n = int(input())\r\ninputs = list(map(int,input().split()))\r\nhas = [False] * n \r\ncurrent = n\r\n\r\n\"\"\" Approach 1\r\nfor i in range(n):\r\n if inputs[i] == n-i and temp == 0:\r\n print(n-i)\r\n elif inputs[i] == n-i and temp != 0:\r\n print()\r\n elif inputs[i] != n-i and temp == inputs[i]:\r\n for j in range(temp, n-i-1, -1):\r\n print(j, end=\" \")\r\n print()\r\n temp = 0\r\n elif inputs[i] != n-i and temp == 0:\r\n temp = n-i\r\n print() \"\"\"\r\n \r\nfor i in range(n):\r\n has[inputs[i]-1] = True\r\n while has[current-1] == True and current > 0:\r\n print(current, end = \" \")\r\n current = current - 1\r\n print()", "n = int(input())\nsnacks = list(map(int, input().split(\" \")))\nja_foram = [0]*n\nfalta = n\n\ndef procurar(v, valor):\n retorno = ''\n if v == valor:\n for i in range(valor-1, -1, -1):\n if ja_foram[i] > 0:\n retorno += \"%s \"%(i+1)\n ja_foram[i] = 0\n valor = i\n else:\n break\n print(retorno)\n return valor\n\nfor s in snacks:\n ja_foram[s-1]=1\n falta = procurar(s, falta)\n \t \t\t\t \t\t \t \t\t\t\t\t\t\t\t\t \t \t", "t =int(input())\r\nn = list(map(int, input().split()))\r\nmx = 0\r\nd = {}\r\nfor i in range(t):\r\n d[n[i]] = i\r\nn.sort(reverse= True)\r\nfor i in range(t):\r\n if mx < d[n[i]]:\r\n print(f\"\\n\"*(d[n[i]]-mx), end = '')\r\n print(n[i], end = ' ')\r\n mx = d[n[i]]\r\n else:\r\n print(n[i], end = ' ')", "def snack():\r\n from sys import stdin\r\n from sys import stdout\r\n w=stdout.write\r\n w=stdout.write\r\n inp=stdin.readline\r\n n=int(inp())\r\n a=[0 for i in range(n+1)]\r\n st=[n+1]\r\n s=list(map(int,inp().split()))\r\n t=1\r\n \r\n i=0\r\n top=0\r\n while(i<n):\r\n ans=[]\r\n temp=st[top]\r\n if(temp==s[i]+1):\r\n # print(s[i])\r\n ans.append(str(s[i]))\r\n st.append(s[i])\r\n t=t+1\r\n top=top+1\r\n while(a[temp-2]==1):\r\n a[temp-2]=0\r\n st.append(temp-2)\r\n t=t+1\r\n ans.append(str(temp-2))\r\n temp=temp-1\r\n top=top+1\r\n else:\r\n a[s[i]]=1\r\n\r\n i=i+1\r\n w(' '.join(ans))\r\n w('\\n')\r\n # ans=ans[:len(ans)-2]\r\n # w(ans.lower())\r\nsnack()", "n = int(input())\r\nlist1 = input().split(' ')\r\nlist2 = [False]*(n+1)\r\ntarget = n\r\nfor i in range(n):\r\n list2[int(list1[i])] = True\r\n str1 = ''\r\n while list2[target] == True:\r\n str1 += str(target) + ' '\r\n target -= 1\r\n print(str1)", "snacks = int(input())\r\nsnacks_order= [int(x) for x in input().split()]\r\nfreq_snacks = [0 for x in range(len(snacks_order)+1)]\r\nmax = snacks\r\nfor i in range(snacks):\r\n freq_snacks[snacks_order[i]] = 1\r\n while(freq_snacks[max]):\r\n print(max , end= \" \")\r\n max-=1\r\n print(\" \")\r\n ", "#siddhanta007\r\nimport sys\r\nfrom bisect import insort\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\na = [int(q) for q in input().split()]\r\ns = [0] * (n + 1)\r\nfor i in range(n):\r\n s[a[i]] = i + 1\r\nm = n\r\nfor i in range(1, n + 1):\r\n while m > 0 and i >= s[m]:\r\n print(m, end = ' ')\r\n m -= 1\r\n print()", "#D - Snacktower\n\nn = int(input())\nk = n\nsnacks = [int(x) for x in input().split()]\npastsnacks = (n+1)*[0]\n\nfor i in range(n):\n\n pastsnacks[snacks[i]] = 1\n\n if snacks[i] != k:\n print()\n\n elif snacks[i] == k:\n\n print(k, end = \"\")\n k -= 1\n\n while pastsnacks[k] == 1:\n\n print(\" \", k, end = \"\")\n k -= 1\n\n if i != n:\n print()\n\n\n \n\n\t\t \t\t \t\t \t\t \t\t\t \t\t\t\t\t\t \t \t\t", "\r\nimport heapq as hq\r\n\r\nn=int(input())\r\nl=list(map(int,input().split()))\r\n\r\nq=[]\r\n\r\n\r\nc=n\r\n\r\n\r\n\r\nfor i in range(n):\r\n \r\n hq.heappush(q,-1*l[i])\r\n\r\n \r\n if -1*q[0]==c:\r\n while(q and -1*q[0]==c):\r\n print(-1*hq.heappop(q),end=\" \")\r\n \r\n \r\n c-=1\r\n print()\r\n else:\r\n print()\r\n \r\n \r\n\r\n", "n = int(input())\r\nnext = n\r\nsnacks = [False] * (n+2)\r\norderedSnacks = [0]*(n+2)\r\n\r\norderedSnacks = list(input().split(' '))\r\nfor i in range(0, n):\r\n orderedSnacks[i] = int(orderedSnacks[i])\r\n\r\nfor i in range(1, n+1):\r\n inSnack = orderedSnacks[i-1]\r\n snacks[inSnack] = True\r\n if(inSnack == next):\r\n snacks[next] = False\r\n print(next, ' ', sep='', end='')\r\n next = next - 1\r\n for next in range(next, 0, -1):\r\n if(snacks[next] == True):\r\n print(next, ' ', end='')\r\n next = next - 1\r\n else:\r\n break\r\n print('')", "n = int(input())\nvis = set()\na = list(map(int, input().split(\" \")))\nfor i in range(n):\n vis.add(a[i])\n while n in vis:\n print(n, end=\" \")\n n -= 1\n print()\n", "import sys\nimport heapq\n\ndef main(arr):\n s = sorted(arr, reverse=True)\n max_heap = []\n i = 0\n for e, num in enumerate(arr):\n if num == s[i]:\n # This is the number we want.\n doing = [num]\n i += 1\n while max_heap and -max_heap[0] == s[i]:\n n = heapq.heappop(max_heap)\n doing.append(-n)\n i += 1\n print(\" \".join(str(d) for d in doing))\n else:\n # We can't print this number yet.\n # Push it to the print queue.\n print()\n heapq.heappush(max_heap, -num)\n\nif __name__ == \"__main__\":\n for e, line in enumerate(sys.stdin.readlines()):\n if e == 0:\n continue\n else:\n arr = list(map(int, line.strip().split()))\n\n # Proof by induction that sorting is that\n # same as solving this problem.\n main(arr)\n", "n = int(input())\r\n\r\nlst = list(map(int, input().split()))\r\nt = list(range(1, n+1))\r\n\r\ni, r = 0, n\r\nwhile i<n: \r\n if lst[i] != r:\r\n print()\r\n t[lst[i]-1] = 0\r\n else:\r\n r-=1\r\n print(lst[i], end = ' ')\r\n id = lst[i]-2\r\n \r\n while id>=0:\r\n \r\n if t[id] == 0:\r\n print(id+1, end = ' ')\r\n else:\r\n break\r\n r-=1\r\n id-=1\r\n print()\r\n i+=1", "n = int(input())\n\nsnacks = input().split(\" \")\n\ncur_stack = set()\nbase_req = n\nfor i in snacks:\n if int(i) == base_req:\n can_place = []\n j = int(i) - 1\n while str(j) in cur_stack:\n can_place.append(str(j))\n cur_stack.remove(str(j))\n j -= 1\n \n print(i, \" \".join(can_place))\n if can_place:\n base_req = j\n else:\n base_req -= 1\n continue\n else:\n cur_stack.add(i)\n print(\"\")\n \n\n", "'''\r\n# Submitted By M7moud Ala3rj\r\nDon't Copy This Code, CopyRight . [email protected] © 2022-2023 :)\r\n'''\r\n# Problem Name = \"Snacktower\"\r\n# Class: A\r\n\r\nfrom collections import defaultdict\r\nimport sys\r\n\r\n#sys.setrecursionlimit(2147483647)\r\ninput = sys.stdin.readline\r\ndef printf(*args, end='\\n', sep=' ') -> None:\r\n sys.stdout.write(sep.join(map(str, args)) + end)\r\n\r\ndef Solve():\r\n n = int(input())\r\n o = n ; l = defaultdict(int)\r\n a = list(map(int, input().split()))\r\n for i in a:\r\n if i!=o:\r\n l[i]+=1\r\n printf()\r\n else:\r\n printf(i, end=\" \")\r\n for x in range(o-1, -1, -1):\r\n if l[x]:\r\n printf(x, end=\" \")\r\n l[x]-=1\r\n else:\r\n break\r\n printf()\r\n o = x\r\n\r\nif __name__ == \"__main__\":\r\n # for t in range(int(input())):\r\n Solve()", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn = int(input())\r\nw = list(map(int, input().split()))\r\n\r\nd = set()\r\nfor i in w:\r\n if i != n:\r\n d.add(i)\r\n print('')\r\n else:\r\n s = [i]\r\n for j in range(i-1, 0, -1):\r\n if j in d:\r\n d.discard(j)\r\n s.append(j)\r\n else:\r\n n = j\r\n break\r\n print(' '.join(map(str, s)))", "# import math\r\nfrom collections import Counter, deque\r\nfrom math import *\r\n# from bisect import *\r\nmod = 998244353\r\n\r\n\r\n#1207-B\r\n\r\n# from functools import reduce\r\n# from itertools import permutations\r\n# import queue\r\n\r\n\r\n# def line1(x,y,n,d):\r\n# return y-d-x\r\n# def line2(x,y,n,d):\r\n# return y+d-x\r\n# def line3(x,y,n,d):\r\n# return y-d+x\r\n# def line4(x,y,n,d):\r\n# return y+d+x\r\ndef solve():\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n pointer=n-1\r\n arr=[False]*n\r\n for i in l:\r\n if i==pointer+1:\r\n cur=[]\r\n arr[pointer]=True\r\n while pointer>=0 and arr[pointer]:\r\n cur.append(pointer+1)\r\n pointer-=1\r\n print(*cur)\r\n else:\r\n print()\r\n arr[i-1]=True\r\n\r\n\r\n\r\n\r\n# t=int(input())\r\nt = 1\r\nfor _ in range(t):\r\n # print(\"Case #{}: \".format(_ + 1), end=\"\")\r\n solve()", "n=int(input())\r\ns=list(map(int,input().split()))\r\nz=set()\r\nfor i in s:\r\n z.add(i)\r\n while n in z:\r\n print(n,end=' ')\r\n n-=1\r\n print() ", "n=int(input())\r\nhas=[False]*n\r\nnxt=n\r\nsnack=list(map(int,input().split()))\r\nfor i in snack:\r\n has[i-1]=True\r\n if i==nxt:\r\n j=nxt-1\r\n while j<n and j>-1 and has[j]:\r\n print(j+1,end=' ')\r\n j-=1\r\n print()\r\n nxt=j+1\r\n else:\r\n print()\r\n", "#Ahmed_Abdelrazik\r\n\r\nt = int(input())\r\nW = list(map(int,input().split()))\r\nQ = [0]*(t+1)\r\n\r\nfor q in range(t):\r\n Q[W[q]] = 1\r\n while Q[t]:\r\n print(t,end = \" \")\r\n t -= 1\r\n if Q[t] !=1:\r\n print()\r\n\r\n", "a = int(input())\r\nb = list(map(int, input().split()))\r\nvis = [0] * (a+1)\r\nc = a\r\nfor i in range(len(b)):\r\n vis[b[i]] = True\r\n while vis[c] and c > 0:\r\n print(c, end=\" \")\r\n c -= 1\r\n if i != len(b)-1:\r\n print()\r\n", "from collections import deque, defaultdict\nnum_snacks = int(input())\nsnacks = deque([int(num) for num in input().split(\" \")])\n\nother_sizes = defaultdict(bool)\nwhile snacks:\n sizes_to_print = []\n if snacks:\n current_size = snacks.popleft()\n\n #print(current_size)\n if current_size == num_snacks:\n num_snacks -= 1\n sizes_to_print.append(current_size)\n\n while other_sizes[num_snacks]:\n if other_sizes[num_snacks] == True:\n sizes_to_print.append(num_snacks)\n num_snacks -= 1\n continue\n\n # for other_size in other_sizes:\n # if other_size == num_snacks:\n # num_snacks -= 1\n # sizes_to_print.append(other_size)\n # other_sizes.remove(other_size)\n # continue\n # break\n\n # if other_sizes:\n # for size in sizes_to_print[1:]:\n # other_sizes.remove(size)\n\n print(*sizes_to_print)\n continue\n\n other_sizes[current_size] = True\n print()\n\n \t\t\t \t \t\t \t\t \t \t\t \t \t", "n = int(input())\r\na = list(map(int,input().split()))\r\n\r\np = sorted(a)\r\np.reverse()\r\n\r\nd = {}\r\nfor i in a:\r\n\td[i] = 0\r\nmax_so_far = p[0]\r\n\r\nfor i in range(len(a)):\r\n\tif a[i]==max_so_far:\r\n\t\td[a[i]]+=1\r\n\t\tfor j in range(max_so_far,0,-1):\r\n\t\t\tif d[j] == 1:\r\n\t\t\t\tprint(j,end= ' ')\r\n\t\t\t\tmax_so_far = j-1\r\n\t\t\telse:\r\n\t\t\t\tbreak\r\n\t\tprint('')\r\n\telse:\r\n\t\td[a[i]]+=1\r\n\t\tprint(' ')\r\n\t\t", "n=int(input())\r\narr=input().split()\r\ndic={}\r\nc=1\r\nfor i in arr:\r\n dic[i]=c\r\n c+=1\r\n\r\nday=1 \r\nfor i in range(n,0,-1):\r\n if dic[str(i)]>day:\r\n for j in range(dic[str(i)]-day):\r\n print()\r\n print(i,end=\" \")\r\n day+=dic[str(i)]-day\r\n else:\r\n print(i,end=\" \")\r\n \r\n \r\n\r\n ", "n = int(input())\nsnacks = list(map(int, input().split()))\n\ntower = [0] * (n + 1) # Initialize tower with zeros\n\ntop = n # Represents the top position of the tower\n\nfor snack in snacks:\n tower[snack] = 1 # Place the current snack in the tower\n\n while tower[top] == 1: # Check if snacks can be placed from the top\n print(top, end=\" \")\n top -= 1\n\n print() # Print a new line for each day\n\n\t\t\t \t \t \t\t \t\t \t \t \t\t\t \t", "n = int(input())\r\na = [0] * (n + 1)\r\n\r\narr = input().split()\r\n\r\nfor i in range(1 , n + 1):\r\n a[i] = int(arr[i - 1])\r\n\r\nc = n\r\nvis = [False] * (n + 1)\r\n\r\nfor i in range(1 , n + 1):\r\n vis[a[i]] = True\r\n\r\n while vis[c] and c > 0:\r\n print(str(c )+ \" \" , end=\"\")\r\n c -= 1\r\n print() ", "# -*- coding: utf-8 -*-\n\n# Baqir Khan\n# Software Engineer (Backend)\n\nn = int(input())\na = list(map(int, input().split()))\nfound = [False] * (n+1)\ngo_back = n\n\nfor i in a:\n found[i] = True\n if i == go_back:\n bucket = []\n while found[i]:\n bucket.append(i)\n i -= 1\n print(\" \".join([str(item) for item in bucket]))\n if i > 0:\n go_back = i\n else:\n print()\n\n", "n = int(input())\r\nList = [int(x) for x in input().split()]\r\nVisited = [False]*n #O based Indexing\r\nSearching = n\r\nfor i in range(n):\r\n if(List[i] == Searching):\r\n Visited[List[i]-1] = True\r\n for x in range(Searching-1,-1,-1):\r\n if(Visited[x] == True):\r\n print(x+1,end = \" \")\r\n else:\r\n print()\r\n Searching = x+1\r\n break\r\n else:\r\n Visited[List[i] - 1] = True\r\n print()", "n = int(input()) \r\narr = [0]*(n+1)\r\nfor x in input().split():\r\n arr[int(x)]=1\r\n while(arr[n]):\r\n print(n, end=\" \")\r\n n-=1\r\n print(\"\")", "n = int(input())\r\narr = list(map(int,input().split()))\r\nlst = [0]*(n+1)\r\nk = n\r\nfor i in range(n):\r\n lst[arr[i]]=1\r\n while lst[k]==1:\r\n print(k,end=' ')\r\n k = k-1\r\n else:\r\n print('')\r\n ", "balaBase= int(input())\nsequenciaBalas = [int(t) for t in input().split()]\n#array que idnica quais balas ja cairam\nbalasMomento =[False]*(balaBase+1)\n\nfor bala in sequenciaBalas:\n balasMomento[bala]=True\n stringBalas = \"\"\n while(balasMomento[balaBase]):\n stringBalas+=str(balaBase)+\" \"\n balaBase-=1\n print(stringBalas)\n\n\t\t \t \t\t\t \t \t\t\t \t\t\t \t \t\t \t\t", "n = int(input())\r\n\r\nsnacks = [int(x) for x in input().split()]\r\nskipped = set()\r\n\r\nfor snack in snacks:\r\n skipped.add(snack)\r\n while n in skipped:\r\n print(n, end= ' ')\r\n n -= 1\r\n print()\r\n", "n = int(input())\r\nordered = [0] * (n + 1)\r\nturn = n\r\n\r\nfor snack in input().split():\r\n if int(snack) != turn:\r\n print()\r\n ordered[int(snack)] = 1\r\n else:\r\n print(turn, end=' ')\r\n turn -= 1\r\n while ordered[turn]:\r\n print(turn, end=' ')\r\n turn -= 1\r\n print()\r\n", "n=int(input())\r\na=[int(x) for x in input().split()]\r\ns=set()\r\nj=n\r\n\r\nfor i in range(n):\r\n s.add(a[i])\r\n while j in s:\r\n print(j,end=\" \")\r\n j-=1\r\n print()\r\n \r\n \r\n \r\n", "n = int(input())\r\narr = list(map(int, input().strip().split(' ')))\r\n# # arr.reverse()\r\n# i = 0\r\n\r\n# printf = []\r\n\r\n# while (n > 0):\r\n# while (i < len(arr) and arr[i] >= n):\r\n# printf.append(arr[i])\r\n# i += 1\r\n# print(*(i for i in sorted(printf, reverse=True)), sep=' ')\r\n# printf = []\r\n# n -= 1\r\n\r\nmyset = set()\r\n\r\nfor i in range(n):\r\n myset.add(arr[i])\r\n while (n in myset):\r\n print(n, end=' ')\r\n n -= 1\r\n else:\r\n print()\r\n", "n = int(input())\nsnacks = list(map(int,input().split()))\n\nnotplaced = set()\nfor snack in snacks:\n if snack == n:\n print(snack, end=' ')\n n -= 1\n while n in notplaced:\n print(n, end=' ')\n n -= 1\n else:\n notplaced.add(snack)\n print()\n\n\t\t\t \t \t \t\t \t\t \t \t \t", "n=int(input())\r\nm=n\r\na = [int(y) for y in input().split()]\r\ns=[]\r\nres=''\r\ntemp=[False]*n\r\nfor idx, i in enumerate(a):\r\n if i==m:\r\n temp[i-1]=True\r\n for j in range(m, 0, -1):\r\n if temp[j-1]:\r\n res+=str(m)+' '\r\n m-=1\r\n else:\r\n break\r\n print(res)\r\n res=''\r\n else:\r\n print()\r\n temp[i-1]=True", "\"\"\"\r\nAccording to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.\r\n\r\nYears passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.\r\n\r\n\r\nHowever, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.\r\n\r\nWrite a program that models the behavior of Ankh-Morpork residents.\r\n\r\nInput\r\nThe first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.\r\n\r\nThe second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.\r\n\r\nOutput\r\nPrint n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.\r\n\"\"\"\r\n\r\nn = int(input())\r\nsnacks = [int(i) for i in input().split()]\r\navailable = [False] * n\r\nnext_ = n\r\n\r\nfor snack in snacks:\r\n placed = ''\r\n available[snack - 1] = True\r\n while next_ > 0 and available[next_ - 1]:\r\n placed += ' ' + str(next_)\r\n next_ -= 1\r\n print(placed)", "from collections import deque\r\nimport heapq\r\n\r\nn = int(input())\r\nmaxiArr = list(map(int, input().split()))\r\n\r\narr = deque(maxiArr)\r\nmaxiPointer = 0\r\nmaxiArr.sort(reverse=True)\r\ncaching = []\r\n\r\nwhile arr:\r\n maxi = maxiArr[maxiPointer]\r\n item = arr.popleft()\r\n if item != maxi:\r\n heapq.heappush(caching, -item)\r\n print()\r\n else:\r\n maxiPointer += 1\r\n print(item, end = \" \")\r\n last = item\r\n while caching and last+caching[0]==1:\r\n last = -heapq.heappop(caching)\r\n print(last, end = \" \")\r\n maxiPointer += 1\r\n print()", "N = int(input())\r\nCandies = [int(x) for x in input().split()]\r\nFallenCandies = [False] * N\r\nC = N\r\nfor i in range(N):\r\n FallenCandies[Candies[i] - 1] = True\r\n while FallenCandies[C-1] == True and C > 0:\r\n C -= 1\r\n print(C+1,end=\" \")\r\n print(\"\")", "n=int(input())\r\nl1=list(map(int,input().split()))\r\ns=set()\r\nfor i in l1:\r\n s.add(i)\r\n while n in s:\r\n print (n,end=\" \")\r\n n=n-1\r\n print()\r\n", "n = int(input())\r\nl = list(map(int, input().split()))\r\n \r\ng = set()\r\n \r\nfor i in l:\r\n g.add(i)\r\n while n in g:\r\n print(n, end=' ')\r\n n -= 1\r\n print()", "import math\r\ndef fact(n):\r\n ans = 1\r\n for i in range(2, n+1):\r\n ans*= i\r\n return ans\r\ndef comb(n, c):\r\n return fact(n)//(fact(n-c)*c)\r\n\r\nn = int(input())\r\nd = list(map(int, input().split()))\r\nhas = [0 for i in range(n+1)]\r\nhas[0] = 0\r\nnxt = n\r\nans = []\r\nfor i in range(n):\r\n if(d[i]==nxt):\r\n temp = [str(nxt)]\r\n nxt-=1\r\n while(has[nxt]):\r\n temp.append(str(nxt))\r\n has[nxt]=0\r\n nxt-=1\r\n ans.append(temp)\r\n else:\r\n has[d[i]]=1\r\n ans.append([''])\r\nfor i in range(n):\r\n print(' '.join(ans[i]))\r\n", "\r\ndef main():\r\n n = int(fin())\r\n *a, = map(int, fin().split())\r\n b = [False]*(n+1)\r\n c = n\r\n for i in range(0, n):\r\n b[a[i]] = True\r\n while b[c] and c>0:\r\n fout(f\"{c} \")\r\n c -= 1\r\n fout(\"\\n\")\r\n\r\n\r\n# FastIO\r\nfrom sys import stdin, stdout\r\ndef fin(): return stdin.readline().strip(\"\\r\\n\")\r\ndef fout(s): return stdout.write(str(s))\r\nif __name__ == \"__main__\":\r\n t = 1 or int(fin())\r\n for i in range(t): main()", "import os.path\r\nimport sys\r\nfrom math import *\r\nfrom math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log\r\nif os.path.exists('input.txt'):\r\n sys.stdin = open('input.txt', 'r')\r\n sys.stdout = open('output.txt', 'w')\r\n\r\ndef inp(): return sys.stdin.readline().strip()\r\n\r\nn=int(inp())\r\narr=list(map(int,inp().split()))\r\nm=n\r\nst=[0]*(n+1)\r\ntemp=[]\r\nfor i in range(n):\r\n st[arr[i]]=1\r\n while st[m]:\r\n temp.append(m)\r\n m-=1\r\n if len(temp):\r\n print(*temp)\r\n temp=[]\r\n else:\r\n print()\r\n", "n = int(input())\r\n\r\nsnacks = list(map(int, input().split()))\r\n\r\nindices = [-1 for i in range(n)]\r\nbig = n\r\nindex = n-2\r\nfor i in range(n):\r\n if snacks[i] == big:\r\n indices[snacks[i]-1] = 0\r\n output = str(big)\r\n j = index\r\n while(indices[j] != -1 and j > -1):\r\n output += ' '+str(j+1)\r\n j-=1\r\n index = j-1\r\n big = j+1 \r\n print(output)\r\n else:\r\n print(' ')\r\n indices[snacks[i]-1] = 0\r\n\r\n \r\n \r\n \r\n \r\n \r\n ", "import sys\n\nn = int(sys.stdin.readline())\narr = list(map(int, sys.stdin.readline().split()))\n\nordered = sorted(arr, reverse=True)\nseen = set()\ni = 0\n\nfor num in arr:\n seen.add(num)\n while i < len(ordered) and ordered[i] in seen:\n print(ordered[i], end=\" \")\n i += 1\n if i < len(ordered) and num != ordered[i]:\n print()\n \n\nwhile i < len(ordered) and ordered[i] in seen:\n print(ordered[i], end=\" \")\n i += 1", "n = int(input())\r\na = list(map(int, input().split()))\r\na.insert(0, 0)\r\n\r\nb = []\r\nfor i in range(0,n+1):\r\n b.append(False)\r\n\r\nc = n\r\nfor i in range(1, n+1):\r\n b[a[i]] = True\r\n \r\n while b[c]:\r\n print(str(c) + \" \", end=\"\")\r\n c -= 1\r\n print(\"\")\r\n", "# ██████╗\r\n# ███ ███═█████╗\r\n# ████████╗ ██████╗ ████████╗ ████ █████ ████╗\r\n# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║\r\n# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝\r\n# ██╔═══╝ ██║ ██╗ ██╔═══╝ ███ ███╔══╝\r\n# ████████╗ ╚██████╔╝ ████████╗ ███ ██╔═╝\r\n# ╚═══════╝ ╚═════╝ ╚═══════╝ ███╔══╝\r\n# Legends ╚══╝\r\n\r\nimport sys\r\n\r\ninput = sys.stdin.readline\r\nn = int(input())\r\nin_ = list(map(int, input().split()))\r\nfreq = [0] * (n + 1)\r\nfor _ in range(n):\r\n freq[in_[_]] += 1\r\n while freq[n]:\r\n print(n, end=\" \")\r\n n -= 1\r\n print()\r\n", "n = int(input())\r\nlis = list(map(int, input().split()))\r\n\r\nhave = set()\r\n\r\nfor i in lis:\r\n have.add(i)\r\n while n in have:\r\n print(n, end=' ')\r\n n -= 1\r\n print()", "n = int(input())\r\nara = list(int(i) for i in input().split())\r\n\r\nmarker = list(int(0) for i in range(n))\r\n\r\nst = n\r\n\r\nfor i in range(n):\r\n if ara[i] == st:\r\n marker[ara[i]-1] = 1\r\n while(marker[st-1] != 0 and st >= 1):\r\n print(st, end=\" \")\r\n st -= 1\r\n print()\r\n else:\r\n marker[ara[i]-1] = 1\r\n print()\r\n", "def sol():\r\n\tn = int(input())\r\n\tsnack = [int(i) for i in input().split()]\r\n\tvisited = [False] * (n+1)\r\n\tcount = n\r\n\t\r\n\tfor i in range(n):\r\n\t\tvisited[snack[i]] = True\r\n\t\t\r\n\t\twhile visited[count] and count > 0:\r\n\t\t\tprint(\"%i\" % count, end = \" \")\r\n\t\t\tcount -= 1\r\n\t\tprint()\r\n\r\nsol()", "snacks_number = int(input())\r\nsnacks = list(map(int, input().split()))\r\ntemp_dict = {}\r\nfor i in snacks:\r\n if i == snacks_number:\r\n print(i, end = \"\")\r\n snacks_number = snacks_number - 1\r\n try:\r\n while temp_dict[snacks_number] == 1:\r\n print(\" \" + str(snacks_number), end = \"\")\r\n snacks_number = snacks_number - 1\r\n except:\r\n None\r\n else:\r\n temp_dict[i] = 1\r\n if snacks_number:\r\n print()", "n=int(input())\r\nl=list(map(int,input().split()))\r\ns=set()\r\nx=n\r\nfor i in range(n):\r\n s.add(l[i])\r\n while x in s:\r\n print(x,end=' ')\r\n x-=1\r\n print()\r\n\r\n", "n = int(input())\nline = input().split()\nnextEl = n\nboard = []\nfor i in range(0, n):\n board.append(0)\n\nfor word in line:\n snack = int(word)\n board[snack - 1] = 1\n if (snack == nextEl):\n while (board[nextEl - 1] == 1 and nextEl > 0):\n print(nextEl, end=' ')\n nextEl = nextEl - 1\n print()\n\n\n\t \t\t \t\t\t\t \t\t\t\t\t\t \t\t \t\t \t", "import bisect\r\nt = int(input())\r\ns=list()\r\narr=list(map(int,input().split()))\r\nfor i in arr :\r\n if i == t :\r\n print(t,end=\" \")\r\n t-=1\r\n else :\r\n bisect.insort(s, i)\r\n while len(s)>0 and t == s[-1] :\r\n print(t,end=\" \")\r\n s.pop()\r\n t-=1\r\n print()\r\n \r\n\r\n", "n=int(input())\r\nl=list(map(int,input().split()))\r\nz=[0]*(n+1)\r\nx=n\r\nfor i in range(n):\r\n\tz[l[i]]=2\r\n\twhile z[x]==2:\r\n\t\tprint(x,end=' ')\r\n\t\tx-=1\r\n\tprint()", "n = int(input())\r\nstone = list(map(int,input().split()))\r\nh = set()\r\nfor i in stone:\r\n h.add(i)\r\n while n in h and n > 0:\r\n print(n, end=\" \")\r\n n -= 1\r\n print()", "n = int(input())\r\nl = [int(x) for x in input().split()]\r\nx = n\r\nl1 = [0]*(n+1)\r\nfor i in l:\r\n l1[i]=1\r\n while l1[x]:\r\n print(x,end=' ')\r\n x-=1\r\n print()", "def solve():\r\n n = int(input())\r\n waiting_for = n\r\n stored = set([])\r\n for i in [int(i) for i in input().split()]:\r\n if i == waiting_for:\r\n stored.add(i)\r\n res = []\r\n for j in range(i, 0, -1):\r\n if j in stored: res.append(str(j))\r\n else:\r\n waiting_for = j\r\n break\r\n print(' '.join(res))\r\n else:\r\n print('')\r\n stored.add(i)\r\nsolve()\r\n\r\n", "n = int(input())\r\nl = list(map(int,input().split()))\r\nd = {}\r\nfor i in range(n):\r\n if l[i] == n:\r\n print(n,end = \" \")\r\n while n - 1 in d:\r\n print(n - 1, end = \" \")\r\n n-= 1\r\n n -= 1\r\n print()\r\n else:\r\n d[l[i]] = None\r\n print()", "n=int(input())\r\nsize=list(map(int,input().split()))\r\nfreq=[0]*(n+1)\r\nx=n\r\nfor i in size:\r\n freq[i]=1\r\n while freq[x]==1:\r\n print(x,end=\" \")\r\n x-=1\r\n print('')\r\n ", "n = int(input())\r\nsnacks = set()\r\nfor i in input().split():\r\n\tsnacks.add(int(i))\r\n\twhile n in snacks:\r\n\t\tprint(n, end=' ')\r\n\t\tn -= 1\r\n\tprint()", "n = int(input())\r\nvalues = list(map(int,input().split()))\r\nnextv = n\r\nhas = [0]*(n+1)\r\nfor x in values:\r\n has[x]=1\r\n if x == nextv:\r\n for i in range(nextv,-1,-1):\r\n if has[i]==1:\r\n print(i,end=\" \")\r\n nextv-=1\r\n has[i]=0\r\n else:\r\n break\r\n print()\r\n ", "n = int(input())\r\nb = list(map(int, input().split()))\r\na=[0]*n\r\n\r\ncur=n\r\ndef print_(x,curr):\r\n global cur\r\n s = ''\r\n if x==curr:\r\n i=curr\r\n while (i>0):\r\n if a[i-1]:\r\n s+=(f'{i} ')\r\n a[i-1]=0\r\n cur = i-1\r\n i-=1\r\n else:\r\n break\r\n return s\r\nfor i in range(n):\r\n x=b[i]\r\n a[x-1] = 1\r\n print(print_(x,cur))\r\n", "from collections import deque\r\n\r\nn = int(input())\r\nsizes = list( map(int, input().split()) )\r\n\r\nst = set()\r\nfor i in sizes:\r\n if i == n:\r\n prnt = list()\r\n prnt.append(i)\r\n n -= 1\r\n while n in st:\r\n prnt.append(n)\r\n n -= 1\r\n print(*prnt)\r\n else:\r\n print('')\r\n st.add(i)\r\n \r\n\r\n", "# n,k = map(int,input().split())\r\n\r\nn = int(input())\r\nnums = list(map(int, input().split()))\r\n\r\nvisited = [False]*(n)\r\n\r\nindex = n-1\r\nfor i in range(n):\r\n visited[nums[i]-1] = True\r\n while visited[index] == True and index >= 0 :\r\n\r\n print(index+1, end=\" \")\r\n index = index-1\r\n print(\" \")\r\n\r\n\r\n\r\n\r\n", "n = int(input())\r\nsnacks = [int(i) for i in input().split()]\r\nordered = [0] * (n + 1)\r\nturn = n\r\n\r\nfor snack in snacks:\r\n if snack != turn:\r\n print()\r\n ordered[snack] = 1\r\n else:\r\n print(turn, end=' ')\r\n turn -= 1\r\n while ordered[turn]:\r\n print(turn, end=' ')\r\n turn -= 1\r\n print()\r\n", "\r\n#I used a bollean list that stores the visited numbers as \r\n# we iterate through the \"num\". I start first to print the maximum number n,\r\n#then the numbers before it (if possiple)\r\n\r\n\r\nn = int(input())\r\nnum = input()\r\nnum = list(int(x) for x in num.split(\" \"))\r\nvisited = [1] * (n+1)\r\ni = 0\r\nwhile n > 0 and i < len(num):\r\n visited[num[i]] = 0\r\n while visited[n] == 0:\r\n print(n, end=\" \"); n -= 1\r\n if n != 0:\r\n print(\" \")\r\n i += 1", "n = int(input())\nsizes = [int(x) for x in input().split()]\n\nwait = {} #representa quem está aguardando para ser liberado\nbigger = n #representa quem deve ser liberado primeiro\n\nfor size in sizes:\n wait[size] = True\n \n if size == bigger:\n for i in range(bigger, 0, -1):\n if (wait.get(i)):\n wait[i] = False\n print(i, end=\" \")\n bigger = i-1\n else:\n break\n print()\n \t\t\t \t \t\t\t\t\t\t \t\t \t \t \t\t\t\t \t\t", "n=int(input())\r\nz=[0]*100098\r\nss=n\r\nar=list(map(int,input().split()))\r\nfor x in range(n):\r\n z[ar[x]]=1\r\n while z[ss]:\r\n print(ss,end=\" \")\r\n ss-=1 \r\n print(\" \")\r\n", "n = int(input())\ns = list(map(int,input().split()))\nl = [None]*(n+1)\nx = n\nfor i in range(n):\n l[s[i]] = 0\n while ((l[x] == 0) & (x > 0)):\n print(x ,end = ' ')\n x -= 1\n print()\n \t \t \t\t\t \t \t \t\t \t \t\t\t", "n = int(input())\r\narr = list(map(int, input().split()))\r\narr_sorted = sorted(arr)\r\narr_sorted.reverse()\r\nj, i = 0, 0\r\nvisited = set()\r\nans = \"\"\r\nwhile i < len(arr):\r\n visited.add(arr[i])\r\n ans = \"\"\r\n while j < len(arr) and arr_sorted[j] in visited:\r\n ans += str(arr_sorted[j]) + \" \"\r\n j += 1\r\n if ans == \"\":\r\n print()\r\n else:\r\n print(ans[0:-1])\r\n i += 1\r\n", "n = int(input())\r\nl = n\r\ns = set()\r\na = map(int, input().split())\r\nfor i in a:\r\n s.add(i)\r\n while n in s:\r\n print(n, end=' ')\r\n n = n-1\r\n print()\r\n", "n = int(input())\r\narr = list(map(int,input().split(' ')))\r\nmax_n = n\r\nflags = [False for i in range(n+1)]\r\nfor i in range(n):\r\n flags[arr[i]]=True\r\n while(flags[max_n]):\r\n print(max_n,end=' ')\r\n max_n-=1\r\n print(' ')", "n = int(input())\r\nnums = [0]+[int(i) for i in input().split(\" \")]\r\nhas_value = [0]*len(nums)\r\nlast_output = n\r\nfor i in range(1,len(nums)):\r\n has_value[nums[i]]=1\r\n while has_value[last_output] and last_output>0:\r\n print(str(last_output) + \" \", end ='')\r\n last_output -= 1\r\n print(\"\")\r\n\r\n\r\n\r\n", "n = int(input())\r\nl = map(int,input().split())\r\na = set()\r\nfor i in l:\r\n a.add(i)\r\n while(n in a):\r\n print(n,end = ' ')\r\n n-=1\r\n print()\r\n\r\n\r\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nfrq={}\r\nfor i in a:\r\n frq[i]=1\r\n try:\r\n while frq[n] != 0:\r\n print(n,end=\" \")\r\n n-=1\r\n except:\r\n pass\r\n print()\r\n", "n = int(input())\nsnacks = list(map(int, input().split()))\n\ntower = [0] * (n + 1) \n\ntop = n \nfor snack in snacks:\n tower[snack] = 1 \n while tower[top] == 1: \n print(top, end=\" \")\n top -= 1\n\n print() # Print a new line for each day\n \t\t\t\t \t \t \t \t\t \t", "n=int(input())\r\nli=list(map(int,input().split(\" \")))\r\ncheck=[]\r\nfor x in range(n):\r\n check.append(False)\r\ni=n\r\nfor x in li:\r\n check[x-1]=True\r\n\r\n while i>0 and check[i-1]==True :\r\n print(i,end=\" \")\r\n\r\n i-=1\r\n print()\r\n\r\n\r\n", "n = input()\nsnack_sequence = input().split(' ')\n\nsnack_list = [False]*int(n)\nnext_largest_snack = int(n)\n\nfor snack in snack_sequence:\n current_snack = int(snack)\n snack_list[current_snack - 1] = True\n if int(snack) == next_largest_snack:\n while current_snack > 0 and snack_list[current_snack - 1]:\n print(current_snack, end='')\n current_snack -= 1\n if current_snack > 0 and snack_list[current_snack - 1]:\n print(' ', end='')\n next_largest_snack = current_snack\n if current_snack > 0:\n print('')\n else:\n print('')\n\n \t\t\t \t\t \t \t\t\t \t\t\t\t \t\t \t \t\t\t", "import sys\r\nfrom math import sqrt,ceil,floor,gcd\r\nfrom collections import Counter\r\nfrom heapq import *\r\n\r\ninput = lambda:sys.stdin.readline()\r\n\r\ndef int_arr(): return list(map(int,input().split()))\r\ndef str_arr(): return list(map(str,input().split()))\r\ndef get_str(): return map(str,input().split())\r\ndef get_int(): return map(int,input().split())\r\ndef get_flo(): return map(float,input().split())\r\ndef lcm(a,b): return (a*b) // gcd(a,b)\r\n\r\nmod = 1000000007\r\n\r\ndef solve(n,arr):\r\n d = {}\r\n for i in range(n):\r\n d[arr[i]] = i\r\n\r\n maxx = max(arr)\r\n res = []\r\n ans = []\r\n while maxx > 0:\r\n if res == []:\r\n res.append(maxx)\r\n maxx -= 1\r\n\r\n elif d[maxx] < d[res[0]]:\r\n res.append(maxx)\r\n maxx -= 1\r\n\r\n elif d[maxx] > d[res[0]]: \r\n ans.append(res)\r\n res = []\r\n\r\n if res:ans.append(res)\r\n\r\n curr = d[ans[0][0]]\r\n for i in range(curr):\r\n print()\r\n print(*ans[0])\r\n for i in range(1,len(ans)):\r\n curr = d[ans[i][0]]-curr-1\r\n for j in range(curr):\r\n print()\r\n print(*ans[i])\r\n curr = d[ans[i][0]]\r\n\r\n\r\n\r\n\r\n\r\n# for _ in range(int(input())):\r\nn = int(input())\r\narr = int_arr()\r\nsolve(n,arr)\r\n", "# Codeforces - Snacktower\r\n# https://codeforces.com/problemset/problem/767/A\r\n#\r\n# Author: eloyhz\r\n# Date: Aug/31/2020\r\n\r\nimport heapq\r\n\r\nif __name__ == '__main__':\r\n n = int(input())\r\n a = [int(x) for x in input().split()]\r\n expected = n\r\n stored = []\r\n heapq.heapify(stored)\r\n for ai in a:\r\n if ai != expected:\r\n print()\r\n heapq.heappush(stored, -ai)\r\n else:\r\n print(f'{ai} ', end='')\r\n expected -= 1\r\n if not stored:\r\n print()\r\n continue\r\n while stored:\r\n q = -heapq.heappop(stored)\r\n if q != expected:\r\n heapq.heappush(stored, -q)\r\n break\r\n print(f'{q} ', end='')\r\n expected -= 1\r\n print()\r\n while stored:\r\n q = -heapq.heappop(stored)\r\n print(f'{q} ', end='')\r\n", "# A. Snacktower\r\nn=int(input())\r\na=list(map(int,input().split()))\r\ns=set()\r\nfor i in a:\r\n c=[]\r\n s.add(i)\r\n while n in s:\r\n c.append(n)\r\n n-=1\r\n print(*c)\r\n \r\n " ]
{"inputs": ["3\n3 1 2", "5\n4 5 1 2 3", "1\n1", "2\n1 2", "10\n5 1 6 2 8 3 4 10 9 7", "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "2\n2 1"], "outputs": ["3 \n\n2 1 ", "5 4 \n\n\n3 2 1 ", "1 ", "2 1 ", "10 \n9 8 \n7 6 5 4 3 2 1 ", "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 ", "100 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 \n39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 ", "2 \n1 "]}
UNKNOWN
PYTHON3
CODEFORCES
283
2107d7677a31fc3b2e3f2f48f90ea65d
Coach
A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive. Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on the same team. Besides, if the *i*-th student wants to be on the same team with the *j*-th one, then the *j*-th student wants to be on the same team with the *i*-th one. The coach wants the teams to show good results, so he wants the following condition to hold: if the *i*-th student wants to be on the same team with the *j*-th, then the *i*-th and the *j*-th students must be on the same team. Also, it is obvious that each student must be on exactly one team. Help the coach and divide the teams the way he wants. The first line of the input contains integers *n* and *m* (3<=≤<=*n*<=≤<=48, . Then follow *m* lines, each contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=*n*) — the pair *a**i*,<=*b**i* means that students with numbers *a**i* and *b**i* want to be on the same team. It is guaranteed that *n* is divisible by 3. It is guaranteed that each pair *a**i*,<=*b**i* occurs in the input at most once. If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=*n*) — the *i*-th team. If there are multiple answers, you are allowed to print any of them. Sample Input 3 0 6 4 1 2 2 3 3 4 5 6 3 3 1 2 2 3 1 3 Sample Output 3 2 1 -1 3 2 1
[ "import sys\r\nfrom collections import defaultdict\r\ninput = sys.stdin.readline \r\n\r\nn, m = map(int, input().split()) \r\nd = defaultdict(list) \r\nfor i in range(m):\r\n u, v = map(int, input().split()) \r\n d[u].append(v) \r\n d[v].append(u) \r\n\r\nv = [0] * (n + 1) \r\np = [-1] * (n + 1) \r\n\r\nans = [] \r\nal = []\r\ndb = []\r\nfor i in range(1, n + 1):\r\n if(not v[i]):\r\n v[i] = 1\r\n if(len(d[i]) == 2): \r\n if(v[d[i][0]] or v[d[i][1]]):\r\n print(-1) \r\n exit() \r\n \r\n ans.append([i, d[i][0], d[i][1]])\r\n v[d[i][0]], v[d[i][1]] = 1, 1 \r\n elif(len(d[i]) == 1):\r\n if(v[d[i][0]]):\r\n print(-1) \r\n exit()\r\n db.append([i, d[i][0]]) \r\n v[d[i][0]] = 1\r\n elif(len(d[i]) == 0):\r\n al.append(i)\r\n else:\r\n print(-1)\r\n exit()\r\nif((len(al) - len(db)) % 3 == 0 and len(al) >= len(db)):\r\n for i in ans:\r\n print(*i) \r\n for i in range(len(db)):\r\n print(al[i], db[i][0], db[i][1]) \r\n for i in range(len(db), len(al), 3):\r\n print(al[i], al[i + 1], al[i + 2]) \r\nelse:\r\n print(-1)\r\n", "def solve(n, pairs):\n paired = [[] for _ in range(n)]\n unpaired = set(q for q in range(1,n+1))\n for i, j in pairs:\n if i in unpaired:\n unpaired.remove(i)\n if j in unpaired:\n unpaired.remove(j)\n paired[i-1].append(j)\n\n unpaired = list(unpaired)\n handled_pairs = set()\n output = []\n for index, person in enumerate(paired):\n if len(person) > 3:\n print(-1)\n return\n if len(person) == 2:\n a, b = min(person), max(person)\n if len(paired[b-1]) != 0:\n print(-1)\n return\n if len(paired[a-1]) > 1:\n print(-1)\n return\n if len(paired[a-1]) == 1 and paired[a-1][0] != b:\n print(-1)\n return\n handled_pairs.add((a,b))\n output.append((index+1, a, b))\n if len(person) == 1 and (index+1, person[0]) not in handled_pairs:\n a = person[0]\n if len(paired[a-1]) > 1:\n print(-1)\n return\n if len(paired[a-1]) == 1:\n if len(paired[paired[a-1][0]-1]) > 0:\n print(-1)\n return\n b = paired[a-1][0]\n if len(paired[a-1]) == 0:\n if len(unpaired) == 0:\n print(-1)\n return\n b = unpaired.pop()\n output.append((index+1, a, b))\n\n if len(unpaired) > 0:\n if len(unpaired) % 3 != 0:\n print(-1)\n return\n while len(unpaired) > 0:\n a, b, c = unpaired.pop(), unpaired.pop(), unpaired.pop()\n output.append((a,b,c))\n\n for a, b, c in output:\n print(f\"{a} {b} {c}\")\n\n\nn, m = [int(component) for component in input().split(\" \")]\n\npairs = []\nfor row in range(m):\n pairs.append(tuple([int(component) for component in input().split(\" \")]))\n\nsolve(n, pairs)", "def dfs(start,color):\r\n m[start] = True\r\n if len(mas[start]) == 0:\r\n colors[0].append(start + 1)\r\n else:\r\n colors[color].append(start + 1)\r\n for i in mas[start]:\r\n if not m[i]:\r\n dfs(i,color)\r\n\r\n\r\nn, m = map(int, input().split())\r\nmas = []\r\nfor i in range(n):\r\n mas.append([])\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n mas[a - 1].append(b - 1)\r\n mas[b - 1].append(a - 1)\r\nm = [False] * n\r\ncolors = []\r\nfor i in range(n):\r\n colors.append([])\r\ncolor = 1\r\nfor i in range(n):\r\n if not m[i]:\r\n dfs(i,color)\r\n color += 1\r\nfor i in range(1,n):\r\n if len(colors[i]) > 3:\r\n print(-1)\r\n exit()\r\n elif len(colors[i]) == 3 or len(colors[i]) == 0:\r\n continue\r\n else:\r\n if len(colors[0]) == 0:\r\n print(-1)\r\n exit()\r\n elif len(colors[i]) == 2 and len(colors[0]) > 0:\r\n colors[i].append(colors[0][0])\r\n del colors[0][0]\r\n elif len(colors[i]) == 1 and len(colors[0]) > 1:\r\n colors[i].append(colors[0][0])\r\n colors[i].append(colors[0][1])\r\n del colors[0][0]\r\n del colors[0][1]\r\n else:\r\n print(-1)\r\n exit()\r\nif len(colors[0]) % 3 == 0:\r\n for i in range(0,len(colors[0]),3):\r\n print(' '.join(map(str, colors[0][i : i + 3])))\r\n for i in range(1,n):\r\n if colors[i] != []:\r\n print(' '.join(map(str, colors[i])))\r\nelse:\r\n print(-1)\r\n", "\r\nfrom collections import defaultdict\r\n\r\n\r\nn,m=map(int,input().split())\r\np=[-1]*n\r\ndef find(x):\r\n if p[x]<0:return x\r\n p[x]=find(p[x])\r\n return p[x]\r\ndef join(a,b):\r\n a=find(a)\r\n b=find(b)\r\n if a==b:return\r\n p[a]+=p[b]\r\n p[b]=a\r\ndef sz(x):\r\n return -p[find(x)]\r\nfor _ in range(m):\r\n a,b=map(int,input().split())\r\n a-=1\r\n b-=1\r\n join(a,b)\r\n\r\ndef go():\r\n threes=[]\r\n twos=[]\r\n ones=[]\r\n for i in range(n):\r\n if find(i)==i:\r\n if sz(i)==1:ones.append(i)\r\n elif sz(i)==2:twos.append(i)\r\n elif sz(i)==3:threes.append(i)\r\n else:\r\n return False\r\n\r\n for t in twos:\r\n if not len(ones):return False\r\n o=ones.pop()\r\n join(t,o)\r\n threes.append(find(t))\r\n \r\n if len(ones)%3!=0:return False\r\n\r\n while len(ones):\r\n a,b,c=ones.pop(),ones.pop(),ones.pop()\r\n join(a,b)\r\n join(a,c)\r\n threes.append(find(a))\r\n \r\n ts=defaultdict(list)\r\n for i in range(n):ts[find(i)].append(i)\r\n return list(ts.values())\r\n\r\nres=go()\r\nif res==False:print(-1)\r\nelse:\r\n for g in res:\r\n print(*[v+1 for v in g])\r\n\r\n", "import sys\r\nfrom math import sqrt, gcd, ceil, log\r\n# from bisect import bisect, bisect_left\r\nfrom collections import defaultdict, Counter, deque\r\n# from heapq import heapify, heappush, heappop\r\ninp = sys.stdin.readline\r\nread = lambda: list(map(int, inp().strip().split()))\r\n\r\ndef main():\r\n\tn, m = read();\r\n\tadj = [[] for i in range(n+1)]\r\n\tvisited = [0]*(n+1)\r\n\tfor i in range(m):\r\n\t\tu, v = read()\r\n\t\tadj[u].append(v); adj[v].append(u)\r\n\r\n\tdef dfs(node):\r\n\t\tstack = [node]\r\n\t\tteam = []\r\n\t\twhile stack:\r\n\t\t\tpar = stack.pop()\r\n\t\t\tvisited[par] = 1\r\n\t\t\tteam.append(par)\r\n\t\t\tfor child in adj[par]:\r\n\t\t\t\tif not visited[child]:\r\n\t\t\t\t\tvisited[child] = 1\r\n\t\t\t\t\tstack.append(child)\r\n\t\tif len(team) > 3:return\r\n\t\telse:return(team)\r\n\r\n\tans = []; two = []; one = []\r\n\tfor i in range(1, n+1):\r\n\t\tif not visited[i]:\r\n\t\t\tteam = dfs(i)\r\n\t\t\tif not team:\r\n\t\t\t\tprint(-1); exit()\r\n\t\t\telif len(team) == 3:\r\n\t\t\t\tans.append(team)\r\n\t\t\telif len(team) == 2:\r\n\t\t\t\ttwo.append(team)\r\n\t\t\telse:\r\n\t\t\t\tone.extend(team)\r\n\twhile two:\r\n\t\tif one:\r\n\t\t\telem = two.pop()\r\n\t\t\telem.append(one.pop())\r\n\t\t\tans.append(elem)\r\n\t\telse:\r\n\t\t\tprint(-1);exit()\r\n\twhile one:\r\n\t\telem = []\r\n\t\tfor i in range(3):elem.append(one.pop())\r\n\t\tans.append(elem)\r\n\r\n\t# print(ans)\r\n\tfor i in ans:\r\n\t\tprint(*i)\r\n\r\n\r\n\r\n\r\n\r\n\t\t\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()", "import itertools\r\nimport math\r\nfrom math import gcd as gcd\r\nimport sys\r\nimport queue\r\nimport itertools\r\nfrom heapq import heappop, heappush\r\nimport random\r\n\r\n\r\ndef solve():\r\n def bfs(s, n):\r\n comp[s] = 1\r\n q = [s]\r\n it = 0\r\n while it < len(q):\r\n k = q[it]\r\n\r\n for u in g[k]:\r\n if comp[u] == -1:\r\n comp[u] = 1\r\n q.append(u)\r\n\r\n it += 1\r\n\r\n return [len(q), q]\r\n\r\n\r\n n,m=map(int,input().split())\r\n\r\n g = [set() for i in range(n)]\r\n comp = [-1 for i in range(n)]\r\n\r\n for i in range(m):\r\n a,b = map(int,input().split())\r\n g[a - 1].add(b - 1)\r\n g[b - 1].add(a - 1)\r\n\r\n ok = True\r\n two = []\r\n one = []\r\n done = []\r\n\r\n for i in range(n):\r\n if comp[i] == -1:\r\n size, node = bfs(i, n)\r\n if size >= 4:\r\n ok = False\r\n else:\r\n if size == 1:\r\n one.append(node)\r\n elif size == 2:\r\n two.append(node)\r\n else:\r\n done.append(node)\r\n\r\n if ok:\r\n if len(two) > len(one):\r\n print(\"-1\")\r\n else:\r\n for a,b,c in done:\r\n print(a + 1,b + 1,c + 1)\r\n for i in range(len(two)):\r\n print(two[i][0] + 1, two[i][1] + 1, one[i][0] + 1)\r\n y = 0\r\n for i in range(len(two), len(one)):\r\n print(one[i][0] + 1,end= \" \")\r\n y += 1\r\n if y == 3:\r\n y = 0\r\n print()\r\n else:\r\n print(\"-1\")\r\n\r\n\r\n\r\nif __name__ == '__main__':\r\n multi_test = 0\r\n\r\n if multi_test:\r\n t = int(sys.stdin.readline())\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "def dfs(s):\r\n vis[s] = True\r\n z.append(s)\r\n for i in range(len(p[s])):\r\n if not vis[p[s][i]]:\r\n dfs(p[s][i])\r\n\r\nn, m = map(int, input().split())\r\np,z={},[]\r\n\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n if a not in p.keys():p[a] = []\r\n if b not in p.keys():p[b] = []\r\n p[a].append(b); p[b].append(a)\r\n\r\nvis = [False] * (n + 1)\r\nzz = [i for i in range(1, n + 1) if i not in p.keys()]\r\nans = []\r\nfl = True\r\nfor i in range(1, n + 1):\r\n z = []\r\n if not vis[i] and i in p.keys(): dfs(i)\r\n if len(z) > 3:\r\n fl = False\r\n break\r\n elif len(z) == 3:\r\n ans.append(z)\r\n elif len(z) == 2:\r\n if len(zz) == 0:\r\n fl = False\r\n break\r\n z.append(zz[0])\r\n ans.append(z)\r\n zz = zz[1:]\r\nif not fl:\r\n print(-1)\r\nelse:\r\n for i in ans:\r\n print(*i)\r\n for j in range(0, len(zz), 3):\r\n print(*zz[j:j + 3])\r\n", "N = 64\r\nread_input = lambda: list(map(int, input().split()))\r\nn, m = read_input()\r\ngraph = [[0]*N for _ in range(N)]\r\n\r\nfor _ in range(m):\r\n u, v = read_input()\r\n graph[u][v] = graph[v][u] = 1\r\n\r\ngroups = [[], [], [], []]\r\nvisited_nodes = set()\r\nnodes_range = range(1, n + 1)\r\n\r\ndef dfs(u):\r\n group = [u]\r\n visited_nodes.add(u)\r\n \r\n for v in nodes_range:\r\n if graph[u][v] and v not in visited_nodes:\r\n group += dfs(v)\r\n \r\n return group\r\n\r\ndef fail():\r\n print(-1)\r\n exit()\r\n\r\nfor i in nodes_range:\r\n if i not in visited_nodes:\r\n group = dfs(i)\r\n group_length = len(group)\r\n\r\n if group_length > 3:\r\n fail()\r\n\r\n groups[group_length] += [group]\r\n\r\nfor x in groups[2]:\r\n if groups[1]:\r\n groups[3] += [x + groups[1].pop()]\r\n else:\r\n fail()\r\n\r\nif len(groups[1]) % 3:\r\n fail()\r\n\r\nwhile groups[1]:\r\n groups[3] += [groups[1].pop() + groups[1].pop() + groups[1].pop()]\r\n\r\nfor x in groups[3]:\r\n print(' '.join(map(str, x)))\r\n", "import sys,math\r\nfrom collections import deque,defaultdict\r\nimport operator as op\r\nfrom functools import reduce\r\nfrom itertools import permutations\r\nimport heapq\r\n\r\n#sys.setrecursionlimit(10**7) \r\n# OneDrive\\Documents\\codeforces\r\n\r\nI=sys.stdin.readline\r\n\r\nalpha=\"abcdefghijklmnopqrstuvwxyz\"\r\n\r\nmod=10**9 + 7\r\n\r\n\"\"\"\r\nx_move=[-1,0,1,0,-1,1,1,-1]\r\ny_move=[0,1,0,-1,1,1,-1,-1]\r\n\"\"\"\r\ndef ii():\r\n\treturn int(I().strip())\r\ndef li():\r\n\treturn list(map(int,I().strip().split()))\r\ndef mi():\r\n\treturn map(int,I().strip().split())\r\n\r\n\r\ndef ncr(n, r):\r\n r = min(r, n-r)\r\n numer = reduce(op.mul, range(n, n-r, -1), 1)\r\n denom = reduce(op.mul, range(1, r+1), 1)\r\n return numer // denom \r\n\r\ndef ispali(s):\r\n\ti=0\r\n\tj=len(s)-1\r\n\r\n\twhile i<j:\r\n\t\tif s[i]!=s[j]:\r\n\t\t\treturn False\r\n\t\ti+=1\r\n\t\tj-=1\r\n\treturn True\r\n\r\n\r\n\r\ndef isPrime(n):\r\n\tif n<=1:\r\n\t\treturn False\r\n\telif n<=2:\r\n\t\treturn True\r\n\telse:\r\n\t\t\r\n\t\tfor i in range(2,int(n**.5)+1):\r\n\t\t\tif n%i==0:\r\n\t\t\t\treturn False\r\n\t\treturn True\r\n\r\n\r\n\r\n\r\ndef main():\r\n\tn,m=mi()\r\n\td=defaultdict(list)\r\n\tfor i in range(m):\r\n\t\tu,v=mi()\r\n\t\td[u].append(v)\r\n\t\td[v].append(u)\r\n\r\n\tvis=[-1]*(n+1)\r\n\r\n\tcnt=1\r\n\tgroups=defaultdict(list)\r\n\tdef dfs(i):\r\n\t\tvis[i]=cnt\r\n\t\tcon=1\r\n\t\tfor child in d[i]:\r\n\t\t\tif vis[child]==-1:\r\n\t\t\t\tcon+=dfs(child)\r\n\t\treturn con\r\n\tf=0\r\n\tfor i in range(1,n+1):\r\n\t\tif vis[i]==-1:\r\n\t\t\tgrup=dfs(i)\t\t\t\r\n\t\t\ttmp=[]\r\n\t\t\tfor j in range(1,n+1):\r\n\t\t\t\tif vis[j]==cnt:\r\n\t\t\t\t\ttmp.append(j)\r\n\t\t\t\r\n\t\t\tif grup==3:\r\n\t\t\t\tgroups[3].append(tmp)\r\n\t\t\telif grup==2:\r\n\t\t\t\tgroups[2].append(tmp)\r\n\t\t\telif grup==1:\r\n\t\t\t\tgroups[1].append(tmp)\r\n\t\t\telse:\r\n\t\t\t\tf=1\r\n\t\t\t\tbreak\r\n\r\n\t\t\tcnt+=1\r\n\t# print(groups)\r\n\tif len(groups[2])>len(groups[1]):\r\n\t\tf=1\r\n\telse:\r\n\t\tfor i in range(len(groups[2])):\r\n\t\t\tgroups[3].append(groups[2].pop()+groups[1].pop())\r\n\r\n\tfor i in range(len(groups[1])//3):\r\n\t\ttmp=[]\r\n\t\tfor _ in range(3):\r\n\t\t\ttmp+=groups[1].pop()\r\n\t\tgroups[3].append(tmp)\r\n\t# if len(groups[1])>0 or len(groups[3])!=n//3:\r\n\t# \tf=1\r\n\r\n\tif f:\r\n\t\tprint(-1)\r\n\r\n\telse:\r\n\t\tfor i in groups[3]:\r\n\t\t\tprint(*i) \r\n\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\r\n\t\t\t\r\n\r\n\t\r\n\r\n\t\t\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t\r\n\r\n\t\t\r\n\r\n\r\n\t\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t\r\n\r\n\r\n\r\n\t\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\t\r\n\r\n\r\n\t\r\n\t\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\r\n \r\n\t\t\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\t\r\n\r\n\r\n\t\t\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\r\n\t\t\t\t\r\n\r\n\r\n\t\r\n\r\n\t\r\n\t\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\t\r\n\r\n\r\n\t\r\n\r\n\r\n\r\n\r\n\t\t\r\n\t\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\t\t\t\t\t\r\n\r\nif __name__ == '__main__':\r\n\tmain()", "def dfs(s):\r\n used[s] = True\r\n x.append(s)\r\n for i in range(len(p[s])):\r\n if not used[p[s][i]]:\r\n dfs(p[s][i])\r\n\r\n\r\nn, m = map(int, input().split())\r\np = {}\r\nx = []\r\nfor i in range(m):\r\n a, b = map(int, input().split())\r\n if a not in p.keys():\r\n p[a] = []\r\n if b not in p.keys():\r\n p[b] = []\r\n p[a].append(b)\r\n p[b].append(a)\r\ncomp = []\r\nused = [False] * (n + 1)\r\nhp = [i for i in range(1, n + 1) if i not in p.keys()]\r\nans = []\r\nis_ans = True\r\nfor i in range(1, n + 1):\r\n x = []\r\n if not used[i] and i in p.keys():\r\n dfs(i)\r\n if len(x) > 3:\r\n is_ans = False\r\n break\r\n elif len(x) == 3:\r\n ans.append(x)\r\n elif len(x) == 2:\r\n if len(hp) == 0:\r\n is_ans = False\r\n break\r\n x.append(hp[0])\r\n ans.append(x)\r\n hp = hp[1:]\r\nif not is_ans:\r\n print(-1)\r\nelse:\r\n for i in ans:\r\n print(*i)\r\n for j in range(0, len(hp), 3):\r\n print(*hp[j:j + 3])\r\n", "import sys\r\ninput = lambda: sys.stdin.readline().rstrip()\r\nfrom collections import defaultdict\r\n\r\nN,M = map(int, input().split())\r\nP = [[] for _ in range(N)]\r\nfor _ in range(M):\r\n a,b = map(int, input().split())\r\n P[a-1].append(b-1)\r\n P[b-1].append(a-1)\r\n\r\nseen = [-1]*N\r\ndef paint(idx, color):\r\n v = [idx]\r\n cnt = 0\r\n while v:\r\n i = v.pop()\r\n if seen[i]!=-1:continue\r\n cnt+=1\r\n seen[i] = color\r\n \r\n if cnt>3:\r\n exit(print(-1))\r\n \r\n \r\n for j in P[i]:\r\n if seen[j]==-1:\r\n v.append(j)\r\n \r\ncolor = 1\r\nfor i in range(N):\r\n if seen[i]==-1:\r\n paint(i, color)\r\n color+=1\r\n\r\nlib = defaultdict(list)\r\nfor i in range(N):\r\n lib[seen[i]].append(i+1)\r\n\r\nans = []\r\nc1,c2=[],[]\r\nfor k,v in lib.items():\r\n if len(v)==1:\r\n c1.append(v)\r\n elif len(v)==2:\r\n c2.append(v)\r\n else:\r\n ans.append(v)\r\n\r\nfor v in c2:\r\n if not c1:\r\n exit(print(-1))\r\n ans.append(v+c1.pop())\r\nif len(c1)%3:\r\n exit(print(-1))\r\n\r\nfor i in range(0,len(c1),3):\r\n ans.append(c1[i]+c1[i+1]+c1[i+2])\r\nfor a in ans:\r\n print(*a)\r\n\r\n ", "'''input\r\n3 3\r\n1 2\r\n2 3\r\n1 3\r\n\r\n'''\r\nimport sys\r\ninput = sys.stdin.readline\r\ndef getstr(): return input().rstrip('\\r\\n')\r\ndef getint(): return int(input().strip())\r\ndef getints(): return list(map(int, input().strip().split()))\r\ndef impossible(): print(-1),exit(0)\r\n\r\nn,m = getints()\r\n\r\nif m == 0:\r\n\tj = 1\r\n\tfor i in range(n//3):\r\n\t\tprint(*[j, j+1, j+2])\r\n\t\tj+=3\r\n\texit(0)\r\n\r\nteams = [set() for _ in range(n//3)]\r\nu = []\r\nempty = 0\r\nfor i in range(m):\r\n\ta,b = getints()\r\n\tfor s in teams:\r\n\t\tif a in s or b in s:\r\n\t\t\ts.add(a)\r\n\t\t\ts.add(b)\r\n\t\t\tif len(s)>3: impossible()\r\n\t\t\tbreak\r\n\telse: #new team\r\n\t\tif empty>=n//3: impossible()\r\n\t\tteams[empty].add(a)\r\n\t\tteams[empty].add(b)\r\n\t\tempty += 1\r\n\r\n\r\nu = set()\r\nfor s in teams:\r\n\tu = u.union(s)\r\nu = list(sorted(set(range(1,n+1)) - u))\r\ni = 0\r\nfor s in teams:\r\n\twhile len(s)<3:\r\n\t\tif i>=len(u): impossible()\r\n\t\ts.add(u[i])\r\n\t\ti+=1\r\n\tprint(*s)\r\n", "def dfs(graph, u, visited, comp, actual_team):\r\n if not visited[u]:\r\n actual_team.append(u)\r\n visited[u] = True\r\n for v in range(len(graph)):\r\n if not visited[v] and graph[u][v] == 1:\r\n comp[0] += 1\r\n dfs(graph, v, visited, comp, actual_team)\r\n\r\n\r\nn, m = map(int, input().split())\r\ngraph = [[0] * n for _ in range(n)]\r\nfor _ in range(m):\r\n a, b = map(int, input().split())\r\n graph[a - 1][b - 1] = 1\r\n graph[b - 1][a - 1] = 1\r\ncomponents = [0, 0, 0]\r\nteams = [[], [], []]\r\nvisited = [False] * len(graph)\r\nflag = False\r\nfor i in range(len(graph)):\r\n comp = [1]\r\n actual_team = []\r\n dfs(graph, i, visited, comp, actual_team)\r\n if comp[0] >= 4:\r\n flag = True\r\n break\r\n elif len(actual_team) > 0:\r\n components[comp[0] - 1] += 1\r\n teams[comp[0] - 1].append(actual_team)\r\nif flag or (not flag and components[1] > components[0]):\r\n print(-1)\r\nelse:\r\n for i in range(len(teams[2])):\r\n print(teams[2][i][0] + 1, teams[2][i][1] + 1, teams[2][i][2] + 1, )\r\n idx = 0\r\n for i in range(len(teams[1])):\r\n print(teams[1][i][0] + 1, teams[1][i][1] + 1, teams[0][idx][0] + 1)\r\n idx += 1\r\n count = 0\r\n for i in range(idx, len(teams[0])):\r\n if count == 3:\r\n count = 0\r\n print('\\n')\r\n print(teams[0][i][0] + 1, end=\" \")\r\n count += 1", "from collections import defaultdict \r\nn,m=map(int,input().split())\r\nd=defaultdict(list)\r\nf=[False]*(n+1)\r\nv=[]\r\ndef dfs(i,s): \r\n\ts.add(i)\r\n\tf[i]=True \r\n\tfor k in d[i]:\r\n\t\tif not f[k]:\r\n\t\t\tdfs(k,s)\r\nfor j in range(m):\r\n\tx,y=map(int,input().split())\r\n\td[x].append(y)\r\n\td[y].append(x)\r\nfor i in range(1,n+1):\r\n\tif d[i] and not f[i]: \r\n\t\ts=set() \r\n\t\tdfs(i,s)\r\n\t\tif len(s)>3:\r\n\t\t\tprint(-1)\r\n\t\t\texit() \r\n\t\tv.append(list(s)) \r\nif len(v)>(n//3):\r\n\tprint(-1)\r\n\texit() \r\nwhile len(v)<(n//3):\r\n\tv.append([])\r\nj=0\r\nfor i in range(1, n + 1):\r\n\tif not f[i]:\r\n\t\twhile len(v[j]) == 3:\r\n\t\t\tj += 1\r\n\t\tv[j].append(i)\r\nfor i in v:\r\n\tprint(i[0],i[1],i[2])", "import sys\r\ninput = sys.stdin.readline\r\n\r\n############ ---- Input Functions ---- ############\r\ndef inp():\r\n return(int(input()))\r\ndef inlt():\r\n return(list(map(int,input().split())))\r\ndef insr():\r\n s = input()\r\n return(list(s[:len(s) - 1]))\r\ndef invr():\r\n return(map(int,input().split()))\r\n############ ---- Input Functions ---- ############\r\n\r\ndef Coach():\r\n def do_dfs(startNode,path):\r\n visited[startNode-1] = True \r\n path.append(startNode)\r\n \r\n if startNode in neighbours.keys():\r\n for node in neighbours[startNode]:\r\n if visited[node-1] == False:\r\n do_dfs(node,path)\r\n \r\n return path\r\n\r\n n,m = invr()\r\n \r\n neighbours = {}\r\n for i in range(m):\r\n node1,node2 = invr()\r\n if node1 not in neighbours.keys():\r\n neighbours[node1] = []\r\n if node2 not in neighbours.keys():\r\n neighbours[node2] = []\r\n \r\n neighbours[node1].append(node2)\r\n neighbours[node2].append(node1)\r\n\r\n visited = [False]*n\r\n distict_nodes = [x for x in range(1,n+1)] #1 to n\r\n\r\n three_nodes = []\r\n two_nodes = []\r\n one_node = []\r\n\r\n while(True):\r\n if False in visited:\r\n unvisited_node = visited.index(False) + 1 \r\n path = []\r\n path_obtained = do_dfs(unvisited_node,path)\r\n\r\n if len(path_obtained) > 3:\r\n print(-1)\r\n return \r\n elif len(path_obtained) == 3:\r\n three_nodes.append(path_obtained)\r\n elif len(path_obtained) == 2:\r\n two_nodes.append(path_obtained)\r\n else:\r\n one_node.append(path_obtained)\r\n\r\n else:\r\n break\r\n \r\n if len(two_nodes) > len(one_node):\r\n print(-1)\r\n return \r\n else:\r\n outputStr = ''\r\n for i in three_nodes:\r\n outputStr += str(i[0]) + ' ' + str(i[1]) + ' ' + str(i[2]) +'\\n'\r\n\r\n index = 0\r\n while index <= len(two_nodes)-1:\r\n outputStr += str(two_nodes[index][0]) + ' ' + str(two_nodes[index][1]) + ' ' + str(one_node[index][0]) + '\\n'\r\n index += 1 \r\n \r\n while index <= len(one_node)-1:\r\n outputStr += str(one_node[index][0]) + ' ' + str(one_node[index+1][0]) + ' ' + str(one_node[index+2][0]) + '\\n'\r\n index += 3\r\n \r\n outputStr = outputStr.strip()\r\n print(outputStr)\r\n return\r\n\r\n\r\nCoach()", "N = 64\r\n \r\ndef dfs(u):\r\n x = [u]\r\n c.add(u)\r\n for v in I:\r\n if g[u][v] and v not in c:\r\n x += dfs(v)\r\n return x\r\nn, m = map(int,input().split())\r\ng = [[0]*N for _ in range(N)]\r\nfor _ in range(m):\r\n u, v = map(int,input().split())\r\n g[u][v] = g[v][u] = True\r\nv = [[],[],[],[]]\r\nc = set()\r\nI = range(1, n+1)\r\nfor i in I:\r\n if i not in c:\r\n x = dfs(i)\r\n l = len(x)\r\n if l > 3:\r\n exit(print(-1))\r\n v[l] += [x]\r\nfor x in v[2]:\r\n if v[1]: v[3] += [x+v[1].pop()]\r\n else: exit(print(-1))\r\nif len(v[1])%3: exit(print(-1))\r\nwhile v[1]: v[3] += [v[1].pop()+v[1].pop()+v[1].pop()]\r\nfor x in v[3]: print(' '.join(map(str, x)))", "n, m = map(int, input().split())\n\n\nvisited = [False for i in range(n)]\n\n\ng = [[] for _ in range(n)]\nfor _ in range(m):\n a, b = map(int, input().split())\n g[a-1].append(b-1)\n g[b-1].append(a-1)\n\ndef dfs(x, s):\n s.add(x)\n visited[x] = True\n for adj in g[x]:\n if not visited[adj]:\n dfs(adj, s)\n\n\ngroups = []\nfor i in range(n):\n if g[i] and not visited[i]:\n s = set()\n\n dfs(i, s)\n\n if len(s) > 3:\n print(-1)\n exit()\n \n groups.append(list(s))\n\nif len(groups) > n//3:\n print(-1)\n exit()\n\nwhile len(groups) < n // 3:\n groups.append([])\n\n\ncurrent_v = 0\n\nfor i in range(n):\n if not visited[i]:\n while len(groups[current_v]) == 3:\n current_v += 1\n \n groups[current_v].append(i)\n\nfor g in groups:\n print(\" \".join(map(lambda x: str(x+1), g)))\n" ]
{"inputs": ["3 0", "6 4\n1 2\n2 3\n3 4\n5 6", "3 3\n1 2\n2 3\n1 3", "6 3\n1 2\n3 4\n5 6", "15 9\n1 4\n1 6\n2 7\n2 11\n4 6\n5 12\n7 11\n9 14\n13 15", "3 1\n1 3", "15 13\n1 9\n1 11\n2 7\n2 12\n3 8\n3 15\n4 10\n5 6\n5 14\n6 14\n7 12\n8 15\n9 11", "36 27\n1 34\n2 18\n2 20\n3 9\n3 21\n4 5\n4 25\n5 25\n6 13\n6 22\n8 23\n8 31\n9 21\n10 14\n11 17\n11 19\n13 22\n15 24\n15 26\n17 19\n18 20\n23 31\n24 26\n28 29\n28 33\n29 33\n32 36", "18 12\n1 10\n2 4\n2 8\n3 15\n3 18\n4 8\n5 6\n9 13\n12 14\n12 16\n14 16\n15 18", "39 27\n1 2\n1 25\n2 25\n4 16\n5 22\n5 28\n6 7\n6 26\n7 26\n8 24\n10 31\n10 38\n11 17\n11 21\n12 35\n12 37\n13 34\n17 21\n18 23\n19 39\n22 28\n27 29\n27 36\n29 36\n31 38\n32 33\n35 37", "12 7\n1 2\n4 5\n6 12\n7 8\n9 10\n9 11\n10 11", "33 22\n3 9\n3 28\n4 12\n5 11\n5 31\n6 18\n8 15\n8 29\n9 28\n10 22\n11 31\n13 14\n15 29\n16 23\n16 27\n17 25\n17 32\n19 21\n20 30\n23 27\n24 33\n25 32", "18 8\n1 14\n2 16\n4 7\n5 11\n8 9\n8 12\n9 12\n10 18", "27 21\n1 3\n2 9\n2 11\n5 16\n5 25\n7 26\n8 14\n8 22\n9 11\n10 17\n10 27\n12 21\n13 20\n13 23\n14 22\n15 18\n15 19\n16 25\n17 27\n18 19\n20 23", "24 21\n1 14\n2 6\n3 4\n3 19\n4 19\n5 7\n5 21\n7 21\n8 18\n8 23\n9 15\n9 16\n10 12\n10 17\n11 22\n12 17\n13 20\n13 24\n15 16\n18 23\n20 24", "45 31\n1 5\n2 45\n3 29\n3 30\n4 16\n4 32\n6 40\n7 13\n7 25\n8 42\n10 31\n11 20\n11 26\n12 27\n12 34\n13 25\n14 24\n14 43\n15 36\n15 37\n16 32\n18 19\n18 33\n19 33\n20 26\n23 41\n24 43\n27 34\n28 39\n29 30\n36 37", "18 9\n1 16\n2 17\n4 6\n5 18\n7 8\n7 15\n8 15\n9 11\n10 13", "6 6\n1 6\n1 3\n3 6\n2 4\n4 5\n2 5", "48 48\n7 39\n39 45\n7 45\n25 26\n26 31\n25 31\n4 11\n11 19\n4 19\n8 16\n16 37\n8 37\n14 22\n22 33\n14 33\n6 12\n12 46\n6 46\n29 44\n44 48\n29 48\n15 27\n27 41\n15 41\n3 24\n24 34\n3 34\n13 20\n20 47\n13 47\n5 9\n9 36\n5 36\n21 40\n40 43\n21 43\n2 35\n35 38\n2 38\n23 28\n28 42\n23 42\n1 10\n10 32\n1 32\n17 18\n18 30\n17 30", "12 9\n1 2\n2 4\n1 3\n5 6\n6 8\n5 7\n9 10\n10 12\n9 11", "9 7\n1 2\n3 4\n5 6\n7 8\n2 3\n2 5\n2 7", "9 3\n4 5\n6 7\n8 9", "6 2\n3 4\n5 6", "9 7\n1 2\n2 3\n1 3\n4 5\n4 6\n4 7\n4 8", "6 1\n1 2", "48 1\n1 2"], "outputs": ["3 2 1 ", "-1", "3 2 1 ", "-1", "6 4 1 \n11 7 2 \n12 5 3 \n14 9 8 \n15 13 10 ", "3 2 1 ", "11 9 1 \n12 7 2 \n14 6 5 \n15 8 3 \n13 10 4 ", "19 17 11 \n20 18 2 \n21 9 3 \n22 13 6 \n25 5 4 \n26 24 15 \n31 23 8 \n33 29 28 \n14 10 7 \n34 12 1 \n36 32 16 \n35 30 27 ", "8 4 2 \n16 14 12 \n18 15 3 \n7 6 5 \n11 10 1 \n17 13 9 ", "21 17 11 \n25 2 1 \n26 7 6 \n28 22 5 \n36 29 27 \n37 35 12 \n38 31 10 \n16 4 3 \n23 18 9 \n24 14 8 \n33 32 15 \n34 20 13 \n39 30 19 ", "-1", "-1", "12 9 8 \n7 4 3 \n11 6 5 \n14 13 1 \n16 15 2 \n18 17 10 ", "11 9 2 \n19 18 15 \n22 14 8 \n23 20 13 \n25 16 5 \n27 17 10 \n4 3 1 \n21 12 6 \n26 24 7 ", "-1", "25 13 7 \n26 20 11 \n30 29 3 \n32 16 4 \n33 19 18 \n34 27 12 \n37 36 15 \n43 24 14 \n9 5 1 \n31 17 10 \n39 28 21 \n40 22 6 \n41 35 23 \n42 38 8 \n45 44 2 ", "-1", "5 4 2 \n6 3 1 ", "19 11 4 \n30 18 17 \n31 26 25 \n32 10 1 \n33 22 14 \n34 24 3 \n36 9 5 \n37 16 8 \n38 35 2 \n41 27 15 \n42 28 23 \n43 40 21 \n45 39 7 \n46 12 6 \n47 20 13 \n48 44 29 ", "-1", "-1", "5 4 1 \n7 6 2 \n9 8 3 ", "4 3 1 \n6 5 2 ", "-1", "3 2 1 \n6 5 4 ", "3 2 1 \n6 5 4 \n9 8 7 \n12 11 10 \n15 14 13 \n18 17 16 \n21 20 19 \n24 23 22 \n27 26 25 \n30 29 28 \n33 32 31 \n36 35 34 \n39 38 37 \n42 41 40 \n45 44 43 \n48 47 46 "]}
UNKNOWN
PYTHON3
CODEFORCES
17
210b0dcb71762d4b15aa74549a099ce5
Compote
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has. Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. Sample Input 2 5 7 4 7 13 2 3 2 Sample Output 7 21 0
[ "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nans = 0\r\nfor aa in range(a + 1):\r\n bb, cc = 2 * aa, 4 * aa\r\n if bb <= b and cc <= c:\r\n ans = aa + bb + cc\r\nprint(ans)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\n\r\na, p = a//2, p//4\r\nm = min(a,l,p)\r\nprint(m*1 + m*2 + m*4)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ncount=0\r\nfor i in range(a):\r\n if a>=1 and b>=2 and c>=4:\r\n a-=1\r\n b-=2\r\n c-=4\r\n count+=1\r\nif count!=0:\r\n print(7*count)\r\nelse:\r\n print(0)\r\n\r\n", "l = int(input())\r\na = int(input())\r\np = int(input())\r\n\r\nm = min(l, a // 2, p // 4)\r\nprint(sum([m, m * 2, m * 4]))", "x = int(input())\ny = int(input())\nz = int(input())\ny = y // 2\nz = z // 4\nmin = min(min(x, y), z)\nprint(min * 7)\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\ntotal = 0\r\nfor i in range(1000):\r\n if b >= 2*a and c >= 4*a and a > 0:\r\n b = (2*a)\r\n c = (4*a)\r\n total = (a+b+c)\r\n\r\n else:\r\n a -= 1\r\n\r\nprint(total)", "lemon=int(input()) ; apple=int(input()) ; pears=int(input())\r\nleft=0 ; right=lemon\r\nwhile left<=right:\r\n mid=(right+left)//2\r\n if mid*2<=apple and mid *4<=pears:\r\n left=mid+1 ; ans=mid\r\n else:\r\n right=mid-1\r\nprint(ans+ans*2+ans*4)\r\n \r\n ", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nd=(min(a,b//2,c//4))*7\r\nprint(d)\r\n", "a=int(input())\nb=int(input())\nc=int(input())\nb//=2\nc//=4\ns=0\nfor i in range(min(a,b,c)):\n s+=1\n s+=2\n s+=4\nprint(s)\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ny = b//2\r\nz = c//4\r\nn = min(a, y, z)\r\nprint(n * 7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nk = min(a, b//2, c//4)\r\nprint(k*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n# assume each 1:2:4 = 1 liter of kompot\r\nliters = min(a // 1, b // 2, c // 4)\r\nprint(liters*7)\r\n\r\n", "from sys import stdin, stdout\r\ndef read():\r\n\treturn stdin.readline().rstrip()\r\n\r\ndef read_int():\r\n\treturn int(read())\r\n \r\ndef read_ints():\r\n\treturn list(map(int, read().split()))\r\n \r\ndef solve():\r\n\ta=read_int()\r\n\tb=read_int()\r\n\tc=read_int()\r\n\tprint(7*min([a, b//2, c//4]))\r\n\r\nsolve()\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nprint(min(a, b//2, c//4)*7)\r\n", "a, b, c = int(input()), int(input()), int(input())\r\napples = a\r\nlemons = b // 2\r\npears = c // 4\r\nprint(min(apples, lemons, pears) * 7)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ndiff1 = a // 1\r\ndiff2 = b // 2\r\ndiff3 = c // 4\r\ncheck = [diff1,diff2,diff3]\r\nfinal = min(check)\r\nprint(7*final)\r\n\r\n", "a = int(input())\nb = int(input())\nc = int(input())\nx = a // 1\ny = b // 2\nw = c // 4\nq = min(x, min(y,w))\nprint(q*(1+2+4))\n \t\t \t \t\t\t\t\t\t\t \t \t\t", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nd=c//4\r\nd=min(d,b//2)\r\nd=min(d,a)\r\nprint(1*d + 2*d + 4*d)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nLm,Ap,PE=0,0,0\r\nif 1<=a and a<=1000 and 1<=b and b<=1000 and 1<=c and c<=1000:\r\n\tfor i in range(1,a+1):\r\n\t\tif i*2<=b and i*4<=c:\r\n\t\t\tLm,Ap,PE=i,i*2,i*4\r\n\t\telse:\r\n\t\t\tbreak\r\n\tprint(Lm+Ap+PE)\r\n\t\t\t", "import math\na = int(input())\nb = int(input())\nc = int(input())\n\nresult = 0\nif a <= math.floor(b/2) and a <= math.floor(c/4):\n result = 7*a\nelif math.floor(b/2) <= a and math.floor(b/2) <= math.floor(c/4):\n result = math.floor(b/2) * 7\nelif math.floor(c/4) <= math.floor(b/2) and math.floor(c/4) <= a:\n result = math.floor(c/4) * 7\n\nprint(result)\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nabatch = a\r\nbbatch = b//2\r\ncbatch = c//4\r\nmini = min(abatch,bbatch,cbatch)\r\nprint(mini*7)", "import math\r\n\r\n\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\nd=min(a,int(math.floor(b/2)),int(math.floor(c/4)))\r\nprint(d*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nprint(min(a,b//2,c//4)*7)", "l=int(input())\r\na=int(input())\r\np=int(input())\r\nwhile (((l*2)>a or (l*4)>p) and l>0):\r\n l=l-1\r\nprint(l*7)\r\n ", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nstep = 0\r\nwhile step <= a and step*2 <= b and step*4 <= c:\r\n step += 1\r\nprint((step-(step > a or step*2 > b or step*4 > c))*7)\r\n", "def main(a,b,c):\r\n b//=2\r\n c//=4\r\n return min([a,b,c])*7\r\n\r\nprint(main(int(input()),int(input()),int(input())))", "a = int(input())\nb = int(input())\nc = int(input())\na2 = a//1\nb2 = b//2\nc2 = c//4\nx = min(a2,b2,c2)\nprint (x*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\ndef solve(a, b, c):\r\n res, rem = divmod(c, 4)\r\n res2, rem2 = divmod(b, 2)\r\n if res == 0 or res2 == 0: return 0\r\n return 7 * min(res, res2, a)\r\n\r\nprint(solve(a, b, c))", "a = int(input())\nb = int(input())\nc = int(input())\nminium = min(a, b//2, c//4)\nprint(minium*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nb = b//2\r\nc = c//4\r\nans = min(a,b,c)\r\nprint(ans+ans*2+ans*4)", "a = int(input())\nb = int(input())\nc = int(input())\nn = min(a, b // 2, c // 4)\nprint(n + 2*n + 4*n)\n", "import math\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nsum = 0\r\nwhile a>=1 and b>=2 and c>=4:\r\n sum+=7\r\n a-=1\r\n b-=2\r\n c-=4\r\nprint(sum)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\n\r\nel = min(a//2, p//4)\r\nrl = min(l, el)\r\nres = rl + rl*2 + rl*4\r\nprint(res)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nk = min(a, b//2, c//4)\r\nprint(7 * k)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nd = min(a, b // 2, c // 4)\r\nprint(d * 7)\r\n \r\n", "#Compote\r\nmax=0\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\na1=min(a,int(b/2),int(c/4))\r\nprint(a1*7)", "import sys\r\n\r\ninput = sys.stdin.readline\r\n\r\na, b, c = [int(input()) for _ in range(3)]\r\nprint(min(a, b // 2, c // 4) * 7)", "n=int(input())\r\nm=int(input())\r\nl=int(input())\r\ncount=0\r\nwhile(n>=1 and m>=2 and l>=4):\r\n n-=1\r\n m-=2\r\n l-=4\r\n count+=7\r\nprint(count)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\nz = 0\r\nwhile(l >= 1 and a >= 2 and p >= 4):\r\n l = l-1\r\n a = a-2\r\n p = p-4\r\n z += 1\r\nprint(7*z)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nb=b//2\r\nc=c//4\r\nd= min(a,b,c)*7\r\nprint(d)", "from math import floor\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nif b < 2 or c < 4:\r\n print(0)\r\nelse:\r\n b = floor(b / 2)\r\n c = floor(c / 4)\r\n d = min(a, b, c)\r\n print(d * 1 + d * 2 + d * 4)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nprint(7*min(a,b//2,c//4))\t\t", "import sys\r\n\r\na,b,c=int(input()),int(input()),int(input())\r\ncomp=min(a,b//2,c//4)\r\nprint(7*comp)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nx = min(a,b//2,c//4)\r\nprint(x+2*x+4*x)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\ncompotes = min(a, b // 2, c // 4)\r\n\r\ntotal_lemons = compotes\r\ntotal_apples = compotes * 2\r\ntotal_pears = compotes * 4\r\n\r\nprint(total_lemons + total_apples + total_pears)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nfruit = 0\r\nwhile a > 0:\r\n if b >= 2*a and c >= 4*a:\r\n fruit = a+2*a+4*a\r\n a = a - 1\r\n b = b - 2*a\r\n c = c - 4*c\r\n else:\r\n a = a - 1\r\nprint(fruit)", "print(min(int(input()), int(input()) // 2, int(input()) // 4) * 7)", "a=int(input());b=int(input());c=int(input());x=0\r\nwhile a>=1 and b>=2 and c>=4:\r\n x+=7\r\n a-=1;b-=2;c-=4\r\nif x>0:\r\n print(x)\r\nelse:\r\n print(0)\r\n", "list1 = []\r\nfor i in range(3):\r\n list1.append(int(input()))\r\n \r\nlemons = list1[0]\r\napples = list1[1]\r\npears = list1[-1]\r\n\r\nstart = 1\r\ncount1= 0\r\ncount2 = 0\r\nb1 = False\r\nwhile b1==False:\r\n if start * 2 > apples or start * 4 > pears or start > lemons:\r\n print(start + count1 + count2-1)\r\n break\r\n if start * 2 <= apples and start *4 <= pears:\r\n count1 = start*2\r\n count2 = start*4\r\n start+=1\r\n \r\n ", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\n\r\ndef compote_maker(lemons, apples, pears):\r\n biggest = min(lemons, int(apples / 2), int(pears / 4))\r\n return biggest + (biggest * 2) + (biggest * 4)\r\n\r\n\r\nprint(compote_maker(a, b, c))", "a_str=input()\na=int(a_str)\na=a*7\nb_str=input()\nb=int(b_str)\nb=b//2*7\nc_str=input()\nc=int(c_str)\nc=c//4*7\nif a<=b:\n if a<=c:\n print(a)\n else:\n print(c)\nelse:\n if b<=c:\n print(b)\n else:\n print(c)\n\t\t\t\t \t\t\t\t \t\t \t \t\t \t\t \t\t \t", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nx = a\r\ny = b//2\r\nz = c//4\r\nn = min(x,y,z)\r\nprint(n*7)", "a = int(input())\nb = int(input())\nc = int(input())\nprint(7 * min(a, b >> 1, c >> 2))\n", "print(min([int(input())//(2**i) for i in range(3)])*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ny = max(a,b,c)\r\ntotal = 0\r\nfor i in range (y):\r\n if a >= 1 and b >= 2 and c >= 4 :\r\n a = a - 1\r\n b = b - 2\r\n c = c - 4\r\n total = total + 1 + 2 + 4\r\n else:\r\n break\r\nprint(total)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nb=b//2\r\nc=c//4\r\ng=min(a,b,c)\r\nprint(g*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\na = a//1\r\nb = b//2\r\nc = c//4\r\n\r\ng = min(a,b,c)\r\n\r\nprint(g*7)", "a = int(input())\r\nb = int(input())\r\nw = int(input())\r\nz = a // 1\r\nx = b // 2\r\nc = w // 4\r\nprint(7 * min(z, x, c))", "a, b, c = map(int, open(0))\nprint(min(a // 1, b // 2, c // 4) * 7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nif(b<2 or c<4):\r\n print(\"0\")\r\nelse:\r\n temp=0\r\n while(a>=1 and b>=2 and c>=4):\r\n temp+=7\r\n a-=1 \r\n b-=2\r\n c-=4 \r\n print(temp) ", "a=input()\r\na=int(a)\r\n\r\nb=input()\r\nb=int(b)\r\n\r\nc=input()\r\nc=int(c)\r\n\r\ncnt=0\r\nwhile a>=1 and b>=2 and c>=4 :\r\n cnt+=7\r\n a-=1\r\n b-=2\r\n c-=4\r\n\r\nprint(cnt)", "if __name__ == '__main__':\r\n aa = []\r\n for i in range(3):\r\n aa.append(int(input()) // (2 ** i))\r\n print(min(aa) * 7)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ncnt=0\r\nif a<1 and b<2 and c<4:\r\n print(cnt)\r\nelse:\r\n b=b//2\r\n c=c//4\r\n t=min(a,b,c)\r\n t*=7\r\n print(t)\r\n\r\n\r\n \r\n", "#problem37\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nx = min(a,b//2,c//4)\r\nprint(x*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ns = min(a//1, b//2, c//4)\r\nans = s*7\r\nprint(ans)\r\n", "# https://codeforces.com/problemset/problem/746/A\r\n\r\n# input -->\r\n# a ~~ number of lemons\r\n# b ~~ number of apples\r\n# c ~~ number of pears\r\n\r\n# to cook the compote the fruit ratios have to be 1:2:4 respectively\r\n# output --> totall of used fruits\r\nimport math\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\na_ratio, b_ratio, c_ratio = math.floor(a/1), math.floor(b/2), math.floor(c/4)\r\n\r\nn_compote = min(a_ratio, b_ratio, c_ratio)\r\n\r\nprint(1*n_compote+2*n_compote+4*n_compote)\r\n\r\n\r\n", "cnt=0;l=int(input());a=int(input());p=int(input())\r\nwhile l>=1 and a>=2 and p>=4:\r\n if l>=1 and a>=2 and p>=4:\r\n l=l-1;a=a-2;p=p-4\r\n cnt+=7\r\nprint(cnt)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nb,c = b-(b%2),c-(c%4)\r\ncc=0\r\nfor i in range(a):\r\n if a>=1 and b>=2 and c>=4:\r\n a,b,c = a-1,b-2,c-4\r\n cc+=1\r\n else:\r\n break\r\nprint(cc*7)", "a=int(input());b=int(input());c=int(input())\r\nprint(7*min(a,b>>1,c>>2))", "lemon = int(input())\r\napple = int(input())\r\npear = int(input())\r\na, b, c = 0, 0, 0\r\nif lemon<1 or apple<2 or pear<4:\r\n print(\"0\")\r\nelse:\r\n while lemon>=1 and apple>=2 and pear>=4:\r\n a, b, c = a+1, b+2, c+4\r\n lemon, apple, pear = lemon-1, apple-2, pear-4\r\n print(a+b+c)", "import math\r\ndef solve(a,b,c,):\r\n minx = min(a//1 , b//2 , c//4)\r\n return minx*7\r\n# n,k = map(int,input().split())\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\n# l = list(map(int,input().split()))\r\n# n = int(input())\r\nprint(solve(a,b,c))\r\n\r\n\r\n\r\n\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif b < 2 or c < 4:\r\n print(0)\r\nelse:\r\n b = b // 2\r\n c = c // 4\r\n if min(a, b, c) == a:\r\n sum = a + a * 2 + a * 4\r\n print(sum)\r\n elif min(a, b, c) == b:\r\n sum = b + b * 2 + b * 4\r\n print(sum)\r\n else:\r\n sum = c + c * 2 + c * 4\r\n print(sum)", "a=int(input())\nb=int(input())\nc=int(input())\nprint (min(a,int(b/2),int(c/4))*7)\n\t \t \t \t \t \t\t\t\t \t\t \t", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nx = min(a, b // 2, c // 4)\r\n\r\nprint(x*7)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\naa=a//1\r\nbb=b//2\r\ncc=c//4\r\nprint(min(aa,bb,cc)*7)", "a, b, c = int(input()), int(input()), int(input())\r\n\r\nprint(7*min(a, b // 2, c // 4))", "def solve(s,ba,bu):\r\n tmp=min(s,ba//2,bu//4)\r\n ans=tmp*7\r\n return ans\r\n\r\ns=int(input())\r\nba=int(input())\r\nbu=int(input())\r\nprint(solve(s,ba,bu))\r\n", "# cook your dish here\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nres = min(min(a,b//2), c//4)\r\nprint(res*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nx=min(c//4,b//2,a)\r\nprint(4*x+2*x+x)", "# coding=utf-8\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\ns=0\r\nwhile a>=1 and b>=2 and c>=4:\r\n s+=7\r\n a-=1\r\n b-=2\r\n c-=4\r\nprint(s)\r\n\n\t\t\t\t\t \t \t\t \t \t \t \t \t", "lemons = int(input())\napples = int(input())\npear = int(input())\nfound = False\nfor i in range(lemons, 0, -1):\n if i * 2 <= apples and i * 4 <= pear:\n found = True\n break \n\nif found:\n print(i + i *2 + i * 4)\nelse:\n print(0)", "lemons = int(input())\napples = int(input())\npears = int(input())\n\nvar1 = lemons\nvar2 = apples // 2\nvar3 = pears // 4\n\nbatch = min(var1, var2, var3)\n\nprint(batch * 7)\n\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nif (b < 2) or (c < 4):\r\n print(0)\r\nelse:\r\n net = 0\r\n i, j, k = 0, 0, 0\r\n while i < a and j < b and k < c:\r\n if (i + 1 <= a) and (j + 2 <= b) and (k + 4 <= c):\r\n i += 1\r\n j += 2\r\n k += 4\r\n net += 7\r\n else:\r\n break\r\n \r\n print(net)", "# LUOGU_RID: 101648104\na, b, c = map(int, open(0).read().split())\r\nb //= 2\r\nc //= 4\r\nprint(min(a, b, c) * 7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nb //= 2\r\nc //= 4\r\n\r\ncompote_max = min(a, b, c) * 7\r\nprint(compote_max)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nprint(7*(min(a, b//2, c//4)))", "a=int(input())\nb=int(input())\nc=int(input())\ng=0\nfor i in range(a,0,-1):\n if b>=2*i and c>=4*i:\n print(2*i+4*i+i)\n g=g+1\n break\nif g==0:\n print(0)\n \t\t\t\t \t\t\t \t \t \t\t\t\t \t\t\t \t \t\t", "a = int(input())\r\n\r\nb = int(input())\r\n\r\nc = int(input())\r\n\r\np = b - (b % 2)\r\n\r\nx = p//2 \r\n\r\nq = c - (c % 4)\r\n\r\ny = q//4 \r\n\r\nj = min(a, x, y) \r\n\r\nprint (j*7)", "#37\r\n\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\nc=c//4\r\nb=b//2\r\na=a//1\r\nprint(min(a,b,c)*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\n\r\nb=b//2\r\nc=c//4\r\ntemp=min([a,b,c])\r\n\r\nprint(temp*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\n\r\ncom = min(a, b//2, c//4)\r\nprint(7*com)", "a,b,c=int(input()),int(input()),int(input())\r\ne=2*a\r\nf=4*a\r\nwhile b<e or c<f:\r\n a-=1\r\n e,f=2*a,4*a\r\nprint(a+e+f)\r\n", "l, a, p = int(input()), int(input()), int(input())\narr = [l, a//2, p//4]\n\nans = 0\n\nif arr.index(min(arr)) == 0:\n print(l * 7)\n\nelif arr.index(min(arr)) == 1:\n print((a//2) * 7)\n\nelif arr.index(min(arr)) == 2:\n print((p//4) * 7)\n\n\n\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\na //= 1 \r\nb //= 2\r\nc //= 4\r\nm = min(a,b,c)\r\nprint(m * 7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nd=0\r\nfor i in range(a,-1,-1):\r\n if i*2<=b and i*4<=c:\r\n d=i\r\n break\r\nif d==0:print(0)\r\nelse:print(d*7)\r\n", "a, b, c = int(input()), int(input()), int(input())\r\nprint(min([a, b//2, c//4])*7)", "l = int(input())\r\na = int(input())//2\r\np = int(input())//4\r\n\r\nif l < 1 or a < 1 or p < 1:\r\n print(0)\r\nelse:\r\n mn = min(l,a,p)\r\n print(mn + mn*2 + mn*4)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nx=[a,b,c]\r\nt=a\r\nj=0\r\nwhile j<len(x):\r\n y=[t,t*2,t*4]\r\n for j in range(len(x)):\r\n if x[j]<y[j]:\r\n t-=1\r\n j=-1\r\n break\r\n j+=1 \r\nif y[0]==0:\r\n print(0)\r\nelse: \r\n print(sum(y))", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nif a>=1 and b>=2 and c>=4:\r\n b=b//2\r\n c=c//4\r\n compot = min(a,b,c)\r\n res= compot*7\r\n print(res)\r\nelse:\r\n print(0)", "import sys \r\ninput = sys.stdin.buffer.readline \r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nanswer = 0 \r\nfor i in range(2000):\r\n if i <= a and 2*i <= b and 4*i <= c:\r\n answer = max(answer, 7*i)\r\nsys.stdout.write(f'{answer}\\n')", "#Compote\r\n'''https://codeforces.com/contest/746/problem/A'''\r\n\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\nprint(7*(min(a, b//2, c//4)))", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nNumber_of_Compotes = int(min(a,b/2,c/4,))\r\n\r\nprint(Number_of_Compotes*7)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nb=b//2;c=c//4\r\nk=c if c<(a if a<b else b) else (a if a<b else b)\r\nprint(7*k)", "a,b,c=int(input()),int(input()),int(input())\r\nx=min(b//2,c//4,a)\r\nprint(7*x)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\n\r\nprint(min(l, a//2, p//4)*7)", "a = int(input())\np = int(input())\nl = int(input())\n\nprint(min(a, p//2, l//4) * 7)", "def max_fruits(a, b, c):\r\n p = 0\r\n while(a > 0 and b > 1 and c > 3):\r\n a = a - 1\r\n b = b - 2\r\n c = c - 4\r\n p = p + 7\r\n\r\n return p\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nresult = max_fruits(a, b, c)\r\nprint(result)", "lemons = int(input())\r\napples = int(input())\r\npears = int(input())\r\ntotal = 0\r\na = False \r\nwhile a == False:\r\n if lemons * 2 <= apples:\r\n total = lemons + (lemons * 2)\r\n if lemons * 4 <= pears:\r\n total = total + (lemons*4)\r\n a = True\r\n else:\r\n lemons = lemons - 1\r\n total = 0\r\n else:\r\n lemons = lemons - 1\r\n total = 0\r\n if lemons == 0:\r\n a = True\r\n total = 0\r\nprint(total)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nmax_fruits = min(a, b//2, c//4)\r\ntotal_lemons = max_fruits \r\ntotal_apples = max_fruits*2 \r\ntotal_pears = max_fruits*4 \r\nprint(total_lemons + total_apples + total_pears)\r\n", "def binarySearch(n, a):\n l = 0\n h = len(a)-1\n ans = 0\n while l <= h:\n mid = (l+h)//2\n if a[mid] == n:\n return 1\n elif a[mid] > n:\n h = mid - 1\n else:\n l = mid + 1\n return ans\n\nl, a, p = int(input()), int(input()), int(input())\nans = min(l, a//2, p//4)\nprint(ans*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ncounter = 0\r\nfor i in range(a):\r\n if a-1 >= 0 and b-2 >= 0 and c-4>=0:\r\n counter += 7\r\n a -= 1\r\n b -= 2\r\n c -= 4\r\nprint(counter)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\ncount = 0\r\n\r\nfor i in range(1,a+1):\r\n if a >= 1 and b >= 2 and c >= 4:\r\n a-=1\r\n b-=2\r\n c-=4\r\n count+=1\r\n else:\r\n break\r\n\r\nprint(count*1+count*2+count*4)\r\n", "l=int(input())\r\na=int(input())\r\np=int(input())\r\nprint(7*(int(min(l,a/2,p/4))))", "# Compote\na = int(input())\nb = int(input())\nc = int(input())\nx = min(a, b//2, c//4)\nprint(x*7)\n", "l=int(input())\na=int(input())\np=int(input())\nt=0\nwhile l>=1 and a>=2 and p>=4:\n t=t+7\n l-=1\n a-=2\n p-=4\nprint(t)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nsum = 0\r\nwhile a>=1 and b>=2 and c>=4:\r\n a-= 1\r\n b-= 2\r\n c-= 4\r\n sum += 7\r\n\r\nprint(sum)", "a = int(input())\r\nb = int(input()) // 2\r\nc = int(input()) // 4\r\n \r\nk = min(a, b, c)\r\nprint(k + k * 2 + k * 4)", "from sys import stdin, stdout\r\n \r\nintn = lambda : int(stdin.readline())\r\nstrs = lambda : stdin.readline()[:-1]\r\nlstr = lambda : list(stdin.readline()[:-1])\r\nmint = lambda : map(int, stdin.readline().split())\r\nlint = lambda : list(map(int, stdin.readline().split()))\r\nout = lambda x: stdout.write(str(x)+\"\\n\")\r\nout_ = lambda x: stdout.write(str(x)+\" \")\r\n\r\ndef main():\r\n a = intn()\r\n b = intn()//2\r\n c = intn()//4\r\n y = min(a,b,c)\r\n if y == 0:\r\n out(0)\r\n else:\r\n out(y*7)\r\n\r\nif __name__ == \"__main__\":\r\n main()", "a = int(input())\nb = int(input())\nc = int(input())\n\nx = min(a, b // 2, c // 4)\n\nprint(7 * x)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nknt = 0\r\nwhile a>=1 and b>=2 and c>=4:\r\n knt += 7\r\n a -= 1\r\n b -= 2\r\n c -= 4\r\nprint(knt)", "L = int(input())\r\nA = int(input())\r\nP = int(input())\r\n\r\nans = 0\r\n\r\nif L >= 1:\r\n for i in range(1, L+1):\r\n if A//i >= 2 and P//i >= 4:\r\n ans += 7\r\n else:\r\n break\r\n\r\nprint(ans)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ns=a+b+c\r\nt=0\r\nwhile(t<s and a>=0 and b>=0 and c>=0):\r\n t+=1\r\n a-=1\r\n t+=2\r\n b-=2\r\n t+=4\r\n c-=4\r\n \r\nif a<0 or b<0 or c<0:\r\n print(t-7)\r\nelse:\r\n print(t)", "a = int(input())\nb = int(input())\nc = int(input())\nd = min(a, b//2, c//4)\nprint(d*7)", "n=int(input())\r\nm=int(input())\r\nd=int(input())\r\nr=0\r\nfor i in range(n):\r\n if n>=1 and m>=2 and d>=4:\r\n n-=1\r\n m-=2\r\n d-=4\r\n r+=7\r\nprint(r)", "a,b,c = int(input()),int(input()),int(input())\r\nif 2*a <= b and 4*a <=c:print(a+(2*a)+(4*a))\r\nelse:\r\n b = b//2\r\n c = c//4\r\n print(min(c + (c*2) + (c*4),b + (b*2) + (b*4)))", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\n\r\n#1:2:4\r\n\r\nn=min(a,b//2,c//4)\r\n\r\nprint(7*n)\r\n\r\n\r\n", "a = int(input().strip())\nb = int(input().strip())\nc = int(input().strip())\n\nfruits = 0\nwhile a - 1 >= 0 and b - 2 >= 0 and c - 4 >= 0:\n fruits += 7\n a -= 1\n b -= 2\n c -= 4\nprint(fruits)", "a = int(input())\nb = int(input())\nc = int(input())\nfor i in reversed(range(1,a+1)):\n\tif 2 * i <= b and 4 * i <= c:\n\t\tprint (7 * i)\n\t\texit(0)\nprint (0)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nv=min(a,int(b/2),int(c/4))\r\nprint(7*v)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ny = 7 * min(a, b // 2, c // 4)\r\nprint(y)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nsum_f=0\r\nwhile a>0 and b>1 and c>3:\r\n a-=1\r\n b-=2\r\n c-=4\r\n sum_f+=7\r\nprint(sum_f)\r\n", "import sys\r\nimport math\r\nfrom collections import defaultdict,Counter,deque\r\n \r\ninput = sys.stdin.readline\r\n \r\ndef I():\r\n return input()\r\n \r\ndef II():\r\n return int(input())\r\n \r\ndef MII():\r\n return map(int, input().split())\r\n \r\ndef LI():\r\n return list(input().split())\r\n \r\ndef LII():\r\n return list(map(int, input().split()))\r\n \r\ndef GMI():\r\n return map(lambda x: int(x) - 1, input().split())\r\n \r\ndef LGMI():\r\n return list(map(lambda x: int(x) - 1, input().split()))\r\n \r\ndef WRITE(out):\r\n return print('\\n'.join(map(str, out)))\r\n \r\ndef WS(out):\r\n return print(' '.join(map(str, out)))\r\n \r\ndef WNS(out):\r\n return print(''.join(map(str, out)))\r\n\r\n'''\r\ni k j\r\ndistance between i k and k j must be the same\r\n\r\nsort\r\ncreate set\r\n\r\nfor i k check if j in set? o(n^2)\r\n\r\nI just need one arithmetic progression\r\n\r\nWait no it's just i as min and j as max\r\n'''\r\n\r\ndef solve():\r\n a = II()\r\n b = II()\r\n c = II()\r\n compotes = min(a, b//2, c//4)\r\n print(compotes * 7)\r\n\r\nsolve()\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\na1 = a\r\nb1 = b // 2\r\nc1 = c // 4\r\nprint(min(a1,b1,c1)*7)", "a = int(input())\r\nb = int(input()) // 2\r\nc = int(input()) // 4\r\nprint(min(a, b, c) * 7)", "a = int(input())\r\nb= int(input())\r\nc= int(input())\r\nimport math\r\nprint(min(a, math.floor(b/2), math.floor(c/4))*7)", "a = int(input())\nb = int(input())\nc = int(input())\nwhile True:\n if b - a*2 >= 0 and c - a*4 >= 0:\n print(a*7)\n break\n else:\n a = a-1", "from sys import stdin\r\n\r\ninput = stdin.readline\r\n\r\n\r\ndef ii():\r\n return int(input())\r\n\r\n\r\ndef li():\r\n return list(map(int, input().split()))\r\n\r\na=ii()\r\nb=ii()\r\nc=ii()\r\nans=min(a,b//2,c//4)\r\nprint(ans*7)", "a,b,c=int(input()),int(input()),int(input())\r\nprint(min(a,b//2,c//4)*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nans=0\r\nwhile True:\r\n if a>=1 and b>=2 and c>=4:\r\n a=a-1\r\n b=b-2\r\n c=c-4\r\n ans=ans+7\r\n else:\r\n break\r\nprint(ans)", "import math\n\na = int(input())\nb = int(input())\nc = int(input())\n\nn = math.floor(b/2)\np = math.floor(c/4)\nif n >= a and p >= a:\n print(a+a*2+a*4)\n \nelif n >= p and a >= p:\n print(p+p*2+p*4)\n \nelif n <= a and n <= p:\n print(n+n*2+n*4)\n\nelif c < 4 or b < 2 or a < 1:\n print(0)\n\nelse:\n print(0)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nx=min(a,b//2,c//4)\r\nprint(x*7)", "lemon = int(input())\r\napple = int(input())\r\npear = int(input())\r\nif lemon < 1 or apple < 2 or pear < 4:\r\n print(\"0\")\r\nelse:\r\n lemon = lemon\r\n apple = (apple//2)\r\n pear = (pear//4)\r\n Min = min(apple,pear,lemon)\r\n print((Min)+(Min*2)+(Min*4))\r\n\r\n \r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif a * 2 <= b and a * 4 <= c:\r\n g = a + a*2 + a*4\r\nelse:\r\n while a * 2 > b or a * 4 > c:\r\n a -= 1\r\n g = a + a*2 + a*4\r\nprint(g)", "#codeforces 746A\r\n\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\nt=0\r\nwhile(1):\r\n if(a<=0 or b<2 or c<4):\r\n break\r\n a-=1\r\n b-=2\r\n c-=4\r\n t+=1\r\nprint(t*1+t*2+t*4)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nlemons = a\r\napples = b//2\r\npears = c//4\r\n\r\n_min = min(lemons, apples, pears)\r\n\r\nprint(_min*7)\r\n", "a = int(input())\r\nb = int(input()) // 2\r\nc = int(input()) // 4\r\nprint(7 * min(a,b,c))", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ns=[]\r\ns.append(a)\r\ns.append(b//2)\r\ns.append(c//4)\r\nprint(7*min(s))", "import sys\ninput = sys.stdin.readline\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(list(s[:len(s) - 1]))\ndef invr():\n return(map(int,input().split()))\n\n\nif __name__ == \"__main__\":\n a = inp()\n b = inp()\n c = inp()\n\n print(min(a//1, b//2, c//4)*7)", "I=input;print(7*min(int(I()),int(I())//2,int(I())//4))\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nif a>=1 and a<=1000 and b>=1 and b<=1000 and c>=1 and c<=1000:\r\n t=min(a,b//2,c//4)\r\n print(7*t)\r\n ", "a = int(input())\nb = int(input())\nc = int(input())\n\nmin_val = min(a, b // 2, c // 4)\nprint(min_val*7)\n\n \t\t\t\t \t\t \t \t\t\t \t\t \t\t \t\t \t\t\t \t", "l = int(input())\r\na = int(input())\r\np = int(input())\r\nx = min(l, a//2, p//4)\r\nprint(x*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\naVal = a//1\r\nbVal = b//2\r\ncVal = c//4\r\nprint( min(aVal, bVal, cVal)*7 )\r\n", "import math\r\nfrom sys import stdin, stdout\r\ninput, print = stdin.readline, stdout.write\r\n\r\n\r\ndef str_input():\r\n s = input()\r\n return s[:len(s)-1]\r\n\r\n\r\ndef char_list_input():\r\n s = input()\r\n return list(s[:len(s)-1])\r\n\r\n\r\ndef list_input(type):\r\n return list(map(type, input().split()))\r\n\r\n\r\ndef multi_input():\r\n return map(int, input().split())\r\n\r\n\r\ndef main():\r\n a = int(input())\r\n b = int(input())\r\n c = int(input())\r\n ans = 0\r\n for i in range(a+1):\r\n if 2*i <= b and 4*i <= c:\r\n ans = i\r\n print(f\"{7*ans}\\n\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import math\r\n\r\n\r\na= int(input())\r\nb = int(input())\r\nc = int(input())\r\nx = math.floor(c/4)\r\ny = math.floor(b/2)\r\n\r\nif(a<=x and a<=y): z = a\r\nelif(y<=a and y<=x): z = y\r\nelse : z = x\r\ntotal = z * 4\r\ntotal += z * 2\r\ntotal += z\r\n\r\nprint(total)", "a, b, c = (int(input()) for _ in range(3))\nres = (1 + 2 + 4) * min(a, b // 2, c // 4)\nprint(res)\n", "# Compote version 2\na = int(input()) # number of lemons\nb = int(input()) # number of apples\nc = int(input()) # number of pears\nlemons_to_use = a\napples_to_use = b // 2\npears_to_use = c // 4\nif lemons_to_use <= apples_to_use and lemons_to_use <= pears_to_use:\n print(lemons_to_use*7)\nelif apples_to_use <= lemons_to_use and apples_to_use <= pears_to_use:\n print(apples_to_use*7)\nelse:\n print(pears_to_use*7)\n", "a = int(input(''))\nb = int(input(''))\nc = int(input(''))\nflag = True\nfor i in range(a, 0, -1):\n if b >= i*2 and c >= i*4:\n print(i + i*2 + i*4)\n flag = False\n break\nif flag:\n print(0)\n\t \t \t\t \t\t\t\t\t\t \t \t\t\t\t", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nprint(min(a,int(b/2),int(c/4))*7)", "l = int(input())\na = int(input())\nc = int(input())\n\ncount = min(l, a // 2, c // 4)\n\nprint(count * 7)\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nprint(min(a*7, b//2*7, c//4*7))", "#y,b,r=map(int,input().split())\r\ny=int(input())\r\nr=int(input())\r\nb=int(input())\r\n#m=min(y,b,r)\r\n\"\"\"\r\nif(m==y):\r\n if(b>=y+1):\r\n if(r>=y+2):\r\n print(m,m+1,m+2)\r\n else:\r\n \"\"\" \r\nk=1\r\nwhile(1):\r\n if(k<=y and k*2<=r and k*4<=b):\r\n k+=1\r\n else:\r\n break\r\nk-=1\r\nprint(k+2*k+4*k)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ns=0\r\nwhile a>0 and b>0 and c>0:\r\n if a>=1 and b>=2 and c>=4:\r\n s+=7\r\n a-=1 \r\n b-=2 \r\n c-=4\r\n else:\r\n break\r\nprint(s)\r\n ", "class Solution:\r\n\tdef __init__(self):\r\n\t\tpass\r\n\r\n\tdef solve(self):\r\n\t\ta = int(input())\r\n\t\tb = int(input())\r\n\t\tc = int(input())\r\n\t\t\t\r\n\t\tprint(7*(min(a, b//2, c//4)))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n\tsol = Solution()\r\n\tsol.solve()\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nlis=[]\r\nlis.append(a)\r\nlis.append(b)\r\nlis.append(c)\r\nflag=True\r\ni=0\r\nsumi=0\r\nwhile(flag):\r\n if(lis[i]<=0):\r\n break\r\n\r\n if lis[i]*2<=lis[i+1] and lis[i]*4<=lis[i+2]:\r\n sumi=lis[i]+lis[i]*2+lis[i]*4\r\n flag=False\r\n break\r\n else:\r\n lis[i]-=1\r\nif(flag==False):\r\n print(sumi)\r\nelse:\r\n print(0)\r\n", "print(7*min(int(input())//1,int(input())//2,int(input())//4))", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\np = 0\r\nwhile(a > 0 and b > 1 and c > 3):\r\n a = a - 1\r\n b = b - 2\r\n c = c - 4\r\n p = p + 7\r\n\r\nprint(p)", "\r\n\r\nx = int(input())\r\ny = int(input())\r\nz = int(input())\r\n \r\ny = int(y/2);\r\nz= int (z/4);\r\n\r\nm =min(y,z,x);\r\nprint(m*(7))", "from collections import defaultdict, deque\r\nfrom heapq import heappush, heappop\r\nfrom math import inf\r\n\r\nri = lambda : map(int, input().split())\r\n\r\ndef solve():\r\n a = int(input())\r\n b = int(input())\r\n c = int(input())\r\n b //= 2\r\n c //= 4\r\n can = min(a,b,c)\r\n print(can * 7)\r\n\r\nt = 1\r\n#t = int(input())\r\nwhile t:\r\n t -= 1\r\n solve()\r\n\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nb -= b%2\r\nc -= c%4\r\nprint(min([a,b//2,c//4])*7)", "a= int (input())\r\nb= int(input())//2\r\nc=int(input())//4\r\nans=0;\r\nif a <= min(b,c):\r\n ans=7*a\r\nelif b<=min(a,c):\r\n ans= 7*b\r\nelse:\r\n ans=7*c\r\nprint(ans)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nk = 0\r\ni = a\r\nwhile i > 0:\r\n if i * 2 < b + 1 and i * 4 < c + 1:\r\n print(i * 7)\r\n k = 1\r\n break\r\n i -= 1\r\nif k == 0:\r\n print(0)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nmoo = 0\r\nfor i in range(1, a+1):\r\n if (2 * i <= b) and (4 * i <= c):\r\n moo = 7 * i\r\nprint(moo)", "a = int(input())\r\nb = int(input())\r\n\r\nc = int(input())\r\n\r\nans = min(a, int(b/2), int(c/4))*7\r\n \r\nprint(ans)", "arr = [int(input()) for _ in range(3)]\r\nprint(7*min(arr[0],arr[1]//2,arr[2]//4))\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nlist = [a, b, c]\r\ncheck = False\r\n\r\nfruitlist = []\r\n\r\ndiv = 1\r\nfor i in range(len(list)):\r\n fruitlist.append(list[i]//div)\r\n div *= 2\r\n\r\nfruitlist.sort()\r\nans = fruitlist[0]*7\r\nprint(ans)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nb = b//2\r\nc = c//4\r\nprint(min(a,b,c)*7)", "def solve(a, b, c):\r\n return min(min(a, b // 2), c // 4) * 7\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nprint(solve(a, b, c))", "print(min(int(input()), int(input())//2, int(input())//4)*7)", "# # RED CODER # #\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nx = min(a, b//2, c//4)\r\nprint((x*1)+(x*2)+(x*4))", "def max_compote_fruits(lemons, apples, pears):\r\n min_participants = min(lemons, apples // 2, pears // 4)\r\n total_fruits = min_participants * 7\r\n return total_fruits\r\n\r\nif __name__ == '__main__':\r\n lemons = int(input().strip())\r\n apples = int(input().strip())\r\n pears = int(input().strip())\r\n result = max_compote_fruits(lemons, apples, pears)\r\n print(result)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nsum =0\r\n\r\nwhile a >0 and b >0 and c >0 :\r\n while True :\r\n sum = a +a*2 + a*4\r\n if a*2 <=b and a*4<=c :\r\n \r\n print(sum)\r\n break\r\n \r\n a -=1\r\n break\r\n\r\n print(\"0\")\r\n \r\n ", "print(min(int(input())* 4,int(input())* 2,int(input()))// 4 * 7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\ns1 = b//2 \r\ns2 = c//4\r\n\r\nmini= min(a,s1,s2)\r\nprint(7*mini)\r\n", "a = int(input())\nb = int(input())\nc = int(input())\nprint(7*min(a//1, b//2, c//4))", "a = int(input())\r\nb = int(input())//2\r\nc = int(input())//4\r\n\r\nout = min(a, b, c)\r\nprint(out + out*2 + out*4)\r\n", "import math\ndef solve(a,b,c):\n count = 0\n for i in range(a):\n if b >= 2 and c >= 4:\n count += 7\n b -= 2\n c -= 4\n return count\n \n\ndef main():\n #arr =list(map(int,input().split(' ')))\n a = int(input())\n b = int(input())\n c = int(input())\n #arr = []\n #for j in range(n):\n # i = list(map(int,input().split(' ')))\n # i = input().split(' ')\n #i = int(''.join(input().split(' ')))\n #arr.append(i)\n print(solve(a,b,c))\n\nmain()", "# Read input values\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\n# Calculate the maximum number of complete sets\r\nmax_sets = min(a, b // 2, c // 4)\r\n\r\n# Calculate the total number of fruits that can be used\r\ntotal_fruits = max_sets * (1 + 2 + 4)\r\n\r\n# Print the result\r\nprint(total_fruits)", "def max_compote_fruits(a, b, c):\r\n min_ratio = min(b // 2, c // 4)\r\n max_compote_lemons = min(a, min_ratio)\r\n return max_compote_lemons * 1 + max_compote_lemons * 2 + max_compote_lemons * 4\r\n\r\ndef main():\r\n a = int(input())\r\n b = int(input())\r\n c = int(input())\r\n result = max_compote_fruits(a, b, c)\r\n print(result)\r\n\r\nif __name__ == '__main__':\r\n main()", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ntimes = c // 4\r\nif times*2 <= b:\r\n n = 1*times + 2*times + 4*times\r\nelse:\r\n times = b // 2\r\nif times*1 <= a:\r\n n = 1*times + 2*times + 4*times\r\nelse:\r\n times = a\r\n n = 1*times + 2*times + 4*times\r\nprint(n)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nlis=[1,2,4]\r\nlis=[lis[i]*a for i in range(3)]\r\nif lis[0]<=a and lis[1]<=b and lis[2]<=c:print(sum(lis))\r\nelse:\r\n while(lis[0]>a or lis[1]>b or lis[2]>c):\r\n lis[0]=lis[0]-1\r\n lis[1]=lis[1]-2\r\n lis[2]=lis[2]-4\r\n print(sum(lis))", "lemons = int(input())\napples = int(input())\npears = int(input())\n\nratio = False\nwhile not ratio:\n if lemons * 2 <= apples and lemons * 4 <= pears:\n ratio = True\n else:\n lemons -= 1\n\nprint(lemons + (lemons*2) + (lemons*4))\n", "#746A\r\nn=int(input())\r\nm=int(input())\r\nk=int(input())\r\nm1=m//2;k1=k//4\r\nz=min(min(m1,k1),n)\r\nprint(7*z)\r\n\r\n \r\n \r\n", "a = int(input())\nb = int(input())\nc = int(input())\nx = a\ny = b/2\nz = c/4\nif min(x,y,z) == x:\n a,b,c = a, 2*a, 4*a\nelif min(x,y,z) == y:\n w = b - b%2\n a,b,c = w//2, w, w*2\nelse:\n w = c - c%4\n a,b,c = w//4, w//2, w\nprint(a+b+c)\n", "maxLem = int( input( ) )\r\nmaxAppl = int( input( ) ) // 2\r\nmaxPea = int( input( ) ) // 4\r\nprint( min( maxLem, maxAppl, maxPea ) * 7 )\r\n", "import math\r\n\r\na = int(input())\r\nb = int(input())/2\r\nc = int(input())/4\r\nb = math.floor(b)\r\nc = math.floor(c)\r\n\r\nprint(7*min(a,b,c))", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nl=a//1\r\na=b//2\r\np=c//4\r\nres=min(l,a,p)*7\r\nprint(res)", "i=int(input())\r\nj=int(input())\r\nk=int(input())\r\ncount=0\r\nwhile(i>=1 and j>=2 and k>=4):\r\n i-=1\r\n j-=2\r\n k-=4\r\n count+=1\r\nif(count>0):\r\n print(7*count)\r\nelse:\r\n print(0)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\na = a // 1\r\nb = b // 2\r\nc = c // 4\r\n\r\nres = min(a, min(b, c)) * 7\r\nprint(res)", "l,a,p=[int(input()) for _ in range(3)]\r\nli=[l,a//2,p//4]\r\ntotal=0\r\ncheck_min=min(li)\r\nfor i in range(len(li)):\r\n li[i]=check_min\r\ntotal=(li[0])+(li[1]*2)+(li[2]*4)\r\nprint(total)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nprint(7*min(a,b//2,c//4))\r\n ", "# Problem Link:\r\n# Problem Status:\r\n# ------------ Separator ------------\r\nimport math\r\n\r\n\r\ndef TheAmazingFunction(A, B, C):\r\n return (min(A, math.floor(B / 2), math.floor(C / 4))) * 7\r\n\r\n\r\n# ------------ Separator ------------\r\nX = int(input())\r\nY = int(input())\r\nZ = int(input())\r\nprint(TheAmazingFunction(X, Y, Z))\r\n# ------------ Separator ------------", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nans = min(a, b // 2, c // 4)\r\nprint(ans*7)", "a = int(input())\nb = int(input())\nc = int(input())\n\nl = [a//1,b//2,c//4]\nprint(min(l)*7)\n\t \t \t\t \t\t\t \t\t \t\t \t \t \t\t", "lemon=int(input())\r\napple=int(input())\r\npear=int(input())\r\nkompot=0\r\nif lemon==0 or apple==0 or pear==0:\r\n print(kompot)\r\nelif lemon==1 and apple==2 and pear==4:\r\n print(7)\r\nelse:\r\n while lemon>=1 and apple>=2 and pear>=4:\r\n apple-=2\r\n lemon-=1\r\n pear-=4\r\n kompot+=7\r\n print(kompot)", "L=int(input())\r\nA=int(input())\r\nP=int(input())\r\nTotal=0\r\nwhile(L>0):\r\n if (L*2)<=A:\r\n if (L*4)<=P:\r\n Total=7*L\r\n break\r\n L-=1\r\nprint(Total)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nd = [a, b // 2, c // 4]\r\nprint(min(d) * 7)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\ns = min(a, b // 2, c // 4)\r\nif a < 1 or b < 2 or c < 4:\r\n\ts = 0\r\n\r\nprint(1 * s + 2 * s + 4 * s)\r\n\r\n", "s1 = int(input())\r\ns2 = int(input())\r\ns3 = int(input())\r\n\r\nlemons = s1 // 1\r\napples = s2 // 2\r\npears = s3 // 4\r\n\r\nmin_fruits = min(lemons, apples, pears)\r\ntotal_fruits = min_fruits * (1 + 2 + 4)\r\n\r\nprint(total_fruits)", "def main():\n\ta=int(input())\n\tb=int(input())\n\tc=int(input())\n\tprint(7*(min(a,b//2,c//4)))\n\n\nif __name__ =='__main__':\n\tmain()", "a=int(input())\nb=int(input())\nc=int(input())\na>=0\nb>=0\nc>=0\nd=a\ne=b//2\nf=c//4\nprint(min(d,e,f)*7)", "a = int(input ())\nb = int(input ())\nc = int(input ())\nb = b - (b % 2)\nc = c - (c % 4)\nx = min(a, b//2, c//4)\nif a < 1 or b < 2 or c < 4:\n print (0)\nelif x == a:\n print(a + a * 2 + 4 * a)\nelif x == b//2:\n print(b // 2 + b + 2 * b)\nelif x == c//4:\n print(c // 4 + c // 2 + c)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\nprint(min(l,a//2,p//4)*7)", "a = int(input())\nb = int(input())\nc = int(input())\n\n\n\nif 2 * a <= b and 4 * a <= c:\n answer = a\nelif 2 * a >=b and 2 * b <= c:\n answer = b // 2\nelse:\n answer = c // 4\n\n\nnewanswer = answer * 7\n\n\nprint(newanswer)\n\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nl=[a//1,b//2,c//4]\r\nm=min(l)\r\nprint(7*m)", "\"\"\"\r\n\r\n ____ _ _____ \r\n / ___|___ __| | ___| ___|__ _ __ ___ ___ ___ \r\n| | / _ \\ / _` |/ _ \\ |_ / _ \\| '__/ __/ _ \\/ __|\r\n| |__| (_) | (_| | __/ _| (_) | | | (_| __/\\__ \\\r\n \\____\\___/ \\__,_|\\___|_| \\___/|_| \\___\\___||___/\r\n\"\"\"\r\n\"\"\"\r\n░░██▄░░░░░░░░░░░▄██\r\n░▄▀░█▄░░░░░░░░▄█░░█░\r\n░█░▄░█▄░░░░░░▄█░▄░█░\r\n░█░██████████████▄█░\r\n░█████▀▀████▀▀█████░\r\n▄█▀█▀░░░████░░░▀▀███\r\n██░░▀████▀▀████▀░░██\r\n██░░░░█▀░░░░▀█░░░░██\r\n███▄░░░░░░░░░░░░▄███\r\n░▀███▄░░████░░▄███▀░\r\n░░░▀██▄░▀██▀░▄██▀░░░\r\n░░░░░░▀██████▀░░░░░░\r\n░░░░░░░░░░░░░░░░░░░░\r\n\"\"\"\r\n\r\n#Talha\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif a<= (b//2):\r\n d = a\r\nelse:\r\n d = (b//2)\r\nif d > (c//4):\r\n d = (c//4)\r\nd*=7\r\nprint(d)", "a, b, c = (int(input()) for _ in range(3))\nprint(7 * min(a, b // 2, c // 4))", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nk = [c // 4, b // 2, a // 1]\r\n\r\nprint((1 * min(k)) + (2 * min(k)) + (4 * min(k)))\r\n", "def print_answer(n, i1, i2, j1, j2):\r\n for i in range(n):\r\n for j in range(n):\r\n if (i == i1 or i == i2) and (j == j1 or j == j2):\r\n print(\"*\", end=\"\")\r\n else:\r\n print(\".\", end=\"\")\r\n print(\"\")\r\n\r\n\r\ndef solve():\r\n a = int(input())\r\n b = int(input())\r\n c = int(input())\r\n print(7 * min(a, b // 2, c // 4))\r\n\r\n\r\nsolve()\r\n", "lemons = int(input())\r\napples = int(input())\r\npears = int(input())\r\n\r\nlowest = [lemons, apples//2, pears//4]\r\nmini = min(lowest)\r\n\r\nprint(mini + mini * 2 + mini * 4)", "def solve(a, b, c):\n lem = 0\n x = c // 4\n y = b // 2\n lem = min(a, min(x,y))\n print(7*lem)\n\na = int(input())\nb = int(input())\nc = int(input())\nsolve(a, b, c)\n", "n=[int(input()), int(input()), int(input())]\r\na=[]\r\na.append(n[0]//1)\r\na.append(n[1]//2)\r\na.append(n[2]//4)\r\nprint(min(a)*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nr1=c//4\r\nr2=b//2\r\nprint(min(a,r2,r1)*7)\r\n", "\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\nt=su=0\r\nwhile(a>=1 and b>=2 and c>=4):\r\n\tsu=su+4+2+1\r\n\ta=a-1\r\n\tb=b-2\r\n\tc=c-4\r\nprint(su)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif b < 2 or c < 4:\r\n print(0)\r\nelse:\r\n b = b // 2\r\n c = c // 4\r\n w = min(a,b,c)\r\n a = w\r\n b = w\r\n c = w\r\n q = a+(b*2)+(c*4)\r\n print(q)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\n\r\n\r\ncompotes = c//4\r\ncompotes = min(compotes, b//2) \r\ncompotes = min(compotes, a)\r\n\r\n# fruits = lemons(x1) + apples(x2) + pears(x4)\r\nfruits = compotes + compotes*2 + compotes*4\r\n\r\nprint(fruits)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ni=a\r\nans=0\r\nwhile(i>=0):\r\n if(b>=2*i and c>=4*i):\r\n ans=7*i\r\n break\r\n else:\r\n i=i-1\r\nprint(ans) \r\n ", "a = int(input())\nb = int(input())\nc = int(input())\n\nr = 0\nwhile a >= 1 and b >= 2 and c >= 4:\n a -= 1\n b -= 2\n c -= 4\n r += 7\n\nprint(r)\n", "l = int(input())\r\np = int(input())\r\no = int(input())\r\ncountt = 0\r\nwhile(l >= 1 and p >=2 and o>=4):\r\n l -= 1\r\n p -= 2\r\n o -= 4\r\n countt += 1\r\nprint(countt * 7)\r\n ", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ns = 0\r\nfor i in range(1, a+1):\r\n if i*2 <= b and i*4 <= c:\r\n s = i*7\r\nprint(s)", "#749A (43No. Problem A) \r\nlemon = int(input())\r\napple = int(input())\r\npear = int(input())\r\nl,a,p = 1,2,4\r\ntotal = 0\r\nif (lemon < l or apple < a or pear < p):\r\n print(0)\r\nelse:\r\n while (lemon >= l and apple >= a and pear >= p):\r\n total += l + a + p\r\n lemon-=l\r\n apple-=a\r\n pear-=p\r\n print(total)\r\n ", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nwhile True:\r\n if a * 2 <= b and a * 4 <= c:\r\n print(a + 2 * a + 4 * a)\r\n break\r\n a -= 1", "a, b, c = int(input()), int(input()), int(input())\r\nprint(min(a, b // 2, c // 4) * 7)", "import sys\r\nfrom os import path\r\nif(path.exists('Input.txt')):\r\n sys.stdin = open(\"Input.txt\",\"r\")\r\n sys.stdout = open(\"Output.txt\",\"w\")\r\n\r\nimport math\r\nfrom collections import deque\r\ndef solve():\r\n\ta=int(input())\t\r\n\tb=int(input())\r\n\tc=int(input())\r\n\tz=min(a,b//2,c//4)\r\n\tprint(7*z)\r\n\t\t\r\nt=1\r\n#t=int(input())\t\t\r\nfor _ in range(t):\r\n\tsolve()", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nb = b // 2\r\nc = c // 4\r\nd = min(a,b,c)\r\nprint(d*1+d*2+d*4)", "a = int(input())\nb = int(input())\nc = int(input())\nPossible = True\n\nprint(min(a, b//2, c//4) * 7)\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nresult = 0\r\nfor i in range(a):\r\n if a - 1 >= 0 and b - 2 >= 0 and c - 4 >= 0:\r\n a -= 1\r\n b -= 2\r\n c -= 4\r\n result += 7\r\n\r\nprint(result)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nd=(min(a,(b//2),(c//4)))\r\nprint(d*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nk = min(a,b//2,c//4)\r\nprint(7*k)\r\n\r\n", "# 1:2:4\r\na = int(input()) #лимоны\r\nb = int(input()) #яблоки\r\nc = int(input()) #груши\r\nd1 = a//1\r\nd2 = b//2\r\nd3 = c//4\r\nd = min(d1, d2, d3)\r\nprint(d+(d*2)+(d*4))\r\n \r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\na1=a\r\nb1=b//2\r\nc1=c//4\r\nprint (min(a1,b1,c1)*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nif (b < 2*a):\r\n if (c < 2*b):\r\n a = c//4\r\n b = 2*a \r\n c = 2*b \r\n else: \r\n a = b//2 \r\n b = 2*a \r\n c = 2*b \r\nelse: \r\n if (c < 4*a):\r\n a = c//4\r\n b = 2*a \r\n c = 2*b \r\n else:\r\n a = a \r\n b = 2*a \r\n c = 2*b \r\n \r\nprint(a+b+c)\r\n", "l=int(input())\r\na=int(input())\r\np=int(input())\r\n\r\nprint(7*min(l,a//2,p//4))", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nl=[]\r\nif a>=1 and b>=2 and c>=4:\r\n l=[a//1,b//2,c//4]\r\n k=min(l)\r\n p=(1*k)+(2*k)+(4*k)\r\n print(p)\r\nelse:\r\n print(0)", "def solve():\r\n ratios = [1, 2, 4]\r\n lemons, apples, pears = map(int, (input(), input(), input()))\r\n \r\n least = [j//i for i, j in zip(ratios, (lemons, apples, pears)) if j // i > 0]\r\n \r\n print(0) if len(least) != 3 else print(sum([i * min(least) for i in ratios]))\r\n \r\nsolve()\r\n", "q,w,e=int(input()),int(input()),int(input())\r\nr=[q,w//2,e//4]\r\nt=r.index(min(r))\r\nprint((1+2+4)*r[t])", "a=int(input())\r\nb=int(input())//2\r\nc=int(input())//4\r\nprint(min(a,b,c)*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nprint(min(a, b // 2, c // 4) * 7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif a < 1 or b < 2 or c < 4:\r\n print(0)\r\nelse:\r\n x = a\r\n y = b // 2\r\n z = c // 4\r\n p = min(x,min(y,z))\r\n sum = p * 7\r\n print(sum)", "import sys\r\n\r\ndef main():\r\n a, b, c = map(int, sys.stdin.read().strip().split())\r\n return min((c//4, b//2, a))*7\r\n \r\nprint(main())\r\n", "a = int(input())\nb = int(input())\nc = int(input())\n\nnumber_of_compote = min(int(a/1), int(b/2), int(c/4))\n\nprint(number_of_compote*7)", "#!/usr/bin/env python\n# coding: utf-8\n\n# In[21]:\n\n\na = int(input())\nb = int(input())\nc = int(input())\nprint((min(a//1,b//2,c//4))*7)\n\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nb = b//2\r\nc = c//4\r\nsmallest = min(a, b, c)\r\nprint(smallest * 7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\na,b,c=a,b//2,c//4\r\nprint(7*min(a,b,c))", "print(min(int(input()),int(input())//2,int(input())//4)*7)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ns = 0\r\nfor i in reversed(range(1, a+1)):\r\n if i*2 <= b and i*4 <= c:\r\n s = i + i*2 + i*4\r\n break\r\nprint(s)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nlemon=a\r\napples=b//2\r\npears=c//4\r\nminn=min(lemon,min(apples,pears))\r\nprint(minn+minn*2+minn*4)", "from math import floor as f\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\nm=min(a,f(b/2),f(c/4))\r\nprint(m*7)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\nb = a % 2\r\nc = p % 4\r\nb = a-b\r\nc = p-c\r\nq = b/2\r\nw = c/4\r\nsmall = min([l, q, w])\r\nprint(int(small*7))\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nd = min(a,b//2,c//4)\r\nprint(7*d)\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nb//=2\r\nc//=4\r\nprint(7*min(a,b,c))", "l=int(input())\r\na=int(input())\r\np=int(input())\r\nc=0\r\nwhile( l>=1 and a>=2 and p>=4):\r\n c+=7\r\n l-=1\r\n a-=2\r\n p-=4\r\n \r\nprint(c)", "# a lemons , b apples , c pears\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nx = int(min(a, int(min(b/2,c/4))))\r\ny = x + (2 * x) + (4 * x)\r\nprint(y)\r\n", "def solve(a, b, c):\r\n\r\n while True:\r\n if a*4 - c > 0:\r\n a -= 1\r\n elif a*2 - b > 0:\r\n a -= 1\r\n else:\r\n break\r\n\r\n return a*7\r\n\r\n\r\nif __name__ == \"__main__\":\r\n a, b, c, = int(input()), int(input()), int(input())\r\n print(solve(a, b, c))\r\n", "# LUOGU_RID: 99994531\na = int (input ())\nb = int (input ())\nc = int (input ())\nprint (min (a, b // 2, c // 4) * 7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nans=0\r\nif(a>=1 and b>=2 and c>=4):\r\n x=int(b/2)\r\n y=int(c/4)\r\n z=min(a,min(x,y))\r\n ans=z+(2*z)+(4*z)\r\n print(ans)\r\nelse:\r\n print('0')", "\r\nprint(min(int(input()), min(int(input())//2, int(input())//4))*7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nif (b < 2*a):\r\n # Constraint is b, rather than a\r\n if (c < 2*b):\r\n # Constraint is c, not a or b \r\n a = c//4\r\n b = 2*a \r\n c = 2*b \r\n else: \r\n # c >= 2b, so constraint is b, not a or c \r\n a = b//2 \r\n b = 2*a \r\n c = 2*b \r\nelse: \r\n # b >= 2a, constraint is a, rather than b \r\n if (c < 4*a):\r\n # Constraint is c, not a or b \r\n a = c//4\r\n b = 2*a \r\n c = 2*b \r\n else:\r\n # c >= 4a, so constraint is a, not b or c \r\n a = a \r\n b = 2*a \r\n c = 2*b \r\n \r\nprint(a+b+c)", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nans = 7 * min(a, b // 2, c // 4)\r\nprint(ans)", "#بسم الله الرحمن الرحيم\r\na,b,c =int(input()),int(input()),int(input())\r\nprint(min(a,b//2,c//4)*(7)if min(a,b//2,c//4)*(7)>0else 0)", "# coding: utf-8\r\n\r\na, b, c = [int(input()) for i in range(3)]\r\n\r\nwhile (2 * a > b or 4 * a > c) and a > 0:\r\n a -= 1\r\n \r\nprint(7 * a)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif b >= 2 and c >= 4:\r\n for i in range(a, 0, -1):\r\n if b >= i*2 and c >= i*4:\r\n print(i*7)\r\n break\r\nelse:\r\n print(0)", "def solution():\r\n a = int(input())\r\n b = int(input())\r\n c = int(input())\r\n ct = 0\r\n while 1:\r\n a,b,c = a-1, b-2, c-4\r\n if a >= 0 and b >= 0 and c >= 0:\r\n ct += 7\r\n else:\r\n break\r\n print(ct)\r\n\r\nsolution()", "t1 = int(input())\r\nt2 = int(input())\r\nt3 = int(input())\r\nt11 = t1*4\r\nt22 = t2*2\r\nt33 = t3\r\nprint(int(min(t11,t22,t33)/4)*7)\r\n ", "s1 = int(input())\r\ns2 = int(input())\r\ns3 = int(input())\r\n\r\nmin_ratio = min(s1, s2 // 2, s3 // 4)\r\np = min_ratio * (1 + 2 + 4)\r\n\r\nprint(p)", "print(7*min(int(input()),int(input())//2,int(input())//4))", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\np1=1\r\np2=2\r\np3=4\r\n\r\nfor i in range(1001):\r\n cur1=p1*i\r\n cur2=p2*i\r\n cur3=p3*i\r\n \r\n if(cur1>a or cur2>b or cur3>c):\r\n print(7*(i-1))\r\n break\r\n \r\n \r\n \r\n \r\n ", "x=int(input())\r\ny=int(input())\r\nz=int(input())\r\nwhile(x>0):\r\n if(y>=2*x and z>=4*x):\r\n print(x+2*x+4*x)\r\n exit(0);\r\n x-=1\r\nprint(0)", "a = int(input())\nb = int(input())\nc = int(input())\nfor i in range(a,-1,-1):\n\n if b >= i*2 and c >= i*4:\n print(i + i*2 + i*4)\n break", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nwhile a>0 and (c<a*4 or b<a*2):\r\n a-=1\r\nprint(a+a*2+a*4)\r\n \r\n", "lemon=int(input()) ; apple=int(input()) ; pears=int(input())\r\nx=min(apple//2,pears//4,lemon) ; print(x+x*2+x*4)", "lemon = int(input())\r\napple = int(input())\r\npear = int(input())\r\nresult = 0\r\n\r\nto_use_pear = pear - (pear % 4)\r\nto_use_apple = apple - (apple % 2)\r\n\r\nwhile lemon >= 1 and apple >= 2 and pear >= 4:\r\n lemon -= 1\r\n apple -= 2\r\n pear -= 4\r\n result += 7\r\n\r\nprint(result)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\ns = 0\r\n\r\nwhile True:\r\n if a>=1 and b>=2 and c>=4:\r\n a-=1\r\n b-=2\r\n c-=4\r\n s+=7\r\n else:\r\n break\r\n\r\nprint(s)\r\n", "def solution():\r\n a = int(input())\r\n b = int(input()) // 2\r\n c = int(input()) // 4\r\n print(min(a,b,c) * 7)\r\n\r\nsolution()", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif a < 1 or b < 2 or c < 4:\r\n print(0)\r\nelse:\r\n if a * 2 <= b and a * 4 <= c:\r\n print(a+a*2+a*4)\r\n else:\r\n m = min(a//1,b//2,c//4)\r\n print(m*1+m*2+m*4)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nx=a\r\ny=b//2\r\nz=c//4\r\nn=min(x,y,z)\r\nprint(n+(n*2)+(n*4))\r\n", "\r\nl=int(input())\r\na=int(input())\r\np=int(input())\r\nx=a//2\r\ny=p//4\r\nm=min(l,x,y)\r\nprint(m+m*2+m*4)", "# 746A\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nn = 1+2+4\r\nb = b//2\r\nc = c//4\r\n\r\nif a > b:\r\n p = b\r\nelse:\r\n p = a\r\n\r\nif p > c:\r\n p = c\r\n \r\nprint (p*n)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nmaximumfactor=min(a, b//2, c//4)\r\nprint(maximumfactor*7)", "lemons = int(input())\napples = int(input())\npears = int(input())\n\ncompote = min(lemons, apples // 2, pears // 4)\n\nprint(compote * 7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\np = min(a, b // 2, c // 4)\r\nprint(p * 7)\r\n", "# Author : Ghulam Junaid aka redhaired (not redhaired tho)\r\nlemons = int(input())\r\napples = int(input())\r\npears = int(input())\r\nminn = min(lemons,apples//2,pears//4)\r\nprint(minn+minn*(2)+minn*(4))", "a,b,c,ans=int(input()),int(input()),int(input()),0\r\nwhile a>0 and b>0 and c>0:\r\n a-=1\r\n b-=2\r\n c-=4\r\n if a>=0 and b>=0 and c>=0:\r\n ans+=7\r\nprint(ans)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nr2=int(b/2)\r\nr3=int(c/4)\r\nm=min(a,r2,r3)\r\nprint(7*m)", "a = int(input())\nb = int(input())\nc = int(input())\nleast = [a, int(b / 2), int(c / 4)]\nleast.sort()\nprint(least[0] * 7)", "lemon = int(input())\napple = int(input())\npears = int(input())\ncompote = list(['0'])\ncompote.append(lemon)\ncompote.append(int(apple/2))\ncompote.append(int(pears/4))\ndel compote[0]\nmini = min(compote)\nprint(mini*7)\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ncount=0\r\nfor i in range(1,a+1):\r\n if i<=a and 2*i<=b and 4*i<=c:\r\n count+=7\r\n else:\r\n break\r\nprint(count)", "L = int(input())\r\nA = int(input())\r\nP = int(input())\r\n\r\nx = min(L, A//2, P//4)\r\n\r\nprint(x*7)", "l = int(input())\r\na = int(input())\r\np = int(input())\r\n\r\ntotal=0\r\nwhile(l>0 and a>1 and p>3):\r\n total+=7\r\n l = l - 1\r\n a = a - 2\r\n p = p - 4\r\n \r\nprint(total)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\n\r\nfor i in range (a,-1,-1):\r\n\r\n if(b>=2*i and c>=4*i):\r\n print(7*i)\r\n break\r\n elif(i==0):\r\n print(0)\r\n\r\n", "import math\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nif min(a,b/2,c/4) == a: print(math.floor(a)*7)\r\nelif min(b/2,c/4) == b/2: print(math.floor(b/2)*7)\r\nelse: print(math.floor(c/4)*7)\r\n", "a=int(input(\"\"))\r\nb=int(input(\"\"))\r\nc=int(input(\"\"))\r\n\r\ne=b//2\r\nf=c//4\r\n\r\nz=min(a, e, f)\r\n\r\nprint(z+(2*z)+(4*z))", "a = int(input())\nb = int(input())\nc = int(input())\nprint(min(a, min(int(b/2), int(c/4))) * 7);\n", "\na = int ( input () )\nb = int ( input () )\nc = int ( input () )\n\nd = b // 2\ne = c // 4\n\nif a < d and a < e:\n #a is the smallest\n p = a * 7\nelif d < e:\n # b is the smallest\n p = ( b // 2 ) * 7\nelse:\n # c is the smallest\n p = ( c // 4 ) * 7\n \nprint (p)\n", "res = \"\"\r\n\r\nlemon = int(input())\r\napple = int(input())\r\npear = int(input())\r\n\r\nnc = min(lemon, min(apple//2, pear//4))\r\nprint(1 * nc + 2*nc + 4*nc)", "a,b,c=int(input('')),int(input('')),int(input(''))\r\nl=[a,b//2,c//4]\r\nprint(min(l)*7)", "a = int(input())\nb = int(input())\nc = int(input())\n\nm = min(a, int(b/2), int(c/4))\nprint(m + m*2 + m*4)\n", "# import sys\r\n# sys.stdout = open('DSA/Stacks/output.txt', 'w')\r\n# sys.stdin = open('DSA/Stacks/input.txt', 'r')\r\n\r\n\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\ncompote = 0\r\nwhile True:\r\n if a<1:\r\n break\r\n if b<2:\r\n break\r\n if c<4:\r\n break\r\n a-=1\r\n compote+=1\r\n b-=2\r\n compote+=2\r\n c-=4\r\n compote+=4\r\nprint(compote)\r\n ", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ntemp = 0\r\n\r\nwhile a >= 1 and b >= 2 and c >= 4:\r\n temp += 7\r\n a -= 1\r\n b -= 2\r\n c -= 4\r\nprint(temp)\r\n\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nm=min(a,b//2,c//4)\r\nprint(m+(m*2)+(m*4))\r\n", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nx=b//2\r\ny=c//4\r\nm=min(a,x)\r\nn=min(m,y)\r\nprint(n+n*2+n*4)", "lemons = int(input())\r\napple = int(input())\r\npears = int(input())\r\n\r\nx = min(lemons, apple//2, pears//4)\r\nprint(x * 7)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nb=b//2\r\nc=c//4\r\nif min(a,b,c)==a:\r\n print(a*7)\r\nelif min(a,b,c)==b:\r\n print(b*7)\r\nelse:\r\n print(c*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nprint(min(a,b//2,c//4)*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nb1=b//2\r\nc1=c//4\r\nx=min(a,b1,c1)\r\nprint(7*x)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nflag = True\r\nmax=0\r\nwhile flag:\r\n if a>=1 and b>=2 and c>=4:\r\n max+=7\r\n a-=1\r\n b-=2\r\n c-=4\r\n else:\r\n flag=False\r\nprint(max)\r\n", "a = int(input())\r\nb = int(input())\r\nb2 = b // 2\r\nc = int(input())\r\nc2 = c // 4\r\nd = min(a, b2, c2)\r\nprint((1*d)+(2*d)+(4*d))", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nb=b//2\r\nc=c//4\r\nn = min(a,b,c)\r\nprint(7*n)\r\n", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ntotal = 0\r\nflag = True\r\nwhile flag:\r\n if a >= 1 and b >= 2 and c >= 4:\r\n total += 7\r\n a -= 1\r\n b -= 2\r\n c -=4\r\n else:\r\n flag = False\r\nprint(total)", "import math\r\n\r\na = int(input())\r\nb = int(input())\r\nc = int(input())\r\nans = 0\r\nfor i in range(1, a+1):\r\n if i*2 > b:\r\n break\r\n if i*4 > c:\r\n break\r\n ans = 7*i\r\nprint(ans)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ni=1\r\nj=2\r\nk=4\r\ns=0\r\nwhile(a-i>=0 and b-j>=0 and c-k>=0):\r\n i+=1 \r\n j+=2\r\n k+=4\r\n s+=1\r\nif(a-i>=0 and b-j>=0 and c-k>=0):\r\n print(i*7)\r\nelse:\r\n print((i-1)*7)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\ns=0\r\nwhile(a>=1):\r\n if(a>=1 and b>=2 and c>=4):\r\n s=s+7\r\n a-=1\r\n b-=2\r\n c-=4\r\n else:\r\n break\r\nprint(s)\r\n ", "l = int(input())\r\na = int(input())\r\np = int(input())\r\nct = 0\r\nf = 1\r\ntotal = 0\r\nmaxim = 0\r\nwhile(f):\r\n ct+=1\r\n lemon = 1*ct\r\n apple = 2*ct\r\n pear = 4*ct\r\n\r\n if lemon<=l and apple<=a and pear<=p:\r\n total = lemon+apple+pear\r\n maxim = max(total,maxim)\r\n else:\r\n f = 0\r\n\r\nprint(maxim)", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nif a//1>=1 and b//2>=1 and c//4>=1:\r\n\tl=[a//1,b//2,c//4]\r\n\ts=min(l)\r\n\tprint(s*1+s*2+s*4)\r\nelse:\r\n\tprint(0)", "A = []\r\nfor i in range(3):\r\n A.append(int(input().strip()))\r\nans = min(A[0]//1 , A[1]//2 ,A[2]//4)*7\r\nprint(ans)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nv = min(a, int(b/2), int(c/4))\r\nprint(7 * v)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\nmax_sum = 0\r\n\r\nwhile True:\r\n max_sum = 0\r\n if a > 0:\r\n max_sum += a\r\n if b < a * 2:\r\n a -= 1\r\n continue\r\n elif b >= a * 2:\r\n max_sum += a * 2\r\n if c >= a * 4:\r\n max_sum += a * 4\r\n break\r\n elif c < a * 4:\r\n a -= 1\r\n continue \r\n else: break\r\nprint(max_sum)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ns = 1 + 2 + 4\r\nr = a // 1\r\nt = b // 2\r\ne = c // 4\r\nm = min(r, t ,e)\r\nprint(m * s)\r\n", "limons=int(input())\r\nappels=int(input())\r\npears=int(input())\r\n \r\ncount=0 \r\n\r\nfor i in range(1,limons+1):\r\n if limons >= 1 and appels >= 2 and pears >= 4:\r\n count +=7\r\n limons = limons - 1\r\n appels = appels - 2\r\n pears = pears - 4 \r\n else:\r\n break\r\n \r\nprint(count) \r\n ", "a =int(input())\r\nb=int(input())\r\nc=int(input())\r\n\r\nx=a//1\r\ny=b//2\r\nz=c//4\r\nd=min(x,y,z)\r\nres=(d*1)+(d*2)+(d*4)\r\nprint(res)\r\n\r\n", "import bisect\r\na=int(input())\r\nb=int(input())\r\nc=int(input())\r\na1=a//1\r\nb1=b//2\r\nc1=c//4\r\nprint(7*(min(a1,b1,c1)))", "a=int(input())\r\nb=int(input())\r\nc=int(input())\r\nx=1\r\ny=2\r\nz=4\r\ns=x+y+z\r\nl=2\r\nwhile(x<=a and y<=b and z<=c):\r\n x=1*l\r\n y=2*l\r\n z=4*l\r\n s=x+y+z\r\n l=l+1\r\nprint(s-7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\n\r\nmax_a = a\r\nmax_b = b//2\r\nmax_c = c//4\r\n\r\nmax_compote = min(max_a, max_b, max_c)\r\n\r\nprint(max_compote * 7)", "a = int(input())\r\nb = int(input())\r\nc = int(input())\r\ng = 0\r\nwhile a >= 1 and b >= 2 and c >= 4:\r\n a -= 1\r\n b -= 2\r\n c -= 4\r\n g += 7\r\nprint(g)\r\n\r\n\r\n" ]
{"inputs": ["2\n5\n7", "4\n7\n13", "2\n3\n2", "1\n1\n1", "1\n2\n4", "1000\n1000\n1000", "1\n1\n4", "1\n2\n3", "1\n1000\n1000", "1000\n1\n1000", "1000\n2\n1000", "1000\n500\n1000", "1000\n1000\n4", "1000\n1000\n3", "4\n8\n12", "10\n20\n40", "100\n200\n399", "200\n400\n800", "199\n400\n800", "201\n400\n800", "200\n399\n800", "200\n401\n800", "200\n400\n799", "200\n400\n801", "139\n252\n871", "109\n346\n811", "237\n487\n517", "161\n331\n725", "39\n471\n665", "9\n270\n879", "137\n422\n812", "15\n313\n525", "189\n407\n966", "18\n268\n538", "146\n421\n978", "70\n311\n685", "244\n405\n625", "168\n454\n832", "46\n344\n772", "174\n438\n987", "144\n387\n693", "22\n481\n633", "196\n280\n848", "190\n454\n699", "231\n464\n928", "151\n308\n616", "88\n182\n364", "12\n26\n52", "204\n412\n824", "127\n256\n512", "224\n446\n896", "146\n291\n584", "83\n164\n332", "20\n38\n80", "198\n393\n792", "120\n239\n480", "208\n416\n831", "130\n260\n517", "67\n134\n267", "245\n490\n979", "182\n364\n727", "104\n208\n413", "10\n2\n100", "2\n100\n100", "2\n3\n8", "1\n2\n8", "1\n2\n200", "5\n4\n16", "1\n10\n10", "1\n4\n8", "100\n4\n1000", "2\n6\n12", "10\n7\n4", "2\n10\n100", "2\n3\n4", "1\n2\n999", "1\n10\n20", "100\n18\n20", "100\n1\n100", "3\n7\n80", "2\n8\n24", "1\n100\n100", "2\n1\n8", "10\n5\n23"], "outputs": ["7", "21", "0", "0", "7", "1750", "0", "0", "7", "0", "7", "1750", "7", "0", "21", "70", "693", "1400", "1393", "1400", "1393", "1400", "1393", "1400", "882", "763", "903", "1127", "273", "63", "959", "105", "1323", "126", "1022", "490", "1092", "1176", "322", "1218", "1008", "154", "980", "1218", "1617", "1057", "616", "84", "1428", "889", "1561", "1015", "574", "133", "1372", "833", "1449", "903", "462", "1708", "1267", "721", "7", "14", "7", "7", "7", "14", "7", "7", "14", "14", "7", "14", "7", "7", "7", "35", "0", "21", "14", "7", "0", "14"]}
UNKNOWN
PYTHON3
CODEFORCES
334
21597ff5cde4d9dc159f25a26dd6a0ce
Directed Roads
ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of *n* towns numbered from 1 to *n*. There are *n* directed roads in the Udayland. *i*-th of them goes from town *i* to some other town *a**i* (*a**i*<=≠<=*i*). ZS the Coder can flip the direction of any road in Udayland, i.e. if it goes from town *A* to town *B* before the flip, it will go from town *B* to town *A* after. ZS the Coder considers the roads in the Udayland confusing, if there is a sequence of distinct towns *A*1,<=*A*2,<=...,<=*A**k* (*k*<=&gt;<=1) such that for every 1<=≤<=*i*<=&lt;<=*k* there is a road from town *A**i* to town *A**i*<=+<=1 and another road from town *A**k* to town *A*1. In other words, the roads are confusing if some of them form a directed cycle of some towns. Now ZS the Coder wonders how many sets of roads (there are 2*n* variants) in initial configuration can he choose to flip such that after flipping each road in the set exactly once, the resulting network will not be confusing. Note that it is allowed that after the flipping there are more than one directed road from some town and possibly some towns with no roads leading out of it, or multiple roads between any pair of cities. The first line of the input contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of towns in Udayland. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*,<=*a**i*<=≠<=*i*), *a**i* denotes a road going from town *i* to town *a**i*. Print a single integer — the number of ways to flip some set of the roads so that the resulting whole set of all roads is not confusing. Since this number may be too large, print the answer modulo 109<=+<=7. Sample Input 3 2 3 1 4 2 1 1 1 5 2 4 2 5 3 Sample Output 6 8 28
[ "n = int(input())\r\nl = list(map(int, input().split()))\r\nl.insert(0,0)\r\nmark = {}\r\nloop, pos, res , mod= 0, 1, 1, int(1e9+7)\r\nfor i in range(1, n+1):\r\n if not i in mark:\r\n start, j = pos, i\r\n while not j in mark:\r\n mark[j] = pos\r\n pos+= 1\r\n j = l[j]\r\n if mark[j]>=start:\r\n size = pos-mark[j]\r\n loop+= size\r\n res*= pow(2, size)-2+mod\r\n res%= mod\r\nres = (res * pow(2, n-loop,mod))%mod\r\nprint(res)\r\n", "import random\r\nimport sys\r\nfrom math import gcd, lcm, sqrt, isqrt, perm\r\nfrom collections import Counter, defaultdict, deque\r\nfrom functools import lru_cache, reduce, cmp_to_key\r\nfrom itertools import accumulate, combinations, permutations\r\nfrom heapq import nsmallest, nlargest, heappushpop, heapify, heappop, heappush\r\nfrom copy import deepcopy\r\nfrom bisect import bisect_left, bisect_right\r\nfrom string import ascii_lowercase, ascii_uppercase\r\ninf = float('inf')\r\nMOD = 10**9+7\r\ninput = lambda: sys.stdin.readline().strip()\r\nI = lambda: input()\r\nII = lambda: int(input())\r\nMII = lambda: map(int, input().split())\r\nLI = lambda: list(input().split())\r\nLII = lambda: list(map(int, input().split()))\r\nGMI = lambda: map(lambda x: int(x) - 1, input().split())\r\nLGMI = lambda: list(map(lambda x: int(x) - 1, input().split()))\r\n\r\n# 时间戳找环\r\ndef solve():\r\n n = II()\r\n a = LGMI()\r\n clock = 0\r\n res = 1\r\n time = [0] * n\r\n loop = 0\r\n for i, t in enumerate(time):\r\n if t:\r\n continue\r\n start_t = clock\r\n while True:\r\n if time[i]:\r\n if time[i] >= start_t:\r\n sz = clock - time[i]\r\n loop += sz\r\n res *= pow(2, sz, MOD) - 2\r\n res %= MOD\r\n break\r\n time[i] = clock\r\n clock += 1\r\n i = a[i]\r\n res *= pow(2, n-loop, MOD)\r\n res %= MOD\r\n print(res)\r\n return\r\n\r\nsolve()\r\n", "n = int(input())\r\nl = list(map(int, input().split()))\r\nl.insert(0, 0)\r\n\r\nmark = {}\r\nloop, pos, res, mod = 0, 1, 1, int(1e9 + 7)\r\nfor i in range(1, n+1):\r\n if not i in mark:\r\n start, j = pos, i\r\n while not j in mark:\r\n mark[j] = pos\r\n pos += 1\r\n j = l[j]\r\n if mark[j] >= start:\r\n size = pos - mark[j]\r\n loop += size\r\n res *= pow(2, size, mod) - 2 + mod\r\n res %= mod\r\nres = (res * pow(2, n - loop, mod)) % mod\r\nprint(res)\r\n", "n = int(input())\r\nw = [int(i) - 1 for i in input().split()]\r\n\r\nti = [0] * n\r\nt, m = 0, n\r\nres = 1\r\nmod = int(1e9 + 7)\r\n\r\ndef qmi(a, k, mod) -> int :\r\n res = 1\r\n while k > 0:\r\n if (k & 1) == 1:\r\n res = res * a % mod\r\n k >>= 1\r\n a = a * a % mod\r\n return res\r\n \r\nfor i in range(n):\r\n if ti[i] > 0:\r\n continue\r\n j, start = i, t\r\n while ti[j] == 0:\r\n ti[j] = t\r\n t += 1\r\n j = w[j]\r\n if ti[j] >= start:\r\n s = t - ti[j]\r\n m -= s\r\n res = (res * (qmi(2, s, mod) - 2) % mod + mod) % mod\r\n \r\nres = (res * qmi(2, m, mod) + mod) % mod\r\n\r\nprint(res)", "from sys import stdin\r\n\r\nn = int(stdin.readline())\r\na = [int(x)-1 for x in stdin.readline().split()]\r\n\r\nnodes = set([x for x in range(n)])\r\n\r\nloops = []\r\n\r\nwhile nodes:\r\n for x in nodes:\r\n nxt = x\r\n break\r\n visited = set()\r\n q = []\r\n\r\n early = False\r\n while not nxt in visited:\r\n if not nxt in nodes:\r\n early = True\r\n break\r\n q.append(nxt)\r\n visited.add(nxt)\r\n nodes.remove(nxt)\r\n nxt = a[nxt]\r\n\r\n if not early:\r\n loops.append(len(q)-q.index(nxt))\r\n\r\nbase = pow(2,n-sum(loops),10**9+7)\r\n\r\nfor x in loops:\r\n base *= pow(2,x,10**9+7)-2\r\n base %= 10**9+7\r\n\r\nprint(base)\r\n", "# Problem: D. Directed Roads\r\n# Contest: Codeforces - Codeforces Round 369 (Div. 2)\r\n# URL: https://codeforces.com/problemset/problem/711/D\r\n# Memory Limit: 256 MB\r\n# Time Limit: 2000 ms\r\n\r\nimport sys\r\nimport bisect\r\nimport random\r\nimport io, os\r\nfrom bisect import *\r\nfrom collections import *\r\nfrom contextlib import redirect_stdout\r\nfrom itertools import *\r\nfrom array import *\r\nfrom functools import lru_cache, reduce\r\nfrom types import GeneratorType\r\nfrom heapq import *\r\nfrom math import sqrt, gcd, inf\r\n\r\nif sys.version >= '3.8': # ACW没有comb\r\n from math import comb\r\n\r\nRI = lambda: map(int, sys.stdin.buffer.readline().split())\r\nRS = lambda: map(bytes.decode, sys.stdin.buffer.readline().strip().split())\r\nRILST = lambda: list(RI())\r\nDEBUG = lambda *x: sys.stderr.write(f'{str(x)}\\n')\r\n# print = lambda d: sys.stdout.write(str(d) + \"\\n\") # 打开可以快写,但是无法使用print(*ans,sep=' ')这种语法,需要print(' '.join(map(str, p))),确实会快。\r\n\r\nDIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 右下左上\r\nDIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),\r\n (-1, 1)] # →↘↓↙←↖↑↗\r\n\r\nMOD = 10 ** 9 + 7\r\nPROBLEM = \"\"\"https://codeforces.com/problemset/problem/711/D\r\n\r\n输入 n(2≤n≤2e5) 和长为 n 的数组 a(1≤a[i]≤n,a[i]≠i),表示一个 n 点 n 边的无向图(节点编号从 1 开始),点 i 和 a[i] 相连。\r\n\r\n你需要给每条边定向(无向变有向),这一共有 2^n 种方案。\r\n其中有多少种方案,可以使图中没有环?\r\n模 1e9+7。\r\n输入\r\n3\r\n2 3 1\r\n输出 6\r\n\r\n输入\r\n4\r\n2 1 1 1\r\n输出 8\r\n\r\n输入\r\n5\r\n2 4 2 5 3\r\n输出 28\r\n\"\"\"\r\n\"\"\"https://codeforces.com/contest/711/submission/207047798\r\n\r\n前置题目:\r\n2550. 猴子碰撞的方法数\r\n2360. 图中的最长环\r\n\r\n遍历每个环,这个环的贡献为 2^环长 - 2。\r\n不在环上的边可以随意取,贡献为 2^边数。\r\n这些贡献相乘即为答案。\"\"\"\r\n\r\n\r\n# ms\r\ndef solve():\r\n n, = RI()\r\n a = RILST()\r\n for i in range(n):\r\n a[i] -= 1\r\n ans = 1\r\n clock = 1\r\n circle = 0\r\n time = [0] * n\r\n for u, t in enumerate(time):\r\n if t: continue\r\n start_time = clock\r\n while u >= 0:\r\n if time[u]:\r\n if time[u] >= start_time:\r\n p = clock - time[u]\r\n circle += p\r\n ans = ans * (pow(2, p, MOD) - 2) % MOD\r\n break\r\n time[u] = clock\r\n clock += 1\r\n u = a[u]\r\n print(ans * pow(2, n - circle, MOD) % MOD)\r\n\r\n\r\nif __name__ == '__main__':\r\n t = 0\r\n if t:\r\n t, = RI()\r\n for _ in range(t):\r\n solve()\r\n else:\r\n solve()\r\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn = int(input())\r\nmod = pow(10, 9) + 7\r\na = [0] + list(map(int, input().split()))\r\npow2 = [1]\r\nfor _ in range(n + 5):\r\n pow2.append(2 * pow2[-1] % mod)\r\nvisit = [0] * (n + 1)\r\nans = 1\r\nfor i in range(1, n + 1):\r\n if visit[i]:\r\n continue\r\n q = [i]\r\n visit[i] = 1\r\n while not visit[a[q[-1]]]:\r\n j = a[q[-1]]\r\n visit[j] = 1\r\n q.append(j)\r\n q.reverse()\r\n u = a[q[0]]\r\n while q and q[-1] ^ u:\r\n q.pop()\r\n ans = 2 * ans % mod\r\n l = len(q)\r\n if len(q):\r\n ans = ans * (pow2[l] - 2) % mod\r\nprint(ans)", "mod = 1000000007\r\n\r\ndef solve(A):\r\n n = len(A)\r\n aa = [0]\r\n for x in A:\r\n aa.append(x)\r\n idx = [0] * (n+1)\r\n res = pos = 1\r\n for i in range(1, n + 1):\r\n if not idx[i]:\r\n j, start = i, pos\r\n while not idx[j]:\r\n idx[j] = pos\r\n pos += 1\r\n j = aa[j]\r\n if idx[j] >= start:\r\n n -= pos - idx[j]\r\n res = res * (pow(2, pos - idx[j], mod) - 2) % mod\r\n print(res * pow(2, n, mod) % mod)\r\n\r\nnn = int(input())\r\naa = list(map(int, input().strip().split()))\r\nsolve(aa)\r\n" ]
{"inputs": ["3\n2 3 1", "4\n2 1 1 1", "5\n2 4 2 5 3", "4\n2 1 4 3", "7\n2 3 4 1 6 5 4", "20\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1", "2\n2 1", "84\n2 50 67 79 71 45 43 40 57 20 25 8 60 47 52 10 37 23 1 28 22 26 3 42 11 63 61 68 49 32 55 18 5 24 31 70 66 27 38 41 54 12 65 51 15 34 30 35 77 74 21 62 33 16 81 14 19 48 80 73 69 78 39 6 76 46 75 72 84 29 58 59 13 17 82 9 83 4 36 56 53 7 64 44"], "outputs": ["6", "8", "28", "4", "56", "1048574", "2", "428380105"]}
UNKNOWN
PYTHON3
CODEFORCES
8
216626f8e3129d6463eb791d51eaa0ad
Permutation Cycle
For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows: Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists. For given *N*,<=*A*,<=*B*, find a permutation *P* of integers from 1 to *N* such that for 1<=≤<=*i*<=≤<=*N*, *g*(*i*) equals either *A* or *B*. The only line contains three integers *N*,<=*A*,<=*B* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*A*,<=*B*<=≤<=*N*). If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to *N*. Sample Input 9 2 5 3 2 1 Sample Output 6 5 8 3 4 1 9 2 71 2 3
[ "#This code sucks, you know it and I know it. \r\n#Move on and call me an idiot later.\r\n\r\ndef solve(a, b, n):\r\n \r\n i = 0\r\n while i * a <= n:\r\n \r\n if (n - (i * a)) % b == 0:\r\n x = i\r\n y = (n - (i * a)) // b\r\n return (x, y)\r\n i = i + 1\r\n \r\n return (-1, -1)\r\n\r\nn, a, b = map(int, input().split())\r\naa, bb = solve(a, b, n)\r\nl = []\r\nif (aa, bb) == (-1, -1):\r\n print(-1)\r\nelse:\r\n\r\n for i in range(1,aa+1):\r\n x = a*(i-1) + 1\r\n y = a*i\r\n l += [y]\r\n l += [j for j in range(x, y)]\r\n\r\n for i in range(1,bb+1):\r\n x = a*aa + b*(i-1) + 1\r\n y = a*aa + b*i\r\n l += [y]\r\n l += [j for j in range(x, y)]\r\n \r\n print(\" \".join(map(str, l)))", "x, a, b=map(int, input().split())\r\na1=0\r\nwhile (a1<=x) and ((x-a1)%b!=0):\r\n\ta1+=a\r\nif a1>x:\r\n\tprint(-1)\r\n\texit(0)\r\nk=a1//a\r\nl=(x-a1)//b\r\nfor i in range(k):\r\n\tprint(a*i+a, end=\" \")\r\n\tfor j in range(1, a):\r\n\t\tprint(a*i+j, end=\" \")\r\nfor i in range(l):\r\n\tprint(a1+b*i+b, end=\" \")\r\n\tfor j in range(1, b):\r\n\t\tprint(a1+b*i+j, end=\" \")", "n, a, b = [int(x) for x in input().split()]\r\n\r\ndef egcd(a, b):\r\n if a == 0:\r\n return (b, 0, 1)\r\n else:\r\n g, y, x = egcd(b % a, a)\r\n return (g, x - (b // a) * y, y)\r\n\r\ng, a_1, b_1 = egcd(a, b)\r\nif n % g:\r\n print(-1)\r\n exit(0)\r\n\r\nfac = n // g\r\na_1 *= fac\r\nb_1 *= fac\r\nif a_1 < 0:\r\n while a_1 < 0:\r\n a_1 += b//g\r\n b_1 -= a//g\r\n if b_1 < 0:\r\n print(-1)\r\n exit(0)\r\nelif b_1 < 0:\r\n while b_1 < 0:\r\n b_1 += a//g\r\n a_1 -= b//g\r\n if a_1 < 0:\r\n print(-1)\r\n exit(0)\r\n\r\nres = []\r\ni = 1\r\nfor _ in range(a_1):\r\n for j in range(a-1):\r\n i += 1\r\n res.append(i)\r\n res.append(i - a + 1)\r\n i += 1\r\n \r\nfor _ in range(b_1):\r\n for j in range(b-1):\r\n i += 1\r\n res.append(i)\r\n res.append(i - b + 1)\r\n i += 1\r\n \r\nprint(\" \".join(map(str, res)))", "n,a,b=map(int,input().split())\np=[i+1 for i in range(n)]\nf=0\na,b=min(a,b),max(a,b)\nfor i in range(0,n+1,a):\n\tif (n-i)%b==0:\n\t\tx=((n-i)//b)\n\t\tf=1\n\t\tbreak\nif f:\n\tfor i in range(0,b*x,b):\n\t\tp[i:i+b]=[p[i+b-1]]+p[i:i+b-1]\n\tfor j in range(b*x,n,a):\n\t\tp[j:j+a]=[p[j+a-1]]+p[j:j+a-1]\n\tprint(*p)\n\nelse:\n\tprint(-1)", "n,a,b=map(int,input().split())\r\nif a==1 or b==1:\r\n print(*[el for el in range(1,n+1)])\r\nelse:\r\n \r\n p=n\r\n f=False\r\n a,b=max(a,b),min(a,b)\r\n i=0\r\n o=0\r\n t=0\r\n while p>=0 and (not f):\r\n if p%b==0:\r\n o=p//b\r\n f=True\r\n else:\r\n p-=a\r\n t+=1\r\n if not f:\r\n print(-1)\r\n else:\r\n ans=[]\r\n start=1\r\n for _ in range(t):\r\n for i in range(a-1):\r\n \r\n ans.append(start+i+1)\r\n ans.append(start)\r\n start=ans[-2]+1\r\n for _ in range(o):\r\n for i in range(b-1):\r\n \r\n ans.append(start+i+1)\r\n ans.append(start)\r\n start=ans[-2]+1\r\n print(*ans)\r\n \r\n ", "n, a, b = map(int, input().strip().split())\n\ndef pp(seq):\n return ' '.join(map(str, seq))\n\ndef cycle(start, size):\n return list(range(start+1, start+size)) + [start]\n\ndef fail_sequence(target, acc=[]):\n ''' recursion failure, bloody python '''\n\n if target % a == 0:\n return acc + [a] * (target//a)\n if target % b == 0:\n return acc + [b] * (target//b)\n\n if a <= target:\n acc.append(a)\n res = sequence(target-a, acc)\n if res:\n return res\n acc.pop()\n if b <= target:\n acc.append(b)\n return sequence(target-b, acc)\n return []\n\ndef sequence(target, a, b):\n dp = {0:(0,0)} # num of (a, b) needed to reach sum\n for i in range(1, target+1):\n if i-a in dp:\n na, nb = dp[i-a]\n dp[i] = (na+1, nb)\n elif i-b in dp:\n na, nb = dp[i-b]\n dp[i] = (na, nb+1)\n na, nb = dp.get(target, (0,0))\n return [a]*na + [b]*nb\n\ndef sol():\n seq = sequence(n, a, b)\n\n if seq:\n res = []\n i = 1\n for size in seq:\n res.extend(cycle(i, size))\n i += size\n return pp(res)\n else:\n return -1\n\nprint(sol())\n", "res=[]\r\ndef solve(Ax,A,sum=0):\r\n\tfor i in range(0,Ax):\r\n\t\tfor k in range(0,A):\r\n\t\t\tif (k==0):\r\n\t\t\t\tres.append(sum+A)\r\n\t\t\telse:\r\n\t\t\t\tres.append(sum+k)\r\n\t\tsum+=A\r\n\treturn sum\r\n\r\ns=input().split()\r\nN=int(s[0])\r\nA=int(s[1])\r\nB=int(s[2])\r\nAx=Bx=0\r\nwhile 1 :\r\n\tif Ax*A>N:\r\n\t\tbreak;\r\n\tBx=N-Ax*A\r\n\tif Bx%B==0 :\r\n\t\tBx//=B\r\n\t\tbreak\r\n\tAx+=1\r\nif (Ax*A+Bx*B!=N):\r\n\tprint('-1')\r\nelse:\r\n\tsolve(Bx,B,solve(Ax,A))\r\n\tprint (' '.join(map(str, res)))", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, a, b = map(int, input().split())\r\nans = [-1]\r\nok = 0\r\nfor u in range(n + 1):\r\n x = n - a * u\r\n if x < 0:\r\n break\r\n if x % b:\r\n continue\r\n ok = 1\r\n v = x // b\r\n x = 0\r\n ans = []\r\n for _ in range(u):\r\n ans.append(x + a)\r\n x += 1\r\n for _ in range(a - 1):\r\n ans.append(x)\r\n x += 1\r\n for _ in range(v):\r\n ans.append(x + b)\r\n x += 1\r\n for _ in range(b - 1):\r\n ans.append(x)\r\n x += 1\r\n if ok:\r\n break\r\nsys.stdout.write(\" \".join(map(str, ans)))", "from collections import defaultdict\r\nfrom math import *\r\nfrom sys import stdin\r\ninput = lambda: stdin.readline()[:-1]\r\ninp = lambda: list(map(int, input().split()))\r\n\r\n\r\nn, a, b = inp()\r\nans = False\r\nfor x in range(n+1):\r\n if (n - (a * x))%b == 0 and n - (a * x) >= 0:\r\n ans = True\r\n ac, bc = x, (n - (a*x))//b\r\n break\r\n\r\nif not ans:\r\n print(-1)\r\n exit()\r\n\r\ncur = 1\r\nret = []\r\nfor x in range(ac):\r\n l = list(range(cur, cur + a))\r\n ret += l[1:] + l[:1]\r\n cur = cur + a\r\nfor x in range(bc):\r\n l = list(range(cur, cur + b))\r\n ret += l[1:] + l[:1]\r\n cur = cur + b\r\nprint(*ret)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n", "n,a,b=map(int,input().split())\r\np=[i+1 for i in range(n)]\r\nf=0\r\na,b=min(a,b),max(a,b)\r\nfor i in range(0,n+1,a):\r\n\tif (n-i)%b==0:\r\n\t\tx=((n-i)//b)\r\n\t\tf=1\r\n\t\tbreak\r\nif f:\r\n\tfor i in range(0,b*x,b):\r\n\t\tp[i:i+b]=[p[i+b-1]]+p[i:i+b-1]\r\n\tfor j in range(b*x,n,a):\r\n\t\tp[j:j+a]=[p[j+a-1]]+p[j:j+a-1]\r\n\tprint(*p)\r\n\r\nelse:\r\n\tprint(-1)", "n,a,b=map(int,input().split())\r\nx,y=-1,-1\r\nfor i in range(n+1):\r\n if n-a*i>=0 and (n-a*i)%b==0:\r\n x=i\r\n y=(n-a*i)//b\r\n break\r\nif x==-1:\r\n print(-1)\r\n exit()\r\nans=[-1]*n\r\nfor i in range(0,a*x,a):\r\n for j in range(i,i+a-1):\r\n ans[j]=j+1\r\n ans[i+a-1]=i\r\nfor i in range(a*x,n,b):\r\n for j in range(i,i+b-1):\r\n ans[j]=j+1\r\n ans[i+b-1]=i\r\nfor i in range(n):\r\n ans[i]+=1\r\nprint(*ans)", "n, a, b = map(int, input().split())\r\nx, y = 0, 0\r\nfor i in range(0, n):\r\n if i * a > n: break\r\n if (n - i * a) % b == 0:\r\n x, y = i, (n-i*a)//b\r\n break\r\n\r\nif (x == y == 0):\r\n print(-1)\r\n exit(0)\r\n\r\nans = []\r\np = 1\r\nfor i in range(x):\r\n for j in range(1, a):\r\n ans += [p+j]\r\n ans += [p]\r\n p += a\r\n\r\nfor i in range(y):\r\n for j in range(1, b):\r\n ans += [p+j]\r\n ans += [p]\r\n p += b\r\n\r\nprint(*ans)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, a, b = map(int, input().split())\r\nm = n\r\nwhile m % b != 0:\r\n m -= a\r\n if m < 0:\r\n break\r\n\r\nw = []\r\nif m < 0:\r\n print(-1)\r\nelse:\r\n for i in range(1, m+1, b):\r\n w.extend(list(range(i+1, i+b)))\r\n w.append(i)\r\n for i in range(m+1, n+1, a):\r\n w.extend(list(range(i+1, i+a)))\r\n w.append(i)\r\n print(' '.join(map(str, w)))\r\n", "from sys import stdin, stdout\r\n\r\nn, a, b = map(int, input().split())\r\nfound = False\r\nfor x in range(n+1):\r\n if (n - a * x) % b == 0:\r\n y = (n - a * x) // b\r\n if y >= 0:\r\n found = True\r\n break\r\nif not found:\r\n print(-1)\r\n exit()\r\nans = []\r\nl, r = 0, 1\r\nfor _ in range(x):\r\n l = r\r\n r = l + a\r\n for i in range(l, r):\r\n if i+1 == r:\r\n ans.append(l)\r\n else:\r\n ans.append(i+1)\r\n\r\nfor _ in range(y):\r\n l = r\r\n r = l + b\r\n for i in range(l, r):\r\n if i+1 == r:\r\n ans.append(l)\r\n else:\r\n ans.append(i+1)\r\n\r\nprint(*ans)", "\r\n# If you win, you live. You cannot win unless you fight.\r\nfrom sys import stdin\r\ninput=stdin.readline\r\nimport heapq\r\nimport string\r\nrd=lambda: map(lambda s: int(s), input().strip().split())\r\nri=lambda: int(input())\r\nrs=lambda :input().strip()\r\nfrom collections import defaultdict,deque,Counter\r\nfrom bisect import bisect_left as bl, bisect_right as br\r\nfrom random import randint\r\nfrom math import gcd, ceil, floor,log2,factorial\r\nrandom = randint(1, 10 ** 9)\r\nmod=10**9+7\r\nclass wrapper(int):\r\n def __hash__(self):\r\n return super(wrapper, self).__hash__() ^ random\r\n\r\nn,a,b=rd()\r\nA=None\r\nB=None\r\nfor fac in range(0,n+1):\r\n res=n-(fac*a)\r\n if res>=0:\r\n if res%b==0:\r\n A=fac\r\n B=res//b\r\n break\r\n else:\r\n break\r\nif A==None or B==None:\r\n print(-1)\r\n exit()\r\n# print(A,B)\r\nar=[i for i in range(1,n+1)]\r\nans=[]\r\nlast=0\r\nfor i in range(A):\r\n # ans.append(ar[las]\r\n for ind in range(last+1,last+a):\r\n ans.append(ar[ind])\r\n ans.append(ar[last])\r\n last+=a\r\nfor i in range(B):\r\n for ind in range(last + 1, last + b):\r\n ans.append(ar[ind])\r\n ans.append(ar[last])\r\n last+=b\r\nprint(*ans)\r\n", "n,a,b = map(int,input().split())\r\n#Pick any i,j such that i*a + j*b == n\r\nchoose = None\r\nfor i in range(n+1):\r\n if a*i > n:\r\n continue\r\n j = (n-a*i)//b\r\n if i*a + j*b == n:\r\n choose = (i,j)\r\nif choose:\r\n i,j = choose\r\n arr = []\r\n for t in range(i):\r\n arr.append(a)\r\n for t in range(j):\r\n arr.append(b)\r\n got = 0\r\n answer = []\r\n # print(arr)\r\n for x in arr:\r\n cur = []\r\n for i in range(got+1,got+x+1):\r\n cur.append(i)\r\n cur = cur[1:] + [cur[0]]\r\n got += x\r\n answer += cur\r\n print(' '.join(map(str,answer)))\r\n\r\nelse:\r\n print(-1)\r\n\r\n", "#!/usr/bin/env python3\n\nimport sys\n\nn, a, b = map(int, sys.stdin.readline().strip().split())\n\n# supposed a>=0, b>=0, a+b>0\n# returns (d, p, q) where d = gcd(a, b) = a*p + b*q\ndef euc(a, b):\n if b > a:\n (d, p, q) = euc(b, a)\n return (d, q, p)\n if b == 0:\n return (a, 1, 0)\n s = a // b\n (d, sp, sq) = euc(a - s * b, b)\n return (d, sp, sq - s * sp)\n\ndef normalize(n, a, b, d, p, q):\n if p < 0:\n (sp, sq) = normalize(n, b, a, d, q, p)\n return (sq, sp)\n elif q >= 0:\n return (p, q)\n # p>=0, q < 0\n r = - (q // (a // d))\n sp = p - r * (b // d)\n sq = q + r * (a // d)\n if sp < 0:\n raise ValueError\n else:\n return (sp, sq)\n\n(d, p, q) = euc(a, b)\nif n % d != 0:\n print ('-1')\n sys.exit(0)\nm = n // d\np, q = m * p, m * q\ntry:\n (p, q) = normalize(n, a, b, d, p, q)\nexcept ValueError:\n print ('-1')\n sys.exit(0)\n\nres = []\nlast = 1\nfor _ in range(p):\n res.extend(range(last + 1, last + a))\n res.append(last)\n last += a\nfor _ in range(q):\n res.extend(range(last + 1, last + b))\n res.append(last)\n last += b\n\nprint (' '.join(map(str, res)))\n", "n , A , B = (list)(map(int , input().split()))\r\nfor _ in range(n + 1) :\r\n if _ * A > n : break\r\n if (n - _ * A) % B == 0 :\r\n b = (n - _ * A) // B\r\n ans = [0 for __ in range(n + 1)]\r\n ptr = 1\r\n for __ in range(_) :\r\n start = ptr\r\n for ___ in range(A - 1) :\r\n ans[ptr] = ptr + 1\r\n ptr += 1\r\n ans[ptr] = start\r\n ptr += 1\r\n for __ in range(b) :\r\n start = ptr\r\n for ___ in range(B - 1) : \r\n ans[ptr] = ptr + 1\r\n ptr += 1\r\n ans[ptr] = start\r\n ptr += 1\r\n print(*ans[1:])\r\n quit()\r\nprint(-1) ", "import sys,math,heapq,queue\r\nfast_input=sys.stdin.readline \r\nn,a,b=map(int,fast_input().split())\r\n\r\nx=0\r\nwhile a*x<=n:\r\n r=n-a*x \r\n if r%b==0:\r\n break \r\n x+=1 \r\nif (n-a*x)>=0 and (n-a*x)%b==0:\r\n\r\n res=[] \r\n j=1\r\n for i in range(x):\r\n v=j \r\n for _ in range(a-1):\r\n res.append(j+1)\r\n j+=1 \r\n j+=1 \r\n res.append(v)\r\n x=(n-a*x)//b \r\n for i in range(x):\r\n v=j \r\n for _ in range(b-1):\r\n res.append(j+1)\r\n j+=1 \r\n j+=1 \r\n res.append(v)\r\n print(*res)\r\n\r\nelse:\r\n print(-1)", "n, a, b = map(int, input().split())\r\nfor i in range(n//a + 1):\r\n if (n - i*a) % b == 0:\r\n res = []\r\n for j in range(i):\r\n t = [j*a + k for k in range(1, a+1)]\r\n res += t[1:] + [t[0]]\r\n for j in range((n - i*a) // b):\r\n t = [i*a + j*b + k for k in range(1, b+1)]\r\n res += t[1:] + [t[0]] \r\n print(*res)\r\n break\r\nelse:\r\n print(-1)\r\n", "def exgcd(a,b):\r\n if b > 0:\r\n y,x,g = exgcd(b,a%b)\r\n y -= a//b * x\r\n return x,y,g\r\n else:\r\n return 1,0,a\r\nn,a,b = map(int,input().split())\r\nx0,y0,g = exgcd(a,b)\r\nif n % g != 0:\r\n print(-1)\r\n exit(0)\r\na //= g\r\nb //= g\r\nk = n//g\r\n#print(a,x0,b,y0,g)\r\nr = k * x0 // b\r\nl = (k * -y0 + a - 1) // a\r\nif l > r:\r\n print(-1)\r\n exit(0)\r\nx = k * x0 - b * l\r\ny = k * y0 + a * l\r\na *= g\r\nb *= g\r\n#print(a,x,b,y,n)\r\nfor i in range(x):\r\n for j in range(a-1):\r\n print(i*a + j + 2,end=' ')\r\n print(i*a+1,end=' ')\r\nfor i in range(y):\r\n for j in range(b-1):\r\n print(x*a + i*b + j + 2,end=' ')\r\n print(x*a + i*b+1,end=' ')\r\nprint()\r\n" ]
{"inputs": ["9 2 5", "3 2 1", "7 4 4", "1000000 999998 3", "1 1 1", "993012 997 1001", "1000000 2017 881", "390612 20831 55790", "689292 69319 96267", "99929 99929 2", "807990 72713 11616", "514004 50866 26101", "631610 7702 63553", "391861 47354 60383", "822954 53638 55936", "794948 794948 85946", "786009 37429 59524", "402440 201220 220895", "701502 342867 350751", "865746 865746 634846", "562825 562825 145593", "960677 797144 960677", "228456 38076 136364", "465111 297688 155037", "1000000 3 999997", "474441 99291 77277", "542226 90371 64993", "911106 51038 78188", "800577 56373 62017", "667141 63085 50338", "321361 79845 81826", "439365 78717 87873", "436061 59464 79277", "482184 56941 83597", "253274 82704 85285", "679275 59632 75475", "279013 56717 52145", "91401 88756 91401", "414372 59196 93713", "482120 96424 93248", "505383 77277 99291", "276681 90371 92227", "201292 78188 62600", "223899 74633 69608", "726152 70146 71567", "432613 95501 84278", "383151 97630 81017", "663351 51961 83597", "255855 82704 85285", "210582 59632 75475", "422699 52145 56717", "734965 91401 69490", "732687 59196 63663", "432316 96424 86324", "674504 89149 64156", "449238 72357 77951", "500754 60855 65493", "510382 53668 84117", "536156 82311 68196", "620908 51298 77886", "9 7 9", "10 7 5", "4 3 2", "5 4 5", "5 3 4", "1000000 3 3", "999999 2 4", "1000000 1 500001", "999999 2 2"], "outputs": ["2 1 4 3 6 7 8 9 5 ", "1 2 3 ", "-1", "-1", "1 ", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "-1", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "-1", "-1", "2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 1...", "-1", "-1", "-1", "2 3 4 5 6 7 8 9 1 ", "2 3 4 5 1 7 8 9 10 6 ", "2 1 4 3 ", "2 3 4 5 1 ", "-1", "-1", "-1", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155...", "-1"]}
UNKNOWN
PYTHON3
CODEFORCES
21
21675d66e7006d324b0336d4ffb917d7
Almost Permutation
Recently Ivan noticed an array *a* while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were *n* elements in the array, and each element was not less than 1 and not greater than *n*. Also he remembers *q* facts about the array. There are two types of facts that Ivan remembers: - 1 *l**i* *r**i* *v**i* — for each *x* such that *l**i*<=≤<=*x*<=≤<=*r**i* *a**x*<=≥<=*v**i*; - 2 *l**i* *r**i* *v**i* — for each *x* such that *l**i*<=≤<=*x*<=≤<=*r**i* *a**x*<=≤<=*v**i*. Also Ivan thinks that this array was a permutation, but he is not so sure about it. He wants to restore some array that corresponds to the *q* facts that he remembers and is very similar to permutation. Formally, Ivan has denoted the *cost* of array as follows: , where *cnt*(*i*) is the number of occurences of *i* in the array. Help Ivan to determine minimum possible *cost* of the array that corresponds to the facts! The first line contains two integer numbers *n* and *q* (1<=≤<=*n*<=≤<=50, 0<=≤<=*q*<=≤<=100). Then *q* lines follow, each representing a fact about the array. *i*-th line contains the numbers *t**i*, *l**i*, *r**i* and *v**i* for *i*-th fact (1<=≤<=*t**i*<=≤<=2, 1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*, 1<=≤<=*v**i*<=≤<=*n*, *t**i* denotes the type of the fact). If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible *cost* of the array. Sample Input 3 0 3 1 1 1 3 2 3 2 1 1 3 2 2 1 3 2 3 2 1 1 3 2 2 1 3 1 Sample Output 3 5 9 -1
[ "#~ # MAGIC CODEFORCES PYTHON FAST IO\nimport atexit\nimport io\nimport sys\n\n_INPUT_LINES = sys.stdin.read().splitlines()\ninput = iter(_INPUT_LINES).__next__\n_OUTPUT_BUFFER = io.StringIO()\nsys.stdout = _OUTPUT_BUFFER\n\[email protected]\ndef write():\n sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())\n#~ # END OF MAGIC CODEFORCES PYTHON FAST IO\n\nclass Arista():\n\tdef __init__(self,salida,llegada,capacidad,flujo,costo,indice):\n\t\tself.salida = salida\n\t\tself.llegada = llegada\n\t\tself.capacidad = capacidad\n\t\tself.flujo = flujo\n\t\tself.costo = costo\n\t\tself.indice = indice\n\t\t\n\tdef __str__(self):\n\t\ts = \"\"\n\t\ts = s + \"salida =\" + str(self.salida) + \"\\n\"\n\t\ts = s + \"llegada =\" + str(self.llegada) + \"\\n\"\n\t\ts = s + \"capacidad =\" + str(self.capacidad) + \"\\n\"\n\t\ts = s + \"flujo =\" + str(self.flujo) + \"\\n\"\n\t\ts = s + \"costo =\" + str(self.costo) + \"\\n\"\n\t\ts = s + \"indice =\" + str(self.indice) + \"\\n\"\n\t\ts = s + \"------------\"\n\t\treturn s\n\t\t\n\t\t\nclass Red(): \n\t## Representacion de una Red de flujo ##\n\tdef __init__(self,s,t): # Crea una red vacio\n\t\tself.lista_aristas = []\n\t\tself.lista_adyacencia = {}\n\t\tself.vertices = set()\n\t\tself.fuente = s\n\t\tself.sumidero = t\n\t\t\n\tdef agregar_vertice(self,vertice):\n\t\tself.vertices.add(vertice)\n\t\t\n\tdef agregar_arista(self,arista): \n\t\tself.vertices.add(arista.salida)\n\t\tself.vertices.add(arista.llegada)\n\t\tself.lista_aristas.append(arista)\n\t\tif arista.salida not in self.lista_adyacencia:\n\t\t\tself.lista_adyacencia[arista.salida] = set()\n\t\tself.lista_adyacencia[arista.salida].add(arista.indice)\n\t\t\t\n\tdef agregar_lista_aristas(self,lista_aristas):\n\t\tfor arista in lista_aristas:\n\t\t\tself.agregar_arista(arista)\n\t\t\t\n\tdef cantidad_de_vertices(self):\n\t\treturn len(self.vertices)\n\t\n\tdef vecinos(self,vertice):\n\t\tif vertice not in self.lista_adyacencia:\n\t\t\treturn set()\n\t\telse:\n\t\t\treturn self.lista_adyacencia[vertice]\n\t\n\tdef buscar_valor_critico(self,padre):\n\t\tINFINITO = 1000000000\n\t\tvalor_critico = INFINITO\n\t\tactual = self.sumidero\n\t\twhile actual != self.fuente:\n\t\t\tarista_camino = self.lista_aristas[padre[actual]]\n\t\t\tvalor_critico = min(valor_critico,arista_camino.capacidad - arista_camino.flujo)\n\t\t\tactual = arista_camino.salida\n\t\treturn valor_critico\n\t\n\tdef actualizar_camino(self,padre,valor_critico):\n\t\tactual = self.sumidero\n\t\tcosto_actual = 0\n\t\twhile actual != self.fuente:\n\t\t\tself.lista_aristas[padre[actual]].flujo += valor_critico\n\t\t\tself.lista_aristas[padre[actual]^1].flujo -= valor_critico\n\t\t\tcosto_actual += valor_critico*self.lista_aristas[padre[actual]].costo\n\t\t\tactual = self.lista_aristas[padre[actual]].salida\n\t\treturn costo_actual,True\t\n\t\t\n\tdef camino_de_aumento(self):\n\t\tINFINITO = 1000000000\n\t\tdistancia = {v:INFINITO for v in self.vertices}\n\t\tpadre = {v:-1 for v in self.vertices}\n\t\tdistancia[self.fuente] = 0\n\t\t#~ for iteracion in range(len(self.vertices)-1):\n\t\t\t#~ for arista in self.lista_aristas:\n\t\t\t\t#~ if arista.flujo < arista.capacidad and distancia[arista.salida] + arista.costo < distancia[arista.llegada]:\n\t\t\t\t\t#~ distancia[arista.llegada] = distancia[arista.salida] + arista.costo\n\t\t\t\t\t#~ padre[arista.llegada] = arista.indice\n\t\tcapa_actual,capa_nueva = set([self.fuente]),set()\n\t\twhile capa_actual:\n\t\t\tfor v in capa_actual:\n\t\t\t\tfor arista_indice in self.vecinos(v):\n\t\t\t\t\tarista = self.lista_aristas[arista_indice]\n\t\t\t\t\tif arista.flujo < arista.capacidad and distancia[arista.salida] + arista.costo < distancia[arista.llegada]: \n\t\t\t\t\t\tdistancia[arista.llegada] = distancia[arista.salida] + arista.costo\n\t\t\t\t\t\tpadre[arista.llegada] = arista.indice\n\t\t\t\t\t\tcapa_nueva.add(arista.llegada)\n\t\t\tcapa_actual = set()\n\t\t\tcapa_actual,capa_nueva = capa_nueva,capa_actual\n\t\t\t\t\n\t\tif distancia[self.sumidero] < INFINITO:\n\t\t\tvalor_critico = self.buscar_valor_critico(padre)\n\t\t\tcosto_actual,hay_camino = self.actualizar_camino(padre,valor_critico)\n\t\t\treturn valor_critico,costo_actual,hay_camino\n\t\telse:\n\t\t\treturn -1,-1,False\n\t\t\t\n\t\t\t\n\tdef max_flow_min_cost(self):\n\t\tflujo_total = 0\n\t\tcosto_total = 0\n\t\thay_camino = True\n\t\twhile hay_camino:\n\t\t\t#~ for x in self.lista_aristas:\n\t\t\t\t#~ print(x)\n\t\t\t\n\t\t\tflujo_actual,costo_actual,hay_camino = self.camino_de_aumento()\n\t\t\tif hay_camino:\n\t\t\t\tflujo_total += flujo_actual\n\t\t\t\tcosto_total += costo_actual\n\t\treturn flujo_total,costo_total\n\t\t\n\t\nINFINITO = 10000000000000\t\nn,q = map(int,input().split())\nmaxi = [n for i in range(n)]\nmini = [1 for i in range(n)]\nR = Red(0,2*n+1)\nprohibidos = {i:set() for i in range(n)}\nfor i in range(n):\n\tfor k in range(n+1):\n\t\tR.agregar_arista(Arista(R.fuente,i+1,1,0,2*k+1,len(R.lista_aristas)))\n\t\tR.agregar_arista(Arista(i+1,R.fuente,0,0,-2*k-1,len(R.lista_aristas)))\n\nfor j in range(n):\n\tR.agregar_arista(Arista(n+j+1,R.sumidero,1,0,0,len(R.lista_aristas)))\n\tR.agregar_arista(Arista(R.sumidero,n+j+1,0,0,0,len(R.lista_aristas)))\n\nfor z in range(q):\n\tt,l,r,v = map(int,input().split())\n\tif t == 1:\n\t\tfor i in range(v-1):\n\t\t\tfor j in range(l,r+1):\n\t\t\t\tprohibidos[i].add(j)\n\telse:\n\t\tfor i in range(v,n):\n\t\t\tfor j in range(l,r+1):\n\t\t\t\tprohibidos[i].add(j)\n\t\t\n\t\t\n\nfor i in range(n):\n\tfor j in range(mini[i],maxi[i]+1):\n\t\tif j not in prohibidos[i]:\n\t\t\tR.agregar_arista(Arista(i+1,n+j,1,0,0,len(R.lista_aristas)))\n\t\t\tR.agregar_arista(Arista(n+j,i+1,0,0,0,len(R.lista_aristas)))\t\t\n\t\t\nflujo_total,costo_total = R.max_flow_min_cost()\n#~ print(flujo_total,costo_total)\nif flujo_total < n:\n\tprint(\"-1\")\nelse:\n\tprint(costo_total)\t\t\n\t\t\n\n\t\t\n\t\n\t\t\t\n\t\t\n\n\n", "import heapq\r\nclass mcf_graph():\r\n n=1\r\n pos=[]\r\n g=[[]]\r\n def __init__(self,N):\r\n self.n=N\r\n self.pos=[]\r\n self.g=[[] for i in range(N)]\r\n def add_edge(self,From,To,cap,cost):\r\n assert 0<=From and From<self.n\r\n assert 0<=To and To<self.n\r\n m=len(self.pos)\r\n self.pos.append((From,len(self.g[From])))\r\n self.g[From].append({\"to\":To,\"rev\":len(self.g[To]),\"cap\":cap,\"cost\":cost})\r\n self.g[To].append({\"to\":From,\"rev\":len(self.g[From])-1,\"cap\":0,\"cost\":-cost})\r\n def get_edge(self,i):\r\n m=len(self.pos)\r\n assert 0<=i and i<m\r\n _e=self.g[self.pos[i][0]][self.pos[i][1]]\r\n _re=self.g[_e[\"to\"]][_e[\"rev\"]]\r\n return {\"from\":self.pos[i][0],\"to\":_e[\"to\"],\"cap\":_e[\"cap\"]+_re[\"cap\"],\r\n \"flow\":_re[\"cap\"],\"cost\":_e[\"cost\"]}\r\n def edges(self):\r\n m=len(self.pos)\r\n result=[{} for i in range(m)]\r\n for i in range(m):\r\n tmp=self.get_edge(i)\r\n result[i][\"from\"]=tmp[\"from\"]\r\n result[i][\"to\"]=tmp[\"to\"]\r\n result[i][\"cap\"]=tmp[\"cap\"]\r\n result[i][\"flow\"]=tmp[\"flow\"]\r\n result[i][\"cost\"]=tmp[\"cost\"]\r\n return result\r\n def flow(self,s,t,flow_limit=-1-(-1<<63)):\r\n return self.slope(s,t,flow_limit)[-1]\r\n def slope(self,s,t,flow_limit=-1-(-1<<63)):\r\n assert 0<=s and s<self.n\r\n assert 0<=t and t<self.n\r\n assert s!=t\r\n '''\r\n variants (C = maxcost):\r\n -(n-1)C <= dual[s] <= dual[i] <= dual[t] = 0\r\n reduced cost (= e.cost + dual[e.from] - dual[e.to]) >= 0 for all edge\r\n '''\r\n dual=[0 for i in range(self.n)]\r\n dist=[0 for i in range(self.n)]\r\n pv=[0 for i in range(self.n)]\r\n pe=[0 for i in range(self.n)]\r\n vis=[False for i in range(self.n)]\r\n def dual_ref():\r\n for i in range(self.n):\r\n dist[i]=-1-(-1<<63)\r\n pv[i]=-1\r\n pe[i]=-1\r\n vis[i]=False\r\n que=[]\r\n heapq.heappush(que,(0,s))\r\n dist[s]=0\r\n while(que):\r\n v=heapq.heappop(que)[1]\r\n if vis[v]:continue\r\n vis[v]=True\r\n if v==t:break\r\n '''\r\n dist[v] = shortest(s, v) + dual[s] - dual[v]\r\n dist[v] >= 0 (all reduced cost are positive)\r\n dist[v] <= (n-1)C\r\n '''\r\n for i in range(len(self.g[v])):\r\n e=self.g[v][i]\r\n if vis[e[\"to\"]] or (not(e[\"cap\"])):continue\r\n '''\r\n |-dual[e.to]+dual[v]| <= (n-1)C\r\n cost <= C - -(n-1)C + 0 = nC\r\n '''\r\n cost=e[\"cost\"]-dual[e[\"to\"]]+dual[v]\r\n if dist[e[\"to\"]]-dist[v]>cost:\r\n dist[e[\"to\"]]=dist[v]+cost\r\n pv[e[\"to\"]]=v\r\n pe[e[\"to\"]]=i\r\n heapq.heappush(que,(dist[e[\"to\"]],e[\"to\"]))\r\n if not(vis[t]):\r\n return False\r\n for v in range(self.n):\r\n if not(vis[v]):continue\r\n dual[v]-=dist[t]-dist[v]\r\n return True\r\n flow=0\r\n cost=0\r\n prev_cost=-1\r\n result=[(flow,cost)]\r\n while(flow<flow_limit):\r\n if not(dual_ref()):\r\n break\r\n c=flow_limit-flow\r\n v=t\r\n while(v!=s):\r\n c=min(c,self.g[pv[v]][pe[v]][\"cap\"])\r\n v=pv[v]\r\n v=t\r\n while(v!=s):\r\n self.g[pv[v]][pe[v]][\"cap\"]-=c\r\n self.g[v][self.g[pv[v]][pe[v]][\"rev\"]][\"cap\"]+=c\r\n v=pv[v]\r\n d=-dual[s]\r\n flow+=c\r\n cost+=c*d\r\n if(prev_cost==d):\r\n result.pop()\r\n result.append((flow,cost))\r\n prev_cost=cost\r\n return result\r\n\r\nn,q=map(int,input().split())\r\nleft=[0]*n\r\nright=[n-1]*n\r\nfor _ in range(q):\r\n t,l,r,v=map(lambda x:int(x)-1,input().split())\r\n if t==0:\r\n for i in range(l,r+1):\r\n left[i]=max(left[i],v)\r\n else:\r\n for i in range(l,r+1):\r\n right[i]=min(right[i],v)\r\n\r\nS=2*n\r\nT=S+1\r\ng=mcf_graph(2*n+2)\r\nfor i in range(n):\r\n for j in range(1,n+1):\r\n g.add_edge(S,i,1,2*j-1)\r\n\r\nfor i in range(n):\r\n if left[i]>right[i]:\r\n print(-1)\r\n exit()\r\n g.add_edge(i+n,T,1,0)\r\n for j in range(left[i],right[i]+1):\r\n g.add_edge(j,i+n,1,0)\r\n\r\nprint(g.flow(S,T)[1])", "import sys\r\n \r\ndef is_feasible(cnt,L,R):\r\n\tn = len(R)\r\n\tinter = [(L[i],R[i]) for i in range(n)]\r\n\tright = []\r\n\tfeasible = True\r\n\tfor x in range(n):\r\n\t\tfor p in inter:\r\n\t\t\tif p[0] == x:\r\n\t\t\t\tright.append(p[1])\r\n\t\t\t\t\r\n\t\twhile right and min(right) < x:\r\n\t\t\tright.remove(min(right))\r\n\t\tfor quantity in range(cnt[x]):\r\n\t\t\tif right:\r\n\t\t\t\tright.remove(min(right))\r\n\t\t\telse:\r\n\t\t\t\tfeasible = False\r\n\treturn feasible\r\n \r\n \r\nn,q = map(int,sys.stdin.readline().split())\r\nL = [0 for i in range(n)]\r\nR = [n-1 for i in range(n)]\r\nfor restriction in range(q):\r\n\tt,l,r,v = map(int,sys.stdin.readline().split())\r\n\tif t == 1:\r\n\t\tfor k in range(l-1,r):\r\n\t\t\tL[k] = max(L[k],v-1)\r\n\telse:\r\n\t\tfor k in range(l-1,r):\r\n\t\t\tR[k] = min(R[k],v-1)\r\n\t\t\t\r\nis_possible = all(map(lambda x,y : x <= y,L,R))\r\nif not is_possible:\r\n\tprint(-1)\r\nelse:\r\n\tcnt = {x:0 for x in range(n)}\r\n\tfor y in range(n):\r\n\t\tfor x in range(n):\r\n\t\t\tif cnt[x] == y:\r\n\t\t\t\tcnt[x] += 1\r\n\t\t\t\tif not is_feasible(cnt,L,R):\r\n\t\t\t\t\tcnt[x] -= 1 \r\n\tans = sum([cnt[x]*cnt[x] for x in range(n)])\r\n\tprint(ans)\r\n\t\r\n\t\t\t\t\t\r\n\t\t\t\r\n\t\t\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\t\t\r\n\t\t\t\r\n\t\t\t", "import math\nimport heapq\nimport math\n\n\nclass MCF:\n def __init__(self):\n self.edges = {}\n self.edge_indexes = {}\n self.source = 0\n self.sink = 1\n self.nodes = set()\n self.sources = set()\n self.sinks = set()\n self.visiting = dict()\n self.dijkstra_path = dict()\n self.flow_iteration = -1\n self._add_node(self.source)\n self._add_node(self.sink)\n self.cost = 0\n\n def add_edge(self, origin, destination, cost, capacity):\n if origin not in self.nodes:\n self._add_node(origin)\n if destination not in self.nodes:\n self._add_node(destination)\n self.edges[origin][destination] = [cost, capacity]\n self.edge_indexes[len(self.edge_indexes)] = self.edges[origin][destination]\n self.edges[destination][origin] = [cost, 0]\n\n def add_source(self, source):\n self.sources.add(source)\n\n def add_sink(self, sink):\n self.sinks.add(sink)\n\n def solve(self):\n self._add_arcs_from_main_source_to_sources()\n self._add_arcs_from_sinks_to_main_sink()\n while self._dijkstra():\n self._apply_flow()\n\n def get_flow(self):\n return self.flow_iteration\n\n def _add_node(self, node):\n self.nodes.add(node)\n self.edges[node] = {}\n self.visiting[node] = -1\n self.dijkstra_path[node] = -1\n\n def _add_arcs_from_main_source_to_sources(self):\n for source in self.sources:\n self.add_edge(self.source, source, 0, math.inf)\n\n def _add_arcs_from_sinks_to_main_sink(self):\n for sink in self.sinks:\n self.add_edge(sink, self.sink, 0, math.inf)\n\n def _dijkstra(self):\n heap = []\n heapq.heappush(heap, (0, self.source))\n self.flow_iteration += 1\n distances = {node: math.inf for node in self.nodes}\n distances[self.source] = 0\n while len(heap) > 0:\n (distance, node) = heapq.heappop(heap)\n if node in self.sinks:\n self.dijkstra_path[self.sink] = node\n return True\n if self.flow_iteration != self.visiting[node]:\n self.visiting[node] = self.flow_iteration\n for neighbor, [cost, capacity] in self.edges[node].items():\n if capacity > 0 and distances[neighbor] > distance + cost:\n self.dijkstra_path[neighbor] = node\n distances[neighbor] = distance + cost\n heapq.heappush(heap, (distance + cost, neighbor))\n return distances[self.sink] != math.inf\n\n def _apply_flow(self):\n iterator = self.sink\n while iterator != self.source:\n previous_node = self.dijkstra_path[iterator]\n self.edges[previous_node][iterator][1] -= 1\n self.edges[iterator][previous_node][1] += 1\n if previous_node in self.sources:\n self.cost += self.edges[previous_node][iterator][0]\n iterator = previous_node\n\n\ndef get_inputs():\n n, q = [int(number) for number in input().split()]\n Lower = [0] * n\n Upper = [n-1] * n\n for i in range(q):\n t, l, r, v = [int(number) for number in input().split()]\n for j in range(l-1, r):\n if t == 1:\n Lower[j] = max(Lower[j], v-1)\n else:\n Upper[j] = min(Upper[j], v-1)\n return n, Lower, Upper\n\n\nmcf = MCF()\n\nn, Lower, Upper = get_inputs()\n\nsrc = 2\nsink = 3\nfor i in range(n):\n for j in range(1, n + 1):\n mcf.add_edge(src, 2500 + n * n + n * i + j, 2 * j - 1, 1)\n mcf.add_edge(2500 + n * n + n * i + j, i + 4, 2 * j - 1, 1)\n mcf.add_edge(i + 4 + n, sink, 0, 1)\n for j in range(Lower[i], Upper[i]+1):\n mcf.add_edge(j + 4, i + n + 4, 0, 1)\n\nmcf.add_source(src)\nmcf.add_sink(sink)\nmcf.solve()\n\nif mcf.get_flow() == n:\n print(mcf.cost)\nelse:\n print(-1)\n\n" ]
{"inputs": ["3 0", "3 1\n1 1 3 2", "3 2\n1 1 3 2\n2 1 3 2", "3 2\n1 1 3 2\n2 1 3 1", "50 0", "50 1\n2 31 38 25", "50 2\n2 38 41 49\n1 19 25 24", "50 10\n2 4 24 29\n1 14 49 9\n2 21 29 12\n2 2 46 11\n2 4 11 38\n2 3 36 8\n1 24 47 28\n2 23 40 32\n1 16 50 38\n1 31 49 38", "50 20\n1 14 22 40\n1 23 41 3\n1 32 39 26\n1 8 47 25\n2 5 13 28\n2 2 17 32\n1 23 30 37\n1 33 45 49\n2 13 27 43\n1 30 32 2\n2 28 49 40\n2 33 35 32\n2 5 37 30\n1 45 45 32\n2 6 24 24\n2 28 44 16\n2 36 47 24\n1 5 11 9\n1 9 37 22\n1 28 40 24", "50 1\n1 12 38 31", "50 2\n2 6 35 37\n1 19 46 44", "50 10\n1 17 44 44\n2 32 40 4\n2 1 45 31\n1 27 29 16\n1 8 9 28\n2 1 34 16\n2 16 25 2\n2 17 39 32\n1 16 35 34\n1 1 28 12", "50 20\n1 44 48 43\n1 15 24 9\n2 39 44 25\n1 36 48 35\n1 4 30 27\n1 31 44 15\n2 19 38 22\n2 18 43 24\n1 25 35 10\n2 38 43 5\n2 10 22 21\n2 5 19 30\n1 17 35 26\n1 17 31 10\n2 9 21 1\n2 29 34 10\n2 25 44 21\n2 13 33 13\n2 34 38 9\n2 23 43 4", "50 1\n2 12 34 9", "50 2\n1 15 16 17\n2 12 35 41", "50 10\n2 31 38 4\n2 33 43 1\n2 33 46 21\n2 37 48 17\n1 12 46 33\n2 25 44 43\n1 12 50 2\n1 15 35 18\n2 9 13 35\n1 2 25 28", "50 20\n1 7 49 43\n1 10 18 42\n2 10 37 24\n1 45 46 24\n2 5 36 33\n2 17 40 20\n1 22 30 7\n1 5 49 25\n2 18 49 21\n1 43 49 39\n2 9 25 23\n1 10 19 47\n2 36 48 10\n1 25 30 50\n1 15 49 13\n1 10 17 33\n2 8 33 7\n2 28 36 34\n2 40 40 16\n1 1 17 31", "1 0", "1 1\n1 1 1 1", "50 1\n2 1 2 1", "50 2\n2 1 33 1\n2 14 50 1", "49 10\n2 17 19 14\n1 6 46 9\n2 19 32 38\n2 27 31 15\n2 38 39 17\n1 30 36 14\n2 35 41 8\n1 18 23 32\n2 8 35 13\n2 24 32 45", "49 7\n1 17 44 13\n1 14 22 36\n1 27 39 3\n2 20 36 16\n2 29 31 49\n1 32 40 10\n2 4 48 48", "50 8\n2 11 44 10\n2 2 13 2\n2 23 35 41\n1 16 28 17\n2 21 21 46\n1 22 39 43\n2 10 29 34\n1 17 27 22", "5 2\n1 1 2 4\n1 3 5 5", "4 3\n2 1 2 2\n1 2 2 2\n2 3 4 1", "5 2\n1 1 5 4\n2 3 5 4", "42 16\n2 33 37 36\n1 14 18 1\n2 24 25 9\n2 4 34 29\n2 32 33 8\n2 27 38 23\n2 1 1 7\n2 15 42 35\n2 37 42 17\n2 8 13 4\n2 19 21 40\n2 37 38 6\n2 33 38 18\n2 12 40 26\n2 27 42 38\n2 40 40 30", "7 3\n2 1 2 2\n1 3 7 2\n2 3 7 3", "29 5\n2 4 9 27\n1 25 29 14\n1 9 10 18\n2 13 13 5\n2 1 19 23", "3 6\n1 1 1 2\n2 1 1 2\n1 2 2 2\n2 2 2 2\n1 3 3 2\n2 3 3 3", "7 14\n1 1 1 1\n2 1 1 6\n1 2 2 1\n2 2 2 5\n1 3 3 1\n2 3 3 6\n1 4 4 5\n2 4 4 7\n1 5 5 1\n2 5 5 2\n1 6 6 2\n2 6 6 2\n1 7 7 5\n2 7 7 5", "8 16\n1 1 1 2\n2 1 1 3\n1 2 2 6\n2 2 2 8\n1 3 3 1\n2 3 3 2\n1 4 4 3\n2 4 4 3\n1 5 5 1\n2 5 5 2\n1 6 6 2\n2 6 6 5\n1 7 7 3\n2 7 7 3\n1 8 8 3\n2 8 8 3"], "outputs": ["3", "5", "9", "-1", "50", "50", "50", "-1", "-1", "64", "-1", "-1", "-1", "88", "50", "-1", "-1", "1", "1", "52", "2500", "-1", "-1", "-1", "13", "8", "13", "64", "17", "29", "5", "7", "16"]}
UNKNOWN
PYTHON3
CODEFORCES
4
216b7c32d3e33f332f60bc12ab2da822
Logo Turtle
A lot of people associate Logo programming language with turtle graphics. In this case the turtle moves along the straight line and accepts commands "T" ("turn around") and "F" ("move 1 unit forward"). You are given a list of commands that will be given to the turtle. You have to change exactly *n* commands from the list (one command can be changed several times). How far from the starting point can the turtle move after it follows all the commands of the modified list? The first line of input contains a string *commands* — the original list of commands. The string *commands* contains between 1 and 100 characters, inclusive, and contains only characters "T" and "F". The second line contains an integer *n* (1<=≤<=*n*<=≤<=50) — the number of commands you have to change in the list. Output the maximum distance from the starting point to the ending point of the turtle's path. The ending point of the turtle's path is turtle's coordinate after it follows all the commands of the modified list. Sample Input FT 1 FFFTFFF 2 Sample Output 2 6
[ "s = input()\r\nn = int(input())\r\nl, r = [-1e9] * 101, [-1e9] * 101\r\nl[0] = r[0] = 0\r\nfor q in s:\r\n for j in range(n, -1, -1):\r\n x = max(r[j], l[j - 1] + 1) if q == 'T' else max(l[j] + 1, r[j - 1])\r\n y = max(l[j], r[j - 1] + 1) if q == 'T' else max(r[j] - 1, l[j - 1])\r\n l[j], r[j] = x, y\r\nprint(max(l[n % 2:n + 1:2] + r[n % 2:n + 1:2]))", "s=input().strip()\r\nn=int(input())\r\ndp=[[[-float(\"inf\"),-float(\"inf\")] for _ in range(n+1)]for _ in range(len(s))]\r\nx=int(s[0]!=\"F\")\r\nfor i in range(n+1):\r\n dp[0][i][x]=x^1\r\n x^=1\r\nfor i in range(1,len(s)):\r\n for j in range(n+1):\r\n x=int(s[i]!=\"F\")\r\n for k in range(j,-1,-1):\r\n dp[i][j][0]=max(dp[i][j][0],dp[i-1][k][x]+(x^1))\r\n dp[i][j][1]=max(dp[i][j][1],dp[i-1][k][x^1]-(x^1))\r\n x^=1\r\ndp1=[[[float(\"inf\"),float(\"inf\")] for _ in range(n+1)]for _ in range(len(s))]\r\nx=int(s[0]!=\"F\")\r\nfor i in range(n+1):\r\n dp1[0][i][x]=x^1\r\n x^=1\r\nfor i in range(1,len(s)):\r\n for j in range(n+1):\r\n x=int(s[i]!=\"F\")\r\n for k in range(j,-1,-1):\r\n dp1[i][j][0]=min(dp1[i][j][0],dp1[i-1][k][x]+(x^1))\r\n dp1[i][j][1]=min(dp1[i][j][1],dp1[i-1][k][x^1]-(x^1))\r\n x^=1 \r\nprint(max(max(dp[-1][n]),abs(min(dp1[-1][n]))))", "line = input()\r\nn = int(input())\r\ndp = [[[-100] * 2 for _ in range(n+1)] for _ in range(len(line)+1)]\r\ndp[0][0][0], dp[0][0][1] = 0, 0\r\nfor i in range(1, len(line)+1):\r\n for j in range(n+1):\r\n for k in range(j+1):\r\n if (line[i-1] == \"F\" and k % 2 == 1) or (line[i-1] == \"T\" and k % 2 == 0):\r\n dp[i][j][0] = max(dp[i][j][0], dp[i-1][j-k][1])\r\n dp[i][j][1] = max(dp[i][j][1], dp[i-1][j-k][0])\r\n else:\r\n dp[i][j][0] = max(dp[i][j][0], dp[i-1][j-k][0] + 1)\r\n dp[i][j][1] = max(dp[i][j][1], dp[i-1][j-k][1] - 1)\r\nprint(max(dp[-1][-1][0], dp[-1][-1][1]))", "s=input();m,n=len(s),int(input());inf=float('inf');f=[[-inf]*2 for _ in range(n+1)]\r\nfor i in range(m):\r\n f1=[[-inf]*2 for _ in range(n+1)]\r\n for j in range(n+1):\r\n for k in range(2):\r\n for c in range([0,j][i==0],j+1):\r\n t=s[i]=='T' and c&1==0 or s[i]=='F' and c&1==1\r\n sub=f[j-c][1^k if t else k] if 0<i else 0\r\n d=0 if t else(1 if k==1 else -1)\r\n f1[j][k]=max(f1[j][k],sub+d)\r\n f1,f=f,f1\r\nprint(max(f[n]))# 1698410541.8080277", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\ndef f(u, v):\r\n return 210 * u + v\r\n\r\ns = list(input().rstrip())\r\nn = int(input())\r\nl = 210 * (n + 1)\r\ndpl, dpr = [0] * l, [0] * l\r\nc = 104\r\ndpl[f(0, c)] = 1\r\nm = 0\r\nfor i in s:\r\n m = min(m + 1, n)\r\n if i & 2:\r\n for j in range(m, -1, -1):\r\n if j ^ m:\r\n for k in range(1, 209):\r\n u, v = f(j, k), f(j + 1, k)\r\n dpl[v] |= dpr[u]\r\n dpr[v] |= dpl[u]\r\n for k in range(1, 209):\r\n u = f(j, k)\r\n if dpl[u + 1]:\r\n dpl[u], dpl[u + 1] = 1, 0\r\n for k in range(208, 0, -1):\r\n u = f(j, k)\r\n if dpr[u - 1]:\r\n dpr[u], dpr[u - 1] = 1, 0\r\n else:\r\n for j in range(m, -1, -1):\r\n if j ^ m:\r\n for k in range(1, 209):\r\n u, v = f(j, k + 1), f(j + 1, k)\r\n dpl[v] |= dpl[u]\r\n for k in range(208, 0, -1):\r\n u, v = f(j, k - 1), f(j + 1, k)\r\n dpr[v] |= dpr[u]\r\n for k in range(1, 209):\r\n u = f(j, k)\r\n dpl[u], dpr[u] = dpr[u], dpl[u]\r\nans = 0\r\nfor i in range(n % 2, n + 1, 2):\r\n for j in range(1, 209):\r\n if dpl[f(i, j)] | dpr[f(i, j)]:\r\n ans = max(ans, abs(j - c))\r\nprint(ans)", "from sys import stdin\r\nimport sys\r\nsys.setrecursionlimit(10000000)\r\ns=stdin.readline().strip()\r\nn=int(stdin.readline().strip())\r\ndp1=[[[[-110 for i in range(51)] for j in range(101)] for k in range(2)] for k1 in range(2)]\r\ndp2=[[[[-110 for i in range(51)] for j in range(101)] for k in range(2)] for k1 in range(2)]\r\ninf=1000\r\ndef sol(pos,el,cam,dir):\r\n \r\n if pos>=len(s):\r\n if el==0:\r\n return 0\r\n else:\r\n return -inf\r\n if el<0:\r\n return -inf\r\n \r\n if dp1[dir][cam][pos][el]!=-110:\r\n return dp1[dir][cam][pos][el]\r\n e=s[pos]\r\n if s[pos]==\"F\" and cam==1:\r\n e=\"T\"\r\n if s[pos]==\"T\" and cam==1:\r\n e=\"F\"\r\n ans=-inf\r\n if e==\"F\":\r\n if dir==1:\r\n ans=max(1+sol(pos+1,el,0,dir),sol(pos,el-1,(cam+1)%2,(dir)%2))\r\n else:\r\n ans=max(-1+sol(pos+1,el,0,dir),sol(pos,el-1,(cam+1)%2,(dir)%2))\r\n else:\r\n ans=max(sol(pos+1,el,0,(dir+1)%2),sol(pos,el-1,(cam+1)%2,dir))\r\n dp1[dir][cam][pos][el]=ans\r\n return ans\r\ndef sol2(pos,el,cam,dir):\r\n \r\n if pos>=len(s):\r\n if el==0:\r\n return 0\r\n else:\r\n return inf\r\n if el<0:\r\n return inf\r\n if dp2[dir][cam][pos][el]!=-110:\r\n return dp2[dir][cam][pos][el]\r\n e=s[pos]\r\n if s[pos]==\"F\" and cam==1:\r\n e=\"T\"\r\n if s[pos]==\"T\" and cam==1:\r\n e=\"F\"\r\n ans=inf\r\n if e==\"F\":\r\n if dir==1:\r\n ans=min(1+sol2(pos+1,el,0,dir),sol2(pos,el-1,(cam+1)%2,(dir)))\r\n else:\r\n ans=min(-1+sol2(pos+1,el,0,dir),sol2(pos,el-1,(cam+1)%2,(dir)))\r\n else:\r\n ans=min(sol2(pos+1,el,0,(dir+1)%2),sol2(pos,el-1,(cam+1)%2,dir))\r\n dp2[dir][cam][pos][el]=ans\r\n return ans\r\nprint(max(sol(0,n,0,1),-sol2(0,n,0,1)))\r\n", "I,G=input,range;s=I();m,n=len(s),int(I());inf=float('inf');f=[[-inf]*2 for _ in G(n+1)]\r\nfor i in G(m):\r\n f1=[[-inf]*2 for _ in G(n+1)]\r\n for j in G(n+1):\r\n for k in G(2):\r\n for c in G([0,j][i==0],j+1):\r\n t=s[i]=='T' and c&1==0 or s[i]=='F' and c&1==1\r\n sub=f[j-c][1^k if t else k] if 0<i else 0\r\n d=0 if t else(1 if k==1 else -1)\r\n f1[j][k]=max(f1[j][k],sub+d)\r\n f1,f=f,f1\r\nprint(max(f[n]))" ]
{"inputs": ["FT\n1", "FFFTFFF\n2", "F\n1", "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n50", "FTFTFTFFFFTFTFTTTTTTFFTTTTFFTFFFTFTFTFFTFTFTFFFTTTFTTFTTTTTFFFFTTT\n12", "TTFFTFTTFTTTFFFTFTFFTFFTTFFTFTFTFTFFTTTFTFFTFFTTTTFTTTFFT\n46", "TTFFFFFFFTTTTFTTFTFFTTFFFTFTTTFFFFTFFFTFTTTFTTF\n24", "FFTTFTTFFFTFFFFTFTTFFTTFTFFFTFFTFTFTTT\n46", "FFTFTTFTFTFTFFTTFTFFTFTFTTTT\n1", "TFFTTFTFFTFFTTTTFTF\n19", "TTFFFFTTF\n22", "FTFTFFFTTTFFTTTFTTFTTTFTTTTFTTFFFTFTFTFTFFFTFTFFTTTFFTFTFTFTTFTTTTFFTTTTTFFFFTFTTFFTFFFTTTFFTFF\n18", "FTTFTTTFTTFFFTFFTTFTFTTTFFFTFTFTFFTTTFFFFFFTFTTFFTFFFFTFTTFFFTFFTTTTTFFTFTTFFFTFFTFFTF\n16", "TFFTFTTTFFTFTFTTTFFTTFFTFTFFTFFFFTTTTTFTFTFTTFFTTFTFFTTFTFFTTTTFFTFTTTFTTTTFFFFTFFTFFTFFFFTTTT\n2", "FTTFFTFFFFTTFFFTFFTTFFTTFFTTFFFTTFFTFTFTTFTFFTTTFTTFTTFTFFFFTFTFTFFFFFTTFTFFTTTFFFTF\n50", "FTTTTTFTTTTFTFFTFFFTTTTTTTTFTTFFTTTTFFTFTFTFFTFTFTTFTFTFTFFTFTFTFFTFFTTTTTT\n4", "TTTFTFTTTFTTFFTFFFFTTTFFFFTTFTFTFFFTTTTFFTTTFFTFTFTFFTTTFFTTFFTFT\n27", "TFFTFFFFTFFFTFFFFFTFFFFFFTFFTTTTFFTTFTTTFFTTFFFFTTFFTFFF\n42", "FFFFTTTTTTFTFFTFFFTFTFTFTFFTFFTFFTFTTFTTTFFFTF\n48", "FFFTTTFTTFFTTFFFTFFFFFTTFTFFTFTTTFFT\n48", "TTTTFFTFTFFFFTTFTFTFTTTTFFF\n43", "TTTFFFFTTTFTFTFFT\n50", "FTFTTFTF\n38", "TFTFFTFTTFFTTTTTTFTFTTFFTTTTTFTFTFTTFFTTFTTTFT\n11", "FFTTTFTFTFFFFTTTFFTFTFTFTFFFFFTTFTFT\n10", "TFFFTFFFTTFTTTFTFFFFFFTTFTF\n10", "TTFFFTTTTFFFFTTTF\n34", "FTTTFTFF\n8", "FTTFTFFTFTTTFTTFTFFTTFFFFFTFFFFTTFTFFFFFFTFFTTTFTTFTTTFFFTFTFTFFFFTFFTFTTTTTTTTFTTTTTTFFTTFTTT\n35", "TFTTFFTTFFTFTTFFTFFTTFTFTTTTTFFFFTFFTTFTTTFFTFTTFFFFTFTTTTFFFFTTTFTFTFTTFTFTFTFTTFTF\n26", "TFFFFFFFFFTTFTTFTFTFFFTFTFTTFTFTFFTFTTFTTFTTFFFTTFTFFFFFTFTFFTFTFFTTTTFTTFT\n13", "FFFTTTTTFTTFTTTFTFTFTTFTFTTFTTFTTTFFFFFFFFTTFTTTTTTFTTFFFFTTFTFFF\n6", "FTTFTTFFFFFTTFFFTFFFFTFTTFFTFTFFTFTFTTTFFTTFFTFTFTTFFFTT\n47", "FTFFTFTTFFTFTFFTTTTTFTFTFTFFFFTTFTTFTFTTTFTTFFFFFFTFTFTFFFTFTT\n10", "FFFTTTFTFTTTFFTTFTTTTTFFFFFTTFTFTFFFFTFFFFFTTTTFFFTF\n21", "TFTFFTTFFTTFTFFTFTFTFFTFTTTFFTTTTTTFTFFTFTF\n27", "TFTTFFFTFFTTFFTTFTTFTFTFFFTTFTTTF\n4", "FTTFTFTFFTTTTFFTFTTFTTFT\n24", "TTFTTTFFFTFFFF\n36", "TTFFF\n49", "FFTFTTFFTTFFFFFFTTTTFFTFFTFFFTTTTTTTTTTFFFTFFTFTFFTTTTTFFFFTTTFFFFTFFFFFTTTFTTFFFTFTFTTTFFT\n40", "FFTTTFFTTTFTTFTFTTFTTFTFTFFTTTTFFFFTFFTFTTFTFFTTTTTTFFTTFFFTTFTTFFTTTTTFFTFFTFTTT\n1", "TFTFFFTTTFFFFFFFTTFTTTFFFTTFFTTTFTTTFTTTTTFTTFFFTTTTTTFFTFFFFTFFTFTFTFFT\n4", "FTTTTTFTFFTTTFFTTFTFFTFTTFTTFFFTTFTTTFFFFFFFTFFTTTTFFTTTFFFFFTFFFFFFFFTFTTFTFT\n6", "TTTFFFTTFTFFFTTTFFFFTTFTTTTFTFFFFTFTTTFTTTFTTFTTFFTFTFTFTFFTTFTFTFTT\n41", "TFTTFFFFFFFTTTFTFFFTTTFTFFFTFTFTFFFTFTFTTTFTTFFTFTTFTFFTFTF\n8", "FFFFTTTTTFFFFTTTFFTTFFTFTTFFTTFFFTTTTFTFFFTFTTFTT\n43", "FFFFTTFFTTFFTTFTFFTTTFTFTFFTFTFTTFFTFTTF\n41", "TTTTFTTFTFFTFTTTTFFTFTFFFTFFTF\n24", "TTTFFFFTTFTFTTTTTFTFF\n30", "FTTTTFTFTTT\n31", "FFFFTTFTTTTFTTTFTFFFFFTTFFTFFTFFTTFTTFFTFTFTTTTFFFTFTTTFTFTFFTFFFTFTFFFFFFFFFTFFTTFFFFFFTFFFFFTTT\n18", "TFFTFTTTTFTTFTFFTFTFTFTTTTTTTTFTTFTTFTFTTFFTTTFFTTTFFTTTTFTFTFFTTTTTFTTFTFTFTTTTFFFTTFTF\n45", "TTFFFFFFTFFFFTFFTFTTTFTFFFFFFFTFFTTFFFTFFFFFTTFFFTTTTFFFFFTFFFTTFTFFTTTTFFFFTFTTTFTFTTTTFFTFTF\n44", "TFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTFTF\n25", "TFFFTTFFF\n2", "TFFFTTTFFFFTFFTTFTTFTTFFTFFFTTTTTTFTTTTTTFFFFFFFTFFFFTTTFTFFTTTTTTFFFFFTTFTFTFFFTFTTFFTTFFFTTFFFTTTT\n1", "TFFFFFTFFFFF\n1", "FFFFTFTF\n1"], "outputs": ["2", "6", "0", "100", "41", "57", "47", "37", "6", "18", "9", "61", "61", "19", "83", "20", "58", "56", "45", "36", "26", "16", "8", "28", "30", "26", "16", "8", "80", "66", "54", "32", "56", "38", "47", "43", "20", "24", "14", "4", "87", "16", "29", "40", "68", "34", "49", "40", "30", "21", "10", "75", "78", "94", "51", "8", "17", "11", "5"]}
UNKNOWN
PYTHON3
CODEFORCES
7
217e38012c7854256183c07a6bdc62c5
Petya's Exams
Petya studies at university. The current academic year finishes with $n$ special days. Petya needs to pass $m$ exams in those special days. The special days in this problem are numbered from $1$ to $n$. There are three values about each exam: - $s_i$ — the day, when questions for the $i$-th exam will be published, - $d_i$ — the day of the $i$-th exam ($s_i &lt; d_i$), - $c_i$ — number of days Petya needs to prepare for the $i$-th exam. For the $i$-th exam Petya should prepare in days between $s_i$ and $d_i-1$, inclusive. There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the $i$-th exam in day $j$, then $s_i \le j &lt; d_i$. It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days. Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible. The first line contains two integers $n$ and $m$ $(2 \le n \le 100, 1 \le m \le n)$ — the number of days and the number of exams. Each of the following $m$ lines contains three integers $s_i$, $d_i$, $c_i$ $(1 \le s_i &lt; d_i \le n, 1 \le c_i \le n)$ — the day, when questions for the $i$-th exam will be given, the day of the $i$-th exam, number of days Petya needs to prepare for the $i$-th exam. Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given. If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print $n$ integers, where the $j$-th number is: - $(m + 1)$, if the $j$-th day is a day of some exam (recall that in each day no more than one exam is conducted), - zero, if in the $j$-th day Petya will have a rest, - $i$ ($1 \le i \le m$), if Petya will prepare for the $i$-th exam in the day $j$ (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).Assume that the exams are numbered in order of appearing in the input, starting from $1$.If there are multiple schedules, print any of them. Sample Input 5 2 1 3 1 1 5 1 3 2 1 3 1 1 2 1 10 3 4 7 2 1 10 3 8 9 1 Sample Output 1 2 3 0 3 -1 2 2 2 1 1 0 4 3 4 4
[ "(n, m) = map(int, input().split())\r\n\r\narray = [0] * (n + 1)\r\nlst = []\r\nfor x in range(m):\r\n (s, d, c) = map(int, input().split())\r\n lst.append((d, s, c, x + 1))\r\n\r\nlst.sort()\r\ni = 0\r\nflag = True\r\nfor (d, s, c, p) in lst:\r\n x = s\r\n while c > 0 and x < d:\r\n if array[x] == 0:\r\n array[x] = p\r\n c -= 1\r\n x += 1\r\n if c != 0:\r\n flag = False\r\n break\r\n else:\r\n array[d] = m + 1\r\n\r\nif flag:\r\n print(*array[1:])\r\nelse:\r\n print(-1)\r\n", "\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nd = [0]*101\r\ng = sorted([(list(map(int, input().split())), i+1) for i in range(m)], key=lambda x:x[0][1])\r\new = 0\r\nfor a, b in g:\r\n d[a[1]] = m+1\r\n i, j = a[0], a[2]\r\n while j:\r\n if d[i] == 0:\r\n d[i] = b\r\n j -= 1\r\n i += 1\r\n if i == a[1]:\r\n break\r\n if j:\r\n ew = 1\r\n break\r\nprint(-1 if ew else ' '.join(map(str, d[1:n+1])))\r\n", "from collections import defaultdict\r\nimport sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\nans = [0] * (n+1)\r\narr = []\r\nf = True\r\n\r\nfor i in range(m):\r\n s, d, c = map(int, input().split())\r\n arr.append((s, d, c, i+1))\r\n ans[d] = m+1\r\n\r\narr.sort(key=lambda x: x[1])\r\n\r\nfor v in arr:\r\n cnt = 0\r\n for i in range(v[0], v[1]+1):\r\n if ans[i] == 0:\r\n ans[i] = v[3]\r\n cnt += 1\r\n\r\n if cnt == v[2]:\r\n break\r\n\r\n if cnt < v[2]:\r\n f = False\r\n break\r\n\r\nif f:\r\n print(*ans[1:])\r\nelse:\r\n print(-1)", "import heapq\nfrom collections import defaultdict\n\ndays, num_exams = map(int, input().split())\n\nevents = defaultdict(list)\nexams = set()\n\nfor i in range(num_exams):\n day_released, exam_day, cooldown = map(int, input().split())\n events[day_released].append([exam_day, cooldown, i + 1])\n exams.add(exam_day)\n\ncan_take = [False] * days\nexams_taken = set()\n\nans = []\npq = []\nfor day in range(1, days + 1):\n for (exam_day, cooldown, exam_id) in events[day]:\n heapq.heappush(pq, [exam_day, cooldown, exam_id])\n\n if day in exams:\n if can_take[day - 1]:\n exams_taken.add(day)\n ans.append(num_exams + 1)\n else:\n print(-1)\n exit()\n elif len(pq) == 0:\n ans.append(0)\n else:\n exam_day, cooldown, exam_id = heapq.heappop(pq)\n cooldown -= 1\n ans.append(exam_id)\n if cooldown > 0:\n heapq.heappush(pq, [exam_day, cooldown, exam_id])\n else:\n can_take[exam_day - 1] = True\n\nprint(*ans)\n\n\n", "n, m = map(int, input().split())\n\na = [list(map(int, input().split())) for i in range(m)]\nfor i in range(m):\n a[i].append(i+1)\na = sorted(a, key=lambda x: [x[1], x[0]])\n\nsol = [0 for i in range(n)]\nimp = False\nfor i in range(m):\n si, di, ci, pos = a[i]\n if sol[di-1] != 0:\n imp = True\n break\n else:\n sol[di-1] = m+1\n\n for j in range(si-1, di-1):\n if sol[j] == 0:\n sol[j] = pos\n ci -= 1\n\n if ci == 0:\n break\n\n if ci != 0:\n imp = True\n break\n\nif imp:\n print(-1)\nelse:\n print(*sol)\n", "# https://codeforces.com/contest/978\n\nimport sys\n\ninput = lambda: sys.stdin.readline().rstrip() # faster!\n\nn, m = map(int, input().split())\ns, d, c = [], [], []\nfor _ in range(m):\n x, y, z = map(int, input().split())\n s += [x - 1]\n d += [y - 1]\n c += [z]\n\nans = [0] * n\nfor x in d:\n ans[x] = m + 1\n\nactive = []\nfor t in range(n):\n active += [i for i in range(m) if s[i] == t]\n if ans[t] == m + 1 or not active:\n continue\n nxt = active[0]\n for i in active:\n if d[i] < d[nxt]:\n nxt = i\n if t >= d[nxt]:\n print(-1)\n exit()\n ans[t] = nxt + 1\n c[nxt] -= 1\n if c[nxt] == 0:\n active.remove(nxt)\n\nif active:\n print(-1)\nelse:\n print(*ans)\n", "from heapq import *\nt = 1\n\nfor _ in range(t):\n n, m = map(int,input().split())\n h = []\n res = [0]*n\n exams = []\n for _ in range(m):\n a,b,c = map(int,input().split())\n res[b-1] = m + 1\n exams.append([a-1,b-1,c])\n curr = 0\n while curr < n:\n best = -1\n if res[curr] != 0:\n curr +=1\n continue\n for i,exam in enumerate(exams):\n if exam[0] > curr or exam[2] == 0 or exam[1] < curr:\n continue\n if best == -1:\n best = i\n else:\n if exams[i][1] < exams[best][1]:\n best = i\n if best != -1:\n res[curr] = best + 1\n exams[best][2] -= 1\n curr += 1\n poss = True \n for exam in exams:\n if exam[-1] > 0:\n poss = False\n if poss:\n for r in res:\n print(r,end=\" \")\n else:\n print(-1)", "rd=lambda:map(int,input().split())\r\nn,m=rd()\r\na=sorted(([*rd()]+[i+1] for i in range(m)),key=lambda x:x[1])\r\nr=[0]*n\r\nfor x in a:\r\n\tr[x[1]-1]=m+1\r\n\tfor i in range(x[0]-1,x[1]-1):\r\n\t\tif not r[i]:\r\n\t\t\tr[i]=x[3]\r\n\t\t\tx[2]-=1\r\n\t\t\tif not x[2]:\r\n\t\t\t\tbreak\r\n\tif x[2]:\r\n\t\tprint(-1)\r\n\t\texit()\r\nprint(*r)", "n,m=list(map(int, input().split()))\r\nans,p,flag=[0]*n,[],0\r\nfor i in range(m):\r\n s,d,c=list(map(int, input().split()))\r\n s-=1\r\n d-=1\r\n if ans[d]:\r\n print(\"-1\")\r\n flag=1\r\n break\r\n ans[d]=m+1\r\n p.append([d,s,c,i+1])\r\nif not flag:\r\n p.sort()\r\n for d,s,c,i in p:\r\n j=s\r\n while j<d:\r\n if not ans[j]:\r\n ans[j]=i\r\n c-=1\r\n if c==0:\r\n break\r\n j+=1\r\n else:\r\n print(\"-1\")\r\n flag=1\r\n break\r\n if not flag:\r\n print(*ans)", "from collections import *\r\nfrom heapq import *\r\nfrom bisect import *\r\nfrom itertools import *\r\nfrom functools import *\r\nfrom math import *\r\nfrom string import *\r\nimport operator\r\nimport sys\r\nimport heapq\r\n\r\ninput = sys.stdin.readline\r\n\r\n\r\ndef solve():\r\n n, m = map(int, input().split())\r\n TEST = m + 1\r\n\r\n events = defaultdict(list)\r\n studied = set()\r\n test_days = {}\r\n\r\n for exam_id in range(1, m + 1):\r\n released, exam, req = map(int, input().split())\r\n events[released].append((exam, exam_id, req))\r\n test_days[exam] = exam_id\r\n\r\n ans = [0] * (n + 1)\r\n pq = []\r\n for day in range(1, n + 1):\r\n # emit events\r\n for exam, exam_id, req in events[day]:\r\n heapq.heappush(pq, (exam, exam_id, req))\r\n\r\n if day in test_days:\r\n exam = test_days[day]\r\n if exam not in studied:\r\n print(-1)\r\n return\r\n\r\n ans[day] = TEST\r\n continue\r\n\r\n if len(pq) == 0:\r\n ans[day] = 0\r\n continue\r\n\r\n exam, exam_id, req = heapq.heappop(pq)\r\n ans[day] = exam_id\r\n\r\n req -= 1\r\n if req == 0:\r\n studied.add(exam_id)\r\n else:\r\n heapq.heappush(pq, (exam, exam_id, req))\r\n\r\n print(*ans[1:])\r\n\r\n\r\ndef main():\r\n tests = 1\r\n for _ in range(tests):\r\n solve()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n" ]
{"inputs": ["5 2\n1 3 1\n1 5 1", "3 2\n1 3 1\n1 2 1", "10 3\n4 7 2\n1 10 3\n8 9 1", "2 1\n1 2 1", "3 1\n1 2 2", "3 1\n1 3 2", "100 1\n1 100 99", "100 1\n1 100 100", "100 1\n1 100 98", "100 2\n1 100 49\n1 99 49", "10 2\n3 7 4\n6 10 1", "10 4\n2 5 1\n1 4 2\n4 7 1\n7 10 2", "20 5\n6 16 3\n4 14 4\n3 13 1\n1 11 1\n10 20 4", "30 7\n1 4 1\n22 25 1\n25 28 2\n9 12 1\n13 16 1\n11 14 1\n14 17 1", "50 14\n42 44 2\n38 40 1\n6 8 2\n37 39 1\n33 35 1\n17 19 2\n12 14 2\n2 4 1\n9 11 2\n1 3 1\n32 34 1\n24 26 1\n44 46 1\n48 50 1", "50 7\n45 50 4\n26 31 5\n35 40 3\n38 43 1\n39 44 3\n3 8 2\n1 6 1", "50 15\n41 46 5\n35 40 5\n27 32 3\n10 15 2\n1 6 3\n20 25 1\n11 16 1\n9 14 1\n13 18 2\n18 23 3\n2 7 2\n25 30 1\n29 34 1\n43 48 1\n45 50 1", "90 30\n1 5 1\n57 61 3\n13 17 1\n60 64 1\n73 77 2\n5 9 2\n16 20 3\n29 33 4\n83 87 3\n63 67 2\n35 39 4\n18 22 1\n42 46 4\n46 50 2\n48 52 2\n23 27 1\n82 86 1\n77 81 3\n67 71 2\n22 26 2\n37 41 1\n6 10 1\n50 54 1\n8 12 1\n86 90 1\n68 72 1\n11 15 1\n72 76 1\n62 66 1\n52 56 1", "100 38\n41 43 1\n53 55 2\n91 93 2\n47 49 2\n77 79 2\n5 7 2\n2 4 2\n28 30 1\n79 81 1\n42 44 1\n27 29 1\n95 97 2\n58 60 1\n57 59 1\n61 63 2\n33 35 2\n22 24 1\n44 46 1\n10 12 2\n13 15 1\n97 99 1\n37 39 2\n18 20 1\n50 52 2\n21 23 1\n68 70 2\n83 85 1\n71 73 2\n65 67 1\n64 66 1\n15 17 1\n7 9 1\n88 90 2\n30 32 1\n74 76 1\n24 26 1\n85 87 1\n82 84 1", "100 43\n76 77 1\n24 25 1\n2 3 1\n85 86 1\n49 50 1\n15 16 1\n30 31 1\n78 79 1\n54 55 1\n58 59 1\n17 18 1\n67 68 1\n21 22 1\n80 81 1\n35 36 1\n8 9 1\n83 84 1\n44 45 1\n62 63 1\n64 65 1\n72 73 1\n27 28 1\n56 57 1\n12 13 1\n40 41 1\n32 33 1\n52 53 1\n70 71 1\n97 98 1\n37 38 1\n87 88 1\n46 47 1\n89 90 1\n4 5 1\n94 95 1\n60 61 1\n99 100 1\n10 11 1\n74 75 1\n6 7 1\n91 92 1\n19 20 1\n42 43 1", "100 35\n52 55 1\n55 58 1\n69 72 1\n32 35 1\n9 12 3\n68 71 1\n78 81 3\n51 54 1\n56 59 1\n63 66 3\n4 7 2\n12 15 2\n74 77 1\n87 90 3\n72 75 1\n93 96 2\n39 42 2\n15 18 1\n92 95 1\n23 26 3\n83 86 2\n28 31 2\n58 61 1\n47 50 1\n46 49 2\n31 34 1\n82 85 1\n96 99 2\n38 41 1\n41 44 1\n5 8 1\n34 37 1\n19 22 3\n27 30 1\n67 70 1", "100 4\n73 83 4\n79 89 8\n12 22 6\n23 33 9", "100 2\n39 43 1\n82 86 3", "100 36\n2 5 2\n35 38 1\n55 58 2\n40 43 3\n73 76 2\n30 33 3\n87 90 3\n93 96 1\n97 100 1\n42 45 1\n44 47 1\n66 69 3\n95 98 1\n12 15 3\n47 50 1\n72 75 1\n57 60 2\n1 4 1\n8 11 3\n15 18 1\n22 25 2\n76 79 2\n82 85 1\n91 94 2\n83 86 2\n33 36 1\n62 65 3\n26 29 3\n18 21 1\n36 39 1\n68 71 1\n50 53 1\n51 54 1\n4 7 1\n17 20 1\n78 81 1", "100 37\n49 51 2\n79 81 2\n46 48 2\n71 73 2\n31 33 2\n42 44 1\n17 19 2\n64 66 2\n24 26 1\n8 10 2\n38 40 1\n1 3 2\n75 77 2\n52 54 2\n11 13 2\n87 89 1\n98 100 2\n60 62 1\n56 58 2\n39 41 1\n92 94 1\n13 15 1\n67 69 2\n4 6 2\n19 21 1\n91 93 1\n86 88 1\n43 45 1\n25 27 1\n94 96 1\n81 83 1\n35 37 1\n34 36 1\n61 63 1\n21 23 1\n83 85 1\n27 29 1", "50 16\n42 44 2\n18 20 2\n10 12 1\n9 11 2\n25 27 1\n45 47 1\n12 14 1\n29 31 2\n4 6 1\n46 48 1\n32 34 2\n34 36 1\n48 50 1\n21 23 1\n15 17 2\n24 26 1", "90 29\n1 5 1\n56 60 2\n31 35 4\n86 90 2\n25 29 4\n58 62 2\n73 77 2\n12 16 2\n65 69 1\n16 20 3\n42 46 4\n62 66 2\n2 6 2\n77 81 1\n80 84 1\n48 52 4\n81 85 2\n68 72 1\n57 61 1\n75 79 1\n35 39 2\n37 41 1\n18 22 1\n4 8 2\n67 71 1\n85 89 1\n20 24 1\n10 14 2\n51 55 2", "100 6\n3 43 40\n46 86 24\n38 78 5\n51 91 8\n59 99 12\n60 100 2", "100 36\n2 5 2\n35 38 1\n55 58 2\n40 43 3\n73 76 2\n30 33 3\n87 90 3\n93 96 1\n97 100 1\n42 45 1\n44 47 1\n66 69 3\n95 98 1\n12 15 3\n47 50 1\n72 75 1\n57 60 2\n1 4 1\n8 11 3\n15 18 1\n22 25 2\n76 79 2\n82 85 1\n91 94 2\n83 86 2\n33 36 1\n62 65 3\n26 29 3\n18 21 1\n36 39 1\n68 71 1\n50 53 2\n51 54 1\n4 7 1\n17 20 1\n78 81 1", "100 37\n49 51 2\n79 81 2\n46 48 2\n71 73 2\n31 33 3\n42 44 1\n17 19 2\n64 66 2\n24 26 1\n8 10 2\n38 40 1\n1 3 2\n75 77 2\n52 54 2\n11 13 2\n87 89 1\n98 100 2\n60 62 1\n56 58 2\n39 41 1\n92 94 1\n13 15 1\n67 69 2\n4 6 2\n19 21 1\n91 93 1\n86 88 1\n43 45 1\n25 27 1\n94 96 1\n81 83 1\n35 37 1\n34 36 1\n61 63 1\n21 23 1\n83 85 1\n27 29 1", "90 30\n1 5 1\n57 61 3\n13 17 1\n60 64 1\n73 77 2\n5 9 2\n16 20 3\n29 33 5\n83 87 3\n63 67 2\n35 39 4\n18 22 1\n42 46 4\n46 50 2\n48 52 2\n23 27 1\n82 86 1\n77 81 3\n67 71 2\n22 26 2\n37 41 1\n6 10 1\n50 54 1\n8 12 1\n86 90 1\n68 72 1\n11 15 1\n72 76 1\n62 66 1\n52 56 1", "100 38\n41 43 1\n53 55 2\n91 93 2\n47 49 2\n77 79 2\n5 7 2\n2 4 2\n28 30 1\n79 81 1\n42 44 1\n27 29 1\n95 97 2\n58 60 1\n57 59 1\n61 63 2\n33 35 2\n22 24 1\n44 46 1\n10 12 2\n13 15 1\n97 99 1\n37 39 3\n18 20 1\n50 52 2\n21 23 1\n68 70 2\n83 85 1\n71 73 2\n65 67 1\n64 66 1\n15 17 1\n7 9 1\n88 90 2\n30 32 1\n74 76 1\n24 26 1\n85 87 1\n82 84 1", "100 43\n76 77 1\n24 25 1\n2 3 1\n85 86 1\n49 50 1\n15 16 1\n30 31 1\n78 79 2\n54 55 1\n58 59 1\n17 18 1\n67 68 1\n21 22 1\n80 81 1\n35 36 1\n8 9 1\n83 84 1\n44 45 1\n62 63 1\n64 65 1\n72 73 1\n27 28 1\n56 57 1\n12 13 1\n40 41 1\n32 33 1\n52 53 1\n70 71 1\n97 98 1\n37 38 1\n87 88 1\n46 47 1\n89 90 1\n4 5 1\n94 95 1\n60 61 1\n99 100 1\n10 11 1\n74 75 1\n6 7 1\n91 92 1\n19 20 1\n42 43 1", "100 35\n52 55 1\n55 58 1\n69 72 1\n32 35 1\n9 12 3\n68 71 1\n78 81 3\n51 54 1\n56 59 1\n63 66 3\n4 7 2\n12 15 2\n74 77 1\n87 90 3\n72 75 1\n93 96 2\n39 42 2\n15 18 1\n92 95 1\n23 26 4\n83 86 2\n28 31 2\n58 61 1\n47 50 1\n46 49 2\n31 34 1\n82 85 1\n96 99 2\n38 41 1\n41 44 1\n5 8 1\n34 37 1\n19 22 3\n27 30 1\n67 70 1", "97 22\n10 17 6\n24 31 6\n79 86 7\n60 67 6\n42 49 5\n67 74 5\n34 41 4\n70 77 3\n51 58 5\n82 89 2\n89 96 5\n14 21 2\n40 47 1\n1 8 2\n23 30 1\n59 66 1\n50 57 2\n26 33 1\n15 22 2\n90 97 1\n32 39 1\n2 9 4", "12 11\n1 2 1\n2 3 2\n3 4 3\n4 5 4\n5 6 5\n6 7 6\n7 8 7\n8 9 8\n9 10 9\n10 11 10\n11 12 1", "6 2\n1 6 3\n1 2 1", "88 1\n1 2 1", "4 2\n1 4 1\n1 2 1", "100 2\n1 100 30\n1 20 1", "88 1\n1 3 1", "6 2\n1 5 2\n2 3 1", "7 2\n1 7 3\n2 3 1", "8 2\n3 8 2\n4 5 1", "10 2\n1 10 7\n2 3 1", "5 2\n1 5 2\n2 3 1", "10 2\n1 10 5\n2 3 1", "10 2\n1 10 4\n2 4 2", "10 2\n1 10 6\n3 7 1", "10 3\n4 8 2\n1 10 3\n5 6 1", "20 5\n4 14 4\n3 13 1\n1 11 1\n10 20 4\n6 16 3", "73 2\n33 35 2\n12 63 44", "86 5\n66 74 1\n29 33 3\n13 78 38\n20 34 2\n72 85 1", "9 4\n3 7 1\n6 9 1\n2 3 1\n1 8 2", "10 2\n1 10 5\n2 4 1", "10 4\n1 10 2\n1 4 2\n2 5 1\n7 8 1", "10 2\n1 10 7\n3 7 1", "96 37\n9 43 23\n60 66 4\n7 15 1\n3 86 4\n30 65 14\n36 38 1\n28 36 8\n68 80 4\n7 22 5\n17 68 1\n7 18 1\n12 47 2\n4 6 2\n5 11 3\n41 55 10\n7 45 22\n6 67 16\n12 50 18\n64 70 2\n21 48 26\n2 17 6\n14 44 10\n63 84 18\n14 19 5\n34 92 56\n51 56 2\n13 20 5\n62 74 2\n1 3 1\n6 46 17\n58 62 4\n10 27 16\n13 37 16\n21 23 1\n48 69 13\n67 82 13\n17 51 18", "31 3\n2 3 1\n1 12 4\n13 15 1", "7 2\n2 6 4\n3 4 1", "20 2\n3 4 1\n2 7 3", "100 5\n15 53 23\n16 85 32\n59 93 3\n54 57 1\n13 40 11", "100 5\n24 57 8\n28 72 15\n20 75 49\n27 67 7\n68 100 21", "11 2\n1 11 5\n4 8 4", "29 5\n5 10 3\n15 22 2\n18 27 4\n16 20 4\n7 11 1", "28 4\n4 23 11\n11 12 1\n2 4 1\n16 24 1", "90 8\n7 10 2\n27 28 1\n18 20 2\n12 48 2\n37 84 27\n29 32 2\n37 73 16\n3 40 14", "61 2\n12 41 24\n20 29 2", "27 8\n7 22 2\n3 5 1\n24 26 1\n1 14 1\n4 23 8\n10 12 1\n16 18 1\n5 6 1", "88 8\n1 5 2\n29 50 7\n36 42 6\n72 81 2\n12 19 4\n65 73 2\n15 80 29\n4 43 16", "34 17\n1 2 1\n6 12 4\n22 23 1\n5 6 1\n8 30 9\n2 7 2\n22 26 3\n3 34 31\n1 19 9\n4 11 7\n2 5 1\n4 9 3\n8 14 4\n2 22 14\n3 8 5\n32 33 1\n18 31 10", "9 2\n3 7 2\n1 9 5", "85 6\n4 63 17\n1 47 2\n25 26 1\n1 8 1\n24 78 44\n39 79 4", "85 5\n3 44 9\n77 85 7\n3 27 8\n5 42 4\n4 7 1", "50 5\n7 23 7\n4 12 4\n7 46 14\n15 32 8\n16 24 2", "6 3\n1 5 1\n1 6 1\n1 2 1", "100 3\n17 21 3\n1 66 38\n8 22 2"], "outputs": ["1 2 3 0 3 ", "-1", "2 2 2 1 1 0 4 3 4 4 ", "1 2 ", "-1", "1 1 2 ", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 ", "-1", "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 2 ", "2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 ", "0 0 1 1 1 1 3 2 0 3 ", "2 2 1 5 5 3 5 4 4 5 ", "4 0 3 2 2 2 2 1 1 1 6 5 6 6 5 6 5 5 0 6 ", "1 0 0 8 0 0 0 0 4 0 6 8 5 8 7 8 8 0 0 0 0 2 0 0 8 3 3 8 0 0 ", "10 8 15 15 0 3 3 15 9 9 15 7 7 15 0 0 6 6 15 0 0 0 0 12 0 15 0 0 0 0 0 11 5 15 15 0 4 2 15 15 0 1 1 15 13 15 0 14 0 15 ", "7 0 6 6 0 8 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 8 0 0 0 3 3 3 4 5 8 5 5 8 8 1 1 1 1 0 8 ", "5 5 5 11 11 16 16 0 8 4 4 7 9 16 16 16 9 16 10 10 10 6 16 0 16 12 3 3 3 16 13 16 0 16 2 2 2 2 2 16 1 1 1 1 1 16 14 16 15 16 ", "1 0 0 0 31 6 6 22 31 31 24 31 27 3 31 7 31 7 7 31 12 31 20 20 16 31 31 0 8 8 8 8 31 0 11 11 11 11 31 21 31 13 13 13 13 31 14 14 15 31 15 31 23 31 30 31 2 2 2 4 31 29 10 31 10 31 31 19 19 26 31 31 28 5 5 31 31 18 18 18 31 17 9 9 9 31 31 25 0 31 ", "0 7 7 39 6 6 39 32 39 19 19 39 20 0 39 31 39 23 0 39 25 17 39 39 36 39 11 8 39 39 34 39 16 16 39 0 22 22 39 0 1 10 39 39 18 39 4 4 39 24 24 39 2 2 39 0 14 13 39 39 15 15 39 30 29 39 39 26 26 39 28 28 39 35 0 39 5 5 39 9 39 38 27 39 39 37 39 33 33 39 3 3 39 0 12 12 39 21 39 0 ", "0 3 44 34 44 40 44 16 44 38 44 24 44 0 6 44 11 44 42 44 13 44 0 2 44 0 22 44 0 7 44 26 44 0 15 44 30 44 0 25 44 43 44 18 44 32 44 0 5 44 0 27 44 9 44 23 44 10 44 36 44 19 44 20 44 0 12 44 0 28 44 21 44 39 44 1 44 8 44 14 44 0 17 44 4 44 31 44 33 44 41 44 0 35 44 0 29 44 37 44 ", "0 0 0 11 11 31 36 36 5 5 5 36 12 12 36 18 0 36 33 33 33 36 20 20 20 36 34 22 22 36 36 26 4 36 36 32 36 29 17 17 36 36 30 36 0 25 25 24 36 36 8 1 0 36 36 2 9 36 36 23 36 0 10 10 10 36 35 6 3 36 36 36 15 13 36 0 36 7 7 7 36 27 21 21 36 36 14 14 14 36 0 19 16 16 36 36 28 28 36 0 ", "0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 0 0 0 0 5 4 4 4 4 4 4 4 4 4 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 2 2 2 2 5 2 2 2 2 0 5 0 0 0 0 0 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "18 1 1 37 37 34 37 19 19 19 37 14 14 14 37 20 35 37 29 37 37 21 21 0 37 28 28 28 37 6 6 6 37 26 2 37 30 37 37 4 4 4 37 10 37 11 37 15 0 37 32 33 37 37 3 3 17 37 17 37 0 27 27 27 37 12 12 12 37 31 37 16 5 5 37 37 22 22 37 36 37 23 25 25 37 37 7 7 7 37 24 24 8 37 13 37 9 37 0 37 ", "12 12 38 24 24 38 0 10 10 38 15 15 38 22 38 0 7 7 38 25 38 35 38 9 29 38 38 37 38 0 5 5 38 33 32 38 38 11 20 38 38 6 28 38 38 3 3 38 1 1 38 14 14 38 0 19 19 38 0 18 34 38 38 8 8 38 23 23 38 0 4 4 38 0 13 13 38 0 2 2 38 31 38 36 38 27 16 38 38 0 26 21 38 38 30 38 0 17 17 38 ", "-1", "-1", "0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 7 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 4 4 4 4 7 4 4 4 5 5 5 5 7 5 5 5 5 7 5 5 5 5 6 6 0 7 7 ", "-1", "-1", "-1", "-1", "-1", "-1", "14 14 22 22 22 22 0 23 23 1 1 1 1 1 1 12 23 12 19 19 23 23 15 2 2 2 2 2 2 23 23 18 23 21 7 7 7 7 23 13 23 5 5 5 5 5 23 0 23 17 17 9 9 9 9 9 23 23 16 4 4 4 4 4 4 23 23 6 6 6 6 6 8 23 8 8 23 0 3 3 3 3 3 3 3 23 10 10 23 11 11 11 11 11 20 23 23 ", "-1", "2 3 1 1 1 3 ", "1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "2 3 1 3 ", "2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 ", "1 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "1 2 3 1 3 0 ", "1 2 3 1 1 0 3 ", "0 0 1 2 3 1 0 3 ", "1 2 3 1 1 1 1 1 1 3 ", "1 2 3 1 3 ", "1 2 3 1 1 1 1 0 0 3 ", "1 2 2 3 1 1 1 0 0 3 ", "1 1 2 1 1 1 3 1 0 3 ", "2 2 2 1 3 4 1 4 0 4 ", "3 0 2 1 1 1 1 5 5 5 6 4 6 6 4 6 4 4 0 6 ", "0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 4 4 3 3 3 3 3 3 3 2 2 2 3 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 0 0 0 0 0 0 1 0 0 0 0 0 5 0 6 0 0 0 6 0 0 0 0 0 0 6 0 ", "4 3 5 1 4 2 5 5 5 ", "1 2 1 3 1 1 1 0 0 3 ", "2 2 3 5 5 1 4 5 1 5 ", "1 1 2 1 1 1 3 1 1 3 ", "-1", "2 1 4 2 2 2 0 0 0 0 0 4 3 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "-1", "0 2 1 3 2 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 0 0 5 5 5 5 5 5 5 5 5 5 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 2 2 2 2 2 6 4 2 2 6 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 6 3 0 0 0 0 0 0 6 0 0 0 0 0 0 0 ", "-1", "1 1 1 2 2 2 2 3 1 1 3 ", "0 0 0 0 1 1 1 5 0 6 6 0 0 0 2 4 4 4 4 6 2 6 3 3 3 3 6 0 0 ", "0 3 0 5 1 1 1 1 1 1 2 5 1 1 1 1 1 4 0 0 0 0 5 5 0 0 0 0 ", "0 0 8 8 8 8 1 1 8 9 8 8 8 8 8 8 8 3 3 9 8 8 4 4 0 0 2 9 6 6 0 9 0 0 0 0 7 7 7 9 7 7 7 7 7 7 7 9 7 7 7 7 7 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 9 5 5 5 5 5 5 5 5 5 0 9 0 0 0 0 0 0 ", "0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ", "-1", "1 1 0 8 9 8 8 8 8 8 8 5 5 5 5 8 8 8 9 8 8 8 8 8 8 7 7 7 2 2 2 2 2 2 2 3 3 3 3 3 3 9 9 7 7 7 7 7 7 9 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 7 7 7 7 7 7 9 4 4 0 0 0 0 9 9 0 0 0 0 0 0 0 ", "-1", "2 2 1 1 2 2 3 2 3 ", "4 2 2 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 5 3 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 5 5 5 5 5 5 5 5 6 6 6 6 0 0 7 7 0 0 0 0 0 0 ", "0 0 3 5 3 3 6 3 3 3 3 3 4 4 4 4 1 1 1 1 1 1 1 1 1 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 0 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 2 2 2 2 0 6 ", "0 0 0 2 2 2 2 1 1 1 1 6 1 1 1 5 5 4 4 4 4 4 6 6 4 4 4 3 3 3 3 6 3 3 3 3 3 3 3 3 3 3 0 0 0 6 0 0 0 0 ", "3 4 1 2 4 4 ", "2 2 2 2 2 2 2 3 3 2 2 2 2 2 2 2 1 1 1 2 4 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 "]}
UNKNOWN
PYTHON3
CODEFORCES
10
2189a2c8e311addc29b933b2d542edfc
Circle of Numbers
*n* evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number *k*. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by *k* or decrease all numbers at points in the set by *k*. You would like to eventually end up with all numbers equal to 0. Is it possible? A set of 2 points is considered evenly spaced if they are diametrically opposed, and a set of 3 or more points is considered evenly spaced if they form a regular polygon. The first line of input contains an integer *n* (3<=≤<=*n*<=≤<=100000), the number of points along the circle. The following line contains a string *s* with exactly *n* digits, indicating the numbers initially present at each of the points, in clockwise order. Print "YES" (without quotes) if there is some sequence of operations that results in all numbers being 0, otherwise "NO" (without quotes). You can print each letter in any case (upper or lower). Sample Input 30 000100000100000110000000001100 6 314159 Sample Output YES NO
[ "def factor(n):\n ps = []\n for i in range(2, n):\n if i * i > n:\n break\n if n % i == 0:\n e = 0\n while n % i == 0:\n e += 1\n n //= i\n ps += [(i, e)]\n if n > 1:\n ps += [(n, 1)]\n return ps\n\n\nn = int(input())\na = list(map(int, input()))\n\nps = factor(n)\n\nP = 1\nfor p, _ in ps:\n P *= p\nQ = n // P\n\nfor p, _ in ps:\n k = (1 - pow(P // p, -1, p) * (P // p)) % P\n for r in range(Q):\n for i in range(0, P, p):\n for j in range(1, p):\n a[r + (i + j) * Q] -= a[r + ((i + j * k) % P) * Q]\n for i in range(0, P, p):\n a[r + i * Q] = 0\nprint(\"YES\" if all(x == 0 for x in a) else \"NO\")\n" ]
{"inputs": ["30\n000100000100000110000000001100", "6\n314159", "3\n000", "15\n522085220852208", "300\n518499551238825328417663140237955446550596254299485115465325550413577584420893115025535675971808926451691055930219585997807344070011845434733526017118933548589759649920016568578201769564228210045739230664506968281414229830885120812000132083367912869773547090902954497697057079934454847714732943455588", "16\n0110100110010110", "6\n564837", "9\n975975975", "10\n0414240506", "33\n459847811604598478116045984781160", "54\n668822125317092836839407462257441103728473858428026440", "147\n258714573455458660598376355525847569123841578643535970557335666766056747734652574877812381067963453587176633563586704774763586157484691337206786466", "171\n570962255153238631524151841322466383830411184871666785642671862254254138630625051840423366382931311183972566784743571861355154137731525050941323365483831310284872565885643", "256\n0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110", "5\n66666", "9\n735358934", "18\n008697913853945708", "32\n63227607169607744763319434680883", "55\n3051191835797699222829630849704721747109367868763178250", "124\n4087853659974995340862097721504457205060797709029986511524903183441846431857346142268549624240693503777827416946735887323115", "191\n13749871615832352185918872672752947110954476837054206370341509698888491814630432290010512405256834335260576808366797121146435132126443422459679991449630693949793303863445042394342711401003212", "488\n45334958248886256215245432812097462402188584275950565932256169435872815051620433766475524373331668138254775135319898212744118387896269009559223646980708720716169171410452756878161887568810441524371550690928477055425661664202050311645854048922622038301574832340035693673614973249646168547494526620934733803262859266238709131053471167257719634461068324341221207027892565402615143073772528401151209845684767396920588208903922337152277526342947329398157696709654980477214668927347471119604451", "3\n007", "4\n0500", "6\n700000"], "outputs": ["YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "YES", "YES", "YES", "YES", "YES", "NO", "YES", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO", "NO"]}
UNKNOWN
PYTHON3
CODEFORCES
1
218df72e4efbe2b7cc341ffe3d16707e
Rebranding
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name. For this purpose the corporation has consecutively hired *m* designers. Once a company hires the *i*-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters *x**i* by *y**i*, and all the letters *y**i* by *x**i*. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that *x**i* coincides with *y**i*. The version of the name received after the work of the last designer becomes the new name of the corporation. Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive. Satisfy Arkady's curiosity and tell him the final version of the name. The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively. The second line consists of *n* lowercase English letters and represents the original name of the corporation. Next *m* lines contain the descriptions of the designers' actions: the *i*-th of them contains two space-separated lowercase English letters *x**i* and *y**i*. Print the new name of the corporation. Sample Input 6 1 police p m 11 6 abacabadaba a b b c a d e g f a b b Sample Output molice cdcbcdcfcdc
[ "def solve():\n N, M = map(int, input().split())\n name = input()\n\n td = {}\n for c in 'abcdefghijklmnopqrstuvwxyz':\n td[c] = c\n\n for i in range(M):\n p, m = input().split()\n if p == m:\n continue\n pt = td[p]\n mt = td[m]\n del td[p]\n del td[m]\n td[m] = pt\n td[p] = mt\n\n nd = {f: t for t, f in td.items()}\n\n ans = ''.join([nd[c] for c in name])\n\n print(ans)\n\n\nif __name__ == '__main__':\n solve()\n", "#!/usr/bin/env python\r\n# -*- coding: utf-8 -*-\r\n\r\nn, m = map(int,input().split())\r\nS = input()\r\nchar = {chr(i) : chr(i) for i in range(ord('a'), ord('z')+1 )}\r\nkeys = char.keys()\r\n\r\nfor i in range(m):\r\n x, y = input().split()\r\n for c in keys:\r\n if char[c] == x:\r\n char[c] = y\r\n elif char[c] == y:\r\n char[c] = x\r\n\r\nans = []\r\nfor c in list(S):\r\n ans.append(char[c])\r\nprint(''.join(ans))\r\n", "import string\r\n\r\nn = int(input().split()[1])\r\ns = list(input())\r\nr = {c:c for c in string.ascii_lowercase}\r\nfor i in range(n):\r\n x, y = input().split()\r\n for a, b in r.items():\r\n if b == x:\r\n r[a] = y\r\n elif b == y:\r\n r[a] = x\r\nfor i in range(len(s)):\r\n s[i] = r[s[i]]\r\nprint(''.join(s))", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\nN,M = map(int,input().split())\nname=input()\n\ntable = [0] * 26\nfor i in range(26):\n table[i] = i\n\nbuffs = []\nfor _ in range(M):\n before,after = map(ord, input().split())\n before -= ord('a')\n after -= ord('a')\n buffs.append((before,after))\nbuffs.reverse()\n\nfor pair in buffs:\n table[pair[0]], table[pair[1]] = table[pair[1]], table[pair[0]]\n\nret = \"\"\nfor ch in name:\n ret += chr( table[ ord(ch) - ord('a') ] + ord('a') )\n\nprint(ret) \n\n\n\n \n \n", "import string\n\nn,m = map(int, input().split())\ns = input()\n\nchars = string.ascii_lowercase\n\nfor _ in range(m):\n a,b = input().split()\n chars = chars.replace(a, \"%\").replace(b,a).replace(\"%\",b)\n\nreplacements = {ord(string.ascii_lowercase[i]):chars[i] for i in range(26)}\n\nprint(s.translate(replacements))", "# Description of the problem can be found at http://codeforces.com/problemset/problem/591/B\r\n\r\nn, m = map(int, input().split())\r\ns = list(input())\r\n\r\nd_c = {}\r\n\r\nfor c in range(26):\r\n d_c[chr(ord(\"a\") + c)] = chr(ord(\"a\") + c)\r\n\r\nfor _ in range(m):\r\n x, y = input().split()\r\n if x != y:\r\n d_c[x], d_c[y] = d_c[y], d_c[x]\r\n \r\nd_c = {v: k for k, v in d_c.items()}\r\nprint(\"\".join(d_c[c] for c in s))", "(a,b)=(int(i) for i in input().split())\r\nstr=input()\r\nimport string\r\ng={c:c for c in string.ascii_lowercase}\r\n\r\nfor j in range(b):\r\n (c,e)=(t for t in input().split())\r\n g[c],g[e]=g[e],g[c]\r\n\r\nr={b:a for a,b in g.items()}\r\n\r\nfor j in str:\r\n if j in r.keys():\r\n print(r[j],end='')\r\n else:\r\n print(j,end='')", "n,m=map(int,input().split())\r\nst=input()\r\ndic={}\r\nxr=\"abcdefghijklmnopqrstuvwxyz\"\r\nfor x in xr:\r\n dic[x]=x\r\nfor x in range(m):\r\n g,h=input().split()\r\n dic[g],dic[h]=dic[h],dic[g]\r\n#print(dic) \r\nt={}\r\nfor k in dic:\r\n t[dic[k]]=k\r\n#print(t) \r\nls=[ t[x] for x in st]\r\nprint(''.join(ls))", "import string\r\nn,m = map(int,input().split())\r\ns = input()\r\nold = 'abcdefghijklmnopqrstuvwxyz'\r\nnew = old\r\nfor i in range(m):\r\n x,y = map(str,input().split())\r\n new = new.translate(''.maketrans(x+y,y+x))\r\nprint(s.translate(''.maketrans(old,new)))\r\n ", "# print(\"Input n and m\")\nn,m = [int(x) for x in input().split()]\n# print(\"Input the starting string\")\nst = input()\n\nd = {}\nch = 'a'\nfor i in range(26):\n d[ch] = ch\n ch = chr(ord(ch)+1)\n\nfor i in range(m):\n # print(\"Input the next switch\")\n x,y = [z for z in input().split()]\n # Find the values to change--doing the dictionary backwards, to save time!\n temp = d[x]\n d[x] = d[y]\n d[y] = temp\n\nanswer = []\n# Now need to reverse the dictionary\nnewd = {}\nfor key in d:\n value = d[key]\n newd[value] = key\n \nfor ch in st:\n answer.append(newd[ch])\n\nprint(''.join(answer))\n \n\n\n \n", "m, n = map(int, input().split())\r\ns = input()\r\nd = {}\r\nfor _ in range(n):\r\n x, y = input().split()\r\n if x != y:\r\n d[x], d[y] = d.get(y, y), d.get(x, x)\r\ndd = {}\r\nfor x in d:\r\n dd[d[x]] = x\r\nprint(\"\".join(dd.get(x, x) for x in s)) ", "import sys\r\nimport string\r\n\r\nlines = sys.stdin.readlines()\r\nm, n = map(int, lines[0].split())\r\ns = list(lines[1])\r\nr = {c:c for c in string.ascii_lowercase}\r\nfor i in range(n):\r\n x, y = lines[2 + i].split()\r\n for a, b in r.items():\r\n if b == x:\r\n r[a] = y\r\n elif b == y:\r\n r[a] = x\r\nfor i in range(m):\r\n s[i] = r[s[i]]\r\nprint(''.join(s))", "n, m = map(int, input().split())\r\nmapping = [i for i in \"abcdefghijklmnopqrstuvwxyz\"]\r\nname = input()\r\nfor i in range(m):\r\n a, b = input().split()\r\n ia = mapping.index(a)\r\n ib = mapping.index(b)\r\n mapping[ia] = b\r\n mapping[ib] = a\r\nprint(\"\".join(mapping[ord(i)-97] for i in name))", "IL = lambda: list(map(int, input().split()))\r\nIS = lambda: input().split()\r\nI = lambda: int(input())\r\nS = lambda: input()\r\n\r\nn, m = IL()\r\nname = S()\r\nletters = dict([[chr(i), chr(i)] for i in range(97, 123)])\r\n\r\nfor i in range(m):\r\n l1, l2 = IS()\r\n letters[l1], letters[l2] = letters[l2], letters[l1]\r\n\r\nrletters = {v: k for k, v in letters.items()}\r\nprint(\"\".join([rletters[l] for l in name]))", "n, m = map(int, input().split())\ns = input()\nk = []\na = ['' for i in range(m)]\nb = ['' for i in range(m)]\nans = [0 for i in range(n)]\nfor i in range(n):\n k.append(s[i])\nd = {}\nfor i in range(26):\n d[chr(ord('a') + i)] = 0\nfor i in range(m):\n a[i], b[i] = map(str, input().split())\n\nfor i in range(26):\n cur = chr(ord('a') + i)\n for j in range(m):\n if a[j] == cur or b[j] == cur:\n if a[j] == cur:\n cur = b[j]\n else:\n cur = a[j]\n d[chr(ord('a') + i)] = cur\nused = [True for i in range(n)]\nfor i in range(26):\n for j in range(n):\n if s[j] == chr(ord('a') + i) and used[j] == True:\n ans[j] = d[chr(ord('a') + i)]\n used[j] = False\nprint(''.join(str(i) for i in ans))\n \n \n ", "import sys\r\nimport string\r\n\r\nfrom collections import Counter, defaultdict\r\nfrom math import fsum, sqrt, gcd, ceil, factorial\r\nfrom operator import *\r\nfrom itertools import accumulate\r\n\r\ninf = float(\"inf\")\r\n# input = sys.stdin.readline\r\nflush = lambda: sys.stdout.flush\r\ncomb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)\r\n\r\n\r\n# inputs\r\n# ip = lambda : input().rstrip()\r\nip = lambda: input()\r\nii = lambda: int(input())\r\nr = lambda: map(int, input().split())\r\nrr = lambda: list(r())\r\n\r\n\r\nn, k = r()\r\ns = ip()\r\narr = {i: i for i in string.ascii_lowercase}\r\n\r\n\r\ndef get_key(arr, val):\r\n for i, j in arr.items():\r\n if j == val:\r\n return i\r\n\r\n\r\nfor _ in range(k):\r\n a, b = ip().split()\r\n if a == b:\r\n continue\r\n\r\n x = get_key(arr, a)\r\n y = get_key(arr, b)\r\n temp = arr[x]\r\n arr[x] = arr[y]\r\n arr[y] = temp\r\n\r\n\r\nfor i in s:\r\n print(arr[i], end=\"\")\r\n", "n,m=map(int,input().split())\r\nS=input()\r\nl=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nl1=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\nfor i in range(m) :\r\n a,b=input().split()\r\n c=0\r\n \r\n if a!=b :\r\n p=l1.index(a)\r\n p1=l1.index(b)\r\n l1[p]=b\r\n l1[p1]=a\r\n \r\n \r\n \r\nS1=''\r\nfor i in range(len(S)) :\r\n S1=S1+l1[l.index(S[i])]\r\nprint(S1)\r\n", "def main():\n _, m = map(int, input().split())\n s, d = input(), {c: c for c in \"abcdefghijklmnopqrstuvwxyz\"}\n for _ in range(m):\n x, y = input().split()\n d[x], d[y] = d[y], d[x]\n d = {v: k for k, v in d.items()}\n print(''.join(map(d.get, s)))\n\n\nif __name__ == '__main__':\n main()\n", "import string\nimport sys\nimport traceback\nfrom contextlib import contextmanager\nfrom io import StringIO\n\n\nAL = string.ascii_lowercase.encode('ascii')\nOA = ord('a')\n\n\ndef transform(n, m, name, designers):\n tr = bytearray(AL)\n for x, y in reversed(designers):\n i1 = ord(x) - OA\n i2 = ord(y) - OA\n tr[i1], tr[i2] = tr[i2], tr[i1]\n table = bytes.maketrans(AL, tr)\n return name.translate(table)\n \n\ndef pd():\n line = input()\n t = line.encode('ascii').split()\n assert len(t) == 2, f\"Invalid designer: {line}\"\n return t\n\n\ndef main():\n n, m = map(int, input().split())\n name = input().encode('ascii')\n assert len(name) == n\n designers = [pd() for _ in range(m)]\n print(transform(n, m, name, designers).decode('ascii'))\n\n\ndef log(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n\n\n@contextmanager\ndef patchio(i):\n try:\n sys.stdin = StringIO(i)\n sys.stdout = StringIO()\n yield sys.stdout\n finally:\n sys.stdin = sys.__stdin__\n sys.stdout = sys.__stdout__\n\n\ndef do_test(k, test):\n try:\n log(f\"TEST {k}\")\n i, o = test\n with patchio(i) as r:\n main()\n if r.getvalue() == o:\n log(\"OK\\n\")\n else:\n log(f\"Expected:\\n{o}Got:\\n{r.getvalue()}\")\n except Exception:\n traceback.print_exc()\n log()\n\n\ndef test(ts):\n for k in ts or range(len(tests)):\n do_test(k, tests[k])\n\n\ntests = [(\"\"\"\\\n6 1\npolice\np m\n\"\"\", \"\"\"\\\nmolice\n\"\"\"), (\"\"\"\\\n11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n\"\"\", \"\"\"\\\ncdcbcdcfcdc\n\"\"\")]\n\n\nif __name__ == '__main__':\n from argparse import ArgumentParser\n parser = ArgumentParser()\n parser.add_argument('--test', '-t', type=int, nargs='*')\n args = parser.parse_args()\n main() if args.test is None else test(args.test)\n", "from string import ascii_lowercase as asc\r\ng={};n,m=map(int,input().split());ans=['']*n;s=input()\r\nfor i in asc:g[i]=[]\r\nfor i in range(n):g[s[i]]+=[i]\r\nfor i in range(m):a,b=input().split();ga=g.get(a);gb=g.get(b);g[b]=ga;g[a]=gb;\r\nfor i in g:\r\n for j in g[i]:ans[j]=i\r\nprint(''.join(ans))", "letterlist = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\nimport sys\ninput = sys.stdin.readline\n\nllength, queries =list(map(int, input().split()))\n\nname = input()\n\ncountlist = [[] for i in range(26)]\n\nogname = ['' for i in range(llength)]\nfor i in range(llength):\n countlist[letterlist.index(name[i])].append(i)\n\nfor i in range(queries):\n repl = input().split()\n meow = letterlist.index(repl[0])\n bark = letterlist.index(repl[1])\n saus = countlist[meow]\n corgi = countlist[bark]\n countlist[meow] = corgi\n countlist[bark] = saus\n\nfor i in range(26):\n for q in countlist[i]:\n ogname[q] = letterlist[i]\n\nprint(''.join(ogname))\n \t\t\t\t \t\t \t\t\t\t\t\t\t \t \t \t\t \t", "n,m=map(int,input().split())\r\ns=input()\r\np=[chr(i) for i in range(97,97+26)]\r\nfor i in range(m):\r\n a,b=input().split()\r\n for i in range(26):\r\n if p[i]==a: p[i]=b\r\n elif p[i]==b: p[i]=a\r\nprint(\"\".join([p[ord(x)-97] for x in s]))", "#In the name of Allah\r\n\r\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\nd = {'x': 'x', 'y': 'y', 'z': 'z', 'p': 'p', 'q': 'q', 'r': 'r', 's': 's', 't': 't', 'u': 'u', 'v': 'v', 'w': 'w', 'h': 'h', 'i': 'i', 'j': 'j', 'k': 'k', 'l': 'l', 'm': 'm', 'n': 'n', 'o': 'o', 'a': 'a', 'b': 'b', 'c': 'c', 'd': 'd', 'e': 'e', 'f': 'f', 'g': 'g'}\r\nn, m = map(int, input().split())\r\n\r\ns = input()\r\n\r\nxy = [input()for i in range(m)]\r\n\r\nfor i in d:\r\n t = i\r\n for j in xy:\r\n if j[0] == t:\r\n t = j[2]\r\n elif j[2] == t:\r\n t = j[0]\r\n d[i] = t\r\n \r\n \r\nfor i in range(n):\r\n stdout.write(d[s[i]])\r\n\r\n", "n,m=map(int,input().split())\r\na=[ord(x) for x in input()]\r\ns={}\r\n# print(a)\r\nfor i in range(97 ,123):\r\n\ts[i]=i\r\n\r\nfor i in range(m):\r\n\tX,Y=map(str,input().split())\r\n\tX=ord(X)\r\n\tY=ord(Y)\r\n\t\r\n\tfor j in range(97,123):\r\n\t\tif s[j]==X:\r\n\t\t\ts[j]=Y\r\n\t\t\t\r\n\t\telif s[j]==Y:\r\n\t\t\ts[j]=X\t\r\n\t\t\r\nd=\"\"\r\nfor i in range(n):\r\n\ta[i]=s[a[i]]\r\n\td+=chr(a[i])\r\n\r\nprint(d)\r\n\r\n\r\n\r\n\r\n\r\n", "n,m = map(int, input().split())\r\nalph = list(\"abcdefghijklmnopqrstuvwxyz\")\r\nindex = [int(i) for i in range(26)]\r\ns = input()\r\nfor i in range(m):\r\n a,b = input().split()\r\n a_index = index[ord(a) - ord('a')]\r\n b_index = index[ord(b) - ord('a')]\r\n alph[a_index] = b\r\n alph[b_index] = a\r\n index[ord(a) - ord('a')] = b_index\r\n index[ord(b) - ord('a')] = a_index\r\nfor i in s:\r\n print(alph[ord(i) - ord('a')], end='')", "import sys\nimport string\nread = lambda: list(map(int, sys.stdin.readline().split()))\n\nn, m = read()\ns = sys.stdin.readline().strip()\ndesign = {c:c for c in string.ascii_lowercase}\nfor i in range(m):\n a, b = sys.stdin.readline().split()\n design[a], design[b] = design[b], design[a]\ndesign2 = {b:a for a,b in design.items()}\nprint(''.join(design2[c] for c in s))\n\n", "\r\nn, m = map(int, input().split())\r\ns = input()\r\n\r\nold = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\nnew = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\r\n\r\nfor i in range(m):\r\n x, y = input().split()\r\n posX = new.index(x)\r\n posY = new.index(y)\r\n new[posX] = y\r\n new[posY] = x\r\n\r\nnewStr = \"\"\r\nfor i in range(n):\r\n newStr += new[old.index(s[i])]\r\nprint(newStr)\r\n\r\n", "from sys import *\r\nfrom collections import *\r\n\r\n\r\ndef inp(n):\r\n if n == 1:\r\n return map(int, stdin.readline().split())\r\n elif n == 2:\r\n return map(float, stdin.readline().split())\r\n else:\r\n return map(str, stdin.readline().split())\r\n\r\n\r\ndef main():\r\n n, m = inp(1)\r\n org, mem = deque(input()), defaultdict(int)\r\n for i in range(m):\r\n u, v = inp(3)\r\n flag1, flag2 = 0, 0\r\n\r\n for i, j in mem.items():\r\n if not flag1 and j == u:\r\n mem[i] = v\r\n flag1 = 1\r\n if not flag2 and j == v:\r\n mem[i] = u\r\n flag2 = 1\r\n if flag1 and flag2:\r\n break\r\n\r\n if not flag1:\r\n mem[u] = v\r\n if not flag2:\r\n mem[v] = u\r\n\r\n # print(mem)\r\n\r\n for i in range(n):\r\n if mem[org[i]]:\r\n org[i]=mem[org[i]]\r\n\r\n print(''.join(org))\r\n\r\n\r\nif __name__ == '__main__':\r\n main()\r\n", "import sys\n\ninput = sys.stdin.readline\n\nn, employ = map(int, input().split())\nword = list(input())\n\nletters = 'abcdefghijklmnopqrstuvwxyz'\nreplacements = list(letters)\n\nfor i in range(employ):\n x, y = input().split()\n for j in range(26):\n if replacements[j] == x:\n replacements[j] = y\n \n elif replacements[j] == y:\n replacements[j] = x\n\nfor k in range(n):\n word[k] = replacements[letters.find(word[k])]\n\nprint(''.join(word))\n\t \t\t\t\t\t \t \t\t \t \t \t \t \t\t\t \t\t", "\"\"\"\nCodeforces Round #327 (Div. 2)\n\nProblem 591 B. Rebranding\n\n@author yamaton\n@date 2015-11-06\n\"\"\"\n\nimport itertools as it\nimport functools\nimport operator\nimport collections\nimport math\nimport sys\n\nimport string\n\ndef solve(s, pairs, n, m):\n d = {c: c for c in string.ascii_lowercase}\n for (c1, c2) in pairs:\n for c in string.ascii_lowercase:\n if d[c] == c1:\n d[c] = c2\n elif d[c] == c2:\n d[c] = c1\n return ''.join(d[c] for c in s)\n\n\ndef print_stderr(*args, **kwargs):\n print(*args, file=sys.stderr, **kwargs)\n\n\ndef main():\n [n, m] = [int(i) for i in input().strip().split()]\n s = input().strip()\n assert len(s) == n\n pairs = [tuple(input().strip().split()) for _ in range(m)]\n result = solve(s, pairs, n, m)\n print(result)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m = map(int, input().split())\r\ns = input()[:-1]\r\n\r\nd = list(range(97,123))\r\nfor _ in range(m):\r\n w = input()\r\n x = w[0]\r\n y = w[2]\r\n a = d.index(ord(x))\r\n b = d.index(ord(y))\r\n d[a], d[b] = ord(y), ord(x)\r\ntranslation = {97:d[0], 98:d[1], 99:d[2], 100:d[3], 101:d[4], 102:d[5], 103:d[6], 104:d[7], 105:d[8], 106:d[9], 107:d[10], 108:d[11], 109:d[12], 110:d[13], 111:d[14], 112:d[15], 113:d[16], 114:d[17], 115:d[18], 116:d[19], 117:d[20], 118:d[21], 119:d[22], 120:d[23], 121:d[24], 122:d[25]}\r\ns = s.translate(translation)\r\nprint(s)\r\n", "#!/usr/bin/env python3\n\nfrom sys import stdin\n\ninp = stdin.readline().split()\n\nm = int(inp[1])\n\nword = stdin.readline().strip()\n\nreplaces = {}\n\nfor i in range(0, m):\n replacement = stdin.readline().split()\n fr = replacement[0]\n to = replacement[1]\n\n for key, value in replaces.items():\n if value == fr:\n replaces[key] = to\n if value == to:\n replaces[key] = fr\n\n if fr not in replaces:\n replaces[fr] = to\n\n if to not in replaces:\n replaces[to] = fr\n\ntable = str.maketrans(*[\"\".join(x) for x in zip(*replaces.items())])\nword = word.translate(table)\n\nprint(word)\n", "x=input().split()\nlength=int(x[0])\nnum=int(x[1])\n\nname=input()\n\ntrans=[0]*num\nfor i in range(num):\n trans[i]=input().split()\n\ntrans_final={}\nfor i in range(97,123):\n c=chr(i)\n x=c\n for j in range(len(trans)):\n if x in trans[j]:\n if(x==trans[j][0]):\n x=trans[j][1]\n else:\n x=trans[j][0]\n trans_final[c]=x\n\nnew_name=[0]*length\nfor i in range(length):\n new_name[i]=trans_final[name[i]]\nprint(''.join(new_name))\n\n", "n,m = map(int,input().split())\r\ns =input()\r\na = []\r\nans=''\r\nz=dict()\r\nfor i in range(m):\r\n x,y = input().split()\r\n a.append((x,y))\r\n\r\nfor i in set(s):\r\n t = i\r\n for f in a:\r\n if t == f[0]:\r\n t=f[1]\r\n elif t == f[1]:\r\n t=f[0]\r\n z[i]=t\r\n\r\nfor i in s:\r\n print(z[i],end='')", "from sys import stdin ,stdout \r\ninput=stdin.readline\r\ndef print(*args, end='\\n', sep=' ') -> None:\r\n stdout.write(sep.join(map(str, args)) + end)\r\n\r\nn,m=map(int,input().split()) ; name=list(input().strip()) ; dic={} \r\nfor i in range(m):\r\n a,b=input().split()\r\n key=list(dic.keys())\r\n value=list(dic.values())\r\n if a in dic:\r\n for i in range(len(value)):\r\n if value[i]==a:\r\n dic[key[i]]=b\r\n break\r\n else:\r\n dic[a]=b\r\n if b in dic:\r\n for i in range(len(value)):\r\n if value[i]==b:\r\n dic[key[i]]=a\r\n break\r\n else:\r\n dic[b]=a\r\n\r\nfor i in range(n):\r\n if name[i] in dic:\r\n name[i]=dic[name[i]]\r\nprint(\"\".join(name))\r\n", "import sys\ninput = sys.stdin.readline\nn, m = input().split()\nm = int(m)\nname = input()\nletters = \"qwertyuiopasdfghjklzxcvbnm\"\nletters1 = \"qwertyuiopasdfghjklzxcvbnm\"\nfor i in range(m):\n let1, let2 = input().split()\n letters = letters.replace(let1, let2.upper())\n letters = letters.replace(let2, let1.upper())\n letters = letters.lower()\nfor i in range(len(letters)):\n name = name.replace(letters1[i], letters[i].upper())\nprint(name.lower())\n\t\t\t \t\t \t\t\t\t \t \t \t \t\t\t\t \t\t", "import string\r\nn,m=list(map(int,input().split()))\r\nalf=list(string.ascii_lowercase)\r\ns=input()\r\nfor i in range(m):\r\n x,y=input().split()\r\n index1 = alf.index(x)\r\n index2 = alf.index(y)\r\n alf[index1], alf[index2] = alf[index2], alf[index1]\r\nfor i in s:\r\n print(alf[ord(i)-ord('a')],end='')", "n, m = map(int, input().split())\r\ns = input()\r\nperm = list(range(26))\r\nv = ord('a')\r\nfor _ in range(m):\r\n ss = input()\r\n i, j = (ord(ss[0]) - v, ord(ss[2]) - v)\r\n perm[i], perm[j] = perm[j], perm[i]\r\nrev = [perm.index(c) for c in range(26)]\r\nprint(''.join(chr(rev[ord(c) - v] + v) for c in s))\r\n", "n, m = map(int, input().split())\r\ns = input()\r\ns1 = ''\r\nfor i in range(ord('a'), ord('z') + 1):\r\n s1 += chr(i)\r\ns2 = s1 + \"\"\r\nfor i in range(m):\r\n a, b = input().split()\r\n s2 = s2.replace(a, '*')\r\n s2 = s2.replace(b, a)\r\n s2 = s2.replace('*', b)\r\n\r\nss = ''\r\nfor i in range(n):\r\n ss += s2[s1.index(s[i])]\r\nprint(ss)\r\n", "import string\n\nn, m = [int(x) for x in input().split(' ')]\n\ns = input()\n\nxy = {}\nfor c in string.ascii_lowercase:\n xy[c] = c\n\nfor i in range(m):\n x, y = input().split(' ')\n\n x_ls = []\n y_ls = []\n\n for k, v in xy.items():\n if v == x:\n x_ls.append(k)\n if v == y:\n y_ls.append(k)\n\n for k in x_ls:\n xy[k] = y\n\n for k in y_ls:\n xy[k] = x\n\nans = ''\nfor c in s:\n ans += xy[c]\n\nprint(ans)\n", "\n\n\nN, M = map(int, input().split())\n\ns = input()\n\nmapping = [i for i in range(26)] # 映射数组0~26,初始状态mapping[i] = i, 表示a~a, b~b\n\nfor i in range(M):\n\n x, y = input().split()\n x = ord(x) - 97\n y = ord(y) - 97 # ord(x) 获得x的ascii值,减去a的ascii 97 ,则'a' -> 0, 'b' -> 1, 'z -> 25\n\n pos_x, pos_y = 0, 0 # 找出x和y所在的位置\n\n for j in range(26):\n if mapping[j] == x:\n pos_x = j\n if mapping[j] == y:\n pos_y = j\n mapping[pos_x], mapping[pos_y] = mapping[pos_y], mapping[pos_x] # 在映射数组中交换x和y的位置,相当于把所有的x变成y,所有的y变成x\n\nlst = [ord(s[i]) - 97 for i in range(len(s))]\nans = []\n\n\nfor i in range(N):\n ans.append(chr(mapping[lst[i]] + 97))\n\n\nprint(\"\".join(ans))\n\t \t\t \t \t \t\t \t \t\t\t \t", "letters, designers = [int(x) for x in input().split(' ')]\r\nname = input()\r\nalphabet_dict = {x: x for x in range(26)}\r\nalphabet_arr = [(x + 97) for x in range(26)]\r\n\r\ndef print_dict(dict_al):\r\n\tfor key, value in dict_al.items():\r\n\t\tprint('{}: {}'.format(chr(key), chr(value)))\r\n\r\nfor _ in range(designers):\r\n\tletter1, letter2 = input().split(' ')\r\n\twho_has_1 = alphabet_dict[ord(letter1) - 97]\r\n\twho_has_2 = alphabet_dict[ord(letter2) - 97]\r\n\talphabet_arr[who_has_1] = ord(letter2)\r\n\talphabet_arr[who_has_2] = ord(letter1)\r\n\talphabet_dict[ord(letter1) - 97] = who_has_2\r\n\talphabet_dict[ord(letter2) - 97] = who_has_1\r\n\t\r\n\r\nfor letter in name:\r\n\tprint(chr(alphabet_arr[ord(letter) - 97]), end='')\r\nprint()", "def tr(d,a,b):\r\n for i, j in d.items():\r\n if j == a:\r\n d[i] = b\r\n elif j == b:\r\n d[i] = a\r\n if not (a in d.keys()):\r\n d.update({a:b})\r\n if not (b in d.keys()):\r\n d.update({b:a})\r\n\r\nm = int(input().split()[1])\r\nname = input()\r\ns = set(name)\r\nd = dict()\r\nfor i in range(m):\r\n a,b = input().split()\r\n if a != b:\r\n tr(d,a,b)\r\nname = name.translate(str.maketrans(''.join(d.keys()),''.join(d.values())))\r\nprint(name)", "#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n# vim:fenc=utf-8\n#\n# Copyright © 2015 missingdays <missingdays@missingdays>\n#\n# Distributed under terms of the MIT license.\n\n\"\"\"\n\n\"\"\"\n\nfrom string import ascii_lowercase\nl = ascii_lowercase\n\n[n, m] = list(map(int, input().split()))\ns = input()\n\na = [None] * n\n\nfor i in range(n):\n a[i] = l.index(s[i])\n\nalpha = [i for i in range(26)]\n\nfor i in range(m):\n al, bl = input().split()\n\n ai = l.index(al)\n bi = l.index(bl)\n\n ai = alpha.index(ai)\n bi = alpha.index(bi)\n\n alpha[ai], alpha[bi] = alpha[bi], alpha[ai]\n\n\nfor i in range(n):\n print(l[alpha[a[i]]], end=\"\")\nprint()\n", "n,m = input().split()\r\ns=input()\r\nn=int(n)\r\nm=int(m)\r\n#v=[chr(97+i) for i in range(26)]\r\nl=[[] for i in range(26)]\r\nfor i in range(n):\r\n r=ord(s[i])-97\r\n l[r].append(i)\r\n #v[r]=s[i]\r\n\r\nfor i in range(m):\r\n k1,k2=input().split()\r\n r1,r2=ord(k1)-97,ord(k2)-97\r\n #v[r1],v[r2]=v[r2],v[r1]\r\n l[r1],l[r2]=l[r2],l[r1]\r\n\r\nq=[0 for i in range(n)]\r\nfor i in range(26):\r\n q1=len(l[i])\r\n q2=chr(97+i)\r\n if(q1!=0):\r\n for j in range(q1):\r\n q[l[i][j]]=q2\r\nfor i in range(n):\r\n print(q[i],end=\"\")\r\n", "#!/usr/bin/env python3\nimport string\n\nif __name__ == '__main__':\n n, m = map(int, input().split())\n name = input()\n\n tr = string.ascii_lowercase\n for _ in range(m):\n src, dst = input().split()\n tr = tr.replace(src, '@').replace(dst, src).replace('@', dst)\n\n for c in name:\n pos = ord(c) - ord('a')\n print(tr[pos], end='')\n print()\n", "n, m = map(int, input().split())\r\nline = input()\r\nalphabet = 'abcdefghijklmnopqrstuvwxyz'\r\nvocab = dict()\r\nantivocab = dict()\r\nfor x in range(len(alphabet)):\r\n vocab[alphabet[x]] = alphabet[x]\r\n antivocab[alphabet[x]] = alphabet[x]\r\nfor i in range(m):\r\n x, y = input().split()\r\n for i in antivocab[x]:\r\n vocab[i] = y\r\n for i in antivocab[y]:\r\n vocab[i] = x\r\n antivocab[x], antivocab[y] = antivocab[y], antivocab[x]\r\nnew = []\r\nfor i in range(n):\r\n new.append(vocab[line[i]])\r\nprint(''.join(map(str, new)))", "n, m = map(int, input().split(' ')[:2])\r\ns = input()[:n]\r\nls = {}\r\nfor c in range(97,123):\r\n ls[chr(c)] = chr(c)\r\nfor i in range(m):\r\n x, y = input().split(' ')[:2]\r\n ls[x], ls[y] = ls[y], ls[x]\r\nrev = {}\r\nfor c, v in ls.items():\r\n rev[v] = c\r\nprint(''.join([rev[c] for c in s]))", "def dict_find(d,value):\n for k,v in d.items():\n if v == value:\n return k\n\nn, m = map(int, input().split())\n\ns = input()\n\nd = {chr(c) : chr(c) for c in range(ord('a'), ord('z') + 1)}\n\nfor _ in range(m):\n x,y = input().split()\n c1 = dict_find(d,x)\n c2 = dict_find(d,y)\n d[c1],d[c2] = d[c2], d[c1]\n\nfor character in s:\n print(d[character],end='')\n\nprint()\n", "n, m = map(int, input().split())\r\ns = [c for c in input()]\r\nd = {}\r\nfor i in range(n):\r\n\tif s[i] in d:\r\n\t\td[s[i]].append(i)\r\n\telse:\r\n\t\td[s[i]] = [i]\r\nfor _ in range(m):\r\n\tx, y = input().split()\r\n\tif x==y or (x not in d and y not in d):\r\n\t\tcontinue\r\n\telif x in d and y in d:\r\n\t\td[x], d[y] = d[y], d[x]\r\n\telif x in d and y not in d:\r\n\t\td[y] = d[x]\r\n\t\tdel d[x]\r\n\telif x not in d and y in d:\r\n\t\td[x] = d[y]\r\n\t\tdel d[y]\r\n\r\nans = ['']*len(s)\r\nfor k, v in d.items():\r\n\tfor i in v:\r\n\t\tans[i] = k\r\n\r\nprint(''.join(ans))", "import string\n\nn, m = map(int, input().split())\nbrand = [ c for c in input() ]\n\nocr = { c: [] for c in string.ascii_lowercase}\nfor i in range(n):\n ocr[brand[i]].append(i)\n\nchanges = []\nfor _ in range(m):\n changes.append([ c for c in input().split() ])\n\nfor change in changes:\n hold1 = ocr[change[0]]\n hold2 = ocr[change[1]]\n ocr[change[0]] = hold2\n ocr[change[1]] = hold1\n\nnewbrand = [ \"\" ] * n\nfor key in ocr.keys():\n for i in ocr[key]:\n newbrand[i] = key\nprint(\"\".join(newbrand))", "import string\n\nn, m = map(int, input().split())\ns = list(input().strip())\nencode = { ch: ch for ch in string.ascii_lowercase }\n\nfor i in range(m):\n x, y = input().split()\n t = encode[x]\n encode[x] = encode[y]\n encode[y] = t\n\ninverse = { ch: ch for ch in string.ascii_lowercase }\nfor key, value in encode.items():\n inverse[value] = key\nfor i, ch in enumerate(s):\n s[i] = inverse[ch]\n\nprint(''.join(s))\n", "n,m = map(int,input().split())\r\ns = input()\r\nl = [chr(ord('a')+i) for i in range(26)]\r\nfor i in range(m):\r\n a,b = input().split()\r\n for j in range(26):\r\n if l[j] == a:\r\n l[j] = b\r\n elif l[j] == b:\r\n l[j] = a\r\nprint(''.join([l[ord(k)-ord('a')] for k in s]))", "alf = ['']*26\nfor i in range(26):\n alf[i] = chr(97+i)\n \nl = list(map(int, input().split()))\nn,m = l[0],l[1]\ns = input()\nfor i in range(m):\n z = list(input().split())\n x,y = z[0],z[1]\n for i in range(26):\n if alf[i] == x:\n alf[i] = y\n elif alf[i] == y:\n alf[i] = x\nans = ''\nfor j in range(n):\n ans += alf[ord(s[j]) - 97]\n \nprint(ans)\n \n\n", "import sys\nsize,swaps=map(int,sys.stdin.readline().split())\nword=sys.stdin.readline()\nalp='abcdefghijklmnopqrstuvwxyz'\nalp2='abcdefghijklmnopqrstuvwxyz'\nfor i in range(swaps):\n a,b=map(str,sys.stdin.readline().split())\n alp2=alp2.replace(a,b.upper())\n alp2=alp2.replace(b,a)\n alp2=alp2.lower()\nfor i in range(26):\n word=word.replace(alp[i],alp2[i].upper())\nsys.stdout.write(word.lower().strip('\\n'))\n \t\t \t \t \t \t\t \t \t\t \t \t \t", "import sys\r\ninput = sys.stdin.readline\r\n\r\n\r\nn, m = map(int, input().split())\r\ns = input().strip()\r\n\r\nbase = ord('a')\r\nc = [chr(base + i) for i in range(26)]\r\n\r\nfor _ in range(m):\r\n\tx, y = input().split()\r\n\r\n\tfor i in range(len(c)):\r\n\t\tif c[i] == x: c[i] = y\r\n\t\telif c[i] == y: c[i] = x\r\n\r\nlet = {}\r\nfor i in range(26):\r\n\tlet[base + i] = ord(c[i])\r\nsys.stdout.write(s.translate(let))", "from sys import stdin,stdout\r\na,b=map(int,stdin.readline().split())\r\nz=stdin.readline().replace('',' ').split()\r\nans_digit=[*range(27)]\r\nfor _ in \" \"*b:\r\n c,d=map(str,stdin.readline().split())\r\n ans_digit[ord(c)-97],ans_digit[ord(d)-97]=ans_digit[ord(d)-97],ans_digit[ord(c)-97]\r\nans_char=[]\r\nfor i in range(27):\r\n w=ans_digit[i];p=i\r\n while w!=i:p=w;w=ans_digit[w]\r\n ans_char+=[p]\r\nfor i in range(a):\r\n z[i]=chr(97+ans_char[ord(z[i])-97])\r\nstdout.write(\"\".join(z))", "from sys import stdin\r\nfrom sys import exit\r\n\r\nlive = True\r\nif not live: stdin = open('data.in', 'r')\r\n\r\nn, m = list(map(int, stdin.readline().strip().split()))\r\nname = stdin.readline().strip()\r\nswitch = list(\"abcdefghijklmnopqrstuvwxyz\")\r\npos = list(range(26))\r\n\r\nfor it in range(m):\r\n\tx, y = list(map(str, stdin.readline().strip().split()))\r\n\tposX = ord(x) - 97\r\n\tposY = ord(y) - 97\r\n\tswitch[pos[posX]] = y\r\n\tswitch[pos[posY]] = x\r\n\ttemp = pos[posX]\r\n\tpos[posX] = pos[posY]\r\n\tpos[posY] = temp\r\n\t\t\r\nfor it in name:\r\n\tprint(switch[ord(it) - 97], end = \"\")\r\n\t\t\t\r\nif not live: stdin.close()", "import string\nn, m = input().split()\nn, m = [int(n), int(m)]\nname = input()\nname = list(name)\nbuffer = {}\nfor ch in list(string.ascii_lowercase):\n buffer[ch] = [] \nfor i in range(n):\n buffer[name[i]].append(i)\nfor j in range(m):\n xi, yi = input().split()\n temp = buffer[xi]\n buffer[xi] = buffer[yi]\n buffer[yi] = temp\nfor key, value in buffer.items():\n for i in value:\n name[i] = key\nname = \"\".join(name)\nprint(name)\n", "n,m = map(int,input().split())\r\nst=input()\r\nd = {}\r\nimport string\r\nfor x in string.ascii_lowercase:\r\n\td[x] = []\r\nfor i in range(n):\r\n\td[st[i]].append(i)\r\nfor i in range(m):\r\n\tx,y = input().split()\r\n\td[x],d[y] = d[y],d[x]\r\nans = [0]*n\r\nfor x in d:\r\n\tfor y in d[x]:\r\n\t\tans[y] =x\r\nprint(''.join(ans))\t\t", "from collections import *\r\nd=defaultdict(list)\r\nn,m=map(int,input().split())\r\ns=input()\r\nl=\"abcdefghijklmnopqrstuvwxyz\"\r\nfor i in l:\r\n d[i]=i\r\nfor i in range(m):\r\n x,y=input().split()\r\n for k in d.keys():\r\n if(d[k]==x):\r\n d[k]=y\r\n elif(d[k]==y):\r\n d[k]=x\r\nfor i in s:\r\n print(d[i],end='')\r\nprint()", "s = list('abcdefghijklmnopqrstuvwxyz')\r\n\r\nn, m = tuple(map(int, input().split()))\r\nname = input()\r\nname_num = [s.index(name[i]) for i in range(n)]\r\n\r\nfor i in range(m):\r\n a, b = input().split()\r\n a, b = s.index(a), s.index(b)\r\n s[a], s[b] = s[b], s[a]\r\n \r\nfor elem in name_num:\r\n print(s[elem], end = \"\")\r\n\r\n", "_, m = map(int, input().split())\r\ns = input()\r\nold = 'abcdefghijklmnopqrstuvwxyz'\r\nnew = old\r\nfor _ in range(m):\r\n\tx, y = input().split()\r\n\tnew = new.translate(''.maketrans(x+y, y+x))\r\nprint(s.translate(''.maketrans(old, new)))", "''' Книга - лучший подарок 1100'''\r\n#n = int(input())\r\n\r\nch = input()\r\nch = ch.split()\r\nch = [int(x) for x in ch]\r\nn, m = ch\r\n#a = ch.copy()\r\n\r\nch = input()\r\nch.split()\r\n#ch_s = set(ch)\r\nalf = [chr(x) for x in range(ord('a'), ord('z')+1)]\r\naf = alf.copy()\r\nfor i in range(m):\r\n a = input()\r\n a = a.split()\r\n a, b = a;\r\n\r\n if (a in af) and (b in af):\r\n ina = af.index(a)\r\n inb =af.index(b)\r\n af[ina] = b\r\n af[inb] = a\r\n elif a in af:\r\n af[af.index(a)] = b\r\n elif b in af:\r\n af[af.index(b)] = a\r\n\r\nrez = ''\r\nfor i in range(n):\r\n rez += af[alf.index(ch[i])]\r\n\r\n\r\n\r\nprint(rez)", "n, m = map(int, input().split())\r\ns = input()\r\nrepos = {}\r\nans = [[] for i in range(n)]\r\nfor i in range(len(s)):\r\n if s[i] in repos:\r\n repos[s[i]].append(i)\r\n else:\r\n repos[s[i]] = [i]\r\nfor i in range(m):\r\n charbefore, charafter = input().split()\r\n if charafter in repos and charbefore in repos:\r\n repos[charbefore], repos[charafter] = repos[charafter], repos[charbefore]\r\n elif charbefore in repos:\r\n repos[charbefore], repos[charafter] = [], repos[charbefore]\r\n elif charafter in repos:\r\n repos[charbefore], repos[charafter] = repos[charafter], []\r\n else:\r\n repos[charafter], repos[charbefore] = [], []\r\nfor i in repos:\r\n if repos[i]:\r\n for j in repos[i]:\r\n ans[j] = i\r\nprint(''.join(ans))", "n, m = map(int, input().split())\r\nname = list(input())\r\nletters = list(\"abcdefghijklmnopqrstuvwxyz\")\r\n\r\nfor i in range(m):\r\n x, y = input().split()\r\n xi, yi = -1, -1\r\n for i, v in enumerate(letters):\r\n if x == v:\r\n xi = i\r\n if y == v:\r\n yi = i\r\n letters[xi], letters[yi] = letters[yi], letters[xi]\r\n\r\nprint(\"\".join(letters[ord(i) - ord(\"a\")] for i in name))\r\n", "# import sys\r\n#\r\n# sys.setrecursionlimit(2000000)\r\n\r\nn, m = map(int, input().split())\r\n\r\ns = list(input())\r\ntemp = list(range(0, 26))\r\n\r\nwhile m:\r\n m -= 1\r\n a, b = input().split()\r\n for i in range(0, 26):\r\n if temp[i] == ord(a)-ord(\"a\"):\r\n temp[i] = ord(b)-ord(\"a\")\r\n continue\r\n elif temp[i] == ord(b)-ord(\"a\"):\r\n temp[i] = ord(a)-ord(\"a\")\r\n continue\r\n # print(temp)\r\nfor i in range(n):\r\n for j in range(26):\r\n if ord(s[i]) - ord(\"a\") == j:\r\n s[i] = chr(temp[j] + ord(\"a\"))\r\n break\r\nprint(\"\".join(s))\r\n\r\n\r\n\r\n\r\n", "\nn,m =[int(x) for x in input().split(' ')]\nname = input().strip()\n\n\ndef findChanges(D, x, y):\n changes = []\n if x not in D:\n changes.append((x,y))\n #D[x] = y\n\n for k,v in D.items():\n if v == x:\n changes.append((k,y))\n #D[k] = y\n return changes\n\nD = {}\nfor i in range(m):\n x,y = input().split(' ')\n\n changes = findChanges(D, x, y)\n changes += findChanges(D, y, x)\n\n for a,b in changes:\n D[a] = b\n\nout = []\nfor l in name:\n if l in D:\n l = D[l]\n out.append(l)\n\nprint(\"\".join(out))\n", "import sys\r\n\r\nn,m = map(int,sys.stdin.readline().split())\r\ns = sys.stdin.readline().strip()\r\n\r\ndef replaceRequests(n,m,s):\r\n alph = ''\r\n for code in range(ord('a'),ord('z')+1):\r\n alph = alph+chr(code)\r\n english_alph = alph\r\n alph = list(alph)\r\n \r\n for t in range(m):\r\n request = sys.stdin.readline().strip().split()\r\n index1 = alph.index(request[0])\r\n index2 = alph.index(request[1])\r\n alph[index1],alph[index2] = alph[index2],alph[index1]\r\n #print(alph)\r\n alph_replace = {}\r\n \r\n for pos in range(len(alph)):\r\n alph_replace[english_alph[pos]] = alph[pos]\r\n \r\n \r\n replacedS = list(s)\r\n for pos in range(len(s)):\r\n replacedS[pos] = alph_replace[replacedS[pos]]\r\n return \"\".join(replacedS)\r\n\r\nprint(replaceRequests(n,m,s))", "d={};j={}\r\nfor i in range(26):\r\n\ta=chr(i+97);d[a]=a\r\nn,m=map(int,input().split());s=input()\r\nfor i in range(m):\r\n\tl,k=input().split()\r\n\tfor i in d:\r\n\t\tif d[i]==l:d[i]=k\r\n\t\telif d[i]==k:d[i]=l\r\nfor i in s:print(d[i],end='') ", "n, m = map(int, input().split())\ns = input()\nd = {}\nfor i in range(m):\n a, b = input().split()\n for k in d:\n if d[k] == a:\n d[k] = b\n elif d[k] == b:\n d[k] = a\n if a not in d:\n d[a] = b\n if b not in d:\n d[b] = a\nr = ''\nfor c in s:\n if c in d:\n r+=d[c]\n else:\n r+=c\n\nprint(r)\n\n", "l,a=map(int,input().split())\r\ns=input()\r\n\r\nreplace=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\n\r\nfor i in range(a):\r\n b=input().split()\r\n x=b[0]\r\n y=b[1]\r\n for j in range(26):\r\n if replace[j]==x:\r\n replace[j]=y\r\n elif replace[j]==y:\r\n replace[j]=x\r\noutput=''\r\nfor i in range(l):\r\n output+=replace[ord(s[i])-97]\r\nprint(output)\r\n", "s=input()\r\na=s.split(' ')\r\nn,m=int(a[0]),int(a[1])\r\ncorpname=input()\r\nus=set(list(corpname))\r\nds={}\r\nfor i in us:\r\n ds.update({i:i})\r\nwhile m>0:\r\n m-=1\r\n s=input()\r\n a=s.split(' ')\r\n x,y=a[0],a[1]\r\n if x!=y:\r\n for i in ds:\r\n if ds[i]==x:\r\n ds[i]=y\r\n else:\r\n if ds[i]==y:\r\n ds[i]=x\r\ncn=''\r\nfor i in corpname:\r\n cn+=ds[i]\r\nprint(cn)\r\n ", "n,m = [int(_) for _ in input().split()]\nconvert = \"abcdefghijklmnopqrstuvwxyz\"\ns = input()\n\nfor i in range(m):\n x,y = input().split()\n convert = convert.replace(x,'*')\n convert = convert.replace(y,x)\n convert = convert.replace('*',y)\n\nabc = \"abcdefghijklmnopqrstuvwxyz\"\n\nfor i in range(n):\n print(convert[abc.find(s[i])],end=\"\")\nprint()\n\n \t\t \t\t \t \t \t \t\t \t\t \t", "#Author : Zahin uddin\r\n#Github : https://github.com/Zahin52\r\n\r\n\r\nfrom sys import *\r\n#import math\r\n#import queue\r\nfrom collections import Counter,defaultdict\r\ninput=stdin.readline\r\nlistInput=lambda:list(map(int,input().strip().split()))\r\nlineInput= lambda:map(int,input().strip().split())\r\n# sJoin=lambda a,sep : f'{sep}'.join(a)\r\n# arrJoin=lambda a,sep : f'{sep}'.join(map(str,a))\r\n#print=stdout.write\r\ndef isPrime(n):\r\n if(n <= 1):\r\n return False\r\n if(n <= 3):\r\n return True\r\n if(n % 2 == 0 or n % 3 == 0):\r\n return False\r\n for i in range(5,int(math.sqrt(n) + 1), 6):\r\n if(n % i == 0 or n % (i + 2) == 0):\r\n return False\r\n return True\r\ndef main():\r\n n,m=lineInput()\r\n s=list(input().strip())\r\n ans=\"\"\r\n alpa=\"abcdefghijklmnopqrstuvwxyz\"\r\n dic=defaultdict(list)\r\n for i in alpa:\r\n dic[i]=i\r\n for _ in range(m):\r\n x,y=map(str,input().strip().split(\" \"))\r\n for v in dic.keys():\r\n if dic[v]==x:\r\n dic[v]=y\r\n elif dic[v]==y:\r\n dic[v]=x\r\n \r\n for i in s:\r\n print(dic[i],end=\"\")\r\n print()\r\n \r\n \r\n \r\n \r\n \r\nif __name__ == \"__main__\":\r\n main()\r\n", "n,m=map(int,input().split())\r\ns=list(input())\r\ns1='abcdefghijklmnopqrstuvwxyz'\r\nd={}\r\nfor p in s1:\r\n d[p]=p\r\nfor i in range(m):\r\n x,y=input().split()\r\n for j in d:\r\n if d[j]==x:\r\n d[j]=y\r\n elif d[j]==y:\r\n d[j]=x\r\nfor i in range(n):\r\n s[i]=d[s[i]]\r\nprint(''.join(map(str,s)))", "n, m = map(int, input().split())\nname = input()\nchanges = [input().split() for i in range(m)]\n\nchanges_table = sorted(list(set(name)))\n\nfor x, y in changes:\n for i, c in enumerate(changes_table):\n if c == x:\n changes_table[i] = y\n elif c == y:\n changes_table[i] = x\n\nlookup_table = { c: changes_table[i] for i, c in enumerate(sorted(list(set(name)))) }\n\nfinal_name = ''.join(map(lambda c: lookup_table[c], name))\nprint(final_name)\n", "n,m = map(int,input().split())\r\ns = input()\r\ndic = {}\r\nfor i in s:\r\n dic[i] = i\r\nfor i in range(m):\r\n x,y = map(str,input().split())\r\n for j in dic:\r\n if dic[j] == x:\r\n dic[j] = y\r\n elif dic[j] == y:\r\n dic[j] = x\r\ns = list(s)\r\nprint(''.join(map(lambda x:dic[x],s)))", "n, m = map(int, input().split())\r\ns = list(input())\r\nd = {i: i for i in \"qwertyuiopasdfghjklzxcvbnm\"}\r\n\r\nfor _ in range(m):\r\n x, y = input().split()\r\n d[x], d[y] = d[y], d[x]\r\n\r\nd = {value: key for key, value in d.items()}\r\n\r\nfor i in range(n):\r\n s[i] = d[s[i]]\r\n\r\nprint(\"\".join(s))\r\n \r\n", "from sys import stdin\r\nfrom sys import stdout\r\n\r\na1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\r\na2 = list(a1)\r\n\r\nn, m = map(int, stdin.readline().split())\r\nst = stdin.readline()\r\n\r\nfor i in range(0, m):\r\n x, y = stdin.readline().split()\r\n if x != y:\r\n for j in range(0, len(a2)):\r\n if a2[j] == x:\r\n a2[j] = y\r\n elif a2[j] == y:\r\n a2[j] = x\r\n \r\nd = {}\r\nfor i in range(0, len(a1)):\r\n d[a1[i]] = a2[i]\r\n\r\nfor i in range(0, n):\r\n stdout.write(d[st[i]])", "from sys import stdin, stdout\r\nimport math,sys\r\nfrom itertools import permutations, combinations\r\nfrom collections import defaultdict,deque,OrderedDict\r\nfrom os import path\r\nimport bisect as bi\r\nimport heapq \r\ndef yes():print('YES')\r\ndef no():print('NO')\r\nif (path.exists('input.txt')): \r\n #------------------Sublime--------------------------------------#\r\n sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');\r\n def I():return (int(input()))\r\n def In():return(map(int,input().split()))\r\nelse:\r\n #------------------PYPY FAst I/o--------------------------------#\r\n def I():return (int(stdin.readline()))\r\n def In():return(map(int,stdin.readline().split()))\r\n\r\ndef dict(a):\r\n d={}\r\n for x in a:\r\n if d.get(x,-1)!=-1:\r\n d[x]+=1\r\n else:\r\n d[x]=1\r\n return d\r\n\r\ndef find_gt(a, x):\r\n 'Find leftmost value greater than x'\r\n i = bi.bisect_right(a, x)\r\n if i != len(a):\r\n return i\r\n else:\r\n return -1\r\ndef main():\r\n try:\r\n n,m=In()\r\n l=list(input())\r\n d=defaultdict(list)\r\n for x in range(n):\r\n d[l[x]].append(x)\r\n #print(d)\r\n for i in range(m):\r\n a,b=input().split(' ')\r\n d[a],d[b]=d[b],d[a]\r\n #print(d)\r\n ans=['']*n\r\n for x in d:\r\n for i in d[x]:\r\n ans[i]=x\r\n print(''.join(ans))\r\n \r\n except:\r\n pass\r\n \r\nM = 998244353\r\nP = 1000000007\r\n \r\nif __name__ == '__main__':\r\n #for _ in range(I()):main()\r\n for _ in range(1):main()", "# n = int(input())\r\n# a = [int(i) for i in input().split()]\r\n# s = input()\r\nn, m = [int(i) for i in input().split()]\r\ns = input()\r\nx = [''] * m\r\ny = [''] * m\r\nfor i in range(m):\r\n x[i], y[i] = [i for i in input().split()]\r\nletter = [[] for i in range(26)]\r\nfor i in range(n):\r\n letter[ord(s[i]) - ord('a')].append(i)\r\nfor i in range(m):\r\n letter[ord(x[i]) - ord('a')], letter[ord(y[i]) - ord('a')] = letter[ord(y[i]) - ord('a')], letter[ord(x[i]) - ord('a')]\r\ns_ans = [''] * n\r\nfor i in range(26):\r\n for j in range(len(letter[i])):\r\n s_ans[letter[i][j]] = chr(i + ord('a'))\r\nprint(''.join(s_ans))\r\n\r\n", "n, m = map(int, input().split())\r\ns = input()\r\n\r\nmatrix = []\r\nfor r in range(26):\r\n matrix.append([0] * 26)\r\n matrix[-1][r] = 1\r\n\r\nfor _ in range(m):\r\n old, new = input().split()\r\n _old = ord(old) - ord('a')\r\n _new = ord(new) - ord('a')\r\n matrix[_old], matrix[_new] = matrix[_new], matrix[_old]\r\n\r\n\r\nans = []\r\nchanges = {}\r\nfor i, row in enumerate(matrix):\r\n pos = row.index(1)\r\n changes[chr(pos + ord('a'))] = chr(i + ord('a'))\r\n\r\nfor c in s:\r\n ans.append(c if c not in changes else changes[c])\r\n\r\nans = ''.join(ans)\r\nprint(ans)\r\n", "import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n# def LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\n# a〜z -- START --\nalf=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n# a〜z --- END ---\n\ndef main():\n n,k=LI()\n d={}\n for x in alf:\n d[x]=x\n\n s=S()\n for _ in range(k):\n a,b=LS()\n for k,v in d.items():\n if v==a:\n d[k]=b\n if v==b:\n d[k]=a\n\n ans=''\n for x in s:\n ans+=d[x]\n\n return ans\n\n# main()\nprint(main())\n", "n, m = map(int, input().split())\ns = input()\nw = list(range(26))\nfor i in range(m):\n a, b = input().split()\n c, d = ord(a) - ord('a'), ord(b) - ord('a')\n w[c], w[d] = w[d], w[c]\nt = { chr(w[c] + ord('a')): chr(c + ord('a')) for c in range(26) }\nfor c in s:\n print(t[c], end=\"\")\nprint()\n", "(a,b)=(int(i) for i in input().split())\r\nimport string\r\nstr=input()\r\ng={c:c for c in string.ascii_lowercase}\r\nfor j in range(b):\r\n (e,r)=(h for h in input().split())\r\n g[e],g[r]=g[r],g[e]\r\ng2 = {b:a for a,b in g.items()}\r\nprint(''.join(g2[c] for c in str))\r\n", "from string import ascii_lowercase as ascii\r\nn, m = (int(x) for x in input().split())\r\ns = input()\r\nf = dict(zip(ascii, ascii))\r\nt = dict(zip(ascii, ascii))\r\nfor i in range(m):\r\n\ta, b = input().split()\r\n\tA = t[a]\r\n\tB = t[b]\r\n\tf[A] = b\r\n\tf[B] = a\r\n\tt[a] = B\r\n\tt[b] = A\r\nfor c in s:\r\n\tprint(f[c], end='')\r\nprint()\r\n", "import sys, os, io\r\ninput = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline\r\n\r\nn, m = map(int, input().split())\r\ns = list(input().rstrip())\r\nu = [i for i in range(130)]\r\nfor _ in range(m):\r\n xy = list(input().rstrip())\r\n x, y = u.index(xy[0]), u.index(xy[2])\r\n u[x], u[y] = u[y], u[x]\r\nans = [chr(u[i]) for i in s]\r\nsys.stdout.write(\"\".join(ans))", "# ========== //\\\\ //|| ||====//||\r\n# || // \\\\ || || // ||\r\n# || //====\\\\ || || // ||\r\n# || // \\\\ || || // ||\r\n# ========== // \\\\ ======== ||//====|| \r\n# code\r\n\r\ninn = lambda : int(input())\r\ninm = lambda : map(int, input().split())\r\nins = lambda : str(input())\r\nina = lambda : list(map(int, input().split()))\r\n\r\nimport string\r\n\r\ndef solve():\r\n n,m = inm()\r\n s = ins()\r\n c = {}\r\n\r\n for i in string.ascii_lowercase:\r\n c[i] = i\r\n \r\n for i in range(m):\r\n a,b = map(str, input().split())\r\n for j in c.keys():\r\n if c[j] == a:\r\n c[j] = b\r\n elif c[j] == b:\r\n c[j] = a\r\n \r\n t = \"\"\r\n for i in s:\r\n t += c[i]\r\n print(t)\r\n \r\ndef main():\r\n t = 1\r\n # t = int(input())\r\n for _ in range(t):\r\n solve()\r\n\r\nif __name__ == \"__main__\":\r\n main()", "import sys\n\ndigitInput = (sys.stdin.readline()).split()\n\noriginalAlpha = \"abcdefghijklmnopqrstuvwxyz\"\nnewAlpha = \"abcdefghijklmnopqrstuvwxyz\"\n\nword = sys.stdin.readline()\n\nfor n in range(int(digitInput[1])):\n change = (sys.stdin.readline()).strip(\"\\n\").split()\n\n newAlpha = newAlpha.replace(change[0],change[1].upper())\n newAlpha = newAlpha.replace(change[1],change[0])\n newAlpha = newAlpha.lower()\n\nfor f in range(26):\n word = word.replace(originalAlpha[f],newAlpha[f].upper())\n\nsys.stdout.write(word.lower())\n\n\t\t \t\t\t\t\t\t\t \t\t\t\t\t \t \t\t \t\t \t", "# 591B\r\n# θ(n + m) time\r\n# θ(n) space\r\n\r\n__author__ = 'artyom'\r\n\r\n\r\n# SOLUTION\r\n\r\ndef main():\r\n z = {}\r\n for i in range(26):\r\n z[chr(i + 97)] = chr(i + 97)\r\n n, m = read(3)\r\n s = read(0)\r\n for _ in range(m):\r\n f, t = read(2)\r\n z[t], z[f] = z[f], z[t]\r\n repl = [0] * 26\r\n for key, val in z.items():\r\n repl[ord(val) - 97] = key\r\n r = ''\r\n for c in s:\r\n r += repl[ord(c) - 97]\r\n return r\r\n\r\n\r\n# HELPERS\r\n\r\ndef read(mode=1, size=None):\r\n # 0: String\r\n # 1: Integer\r\n # 2: List of strings\r\n # 3: List of integers\r\n # 4: Matrix of integers\r\n if mode == 0: return input().strip()\r\n if mode == 1: return int(input().strip())\r\n if mode == 2: return input().strip().split()\r\n if mode == 3: return list(map(int, input().strip().split()))\r\n a = []\r\n for _ in range(size):\r\n a.append(read(3))\r\n return a\r\n\r\n\r\ndef write(s=\"\\n\"):\r\n if s is None: s = ''\r\n if isinstance(s, tuple) or isinstance(s, list): s = ' '.join(map(str, s))\r\n s = str(s)\r\n print(s, end=\"\\n\")\r\n\r\n\r\nwrite(main())", "n, m = [int(i) for i in input().split()]\r\ns = input()\r\n\r\nst = [chr(ord('a')+i) for i in range(26)]\r\nfor i in range (m) :\r\n a, b = input().split()\r\n for i in range(26):\r\n if st[i] == a:\r\n st[i] = b\r\n elif st[i] == b:\r\n st[i] = a\r\n\r\n\r\nprint(''.join([ st[ord(i)-ord('a')] for i in s]))\r\n\r\n\r\n\r\n\r\n'''RATHER THAN CHANGING LONG STRING WE WILL ONLY CHANG ETHE ALPHABETS AND THEN CHNAGE THE STRING ONLY \r\nONCE ACCORDING TO ALPHABETS\r\n'''", "import sys\n\nn, m = map(int, sys.stdin.readline().split())\n\nname = list(sys.stdin.readline())\n\nletters = 'abcdefghijklmnopqrstuvwxyz'\nreplacement = list(letters)\n\n# letters.index(a)\n\nfor i in range(m):\n a, b = sys.stdin.readline().split()\n for j in range(26):\n if replacement[j] == a:\n replacement[j] = b\n elif replacement[j] == b:\n replacement[j] = a\n\nfor i in range(n):\n name[i] = replacement[letters.index(name[i])]\n\nprint(''.join(name))\n \t \t \t\t \t\t\t \t\t\t\t\t \t\t\t \t\t\t", "import sys\n\n\n#sys.stdin = open(\"input.txt\")\n#sys.stdout = open(\"output.txt\", \"w\")\n\nn, m = [int(x) for x in input().split()]\ns = input()\nc1 = ord('a')\nc2 = ord('z')\nma = [i for i in range(c2-c1+1)]\nwhere = [i for i in range(c2-c1+1)]\nfor i in range(m):\n\tcf, cs = [ord(c) for c in input().split()]\n\twcf = where[cf - c1]\n\twcs = where[cs - c1]\n\tma[wcf], ma[wcs] = ma[wcs], ma[wcf]\n\twhere[cf - c1], where[cs - c1] = where[cs - c1], where[cf - c1]\n\nans = []\nfor c in s:\n\tcur = ord(c)\n\tans.append(chr(ma[cur-c1] + c1))\n\nprint(''.join(ans))\n\n", "alf = list('abcdefghijklmnopqrstuvwxyz')\r\nn, m = map(int, input().split())\r\ns = input()\r\nfor i in range(m):\r\n\tx, y = input().split()\r\n\tindex1 = alf.index(x)\r\n\tindex2 = alf.index(y)\r\n\talf[index1], alf[index2] = alf[index2], alf[index1]\r\nfor i in s:\r\n\tprint(alf[ord(i) - ord('a')], end='')", "import string\r\nN, M = map(int, input().split())\r\nS = input()\r\ndic = string.ascii_lowercase\r\nfor _ in range(M):\r\n x, y = input().split()\r\n dic = dic.translate(str.maketrans(x+y, y+x))\r\nprint(S.translate(str.maketrans(string.ascii_lowercase, dic)))", "n, m = map(int, input().split())\r\n\r\nname = input()\r\ncharList = [[chr(ord('a') + i),chr(ord('a') + i)] for i in range(26)]\r\n\r\nfor i in range(m):\r\n x, y = input().split()\r\n (charList[ord(y)-ord('a')][1], charList[ord(x)-ord('a')][1]) = (charList[ord(x)-ord('a')][1], charList[ord(y)-ord('a')][1])\r\n (charList[ord(y)-ord('a')], charList[ord(x)-ord('a')]) = (charList[ord(x)-ord('a')], charList[ord(y)-ord('a')])\r\n\r\ncharList.sort()\r\nnewName = \"\"\r\nfor i in range(n):\r\n newName = newName + charList[ord(name[i]) - ord('a')][1]\r\n\r\nprint(newName)\r\n", "from math import sqrt, ceil, floor\nfrom sys import stdin, stdout\nfrom heapq import heapify, heappush, heappop\nimport string\n\nn, m = map(int, stdin.readline().split())\na = stdin.readline()\nl = list(string.ascii_lowercase)\n\nz = [[] for i in range(26)]\nfor i in range(n):\n z[ord(a[i]) - ord('a')].append(i)\nfor i in range(m):\n tmp1, tmp2 = stdin.readline().split()\n le = l.index(tmp1)\n re = l.index(tmp2)\n l[le], l[re] = l[re], l[le]\nans = [\" \"] * n\nfor i in range(26):\n for j in range(len(z[i])):\n ans[z[i][j]] = l[i]\nfor i in range(n):\n stdout.write(ans[i])\n", "# import sys\r\n# sys.stdin = open('cf591b.in')\r\n\r\nn, m = map(int, input().split())\r\ns = input()\r\n\r\nperm = list(range(26))\r\n\r\nv = ord('a')\r\n\r\nfor _ in range(m):\r\n\tss = input()\r\n\ti, j = (ord(ss[0]) - v, ord(ss[2]) - v)\r\n\tperm[i], perm[j] = perm[j], perm[i]\r\n\r\nrev = [perm.index(c) for c in range(26)]\r\nprint(''.join(chr(rev[ord(c) - v] + v) for c in s))", "A = list(\"abcdefghijklmnopqrstuvwxyz\")\r\nn, m = map( int, input().split() )\r\nname = input()\r\n\r\nfor i in range( m ) :\r\n s = input()\r\n x, y = s[0], s[2]\r\n\r\n x_index = A.index( x )\r\n y_index = A.index( y )\r\n\r\n A[x_index], A[y_index] = A[y_index], A[x_index]\r\n\r\nfor c in name :\r\n index = ord( c ) - ord( 'a' )\r\n print( A[index], end='')", "import math\n\ndef main():\n n, m = tuple(map(int, input().split()))\n s = input()\n d = {}\n for i in range(n):\n d[s[i]] = s[i]\n\n for i in range(m):\n x, y = [i for i in input().split()] \n used = None\n for k, v in d.items():\n if d[k] == x and k != used:\n d[k] = y\n used = k\n continue\n if d[k] == y and k != used:\n d[k] = x\n used = k\n continue\n\n res = \"\"\n for c in s:\n res += d[c]\n return res\n\n\nif __name__==\"__main__\":\n print(main())\n", "n, m = map(int, input().split(' ')[:2])\ns = input()[:n]\n\nls = {}\n\nfor c in s:\n ls[c] = c\n\nfor i in range(m):\n x, y = input().split(' ')[:2]\n if x not in ls:\n ls[x] = x\n if y not in ls:\n ls[y] = y\n ls[x], ls[y] = ls[y], ls[x]\n\nrev = {}\nfor c, v in ls.items():\n rev[v] = c\n\nprint(''.join([rev[c] for c in s]))\n", "inp=input().strip().split()\r\nn,m=int(inp[0]),int(inp[1])\r\ns=input().strip()\r\nd={}\r\nfor i in range(n):\r\n if(s[i] in d):\r\n d[s[i]].append(i)\r\n else:\r\n d[s[i]]=[i]\r\n\r\nfor i in range(m):\r\n inp=input().strip().split()\r\n l0,l1=[],[]\r\n b0,b1=False,False\r\n if(inp[0] in d):\r\n #l0=d[inp[0]]\r\n b0=True\r\n if(inp[1] in d):\r\n #l1=d[inp[1]]\r\n b1=True\r\n if(b0 and b1):\r\n d[inp[0]],d[inp[1]]=d[inp[1]],d[inp[0]]\r\n elif(b0 and (not b1)):\r\n d[inp[1]]=d[inp[0]]\r\n del(d[inp[0]])\r\n elif(b1 and (not b0)):\r\n d[inp[0]]=d[inp[1]]\r\n del(d[inp[1]])\r\n \r\n \r\n\r\nans=[0]*n\r\nfor key in d.keys():\r\n for i in d[key]:\r\n ans[i]=key\r\n\r\nfor ctmp in ans:\r\n print(ctmp,end='')\r\nprint()\r\n \r\n \r\n", "n,m = map(int,input().split())\r\ns = list(input())\r\nstrn = 'abcdefghijklmnopqrstuvwxyz'\r\ndic = {}\r\nfor i in strn:\r\n dic[i] = i\r\nfor i in range(m):\r\n x,y = input().split()\r\n for j in dic:\r\n if dic[j]==x:\r\n dic[j]=y\r\n elif dic[j]==y:\r\n dic[j]=x\r\nfor i in range(n):\r\n s[i] = dic[s[i]]\r\nprint(''.join(s))", "import sys\r\nimport string\r\n\r\nlines = sys.stdin.readlines()\r\nm, n = map(int, lines[0].split())\r\ns = list(map(lambda x: ord(x) - ord('a'), lines[1]))[:-1]\r\nr = [c for c in string.ascii_lowercase]\r\nfor i in range(n):\r\n x, y = lines[2 + i][0], lines[2 + i][2]\r\n for j in range(26):\r\n if r[j] == x:\r\n r[j] = y\r\n elif r[j] == y:\r\n r[j] = x\r\nfor i in range(m):\r\n s[i] = r[s[i]]\r\nprint(''.join(s))", "n,m = [int(x) for x in input().split()]\r\nname = input()\r\n\r\nalphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\r\n\r\nfor i in range(m):\r\n x,y = input().split()\r\n indexX = alphabet.index(x)\r\n indexY = alphabet.index(y)\r\n alphabet[indexX],alphabet[indexY] = alphabet[indexY],alphabet[indexX]\r\n\r\nnewName = ''\r\n\r\nfor character in name:\r\n newName += alphabet[ord(character)-97]\r\n\r\nprint(newName)\r\n\r\n\r\n\r\n\r\n\r\n#for i in range(m):\r\n# x,y = input().split()\r\n# name = name.replace(x,'.').replace(y,x).replace('.',y)\r\n\r\n\r\n\r\n\r\n#for i in range(m):\r\n# newName = \"\"\r\n# x,y = input().split()\r\n# for character in name:\r\n# if character == x:\r\n# newName+=y\r\n# elif character == y:\r\n# newName += x\r\n# else:\r\n# newName += character\r\n# name = newName", "import string\r\nt = string.ascii_lowercase\r\nt2 = list(t)\r\n#print(t2)\r\nn , m = map(int,input().split())\r\ns = input()\r\n\r\nfor i in range(m):\r\n x , y = input().split()\r\n\r\n index_x = t2.index(x)\r\n index_y = t2.index(y)\r\n t2[index_x] , t2[index_y] = t2[index_y] , t2[index_x]\r\n\r\n#print(t2)\r\nfor i in s :\r\n index = ord(i) - ord('a')\r\n print(t2[index] , end = '')\r\n\r\n\r\n\r\n", "def main():\n n, m = map(int, input().split())\n s = input()\n l = list(\"abcdefghijklmnopqrstuvwxyz\")\n f = l.index\n for _ in range(m):\n x, y = map(f, input().split())\n l[x], l[y] = l[y], l[x]\n print(''.join(l[ord(c) - 97] for c in s))\n\n\nif __name__ == '__main__':\n main()\n", "import string\r\n\r\nn, m = map(int, input().split())\r\nd = {i:i for i in string.ascii_lowercase}\r\na = [*input()]\r\nfor i in range(m):\r\n x, y = input().split()\r\n d[x], d[y] = d[y], d[x]\r\nd = {d[i]:i for i in d}\r\na = [d[i] for i in a]\r\nprint(''.join(a))", "n, m = (int(x) for x in input().split())\r\ns = input()\r\nf = dict(zip(\"abcdefghijklmnopqrstuvxwyz\", \"abcdefghijklmnopqrstuvxwyz\"))\r\nt = dict(zip(\"abcdefghijklmnopqrstuvxwyz\", \"abcdefghijklmnopqrstuvxwyz\"))\r\nfor i in range(m):\r\n\ta, b = input().split()\r\n\tA = t[a]; B = t[b]\r\n\tf[A] = b; f[B] = a\r\n\tt[a] = B; t[b] = A\r\nfor c in s:\r\n\tprint(f[c], end='')\r\nprint()", "n, m = map(int, input().split())\r\na = input()\r\nold = \"abcdefghijklmnopqrstuvwxyz\"\r\nnew = old\r\nfor _ in range(m):\r\n x, y = input().split()\r\n new = new.translate(\"\".maketrans(x + y, y + x))\r\nprint(a.translate(''.maketrans(old, new)))\r\n", "import string\r\ndef mp():\r\n return map(int,input().split())\r\ndef lt():\r\n return list(map(int,input().split()))\r\ndef pt(x):\r\n print(x)\r\n\r\nn,m = mp()\r\ns = input()\r\ns1 = string.ascii_lowercase\r\nfor i in range(m):\r\n L = input().split()\r\n a,b = L[0],L[1]\r\n s1 = s1.translate(str.maketrans(a+b,b+a))\r\npt(s.translate(str.maketrans(string.ascii_lowercase,s1)))\r\n \r\n\r\n \r\n ", "from string import ascii_lowercase as ascii\nn, m = (int(x) for x in input().split())\ns = input()\nf = dict(zip(ascii, ascii))\nt = dict(zip(ascii, ascii))\nfor i in range(m):\n\ta, b = input().split()\n\tA = t[a]\n\tB = t[b]\n\tf[A] = b\n\tf[B] = a\n\tt[a] = B\n\tt[b] = A\nfor c in s:\n\tprint(f[c], end='')\nprint()\n", "n,m=map(int,input().split())\r\nx=list(input())\r\nd={}\r\ny=list(set(x))\r\nz=list(set(x))\r\nfor i in x:\r\n d[i]=i\r\nfor t in range(m):\r\n a,b=map(str,input().split())\r\n for i in range(len(y)):\r\n if y[i]==a:\r\n y[i]=b\r\n elif y[i]==b:\r\n y[i]=a\r\nfor i in range(len(y)):\r\n d[z[i]]=y[i]\r\n# print(d)\r\nfor i in range(n):\r\n x[i]=d[x[i]]\r\nprint(\"\".join(x))", "from collections import defaultdict\r\n\r\n\r\ndef rebranding():\r\n\tn_m = input().split()\r\n\tn = int(n_m[0])\r\n\tm = int(n_m[1])\r\n\r\n\tbrand_name = list(input())\r\n\r\n\tlowercase_letters = list(map(chr, range(97, 123)))\r\n\torigin_lowercase_letters = list(map(chr, range(97, 123)))\r\n\r\n\r\n\tfor _ in range(0, m):\r\n\t\tx, y = input().split()\r\n\t\tif x != y:\r\n\t\t\tidx = lowercase_letters.index(x)\r\n\t\t\tidy = lowercase_letters.index(y)\r\n\t\t\tlowercase_letters[idx] = y\r\n\t\t\tlowercase_letters[idy] = x\r\n\r\n\tdictionnary = defaultdict(str)\r\n\r\n\tfor i, letter in enumerate(origin_lowercase_letters):\r\n\t\tdictionnary[letter] = lowercase_letters[i]\r\n\r\n\tfor i, letter in enumerate(brand_name):\r\n\t\tbrand_name[i] = dictionnary[letter]\r\n\t\t\r\n\tprint(''.join(brand_name))\r\n\r\n\r\nif __name__ == '__main__':\r\n\trebranding()\r\n\r\n\r\n", "n, m = map(int, input().split())\r\ns = input()\r\nd = dict()\r\nfor i in range(26):\r\n d[chr(i + 97)] = chr(i + 97)\r\nfor i in range(m):\r\n a, x = input().split()\r\n for j in range(26):\r\n if d[chr(j + 97)] == a:\r\n d[chr(j + 97)] = x\r\n elif d[chr(j + 97)] == x:\r\n d[chr(j + 97)] = a\r\nfor i in s:\r\n print(d[i], end = '')", "mp=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\nn,m=map(int,input().split())\nstrs=[i for i in input()]\nsize=26\nfor i in range(m):\n a,b=input().split()\n for j in range(size):\n if mp[j]==a:\n mp[j]=b\n elif mp[j]==b:\n mp[j]=a\nfor i in range(len(strs)):\n print(mp[ord(strs[i])-97],end=\"\")\nprint()\n\n \t\t\t\t \t \t\t \t\t\t \t\t \t \t", "from sys import stdin\r\n\r\n#stdin = open('input.txt')\r\n\r\nlet_a = ord('a')\r\nletters = [0]*26\r\nfor i in range(0, 26):\r\n letters[i] = chr(let_a + i)\r\n\r\n(n, m) = [int(x) for x in stdin.readline().split()]\r\ns = stdin.readline().strip()\r\ni = 0\r\nwhile i < m:\r\n (a, b) = stdin.readline().split()\r\n if a[0] != b[0]:\r\n letters[ord(a[0]) - let_a], letters[ord(b[0]) - let_a] = letters[ord(b[0]) - let_a], letters[ord(a[0]) - let_a]\r\n i += 1\r\n\r\nreplace = [0]*26\r\nfor i in range(0, 26):\r\n replace[ord(letters[i]) - let_a] = chr(let_a + i)\r\n\r\nfor c in s:\r\n print(replace[ord(c) - let_a], end='')\r\n", "g={}\r\nn,m=map(int,input().split())\r\nans=['']*n\r\ns=input()\r\nfor i in'qwertyuiopasdfghjklzxcvbnm':\r\n g[i]=[]\r\nfor i in range(n):\r\n g[s[i]]+=[i]\r\nfor i in range(m):\r\n a,b=input().split()\r\n g[a],g[b]=g[b],g[a]\r\nfor i in g:\r\n for j in g[i]:\r\n ans[j]=i\r\nprint(''.join(ans))" ]
{"inputs": ["6 1\npolice\np m", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b", "1 1\nf\nz h", "1 1\na\na b", "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e"], "outputs": ["molice", "cdcbcdcfcdc", "f", "b", "lellelleel"]}
UNKNOWN
PYTHON3
CODEFORCES
119
219366dfd3d5a68d977c0efa6cb0721a
DZY Loves Sequences
DZY has a sequence *a*, consisting of *n* integers. We'll call a sequence *a**i*,<=*a**i*<=+<=1,<=...,<=*a**j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) a subsegment of the sequence *a*. The value (*j*<=-<=*i*<=+<=1) denotes the length of the subsegment. Your task is to find the longest subsegment of *a*, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing. You only need to output the length of the subsegment you find. The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). In a single line print the answer to the problem — the maximum length of the required subsegment. Sample Input 6 7 2 3 1 5 6 Sample Output 5
[ "# Love u Atreyee\nn = int(input())\na = list(map(int, input().split()))\nleft = [1] * n\nfor i in range(1, n):\n if a[i] > a[i - 1]:\n left[i] = left[i - 1] + 1\nright = [1] * n\nfor i in range(n-2,-1,-1):\n if a[i] < a[i + 1]:\n right[i] = right[i + 1] + 1\nans = max(left)\nif ans < n:\n ans += 1\nfor i in range(1, n - 1):\n if a[i - 1] + 1 < a[i + 1]:\n ans = max(ans, left[i - 1] + right[i + 1] + 1)\nprint(ans)", "n = int(input())\r\ndata = list(map(int, input().split()))\r\nl = [1] * n\r\nr = [1] * n\r\nfor i in range(1, n):\r\n if data[i - 1] < data[i]: \r\n l[i] += l[i - 1]\r\nfor i in range(n - 2, 0, -1):\r\n if data[i + 1] > data[i]: \r\n r[i] += r[i + 1]\r\nans = max(max(l), max(r))\r\nif ans < n:\r\n ans += 1\r\nfor i in range(1, n - 1):\r\n if data[i - 1] + 1 < data[i + 1]:\r\n ans = max(ans, l[i - 1] + r[i + 1] + 1)\r\nprint(ans)", "n=int(input())\na=list(map(int,input().split()))\nl = [1]*n\nr = [1]*n\n\nfor i in range(1,n):\n if a[i-1]<a[i]:l[i]+=l[i-1]\nfor i in range(n-2,0,-1):\n if a[i+1]>a[i]:r[i]+=r[i+1]\nans = max(max(l),max(r))\nif ans<n:\n ans+=1\nfor i in range(1,n-1):\n if a[i-1]+1<a[i+1]:\n ans= max(ans,l[i-1]+r[i+1]+1)\nprint(ans)\n", "n = int(input())\na = [-1] + list(map(int, input().split())) + [1000000007]\n\nmaxi = 0\nup = [0 for i in range(n+2)]\ndown = [0 for i in range(n+2)]\n\nfor i in range(1, n+1):\n\tup[i] = up[i-1] + 1 if a[i] > a[i-1] else 1\nfor i in range(n, 0, -1):\n\tdown[i] = down[i+1] + 1 if a[i] < a[i+1] else 1\nfor i in range(1, n+1):\n\tmaxi = max(maxi, up[i-1]+(a[i-1]+1 < a[i+1])*down[i+1]+1)\n\tmaxi = max(maxi, up[i-1]*(a[i+1]-1 > a[i-1])+down[i+1]+1)\nprint(maxi)", "n=int(input())\r\na=list(map(int,input().split()))\r\nb=[1]\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n b.append(b[-1]+1)\r\n else:\r\n b.append(1)\r\nans=max(b)\r\nif ans!=n:\r\n ans+=1\r\nc=[0]*n\r\ni=n-1\r\nval=b[-1]\r\nwhile i>=0:\r\n for j in range(val):\r\n c[i]=val\r\n i-=1\r\n val=b[i]\r\nfor i in range(1,n-1):\r\n if a[i+1]-a[i-1]>=2:\r\n if b[i]==1:\r\n ans=max(ans,c[i-1]+c[i])\r\n elif b[i+1]==1:\r\n ans=max(ans,c[i+1]+c[i])\r\nprint(ans)", "n = int(input())\r\nl = list(map(int, input().split(\" \")))\r\na = [1] * n\r\nb = [1] * n\r\nfor i in range(1, n):\r\n if l[i] > l[i - 1]:\r\n a[i] = a[i - 1] + 1\r\ni = n - 2\r\nwhile i >= 0:\r\n if l[i + 1] > l[i]:\r\n b[i] = b[i + 1] + 1\r\n i = i - 1\r\ntotal = max(a)\r\nif total < n:\r\n total = total + 1\r\nfor i in range(1, n - 1):\r\n if l[i - 1] + 1 < l[i + 1]:\r\n total = max(total, a[i - 1] + 1 + b[i + 1])\r\n else:\r\n total = max(total, a[i - 1] + 1)\r\nprint(total)\r\n", "import sys\r\nT=1\r\nfor _ in range(T):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n p=[]\r\n i=0\r\n j=1\r\n kk=0\r\n while(j<n):\r\n if(l[j]<=l[j-1]):\r\n p.append((i,j-1))\r\n if(j-i>kk):\r\n kk=j-i\r\n i=j\r\n j+=1\r\n p.append((i,j-1))\r\n if j-i>kk:\r\n kk=j-i\r\n ans=0\r\n if(len(p)==1):\r\n ans=n\r\n else:\r\n ans=kk+1\r\n for i in range(len(p)-1):\r\n t1=p[i]\r\n t2=p[i+1]\r\n i1,i2=t1[0],t1[1]\r\n j1,j2=t2[0],t2[1]\r\n if(i1==i2 or j1==j2):\r\n q=j2-i1+1\r\n if(q>ans):\r\n ans=q\r\n else:\r\n if(l[j1]-l[i2-1]>=2 or l[j1+1]-l[i2]>=2):\r\n q=j2-i1+1\r\n if(q>ans):\r\n ans=q\r\n print(ans)\r\n ", "n = int(input())\r\narr = list(map(int, input().split()))\r\nl, r = [1] * n, [1] * n\r\nfor i in range(1, n):\r\n if arr[i-1] < arr[i]: \r\n l[i] += l[i-1]\r\nfor i in range(n - 2, -1, -1):\r\n if arr[i+1] > arr[i]: \r\n r[i] += r[i+1]\r\nres = max(l)\r\nif res < n: \r\n res += 1\r\nfor i in range(1, n - 1):\r\n if arr[i-1] + 1 < arr[i+1]:\r\n res = max(res, l[i-1] + 1 + r[i+1])\r\nprint(res)\r\n", "n = int(input())\r\naa = [-2] + list(map(int, input().split(' '))) + [10 ** 10]\r\n\r\nls = [0] * (n + 2)\r\nrs = [0] * (n + 2)\r\n\r\nfor i in range(2, n + 1):\r\n\tif aa[i - 2] < aa[i - 1]:\r\n\t\tls[i] = ls[i - 1] + 1\r\n\telse:\r\n\t\tls[i] = 1\r\n\r\nfor i in range(n-1, 0, -1):\r\n\tif aa[i + 1] < aa[i + 2]:\r\n\t\trs[i] = rs[i + 1] + 1\r\n\telse:\r\n\t\trs[i] = 1\r\n\r\n#print(ls)\r\n#print(rs)\r\n\r\nm = 0\r\nfor i in range(1, n + 1):\r\n\tcur = ls[i] + rs[i] + 1 if aa[i - 1] + 1 < aa[i + 1] else max(ls[i], rs[i]) + 1\r\n\tm = max(m, cur)\r\n\r\nprint(m)", "n=int(input())\r\na=list(map(int,input().split()))\r\nl=[1]*n\r\nr=[1]*n\r\nfor i in range(1,n):\r\n if a[i-1]<a[i]: l[i]+=l[i-1]\r\nfor i in range(n-2,-1,-1):\r\n if a[i+1]>a[i]: r[i]+=r[i+1]\r\nmx=max(l)\r\nif mx<n: mx+=1\r\nfor i in range(1,n-1):\r\n if a[i-1]+1<a[i+1]:\r\n mx=max(mx,l[i-1]+1+r[i+1])\r\nprint(mx)\r\n\r\n##//////////////// ////// /////// // /////// // // //\r\n##//// // /// /// /// /// // /// /// //// //\r\n##//// //// /// /// /// /// // ///////// //// ///////\r\n##//// ///// /// /// /// /// // /// /// //// // //\r\n##////////////// /////////// /////////// ////// /// /// // // // //\r\n\r\n\r\n\r\n", "# Description of the problem can be found at http://codeforces.com/problemset/problem/446/A\r\n\r\nn=int(input())\r\n\r\na=list(map(int, input().split()))\r\n\r\npre=[1] * n\r\nsuf=[1] * n\r\n\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n pre[i] = pre[i - 1] + 1\r\nfor i in range(n - 2, 0, -1):\r\n if a[i] < a[i + 1]:\r\n suf[i] = suf[i + 1] + 1\r\n\r\nans=max(pre)\r\n\r\nfor i in range(0, n):\r\n if i > 0:\r\n ans=max(ans, pre[i - 1] + 1)\r\n if i < n - 1:\r\n ans = max(ans, suf[i + 1] + 1)\r\n if i > 0 and i < n - 1 and a[i - 1] <= a[i + 1] - 2:\r\n ans = max(ans, pre[i - 1] + suf[i + 1] + 1)\r\nprint(ans)", "n=int(input())\r\na=list(map(int,input().split()))\r\ndpl=[1]*n\r\ndpr=[1]*n\r\nfor i in range(1,n):\r\n\tif a[i]>a[i-1]:dpl[i]=dpl[i-1]+1\r\nfor i in range(n-2,-1,-1):\r\n\tif a[i]<a[i+1]:dpr[i]=dpr[i+1]+1\r\nres=max(dpl)\r\nif res<n:res=res+1\r\nfor i in range(1,n-1):\r\n\tif a[i+1]-a[i-1]>1:res=max(res,dpl[i-1]+dpr[i+1]+1)\r\nprint(res)", "import sys\r\n\r\nnum = int(input())\r\nseq = [-1] + list(map(int, input().split())) + [sys.maxsize]\r\n\r\nmaxi = 0\r\nforward = [0 for i in range(num+2)]\r\nback = [0 for i in range(num+2)]\r\n\r\nfor i in range(1, num+1):\r\n\tforward[i] = forward[i-1] + 1 if seq[i] > seq[i-1] else 1\r\nfor i in range(num, 0, -1):\r\n\tback[i] = back[i+1] + 1 if seq[i] < seq[i+1] else 1\r\nfor i in range(1, num+1):\r\n maxi = max(maxi, forward[i-1]+(seq[i-1]+1 < seq[i+1])*back[i+1]+1)\r\n maxi = max(maxi, forward[i-1]*(seq[i+1]-1 > seq[i-1])+back[i+1]+1)\r\nprint(maxi)", "a=int(input())\r\nz=list(map(int,input().split()))\r\ndp=[[0 for i in range(len(z))] for i in range(2)]\r\nans=[1]\r\nfor i in range(1,len(z)):\r\n if(z[i]>z[i-1]):\r\n ans.append(ans[-1]+1)\r\n else:\r\n ans.append(1)\r\ndp[0][0]=1\r\ndp[1][0]=0\r\n\r\nmaxa=1\r\nfor i in range(1,len(z)):\r\n\r\n if(z[i]>z[i-1]):\r\n if(i==1):\r\n dp[0][i]=2\r\n dp[1][i]=2\r\n maxa=max(dp[0][i],dp[1][i],maxa)\r\n continue;\r\n dp[1][i]=ans[i-1]+1\r\n #u did not change the previous one\r\n dp[0][i]=dp[0][i-1]+1\r\n if(z[i-2]+1<z[i]):\r\n dp[0][i]=max(dp[1][i-1]+1,dp[0][i])\r\n \r\n maxa=max(maxa,dp[0][i],dp[1][i])\r\n else:\r\n if(i==1):\r\n dp[0][i]=2\r\n dp[1][i]=2\r\n maxa=max(dp[0][i],dp[1][i],maxa)\r\n continue;\r\n dp[1][i]=ans[i-1]+1\r\n dp[0][i]=2\r\n if(z[i-2]+1<z[i]):\r\n dp[0][i]=max(dp[1][i-1]+1,dp[0][i])\r\n \r\n maxa=max(dp[0][i],dp[1][i],maxa)\r\nprint(maxa)\r\n\r\n \r\n", "n = int(input())\r\nif n == 1:\r\n print(1)\r\nelse:\r\n a = [int(i) for i in input().split()]\r\n good = [[0 for j in range(2)] for i in range(n)]\r\n good[0][1] = 1\r\n for i in range(n):\r\n if a[i] > a[i - 1]:\r\n good[i][1] = good[i - 1][1] + 1\r\n else:\r\n good[i][1] = 1\r\n good[n - 1][0] = 1\r\n for i in range(n - 2, -1, -1):\r\n if a[i] < a[i + 1]:\r\n good[i][0] = good[i + 1][0] + 1\r\n else:\r\n good[i][0] = 1\r\n mx = max(good[1][0] + 1, good[n - 2][1] + 1)\r\n for i in range(1, n - 1):\r\n if a[i + 1] - a[i - 1] > 1:\r\n mx = max(mx, good[i - 1][1] + good[i + 1][0] + 1)\r\n mx = max(mx, good[i - 1][1] + 1, good[i + 1][0] + 1)\r\n print(mx)", "n,b,i,ma=int(input()),[],0,0\r\na=list(map(int,input().split()))\r\nwhile i<n:\r\n j=i\r\n while j<n-1 and a[j]<a[j+1]:\r\n j+=1\r\n b.append([i,j])\r\n ma,i=max(j-i+1+(i!=0 or j!=n-1),ma),j+1\r\nfor i in range(len(b)-1):\r\n if b[i+1][0]-b[i][1]==2 and a[b[i+1][0]]>a[b[i][1]]+1:\r\n ma=max(ma,b[i+1][1]-b[i][0]+1)\r\n elif b[i+1][0]-b[i][1]==1:\r\n if (b[i+1][0]+1<n and a[b[i+1][0]+1]>a[b[i][1]]+1) or (b[i][1]-1>=0 and a[b[i][1]-1]+1<a[b[i+1][0]]):\r\n ma=max(ma,b[i+1][1]-b[i][0]+1)\r\nprint(ma)", "n = int(input())\nc = [0] * (n+2)\nd = [1] * (n+2)\na = [1] * (n+2)\na[0] = 0\nd[-1] = 0\nfor i, x in enumerate(map(int, input().split()), 1):\n c[i] = x\n if c[i] > c[i-1]:\n a[i] = a[i-1] + 1\n\nfor i in range(n, 0, -1):\n if c[i] < c[i+1]:\n d[i] = d[i+1] + 1\n\nm = 0\nfor i in range(1, n+1):\n if c[i+1] - c[i-1] > 1:\n m = max(m, a[i-1]+d[i+1]+1)\n else:\n m = max(m, a[i-1]+1, d[i+1]+1)\n\nprint(m)\n\n \t\t \t\t \t \t \t\t\t\t \t\t\t \t\t\t\t\t", "R = lambda: map(int, input().split())\r\nn = int(input())\r\narr = list(R())\r\nif n <= 2:\r\n print(n)\r\n exit(0)\r\nleft, right = [1] * (n + 1), [1] * (n + 1)\r\nfor i in range(1, n):\r\n if arr[i] > arr[i - 1]:\r\n left[i] += left[i - 1]\r\nfor i in range(n - 2, -1, -1):\r\n if arr[i] < arr[i + 1]:\r\n right[i] += right[i + 1]\r\nres = max(*left, *right) + 1\r\nfor i in range(1, n - 1):\r\n if arr[i - 1] < arr[i + 1] - 1:\r\n res = max(res, left[i - 1] + 1 + right[i + 1])\r\nprint(min(res, n))", "n = int(input())\na = [int(x) for x in input().split()]\n\nl, r = 0, 0\nc = None\nmx = 1\n\nwhile r < n - 1:\n r += 1\n \n if a[r] <= (a[r - 1] if r - 1 != c else a[r - 2] + 1):\n if c is not None and r - 1 == c and a[r - 1] < a[r]:\n if a[c] < a[c + 1]:\n l = c = c - 1\n else:\n l = c\n else:\n if c is not None:\n if a[c] < a[c + 1]:\n l = c\n else:\n l = c + 1\n \n if r - 1 == l or a[r] - a[r - 2] > 1:\n c = r - 1\n else:\n c = r\n \n mx = max(mx, r - l + 1)\n\nprint(mx)\n", "from sys import *\r\nfrom math import *\r\nfrom collections import *\r\nn=int(stdin.readline())\r\nl=list(map(int,stdin.readline().split()))\r\nend=[1]*(n+1)\r\nstart=[1]*(n+1)\r\nfor i in range(1,n):\r\n if l[i]>l[i-1]:\r\n end[i]+=end[i-1]\r\nfor i in range(n-2,-1,-1):\r\n if l[i]<l[i+1]:\r\n start[i]+=start[i+1]\r\nans=max(end)\r\nif ans<n:\r\n ans+=1\r\nfor i in range(1,n-1):\r\n if l[i-1]+1<l[i+1]:\r\n ans=max(ans,end[i-1]+start[i+1]+1)\r\nprint(ans)", "length = int(input())\nnums = [int(num) for num in input().split()] + [float('inf'), float('-inf')]\n\n\nans, small, big = 0, 0, 0\nfor i in range(length):\n if nums[i] > nums[i - 1]:\n small += 1\n big += 1\n else:\n ans = max(ans, small + 1, big)\n big = small + 1 if nums[i + 1] > nums[i - 1] + 1 or nums[i] > nums[i - 2] + 1 else 2\n if nums[i + 1] > nums[i]:\n small = 1\n else:\n small = 0\nprint(max(ans, big))", "dp_right, dp_left = [], []\ndef solve(n, a) : \n a.insert(0, 0); a.append(0)\n for i in range (1000005) :\n dp_right.append(0)\n dp_left.append(0)\n\n res = 0\n for i in range(1, n + 1) :\n if a[i] > a[i - 1] : dp_right[i] = dp_right[i - 1] + 1\n else : dp_right[i] = 1 \n res = max(res, dp_right[i])\n #print(dp_right[i], sep = ' ')\n\n for i in range(n, 1 - 1, -1) :\n if a[i] < a[i + 1] : dp_left[i] = dp_left[i + 1] + 1\n else : dp_left[i] = 1\n #print(dp_left[i], sep = ' ')\n #print(res)\n for i in range (1, n + 1) : \n res = max(res, max(dp_right[i - 1] + 1, dp_left[i + 1] + 1))\n if a[i - 1] + 1 < a[i + 1] : res = max(res, dp_right[i - 1] + 1 + dp_left[i + 1])\n return res\n\ndef dp010_dzy_loves_sequences(n, a) : \n return solve(n, a)\n\nif __name__ == '__main__' : \n n = int(input())\n a = list(map(int, input().split()))\n print(dp010_dzy_loves_sequences(n, a))", "from operator import le\r\n\r\n\r\nn=int(input())\r\na=[int(x) for x in (\"0 \"+input()+\" 0\").split(\" \")]\r\na[0]=int(1e10)\r\na[n+1]=int(-1e10)\r\n\r\nleft=[1]*(n+5)\r\nright=[1]*(n+5)\r\nans=0\r\nfor i in range(1, n+1):\r\n if a[i]>a[i-1]: left[i]=left[i-1]+1\r\nfor i in range(n, 0, -1):\r\n if a[i]<a[i+1]: right[i]=right[i+1]+1\r\n\r\nans=max(left)\r\nans=max(right)\r\nif ans<n: \r\n ans+=1\r\nfor i in range(2, n):\r\n if a[i-1]+1<a[i+1]: \r\n ans=max(ans, left[i-1]+right[i+1]+1)\r\nprint(ans)\r\n ", "import sys,random,bisect\r\nfrom collections import deque,defaultdict,Counter\r\nfrom heapq import heapify,heappop,heappush\r\nimport math \r\nfrom types import GeneratorType\r\n#from functools import cache 3.9\r\nmod = int(1e9 + 7) #998244353\r\ninf = int(1e20)\r\ninput = lambda :sys.stdin.readline().rstrip()\r\nmi = lambda :map(int,input().split())\r\nli = lambda :list(mi())\r\nii = lambda :int(input())\r\npy = lambda :print(\"YES\")\r\npn = lambda :print(\"NO\")\r\n\r\nn=ii()\r\n\r\na=li()\r\n\r\nl=[0]*n\r\nr=[0]*n\r\n\r\nfor i in range(1,n):\r\n if i==1:\r\n l[i]=1\r\n elif a[i-1]>a[i-2]:\r\n l[i]=l[i-1]+1\r\n else:\r\n l[i]=1\r\n\r\n\r\nfor i in range(n-2,-1,-1):\r\n if i==n-2:\r\n r[i]=1\r\n elif a[i+1]<a[i+2]:\r\n r[i]=r[i+1]+1\r\n else:\r\n r[i]=1\r\n\r\nres=0\r\n\r\n\r\nfor i in range(n):\r\n if i==0 or i==n-1 or a[i+1]-a[i-1]>1:\r\n res=max(res,l[i]+r[i]+1)\r\n res=max(res,l[i]+1,r[i]+1)\r\n\r\nprint(res)\r\n\r\n\r\n\r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\na.append(a[n - 1])\r\na.append(a[n - 1])\r\nm = len(a)\r\nL = [0] * m\r\nR = [0] * m\r\nL[0] = 1\r\nfor i in range(1, n):\r\n if a[i] > a[i - 1]:\r\n L[i] = L[i - 1] + 1\r\n else:\r\n L[i] = 1\r\nR[n - 1] = 1\r\nfor i in range(n - 2, -1, -1):\r\n if a[i] < a[i + 1]:\r\n R[i] = R[i + 1] + 1\r\n else:\r\n R[i] = 1\r\nL[m - 2] = 0\r\nL[m - 1] = 0\r\nR[m - 2] = 0\r\nR[m - 1] = 0\r\nans = 1\r\nfor i in range(n):\r\n if a[i + 2] - a[i] > 1:\r\n ans = max(ans, L[i] + R[i + 2] + 1)\r\n else:\r\n ans = max(ans, L[i] + 1, R[i + 2] + 1)\r\nans = min(ans, n)\r\nprint(ans)", "length = int(input())\r\nnums = [int(num) for num in input().split()] + [float('inf'), float('-inf')]\r\n\r\n\r\nans = 0\r\nsmall = 0\r\nbig = 0\r\nfor i in range(length):\r\n if nums[i] > nums[i - 1]:\r\n small += 1\r\n big += 1\r\n else:\r\n ans = max(ans, small + 1, big)\r\n big = small + 1 if nums[i + 1] > nums[i - 1] + 1 or nums[i] > nums[i - 2] + 1 else 2\r\n small = 1 if nums[i + 1] > nums[i] else 0\r\n # print(i, small, big, ans)\r\nans = max(ans, big)\r\nprint(ans)", "n = int(input())\r\na = list(map(int, input().split()))\r\nl, r = [1] * n, [1] * n\r\nfor i in range(1, n):\r\n if(a[i] > a[i - 1]):\r\n l[i] = l[i - 1] + 1 \r\nfor i in range(n - 2, -1, -1):\r\n if(a[i] < a[i + 1]):\r\n r[i] = r[i + 1] + 1\r\nm = max(l) + 1 if max(l) < n else max(l)\r\nfor i in range(1, n - 1):\r\n if(a[i - 1] + 1 < a[i + 1]):\r\n m = max(m, l[i - 1] + r[i + 1] + 1)\r\nprint(m)", "import sys\r\n\r\ndef answer(n, a):\r\n if n == 1:\r\n return 1\r\n if n == 2:\r\n return 2\r\n\r\n lord = [0 for _ in range(n)]\r\n lord[0] = 1\r\n for i in range(1, n):\r\n if a[i] > a[i-1]:\r\n lord[i] = lord[i-1] + 1\r\n else:\r\n lord[i] = 1\r\n \r\n rord = [0 for _ in range(n)]\r\n rord[n-1] = 1\r\n for i in range(n-2, -1, -1):\r\n if a[i] < a[i+1]:\r\n rord[i] = rord[i+1] + 1\r\n else:\r\n rord[i] = 1\r\n rep = [0 for _ in range(n)]\r\n rep[0] = rord[1] + 1\r\n rep[n-1] = lord[n-2] + 1\r\n for i in range(1, n-1):\r\n rep[i] = max(lord[i-1] + 1, rord[i+1] + 1)\r\n if a[i-1] + 1 < a[i+1]:\r\n rep[i] = max(rep[i], lord[i-1] + rord[i+1] + 1)\r\n \r\n return max(rep)\r\n\r\ndef main():\r\n n = int(sys.stdin.readline())\r\n a = list(map(int, sys.stdin.readline().split()))\r\n print(answer(n, a))\r\n return\r\nmain()\r\n", "n = int(input())\r\narr = list(map(int, input().split()))\r\nleft, right = [1]*n, [1]*n\r\nleft[0] = 0\r\nfor i in range(2, n):\r\n if arr[i-1] > arr[i-2]:\r\n left[i] += left[i-1]\r\n\r\nright[-1] = 0\r\nfor i in range(n-3, -1, -1):\r\n if arr[i+1] < arr[i+2]:\r\n right[i] += right[i+1]\r\n\r\nans = 1\r\nfor i in range(n):\r\n if i-1 >= 0 and i+1 <= n-1:\r\n if arr[i+1] - arr[i-1] >= 2:\r\n ans = max(ans, left[i] + 1 + right[i])\r\n ans = max(ans, left[i] + 1, right[i] + 1)\r\nprint(ans)", "def ii(): return int(input())\r\ndef si(): return input()\r\ndef mi(): return map(int,input().split())\r\ndef msi(): return map(str,input().split())\r\ndef li(): return list(mi())\r\n\r\n\r\nn=ii()\r\na=li()\r\npre,suf = [1]*n,[1]*n\r\n\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n pre[i]+=pre[i-1]\r\n \r\nfor i in range(n-2,-1,-1):\r\n if a[i]<a[i+1]:\r\n suf[i]+=suf[i+1]\r\n \r\nans=max(pre)\r\nif ans<n:\r\n ans+=1\r\n\r\nfor i in range(1,n-1):\r\n if a[i+1]>a[i-1]+1:\r\n ans=max(ans,pre[i-1]+suf[i+1]+1)\r\n \r\nprint(ans)", "n=int(input())\r\na=list(map(int,input().split()))\r\n# a=[int(i/min(a)*10) for i in a]\r\n# print(*a)\r\nif n<=2:\r\n print(n)\r\n exit()\r\nends=[1]\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n ends.append(ends[i-1]+1)\r\n else:\r\n ends.append(1)\r\n\r\nstarts=[1]\r\nfor i in range(n-2,-1,-1):\r\n if a[i]<a[i+1]:\r\n starts.append(starts[-1]+1)\r\n else:\r\n starts.append(1)\r\nstarts.reverse()\r\n\r\nans=0\r\nfor i in range(1,n-1):\r\n if a[i-1]<a[i+1]-1:\r\n ans=max(ans,ends[i-1]+starts[i+1]+1)\r\n else:\r\n ans=max(ans,ends[i-1]+1,starts[i+1]+1)\r\nans=max(ans,starts[1]+1)\r\nans=max(ans,ends[n-2]+1)\r\nprint(ans)", "n = int(input())\r\na = list(map(int,input().split()))\r\nl,r = [1]*n,[1]*n\r\nfor i in range(1,n):\r\n if a[i-1]<a[i]: l[i]+=l[i-1]\r\nfor i in range(n-2,0,-1):\r\n if a[i+1]>a[i]: r[i]+=r[i+1]\r\nz = max(l)\r\nif z<n: z+=1\r\nfor i in range(1,n-1):\r\n if a[i-1]+1<a[i+1]: z=max(z,l[i-1]+r[i+1]+1)\r\nprint(z)", "#ff = open('input.txt')\r\n#for i in range(8):\r\nn = int(input())\r\n#n = int(ff.readline())\r\na = [int(x) for x in input().split()]\r\n#a = [int(x) for x in ff.readline().split()]\r\nvcnt = 1\r\nvpl = [0]\r\nvpr = []\r\nfor i in range(1, n):\r\n if (a[i - 1] >= a[i]):\r\n vcnt += 1\r\n vpr.append(i - 1)\r\n vpl.append(i)\r\n\r\nif len(vpl) > len(vpr):\r\n vpr.append(n - 1)\r\n\r\nmmax = 0\r\nfor i in range(vcnt):\r\n if vpr[i] - vpl[i] + 1 > mmax:\r\n mmax = vpr[i] - vpl[i] + 1 \r\n\r\nif mmax < len(a):\r\n mmax += 1\r\n\r\nmmax1 = 0;\r\nfor i in range(vcnt - 1):\r\n if (vpr[i] - vpl[i] > 0) and (vpr[i + 1] - vpl[i + 1] > 0):\r\n if (a[vpr[i] - 1] + 1 < a[vpl[i + 1]]) or (a[vpr[i]] < a[vpl[i + 1] + 1] - 1):\r\n mm = vpr[i] - vpl[i] + vpr[i + 1] - vpl[i + 1] + 2\r\n if mm > mmax1:\r\n mmax1 = mm\r\n\r\nif mmax1 > mmax:\r\n print(mmax1)\r\nelse:\r\n print(mmax)\r\n", "def solve():\n size = int(input())\n ls = list(map(int, input().rstrip().split()))\n dp0 = [1 for i in range(size)]\n dp1 = [1 for i in range(size)]\n for i in range(1, size):\n dp0[i] = dp0[i - 1] + 1 if (ls[i - 1] < ls[i]) else 1 \n for i in range(0, size - 1)[::-1]:\n dp1[i] = dp1[i + 1] + 1 if (ls[i + 1] > ls[i]) else 1\n best = max(max(dp0), max(dp1))\n for i in range(0, size):\n if i >= 1:\n best = max(best, dp0[i - 1] + 1)\n if i <= size - 2:\n best = max(best, dp1[i + 1] + 1)\n if i <= size - 2 and i >= 1:\n if ls[i - 1] + 1 < ls[i + 1]:\n best = max(best, dp0[i - 1] + dp1[i + 1] + 1)\n return best\n\nif __name__ == '__main__':\n print(solve())\n", "n=int(input())\r\nl=[0]+list(map(int,input().split()))+[0]\r\nfront=[0]*(n+2)\r\nlast=[0]*(n+2)\r\nfront[1]=1\r\nlast[n]=1\r\nfor i in range(2,n+1):\r\n if l[i-1]<l[i]:\r\n front[i]=front[i-1]+1\r\n else:\r\n front[i]=1\r\nfor i in range(n-1,0,-1):\r\n if l[i]<l[i+1]:\r\n last[i]=last[i+1]+1\r\n else:\r\n last[i]=1\r\nans=1\r\nfor i in range(1,n+1):\r\n if l[i-1]<l[i+1]-1:\r\n ans=max(ans,front[i-1]+last[i+1]+1)\r\n else:\r\n ans=max(ans,front[i-1]+1,last[i+1]+1)\r\nprint(ans)", "n = int(input())\narr = [int(x) for x in input().split(' ')]\naf=[0]*n\nab=[0]*n\nfor i in range(n):\n if(i==0 or arr[i]<=arr[i-1]):\n af[i]=1\n else:\n af[i]=af[i-1]+1\n\nfor i in range(n-1,-1,-1):\n if(i==n-1 or arr[i]>=arr[i+1]):\n ab[i]=1\n else:\n ab[i]=ab[i+1]+1\n\nans=0\nfor i in range(n):\n if(i==0):\n left=0\n else:\n left=af[i-1]\n if(i==n-1):\n right=0\n else:\n right=ab[i+1]\n if(left and right and arr[i-1]+2<=arr[i+1]):\n ans = max(ans,left+right+1)\n else:\n ans = max(ans,max(left,right)+1)\nprint(ans)", "import sys\r\ninput = sys.stdin.readline\r\nn = int(input())\r\na = list(map(int,input().split()))\r\na = [0] + a + [int(1e10)]\r\nl = [0 for _ in range(0,n+2)]\r\nr = [0 for _ in range(0,n+2)]\r\nans = 1\r\n\r\nfor i in range(1,n+1):\r\n if a[i] > a[i-1]:\r\n l[i] = l[i-1] + 1\r\n else:\r\n l[i] = 1\r\n \r\n ans = max(ans,l[i])\r\n\r\nfor i in range(n,0,-1):\r\n if a[i] < a[i+1]:\r\n r[i] = r[i+1] + 1\r\n else:\r\n r[i] = 1\r\n\r\nfor i in range(1,n+1):\r\n if a[i-1] + 1 < a[i+1]:\r\n ans = max(ans, l[i-1] + 1 + r[i+1])\r\n else:\r\n ans = max(ans, max(l[i-1]+1, 1+r[i+1]))\r\n\r\nprint(ans)", "n=int(input())\nl=list(map(int,input().split(\" \")))\na=[1]*n\nb=[1]*n\nfor i in range(1,n):\n\tif l[i]>l[i-1]:\n\t\ta[i]=a[i-1]+1\ni=n-2\nwhile(i>=0):\n\tif l[i+1]>l[i]:\n\t\tb[i]=b[i+1]+1\n\ti=i-1\ntotal=max(a)\nif total<n:\n\ttotal=total+1\nfor i in range(1,n-1):\n\tif l[i-1]+1<l[i+1]:\n\t\ttotal=max(total,a[i-1]+1+b[i+1])\n\telse:\n\t\ttotal=max(total,a[i-1]+1)\nprint(total)", "from sys import stdin,stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,input().split()))\r\nfor i in range(1):#nmbr()):\r\n n=nmbr()\r\n a=lst()\r\n if n==1:\r\n print(1)\r\n continue\r\n f=[1]*n\r\n b=[1]*(1+n)\r\n for i in range(1,n):\r\n if a[i]>a[i-1]:f[i]=1+f[i-1]\r\n for i in range(n-2,-1,-1):\r\n if a[i]<a[i+1]:b[i]=b[i+1]+1\r\n ans=min(n,max(f)+1)\r\n for i in range(n):\r\n if i-1>=0 and i+1<n and a[i-1]+2<=a[i+1]:\r\n ans=max(ans,f[i-1]+b[i+1]+1)\r\n # print(f)\r\n # print(b)\r\n print(ans)", "#very good solution i like this\r\ndef seq(arr):\r\n l=[1]*len(arr)\r\n r=[1]*len(arr)\r\n for i in range(1,len(arr)):\r\n if arr[i]>arr[i-1]:\r\n l[i]=l[i-1]+1\r\n for i in range(len(arr)-2,-1,-1):\r\n if arr[i]<arr[i+1]:\r\n r[i]=r[i+1]+1\r\n m=max(l)\r\n if m<len(arr):\r\n m+=1\r\n for i in range(1,len(arr)-1):\r\n if arr[i-1]+1<arr[i+1]:\r\n m=max(m,l[i-1]+r[i+1]+1) \r\n return m\r\na=input()\r\nlst=list(map(int,input().strip().split()))\r\nprint(seq(lst))", "n = int(input())\r\n\r\na = list(map(int, input().split()))\r\n\r\na = [-1] + a + [1000000007]\r\n\r\n#print(a)\r\nmaxi = 0\r\nup = [0 for i in range(n + 2)]\r\ndown = [0 for i in range(n + 2)]\r\n\r\nfor i in range(1, n + 1):\r\n up[i] = up[i - 1] + 1 if a[i] > a[i - 1] else 1\r\n \r\nfor i in range(n, 0, -1):\r\n down[i] = down[i + 1] + 1 if a[i] < a[i + 1] else 1\r\n \r\n#print(up, down)\r\n\r\n\r\nfor i in range(1, n + 1):\r\n maxi = max(maxi, up[i - 1] + (a[i - 1] + 1 < a[i + 1]) * down[i + 1] + 1)\r\n maxi = max(maxi, up[i - 1] * (a[i + 1] - 1 > a[i - 1]) + down[i + 1] + 1)\r\n \r\nprint(maxi)\r\n \r\n \r\n", "n = int(input())\r\na = list(map(int, input().split()))\r\na = [0] + a + [0]\r\n\r\npre = [0 for i in range(n+2)]\r\npre[1] = 1\r\nfor i in range(2, n+1):\r\n pre[i] = (pre[i-1] + 1) if a[i] > a[i-1] else 1\r\n\r\nsuf = [0 for i in range(n+2)]\r\nsuf[n] = 1\r\nfor i in range(n-1, 0, -1):\r\n suf[i] = (suf[i+1] + 1) if a[i] < a[i+1] else 1\r\n\r\nsol = 0\r\nfor i in range(1, n+1):\r\n curr = max(pre[i-1], suf[i+1]) + 1\r\n \r\n if a[i-1] + 1 < a[i+1]:\r\n curr = max(curr, pre[i-1] + suf[i+1] + 1)\r\n sol = max(sol, curr)\r\n\r\nprint(sol)", "n=int(input())\r\nAr=[int(0)]*(n+5)\r\nA=[int(0)]*(n+5)\r\ni=1\r\nres=0\r\nfor x in input().split():\r\n Ar[i]=int(x)\r\n A[i]=1\r\n if Ar[i]>Ar[i-1]:\r\n A[i]=A[i-1]+1\r\n i+=1\r\nfor i in range(1,n+1):\r\n res=max(res,min(A[i]+1,n))\r\n if Ar[i-A[i]+1]>(Ar[i-A[i]-1]+1) :\r\n res=max(res,A[i]+A[i-A[i]])\r\n# print(i,A[i])\r\n if Ar[i-A[i]+2]>(Ar[i-A[i]]+1) :\r\n res=max(res,A[i]+A[i-A[i]])\r\nprint(res)", "n = int(input())\r\narr = list(map(int,input().split()))\r\npre = [0 for i in range(n)]\r\npre[-1] = 1\r\nfor i in range(n-2,-1,-1):\r\n\tif arr[i+1]>arr[i]:\r\n\t\tpre[i] = pre[i+1]+1\r\n\telse:\r\n\t\tpre[i] = 1\r\nans = 0\r\nfor i in range(n):\r\n\tlast1 = arr[i+pre[i]-1]\r\n\tans = max(ans,pre[i])\r\n\tif pre[i]==1:\r\n\t\tif i+1<n:\r\n\t\t\tans = max(ans,pre[i+1]+1)\r\n\telif i+pre[i]<n:\r\n\t\tif arr[i+pre[i]]>last1:\r\n\t\t\tans = max(ans,pre[i]+pre[i+pre[i]])\r\n\t\telse:\r\n\t\t\tif pre[i+pre[i]]==1:\r\n\t\t\t\tans = max(ans,pre[i]+1)\r\n\t\t\telse:\r\n\t\t\t\tif arr[i+pre[i]+1]-last1>=2:\r\n\t\t\t\t\tans = max(ans,pre[i]+pre[i+pre[i]])\r\n\t\t\t\tif last1+1>=arr[i+pre[i]+1]:\r\n\t\t\t\t\tans = max(ans,pre[i]+1)\r\n\t\t\t\tif arr[i+pre[i]]-arr[i+pre[i]-2]>=2:\r\n\t\t\t\t\tans = max(ans,pre[i]+pre[i+pre[i]])\r\nprint(ans)", "n = int(input())\na = list(map(int, input().split())) + [0]\ns, sb, val = [], 0, 0\nfor i in range(1, n + 1):\n if a[i] <= a[i - 1]:\n s.append((sb, i - 1))\n val = max(val, i - sb)\n sb = i\nval += len(s) > 1\nfor i in range(1, len(s)):\n c = s[i][0]\n if c in range(2, n - 1) and max(a[c] - a[c - 2], a[c + 1] - a[c - 1]) >= 2:\n val = max(val, s[i][1] - s[i - 1][0] + 1)\nprint(val)\n", "# cook your dish here\r\nfrom collections import deque, defaultdict\r\nfrom math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd\r\nimport bisect\r\nimport sys\r\nimport copy\r\n\r\n\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\n\r\n\r\ndef input(): return sys.stdin.readline().strip()\r\n\r\nn=int(input())\r\ndp=[1]*n\r\ndp1=[1]*n\r\na=get_array()\r\nmaxi=1\r\nmax_li=(10**9)\r\nfor i in range(1,n):\r\n if a[i-1]<a[i]:\r\n dp[i]=dp[i-1]+1\r\nfor i in range(n-2,-1,-1):\r\n if a[i+1]>a[i]:\r\n dp1[i]=dp1[i+1]+1\r\nmaxi=max(maxi,min(n,max(max(dp),max(dp1))+1))\r\nfor i in range(1,n-1):\r\n ele=a[i+1]-1\r\n if ele>a[i-1]:\r\n maxi=max(maxi,1+dp[i-1]+dp1[i+1])\r\n\r\nprint(maxi)", "n = int(input())\r\na = [int(i) for i in input().split()]\r\nl,r = [1]*n,[1]*n\r\n\r\nfor i in range(1,n):\r\n if a[i-1]<a[i]: l[i]+=l[i-1]\r\n\r\nfor i in range(n-2,0,-1):\r\n if a[i+1]>a[i]: r[i]+=r[i+1]\r\n\r\nans = max(l)\r\nif ans<n: ans+=1\r\nfor i in range(1,n-1):\r\n if a[i-1]+1<a[i+1]: ans=max(ans,l[i-1]+r[i+1]+1)\r\nprint(ans)", "import sys\r\n\r\ndef inputArray():\r\n tp=str(input()).split();\r\n return list(map( int , tp));\r\n\r\nif( __name__==\"__main__\"):\r\n n=int(input());\r\n input=inputArray();\r\n\r\n if(n==1):\r\n print(\"1\");\r\n sys.exit();\r\n\r\n left=[1 for x in range(n)];\r\n right=[1 for x in range(n) ];\r\n\r\n for i in range(1,n,1): \r\n if( input[i-1] < input[i]):\r\n left[i]=left[i-1]+1;\r\n \r\n for i in range(n-2,-1,-1):\r\n if( input[i] < input[i+1]):\r\n right[i]=right[i+1]+1;\r\n\r\n ans=1;\r\n\r\n for i in range(n):\r\n if(i==0):\r\n #Make curr smaller than `right one\r\n ans=max(ans , right[i+1]+1);\r\n continue;\r\n\r\n if(i==n-1 ):\r\n ans=max(ans, left[i-1]+1);\r\n continue;\r\n\r\n ans=max(ans , right[i+1] +1 );\r\n ans=max(ans ,left[i-1]+1);\r\n\r\n if( input[i+1]-input[i-1] >=2):\r\n ans=max(ans , left[i-1]+1+right[i+1]);\r\n\r\n print(ans);\r\n\r\n", "n = int(input())\r\nseq = [int(n) for n in input().split()]\r\ndp = [0 for n in range(n+1)]\r\nfor j in range(0, n):\r\n if(seq[j] > seq[j-1]):\r\n dp[j] = (dp[j-1] + 1)\r\n else:\r\n dp[j] = 1\r\nseq.append(0)\r\n\r\nm = 0\r\nx = 0\r\nfor i in range(n-1, -1, -1):\r\n m = max(m, dp[i-1] + 1, x + 1)\r\n if(i == 0 or i == n-1 or seq[i-1] + 1 < seq[i+1]):\r\n m = max(m, dp[i-1] + x + 1)\r\n \r\n if(seq[i] < seq[i+1]):\r\n x += 1\r\n else:\r\n x = 1\r\n \r\nprint(m)", "\"\"\"\r\nRead DP Solution....going to code different solution which utilizes precomputation\r\n\"\"\"\r\nfrom sys import stdin\r\ninput = stdin.readline\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nif n <= 2:\r\n print(n)\r\nelse:\r\n curr = [a[0]]; prev = a[0]; segments = []\r\n for i in range(1, n):\r\n if a[i] > prev:\r\n curr.append(a[i])\r\n else:\r\n segments.append(curr)\r\n curr = [a[i]]\r\n prev = a[i]\r\n segments.append(curr)\r\n\r\n curr_seg = 0; seg_ind = 0; global_ind = 0; endings = [1 for i in range(n)]; startings = [1 for i in range(n)]\r\n while global_ind < n:\r\n startings[global_ind] = len(segments[curr_seg]) - seg_ind\r\n endings[global_ind] = seg_ind + 1\r\n seg_ind += 1; global_ind += 1\r\n if seg_ind == len(segments[curr_seg]): \r\n seg_ind = 0; curr_seg += 1\r\n\r\n def get_startings(i: int):\r\n if 0 <= i < len(startings): return startings[i]\r\n return 0\r\n\r\n def get_endings(i: int):\r\n if 0 <= i < len(endings): return endings[i]\r\n return 0\r\n\r\n ans = 2\r\n for i in range(n):\r\n curr1 = 1; curr2 = 1;\r\n #case 1. a[i] = a[i - 1] + 1 ...\r\n try: \r\n if a[i - 1] + 1 > a[i - 1]: curr1 += get_endings(i - 1)\r\n except: pass\r\n try:\r\n if a[i - 1] + 1 < a[i + 1]: curr1 += get_startings(i + 1)\r\n except: pass\r\n\r\n #case 2. a[i] = a[i + 1] - 1 ...\r\n try:\r\n if a[i + 1] - 1 > a[i - 1]: curr2 += get_endings(i - 1)\r\n except: pass\r\n try:\r\n if a[i + 1] - 1 < a[i + 1]: curr2 += get_startings(i + 1)\r\n except: pass\r\n\r\n ans = max(ans, curr1, curr2)\r\n\r\n print(ans)\r\n \r\n \r\n \r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n", "'''\r\n Auther: ghoshashis545 Ashis Ghosh\r\n College: jalpaiguri Govt Enggineerin College\r\n Date:06/05/2020\r\n\r\n'''\r\nfrom collections import deque\r\nfrom bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right\r\nfrom itertools import permutations\r\nfrom datetime import datetime\r\nfrom math import ceil,sqrt,log,gcd\r\ndef ii():return int(input())\r\ndef si():return input()\r\ndef mi():return map(int,input().split())\r\ndef li():return list(mi())\r\n\r\n\r\nabc='abcdefghijklmnopqrstuvwxyz'\r\nabd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}\r\nmod=1000000007\r\n#mod=998244353\r\ninf = float(\"inf\")\r\nvow=['a','e','i','o','u']\r\ndx,dy=[-1,1,0,0],[0,0,1,-1]\r\n\r\n\r\n\r\n \r\ndef solve():\r\n \r\n n=ii()\r\n a=li()\r\n pre=[1]*n\r\n\r\n suf=[1]*n \r\n ans=2\r\n for i in range(1,n):\r\n if(a[i]>a[i-1]):\r\n pre[i]=pre[i-1]+1\r\n ans=max(ans,pre[i])\r\n \r\n for i in range(n-2,-1,-1):\r\n if(a[i]<a[i+1]):\r\n suf[i]=suf[i+1]+1\r\n \r\n ans=max(ans,pre[i])\r\n \r\n for i in range(1,n-1):\r\n x=a[i+1]-a[i-1]\r\n if(x>1):\r\n ans=max(ans,1+pre[i-1]+suf[i+1])\r\n ans=max(ans,1+pre[i])\r\n ans=max(ans,1+suf[i])\r\n print(min(ans,n))\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\nif __name__== \"__main__\":\r\n solve()", "n=int(input())\r\na=[0]+list(map(int,input().split()))+[0]\r\nl=[]\r\nst=1\r\nfor i in range(2,n+2):\r\n if a[i]<=a[i-1]:\r\n l.append([st,i-1])\r\n st=i\r\n\r\n\r\nif len(l)==1:\r\n print(n)\r\n exit()\r\nmx=0\r\nfor i in range(1,len(l)):\r\n lf=l[i-1][1]\r\n rt=l[i][0]\r\n ln1=l[i][1]-l[i][0]+1\r\n ln2=l[i-1][1]-l[i-1][0]+1\r\n if a[rt+1]-a[lf]>1 or a[rt]-a[lf-1]>1:\r\n tm=ln1+ln2\r\n else:\r\n tm=max(ln1,ln2)+1\r\n mx=max(mx,tm)\r\nprint(mx)\r\n", "#!/usr/bin/env python3\nimport sys\n\nn = int(input())\n\na = list( map(int,input().split( )))\n\na = [-1] + a + [10000007]\n\n\nup = [0 for i in range(n+2)]\ndown = [0 for i in range (n+2)]\n\n\nfor i in range(1,n+1):\n up[i] = up[i-1]+1 if (a[i]>a[i-1])else 1\n\nfor i in range(n,0,-1):\n down[i] = down[i+1]+1 if(a[i]<a[i+1])else 1\n\n\n#print (up,down)\n\nmaxi=0\nfor i in range(1,n+1):\n maxi = max( maxi,up[i-1]+(a[i-1]+1<a[i+1])*down[i+1]+1)\n maxi = max(maxi,up[i-1]*(a[i-1]+1<a[i+1])+down[i+1]+1)\n\nprint (maxi)\n", "n=int(input())\r\na=list(map(int,input().split()))\r\nl=[1]*n\r\nr=[1]*n\r\nfor i in range(1,n):\r\n if(a[i]>a[i-1]):\r\n l[i]=l[i-1]+1\r\nfor i in range(n-2,-1,-1):\r\n if(a[i]<a[i+1]):\r\n r[i]=r[i+1]+1\r\nm=max(l)\r\nif(m<n):\r\n m=m+1\r\nfor i in range(1,n-1):\r\n if(a[i-1]+1<a[i+1]):\r\n m=max(m,l[i-1]+r[i+1]+1)\r\nprint(m)\r\n \r\n \r\n ", "\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nl=[1]\r\nr=[1]\r\nfor i in range(1,n):\r\n if a[i]>a[i-1]:\r\n l.append(l[-1]+1)\r\n else:\r\n l.append(1)\r\nfor i in range(n-2,-1,-1):\r\n if a[i]<a[i+1]:\r\n r.append(r[-1]+1)\r\n else :\r\n r.append(1)\r\nr=r[::-1]\r\nmx=max(max(l),max(r))\r\nif mx!=n:\r\n mx+=1\r\nfor i in range(1,n-1):\r\n if a[i-1]+2<=a[i+1]:\r\n mx=max(mx,1+l[i-1]+r[i+1])\r\nprint(mx)", "import sys\r\n\r\nn = int(input())\r\ns = list(map(int, input().split()))\r\na = [0] * n\r\nb = [0] * n\r\na[0] = 1\r\nb[0] = 1\r\n\r\nif n == 1:\r\n print(1)\r\n sys.exit()\r\n\r\nfor i in range(1, n):\r\n if s[i] > s[i-1]:\r\n a[i] = a[i-1] + 1\r\n else:\r\n a[i] = 1\r\n\r\ns = s[::-1]\r\nfor i in range(1, n):\r\n if s[i] < s[i-1]:\r\n b[i] = b[i-1] + 1\r\n else:\r\n b[i] = 1\r\n\r\ns = s[::-1]\r\nb = b[::-1]\r\nans = b[1] + 1\r\nfor i in range(1, n - 1):\r\n if s[i-1] + 1 < s[i + 1]:\r\n ans = max(ans, a[i - 1] + 1 + b[i + 1])\r\n else:\r\n ans = max(ans, a[i - 1] + 1, 1 + b[i + 1])\r\nans = max(ans, a[n - 2] + 1)\r\n\r\nprint(ans)", "sequenceLength = int(input())\r\nsequence = list(map(int, input().split()))\r\n\r\nans = 0\r\nleftList = [1] * sequenceLength\r\nrightlist = [1] * sequenceLength\r\n\r\nfor i in range(1, sequenceLength):\r\n if sequence[i - 1] < sequence[i]:\r\n leftList[i] += leftList[i-1]\r\n\r\n ans = max(ans, leftList[i])\r\n\r\nif ans < sequenceLength:\r\n ans += 1\r\n\r\nfor i in range(sequenceLength - 2, 0, -1):\r\n if sequence[i + 1] > sequence[i]:\r\n rightlist[i] += rightlist[i + 1]\r\n\r\nfor i in range(1, sequenceLength - 1):\r\n if sequence[i+1] - sequence[i-1] >= 2:\r\n ans = max(ans, leftList[i - 1] + 1 + rightlist[i + 1])\r\n\r\nprint(ans)", "n = int(input())\na = list(map(int, input().split()))\n\nINF = 10 ** 9\n\ndp = [[-INF] * 3 for i in range(n)]\nfor i in range(n):\n dp[i][0] = dp[i][2] = 1\n if i > 0:\n dp[i][1] = 2\n\n\ndef upd(i, cr, nx):\n dp[i + 1][nx] = max(dp[i + 1][nx], dp[i][cr] + 1)\n\n\nfor i in range(n - 1):\n for j in range(3):\n cur = dp[i][j]\n\n if j == 0:\n if a[i + 1] > a[i]:\n upd(i, j, 0)\n upd(i, j, 2)\n else:\n upd(i, j, 2)\n elif j == 1:\n if a[i + 1] > a[i]:\n upd(i, j, 1)\n else:\n if i > 0 and a[i + 1] > a[i - 1] + 1:\n upd(i, j, 1)\n\n\nans = 0\nfor i in range(n):\n ans = max(ans, max(dp[i]))\n\nprint(ans)\n", "def main():\n\tn = int(input())\n\t\n\ta = [10 ** 10] + list(map(int, input().split())) + [-(10 ** 10)]\n\tif n == 1:\n\t\tprint(1)\n\t\texit()\n\tb = [0] * (n + 10)\n\tc = [0] * (n + 10)\n\t#print(a, b, c)\n\ti = 1\n\twhile i <= n:\n\t\tfor j in range(i, n+1):\n\t\t\tif a[j] >= a[j+1]:\n\t\t\t\tbreak\n\t\tfor k in range(i, j+1):\n\t\t\tb[k] = i\n\t\t\tc[k] = j\n\t\ti = j + 1\n\t#print(c,b)\n\tans = max(c[2], n - b[n-1] + 1, c[1], n - b[n] + 1)\n\tfor i in range(2, n):\n\t\tans = max(ans, c[i] - i + 2, i - b[i] + 2)\n\t\tif a[i - 1]+ 1 < a[i+1]:\n\t\t\tans = max(ans, c[i+1] - b[i-1] + 1)\n\tprint(ans)\n\n\nif __name__ == '__main__':\n\tmain()\n" ]
{"inputs": ["6\n7 2 3 1 5 6", "10\n424238336 649760493 681692778 714636916 719885387 804289384 846930887 957747794 596516650 189641422", "50\n804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 350490028 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737 35005212 521595369 294702568 726956430 336465783 861021531 59961394 89018457 101513930 125898168 131176230 145174068 233665124 278722863 315634023 369133070 468703136 628175012 635723059 653377374 656478043 801979803 859484422 914544920 608413785 756898538 734575199 973594325 149798316 38664371", "1\n1", "2\n1000000000 1000000000", "5\n1 2 3 4 1", "10\n1 2 3 4 5 5 6 7 8 9", "5\n1 1 1 1 1", "5\n1 1 2 3 4", "5\n1 2 3 1 6", "1\n42", "5\n1 2 42 3 4", "5\n1 5 9 6 10", "5\n5 2 3 4 5", "3\n2 1 3", "5\n1 2 3 3 4", "8\n1 2 3 4 1 5 6 7", "1\n3", "3\n5 1 2", "4\n1 4 3 4", "6\n7 2 12 4 5 6", "6\n7 2 3 1 4 5", "6\n2 3 5 5 6 7", "5\n2 4 7 6 8", "3\n3 1 2", "3\n1 1 2", "2\n1 2", "5\n4 1 2 3 4", "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6", "4\n1 2 1 3", "4\n4 3 1 2", "6\n1 2 2 3 4 5", "4\n1 1 1 2", "4\n5 1 2 3", "5\n9 1 2 3 4", "2\n1 1", "5\n1 3 2 4 5", "6\n1 2 1 2 4 5", "10\n1 1 5 3 2 9 9 7 7 6", "6\n1 2 3 100000 100 101", "4\n3 3 3 4", "3\n4 3 5", "5\n1 3 2 3 4", "10\n1 2 3 4 5 10 10 11 12 13", "7\n11 2 1 2 13 4 14", "3\n5 1 3", "4\n1 5 3 4", "10\n1 2 3 4 100 6 7 8 9 10", "3\n5 3 5", "5\n100 100 7 8 9", "5\n1 2 3 4 5", "5\n1 2 4 4 5", "6\n7 4 5 6 7 8", "9\n3 4 1 6 3 4 5 6 7", "3\n1000 1 2", "3\n20 1 9", "6\n7 2 3 1 4 6", "3\n100 5 10", "4\n2 2 2 3", "6\n4 2 8 1 2 5", "3\n25 1 6", "10\n17 99 23 72 78 36 5 43 95 9", "7\n21 16 22 21 11 13 19", "5\n1 2 5 3 4", "6\n2 2 2 3 4 5", "5\n1 3 1 2 3", "3\n81 33 64", "7\n14 3 3 19 13 19 15", "9\n1 2 3 4 5 42 7 8 9", "5\n2 3 7 5 6", "5\n1 3 3 4 5", "6\n1 5 4 3 4 5"], "outputs": ["5", "9", "19", "1", "2", "5", "6", "2", "5", "5", "1", "4", "4", "5", "3", "4", "5", "1", "3", "4", "5", "4", "6", "5", "3", "3", "2", "5", "7", "3", "3", "5", "3", "4", "5", "2", "4", "5", "3", "6", "3", "3", "4", "10", "5", "3", "4", "10", "3", "4", "5", "5", "6", "7", "3", "3", "4", "3", "3", "4", "3", "5", "4", "4", "5", "4", "3", "4", "9", "5", "5", "4"]}
UNKNOWN
PYTHON3
CODEFORCES
59
21981a6dd776117fe98a2f0d77c136c9
Average Sleep Time
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last *n* days. So now he has a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the sleep time on the *i*-th day. The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider *k* consecutive days as a week. So there will be *n*<=-<=*k*<=+<=1 weeks to take into consideration. For example, if *k*<==<=2, *n*<==<=3 and *a*<==<=[3,<=4,<=7], then the result is . You should write a program which will calculate average sleep times of Polycarp over all weeks. The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). Output average sleeping time over all weeks. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point. Sample Input 3 2 3 4 7 1 1 10 8 2 1 2 4 100000 123 456 789 1 Sample Output 9.0000000000 10.0000000000 28964.2857142857
[ "n, k = map(int, input().split(' '))\na = list(map(int, input().split(' ')))\n\ntot = 0\nfor i in range(k):\n tot += a[i]\n\nans = tot\nfor i in range(k, n):\n tot += a[i]\n tot -= a[i - k]\n ans += tot\n\nprint(ans / (n - k + 1))\n\n \t \t\t\t\t\t \t \t\t\t\t\t \t\t \t\t \t \t\t\t", "from sys import stdin\r\na,b=map(int,stdin.readline().split())\r\nc=list(map(int,stdin.readline().split()))\r\ns=sum(c[:b]);k=s\r\nfor i in range(1,a-b+1):k=k-c[i-1]+c[i+b-1];s+=k\r\nprint((s)/(a-b+1))", "##n = int(input())\r\n##a = list(map(int, input().split()))\r\n##print(' '.join(map(str, res)))\r\n\r\n[n, k] = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n\r\nsum = 0\r\nfor i in range(k):\r\n sum += a[i]\r\ntot = sum;\r\nfor i in range(n-k):\r\n sum -= a[i]\r\n sum += a[i+k]\r\n tot += sum \r\ntot /= n-k+1\r\nprint(tot)", "n, k = map(int, input().split())\r\nactivities = list(map(int, input().split()))\r\n\r\ncumulative_sum = [0] * (n + 1)\r\nfor i in range(n):\r\n cumulative_sum[i + 1] = cumulative_sum[i] + activities[i]\r\n\r\n\r\ntotal_time = 0.0\r\n\r\n\r\nfor i in range(k, n + 1):\r\n week_time = cumulative_sum[i] - cumulative_sum[i - k]\r\n total_time += week_time\r\n\r\n\r\naverage_time = total_time / (n - k + 1)\r\n\r\nprint(\"{:.10f}\".format(average_time))\r\n", "n,k = map(int, input().split())\n\nvalues = list(map(int, input().split()))\ntotal = sum(values[:k])\n\nhours = total\nfor i in range(k,n):\n total += values[i] - values[i-k]\n hours += total\n\nprint(\"%.6f\" % (hours/(n-k+1)))\n\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\ntotal = 0\r\nweek = 0\r\n\r\nfor i in range(0, k):\r\n week+=a[i]\r\n\r\ntotal += week\r\n\r\nfor i in range(1, n-k+1):\r\n week-=a[i-1]\r\n week+=a[i+k-1]\r\n total += week\r\nprint(total / (n-k+1))\r\n", "(n, k) = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nS = sum(A[:k])\r\noper = S\r\nfor i in range(n-k):\r\n oper -= A[i]\r\n oper += A[i+k]\r\n S += oper\r\n#if n != 1:\r\n# print(str((sum(S) / (n-k+1))*2)[:-2])\r\n#else:\r\nprint(S / (n-k+1))", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\ntotal = sum(a[:k])\r\nans = total\r\nfor i in range(k, n):\r\n total += a[i]\r\n total -= a[i-k]\r\n ans += total\r\n\r\nprint(ans / (n-k+1))\r\n", "n,k = map(int,input().split())\r\na=list(map(int,input().split()))\r\nsum=0\r\nfor i in range(k):\r\n sum+=a[i]\r\ntotal = sum \r\ni=1\r\nwhile(i+k-1 < n):\r\n sum-=a[i-1]\r\n sum+=a[i+k-1]\r\n i+=1\r\n total+=sum\r\nprint(format(total/(n-k+1),'.6f'))", "\r\n\r\ndienu_sk, ned_len = [int(x) for x in input().split()]\r\n\r\nned_sk = dienu_sk-ned_len+1\r\n\r\narr = [int(x) for x in input().split()]\r\n\r\n\r\n\r\nsumma=0\r\ncur_summa=0\r\nfor i in range(ned_len): cur_summa+=arr[i]\r\nsumma=cur_summa\r\n\r\n\r\nprev=0\r\nnext=ned_len\r\n\r\nwhile(next<dienu_sk):\r\n cur_summa-=arr[prev]\r\n cur_summa+=arr[next]\r\n summa+=cur_summa\r\n prev+=1\r\n next+=1\r\n\r\n\r\nrez = summa/ned_sk\r\n\r\n#print(\"rez := %.6f\" %(rez) )\r\nprint(\"%.6f\" %(rez) )\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\n\r\nstart=min(k-1,n-k)\r\ncount=sum(a[start:n-start])*(start+1)\r\nfor i in range(start):\r\n\tcount+=(a[i]+a[~i])*(i+1)\r\nprint(count/(n-k+1))", "n, k = map(int, input().split())\naa = list(map(int, input().split()))\nres, t = sum(aa) * k, 0\nfor a, b in zip(aa[:k - 1], aa[-1:-k:-1]):\n t += a + b\n res -= t\nprint(res / (n - k + 1))", "arr = list(map(int, input().split()))\r\nn=arr[0]\r\nk=arr[1]\r\na= list(map(int, input().split()))\r\nts=0\r\nfor i in range(k):\r\n ts+=a[i]\r\ni=1\r\nj=k\r\ns=ts\r\nwhile(j<n):\r\n ts-=a[i-1]\r\n ts+=a[j]\r\n s+=ts\r\n i+=1\r\n j+=1\r\nprint(s/(n-k+1))", "n,k=map(int,input().split())\r\nans=0\r\na=list(map(int,input().split()))\r\ns=sum(a[:k])\r\nt=s\r\nfor i in range(1,1+n-k):\r\n s-=a[i-1]\r\n s+=a[i+k-1]\r\n t+=s\r\nprint(t/(1+n-k))\r\n", "import sys\nsys.setrecursionlimit(10000)\n# default is 1000 in python\n\n# increase stack size as well (for hackerrank)\n# import resource\n# resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY))\n\n\n# t = int(input())\nt = 1\n\nfor _ in range(t):\n\t# n = int(input())\n\n\tn, k = list(map(int, input().split()))\n\n\ta = list(map(int, input().split()))\n\n\tans = 0\n\tfor i in range(k):\n\t\tans += a[i]\n\t\t# print(ans)\n\tthesum = ans\n\n\tfor j in range(k, n):\n\t\tthesum -= a[j-k]\n\t\tthesum += a[j]\n\t\tans += thesum\n\n\tprint(ans/(n-k+1))\n\n# try:\n\t# raise Exception\n# except:\n\t# print(\"-1\")\n\n\n# from itertools import combinations \n# all_combs = list(combinations(range(N), r))\n\n\n\n# from collections import OrderedDict \n# mydict = OrderedDict() \n\n\n# thenos.sort(key=lambda x: x[2], reverse=True)\n\n\n# int(math.log(max(numbers)+1,2))\n\n\n# 2**3 (power)\n\n\n# a,t = (list(x) for x in zip(*sorted(zip(a, t))))\n\n\n# to copy lists use:\n# import copy\n# copy.deepcopy(listname)\n\n# pow(p, si, 1000000007) for modular exponentiation\n\n\n# my_dict.pop('key', None)\n# This will return my_dict[key] if key exists in the dictionary, and None otherwise.\n\n\n# bin(int('010101', 2))\n\n# Binary Search\n# from bisect import bisect_right\n# i = bisect_right(a, ins)\n", "#Bhargey Mehta (Sophomore)\r\n#DA-IICT, Gandhinagar\r\nimport sys, math, queue\r\n#sys.stdin = open(\"input.txt\", \"r\")\r\nMOD = 10**9+7\r\nsys.setrecursionlimit(1000000)\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 0\r\ns = sum(a[:k-1])\r\nfor i in range(k-1, n):\r\n s += a[i]\r\n ans += s\r\n s -= a[i-k+1]\r\nprint(ans/(n-k+1))", "# testCase = int(input())\r\n\r\n\r\n\r\n# for i in range(testCase):\r\n\r\n# QueueLeft=[]\r\n# QueueRight=[]\r\n# countSwitch=0\r\n\r\n# capacityWood,transaction= map(int,input().split())\r\n\r\n \r\n# #print(capacityWood,transaction)\r\n\r\n# capacityWood = capacityWood * 100\r\n\r\n# capacityWood1=capacityWood\r\n\r\n# for sw in range(transaction):\r\n\r\n \r\n# lengthCar,direction = map(str,input().split())\r\n\r\n# lengthCar = int(lengthCar)\r\n\r\n# if(direction==\"left\"):\r\n# QueueLeft.append(lengthCar)\r\n# else:\r\n# QueueRight.append(lengthCar)\r\n \r\n \r\n \r\n# tempQL=len(QueueLeft)\r\n# tempQR=len(QueueRight)\r\n \r\n \r\n# while(len(QueueLeft)!=0 or len(QueueRight)!=0 ):\r\n\r\n \r\n \r\n# while(len(QueueLeft)!=0):\r\n \r\n# firstCar = QueueLeft[0]\r\n \r\n \r\n# if(firstCar<=capacityWood):\r\n# capacityWood-=firstCar\r\n# QueueLeft.pop(0)\r\n \r\n \r\n# if(len(QueueLeft)==0):\r\n# countSwitch+=1\r\n# break\r\n# else:\r\n# countSwitch+=1\r\n# capacityWood = capacityWood1\r\n \r\n \r\n \r\n\r\n# capacityWood = capacityWood1\r\n \r\n# while(len(QueueRight)!=0):\r\n \r\n# firstCar = QueueRight[0]\r\n# #380-2000\r\n# #1620\r\n \r\n# if(firstCar<=capacityWood):\r\n# capacityWood-=firstCar\r\n# QueueRight.pop(0)\r\n\r\n \r\n# if(len(QueueRight)==0):\r\n# countSwitch+=1\r\n \r\n# break\r\n# else:\r\n# countSwitch+=1\r\n# capacityWood = capacityWood1\r\n \r\n \r\n \r\n \r\n \r\n# if(tempQL==0):\r\n# countSwitch*=2\r\n# elif(tempQR==0):\r\n# countSwitch*=2\r\n# countSwitch-=1\r\n \r\n \r\n# print(countSwitch)\r\n\r\n \r\n \r\nn,k = map(int,input().split())\r\n \r\navgTimeSleep=0\r\n\r\narrayPrefix =[0]*(n+1)\r\narray = list(map(int,input().split()))\r\n\r\nfor i in range(1,n+1):\r\n\r\n arrayPrefix[i] = array[i-1] + arrayPrefix[i-1]\r\n\r\n\r\n\r\navgTimeSleep = arrayPrefix[k]\r\n\r\n\r\nfor i in range(k+1,n+1):\r\n\r\n avgTimeSleep += (arrayPrefix[i]-arrayPrefix[i-k]) \r\n \r\n \r\n\r\n\r\n\r\n\r\nprint(\"%.10f\" % (avgTimeSleep/(n-k+1)))\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n ", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\ntmp = sum(a[:k])\r\ni = k\r\ns = tmp\r\nwhile i < n:\r\n tmp += a[i] - a[i - k]\r\n s += tmp\r\n i += 1\r\n\r\nprint(s / (n - k + 1))\r\n\r\n", "n, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nr, s, x = n-k+1, 0, []\r\nx.append(a[0])\r\nfor i in range(1, n+1):\r\n x.append(x[i-1] + a[i-1])\r\nfor i in range(k, n+1):\r\n s += x[i] - x[i-k]\r\nprint(s/r)\r\n", "x = input()\r\na,b = x.split()\r\nn = int(a)\r\nk = int(b)\r\nx = input()\r\nx = x.split()\r\nfor i in range(0,n):\r\n x[i] = int(x[i])\r\nans = 0\r\nl,r = 0,n-1\r\ntim = 1\r\nmon = n-k+1\r\nwhile l <= r:\r\n if l == r:\r\n ans += x[l] * tim\r\n break\r\n else:\r\n ans += (x[l]+x[r])*tim\r\n l += 1\r\n r -= 1\r\n if tim < min(mon,k):\r\n tim += 1\r\nprint(ans/mon)", "n,m=map(int,input().split())\r\nsu=0\r\nsu1=0\r\nl=list(map(int,input().split()))\r\nfor i in range(min(n,m)) :\r\n su+=l[i]\r\n su1=su\r\nj=0\r\n\r\nfor i in range(min(n,m),n) :\r\n su+=l[i]-l[j]\r\n j+=1\r\n su1+=su\r\nprint(su1/(j+1))\r\n \r\n \r\n \r\n \r\n", "import sys\r\nfrom itertools import accumulate\r\n\r\nn, k = map(int, input().split())\r\na = [0] + list(accumulate(map(int, input().split())))\r\ntotal = 0\r\nfor l, r in zip(range(n), range(k, n+1)):\r\n total += a[r] - a[l]\r\n\r\nprint(total / (n - k + 1))\r\n", "# LUOGU_RID: 119829065\nn, m = map(int, input().split())\na = list(map(int, input().split()))\n\nfor i in range(1, n):\n a[i] += a[i - 1]\n\nsum_val = 0\nk = n - m + 1\n\nfor i in range(k):\n sum_val += (a[i + m - 1] - a[i - 1]) if i > 0 else a[i + m - 1]\n\naverage = sum_val / k\nprint(\"{:.10f}\".format(average))\n", "n,k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nfrom itertools import accumulate\r\nC = [0]+A\r\nC = list(accumulate(C))\r\nans = 0\r\nfor i in range(n-k+1):\r\n s = C[i+k]-C[i]\r\n ans += s\r\nprint(ans/(n-k+1))\r\n", "n, k = (int(x) for x in input().split())\na = [int(x) for x in input().split()]\n\ns = [0] * (n + 1)\n\nfor i in range(n):\n s[i + 1] = s[i] + a[i]\n\nt = 0\n\nfor i in range(k, n + 1):\n t += s[i] - s[i - k]\n\nprint(t / (n - k + 1))\n\n", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=0\r\nz=n-k+1\r\nfor i in range(n):\r\n s+=a[i]*min(z,k,i+1,n-i)\r\nprint(s/(z))", "n,k=input().split()\r\nn=int(n)\r\nk=int(k)\r\narr=[0]*n\r\narr=input().split()\r\nfor i in range (n):\r\n arr[i]=int(arr[i])\r\nlength=n-k+1\r\nwindow=sum(arr[:n-k+1])\r\ntotal=window\r\nfor t in range (1,k,+1):\r\n window=window-arr[t-1]+arr[t+(n-k)]\r\n total=total+window\r\nprint (total/(n-k+1))", "from math import floor\n\ndef bounded_sum(l, p1, p2):\n r = 0\n for i in range(p1, p2 + 1):\n r += l[i]\n return r\n\n\ndef solve(n, k, a):\n r = 0\n for i in range(k):\n r += a[i]\n aux = r\n for j in range(k, n):\n r += a[j] - a[j-k]\n aux += r\n return aux/(n - k + 1)\n\n\nN, K = [int(i) for i in input().split()]\nA = [int(i) for i in input().split()]\nprint(\"{0:.12f}\".format(solve(N, K, A)))\n# 1522021248774\n", "t = list(map(int,input().split()))\r\nn = t[0]\r\nk = t[1]\r\na = list(map(int,input().split()))\r\nsumma = sum(a[0:k])\r\nres=summa\r\nfor i in range(n-k):\r\n summa-=a[i]\r\n summa+=a[k+i]\r\n res+=summa\r\nprint('%6f'% (res/(n-k+1)))\r\n", "n, k = map(int, input().split())\r\na = [int(i) for i in input().split()]\r\ns = 0\r\nfor i in range(n - k + 1):\r\n s += a[i]*min(i + 1, k)\r\nfor i in range(n - k + 1, n):\r\n s += a[i]*min(n - k + 1, n - i)\r\ns /= n - k + 1\r\nprint(\"%.7f\" % s)", "n,k = map(int,input().split())\n\nA = list(map(int,input().split()))\n\nacc = sum([min(i+1,n-i,n-k+1,k) * A[i] for i in range(n)])\n\nprint(acc / (n - k + 1))\n", "n, k = map(int, input().split(' '))\na = list(map(int, input().split(' ')))\nb = [0]\nfor i in range(n):\n b.append(b[-1] + a[i])\nweeks = n - k + 1\nsum = 0\nfor i in range(weeks):\n sum += b[i + k] - b[i]\nprint('{:.10f}'.format(sum / weeks))\n", "ln,l=map(int,input().split())\r\nk = ln-l+1\r\narr = list(map(int,input().split()))\r\npref = [0]*ln\r\ns = 0\r\nfor i in range(ln):\r\n pref[i] = arr[i]+pref[i-1]\r\n if i>=l:\r\n s+=pref[i]-pref[i-l]\r\ns+=pref[l-1]\r\nprint(s/k)", "from collections import deque\r\nn, k = map(int, input().split())\r\nlis = list(map(int, input().split()))\r\nd = deque()\r\nsu = 0\r\ncur = 0\r\ni = 0\r\nwhile i < k:\r\n cur += lis[i]\r\n d.append(lis[i])\r\n i += 1\r\nwhile i < n:\r\n su += cur\r\n cur -= d.popleft()\r\n d.append(lis[i])\r\n cur += lis[i]\r\n i += 1\r\nsu += cur\r\nprint(su / (n - k + 1))\r\n", "import sys\r\n\r\ninp = lambda : sys.stdin.readline().rstrip('\\n')\r\nout = lambda a: sys.stdout.write(str(a)+'\\n')\r\n\r\n\r\nn,k = map(int,inp().split())\r\n\r\na = list(map(int,inp().split()))\r\n\r\nweeks = n-k+1\r\n\r\nsum = 0\r\ntimes = 1\r\ncount = 0\r\nfor i,e in enumerate(a):\r\n sum += (e * times) / weeks\r\n if i < k-1:\r\n times += 1\r\n if i >= n-k:\r\n times -= 1\r\n # count += 1\r\n # if count == k:\r\n # sum = sum / weeks\r\n # count = 0\r\n\r\nout(sum)\r\n\r\n\r\n\r\n\r\n\r\n", "import math\nn, k = map(int, input().split())\nsleeps = list(map(int, input().split()))\nres = 0\nprefix = [0] * (n+1)\nprefix[0] = sleeps[0]\nfor i in range(1,n):\n\tprefix[i] = prefix[i-1] + sleeps[i]\n\nfor i in range(k-1, n):\n\tres += prefix[i] - prefix[i-k]\nprint(res / (n-k+1)) \n", "import sys, math\r\ninput = sys.stdin.readline\r\n\r\ndef main():\r\n n,k = map(int,input().split())\r\n tab = list(map(int,input().split()))\r\n s = 0\r\n cu = [0]\r\n for x in range(n):\r\n s += tab[x]\r\n cu.append(s)\r\n s = 0\r\n for x in range(n-k+1):\r\n if x+k <= n:\r\n s += cu[x+k] - cu[x]\r\n print(s/(n-k+1))\r\n \r\n \r\n \r\nmain()\r\n", "n, k = map(int, input().split())\r\nvalores = list(map(int, input().split()))\r\n\r\n\r\nv_acumu = [0 for i in range(len(valores))]\r\nv_acumu[0] = valores[0]\r\nfor i in range(len(valores)):\r\n if i == 0:\r\n continue\r\n v_acumu[i] = valores[i] + v_acumu[i-1]\r\n\r\nv_acumu = [0] + v_acumu\r\n\r\nsomatorio = 0\r\n\r\nfor i in range(n):\r\n if i+k > n:\r\n break\r\n somatorio += v_acumu[i+k] - v_acumu[i]\r\n\r\n\r\nprint(somatorio/(n-k+1))", "n, k = [int(j) for j in input().split()]\r\nnums = [int(j) for j in input().split()]\r\ns = sum(nums[: k])\r\ntot = s\r\np1, p2 = 0, k\r\nfor j in range(n - k):\r\n s -= nums[p1]\r\n s += nums[p2]\r\n tot += s\r\n p1 += 1\r\n p2 += 1\r\nprint(tot / (n - k + 1))\r\n", "# LUOGU_RID: 119934064\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\n# 计算所有周的平均睡眠时间\r\ntotal_sleep = sum(a[:k])\r\naverage_sleep = total_sleep\r\n\r\nfor i in range(k, n):\r\n total_sleep += a[i] - a[i - k]\r\n average_sleep += total_sleep\r\n\r\naverage_sleep /= (n - k + 1)\r\nprint(\"{:.9f}\".format(average_sleep))", "def addion(arr_ai, k):\r\n\toutput = 0\r\n\tprevOut = 0\r\n\tanswer = 0\r\n\tfor x in range(0,len(arr_ai)):\r\n\t\tif(x+k <= len(arr_ai)):\r\n\t\t\tif(prevOut == 0):\r\n\t\t\t\tanswer = int(arr_ai[x])\r\n\t\t\t\tif(k > 1):\r\n\t\t\t\t\tfor z in range(1,k):\r\n\t\t\t\t\t\tanswer += int(arr_ai[x+z])\r\n\t\t\telse:\r\n\t\t\t\tif(k > 1):\r\n\t\t\t\t\tanswer = prevOut - int(arr_ai[x-1]) + int(arr_ai[x+k-1])\r\n\t\t\t\telse:\r\n\t\t\t\t\tanswer = int(arr_ai[x])\r\n\t\t\toutput += answer\r\n\t\t\tprevOut = answer\r\n\treturn output\r\n\t\t\t\r\n\t\r\nn_k = input()\r\na_i = input()\r\nnk_arr = n_k.split(' ')\r\nn = int(nk_arr[0])\r\nk = int(nk_arr[1])\r\nw = float(n) - float(k) + 1\r\nif(n == 1):\r\n\tprint(a_i)\r\nelse:\r\n\tai_arr = a_i.split(' ')\r\n\tsum = addion(ai_arr,int(k))\r\n\toutput = round(sum / w,6)\r\n\tprint(output)", "n,k=map(int,input().split())\narr=list(map(float,input().split()))\nsum_arr=0\nfor i in range(n):\n\tsum_arr+=arr[i]*min(n-k+1,k,i+1,n-i)\nprint(sum_arr/(n-k+1))\n", "# -*- coding: utf-8 -*-\n\n# Baqir Khan\n# Software Engineer (Backend)\n\nfrom sys import stdin\n\ninp = stdin.readline\n\nn, k = map(int, inp().split())\na = list(map(int, inp().split()))\n\ncur_sum = 0\nfor i in range(k):\n cur_sum += a[i]\n\ntotal_sum = cur_sum\nfor i in range(k, n):\n cur_sum += a[i]\n cur_sum -= a[i - k]\n total_sum += cur_sum\n\nprint(\"{:.6f}\".format(total_sum / (n - k + 1)))\n", "n, k=map(int, input (). split ())\r\ns=[0]\r\nsumma=0\r\nA=list (map (int, input ().split ()))\r\nfor i in range (n) :\r\n s. append (s[i] +A[i])\r\nfor i in range (k,n+1):\r\n summa+=s[i] - s[i-k]\r\nfrom decimal import Decimal as D\r\nans=D(summa)/D(n-k+1)\r\nprint ((ans) )\r\n \r\n", "import math as mt \r\nimport sys,string,bisect\r\ninput=sys.stdin.readline\r\nimport random\r\nfrom collections import deque,defaultdict\r\nL=lambda : list(map(int,input().split()))\r\nLs=lambda : list(input().split())\r\nM=lambda : map(int,input().split())\r\nI=lambda :int(input())\r\ndef check(n):\r\n n=list(set(list(str(n))))\r\n if(len(n)==1):\r\n return True\r\n n.sort()\r\n if(n[0]=='0'):\r\n if(len(n)<=2):\r\n return True\r\n else:\r\n return False\r\n else:\r\n return False\r\n\r\nn,k=M()\r\nl=L()\r\nx=0\r\nans=sum(l[:k:])\r\nx=ans\r\n\r\nfor i in range(k,n):\r\n x+=l[i]\r\n\r\n x-=l[i-k]\r\n ans+=x\r\nprint(ans/(n-k+1))\r\n", "n,k=map(int,input().split())\r\nls=list(map(int,input().split()))\r\nm=n-k+1\r\na=min(k,n-k+1)\r\ns=0\r\ng=1\r\nfor i in range(a-1):\r\n s+=(g*ls[i])\r\n g+=1\r\ng=1\r\nfor i in range(-1,-a,-1):\r\n s += (g * ls[i])\r\n g += 1\r\nfor i in range(a-1,n-a+1):\r\n s+=(a*ls[i])\r\nprint(\"{:.10f}\".format(s/m))", "n,k=map(int,input().split())\r\nl=[int(i) for i in input().split()]\r\nsm=sum(l[0:k]) \r\ntot=0 \r\ntot+=sm \r\nfor i in range(k,n):\r\n sm+=l[i]\r\n sm-=l[i-k]\r\n tot+=sm \r\nprint(tot/(n-k+1))", "n, k = list(map(int, input().split()))\r\narr = list(map(int, input().split()))\r\ncount = n - k + 1\r\nprefixAr = [0]\r\ncumSum = 0\r\nfor x in arr:\r\n cumSum += x\r\n prefixAr.append(cumSum)\r\n\r\nnewCumSum = 0\r\nfor i in range(1, count+1):\r\n newCumSum += (prefixAr[i + k - 1] - prefixAr[i-1])\r\n\r\nprint(newCumSum/count)", "N, K = map( int, input().split() )\r\nA = list( map( int, input().split() ) )\r\nans = 0\r\nfor i in range( N ):\r\n c = min( i + 1, K )\r\n c -= K - min( N - i, K )\r\n ans += c * A[ i ]\r\nprint( \"%.7f\" % ( ans / ( N - K + 1 ) ) )\r\n", "n, k = map(int, input().split())\r\ns = list(map(int, input().split()))\r\nres = 0\r\nt = n-k\r\nres = sum(s)*(n-k+1)\r\ni = 0\r\nwhile(t):\r\n res -= t*(s[i] + s[-i-1])\r\n t -= 1\r\n i += 1\r\nprint(res/(n-k+1))\r\n", "n,k=list(map(int,input().split(\" \")))\r\n\r\nli=list(map(int,input().split(\" \")))\r\nsum=0\r\nfor x in range(k):\r\n sum=sum+li[x]\r\n\r\ni=0\r\nj=k\r\nres=sum\r\nfor x in range(n-k):\r\n sum = sum - li[i] + li[j]\r\n res=res+sum\r\n\r\n i+=1\r\n j+=1\r\n\r\n\r\nprint(res/(n-k+1))", "def sleep(k, lst):\r\n sum1 = sum(lst[0: k])\r\n sum2 = sum1\r\n for i in range(len(lst) - k):\r\n sum1 += (lst[i + k] - lst[i])\r\n sum2 += sum1\r\n return '{:.10f}'.format(sum2 / (len(lst) - k + 1))\r\n\r\n\r\nN, K = [int(i) for i in input().split()]\r\na = [int(j) for j in input().split()]\r\nprint(sleep(K, a))\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\nw = list(map(int, input().split()))\r\nc = x = sum(w[:k])\r\nfor i in range(n-k):\r\n x -= w[i]\r\n x += w[i+k]\r\n c += x\r\nprint(c/(n-k+1))\r\n", "# LUOGU_RID: 120352999\nn, k = map(int, input().split())\r\nnum_list = [int(num) for num in input().split()]\r\ngroup = 0 # 存储当前选择的组合的值\r\nres = 0 # 存储最终结果\r\ngroup_num = n - k + 1 # 存储共有多少种组合\r\n\r\n\r\nfor i in range(k): # 计算第一个组合\r\n group += num_list[i]\r\nres += group / group_num # 第一个组合计算后的结果\r\n\r\nfor i in range(group_num - 1): # 计算剩余组合\r\n # 只要先将最前面的数字减去,再加上最后面的数字,就得到了新的组合的结果\r\n group -= num_list[i]\r\n group += num_list[i + k]\r\n res += group / group_num\r\n\r\nprint('{:.10f}'.format(res))\r\n", "n,k=map(int,input().split())\n\na=list(map(int,input().split()))\n\ns=x=sum(a[:k])\n\nfor i in range(k,n):\n\n s+=a[i]-a[i-k]\n\n x+=s\n\nprint(x/(n-k+1))\n\n\n\n# Made By Mostafa_Khaled", "n,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nww=n-k+1\r\na=[]\r\na.append(0)\r\nfor i in range(n):\r\n\ta.append(arr[i])\r\nfor i in range(1,n+1):\r\n\ta[i]=a[i]+a[i-1]\r\nans=0\r\nfor i in range(k,n+1):\r\n\ttmp=a[i]-a[i-k]\r\n\tans+=(tmp/ww)\r\nprint(ans)", "import sys\ninput=sys.stdin.readline\nn,k=map(int,input().split())\nsm=0\nar=list(map(int,input().split()))\ncr=sum(ar[:k-1])\nfor x in range(n-k+1):\n cr+=ar[k+x-1]\n sm+=cr\n #print(sm)\n cr-=ar[x]\nprint(sm/(n-k+1))\n#print(sm)", "n,k = map(int,input().split())\r\nA = list(map(int,input().split()))\r\nN = n-k+1\r\nS = 0\r\nfor i in range(k):\r\n S += A[i] # сумма первых k элементов\r\nV = S\r\nfor i in range(k,len(A)):\r\n S = S + A[i] - A[i-k]\r\n V += S\r\nx = V / N\r\nif (x * (10**6)) % 1 == 0: # значит к ним нужно добавлять нули под конец к единому формату\r\n print(str(x) + str('000000'))\r\nelse:\r\n print(x)", "def solve(c, v):\r\n ans=0\r\n for i in range(c):\r\n ans+=v[i]\r\n tmp=ans\r\n for i in range(c, len(v)):\r\n tmp+=v[i]\r\n tmp-=v[i-c]\r\n ans+=tmp\r\n ln = len(v)\r\n return ans/(ln-c+1)\r\n\r\nln,c=map(int,input().split())\r\nv=list(map(int,input().split()))\r\nprint(solve(c,v))\r\n", "m,n = map(int,input().split())\r\narr = [int(x) for x in input().split()]\r\ns = sum(arr[:n])\r\nval = m-n+1\r\nns = s/val\r\nfor i in range(n,m):\r\n\ts = s + arr[i] - arr[i-n]\r\n\tns += s/val\r\nprint(ns)", "n,k=map(int,input().split())\na=list(map(int,input().split()))\ns=0\nz=n-k+1\nfor i in range(n):\n s+=a[i]*min(z,k,i+1,n-i)\nprint(s/(z))\n\t \t\t\t\t \t \t \t \t\t\t\t\t", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nb = [0]\r\nfor i in a:\r\n b.append(b[-1] + i)\r\nans = 0\r\nfor i in range(n - k + 1):\r\n ans += b[i + k] - b[i]\r\nans /= (n - k + 1)\r\nprint(ans)", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nd=[]\r\nc=0\r\nfor i in range(n):\r\n c=c+l[i]\r\n d.append(c)\r\ns=d[k-1]\r\nfor i in range(k,n):\r\n s=s+d[i]-d[i-k]\r\nx=n-k+1\r\nprint(s/x)\r\n", "n , k = map(int,input().split())\r\n\r\na = list(map(int,input().split()))\r\n\r\npref = [0]\r\n\r\nfor i in a:\r\n pref.append(i+pref[-1])\r\nd = sm = 0\r\nfor i in range(k,n+1):\r\n sm += pref[i] - pref[i-k]\r\n d += 1\r\nprint(sm/d)\r\n", "s=input()\r\ns1=s.split()\r\nn=int(s1[0])\r\nk=int(s1[1])\r\ns=input()\r\ns1=s.split()\r\narr=[]\r\nfor i in range(n):\r\n arr.append(int(s1[i]))\r\nsum=0\r\nfor i in range(k):\r\n sum+=arr[i]\r\nsum1=sum\r\nfor i in range(k,n):\r\n sum+=arr[i]\r\n sum-=arr[i-k]\r\n sum1+=sum\r\ns=str(sum1/(n-k+1))\r\ns+='000000'\r\nprint(s)", "n, k = map(int, input().split())\n\nres = 0\na = [int(i) for i in input().split()]\ncur_sum = sum(a[0:k])\nres += cur_sum\n\nfor i in range(n - k):\n cur_sum -= a[i]\n cur_sum += a[k + i]\n res += cur_sum\n\nprint(res / (n - k + 1))\n", "f = lambda: map(int, input().split())\r\nn, k = f()\r\nt = [0] + list(f())\r\nfor i in range(n): t[i + 1] += t[i]\r\nm = min(n - k + 1, k)\r\nprint((sum(t[m:]) - sum(t[:-m])) / (n - k + 1))", "n,k=list(map(int,input().strip().split(' ')))\r\nA=list(map(int,input().strip().split(' ')))\r\ntemp=0\r\ntotal=0\r\nfor i in range(n-k+1):\r\n if i==0:\r\n temp=sum(A[:k])\r\n total+=temp\r\n else:\r\n temp-=A[i-1]\r\n temp+=A[i+k-1]\r\n total+=temp\r\n #print(temp) \r\nans=total/(n-k+1)\r\nprint(ans)", "\nn, k = map(int, input().split())\n\ntab = [int(x) for x in input().split()]\n\ntmp = sum(tab[:k])\n\nS = tmp\n\nfor i in range(k, len(tab)):\n tmp -= tab[i - k]\n tmp += tab[i]\n S += tmp\n\nprint(S / (n - k + 1))\n", "import sys\r\nfrom math import gcd, sqrt\r\n\r\nsys.setrecursionlimit(10 ** 5)\r\n\r\n\r\ninf = float(\"inf\")\r\nen = lambda x: list(enumerate(x))\r\n\r\nii = lambda: int(input())\r\nr = lambda: map(int, input().split())\r\nrr = lambda: list(r())\r\n\r\n\r\nn, k = r()\r\narr = rr()\r\nans = 0\r\nz = n - k + 1\r\nfor i, j in enumerate(arr, 1):\r\n ans += j * min(i, n - i + 1, z, k)\r\n\r\nprint(ans / z)\r\n", "n, k = [int(p) for p in input().split()]\nw = n - k + 1\narr = [int(p) for p in input().split()]\ns = sum(arr[:k])\ncurr = s\nj = k\ni = 0\nwhile j < len(arr):\n s -= arr[i]\n i += 1\n s += arr[j]\n j += 1\n curr += s\n\nprint(curr/w)", "n,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nans=0\r\nfor i in range(n):\r\n ans+=min(i+1,n-k+1,k,n-i)*a[i]\r\nprint(ans/(n-k+1))", "n,k = map(int, input().split())\na = list(map(int, input().split()))\n\n\nslide = a[:k]\ncurrent = sum(slide)\nans = current\nfor x in range(1,n-k+1):\n current = current - a[x-1] + a[x + k-1]\n ans += current\n\nprint(\"{0:.6f}\".format(ans/(n-k+1)))", "[n, k] = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\n \r\nsum = 0\r\nfor i in range(k):\r\n sum += a[i]\r\ntot = sum\r\nfor i in range(n-k):\r\n sum -= a[i]\r\n sum += a[i+k]\r\n tot += sum \r\ntot /= n-k+1\r\nprint(tot)\r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n \r\n\r\n \r\n \r\n \r\n", "n,k = map(int,input().split())\r\n\r\n\r\ns = list(map(int,input().split()))\r\nr = 0\r\nfor i in range(k):\r\n\r\n\tr = r + s[i]\r\nt = r\r\nfor i in range(k,n):\r\n\r\n\tr = r - s[i-k]\r\n\tr = r + s[i]\r\n\tt = t + r\r\nprint(t/(n-k+1))\r\n", "n,k=list(map(int,input().split()))\r\nc=[]\r\na=list(map(int,input().split()))\r\nsum=0\r\nfor i in range(n):\r\n sum+=a[i]\r\n c.append(sum)\r\nans=0\r\nfor j in range(k-1,n):\r\n if j==k-1:\r\n ans+=c[j]\r\n else:\r\n ans+=c[j]-c[j-k]\r\n# print(*c)\r\n# print(ans)\r\nprint(ans/(n-k+1))\r\n", "#!/usr/bin/env python3\r\n# -*- coding: utf-8 -*-\r\nn,m=map(int,input().strip().split())\r\na=input()\r\nb=list(map(float,a.strip().split()))\r\nsum=0\r\nt=m\r\nfor i in range(m):\r\n sum+=b[i]\r\ntemp=sum\r\nL=0\r\nwhile m<n:\r\n temp=temp-b[L]+b[m]\r\n L+=1\r\n m+=1\r\n sum+=temp\r\nans=sum/(n-t+1)\r\nprint(\"%.10f\" %ans)\r\n", "def solve(n,k,a):\r\n s = sum(a[:k])\r\n tot = 0\r\n l = 0\r\n\r\n tot += s\r\n for r in range(k,n):\r\n s = s-a[l]+a[r]\r\n tot += s\r\n l+=1\r\n\r\n return tot/(n-k+1)\r\n\r\ndef main():\r\n n,k = map(int,input().split(' '))\r\n a = [int(x) for x in input().split(' ')]\r\n print('{:0.6f}'.format(solve(n,k,a)))\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n, k = [int(x) for x in input().split()]\r\nweeks = n-k+1\r\nlist = [int(x) for x in input().split()]\r\ntotal = 0\r\nsum = 0\r\nfor x in range(k):\r\n sum += list[x]\r\ntotal += sum\r\nfor i in range(k, n):\r\n sum += list[i] - list[i-k]\r\n total += sum\r\nprint(total/weeks)", "from itertools import accumulate \r\nn, k = map(int, input().split(' '))\r\na = map(int, input().split(' '))\r\n\r\nprefix = list(accumulate(a))\r\ntotal = prefix[k-1]\r\n\r\nfor i in range(k, n):\r\n total = total + prefix[i] - prefix[i-k]\r\n\r\nprint(\"{:.10f}\".format(float(total) / float(n-k+1)))\r\n", "n,k=input().split()\r\nwork=list(map(int,input().split()))\r\nl=[0]+work\r\nsumm=0\r\nbig=0\r\nx=1\r\ny=0\r\nwhile y<int(n)+1:\r\n if y==int(k):\r\n summ+=l[y]\r\n big+=summ\r\n y+=1\r\n elif y<int(k):\r\n summ+=l[y]\r\n y+=1\r\n else:\r\n summ-=l[x]\r\n x+=1\r\n summ+=l[y]\r\n y+=1\r\n big+=summ\r\nprint(big/(int(n)-int(k)+1))\r\n \r\n \r\n \r\n \r\n", "import sys\ninput = sys.stdin.readline\n\n'''\nweek = k days\nai sleep time on i-th day\n'''\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\n\nk_sum = sum(a[:k])\ntot = k_sum\n\nleft, right = 0, k\nwhile right < n:\n k_sum -= a[left]\n k_sum += a[right]\n tot += k_sum\n left += 1\n right += 1\n\nprint(tot / (n-k+1))", "from sys import stdin\r\ninput = stdin.readline\r\n# ~ T = int(input())\r\nT = 1\r\nfor t in range(1,T + 1):\r\n\tn,k = map(int,input().split())\r\n\t_input = list(map(int,input().split()))\r\n\tif n == 1:\r\n\t\tprint(\"{0:.6f}\".format(sum(_input) / (n - k + 1)))\r\n\t\texit()\r\n\tfor i in range(len(_input)):\r\n\t\tif i > 0:\r\n\t\t\t_input[i] += _input[i - 1]\r\n\t_sum = 0\r\n\tfor i in range(k - 1,len(_input)):\r\n\t\tif i == k - 1:\r\n\t\t\t_sum += _input[i]\r\n\t\telse:\r\n\t\t\t_sum += _input[i] - _input[i - k]\r\n\tprint(\"{0:.6f}\".format(_sum / (n - k + 1)))\r\n\t\r\n", "n, k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nans = 0 \r\nfor i in range(n) :\r\n temp = min (i + 1, k)\r\n temp -= k - min ( n - i, k)\r\n ans += temp * a[i]\r\nprint(\"%.10f\"%(ans / ( n - k + 1))) ", "f = lambda: map(int, input().split())\r\nn, k = f()\r\nt = list(f())\r\nh = s = sum(t[:k])\r\nfor i in range(n - k):\r\n s += t[k + i] - t[i]\r\n h += s\r\nprint(h / (n - k + 1))", "from itertools import *\r\n\r\ndef calc_pref(l):\r\n\tn = len(l)\r\n\tres = list(repeat(0, n+1))\r\n\tfor i in range(1, n+1):\r\n\t\tres[i] += res[i-1]+l[i-1]\r\n\treturn res\r\n\r\n[n, k] = map(int, input().split())\r\nl = list(map(int, input().split()))\r\npref = calc_pref(l)\r\nres = 0.0\r\nfor i in range(0, n-k+1):\r\n\tres += (pref[i+k]-pref[i])/(n-k+1)\r\nprint(res)", "n,m = map(int , input().split())\r\nl = [int(i) for i in input().split()] ; sumans = sum(l[:m]) ; temp = sumans\r\nj = m\r\nfor i in range(1,n-m+1):\r\n temp += l[j]\r\n temp -= l[i-1]\r\n sumans += temp\r\n j+=1\r\nprint(sumans/(n-m+1))\r\n", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\ns = 0\r\nfor i in range(n):\r\n l = max(0, i - k + 1)\r\n r = min(i, n - k)\r\n \r\n s += a[i] * (r - l + 1)\r\n \r\n \r\nprint(s / (n - k + 1))", "n, m = map(int, input().split())\r\nA = list(map(int, input().split()))\r\nz = 0\r\nfor i in range(m):\r\n z += A[i]\r\nans = int(z)\r\nfor i in range(m, n):\r\n z -= A[i - m]\r\n z += A[i]\r\n ans += z\r\nprint(ans / (n - m + 1))", "# ========= /\\ /| |====/|\r\n# | / \\ | | / |\r\n# | /____\\ | | / |\r\n# | / \\ | | / |\r\n# ========= / \\ ===== |/====| \r\n# code\r\n\r\nif __name__ == \"__main__\":\r\n n,k = map(int,input().split())\r\n a = list(map(int,input().split()))\r\n su = sum(a[:k])\r\n s = su\r\n j = k\r\n while j < n:\r\n s = s + a[j] - a[j-k]\r\n su += s\r\n j += 1\r\n # print(su)\r\n print(su/(n-k+1))", "n,k = map(int,input().split())\r\nl1 = list(map(int,input().split()))\r\nl2 = [0]*len(l1)\r\nfor i in range(len(l1)):\r\n l2[i] = l1[i]\r\nfor i in range(1,len(l1)):\r\n l2[i]+=l2[i-1]\r\ns=0\r\nfor i in range(k-1,len(l1)):\r\n x = l2[i]\r\n if(i-k>=0):\r\n x-=l2[i-k]\r\n s+=x\r\nprint(s/(n-k+1))", "# IAWT\r\nn, k = list(map(int, input().split()))\r\nl = list(map(int, input().split()))\r\n\r\ndef get_t(i):\r\n start = max(i-k+1, 0)\r\n end = min(i+k-1, n-1) - (k - 1)\r\n if start > end: return 0\r\n return end - start + 1\r\n\r\ns = 0\r\nfor i in range(n):\r\n s += get_t(i) * l[i]\r\nprint(s / (n-k+1))\r\n", "n,k=map(int,input().split())\r\na=[int(x) for x in input().split()]\r\nans=0\r\nniche=n-k+1\r\npresum=[0]*(n)\r\npresum[0]=a[0]\r\n\r\nfor i in range(1,n):\r\n presum[i]=presum[i-1]+a[i]\r\n#print(presum)\r\nfor i in range(k):\r\n ans+=a[i]\r\n\r\nj=0\r\nfor i in range(k,n):\r\n ans+=presum[i]-presum[j]\r\n \r\n j+=1\r\n\r\nprint(ans/niche)\r\n", "n,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nA=[0]\r\nfor i in l:\r\n A.append(A[-1]+i)\r\ns=0\r\nfor i in range(k,n+1):\r\n s+=A[i]-A[i-k]\r\nprint(s/(n-k+1))", "n,m = map(int,input().split())\r\nx = list(map(int,input().split()))\r\n\r\nss=0\r\nc=0\r\nl=0\r\nf=0\r\nfor i in range(len(x)):\r\n ss+=x[i]\r\n if(i==m-1 and l==0):\r\n c+=ss\r\n l=1\r\n \r\n elif(l==1):\r\n ss-=x[f]\r\n c+=ss\r\n f+=1\r\n\r\n \r\n \r\n\r\nprint(c/(n-m+1))", "\nn,k = map(int,input().split(' '))\nA = list(map(int,input().split(' ')))\n# print (n,k,A)\nsums = 0\nfor i in range(k):\n\tsums=sums+A[i]\nwindow = sums\nfor i in range(0,n-k):\n\twindow=window-A[i]+A[i+k]\n\tsums+=window\nweeks= n - k + 1\na=sums/weeks\nprint(\"%.11f\" % a)", "n, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nl = [0]\r\nfor i in a:\r\n l.append(l[-1] + i)\r\ns = 0\r\nfor i in range(k,n+1):\r\n s += l[i] - l[i-k]\r\nprint(s/(n-k+1))\r\n" ]
{"inputs": ["3 2\n3 4 7", "1 1\n10", "8 2\n1 2 4 100000 123 456 789 1", "1 1\n1", "1 1\n100000", "3 1\n1 2 3", "10 4\n11 3 5 20 12 7 9 2 2 20", "10 5\n15 9 3 2 17 10 9 18 4 19", "10 6\n19 3 20 16 14 10 1 13 7 3", "10 7\n8 16 2 13 15 9 5 13 9 2", "10 4\n127 1459 718 1183 880 1044 1857 1340 725 1496", "10 5\n1384 1129 1780 1960 1567 1928 12 1523 1165 344"], "outputs": ["9.0000000000", "10.0000000000", "28964.2857142857", "1.0000000000", "100000.0000000000", "2.0000000000", "36.2857142857", "50.3333333333", "65.8000000000", "68.2500000000", "4574.4285714286", "6931.3333333333"]}
UNKNOWN
PYTHON3
CODEFORCES
97
21b7de902f49277b20a3051ca8ba9528
Rook, Bishop and King
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: - A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally. Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Sample Input 4 3 1 6 5 5 5 6 Sample Output 2 1 3 1 0 1
[ "def stessocolore(x1,y1,x2,y2):\r\n if (x1+y1)%2 == (x2+y2)%2:\r\n return True\r\n else:\r\n return False\r\nx1, y1, x2, y2 = map(int, input().split())\r\nif x1 == x2 or y1 == y2:\r\n rook = 1\r\nelse:\r\n rook = 2\r\nking = max([abs(x1-x2),abs(y1-y2)])\r\nif stessocolore(x1,y1,x2,y2):\r\n if (x1-y1) == (x2-y2) or x1+y1 == x2+y2:\r\n bish = 1\r\n else:\r\n bish = 2\r\nelse:\r\n bish = 0\r\n\r\nprint(rook, bish, king)", "import sys\n\nline = sys.stdin.readline().split()\nr1, c1, r2, c2 = int(line[0]), int(line[1]), int(line[2]), int(line[3])\n\nrook, bishop, king = 0, 0, 0\n\nif r1 != r2 and c1 != c2:\n rook = 2\nelse:\n rook = 1\n\nif abs(r1 - r2) == abs(c1 - c2):\n bishop = 1\nelif abs(r1 - r2) % 2 == abs(c1 - c2) % 2:\n bishop = 2\nelse:\n bishop = 0\n\nking = max(abs(r1 - r2), abs(c1 - c2))\n\nprint(rook, bishop, king)\n\n\t\t\t\t \t\t \t \t\t \t\t \t \t\t \t \t \t", "__author__ = 'widoc'\r\n\r\nr1, c1, r2, c2 = map(int, input().split())\r\n\r\na1 = 1 if r1 == r2 or c1 == c2 else 2\r\na2 = 0\r\nif abs(r1-r2) == abs(c1-c2):\r\n a2 = 1\r\nelif (abs(r1-r2) + abs(c1-c2)) % 2 == 0:\r\n a2 = 2\r\na3 = max(abs(r1-r2),abs(c1-c2))\r\n\r\nprint(a1, a2, a3)\r\n\r\n", "x1, y1, x2, y2 = map(int, input().split())\r\n\r\nif x1 == x2 or y1 == y2:\r\n a = 1\r\nelse:\r\n a = 2\r\n\r\nif (x1 % 2 + y1 % 2) % 2 == (x2 % 2 + y2 % 2) % 2:\r\n if abs(x1 - x2) == abs(y2 - y1):\r\n b = 1\r\n else:\r\n b = 2\r\nelse:\r\n b = 0\r\n\r\nc = max(abs(x1 - x2), abs(y1 - y2))\r\n\r\nprint(a, b, c)\r\n\n# Tue Jul 11 2023 11:26:32 GMT+0300 (Moscow Standard Time)\n", "if __name__ == '__main__':\n s = ''\n r1, c1, r2, c2 = map(int, input().split())\n diff_row = (abs(r1-r2))\n diff_col = (abs(c1-c2))\n #### rook ####\n if(r1 == r2 or c1 == c2):\n s += '1 '\n else:\n s += '2 '\n #### bishop ####\n if(diff_row % 2 != diff_col % 2):\n s += '0 '\n elif(diff_row == diff_col):\n s += '1 '\n else:\n s += '2 '\n #### king ####\n s += str(max(diff_row, diff_col))\n print(s)\n\n \t\t\t \t \t \t\t \t \t \t\t", "\r\nx1, y1, x2, y2 = list(map(int, input().split()))\r\n\r\ndx = abs(x2 - x1)\r\ndy = abs(y2 - y1)\r\n\r\n# for the rook\r\nif dx > 0 and dy > 0:\r\n print(2, end=\" \")\r\nelif dx > 0 or dy > 0:\r\n print(1, end=\" \")\r\n\r\n\r\ndef func(a, b, c, d):\r\n y = (b+d+c-a)/2\r\n x = (d+c-b+a)/2\r\n return x in range(1,9) and y in range(1,9)\r\n\r\n\r\n# for the bishop\r\nif dx == dy:\r\n print(1, end=\" \")\r\nelse:\r\n if func(x1, y1, x2, y2):\r\n print(2, end=\" \")\r\n elif func(x2, y2, x1, y1):\r\n print(2, end=\" \")\r\n else:\r\n print(0, end=\" \")\r\n\r\n# for the king\r\nif dx == dy:\r\n print(dx)\r\nelif dx > dy:\r\n print(dx)\r\nelse:\r\n print(dy)\r\n", "xa, ya, xb, yb = [int(x) for x in input().split(' ')]\n\nxv = xa-xb if xa > xb else xb-xa\nyv = ya - yb if ya > yb else yb - ya\n\n# def torr():\nif xa == xb or ya == yb:\n print(1, end=' ')\nelse:\n print(2, end=' ')\n\n# def alf():\nif ((xa + ya)%2 == 0) != ((xb + yb)%2 == 0):\n print(0, end=' ')\n # return\nelif xv == yv:\n print(1, end=' ')\nelse:\n print(2, end=' ')\n\n# def king():\nprint(max(xv, yv), end='')\n\t\t\t\t \t \t\t \t\t\t \t\t \t \t\t \t \t", "x1, y1, x2, y2 = map(int, input().split())\r\n\r\nx1 = abs(x1-x2)\r\ny1 = abs(y1-y2)\r\n\r\nt = min(x1, 1) + min(y1, 1)\r\nk = max(x1, y1)\r\np = 2\r\n\r\nif x1 == y1:\r\n p = 1\r\nelif x1+y1 == 0 or (x1+y1)%2:\r\n p = 0\r\n\r\nprint(t, p, k)\r\n", "r1, c1, r2, c2 = map(int, input().split())\r\nk = max(abs(c2 - c1), abs(r2 - r1))\r\nr, b = 0, 2\r\nif r1 == r2 or c1 == c2:\r\n r = 1\r\nelse:\r\n r = 2\r\n\r\nfor i in range(1, 8):\r\n if r1 + i == r2 and c1 + i == c2 or r1 - i == r2 and c1 - i == c2 or r1 + i == r2 and c1 - i == c2 \\\r\n or r1 - i == r2 and c1 + i == c2:\r\n b = 1\r\n break\r\nelse:\r\n if (abs(c2 - c1) + abs(r2 - r1)) % 2 == 1:\r\n b = 0\r\nprint(r, b, k)\r\n", "def rook(r1, c1, r2, c2):\n res = 0\n\n if r1 != r2:\n res += 1\n \n if c1 != c2:\n res += 1\n\n return res\n\ndef bishop(r1, c1, r2, c2):\n res = 1\n if abs((r1 % 2) - (c1 % 2)) != abs((r2 % 2) - (c2 % 2)):\n res = 0\n elif abs(r1 - r2) != abs(c1 - c2):\n res += 1\n \n return res\n\ndef king(r1, c1, r2, c2):\n res = max(abs(r1 - r2), abs(c1 - c2))\n\n return res\n\n\nr1, c1, r2, c2 = [int(i) for i in input().split()]\n\nr = rook(r1, c1, r2, c2)\nb = bishop(r1, c1, r2, c2)\nk = king(r1, c1, r2, c2)\n\nprint(r, b, k)\n \t\t\t\t \t\t\t \t \t\t\t \t", "__author__ = 'Esfandiar and HajLorenzo'\na=list(map(int,input().split()))\nres = 2\nres-= a[0]==a[2]\nres-= a[1]==a[3]\nprint(res,end=\" \")\nres=2\nblack1 = (a[0]+a[1]) % 2 != 0\nblack2 = (a[2]+a[3]) % 2 != 0\nif black1 != black2 or (a[0] == a[2] and a[1] == a[3]):\n print(0,end=\" \")\nelse:\n print(1 if abs(a[0]-a[2]) == abs(a[1]-a[3]) else 2,end=\" \")\nprint(abs(a[0] - a[2]) + max(abs(a[1] - a[3]) - (abs(a[0] - a[2])),0))", "r1, c1, r2, c2 = list(map(int, input().rstrip().split()))\nhook = 0\nif r1!=r2:\n hook += 1\nif c1 != c2:\n hook += 1\nbishop = 0\nking = 0\n# For king\nr = abs(r1 - r2)\nc = abs(c1 - c2)\nking += min(r, c)\nif r2 >= r1:\n rx = king + r1\nelse:\n rx = r1 - king\nif c2 >= c1:\n cx = king + c1\nelse:\n cx = c1 - king\nking += max(abs(r2 - rx), abs(c2 - cx))\nif r == c:\n bishop = 1\nelif (r + c) % 2 == 0:\n bishop = 2\nelse:\n bishop = 0\n\n\nprint(hook,bishop,king)", "# 84\r\nr1 , c1 , r2 , c2 = [int(x) for x in input().split()]\r\n\r\n#Rock\r\nrock = 2\r\nif r1 == r2 or c1 == c2:\r\n rock = 1\r\n\r\n#Bishop\r\nbishop = 2\r\nif (r1 + c1) % 2 != (r2 + c2) % 2:\r\n bishop = 0\r\nelif abs(r1 - r2) == abs(c1 - c2):\r\n bishop = 1\r\n\r\n#king\r\nking = max([abs(r1 - r2) , abs(c1 - c2)])\r\n\r\nprint(rock , bishop , king)", "def same_diagonal(x1, y1, x2, y2):\r\n return x1 - y1 == x2 - y2 or x1 + y1 == x2 + y2\r\n \r\ndef same_row_or_col(x1, y1, x2, y2):\r\n return x1 == x2 or y1 == y2\r\n \r\ndef isBlack(x, y):\r\n return (x % 2 == 0 and y % 2) or (x % 2 and y % 2 == 0) \r\n \r\ndef main():\r\n x1, y1, x2, y2 = map(int, input().split())\r\n rook , bishop, king = 0, 0, 0\r\n if same_row_or_col(x1, y1, x2, y2):\r\n rook = 1\r\n else:\r\n rook = 2\r\n \r\n if (isBlack(x1, y1) ^ isBlack(x2, y2)):\r\n bishop = 0\r\n elif same_diagonal(x1, y1, x2, y2):\r\n bishop = 1\r\n else:\r\n bishop = 2\r\n \r\n king = max(abs(y2-y1), abs(x2-x1))\r\n print(rook, bishop, king)\r\nmain()", "# full logic before coding\r\n\r\n# notc = int(input())\r\n\r\n# for i in range(notc):\r\nr1, c1, r2, c2 = map(int, input().split())\r\n\r\nrook, bishop, king = 0, 0, 0\r\n\r\ndiff_r = abs(r1 - r2)\r\ndiff_c = abs(c1 - c2)\r\n\r\nif diff_r == 0 or diff_c == 0:\r\n rook = 1\r\nelse:\r\n rook = 2\r\n\r\nif (diff_r + diff_c)%2 == 0:\r\n if diff_r == diff_c:\r\n bishop = 1\r\n else:\r\n bishop = 2\r\nelse:\r\n bishop = 0\r\n\r\nking = diff_r + diff_c - min(diff_r, diff_c)\r\n\r\nprint(rook, bishop, king)", "r1, c1, r2, c2 = list(map(int, input().split(' ')))\r\n\r\n#if initially at black or white\r\nx, y = abs(r1-r2), abs(c1-c2)\r\n\r\ninitial = 0\r\n\r\nif x == 0 and y == 0:\r\n print(0, 0, 0)\r\n \r\nelse:\r\n\r\n# if (r1 + c1)%2 == 0:\r\n# initial = 1 #at black\r\n# else:\r\n# inital = 0#at white\r\n \r\n king = min(x, y)\r\n kmoves = king + abs(x - y)\r\n \r\n if x == 0 or y == 0:\r\n rmoves = 1\r\n else:\r\n rmoves = 2\r\n \r\n if (r2 + c2)%2 != (r1 + c1)%2:\r\n bmoves = 0\r\n \r\n else:\r\n if x == y:\r\n bmoves = 1\r\n else:\r\n bmoves = 2\r\n \r\n# print(initial, (r2 + c2)%2)\r\n print(rmoves, bmoves, kmoves)\r\n \r\n \r\n \r\n \r\n\r\n", "r1,c1,r2,c2 = map(int,input().split())\nif (r1+c1)%2!=(r2+c2)%2:\n\tb = 0\nelse:\n\tif abs(r1-r2)==abs(c1-c2):\n\t\tb = 1\n\telse:\n\t\tb = 2\nif r1==r2 or c1==c2:\n\tr = 1\nelse:\n\tr = 2\nx = abs(r1-r2)\ny = abs(c1-c2)\nk = max(x,y)\nprint (r,b,k)", "r1,c1,r2,c2=map(int,input().split())\nselisihr=abs(r2-r1)\nselisihc=abs(c2-c1)\nprint((1 if selisihr==0 or selisihc==0 else 2),end=' ')\nprint((0 if (selisihr+selisihc)%2==1 else 1 if selisihr==selisihc else 2),end=' ')\nprint(max(selisihr,selisihc))\n\t\t\t\t\t\t \t \t\t\t \t\t\t\t\t\t \t \t \t", "def ld(r1,c1,r2,c2):\r\n if r1 == r2 or c1 == c2:\r\n return 1\r\n else :\r\n return 2\r\ndef sl(r1,c1,r2,c2):\r\n if sum((r1,c1,r2,c2))%2 != 0:\r\n return 0\r\n else:\r\n if abs(r1-r2) == abs(c1-c2):\r\n return 1\r\n else:\r\n return 2\r\ndef kr(r1,c1,r2,c2) :\r\n return min(abs(c1-c2),abs(r1-r2)) + abs(abs(c1-c2)-abs(r1-r2))\r\n \r\n\r\nr1,c1,r2,c2 = (int(x) for x in input().split())\r\nprint(ld(r1,c1,r2,c2),sl(r1,c1,r2,c2),kr(r1,c1,r2,c2))", "r1,c1,r2,c2 = map(int,input().split())\r\nif r1 == r2 or c1 == c2:\r\n print(\"1\",end=\" \")\r\nelse:\r\n print(\"2\",end=\" \")\r\nif (r1+c1)%2 != (r2+c2)%2:\r\n print(\"0\",end=\" \")\r\nelif abs(r2-r1) == abs(c2-c1):\r\n print(\"1\",end=\" \")\r\nelse:\r\n print(\"2\",end=\" \")\r\nprint(max(abs(r2-r1),abs(c2-c1)),end=\"\")", "r1, c1, r2, c2 = map(int, input().split())\r\n\r\ndef rookMoves():\r\n return 1 if r1 == r2 or c1 == c2 else 2\r\ndef bishopMoves():\r\n if (r1 + c1) % 2 != (r2 + c2) % 2:\r\n return 0\r\n if r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2:\r\n return 1\r\n return 2\r\ndef kingMoves():\r\n return max(abs(r1 - r2), abs(c1 - c2))\r\n\r\nprint(rookMoves(), bishopMoves(), kingMoves())", "r1,c1,r2,c2 = map(int, input().split())\r\nif r1==r2 or c1==c2:\r\n x=1\r\nelse:\r\n x=2\r\nif (r1+c1)%2 != (r2+c2)%2:\r\n y=0\r\nelse:\r\n if r1+c1==r2+c2 or r1-c1 == r2-c2:\r\n y=1\r\n else:\r\n y=2\r\nz=max(abs(r2-r1), abs(c2-c1))\r\nprint(x,y,z)\r\n", "r1, c1, r2, c2 = map(int, input().split())\nrook = 0\nbishop = 0\nking = 0\n\nif r1 == r2 or c1 == c2:\n rook = 1\nelse:\n rook = 2\n\nif (r1%2 == r2%2 and c1%2 == c2%2) or (r1%2 != r2%2 and c1%2 != c2%2):\n if abs(r2-r1) == abs(c2-c1):\n bishop = 1\n else:\n bishop = 2\nelse:\n bishop = 0\n\nking = max(abs(r2-r1), abs(c2-c1))\n\nif r1 == r2 and c1 == c2:\n rook = 0\n bishop = 0\n king = 0\n\nprint(\"%d %d %d\" %(rook, bishop, king))\n\n \t\t \t\t \t \t\t \t\t\t\t\t \t \t \t\t\t\t\t\t", "WHITE, BLACK = 1, -1\n\n\nr1, c1, r2, c2 = map(int, input().split())\n\ncolor_start = WHITE if (r1 + c1) % 2 == 0 else BLACK\ncolor_end = WHITE if (r2 + c2) % 2 == 0 else BLACK\n\nrook = 1 if r1 == r2 or c1 == c2 else 2\n\nbishop = 0\nif color_start == color_end:\n same_diagonal = r1-c1 == r2-c2 or r1+c1 == r2+c2\n bishop = 1 if same_diagonal else 2\n\nking = max(abs(r1 - r2), abs(c1 - c2))\n\nprint(rook, bishop, king)\n \t\t\t \t \t\t \t \t \t \t", "import math\r\nA=list(map(int,input().split()))\r\nr1=A[0]\r\nc1=A[1]\r\nr2=A[2]\r\nc2=A[3]\r\nif r1==r2 or c1==c2:\r\n if r1==r2:\r\n mi_rey=abs(c1-c2)\r\n else:\r\n mi_rey=abs(r1-r2)\r\nelse:\r\n mi_rey=max(abs(r1-r2),abs(c1-c2))\r\n\r\nmi_torre= 1 if(r1==r2 or c1==c2) else 2\r\nif((r1+c1)%2!=(r2+c2)%2):\r\n mi_alfil=0\r\nelse:\r\n if c1==(-r1+(c2+r2))or c1==(r1+(c2-r2)):\r\n mi_alfil=1\r\n else:\r\n mi_alfil=2\r\n \r\n\r\nprint(mi_torre)\r\nprint(mi_alfil)\r\nprint(mi_rey)", "r1, c1, r2, c2 = [int(x) for x in input().split()];r = 2;b = 0\r\nif (r1-r2) == 0 or (c1-c2) == 0:r = 1\r\nif (r1+c1) % 2 == (r2+c2) % 2:\r\n if abs(r1-r2) == abs(c1-c2):b = 1\r\n else:b = 2\r\nk = max(abs(r1-r2), abs(c1-c2))\r\nprint(r, b, k)\r\n", "while True:\n try:\n l = input().split(' ')\n r1, c1, r2, c2 = int(l[0]), int(l[1]), int(l[2]), int(l[3])\n except:\n break\n flag2 = 0\n if (r1 == r2 and c1 != c2) or (c1 == c2 and r1 != r2):\n flag2 = 1\n print(\"1 \",end='')\n else:\n print(\"2 \",end = '')\n flag1 = 0\n if (abs(r1 - r2) == abs(c1 - c2)):\n\n print(\"1 \",end = '')\n\n flag1 = 1\n else:\n t1 = r1 + c1\n if (r2 > c2):\n t2 = r2 - c2\n else:\n t2 = c2 - r2\n if ((t1 + t2) % 2 == 0):\n print(\"2 \",end='')\n else:\n print(\"0 \",end='')\n if flag2:\n print( abs(r1 - r2) + abs(c1 - c2))\n elif flag1=='1':\n print( abs(r1 - r2))\n elif (abs(r1 - r2) < abs(c1 - c2)):\n print( abs(c1 - c2))\n else:\n print(abs(r1 - r2))\n\n\t \t \t\t\t\t \t\t\t\t\t\t\t \t \t \t\t\t\t", "# Anuneet Anand\r\n \r\na,b,x,y = map(int,input().split())\r\n \r\nr = int(x!=a)+int(y!=b)\r\nk = min(abs(x-a),abs(y-b))+(max(abs(x-a),abs(y-b))-min(abs(x-a),abs(y-b)))\r\nif (x+y)%2!=(a+b)%2:\r\n\tp = 0\r\nelse:\r\n\tp = 1+int((abs(x-a))!=(abs(y-b)))\r\n \r\nprint(r,p,k)\r\n", "def rooksMove(r1, c1, r2, c2):\n if r1 == r2 and c1 == c2:\n return 0\n elif r1 == r2 or c1 == c2:\n return 1\n else:\n return 2\n\ndef kingsMove(r1, c1, r2, c2):\n if r1 == r2 and c1 == c2:\n return 0\n return max(abs(r1 - r2), abs(c1 - c2))\n\ndef bishopsMove(r1, c1, r2, c2):\n if r1 == r2 and c1 == c2:\n return 0\n elif (r1 + c1) % 2 != (r2 + c2) % 2:\n return 0\n elif abs(r1 - r2) == abs(c1 - c2):\n return 1\n else:\n return 2\n\nr1, c1, r2, c2 = map(int, input().split())\n\nprint(\n rooksMove(r1, c1, r2, c2),\n bishopsMove(r1, c1, r2, c2),\n kingsMove(r1, c1, r2, c2)\n)\n\n \t \t \t\t\t\t \t \t\t\t \t\t\t\t\t \t", "def king(r1, c1, r2, c2):\n diag = min(abs(r1 - r2), abs(c1 - c2))\n res = abs(r2- r1) + abs(c2 - c1) - diag\n return res\n\ndef rook(r1, c1, r2, c2):\n res = (1 if r1 != r2 else 0) + (1 if c1 != c2 else 0)\n return res\n\ndef bishop(r1, c1, r2, c2):\n if (r1 + c1) % 2 != (r2 + c2) % 2:\n return 0\n res = (1 if r1 - c1 != r2 - c2 else 0) + (1 if r1 - (8-c1) != r2 - (8-c2) else 0)\n return res\n \n\n\ndef main():\n r1, c1, r2, c2, = list(map(int, input().split()))\n res_k = king(r1, c1, r2, c2)\n res_r = rook(r1, c1, r2, c2)\n res_b = bishop(r1, c1, r2, c2)\n print(f\"{res_r} {res_b} { res_k}\")\nmain()\n\t \t \t \t \t \t \t \t\t \t\t\t\t\t \t", "# for _ in range(int(input())):\r\n # n=int(input())\r\na,b,c,d=map(int,input().split())\r\n # a=list(map(int,input().split()))\r\n # \r\nif(a==c and b==d):\r\n r=bi=0 \r\nelif(a==c or b==d):\r\n r=1\r\nelse:\r\n r=2\r\nif((a+b+c+d)%2==0):\r\n m=abs(a-c)\r\n n=abs(b-d)\r\n if(m==n):\r\n bi=1\r\n else:\r\n bi=2\r\nelse:\r\n bi=0\r\nk=max(abs(a-c),abs(b-d))\r\nprint(r,bi,k)", "inputs = input()\n\nvalues = inputs.split()\n\npos = {\n \"r1\": int(values[0]),\n \"r2\": int(values[2]),\n \"c1\": int(values[1]),\n \"c2\": int(values[3]) \n}\n\ntorre = 0\nif pos[\"r1\"] == pos[\"r2\"] or pos[\"c1\"] == pos[\"c2\"]:\n torre = 1\nelse:\n torre = 2\n\nbispo = 0\nblack_i = False\nblack_j = False\n\nif pos[\"r1\"] % 2 == 0 and pos[\"c1\"] % 2 == 0:\n black_i = False\nelif pos[\"r1\"] % 2 != 0 and pos[\"c1\"] % 2 != 0:\n black_i = False\nelse:\n black_i = True\n\nif pos[\"r2\"] % 2 == 0 and pos[\"c2\"] % 2 == 0:\n black_j = False\nelif pos[\"r2\"] % 2 != 0 and pos[\"c2\"] % 2 != 0:\n black_j = False\nelse:\n black_j = True\n\nif black_i == black_j:\n if abs(pos['r1'] - pos['r2']) == abs(pos['c1'] - pos['c2']):\n bispo = 1\n else:\n bispo = 2\nelse:\n bispo = 0\n\nrei = max(abs(pos[\"r1\"] - pos[\"r2\"]), abs(pos[\"c1\"] - pos[\"c2\"]))\n\n\nprint(f'{torre} {bispo} {rei}')\n\n\t\t \t \t \t \t \t\t \t\t\t\t", "r1,c1,r2,c2 = map(int,input().split())\r\nrock = bishop = king = 0\r\nrock = (r1 != r2) + (c1 != c2)\r\nif (r1 - r2 ) % 2 == (c1 - c2) % 2:\r\n bishop = 1 if abs(r1 - r2) == abs(c1 - c2) else 2\r\nelse:\r\n bishop = 0\r\nking = max(abs(r1 - r2), abs(c1 - c2))\r\nprint(f\"{rock} {bishop} {king}\") ", "r1,c1,r2,c2 = list(map(int,input().split(\" \")))\r\nrook = 2\r\nif(r1==r2 or c1==c2): rook = 1\r\nbishop = 2\r\nif (r1+c1)%2 != (r2+c2)%2: bishop = 0\r\nelif abs(r2-r1)==abs(c2-c1): bishop=1\r\nking = max([abs(r2-r1),abs(c2-c1)])\r\nprint(rook,bishop,king)", "def main():\n r1, c1, r2, c2 = map(int, input().split())\n _1, _2, _3 = 2, 2, 0\n \n if r1 == r2 or c1 == c2:\n _1 = 1\n \n if (r1+c1) % 2 != (r2+c2) % 2:\n _2 = 0\n elif r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2:\n _2 = 1\n\n _3 = max(abs(r1-r2), abs(c1-c2))\n print(_1, _2, _3)\n\n\nif __name__ == '__main__':\n main()\n\n", "\r\nr1,c1,r2,c2 = map(int,input().split())\r\nif r1==r2 or c1==c2:\r\n print(1,end=\" \")\r\nelse:\r\n print(2,end=\" \")\r\nif (r1+c1)%2!=(r2+c2)%2:\r\n print(0,end=\" \")\r\nelse:\r\n if r1+c1==r2+c2 or r1-c1==r2-c2:\r\n print(1,end=\" \")\r\n else:\r\n print(2,end=\" \")\r\nprint(max(abs(r1-r2),abs(c1-c2)))", "a = list(map(int, input().split()))\ny1 = a[0]\nd1 = a[1]\ny2 = a[2]\nd2 = a[3]\nyatay = abs(y1 - y2)#0\ndikey = abs(d1 - d2)#1\na = [0, 0 , 0]\n# kale fil şah\n\nif yatay == 0 or dikey == 0:\n a[0] = 1\nelse:\n a[0] = 2\n\nif ((y1+d1) % 2) == ((y2+d2) % 2):\n if yatay == dikey:\n a[1] = 1\n else:\n a[1] = 2\nelse:\n a[1] = 0\n\nif yatay == dikey:\n a[2] = yatay\nelse:\n a[2] = abs(yatay - dikey) + min(yatay, dikey)\nprint(*a)", "y1, x1, y2, x2 = map(int, input().split())\r\n# r b k\r\nif y1==y2 and x1==x2:\r\n\tprint(0, 0, 0)\r\n\t# it guaranted by task\r\nelse:\r\n\t# rook\r\n\t#print(\"rook\")\r\n\tif y1==y2 or x1==x2:\r\n\t\tprint(1, end=\" \")\r\n\telse:\r\n\t\tprint(2, end=\" \")\r\n\t# bishop\r\n\t#print(\"bishop\")\r\n\tif ((y1%2 == x1%2) and (y2%2 == x2%2)) or ((y1%2 != x1%2) and (y2%2 != x2%2)):\r\n\t\t\t# can\r\n\t\tif abs(y2-y1)==abs(x2-x1):\r\n\t\t\t\tprint(1, end=\" \")\r\n\t\telse:\r\n\t\t\t\tprint(2, end=\" \")\r\n\telse:\r\n\t\t\tprint(0, end=\" \")\r\n\t# king\r\n\t#print(\"king\")\r\n\tdy = abs(y1-y2)\r\n\tdx = abs(x1-x2)\r\n\tres = min(dy, dx)\r\n\tres += max(dy, dx) - min(dy, dx)\r\n\tprint(res)", "x1, y1, x2, y2 = map(int, input().split())\r\nn = 8\r\n\r\n\r\ndef check(x):\r\n return 1 <= x <= n\r\n\r\n\r\ndef get_nbs_sl(x, y):\r\n for i in range(-8, 9):\r\n a, b = x + i, y + i\r\n c, d = x - i, y + i\r\n if i == 0:\r\n continue\r\n\r\n if check(a) and check(b):\r\n yield (a, b)\r\n\r\n if check(c) and check(d):\r\n yield (c, d)\r\n\r\n\r\ndef get_nbs_ld(x, y):\r\n for i in range(1, n + 1):\r\n if i != x:\r\n yield (i, y)\r\n for i in range(1, n + 1):\r\n if i != y:\r\n yield (x, i)\r\n\r\n\r\ndef get_nbs_king(x, y):\r\n for i in range(-1, 2):\r\n for j in range(-1, 2):\r\n nx, ny = x + i, y + j\r\n if (nx, ny) != (x, y) and check(nx) and check(ny):\r\n yield (nx, ny)\r\n\r\n\r\ndef bfs(start_x, start_y, fin_x, fin_y, get_nbs):\r\n dist = {(start_x, start_y): 0}\r\n q = [(start_x, start_y)]\r\n while q:\r\n v = q.pop(0)\r\n # print(v)\r\n for u in get_nbs(v[0], v[1]):\r\n if u not in dist:\r\n dist[u] = dist[v] + 1\r\n q.append(u)\r\n if (fin_x, fin_y) in dist:\r\n return dist[(fin_x, fin_y)]\r\n else:\r\n return 0\r\n\r\n\r\nld = bfs(x1, y1, x2, y2, get_nbs_ld)\r\nsl = bfs(x1, y1, x2, y2, get_nbs_sl)\r\nkk = bfs(x1, y1, x2, y2, get_nbs_king)\r\n\r\nprint(ld, sl, kk)\r\n", "import math\r\nx1,y1,x2,y2 = tuple(int(i) for i in input().split())\r\nV = [[0 for j in range(10)] for i in range(10)]\r\n\r\ndef black(x,y):\r\n\tif(x%2==1):\r\n\t\treturn y%2==1\r\n\telse:\r\n\t\treturn y%2==0\r\na = 2\r\nb = 0\r\nc = 0\r\n\r\nif(x1==x2):\r\n\ta-=1\r\nif(y1==y2):\r\n\ta-=1\r\n\r\nif(abs(x1-x2)==abs(y1-y2)):\r\n\tb=1\r\nelif black(x1,y1)==black(x2,y2):\r\n\tb=2\r\nelse:\r\n\tb=0\r\n\r\nc = max(abs(x1-x2),abs(y1-y2))\r\nprint(a,b,c)", "# total time:O(N)+O(logN)+O(N)\ndef chess(r1,c1,r2,c2):\n #moves\n board = []\n row = []\n rook = 0\n bishop = 0\n king = 0\n r1 -=1\n c1 -=1\n r2-=1\n c2-=1\n #rook\n if r1!=r2 and c1!=c2:\n rook=2\n elif r1==r2 and c1==c2:\n rook=0\n bishop =0\n king = 0\n else:\n rook=1\n #bishop\n for y in range(8):\n lst=[]\n for j in range(8):\n lst.append(-1)\n board.append(lst)\n # board = [[-1]*8]*8\n #bishop can't go to position\n if (r1+c1)%2!=(r2+c2)%2 or (r1==r2 and c1==c2):\n bishop = 0\n else:\n possible1 = bishopMove(r1, c1, r2,c2, -1, 1) or bishopMove(r1, c1, r2,c2, -1, -1) or bishopMove(r1, c1, r2,c2, 1, -1) or bishopMove(r1, c1, r2,c2, 1, 1)\n if possible1:\n bishop=1\n else:\n bishop=2\n kingMove(r1,c1, board)\n king = board[r2][c2]\n print(rook, bishop, king)\n\n\ndef kingMove(r1, c1, board):\n queue=[[r1,c1]]\n # print(board)\n board[r1][c1] = 0\n position = 0\n # print(board)\n while len(queue)>position:\n c = queue[position]\n move = board[c[0]][c[1]]\n # print(c[0], c[1], move)\n kingPossibleMove(c[0],c[1]+1, move, board, queue)\n kingPossibleMove(c[0]+1,c[1], move, board, queue)\n kingPossibleMove(c[0]+1,c[1]+1, move, board, queue)\n kingPossibleMove(c[0]+1,c[1]-1, move, board, queue)\n kingPossibleMove(c[0]-1,c[1]+1, move, board, queue)\n kingPossibleMove(c[0]-1,c[1]-1, move, board, queue)\n kingPossibleMove(c[0]-1,c[1], move, board, queue)\n kingPossibleMove(c[0],c[1]-1, move, board, queue)\n position+=1\n # for i in range(8):\n # print(board[i])\n\ndef kingPossibleMove(r1,c1, move, board, queue): \n if r1>=0 and r1<=7 and c1>=0 and c1<=7 and board[r1][c1] == -1:\n board[r1][c1]= move+1\n queue.append([r1, c1])\n\ndef bishopMove(r1, c1, r2, c2, x, y):\n while r1<=7 and r1>=0 and c1<=7 and c1>=0:\n r1+=x\n c1+=y\n if r1==r2 and c1==c2:\n return True\n return False\n\n\n \nif __name__ == '__main__':\n #Case 1 output expected: 2\n i = input()\n inp = i.split(' ')\n chess(int(inp[0]), int(inp[1]), int(inp[2]), int(inp[3]))\n", "def rook(r1,c1,r2,c2):\r\n if(r1==r2 or c1==c2):\r\n return 1\r\n else:\r\n return 2\r\n \r\n\r\ndef bishop(r1,c1,r2,c2):\r\n if((r1+c1)%2!=(r2+c2)%2):\r\n return 0\r\n else:\r\n if(r1+c1==r2+c2 or r1-c1==r2-c2):\r\n return 1\r\n else:\r\n return 2\r\n \r\n \r\n \r\ndef king(r1,c1,r2,c2):\r\n return(max(abs(r1-r2),abs(c1-c2)))\r\n \r\n\r\nr1,c1,r2,c2=map(int,input().split())\r\n\r\nx=rook(r1,c1,r2,c2)\r\ny=bishop(r1,c1,r2,c2)\r\nz=king(r1,c1,r2,c2)\r\nprint(x,y,z)\r\n", "def rook(a,b,c,d):\n res=0\n if a!=c:\n res+=1\n if b!=d:\n res+=1\n return res\n\ndef bishop(a,b,c,d):\n res=0\n if abs(a-c)==abs(b-d):\n res=1\n elif (abs(a-c)%2==0 and abs(b-d)%2==0) or (abs(a-c)%2==1 and abs(b-d)%2==1):\n res=2\n return res\n\nloc=input().split()\nking = max(abs(int(loc[0])-int(loc[2])),abs(int(loc[1])-int(loc[3])))\nprint(rook(loc[0],loc[1],loc[2],loc[3]),\n bishop(int(loc[0]),int(loc[1]),int(loc[2]),int(loc[3])),king)\n\n\t\t\t \t \t \t\t\t \t \t\t\t\t\t \t", "r1, c1, r2, c2 = list(map(int, input().split(\" \")))\r\n\r\nif r1 == r2 or c1 == c2:\r\n print(1, end=\" \")\r\nelse:\r\n print(2, end=\" \")\r\n\r\nif (r1 + c1) %2 != (r2 + c2) %2:\r\n print(0, end=\" \")\r\nelse:\r\n if r1+c1 == r2 + c2 or r1-c1 == r2-c2:\r\n print(1, end=\" \")\r\n else:\r\n print(2, end=\" \")\r\n\r\nprint(max(abs(c1-c2), abs(r1-r2)))", "l = list(map(int, input().split()))\n\nx = l[0]\ny = l[1]\na = l[2]\nb = l[3]\n\nif x == a or y == b:\n print(\"1\", end=\" \")\nelse:\n print(\"2\", end=\" \")\n\nif (x + y) % 2 != (a + b) % 2:\n print(\"0\", end=\" \")\nelif abs(x - a) == abs(y - b):\n print(\"1\", end=\" \")\nelse:\n print(\"2\", end=\" \")\n\nprint(max(abs(x - a), abs(y - b)))\n\n\t\t \t \t\t\t\t \t \t \t\t \t\t \t\t\t\t", "r1, c1, r2, c2 = [int(i) for i in input().split()]\nif (r1 == r2 or c1 == c2):\n\tprint(1, end=' ')\nelse:\n\tprint(2, end=' ')\nif ((r1 + c1)%2 != (r2 + c2)%2):\n\tprint(0, end=' ')\nelif (abs(r2 - r1) == abs(c2 - c1)):\n\tprint(1, end=' ')\nelse:\n\tprint(2, end=' ')\nprint(max(abs(r2 - r1), abs(c2 - c1) ) )", "a, b, c, d = map(int, input().split())\r\n\r\nif a == c or b == d:\r\n print(1, end = \" \")\r\nelse:\r\n print(2, end = \" \")\r\n\r\n\r\nif (a + b) % 2 == 0 and (c + d) % 2 == 1:\r\n print(0, end = \" \")\r\n\r\nelif (a + b) % 2 == 1 and (c + d) % 2 == 0:\r\n print(0, end = \" \")\r\n\r\nelse:\r\n if abs(a - c) == abs(d - b):\r\n print(1, end = \" \")\r\n else:\r\n print(2, end = \" \")\r\n\r\n\r\nf = min(abs(a-c), abs(d-b))\r\ng = max(abs(a-c), abs(d-b))\r\n\r\nprint(f + (g-f))\r\n\r\n\r\n\n# Tue Jul 11 2023 13:21:56 GMT+0300 (Moscow Standard Time)\n", "r1,c1,r2,c2 = list(map(int,input().split()))\r\n\r\nrook,bishop,king = 0,0,0\r\n\r\nif r1 == r2 and c1 == c2:\r\n rook = 0\r\nelif r1 == r2 or c1 == c2:\r\n rook = 1\r\nelse:\r\n rook = 2\r\n \r\nking = max(abs(r1-r2),abs(c1-c2))\r\n\r\n\r\nif (r1+r2)%2 == (c1+c2)%2:\r\n if r1 == r2 and c1 == c2:\r\n bishop = 0\r\n elif abs(r1-r2) == abs(c1-c2):\r\n bishop = 1\r\n else:\r\n bishop = 2\r\n \r\nprint(rook, bishop, king)", "import sys\r\nimport math\r\nimport bisect\r\nimport heapq\r\nimport itertools\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict, Counter, deque\r\nfrom bisect import bisect_left,bisect_right, insort_left, insort_right\r\n\r\nmod=1000000007\r\n\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_string(): return sys.stdin.readline().strip()\r\ndef get_int(): return int(sys.stdin.readline().strip())\r\ndef get_list_strings(): return list(map(str, sys.stdin.readline().strip().split()))\r\n\r\n\r\n\r\ndef solve():\r\n r1, c1, r2, c2 = get_ints()\r\n \r\n print(1, end = \" \") if r1 == r2 or c1 ==c2 else print(2, end = \" \")\r\n if (r1 + c1) % 2 != (r2 + c2) % 2:\r\n print(0, end = \" \")\r\n else:\r\n print(1, end = \" \") if abs(r1 - r2) == abs(c1 - c2) else print(2, end = \" \")\r\n print(max(abs(r1 - r2), abs(c1 - c2))) \r\n \r\nif __name__ == \"__main__\":\r\n solve()", "\r\ndef foo():\r\n inp = input()\r\n r1, c1, r2, c2 = map(int, inp.split())\r\n if (r1 == r2 or c1 == c2):\r\n print(\"1\", end = \" \")\r\n else:\r\n print(\"2\", end = \" \")\r\n\r\n if ((r1 + c1) % 2) != ((r2 + c2) % 2):\r\n print(\"0\", end = \" \")\r\n elif (r1 - c1 == r2 - c2 or r1 + c1 == r2 + c2):\r\n print(\"1\", end = \" \")\r\n else:\r\n print(\"2\", end = \" \")\r\n\r\n print(max(abs(r1 - r2), abs(c1 - c2)))\r\n\r\nfoo()", "r,c,x,y=map(int,input().split())\n\ndef king(r,c,x,y):\n return (max(abs(r-x),abs(c-y)))\ndef bishop(r,c,x,y):\n if abs(y - c) == abs(x - r):\n return 1\n elif (abs(r - x) + abs(c - y)) % 2 == 1:\n return 0\n else:\n return 2\ndef rook(r,c,x,y):\n if r==x or c==y:\n return 1\n else: return 2\nR=rook(r,c,x,y)\nB=bishop(r,c,x,y)\nK=king(r,c,x,y)\nprint(R,B,K)\n", "import math\r\n\r\n\r\ndef main_function():\r\n r_1, c_1, r_2, c_2 = [int(i) for i in input().split(\" \")]\r\n move_rook = 0\r\n move_bishop = 0\r\n move_king = 0\r\n if r_1 == r_2 and c_1 == c_2:\r\n pass\r\n else:\r\n if r_1 == r_2 or c_1 == c_2:\r\n move_rook = 1\r\n else:\r\n move_rook = 2\r\n move_king = max(abs(c_2 - c_1), abs(r_2 - r_1))\r\n if ((r_1 + c_1) % 2 == 0 and (r_2 + c_2) % 2 == 0) or ((r_1 + c_1) % 2 == 1 and (r_2 + c_2) % 2 == 1):\r\n if r_1 - c_1 == r_2 - c_2 or r_1 + c_1 == r_2 + c_2:\r\n move_bishop = 1\r\n else:\r\n move_bishop = 2\r\n else:\r\n pass\r\n print(str(move_rook) + \" \" + str(move_bishop) + \" \" + str(move_king))\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nmain_function()\r\n", "from math import fabs\r\na=[int(i)for i in input().split()]\r\nif(a[0]==a[2])|(a[1]==a[3]):print(1,end=' ')\r\nelse:print(2,end=' ')\r\nb,c=fabs(a[2]-a[0]),fabs(a[3]-a[1])\r\nif b%2!=c%2:print(0,end=' ')\r\nelif b==c:print(1,end=' ')\r\nelse:print(2,end=' ')\r\nprint(int(max(fabs(a[2]-a[0]),fabs(a[3]-a[1]))))", "import sys\nr1,c1,r2,c2 = map(int, input().split())\nfirst = 1 if r1==r2 or c1==c2 else 2\nsecond = 1 if abs(r1-r2)==abs(c1-c2) else 0 if (r1+r2+c1+c2)%2 == 1 else 2\nthird = max(abs(r1-r2),abs(c1-c2))\nprint(str(first) + \" \" + str(second)+\" \"+str(third))", "r1,c1,r2,c2=map(int,input().split())\nking=max(abs(r1-r2),abs(c1-c2))\nrook=1 if r1==r2 or c1==c2 else 2\nif abs(r1-r2)==abs(c1-c2):\n bishop=1\nelif abs(r1-r2)%2==abs(c1-c2)%2:\n bishop=2\nelse:\n bishop=0\nprint(rook,bishop,king)\n", "x,y,x1,y1=map(int,input().split())\r\nif x1==x or y1==y:\r\n print(1,end=' ')\r\nelse:\r\n print(2,end=' ')\r\nif (x+y)%2!=(x1+y1)%2:\r\n print(0,end=' ')\r\nelif abs(x-x1)==abs(y-y1):\r\n print(1,end=' ')\r\nelse:\r\n print(2,end=' ')\r\nif x1==x :\r\n print(abs(y-y1),end=' ')\r\nelif y1==y :\r\n print(abs(x-x1),end=' ')\r\nelse:\r\n print(abs(abs(x-x1)-abs(y-y1))+min(abs(x-x1),abs(y-y1)),end=' ')", "x0, y0, xf, yf = [int(item) for item in input().split()]\n\nmv_rook, mv_bishop, mv_king = 0, 0, 0\n\n# Rook\nif abs(x0 - xf) > 0:\n mv_rook += 1\nif abs(y0 - yf) > 0:\n mv_rook += 1\n\n# Bishop\nif (x0 + y0) % 2 == (xf + yf) % 2:\n if (x0 + y0) == (xf + yf) or (x0 - y0) == (xf - yf):\n mv_bishop = 1\n else:\n mv_bishop = 2\nelse:\n mv_bishop = 0\n\n# King\nmv_king = max(abs(x0 - xf), abs(y0 - yf))\n\nprint(mv_rook, mv_bishop, mv_king)\n\n \t\t\t \t \t \t \t\t\t\t \t\t \t\t", "r1, c1, r2, c2 = map(int, input().split())\r\n\r\nx, y = abs(r2 - r1), abs(c2 - c1)\r\n\r\nr, b, k = 2, 2, max(x, y)\r\n\r\nif r1 == r2 or c1 == c2:\r\n\tr = 1\r\n\r\nif x == y:\r\n\tb = 1\r\nelif (x - y) % 2 != 0:\r\n\tb = 0\r\n\t\r\nprint(r, b, k)", "x_now, y_now, aim_x, aim_y = map(int, input().split())\r\nans = []\r\nif x_now == aim_x or y_now == aim_y: ans.append('1')\r\nelse: ans.append('2')\r\nif (x_now + y_now)%2 == (aim_x + aim_y)%2:\r\n if abs(x_now - aim_x) == abs(y_now - aim_y): ans.append('1')\r\n else: ans.append('2')\r\nelse: ans.append('0')\r\nans.append(str(max(abs(aim_x-x_now),abs(aim_y-y_now))))\r\nprint(' '.join(ans))", "def move(r1, c1, r2, c2):\r\n if r2 == r1 or c2 == c1:\r\n l = 1\r\n else:\r\n l = 2\r\n\r\n k = max(abs(r2 - r1), abs(c2 - c1))\r\n\r\n if ((r1 + c1) % 2) == ((r2 + c2) % 2):\r\n if abs(r2 -r1) == abs(c2 - c1):\r\n s = 1\r\n else:\r\n s = 2\r\n else:\r\n s = 0\r\n return l, k, s\r\n\r\nr1, c1, r2, c2 = map(int, input().split())\r\nl, k, s = move(r1, c1, r2, c2)\r\n\r\nprint(l, s, k)\r\n", "\t\t###~~~LOTA~~~###\r\na,b,x,y=map(int,input().split())\r\nif a==x and b==y:\r\n\tprint(0,0,0)\r\nelse:\r\n\tif a==x or b==y:\r\n\t\tprint(1,end=' ')\r\n\telse:\r\n\t\tprint(2,end=' ')\r\n\tn=abs(a-x)\r\n\tm=abs(b-y)\r\n\tif (n+m)%2==0:\r\n\t\tif n==m:\r\n\t\t\tprint(1,end=' ')\r\n\t\telse:\r\n\t\t\tprint(2,end=' ')\r\n\telse:\r\n\t\tprint(0,end=' ')\r\n\tprint(max(n,m))", "x1,y1,x2,y2 = list(map(int,input().split()))\r\narr = [min(abs(x1-x2),1) + min(abs(y1-y2),1),(1 if abs(x1-x2) == abs(y1-y2) else 2) if (x1&1^y1&1)==(x2&1^y2&1) else 0,max(abs(y2-y1),abs(x2-x1))]\r\nprint(*arr)", "r1, c1, r2, c2 = map(int, input().split())\r\na = 0\r\nb = 0\r\n\r\nif r1==r2 or c1==c2:\r\n a=1\r\nelse:\r\n a=2\r\nif (r1+c1)%2!=(r2+c2)%2:\r\n b=0\r\nelif r1+c1==r2+c2 or r1-c1==r2-c2:\r\n b=1\r\nelse:\r\n b=2\r\nc=max(abs(r1-r2),abs(c1-c2))\r\nprint(a,b,c)\r\n", "c = list(map(int, input().split()))\r\na = [0, 0, 0]\r\n\r\nif c[0]==c[2] or c[1]==c[3]:\r\n a[0] = 1\r\nelse:\r\n a[0] = 2\r\n\r\nif (c[0]+c[1])%2 == (c[2]+c[3])%2:\r\n if abs(c[2]-c[0]) == abs(c[3]-c[1]):\r\n a[1] = 1\r\n else:\r\n a[1] = 2\r\n\r\na[2] = max(abs(c[2]-c[0]), abs(c[3]-c[1]))\r\n\r\nprint(*a)", "def korol(s, t):\r\n ak = [[9, 1, 8], [10, 2, 8, 0, 9], [11, 3, 9, 1, 10], [12, 4, 10, 2, 11], [13, 5, 11, 3, 12], [14, 6, 12, 4, 13], [15, 7, 13, 5, 14], [14, 6, 15], [17, 1, 9, 0, 16], [18, 2, 10, 0, 16, 8, 1, 17], [19, 3, 11, 1, 17, 9, 2, 18], [20, 4, 12, 2, 18, 10, 3, 19], [21, 5, 13, 3, 19, 11, 4, 20], [22, 6, 14, 4, 20, 12, 5, 21], [23, 7, 15, 5, 21, 13, 6, 22], [6, 22, 14, 7, 23], [25, 9, 17, 8, 24], [26, 10, 18, 8, 24, 16, 9, 25], [27, 11, 19, 9, 25, 17, 10, 26], [28, 12, 20, 10, 26, 18, 11, 27], [29, 13, 21, 11, 27, 19, 12, 28], [30, 14, 22, 12, 28, 20, 13, 29], [31, 15, 23, 13, 29, 21, 14, 30], [14, 30, 22, 15, 31], [33, 17, 25, 16, 32], [34, 18, 26, 16, 32, 24, 17, 33], [35, 19, 27, 17, 33, 25, 18, 34], [36, 20, 28, 18, 34, 26, 19, 35], [37, 21, 29, 19, 35, 27, 20, 36], [38, 22, 30, 20, 36, 28, 21, 37], [39, 23, 31, 21, 37, 29, 22, 38], [22, 38, 30, 23, 39], [41, 25, 33, 24, 40], [42, 26, 34, 24, 40, 32, 25, 41], [43, 27, 35, 25, 41, 33, 26, 42], [44, 28, 36, 26, 42, 34, 27, 43], [45, 29, 37, 27, 43, 35, 28, 44], [46, 30, 38, 28, 44, 36, 29, 45], [47, 31, 39, 29, 45, 37, 30, 46], [30, 46, 38, 31, 47], [49, 33, 41, 32, 48], [50, 34, 42, 32, 48, 40, 33, 49], [51, 35, 43, 33, 49, 41, 34, 50], [52, 36, 44, 34, 50, 42, 35, 51], [53, 37, 45, 35, 51, 43, 36, 52], [54, 38, 46, 36, 52, 44, 37, 53], [55, 39, 47, 37, 53, 45, 38, 54], [38, 54, 46, 39, 55], [57, 41, 49, 40, 56], [58, 42, 50, 40, 56, 48, 41, 57], [59, 43, 51, 41, 57, 49, 42, 58], [60, 44, 52, 42, 58, 50, 43, 59], [61, 45, 53, 43, 59, 51, 44, 60], [62, 46, 54, 44, 60, 52, 45, 61], [63, 47, 55, 45, 61, 53, 46, 62], [46, 62, 54, 47, 63], [49, 57, 48], [50, 58, 48, 56, 49], [51, 59, 49, 57, 50], [52, 60, 50, 58, 51], [53, 61, 51, 59, 52], [54, 62, 52, 60, 53], [55, 63, 53, 61, 54], [54, 62, 55]]\r\n usedk = [-2]*64\r\n qk = [s]\r\n dk = [0]*64\r\n if s == t: \r\n return 0\r\n else:\r\n while len(qk)>0:\r\n vk = qk[0]\r\n qk.pop(0)\r\n for tok in ak[vk]:\r\n if usedk[tok] == -2:\r\n usedk[tok] = vk\r\n qk.append(tok)\r\n dk[tok] = dk[vk] + 1\r\n return dk[t]\r\ndef ladia(s, t):\r\n al = [[1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32, 40, 48, 56], [2, 3, 4, 5, 6, 7, 0, 9, 17, 25, 33, 41, 49, 57], [3, 4, 5, 6, 7, 1, 0, 10, 18, 26, 34, 42, 50, 58], [4, 5, 6, 7, 2, 1, 0, 11, 19, 27, 35, 43, 51, 59], [5, 6, 7, 3, 2, 1, 0, 12, 20, 28, 36, 44, 52, 60], [6, 7, 4, 3, 2, 1, 0, 13, 21, 29, 37, 45, 53, 61], [7, 5, 4, 3, 2, 1, 0, 14, 22, 30, 38, 46, 54, 62], [6, 5, 4, 3, 2, 1, 0, 15, 23, 31, 39, 47, 55, 63], [9, 10, 11, 12, 13, 14, 15, 16, 24, 32, 40, 48, 56, 0], [10, 11, 12, 13, 14, 15, 8, 17, 25, 33, 41, 49, 57, 1], [11, 12, 13, 14, 15, 9, 8, 18, 26, 34, 42, 50, 58, 2], [12, 13, 14, 15, 10, 9, 8, 19, 27, 35, 43, 51, 59, 3], [13, 14, 15, 11, 10, 9, 8, 20, 28, 36, 44, 52, 60, 4], [14, 15, 12, 11, 10, 9, 8, 21, 29, 37, 45, 53, 61, 5], [15, 13, 12, 11, 10, 9, 8, 22, 30, 38, 46, 54, 62, 6], [14, 13, 12, 11, 10, 9, 8, 23, 31, 39, 47, 55, 63, 7], [17, 18, 19, 20, 21, 22, 23, 24, 32, 40, 48, 56, 8, 0], [18, 19, 20, 21, 22, 23, 16, 25, 33, 41, 49, 57, 9, 1], [19, 20, 21, 22, 23, 17, 16, 26, 34, 42, 50, 58, 10, 2], [20, 21, 22, 23, 18, 17, 16, 27, 35, 43, 51, 59, 11, 3], [21, 22, 23, 19, 18, 17, 16, 28, 36, 44, 52, 60, 12, 4], [22, 23, 20, 19, 18, 17, 16, 29, 37, 45, 53, 61, 13, 5], [23, 21, 20, 19, 18, 17, 16, 30, 38, 46, 54, 62, 14, 6], [22, 21, 20, 19, 18, 17, 16, 31, 39, 47, 55, 63, 15, 7], [25, 26, 27, 28, 29, 30, 31, 32, 40, 48, 56, 16, 8, 0], [26, 27, 28, 29, 30, 31, 24, 33, 41, 49, 57, 17, 9, 1], [27, 28, 29, 30, 31, 25, 24, 34, 42, 50, 58, 18, 10, 2], [28, 29, 30, 31, 26, 25, 24, 35, 43, 51, 59, 19, 11, 3], [29, 30, 31, 27, 26, 25, 24, 36, 44, 52, 60, 20, 12, 4], [30, 31, 28, 27, 26, 25, 24, 37, 45, 53, 61, 21, 13, 5], [31, 29, 28, 27, 26, 25, 24, 38, 46, 54, 62, 22, 14, 6], [30, 29, 28, 27, 26, 25, 24, 39, 47, 55, 63, 23, 15, 7], [33, 34, 35, 36, 37, 38, 39, 40, 48, 56, 24, 16, 8, 0], [34, 35, 36, 37, 38, 39, 32, 41, 49, 57, 25, 17, 9, 1], [35, 36, 37, 38, 39, 33, 32, 42, 50, 58, 26, 18, 10, 2], [36, 37, 38, 39, 34, 33, 32, 43, 51, 59, 27, 19, 11, 3], [37, 38, 39, 35, 34, 33, 32, 44, 52, 60, 28, 20, 12, 4], [38, 39, 36, 35, 34, 33, 32, 45, 53, 61, 29, 21, 13, 5], [39, 37, 36, 35, 34, 33, 32, 46, 54, 62, 30, 22, 14, 6], [38, 37, 36, 35, 34, 33, 32, 47, 55, 63, 31, 23, 15, 7], [41, 42, 43, 44, 45, 46, 47, 48, 56, 32, 24, 16, 8, 0], [42, 43, 44, 45, 46, 47, 40, 49, 57, 33, 25, 17, 9, 1], [43, 44, 45, 46, 47, 41, 40, 50, 58, 34, 26, 18, 10, 2], [44, 45, 46, 47, 42, 41, 40, 51, 59, 35, 27, 19, 11, 3], [45, 46, 47, 43, 42, 41, 40, 52, 60, 36, 28, 20, 12, 4], [46, 47, 44, 43, 42, 41, 40, 53, 61, 37, 29, 21, 13, 5], [47, 45, 44, 43, 42, 41, 40, 54, 62, 38, 30, 22, 14, 6], [46, 45, 44, 43, 42, 41, 40, 55, 63, 39, 31, 23, 15, 7], [49, 50, 51, 52, 53, 54, 55, 56, 40, 32, 24, 16, 8, 0], [50, 51, 52, 53, 54, 55, 48, 57, 41, 33, 25, 17, 9, 1], [51, 52, 53, 54, 55, 49, 48, 58, 42, 34, 26, 18, 10, 2], [52, 53, 54, 55, 50, 49, 48, 59, 43, 35, 27, 19, 11, 3], [53, 54, 55, 51, 50, 49, 48, 60, 44, 36, 28, 20, 12, 4], [54, 55, 52, 51, 50, 49, 48, 61, 45, 37, 29, 21, 13, 5], [55, 53, 52, 51, 50, 49, 48, 62, 46, 38, 30, 22, 14, 6], [54, 53, 52, 51, 50, 49, 48, 63, 47, 39, 31, 23, 15, 7], [57, 58, 59, 60, 61, 62, 63, 48, 40, 32, 24, 16, 8, 0], [58, 59, 60, 61, 62, 63, 56, 49, 41, 33, 25, 17, 9, 1], [59, 60, 61, 62, 63, 57, 56, 50, 42, 34, 26, 18, 10, 2], [60, 61, 62, 63, 58, 57, 56, 51, 43, 35, 27, 19, 11, 3], [61, 62, 63, 59, 58, 57, 56, 52, 44, 36, 28, 20, 12, 4], [62, 63, 60, 59, 58, 57, 56, 53, 45, 37, 29, 21, 13, 5], [63, 61, 60, 59, 58, 57, 56, 54, 46, 38, 30, 22, 14, 6], [62, 61, 60, 59, 58, 57, 56, 55, 47, 39, 31, 23, 15, 7]]\r\n usedl = [-2]*64\r\n ql = [s]\r\n dl = [0]*64\r\n if s == t: \r\n return 0\r\n else:\r\n while len(ql)>0:\r\n vl = ql[0]\r\n ql.pop(0)\r\n for tol in al[vl]:\r\n if usedl[tol] == -2:\r\n usedl[tol] = vl\r\n ql.append(tol)\r\n dl[tol] = dl[vl] + 1\r\n return dl[t] \r\ndef slon(s, t):\r\n ae = [[9, 18, 27, 36, 45, 54, 63], [8, 10, 19, 28, 37, 46, 55], [9, 16, 11, 20, 29, 38, 47], [10, 17, 24, 12, 21, 30, 39], [11, 18, 25, 32, 13, 22, 31], [12, 19, 26, 33, 40, 14, 23], [13, 20, 27, 34, 41, 48, 15], [14, 21, 28, 35, 42, 49, 56], [17, 26, 35, 44, 53, 62, 1], [16, 18, 27, 36, 45, 54, 63, 0, 2], [17, 24, 19, 28, 37, 46, 55, 1, 3], [18, 25, 32, 20, 29, 38, 47, 2, 4], [19, 26, 33, 40, 21, 30, 39, 3, 5], [20, 27, 34, 41, 48, 22, 31, 4, 6], [21, 28, 35, 42, 49, 56, 23, 5, 7], [22, 29, 36, 43, 50, 57, 6], [25, 34, 43, 52, 61, 9, 2], [24, 26, 35, 44, 53, 62, 8, 10, 3], [25, 32, 27, 36, 45, 54, 63, 9, 0, 11, 4], [26, 33, 40, 28, 37, 46, 55, 10, 1, 12, 5], [27, 34, 41, 48, 29, 38, 47, 11, 2, 13, 6], [28, 35, 42, 49, 56, 30, 39, 12, 3, 14, 7], [29, 36, 43, 50, 57, 31, 13, 4, 15], [30, 37, 44, 51, 58, 14, 5], [33, 42, 51, 60, 17, 10, 3], [32, 34, 43, 52, 61, 16, 18, 11, 4], [33, 40, 35, 44, 53, 62, 17, 8, 19, 12, 5], [34, 41, 48, 36, 45, 54, 63, 18, 9, 0, 20, 13, 6], [35, 42, 49, 56, 37, 46, 55, 19, 10, 1, 21, 14, 7], [36, 43, 50, 57, 38, 47, 20, 11, 2, 22, 15], [37, 44, 51, 58, 39, 21, 12, 3, 23], [38, 45, 52, 59, 22, 13, 4], [41, 50, 59, 25, 18, 11, 4], [40, 42, 51, 60, 24, 26, 19, 12, 5], [41, 48, 43, 52, 61, 25, 16, 27, 20, 13, 6], [42, 49, 56, 44, 53, 62, 26, 17, 8, 28, 21, 14, 7], [43, 50, 57, 45, 54, 63, 27, 18, 9, 0, 29, 22, 15], [44, 51, 58, 46, 55, 28, 19, 10, 1, 30, 23], [45, 52, 59, 47, 29, 20, 11, 2, 31], [46, 53, 60, 30, 21, 12, 3], [49, 58, 33, 26, 19, 12, 5], [48, 50, 59, 32, 34, 27, 20, 13, 6], [49, 56, 51, 60, 33, 24, 35, 28, 21, 14, 7], [50, 57, 52, 61, 34, 25, 16, 36, 29, 22, 15], [51, 58, 53, 62, 35, 26, 17, 8, 37, 30, 23], [52, 59, 54, 63, 36, 27, 18, 9, 0, 38, 31], [53, 60, 55, 37, 28, 19, 10, 1, 39], [54, 61, 38, 29, 20, 11, 2], [57, 41, 34, 27, 20, 13, 6], [56, 58, 40, 42, 35, 28, 21, 14, 7], [57, 59, 41, 32, 43, 36, 29, 22, 15], [58, 60, 42, 33, 24, 44, 37, 30, 23], [59, 61, 43, 34, 25, 16, 45, 38, 31], [60, 62, 44, 35, 26, 17, 8, 46, 39], [61, 63, 45, 36, 27, 18, 9, 0, 47], [62, 46, 37, 28, 19, 10, 1], [49, 42, 35, 28, 21, 14, 7], [48, 50, 43, 36, 29, 22, 15], [49, 40, 51, 44, 37, 30, 23], [50, 41, 32, 52, 45, 38, 31], [51, 42, 33, 24, 53, 46, 39], [52, 43, 34, 25, 16, 54, 47], [53, 44, 35, 26, 17, 8, 55], [54, 45, 36, 27, 18, 9, 0]]\r\n usede = [-2]*64\r\n qe = [s]\r\n de = [0]*64\r\n if s == t: \r\n return 0\r\n else:\r\n while len(qe)>0:\r\n ve = qe[0]\r\n qe.pop(0)\r\n for toe in ae[ve]:\r\n if usede[toe] == -2:\r\n usede[toe] = ve\r\n qe.append(toe)\r\n de[toe] = de[ve] + 1\r\n return de[t] \r\n\r\n\r\n\r\nb = list(map(int, input().split()))\r\ns = (b[1]-1)*8 + b[0] - 1\r\nt = (b[3]-1)*8 + b[2] - 1\r\nprint(ladia(s, t), slon(s, t), korol(s, t))\n# Tue Jul 11 2023 13:41:59 GMT+0300 (Moscow Standard Time)\n", "r1, c1, r2, c2 = list(map(int,input().split()))\r\n\r\n# print(r1, c1, r2, c2)\r\n\r\ndef torre(r1, c1, r2, c2):\r\n if (r1 == r2) or (c1 == c2):\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef arfil(r1, c1, r2, c2):\r\n p1 = r1 + c1\r\n p2 = r2 + c2\r\n if (p1 % 2) != (p2 % 2):\r\n return 0 \r\n elif abs(r1 - r2) == abs(c1 - c2):\r\n return 1\r\n else:\r\n return 2\r\n \r\ndef rey(r1, c1, r2, c2):\r\n return max(abs(r1 - r2), abs(c1 - c2))\r\n\r\ndef minimos(r1, c1, r2, c2):\r\n t = torre(r1, c1, r2, c2)\r\n a = arfil(r1, c1, r2, c2)\r\n r = rey(r1, c1, r2, c2)\r\n return t, a , r\r\n\r\ntorre, arfil, rey = minimos(r1, c1, r2, c2)\r\nprint(torre, arfil, rey)\r\n", "r1, c1, r2, c2 = map(int, input().split(\" \"))\r\n\r\ndef rook_moves():\r\n if (r1 == r2 or c1 == c2):\r\n return 1\r\n return 2\r\n\r\ndef bishop_moves():\r\n if ((r1+c1) % 2 != (r2+c2) % 2): # Starting and ending cells are different color.\r\n return 0\r\n if (abs(r1-r2)==abs(c1-c2)):\r\n return 1\r\n return 2\r\n\r\n # black even+even=evem odd+odd=even === even\r\n # whote even+odd = odd odd+even=odd === odd\r\n # if ((r1+c1) % 2 == 0 or (r2+c2) % 2):\r\n # return 0\r\n \r\n\r\ndef king_moves():\r\n x = abs(r1 - r2)\r\n y = abs(c1 - c2)\r\n return max(x,y)\r\n\r\nprint(rook_moves(), bishop_moves(), king_moves())\r\n\r\n# 5 5 5 6 output: 1 0 1\r\n# 4 3 1 6 output: 2 1 3 ", "a,b,c,d=map(int,input().split())\r\nif a==c or b==d:\r\n print('1',end=' ')\r\nelse:\r\n print('2',end=' ')\r\nif abs(a-c)==abs(b-d):\r\n print('1',end=' ')\r\nelif (a-b)%2==0 and (c-d)%2==0:\r\n print('2',end=' ')\r\nelif (a-b)%2!=0 and (c-d)%2!=0:\r\n print('2',end=' ')\r\nelse:\r\n print('0',end=' ')\r\nprint(max(abs(a-c),abs(b-d)))\r\n", "import math\nsx, sy, dx, dy = list(map(int, input().split()))\n\n## Rook\na = 0\nif sx != dx:\n a += 1\nif sy != dy:\n a += 1\n\n\n## Bishop\nb = 0\nk1 = sy - sx\nk2 = sy + sx\n\nkd1 = dy - dx\nkd2 = dy + dx\n\nif k1%2 != kd1%2 or k2%2 != kd2%2:\n pass\nelse:\n if k1 != kd1:\n b += 1\n if k2 != kd2:\n b += 1\n\n## King\nc = int(max(math.fabs(dx-sx), math.fabs(dy-sy)))\n\nprint(f'{a} {b} {c}')", "#https://codeforces.com/problemset/problem/370/A\r\n\r\ndef main():\r\n\t#read input (starting and end coordinates)\r\n\tstart_row, start_col, end_row, end_col = (int(i) for i in input().split())\r\n\r\n\r\n\t'''rook: the rook can go to every position in at most 2 moves. \r\n\tif the end position is at the same row or column,it only needs 1 move'''\r\n\tif start_row == end_row or start_col == end_col:\r\n\t\tmoves_rook = 1\r\n\telse:\r\n\t\tmoves_rook = 2\r\n\r\n\t'''bishop: the bishop can't get to every position in the board.\r\n\tit can only get to those fields that are of the same color of\r\n\tthe field that he is on. For these positions, he can get at every one\r\n\tin at most 2 moves. likewise the rook, if the end position is \r\n\ton the same diagonal he only needs 1 move\r\n\t'''\r\n\tcolor_start_p = get_color(start_row, start_col)\r\n\tcolor_end_p = get_color(end_row, end_col)\r\n\tif color_start_p == color_end_p:\r\n\t\t# to positions are on the same diagonal if |r1-r2| = |c1-c2|\r\n\t\tif abs(start_row - end_row) == abs(start_col - end_col):\r\n\t\t\tmoves_bishop = 1\r\n\t\telse:\r\n\t\t\tmoves_bishop = 2\r\n\telse:\r\n\t\tmoves_bishop = 0\r\n\r\n\t'''king: the king can get to any position on the board.\r\n\tthe fastest way to get to a position is to move diagonally until you reach\r\n\tthe desired row or col, and the move straight.\r\n\t'''\r\n\tif abs(start_row - end_row) < abs(start_col-end_col):\r\n\t\tmoves_king = abs(start_col - end_col)\r\n\telse:\r\n\t\tmoves_king = abs(start_row - end_row)\r\n\r\n\tprint(moves_rook, moves_bishop, moves_king)\r\n\r\n\r\n\r\n\r\ndef get_color(r,c):\r\n\tif r % 2 == 0:\r\n\t\tif c % 2 == 0:\r\n\t\t\treturn 1\r\n\t\telse:\r\n\t\t\treturn -1\r\n\telse:\r\n\t\tif c % 2 == 0:\r\n\t\t\treturn -1\r\n\t\telse:\r\n\t\t\treturn 1\r\n\r\nif __name__ == \"__main__\":\r\n\tmain()", "r1, c1, r2, c2 = map(int, input().split())\r\n\r\ndef rock(r1, c1, r2, c2):\r\n if r1 == r2 or c1 == c2: #Same col or same row\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef bishop(r1, c1, r2, c2):\r\n if (r1 + c1) % 2 != (r2 + c2) % 2:\r\n return 0\r\n elif abs(r1-r2) == abs(c1-c2):\r\n return 1\r\n else:\r\n return 2\r\n \r\ndef king(r1, c1, r2, c2):\r\n return max(abs(r1 - r2), abs(c1 - c2))\r\n\r\nif r1 == r2 and c1 == c2:\r\n print(\"0 0 0\")\r\nelse:\r\n a = rock(r1, c1, r2, c2)\r\n b = bishop(r1, c1, r2, c2)\r\n c = king(r1, c1, r2, c2)\r\n print(a,b,c)", "bx, by, ex, ey = list(map(int, input().split()))\r\narr = []\r\nif bx == ex or by == ey:\r\n print(1, end=\" \")\r\nelse:\r\n print(2, end=\" \")\r\nif (bx + by) % 2 == (ex + ey) % 2:\r\n if bx + by == ex + ey or bx - by == ex - ey:\r\n print(1, end=' ')\r\n else:\r\n print(2, end=' ')\r\nelse:\r\n print(0, end=' ')\r\nprint(max((abs((bx - ex))), (abs(by - ey))))", "a,b,c,d=map(int,input().split())\r\ne=abs(a-c)\r\nf=abs(b-d)\r\nt=0\r\nif (e-f)%2==0:t=2\r\nif e==f:t=1\r\nprint((a!=c)+(b!=d),t,max(e,f))", "# A. Rook, Bishop and King\r\n# https://codeforces.com/problemset/problem/370/A\r\n\r\nstart_x, start_y, end_x, end_y = map(int, input().split())\r\n\r\ndef rook(r1, c1, r2, c2):\r\n if r1 == r2 or c1 == c2: return 1\r\n else: return 2\r\n\r\ndef bishop(r1, c1, r2, c2):\r\n# check if start or end position is white \r\n start_field = end_field = \"black\"\r\n if (r1 % 2 != 0 and (r1 * c1) % 2 != 0) or (r1 % 2 == 0 and c1 % 2 == 0): start_field = \"white\"\r\n if (r2 % 2 != 0 and (r2 * c2) % 2 != 0) or (r2 % 2 == 0 and c2 % 2 == 0): end_field = \"white\"\r\n\r\n# if start and end field are not the same color, bishop cant reach field\r\n if start_field != end_field: return 0\r\n else:\r\n if abs(r1 - r2) == abs(c1 - c2): return 1\r\n else: return 2\r\n\r\ndef king(r1, c1, r2, c2):\r\n return max(abs(r1 - r2), abs(c1 - c2))\r\n\r\nprint(rook(start_x, start_y, end_x, end_y), bishop(start_x, start_y, end_x, end_y), king(start_x, start_y, end_x, end_y))", "x1,y1,x2,y2=map(int,input().split())\r\nif x1==x2:\r\n r=1\r\n k=max(y1,y2)-min(y1,y2)\r\n if y1%2==0 and y2%2==0 or y1%2!=0 and y2%2!=0:\r\n b=max(y1,y2)-min(y1,y2)\r\n else:\r\n b=0\r\nelif y1==y2:\r\n r=1\r\n k=max(x1,x2)-min(x1,x2)\r\n if x1%2==0 and x2%2==0 or x1%2!=0 and x2%2!=0:\r\n b=max(x1,x2)-min(x1,x2)\r\n else:\r\n b=0\r\nelif (y2-y1)/(x2-x1)==1 or (y2-y1)/(x2-x1)==-1:\r\n r=2\r\n k=max(x1,x2)-min(x1,x2)\r\n b=1\r\nelse:\r\n r=2\r\n k=max(max(x1,x2)-min(x1,x2),max(y1,y2)-min(y1,y2))\r\n if (x1+y1)%2==0 and (x2+y2)%2==0 or (x1+y1)%2!=0 and (x2+y2)%2!=0:\r\n b=2\r\n else:\r\n b=0\r\nprint(r,b,k)", "sx, sy, ex, ey = map(int, input().split())\r\nstart_color = \"black\"\r\nend_color = \"black\"\r\n\r\nrook=2\r\nif sy == ey or sx == ex: rook =1\r\n\r\nif ((sx * sy) % 2 != 0 and sx% 2 != 0) or (sy % 2 == 0 and sx %2== 0):\r\n start_color = \"white\"\r\n \r\nif (ex % 2!= 0 and (ex*ey) % 2 != 0) or (ex %2 == 0 and ey % 2 == 0):\r\n end_color = \"white\"\r\n\r\nbishop=0\r\nif start_color == end_color:\r\n if abs(sx - ex) == abs(sy - ey):\r\n bishop = 1\r\n else:\r\n bishop = 2\r\nking = max(abs(sx - ex), abs(sy - ey))\r\n \r\nprint(rook, bishop, king)", "r1, c1, r2, c2 = map(int, input().split())\r\nb = 0\r\nif (r1 + c1) % 2 == (r2 + c2) % 2:\r\n b = 1 + (r1 - c1 != r2 - c2 and r1 + c1 != r2 + c2)\r\nprint((r1 != r2) + (c1 != c2), b, max(abs(r1 - r2), abs(c1 - c2)))", "r1,c1,r2,c2 = [int(x) for x in input().split(\" \")]\r\n\r\n# rook\r\nrook = 2\r\nif(r1==r2 or c1==c2): rook = 1\r\n\r\n# bishop\r\nbishop = 2\r\nif (r1+c1)%2 != (r2+c2)%2: bishop = 0\r\nelif abs(r2-r1)==abs(c2-c1): bishop=1\r\n\r\n# king\r\nking = max([abs(r2-r1),abs(c2-c1)])\r\n\r\nprint(rook,bishop,king)", "def is_black(x,y):\n is_x_odd = x %2 != 0\n is_y_odd = y %2 != 0\n return is_x_odd != is_y_odd\n\n\ndef solve(x1,y1,x2,y2):\n v1 = 2\n v2 = 0\n v3 = 0\n if x1==x2 and y1 == y2:\n return 0,0,0\n if x1 == x2 or y1 == y2:\n v1 =1\n\n p1 = is_black(x1,y1)\n p2 = is_black(x2,y2)\n\n if p1 == p2:\n if abs(x1-x2) == abs(y1-y2):\n v2 = 1\n else:\n v2 = 2\n \n \n while x1 != x2 or y1 != y2:\n arr = [[x1,y1],\n [x1-1,y1], \n [x1-1,y1-1],\n [x1,y1-1], \n [x1+1,y1],\n [x1+1,y1+1], \n [x1,y1+1], \n [x1+1,y1],\n [x1+1,y1-1],\n [x1-1, y1+1]\n ]\n min_val = 100000\n min_temp_x = 0\n min_temp_y = 0\n for i in arr:\n temp_x, temp_y = i\n val = (abs(temp_x - x2)**2 + abs(temp_y-y2)**2)**.5\n if val < min_val:\n min_val = val\n min_temp_x = temp_x\n min_temp_y = temp_y\n x1 = min_temp_x\n y1 = min_temp_y\n v3 += 1\n return v1,v2,v3\n \n\n\n\ndef main():\n arr = list(map(int, list(input().split(\" \"))))\n # n = int(input())\n print(*solve(*arr))\n\nmain()", "r1,c1,r2,c2=map(int,input().split())\r\nrook=1\r\nif r1!=r2 and c1!=c2:\r\n rook+=1\r\nif not((r1+c1)%2==(r2+c2)%2):\r\n bis=0\r\nelse:\r\n if abs(r1-r2)==abs(c1-c2):\r\n bis=1\r\n else:\r\n bis=2\r\nking=abs(r1-r2)+abs(c1-c2)-min(abs(r1-r2),abs(c1-c2))\r\nprint(f\"{rook} {bis} {king}\")", "r1, c1, r2, c2 = map(int, input().split())\r\n\r\nif (r1,c1) == (r2, c2):\r\n print(\"0 0 0\")\r\nelse:\r\n if r1 == r2 or c1 == c2:\r\n rook = 1\r\n else:\r\n rook = 2\r\n x, y = abs(r1 - r2), abs(c1 - c2)\r\n king = max(x, y)\r\n bishop = 0\r\n if ((r1+c1)%2 != (r2+c2)%2):\r\n bisohp = 0\r\n elif (r1+c1) == (r2+c2):\r\n bishop = 1\r\n elif x == y:\r\n bishop = 1\r\n else:\r\n bishop = 2\r\n print(f\"{rook} {bishop} {king}\")", "def rook_moves():\r\n if(r1 == r2 or c1 == c2):\r\n return 1\r\n return 2\r\n\r\ndef bishop_moves():\r\n if ((r1+c1) % 2 != (r2+c2) % 2): # Starting and ending cells are different color.\r\n return 0\r\n if (abs(r1-r2)==abs(c1-c2)):\r\n return 1\r\n return 2\r\n\r\ndef king_moves():\r\n return max(abs(r2-r1), abs(c2-c1))\r\n \r\nr1, c1, r2, c2 = map(int, input().split(\" \"))\r\nprint(rook_moves(), bishop_moves(), king_moves())", "r1,c1,r2,c2=map(int,input().split())\r\nif r1==r2 and c1==c2:print(0,end=\" \")\r\nelif r1==r2 or c1==c2:print(1,end=\" \")\r\nelse:print(2,end=\" \")\r\nif (r1+c1)%2!=(r2+c2)%2:print(0,end=\" \")\r\nelif abs(r1-r2)==abs(c1-c2):print(1,end=\" \")\r\nelse:print(2,end=\" \")\r\nprint(max(abs(r1-r2),abs(c1-c2)))", "(r1, c1, r2, c2) = list(map(int, input().split(' ')))\n\nprint(str(1 if (r1 == r2 or c1 == c2) else 2) + ' ' \\\n + str(\n 0 if ((r1 + c1) % 2 != (r2 + c2) % 2) \n else (\n 1 if (r1 + c2 == r2 + c1 or r1 + c1 == r2 + c2) \n else 2\n )) + ' ' \\\n + str(max(abs(c1 - c2), abs(r1-r2))))\n\t \t\t\t\t \t \t\t\t\t\t\t\t \t\t \t\t \t \t\t \t", "import sys\r\nimport math\r\n\r\nr1, c1, r2, c2 = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nres = []\r\nif(r1 == r2 and c1 == c2):\r\n print(\"0 0 0\")\r\n exit()\r\n\r\nif(r1 == r2 or c1 == c2):\r\n res.append(\"1\")\r\nelse:\r\n res.append(\"2\")\r\n\r\nf1 = ((r1 + c1) % 2 == 0)\r\nf2 = ((r2 + c2) % 2 == 0)\r\n\r\nif(f1 != f2):\r\n res.append(\"0\")\r\nelif(math.fabs(r1 - r2) == math.fabs(c1 - c2)):\r\n res.append(\"1\")\r\nelse:\r\n res.append(\"2\")\r\n\r\nres.append(str(int(max(math.fabs(r1 - r2), math.fabs(c1 - c2)))))\r\n\r\nprint(\" \".join(res))", "class handle_input():\n\n def __init__(self, mode):\n if mode == \"multiple_lines\":\n self.input_from_user = self.__read_multiple_lines()\n\n def __read_multiple_lines(self):\n contents = []\n while True:\n try:\n line = input()\n if line in [\"\\n\", \"\"]:\n break\n \n except EOFError:\n break\n contents.append(line)\n\n return contents\n\ninput_handler = handle_input(\"multiple_lines\")\nlist_lines = input_handler.input_from_user\n\nnum = list_lines[0].split(\" \")\nr1 = int(num[0])\nc1 = int(num[1])\nr2 = int(num[2])\nc2 = int(num[3])\n\n### rook\nif (r1 == r2) and (c1 == c2):\n output = \"0\"\nelif (r1 == r2) or (c1 == c2):\n output = \"1\"\nelse:\n output = \"2\"\n\n### bishop\nif ((r1 + c1) % 2 != (r2 + c2) % 2):\n output = output + \" 0\"\nelif abs(r1 - r2) == abs(c1 - c2):\n output = output + \" 1\"\nelse:\n output = output + \" 2\" \n\n### king\noutput = output + \" \" + str(max(abs(r2 - r1), abs(c2 - c1)))\n\nprint(output)\n \t \t \t\t \t\t\t\t\t \t\t\t \t\t \t\t", "x1, y1, x2, y2 = map(int, input().split())\n\nif (x1 == x2 or y1 == y2):\n print(1, end=\" \")\nelse:\n print(2, end=\" \")\n\nif (x1 + y1) % 2 != (x2 + y2) % 2:\n print(0, end=\" \")\nelif ((x1 + y1) == (x2 + y2) or (x1 - y1) == (x2 - y2)):\n print(1, end=\" \")\nelse:\n print(2, end=\" \")\n\nprint(max(abs(x1 - x2), abs(y1 - y2)))\n# Tue Jul 11 2023 12:21:57 GMT+0300 (Moscow Standard Time)\n", "a, b, c, d = map(int, input().split())\r\nif a == c or b == d:\r\n print(1, end = ' ')\r\nelse:\r\n print(2, end = ' ')\r\nif (a+b)%2 != (c+d)%2:\r\n print(0, end = ' ')\r\nelif abs(a-c) == abs(b-d):\r\n print(1, end = ' ')\r\nelse:\r\n print(2, end = ' ')\r\nif a == c:\r\n print(abs(b-d))\r\nelif b == d:\r\n print(abs(a-c))\r\nelse:\r\n Min = min(abs(a-c),abs(b-d))\r\n if a > c:\r\n a -= Min\r\n else:\r\n a += Min\r\n if b > d:\r\n b -= Min\r\n else:\r\n b += Min\r\n if a == c:\r\n print(abs(b-d)+Min)\r\n else:\r\n print(abs(a-c)+Min)\r\n ", "#import math\r\n#n, m = input().split()\r\n#n = int (n)\r\n#m = int (m)\r\nn, m, k , l= input().split()\r\nn = int (n)\r\nm = int (m)\r\nk = int (k)\r\nl = int(l)\r\n#n = int(input())\r\n#m = int(input())\r\n#s = input()\r\n##t = input()\r\n#a = list(map(char, input().split()))\r\n#a.append('.')\r\n#print(l)\r\n#c = list(map(int, input().split()))\r\n#c = sorted(c)\r\n#x1, y1, x2, y2 =map(int,input().split())\r\n#n = int(input())\r\n#f = []\r\n#t = [0]*n\r\n#f = [(int(s1[0]),s1[1]), (int(s2[0]),s2[1]), (int(s3[0]), s3[1])]\r\n#f1 = sorted(t, key = lambda tup: tup[0])\r\nq = max(abs(n-k), abs(m-l))\r\nif (n == k and l == m):\r\n r = 0\r\nelif(n == k or l == m):\r\n r = 1\r\nelse:\r\n r = 2\r\nif ( (n+m) % 2 != (k+l) % 2):\r\n b = 0\r\nelif ( abs(n-k) == abs(m-l)):\r\n b = 1\r\nelse:\r\n b = 2\r\nprint(r, b, q)\r\n", "from collections import deque\r\ndef valid(x,y):\r\n if x>=9 or y>=9 or x<0 or y<0:\r\n return 0\r\n elif v1[x][y]==1:\r\n return 0\r\n return 1\r\ndef king(i,j):\r\n v1[i][j]=True\r\n q=deque()\r\n q.append([i,j])\r\n dx=[1,0,-1,0,-1,-1,1,1]\r\n dy=[0,-1,0,1,-1,1,-1,1]\r\n while q:\r\n node=q.popleft()\r\n x=node[0]\r\n y=node[1]\r\n for i in range(8):\r\n if valid(x+dx[i],y+dy[i]):\r\n newx=x+dx[i]\r\n newy=y+dy[i]\r\n d1[newx][newy]=d1[x][y]+1\r\n v1[newx][newy]=1\r\n q.append([newx,newy])\r\ns1,s2,e1,e2=map(int,input().split())\r\nv1=[[False for i in range(9)]for j in range(9)]\r\nv2=[[False for i in range(9)]for j in range(9)]\r\nd1=[[0 for i in range(9)]for j in range(9)]\r\nking(s1,s2)\r\nif s1==e1 or s2==e2:\r\n rook=1\r\nelse:\r\n rook=2\r\nif (s1+e1)%2!=(s2+e2)%2:\r\n bishop=0\r\nelif s1+s2==e1+e2 or s1-s2==e1-e2:\r\n bishop=1\r\nelse:\r\n bishop=2\r\nprint(rook,bishop,d1[e1][e2])\r\n \r\n", "r1, c1, r2, c2 = map(int, input().split())\r\n\r\nif r1 == r2 and c1 == c2:\r\n print(0,0,0)\r\nelse:\r\n if r1 == r2 or c1 == c2:\r\n print(1, end = ' ')\r\n else:\r\n print(2, end = ' ')\r\n if (r1+c1) % 2 != (r2 + c2) % 2:\r\n print(0, end = ' ')\r\n elif abs(r1-r2) == abs(c1-c2):\r\n print(1, end = ' ')\r\n else:\r\n print(2, end = ' ')\r\n print(abs(r2 - r1) + abs(c2-c1) - min(abs(r2-r1), abs(c2-c1)))", "import math\r\nx1,y1,x2,y2 = map(int, input().split())\r\n\r\n\r\nif (x1 == x2 or y1==y2):\r\n print(1)\r\nelse:\r\n print(2)\r\n\r\nif ((x1%2 == y1%2 and x2%2 != y2%2) or (x1%2 != y1%2 and x2%2 == y2%2)):\r\n print(0)\r\nelif (abs(x2-x1) == abs(y2-y1)):\r\n print(1)\r\nelse:\r\n print(2)\r\n\r\nprint(max(abs(x2-x1), abs(y2-y1)))\r\n", "import sys\n\ny1, x1, y2, x2 = map(int, input().split())\nif x1 == x2 and y1 == y2:\n print(0, 0, 0)\n sys.exit(0)\n\n# Ладья\nif x1 == x2 or y1 == y2:\n print(1, end=\" \")\nelse:\n print(2, end=\" \")\n\n# Слон\nif (x1 + x2) % 2 != (y1 + y2) % 2:\n print(0, end=\" \")\nelif x1 + y1 == x2 + y2 or x1 - y1 == x2 - y2:\n print(1, end=\" \")\nelse:\n print(2, end=\" \")\n\n# Король\nprint(max(abs(x1 - x2), abs(y1 - y2)))\n", "x1,y1,x2,y2=map(int,input().split(' '))\r\ndisX=int( ((x1-x2)**2)**.5 )\r\ndisY=int( ((y1-y2)**2)**.5 )\r\n\r\nif(x1==x2 and y1==y2):\r\n print('0',end=' ')\r\nelif(x1==x2 or y1==y2):\r\n print('1',end=' ')\r\nelse:\r\n print('2',end=' ')\r\n\r\nif(disX==disY):\r\n print('1',end=' ')\r\nelif(disX%2 == disY%2):\r\n print('2',end=' ')\r\nelse:\r\n print('0',end=' ')\r\n \r\nif(disX>disY):\r\n print(disX,end=' ')\r\nelse:\r\n print(disY,end=' ')", "r1, c1, r2, c2 = map(int, input().split())\r\n\r\nif r1 == r2:\r\n print(1, end = \" \")\r\nelif c1 == c2:\r\n print(1, end = \" \")\r\nelse:\r\n print(2, end = \" \")\r\n\r\nif (r1 + c1) % 2 != (r2 + c2) % 2:\r\n print(0, end = \" \")\r\nelif (r1 + c1 == r2 + c2) or (r1 - c1 == r2 - c2):\r\n print(1, end = \" \")\r\nelse:\r\n print(2, end = \" \")\r\n \r\n\r\nprint(max(abs(r1-r2), abs(c1-c2)))\r\n\r\n", "read = lambda: map(int, input().split())\r\nr1, c1, r2, c2 = read()\r\nL = 1 if r1 == r2 or c1 == c2 else 2\r\nK = max(abs(r1 - r2), abs(c1 - c2))\r\nif abs(r1 - r2) == abs(c1 - c2): S = 1\r\nelif (r1 + c1) % 2 == (r2 + c2) % 2: S = 2\r\nelse: S = 0\r\nprint(L, S, K)\r\n", "from collections import deque\r\n\r\ndef main():\r\n r1, c1, r2, c2 = [int(x) - 1 for x in input().split(\" \")]\r\n ans = [0] * 3\r\n\r\n if r1 == r2 or c1 == c2:\r\n ans[0] = 1\r\n else:\r\n ans[0] = 2\r\n\r\n if abs(r1 - r2) == abs(c1 - c2):\r\n ans[1] = 1\r\n elif (r1 + c1) % 2 == (r2 + c2) % 2:\r\n ans[1] = 2\r\n else:\r\n ans[1] = 0\r\n\r\n q = deque()\r\n q.append((r1, c1, 0))\r\n v = [[False] * 8 for _ in range(8)]\r\n v[r1][c1] = True\r\n\r\n dist = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]\r\n\r\n while q:\r\n r, c, d = q.popleft()\r\n if r == r2 and c == c2:\r\n ans[2] = d\r\n break\r\n\r\n for dd in dist:\r\n rr = r + dd[0]\r\n cc = c + dd[1]\r\n\r\n if 0 <= rr < 8 and 0 <= cc < 8 and not v[rr][cc]:\r\n v[rr][cc] = True\r\n q.append((rr, cc, d + 1))\r\n\r\n print(*ans)\r\n\r\n\r\nmain()", "r1, c1, r2, c2 = [int(i) for i in input().split()]\r\nans = str()\r\n\r\nif r1 == r2 or c1 == c2:\r\n ans += '1 '\r\nelse:\r\n ans += '2 '\r\n\r\nif ((r1 + c1) % 2 == 0 and (r2 + c2) % 2 == 1) or ((r2 + c2) % 2 == 0 and (r1 + c1) % 2 == 1):\r\n ans += '0 '\r\nelif (r1 + c1) == (r2 + c2) or (r2 - c2) == (r1 - c1):\r\n ans += '1 '\r\nelse:\r\n ans += '2 '\r\n\r\nans += str(max(abs(r2 - r1), abs(c2 - c1)))\r\n\r\nprint(ans)", "r1, c1, r2, c2 = [int(y) for y in input().split()]\r\n\r\nrook_moves = 0\r\nif r1 != r2:\r\n rook_moves += 1\r\nif c1 != c2:\r\n rook_moves += 1\r\nprint(rook_moves, end=\" \")\r\n\r\nbishop_moves = 0\r\nif (r1+c1)%2 != (r2+c2)%2:\r\n pass\r\nelif r1-c1 == r2-c2 or r1+c1 == r2+c2:\r\n bishop_moves += 1\r\nelse:\r\n bishop_moves += 2\r\nprint(bishop_moves, end=\" \")\r\n\r\nking_moves = 0\r\nking_moves += max(abs(r2-r1), abs(c2-c1))\r\nprint(king_moves)", "a,b,c,d=map(int,input().split())\ne=abs(a-c)\nf=abs(b-d)\nt=0\nif (e-f)%2==0:t=2\nif e==f:t=1\nprint((a!=c)+(b!=d),t,max(e,f))\n \t\t \t \t \t \t \t\t\t \t\t \t\t \t\t\t", "A = list(map(int, input().split()))\r\nx1, y1, x2, y2 = A[0], A[1], A[2], A[3]\r\nK = max(abs(x1 - x2), abs(y1 - y2))\r\nif x1 == x2 or y1 == y2:\r\n L = 1\r\nelse:\r\n L = 2\r\nk2, k1 = (x2 + y2) % 2, (x1 + y1) % 2\r\nif k2 != k1:\r\n S = 0\r\nelse:\r\n m = abs(x1 - x2)\r\n n = abs(y1 - y2)\r\n if m == n:\r\n S = 1\r\n else:\r\n S = 2\r\nprint(L, S, K)\n# Tue Jul 11 2023 11:20:47 GMT+0300 (Moscow Standard Time)\n", "x, y, x1, y1 = map(int, input().split())\r\na, b, c = 0, 0, 0\r\n\r\n\r\ndef ladya(x, y, x1, y1):\r\n global a\r\n if x == x1 or y == y1:\r\n a = 1\r\n else:\r\n a = 2\r\n\r\n\r\ndef slon(x, y, x1, y1):\r\n global b\r\n if (x + y) % 2 == (x1 + y1) % 2:\r\n b = 2\r\n if abs(x - x1) == abs(y - y1):\r\n b = 1\r\n\r\n\r\ndef king(x, y, x1, y1):\r\n global c\r\n if abs(x - x1) > abs(y - y1):\r\n c = abs(x - x1)\r\n else:\r\n c = abs(y - y1)\r\n\r\n\r\nladya(x, y, x1, y1)\r\nslon(x, y, x1, y1)\r\nking(x, y, x1, y1)\r\nprint(a, b, c)\r\n", "# -*- coding: utf-8 -*-\r\n\r\nr1,c1,r2,c2 = map(int, input().split())\r\nif r1 == r2 or c1 == c2:\r\n n1 = 1\r\nelse:\r\n n1 = 2\r\n \r\nif (r1+c1)%2 != (r2+c2)%2:\r\n n2 = 0\r\nelif r1+c1==r2+c2 or r1-c1==r2-c2:\r\n n2 = 1\r\nelse:\r\n n2 = 2\r\n\r\nprint(n1, n2, max(abs(r1-r2), abs(c1-c2)))\r\n", "r1, c1, r2, c2 = map(int, input().split())\r\nif r1 == c1 == r2 == c2:\r\n print(0, 0, 0)\r\nelse:\r\n l = [[0 for i in range(8)] for j in range(8)]\r\n for i in range(1, 8 + 1):\r\n for j in range(1, 8 + 1):\r\n if i % 2 == 1 and j % 2 == 1:\r\n l[i - 1][j - 1] = 1\r\n elif i % 2 == 1 and j % 2 == 0:\r\n l[i - 1][j - 1] = 0\r\n elif i % 2 == 0 and j % 2 == 1:\r\n l[i - 1][j - 1] = 0\r\n elif i % 2 == 0 and j % 2 == 0:\r\n l[i - 1][j - 1] = 1\r\n if r1 == r2 or c1 == c2:\r\n print(1, end=' ')\r\n else:\r\n print(2, end=' ')\r\n if l[r1 - 1][c1 - 1] == l[r2 - 1][c2 - 1]:\r\n if abs(r1 - r2) == abs(c1 - c2):\r\n print(1, end=' ')\r\n else:\r\n print(2, end=' ')\r\n else:\r\n print(0, end=' ')\r\n m = min(abs(r1 - r2), abs(c1 - c2))\r\n if m == abs(r1 - r2):\r\n print(m + (abs(m - abs(c1 - c2))))\r\n else:\r\n print(m + (abs(m - abs(r1 - r2))))", "r1,c1,r2,c2 = map(int, input().split())\r\ndef rook(r1,c1,r2,c2):\r\n if r1 == r2 or c1 == c2:\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef bishop(r1,c1,r2,c2):\r\n if (r1 + c1) % 2 != (r2 + c2) % 2:\r\n return 0\r\n else:\r\n if r1-c1 == r2 - c2 or r1+c1 == r2 + c2:\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef king(r1,c1,r2,c2):\r\n return max(abs(r1-r2), abs(c1-c2))\r\n\r\nr = rook(r1,c1,r2,c2)\r\nb = bishop(r1,c1,r2,c2)\r\nk = king(r1,c1,r2,c2)\r\nprint(r,b,k)\r\n\r\n", "x1, y1, x2, y2 = map(int, input().split())\r\ns1 = 0\r\ns2 = 0\r\ns3 = 0\r\nif x1 != x2:\r\n s1 += 1\r\nif y1 != y2:\r\n s1 += 1\r\nif abs(y2 - y1) == abs(x2 - x1):\r\n s2 = 1\r\nelif (x2 + y2) % 2 != (x1 + y1) % 2:\r\n s2 = 0\r\nelse:\r\n s2 = 2\r\nx = min(abs(x1 - x2), abs(y1 - y2))\r\ns3 = abs(x1 - x2) + abs(y1 - y2) - x\r\nprint(s1, s2, s3)\r\n\n# Tue Jul 11 2023 12:50:42 GMT+0300 (Moscow Standard Time)\n", "r1,c1,r2,c2=map(int,input().split())\r\na=[]\r\nif r1==r2 or c1==c2:\r\n a.append(1)\r\nelse:\r\n a.append(2)\r\nif abs(r1-r2)==abs(c1-c2):\r\n a.append(1)\r\nelif (r1+c1)%2==0 and (r2+c2)%2!=0 or (r1+c1)%2!=0 and (r2+c2)%2==0:\r\n a.append(0)\r\nelse:\r\n a.append(2) \r\nif abs(r1-r2)==abs(c1-c2):\r\n a.append(abs(r1-r2))\r\nelse:\r\n a.append(max(abs(r1-r2),abs(c1-c2)))\r\nprint(*a) ", "import math\r\nimport sys\r\nfrom collections import defaultdict\r\nfrom collections import Counter\r\nfrom collections import deque\r\nimport bisect\r\ninput = iter(sys.stdin.buffer.read().decode().splitlines()).__next__\r\nilele = lambda: map(int,input().split())\r\nalele = lambda: list(map(int, input().split()))\r\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\r\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\r\nINF = 10 ** 18\r\nMOD = 10 ** 9 + 7\r\n\r\nr1,c1,r2,c2 = ilele()\r\nAns1,Ans2,Ans3 = 0,0,0\r\nif (r1,c1) == (r2,c2):\r\n print(0,0,0)\r\nelse:\r\n Ans1 = 2 - (r1== r2) - (c1 == c2)\r\n #print(Ans1)\r\n \r\n if (r1 + c1)%2 != (r2 + c2)%2:\r\n Ans2 = 0\r\n else:\r\n if c1 != c2:\r\n y = (r2-r1)/(c2-c1)\r\n else:\r\n y = (c2-c1)/(r1-r2)\r\n if y==1 or y==-1:\r\n Ans2 = 1\r\n else:\r\n Ans2 = 2\r\n #print(Ans2)\r\n z = min(abs(r1-r2),abs(c1-c2))\r\n Ans3 = abs(r1-r2) + abs(c1-c2) - z\r\n #print(Ans3)\r\n print(Ans1,Ans2,Ans3)\r\n ", "r1 ,c1 ,r2 ,c2 = map(int,input().split())\r\nans1 = ans2 = ans3 = 0\r\nif r1 == r2 or c1 == c2 :\r\n ans1 = 1 \r\nelse :\r\n ans1 = 2 \r\nans3 = max(abs(r1-r2),abs(c1-c2))\r\nif (r1 % 2) == (c1 % 2) :\r\n co1 = 1 \r\nelse :\r\n co1 = 0 \r\nif (r2 % 2) == (c2 % 2) :\r\n co2 = 1 \r\nelse :\r\n co2 = 0 \r\nif co1!=co2 :\r\n ans2 = 0 \r\nelse :\r\n if (abs(r1-r2) == abs(c1-c2)):\r\n ans2 = 1 \r\n else :\r\n ans2 = 2 \r\nprint(f\"{ans1} {ans2} {ans3}\")", "x1,y1,x2,y2 = map(int, input().split())\r\nsrc = (x1,y1)\r\ndest = (x2,y2)\r\n\r\nif x1 != x2 and y1 != y2:\r\n\ta = 2\r\nelse:\r\n\ta = 1\r\n\r\nx = abs(x1-x2)\r\ny = abs(y1-y2)\r\n\r\nc = max(x,y)\r\nb = 0\r\n\r\nif (abs(x-y) % 2 == 0):\r\n\tb = 2\r\nif x == y:\r\n\tb = 1\r\n\r\nprint(a,b,c)\r\n", "r1, c1, r2, c2 = map(int, input().split())\r\nrook = [2, 1][r1 == r2 or c1 == c2]\r\nif (r1 + c1) % 2 == (r2 + c2) % 2:\r\n if abs(r2 - r1) == abs(c2 - c1):\r\n bishop = 1\r\n else:\r\n bishop = 2\r\nelse:\r\n bishop = 0\r\nking = max(abs(r1 - r2), abs(c1 - c2))\r\nprint(rook, bishop, king)\r\n", "from_file, from_row, to_file, to_row = map(int, input().split(' '))\r\n\r\n# rook\r\nrook_moves = (from_file != to_file) + (from_row != to_row)\r\n\r\n# bishop\r\nbishop_moves = 0\r\nif (from_file + from_row) % 2 == (to_file + to_row) % 2:\r\n\t# on the same coloured square: can make the move\r\n\t# is it not aligned on a downwards diagonal?\r\n\tif to_file - from_file != to_row - from_row:\r\n\t\tbishop_moves += 1\r\n\r\n\t# is it not aligned on an upwards diagonal?\r\n\tif to_file - from_file != -(to_row - from_row):\r\n\t\tbishop_moves += 1\r\n\r\n\r\n# king\r\nking_moves = max( abs(to_file - from_file), abs(to_row - from_row) )\r\n\r\nprint(rook_moves, bishop_moves, king_moves)\r\n", "r1, c1, r2, c2 = map(int, input().split())\n\nif r1 == r2 or c1 == c2:\n r= 1\nelse:\n r = 2\nif abs(r2 - r1) == abs(c2 - c1):\n b = 1\nelse:\n if (r1 + c1) % 2 != (r2 + c2) % 2:\n b = 0\n else:\n b = 2\nk = max(abs(r2 - r1), abs(c2 - c1))\n\nprint(r, b, k)\n\n \t\t\t \t \t\t\t\t\t \t\t\t\t \t\t\t\t \t\t\t\t", "a = input() \r\nr1 = int(a[0])\r\nc1 = int(a[2])\r\nr2= int (a[4])\r\nc2 = int (a[6])\r\nif r1 == r2 or c1==c2 : \r\n if r1 == r2 and c1==c2 :\r\n print(0,end=' ')\r\n else :\r\n print(1,end=' ')\r\nelse : \r\n print(2,end=' ')\r\n\r\nif abs(r1-r2) == abs(c1-c2) :\r\n if r1 == r2 and c1==c2:\r\n print(0,end=' ')\r\n else :\r\n print(1,end=' ')\r\nelif ( (r1 % 2 ==0 and c1 %2 ==0) or (r1 % 2 !=0 and c1 %2 !=0)) != ((r2 % 2 ==0 and c2 %2 ==0) or (r2 % 2 !=0 and c2 %2 !=0)):\r\n print(0,end=' ')\r\n\r\nelse : \r\n print(2,end=' ')\r\n\r\n\r\nif abs(r1-r2) >= abs(c1-c2) :\r\n print(abs(r1-r2))\r\n \r\nelif abs(c1-c2) >= abs(r1-r2) :\r\n print(abs(c1-c2))\r\nelse : \r\n print(0)\r\n ", "r1,c1,r2,c2 = list(map(int,input().split()))\r\nif r1 == r2 or c1 == c2:\r\n ladia=1\r\n if r1 == r2:\r\n king = abs(c1-c2)\r\n elif c1 == c2:\r\n king = abs(r1-r2)\r\nelse:\r\n ladia=2\r\n king=max(abs(r1-r2),abs(c1-c2))\r\nif (r1 % 2 == 1 and c1 % 2 == 1) or (r1 % 2 == 0 and c1 % 2 == 0):\r\n color1=\"black\"\r\nelse:\r\n color1=\"white\"\r\nif (r2 % 2 == 1 and c2 % 2 == 1) or (r2 % 2 == 0 and c2 % 2 == 0):\r\n color2=\"black\"\r\nelse:\r\n color2=\"white\"\r\nif color1 == color2:\r\n if abs(r1-r2) == abs(c1-c2):\r\n slon=1\r\n else:\r\n slon=2\r\nelse:\r\n slon=0\r\nprint(ladia,slon,king)\r\n", "a,b,c,d=map(int,input().split())\r\ne=abs(a-c)\r\nf=abs(b-d)\r\nt=0\r\n\r\nif (e-f)%2==0:\r\n t=2\r\nif e==f:\r\n t=1\r\n\r\nprint((a!=c)+(b!=d), t, max(e,f))\r\n", "r1,c1,r2,c2=map(int,input().split())\r\nif r1==r2 or c1==c2:\r\n r=1\r\nelse:\r\n r=2\r\nif abs((r1+c1)-(r2+c2))%2==1:\r\n b=0\r\nelif abs(c2-c1)==abs(r2-r1):\r\n b=1\r\nelse:\r\n b=2\r\nk=max(abs(c2-c1),abs(r2-r1))\r\nprint(r,b,k)", "def isOdd(num): # aux function to know if a number is odd or not\n if num % 2 == 0: return False\n return True\n\ndef isBlackTile(tile): # aux function to know if a tile is black or white\n if (isOdd(tile[0]) and isOdd(tile[1])) or (not isOdd(tile[0]) and not isOdd(tile[1])):\n return True\n return False\n\ndef main(inp):\n origin = [inp[0], inp[1]]\n destination = [inp[2], inp[3]]\n res = \"\"\n # lets go for rook\n # check if already in place\n # if not, check if 1 move is the solution\n # if not, then it's 2 moves\n if origin == destination:\n res += \"0 \"\n if origin[0] == destination[0] or origin[1] == destination[1]:\n res += \"1 \"\n else:\n res += \"2 \"\n # lets go for bishop\n # check if already in place\n # if not, check if available in 1 move\n # if not, check if available in 2 moves\n # if not, then it cannot be done\n if origin == destination:\n res += \"0 \"\n elif abs(origin[0] - destination[0]) == abs(origin[1] - destination[1]):\n res += \"1 \"\n elif isBlackTile(origin) == isBlackTile(destination):\n res += \"2 \"\n else:\n res += \"0 \"\n\n # lets go for king\n # movement is equal to the biggest absolute difference between axis\n diffX = abs(origin[0]-destination[0])\n diffY = abs(origin[1]-destination[1])\n res += str(max(diffX, diffY))\n\n return res\n\ndef test(testNum, inp, ans):\n print(\"Case \"+str(testNum)+\"..........\", end=\" \")\n res = main(inp)\n assert res == ans, \"out: \"+ str(res)+\" Should be: \"+str(ans)\n print(\"Success!\")\n\ndef tdd():\n test(1, [4, 3, 1, 6], \"2 1 3\")\n test(2, [5, 5, 5, 6], \"1 0 1\")\ndef user():\n inp = list(map(int, input().split()))\n print(main(inp))\n\n#tdd() # execute test (only during development)\nuser()\n\t\t \t \t \t\t\t\t\t\t \t \t\t\t\t \t\t \t", "r1, c1, r2, c2 = map(int, input().split())\n\nrk = 2\nif r1 == r2 or c1 == c2:\n rk = 1\n\nbi = 2\nif (r1 + c1) % 2 != (r2 + c2) % 2:\n bi = 0\nelif r1 + c1 == r2 + c2 or r1 + c2 == r2 + c1:\n bi = 1\n\nk = max(abs(r1 - r2), abs(c1 - c2))\n\nprint(rk, bi, k)\n \t\t \t\t\t \t\t\t \t\t \t \t \t\t \t\t \t", "import sys\r\ninput = sys.stdin.readline\r\n\r\nx, y, x1, y1 = map(int, input().split())\r\n\r\na, b, c = 0, 0, 0\r\nif x1 == x and y1 == y:\r\n a = b = c = 0\r\nelse:\r\n m, n = x1 - x, y1 - y\r\n if x1 == x or y1 == y:\r\n a = 1\r\n else:\r\n a = 2\r\n\r\n if abs(m) == abs(n):\r\n b = 1\r\n elif (m + n) % 2:\r\n b = 0\r\n else:\r\n b = 2\r\n\r\n c = max(abs(m), abs(n))\r\n\r\nprint(a, b, c)\r\n\r\n", "# import math\r\n#n=int(input())\r\nr1,c1,r2,c2 = map(int, input().strip().split(' '))\r\n#a = list(map(int, input().strip().split(' ')))\r\nr=0\r\nb=0\r\nk=0\r\nif r1==r2 or c1==c2:\r\n r=1\r\nelse:\r\n r=2\r\nk=max(abs(r2-r1),abs(c2-c1))\r\nl1=abs(r2-r1)\r\nl2=abs(c1-c2)\r\nif (l1%2==0 and l2%2!=0) or (l1%2!=0 and l2%2==0):\r\n b=0\r\nelse:\r\n if l1==l2:\r\n b=1\r\n else:\r\n b=2\r\nprint(r,b,k,end=\" \")", "a, b, c, d = map(int,input().split())\r\n\r\nx = abs(a-c)\r\ny = abs(b-d)\r\nz = 0\r\n \r\nif (x-y) % 2 == 0:\r\n z = 2\r\n\r\nif x == y:\r\n z = 1\r\n \r\nprint((a != c)+(b != d), z, max(x,y))", "class CodeforcesTask370ASolution:\r\n def __init__(self):\r\n self.result = ''\r\n self.cords = []\r\n\r\n def read_input(self):\r\n self.cords = [int(x) for x in input().split(\" \")]\r\n\r\n def process_task(self):\r\n h = abs(self.cords[2] - self.cords[0])\r\n v = abs(self.cords[3] - self.cords[1])\r\n if self.cords[0] == self.cords[2] or self.cords[1] == self.cords[3]:\r\n rook = 1\r\n else:\r\n rook = 2\r\n if (self.cords[0] + self.cords[1]) % 2 != (self.cords[2] + self.cords[3]) % 2:\r\n bishop = 0\r\n elif h == v:\r\n bishop = 1\r\n else:\r\n bishop = 2\r\n king = max(h, v)\r\n self.result = \"{0} {1} {2}\".format(rook, bishop, king)\r\n\r\n def get_result(self):\r\n return self.result\r\n\r\n\r\nif __name__ == \"__main__\":\r\n Solution = CodeforcesTask370ASolution()\r\n Solution.read_input()\r\n Solution.process_task()\r\n print(Solution.get_result())\r\n", "F = list(map(int, input().split()))\n\nX = [F[0], F[1]]\nY = [F[2], F[3]]\n\ndef tor(x, y):\n if x[0] == y[0] or x[1] == y[1]:\n return 1\n return 2\n\ndef alf(x, y):\n if (x[0] + x[1]) % 2 == (y[0] + y[1]) % 2:\n if abs(y[0] - x[0]) == abs(y[1] - x[1]):\n return 1\n return 2\n return 0\n\ndef kng(x, y):\n return max(abs(y[0] - x[0]), abs(y[1] - x[1]))\n\n\nprint(tor(X, Y), alf(X, Y), kng(X, Y))\n \t\t \t \t\t \t\t \t\t \t", "r1,c1,r2,c2=map(int,input().split())\r\nl=[]\r\nbishop=[]\r\nwhite=[]\r\nfor i in range(1,9):\r\n for t in [1,3,5,7]:\r\n if i%2==1:\r\n white.append([i,t])\r\n else:\r\n white.append([i,t+1])\r\nx,y=r1,c1\r\nwhile x>1 and y>1:\r\n x-=1\r\n y-=1\r\n bishop.append([x,y])\r\nx,y=r1,c1\r\nwhile x<8 and y>1:\r\n x+=1\r\n y-=1\r\n bishop.append([x,y])\r\nx,y=r1,c1\r\nwhile x > 1 and y < 8:\r\n x-=1\r\n y+=1\r\n bishop.append([x,y])\r\nx,y=r1,c1\r\nwhile x < 8 and y < 8:\r\n x+=1\r\n y+=1\r\n bishop.append([x,y])\r\nif (r1==r2 and c1==c2):\r\n print(0,0,0)\r\n exit()\r\nif r1==r2 or c1==c2:\r\n l.append(1)\r\nelse:\r\n l.append(2)\r\nif ([r1,c1] in white and [r2,c2] not in white) or([r1,c1] not in white and [r2,c2] in white):\r\n l.append(0)\r\nelif [r2,c2] in bishop:\r\n l.append(1)\r\nelse:\r\n l.append(2)\r\nl.append(max(abs(r1-r2),abs(c1-c2)))\r\nprint(*l)\r\n", "line = input().split(\" \")\nr1 = int(line[0])\nc1 = int(line[1])\nr2 = int(line[2])\nc2 = int(line[3])\n#torre\nmovT = 0;\nif r1 == r2 or c1 == c2:\n movT = 1\nelse:\n movT = 2\n#alfil\nmovA = 0\nif abs((r1+c1)%2 -(r2+c2)%2)==1:\n movA = 0\nelse:\n if abs(r1-r2)==abs(c1-c2):\n movA = 1\n else:\n movA = 2\n#rey\nmovR = max(abs(r1-r2),abs(c1-c2))\nprint(f\"{movT} {movA} {movR}\")\n\t\t \t\t\t \t \t \t \t \t \t\t", "#Rook, Bishop and King\r\n# graph, maths, shortest path\r\n\r\nr1, c1, r2, c2 = map(int, input().split())\r\n# For Bishop\r\nBishop = -1\r\nif((r1+c1) % 2 != (r2+c2) % 2):\r\n Bishop = 0\r\nelif(abs(r2-r1) == abs(c2-c1)):\r\n Bishop = 1\r\nelse:\r\n Bishop = 2\r\n\r\n# For Rook\r\n\r\nRook = -1\r\nif(r1==r2 or c1==c2):\r\n Rook = 1\r\nelse:\r\n Rook = 2\r\n\r\n# For King\r\n\r\nKing = max(abs(r1-r2),abs(c1-c2))\r\nprint(Rook,Bishop,King)\r\n", "r1, c1 , r2, c2= map(int, input().split())\r\n\r\n# Torre\r\nif r1 == r2 or c1 == c2:\r\n print(1, end = \" \") \r\nelse: \r\n print(2 , end = \" \")\r\n# Alfil \r\nif (r1+c1)%2 != (r2+c2)%2:\r\n print(0, end = \" \")\r\nelse:\r\n moves = []\r\n posibles = [(1,1), (-1,-1), (-1,1),(1,-1)]\r\n for k in posibles:\r\n for i in range(8):\r\n moves.append((r1 + k[0]*i, c1 + k[1]*i))\r\n if (r2,c2) in moves:\r\n print(1, end = \" \")\r\n else:\r\n print(2, end = \" \")\r\n# Rey\r\nprint(max([abs(r1-r2) , abs(c1-c2)] ))", "def nb_rook(pos1, pos2):\r\n if pos1[0] == pos2[0] or pos1[1] == pos2[1]:\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef nb_bishop(pos1,pos2):\r\n if (pos1[0]+pos2[0]-(pos1[1]+pos2[1]))%2 == 1:\r\n return 0\r\n elif pos1[1] - pos1[0] == pos2[1] - pos2[0] or pos1[1]+pos1[0] == pos2[1]+pos2[0]:\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef nb_king(pos1,pos2):\r\n return max(abs(pos2[0]-pos1[0]),abs(pos2[1]-pos1[1]))\r\n\r\na,b,c,d = tuple(map(int,input().split()))\r\npos1 = (a,b)\r\npos2 = (c,d)\r\nnbr = nb_rook(pos1,pos2)\r\nnbb = nb_bishop(pos1,pos2)\r\nnbk = nb_king(pos1,pos2)\r\nprint(nbr, nbb, nbk)", "a,b,c,d = map(int,input().split())\r\n\r\ns=str(int(a!=c)+int(b!=d))+' '\r\nif (a+b) % 2 != (c+d) %2 : s+='0 '\r\nelif a+b == c+d or a-b==c-d : s+='1 '\r\nelse :s+='2 '\r\ns+=str(max(abs(a-c),abs(b-d)))\r\nprint(s)", "a=list(map(int,input().split()))\nstart=(a[0],a[1])\ndest=(a[2],a[3])\nif start==dest:\n print(\"0 0 0\")\nelse:\n if(start[0]==dest[0] or start[1]==dest[1] ):\n rook=1\n\n\n else:\n rook=2\n\n king=max(abs(start[0]-dest[0]),abs(start[1]-dest[1]))\n bishop=0\n if ((start[0]+start[1])%2==(dest[0]+dest[1])%2):\n if(abs(start[0]-dest[0])==abs(start[1]-dest[1])):\n bishop=1\n else:\n bishop=2\n print(f\"{rook} {bishop} {king}\")\n\t\t \t \t\t \t\t\t \t \t\t \t\t \t \t \t", "def solve(a):\n start = (a[0] - 1, a[1] - 1) \n end = (a[2] - 1, a[3] - 1) \n king = max(abs(start[0] - end[0]), abs(start[1] - end[1]))\n if start[0] == end[0] or start[1] == end[1]:\n rook = 1\n else:\n rook = 2\n \n if (start[0] + start[1]) % 2 != (end[1] + end[0]) % 2:\n bishop = 0\n elif abs(start[0] - end[0]) == abs(start[1] - end[1]):\n bishop = 1\n else:\n bishop = 2\n\n return \" \".join([str(x) for x in [rook, bishop, king]])\n\na = [int(x) for x in input().split()]\nprint(solve(a))\n", "r1, c1, r2, c2 = map(lambda x: int(x)-1, input().split())\r\n\r\ndef solve_bishop(r1, c1, r2, c2):\r\n if abs(r1-r2) == abs(c2-c1):\r\n return 1\r\n elif (r1+c1) % 2 == (r2+c2) % 2:\r\n return 2\r\n else:\r\n return 0\r\n\r\ndef solve_king(r1, c1, r2, c2):\r\n if r1 == r2 and c1 == c2:\r\n return 0\r\n \r\n if r1 == r2:\r\n r_inc = 0\r\n else:\r\n r_inc = 1 if r2 > r1 else -1\r\n\r\n if c1 == c2:\r\n c_inc = 0\r\n else:\r\n c_inc = 1 if c2 > c1 else -1\r\n \r\n return 1 + solve_king(r1 + r_inc, c1 + c_inc, r2, c2)\r\n\r\ndef solve(r1, c1, r2, c2):\r\n if r1 == r2 and c1 == c2:\r\n return 0, 0, 0\r\n \r\n if r1 != r2 and c1 != c2:\r\n rook = 2\r\n else:\r\n rook = 1\r\n\r\n bishop = solve_bishop(r1, c1, r2, c2)\r\n king = solve_king(r1, c1, r2, c2)\r\n\r\n return rook, bishop, king\r\n\r\nprint(*solve(r1, c1, r2, c2))\r\n", "def main():\n while True:\n try:\n x1, y1, x2, y2 = map(int, input().split())\n ans = [0] * 3\n if x1 == x2 and y1 == y2:\n ans[0], ans[1], ans[2] = 0, 0, 0\n else:\n if x1 == x2 or y1 == y2:\n ans[0] = 1\n else:\n ans[0] = 2\n if (abs(x1 - x2) + abs(y1 - y2)) % 2 == 0:\n if abs(x1 - x2) == abs(y1 - y2):\n ans[1] = 1\n else:\n ans[1] = 2\n else:\n ans[1] = 0\n ans[2] = abs(x1 - x2) if abs(x1 - x2) > abs(y1 - y2) else abs(y1 - y2)\n print(*ans)\n except EOFError:\n break\n\nif __name__ == '__main__':\n main()\n\n \t\t\t\t \t\t \t\t\t\t \t \t \t \t \t\t", "(r1,c1,r2,c2) = input().split()\r\nr1 = int(r1)\r\nc1 = int(c1)\r\nr2 = int(r2)\r\nc2 = int(c2)\r\ns = ''\r\nif r1 == r2 or c1 == c2:\r\n s += '1'\r\nelse:\r\n s += '2'\r\na = r1 + c1\r\nb = r2 + c2\r\nif (a + b)%2 == 1:\r\n s += ' 0 '\r\nelif abs(r2-r1) == abs(c2-c1):\r\n s += ' 1 '\r\nelse:\r\n s += ' 2 '\r\na = abs(r1-r2)\r\nb = abs(c1-c2)\r\nc =max(a,b)\r\ns += str(c)\r\nprint (s)\r\n \r\n", "r1,c1,r2,c2=map(int,input().split())\r\nprint(1+(r1!=r2 and c1!=c2),(1+(abs(r1-r2)!=abs(c1-c2)))*((r1+c1-r2-c2)%2==0),max(abs(r1-r2),abs(c1-c2)))", "from collections import deque\r\nr1, c1, r2, c2 = map(int, input().split(' '))\r\nseen = set()\r\n\r\ndef invalid (row, col):\r\n if row < 0 or row >= 8: return True\r\n if col < 0 or col >= 8: return True\r\n if (row, col) in seen: return True\r\ndef rook(r1, c1, r2, c2):\r\n if r1 == r2 or c1 == c2: return 1\r\n else: return 2\r\ndef king(r1, c1, r2, c2):\r\n q = deque()\r\n q.append((r1, c1))\r\n level = 0\r\n while q:\r\n for i in range(len(q)):\r\n a, b = q.popleft() \r\n if (a, b) == (r2, c2): return level\r\n directions = [[1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]]\r\n for dr, dc in directions:\r\n if not invalid(dr + a, dc + b):\r\n q.append((dr + a, dc + b))\r\n seen.add((dr + a, dc + b))\r\n level += 1\r\n return 0\r\n\r\ndef bishop(r1, c1, r2, c2):\r\n if (r1 + c1) == (r2 + c2) or (r1 - c1) == (r2 - c2): return 1\r\n if ((not (r1 % 2) and not (c1 % 2))) or ((r1 % 2) and (c1 % 2)):\r\n if not(r2 % 2) and not (c2 % 2): return 2\r\n if (r2 % 2) and (c2 % 2): return 2\r\n if (not (r1 % 2) and (c1 % 2)) or ((r1 % 2) and not (c1 % 2)):\r\n if not (r2 % 2) and (c2 % 2): return 2\r\n if (r2 % 2) and not (c2 % 2): return 2\r\n return 0 \r\n\r\nroo = rook(r1, c1, r2, c2)\r\nbish = bishop(r1, c1, r2, c2)\r\nseen.add((r1 - 1, c1 - 1))\r\nkin = king(r1 - 1, c1 - 1, r2 - 1, c2 - 1)\r\nprint(roo, bish, kin)", "r1,c1,r2,c2 = map(int,input().split())\nrk=0\nif(r1==r2 or c1==c2):\n rk=1\nelse:\n rk=2\nkg=0\nmx=max((abs(r1-r2)),(abs(c1-c2)))\nkg=mx\nb=0\nif abs(r2-r1)==abs(c2-c1):\n b=1\nelse:\n b=2\nb1,b2='',''\nif(r2%2==0 and c2%2==0):\n b1='b'\nelif(r2%2!=0 and c2%2!=0):\n b1='b'\nelse:\n b1='w'\nif(r1%2==0 and c1%2==0):\n b2='b'\nelif(r1%2!=0 and c1%2!=0):\n b2='b'\nelse:\n b2='w'\nif(b1!=b2):\n b=0\n\nprint(rk,b,kg)\n \t\t\t\t \t\t\t \t\t \t \t\t \t \t\t\t\t\t", "r1,c1,r2,c2 = input().split(\" \")\nr1,c1,r2,c2 = int(r1),int(c1),int(r2),int(c2)\nif (r1==r2) and (c1==c2): r = 0\nelif (r1==r2) or (c1==c2): r = 1\nelse: r = 2\nif (r1%2==c1%2)!=(r2%2==c2%2) or (r1==r2 and c1==c2): b = 0\nelif r2-r1==c2-c1 or r2-r1==c1-c2 or r1-r2==c2-c1 or r1-r2==c1-c2: b = 1\nelse: b = 2\nif c2>=c1:\n\tif r2<=r1:\n\t\tif c2-c1>=r1-r2: k = c2-c1 \n\t\telif c2-c1<=r1-r2: k = r1-r2\n\telif r2>=r1:\n\t\tif c2-c1>=r2-r1: k = c2-c1\n\t\telif c2-c1<=r2-r1: k = r2-r1 \nelif c1>=c2:\n\tif r2<=r1:\n\t\tif c1-c2>=r1-r2: k = c1-c2\n\t\telif c1-c2<r1-r2: k = r1-r2\n\telif r2>=r1:\n\t\tif c1-c2>=r2-r1: k = c1-c2\n\t\telif c1-c2<=r2-r1: k = r2-r1\nif k<0: k = 0-k\nprint(r,b,k)\n \t\t \t \t\t \t \t \t \t\t \t\t \t\t \t\t", "import sys\r\nlines = sys.stdin.read().splitlines()\r\noutput = []\r\n\r\nr1, c1, r2, c2 = map(lambda x: int(x)-1, lines[0].split())\r\n\r\n#rook\r\nif r1 == r2 or c1 == c2:\r\n output.append(1)\r\nelse:\r\n output.append(2)\r\n\r\n#bishop\r\nif (r1 + c1) % 2 != (r2 + c2) % 2:\r\n output.append(0)\r\nelif abs(r1-r2) == abs(c1-c2):\r\n output.append(1)\r\nelse:\r\n output.append(2)\r\n\r\n#king\r\noutput.append(max(abs(r1-r2), abs(c1-c2)))\r\n\r\nprint(\" \".join(map(str, output)))", "def main():\n\n r1, c1, r2, c2 = map(int, input().split())\n r_moves, k_moves, b_moves = 0, 0, 0\n\n if r1 == r2 and c1 == c2:\n print(\"0 0 0\")\n else:\n\n if r1 == r2 or c1 == c2:\n r_moves = 1\n else:\n r_moves = 2\n \n if (r1 + c1) % 2 == (r2 + c2) % 2 and abs(r1 - r2) == abs(c1 - c2):\n b_moves = 1\n elif (r1 + c1) % 2 == (r2 + c2) % 2 and abs(r1 - r2) != abs(c1 - c2):\n b_moves = 2\n else:\n b_moves = 0\n\n if abs(r1 - r2) == abs(c1 - c2):\n k_moves = abs(r1 - r2)\n else: \n k_moves = min(abs(r1 - r2), abs(c1 - c2)) + abs(abs(c1-c2) - abs(r1-r2))\n \n print(f'{r_moves} {b_moves} {k_moves}')\n\nmain() \n \t \t \t\t\t \t\t\t \t \t\t\t \t\t\t", "#king = min +1 + max - (min+1) \r\n# haathi rok if r1 == r2 or c1 == c2 then 1 else 2\r\n# if r2 - r1 == c2 -c1 then 1 else 2 \r\nrc = [int(x) for x in input().split()]\r\nrone = rc[0]\r\ncone = rc[1]\r\nrtwo = rc[2]\r\nctwo = rc[3]\r\nz = max(abs(rtwo - rone), abs(ctwo - cone))\r\nking = z\r\nif abs( rtwo - rone) == abs(ctwo - cone) :\r\n bishop = 1 # elephant , haathi\r\nelif( rtwo -rone - ctwo +cone )%2 == 0:\r\n bishop = 2 \r\nelse:\r\n bishop = 0 # camel, unt\r\nif rone == rtwo or cone == ctwo:\r\n rook = 1\r\nelse:\r\n rook = 2 \r\nprint(rook, bishop, king) \r\n", "for _ in range(1):\r\n x1,y1,x2,y2=map(int,input().split())\r\n s1=0\r\n s2=0\r\n s3=0\r\n if x1!=x2:\r\n s1+=1\r\n if y1!=y2:\r\n s1+=1\r\n if abs(y2-y1)==abs(x2-x1):\r\n s2=1\r\n elif (x2+y2)%2!=(x1+y1)%2:\r\n s2=0\r\n else:\r\n s2=2\r\n x=min(abs(x1-x2),abs(y1-y2))\r\n s3=abs(x1-x2)+abs(y1-y2)-x\r\n print(s1,s2,s3)", "import logging\n\nl = logging.Logger(\"\")\nh = logging.StreamHandler()\nf = logging.Formatter(fmt=\"[{filename}:{lineno}] {msg}\", style=\"{\")\nh.setFormatter(f)\nl.addHandler(h)\nbug = l.info\n\n# To disable uncomment the next line\n# bug = lambda x:None\n\n# teste=(1,2,3,4)\n# bug(f'{teste=}')\n# bug(f'{2*teste=}')\n\n# -------------------------------------------------------------------- #\nfrom math import sqrt\n\n\ndef main():\n torre = bispo = rei = 0\n i1, j1, i2, j2 = map(int, input().split())\n # torre\n if i1 != i2:\n torre += 1\n if j1 != j2:\n torre += 1\n\n # rei\n if abs(i1 - i2) >= abs(j1 - j2):\n rei = abs(i1 - i2)\n else:\n rei = abs(j1 - j2)\n\n # bispo\n if abs(i1 - i2) == abs(j1 - j2):\n bispo = 1\n elif abs(i1 - i2) % 2 == 1 and abs(j1 - j2) % 2 == 1:\n bispo = 2\n elif abs(i1 - i2) % 2 == 0 and abs(j1 - j2) % 2 == 0:\n bispo = 2\n\n print(torre, bispo, rei)\n\n\nif __name__ == '__main__':\n main()\n\n\t\t\t \t\t \t \t \t \t \t \t \t\t\t\t \t\t", "r,c,r1,c1 = map(int,input().split())\r\nrk = 1 if r==r1 or c==c1 else 2\r\nb = 0 if (r+c)%2 != (r1+c1)%2 else (1 if abs(r-r1)==abs(c-c1) else 2)\r\nk = max(abs(r1-r),abs(c1-c))\r\nprint(rk,b,k)", "inn = input().split()\ninn = list(map(int,inn))\na = [inn[0],inn[1]]\nb = [inn[2],inn[3]]\n\nx = abs(a[0]-b[0])\ny = abs(a[1]-b[1])\none = 0\nif x > 0:\n one += 1\nif y > 0:\n one += 1\n\nif (x+y) %2 != 0:\n two = 0\nelse:\n if x == y:\n two = 1\n else:\n two = 2\n\ntree = max(x, y)\nprint(one,two,tree)\n\t\t \t \t\t\t\t\t\t \t \t\t\t \t\t \t\t\t\t", "y1, x1, y2, x2 = map(int, input().split())\r\nres = ''\r\nif x1 == x2 or y1 == y2: # ладья\r\n res += '1 '\r\nelse:\r\n res += '2 '\r\nif (x1 + y1) % 2 == (x2 + y2) % 2: # офицер\r\n if abs(x1 - x2) == abs(y1 - y2):\r\n res += '1 '\r\n else:\r\n res += '2 '\r\nelse:\r\n res += '0 '\r\nxx = abs(x1 - x2)\r\nyy = abs(y1 - y2)\r\ncount = 0\r\nwhile xx > 0 or yy > 0: # король\r\n if xx > 0 and yy > 0:\r\n xx -= 1\r\n yy -= 1\r\n elif xx > 0:\r\n xx -= 1\r\n elif yy > 0:\r\n yy -= 1\r\n count += 1\r\nres += str(count)\r\nprint(res)\r\n", "a,b,c,d=map(int,input().split())\r\na = abs(a-c)\r\nb = abs(b-d)\r\n\r\nx = min(a, 1)+min(b, 1)\r\ny = max(a, b)\r\nz = 2\r\nif a==b:\r\n z=1\r\nif a+b==0 or (a+b)%2:\r\n z=0\r\n\r\nprint(x, z, y)\r\n", "def absdif(a,b):\n if a-b >= 0:\n return a-b\n return b-a\n\nr1, c1, r2, c2 = [int(i) for i in input().split()]\nrm = 2\nbm = 0\nkm = max(absdif(r2,r1),absdif(c2,c1))\nif r1 == r2:\n rm -=1\nif c1 == c2:\n rm -=1\nif (r1+c1)%2 == (r2+c2)%2:\n if c1 == c2 and r1 == r2:\n bm = 0\n elif absdif(c1,c2) == absdif(r1,r2):\n bm = 1\n else:\n bm = 2\nprint(rm, end = \" \")\nprint(bm, end = \" \")\nprint(km)\n\n \t\t \t \t \t\t \t \t \t\t\t", "r1, c1, r2, c2 = map(int, input().split())\r\nr_dif = abs(r2 - r1)\r\nc_dif = abs(c2 - c1)\r\nprint(0, 0, 0) if r_dif == 0 and c_dif == 0 else print(1 if r_dif == 0 or c_dif == 0 else 2, 0 if (r_dif+c_dif)%2 == 1 else (1 if r_dif == c_dif else 2), max(r_dif, c_dif))", "def sign(num):\r\n\treturn -1 if num < 0 else 1\r\n\r\ndef rook(cord):\r\n\tif cord[0] == cord[2] and cord[1] == cord[3]:\r\n\t\treturn 0\r\n\tif cord[0] == cord[2] or cord[1] == cord[3]:\r\n\t\treturn 1\r\n\treturn 2 \r\n\r\ndef bishop(cord):\r\n\tif (cord[0] + cord[1]) % 2 != (cord[2] + cord[3]) % 2:\r\n\t\treturn 0\r\n\telif (cord[0] - cord[1] == cord[2] - cord[3]) or (cord[0] + cord[1] == cord[2] + cord[3]):\r\n\t\treturn 1\r\n\treturn 2\r\n\r\ndef king(cord):\r\n\treturn max(abs(cord[0] - cord[2]), abs(cord[1] - cord[3]))\r\n\r\ncord = list(map(int, input().split()))\r\nprint(rook(cord), bishop(cord), king(cord))\r\n", "def main():\n r1, c1, r2, c2 = map(int, input().split())\n print((r1 != r2) + (c1 != c2),\n 0 if (r1 + r2 + c1 + c2) & 1 else 1 if abs(r1 - r2) == abs(c1 - c2) else 2,\n max(abs(r1 - r2), abs(c1 - c2)))\n\n\nif __name__ == '__main__':\n main()\n", "x1,y1,x2,y2=list(map(int,input().split()))\r\na,b,c=0,0,0\r\n\r\nif x1==x2 or y1==y2:\r\n a=1\r\nelse:\r\n a=2\r\n \r\nc=max(abs(x1-x2),abs(y1-y2))\r\nif (abs(x1-x2)+abs(y1-y2))%2!=0:\r\n b=0\r\nelse:\r\n if abs(x1-x2)==abs(y1-y2):\r\n b=1\r\n else:\r\n b=2\r\nprint(a,b,c)\r\n\r\n", "r1, c1, r2, c2 = list(map(int, input().split()))\r\ndr, dc = abs(r2 - r1), abs(c2 - c1)\r\nrook = 0\r\nif dr != 0:\r\n rook += 1\r\nif dc != 0:\r\n rook += 1\r\nking = max(dr, dc)\r\nif (dr + dc) % 2:\r\n bishop = 0\r\nelif dr == dc:\r\n bishop = 1\r\nelse:\r\n bishop = 2\r\nprint(rook, bishop, king)", "r_1, c_1, r_2, c_2 = map(int, input().split())\r\n\r\n# Rook\r\nif r_1 == r_2 or c_1 == c_2:\r\n rook = 1\r\nelse:\r\n rook = 2\r\n\r\n# Bishop\r\nif abs(r_1 - r_2) == abs(c_1 - c_2):\r\n bishop = 1\r\nelif (r_1 + c_1) % 2 != (r_2 + c_2) % 2:\r\n bishop = 0\r\nelse:\r\n bishop = 2\r\n\r\n# King\r\nking = max(abs(r_1 - r_2), abs(c_1 - c_2))\r\nprint(\" \".join(map(str, [rook, bishop, king])))", "class Queue: # Initialize a queue\r\n def __init__(self):\r\n self.head = []\r\n self.tail = []\r\n\r\n def queue(self, item):\r\n self.tail.append(item)\r\n\r\n def __len__(self):\r\n return len(self.head + self.tail)\r\n\r\n def dequeue(self):\r\n if not self.head:\r\n self.head = self.tail[::-1]\r\n self.tail = []\r\n return self.head.pop()\r\n else:\r\n return self.head.pop()\r\n\r\n\r\ndef backtrack(start, destination, seen):\r\n path = []\r\n node = destination\r\n while True:\r\n path.append(node)\r\n if node == start:\r\n break\r\n node = seen[node]\r\n return len(path) - 1\r\n\r\n\r\ndef breadth_first_search(graph, start, destination):\r\n seen = {start: None}\r\n node = start\r\n queue = Queue()\r\n queue.queue(start)\r\n while queue:\r\n node = queue.dequeue()\r\n for neighbour in graph[node]:\r\n if neighbour not in seen:\r\n queue.queue(neighbour)\r\n seen[neighbour] = node\r\n if destination not in seen:\r\n return 0\r\n return backtrack(start, destination, seen)\r\n\r\n\r\ndef rook_adjacency(r, c):\r\n adjacency = []\r\n for a in range(1, 9):\r\n if a != c:\r\n adjacency.append((r, a))\r\n if a != r:\r\n adjacency.append((a, c))\r\n return adjacency\r\n\r\n\r\ndef bishop_adjacency(r, c):\r\n adjacency = []\r\n i = 1\r\n while 1 <= r + i <= 8 and 1 <= c + i <= 8:\r\n adjacency.append((r + i, c + i))\r\n i += 1\r\n i = -1\r\n while 1 <= r + i <= 8 and 1 <= c + i <= 8:\r\n adjacency.append((r + i, c + i))\r\n i -= 1\r\n i = 1\r\n while 1 <= r + i <= 8 and 1 <= c - i <= 8:\r\n adjacency.append((r + i, c - i))\r\n i += 1\r\n i = -1\r\n while 1 <= r + i <= 8 and 1 <= c - i <= 8:\r\n adjacency.append((r + i, c - i))\r\n i -= 1\r\n return adjacency\r\n\r\n\r\ndef king_adjacency(r, c):\r\n adjacency = []\r\n list = [-1, 0, 1]\r\n for i in list:\r\n for j in list:\r\n if (i, j) != (0, 0) and 1 <= r + i <= 8 and 1 <= c + j <= 8:\r\n adjacency.append((r + i, c + j))\r\n return adjacency\r\n\r\n\r\ndef king_graph():\r\n adjacency = {}\r\n for r in range(1, 9):\r\n for c in range(1, 9):\r\n adjacency[(r, c)] = king_adjacency(r, c)\r\n return adjacency\r\n\r\n\r\ndef bishop_graph():\r\n adjacency = {}\r\n for r in range(1, 9):\r\n for c in range(1, 9):\r\n adjacency[(r, c)] = bishop_adjacency(r, c)\r\n return adjacency\r\n\r\n\r\ndef rook_graph(): # t = o(n^3) with bfs but it is possible in t = o(n) with case -partitioning\r\n adjacency = {}\r\n for r in range(1, 9):\r\n for c in range(1, 9):\r\n adjacency[(r, c)] = rook_adjacency(r, c)\r\n return adjacency\r\n\r\n\r\ninput_list = input().split()\r\nstart = (int(input_list[0]), int(input_list[1]))\r\ndestination = (int(input_list[2]), int(input_list[3]))\r\nprint(breadth_first_search(rook_graph(), start, destination))\r\nprint(breadth_first_search(bishop_graph(), start, destination))\r\nprint(breadth_first_search(king_graph(), start, destination))\r\n\r\n\r\n", "r1,c1,r2,c2 = map(int,input().split())\r\na = []\r\nif r1 == r2 or c1 == c2:\r\n a.append(1)\r\nelse:\r\n a.append(2)\r\nif (r1 + c1) % 2 != (r2 + c2) % 2:\r\n a.append(0)\r\nelse:\r\n if r1 - c1 == r2 - c2 or r1 + c1 == r2 + c2 :\r\n a.append(1)\r\n else:\r\n a.append(2)\r\na.append(max(abs(r1-r2),abs(c1-c2)))\r\nprint(*a)", "rook,r1,c1,r2,c2=tuple([2]+[int(i)for i in input().split()])\ndr,dc=abs(r2-r1),abs(c2-c1)\nif r2==r1:rook-=1\nif c2==c1:rook-=1\nif(r1+c1)%2==(r2+c2)%2:\n if dr==dc:bishop=1\n else:bishop=2\nelse:bishop=0\nif dr>dc:king=dr\nelse:king=dc\nprint('{} {} {}'.format(rook,bishop,king))\n\n \t\t\t\t \t\t \t\t \t\t\t \t \t \t\t\t", "from collections import *\nfrom functools import reduce\nfrom itertools import *\nfrom heapq import *\nfrom sys import *\nfrom threading import *\n\ndirs4 = [[1, 0], [-1, 0], [0, 1], [0, -1]]\ndirs8 = [[1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [-1, -1], [1, -1], [-1,1]]\n\ndef _input(): return stdin.readline().rstrip(\"\\r\\n\") \ndef I(): return int(_input())\ndef II(): return _input()\ndef III(): return map(int, _input().split())\ndef IV(): return list(map(int, _input().split()))\ndef V(): return sorted(list(map(int, _input().split())))\ndef out(var): stdout.write(str(var) + \"\\n\")\n\ndef Solve():\n r1, c1, r2, c2 = III()\n A, B, C = 0, 0, 0\n if r1 == r2 and c1 == c2:\n A = 0\n elif r1 == r2 or c1 == c2:\n A = 1\n else:\n A = 2\n if (r1 + c1) % 2 != (r2 + c2) % 2:\n B = 0\n elif r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2:\n B = 1\n else:\n B = 2\n C = max(abs(r1 - r2), abs(c1 - c2))\n print(A, B, C)\n\n\nT = 1\nfor ___ in range(T):\n Solve()\n \n\n\"\"\"\nsetrecursionlimit(1<<30)\nstack_size(1<<27)\n\nmain_thread = Thread(target=Solve)\nmain_thread.start()\nmain_thread.join()\n\"\"\"\n", "ro, co, rk, ck = map(int, input().split())\r\ndr, dc = abs(rk - ro), abs(co - ck)\r\nif dr == 0 or dc == 0: print(1, )\r\nelse: print(2, )\r\nif dr == dc: print(1, )\r\nelif (dr - dc) % 2: print(0, )\r\nelse: print(2, )\r\nprint(max(dr, dc))", "\r\ndef rook(r1,c1,r2,c2):\r\n if r1==r2 or c1==c2:\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef bishop(r1,c1,r2,c2):\r\n s1 = r1+c1\r\n s2 = r2+c2\r\n if (s1%2==0 and s2%2!=0) or (s1%2!=0 and s2%2==0):\r\n return 0\r\n elif abs(r1-r2)==abs(c1-c2):\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef king(r1,c1,r2,c2):\r\n mine = abs(r1-r2)+abs(c1-c2)\r\n #move horizonatal\r\n for i in range(1,9):\r\n if abs(i-r2)==abs(c1-c2):\r\n mine = min(mine,abs(i-r1)+abs(c1-c2))\r\n for i in range(1,9):\r\n if abs(i-c2)==abs(r1-r2):\r\n mine = min(mine,abs(i-c1)+abs(r2-r1))\r\n return mine\r\n\r\ns = input().split()\r\nr1 = int(s[0])\r\nc1 = int(s[1])\r\nr2 = int(s[2])\r\nc2 = int(s[3])\r\nans = str(rook(r1,c1,r2,c2))+\" \"+str(bishop(r1,c1,r2,c2))+\" \"+str(king(r1,c1,r2,c2))\r\nprint(ans)\r\n", "def findPositionColor(r, c):\n if r % 2 != 0:\n if c % 2 != 0:\n return \"black\"\n else:\n return \"white\"\n else:\n if c % 2 != 0:\n return \"white\"\n else:\n return \"black\" \n\nr1, c1, r2, c2 = [int(x) for x in input().split(\" \")]\n\nrook = 0\nking = 0\nbishop = findPositionColor(r1, c1) == findPositionColor(r2, c2)\n\nif bishop:\n bishop = 0\n \n if abs(r2 - r1) == abs(c2 - c1):\n bishop = 1\n else:\n bishop = 2 \n \nelse:\n bishop = 0 \n \nif r1 == r2 or c1 == c2:\n rook = 1\nelse:\n rook = 2\n \nif abs(r2 - r1) > abs(c2 - c1):\n king = abs(r2 - r1)\nelse:\n king = abs(c2 - c1)\n \nprint(f\"{rook} {bishop} {king}\") \n \t\t\t \t \t\t \t\t \t\t \t\t", "r1,c1,r2,c2=input().split()\r\nr1,c1,r2,c2=int(r1),int(c1),int(r2),int(c2)\r\nk=max(abs(r1-r2),abs(c1-c2))\r\nif(r1==r2 or c1==c2):\r\n\tr=1\r\nelse:\r\n\tr=2\r\n\t\r\nif(((r1+c1)%2==0 and (r2+c2)%2!=0)or ((r1+c1)%2!=0 and (r2+c2)%2==0)):\r\n\tb=0\r\nelse:\r\n\tif(abs(r2-r1)==abs(c2-c1)):\r\n\t\tb=1\r\n\telse:\r\n\t\tb=2\r\n\r\nprint(str(r)+\" \"+str(b)+\" \"+str(k))\r\n", "from sys import stdin\r\ninp = stdin.readline\r\n\r\nr1, c1, r2, c2 = map(int, inp().split())\r\nr = abs(r2 - r1)\r\nc = abs(c2 - c1)\r\n\r\nans = [2 if r and c else 1, 0, max(r, c)]\r\n\r\nif r == c:\r\n ans[1] = 1\r\nelif (r + c) % 2 == 0:\r\n ans[1] = 2\r\n\r\nprint(*ans)\r\n\r\n\r\n", "start_row, start_col, end_row, end_col = list(map(int, input().split()))\r\n\r\n# rock\r\n\r\nif start_row == end_row or start_col == end_col:\r\n print(1, end = \" \")\r\nelse:\r\n print(2, end = \" \")\r\n\r\n# bishop\r\n\r\nif (start_row + start_col) % 2 != (end_row + end_col) % 2:\r\n print(0, end = \" \")\r\nelif start_col + start_row == end_row + end_col:\r\n print(1, end = \" \")\r\nelif start_col - start_row == end_col - end_row:\r\n print(1, end = \" \")\r\nelse:\r\n print(2, end = \" \")\r\n\r\n\r\nprint(max(abs(start_row - end_row), abs(start_col - end_col)))", "r1, c1, r2, c2 = list(map(int, input().split()))\n\nm = 1 if (r1 == r2 or c1 == c2) else 2\n\nr = abs(r2 - r1)\nc = abs(c2 - c1)\nk = max(r, c)\n\nif (r1 + c1) % 2 != (r2 + c2) % 2:\n b = 0\nelif r == c:\n b = 1\nelse:\n b = 2\n\nprint(m, b, k)\n\t\t \t \t\t \t\t \t\t \t \t \t \t\t", "def f(l):\r\n ab = lambda x: x if x>0 else -x\r\n r1,c1,r2,c2 = l\r\n r = 1 if (r1==r2 or c1==c2) else 2\r\n b = (1 if (r2-r1==c1-c2 or r2-r1==c2-c1) else 2) if (r1+r2+c1+c2)%2==0 else 0 \r\n k = max(ab(r2-r1),ab(c2-c1))\r\n return [r,b,k]\r\n\r\nl = list(map(int,input().split()))\r\nprint(*f(l))\r\n\r\n", "def main():\r\n r1, c1,r2,c2 = map(int, input().split())\r\n # r2, c2 = map(int, input().split())\r\n\r\n if r1 == r2 and c1 == c2:\r\n print(\"0 0 0\")\r\n return\r\n\r\n # rook\r\n if r1 == r2 or c1 == c2:\r\n print(\"1 \", end=\"\")\r\n else:\r\n print(\"2 \", end=\"\")\r\n\r\n # bishop\r\n if (r1 + c1) % 2 != (r2 + c2) % 2:\r\n print(\"0 \", end=\"\")\r\n elif abs(r1 - r2) == abs(c1 - c2):\r\n print(\"1 \", end=\"\")\r\n else:\r\n print(\"2 \", end=\"\")\r\n\r\n # king\r\n print(max(abs(r1 - r2), abs(c1 - c2)))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\ndef read():\r\n return tuple(map(int, input().split()))\r\n\r\ndef rookMoves(init, dest):\r\n # Posiciones iguales ya ha sido chequeado\r\n if (init[0] == dest[0]):\r\n return 1 # Solo coord X esta alineada\r\n if (init[1] == dest[1]):\r\n return 1 # Solo coord Y esta alineada\r\n return 2 # Ninguna coord esta alineada\r\n\r\ndef bishopMoves(init, dest):\r\n if ((init[0] + init[1]) % 2 != (dest[0] + dest[1]) % 2):\r\n return 0 # Coords son de colores distintos\r\n\r\n if (abs(dest[0] - init[0]) != abs(dest[1] - init[1])):\r\n return 2 # Coords no forman triangulo isoceles\r\n\r\n return 1 # Coords forman triangulo isoceles\r\n\r\ndef kingMoves(init, dest):\r\n return max(abs(dest[0] - init[0]), abs(dest[1] - init[1])) # Movimientos en diagonal son mejores, anulan el inferior entre deltaX o deltaY\r\n\r\n(ri, ci, rf, cf) = read()\r\n\r\nif (ri == rf and ci == cf):\r\n print(\"0 0 0\")\r\nelse:\r\n print(\"{0} {1} {2}\".format(rookMoves((ri, ci), (rf, cf)), bishopMoves((ri, ci), (rf, cf)), kingMoves((ri, ci), (rf, cf))))", "import sys\r\nfrom math import *\r\nz=1\r\nif z:\r\n\tinput=sys.stdin.readline\r\nelse:\t\r\n\tsys.stdin=open('input.txt', 'r')\r\n\tsys.stdout=open('output.txt','w')\r\nmini=9999999999\t\r\n\r\n\r\nr1,c1,r2,c2=map(int,input().split())\r\nb=r=k=0\r\nr=int(r1!=r2)+int(c1!=c2)\r\nif (r1+c1)&1==(r2+c2)&1:\r\n\tif(abs(r1-r2)==abs(c1-c2)):\r\n\t\tb=1\r\n\telse:\r\n\t\tb=2\r\nmini=min(abs(r1-r2),abs(c1-c2))\t\t\r\nmaxi=max(abs(r1-r2),abs(c1-c2))\t\t\r\nprint(r,b,maxi)\r\n", "import sys\r\n\r\ndef main():\r\n r1, c1, r2, c2 = map(int, input().split())\r\n\r\n if r1 == r2 and c1 == c2:\r\n print(\"0 0 0\")\r\n return\r\n\r\n # rook\r\n if r1 == r2 or c1 == c2:\r\n sys.stdout.write(\"1 \")\r\n else:\r\n sys.stdout.write(\"2 \")\r\n\r\n # bishop\r\n if (r1 + c1) % 2 != (r2 + c2) % 2:\r\n sys.stdout.write(\"0 \")\r\n elif r1 - c1 == r2 - c2 or r1 + c1 == r2 + c2:\r\n sys.stdout.write(\"1 \")\r\n else:\r\n sys.stdout.write(\"2 \")\r\n\r\n # king\r\n sys.stdout.write(str(max(abs(r1 - r2), abs(c1 - c2))))\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n", "def modulo(x):\n if x<0:\n return -x\n return x\n\n\nnumbers = input().split()\nnumbers = [int(n) for n in numbers]\nd1,d2 = modulo(numbers[2]-numbers[0]),modulo(numbers[3]-numbers[1])\n\nr,k,b = 0,0,0\n\nif(d1 == 0 and d2 == 0):\n print(0,0,0)\n exit()\n\nif (d1>0):\n r += 1\nif (d2> 0):\n r += 1\n\nif(d1>d2):\n k += d1\nelse:\n k += d2\n\nif(d1 == d2 ):\n b = 1\nelif(d1%2 == d2%2):\n b = 2\n\nprint(r,b,k)\n\t \t\t\t\t \t \t \t\t\t \t \t\t\t\t\t", "def rook(r1,c1,r2,c2):\r\n if r1==r2 and c1==c2:\r\n return 0\r\n if r1==r2 or c1==c2:\r\n return 1\r\n return 2\r\ndef bishop(r1,c1,r2,c2):\r\n if r1==r2 and c1==c2:\r\n return 0\r\n if abs(r1-r2)==abs(c2-c1):\r\n return 1\r\n if (r1-r2+c2-c1)%2==0:\r\n return 2\r\n return 0\r\ndef king(r1,c1,r2,c2):\r\n res1 = abs(r2-r1)\r\n res2 = abs(c2-c1)\r\n return max(res1,res2)\r\n\r\nr1,c1,r2,c2 = [int(x) for x in input().split()]\r\nprint(rook(r1,c1,r2,c2),bishop(r1,c1,r2,c2),king(r1,c1,r2,c2))", "r1,c1,r2,c2 = map(int,input().split())\r\nl = []\r\nif r1 == r2 or c1 == c2:\r\n l.append(1)\r\nelse:\r\n l.append(2)\r\n \r\nif not (r1 + c1) % 2 == (r2 + c2 ) %2:\r\n l.append(0)\r\n \r\nelse:\r\n if r1 - r2 == c1 - c2 or r1 + c1 == r2 + c2:\r\n l.append(1)\r\n else:\r\n l.append(2)\r\n \r\n\r\nl.append(max(abs(r1-r2),abs(c1-c2))) \r\n\r\nprint(*l) ", "def rook(r1,c1,r2,c2):\n\tif r1==r2 or c1==c2:\n\t\treturn 1\n\telse:\n\t\treturn 2\n\ndef king(r1,c1,r2,c2):\n\tx = abs( c1-c2 )\n\ty = abs( r1-r2 )\n\treturn max( x,y )\n\n\ndef bishop(r1,c1,r2,c2):\n\tif not (r1+c1)%2==(r2+c2)%2:\n\t\treturn 0\n\t\n\tx = abs(r1-r2)\n\ty = abs(c1-c2)\n\tif x==y:\n\t\treturn 1\n\t\n\treturn 2\n\t\n\nif __name__=='__main__':\n\tr1,c1,r2,c2 = [int(x) for x in input().split()]\n\tr = rook(r1,c1,r2,c2)\n\tb = bishop(r1,c1,r2,c2)\n\tk = king(r1,c1,r2,c2)\n\tprint( str(r)+' '+str(b)+' '+str(k) )\n\t\n", "sx,sy,ex,ey=map(int,input().split())\r\nrook=1 if sx==ex or sy==ey else 2\r\nbishop=0\r\nif abs(sx-ex)==abs(sy-ey): bishop=1\r\nelif (sx+sy)%2==(ex+ey)%2: bishop=2\r\nking=max(abs(sx-ex),abs(sy-ey))\r\nprint(rook,bishop,king)", "a,b,c,d=map(int,input().split())\na = abs(a-c)\nb = abs(b-d)\n\nx = min(a, 1)+min(b, 1)\ny = max(a, b)\nz = 2\nif a==b:\n z=1\nif a+b==0 or (a+b)%2:\n z=0\n\nprint(x, z, y)\n", "def process(r1, c1, r2, c2):\r\n if r1==r2:\r\n rook = 1\r\n elif c1==c2:\r\n rook = 1\r\n else:\r\n rook = 2\r\n if (r1+c1) % 2 != (r2+c2) % 2:\r\n bishop = 0\r\n elif (r1+c1)==(r2+c2):\r\n bishop = 1\r\n elif (r1-c1)==(r2-c2):\r\n bishop = 1\r\n else:\r\n bishop = 2\r\n king = 0\r\n while r1 > r2 and c1 > c2:\r\n king+=1\r\n r1-=1\r\n c1-=1\r\n while r1 > r2 and c1 < c2:\r\n king+=1\r\n r1-=1\r\n c1+=1\r\n while r1 < r2 and c1 > c2:\r\n king+=1\r\n r1+=1\r\n c1-=1\r\n while r1 < r2 and c1 < c2:\r\n king+=1\r\n r1+=1\r\n c1+=1\r\n king+=abs(r1-r2)+abs(c1-c2)\r\n print(f'{rook} {bishop} {king}')\r\n \r\nr1, c1, r2, c2 = [int(x) for x in input().split()]\r\nprocess(r1, c1, r2, c2)", "r1, c1, r2, c2 = [int(i) for i in input().split()]\r\n\r\nrook = 1 if r1 == r2 or c1 == c2 else 2\r\nbishop = 0 if not (r1+c1) % 2 == (r2+c2) % 2 else 1 if r1-c1 == r2-c2 or r1+c1 == r2+c2 else 2\r\nking = max(abs(r1-r2), abs(c1-c2))\r\n\r\nprint(rook, bishop, king)\r\n", "s=input()\nr1=int(s.split(' ')[0])\nc1=int(s.split(' ')[1])\nr2=int(s.split(' ')[2])\nc2=int(s.split(' ')[3])\n\nrook=0\nbishop=0\nking=0\n\n#Rook\nif r1==r2 or c1==c2:\n rook=1\nelse:\n rook=2\n\n#Bishop\nif not ((r1==r2 and c1==c2) or ((abs(r1-r2)%2)!=(abs(c1-c2)%2))):\n if (abs(r1-r2)==abs(c1-c2)):\n bishop=1\n else:\n bishop=2\n\n\n#King\ndr=abs(r1-r2)\ndc=abs(c1-c2)\nif (dr>dc):\n king=dr\nelse:\n king=dc\n\nprint(str(rook)+' '+str(bishop)+' '+str(king))\n\t\t \t \t\t \t\t\t \t\t \t \t", "r1,c1,r2,c2 = map(int,input().split())\r\nif r1 == r2 and c1 == c2:\r\n print(1,1,1)\r\nelse:\r\n if r1 == r2 or c1 == c2:\r\n print(1, end = ' ')\r\n else:\r\n print(2,end = ' ')\r\n if abs(max(r1,r2) - min(r1,r2)) == abs(max(c1,c2) - min(c1,c2)):\r\n print(1, end = ' ')\r\n elif (abs(r2-r1) % 2 == 0 and abs(c2-c1) % 2 == 1) or (abs(r2-r1) % 2 == 1 and abs(c2-c1) % 2 == 0):\r\n print(0,end = ' ')\r\n else:\r\n print(2,end = ' ')\r\n print(max(abs(r2-r1),abs(c2-c1)))", "def diagonal(r1, c1, r2, c2):\n for i in range(1, 9):\n if (c1 + i == c2 and r1+i == r2) or (c2 + i == c1 and r2+i == r1) or (c1 - i == c2 and r1+i == r2) or (c1+i == c2 and r1-i == r2):\n return True\n\n return False\n\n\ndef rook_moves(r1, c1, r2, c2):\n if r1 == r2 or c1 == c2:\n return 1\n else:\n return 2\n\ndef bishop_moves(r1, c1, r2, c2):\n if (r1+c1) % 2 != (r2+c2) % 2:\n return 0\n \n if diagonal(r1, c1, r2, c2):\n return 1\n else:\n return 2\n\ndef king_moves(r1, c1, r2, c2):\n if(diagonal(r1, c1, r2, c2)):\n return abs(r1-r2)\n\n elif(r1 == r2):\n return abs(c1 - c2)\n\n elif(c1 == c2):\n return abs(r1 - r2)\n\n else:\n return abs(r1-r2) + abs(c1-c2) - min(abs(r1 - r2), abs(c1 - c2))\n\nr1, c1, r2, c2 = [int(i) for i in input().split()]\n\nprint(rook_moves(r1, c1, r2, c2), bishop_moves(r1, c1, r2, c2), king_moves(r1, c1, r2, c2))\n\t\t\t \t \t \t\t \t\t\t \t\t \t\t\t \t\t \t \t", "r1,c1,r2,c2=map(int,input().split())\r\na=abs(r1-r2)\r\nb=abs(c1-c2) \r\nfrom collections import deque\r\nif(a==0 or b==0):\r\n e=1 \r\nelse:\r\n e=2 \r\nz=max(a,b) \r\nif ((r1 + c1) % 2 != (r2 + c2) % 2):\r\n m=0\r\nelse:\r\n if (r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2):\r\n m=1\r\n else:\r\n m=2\r\n \r\nprint(e,m,z) \r\n ", "from sys import stdin\r\ninput = stdin.readline\r\n\r\nr1, c1, r2, c2 = [int(x) for x in input().split()]\r\nans = []\r\n\r\nif r1 == r2 or c1 == c2:\r\n ans.append(1)\r\nelse:\r\n ans.append(2)\r\n \r\nif (r1 + c1) % 2 != (r2 + c2) % 2:\r\n ans.append(0)\r\nelif abs(r1 - r2) == abs(c1 - c2):\r\n ans.append(1)\r\nelse:\r\n ans.append(2)\r\n\r\nmin_ = min(abs(r1 - r2), abs(c1 - c2))\r\nmax_ = max(abs(r1 - r2), abs(c1 - c2))\r\nans.append(min_ + (max_ - min_))\r\n\r\nprint(*ans)", "r1,r2,t1,t2=map(int,input().split())\r\nif r1==t1 or r2==t2:\r\n print(1,end=' ')\r\nelse:\r\n print(2,end=' ')\r\n\r\nif r1%2!=r2%2 and t2%2!=t1%2 or r1%2==r2%2 and t1%2==t2%2:\r\n if abs(r1-t1)==abs(r2-t2):\r\n print(1,end=' ')\r\n else:\r\n print(2,end=' ')\r\nelse:\r\n print(0,end=' ')\r\n\r\nprint(max(abs(t1-r1),abs(t2-r2)))", "line = input().split(\" \")\r\nr1 = int(line[0])\r\nc1 = int(line[1])\r\nr2 = int(line[2])\r\nc2 = int(line[3])\r\n#torre\r\nmovT = 0;\r\nif r1 == r2 or c1 == c2:\r\n movT = 1\r\nelse:\r\n movT = 2\r\n#alfil\r\nmovA = 0\r\nif abs((r1+c1)%2 -(r2+c2)%2)==1:\r\n movA = 0\r\nelse:\r\n if abs(r1-r2)==abs(c1-c2):\r\n movA = 1\r\n else:\r\n movA = 2\r\n#rey\r\nmovR = max(abs(r1-r2),abs(c1-c2))\r\nprint(f\"{movT} {movA} {movR}\")", "import math\r\n\r\ndef moves_rook(sx, sy, ex, ey):\r\n if sx == ex or sy == ey:\r\n return 1\r\n else:\r\n return 2\r\n\r\ndef moves_bishop(sx, sy, ex, ey):\r\n dx, dy = abs(sx - ex), abs(sy - ey)\r\n if dx == dy:\r\n return 1\r\n elif (dx % 2 == 0 and dy % 2 == 0) or (dx % 2 != 0 and dy % 2 != 0):\r\n return 2\r\n else:\r\n return 0\r\n\r\ndef moves_king(sx, sy, ex, ey):\r\n return max(abs(sx - ex), abs(sy - ey))\r\n\r\nsx, sy , ex, ey = map(int, input().split())\r\n\r\n\r\nrook = moves_rook(sx, sy, ex, ey)\r\nbishop = moves_bishop(sx, sy, ex, ey)\r\nking = moves_king(sx, sy, ex, ey)\r\n\r\nprint(rook, bishop, king)\r\n", "import math\n\nA = list(map(int, input().split()))\nr1 = A[0]\nc1 = A[1]\nr2 = A[2]\nc2 = A[3]\n\n# Calculate kings movements\n# If they are horizontally aligned\nif r1 == r2 or c1 == c2:\n if r1 == r2:\n king_movements = abs(c1 - c2)\n else:\n king_movements = abs(r1 - r2)\nelse:\n king_movements = max(abs(r1 - r2), abs(c1 - c2))\n\n# Rooks can always reach their position\nrook_movements = 1 if (r1 == r2 or c1 == c2) else 2\n\n# Bishop can move either 1 or 2 moves, no other way\n# If they are not on the same color\nif ((r1 + c1) % 2 != (r2 + c2) % 2):\n bishop_movements = 0\nelse:\n # If they are on the same diagonal\n if c1 == (-r1 + (c2 + r2)) or c1 == (r1 + (c2 - r2)):\n bishop_movements = 1\n # If they are not, we can get in two moves\n else:\n bishop_movements = 2\n\nprint(rook_movements)\nprint(bishop_movements)\nprint(king_movements)\n\n \t\t \t \t \t\t\t\t \t \t \t \t\t\t\t", "r1, c1, r2, c2 = list(map(int, input().split(' ')))\n\n# rooks\nrook = 0\nif r1 == r2 or c1 == c2:\n rook = 1\nelse:\n rook = 2\n\n# king\nking = 0\nr_diff = abs(r1 - r2)\nc_diff = abs(c1 - c2)\nif c1 == c2:\n king = r_diff\nelif r1 == r2:\n king = c_diff\nelse:\n path = min(c_diff, r_diff)\n if path == c_diff:\n king = c_diff + abs(r_diff - c_diff)\n else:\n king = r_diff + abs(c_diff - r_diff)\n\n# bishop\nbishop = 0\n\nif (r1 % 2 == c1 % 2) == (r2 % 2 == c2 % 2):\n if r_diff == c_diff:\n bishop = 1\n else:\n bishop = 2\n\nprint(f'{rook} {bishop} {king}')\n \t \t\t \t\t\t \t\t \t\t\t \t \t \t", "a,b,c,d=map(int,input().split())\r\ne=[0,0,0]\r\nif a==c or b==d:e[0]=1\r\nelse:e[0]=2\r\nif abs(a%2-b%2)!=abs(c%2-d%2):e[1]=0\r\nelif abs(a-c)==abs(b-d):e[1]=1\r\nelse:e[1]=2\r\ne[2]=max(abs(a-c),abs(b-d))\r\nprint(' '.join(map(str,e)))\r\n", "r1, c1, r2, c2 = map(int, input().split())\nm = abs(r2 - r1)\nn = abs(c2 - c1)\n\nr = (r1 != r2) + (c1 != c2)\nb = 0\nk = max(m, n)\n\nif (abs(m - n) % 2 == 0):\n b = 2\n\nif (m == n):\n b = 1\n\nprint(r, b, k)\n\t \t \t \t\t\t\t \t\t \t \t \t\t \t", "\r\n\r\n#https://codeforces.com/problemset/problem/266/B\r\nimport sys\r\nimport math\r\nfrom collections import defaultdict\r\nimport heapq\r\ntry: \r\n sys.stdin = open('input.txt', 'r') \r\n sys.stdout = open('output.txt', 'w')\r\n \r\nexcept: \r\n pass\r\n \r\n\r\nclass Graph():\r\n def __init__(self,type):\r\n self.neighbours=defaultdict(list)\r\n if(type==0):\r\n #King\r\n self.addKing()\r\n \r\n elif(type==1):\r\n #Rook\r\n self.addRook()\r\n\r\n else:\r\n #Add Bishop moves\r\n self.addBishop()\r\n\r\n def addKing(self):\r\n for x in range(1,9):\r\n for y in range(1,9):\r\n for i in range(-1,2):\r\n for j in range(-1,2):\r\n pos_x=x+i\r\n pos_y=y+j\r\n if(self.isValid(pos_x,pos_y)):\r\n self.addEdge([x,y],[pos_x,pos_y])\r\n def addRook(self):\r\n for x in range(1,9):\r\n for y in range(1,9):\r\n for pos_y in range(1,9):\r\n if(pos_y!=y):\r\n self.addEdge([x,y],[x,pos_y])\r\n for x in range(1,9):\r\n for y in range(1,9):\r\n for pos_x in range(1,9):\r\n if(pos_x!=x):\r\n self.addEdge([x,y],[pos_x,y])\r\n\r\n def addBishop(self):\r\n #Absolute diff(x2-x1)==Absolute diff (y2-y1)\r\n for x in range(1,9):\r\n for y in range(1,9):\r\n for posx in range(1,9):\r\n for posy in range(1,9):\r\n if(abs(x-posx)==abs(y-posy)):\r\n self.addEdge([x,y],[posx,posy])\r\n\r\n def addEdge(self,u,v):\r\n pos1=self.ltos(u)\r\n pos2=self.ltos(v)\r\n self.neighbours[pos1].append(pos2)\r\n self.neighbours[pos2].append(pos1)\r\n\r\n def ltos(self,l):\r\n return str(l[0])+\":\"+str(l[1])\r\n def isValid(self,x,y):\r\n if(x<1 or x>8):\r\n return False\r\n if(y<1 or y>8):\r\n return False\r\n return True\r\n\r\n def stol(self,s):\r\n return [int(s[0]),int(s[2])]\r\n\r\n def BFS(self,source,destination):\r\n source=self.ltos(source)\r\n destination=self.ltos(destination)\r\n visited=defaultdict(lambda:False)\r\n distance=defaultdict(lambda:float(\"inf\"))\r\n distance[source]=0\r\n visited[source]=True\r\n queue=[source]\r\n parent=defaultdict(lambda:None)\r\n while queue:\r\n u=queue.pop(0)\r\n if(u==destination):\r\n break\r\n for v in self.neighbours[u]:\r\n if(not visited[v]):\r\n visited[v]=True\r\n parent[v]=u\r\n distance[v]=distance[u]+1\r\n queue.append(v)\r\n if(distance[destination]==float(\"inf\")):\r\n return 0\r\n return(distance[destination])\r\n \r\n\r\n\r\nx1,y1,x2,y2=[int(x) for x in input().split()]\r\nsource=[x1,y1]\r\ndestination=[x2,y2]\r\nking=Graph(0)\r\nrook=Graph(1)\r\nbishop=Graph(2)\r\nprint(rook.BFS(source,destination),bishop.BFS(source,destination),king.BFS(source,destination))\r\n", "def solve_king(r1, c1, r2, c2):\r\n\treturn max(abs(r1-r2), abs(c1-c2))\r\n\r\ndef solve_rook(r1, c1, r2, c2):\r\n\treturn (r1 != r2) + (c1 != c2)\r\n\r\ndef solve_elephant(r1, c1, r2, c2):\r\n\tif (r1 + c1)%2 == (r2 + c2)%2:\r\n\t\treturn 1 + (abs(r1-r2) != abs(c1-c2))\r\n\r\n\treturn 0\r\n\r\ndef solve(r1, c1, r2, c2):\r\n\tking = solve_king(r1, c1, r2, c2)\r\n\trook = solve_rook(r1, c1, r2, c2)\r\n\telephant = solve_elephant(r1, c1, r2, c2)\r\n\r\n\treturn f'{rook} {elephant} {king}'\r\n\r\nr1, r2, c1, c2 = map(int, input().split())\r\nprint(solve(r1, r2, c1, c2))", "def rook():\r\n if r1 == r2 and c1 == c2:\r\n return 0\r\n if r1 == r2 or c1 == c2:\r\n return 1\r\n return 2\r\n\r\ndef bishop():\r\n if r1 == r2 and c1 == c2:\r\n return 0\r\n if (r1 + c1)%2 == (r2 + c2)%2:\r\n if abs(c2 - c1) == abs(r2 - r1):\r\n return 1\r\n return 2\r\n return 0\r\n\r\ndef king():\r\n a, b = min(abs(r2 - r1), abs(c2 - c1)), max(abs(r2 - r1), abs(c2 - c1))\r\n return b\r\n\r\ndef solve():\r\n print(rook(), end = \" \")\r\n print(bishop(), end = \" \")\r\n print(king(), end = \" \")\r\n\r\nr1, c1, r2, c2 = map(int, input().split())\r\nsolve()", "r1,c1,r2,c2=map(int,input().split())\r\nif r1==r2 and c1==c2:\r\n print('0 0 0')\r\nelse:\r\n if r1==r2 or c1==c2: #ladya\r\n print(1,end=' ')\r\n else:\r\n print(2,end=' ')\r\n if (((c1%2==0 and r1%2==0) or (c1%2!=0 and r1%2!=0)) and ((c2%2==0 and r2%2==0) or (c2%2!=0 and r2%2!=0))) or (((c1%2==0 and r1%2!=0) or (c1%2!=0 and r1%2==0)) and ((c2%2!=0 and r2%2==0) or (c2%2==0 and r2%2!=0))): #slon\r\n if abs(c2-c1)==abs(r2-r1):\r\n print(1,end=' ')\r\n else:\r\n print(2,end=' ')\r\n else:\r\n print(0,end=' ')\r\n if abs(r2-r1)>abs(c2-c1): #corol\r\n print(abs(r2-r1))\r\n else:\r\n print(abs(c2-c1))\r\n", "r1,c1,r2,c2=map(int,input().split())\r\nrook=0\r\nbishop=0\r\nking=max(abs(r1-r2),abs(c1-c2))\r\nif r1==r2 or c1==c2:\r\n rook=1\r\nelse:\r\n rook=2\r\nif (r1+c1)%2 != (r2+c2)%2:\r\n bishop=0\r\nelse:\r\n if abs(r1-r2)==abs(c1-c2):\r\n bishop=1\r\n else:\r\n bishop=2\r\nprint(rook,bishop,king)", "a, b, c, d = map(int, input().split())\r\ndata = [[0 for _ in range(8)] for _ in range(8)]\r\nxcarol = []\r\nycarol = []\r\ndef rec_carol():\r\n x = abs(c-a)\r\n y = abs(d-b)\r\n return max(x, y)\r\n\r\ndef rec_ladia():\r\n x = abs(c-a)\r\n y = abs(d-b)\r\n if x==y: return 1\r\n else:\r\n if (x+y)%2==0: return 2\r\n else: return 0\r\n\r\ndef rec_slon():\r\n x = abs(c-a)\r\n y = abs(d-b)\r\n return int(not (x==0 or y==0)) + 1\r\nprint(rec_slon(), rec_ladia(), rec_carol() )\r\n ", "entrada=[int(x) for x in input().split()]\n\nr1 = entrada[0]\nc1 = entrada[1]\nr2 = entrada[2]\nc2 = entrada[3]\n\nans = []\n\nif(r1 == r2 and c1 == c2):\n print(\"0 0 0\")\n\nif(r1 == r2 or c1 == c2):\n ans.append(1)\nelse:\n ans.append(2)\n\n\nif((r1 + c1) % 2 != (r2 + c2) % 2):\n ans.append(0)\nelif (r1 - c1 == r2 - c2 or r1 + c1 == r2 + c2):\n ans.append(1)\nelse:\n ans.append(2)\n\nans.append(max(abs(r1 - r2), abs(c1 - c2)))\n\nprint(*ans)\n\n \t \t\t\t \t\t\t \t\t \t\t\t\t", "r1,c1,r2,c2=map(int,input().split())\ndef kralj():\n a,b=r1,c1\n x,y=r2,c2\n br=0\n while a<x and b<y:\n a+=1\n b+=1\n br+=1\n while a>x and b<y:\n a-=1\n b+=1\n br+=1\n while a>x and b>y:\n a-=1\n b-=1\n br+=1\n while a<x and b>y:\n a+=1\n b-=1\n br+=1\n br+=abs(a-x)\n br+=abs(b-y)\n return br\n\ndef top():\n a,b=r1,c1\n x,y=r2,c2\n br=0\n if a!=x and b!=y:\n br=2\n else:\n br=1\n return br\n\ndef lovac():\n a,b=r1,c1\n x,y=r2,c2\n br=0\n if (abs(a-b)%2)!=(abs(x-y)%2):\n return 0\n else:\n mog=[]\n i,j=x,y\n while i<8 and j<8:\n i+=1\n j+=1\n mog.append([i,j])\n i,j=x,y\n while i<8 and j>0:\n i+=1\n j-=1\n mog.append([i,j])\n i,j=x,y\n while i>0 and j>0:\n i-=1\n j-=1\n mog.append([i,j])\n i,j=x,y\n while i>0 and j<8:\n i-=1\n j+=1\n mog.append([i,j])\n if [a,b] in mog:\n br=1\n else:\n br=2\n return br\n \nprint(top(),lovac(),kralj())\n\n \t \t \t \t \t \t \t \t\t \t", "r1, c1, r2, c2 = map(int, input().split())\r\nrook = 1 if r1 == r2 or c1 == c2 else 2\r\nif (r1 + c1) % 2 != (r2 + c2) % 2:\r\n bishop = 0\r\nelif r1 - c1 == r2 - c2 or r1 + c1 == r2 + c2:\r\n bishop = 1\r\nelse:\r\n bishop = 2\r\nking = max(abs(r1 - r2), abs(c1 - c2))\r\nprint(rook, bishop, king)", "r1,c1,r2,c2=[int(x) for x in input().split()]\r\nif r1==r2 or c1==c2:\r\n\tif (r1==r2 and c1%2!=c2%2) or (c1==c2 and r1%2!=r2%2):\r\n\t\tprint(1,0,abs(r1-r2)+abs(c1-c2))\r\n\telse:\r\n\t\tprint(1,2,abs(r1-r2)+abs(c1-c2))\r\nelif abs(r1-r2)==abs(c1-c2):\r\n\tprint(2,1,abs(r1-r2))\r\nelse:\r\n\tif (r1+c1)%2==(r2+c2)%2:\r\n\t\tprint(2,2,max(abs(r1-r2),abs(c1-c2)))\r\n\telse:\r\n\t\tprint(2,0,max(abs(r1-r2),abs(c1-c2)))\r\n", "r1,c1,r2,c2=map(int,input().split())\r\nif r1==r2 or c1==c2:r=1\r\nelse:r=2\r\nif abs((r1+c1)-(r2+c2))%2==1:b=0\r\nelif abs(c2-c1)==abs(r2-r1):b=1\r\nelse:b=2\r\nk=max(abs(c2-c1),abs(r2-r1))\r\nprint(r,b,k)\r\n", "\"\"\"\nhttps://codeforces.com/problemset/problem/370/A\n\"\"\"\n\nr1, c1, r2, c2 = [int(x) for x in input().split()]\n\n# rook\nmr = (1 if r1 != r2 else 0) + (1 if c1 != c2 else 0)\nprint(mr, end=\" \")\n\n# bishop\nif (r1 + c1) % 2 == (r2 + c2) % 2:\n if abs(r1-r2)==abs(c1-c2):\n print(1,end=' ')\n else:\n print(2,end=' ')\nelse:\n print(0, end=\" \")\n\n# king\nr = abs(r1 - r2)\nc = abs(c1 - c2)\nk = min(r, c)\nmk = k + abs(r - k) + abs(c - k)\nprint(mk)\n", "#370A\r\nr1, c1, r2, c2 = map(int, input().split())\r\nif r1 == r2 or c1 == c2:\r\n print(1, end =\" \")\r\nelse:\r\n print(2, end =\" \")\r\n\r\nif (r1+c1)%2 != (r2+c2)%2:\r\n print(0, end =\" \")\r\nelse:\r\n if r1+c1 == r2+c2 or r1-c1 == r2-c2:\r\n print(1, end =\" \")\r\n else:\r\n print(2, end =\" \")\r\n\r\nprint(max(abs(r1-r2), abs(c1-c2)))\r\n", "r1, c1, r2, c2 =map(int, input().split())\r\nif r1==r2 or c1==c2:\r\n l=1\r\nelse:\r\n l=2\r\nif (r1+c1)%2!=(r2+c2)%2:\r\n s=0\r\nelif r1+c1==r2+c2 or r1-c1==r2-c2:\r\n s=1\r\nelse:\r\n s=2\r\nk=max(abs(r1-r2), abs(c1-c2))\r\nprint(l, s, k)\r\n", "import sys\r\n\r\nstdin = sys.stdin\r\ninf = 1 << 60\r\nmod = 1000000007\r\n\r\nni = lambda: int(ns())\r\nnin = lambda y: [ni() for _ in range(y)]\r\nna = lambda: list(map(int, stdin.readline().split()))\r\nnan = lambda y: [na() for _ in range(y)]\r\nnf = lambda: float(ns())\r\nnfn = lambda y: [nf() for _ in range(y)]\r\nnfa = lambda: list(map(float, stdin.readline().split()))\r\nnfan = lambda y: [nfa() for _ in range(y)]\r\nns = lambda: stdin.readline().rstrip()\r\nnsn = lambda y: [ns() for _ in range(y)]\r\nncl = lambda y: [list(ns()) for _ in range(y)]\r\nnas = lambda: stdin.readline().split()\r\n\r\nfrom collections import deque\r\n\r\nx, y, gx, gy = na()\r\nx -= 1\r\ny -= 1\r\ngx -= 1\r\ngy -= 1\r\nh, w = 8, 8\r\n\r\ndef bfs(ty):\r\n q = deque()\r\n q.append((x, y))\r\n dist = [[inf] * w for _ in range(h)]\r\n dist[y][x] = 0\r\n while len(q):\r\n p = q.popleft()\r\n cx, cy = p\r\n if ty == \"rook\":\r\n dx = [0, 1, -1, 0]\r\n dy = [1, 0, 0, -1]\r\n for i in range(4):\r\n nx, ny = cx + dx[i], cy + dy[i]\r\n while nx >= 0 and nx < w and ny >= 0 and ny < h:\r\n if dist[ny][nx] == inf:\r\n dist[ny][nx] = dist[cy][cx] + 1\r\n q.append((nx, ny))\r\n nx, ny = nx + dx[i], ny + dy[i]\r\n elif ty == \"bishop\":\r\n dx = [1, -1, -1, 1]\r\n dy = [-1, 1, -1, 1]\r\n for i in range(4):\r\n nx, ny = cx + dx[i], cy + dy[i]\r\n while nx >= 0 and nx < w and ny >= 0 and ny < h:\r\n if dist[ny][nx] == inf:\r\n dist[ny][nx] = dist[cy][cx] + 1\r\n q.append((nx, ny))\r\n nx, ny = nx + dx[i], ny + dy[i]\r\n elif ty == \"king\":\r\n # (1, 1) (1, 0) (1, -1) (0, -1) (-1, -1) (-1, 0) (-1, 1) (0, 1)\r\n dx = [1, 1, 1, 0, -1, -1, -1, 0]\r\n dy = [1, 0, -1, -1, -1, 0, 1, 1]\r\n for i in range(8):\r\n nx, ny = cx + dx[i], cy + dy[i]\r\n if nx >= 0 and nx < w and ny >= 0 and ny < h and dist[ny][nx] == inf:\r\n dist[ny][nx] = dist[cy][cx] + 1\r\n q.append((nx, ny))\r\n return dist[gy][gx] if dist[gy][gx] != inf else 0\r\n\r\nprint(bfs(\"rook\"), bfs(\"bishop\"), bfs(\"king\"))", "n = input()\na = n.split()\nfor x in range(4):\n a[x] = int(a[x])\nrook = 0\nif a[0] != a[2]:\n rook += 1\nif a[1] != a[3]:\n rook += 1\nbishop = 0\nif (a[0]+a[1])%2 == (a[2]+a[3])%2:\n if abs(a[0]-a[2]) == abs(a[1]-a[3]):\n bishop = 1\n else:\n bishop = 2\nif abs(a[0]-a[2])>abs(a[1]-a[3]):\n king = abs(a[0]-a[2])\nelse:\n king = abs(a[1]-a[3])\nprint(rook,bishop,king)\n\n\t\t\t\t \t\t\t\t \t\t\t\t\t \t \t\t\t \t", "r1, c1, r2, c2 = [int(i) for i in input().split()]\r\n\r\nr, c = abs(r2 - r1), abs(c2 - c1)\r\n\r\nrook, bishop, king = 0, 0, 0\r\n\r\n#Rook\r\nif r == 0 or c== 0:\r\n rook = 1\r\nelse:\r\n rook = 2\r\n\r\n#King\r\nking = min([r, c]) + abs(r - c)\r\n\r\n#Bishop\r\nif (r + c)%2 != 0:\r\n bishop = 0\r\nelif r == c:\r\n bishop = 1\r\nelse:\r\n bishop = 2\r\n\r\n\r\nprint(f\"{rook} {bishop} {king}\")", "r1,c1,r2,c2=map(int,input().split())\r\nans=[0,0,0]\r\nimport sys\r\nif r1==r2 or c1==c2:\r\n if r1==r2 and c1==c2:\r\n print(0,0,0)\r\n sys.exit()\r\n else :\r\n ans[0]=1\r\nelse :\r\n ans[0]=2\r\nans[2]=max(abs(r1-r2),abs(c1-c2))\r\nif ((r1+c1)%2)^((r2+c2)%2)==1:\r\n ans[1]=0\r\n print(' '.join(str(x) for x in ans))\r\nelse :\r\n if (r1+c1)==(r2+c2) or (r1-c1)==(r2-c2):\r\n ans[1]=1\r\n else :\r\n ans[1]=2\r\n print(' '.join(str(x) for x in ans))", "# A. Rook, Bishop and King\r\n# https://codeforces.com/problemset/problem/370/A\r\n\r\nstart_x, start_y, end_x, end_y = map(int, input().split())\r\n\r\nif start_x == end_x or start_y == end_y: rook = 1\r\nelse: rook = 2\r\n \r\nstart_field = end_field = \"black\"\r\nif (start_x % 2 != 0 and (start_x * start_y) % 2 != 0) or (start_x % 2 == 0 and start_y % 2 == 0): start_field = \"white\"\r\nif (end_x % 2 != 0 and (end_x * end_y) % 2 != 0) or (end_x % 2 == 0 and end_y % 2 == 0): end_field = \"white\"\r\n\r\nif start_field != end_field: bishop = 0\r\nelse:\r\n if abs(start_x - end_x) == abs(start_y - end_y): bishop = 1\r\n else: bishop = 2\r\n\r\nking = max(abs(start_x - end_x), abs(start_y - end_y))\r\n\r\nprint(rook, bishop, king)", "# your code goes here\r\nr1,c1,r2,c2=map(int,input().split())\r\nt=0\r\na=abs(r1-r2)\r\nb=abs(c1-c2)\r\nif (a-b)%2==0:\r\n\tt=2\r\nif a==b:\r\n\tt=1\r\nprint((r1!=r2)+(c1!=c2),t,max(a,b))\r\n", "r1, c1, r2, c2 = map(int, input().split())\r\ndr, dc = abs(r1-r2), abs(c1-c2)\r\nx, y = divmod(dr-dc, 2)\r\nprint(1+(dr*dc>0), (1-y)*(1+bool(x)), max(dr,dc))", "from collections import deque\r\n\r\ngraph = [[0] * 8 for i in range(8)]\r\nr1, c1, r2, c2 = [int(i) - 1 for i in input().split()]\r\n\r\n\r\ndef bfs_l():\r\n inf = 10 ** 9\r\n visited = [[inf] * 8 for i in range(8)]\r\n visited[r1][c1] = 0\r\n queue = deque([[c1, r1]])\r\n\r\n while queue:\r\n x, y = queue.pop()\r\n t = visited[y][x]\r\n for i in range(8):\r\n if t + 1 < visited[y][i]:\r\n visited[y][i] = t + 1\r\n queue.append([i, y])\r\n if t + 1 < visited[i][x]:\r\n visited[i][x] = t + 1\r\n queue.append([x, i])\r\n\r\n return visited[r2][c2]\r\n\r\n\r\ndef bfs_s():\r\n inf = 10 ** 9\r\n visited = [[inf] * 8 for i in range(8)]\r\n visited[r1][c1] = 0\r\n queue = deque([[c1, r1]])\r\n\r\n while queue:\r\n x, y = queue.pop()\r\n t = visited[y][x]\r\n for i in [[1, 1], [-1, -1], [1, -1], [-1, 1]]:\r\n rx, ry = i\r\n for j in range(1, 8):\r\n tx, ty = x + rx * j, y + ry * j\r\n if 0 <= tx <= 7 and 0 <= ty <= 7:\r\n if t + 1 < visited[ty][tx]:\r\n visited[ty][tx] = t + 1\r\n queue.append([tx, ty])\r\n else:\r\n break\r\n\r\n return visited[r2][c2]\r\n\r\n\r\ndef bfs_k():\r\n inf = 10 ** 9\r\n visited = [[inf] * 8 for i in range(8)]\r\n visited[r1][c1] = 0\r\n queue = deque([[c1, r1]])\r\n\r\n while queue:\r\n x, y = queue.pop()\r\n t = visited[y][x]\r\n for i in [[0, 1], [0, -1], [1, 0], [-1, 0], [1, 1], [-1, -1], [-1, 1], [1, -1]]:\r\n rx, ry = i\r\n if 0 <= x + rx <= 7 and 0 <= y + ry <= 7:\r\n if t + 1 < visited[y + ry][x + rx]:\r\n visited[y + ry][x + rx] = t + 1\r\n queue.append([x + rx, y + ry])\r\n\r\n return visited[r2][c2]\r\n\r\n\r\nl = bfs_l()\r\ns = bfs_s()\r\nk = bfs_k()\r\ninf = 10 ** 9\r\nl = l if l < inf else 0\r\ns = s if s < inf else 0\r\nk = k if k < inf else 0\r\nprint(l, s, k)", "r1,c1,r2,c2= map(int, input().split())\r\nl=[]\r\nif r1==r2 or c1==c2:\r\n l.append(1)\r\nelse:\r\n l.append(2)\r\n\r\nif (r1+c1)%2!= (r2+c2)%2:\r\n l.append(0)\r\nelse:\r\n if r1+c1==r2+c2 or r1-c1==r2-c2:\r\n l.append(1)\r\n else:\r\n l.append(2)\r\n\r\nl.append(max(abs(r1-r2), abs(c1-c2)))\r\n\r\nprint(*l)\r\n", "r1, c1, r2, c2 = map(int, input().split())\r\ndef rook(r1, c1, r2, c2):\r\n if r1 == r2 or c1 == c2:\r\n return 1\r\n else:\r\n return 2\r\n\r\n\r\ndef bis(r1, c1, r2, c2):\r\n if (r1 + c1) % 2 != (r2 + c2) % 2:\r\n return 0\r\n else:\r\n if r1 - c1 == r2 - c2 or r1 + c1 == r2 + c2:\r\n return 1\r\n else:\r\n return 2\r\n\r\n\r\ndef king(r1, c1, r2, c2):\r\n return max(abs(r1 - r2), abs(c1 - c2))\r\n\r\n\r\nr = rook(r1, c1, r2, c2)\r\nb = bis(r1, c1, r2, c2)\r\nk = king(r1, c1, r2, c2)\r\nprint(r, b, k)", "r1, c1, r2, c2 = [int(i) for i in input().split()]\ndifr = abs(r1-r2)\ndifc = abs(c1-c2)\nans = []\n\n#rook\nif r1 == r2 or c1 == c2:\n ans.append(1)\nelse:\n ans.append(2)\n\n#bishop\nif (r1+c1)%2 != (r2+c2)%2:\n ans.append(0)\nelif difr == difc:\n ans.append(1)\nelse:\n ans.append(2)\n\n#king\nans.append(max(difr, difc))\n\nprint(*ans)\n \t\t \t\t\t \t\t\t \t\t \t \t \t \t", "import sys\r\nimport string\r\n\r\nfrom collections import Counter, defaultdict\r\nfrom math import fsum, sqrt, gcd, ceil, factorial\r\nfrom itertools import combinations, permutations\r\n\r\n# input = sys.stdin.readline\r\nflush = lambda: sys.stdout.flush\r\ncomb = lambda x, y: (factorial(x) // factorial(y)) // factorial(x - y)\r\n\r\n\r\n# inputs\r\n# ip = lambda : input().rstrip()\r\nip = lambda: input()\r\nii = lambda: int(input())\r\nr = lambda: map(int, input().split())\r\nrr = lambda: list(r())\r\n\r\n\r\na, b, x, y = r()\r\n\r\nif a == x or b == y:\r\n rook = 1\r\nelse:\r\n rook = 2\r\n\r\nif (a + b) % 2 != (x + y) % 2:\r\n bishop = 0\r\nelse:\r\n if abs(a - x) == abs(b - y):\r\n bishop = 1\r\n else:\r\n bishop = 2\r\n\r\nking = max(abs(a - x), abs(b - y))\r\n\r\nprint(rook , bishop , king)\r\n" ]
{"inputs": ["4 3 1 6", "5 5 5 6", "1 1 8 8", "1 1 8 1", "1 1 1 8", "8 1 1 1", "8 1 1 8", "7 7 6 6", "8 1 8 8", "1 8 1 1", "1 8 8 1", "1 8 8 8", "8 8 1 1", "8 8 1 8", "8 8 8 1", "1 3 1 6", "1 3 1 4", "1 3 1 5", "3 3 2 4", "3 3 1 5", "1 6 2 1", "1 5 6 4", "1 3 3 7", "1 1 8 1", "1 7 5 4", "1 5 2 7", "1 4 6 2", "1 2 3 5", "1 8 8 7", "6 5 6 2", "6 3 3 5", "6 1 7 8", "1 2 3 2", "3 8 7 2", "4 2 6 4", "1 1 1 3", "6 8 8 6", "6 7 4 1", "6 5 1 4", "3 2 7 6", "3 8 4 1", "3 6 1 4"], "outputs": ["2 1 3", "1 0 1", "2 1 7", "1 0 7", "1 0 7", "1 0 7", "2 1 7", "2 1 1", "1 0 7", "1 0 7", "2 1 7", "1 0 7", "2 1 7", "1 0 7", "1 0 7", "1 0 3", "1 0 1", "1 2 2", "2 1 1", "2 1 2", "2 2 5", "2 2 5", "2 2 4", "1 0 7", "2 0 4", "2 0 2", "2 0 5", "2 0 3", "2 2 7", "1 0 3", "2 0 3", "2 2 7", "1 2 2", "2 2 6", "2 1 2", "1 2 2", "2 1 2", "2 2 6", "2 2 5", "2 1 4", "2 2 7", "2 1 2"]}
UNKNOWN
PYTHON3
CODEFORCES
217
21c7afb1480e78ad47c23361b6dbbc61
Valera and Plates
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can eat dishes of the first type from bowls and dishes of the second type from either bowls or plates. When Valera finishes eating, he leaves a dirty plate/bowl behind. His life philosophy doesn't let him eat from dirty kitchenware. So sometimes he needs to wash his plate/bowl before eating. Find the minimum number of times Valera will need to wash a plate/bowl, if he acts optimally. The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Valera will eat a first type dish. If *a**i* equals two, then on day *i* Valera will eat a second type dish. Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. Sample Input 3 1 1 1 2 1 4 3 1 1 1 1 1 3 1 2 2 2 2 8 2 2 1 2 1 2 1 2 1 2 Sample Output 1 1 0 4
[ "n, m, k = map(int, input().split())\r\ndaf = list(map(int, input().split()))\r\n\r\nc = 0\r\ntotal = 0\r\nwhile (m>0 or k>0) and c < n:\r\n f = daf[c]\r\n if f == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n total += 1\r\n else:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n total += 1\r\n c += 1\r\n\r\nprint(total + n - c)\r\n", "# cook your dish here\r\nn, b, p = map(int,input().split())\r\nls = list(map(int, input().split()))\r\nans = n - min(ls.count(2), p) - b\r\nif ans<=0:\r\n print(0)\r\nelse:\r\n print(ans)", "n, m, k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\n\ndef solve(n, m, k, a):\n cnt = 0\n\n for dish in a:\n if dish == 1:\n if m > 0:\n m -= 1\n else:\n cnt += 1\n else:\n if m == 0 and k == 0:\n cnt += 1\n elif k > 0:\n k -= 1\n else:\n m -= 1\n\n return cnt\n\nprint(solve(n, m, k, a))\n\t\t\t \t \t\t\t\t\t \t \t \t", "days, bowls, dishes = map(int, input().split())\r\nmeals = input().split(\" \")\r\nwash = 0\r\nfor meal in meals:\r\n if int(meal) == 1:\r\n if bowls <= 0:\r\n wash += 1\r\n else:\r\n bowls -= 1\r\n else:\r\n if dishes > 0:\r\n dishes -= 1\r\n elif bowls > 0:\r\n bowls -= 1\r\n else:\r\n wash += 1\r\nprint(wash)\r\n", "n, m, k = list(map(int, input().split()))\ntypes = list(map(int, input().split()))\nans = 0\n\nfor t in types:\n if t == 1:\n if m == 0:\n ans += 1\n else:\n m -= 1\n else:\n if k != 0:\n k -= 1\n continue\n if m != 0:\n m -= 1\n continue\n ans += 1\nprint(ans)\n\t \t \t\t\t \t \t \t \t\t \t\t \t\t\t\t \t\t\t", "n, m, k=map(int, input().split())\r\na=list(map(int, input().split()))\r\nv1=a.count(1)\r\nv2=a.count(2)\r\nh=v2-k\r\nif(h<0):\r\n h=0\r\nl=v1+h-m\r\nif(l<0):\r\n l=0\r\nprint(l)", "n,m,k=map(int,input().split())\r\ns=list(map(int,input().split()))\r\nfor i in range(n):\r\n if s[i]==2:\r\n k-=1\r\n else:\r\n m-=1\r\nif k<0:m+=k\r\nif m<=0:print(-m)\r\nelse:print(0)", "I=input\r\nn,m,k=map(int,I().split())\r\nt=I().count('2')\r\nprint(-min(0,m+min(0,k-t)-n+t))", "n, deep_dish, ploskiy_dish = map(int, input().split())\r\ntype = list(map(int, input().split()))\r\ndeep_meal = type.count(1)\r\nuniversal_meal = type.count(2)\r\nif deep_dish < deep_meal and ploskiy_dish < universal_meal:\r\n # print('first')\r\n print(deep_meal - deep_dish + universal_meal - ploskiy_dish)\r\n quit()\r\nif deep_dish < deep_meal and ploskiy_dish >= universal_meal:\r\n print(deep_meal - deep_dish)\r\n # print('2nd')\r\n quit()\r\nif deep_dish >= deep_meal and ploskiy_dish < universal_meal:\r\n if (universal_meal - ploskiy_dish) - (deep_dish - deep_meal) <= 0:\r\n # print('3rd')\r\n print(0)\r\n quit()\r\n else:\r\n print((universal_meal - ploskiy_dish) - (deep_dish - deep_meal))\r\n # print('3rd 2nd var')\r\n quit()\r\nif deep_dish >= deep_meal and ploskiy_dish >= universal_meal:\r\n # print('4th')\r\n print(0)\r\n\r\n\r\n\r\n\r\n\r\n", "setup = input().split(' ')\r\ndays = input().split(' ')\r\n\r\nbowls = int(setup[1])\r\nplates = int(setup[2])\r\n\r\nd1 = days.count('1')\r\nd2 = days.count('2')\r\n\r\nwash = 0\r\n\r\nif bowls - d1 >= 0:\r\n bowls -= d1\r\nelse:\r\n wash = -1 * (bowls - d1)\r\n bowls = 0\r\n\r\n#print(wash)\r\n\r\nif d2 - (bowls + plates) > 0:\r\n wash += (d2 - (bowls + plates))\r\n\r\nprint(wash)\r\n", "(days, bowls, plates) = map(int, input().split())\r\ntemp = input()\r\ntype1, type2 = temp.count('1'), temp.count('2')\r\n\r\nif bowls < type1:\r\n type1 -= bowls\r\n bowls = 0\r\nelse:\r\n bowls -= type1\r\n type1 = 0\r\n\r\ndishes = bowls + plates\r\n\r\nif dishes < type2:\r\n type2 -= dishes\r\nelse:\r\n type2 = 0\r\n \r\nprint(type1 + type2)", "#!/usr/bin/python3\n\nimport itertools as ittls\nfrom collections import Counter\n\nfrom pprint import pprint as pprint\n\nimport re\nimport math\n\n\ndef sqr(x):\n return x*x\n\ndef inputarray(func=int):\n return map(func, input().split())\n\n# --------------------------------------\n# --------------------------------------\n\nn, m, k = inputarray()\n\ntype2 = sum(inputarray()) - n\ntype1 = n - type2\n\nsm = max(type1 - m, 0) + max(type2 - max(m - type1, 0) - k, 0)\n\nprint(sm)\n", "n,bowl,plates = map(int,input().split())\r\ndays = list(map(int,input().split()))\r\nwash = 0\r\nfor i in range(n):\r\n\tif days[i] == 1 and bowl == 0 or bowl + plates == 0:\r\n\t\twash = wash + 1\r\n\telif days[i] == 2 and plates:\r\n\t\tplates = plates - 1\r\n\telse:\r\n\t\tbowl = bowl - 1\r\nprint(wash)", "'''\r\nCreated on ٠٩‏/١٢‏/٢٠١٤\r\n\r\n@author: mohamed265\r\n'''\r\n\r\nt = input().split()\r\nm = int(t[1])\r\nk = int(t[2])\r\ns = input()\r\np = s.count('1')\r\nb = s.count('2')\r\nm -= p\r\nk -= b\r\n#print(m , k)\r\nif m > 0:\r\n k += m\r\n if k < 0:\r\n print(abs(k))\r\n else:\r\n print(0)\r\nelif k >= 0:\r\n print(abs(m))\r\nelse:\r\n print(abs(k) + abs(m))\r\n", "def solve(n, m, k, days):\n \"\"\"\n \"\"\"\n to_wash = 0\n\n for d in days:\n\n if d == 1:\n if m == 0:\n to_wash += 1\n else:\n m -= 1\n\n if d == 2:\n\n if m == 0 and k == 0:\n to_wash += 1\n\n elif k != 0:\n k -= 1\n\n else:\n m -= 1\n\n return to_wash\n\n\nif __name__ == \"__main__\":\n n, m, k = [int(num) for num in input().split()]\n days = [int(num) for num in input().split()]\n\n print(solve(n, m, k, days))\n\n \t\t\t\t \t\t \t\t \t\t \t\t \t\t\t \t", "n,m,k= list(map(int, input().split(\" \")))\r\nx = list(map(int, input().split(\" \")))\r\ncount=0\r\ncount+=abs(min(m-x.count(1),0))\r\nk+=max(0,m-x.count(1))\r\ncount+=abs(min(k-x.count(2),0))\r\nprint(count)", "#!/usr/bin/python3.4\n\n# SIZE = 10\n# matrix = [[0] * SIZE for i in range(SIZE)]\n# array = [0] * SIZE\n\nn, a, b = map(int, input().split())\nans = 0\narr = list(map(int, input().split()))\na -= arr.count(1)\nb -= (arr.count(2) - (a if a > 0 else 0))\nprint((abs(a) if a < 0 else 0) + (abs(b) if b < 0 else 0))\n", "n,m,k=map(int,input().split())\n\nL=list(map(int,input().split()))\nans=0\nfor item in L:\n if(item==1):\n if(m==0):\n ans+=1\n m+=1\n m-=1\n else:\n if(k>0):\n k-=1\n continue\n if(m>0):\n m-=1\n continue\n ans+=1\nprint(ans)\n", "n,g,p=map(int,input().split())\r\na=list(map(int,input().split()))\r\nfor i in range(n):\r\n if a[i]==1:\r\n g-=1\r\n else:\r\n if p==0:\r\n g-=1\r\n else:\r\n p-=1\r\nif g<0:\r\n print(abs(g))\r\nelse:\r\n print(0)", "n, m, k = map(int, input().split())\r\nl = list(map(int, input().split()))\r\n\r\nm1 = l.count(1)\r\nm2 = l.count(2)\r\n\r\ns=0\r\nfor i in l:\r\n if i == 1:\r\n if m == 0:\r\n s+= 1\r\n else:\r\n m -=1\r\n else:\r\n if k == 0 and m==0:\r\n s+=1\r\n elif k == 0:\r\n m -= 1\r\n else:\r\n k -=1\r\nprint(s)", "n,m,k=(int(i) for i in input().split())\r\nl=[int(i) for i in input().split()]\r\nc=0\r\nfor i in range(n):\r\n if(l[i]==1):\r\n if(m>0):\r\n m-=1\r\n else:\r\n c+=1\r\n else:\r\n if(k>0):\r\n k-=1\r\n else:\r\n if(m>0):\r\n m-=1\r\n else:\r\n c+=1\r\nprint(c)", "import sys\r\ninput = sys.stdin.readline\r\n\r\nn, m, k = map(int, input().split())\r\nw = list(map(int, input().split()))\r\na = w.count(1)\r\n\r\nprint(max(a-m, 0) + max((n-a) - (max(m-a, 0) + k), 0))", "n, m, k = list(map(int, input().split()))\r\ns = list(map(int, input().split()))\r\nq = 0\r\nfor i in s:\r\n\tif i == 1:\r\n\t\tq += 1\r\nm -= q\r\nans = 0\r\nif m > 0:\r\n\tk += m\r\nelse:\r\n\tans = abs(m)\r\nif n - q > k:\r\n\tans += n - q - k\r\nprint(ans)\r\n", "s=input().split()\r\nn=int(s[0])\r\nbowl=int(s[1])\r\nplate=int(s[2])\r\ns=input().split()\r\na=0\r\nb=0\r\nfor i in s:\r\n if i=='1':\r\n a+=1\r\n if i=='2':\r\n b+=1\r\nkq=0\r\nif a>bowl:\r\n kq=a-bowl\r\n bowl=0\r\nelse: bowl=bowl-a\r\nif b>plate+bowl: kq+=b-(plate+bowl)\r\nprint(kq) \r\n", "n, b, p = map(int, input().split())\n\narr = list(map(int, input().split()))\n\nres = 0\n\nfor i in arr:\n if i == 1:\n if b > 0: b-=1\n\n else: res+=1\n \n if i == 2:\n if p > 0: p-=1\n\n elif b > 0: b-=1\n\n else: res+=1\n\n\nprint(res)", "import itertools\r\nimport math\r\nfrom collections import defaultdict\r\n\r\ndef input_ints():\r\n return list(map(int, input().split()))\r\n\r\ndef solve():\r\n n, m, k = input_ints()\r\n a, b = m, k\r\n ans = 0\r\n for x in input_ints():\r\n if x == 1:\r\n if a == 0:\r\n a = 1\r\n ans += 1\r\n a -= 1\r\n else:\r\n if a + b == 0:\r\n a = 1\r\n ans += 1\r\n if b:\r\n b -= 1\r\n else:\r\n a -= 1\r\n print(ans)\r\n\r\nif __name__ == '__main__':\r\n solve()\r\n", "n,m,k = map(int, input().split())\r\nal = list(map(int, input().split()))\r\nk -= al.count(2)\r\nm -= al.count(1) + max(0, -k)\r\nprint(max(0, -m))\r\n ", "n, m, k = map(int, input().split())\r\nb1 = len([0 for i in input().split() if i == '1'])\r\nb2 = n - b1\r\n\r\nprint (max(0, b1 - m + max(0, b2 - k)))", "# n, bowls, plates = map(int, input().split())\n# days = list(map(int, input().split()))\n# res = 0\n# for day in days:\n# if day == 1:\n# if bowls>0:\n# bowls -= 1\n# else:\n# res += 1\n# else:\n# if bowls+plates <=0:\n# res+=1\n# else:\n# if plates >= bowls:\n# plates -= 1\n# else:\n# bowls -= 1\n# print(res)\n\nn, m, k = map(int, input().split())\nl_d = list(map(int, input().split()))\n\nt = 0\nfor d in l_d:\n if d == 2:\n if k > 0:\n k -= 1\n else:\n if m > 0:\n m -= 1\n else:\n t += 1\n else:\n if m > 0:\n m -= 1\n else:\n t += 1\n\nprint(t)", "n, m, k = map(int, input().split())\r\na = input().count('1')\r\nm, k = m - a, k - (n - a)\r\nif k < 0:\r\n m += k\r\nprint(0 if m >= 0 else abs(m))\r\n", "n, m, k = map(int, input().split())\r\ninp = input()\r\nk -= inp.count(\"2\")\r\nm -= inp.count(\"1\")\r\nif k < 0:\r\n m += k\r\nprint(0 if m >= 0 else abs(m))", "dias, bowls, plates = list(map(int, input().split(\" \")))\na = list(map(int, input().split(\" \")))\num = a.count(1)\ndois = a.count(2)\n\nde_um = um - bowls\nde_dois = dois\n\nif de_um < 0:\n\tbowls = bowls - um\n\tde_dois = de_dois - bowls\nde_dois = de_dois - plates\n\nif de_um <= 0: de_um = 0\nif de_dois <= 0: de_dois = 0\nprint(de_um + de_dois)\n\n \t \t\t\t \t\t\t \t \t\t \t\t\t\t\t\t\t\t \t \t", "inputLine = input().split(\" \")\r\nnumDays = int(inputLine[0])\r\nnumBowls = int(inputLine[1])\r\nnumPlates = int(inputLine[2])\r\ndays = input().split(\" \")\r\nmeal1 = 0\r\nmeal2 = 0\r\nfor i in range(numDays):\r\n if days[i] == \"1\":\r\n meal1 += 1\r\n else:\r\n meal2 += 1\r\nnumBowls = numBowls - meal1\r\nnumPlates -= meal2\r\nif numPlates < 0:\r\n if numBowls > 0:\r\n numPlates += numBowls\r\nneedToWash = 0\r\nif numPlates < 0:\r\n needToWash += (-1 * numPlates)\r\nif numBowls < 0:\r\n needToWash += (-1 * numBowls)\r\nprint(needToWash)\r\n", "n, m, k = map(int,input().split())\nl = list(map(int, input().split()))\nb = l.count(1)\nbp = l.count(2)\ncount = 0\nif b > m:\n count += b-m\n if bp > k:\n count += bp - k\nelse:\n x = m-b\n if bp > (k+x):\n count += bp - (k+x)\n\nprint(count)\n\n \t\t \t\t\t \t\t\t \t\t \t \t \t", "'''input\n8 2 2\n1 2 1 2 1 2 1 2\n'''\nn, m, k = map(int, input().split())\na = list(map(int, input().split()))\nt = 0\nfor x in a:\n\tif x == 1:\n\t\tif m > 0:\n\t\t\tm -= 1\n\t\telse:\n\t\t\tt += 1\n\telse:\n\t\tif k > 0:\n\t\t\tk -= 1\n\t\telif m > 0:\n\t\t\tm -= 1\n\t\telse:\n\t\t\tt += 1\nprint(t)\n\n\n\n\n\n\n\n\n\n\n\n", "# https://codeforces.com/problemset/problem/369/A\n\ndef plates(n, m, k, arr):\n count = 0\n for i in range(n):\n if arr[i] == 1:\n if m:\n m -= 1\n else:\n count += 1\n if arr[i] == 2:\n if k:\n k -= 1\n elif m:\n m -= 1\n else:\n count += 1\n\n return count\n\n\nn, m, k = map(int, input().split())\narr = list(map(int, input().split()))\nprint(plates(n, m, k, arr))\n", "n, m, k = map(int, input().split())\r\nx = list(map(int, input().split()))\r\n\r\nt = 0\r\nfor d in x:\r\n if d == 2:\r\n if k > 0:\r\n k -= 1\r\n else:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n t += 1\r\n else:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n t += 1\r\n\r\nprint(t)", "n, m, k = tuple(map(int, input().split()))\r\ndays = list(map(int, input().split()))\r\nwashes = 0\r\nfor i in days:\r\n if i == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n washes += 1\r\n else:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n washes += 1\r\nprint(washes)\r\n", "n,b,p=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nw=0\r\nfor i in a:\r\n\tif i==1 and b>0:\r\n\t\tb=b-1\r\n\telif i==1 and b==0:\r\n\t\tw+=1\r\n\telif i==2:\r\n\t\tif p>0:\r\n\t\t\tp=p-1\r\n\t\t\tcontinue\r\n\t\telif b>0:\r\n\t\t\tb=b-1\r\n\t\t\tcontinue\r\n\t\telse:\r\n\t\t\tw+=1\r\nprint(w)", "n,m,k=map(int,input().split())\r\ntoeat=list(map(int,input().split()))\r\nclean=0\r\n\r\nfor i in range(len(toeat)):\r\n if(toeat[i]==1):\r\n if(m!=0):\r\n m=m-1\r\n else:\r\n clean=clean+1\r\n else:\r\n if(k!=0):\r\n k=k-1\r\n elif(m!=0):\r\n m=m-1\r\n else:\r\n clean=clean+1\r\nprint(clean)", "n, m, k = map(int, input().split())\r\nalist = [int(x) for x in input().split()]\r\n\r\n\r\nfor i in range(n):\r\n if alist[i] == 1:\r\n m -= 1\r\n elif alist[i] == 2:\r\n k -= 1\r\n \r\nprint(-1*min(0, m, m + k))", "\"\"\"\nModule which implements the search of the minimum number of plates that need to\nbe washed.\n\"\"\"\ndef min_plates(first: int, second: int, plan: list):\n \"\"\"\n Return the minimum number of plates.\n \"\"\"\n first_need = 0\n second_need = 0\n for elem in plan:\n if elem == 1:\n first_need += 1\n else:\n second_need += 1\n result = 0\n if first < first_need:\n result += first_need - first\n first = 0\n else:\n first -= first_need\n if second + first < second_need:\n result += second_need - second - first\n return result\n\nif __name__ == \"__main__\":\n settings = [int(x) for x in input().strip().split(\" \")]\n plan = [int(x) for x in input().strip().split(\" \")]\n print(min_plates(settings[1], settings[2], plan))\n \t \t \t\t \t\t \t\t \t \t \t \t\t", "n, m, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nans = 0\r\nmn = max(arr.count(1) - m, 0)\r\n\r\nans += mn\r\n\r\nk += max(-arr.count(1) + m, 0)\r\n\r\nmn2 = max(arr.count(2) - k, 0)\r\n\r\nans += mn2\r\n\r\nprint(ans)\r\n\r\n\r\n", "n, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\ncount = 0\r\nfor i in range(n):\r\n if a[i] == 1:\r\n if m:\r\n m -= 1\r\n else:\r\n count += 1\r\n elif a[i] == 2:\r\n if k:\r\n k -= 1\r\n else:\r\n if m:\r\n m -= 1\r\n else:\r\n count += 1\r\nprint(count)", "n, m, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nans = 0\r\nfor i in range(len(arr)):\r\n if arr[i] == 1 and m > 0:\r\n m -= 1\r\n elif arr[i] == 1 and m <= 0:\r\n ans += 1\r\n if arr[i] == 2 and k > 0:\r\n k -= 1\r\n elif arr[i] == 2 and k <= 0:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n ans += 1\r\nprint(ans)\r\n\r\n", "n,m,k = map(int,input().split())\r\nai = list(map(int,input().split()))\r\nfor el in ai:\r\n if el == 1:\r\n m -= 1\r\n else:\r\n k -= 1\r\nif k < 0 :\r\n m += k\r\nif m < 0:\r\n print(0 - m)\r\nelse:\r\n print(0)\r\n", "n, m, k = map(int, input().split())\r\na = [int(x) for x in input().split()]\r\nout=0\r\nfor i in range(n):\r\n if (a[i] == 2 and k != 0):\r\n k -= 1\r\n elif (m != 0):\r\n m -= 1\r\n else:\r\n out+=1\r\n\r\nprint(out)\r\n", "n, b, p = map(int, input().split())\r\narr = list(map(int, input().split()))\r\ncount = 0\r\nfor i in range(n):\r\n if arr[i] == 1:\r\n if b > 0:\r\n count += 1\r\n b -= 1\r\n else:\r\n if p > 0:\r\n p -= 1\r\n count += 1\r\n else:\r\n if b > 0:\r\n b -= 1\r\n count += 1\r\nprint(n - count)", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nans=0\r\nif m>=a.count(1):\r\n m=m-a.count(1)\r\nelse:\r\n ans=a.count(1)-m\r\n m=0\r\nif m+k>=a.count(2):\r\n pass\r\nelse:\r\n ans+=a.count(2)-(m+k)\r\nprint(ans)\r\n", "def main():\r\n [n,m,k]=[int(x) for x in input().split()]\r\n a=[int(x) for x in input().split()]\r\n w=0\r\n clean_b=m\r\n clean_p=k\r\n for i in a:\r\n if i==1:\r\n if clean_b==0:\r\n w = w+1\r\n else:\r\n clean_b=clean_b-1\r\n if i==2:\r\n if clean_p==0:\r\n if clean_b==0:\r\n w = w+1\r\n else:\r\n clean_b = clean_b-1\r\n else:\r\n clean_p = clean_p-1\r\n print(w)\r\n \r\nmain()", "n, bowls, plates = map(int, input().split())\ndays = list(map(int, input().split()))\nres = 0\nfor day in days:\n if day == 1:\n if bowls>0:\n bowls -= 1\n else:\n res += 1\n else:\n if plates > 0:\n plates -= 1\n else:\n if bowls > 0:\n bowls -= 1\n else:\n res += 1\nprint(res)\n\n# n, m, k = map(int, input().split())\n# l_d = list(map(int, input().split()))\n\n# t = 0\n# for d in l_d:\n# if d == 2:\n# if k > 0:\n# k -= 1\n# else:\n# if m > 0:\n# m -= 1\n# else:\n# t += 1\n# else:\n# if m > 0:\n# m -= 1\n# else:\n# t += 1\n\n# print(t)", "n, mangkok, piring = map(int, input().split())\ndishes = list(map(int, input().split()))\ncuci = 0\n\nfor dish in dishes:\n if dish == 1:\n if mangkok > 0:\n mangkok -= 1\n else:\n cuci += 1\n \n else:\n if piring > 0:\n piring -= 1\n elif piring == 0 and mangkok > 0:\n mangkok -= 1\n else:\n cuci += 1\n\nprint(cuci)\n\t\t\t \t \t \t \t \t \t \t\t", "wash = 0\r\na = input().split(' ')\r\nlist1 = input().split(' ')\r\nn = int(a[0])\r\nbowls = int(a[1])\r\nplates = int(a[2])\r\n\r\none = 0\r\ntwo = 0\r\nfor i in range(len(list1)):\r\n if list1[i] == '1':\r\n one += 1\r\n else:\r\n two += 1\r\n\r\nbowls = bowls - one\r\nif bowls < 0:\r\n wash = wash + abs(bowls)\r\n bowls = 0\r\n\r\nplates = plates - two\r\nif plates < 0:\r\n if bowls > 0:\r\n bowls = bowls + plates\r\n if bowls < 0:\r\n wash = wash + abs(bowls)\r\n else:\r\n wash = wash + abs(plates)\r\n\r\nprint(wash)\r\n", "n, k, l = map(int, input().split())\nps = input().split()\n\nr = 0\nfor p in ps:\n if p == '1':\n if k > 0:\n k -= 1\n else:\n r += 1\n elif p == '2':\n if l > 0:\n l -= 1\n elif k > 0:\n k -= 1\n else:\n r += 1\n\nprint(r)\n", "# You lost the game.\nn,m,k = map(int, input().split())\nL = list(map(int, input().split()))\nr = 0\nfor i in range(n):\n if L[i] == 1:\n if m:\n m -= 1\n else:\n r += 1\n else:\n if k:\n k -= 1\n elif m:\n m -= 1\n else:\n r += 1\nprint(r)\n", "n, m, p = map(int, input(). split())\ndishes = list(map(int, input(). split()))\ncuci = 0\n\nfor dish in dishes:\n if dish == 1:\n if m > 0:\n m -= 1\n else:\n cuci += 1\n \n else:\n if p > 0:\n p -= 1\n elif p == 0 and m > 0:\n m -= 1\n else:\n cuci += 1\n\nprint (cuci)\n \t\t\t\t\t\t\t \t \t \t\t \t \t\t\t\t\t\t\t", "\r\ndays,bowls,plates=map(int,input().split())\r\n\r\ndishes=list(map(int,input().split()))\r\n\r\ncwash=0\r\n\r\nfor i in range(0,days):\r\n if(dishes[i]==1 and bowls > 0):\r\n bowls-=1\r\n elif(dishes[i]==2 and plates > 0):\r\n plates-=1\r\n elif(dishes[i]==2 and plates==0 and bowls>0):\r\n bowls-=1\r\n else:\r\n cwash+=1\r\n\r\nprint(cwash)\r\n ", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nk1=a.count(1)\r\nk2=a.count(2)\r\nif k>=k2:\r\n k2=0\r\nelse:\r\n k1=k1+k2-k\r\nif k1<=m:\r\n print(0)\r\nelse:\r\n print(k1-m)", "n, m, k = [int(x) for x in input().split()]\nans = 0\nfor s in input().split():\n\tif s == '1':\n\t\tif m:\n\t\t\tm -= 1\n\t\telse:\n\t\t\tans += 1\n\telse:\n\t\tif k:\n\t\t\tk -= 1\n\t\telif m:\n\t\t\tm -= 1\n\t\telse:\n\t\t\tans += 1\nprint(ans)\n", "n, m, k = (int(i) for i in input().split())\r\ndata = [int(i) for i in input().split()]\r\nwash = 0\r\nfor i in data:\r\n if i == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n wash += 1\r\n else:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n wash += 1\r\nprint(wash)", "planned , bowls , plates = map(int , input().split()) \r\nl = list(map(int ,input().split())) \r\ni = 0\r\ndays = 0\r\nfor i in l : \r\n if bowls and i == 1 : \r\n bowls -= 1\r\n days += 1 \r\n elif (bowls or plates) and i == 2 : \r\n if plates: \r\n plates -= 1 \r\n else: \r\n bowls -=1 \r\n days += 1 \r\nprint(planned - days )", "from sys import stdin\r\ninput = stdin.readline\r\n\r\nlength, num_bowls, num_plates = [int(x) for x in input().split()]\r\narr = [int(x) for x in input().split()]\r\n\r\n# 1 is bowl\r\n# 2 is either\r\n\r\n# \r\n\r\nnum_ones = arr.count(1)\r\nnum_twos = length - num_ones \r\n\r\n# commit bowls to all the ones \r\n# if you dont have enough\r\n\r\n\r\nans = 0\r\nnum_bowls -= num_ones \r\nif num_bowls < 0:\r\n ans -= num_bowls\r\n num_bowls = 0 \r\n\r\n\r\nnum_dishes = num_bowls + num_plates\r\n\r\nmissing = num_twos - num_dishes \r\nif missing > 0:\r\n ans += missing\r\n\r\nprint(ans)", "n,m,k = input().split()\r\nn=int(n)\r\nm=int(m)\r\nk=int(k)\r\n\r\nl=input().split()\r\nm_,k_=l.count('1'),l.count('2')\r\ns=0\r\nr=0\r\nif(m_>=m):\r\n s+=m_-m\r\n if(k_>=k):\r\n s+=k_-k\r\n print(s)\r\nelse:\r\n k+=m-m_\r\n if(k_>=k):\r\n s+=k_-k\r\n print(s)\r\n", "n,b,p=map(int,input().split())\r\nl=[int(i) for i in input().split()]\r\nw=0\r\nfor i in l:\r\n if(i==1):\r\n if(b>0):\r\n b=b-1\r\n else:\r\n w=w+1\r\n else:\r\n if(p>0):\r\n p=p-1\r\n elif(b>0):\r\n b=b-1\r\n else:\r\n w=w+1\r\nprint(w) ", "n, m, k = map(int, input().split())\nr, a = 0, [int(e) for e in input().split()]\nfor i in a:\n if i == 2 and k > 0:\n k -= 1\n elif m > 0:\n m -= 1\n else:\n r += 1\nprint(r)\n", "n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nans=0\r\nfor x in l:\r\n if x==1:\r\n if m: m-=1\r\n else: ans+=1\r\n else:\r\n if k: k-=1\r\n elif m: m-=1\r\n else: ans+=1\r\nprint(ans)", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\na1=a.count(1)\r\na2=a.count(2)\r\nif(m>=a1):\r\n\tm=m-a1\r\n\tif(a2>=(m+k)):\r\n\t\ta2=a2-(m+k)\r\n\t\tprint(a2)\r\n\telse:\r\n\t\tprint(0)\r\nelse:\r\n\ta1=a1-m\r\n\tm=0\r\n\tif(a2>=(m+k)):\r\n\t\ta2=a2-(m+k)\r\n\t\tprint(a1+a2)\r\n\telse:\r\n\t\tprint(a1)", "n,m,k=map(int,input().split())\r\nh=0\r\na=[int(i) for i in input().split()]\r\nfor i in a:\r\n if i==1 and m:m-=1\r\n elif i==1 and not m:h+=1\r\n elif i==2 and k:k-=1\r\n elif i==2 and not k and m:m-=1\r\n elif i==2 and not k and not m:h+=1\r\nprint(h)", "n,m,k = map(int,input().split())\r\nai = list(map(int,input().split()))\r\nones = ai.count(1)\r\ntwos = ai.count(2)\r\ntotal = 0\r\nif ones - m >= 0:\r\n total += (ones-m)\r\n\r\nx = m - ones\r\nif x <= 0:\r\n m = 0\r\nelse:\r\n m -= ones\r\n\r\nk += m\r\n\r\nif twos - k >= 0:\r\n total += (twos-k)\r\n\r\nprint(total)", "# https://codeforces.com/problemset/problem/369/A\n# 900\n\nn, m, k = map(int, input().split())\n\no = 0\nfor d in input().split():\n d = int(d)\n\n if d == 1:\n if m == 0:\n o += 1\n else:\n m -= 1\n else:\n if k > 0:\n k -= 1\n elif m > 0:\n m -= 1\n else:\n o += 1\n\nprint(o)", "# bsdk idhar kya dekhne ko aaya hai, khud kr!!!\r\n# import math\r\n# from itertools import *\r\n# import random\r\n# import calendar\r\n# import datetime\r\n# import webbrowser\r\n\r\n\r\nn, bowls, plates = map(int, input().split())\r\narr = list(map(int, input().split()))\r\ncount = 0\r\nfor i in arr:\r\n if i == 2:\r\n if plates > 0:\r\n plates -= 1\r\n elif bowls > 0:\r\n bowls -= 1\r\n else:\r\n count += 1\r\n else:\r\n if bowls > 0:\r\n bowls -= 1\r\n else:\r\n count += 1\r\nprint(count)\r\n", "n, m, k = [int(x) for x in input().split()]\nq = [int(x) for x in input().split()]\nans = 0\nn1 = q.count(1)\nn2 = q.count(2)\n\nif (n1 > 0):\n\tm -= n1\n\tif ( m < 0):\n\t\tans += abs(m) \n\t\t\nif (n2 > 0):\n\tif (m > 0):\n\t\tk += m\n\t\n\tk -= n2\n\n\tif (k < 0):\n\t\tans += abs(k)\n\nprint(ans)\n \t \t \t \t\t\t \t \t\t\t \t \t \t\t", "n, m, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\nst = a.count(1)\r\nnd = a.count(2)\r\nif st > m:\r\n ans = st - m\r\n ans += max(0, nd - k)\r\nelse:\r\n ans = max(0, nd - (k + m - st))\r\nprint(ans)", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\ncnt1=0\r\ncnt2=0\r\nans=0\r\nfor i in a:\r\n if i==1:\r\n cnt1+=1\r\n else:\r\n cnt2+=1\r\nif cnt1<=m:\r\n m-=cnt1\r\nelse:\r\n ans+=cnt1-m\r\n m=0\r\nif cnt2>m+k:\r\n ans+=cnt2-(m+k)\r\nprint(ans)\r\n", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=0\r\nfor i in range(n):\r\n if a[i]==1:\r\n if m!=0:\r\n m-=1\r\n else:\r\n s+=1\r\n else:\r\n if k!=0:\r\n k-=1\r\n elif m!=0:\r\n m-=1\r\n else:\r\n s+=1\r\nprint(s)\r\n\r\n\r\n\r\n", "\ndef solve():\n num_days, num_bowls, num_plates = list(map(int, input().split()))\n #bowls = type 1 and type 2\n #plates = type 2\n\n days = list(map(int, input().split()))\n\n for dish in days:\n if dish == 1:\n num_bowls -= 1\n elif dish == 2:\n if num_plates > 0:\n num_plates -= 1\n else:\n num_bowls -= 1\n \n num_wash = 0\n if num_bowls <0:\n num_wash += abs(num_bowls)\n \n if num_plates < 0:\n num_wash += abs(num_plates)\n \n print(num_wash)\n\nsolve()\n\t\t \t\t \t \t \t\t \t \t \t \t", "# https://codeforces.com/problemset/problem/369/A\r\n# Valera and Plates\r\n\r\nn,m,k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 0\r\nfor x in a:\r\n if x==1:\r\n if m>0:\r\n m -= 1\r\n else:\r\n ans += 1\r\n else:\r\n if k>0:\r\n k -= 1\r\n elif m>0:\r\n m -= 1\r\n else:\r\n ans += 1\r\nprint(ans)", "n , m ,x = map(int ,input().split())\r\ny = list(map(int , input().split()))\r\n\r\na = y.count(1)\r\nb = n - a\r\n\r\nif b == 0 :\r\n if a >= m:\r\n print(a - m)\r\n else:\r\n print(0)\r\nelse:\r\n if a >= m :\r\n if b >= x :\r\n print((a-m)+(b-x))\r\n else:\r\n print(a-m)\r\n else:\r\n s = (m - a) + x\r\n if b >= s :\r\n print(b - s)\r\n else:\r\n print(0)", "n, m, k = [int(x) for x in input().split(' ')]\r\na = [int(x) for x in input().split(' ')]\r\n\r\n\r\nb = max(a.count(1) - m, 0)\r\np = max(n - b - m - k, 0)\r\nprint(b + p)", "n,m,k=map(int,input().split())\r\nar=list(map(int,input().split()))\r\na=ar.count(1)\r\nb=ar.count(2)\r\nif(a<m):\r\n print(max(0,(b-m+a-k)))\r\nelse:\r\n print(a-m+(max(0,b-k)))\r\n", "n, m, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\none = arr.count(1)\r\ntwo = arr.count(2)\r\n\r\nfirst = m - one\r\n\r\nres = 0\r\nif first < 0 :\r\n res += one - m\r\n m = 0\r\nelse :\r\n m -= one\r\n\r\nsecond = m + k - two\r\n\r\nif second < 0 :\r\n res += abs(second)\r\nprint(res)", "row = input().split()\r\n\r\nn = int(row[0])\r\nm = int(row[1])\r\nk = int(row[2])\r\n\r\nrowValues = input().split()\r\n\r\none = rowValues.count('1')\r\ntwo = rowValues.count('2')\r\n\r\nrem = 0\r\nwash = 0\r\nif m >= one:\r\n rem = m - one + k\r\n if two <= rem: print(wash)\r\n else:\r\n wash = two - rem\r\n print(wash)\r\nelse:\r\n wash = one - m\r\n if two <= k: print(wash)\r\n else:\r\n wash += two - k\r\n print(wash)\r\n\r\n\r\n\r\n\r\n", "n,m,k=map(int,input().split())\r\ns=input()\r\na,b=s.count('1'),s.count('2')\r\nif m<a:\r\n a-=m\r\n m=0\r\nelse:\r\n m-=a\r\n a=0\r\nif k+m<b:\r\n b-=k+m\r\nelse:\r\n b=0\r\nprint(a+b)", "#!/usr/bin/env python3\n\nn, m, k = tuple(map(int, input().split()))\na = list(map(int, input().split()))\n\nw = 0\nfor d in a:\n if d == 1:\n if m > 0:\n m = m - 1\n else:\n w = w + 1\n elif d == 2:\n if k > 0:\n k = k - 1\n elif m > 0:\n m = m - 1\n else:\n w = w + 1\n\nprint(w)\n", "_, clear_g, clear_p = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nwash = 0\r\nfor i in lst:\r\n if i == 1:\r\n wash += clear_g == 0\r\n clear_g = max(clear_g - 1, 0)\r\n else:\r\n wash += (clear_g + clear_p) == 0\r\n clear_g = max(clear_g - (clear_p == 0), 0)\r\n clear_p = max(clear_p - 1, 0)\r\n\r\nprint(wash)\n# Sat Sep 17 2022 10:17:07 GMT+0000 (Coordinated Universal Time)\n", "(n, m, k) = [int(r) for r in input().split()]\r\nxs = [int(r) for r in input().split()]\r\n\r\nans = 0\r\nfor x in xs:\r\n if x == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n ans += 1\r\n else:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n ans += 1\r\nprint(ans)\r\n", "n,bowls,plates = map(int, input().split())\r\nris = 0\r\ntypes = list(map(int, input().split()))\r\nfor p in types:\r\n if p == 1:\r\n if bowls != 0:\r\n bowls -= 1\r\n else:\r\n ris += 1\r\n else:\r\n if plates != 0:\r\n plates -= 1\r\n elif bowls != 0:\r\n bowls -= 1\r\n else:\r\n ris += 1\r\nprint(ris)\r\n", "n,m,k = list(map(int,input().split()))\na = input().split()\nw = 0\nfor x in a:\n if x == \"1\":\n if m > 0:\n m -= 1\n else:\n w += 1\n else:\n if k > 0 :\n k -= 1\n elif m > 0 :\n m -= 1\n else:\n w += 1\n \n \nprint (w) \n \n", "n, m, k = map(int, input().split())\na = list(map(int, input().split()))\n\ncnt = 0\n\nx = m\ny = k\nfor i in range(n):\n if a[i] == 1:\n if x > 0:\n x -= 1\n else:\n cnt += 1\n\n else:\n if y > 0:\n y -= 1\n elif x > 0:\n x -= 1\n else:\n cnt += 1\n\nprint(cnt)\n\n", "n=map(int,input().split())\r\nx,y,z=n\r\nt=list(map(int,input().split()))\r\none=t.count(1)\r\ntwo=t.count(2)\r\nsum=0\r\nif one>=y:\r\n sum+=(one-y)\r\n if two>=z:\r\n sum+=(two-z)\r\n print(sum)\r\n else:\r\n print(sum)\r\nelse:\r\n extra=y-one\r\n z=z+extra\r\n if two>=z:\r\n sum+=two-z\r\n print(sum)\r\n else:\r\n print(sum)\r\n\r\n\r\n\r\n", "import sys\r\nimport math\r\n\r\nnmk = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\na = [int(x) for x in (sys.stdin.readline()).split()]\r\n\r\nm = nmk[1]\r\nk = nmk[2]\r\n\r\nfor i in a:\r\n if(i == 1):\r\n m -= 1\r\n elif(i == 2):\r\n if(k > 0):\r\n k -= 1\r\n else:\r\n m -= 1\r\n \r\nresult = 0\r\nif(m < 0): \r\n result += int(math.fabs(m))\r\nif(k < 0):\r\n result += int(math.fabs(k))\r\n\r\nprint(result)\r\n", "n,m,k = map(int,input().split())\r\nll = input().split()\r\nj = 0\r\nfor i in ll:\r\n if i == '2':\r\n if k != 0:\r\n k -= 1\r\n else:\r\n if m != 0:\r\n m -= 1\r\n else:\r\n j += 1\r\n else:\r\n if m != 0:\r\n m -= 1\r\n else:\r\n j += 1\r\nprint(j)", "n,a,b=map(int,input().split())\r\nk=0\r\nl=list(map(int,input().split()))\r\nfor i in range(n) :\r\n if l[i]==1 :\r\n if a>0 :\r\n a=a-1\r\n else :\r\n k=k+1\r\n else :\r\n if b>0 :\r\n b=b-1\r\n else :\r\n if a>0 :\r\n a=a-1\r\n else :\r\n k=k+1\r\nprint(k)\r\n \r\n\r\n\r\n \r\n", "a,b,c=map(int, input().split())\r\narr = [int(i) for i in input().split()]\r\nc1 = arr.count(1)\r\nc2 = arr.count(2)\r\nans = 0\r\nif c1 > b:\r\n\tans += c1-b\r\n\tb = 0\r\nelse:b -= c1\r\nif c2 > c+b:ans += c2-(c+b)\r\nprint(ans)", "n,m,k = map(int,input().split())\narr = list(map(int,input().split()))\nx,y = 0,0\ncount = 0\nfor i in arr:\n if i==1:\n if x==m:\n count+=1\n else:\n x+=1\n else:\n if x==m and y==k:\n count += 1\n elif y!=k:\n y+=1\n else:\n x+=1\nprint(count)\n", "n, m, k = map(int, input().split())\r\n*a, = map(int, input().split())\r\na = [a.count(1), a.count(2)]\r\nprint(max(0, a[0] - m) + max(0, a[1] - k - max(0, m - a[0])))\r\n", "n, m, k = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nres = 0\r\nfor i in lst:\r\n if i == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n res = res + 1\r\n if i == 2:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n res = res + 1\r\nprint(res)", "n,m,k = input().split()\nn = int(n)\t#no. of days\nm = int(m)\t#no. of clean bowls\nk = int(k)\t#no. of clean plates\nl = list(map(int,input().split()))\ncount = 0\nfor i in l:\n\tif i==2 and k!=0:\n\t\tk-=1\n\telif i==2 and k==0:\n\t\tif m!=0:\n\t\t\tm-=1\n\t\telse:\n\t\t\tcount+=1\n\n\telif i==1 and m!=0:\n\t\tm-=1\n\telif i==1 and m==0:\n\t\tcount+=1\n\nprint(count)\n \t \t\t\t\t\t\t \t\t\t\t \t \t\t\t\t\t\t", "n, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 0\r\nif m <= a.count(1):\r\n ans += a.count(1) - m\r\n m = 0\r\nelse:\r\n m -= a.count(1)\r\nif m + k <= a.count(2):\r\n ans += a.count(2) - (m + k)\r\nprint(ans)", "#369A\r\nn, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\none = a.count(1)\r\ntwo = a.count(2)\r\nif one > m:\r\n ans = one-m\r\n if two > k:\r\n ans += two-k\r\n else:\r\n pass\r\nelse:\r\n left = m - one\r\n if two > left + k:\r\n ans = two - (left + k)\r\n else:\r\n ans = 0\r\nprint(ans)\r\n", "#July 3, 2014\r\n\r\nsa=input().split(' ')\r\nsa2=input().split(' ')\r\n\r\ndish1=0\r\ndish2=0\r\n\r\n#days bowls boths\r\n\r\ndays=int(sa[0])\r\n\r\nbowls=int(sa[1])\r\nboths=int(sa[2])\r\n\r\n\r\nfor element in sa2:\r\n if element=='1':\r\n dish1+=1\r\n else:\r\n dish2+=1\r\n \r\n\r\n\r\nif dish1<=bowls:\r\n print(max(0, dish2-boths-(bowls-dish1)))\r\n\r\nelse:\r\n if dish2>=boths:\r\n print(dish1+dish2-bowls-boths)\r\n else:\r\n print(dish1-bowls)\r\n", "from math import *\r\nfrom copy import *\r\nfrom string import *\t\t\t\t# alpha = ascii_lowercase\r\nfrom random import *\r\nfrom sys import stdin\r\nfrom sys import maxsize\r\nfrom operator import *\t\t\t\t# d = sorted(d.items(), key=itemgetter(1))\r\nfrom itertools import *\r\nfrom collections import Counter\t\t# d = dict(Counter(l))\r\n\r\nn,m,k=map(int,input().split(\" \"))\r\n\r\nc1=0\r\nc2=0\r\narray = list(map(int,input().split(\" \")))\r\nfor i in array:\r\n\tif(i==1):\r\n\t\tc1=c1+1\r\n\telse:\r\n\t\tc2=c2+1\r\ncount=0\r\n\r\nif(m>=c1):\r\n\tm=m-c1\r\nelse:\r\n\tcount=count+c1-m\r\n\tm=0\r\n\r\nif(m+k>=c2):\r\n\tprint(count)\r\nelse:\r\n\tcount=count+c2-m-k\r\n\tprint(count)\r\n\t\t\r\n", "n,m,k=map(int,input().split())\nl=list(map(int,input().split()))\nans=0\nans+=max(0,l.count(1)-m)\nm=max(m-l.count(1),0)\nans+=max(0,l.count(2)-k-m)\nprint (ans)", "b=input().split()\n(n,m,k)=tuple(map(int,b))\nd=input().split()\ndish=list(map(int,d))\nwash=0\nfor i in dish:\n\tif i==1:\n\t\tif m>0:\n\t\t\tm-=1\n\t\telse:\n\t\t\twash+=1\n\telse:\n\t\tif k>0:\n\t\t\tk-=1\n\t\telse:\n\t\t\tif m>0:\n\t\t\t\tm-=1\n\t\t\telse:\n\t\t\t\twash+=1\nprint(wash)\n\t \t\t\t\t\t \t \t\t\t\t \t\t\t\t\t\t \t", "n,m,k = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nl1 = l.count(1)\r\nanswer = 0\r\nif l1 > m:\r\n answer += l1-m\r\n m = 0\r\nelse:\r\n m -= l1\r\n\r\nif m + k < (n-l1):\r\n answer += (n-l1)-(m+k)\r\nprint(answer)\r\n", "class CodeforcesTask369ASolution:\n def __init__(self):\n self.result = ''\n self.n_m_k = []\n self.plan = []\n\n def read_input(self):\n self.n_m_k = [int(x) for x in input().split(\" \")]\n self.plan = [int(x) for x in input().split(\" \")]\n\n def process_task(self):\n cleans = 0\n bowls, plates = self.n_m_k[1], self.n_m_k[2]\n for day in self.plan:\n if day == 1:\n if bowls:\n bowls -= 1\n else:\n cleans += 1\n else:\n if plates:\n plates -= 1\n elif bowls:\n bowls -= 1\n else:\n cleans += 1\n self.result = str(cleans)\n\n def get_result(self):\n return self.result\n\n\nif __name__ == \"__main__\":\n Solution = CodeforcesTask369ASolution()\n Solution.read_input()\n Solution.process_task()\n print(Solution.get_result())\n", "from sys import stdin\nfrom collections import defaultdict, deque, Counter\nfrom math import floor, ceil, log, inf, sqrt\nfrom heapq import *\nfrom functools import lru_cache\nfrom bisect import bisect_left, bisect_right\nimport itertools\nimport random\nfrom string import ascii_lowercase\n\nN,M,K = map(int, stdin.readline().split())\ndishes = [int(x) for x in stdin.readline().split()]\nans = 0\n\nfor d in dishes:\n if d == 1:\n if M == 0:\n ans += 1\n else:\n M -= 1\n else:\n if K == 0:\n if M == 0:\n ans += 1\n else:\n M -= 1\n else:\n K -= 1\nprint(ans)\n\n\t\t \t\t \t\t \t \t \t\t \t\t\t\t", "n, m, k = map(int, input().split())\r\nprint(max(0, n - m - min(k, input().count('2'))))", "n, m, k = [int(x) for x in input().split()]\r\ndishes = [int(x) for x in input().split()]\r\nres = 0\r\nfor i in range (n):\r\n if dishes[i] == 2:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n res += 1\r\n elif dishes[i] == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n res += 1\r\nprint(res)", "from collections import Counter\r\n\r\n\r\nday, bowl, plate = [int(i) for i in input().split()]\r\nc = Counter(input().split())\r\nb = bowl - c['1']\r\nif b >= 0:\r\n need = c['2'] - plate - b\r\n print(need if need > 0 else 0)\r\nelse:\r\n need = c['2'] - plate\r\n print(-b + max(0, need))\r\n", "I = [int(i) for i in input().split()]\r\nn, m, k = I[0], I[1], I[2]\r\nI = [int(i) for i in input().split()]\r\nfirst, second = 0, 0\r\nfor i in I:\r\n if i == 1: first += 1\r\n else: second += 1\r\nans = 0\r\nif first > m:\r\n ans += first - m\r\n m = 0\r\nelse: m -= first\r\nif second > m + k: ans += second - m - k\r\nprint(ans)", "n, m, k = map(int, input().split())\r\na = input().split()\r\ntype1 = a.count('1')\r\ntype2 = a.count('2')\r\nres = 0\r\n\r\nif m - type1 < 0:\r\n res = type1 - m\r\n if k - type2 < 0:\r\n res += (type2 - k)\r\n print(res)\r\nelse:\r\n m -= type1\r\n if (m + k) - type2 < 0:\r\n res = type2 - (m + k)\r\n print(res)\r\n", "n, m, k = (int(x) for x in input().split())\nval = 0\nfor ai in (int(x) for x in input().split()):\n if ai == 2 and k > 0:\n k -= 1\n elif m > 0:\n m -= 1\n else:\n val += 1\nprint(val)\n", "n,m,k = map(int,input().split())\r\nans = 0\r\nfor c in map(int,input().split()):\r\n if c==1:\r\n if m:\r\n m-=1\r\n else:\r\n ans+=1\r\n elif c==2:\r\n if k:\r\n k-=1\r\n elif m:\r\n m-=1\r\n else:\r\n ans+=1\r\nprint(ans)\r\n", "inp = input().split(' ')\r\na = int(inp[0])\r\nb = int(inp[1])\r\nc = int(inp[2])\r\ne = 0\r\nl = input().split(' ')\r\nfor i in range(len(l)):\r\n l[i] = int(l[i])\r\nfor i in range(len(l)):\r\n if l[i] == 2:\r\n if c > 0:\r\n c -= 1\r\n elif b > 0:\r\n b -= 1\r\n else:\r\n e += 1\r\n else:\r\n if b > 0:\r\n b -= 1\r\n else:\r\n e += 1\r\nprint(e)\r\n", "try:\r\n z = list(map(int, input().split()))\r\n a = list(map(int, input().split()))\r\n n = z[0]\r\n m = z[1]\r\n k = z[2]\r\n s1 = a.count(1)\r\n s2 = a.count(2)\r\n if s1 < m:\r\n m -= s1\r\n if s2 < k+m:\r\n print(0)\r\n else:\r\n print(s2 - (k+m))\r\n else:\r\n w = (s1-m)\r\n if s2 > k:\r\n w += (s2-k)\r\n print(w)\r\nexcept:\r\n pass", "n, m, k = list(map(int, input().split()))\r\nans = 0\r\na = list(map(int,input().split()))\r\na.sort()\r\nfor i in range(len(a)):\r\n if (a[i] == 1):\r\n m -= 1\r\n a[i] = 0\r\n if (m <= 0):\r\n break\r\nfor i in range(len(a)):\r\n if (k <= 0 and m <= 0):\r\n break\r\n if (a[i] != 0):\r\n if (a[i] == 2):\r\n if (m >= 1):\r\n m -= 1\r\n a[i] = 0\r\n else:\r\n k -= 1\r\n a[i] = 0\r\n \r\n# print(a)\r\nfor i in range(len(a)):\r\n if (a[i] != 0):\r\n ans += 1\r\nprint(ans)", "n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nb=l.count(1)\r\np=l.count(2)\r\nc=0\r\n\r\nif m>=b:\r\n\tm-=b\r\nelse:\r\n\tc+=b-m\r\n\tm=0\r\nif m+k<p:\r\n\tc+=(p-(m+k))\r\nprint(c)", "n,bowl,dish=(map(int,input().split()))\r\nz=list(map(int,input().split()))\r\nx=z.count(1)\r\ny=z.count(2)\r\nc=0\r\nif bowl<x:\r\n c=x-bowl\r\n bowl=0\r\nelse:\r\n bowl-=x\r\ny=max(0,y-dish)\r\ny=max(0,y-bowl)\r\nprint(c+y)", "n,m,k = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nno = 0\nnt = 0\n\nfor i in a:\n\tif i == 1:\n\t\tno += 1\n\telse:\n\t\tnt += 1\n\nans = (0 if no - m < 0 else (no - m)) + (0 if (nt - (k + (abs(no - m) if no - m < 0 else 0))) < 0 else (nt - (k + (abs(no - m) if no - m < 0 else 0))))\n\nprint(ans)", "n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nc1=l.count(1)\r\nc2=l.count(2)\r\nt=0\r\nif m>=c1:\r\n\tm-=c1\r\nelse:\r\n\tt+=c1-m\r\n\tm=0\r\nif m+k<c2:\r\n\tt+=(c2-m-k)\r\nprint(t)", "_, clear_g, clear_p = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nwash = 0\r\nfor i in lst:\r\n if i == 1:\r\n wash += clear_g <= 0\r\n clear_g -= 1\r\n else:\r\n wash += clear_g <= 0 and clear_p <= 0\r\n clear_g -= clear_p <= 0\r\n clear_p -= 1\r\n\r\nprint(wash)\n# Sat Sep 17 2022 10:25:47 GMT+0000 (Coordinated Universal Time)\n", "n, m, k = map(int, input().split())\na = list(map(int, input().split()))\n\nwash_count = 0\nfor i in range(n):\n if a[i] == 1:\n if m > 0:\n m -= 1\n else:\n wash_count += 1\n else:\n if k > 0:\n k -= 1\n elif m > 0:\n m -= 1\n else:\n wash_count += 1\n\nprint(wash_count)\n\n\t \t\t \t \t \t\t\t \t\t\t \t \t \t", "n,m,k=map(int,input().split());c=0\r\nfor i in map(int,input().split()):\r\n\tif i==1 and m>0:m-=1\r\n\telif i==2 and k>0:k-=1\r\n\telif i==2 and m>0:m-=1\r\n\telse:c+=1\r\nprint(c)", "n,m,k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\nans = 0\r\nfor i in arr:\r\n\tif i == 1:\r\n\t\tif m>0:\r\n\t\t\tm-=1\r\n\t\telse:\r\n\t\t\tans += 1\r\n\telse:\r\n\t\tif k>0:\r\n\t\t\tk-=1\r\n\t\telif m>0:\r\n\t\t\tm-=1\r\n\t\telse:\r\n\t\t\tans += 1\r\nprint(ans)\r\n", "n, m, k = map(int, input().split())\r\nlst = list(map(int, input().split()))\r\nkol1 = lst.count(1)\r\nkol2 = lst.count(2)\r\nans1 = max(0, kol1 - m)\r\ne = max(0, m - kol1)\r\nans2 = max(0, kol2 - k - e)\r\nprint(ans1 + ans2)\r\n", "n,m,k = map(int, input().split())\r\nval = list(map(int, input().split()))\r\nc2 = 0 \r\nfor i in range(n):\r\n if val[i]==2:\r\n c2 += 1 \r\n\r\nprint(max(max(n-m,0) - min(c2,k),0))", "import math\r\n\r\ndef ost(a,b):\r\n if a%b!=0:\r\n return 1\r\n return 0\r\n\r\nn,gl,m=map(int,input().split())\r\na=list(map(int,input().split()))\r\nans=0\r\nif gl>=a.count(1):\r\n gl=gl-a.count(1)\r\n if a.count(2)>gl+m:\r\n print(abs(a.count(2)-gl-m))\r\n else:\r\n print(0)\r\nelse:\r\n if m<a.count(2):\r\n ans=abs(m-a.count(2))\r\n print(a.count(1)-gl+ans)", "from sys import stdin\n\n\ndef main():\n n, m, k = map(int, stdin.readline().strip().split())\n l = [0, 0, 0]\n for x in map(int, stdin.readline().strip().split()):\n l[x] += 1\n return max(sum(l) - m - k, l[1] - m, 0)\n\n\nprint(main())\n", "n, m, k = map(int, input().split())\r\nmeallist = [int(x) for x in input().split()]\r\ntotal = 0\r\nfor elem in meallist:\r\n if elem == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n total += 1\r\n else:\r\n if m + k > 0:\r\n if k > 0:\r\n k -= 1\r\n else:\r\n m -= 1\r\n else:\r\n total += 1\r\nprint(total)", "n,m,k=map(int,input().split())\r\narr=[int(i) for i in input().split()]\r\nc=0\r\nfor i in arr:\r\n if i==1:\r\n if m!=0:\r\n m=m-1\r\n else:\r\n c=c+1\r\n\r\n elif i==2:\r\n if k!=0:\r\n k=k-1\r\n elif m!=0:\r\n m=m-1\r\n else:\r\n c=c+1\r\nprint(c)\r\n", "n,cb,cp=(input().split())\r\nn=int(n)\r\ncb=int(cb)\r\ncp=int(cp)\r\ntot=cb+cp\r\ndishes=map(int,input().split())\r\nans=0\r\nfor i in dishes:\r\n\tif(i==1):\r\n\t\tif(cb>0):\r\n\t\t\tcb-=1\r\n\t\telse:\r\n\t\t\tans+=1\r\n\tif(i==2):\r\n\t\tif(cp > 0):\r\n\t\t\tcp-=1\r\n\t\telif(cb > 0):\r\n\t\t\tcb-=1\r\n\t\telse:\r\n\t\t\tans+=1\r\n\r\nprint(ans)", "n, m, k = map(int, input().split())\r\ndishes= list(map(int, input().split()))\r\nanswer=0\r\nfor i in dishes:\r\n if i==1:\r\n m = m-1\r\n if m<0:\r\n answer = answer +1\r\n if i==2:\r\n if k>0:\r\n k = k-1\r\n elif m>0:\r\n m = m-1\r\n else:\r\n answer = answer+1\r\nprint(answer)\r\n ", "k,n,m=map(int,input().split())\r\ns=list(map(int,input().split()))\r\na=s.count(1)\r\nb=s.count(2)\r\nj=0\r\nif a<=n:\r\n\ta-=n\r\nelse:\r\n\tj+=a-n\r\n\ta=0\r\nif m>=(a+b):\r\n\tj=j\r\nelse:\r\n\tj+=(b+a)-m\r\nprint(j)\r\n\t", "n,m,k=map(int, input().split())\r\na=list(map(int, input().split()))\r\nb=[0,0]\r\nfor i in a:\r\n b[i-1]+=1\r\nif k>b[1]:\r\n b[1]=0\r\nelse:\r\n b[1]-=k\r\nif m>sum(b):\r\n print(0)\r\nelse:\r\n print(sum(b)-m)", "#!/usr/bin/env python3\n\nn, m, k = map(int, input().split())\ndish = [int(i) for i in input().split()]\nwash = 0\nt_m, t_k = m, k\n\nfor i in dish:\n\tif i == 1:\n\t\tif m != 0:\n\t\t\tm -= 1\n\t\telse:\n\t\t\twash += 1\n\tif i == 2:\n\t\tif k != 0:\n\t\t\tk -= 1\n\t\telse:\n\t\t\tif m != 0:\n\t\t\t\tm -= 1\n\t\t\telse:\n\t\t\t\twash += 1\nprint(wash)", "n,m,k=map(int,input().split())\r\ndishes=list(map(int,input().split()))\r\ntoBeWashed=0\r\nfor i in range(len(dishes)):\r\n if dishes[i]==1:\r\n if m!=0:\r\n m=m-1\r\n else:\r\n toBeWashed=toBeWashed+1\r\n else:\r\n if k!=0:\r\n k=k-1\r\n elif m!=0:\r\n m=m-1\r\n else:\r\n toBeWashed=toBeWashed+1\r\nprint(toBeWashed)\r\n", "d, bowls, plates = map(int,input().split())\r\ndishes = input()\r\ntype1 = dishes.count('1')\r\ntype2 = dishes.count('2')\r\n\r\nclean = max(type1-bowls,0) \r\nbowls = max(bowls-type1, 0)\r\nplates += bowls\r\nclean += max(type2-plates,0)\r\nprint (clean)", "n , cleanBowls , cleanPlates = map(int, input().split())\r\nlist = [int(i) for i in input().split()]\r\nwash = 0\r\n\r\nfor i in range(n):\r\n if list[i] == 1 and cleanBowls > 0:\r\n cleanBowls -= 1\r\n elif list[i] == 2 and (cleanBowls > 0 or cleanPlates > 0):\r\n if cleanPlates == 0:\r\n cleanBowls -= 1\r\n else:\r\n cleanPlates -= 1\r\n else:\r\n wash += 1\r\nprint(wash)", "\r\nR = lambda:map(int,input().split())\r\n\r\nn,m,k = R()\r\n\r\narr = list(R())\r\nans = 0\r\nfor i in arr:\r\n \r\n if i == 1:\r\n if m == 0:\r\n ans += 1\r\n else:\r\n m -= 1\r\n else:\r\n if k != 0:\r\n k -= 1\r\n continue\r\n if m != 0:\r\n m -= 1\r\n continue\r\n ans += 1\r\n\r\nprint(ans)\r\n\r\n", "n, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = a.count(2)\r\nif a.count(1) < m:\r\n m -= a.count(1)\r\n ans -= m\r\n if ans > k:\r\n print(ans - k)\r\n else:\r\n print(0)\r\nelse:\r\n m = abs(m - a.count(1))\r\n if ans > k:\r\n print(m + ans - k)\r\n else:\r\n print(m)", "n, m, k = map(int, input().split())\r\narr = list(map(int, input().strip().split()))[:n]\r\ncount = 0\r\n\r\nfor i in range(n):\r\n\tif arr[i] == 1:\r\n\t\tif m:\r\n\t\t m = m-1\r\n\t\telse:\r\n\t\t\tcount += 1\r\n\telse:\r\n\t\tif k:\r\n \t\t\tk-=1\r\n\t\telif m:\r\n \t\t\tm-=1\r\n\t\telse:\r\n \t\t\tcount+=1\r\n \t\t\r\nprint(count)\r\n \t\t\t\r\n", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nx=a.count(1)\r\ny=a.count(2)\r\nc=0\r\nif x>m:\r\n\tc+=(x-m)\r\n\tm=0\t\r\nelse:\r\n\tm-=x\r\nif y>k+m:\r\n\tc+=(y-k-m)\r\nprint(c)", "n, bowl, plate = map(int,input().split())\nplan = [*map(int,input().split())]\n\nwash = 0\nfor i in plan:\n if i == 1:\n if bowl - 1 == -1:\n wash+=1\n else:\n bowl-=1\n else:\n if plate - 1 == -1:\n if bowl - 1 == -1:\n wash+=1\n else:\n bowl-=1\n else:\n plate-=1\nprint(wash)", "n, m, k = map(int, input().split())\na = input().split()\no = a.count('1')\nt = 0\nt += max(0, o - m)\nt += max(0, n - o - max(0, m - o) - k)\nprint(t)\n", "n,x,y=map(int,input().split())\r\na=list(map(int,input().split()))\r\nc=0\r\nfor i in a:\r\n\tif i==1:\r\n\t\tif x<1:\r\n\t\t\tc+=1\r\n\t\telse:\r\n\t\t\tx-=1\r\n\telif i==2:\r\n\t\tif x<1 and y<1:\r\n\t\t\tc+=1\r\n\t\telse:\r\n\t\t\tif y>=1:\r\n\t\t\t\ty-=1\r\n\t\t\telse:\r\n\t\t\t\tx-=1\r\nprint(c)\r\n", "# import sys\r\n# sys.stdin = open(\"test.in\",\"r\")\r\n# sys.stdout = open(\"test.out.py\",\"w\")\r\nn,a,b=map(int,input().split())\r\nc=list(map(int,input().split()))\r\ncount=0\r\nfor i in range(n):\r\n\tif c[i]==1:\r\n\t\tif a>0:\r\n\t\t\ta-=1\r\n\t\telse:\r\n\t\t\tcount+=1\r\n\telse:\r\n\t\tif b>0:\r\n\t\t\tb-=1\r\n\t\telif a>0:\r\n\t\t\ta-=1\r\n\t\telse:\r\n\t\t\tcount+=1\r\nprint(count)\t\t\t\t\t\t\t", "'''\r\nCreated on Nov 24, 2013\r\n\r\n@author: Ismael\r\n'''\r\n\r\nimport sys\r\n\r\ndef readInputs():\r\n global n,m,k, dishes\r\n (n,m,k) = map(int,f.readline().split())\r\n dishes = list(map(int,f.readline().split()))\r\n #print(n,m,k)\r\n #print(dishes)\r\n\r\ndef solve():\r\n global k\r\n nb1 = len([1 for dishe in dishes if dishe == 1])\r\n nb2 = len([1 for dishe in dishes if dishe == 2])\r\n if(nb1 <= m and nb2 <= k+(m-nb1)):\r\n return 0\r\n nbDayOk = m\r\n i = 0\r\n while(i < len(dishes) and k > 0):\r\n if(dishes[i]==2):\r\n k -= 1\r\n nbDayOk += 1\r\n i += 1\r\n return n-nbDayOk\r\n\r\ndef tests():\r\n global f\r\n bFail = False\r\n for i in range(1,5):\r\n # inputs\r\n f = open(\"test\"+str(i)+\".txt\")\r\n readInputs()\r\n # output expected\r\n resExpect = f.readline()\r\n # output\r\n res = str(solve())\r\n if(res != resExpect):\r\n print(\"TEST\",i,\"FAILED !\"+\" Found :\",res,\", Expected :\",resExpect)\r\n bFail = True\r\n else:\r\n print(\"TEST\",i,\"PASSED\")\r\n if(not bFail):\r\n print(\"\\n--- ALL OF THE \"+str(i)+\" TESTS HAVE SUCCEEDED ---\")\r\n\r\ndef main():\r\n global f\r\n i = 2\r\n if(i == 1):\r\n tests()\r\n else:\r\n f = sys.stdin\r\n readInputs()\r\n print(solve())\r\n \r\nmain()\r\n", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\n#if a[i]==1 and m<0 : count+=1\r\n#elif a[i]==2 and m+k<0 : count+=1\r\ncount=0\r\nfor i in a:\r\n if i==1 and m<=0:\r\n count+=1\r\n m=0\r\n elif i==1 and m>0:\r\n m-=1\r\n elif i==2 and m+k<=0:\r\n count+=1\r\n\r\n elif i==2 and m+k>0:\r\n if k>0:\r\n k-=1\r\n elif k<=0:\r\n m-=1\r\nprint(count)\r\n", "days, bowls, plates = map(int, input().split())\n\nmeals = list(map(int, input().split()))\n\ncount = 0\n\nfor i in range(days):\n if meals[i] == 1:\n bowls -= 1\n elif meals[i] == 2:\n if plates > 0:\n plates -= 1\n else:\n bowls -= 1\n\n if bowls < 0:\n bowls = 0\n count += 1\n\nprint(count)\n\t\t\t\t\t \t\t \t \t \t\t\t \t\t\t", "n,m,k = list(map(int, input().split()))\r\nlst = list(map(int, input().split()))\r\nans=0\r\n\r\nfor i in range(n):\r\n if lst[i]==1:\r\n if m==0:\r\n ans+=1\r\n else:\r\n m-=1\r\n else:\r\n if k!=0:\r\n k-=1\r\n continue\r\n if m!=0:\r\n m-=1\r\n continue\r\n \r\n ans+=1\r\n\r\nprint(ans)", "n, m, k = [int(i) for i in input().split()]\r\nlst = [int(i) for i in input().split()]\r\nresult = 0\r\nfor elem in lst:\r\n if elem == 1:\r\n if m == 0:\r\n result += 1\r\n else:\r\n m -= 1\r\n else:\r\n if k != 0:\r\n k -= 1\r\n continue\r\n if m != 0:\r\n m -= 1\r\n continue\r\n result += 1\r\nprint(result)", "def main():\n\tl=input().split(' ')\n\tn,m,k=int(l[0]),int(l[1]),int(l[2])\n\tj=input().split(' ')\n\tbuff=0\n\n\tfor x in range(0,n):\n\t\tj[x]=int(j[x])\n\t\tif j[x]==1:\n\t\t\tif m>=1:\n\t\t\t\tm=m-1\n\t\t\telse:\n\t\t\t\tm=m-1\n\t\t\t\tbuff=buff+1\n\t\telse:\n\t\t\tif k>=1:\n\t\t\t\tk=k-1\n\t\t\telif m>=1:\n\t\t\t\tm=m-1\n\t\t\telse:\n\t\t\t\tbuff=buff+1\n\tprint(buff)\nif __name__ == '__main__':\n\tmain()", "n, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\n\r\nwashing = 0\r\nfor dish in a:\r\n if dish == 1:\r\n if m > 0:\r\n m -= 1\r\n else:\r\n washing += 1\r\n else:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n washing += 1\r\n\r\nprint(washing)\r\n", "n, m, k = list(map(int, input().split()))\r\na = list(map(int, input().split()))\r\na1 = a.count(1)\r\na2 = a.count(2)\r\nres = 0\r\nif a1 > m:\r\n res += a1 - m\r\n m = a1\r\nm -= a1\r\nif k + m < a2:\r\n res += a2 - k - m\r\nprint(res)\r\n", "n, m, k = map(int, input().split())\r\na = [i for i in input().split()]\r\nans = 0\r\nfor i in a:\r\n if i == '1':\r\n if m > 0:\r\n m -= 1\r\n else:\r\n ans += 1\r\n else:\r\n if k > 0:\r\n k -= 1\r\n elif m > 0:\r\n m -= 1\r\n else:\r\n ans += 1\r\nprint(ans)", "a,b,c = map(int,input().split())\r\nd= list(map(int,input().split()))\r\ne=d.count(1)\r\nf=d.count(2)\r\n\r\ng= max(e-b,0)\r\nb = max(b-e, 0)\r\nc+=b\r\ng+= max(f-c,0)\r\nprint (g)", "n, m, k = [int(i) for i in input().split()]\r\na = input().split()\r\nans = 0\r\nfor elem in a:\r\n if elem == '1':\r\n if m == 0:\r\n ans +=1\r\n else:\r\n m-=1\r\n else:\r\n if k == 0:\r\n if m== 0:\r\n ans += 1\r\n else:\r\n m-=1\r\n else:\r\n k-=1\r\nprint (ans)", "[days, bowls, plates] = map(int, input().split())\nlst = list(map(int, input().split()))\n\ndish_one = lst.count(1)\ndish_two = lst.count(2)\ncount = 0\n\nbowls -= dish_one\nif bowls < 0:\n count += (bowls*-1)\nelse:\n plates += bowls\nplates -= dish_two\n\nif plates < 0:\n count += (plates*-1)\n\nprint(count)", "n,m,k=map(int,input().split())\r\nn1=n2=0\r\na=list(map(int,input().split()))\r\nfor i in a:\r\n if(i==1): n1+=1\r\n else: n2+=1\r\nif(n1>=m):\r\n n1-=m\r\n m=0\r\nelse:\r\n m-=n1\r\n n1=0\r\nn2=0 if (n2<m+k) else n2-m-k\r\nprint(n1+n2)\r\n", "n,m,k=map(int, input().split())\r\nl=list(map(int, input().split()))\r\nfor i in range(n):\r\n\tif l[i] == 1:\r\n\t\tm -= 1\r\n\telse:\r\n\t\tif k>0:\r\n\t\t\tk-=1\r\n\t\telse:\r\n\t\t\tm-=1\r\nif m<0:\r\n\tprint(abs(m))\r\nelse:\r\n\tprint(0)", "#4-A. Valera and Plates\r\n\r\nn , m , k = map(int,input().split())\r\nl = list(map(int,input().split()))\r\nans = 0\r\n\r\nfor i in l :\r\n if i == 1 :\r\n if m :\r\n m-=1\r\n else:\r\n ans+=1\r\n else:\r\n if k :\r\n k-=1\r\n elif m :\r\n m-=1\r\n else:\r\n ans +=1\r\n \r\nprint(ans)\r\n\r\n\r\n\r\n\r\n", "n,m,k=map(int,input().split())\r\na= list(map(int, input().split()))\r\nc=0\r\nfor i in a:\r\n if i==2:\r\n if k>0:k-=1\r\n elif m>0:m-=1\r\n else:c+=1\r\n elif i==1:\r\n if m>0:m-=1\r\n else:c+=1\r\nprint(c)\r\n", "n,m,k = map(int, input().split())\nl = list(map(int, input().split()))\nll = [0]*2\nfor i in l:\n ll[i - 1] += 1\nans = 0\nif ll[0] > m:\n ans += ll[0] - m\nelse:\n k += m - ll[0]\nif ll[1] > k:\n ans += ll[1] - k\nprint(ans)\n", "import sys\nn, m, k = map(int, sys.stdin.readline().split())\na = list(map(int, sys.stdin.readline().split()))\nsa = sum(a)\nnb2 = sa-n\nnb1 = n-nb2\nif nb1 >= m:\n ans = nb1-m\n if nb2 > k:\n ans += nb2-k\n print(ans)\nelif m+k >= nb1+nb2:\n print(0)\nelse:\n print(nb1+nb2-m-k)\n", "n,m,k=map(int,input().split())\r\na = list(map(int, input().split()))\r\ncount=0\r\nfor i in range(n):\r\n if a[i]==1 and m>0:\r\n m=m-1\r\n elif a[i]==2 and k>0:\r\n k=k-1\r\n elif a[i]==2 and m>0 and k<1:\r\n m=m-1\r\n else:\r\n count=count+1\r\nprint(count)\r\n \r\n", "meals, bowls, plates = map(int, input().split())\r\narray = list(map(int, input().split()))\r\n\r\ncounter = 0\r\n\r\nfor i in range(0,meals):\r\n if array[i] == 1:\r\n if bowls>0:\r\n bowls -= 1\r\n else:\r\n counter += 1\r\n else:\r\n if plates>0:\r\n plates -= 1\r\n elif bowls>0:\r\n bowls -= 1\r\n else:\r\n counter += 1\r\n\r\nprint(counter)\r\n\r\n", "n, m, k = map(int, input().split())\r\na = list(map(int, input().split()))\r\nans = 0\r\nfor i in a:\r\n if i == 1:\r\n if m == 0:\r\n ans += 1\r\n else: m -= 1\r\n else:\r\n if k == 0 and m == 0:\r\n ans += 1\r\n elif k > 0:\r\n k-= 1\r\n else:\r\n m -= 1\r\nprint(ans)\r\n", "a=list(map(int,input().split()))[1:]\r\nb=input()\r\nc=[b.count('1'),b.count('2')]\r\nd=0\r\nif c[0]>a[0]:d+=c[0]-a[0]\r\nelse:a[1]+=a[0]-c[0]\r\nif c[1]>a[1]:d+=c[1]-a[1]\r\nprint(d)\r\n", "n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\none=l.count(1)\r\ntwo=l.count(2)\r\nans=max(0,one-m)\r\nsec=max(0,two-k-max(0,m-one))\r\n\r\nprint(ans+sec)\r\n \r\n \r\n \r\n \r\n", "n,m,k=list(map(int,input().split()))\r\na=list(map(int,input().split()))\r\n\r\nres=0\r\nfor i in range(n):\r\n if a[i]==1:\r\n if m==0:\r\n res+=1\r\n else:\r\n m-=1\r\n elif a[i]==2:\r\n if k==0:\r\n if m==0:\r\n res+=1\r\n else:\r\n m-=1\r\n else:\r\n k-=1\r\nprint(res)\r\n\r\n \r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n", "#In the name of Allah\r\n\r\nfrom sys import stdin, stdout\r\ninput = stdin.readline\r\n\r\nn, m, k = map(int, input().split())\r\na = input().split()\r\n\r\nfor i in a:\r\n \r\n if i == \"1\":\r\n \r\n m -= 1\r\n \r\n else:\r\n \r\n if k == 0:\r\n \r\n m -= 1\r\n \r\n else:\r\n \r\n k -= 1\r\n\r\nstdout.write(str(abs(min(0, m) + min(0, k))))\r\n", "ar = list(map(int,input().split(' ')))\r\nn = ar[0]\r\nm = ar[1]\r\nk = ar[2]\r\narray = list(map(int,input().split(' ')))\r\nfor i in array:\r\n\tif i==1:\r\n\t\tm-=1\r\n\telse:\r\n\t\tif k > 0:\r\n\t\t\tk -= 1\r\n\t\telse:\r\n\t\t\tm -= 1\r\nres = 0\r\nres += -m if m<0 else 0\r\nres += -k if k<0 else 0\r\nprint(res)\r\n", "n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\na=l.count(1)\r\nb=l.count(2)\r\nc=0\r\nif m-a<0:\r\n\tc+=abs(m-a)\r\nif k+max((m-a),0)-b<0:\r\n\tc+=abs(k-b+max((m-a),0))\r\nprint(c)\t\t\r\n", "# -*- coding: utf-8 -*-\r\n\"\"\"\r\nCreated on Tue Mar 31 00:48:43 2020\r\n\r\n@author: alexi\r\n\"\"\"\r\n\r\n\r\n\r\n#http://codeforces.com/problemset/problem/369/A --- Alexis Galvan\r\n\r\ndef valera_plates():\r\n \r\n days = list(map(int, input().split()))\r\n dishes = list(map(int, input().split()))\r\n \r\n output = 0\r\n \r\n for i in range(len(dishes)):\r\n if days[1] == 0 and days[2] == 0:\r\n output += len(dishes)-i\r\n break\r\n \r\n if dishes[i] == 1:\r\n if days[1] > 0:\r\n days[1] -= 1\r\n else:\r\n output += 1\r\n elif dishes[i] == 2:\r\n if days[2] > 0:\r\n days[2] -= 1\r\n elif days[1] > 0:\r\n days[1] -= 1\r\n else:\r\n output += 1\r\n \r\n return output\r\n\r\n\r\nA = valera_plates()\r\nprint(A)", "def main():\n [n, bowls, plates] = [int(_) for _ in input().split()]\n types = input().split()\n n_type_1 = types.count('1')\n n_type_2 = n - n_type_1\n\n if bowls > n_type_1:\n plates += (bowls - n_type_1)\n bowls = n_type_1\n\n if plates > n_type_2:\n plates = n_type_2\n\n print(n_type_1 - bowls + n_type_2 - plates)\n\n\nif __name__ == '__main__':\n main()\n", "n, bowl, plate = map(int, input().split())\n\nl = list(map(int, input().split()))\ncount = 0\n\nfor i in l:\n\tif i == 2:\n\t\tif plate > 0:\n\t\t\tplate -= 1\n\t\telse:\n\t\t\tif bowl > 0:\n\t\t\t\tbowl -= 1\n\t\t\telse:\n\t\t\t\tcount += 1\n\telse:\n\t\tif bowl > 0:\n\t\t\tbowl -= 1\n\t\telse:\n\t\t\tcount += 1\n\n\nprint(count)\n \t\t \t\t \t \t \t\t\t \t\t\t\t \t \t \t", "n,a,b=[int(i) for i in input().split()]\r\nc=[int(i) for i in input().split()]\r\ne=0\r\nfor i in range(0,len(c)):\r\n if(c[i]==1):\r\n if(a>0):\r\n a=a-1\r\n else:\r\n e=e+1\r\n else:\r\n if(b>0):\r\n b=b-1\r\n elif(a>0):\r\n a=a-1\r\n else:\r\n e=e+1\r\nprint(e)", "n, m, k = list(map(int, input().split()))\na = input().split()\n\ncounter = 0\n\nfor i in range(n):\n if(a[i] == \"1\"):\n m -= 1\n else:\n if(k != 0):\n k -= 1\n else:\n m -= 1\n\nif(m < 0):\n washM = abs(m)\nelse:\n washM = 0\nif(k < 0):\n washK = abs(k)\nelse:\n washK = 0\n\ncounter = washM + washK\n \nprint(counter)\n\n\t\t\t \t\t \t\t \t \t \t \t\t \t\t \t", "n,b,p=map(int,input().strip().split()[:3])\r\nl=list(map(int,input().strip().split()[:n]))\r\ndish1,dish2=l.count(1),l.count(2)\r\nk1,k2=min(dish1,b),min(dish2,b+p-(min(dish1,b)))\r\nprint(n-k1-k2)", "\r\nn, m, k = map(int, input().split())\r\nfood = input().split()\r\nfor i in range(len(food)):\r\n food[i] = int(food[i])\r\nnum_wash = 0\r\nnum_m = 0 # Bowls\r\nnum_k = 0 # Dishes\r\nfor i, values in enumerate(food):\r\n # Eat food\r\n if food[i] == 1:\r\n num_m += 1\r\n elif food[i] == 2:\r\n if num_k < k:\r\n num_k += 1\r\n elif num_m < m:\r\n num_m += 1\r\n else:\r\n num_k += 1\r\n # Update washing\r\n if num_m > m:\r\n num_m -= 1\r\n num_wash += 1\r\n elif num_k > k:\r\n num_k -= 1\r\n num_wash += 1\r\nprint(num_wash)\r\n", "import sys\n\nf = sys.stdin\n#f = open(\"input.txt\", \"r\")\n\na = f.readline().strip().split()\n\nn, m, k = map(int, a)\n\na = [int(i) for i in f.readline().strip().split()]\n\nwash = 0\n\nfor i in a:\n if i == 1:\n if m < 1:\n wash += 1\n else:\n m -= 1\n elif i == 2:\n if k < 1:\n if m < 1:\n wash += 1\n else:\n m -= 1\n else:\n k -= 1\n\nprint(wash)", "n, m, k = map(int, input().split())\r\narr = list(map(int, input().split()))\r\ncnt1, cnt2 = 0, 0\r\nfor i in range(n):\r\n if arr[i] == 1:\r\n cnt1 += 1\r\n else:\r\n cnt2 += 1\r\nif cnt2 > k:\r\n print(max(0, n - m - k))\r\nelse:\r\n print(max(0, cnt1 - m))\r\n", "from sys import stdin; inp = stdin.readline\r\nfrom math import dist, ceil, floor, sqrt, log\r\ndef IA(): return list(map(int, inp().split()))\r\ndef FA(): return list(map(float, inp().split()))\r\ndef SA(): return inp().split()\r\ndef I(): return int(inp())\r\ndef F(): return float(inp())\r\ndef S(): return inp()\r\nfrom collections import Counter\r\ndef main():\r\n n,m,k = IA()\r\n a = IA()\r\n c = Counter(a)\r\n count = 0 \r\n if c[1] > m:\r\n count += c[1]-m\r\n rem = 0\r\n else:\r\n rem = m-c[1]\r\n rem += k \r\n if c[2] > rem:\r\n count += c[2]-rem \r\n return count\r\n \r\n \r\nif __name__ == '__main__':\r\n print(main())", "n, m, k = map(int, input().split())\r\nA = list(map(int, input().split()))\r\n\r\nans = 0\r\nfor a in A :\r\n if a == 1 :\r\n if m > 0 :\r\n m -= 1\r\n else :\r\n ans += 1\r\n elif a == 2 :\r\n if k > 0 :\r\n k -= 1\r\n elif m > 0 :\r\n m -= 1\r\n else :\r\n ans += 1\r\n\r\nprint(ans)\r\n", "n,m,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nn1 = a.count(1)\r\nn2 = a.count(2)\r\ns = 0\r\nif n1 > m:\r\n s = n1-m\r\n m = 0\r\nelse:\r\n m -= n1\r\nif n2>m+k:\r\n s += n2-m-k\r\nprint(s)\r\n", "n, m, k = map(int, input().split())\na = [int(e) for e in input().split()]\nans = 0\nfor i in a:\n\tif i == 2 and k > 0:\n\t\tk -= 1\n\telif m > 0:\n\t\tm -= 1\n\telse:\n\t\tans += 1\nprint(ans)\n", "from collections import Counter\r\ndays,bowl,plate = map(int,input().split(\" \"))\r\narr = list(map(int,input().split(\" \")))\r\ncounts = Counter(arr)\r\nclean = 0\r\nrecipe1 = counts[1]\r\nrecipe2 = counts[2]\r\n\r\nif recipe1>bowl:\r\n clean+=recipe1-bowl\r\n bowl = 0\r\nelse:\r\n bowl = bowl-recipe1\r\n\r\nif recipe2>bowl+plate:\r\n clean+=recipe2-(bowl+plate)\r\n\r\nprint(clean)", "# coding: utf-8\nn, m, k = [int(i) for i in input().split()]\ncnt = 0\nfor i in input().split():\n if i == '1':\n if m > 0:\n m -= 1\n else:\n cnt += 1\n else:\n if k > 0:\n k -= 1\n elif m > 0:\n m -= 1\n else:\n cnt += 1\nprint(cnt)\n", "\r\nn, clean_b, clean_d = list(map(int, input().split()))\r\n\r\narr = sorted(list(map(int, input().split())), reverse=True)\r\n\r\nwork = 0\r\n\r\nfor item in arr:\r\n\r\n if item == 2:\r\n if clean_d:\r\n clean_d -= 1\r\n elif clean_b:\r\n clean_b -= 1\r\n else:\r\n work += 1\r\n\r\n else:\r\n if clean_b:\r\n clean_b -= 1\r\n else:\r\n work += 1\r\n\r\n\r\nprint(work)", "I=lambda:map(int,input().split())\r\nn,m,k=I()\r\nr=0\r\nfor x in I():\r\n if x==1:m-=1;r+=m<0\r\n else:k-=1;m-=(k<0);r+=k<0>m\r\nprint(r)", "n, b, p = tuple((map(int,input().split())))\r\nA = list(map(int,input().split()))\r\nd1 = A.count(1)\r\nd2 = A.count(2)\r\nd2 = max(0, d2-p)\r\nb-=(d1+d2)\r\nprint(abs(min(b, 0)))", "n,m,k = map(int,input().split())\r\na = list(map(int,input().split()))\r\nwsh = 0\r\n# print(a)\r\nfor i in a:\r\n if i==1:\r\n m-=1\r\n if m<0:\r\n wsh+=1\r\n else:\r\n if k>0:\r\n k-=1\r\n elif m>0:\r\n m-=1\r\n else:\r\n wsh+=1\r\nprint(wsh)", "n,m,k=map(int,input().split())\na=list(map(int,input().split()))\ntype1=0\ntype2=0\nfor i in range (n):\n if(a[i]==1):\n type1+=1\n else:\n type2+=1\nmini=0\nm-=type1\nif(m<0):\n k-=type2\n if(k<0):\n mini=mini+abs(m)+abs(k)\n else:\n mini=mini+abs(m)\nelse:\n total=m+k\n total-=type2\n if (total<0):\n mini+=abs(total)\nprint(mini)\n \n \t\t\t\t\t\t \t\t\t \t \t \t\t\t \t", "\r\ninp = list(map(int, input().split()))\r\nnumofdays = inp[0]\r\nnumofdeeplates = inp[1]\r\nnumofplates = inp[2]\r\n\r\ninp2 = list(map(int, input().split()))\r\n\r\nnumofcleans = 0\r\n\r\nfor i in range(0, numofdays):\r\n\tif inp2[i] == 1:\r\n\t\tif numofdeeplates > 0:\r\n\t\t\tnumofdeeplates -= 1\r\n\t\telse:\r\n\t\t\tnumofcleans += 1\r\n\telse: \r\n\t\tif numofplates > 0:\r\n\t\t\tnumofplates -= 1\r\n\t\telse: \r\n\t\t\tif numofdeeplates > 0:\r\n\t\t\t\tnumofdeeplates -= 1\r\n\t\t\telse:\r\n\t\t\t\tnumofcleans += 1\r\n\t\t\t\t\r\nprint(numofcleans)\r\n\t\r\n\r\n", "n,b,p=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nc=l.count(1)\r\nd=n-c\r\nprint([[c-b+d-p,max(0,d-p-(b-c))][b>=c],max(0,c-b)][p>=d])\r\n", "n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nx,y=l.count(1),l.count(2)\r\ns=0\r\nif(x>m):\r\n s=x-m\r\n if(y>k):\r\n s=s+(y-k)\r\nelse:\r\n l=m-x\r\n if(y>(l+k)):\r\n s=s+(y-(l+k))\r\n else:\r\n s=0\r\nprint(s)\r\n", "n, a, b = map(int, input().split())\nk = input()[::2].count('1')\nprint(max(0, k-a)+max(0, n-k-b-max(a-k, 0)))\n", "n, m, k = map(int, input().split())\r\n*a, = map(int, input().split())\r\nk -= a.count(2)\r\nm -= a.count(1)\r\nif m > 0:\r\n k += m\r\n m = 0\r\nelse:\r\n m = -m\r\nif k > 0:\r\n k = 0\r\nelse:\r\n k = -k\r\nprint(abs(k) + abs(m))\r\n", "# -*- coding: utf-8 -*-\r\n\r\nn, m, k = map(int, input().split())\r\na = list(input().split())\r\nt1, t2 = a.count('1'), a.count('2')\r\n\r\nans = 0\r\nif t1 > m:\r\n ans += t1-m\r\n if t2 > k:\r\n ans += t2-k\r\nelif t2 > k + (m-t1):\r\n ans += t2 - k - (m-t1)\r\n \r\nprint(ans)", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\nc=0\r\nfor i in range(0,n):\r\n if a[i]==1:\r\n if m>0:\r\n m=m-1\r\n else:\r\n c=c+1\r\n else:\r\n if k>0:\r\n k=k-1\r\n elif m>0:\r\n m=m-1\r\n else:\r\n c=c+1\r\nprint(c)\r\n ", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\ns=0\r\nfor i in range(n):\r\n\tif m<1 and k<1:\r\n\t\ts+=1\r\n\telif a[i]==1:\r\n\t\tif m<1:\r\n\t\t\ts+=1\r\n\t\telse:\t\r\n\t\t\tm-=1\r\n\telse:\r\n\t\tif k>0:\r\n\t\t\tk-=1\r\n\t\telif m>0:\r\n\t\t\tm-=1\r\n\t\telse:\r\n\t\t\ts+=1\t\t\t\r\nprint(s)", "number, plates_1, plates_2 = (int(i) for i in input().split())\r\ndishes = tuple(input().split())\r\ntotal = 0\r\n\r\nfor i in dishes:\r\n if i == '1':\r\n if plates_1 > 0:\r\n plates_1 -= 1\r\n else:\r\n total += 1\r\n else:\r\n if plates_2 > 0:\r\n plates_2 -= 1\r\n elif plates_1 > 0:\r\n plates_1 -= 1\r\n else:\r\n total += 1\r\n\r\nprint(total)", "n, m, k = [int(x) for x in input().split(' ')]\r\n\r\ndish = [int(x) for x in input().split(' ')]\r\n\r\nans = 0\r\n\r\nfor i in dish:\r\n if i == 1:\r\n if m!= 0:\r\n m = m-1\r\n else:\r\n ans = ans +1\r\n else:\r\n if k!=0:\r\n k = k -1\r\n continue\r\n if m!=0:\r\n m = m-1\r\n continue\r\n else:\r\n ans = ans+1\r\n\r\n\r\nprint(ans)\r\n\r\n", "firstLine = [int(n) for n in input().split()];\r\nsecondLine = [int(n) for n in input().split()];\r\n\r\nbowls = firstLine[1];\r\nplates = firstLine[2];\r\n\r\nliquid = 0;\r\nsolid = 0;\r\n\r\nfor i in secondLine:\r\n if(i==1):\r\n liquid += 1;\r\n else:\r\n solid += 1;\r\n \r\ntotal = 0;\r\n\r\n\r\ntotal += max(liquid-bowls, 0);\r\nbowls = max(bowls-liquid, 0);\r\ntotal += max((solid-bowls)-plates, 0);\r\n\r\nprint(total);", "l1 = [int(x) for x in input().split()]\r\nl2 = [int(x) for x in input().split()]\r\nbowls = l1[1]\r\nplates = l1[2]\r\nfirst = l2.count(1)\r\nsecond = l2.count(2)\r\nbfirst = max(0,first-bowls)\r\nbowls = max(0,bowls-first)\r\nbsecond = max(0,second-plates-bowls)\r\nprint(bfirst+bsecond)\r\n", "# LUOGU_RID: 101541410\nn, m, k, *a = map(int, open(0).read().split())\r\nprint(max(0, n - a.count(2) - min(0, k - a.count(2)) - m))\r\n", "n,m,k=map(int,input().split())\r\narr=list(map(int,input().split()))\r\nans=0\r\nfor el in arr:\r\n if el==1:\r\n if m==0:\r\n ans+=1\r\n else :\r\n m-=1\r\n else :\r\n if k:\r\n k-=1\r\n else :\r\n if m:\r\n m-=1\r\n else :\r\n ans+=1\r\nprint(ans)", "from collections import Counter\n\nn, m, k = (int(i) for i in input().split())\na = (int(i) for i in input().split())\ncnt = Counter(a)\nm -= cnt[1]\nk -= cnt[2]\nk += max(0, m)\nres = max(-m, 0) + max(-k, 0)\nprint(res)\n", "def solve():\r\n days,bowl,plate=map(int,input().split());a=list(map(int,input().split()));ones=a.count(1);two=a.count(2);c=0\r\n bowl-=ones;\r\n if bowl<0:c+=abs(bowl);bowl=0\r\n plate+=bowl;\r\n plate-=two\r\n if plate<0:c+=abs(plate)\r\n print(c)\r\nsolve()\r\n ", "n,m,k=map(int,input().split())\r\nl=list(map(int,input().split()))\r\nc=0\r\nfor i in l:\r\n if(i==1):\r\n if(m>0):\r\n m-=1\r\n else:\r\n c+=1\r\n else:\r\n if(k>0):\r\n k-=1\r\n else:\r\n if(m>0):\r\n m-=1\r\n else:\r\n c+=1\r\nprint(c)", "def main():\r\n [_, b, p] = list(map(int, input().split()))\r\n ds = list(map(int, input().split()))\r\n\r\n sol = 0\r\n for d in ds:\r\n if d == 2:\r\n if p != 0:\r\n p -= 1\r\n elif b != 0:\r\n b -= 1\r\n else:\r\n sol += 1\r\n else:\r\n if b != 0:\r\n b -= 1\r\n else:\r\n sol += 1\r\n\r\n print(sol)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n", "# cook your dish here\r\nn,m,k=map(int,input().split(\" \"))\r\na = [int(i) for i in input().split()]\r\nx=a.count(1)\r\ny=a.count(2)\r\np=x-m\r\nr=0\r\nif p>0:\r\n q=y-k\r\n if q >0:\r\n r=p+q\r\n else:\r\n r=p\r\nelse:\r\n p=abs(p)\r\n k=k+p\r\n if y-k > 0:\r\n r=y-k\r\nprint(r)", "n,m,k=map(int,input().split())\r\na=list(map(int,input().split()))\r\no=0\r\nfor x in range(n):\r\n if a[x]==1:\r\n if m>0:\r\n m-=1\r\n else:\r\n o+=1\r\n else:\r\n if k==0 and m==0:\r\n o+=1\r\n elif k>0:\r\n k-=1\r\n else:\r\n m-=1\r\nprint(o)\r\n", "n, m, k = list(map(int, input().split()))\r\nar = list(map(int, input().split()))\r\n\r\ntwos_counts = ar.count(2)\r\nones_counts = ar.count(1)\r\n\r\ntwos_counts = max(0, twos_counts-k)\r\ntotal = twos_counts + ones_counts\r\nprint(max(0, total - m))", "n, m, k = map(int, input().split())\r\nl = [i for i in input().split()]\r\n\r\nm = res = m-l.count('1')\r\nif m > 0:\r\n res2 = k+m - l.count('2')\r\n if res2<0:\r\n print(abs(res2))\r\n else:\r\n print(0)\r\nelse:\r\n res2 = k-l.count('2')\r\n if res2 < 0:\r\n print(abs(res2+res))\r\n else:\r\n print(abs(res))\r\n", "# m=clean bowls k=clean plates\r\n#1-bowl\r\n#2-either\r\nI = lambda:map(int,input().split())\r\nn,m,k = I()\r\nl=list(I())\r\nc=0\r\nfor i in l:\r\n if(i==1):\r\n if(m>0):\r\n m-=1\r\n else:\r\n c+=1\r\n elif(i==2):\r\n if(k>0):\r\n k-=1\r\n elif(m>0):\r\n m-=1\r\n else:\r\n c+=1\r\nprint(c)\r\n", "def main():\r\n v = input().split()\r\n n = int(v[0])\r\n m = int(v[1])\r\n k = int(v[2])\r\n ans = 0\r\n v = input().split()\r\n for i in range(n):\r\n if int(v[i]) == 1:\r\n if m == 0:\r\n ans += 1\r\n else:\r\n m -= 1\r\n if int(v[i]) == 2:\r\n if k != 0:\r\n k -= 1\r\n continue\r\n if m != 0:\r\n m -= 1\r\n continue\r\n ans += 1\r\n print(ans)\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()", "n, m, k = map(int, input().split())\r\ninp = input()\r\nk -= inp.count(\"2\")\r\nm -= inp.count(\"1\") + max(0, -k)\r\nprint(max(0, -m))", "days, bowls, plates = map(int, input().split())\ndishes = list(map(int, input().split()))\n\nwash = 0\nfor i in range(days):\n dish = dishes[i]\n if dish == 2:\n if plates > 0:\n plates -= 1\n elif bowls > 0:\n bowls -= 1\n else:\n wash += 1\n elif dish == 1:\n if bowls > 0:\n bowls -= 1\n else:\n wash += 1\n\nprint(wash)\n \t \t \t\t \t \t\t \t \t\t\t\t \t", "n,bowls,plates = map(int,input().split(\" \"))\r\nl = list(map(int,input().split(\" \")))\r\ncount = 0\r\nfor i in l:\r\n if(i==1):\r\n if(bowls!=0):\r\n bowls-=1\r\n else:\r\n count+=1\r\n else:\r\n if(bowls!=0 or plates!=0):\r\n if(plates!=0):\r\n plates-=1\r\n else:\r\n bowls-=1\r\n else:\r\n count+=1\r\n\r\nprint(count)", "days , bowls , plates = map(int,input().split())\nwash=0\n\nfor i in list(map(int,input().split())):\n if i == 1 : \n if bowls > 0 :\n bowls-=1\n else:\n wash+=1\n elif i == 2 : \n if plates > 0 :\n plates -= 1\n else:\n if bowls > 0 :\n bowls-=1\n else:\n wash+=1\n \nprint(wash)\n", "n,m,k=list(map(int,input().split()))\r\nl=list(map(int,input().split()))\r\nt=0\r\nfor i in l:\r\n if i==1:\r\n if m>0:\r\n m=m-1\r\n else:\r\n t +=1\r\n elif i==2:\r\n if k>0:\r\n k=k-1\r\n elif m>0:\r\n m=m-1\r\n else:\r\n t +=1\r\nelse:\r\n print(t)\r\n \r\n" ]
{"inputs": ["3 1 1\n1 2 1", "4 3 1\n1 1 1 1", "3 1 2\n2 2 2", "8 2 2\n1 2 1 2 1 2 1 2", "2 100 100\n2 2", "1 1 1\n2", "233 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 1 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2", "123 100 1\n2 2 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 2 1 1 1 1 1 1 1 1 1 2 2 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 1 1 1", "188 100 1\n2 2 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 1 1 2 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 1 2 1 2 2 2 1 1 1 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 1 2 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 1 2 2 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 1", "3 1 2\n1 1 1", "3 2 2\n1 1 1", "3 2 1\n1 1 1", "3 1 1\n1 1 1", "5 1 2\n2 2 2 2 2", "5 2 2\n2 2 2 2 2", "5 2 1\n2 2 2 2 2", "5 1 1\n2 2 2 2 2", "1 1 2\n2", "1 2 2\n2", "1 2 1\n2", "1 1 1\n2", "6 3 1\n1 1 2 2 2 2", "100 40 20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "7 5 2\n2 2 1 1 1 1 1", "10 4 4\n2 2 2 2 2 2 1 1 1 1", "3 2 1\n2 1 1", "7 6 1\n2 1 1 1 1 1 1", "7 5 1\n1 1 1 2 2 2 2", "5 3 1\n1 1 2 2 2", "3 1 1\n2 2 2", "5 2 2\n2 2 2 2 2", "3 1 3\n1 1 1", "5 2 1\n1 1 2 2 2", "4 3 2\n2 1 1 1", "4 2 1\n1 2 2 2", "14 4 7\n1 1 1 2 2 2 2 2 2 2 2 2 2 2", "12 10 4\n2 2 2 2 2 2 1 1 1 1 1 1", "5 3 2\n2 2 1 1 1"], "outputs": ["1", "1", "0", "4", "0", "0", "132", "22", "87", "2", "1", "1", "2", "2", "1", "2", "3", "0", "0", "0", "0", "2", "40", "0", "2", "0", "0", "1", "1", "1", "1", "2", "2", "0", "1", "3", "0", "0"]}
UNKNOWN
PYTHON3
CODEFORCES
223
21c80b84de37c0a6a459ebd411c862bc
Maxim and Discounts
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are *m* types of discounts. We assume that the discounts are indexed from 1 to *m*. To use the discount number *i*, the customer takes a special basket, where he puts exactly *q**i* items he buys. Under the terms of the discount system, in addition to the items in the cart the customer can receive at most two items from the supermarket for free. The number of the "free items" (0, 1 or 2) to give is selected by the customer. The only condition imposed on the selected "free items" is as follows: each of them mustn't be more expensive than the cheapest item out of the *q**i* items in the cart. Maxim now needs to buy *n* items in the shop. Count the minimum sum of money that Maxim needs to buy them, if he use the discount system optimally well. Please assume that the supermarket has enough carts for any actions. Maxim can use the same discount multiple times. Of course, Maxim can buy items without any discounts. The first line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of discount types. The second line contains *m* integers: *q*1,<=*q*2,<=...,<=*q**m* (1<=≤<=*q**i*<=≤<=105). The third line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of items Maxim needs. The fourth line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — the items' prices. The numbers in the lines are separated by single spaces. In a single line print a single integer — the answer to the problem. Sample Input 1 2 4 50 50 100 100 2 2 3 5 50 50 50 50 50 1 1 7 1 1 1 1 1 1 1 Sample Output 200 150 3
[ "from sys import stdin,stdout\r\nnmbr = lambda: int(stdin.readline())\r\nlst = lambda: list(map(int,stdin.readline().split()))\r\nfor _ in range(1):#nmbr()):\r\n n=nmbr()\r\n a=sorted(lst())\r\n d=a[0]\r\n n=nmbr()\r\n a=sorted(lst())\r\n ans=0\r\n p=n-1;buy=d\r\n while p>=0:\r\n if d==0:\r\n d=buy\r\n p-=2\r\n continue\r\n ans+=a[p]\r\n d-=1\r\n p-=1\r\n print(ans)\r\n", "def arr_inp():\r\n return [int(x) for x in input().split()]\r\n\r\n\r\nm, q, n, a = int(input()), sorted(arr_inp()), int(input()), sorted(arr_inp(), reverse=True)\r\nans = 0\r\nif q[0] >= n:\r\n print(sum(a))\r\nelse:\r\n ix = 0\r\n while (ix < n):\r\n if ix + q[0] < n:\r\n ans += sum(a[ix:ix + q[0]])\r\n ix += q[0]\r\n else:\r\n ans += sum(a[ix:])\r\n ix = n\r\n ix += min(n - ix, 2)\r\n # print(ix, ans)\r\n print(ans)\r\n", "import sys\r\ninput = sys.stdin.readline\r\nm=int(input())\r\nq=list(map(int,input().split()))\r\n\r\nn=int(input())\r\na=list(map(int,input().split()))\r\na.sort(reverse=True)\r\nmon=0\r\ni=min(q)\r\n#print(i)\r\nwhile a:\r\n d=a[:i]\r\n # print(d)\r\n # print(a[:i+2])\r\n del a[:i+2]\r\n mon+=sum(d)\r\n\r\n\r\n \r\n\r\nsys.stdout.write(str(mon))\r\n", "def fastio():\r\n\timport sys\r\n\tfrom io import StringIO \r\n\tfrom atexit import register\r\n\tglobal input\r\n\tsys.stdin = StringIO(sys.stdin.read())\r\n\tinput = lambda : sys.stdin.readline().rstrip('\\r\\n')\r\n\tsys.stdout = StringIO()\r\n\tregister(lambda : sys.__stdout__.write(sys.stdout.getvalue()))\r\n# fastio()\r\n\r\nMOD = 10**9 + 7\r\nI = lambda:list(map(int,input().split()))\r\n\r\nm, = I()\r\nd = I()\r\nn, = I()\r\nl = I()\r\nl.sort()\r\nk = min(d)\r\nans = 0\r\ni = n-1\r\nwhile i >= 0:\r\n\tc = 0\r\n\twhile c < k and i >= 0:\r\n\t\tans += l[i]\r\n\t\tc += 1\r\n\t\ti -= 1\r\n\ti -= 2\r\nprint(ans)\r\n", "from collections import defaultdict, Counter, deque\nfrom math import inf\nfrom functools import lru_cache\nfrom heapq import heappop, heappush\n \nimport sys\n#input=sys.stdin.readline\n\ndef solution(): \n # use the minimam one you will be \n m = int(input())\n ln = min(map(int, input().split()))\n\n n = int(input())\n arr = list(map(int, input().split()))\n \n arr.sort()\n res = 0\n while arr:\n for _ in range(ln):\n if arr: \n res += arr.pop()\n for _ in range(2):\n if arr: arr.pop()\n \n return print(res)\n\ndef main():\n t = 1\n #t = int(input())\n for _ in range(t):\n solution()\n \n \nimport sys\nimport threading\nsys.setrecursionlimit(10**6)\nthreading.stack_size(1 << 27)\nthread = threading.Thread(target=main)\nthread.start(); thread.join()\n#main()\n", "m = int(input())\r\nq = list(map(int, input().split()))\r\n\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\nmn = min(q)\r\na.sort(reverse = True)\r\nans, p = 0, 0\r\nwhile 1:\r\n for i in range(p, min(p + mn, n)): ans += a[i]\r\n p += mn + 2\r\n if p >= n: break\r\nprint(ans)", "m = int(input())\nq = list(map(int, input().split()))\nn = int(input())\nl = sorted(list(map(int, input().split())))\n\ncost, mini = 0, min(q) #Buy less Items every time\n\nwhile len(l)!=0:\n\tfor i in range(min(len(l), mini)): cost+=l.pop() #Buy Items high priced items so we can buy the items that are <= min(itemsBought)\n\tfor i in range(min(len(l), 2)): l.pop() # get Items in discount/Free that are highPriced\n\nprint(cost)\n\t\n \t \t\t \t \t \t\t \t \t \t\t \t\t\t", "m = int(input())\r\nq = list(map(int,input().split()))\r\n\r\nn = int(input())\r\na = list(map(int,input().split()))\r\nq = sorted(q)\r\na = sorted(a,reverse = True)\r\ncount = 0\r\ni = 0\r\ncost = 0 \r\nwhile i<n:\r\n if count==q[0]:\r\n i+=2\r\n count = 0 \r\n else:\r\n count+=1\r\n cost+=a[i]\r\n i+=1\r\nprint(cost)", "m=int(input())\r\nq=list(map(int,input().split()))\r\nn=int(input())\r\na=sorted(list(map(int,input().split())),reverse=True)\r\nskid,i,ans=min(q),0,0\r\nwhile True:\r\n for j in range(i,min(i+skid,n)): ans+=a[j]\r\n i+=skid+2\r\n if i>=n:break\r\nprint(ans)\r\n \r\n \r\n", "class CodeforcesTask261ASolution:\r\n def __init__(self):\r\n self.result = ''\r\n self.discounts = []\r\n self.items_count = 0\r\n self.prices = []\r\n\r\n def read_input(self):\r\n input()\r\n self.discounts = [int(x) for x in input().split(\" \")]\r\n self.items_count = int(input())\r\n self.prices = [int(x) for x in input().split(\" \")]\r\n\r\n def process_task(self):\r\n self.discounts.sort()\r\n self.prices.sort(reverse=True)\r\n price = 0\r\n discount = self.discounts[0]\r\n for x in range(self.items_count):\r\n if x % (discount + 2) < discount:\r\n price += self.prices[x]\r\n self.result = str(price)\r\n\r\n def get_result(self):\r\n return self.result\r\n\r\n\r\nif __name__ == \"__main__\":\r\n Solution = CodeforcesTask261ASolution()\r\n Solution.read_input()\r\n Solution.process_task()\r\n print(Solution.get_result())\r\n", "a=int(input())\r\nq=list(map(int,input().split()))\r\nn=int(input())\r\ncost=list(map(int,input().split()))\r\nt=min(q)\r\ncost.sort()\r\ntotal=0\r\nindex=len(cost)-1\r\nwhile(index>=0):\r\n r=t\r\n if(index>=t):\r\n r=t\r\n while(r):\r\n total+=cost[index]\r\n r-=1\r\n index-=1\r\n if(index>=2):\r\n index-=2\r\n else:\r\n break;\r\n else:\r\n total+=sum(cost[0:index+1])\r\n break;\r\nprint(total)\r\n \r\n", "input()\n\nk = min(map(int, input().split()))\n\nn = int(input())\n\np = sorted(map(int, input().split()), reverse = True) + [0] * k\n\nprint(sum(sum(p[i: i + k]) for i in range(0, n, k + 2)))", "rd = lambda: list(map(int, input().split()))\n \ninput()\nz = min(rd())\ninput()\na = sorted(rd(), reverse=True)\nprint(sum(v for i, v in enumerate(a) if i%(z+2)<z))\n \t\t \t\t \t \t\t \t\t\t \t \t\t\t\t \t", "import sys\r\nimport math\r\nimport collections\r\nimport heapq\r\nimport decimal\r\ninput=sys.stdin.readline\r\nm=int(input())\r\ndi=sorted([int(i) for i in input().split()])\r\nd=di[0]\r\nn=int(input())\r\nl=sorted([int(i) for i in input().split()])\r\nc=0\r\ni=n-1\r\nc1=0\r\nwhile(i>-1):\r\n if(c1==d):\r\n i-=2\r\n c1=0\r\n else:\r\n c1+=1\r\n c+=l[i]\r\n i-=1\r\nprint(c)", "m = int(input())\r\nq = [int(i) for i in input().split()]\r\n\r\nn = int(input())\r\na = [int(i) for i in input().split()]\r\nc = min(q)\r\na.sort()\r\n\r\nprice = 0\r\nfor i in range(n):\r\n if i % (c+2) < c:\r\n price += a[n-1-i]\r\n \r\nprint(price)", "import sys\r\n\r\n\r\n# sys.stdin = open('input.txt', 'r')\r\n# sys.stdout = open('output.txt', 'w')\r\n\r\ninput = sys.stdin.readline\r\n\r\nm = int(input())\r\nq = list(map(int, input().split()))\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\ndiscount = min(q)\r\na.sort(reverse=True)\r\n\r\nans = 0\r\nfor i in range(0, n, discount+2):\r\n ans += sum([a[i] for i in range(i, min(i+discount, n))])\r\n\r\nprint(ans)", "m = int(input())\r\nq = list(map(int, input().split()))\r\nc = min(q)\r\n \r\nn = int(input())\r\na = list(map(int, input().split()))\r\na.sort()\r\n \r\nres = 0\r\nfor i in range(n):\r\n if i % (c+2) < c:\r\n res += a[n-1-i]\r\nprint(res)", "import sys\r\ninput = sys.stdin.readline\r\nfor _ in range(1):\r\n n=int(input())\r\n temp=[int(x) for x in input().split()]\r\n m=int(input())\r\n arr=[int(x) for x in input().split()]\r\n now=min(temp)\r\n i=m-1\r\n ans=0\r\n arr.sort()\r\n while i>=0:\r\n curr=0\r\n while i>=0 and curr<now:\r\n ans+=arr[i]\r\n #print(i)\r\n curr+=1\r\n i-=1\r\n i-=2\r\n print(ans)", "# 261A\r\n\r\nfrom sys import stdin\r\n\r\n__author__ = 'artyom'\r\n\r\n\r\ndef read_int():\r\n return int(stdin.readline().strip())\r\n\r\n\r\ndef read_int_ary():\r\n return map(int, stdin.readline().strip().split())\r\n\r\n\r\nm = read_int()\r\nd = sorted(read_int_ary())[0]\r\nn = read_int()\r\na = list(reversed(sorted(read_int_ary())))\r\n\r\nres = i = 0\r\nwhile i < n:\r\n next = i + d\r\n res += sum(a[i:min(next, n)])\r\n i = next + 2\r\n\r\nprint(res)", "m = int(input())\r\nq = list(map(int, input().split()))\r\nn = int(input())\r\nl = sorted(list(map(int, input().split())))\r\n\r\ncost, mini = 0, min(q)\r\n\r\nwhile len(l)!=0:\r\n\tfor i in range(min(len(l), mini)): cost+=l.pop() #Buy Items\r\n\tfor i in range(min(len(l), 2)): l.pop() # get Items in discount\r\n\r\nprint(cost)\r\n\t", "import sys, math\r\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\r\n\r\nm = int(input())\r\ndiscount = get_ints()\r\ndiscount = sorted(discount)\r\nn = int(input())\r\nprices = get_ints()\r\nprices = sorted(prices)\r\nprices = prices[::-1]\r\nindex = 0 \r\ntotalprice = 0 \r\nflag = 0 \r\nans = 0 \r\nwhile True:\r\n dis = discount[0]\r\n if index >= n :\r\n flag = 1\r\n break\r\n for i in range(dis):\r\n if index >= n :\r\n flag = 1\r\n break\r\n ans += prices[index]\r\n index += 1 \r\n if flag == 1 :\r\n break \r\n \r\n index += 2 \r\n if flag == 1:\r\n break \r\n#print(index)\r\nif flag == 1:\r\n print(ans)\r\nelse:\r\n for i in range(index, n):\r\n ans += prices[index]\r\n print(ans)\r\n \r\n", "m = int(input())\r\ndis = list(map(int, input().split()))\r\nn = int(input())\r\np = list(map(int, input().split()))\r\np.sort(reverse=True)\r\ndis.sort()\r\nmoney = sum(p)\r\nmind = dis[0]\r\nif n <= mind:\r\n print(sum(p))\r\nelse:\r\n i = mind - 1\r\n while i < n:\r\n if i + 1 < n:\r\n money -= p[i + 1]\r\n if i + 2 < n:\r\n money -= p[i + 2]\r\n i += mind + 2\r\n print(money)\r\n", "def main():\n input()\n q = min(map(int, input().split()))\n input()\n aa = sorted(map(int, input().split()), reverse=True)\n print(sum(aa) - sum(aa[q::q + 2]) - sum(aa[q + 1::q + 2]))\n\n\nif __name__ == \"__main__\":\n main()\n", "import sys\r\ninput = sys.stdin.readline\r\n\r\nm = int(input())\r\nq = sorted(map(int, input().split()))\r\nn = int(input())\r\na = sorted(map(int, input().split()), reverse=True)\r\n\r\nx = q[0]\r\nc = 0\r\ni = 0\r\nwhile i < n:\r\n if x + 2 < n:\r\n c += sum(a[i:i+x])\r\n i += x + 2\r\n else:\r\n c += sum(a[i:i+x])\r\n break\r\nprint(c)", "if __name__ == '__main__':\r\n\tm = int(input())\r\n\tcarts = [int(x) for x in input().split()]\r\n\tn = int(input())\r\n\tcost = [int(x) for x in input().split()]\r\n\r\n\tx = min(carts)\r\n\tbought = 0\r\n\tfree = 0\r\n\tcost = sorted(cost, reverse = True)\r\n\tamt = 0\r\n\r\n\tfor i in cost:\r\n\t\tif free > 0:\r\n\t\t\tfree -= 1\r\n\t\t\tcontinue\r\n\t\t\r\n\t\tamt += i\r\n\t\tbought += 1\r\n\r\n\t\tif bought == x:\r\n\t\t\tbought = 0\r\n\t\t\tfree = 2\r\n\r\n\tprint(amt)", "m = int(input())\r\nq = list(map(int, input().split()))\r\nn = int(input())\r\na = list(map(int, input().split()))\r\n\r\na.sort(reverse=True)\r\nq.sort()\r\n\r\nans = 0\r\nmm = q[0]\r\n\r\ni = 0\r\nwhile i<n:\r\n j = i\r\n if j+mm <= n:\r\n while i < j+mm:\r\n ans+=a[i]\r\n i+=1\r\n i+=1\r\n else:\r\n break\r\n i+=1\r\nif i <n:\r\n ans += sum(a[i:])\r\nprint(ans)\r\n \r\n", "input()\nd=[int(i) for i in input().split()]\nc=int(input())\nb=[int(i) for i in input().split()]\nb.sort()\n#d.sort()\ntake=1\np=min(d)\ns=0\nbuy=p\nfor i in reversed(b):\n if buy:\n s+=i\n buy-=1\n else:\n if take:\n take-=1\n else:\n buy=p\n take=1\n\nprint(s)\n\n\t \t \t\t\t\t \t\t\t \t \t \t \t \t\t \t", "m=int(input())\r\nq=list(map(int,input().split()))\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nsk=min(q)\r\na.sort()\r\nj=1\r\nans=0\r\nfor i in range(n-1,-1,-1):\r\n l=sk-j\r\n if l==-1:\r\n pass\r\n elif l==-2:\r\n j=0\r\n else:\r\n ans+=a[i]\r\n j+=1\r\nprint(ans)\r\n \r\n\r\n", "a=input()\nb=sorted([int(i) for i in input().split()])[0]\nc=int(input())\nd=sorted([int(i) for i in input().split()])\np=0\nwhile len(d):\n\tfor i in range(0, min(len(d), b)):\n\t\tp+=d.pop()\n\tfor i in range(0, min(len(d), 2)):\n\t\ta=d.pop()\nprint(p)\n \t \t\t \t \t \t\t\t \t \t\t \t \t \t \t", "m=int(input())\r\nq=[int(i) for i in input().split()]\r\nq.sort()\r\nn=int(input())\r\na=[int(i) for i in input().split()]\r\na.sort()\r\nans=0\r\ni=n-1\r\nwhile(i>=0):\r\n d=0\r\n while(i>=0 and d<q[0]):\r\n ans+=a[i]\r\n i-=1\r\n d+=1\r\n d=0\r\n while(i>=0 and d<2):\r\n d+=1\r\n i-=1\r\nprint(ans)", "I=lambda:map(int,input().split())\r\nm,q,n,a,r,k=int(input()),min(I()),int(input())-1,sorted(I()),0,0\r\nwhile n>-1:\r\n r+=a[n]\r\n k+=1\r\n if k==q:n-=3;k=0\r\n else:n-=1\r\nprint(r)", "m=int(input())\r\nlstm = list(map(int, input().strip().split(' ')))\r\nn=int(input())\r\nlstn = list(map(int, input().strip().split(' ')))\r\nm1=min(lstm)\r\nlstn.sort(reverse=True)\r\ni=0\r\ns=0\r\nwhile(i<n):\r\n if i+m1<=n:\r\n s+=sum(lstn[i:i+m1])\r\n i+=m1\r\n if i+2<=n:\r\n i+=2\r\n elif i+1<=n:\r\n i+=1\r\n else:\r\n s+=sum(lstn[i:n])\r\n i=n\r\nprint(s)", "m, mSale = int(input()), list(map(int,input().split()))\r\nn, nPrice = int(input()), list(map(int,input().split()))\r\nnPrice.sort()\r\nsum, small = 0, min(mSale)\r\n\r\nwhile True:\r\n if len(nPrice) <= small:\r\n for k in nPrice: sum+=k\r\n print(sum)\r\n exit()\r\n else:\r\n for i in range(small): sum+=nPrice.pop()\r\n if len(nPrice) <= 2:\r\n print(sum)\r\n exit()\r\n else:\r\n for i in range(2): nPrice.pop()", "nq=int(input())\r\nq=[int(x) for x in input().split()]\r\nn=int(input())\r\na=[int(x) for x in input().split()]\r\na.sort(reverse=True)\r\nm=min(q)\r\ni=0\r\nans=0\r\nx=0\r\nwhile i<n:\r\n if x==m:\r\n x=0\r\n i+=2\r\n continue\r\n x+=1 \r\n ans+=a[i]\r\n i+=1\r\nprint(ans)\r\n", "# _\r\n#####################################################################################################################\r\n\r\ndef main():\r\n nDiscounts, bestDiscount = input(), min(map(int, input().split()))\r\n nItems, prices = input(), list(map(int, input().split()))\r\n prices.sort(reverse=True)\r\n\r\n return supermarketSpending(bestDiscount, prices)\r\n\r\n\r\ndef supermarketSpending(bestDiscount, prices):\r\n if bestDiscount >= len(prices) - 2:\r\n return sum(prices[:bestDiscount])\r\n\r\n step = bestDiscount + 2\r\n return sum(sum(prices[start:end])\r\n for start, end in\r\n zip(range(0, len(prices), step), range(bestDiscount, len(prices)*2, step)))\r\n\r\n\r\nif __name__ == '__main__':\r\n print(main())\r\n # main()\r\n" ]
{"inputs": ["1\n2\n4\n50 50 100 100", "2\n2 3\n5\n50 50 50 50 50", "1\n1\n7\n1 1 1 1 1 1 1", "60\n7 4 20 15 17 6 2 2 3 18 13 14 16 11 13 12 6 10 14 1 16 6 4 9 10 8 10 15 16 13 13 9 16 11 5 4 11 1 20 5 11 20 19 9 14 13 10 6 6 9 2 13 11 4 1 6 8 18 10 3\n26\n2481 6519 9153 741 9008 6601 6117 1689 5911 2031 2538 5553 1358 6863 7521 4869 6276 5356 5305 6761 5689 7476 5833 257 2157 218", "88\n8 3 4 3 1 17 5 10 18 12 9 12 4 6 19 14 9 10 10 8 15 11 18 3 11 4 10 11 7 9 14 7 13 2 8 2 15 2 8 16 7 1 9 1 11 13 13 15 8 9 4 2 13 12 12 11 1 5 20 19 13 15 6 6 11 20 14 18 11 20 20 13 8 4 17 12 17 4 13 14 1 20 19 5 7 3 19 16\n33\n7137 685 2583 6751 2104 2596 2329 9948 7961 9545 1797 6507 9241 3844 5657 1887 225 7310 1165 6335 5729 5179 8166 9294 3281 8037 1063 6711 8103 7461 4226 2894 9085", "46\n11 6 8 8 11 8 2 8 17 3 16 1 9 12 18 2 2 5 17 19 3 9 8 19 2 4 2 15 2 11 13 13 8 6 10 12 7 7 17 15 10 19 7 7 19 6\n71\n6715 8201 9324 276 8441 2378 4829 9303 5721 3895 8193 7725 1246 8845 6863 2897 5001 5055 2745 596 9108 4313 1108 982 6483 7256 4313 8981 9026 9885 2433 2009 8441 7441 9044 6969 2065 6721 424 5478 9128 5921 11 6201 3681 4876 3369 6205 4865 8201 9751 371 2881 7995 641 5841 3595 6041 2403 1361 5121 3801 8031 7909 3809 7741 1026 9633 8711 1907 6363", "18\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\n15\n371 2453 905 1366 6471 4331 4106 2570 4647 1648 7911 2147 1273 6437 3393", "2\n12 4\n28\n5366 5346 1951 3303 1613 5826 8035 7079 7633 6155 9811 9761 3207 4293 3551 5245 7891 4463 3981 2216 3881 1751 4495 96 671 1393 1339 4241", "57\n3 13 20 17 18 18 17 2 17 8 20 2 11 12 11 14 4 20 9 20 14 19 20 4 4 8 8 18 17 16 18 10 4 7 9 8 10 8 20 4 11 8 12 16 16 4 11 12 16 1 6 14 11 12 19 8 20\n7\n5267 7981 1697 826 6889 1949 2413", "48\n14 2 5 3 10 10 5 6 14 8 19 13 4 4 3 13 18 19 9 16 3 1 14 9 13 10 13 4 12 11 8 2 18 20 14 11 3 11 18 11 4 2 7 2 18 19 2 8\n70\n9497 5103 1001 2399 5701 4053 3557 8481 1736 4139 5829 1107 6461 4089 5936 7961 6017 1416 1191 4635 4288 5605 8857 1822 71 1435 2837 5523 6993 2404 2840 8251 765 5678 7834 8595 3091 7073 8673 2299 2685 7729 8017 3171 9155 431 3773 7927 671 4063 1123 5384 2721 7901 2315 5199 8081 7321 8196 2887 9384 56 7501 1931 4769 2055 7489 3681 6321 8489", "1\n1\n1\n1", "1\n2\n1\n1", "1\n1\n3\n3 1 1"], "outputs": ["200", "150", "3", "44768", "61832", "129008", "38578", "89345", "11220", "115395", "1", "1", "3"]}
UNKNOWN
PYTHON3
CODEFORCES
35
21d3086ee327553584f533280fdd7ad2
Broken checker
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. The only line of the output contains an integer between 1 and 3, inclusive. Sample Input Sample Output
[ "#!/usr/bin/env python\n# coding=utf-8\n'''\nAuthor: Deean\nDate: 2021-11-29 23:39:34\nLastEditTime: 2021-11-29 23:40:38\nDescription: Broken checker\nFilePath: CF171D.py\n'''\n\n\ndef func():\n n = int(input())\n print(n % 5 % 3 + 1)\n\n\nif __name__ == '__main__':\n func()\n", "from collections import defaultdict, deque\r\nimport sys\r\ninput = lambda : sys.stdin.readline().strip()\r\n##############################################################################\r\nprint(int(input())%5%3+1)\r\n", "print([1,2,3,1,2,1][int(input())])\n#\n#\n#\n#\n#\n#\n#\n#\n#\n##############################", "a = int(input())\r\nprint(a % 5 % 3 + 1)", "a=int(input())\r\nb=[1,2,3]\r\nif a==5:\r\n print(1)\r\nelse:\r\n print(b[a%3])", "n=int(input())\nprint(n%5%3+1)", "print([0,2,3,1,2,1][int(input())])", "n = int(input())\r\n\r\nprint(1 if n == 5 else n%3 + 1)\r\n", "a = input()\nprint(int(a)%5%3+1)", "import random\r\nx = int(input())\r\nprint(1 if x == 3 or x==5 else 2 if x==1 or x==4 else 3)", "n = int(input())\r\na = [2, 3, 1, 2, 1]\r\n\r\nprint(a[n - 1])", "a=int(input())\r\nif a==5:\r\n print(1)\r\nelse:\r\n print(a%3+1)", "print([2,3,1,2,1][int(input())-1])", "x = int(input())\r\nprint(1 if x == 5 else x % 3 + 1)", "n = int(input())\r\nif n != 5:\r\n print(n%3+1)\r\nelse:\r\n print(1)", "i = int(input())\r\nif i != 5: print(i%3+1)\r\nelse: print(1)", "print([2, 3, 1, 2, 1][int(input()) - 1])", "n = int(input())\r\na = [(i + 1) % 3 + (3 if i % 3 == 2 else 0) for i in range(0, 5)]\r\na.append(a[0])\r\nprint(a[n])", "d = {1:2, 2:3, 3:1, 4:2, 5:1}\r\nprint(d[int(input())])", "n = int(input())\r\nprint(n % 5 % 3 + 1)", "n = int(input())\r\nstr = \"23121\"\r\nprint(str[n-1])", "n = int(input())\nif n != 5:\n print(n % 3 + 1)\nelse:\n print(1)", "print(int(input())%5%3+1)", "a = int(input())\r\nlist = [0,2,3,1,2,1]\r\nprint(list[a])", "x = int(input())\nif (x == 5):\n print(1)\nelse:\n print(x % 3 + 1)\n", "n = int(input())\r\nprint([2, 3,1,2,1][n - 1])", "n =int(input())\nif n==5:\n print(1)\nelse:\n print ((n%3)+1)\n###################\n###\n#\n#\n#\n#\n#\n", "n = int(input())\r\nd = {1:2, 2:3, 3:1, 4:2, 5:1}\r\nprint(d[n])\r\n", "n = int(input())\r\nprint((n%5)%3+1 )", "# /**\r\n# * author: brownfox2k6\r\n# * created: 23/05/2023 20:46:15 Hanoi, Vietnam\r\n# **/\r\n\r\nprint([2,3,1,2,1][int(input())-1])", "a=int(input())\nprint(a%5%3+1)", "n = int(input())\r\nprint((2, 3, 1, 2, 1)[n - 1])", "n = int(input())\r\n\r\nif (n==5):\r\n print(1)\r\nelse:\r\n print(n%3+1)", "n=int(input())\r\nh=[2,3,1,2,1,2]\r\nprint(h[n-1])", "n = int(input())\n\na = [0, 2, 3, 1, 2, 1]\n\nprint(a[n])\n", "n = int(input())\r\nif n == 3 or n == 5:\r\n print(1)\r\nelif n == 2:\r\n print(3)\r\nelse:\r\n print(2)", "print((int(input())%5)%3+1)", "n = int(input())\nprint(n%5%3+1)\n", "n = int(input())\r\nl = [3,5]\r\nif n in l:\r\n print(1)\r\nelif n == 2:\r\n print(3)\r\nelse:\r\n print(2)" ]
{"inputs": ["3", "1", "4", "2", "5"], "outputs": ["1", "2", "2", "3", "1"]}
UNKNOWN
PYTHON3
CODEFORCES
39
21daae042f23778474d174e49a3103bf
DravDe saves the world
How horrible! The empire of galactic chickens tries to conquer a beautiful city "Z", they have built a huge incubator that produces millions of chicken soldiers a day, and fenced it around. The huge incubator looks like a polygon on the plane *Oxy* with *n* vertices. Naturally, DravDe can't keep still, he wants to destroy the chicken empire. For sure, he will start with the incubator. DravDe is strictly outside the incubator's territory in point *A*(*x**a*,<=*y**a*), and wants to get inside and kill all the chickens working there. But it takes a lot of doing! The problem is that recently DravDe went roller skating and has broken both his legs. He will get to the incubator's territory in his jet airplane LEVAP-41. LEVAP-41 flies at speed *V*(*x**v*,<=*y**v*,<=*z**v*). DravDe can get on the plane in point *A*, fly for some time, and then air drop himself. DravDe is very heavy, that's why he falls vertically at speed *F**down*, but in each point of his free fall DravDe can open his parachute, and from that moment he starts to fall at the wind speed *U*(*x**u*,<=*y**u*,<=*z**u*) until he lands. Unfortunately, DravDe isn't good at mathematics. Would you help poor world's saviour find such an air dropping plan, that allows him to land on the incubator's territory? If the answer is not unique, DravDe wants to find the plan with the minimum time of his flight on the plane. If the answers are still multiple, he wants to find the one with the minimum time of his free fall before opening his parachute The first line contains the number *n* (3<=≤<=*n*<=≤<=104) — the amount of vertices of the fence. Then there follow *n* lines containing the coordinates of these vertices (two integer numbers *x**i*,<=*y**i*) in clockwise or counter-clockwise order. It's guaranteed, that the fence does not contain self-intersections. The following four lines contain coordinates of point *A*(*x**a*,<=*y**a*), speeds *V*(*x**v*,<=*y**v*,<=*z**v*), *F**down* and speed *U*(*x**u*,<=*y**u*,<=*z**u*). All the input numbers are integer. All the coordinates don't exceed 104 in absolute value. It's guaranteed, that *z**v*<=&gt;<=0 and *F**down*,<=*z**u*<=&lt;<=0, and point *A* is strictly outside the incubator's territory. In the first line output two numbers *t*1,<=*t*2 such, that if DravDe air drops at time *t*1 (counting from the beginning of the flight), he lands on the incubator's territory (landing on the border is regarder as landing on the territory). If DravDe doesn't open his parachute, the second number should be equal to the duration of DravDe's falling down. If it's impossible for DravDe to get to the incubator's territory, output -1 -1. If the answer is not unique, output the answer with the minimum *t*1. If the answers are still multiple, output the answer with the minimum *t*2. Your answer must have an absolute or relative error less than 10<=-<=6. Sample Input 4 0 0 1 0 1 1 0 1 0 -1 1 0 1 -1 0 1 -1 4 0 0 0 1 1 1 1 0 0 -1 -1 -1 1 -1 0 1 -1 4 0 0 1 0 1 1 0 1 0 -1 1 1 1 -1 1 1 -1 Sample Output 1.00000000 0.00000000 -1.00000000 -1.00000000 0.50000000 0.00000000
[ "class Point:\r\n def __init__(self, x, y, z=0):\r\n self.x = x\r\n self.y = y\r\n self.z = z\r\ndef main():\r\n n = int(input())\r\n pt = [Point(0, 0) for _ in range(n)]\r\n for i in range(n):\r\n pt[i].x, pt[i].y = map(float, input().split())\r\n a = Point(0, 0)\r\n v = Point(0, 0, 0)\r\n u = Point(0, 0, 0)\r\n a.x, a.y= map(float, input().split()) \r\n v.x, v.y, v.z = map(float, input().split())\r\n f = float(input())\r\n u.x, u.y, u.z = map(float, input().split())\r\n inf = 1e9\r\n eps = 1e-9\r\n a1 = v.x + u.x * v.z / abs(u.z)\r\n b1 = u.x * f / abs(u.z)\r\n c1 = a.x\r\n a2 = v.y + u.y * v.z / abs(u.z)\r\n b2 = u.y * f / abs(u.z)\r\n c2 = a.y\r\n ans1 = ans2 = inf\r\n for i in range(n):\r\n x1, y1 = pt[i].x, pt[i].y\r\n x2, y2 = pt[(i + 1) % n].x, pt[(i + 1) % n].y\r\n aa1 = a2 * (x2 - x1) - a1 * (y2 - y1)\r\n bb1 = b2 * (x2 - x1) - b1 * (y2 - y1)\r\n cc1 = (c2 - y2) * (x2 - x1) - (c1 - x2) * (y2 - y1)\r\n if abs(bb1) > eps:\r\n t1 = 0\r\n t2 = -cc1 / bb1\r\n if (a1 * t1 + b1 * t2 + c1 > min(x1, x2) - eps and\r\n a1 * t1 + b1 * t2 + c1 < max(x1, x2) + eps):\r\n if t2 > -eps and (a2 * t1 + b2 * t2 + c2 > min(y1, y2) - eps and\r\n a2 * t1 + b2 * t2 + c2 < max(y1, y2) + eps and\r\n v.z * t1 + f * t2 > -eps):\r\n if ans1 > t1 + eps:\r\n ans1 = t1\r\n ans2 = t2\r\n elif abs(ans1 - t1) < eps and ans2 > t2:\r\n ans2 = t2\r\n if abs(aa1) > eps:\r\n t1 = -cc1 / aa1\r\n t2 = 0\r\n if t1 > -eps:\r\n if (a1 * t1 + b1 * t2 + c1 > min(x1, x2) - eps and\r\n a1 * t1 + b1 * t2 + c1 < max(x1, x2) + eps):\r\n if (a2 * t1 + b2 * t2 + c2 > min(y1, y2) - eps and\r\n a2 * t1 + b2 * t2 + c2 < max(y1, y2) + eps and\r\n v.z * t1 + f * t2 > -eps):\r\n if ans1 > t1 + eps:\r\n ans1 = t1\r\n ans2 = t2\r\n elif abs(ans1 - t1) < eps and ans2 > t2:\r\n ans2 = t2\r\n A = a1 * b2 - a2 * b1\r\n B = (c1 - x1) * b2 - (c2 - y1) * b1\r\n if abs(A) > eps:\r\n t1 = -B / A\r\n B = (c2 - y1) * a1 - (c1 - x1) * a2\r\n t2 = -B / A\r\n if t1 > -eps and t2 > -eps:\r\n if (a1 * t1 + b1 * t2 + c1 > min(x1, x2) - eps and\r\n a1 * t1 + b1 * t2 + c1 < max(x1, x2) + eps):\r\n if (a2 * t1 + b2 * t2 + c2 > min(y1, y2) - eps and\r\n a2 * t1 + b2 * t2 + c2 < max(y1, y2) + eps and\r\n v.z * t1 + f * t2 > -eps):\r\n if ans1 > t1 + eps:\r\n ans1 = t1\r\n ans2 = t2\r\n A = bb1 * v.z / f - aa1\r\n B = cc1\r\n if abs(A) > eps:\r\n t1 = B / A\r\n t2 = -v.z * t1 / f\r\n if t1 > -eps and t2 > -eps:\r\n if (a1 * t1 + b1 * t2 + c1 > min(x1, x2) - eps and\r\n a1 * t1 + b1 * t2 + c1 < max(x1, x2) + eps):\r\n if (a2 * t1 + b2 * t2 + c2 > min(y1, y2) - eps and\r\n a2 * t1 + b2 * t2 + c2 < max(y1, y2) + eps):\r\n if ans1 > t1 + eps:\r\n ans1 = t1\r\n ans2 = t2\r\n if ans1 == inf:\r\n ans1 = ans2 = -1\r\n print(f\"{ans1:.20f} {ans2:.20f}\")\r\nif __name__ == \"__main__\":\r\n main()# 1693911700.4213545" ]
{"inputs": ["4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 0 1\n-1\n0 1 -1", "4\n0 0\n0 1\n1 1\n1 0\n0 -1\n-1 -1 1\n-1\n0 1 -1", "4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 1 1\n-1\n1 1 -1", "3\n-3 4\n5 -1\n-1 0\n-4 3\n4 4 5\n-3\n0 -3 -4", "4\n-2 1\n3 3\n2 -4\n0 -5\n-4 3\n2 4 4\n-4\n2 5 -4", "5\n10 10\n9 10\n8 9\n9 8\n10 9\n-10 -10\n1 1 1\n-1\n0 1 -1", "10\n-14 18\n17 -17\n13 -16\n8 -13\n0 -4\n0 -8\n-13 16\n-1 -12\n-8 -9\n-11 -6\n2 17\n-20 3 9\n-8\n-5 14 -2", "10\n-17 -17\n-6 13\n-13 -8\n-12 -9\n-7 -2\n-11 -13\n2 -11\n-7 -14\n6 -14\n8 -15\n15 -11\n5 -4 1\n-12\n10 -15 -11", "10\n-16 -7\n-13 -4\n6 11\n17 9\n12 2\n15 -8\n5 -11\n5 -12\n-13 -8\n-7 -19\n-12 1\n-11 -12 5\n-16\n-15 -1 -20", "10\n-19 -8\n-6 17\n0 18\n-9 -2\n9 7\n3 1\n2 -9\n-11 -9\n6 -12\n-16 -10\n3 13\n14 20 16\n-20\n2 11 -17", "10\n-19 -13\n-19 8\n-2 13\n-7 5\n1 17\n8 -3\n15 -2\n15 -10\n12 -11\n11 -13\n3 -19\n-14 -20 7\n-3\n20 -17 -19", "10\n-9 4\n-9 10\n1 9\n4 8\n-4 3\n4 -1\n-1 -1\n9 -8\n8 -9\n0 -6\n10 7\n3 -4 2\n-10\n-7 0 -10", "10\n-7 9\n-6 10\n6 9\n-3 8\n10 2\n1 1\n3 -2\n2 -6\n3 -8\n-5 -3\n10 5\n-7 5 4\n-5\n5 -5 -2", "10\n-17 -17\n-6 13\n-13 -8\n-12 -9\n-7 -2\n-11 -13\n2 -11\n-7 -14\n6 -14\n8 -15\n-20 0\n5 -4 1\n-12\n10 -15 -11", "10\n-8 3\n2 10\n9 6\n-2 3\n1 1\n8 -3\n-6 2\n10 -6\n9 -7\n-3 -5\n10 10\n-7 5 4\n-5\n5 -5 -2", "4\n-4 -5\n-4 -3\n-4 -2\n2 -5\n-4 3\n0 -4 3\n-3\n0 4 -3", "4\n-4 2\n1 -3\n0 -4\n-3 -3\n5 4\n0 0 1\n-5\n-1 -1 -2", "4\n-5 4\n1 5\n2 1\n0 0\n-3 0\n0 0 1\n-5\n2 0 -3", "4\n-5 4\n1 5\n2 1\n0 0\n-3 -1\n0 0 1\n-5\n2 0 -3", "4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 1 1\n-5\n0 0 -2", "4\n0 0\n1 0\n1 1\n0 1\n0 -1\n1 1 1\n-5\n-1 -1 -2", "10\n-9 7\n-8 10\n3 10\n0 9\n0 7\n5 1\n8 -3\n7 -4\n4 -7\n-5 -10\n10 1\n-10 20 2\n-2\n-1 -5000 -6", "10\n-9 7\n-8 10\n3 10\n0 9\n0 7\n5 1\n8 -3\n7 -4\n4 -7\n-5 -10\n10 1\n0 0 2\n-2\n0 0 -6", "4\n-8 -2\n8 -2\n8 -5\n-7 -8\n2 -8\n1 2 6\n-4\n-3 -6 -2", "4\n0 0\n0 1\n1 1\n1 0\n0 -1\n1 1 1\n-2\n1 1 -1", "4\n0 0\n0 1\n1 1\n1 0\n0 -1\n1 1 1\n-2\n-1 -1 -2", "4\n-8 -2\n8 -2\n8 -5\n-7 -8\n2 2\n1 2 6\n-4\n-3 -6 -2", "4\n-4 2\n-2 2\n3 -1\n2 -2\n-100 0\n3 -1 2\n-3\n2 2 -2", "10\n-5 -4\n-3 0\n-2 2\n0 4\n-1 2\n2 5\n4 5\n-3 -3\n5 1\n1 -5\n10000 2\n-5 4 4\n-1\n1 -5 -3", "10\n-19 20\n-7 20\n2 8\n-9 3\n-8 -3\n-12 3\n-8 -11\n-16 7\n-14 -6\n-14 -8\n13 -10\n11 20 13\n-20\n5 -12 -16", "10\n-16 19\n8 12\n17 7\n6 5\n13 -9\n1 -4\n-7 -4\n-4 -12\n-3 -18\n-10 -3\n-13 5\n-5 12 17\n-4\n19 2 -5", "5\n10000 10000\n9999 10000\n9998 9999\n9999 9998\n10000 9999\n-10000 -10000\n1 1 1\n-1\n0 1 -1", "5\n10000 10000\n9999 10000\n9998 9999\n9999 9998\n10000 9999\n-10000 -10000\n1 1 1\n-1\n0 0 -1", "5\n10000 10000\n9999 10000\n9998 9999\n9999 9998\n10000 9999\n-10000 -10000\n10000 10000 10000\n-10000\n0 0 -10000", "5\n10 10\n9 10\n8 9\n9 8\n10 9\n-10 -10\n10000 10000 10000\n-10000\n0 0 -10000", "10\n-9 -3\n-7 9\n-7 2\n6 7\n1 -2\n3 -5\n-3 -5\n1 -7\n-7 -4\n-6 -6\n-8 8\n10 3 5\n-6\n-1 -6 -2", "10\n-7 -5\n-6 -1\n-3 3\n6 7\n0 0\n9 2\n-2 -3\n4 -3\n0 -5\n-2 -7\n-5 2\n8 3 1\n-7\n-5 4 -6"], "outputs": ["1.00000000 0.00000000", "-1.00000000 -1.00000000", "0.50000000 0.00000000", "0.25000000 0.41666667", "-1.00000000 -1.00000000", "18.00000000 17.00000000", "-1.00000000 -1.00000000", "-1.00000000 -1.00000000", "-1.00000000 -1.00000000", "-1.00000000 -1.00000000", "-1.00000000 -1.00000000", "-1.00000000 -1.00000000", "0.76923077 0.61538462", "1.17237399 -0.00000000", "2.50000000 0.68000000", "1.25000000 1.25000000", "11.00000000 0.00000000", "4.50000000 0.00000000", "-1.00000000 -1.00000000", "1.00000000 0.00000000", "1.00000000 0.20000000", "0.19984006 0.19504198", "-1.00000000 -1.00000000", "1.00000000 1.50000000", "0.50000000 0.00000000", "1.00000000 0.50000000", "0.25000000 0.00000000", "23.50000000 7.16666667", "2379.80952381 3807.09523810", "-1.00000000 -1.00000000", "0.01264045 -0.00000000", "19998.00000000 19997.00000000", "19998.50000000 0.00000000", "1.99985000 0.00000000", "0.00185000 0.00000000", "0.08771930 -0.00000000", "0.21739130 0.03105590"]}
UNKNOWN
PYTHON3
CODEFORCES
1